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-chinese-date-string
"cal-china" (&optional date
))
44 (declare-function calendar-coptic-date-string
"cal-coptic" (&optional date
))
45 (declare-function calendar-ethiopic-date-string
"cal-coptic" (&optional date
))
46 (declare-function calendar-french-date-string
"cal-french" (&optional date
))
47 (declare-function calendar-goto-date
"cal-move" (date))
48 (declare-function calendar-hebrew-date-string
"cal-hebrew" (&optional date
))
49 (declare-function calendar-islamic-date-string
"cal-islam" (&optional date
))
50 (declare-function calendar-iso-date-string
"cal-iso" (&optional date
))
51 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
52 (declare-function calendar-julian-date-string
"cal-julian" (&optional date
))
53 (declare-function calendar-mayan-date-string
"cal-mayan" (&optional date
))
54 (declare-function calendar-persian-date-string
"cal-persia" (&optional date
))
55 (declare-function org-datetree-find-date-create
"org-datetree"
56 (date &optional keep-restriction
))
57 (declare-function org-columns-quit
"org-colview" ())
58 (declare-function diary-date-display-form
"diary-lib" (&optional type
))
59 (declare-function org-mobile-write-agenda-for-mobile
"org-mobile" (file))
60 (declare-function org-habit-insert-consistency-graphs
61 "org-habit" (&optional line
))
62 (declare-function org-is-habit-p
"org-habit" (&optional pom
))
63 (declare-function org-habit-parse-todo
"org-habit" (&optional pom
))
64 (declare-function org-habit-get-priority
"org-habit" (habit &optional moment
))
65 (defvar calendar-mode-map
)
66 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
67 (defvar org-habit-show-habits
)
68 (defvar org-habit-show-habits-only-for-today
)
70 ;; Defined somewhere in this file, but used before definition.
71 (defvar org-agenda-buffer-name
)
72 (defvar org-agenda-overriding-header
)
73 (defvar org-agenda-title-append nil
)
76 (defvar org-agenda-undo-list
)
77 (defvar org-agenda-pending-undo-list
)
78 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
80 (defcustom org-agenda-confirm-kill
1
81 "When set, remote killing from the agenda buffer needs confirmation.
82 When t, a confirmation is always needed. When a number N, confirmation is
83 only needed when the text to be killed contains more than N non-white lines."
86 (const :tag
"Never" nil
)
87 (const :tag
"Always" t
)
88 (integer :tag
"When more than N lines")))
90 (defcustom org-agenda-compact-blocks nil
91 "Non-nil means make the block agenda more compact.
92 This is done by leaving out unnecessary lines."
96 (defcustom org-agenda-block-separator ?
=
97 "The separator between blocks in the agenda.
98 If this is a string, it will be used as the separator, with a newline added.
99 If it is a character, it will be repeated to fill the window width."
105 (defgroup org-agenda-export nil
106 "Options concerning exporting agenda views in Org-mode."
107 :tag
"Org Agenda Export"
110 (defcustom org-agenda-with-colors t
111 "Non-nil means use colors in agenda views."
112 :group
'org-agenda-export
115 (defcustom org-agenda-exporter-settings nil
116 "Alist of variable/value pairs that should be active during agenda export.
117 This is a good place to set options for ps-print and for htmlize.
118 Note that the way this is implemented, the values will be evaluated
119 before assigned to the variables. So make sure to quote values you do
120 *not* want evaluated, for example
122 (setq org-agenda-exporter-settings
123 '((ps-print-color-p 'black-white)))"
124 :group
'org-agenda-export
128 (sexp :tag
"Value"))))
130 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
131 "Hook run in temporary buffer before writing it to an export file.
132 A useful function is `org-agenda-add-entry-text'."
133 :group
'org-agenda-export
135 :options
'(org-agenda-add-entry-text))
137 (defcustom org-agenda-add-entry-text-maxlines
0
138 "Maximum number of entry text lines to be added to agenda.
139 This is only relevant when `org-agenda-add-entry-text' is part of
140 `org-agenda-before-write-hook', which it is by default.
141 When this is 0, nothing will happen. When it is greater than 0, it
142 specifies the maximum number of lines that will be added for each entry
143 that is listed in the agenda view.
145 Note that this variable is not used during display, only when exporting
146 the agenda. For agenda display, see org-agenda-entry-text-mode and the
147 variable `org-agenda-entry-text-maxlines'."
151 (defcustom org-agenda-add-entry-text-descriptive-links t
152 "Non-nil means export org-links as descriptive links in agenda added text.
153 This variable applies to the text added to the agenda when
154 `org-agenda-add-entry-text-maxlines' is larger than 0.
155 When this variable nil, the URL will (also) be shown."
159 (defcustom org-agenda-export-html-style
""
160 "The style specification for exported HTML Agenda files.
161 If this variable contains a string, it will replace the default <style>
162 section as produced by `htmlize'.
163 Since there are different ways of setting style information, this variable
164 needs to contain the full HTML structure to provide a style, including the
165 surrounding HTML tags. The style specifications should include definitions
166 the fonts used by the agenda, here is an example:
168 <style type=\"text/css\">
169 p { font-weight: normal; color: gray; }
170 .org-agenda-structure {
185 .title { text-align: center; }
186 .todo, .deadline { color: red; }
187 .done { color: green; }
190 or, if you want to keep the style in a file,
192 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
194 As the value of this option simply gets inserted into the HTML <head> header,
195 you can \"misuse\" it to also add other text to the header. However,
196 <style>...</style> is required, if not present the variable will be ignored."
197 :group
'org-agenda-export
198 :group
'org-export-html
201 (defgroup org-agenda-custom-commands nil
202 "Options concerning agenda views in Org-mode."
203 :tag
"Org Agenda Custom Commands"
206 (defconst org-sorting-choice
208 (const time-up
) (const time-down
)
209 (const category-keep
) (const category-up
) (const category-down
)
210 (const tag-down
) (const tag-up
)
211 (const priority-up
) (const priority-down
)
212 (const todo-state-up
) (const todo-state-down
)
213 (const effort-up
) (const effort-down
)
214 (const habit-up
) (const habit-down
)
215 (const user-defined-up
) (const user-defined-down
))
218 (defconst org-agenda-custom-commands-local-options
219 `(repeat :tag
"Local settings for this command. Remember to quote values"
220 (choice :tag
"Setting"
221 (list :tag
"Heading for this block"
222 (const org-agenda-overriding-header
)
223 (string :tag
"Headline"))
224 (list :tag
"Files to be searched"
225 (const org-agenda-files
)
227 (const :format
"" quote
)
229 (list :tag
"Sorting strategy"
230 (const org-agenda-sorting-strategy
)
232 (const :format
"" quote
)
234 ,org-sorting-choice
)))
235 (list :tag
"Prefix format"
236 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
238 (list :tag
"Number of days in agenda"
239 (const org-agenda-ndays
)
241 (list :tag
"Fixed starting date"
242 (const org-agenda-start-day
)
243 (string :value
"2007-11-01"))
244 (list :tag
"Start on day of week"
245 (const org-agenda-start-on-weekday
)
247 (const :tag
"Today" nil
)
248 (integer :tag
"Weekday No.")))
249 (list :tag
"Include data from diary"
250 (const org-agenda-include-diary
)
252 (list :tag
"Deadline Warning days"
253 (const org-deadline-warning-days
)
255 (list :tag
"Tags filter preset"
256 (const org-agenda-filter-preset
)
258 (const :format
"" quote
)
260 (string :tag
"+tag or -tag"))))
261 (list :tag
"Standard skipping condition"
262 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
263 (const org-agenda-skip-function
)
265 (const :format
"" quote
)
268 :tag
"Skipping range"
269 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
270 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
271 (repeat :inline t
:tag
"Conditions for skipping"
273 :tag
"Condition type"
274 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
275 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
276 (const :tag
"scheduled" 'scheduled
)
277 (const :tag
"not scheduled" 'notscheduled
)
278 (const :tag
"deadline" 'deadline
)
279 (const :tag
"no deadline" 'notdeadline
)
280 (const :tag
"timestamp" 'timestamp
)
281 (const :tag
"no timestamp" 'nottimestamp
))))))
282 (list :tag
"Non-standard skipping condition"
283 :value
(org-agenda-skip-function)
284 (const org-agenda-skip-function
)
285 (sexp :tag
"Function or form (quoted!)"))
286 (list :tag
"Any variable"
287 (variable :tag
"Variable")
288 (sexp :tag
"Value (sexp)"))))
289 "Selection of examples for agenda command settings.
290 This will be spliced into the custom type of
291 `org-agenda-custom-commands'.")
294 (defcustom org-agenda-custom-commands nil
295 "Custom commands for the agenda.
296 These commands will be offered on the splash screen displayed by the
297 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
299 (key desc type match settings files)
301 key The key (one or more characters as a string) to be associated
303 desc A description of the command, when omitted or nil, a default
304 description is built using MATCH.
305 type The command type, any of the following symbols:
306 agenda The daily/weekly agenda.
307 todo Entries with a specific TODO keyword, in all agenda files.
308 search Entries containing search words entry or headline.
309 tags Tags/Property/TODO match in all agenda files.
310 tags-todo Tags/P/T match in all agenda files, TODO entries only.
311 todo-tree Sparse tree of specific TODO keyword in *current* file.
312 tags-tree Sparse tree with all tags matches in *current* file.
313 occur-tree Occur sparse tree for *current* file.
314 ... A user-defined function.
315 match What to search for:
316 - a single keyword for TODO keyword searches
317 - a tags match expression for tags searches
318 - a word search expression for text searches.
319 - a regular expression for occur searches
320 For all other commands, this should be the empty string.
321 settings A list of option settings, similar to that in a let form, so like
322 this: ((opt1 val1) (opt2 val2) ...). The values will be
323 evaluated at the moment of execution, so quote them when needed.
324 files A list of files file to write the produced agenda buffer to
325 with the command `org-store-agenda-views'.
326 If a file name ends in \".html\", an HTML version of the buffer
327 is written out. If it ends in \".ps\", a postscript version is
328 produced. Otherwise, only the plain text is written to the file.
330 You can also define a set of commands, to create a composite agenda buffer.
331 In this case, an entry looks like this:
333 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
337 desc A description string to be displayed in the dispatcher menu.
338 cmd An agenda command, similar to the above. However, tree commands
339 are no allowed, but instead you can get agenda and global todo list.
340 So valid commands for a set are:
341 (agenda \"\" settings)
342 (alltodo \"\" settings)
343 (stuck \"\" settings)
344 (todo \"match\" settings files)
345 (search \"match\" settings files)
346 (tags \"match\" settings files)
347 (tags-todo \"match\" settings files)
349 Each command can carry a list of options, and another set of options can be
350 given for the whole set of commands. Individual command options take
351 precedence over the general options.
353 When using several characters as key to a command, the first characters
354 are prefix commands. For the dispatcher to display useful information, you
355 should provide a description for the prefix, like
357 (setq org-agenda-custom-commands
358 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
359 (\"hl\" tags \"+HOME+Lisa\")
360 (\"hp\" tags \"+HOME+Peter\")
361 (\"hk\" tags \"+HOME+Kim\")))"
362 :group
'org-agenda-custom-commands
364 (choice :value
("x" "Describe command here" tags
"" nil
)
365 (list :tag
"Single command"
366 (string :tag
"Access Key(s) ")
367 (option (string :tag
"Description"))
369 (const :tag
"Agenda" agenda
)
370 (const :tag
"TODO list" alltodo
)
371 (const :tag
"Search words" search
)
372 (const :tag
"Stuck projects" stuck
)
373 (const :tag
"Tags/Property match (all agenda files)" tags
)
374 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
375 (const :tag
"TODO keyword search (all agenda files)" todo
)
376 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
377 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
378 (const :tag
"Occur tree (current buffer)" occur-tree
)
379 (sexp :tag
"Other, user-defined function"))
380 (string :tag
"Match (only for some commands)")
381 ,org-agenda-custom-commands-local-options
382 (option (repeat :tag
"Export" (file :tag
"Export to"))))
383 (list :tag
"Command series, all agenda files"
384 (string :tag
"Access Key(s)")
385 (string :tag
"Description ")
386 (repeat :tag
"Component"
389 (const :format
"" agenda
)
390 (const :tag
"" :format
"" "")
391 ,org-agenda-custom-commands-local-options
)
392 (list :tag
"TODO list (all keywords)"
393 (const :format
"" alltodo
)
394 (const :tag
"" :format
"" "")
395 ,org-agenda-custom-commands-local-options
)
396 (list :tag
"Search words"
397 (const :format
"" search
)
398 (string :tag
"Match")
399 ,org-agenda-custom-commands-local-options
)
400 (list :tag
"Stuck projects"
401 (const :format
"" stuck
)
402 (const :tag
"" :format
"" "")
403 ,org-agenda-custom-commands-local-options
)
404 (list :tag
"Tags search"
405 (const :format
"" tags
)
406 (string :tag
"Match")
407 ,org-agenda-custom-commands-local-options
)
408 (list :tag
"Tags search, TODO entries only"
409 (const :format
"" tags-todo
)
410 (string :tag
"Match")
411 ,org-agenda-custom-commands-local-options
)
412 (list :tag
"TODO keyword search"
413 (const :format
"" todo
)
414 (string :tag
"Match")
415 ,org-agenda-custom-commands-local-options
)
416 (list :tag
"Other, user-defined function"
417 (symbol :tag
"function")
418 (string :tag
"Match")
419 ,org-agenda-custom-commands-local-options
)))
421 (repeat :tag
"Settings for entire command set"
422 (list (variable :tag
"Any variable")
423 (sexp :tag
"Value")))
424 (option (repeat :tag
"Export" (file :tag
"Export to"))))
425 (cons :tag
"Prefix key documentation"
426 (string :tag
"Access Key(s)")
427 (string :tag
"Description ")))))
429 (defcustom org-agenda-query-register ?o
430 "The register holding the current query string.
431 The purpose of this is that if you construct a query string interactively,
432 you can then use it to define a custom command."
433 :group
'org-agenda-custom-commands
436 (defcustom org-stuck-projects
437 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
438 "How to identify stuck projects.
439 This is a list of four items:
440 1. A tags/todo/property matcher string that is used to identify a project.
441 See the manual for a description of tag and property searches.
442 The entire tree below a headline matched by this is considered one project.
443 2. A list of TODO keywords identifying non-stuck projects.
444 If the project subtree contains any headline with one of these todo
445 keywords, the project is considered to be not stuck. If you specify
446 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
447 3. A list of tags identifying non-stuck projects.
448 If the project subtree contains any headline with one of these tags,
449 the project is considered to be not stuck. If you specify \"*\" as
450 a tag, any tag will mark the project unstuck. Note that this is about
451 the explicit presence of a tag somewhere in the subtree, inherited
452 tags to not count here. If inherited tags make a project not stuck,
453 use \"-TAG\" in the tags part of the matcher under (1.) above.
454 4. An arbitrary regular expression matching non-stuck projects.
456 If the project turns out to be not stuck, search continues also in the
457 subtree to see if any of the subtasks have project status.
459 See also the variable `org-tags-match-list-sublevels' which applies
460 to projects matched by this search as well.
462 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
463 or `C-c a #' to produce the list."
464 :group
'org-agenda-custom-commands
466 (string :tag
"Tags/TODO match to identify a project")
467 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
468 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
469 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
471 (defcustom org-agenda-filter-effort-default-operator
"<"
472 "The default operator for effort estimate filtering.
473 If you select an effort estimate limit without first pressing an operator,
474 this one will be used."
475 :group
'org-agenda-custom-commands
476 :type
'(choice (const :tag
"less or equal" "<")
477 (const :tag
"greater or equal"">")
478 (const :tag
"equal" "=")))
480 (defgroup org-agenda-skip nil
481 "Options concerning skipping parts of agenda files."
482 :tag
"Org Agenda Skip"
484 (defgroup org-agenda-daily
/weekly nil
485 "Options concerning the daily/weekly agenda."
486 :tag
"Org Agenda Daily/Weekly"
488 (defgroup org-agenda-todo-list nil
489 "Options concerning the global todo list agenda view."
490 :tag
"Org Agenda Todo List"
492 (defgroup org-agenda-match-view nil
493 "Options concerning the general tags/property/todo match agenda view."
494 :tag
"Org Agenda Match View"
496 (defgroup org-agenda-search-view nil
497 "Options concerning the general tags/property/todo match agenda view."
498 :tag
"Org Agenda Match View"
501 (defvar org-agenda-archives-mode nil
502 "Non-nil means the agenda will include archived items.
503 If this is the symbol `trees', trees in the selected agenda scope
504 that are marked with the ARCHIVE tag will be included anyway. When this is
505 t, also all archive files associated with the current selection of agenda
506 files will be included.")
508 (defcustom org-agenda-skip-comment-trees t
509 "Non-nil means skip trees that start with the COMMENT keyword.
510 When nil, these trees are also scanned by agenda commands."
511 :group
'org-agenda-skip
514 (defcustom org-agenda-todo-list-sublevels t
515 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
516 When nil, the sublevels of a TODO entry are not checked, resulting in
517 potentially much shorter TODO lists."
518 :group
'org-agenda-skip
519 :group
'org-agenda-todo-list
522 (defcustom org-agenda-todo-ignore-with-date nil
523 "Non-nil means don't show entries with a date in the global todo list.
524 You can use this if you prefer to mark mere appointments with a TODO keyword,
525 but don't want them to show up in the TODO list.
526 When this is set, it also covers deadlines and scheduled items, the settings
527 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
529 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
530 :group
'org-agenda-skip
531 :group
'org-agenda-todo-list
534 (defcustom org-agenda-todo-ignore-scheduled nil
535 "Non-nil means don't show scheduled entries in the global todo list.
536 The idea behind this is that by scheduling it, you have already taken care
538 See also `org-agenda-todo-ignore-with-date'.
539 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
540 :group
'org-agenda-skip
541 :group
'org-agenda-todo-list
544 (defcustom org-agenda-todo-ignore-deadlines nil
545 "Non-nil means don't show near deadline entries in the global todo list.
546 Near means closer than `org-deadline-warning-days' days.
547 The idea behind this is that such items will appear in the agenda anyway.
548 See also `org-agenda-todo-ignore-with-date'.
549 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
550 :group
'org-agenda-skip
551 :group
'org-agenda-todo-list
554 (defcustom org-agenda-tags-todo-honor-ignore-options nil
555 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
557 `org-agenda-todo-ignore-with-date',
558 `org-agenda-todo-ignore-scheduled'
559 `org-agenda-todo-ignore-deadlines'
560 make the global TODO list skip entries that have time stamps of certain
561 kinds. If this option is set, the same options will also apply for the
562 tags-todo search, which is the general tags/property matcher
563 restricted to unfinished TODO entries only."
564 :group
'org-agenda-skip
565 :group
'org-agenda-todo-list
566 :group
'org-agenda-match-view
569 (defcustom org-agenda-skip-scheduled-if-done nil
570 "Non-nil means don't show scheduled items in agenda when they are done.
571 This is relevant for the daily/weekly agenda, not for the TODO list. And
572 it applies only to the actual date of the scheduling. Warnings about
573 an item with a past scheduling dates are always turned off when the item
575 :group
'org-agenda-skip
576 :group
'org-agenda-daily
/weekly
579 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
580 "Non-nil means skip scheduling line if same entry shows because of deadline.
581 In the agenda of today, an entry can show up multiple times because
582 it is both scheduled and has a nearby deadline, and maybe a plain time
584 When this variable is t, then only the deadline is shown and the fact that
585 the entry is scheduled today or was scheduled previously is not shown.
586 When this variable is nil, the entry will be shown several times. When
587 the variable is the symbol `not-today', then skip scheduled previously,
588 but not scheduled today."
589 :group
'org-agenda-skip
590 :group
'org-agenda-daily
/weekly
592 (const :tag
"Never" nil
)
593 (const :tag
"Always" t
)
594 (const :tag
"Not when scheduled today" not-today
)))
596 (defcustom org-agenda-skip-deadline-if-done nil
597 "Non-nil means don't show deadlines when the corresponding item is done.
598 When nil, the deadline is still shown and should give you a happy feeling.
599 This is relevant for the daily/weekly agenda. And it applied only to the
600 actually date of the deadline. Warnings about approaching and past-due
601 deadlines are always turned off when the item is DONE."
602 :group
'org-agenda-skip
603 :group
'org-agenda-daily
/weekly
606 (defcustom org-agenda-skip-additional-timestamps-same-entry t
607 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
608 When non-nil, after the search for timestamps has matched once in an
609 entry, the rest of the entry will not be searched."
610 :group
'org-agenda-skip
613 (defcustom org-agenda-skip-timestamp-if-done nil
614 "Non-nil means don't select item by timestamp or -range if it is DONE."
615 :group
'org-agenda-skip
616 :group
'org-agenda-daily
/weekly
619 (defcustom org-agenda-dim-blocked-tasks t
620 "Non-nil means dim blocked tasks in the agenda display.
621 This causes some overhead during agenda construction, but if you
622 have turned on `org-enforce-todo-dependencies',
623 `org-enforce-todo-checkbox-dependencies', or any other blocking
624 mechanism, this will create useful feedback in the agenda.
626 Instead of t, this variable can also have the value `invisible'.
627 Then blocked tasks will be invisible and only become visible when
628 they become unblocked. An exemption to this behavior is when a task is
629 blocked because of unchecked checkboxes below it. Since checkboxes do
630 not show up in the agenda views, making this task invisible you remove any
631 trace from agenda views that there is something to do. Therefore, a task
632 that is blocked because of checkboxes will never be made invisible, it
633 will only be dimmed."
634 :group
'org-agenda-daily
/weekly
635 :group
'org-agenda-todo-list
637 (const :tag
"Do not dim" nil
)
638 (const :tag
"Dim to a grey face" t
)
639 (const :tag
"Make invisible" invisible
)))
641 (defcustom org-timeline-show-empty-dates
3
642 "Non-nil means `org-timeline' also shows dates without an entry.
643 When nil, only the days which actually have entries are shown.
644 When t, all days between the first and the last date are shown.
645 When an integer, show also empty dates, but if there is a gap of more than
646 N days, just insert a special line indicating the size of the gap."
647 :group
'org-agenda-skip
649 (const :tag
"None" nil
)
651 (integer :tag
"at most")))
653 (defgroup org-agenda-startup nil
654 "Options concerning initial settings in the Agenda in Org Mode."
655 :tag
"Org Agenda Startup"
658 (defcustom org-finalize-agenda-hook nil
659 "Hook run just before displaying an agenda buffer."
660 :group
'org-agenda-startup
663 (defcustom org-agenda-mouse-1-follows-link nil
664 "Non-nil means mouse-1 on a link will follow the link in the agenda.
665 A longer mouse click will still set point. Does not work on XEmacs.
666 Needs to be set before org.el is loaded."
667 :group
'org-agenda-startup
670 (defcustom org-agenda-start-with-follow-mode nil
671 "The initial value of follow-mode in a newly created agenda window."
672 :group
'org-agenda-startup
675 (defcustom org-agenda-show-outline-path t
676 "Non-nil means show outline path in echo area after line motion."
677 :group
'org-agenda-startup
680 (defcustom org-agenda-start-with-entry-text-mode nil
681 "The initial value of entry-text-mode in a newly created agenda window."
682 :group
'org-agenda-startup
685 (defcustom org-agenda-entry-text-maxlines
5
686 "Number of text lines to be added when `E' is pressed in the agenda.
688 Note that this variable only used during agenda display. Add add entry text
689 when exporting the agenda, configure the variable
690 `org-agenda-add-entry-ext-maxlines'."
694 (defcustom org-agenda-entry-text-exclude-regexps nil
695 "List of regular expressions to clean up entry text.
696 The complete matches of all regular expressions in this list will be
697 removed from entry text before it is shown in the agenda."
699 :type
'(repeat (regexp)))
701 (defvar org-agenda-entry-text-cleanup-hook nil
702 "Hook that is run after basic cleanup of entry text to be shown in agenda.
703 This cleanup is done in a temporary buffer, so the function may inspect and
704 change the entire buffer.
705 Some default stuff like drawers and scheduling/deadline dates will already
706 have been removed when this is called, as will any matches for regular
707 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
709 (defvar org-agenda-include-inactive-timestamps nil
710 "Non-nil means include inactive time stamps in agenda and timeline.")
712 (defgroup org-agenda-windows nil
713 "Options concerning the windows used by the Agenda in Org Mode."
714 :tag
"Org Agenda Windows"
717 (defcustom org-agenda-window-setup
'reorganize-frame
718 "How the agenda buffer should be displayed.
719 Possible values for this option are:
721 current-window Show agenda in the current window, keeping all other windows.
722 other-window Use `switch-to-buffer-other-window' to display agenda.
723 reorganize-frame Show only two windows on the current frame, the current
724 window and the agenda.
725 other-frame Use `switch-to-buffer-other-frame' to display agenda.
726 Also, when exiting the agenda, kill that frame.
727 See also the variable `org-agenda-restore-windows-after-quit'."
728 :group
'org-agenda-windows
730 (const current-window
)
733 (const reorganize-frame
)))
735 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
736 "The min and max height of the agenda window as a fraction of frame height.
737 The value of the variable is a cons cell with two numbers between 0 and 1.
738 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
739 :group
'org-agenda-windows
740 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
742 (defcustom org-agenda-restore-windows-after-quit nil
743 "Non-nil means restore window configuration open exiting agenda.
744 Before the window configuration is changed for displaying the agenda,
745 the current status is recorded. When the agenda is exited with
746 `q' or `x' and this option is set, the old state is restored. If
747 `org-agenda-window-setup' is `other-frame', the value of this
748 option will be ignored."
749 :group
'org-agenda-windows
752 (defcustom org-agenda-ndays
7
753 "Number of days to include in overview display.
755 Custom commands can set this variable in the options section."
756 :group
'org-agenda-daily
/weekly
759 (defcustom org-agenda-start-on-weekday
1
760 "Non-nil means start the overview always on the specified weekday.
761 0 denotes Sunday, 1 denotes Monday etc.
762 When nil, always start on the current day.
763 Custom commands can set this variable in the options section."
764 :group
'org-agenda-daily
/weekly
765 :type
'(choice (const :tag
"Today" nil
)
766 (integer :tag
"Weekday No.")))
768 (defcustom org-agenda-show-all-dates t
769 "Non-nil means `org-agenda' shows every day in the selected range.
770 When nil, only the days which actually have entries are shown."
771 :group
'org-agenda-daily
/weekly
774 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
775 "Format string for displaying dates in the agenda.
776 Used by the daily/weekly agenda and by the timeline. This should be
777 a format string understood by `format-time-string', or a function returning
778 the formatted date as a string. The function must take a single argument,
779 a calendar-style date list like (month day year)."
780 :group
'org-agenda-daily
/weekly
782 (string :tag
"Format string")
783 (function :tag
"Function")))
785 (defun org-agenda-format-date-aligned (date)
786 "Format a date string for display in the daily/weekly agenda, or timeline.
787 This function makes sure that dates are aligned for easy reading."
789 (let* ((dayname (calendar-day-name date
))
791 (day-of-week (calendar-day-of-week date
))
793 (monthname (calendar-month-name month
))
795 (iso-week (org-days-to-iso-week
796 (calendar-absolute-from-gregorian date
)))
797 (weekyear (cond ((and (= month
1) (>= iso-week
52))
799 ((and (= month
12) (<= iso-week
1))
802 (weekstring (if (= day-of-week
1)
803 (format " W%02d" iso-week
)
805 (format "%-10s %2d %s %4d%s"
806 dayname day monthname year weekstring
)))
808 (defcustom org-agenda-time-leading-zero nil
809 "Non-nil means use leading zero for military times in agenda.
810 For example, 9:30am would become 09:30 rather than 9:30."
811 :group
'org-agenda-daily
/weekly
814 (defcustom org-agenda-weekend-days
'(6 0)
815 "Which days are weekend?
816 These days get the special face `org-agenda-date-weekend' in the agenda
817 and timeline buffers."
818 :group
'org-agenda-daily
/weekly
819 :type
'(set :greedy t
820 (const :tag
"Monday" 1)
821 (const :tag
"Tuesday" 2)
822 (const :tag
"Wednesday" 3)
823 (const :tag
"Thursday" 4)
824 (const :tag
"Friday" 5)
825 (const :tag
"Saturday" 6)
826 (const :tag
"Sunday" 0)))
828 (defcustom org-agenda-include-diary nil
829 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
830 Custom commands can set this variable in the options section."
831 :group
'org-agenda-daily
/weekly
834 (defcustom org-agenda-include-all-todo nil
835 "Set means weekly/daily agenda will always contain all TODO entries.
836 The TODO entries will be listed at the top of the agenda, before
837 the entries for specific days.
838 This option is deprecated, it is better to define a block agenda instead."
839 :group
'org-agenda-daily
/weekly
842 (defcustom org-agenda-repeating-timestamp-show-all t
843 "Non-nil means show all occurrences of a repeating stamp in the agenda.
844 When nil, only one occurrence is shown, either today or the
845 nearest into the future."
846 :group
'org-agenda-daily
/weekly
849 (defcustom org-scheduled-past-days
10000
850 "No. of days to continue listing scheduled items that are not marked DONE.
851 When an item is scheduled on a date, it shows up in the agenda on this
852 day and will be listed until it is marked done for the number of days
854 :group
'org-agenda-daily
/weekly
857 (defcustom org-agenda-log-mode-items
'(closed clock
)
858 "List of items that should be shown in agenda log mode.
859 This list may contain the following symbols:
861 closed Show entries that have been closed on that day.
862 clock Show entries that have received clocked time on that day.
863 state Show all logged state changes.
864 Note that instead of changing this variable, you can also press `C-u l' in
865 the agenda to display all available LOG items temporarily."
866 :group
'org-agenda-daily
/weekly
867 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
869 (defcustom org-agenda-log-mode-add-notes t
870 "Non-nil means add first line of notes to log entries in agenda views.
871 If a log item like a state change or a clock entry is associated with
872 notes, the first line of these notes will be added to the entry in the
874 :group
'org-agenda-daily
/weekly
877 (defcustom org-agenda-start-with-log-mode nil
878 "The initial value of log-mode in a newly created agenda window."
879 :group
'org-agenda-startup
880 :group
'org-agenda-daily
/weekly
883 (defcustom org-agenda-start-with-clockreport-mode nil
884 "The initial value of clockreport-mode in a newly created agenda window."
885 :group
'org-agenda-startup
886 :group
'org-agenda-daily
/weekly
889 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
890 "Property list with parameters for the clocktable in clockreport mode.
891 This is the display mode that shows a clock table in the daily/weekly
892 agenda, the properties for this dynamic block can be set here.
893 The usual clocktable parameters are allowed here, but you cannot set
894 the properties :name, :tstart, :tend, :block, and :scope - these will
895 be overwritten to make sure the content accurately reflects the
896 current display in the agenda."
897 :group
'org-agenda-daily
/weekly
900 (defcustom org-agenda-search-view-always-boolean nil
901 "Non-nil means the search string is interpreted as individual parts.
903 The search string for search view can either be interpreted as a phrase,
904 or as a list of snippets that define a boolean search for a number of
907 When this is non-nil, the string will be split on whitespace, and each
908 snippet will be searched individually, and all must match in order to
909 select an entry. A snippet is then a single string of non-white
910 characters, or a string in double quotes, or a regexp in {} braces.
911 If a snippet is preceeded by \"-\", the snippet must *not* match.
912 \"+\" is syntactic sugar for positive selection. Each snippet may
913 be found as a full word or a partial word, but see the variable
914 `org-agenda-search-view-force-full-words'.
916 When this is nil, search will look for the entire search phrase as one,
917 with each space character matching any amount of whitespace, including
920 Even when this is nil, you can still switch to Boolean search dynamically
921 by preceeding the first snippet with \"+\" or \"-\". If the first snippet
922 is a regexp marked with braces like \"{abc}\", this will also switch to
924 :group
'org-agenda-search-view
927 (if (fboundp 'defvaralias
)
928 (defvaralias 'org-agenda-search-view-search-words-only
929 'org-agenda-search-view-always-boolean
))
931 (defcustom org-agenda-search-view-force-full-words nil
933 ans, search words must be matches as complete words.
934 When nil, they may also match part of a word."
935 :group
'org-agenda-search-view
938 (defgroup org-agenda-time-grid nil
939 "Options concerning the time grid in the Org-mode Agenda."
940 :tag
"Org Agenda Time Grid"
943 (defcustom org-agenda-search-headline-for-time t
944 "Non-nil means search headline for a time-of-day.
945 If the headline contains a time-of-day in one format or another, it will
946 be used to sort the entry into the time sequence of items for a day.
947 Some people have time stamps in the headline that refer to the creation
948 time or so, and then this produces an unwanted side effect. If this is
949 the case for your, use this variable to turn off searching the headline
951 :group
'org-agenda-time-grid
954 (defcustom org-agenda-use-time-grid t
955 "Non-nil means show a time grid in the agenda schedule.
956 A time grid is a set of lines for specific times (like every two hours between
957 8:00 and 20:00). The items scheduled for a day at specific times are
958 sorted in between these lines.
959 For details about when the grid will be shown, and what it will look like, see
960 the variable `org-agenda-time-grid'."
961 :group
'org-agenda-time-grid
964 (defcustom org-agenda-time-grid
965 '((daily today require-timed
)
967 (800 1000 1200 1400 1600 1800 2000))
969 "The settings for time grid for agenda display.
970 This is a list of three items. The first item is again a list. It contains
971 symbols specifying conditions when the grid should be displayed:
973 daily if the agenda shows a single day
974 weekly if the agenda shows an entire week
975 today show grid on current date, independent of daily/weekly display
976 require-timed show grid only if at least one item has a time specification
978 The second item is a string which will be placed behind the grid time.
980 The third item is a list of integers, indicating the times that should have
982 :group
'org-agenda-time-grid
985 (set :greedy t
:tag
"Grid Display Options"
986 (const :tag
"Show grid in single day agenda display" daily
)
987 (const :tag
"Show grid in weekly agenda display" weekly
)
988 (const :tag
"Always show grid for today" today
)
989 (const :tag
"Show grid only if any timed entries are present"
991 (const :tag
"Skip grid times already present in an entry"
993 (string :tag
"Grid String")
994 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
996 (defgroup org-agenda-sorting nil
997 "Options concerning sorting in the Org-mode Agenda."
998 :tag
"Org Agenda Sorting"
1001 (defcustom org-agenda-sorting-strategy
1002 '((agenda habit-down time-up priority-down category-keep
)
1003 (todo priority-down category-keep
)
1004 (tags priority-down category-keep
)
1005 (search category-keep
))
1006 "Sorting structure for the agenda items of a single day.
1007 This is a list of symbols which will be used in sequence to determine
1008 if an entry should be listed before another entry. The following
1009 symbols are recognized:
1011 time-up Put entries with time-of-day indications first, early first
1012 time-down Put entries with time-of-day indications first, late first
1013 category-keep Keep the default order of categories, corresponding to the
1014 sequence in `org-agenda-files'.
1015 category-up Sort alphabetically by category, A-Z.
1016 category-down Sort alphabetically by category, Z-A.
1017 tag-up Sort alphabetically by last tag, A-Z.
1018 tag-down Sort alphabetically by last tag, Z-A.
1019 priority-up Sort numerically by priority, high priority last.
1020 priority-down Sort numerically by priority, high priority first.
1021 todo-state-up Sort by todo state, tasks that are done last.
1022 todo-state-down Sort by todo state, tasks that are done first.
1023 effort-up Sort numerically by estimated effort, high effort last.
1024 effort-down Sort numerically by estimated effort, high effort first.
1025 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1026 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1027 habit-up Put entries that are habits first
1028 habit-down Put entries that are habits last
1030 The different possibilities will be tried in sequence, and testing stops
1031 if one comparison returns a \"not-equal\". For example, the default
1032 '(time-up category-keep priority-down)
1033 means: Pull out all entries having a specified time of day and sort them,
1034 in order to make a time schedule for the current day the first thing in the
1035 agenda listing for the day. Of the entries without a time indication, keep
1036 the grouped in categories, don't sort the categories, but keep them in
1037 the sequence given in `org-agenda-files'. Within each category sort by
1040 Leaving out `category-keep' would mean that items will be sorted across
1041 categories by priority.
1043 Instead of a single list, this can also be a set of list for specific
1044 contents, with a context symbol in the car of the list, any of
1045 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1047 Custom commands can bind this variable in the options section."
1048 :group
'org-agenda-sorting
1050 (repeat :tag
"General" ,org-sorting-choice
)
1051 (list :tag
"Individually"
1052 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1053 (repeat ,org-sorting-choice
))
1054 (cons (const :tag
"Strategy for TODO lists" todo
)
1055 (repeat ,org-sorting-choice
))
1056 (cons (const :tag
"Strategy for Tags matches" tags
)
1057 (repeat ,org-sorting-choice
))
1058 (cons (const :tag
"Strategy for search matches" search
)
1059 (repeat ,org-sorting-choice
)))))
1061 (defcustom org-agenda-cmp-user-defined nil
1062 "A function to define the comparison `user-defined'.
1063 This function must receive two arguments, agenda entry a and b.
1064 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1065 the user comparison, return nil.
1066 When this is defined, you can make `user-defined-up' and `user-defined-down'
1067 part of an agenda sorting strategy."
1068 :group
'org-agenda-sorting
1071 (defcustom org-sort-agenda-notime-is-late t
1072 "Non-nil means items without time are considered late.
1073 This is only relevant for sorting. When t, items which have no explicit
1074 time like 15:30 will be considered as 99:01, i.e. later than any items which
1075 do have a time. When nil, the default time is before 0:00. You can use this
1076 option to decide if the schedule for today should come before or after timeless
1078 :group
'org-agenda-sorting
1081 (defcustom org-sort-agenda-noeffort-is-high t
1082 "Non-nil means items without effort estimate are sorted as high effort.
1083 This also applies when filtering an agenda view with respect to the
1084 < or > effort operator. Then, tasks with no effort defined will be treated
1085 as tasks with high effort.
1086 When nil, such items are sorted as 0 minutes effort."
1087 :group
'org-agenda-sorting
1090 (defgroup org-agenda-line-format nil
1091 "Options concerning the entry prefix in the Org-mode agenda display."
1092 :tag
"Org Agenda Line Format"
1095 (defcustom org-agenda-prefix-format
1096 '((agenda .
" %-12:c%?-12t% s")
1100 (search .
" %-12:c"))
1101 "Format specifications for the prefix of items in the agenda views.
1102 An alist with four entries, for the different agenda types. The keys to the
1103 sublists are `agenda', `timeline', `todo', and `tags'. The values
1105 This format works similar to a printf format, with the following meaning:
1107 %c the category of the item, \"Diary\" for entries from the diary, or
1108 as given by the CATEGORY keyword or derived from the file name.
1109 %T the *last* tag of the item. Last because inherited tags come
1111 %t the time-of-day specification if one applies to the entry, in the
1113 %s Scheduling/Deadline information, a short string
1115 All specifiers work basically like the standard `%s' of printf, but may
1116 contain two additional characters: A question mark just after the `%' and
1117 a whitespace/punctuation character just before the final letter.
1119 If the first character after `%' is a question mark, the entire field
1120 will only be included if the corresponding value applies to the
1121 current entry. This is useful for fields which should have fixed
1122 width when present, but zero width when absent. For example,
1123 \"%?-12t\" will result in a 12 character time field if a time of the
1124 day is specified, but will completely disappear in entries which do
1127 If there is punctuation or whitespace character just before the final
1128 format letter, this character will be appended to the field value if
1129 the value is not empty. For example, the format \"%-12:c\" leads to
1130 \"Diary: \" if the category is \"Diary\". If the category were be
1131 empty, no additional colon would be inserted.
1133 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1134 - Indent the line with two space characters
1135 - Give the category in a 12 chars wide field, padded with whitespace on
1136 the right (because of `-'). Append a colon if there is a category
1138 - If there is a time-of-day, put it into a 12 chars wide field. If no
1139 time, don't put in an empty field, just skip it (because of '?').
1140 - Finally, put the scheduling information and append a whitespace.
1142 As another example, if you don't want the time-of-day of entries in
1143 the prefix, you could use:
1145 (setq org-agenda-prefix-format \" %-11:c% s\")
1147 See also the variables `org-agenda-remove-times-when-in-prefix' and
1148 `org-agenda-remove-tags'.
1150 Custom commands can set this variable in the options section."
1152 (string :tag
"General format")
1153 (list :greedy t
:tag
"View dependent"
1154 (cons (const agenda
) (string :tag
"Format"))
1155 (cons (const timeline
) (string :tag
"Format"))
1156 (cons (const todo
) (string :tag
"Format"))
1157 (cons (const tags
) (string :tag
"Format"))
1158 (cons (const search
) (string :tag
"Format"))))
1159 :group
'org-agenda-line-format
)
1161 (defvar org-prefix-format-compiled nil
1162 "The compiled version of the most recently used prefix format.
1163 See the variable `org-agenda-prefix-format'.")
1165 (defcustom org-agenda-todo-keyword-format
"%-1s"
1166 "Format for the TODO keyword in agenda lines.
1167 Set this to something like \"%-12s\" if you want all TODO keywords
1168 to occupy a fixed space in the agenda display."
1169 :group
'org-agenda-line-format
1172 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1173 "Text preceding timerange entries in the agenda view.
1174 This is a list with two strings. The first applies when the range
1175 is entirely on one day. The second applies if the range spans several days.
1176 The strings may have two \"%d\" format specifiers which will be filled
1177 with the sequence number of the days, and the total number of days in the
1178 range, respectively."
1179 :group
'org-agenda-line-format
1181 (string :tag
"Deadline today ")
1182 (choice :tag
"Deadline relative"
1183 (string :tag
"Format string")
1186 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1187 "Text preceeding scheduled items in the agenda view.
1188 This is a list with two strings. The first applies when the item is
1189 scheduled on the current day. The second applies when it has been scheduled
1190 previously, it may contain a %d indicating that this is the nth time that
1191 this item is scheduled, due to automatic rescheduling of unfinished items
1192 for the following day. So this number is one larger than the number of days
1193 that passed since this item was scheduled first."
1194 :group
'org-agenda-line-format
1196 (string :tag
"Scheduled today ")
1197 (string :tag
"Scheduled previously")))
1199 (defcustom org-agenda-inactive-leader
"["
1200 "Text preceeding item pulled into the agenda by inactive time stamps.
1201 These entries are added to the agenda when pressing \"[\"."
1202 :group
'org-agenda-line-format
1204 (string :tag
"Scheduled today ")
1205 (string :tag
"Scheduled previously")))
1207 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1208 "Text preceeding deadline items in the agenda view.
1209 This is a list with two strings. The first applies when the item has its
1210 deadline on the current day. The second applies when it is in the past or
1211 in the future, it may contain %d to capture how many days away the deadline
1213 :group
'org-agenda-line-format
1215 (string :tag
"Deadline today ")
1216 (choice :tag
"Deadline relative"
1217 (string :tag
"Format string")
1220 (defcustom org-agenda-remove-times-when-in-prefix t
1221 "Non-nil means remove duplicate time specifications in agenda items.
1222 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1223 time-of-day specification in a headline or diary entry is extracted and
1224 placed into the prefix. If this option is non-nil, the original specification
1225 \(a timestamp or -range, or just a plain time(range) specification like
1226 11:30-4pm) will be removed for agenda display. This makes the agenda less
1228 The option can be t or nil. It may also be the symbol `beg', indicating
1229 that the time should only be removed what it is located at the beginning of
1230 the headline/diary entry."
1231 :group
'org-agenda-line-format
1233 (const :tag
"Always" t
)
1234 (const :tag
"Never" nil
)
1235 (const :tag
"When at beginning of entry" beg
)))
1238 (defcustom org-agenda-default-appointment-duration nil
1239 "Default duration for appointments that only have a starting time.
1240 When nil, no duration is specified in such cases.
1241 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1242 :group
'org-agenda-line-format
1244 (integer :tag
"Minutes")
1245 (const :tag
"No default duration")))
1247 (defcustom org-agenda-show-inherited-tags t
1248 "Non-nil means show inherited tags in each agenda line."
1249 :group
'org-agenda-line-format
1252 (defcustom org-agenda-hide-tags-regexp nil
1253 "Regular expression used to filter away specific tags in agenda views.
1254 This means that these tags will be present, but not be shown in the agenda
1255 line. Secondayt filltering will still work on the hidden tags.
1256 Nil means don't hide any tags."
1257 :group
'org-agenda-line-format
1259 (const :tag
"Hide none" nil
)
1260 (string :tag
"Regexp ")))
1262 (defcustom org-agenda-remove-tags nil
1263 "Non-nil means remove the tags from the headline copy in the agenda.
1264 When this is the symbol `prefix', only remove tags when
1265 `org-agenda-prefix-format' contains a `%T' specifier."
1266 :group
'org-agenda-line-format
1268 (const :tag
"Always" t
)
1269 (const :tag
"Never" nil
)
1270 (const :tag
"When prefix format contains %T" prefix
)))
1272 (if (fboundp 'defvaralias
)
1273 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1274 'org-agenda-remove-tags
))
1276 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1277 "Shift tags in agenda items to this column.
1278 If this number is positive, it specifies the column. If it is negative,
1279 it means that the tags should be flushright to that column. For example,
1280 -80 works well for a normal 80 character screen."
1281 :group
'org-agenda-line-format
1284 (if (fboundp 'defvaralias
)
1285 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1287 (defcustom org-agenda-fontify-priorities
'cookies
1288 "Non-nil means highlight low and high priorities in agenda.
1289 When t, the highest priority entries are bold, lowest priority italic.
1290 However, settings in org-priority-faces will overrule these faces.
1291 When this variable is the symbol `cookies', only fontify the
1292 cookies, not the entire task.
1293 This may also be an association list of priority faces, whose
1294 keys are the character values of `org-highest-priority',
1295 `org-default-priority', and `org-lowest-priority' (the default values
1296 are ?A, ?B, and ?C, respectively). The face may be a named face,
1297 or a list like `(:background \"Red\")'."
1298 :group
'org-agenda-line-format
1300 (const :tag
"Never" nil
)
1301 (const :tag
"Defaults" t
)
1302 (const :tag
"Cookies only" cookies
)
1303 (repeat :tag
"Specify"
1304 (list (character :tag
"Priority" :value ?A
)
1305 (sexp :tag
"face")))))
1307 (defgroup org-agenda-column-view nil
1308 "Options concerning column view in the agenda."
1309 :tag
"Org Agenda Column View"
1312 (defcustom org-agenda-columns-show-summaries t
1313 "Non-nil means show summaries for columns displayed in the agenda view."
1314 :group
'org-agenda-column-view
1317 (defcustom org-agenda-columns-remove-prefix-from-item t
1318 "Non-nil means remove the prefix from a headline for agenda column view.
1319 The special ITEM field in the columns format contains the current line, with
1320 all information shown in other columns (like the TODO state or a tag).
1321 When this variable is non-nil, also the agenda prefix will be removed from
1322 the content of the ITEM field, to make sure as much as possible of the
1323 headline can be shown in the limited width of the field."
1327 (defcustom org-agenda-columns-compute-summary-properties t
1328 "Non-nil means recompute all summary properties before column view.
1329 When column view in the agenda is listing properties that have a summary
1330 operator, it can go to all relevant buffers and recompute the summaries
1331 there. This can mean overhead for the agenda column view, but is necessary
1332 to have thing up to date.
1333 As a special case, a CLOCKSUM property also makes sure that the clock
1334 computations are current."
1335 :group
'org-agenda-column-view
1338 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1339 "Non-nil means the duration of an appointment will add to day effort.
1340 The property to which appointment durations will be added is the one given
1341 in the option `org-effort-property'. If an appointment does not have
1342 an end time, `org-agenda-default-appointment-duration' will be used. If that
1343 is not set, an appointment without end time will not contribute to the time
1345 :group
'org-agenda-column-view
1348 (defcustom org-agenda-auto-exclude-function nil
1349 "A function called with a tag to decide if it is filtered on '/ RET'.
1350 The sole argument to the function, which is called once for each
1351 possible tag, is a string giving the name of the tag. The
1352 function should return either nil if the tag should be included
1353 as normal, or \"-<TAG>\" to exclude the tag.
1354 Note that for the purpose of tag filtering, only the lower-case version of
1355 all tags will be considered, so that this function will only ever see
1356 the lower-case version of all tags."
1364 (defun org-add-agenda-custom-command (entry)
1365 "Replace or add a command in `org-agenda-custom-commands'.
1366 This is mostly for hacking and trying a new command - once the command
1367 works you probably want to add it to `org-agenda-custom-commands' for good."
1368 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1370 (setcdr ass
(cdr entry
))
1371 (push entry org-agenda-custom-commands
))))
1373 ;;; Define the Org-agenda-mode
1375 (defvar org-agenda-mode-map
(make-sparse-keymap)
1376 "Keymap for `org-agenda-mode'.")
1377 (if (fboundp 'defvaralias
)
1378 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1380 (defvar org-agenda-menu
) ; defined later in this file.
1381 (defvar org-agenda-restrict
) ; defined later in this file.
1382 (defvar org-agenda-follow-mode nil
)
1383 (defvar org-agenda-entry-text-mode nil
)
1384 (defvar org-agenda-clockreport-mode nil
)
1385 (defvar org-agenda-show-log nil
)
1386 (defvar org-agenda-redo-command nil
)
1387 (defvar org-agenda-query-string nil
)
1388 (defvar org-agenda-mode-hook nil
1389 "Hook for org-agenda-mode, run after the mode is turned on.")
1390 (defvar org-agenda-type nil
)
1391 (defvar org-agenda-force-single-file nil
)
1392 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1394 (defun org-agenda-mode ()
1395 "Mode for time-sorted view on action items in Org-mode files.
1397 The following commands are available:
1399 \\{org-agenda-mode-map}"
1401 (kill-all-local-variables)
1402 (setq org-agenda-undo-list nil
1403 org-agenda-pending-undo-list nil
1404 org-agenda-bulk-marked-entries nil
)
1405 (setq major-mode
'org-agenda-mode
)
1406 ;; Keep global-font-lock-mode from turning on font-lock-mode
1407 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1408 (setq mode-name
"Org-Agenda")
1409 (use-local-map org-agenda-mode-map
)
1410 (easy-menu-add org-agenda-menu
)
1411 (if org-startup-truncated
(setq truncate-lines t
))
1412 (org-set-local 'line-move-visual nil
)
1413 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1414 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1415 ;; Make sure properties are removed when copying text
1416 (when (boundp 'buffer-substring-filters
)
1417 (org-set-local 'buffer-substring-filters
1419 (set-text-properties 0 (length x
) nil x
) x
)
1420 buffer-substring-filters
)))
1421 (unless org-agenda-keep-modes
1422 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1423 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1424 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1425 org-agenda-show-log org-agenda-start-with-log-mode
))
1428 '("Agenda") "Agenda Files"
1432 (if (get 'org-agenda-files
'org-restrict
)
1433 "Restricted to single file"
1435 '(org-edit-agenda-file-list)
1436 (not (get 'org-agenda-files
'org-restrict
)))
1438 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1439 (org-agenda-set-mode-name)
1441 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1442 (list 'org-agenda-mode-hook
)))
1444 (substitute-key-definition 'undo
'org-agenda-undo
1445 org-agenda-mode-map global-map
)
1446 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1447 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1448 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1449 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1450 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1451 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1452 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1453 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1454 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1455 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1456 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
1457 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
1458 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
1459 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1460 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1461 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1462 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1463 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
1464 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
1465 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1466 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1467 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1468 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1469 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1470 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1471 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1472 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1473 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1474 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1475 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1476 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1477 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1478 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1479 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1480 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1481 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1482 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1483 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1484 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1485 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1486 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1487 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1488 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1490 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1491 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1492 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1493 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1494 (while l (org-defkey org-agenda-mode-map
1495 (int-to-string (pop l)) 'digit-argument)))
1497 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1498 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1499 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1500 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1501 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1502 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1503 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1504 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1505 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1506 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1507 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1508 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1509 'org-clock-modify-effort-estimate)
1510 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1511 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1512 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1513 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1514 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1515 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1516 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1517 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1518 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1519 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1520 (substitute-key-definition 'next-line 'org-agenda-next-line
1521 org-agenda-mode-map global-map)
1522 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1523 org-agenda-mode-map global-map)
1524 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1525 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1526 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1527 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1528 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1529 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1530 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1531 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1532 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1533 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1534 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1535 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1536 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1537 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1538 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1539 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1540 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1541 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1542 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1543 (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
1544 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1545 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1546 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1547 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1548 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1549 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1550 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1551 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1552 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1553 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1555 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1556 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1557 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1558 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1559 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1560 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1561 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1562 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1563 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1564 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1566 (org-defkey org-agenda-mode-map
1567 (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
1568 (org-defkey org-agenda-mode-map
1569 (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
1570 (when org-agenda-mouse-1-follows-link
1571 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1572 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1577 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1578 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1579 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1580 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1583 ["Day View" org-agenda-day-view
1584 :active (org-agenda-check-type nil 'agenda)
1585 :style radio :selected (equal org-agenda-ndays 1)
1586 :keys "v d (or just d)"]
1587 ["Week View" org-agenda-week-view
1588 :active (org-agenda-check-type nil 'agenda)
1589 :style radio :selected (equal org-agenda-ndays 7)
1590 :keys "v w (or just w)"]
1591 ["Month View" org-agenda-month-view
1592 :active (org-agenda-check-type nil 'agenda)
1593 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1595 ["Year View" org-agenda-year-view
1596 :active (org-agenda-check-type nil 'agenda)
1597 :style radio :selected (member org-agenda-ndays '(365 366))
1600 ["Include Diary" org-agenda-toggle-diary
1601 :style toggle :selected org-agenda-include-diary
1602 :active (org-agenda-check-type nil 'agenda)]
1603 ["Use Time Grid" org-agenda-toggle-time-grid
1604 :style toggle :selected org-agenda-use-time-grid
1605 :active (org-agenda-check-type nil 'agenda)]
1607 ["Show clock report" org-agenda-clockreport-mode
1608 :style toggle :selected org-agenda-clockreport-mode
1609 :active (org-agenda-check-type nil 'agenda)]
1610 ["Show some entry text" org-agenda-entry-text-mode
1611 :style toggle :selected org-agenda-entry-text-mode
1614 ["Show Logbook entries" org-agenda-log-mode
1615 :style toggle :selected org-agenda-show-log
1616 :active (org-agenda-check-type nil 'agenda 'timeline)
1617 :keys "v l (or just l)"]
1618 ["Include archived trees" org-agenda-archives-mode
1619 :style toggle :selected org-agenda-archives-mode :active t
1621 ["Include archive files" (org-agenda-archives-mode t)
1622 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1625 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1626 ["Write view to file" org-write-agenda t]
1627 ["Rebuild buffer" org-agenda-redo t]
1628 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1630 ["Show original entry" org-agenda-show t]
1631 ["Go To (other window)" org-agenda-goto t]
1632 ["Go To (this window)" org-agenda-switch-to t]
1633 ["Follow Mode" org-agenda-follow-mode
1634 :style toggle :selected org-agenda-follow-mode :active t]
1635 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1638 ["Cycle TODO" org-agenda-todo t]
1639 ["Next TODO set" org-agenda-todo-nextset t]
1640 ["Previous TODO set" org-agenda-todo-previousset t]
1641 ["Add note" org-agenda-add-note t])
1642 ("Archive/Refile/Delete"
1643 ["Archive default" org-agenda-archive-default t]
1644 ["Archive default" org-agenda-archive-default-with-confirmation t]
1645 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1646 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1647 ["Archive subtree" org-agenda-archive t]
1649 ["Refile" org-agenda-refile t]
1651 ["Delete subtree" org-agenda-kill t])
1653 ["Mark entry" org-agenda-bulk-mark t]
1654 ["Unmark entry" org-agenda-bulk-unmark t]
1655 ["Act on all marked" org-agenda-bulk-action t]
1656 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1658 ("Tags and Properties"
1659 ["Show all Tags" org-agenda-show-tags t]
1660 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1661 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1663 ["Column View" org-columns t])
1664 ("Deadline/Schedule"
1665 ["Schedule" org-agenda-schedule t]
1666 ["Set Deadline" org-agenda-deadline t]
1668 ["Mark item" org-agenda-action :active t :keys "k m"]
1669 ["Show mark item" org-agenda-action :active t :keys "k v"]
1670 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1671 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1673 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1674 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1675 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1676 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1677 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1678 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1679 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1681 ["Clock in" org-agenda-clock-in t]
1682 ["Clock out" org-agenda-clock-out t]
1683 ["Clock cancel" org-agenda-clock-cancel t]
1684 ["Goto running clock" org-clock-goto t]
1686 ["Set Effort" org-agenda-set-effort t]
1687 ["Change clocked effort" org-clock-modify-effort-estimate
1688 (org-clock-is-active)])
1690 ["Set Priority" org-agenda-priority t]
1691 ["Increase Priority" org-agenda-priority-up t]
1692 ["Decrease Priority" org-agenda-priority-down t]
1693 ["Show Priority" org-agenda-show-priority t])
1695 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1696 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1697 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1698 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1699 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1700 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1702 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1704 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1707 ["Push Files and Views" org-mobile-push t]
1708 ["Get Captured and Flagged" org-mobile-pull t]
1709 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1710 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1712 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1714 ["Quit" org-agenda-quit t]
1715 ["Exit and Release Buffers" org-agenda-exit t]
1720 (defvar org-agenda-allow-remote-undo t
1721 "Non-nil means allow remote undo from the agenda buffer.")
1722 (defvar org-agenda-undo-list nil
1723 "List of undoable operations in the agenda since last refresh.")
1724 (defvar org-agenda-undo-has-started-in nil
1725 "Buffers that have already seen `undo-start' in the current undo sequence.")
1726 (defvar org-agenda-pending-undo-list nil
1727 "In a series of undo commands, this is the list of remaining undo items.")
1730 (defun org-agenda-undo ()
1731 "Undo a remote editing step in the agenda.
1732 This undoes changes both in the agenda buffer and in the remote buffer
1733 that have been changed along."
1735 (or org-agenda-allow-remote-undo
1736 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1737 (if (not (eq this-command last-command))
1738 (setq org-agenda-undo-has-started-in nil
1739 org-agenda-pending-undo-list org-agenda-undo-list))
1740 (if (not org-agenda-pending-undo-list)
1741 (error "No further undo information"))
1742 (let* ((entry (pop org-agenda-pending-undo-list))
1743 buf line cmd rembuf)
1744 (setq cmd (pop entry) line (pop entry))
1745 (setq rembuf (nth 2 entry))
1746 (org-with-remote-undo rembuf
1747 (while (bufferp (setq buf (pop entry)))
1749 (with-current-buffer buf
1750 (let ((last-undo-buffer buf)
1751 (inhibit-read-only t))
1752 (unless (memq buf org-agenda-undo-has-started-in)
1753 (push buf org-agenda-undo-has-started-in)
1754 (make-local-variable 'pending-undo-list)
1756 (while (and pending-undo-list
1757 (listp pending-undo-list)
1758 (not (car pending-undo-list)))
1759 (pop pending-undo-list))
1761 (org-goto-line line)
1762 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1764 (defun org-verify-change-for-undo (l1 l2)
1765 "Verify that a real change occurred between the undo lists L1 and L2."
1766 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1767 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1772 (defvar org-agenda-restrict nil)
1773 (defvar org-agenda-restrict-begin (make-marker))
1774 (defvar org-agenda-restrict-end (make-marker))
1775 (defvar org-agenda-last-dispatch-buffer nil)
1776 (defvar org-agenda-overriding-restriction nil)
1779 (defun org-agenda (&optional arg keys restriction)
1780 "Dispatch agenda commands to collect entries to the agenda buffer.
1781 Prompts for a command to execute. Any prefix arg will be passed
1782 on to the selected command. The default selections are:
1784 a Call `org-agenda-list' to display the agenda for current day or week.
1785 t Call `org-todo-list' to display the global todo list.
1786 T Call `org-todo-list' to display the global todo list, select only
1787 entries with a specific TODO keyword (the user gets a prompt).
1788 m Call `org-tags-view' to display headlines with tags matching
1789 a condition (the user is prompted for the condition).
1790 M Like `m', but select only TODO entries, no ordinary headlines.
1791 L Create a timeline for the current buffer.
1792 e Export views to associated files.
1793 s Search entries for keywords.
1794 / Multi occur across all agenda files and also files listed
1795 in `org-agenda-text-search-extra-files'.
1796 < Restrict agenda commands to buffer, subtree, or region.
1797 Press several times to get the desired effect.
1798 > Remove a previous restriction.
1799 # List \"stuck\" projects.
1800 ! Configure what \"stuck\" means.
1801 C Configure custom agenda commands.
1803 More commands can be added by configuring the variable
1804 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1805 searches can be pre-defined in this way.
1807 If the current buffer is in Org-mode and visiting a file, you can also
1808 first press `<' once to indicate that the agenda should be temporarily
1809 \(until the next use of \\[org-agenda]) restricted to the current file.
1810 Pressing `<' twice means to restrict to the current subtree or region
1814 (let* ((prefix-descriptions nil)
1815 (org-agenda-window-setup (if (equal (buffer-name)
1816 org-agenda-buffer-name)
1818 org-agenda-window-setup))
1819 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1820 (org-agenda-custom-commands
1821 ;; normalize different versions
1825 (cond ((stringp (cdr x))
1826 (push x prefix-descriptions)
1828 ((stringp (nth 1 x)) x)
1829 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1830 (t (cons (car x) (cons "" (cdr x))))))
1831 org-agenda-custom-commands)))
1832 (buf (current-buffer))
1833 (bfn (buffer-file-name (buffer-base-buffer)))
1834 entry key type match lprops ans)
1835 ;; Turn off restriction unless there is an overriding one,
1836 (unless org-agenda-overriding-restriction
1837 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
1838 ;; There is a request to keep the file list in place
1839 (put 'org-agenda-files 'org-restrict nil))
1840 (setq org-agenda-restrict nil)
1841 (move-marker org-agenda-restrict-begin nil)
1842 (move-marker org-agenda-restrict-end nil))
1843 ;; Delete old local properties
1844 (put 'org-agenda-redo-command 'org-lprops nil)
1845 ;; Remember where this call originated
1846 (setq org-agenda-last-dispatch-buffer (current-buffer))
1848 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1850 restriction (cdr ans)))
1851 ;; Establish the restriction, if any
1852 (when (and (not org-agenda-overriding-restriction) restriction)
1853 (put 'org-agenda-files 'org-restrict (list bfn))
1855 ((eq restriction 'region)
1856 (setq org-agenda-restrict t)
1857 (move-marker org-agenda-restrict-begin (region-beginning))
1858 (move-marker org-agenda-restrict-end (region-end)))
1859 ((eq restriction 'subtree)
1861 (setq org-agenda-restrict t)
1862 (org-back-to-heading t)
1863 (move-marker org-agenda-restrict-begin (point))
1864 (move-marker org-agenda-restrict-end
1865 (progn (org-end-of-subtree t)))))))
1867 (require 'calendar) ; FIXME: can we avoid this for some commands?
1868 ;; For example the todo list should not need it (but does...)
1870 ((setq entry (assoc keys org-agenda-custom-commands))
1871 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
1873 (setq type (nth 2 entry) match (eval (nth 3 entry))
1874 lprops (nth 4 entry))
1875 (put 'org-agenda-redo-command 'org-lprops lprops)
1878 (org-let lprops '(org-agenda-list current-prefix-arg)))
1880 (org-let lprops '(org-todo-list current-prefix-arg)))
1882 (org-let lprops '(org-search-view current-prefix-arg match nil)))
1884 (org-let lprops '(org-agenda-list-stuck-projects
1885 current-prefix-arg)))
1887 (org-let lprops '(org-tags-view current-prefix-arg match)))
1888 ((eq type 'tags-todo)
1889 (org-let lprops '(org-tags-view '(4) match)))
1891 (org-let lprops '(org-todo-list match)))
1892 ((eq type 'tags-tree)
1893 (org-check-for-org-mode)
1894 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
1895 ((eq type 'todo-tree)
1896 (org-check-for-org-mode)
1898 '(org-occur (concat "^" outline-regexp "[ \t]*"
1899 (regexp-quote match) "\\>"))))
1900 ((eq type 'occur-tree)
1901 (org-check-for-org-mode)
1902 (org-let lprops '(org-occur match)))
1904 (org-let lprops '(funcall type match)))
1906 (org-let lprops '(funcall type match)))
1907 (t (error "Invalid custom agenda command type %s" type))))
1908 (org-run-agenda-series (nth 1 entry) (cddr entry))))
1910 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
1911 (customize-variable 'org-agenda-custom-commands))
1912 ((equal keys "a") (call-interactively 'org-agenda-list))
1913 ((equal keys "s") (call-interactively 'org-search-view))
1914 ((equal keys "t") (call-interactively 'org-todo-list))
1915 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
1916 ((equal keys "m") (call-interactively 'org-tags-view))
1917 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
1918 ((equal keys "e") (call-interactively 'org-store-agenda-views))
1919 ((equal keys "?") (org-tags-view nil "+FLAGGED")
1923 (unless (current-message)
1924 (let* ((m (org-agenda-get-any-marker))
1925 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
1928 "FLAGGING-NOTE ([?] for more info): "
1930 (replace-regexp-in-string
1932 (copy-sequence note))
1933 nil 'face 'org-warning)))))))
1936 (unless (org-mode-p)
1937 (error "This is not an Org-mode file"))
1939 (put 'org-agenda-files 'org-restrict (list bfn))
1940 (org-call-with-arg 'org-timeline arg)))
1941 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
1942 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
1943 ((equal keys "!") (customize-variable 'org-stuck-projects))
1944 (t (error "Invalid agenda key"))))))
1946 (defun org-agenda-normalize-custom-commands (cmds)
1950 (cond ((stringp (cdr x)) nil)
1951 ((stringp (nth 1 x)) x)
1952 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1953 (t (cons (car x) (cons "" (cdr x))))))
1956 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1957 "The user interface for selecting an agenda command."
1959 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1960 (restrict-ok (and bfn (org-mode-p)))
1961 (region-p (org-region-active-p))
1962 (custom org-agenda-custom-commands)
1964 restriction second-time
1965 c entry key type match prefixes rmheader header-end custom1 desc)
1966 (save-window-excursion
1967 (delete-other-windows)
1968 (org-switch-to-buffer-other-window " *Agenda Commands*")
1970 (insert (eval-when-compile
1973 Press key for an agenda command: < Buffer, subtree/region restriction
1974 -------------------------------- > Remove restriction
1975 a Agenda for current week or day e Export agenda views
1976 t List of all TODO entries T Entries with special TODO kwd
1977 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1978 L Timeline for current buffer # List stuck projects (!=configure)
1979 s Search for keywords C Configure custom agenda commands
1980 / Multi-occur ? Find :FLAGGED: entries
1983 (while (string-match
1984 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1986 (setq start (match-end 0))
1987 (add-text-properties (match-beginning 2) (match-end 2)
1988 '(face bold) header))
1990 (setq header-end (move-marker (make-marker) (point)))
1992 (setq custom1 custom)
1993 (when (eq rmheader t)
1995 (re-search-forward ":" nil t)
1996 (delete-region (match-end 0) (point-at-eol))
1999 (delete-region (match-end 0) (point-at-eol))
2000 (move-marker header-end (match-end 0)))
2001 (goto-char header-end)
2002 (delete-region (point) (point-max))
2003 (while (setq entry (pop custom1))
2004 (setq key (car entry) desc (nth 1 entry)
2006 match (nth 3 entry))
2007 (if (> (length key) 1)
2008 (add-to-list 'prefixes (string-to-char key))
2012 (org-add-props (copy-sequence key)
2015 ((string-match "\\S-" desc) desc)
2016 ((eq type 'agenda) "Agenda for current week or day")
2017 ((eq type 'alltodo) "List of all TODO entries")
2018 ((eq type 'search) "Word search")
2019 ((eq type 'stuck) "List of stuck projects")
2020 ((eq type 'todo) "TODO keyword")
2021 ((eq type 'tags) "Tags query")
2022 ((eq type 'tags-todo) "Tags (TODO)")
2023 ((eq type 'tags-tree) "Tags tree")
2024 ((eq type 'todo-tree) "TODO kwd tree")
2025 ((eq type 'occur-tree) "Occur tree")
2026 ((functionp type) (if (symbolp type)
2028 "Lambda expression"))
2032 (setq match (copy-sequence match))
2033 (org-add-props match nil 'face 'org-warning))
2035 (format "set of %d commands" (length match)))
2041 (org-add-props (char-to-string x)
2043 (or (cdr (assoc (concat selstring (char-to-string x))
2044 prefix-descriptions))
2047 (goto-char (point-min))
2049 (if (not (pos-visible-in-window-p (point-max)))
2050 (org-fit-window-to-buffer))
2051 (setq second-time t)
2052 (org-fit-window-to-buffer))
2053 (message "Press key for agenda command%s:"
2054 (if (or restrict-ok org-agenda-overriding-restriction)
2055 (if org-agenda-overriding-restriction
2056 " (restriction lock active)"
2058 (format " (restricted to %s)" restriction)
2061 (setq c (read-char-exclusive))
2064 ((assoc (char-to-string c) custom)
2065 (setq selstring (concat selstring (char-to-string c)))
2066 (throw 'exit (cons selstring restriction)))
2068 (setq selstring (concat selstring (char-to-string c))
2070 rmheader (or rmheader t)
2071 custom (delq nil (mapcar
2073 (if (or (= (length (car x)) 1)
2074 (/= (string-to-char (car x)) c))
2076 (cons (substring (car x) 1) (cdr x))))
2078 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2079 (message "Restriction is only possible in Org-mode buffers")
2082 (org-agenda-remove-restriction-lock 'noupdate)
2083 (setq restriction 'buffer))
2085 (org-agenda-remove-restriction-lock 'noupdate)
2086 (setq restriction (if region-p 'region 'subtree)))
2088 (org-agenda-remove-restriction-lock 'noupdate)
2091 ((eq restriction 'buffer)
2092 (if region-p 'region 'subtree))
2093 ((memq restriction '(subtree region))
2097 (org-agenda-remove-restriction-lock 'noupdate)
2098 (setq restriction nil))
2099 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2100 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2101 ((and (> (length selstring) 0) (eq c ?\d))
2103 (org-agenda-get-restriction-and-command prefix-descriptions))
2105 ((equal c ?q) (error "Abort"))
2106 (t (error "Invalid key %c" c))))))))
2108 (defun org-run-agenda-series (name series)
2109 (org-let (nth 1 series) '(org-prepare-agenda name))
2110 (let* ((org-agenda-multi t)
2111 (redo (list 'org-run-agenda-series name (list 'quote series)))
2113 (gprops (nth 1 series))
2114 match ;; The byte compiler incorrectly complains about this. Keep it!
2116 (while (setq cmd (pop cmds))
2117 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2120 (org-let2 gprops lprops
2121 '(call-interactively 'org-agenda-list)))
2123 (org-let2 gprops lprops
2124 '(call-interactively 'org-todo-list)))
2126 (org-let2 gprops lprops
2127 '(org-search-view current-prefix-arg match nil)))
2129 (org-let2 gprops lprops
2130 '(call-interactively 'org-agenda-list-stuck-projects)))
2132 (org-let2 gprops lprops
2133 '(org-tags-view current-prefix-arg match)))
2134 ((eq type 'tags-todo)
2135 (org-let2 gprops lprops
2136 '(org-tags-view '(4) match)))
2138 (org-let2 gprops lprops
2139 '(org-todo-list match)))
2141 (org-let2 gprops lprops
2142 '(funcall type match)))
2143 (t (error "Invalid type in command series"))))
2145 (setq org-agenda-redo-command redo)
2146 (goto-char (point-min)))
2147 (org-fit-agenda-window)
2148 (org-let (nth 1 series) '(org-finalize-agenda)))
2151 (defmacro org-batch-agenda (cmd-key &rest parameters)
2152 "Run an agenda command in batch mode and send the result to STDOUT.
2153 If CMD-KEY is a string of length 1, it is used as a key in
2154 `org-agenda-custom-commands' and triggers this command. If it is a
2155 longer string it is used as a tags/todo match string.
2156 Paramters are alternating variable names and values that will be bound
2157 before running the agenda command."
2160 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2161 (if (> (length cmd-key) 2)
2162 (eval (list 'let (nreverse pars)
2163 (list 'org-tags-view nil cmd-key)))
2164 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2165 (set-buffer org-agenda-buffer-name)
2166 (princ (org-encode-for-stdout (buffer-string)))))
2168 ;(defun org-encode-for-stdout (string)
2169 ; (if (fboundp 'encode-coding-string)
2170 ; (encode-coding-string string buffer-file-coding-system)
2173 (defun org-encode-for-stdout (string)
2176 (defvar org-agenda-info nil)
2179 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2180 "Run an agenda command in batch mode and send the result to STDOUT.
2181 If CMD-KEY is a string of length 1, it is used as a key in
2182 `org-agenda-custom-commands' and triggers this command. If it is a
2183 longer string it is used as a tags/todo match string.
2184 Paramters are alternating variable names and values that will be bound
2185 before running the agenda command.
2187 The output gives a line for each selected agenda item. Each
2188 item is a list of comma-separated values, like this:
2190 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2192 category The category of the item
2193 head The headline, without TODO kwd, TAGS and PRIORITY
2194 type The type of the agenda entry, can be
2195 todo selected in TODO match
2196 tagsmatch selected in tags match
2197 diary imported from diary
2198 deadline a deadline on given date
2199 scheduled scheduled on given date
2200 timestamp entry has timestamp on given date
2201 closed entry was closed on given date
2202 upcoming-deadline warning about deadline
2203 past-scheduled forwarded scheduled item
2204 block entry has date block including g. date
2205 todo The todo keyword, if any
2206 tags All tags including inherited ones, separated by colons
2207 date The relevant date, like 2007-2-14
2208 time The time, like 15:00-16:50
2209 extra Sting with extra planning info
2210 priority-l The priority letter if any was given
2211 priority-n The computed numerical priority
2212 agenda-day The day in the agenda where this is listed"
2216 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2217 (push (list 'org-agenda-remove-tags t) pars)
2218 (if (> (length cmd-key) 2)
2219 (eval (list 'let (nreverse pars)
2220 (list 'org-tags-view nil cmd-key)))
2221 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2222 (set-buffer org-agenda-buffer-name)
2223 (let* ((lines (org-split-string (buffer-string) "\n"))
2225 (while (setq line (pop lines))
2227 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2228 (setq org-agenda-info
2229 (org-fix-agenda-info (text-properties-at 0 line)))
2231 (org-encode-for-stdout
2232 (mapconcat 'org-agenda-export-csv-mapper
2233 '(org-category txt type todo tags date time-of-day extra
2234 priority-letter priority agenda-day)
2238 (defun org-fix-agenda-info (props)
2239 "Make sure all properties on an agenda item have a canonical form,
2240 so the export commands can easily use it."
2242 (when (setq tmp (plist-get props 'tags))
2243 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2244 (when (setq tmp (plist-get props 'date))
2245 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2246 (let ((calendar-date-display-form '(year "-" month "-" day)))
2247 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2249 (setq tmp (calendar-date-string tmp)))
2250 (setq props (plist-put props 'date tmp)))
2251 (when (setq tmp (plist-get props 'day))
2252 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2253 (let ((calendar-date-display-form '(year "-" month "-" day)))
2254 (setq tmp (calendar-date-string tmp)))
2255 (setq props (plist-put props 'day tmp))
2256 (setq props (plist-put props 'agenda-day tmp)))
2257 (when (setq tmp (plist-get props 'txt))
2258 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2259 (plist-put props 'priority-letter (match-string 1 tmp))
2260 (setq tmp (replace-match "" t t tmp)))
2261 (when (and (setq re (plist-get props 'org-todo-regexp))
2262 (setq re (concat "\\`\\.*" re " ?"))
2263 (string-match re tmp))
2264 (plist-put props 'todo (match-string 1 tmp))
2265 (setq tmp (replace-match "" t t tmp)))
2266 (plist-put props 'txt tmp)))
2269 (defun org-agenda-export-csv-mapper (prop)
2270 (let ((res (plist-get org-agenda-info prop)))
2275 (t (prin1-to-string res))))
2276 (while (string-match "," res)
2277 (setq res (replace-match ";" t t res)))
2282 (defun org-store-agenda-views (&rest parameters)
2284 (eval (list 'org-batch-store-agenda-views)))
2286 ;; FIXME, why is this a macro?????
2288 (defmacro org-batch-store-agenda-views (&rest parameters)
2289 "Run all custom agenda commands that have a file argument."
2290 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2292 (dir default-directory)
2293 pars cmd thiscmdkey files opts cmd-or-set)
2295 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2296 (setq pars (reverse pars))
2297 (save-window-excursion
2299 (setq cmd (pop cmds)
2300 thiscmdkey (car cmd)
2301 cmd-or-set (nth 2 cmd)
2302 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2303 files (nth (if (listp cmd-or-set) 4 5) cmd))
2304 (if (stringp files) (setq files (list files)))
2306 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2307 (list 'org-agenda nil thiscmdkey)))
2308 (set-buffer org-agenda-buffer-name)
2310 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2311 (list 'org-write-agenda
2312 (expand-file-name (pop files) dir) nil t))))
2313 (and (get-buffer org-agenda-buffer-name)
2314 (kill-buffer org-agenda-buffer-name)))))))
2316 (defun org-agenda-mark-header-line (pos)
2317 "Mark the line at POS as an agenda structure header."
2320 (put-text-property (point-at-bol) (point-at-eol)
2321 'org-agenda-structural-header t)
2322 (when org-agenda-title-append
2323 (put-text-property (point-at-bol) (point-at-eol)
2324 'org-agenda-title-append org-agenda-title-append))))
2326 (defvar org-mobile-creating-agendas)
2327 (defun org-write-agenda (file &optional open nosettings)
2328 "Write the current buffer (an agenda view) as a file.
2329 Depending on the extension of the file name, plain text (.txt),
2330 HTML (.html or .htm) or Postscript (.ps) is produced.
2331 If the extension is .ics, run icalendar export over all files used
2332 to construct the agenda and limit the export to entries listed in the
2334 With prefix argument OPEN, open the new file immediately.
2335 If NOSETTINGS is given, do not scope the settings of
2336 `org-agenda-exporter-settings' into the export commands. This is used when
2337 the settings have already been scoped and we do not wish to overrule other,
2338 higher priority settings."
2339 (interactive "FWrite agenda to file: \nP")
2340 (if (not (file-writable-p file))
2341 (error "Cannot write agenda to file %s" file))
2343 ((string-match "\\.html?\\'" file) (require 'htmlize))
2344 ((string-match "\\.ps\\'" file) (require 'ps-print)))
2345 (org-let (if nosettings nil org-agenda-exporter-settings)
2347 (save-window-excursion
2348 (org-agenda-mark-filtered-text)
2349 (let ((bs (copy-sequence (buffer-string))) beg)
2350 (org-agenda-unmark-filtered-text)
2353 (org-agenda-remove-marked-text 'org-filtered)
2354 (while (setq beg (text-property-any (point-min) (point-max)
2357 beg (or (next-single-property-change beg 'org-filtered)
2359 (run-hooks 'org-agenda-before-write-hook)
2361 ((org-bound-and-true-p org-mobile-creating-agendas)
2362 (org-mobile-write-agenda-for-mobile file))
2363 ((string-match "\\.html?\\'" file)
2364 (set-buffer (htmlize-buffer (current-buffer)))
2366 (when (and org-agenda-export-html-style
2367 (string-match "<style>" org-agenda-export-html-style))
2368 ;; replace <style> section with org-agenda-export-html-style
2369 (goto-char (point-min))
2370 (kill-region (- (search-forward "<style") 6)
2371 (search-forward "</style>"))
2372 (insert org-agenda-export-html-style))
2374 (kill-buffer (current-buffer))
2375 (message "HTML written to %s" file))
2376 ((string-match "\\.ps\\'" file)
2378 (flet ((ps-get-buffer-name () "Agenda View"))
2379 (ps-print-buffer-with-faces file))
2380 (message "Postscript written to %s" file))
2381 ((string-match "\\.pdf\\'" file)
2383 (flet ((ps-get-buffer-name () "Agenda View"))
2384 (ps-print-buffer-with-faces
2385 (concat (file-name-sans-extension file) ".ps")))
2386 (call-process "ps2pdf" nil nil nil
2388 (concat (file-name-sans-extension file) ".ps"))
2389 (expand-file-name file))
2390 (message "PDF written to %s" file))
2391 ((string-match "\\.ics\\'" file)
2392 (require 'org-icalendar)
2393 (let ((org-agenda-marker-table
2394 (org-create-marker-find-array
2395 (org-agenda-collect-markers)))
2396 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2397 (org-combined-agenda-icalendar-file file))
2398 (apply 'org-export-icalendar 'combine
2399 (org-agenda-files nil 'ifmode))))
2401 (let ((bs (buffer-string)))
2406 (kill-buffer (current-buffer))
2407 (message "Plain text written to %s" file))))))))
2408 (set-buffer org-agenda-buffer-name))
2409 (when open (org-open-file file)))
2411 (defvar org-agenda-filter-overlays nil)
2413 (defun org-agenda-mark-filtered-text ()
2414 "Mark all text hidden by filtering with a text property."
2415 (let ((inhibit-read-only t))
2418 (when (equal (org-overlay-buffer o) (current-buffer))
2420 (org-overlay-start o) (org-overlay-end o)
2422 org-agenda-filter-overlays)))
2424 (defun org-agenda-unmark-filtered-text ()
2425 "Remove the filtering text property."
2426 (let ((inhibit-read-only t))
2427 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2429 (defun org-agenda-remove-marked-text (property &optional value)
2430 "Delete all text marked with VALUE of PROPERTY.
2431 VALUE defaults to t."
2433 (setq value (or value t))
2434 (while (setq beg (text-property-any (point-min) (point-max)
2437 beg (or (next-single-property-change beg 'org-filtered)
2440 (defun org-agenda-add-entry-text ()
2441 "Add entry text to agenda lines.
2442 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2443 entry text following headings shown in the agenda.
2444 Drawers will be excluded, also the line with scheduling/deadline info."
2445 (when (and (> org-agenda-add-entry-text-maxlines 0)
2446 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2448 (goto-char (point-min))
2450 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2451 (beginning-of-line 2)
2452 (setq txt (org-agenda-get-some-entry-text
2453 m org-agenda-add-entry-text-maxlines " > "))
2455 (if (string-match "\\S-" txt) (insert "\n" txt)))))))
2457 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2459 "Extract entry text from MARKER, at most N-LINES lines.
2460 This will ignore drawers etc, just get the text.
2461 If INDENT is given, prefix every line with this string. If KEEP is
2462 given, it is a list of symbols, defining stuff that should not be
2463 removed from the entry content. Currently only `planning' is allowed here."
2464 (let (txt drawer-re kwd-time-re ind)
2466 (with-current-buffer (marker-buffer marker)
2467 (if (not (org-mode-p))
2474 (setq txt (buffer-substring
2475 (min (1+ (point)) (point-max))
2476 (progn (outline-next-heading) (point)))
2477 drawer-re org-drawer-regexp
2478 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2482 (when org-agenda-add-entry-text-descriptive-links
2483 (goto-char (point-min))
2484 (while (org-activate-bracket-links (point-max))
2485 (add-text-properties (match-beginning 0) (match-end 0)
2487 (goto-char (point-min))
2488 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2489 (set-text-properties (match-beginning 0) (match-end 0)
2491 (goto-char (point-min))
2492 (while (re-search-forward drawer-re nil t)
2495 (progn (re-search-forward
2496 "^[ \t]*:END:.*\n?" nil 'move)
2498 (unless (member 'planning keep)
2499 (goto-char (point-min))
2500 (while (re-search-forward kwd-time-re nil t)
2501 (replace-match "")))
2502 (goto-char (point-min))
2503 (when org-agenda-entry-text-exclude-regexps
2504 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2505 (while (setq re (pop re-list))
2506 (goto-char (point-min))
2507 (while (re-search-forward re nil t)
2508 (replace-match "")))))
2509 (goto-char (point-max))
2510 (skip-chars-backward " \t\n")
2511 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2513 ;; find and remove min common indentation
2514 (goto-char (point-min))
2515 (untabify (point-min) (point-max))
2516 (setq ind (org-get-indentation))
2518 (unless (looking-at "[ \t]*$")
2519 (setq ind (min ind (org-get-indentation))))
2520 (beginning-of-line 2))
2521 (goto-char (point-min))
2523 (unless (looking-at "[ \t]*$")
2524 (move-to-column ind)
2525 (delete-region (point-at-bol) (point)))
2526 (beginning-of-line 2))
2528 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2530 (goto-char (point-min))
2532 (while (and (not (eobp)) (re-search-forward "^" nil t))
2533 (replace-match indent t t)))
2534 (goto-char (point-min))
2535 (while (looking-at "[ \t]*\n") (replace-match ""))
2536 (goto-char (point-max))
2537 (when (> (org-current-line)
2539 (org-goto-line (1+ n-lines))
2541 (setq txt (buffer-substring (point-min) (point)))))))))
2544 (defun org-agenda-collect-markers ()
2545 "Collect the markers pointing to entries in the agenda buffer."
2548 (goto-char (point-min))
2550 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2551 (org-get-at-bol 'org-marker)))
2553 (beginning-of-line 2)))
2554 (nreverse markers)))
2556 (defun org-create-marker-find-array (marker-list)
2557 "Create a alist of files names with all marker positions in that file."
2559 (while (setq m (pop marker-list))
2560 (setq p (marker-position m)
2561 f (buffer-file-name (or (buffer-base-buffer
2563 (marker-buffer m))))
2564 (if (setq a (assoc f tbl))
2565 (push (marker-position m) (cdr a))
2566 (push (list f p) tbl)))
2567 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2570 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2571 (defun org-check-agenda-marker-table ()
2572 "Check of the current entry is on the marker list."
2573 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2575 (and (setq a (assoc file org-agenda-marker-table))
2578 (org-back-to-heading t)
2579 (member (point) (cdr a)))))))
2581 (defun org-check-for-org-mode ()
2582 "Make sure current buffer is in org-mode. Error if not."
2584 (error "Cannot execute org-mode agenda command on buffer in %s"
2587 (defun org-fit-agenda-window ()
2588 "Fit the window to the buffer size."
2589 (and (memq org-agenda-window-setup '(reorganize-frame))
2590 (fboundp 'fit-window-to-buffer)
2591 (org-fit-window-to-buffer
2593 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2594 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2596 ;;; Agenda prepare and finalize
2598 (defvar org-agenda-multi nil) ; dynamically scoped
2599 (defvar org-agenda-buffer-name "*Org Agenda*")
2600 (defvar org-pre-agenda-window-conf nil)
2601 (defvar org-agenda-columns-active nil)
2602 (defvar org-agenda-name nil)
2603 (defvar org-agenda-filter nil)
2604 (defvar org-agenda-filter-preset nil
2605 "A preset of the tags filter used for secondary agenda filtering.
2606 This must be a list of strings, each string must be a single tag preceeded
2608 This variable should not be set directly, but agenda custom commands can
2609 bind it in the options section.")
2611 (defun org-prepare-agenda (&optional name)
2612 (setq org-todo-keywords-for-agenda nil)
2613 (setq org-done-keywords-for-agenda nil)
2614 (setq org-drawers-for-agenda nil)
2615 (setq org-agenda-filter nil)
2616 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2617 (if org-agenda-multi
2619 (setq buffer-read-only nil)
2620 (goto-char (point-max))
2621 (unless (or (bobp) org-agenda-compact-blocks)
2623 (if (stringp org-agenda-block-separator)
2624 org-agenda-block-separator
2625 (make-string (window-width) org-agenda-block-separator))
2627 (narrow-to-region (point) (point-max)))
2628 (org-agenda-reset-markers)
2629 (setq org-agenda-contributing-files nil)
2630 (setq org-agenda-columns-active nil)
2631 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2632 (setq org-todo-keywords-for-agenda
2633 (org-uniquify org-todo-keywords-for-agenda))
2634 (setq org-done-keywords-for-agenda
2635 (org-uniquify org-done-keywords-for-agenda))
2636 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2637 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2638 (awin (get-buffer-window abuf)))
2640 ((equal (current-buffer) abuf) nil)
2641 (awin (select-window awin))
2642 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2643 ((equal org-agenda-window-setup 'current-window)
2644 (switch-to-buffer abuf))
2645 ((equal org-agenda-window-setup 'other-window)
2646 (org-switch-to-buffer-other-window abuf))
2647 ((equal org-agenda-window-setup 'other-frame)
2648 (switch-to-buffer-other-frame abuf))
2649 ((equal org-agenda-window-setup 'reorganize-frame)
2650 (delete-other-windows)
2651 (org-switch-to-buffer-other-window abuf))))
2652 (setq buffer-read-only nil)
2653 (let ((inhibit-read-only t)) (erase-buffer))
2655 (and name (not org-agenda-name)
2656 (org-set-local 'org-agenda-name name)))
2657 (setq buffer-read-only nil))
2659 (defun org-finalize-agenda ()
2660 "Finishing touch for the agenda buffer, called just before displaying it."
2661 (unless org-agenda-multi
2663 (let ((inhibit-read-only t))
2664 (goto-char (point-min))
2665 (while (org-activate-bracket-links (point-max))
2666 (add-text-properties (match-beginning 0) (match-end 0)
2668 (org-agenda-align-tags)
2669 (unless org-agenda-with-colors
2670 (remove-text-properties (point-min) (point-max) '(face nil))))
2671 (if (and (boundp 'org-agenda-overriding-columns-format)
2672 org-agenda-overriding-columns-format)
2673 (org-set-local 'org-agenda-overriding-columns-format
2674 org-agenda-overriding-columns-format))
2675 (if (and (boundp 'org-agenda-view-columns-initially)
2676 org-agenda-view-columns-initially)
2677 (org-agenda-columns))
2678 (when org-agenda-fontify-priorities
2679 (org-agenda-fontify-priorities))
2680 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2681 (org-agenda-dim-blocked-tasks))
2682 (org-agenda-mark-clocking-task)
2683 (when org-agenda-entry-text-mode
2684 (org-agenda-entry-text-hide)
2685 (org-agenda-entry-text-show))
2686 (if (functionp 'org-habit-insert-consistency-graphs)
2687 (org-habit-insert-consistency-graphs))
2688 (run-hooks 'org-finalize-agenda-hook)
2689 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2690 (when (get 'org-agenda-filter :preset-filter)
2691 (org-agenda-filter-apply org-agenda-filter))
2694 (defun org-agenda-mark-clocking-task ()
2695 "Mark the current clock entry in the agenda if it is present."
2697 (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
2698 (org-delete-overlay o)))
2699 (org-overlays-in (point-min) (point-max)))
2700 (when (marker-buffer org-clock-hd-marker)
2702 (goto-char (point-min))
2704 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2706 (when (equal (org-get-at-bol 'org-hd-marker)
2707 org-clock-hd-marker)
2708 (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
2709 (org-overlay-put ov 'type 'org-agenda-clocking)
2710 (org-overlay-put ov 'face 'org-agenda-clocking)
2711 (org-overlay-put ov 'help-echo
2712 "The clock is running in this item")))))))
2714 (defun org-agenda-fontify-priorities ()
2715 "Make highest priority lines bold, and lowest italic."
2717 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
2718 (org-delete-overlay o)))
2719 (org-overlays-in (point-min) (point-max)))
2721 (let ((inhibit-read-only t)
2723 (goto-char (point-min))
2724 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2725 (setq h (or (get-char-property (point) 'org-highest-priority)
2726 org-highest-priority)
2727 l (or (get-char-property (point) 'org-lowest-priority)
2728 org-lowest-priority)
2729 p (string-to-char (match-string 1))
2730 b (match-beginning 0)
2731 e (if (eq org-agenda-fontify-priorities 'cookies)
2734 ov (org-make-overlay b e))
2737 (cond ((cdr (assoc p org-priority-faces)))
2738 ((and (listp org-agenda-fontify-priorities)
2739 (cdr (assoc p org-agenda-fontify-priorities))))
2740 ((equal p l) 'italic)
2741 ((equal p h) 'bold)))
2742 (org-overlay-put ov 'org-type 'org-priority)))))
2744 (defun org-agenda-dim-blocked-tasks ()
2745 "Dim currently blocked TODO's in the agenda display."
2746 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
2747 (org-delete-overlay o)))
2748 (org-overlays-in (point-min) (point-max)))
2750 (let ((inhibit-read-only t)
2751 (org-depend-tag-blocked nil)
2752 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2753 org-blocked-by-checkboxes
2754 invis1 b e p ov h l)
2755 (goto-char (point-min))
2756 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2757 (and pos (goto-char (1+ pos))))
2758 (setq org-blocked-by-checkboxes nil invis1 invis)
2759 (let ((marker (org-get-at-bol 'org-hd-marker)))
2761 (not (with-current-buffer (marker-buffer marker)
2764 (if (org-entry-get nil "NOBLOCKING")
2765 t ;; Never block this entry
2766 (run-hook-with-args-until-failure
2768 (list :type 'todo-state-change
2772 (if org-blocked-by-checkboxes (setq invis1 nil))
2774 (max (point-min) (1- (point-at-bol)))
2777 ov (org-make-overlay b e))
2779 (org-overlay-put ov 'invisible t)
2780 (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2781 (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
2783 (defvar org-agenda-skip-function nil
2784 "Function to be called at each match during agenda construction.
2785 If this function returns nil, the current match should not be skipped.
2786 Otherwise, the function must return a position from where the search
2787 should be continued.
2788 This may also be a Lisp form, it will be evaluated.
2789 Never set this variable using `setq' or so, because then it will apply
2790 to all future agenda commands. Instead, bind it with `let' to scope
2791 it dynamically into the agenda-constructing command. A good way to set
2792 it is through options in org-agenda-custom-commands.")
2794 (defun org-agenda-skip ()
2795 "Throw to `:skip' in places that should be skipped.
2796 Also moves point to the end of the skipped region, so that search can
2797 continue from there."
2798 (let ((p (point-at-bol)) to fp)
2799 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2800 (get-text-property p :org-archived)
2801 (org-end-of-subtree t)
2803 (and org-agenda-skip-comment-trees
2804 (get-text-property p :org-comment)
2805 (org-end-of-subtree t)
2807 (if (equal (char-after p) ?#) (throw :skip t))
2808 (when (and (or (setq fp (functionp org-agenda-skip-function))
2809 (consp org-agenda-skip-function))
2810 (setq to (save-excursion
2813 (funcall org-agenda-skip-function)
2814 (eval org-agenda-skip-function))))))
2818 (defvar org-agenda-markers nil
2819 "List of all currently active markers created by `org-agenda'.")
2820 (defvar org-agenda-last-marker-time (org-float-time)
2821 "Creation time of the last agenda marker.")
2823 (defun org-agenda-new-marker (&optional pos)
2824 "Return a new agenda marker.
2825 Org-mode keeps a list of these markers and resets them when they are
2827 (let ((m (copy-marker (or pos (point)))))
2828 (setq org-agenda-last-marker-time (org-float-time))
2829 (push m org-agenda-markers)
2832 (defun org-agenda-reset-markers ()
2833 "Reset markers created by `org-agenda'."
2834 (while org-agenda-markers
2835 (move-marker (pop org-agenda-markers) nil)))
2837 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
2838 "Save relative positions of markers in region."
2839 (mapc (lambda (m) (org-check-and-save-marker m beg end))
2840 org-agenda-markers))
2844 (defun org-agenda-entry-text-show-here ()
2845 "Add some text from the entry as context to the current line."
2847 (setq m (org-get-at-bol 'org-hd-marker))
2848 (unless (marker-buffer m)
2849 (error "No marker points to an entry here"))
2850 (setq txt (concat "\n" (org-no-properties
2851 (org-agenda-get-some-entry-text
2852 m org-agenda-entry-text-maxlines " > "))))
2853 (when (string-match "\\S-" txt)
2854 (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
2855 (org-overlay-put o 'evaporate t)
2856 (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
2857 (org-overlay-put o 'after-string txt))))
2859 (defun org-agenda-entry-text-show ()
2860 "Add entry context for all agenda lines."
2863 (goto-char (point-max))
2864 (beginning-of-line 1)
2866 (when (org-get-at-bol 'org-hd-marker)
2867 (org-agenda-entry-text-show-here))
2868 (beginning-of-line 0))))
2870 (defun org-agenda-entry-text-hide ()
2871 "Remove any shown entry context."
2874 (if (eq (org-overlay-get o 'org-overlay-type)
2875 'agenda-entry-content)
2876 (progn (org-delete-overlay o) t)))
2877 (org-overlays-in (point-min) (point-max)))))
2881 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
2883 (defun org-timeline (&optional include-all)
2884 "Show a time-sorted view of the entries in the current org file.
2885 Only entries with a time stamp of today or later will be listed. With
2886 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2887 under the current date.
2888 If the buffer contains an active region, only check the region for
2892 (org-compile-prefix-format 'timeline)
2893 (org-set-sorting-strategy 'timeline)
2895 (dotodo include-all)
2896 (doclosed org-agenda-show-log)
2897 (entry buffer-file-name)
2898 (date (calendar-current-date))
2899 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2900 (end (if (org-region-active-p) (region-end) (point-max)))
2901 (day-numbers (org-get-all-dates beg end 'no-ranges
2902 t doclosed ; always include today
2903 org-timeline-show-empty-dates))
2904 (org-deadline-warning-days 0)
2905 (org-agenda-only-exact-dates t)
2906 (today (time-to-days (current-time)))
2909 s e rtn d emptyp wd)
2910 (setq org-agenda-redo-command
2912 (list 'org-switch-to-buffer-other-window (current-buffer))
2913 (list 'org-timeline (list 'quote include-all))))
2915 ;; Remove past dates from the list of dates.
2916 (setq day-numbers (delq nil (mapcar (lambda(x)
2917 (if (>= x today) x nil))
2919 (org-prepare-agenda (concat "Timeline "
2920 (file-name-nondirectory buffer-file-name)))
2921 (if doclosed (push :closed args))
2922 (push :timestamp args)
2923 (push :deadline args)
2924 (push :scheduled args)
2926 (if dotodo (push :todo args))
2927 (insert "Timeline of file " entry "\n")
2928 (add-text-properties (point-min) (point)
2929 (list 'face 'org-agenda-structure))
2930 (org-agenda-mark-header-line (point-min))
2931 (while (setq d (pop day-numbers))
2932 (if (and (listp d) (eq (car d) :omitted))
2935 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
2936 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
2937 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
2938 (if (and (>= d today)
2943 (insert (make-string 79 ?-) "\n")))
2944 (setq date (calendar-gregorian-from-absolute d)
2945 wd (calendar-day-of-week date))
2947 (setq rtn (and (not emptyp)
2948 (apply 'org-agenda-get-day-entries entry
2950 (if (or rtn (equal d today) org-timeline-show-empty-dates)
2953 (if (stringp org-agenda-format-date)
2954 (format-time-string org-agenda-format-date
2955 (org-time-from-absolute date))
2956 (funcall org-agenda-format-date date))
2958 (put-text-property s (1- (point)) 'face
2959 (if (member wd org-agenda-weekend-days)
2960 'org-agenda-date-weekend
2962 (put-text-property s (1- (point)) 'org-date-line t)
2963 (put-text-property s (1- (point)) 'org-agenda-date-header t)
2965 (put-text-property s (1- (point)) 'org-today t))
2966 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
2967 (put-text-property s (1- (point)) 'day d)))))
2968 (goto-char (point-min))
2969 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
2971 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
2972 (org-finalize-agenda)
2973 (setq buffer-read-only t)))
2975 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
2976 "Return a list of all relevant day numbers from BEG to END buffer positions.
2977 If NO-RANGES is non-nil, include only the start and end dates of a range,
2978 not every single day in the range. If FORCE-TODAY is non-nil, make
2979 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2980 inactive time stamps (those in square brackets) are included.
2981 When EMPTY is non-nil, also include days without any entries."
2983 (if pre-re pre-re "")
2984 (if inactive org-ts-regexp-both org-ts-regexp)))
2985 dates dates1 date day day1 day2 ts1 ts2)
2987 (setq dates (list (time-to-days (current-time)))))
2990 (while (re-search-forward re end t)
2991 (setq day (time-to-days (org-time-string-to-time
2992 (substring (match-string 1) 0 10))))
2993 (or (memq day dates) (push day dates)))
2996 (while (re-search-forward org-tr-regexp end t)
2997 (setq ts1 (substring (match-string 1) 0 10)
2998 ts2 (substring (match-string 2) 0 10)
2999 day1 (time-to-days (org-time-string-to-time ts1))
3000 day2 (time-to-days (org-time-string-to-time ts2)))
3001 (while (< (setq day1 (1+ day1)) day2)
3002 (or (memq day1 dates) (push day1 dates)))))
3003 (setq dates (sort dates '<))
3005 (while (setq day (pop dates))
3006 (setq day2 (car dates))
3008 (when (and day2 empty)
3009 (if (or (eq empty t)
3010 (and (numberp empty) (<= (- day2 day) empty)))
3011 (while (< (setq day (1+ day)) day2)
3012 (push (list day) dates1))
3013 (push (cons :omitted (- day2 day)) dates1))))
3014 (setq dates (nreverse dates1)))
3017 ;;; Agenda Daily/Weekly
3019 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
3020 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3021 "Custom commands can set this variable in the options section.")
3022 (defvar org-agenda-last-arguments nil
3023 "The arguments of the previous call to org-agenda")
3024 (defvar org-starting-day nil) ; local variable in the agenda buffer
3025 (defvar org-agenda-span nil) ; local variable in the agenda buffer
3026 (defvar org-include-all-loc nil) ; local variable
3029 (defun org-agenda-list (&optional include-all start-day ndays)
3030 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3031 The view will be for the current day or week, but from the overview buffer
3032 you will be able to go to other days/weeks.
3034 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3035 all unfinished TODO items will also be shown, before the agenda.
3036 This feature is considered obsolete, please use the TODO list or a block
3039 With a numeric prefix argument in an interactive call, the agenda will
3040 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
3041 the number of days. NDAYS defaults to `org-agenda-ndays'.
3043 START-DAY defaults to TODAY, or to the most recent match for the weekday
3044 given in `org-agenda-start-on-weekday'."
3046 (if (and (integerp include-all) (> include-all 0))
3047 (setq ndays include-all include-all nil))
3048 (setq ndays (or ndays org-agenda-ndays)
3049 start-day (or start-day org-agenda-start-day))
3050 (if org-agenda-overriding-arguments
3051 (setq include-all (car org-agenda-overriding-arguments)
3052 start-day (nth 1 org-agenda-overriding-arguments)
3053 ndays (nth 2 org-agenda-overriding-arguments)))
3054 (if (stringp start-day)
3055 ;; Convert to an absolute day number
3056 (setq start-day (time-to-days (org-read-date nil t start-day))))
3057 (setq org-agenda-last-arguments (list include-all start-day ndays))
3058 (org-compile-prefix-format 'agenda)
3059 (org-set-sorting-strategy 'agenda)
3061 (let* ((org-agenda-start-on-weekday
3062 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3063 org-agenda-start-on-weekday nil))
3064 (thefiles (org-agenda-files nil 'ifmode))
3066 (today (time-to-days
3067 (time-subtract (current-time)
3068 (list 0 (* 3600 org-extend-today-until) 0))))
3069 (sd (or start-day today))
3070 (start (if (or (null org-agenda-start-on-weekday)
3071 (< org-agenda-ndays 7))
3073 (let* ((nt (calendar-day-of-week
3074 (calendar-gregorian-from-absolute sd)))
3075 (n1 org-agenda-start-on-weekday)
3077 (- sd (+ (if (< d 0) 7 0) d)))))
3078 (day-numbers (list start))
3080 (inhibit-redisplay (not debug-on-error))
3081 s e rtn rtnall file date d start-pos end-pos todayp nd wd
3082 clocktable-start clocktable-end)
3083 (setq org-agenda-redo-command
3084 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3085 ;; Make the list of days
3086 (setq ndays (or ndays org-agenda-ndays)
3089 (push (1+ (car day-numbers)) day-numbers)
3090 (setq ndays (1- ndays)))
3091 (setq day-numbers (nreverse day-numbers))
3092 (setq clocktable-start (car day-numbers)
3093 clocktable-end (1+ (or (org-last day-numbers) 0)))
3094 (org-prepare-agenda "Day/Week")
3095 (org-set-local 'org-starting-day (car day-numbers))
3096 (org-set-local 'org-include-all-loc include-all)
3097 (org-set-local 'org-agenda-span
3098 (org-agenda-ndays-to-span nd))
3099 (when (and (or include-all org-agenda-include-all-todo)
3100 (member today day-numbers))
3101 (setq files thefiles
3103 (while (setq file (pop files))
3105 (org-check-agenda-file file)
3106 (setq date (calendar-gregorian-from-absolute today)
3107 rtn (org-agenda-get-day-entries
3109 (setq rtnall (append rtnall rtn))))
3111 (insert "All currently open TODO items:\n")
3112 (add-text-properties (point-min) (1- (point))
3113 (list 'face 'org-agenda-structure
3114 'short-heading "All TODO items"))
3115 (org-agenda-mark-header-line (point-min))
3116 (insert (org-finalize-agenda-entries rtnall) "\n")))
3117 (unless org-agenda-compact-blocks
3118 (let* ((d1 (car day-numbers))
3119 (d2 (org-last day-numbers))
3120 (w1 (org-days-to-iso-week d1))
3121 (w2 (org-days-to-iso-week d2)))
3123 (if org-agenda-overriding-header
3124 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3125 nil 'face 'org-agenda-structure) "\n")
3126 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3128 (if (< (- d2 d1) 350)
3130 (format " (W%02d)" w1)
3131 (format " (W%02d-W%02d)" w1 w2))
3134 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3136 (org-agenda-mark-header-line s))
3137 (while (setq d (pop day-numbers))
3138 (setq date (calendar-gregorian-from-absolute d)
3139 wd (calendar-day-of-week date)
3141 (if (or (setq todayp (= d today))
3142 (and (not start-pos) (= d sd)))
3143 (setq start-pos (point))
3144 (if (and start-pos (not end-pos))
3145 (setq end-pos (point))))
3146 (setq files thefiles
3148 (while (setq file (pop files))
3150 (org-check-agenda-file file)
3152 ((eq org-agenda-show-log 'only)
3153 (setq rtn (org-agenda-get-day-entries
3154 file date :closed)))
3155 (org-agenda-show-log
3156 (setq rtn (org-agenda-get-day-entries
3158 :deadline :scheduled :timestamp :sexp :closed)))
3160 (setq rtn (org-agenda-get-day-entries
3162 :deadline :scheduled :sexp :timestamp))))
3163 (setq rtnall (append rtnall rtn))))
3164 (if org-agenda-include-diary
3165 (let ((org-agenda-search-headline-for-time t))
3166 (require 'diary-lib)
3167 (setq rtn (org-get-entries-from-diary date))
3168 (setq rtnall (append rtnall rtn))))
3169 (if (or rtnall org-agenda-show-all-dates)
3171 (setq day-cnt (1+ day-cnt))
3173 (if (stringp org-agenda-format-date)
3174 (format-time-string org-agenda-format-date
3175 (org-time-from-absolute date))
3176 (funcall org-agenda-format-date date))
3178 (put-text-property s (1- (point)) 'face
3179 (if (member wd org-agenda-weekend-days)
3180 'org-agenda-date-weekend
3182 (put-text-property s (1- (point)) 'org-date-line t)
3183 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3184 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3186 (put-text-property s (1- (point)) 'org-today t)
3187 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
3189 (org-finalize-agenda-entries
3190 (org-agenda-add-time-grid-maybe
3193 (put-text-property s (1- (point)) 'day d)
3194 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3195 (when (and org-agenda-clockreport-mode clocktable-start)
3196 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3197 ;; the above line is to ensure the restricted range!
3198 (p org-agenda-clockreport-parameter-plist)
3200 (setq p (org-plist-delete p :block))
3201 (setq p (plist-put p :tstart clocktable-start))
3202 (setq p (plist-put p :tend clocktable-end))
3203 (setq p (plist-put p :scope 'agenda))
3204 (setq tbl (apply 'org-get-clocktable p))
3206 (goto-char (point-min))
3207 (or org-agenda-multi (org-fit-agenda-window))
3208 (unless (and (pos-visible-in-window-p (point-min))
3209 (pos-visible-in-window-p (point-max)))
3210 (goto-char (1- (point-max)))
3212 (if (not (pos-visible-in-window-p (or start-pos 1)))
3214 (goto-char (or start-pos 1))
3216 (goto-char (or start-pos 1))
3217 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3218 (org-finalize-agenda)
3219 (setq buffer-read-only t)
3222 (defun org-agenda-ndays-to-span (n)
3223 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3225 ;;; Agenda word search
3227 (defvar org-agenda-search-history nil)
3228 (defvar org-todo-only nil)
3230 (defvar org-search-syntax-table nil
3231 "Special syntax table for org-mode search.
3232 In this table, we have single quotes not as word constituents, to
3233 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3235 (defun org-search-syntax-table ()
3236 (unless org-search-syntax-table
3237 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3238 (modify-syntax-entry ?' "." org-search-syntax-table)
3239 (modify-syntax-entry ?` "." org-search-syntax-table))
3240 org-search-syntax-table)
3242 (defvar org-agenda-last-search-view-search-was-boolean nil)
3245 (defun org-search-view (&optional todo-only string edit-at)
3246 "Show all entries that contain a phrase or words or regular expressions.
3248 With optional prefix argument TODO-ONLY, only consider entries that are
3249 TODO entries. The argument STRING can be used to pass a default search
3250 string into this function. If EDIT-AT is non-nil, it means that the
3251 user should get a chance to edit this string, with cursor at position
3254 The search string can be viewed either as a phrase that should be found as
3255 is, or it can be broken into a number of snippets, each of which must match
3256 in a Boolean way to select an entry. The default depends on the variable
3257 `org-agenda-search-view-always-boolean'.
3258 Even if this is turned off (the default) you can always switch to
3259 Boolean search dynamically by preceeding the first word with \"+\" or \"-\".
3261 The default is a direct search of the whole phrase, where each space in
3262 the search string can expand to an arbitrary amount of whitespace,
3265 If using a Boolean search, the search string is split on whitespace and
3266 each snippet is searched separately, with logical AND to select an entry.
3267 Words prefixed with a minus must *not* occur in the entry. Words without
3268 a prefix or prefixed with a plus must occur in the entry. Matching is
3269 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3270 match whole words, not parts of a word) if
3271 `org-agenda-search-view-force-full-words' is set (default is nil).
3273 Boolean search snippets enclosed by curly braces are interpreted as
3274 regular expressions that must or (when preceeded with \"-\") must not
3275 match in the entry. Snippets enclosed into double quotes will be taken
3276 as a whole, to incude whitespace.
3278 - If the search string starts with an asterisk, search only in headlines.
3279 - If (possibly after the leading star) the search string starts with an
3280 exclamation mark, this also means to look at TODO entries only, an effect
3281 that can also be achieved with a prefix argument.
3282 - If (possibly after star and exclamation mark) the search string starts
3283 with a colon, this will mean that the (non-regexp) snippets of the
3284 Boolean search must match as full words.
3286 This command searches the agenda files, and in addition the files listed
3287 in `org-agenda-text-search-extra-files'."
3289 (org-compile-prefix-format 'search)
3290 (org-set-sorting-strategy 'search)
3291 (org-prepare-agenda "SEARCH")
3292 (let* ((props (list 'face nil
3293 'done-face 'org-agenda-done
3294 'org-not-done-regexp org-not-done-regexp
3295 'org-todo-regexp org-todo-regexp
3296 'org-complex-heading-regexp org-complex-heading-regexp
3297 'mouse-face 'highlight
3298 'help-echo (format "mouse-2 or RET jump to location")))
3299 (full-words org-agenda-search-view-force-full-words)
3300 regexp rtn rtnall files file pos
3301 marker category tags c neg re boolean
3302 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3303 (unless (and (not edit-at)
3305 (string-match "\\S-" string))
3306 (setq string (read-string
3307 (if org-agenda-search-view-always-boolean
3308 "[+-]Word/{Regexp} ...: "
3309 "Phrase, or [+-]Word/{Regexp} ...: ")
3311 ((integerp edit-at) (cons string edit-at))
3313 'org-agenda-search-history)))
3314 (org-set-local 'org-todo-only todo-only)
3315 (setq org-agenda-redo-command
3316 (list 'org-search-view (if todo-only t nil) string
3317 '(if current-prefix-arg 1 nil)))
3318 (setq org-agenda-query-string string)
3320 (if (equal (string-to-char string) ?*)
3322 words (substring string 1))
3323 (setq words string))
3324 (when (equal (string-to-char words) ?!)
3326 words (substring words 1)))
3327 (when (equal (string-to-char words) ?:)
3329 words (substring words 1)))
3330 (if (or org-agenda-search-view-always-boolean
3331 (member (string-to-char string) '(?- ?+ ?\{)))
3333 (setq words (org-split-string words))
3334 (setq org-agenda-last-search-view-search-was-boolean boolean)
3337 (while (setq w (pop words))
3338 (if (or (equal (substring w 0 1) "\"")
3339 (and (> (length w) 1)
3340 (member (substring w 0 1) '("+" "-"))
3341 (equal (substring w 1 2) "\"")))
3342 (while (and words (not (equal (substring w -1) "\"")))
3343 (setq w (concat w " " (pop words)))))
3344 (and (string-match "\\`\\([-+]?\\)\"" w)
3345 (setq w (replace-match "\\1" nil nil w)))
3346 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3348 (setq words (nreverse wds))))
3351 (setq c (string-to-char w))
3353 (setq neg t w (substring w 1))
3355 (setq neg nil w (substring w 1))
3357 (if (string-match "\\`{.*}\\'" w)
3358 (setq re (substring w 1 -1))
3360 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3361 (setq re (regexp-quote (downcase w)))))
3362 (if neg (push re regexps-) (push re regexps+)))
3364 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3366 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3368 (setq regexp (concat "^" org-outline-regexp))
3369 (setq regexp (pop regexps+))
3370 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3372 (setq files (org-agenda-files nil 'ifmode))
3373 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3374 (pop org-agenda-text-search-extra-files)
3375 (setq files (org-add-archive-files files)))
3376 (setq files (append files org-agenda-text-search-extra-files)
3378 (while (setq file (pop files))
3381 (org-check-agenda-file file)
3382 (setq buffer (if (file-exists-p file)
3383 (org-get-agenda-file-buffer file)
3384 (error "No such file %s" file)))
3386 ;; If file does not exist, make sure an error message is sent
3387 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3389 (with-current-buffer buffer
3390 (with-syntax-table (org-search-syntax-table)
3391 (unless (org-mode-p)
3392 (error "Agenda file %s is not in `org-mode'" file))
3393 (let ((case-fold-search t))
3396 (if org-agenda-restrict
3397 (narrow-to-region org-agenda-restrict-begin
3398 org-agenda-restrict-end)
3400 (goto-char (point-min))
3401 (unless (or (org-on-heading-p)
3402 (outline-next-heading))
3403 (throw 'nextfile t))
3404 (goto-char (max (point-min) (1- (point))))
3405 (while (re-search-forward regexp nil t)
3406 (org-back-to-heading t)
3407 (skip-chars-forward "* ")
3408 (setq beg (point-at-bol)
3410 end (progn (outline-next-heading) (point)))
3414 (setq str (buffer-substring-no-properties
3416 (if hdl-only (point-at-eol) end)))
3417 (mapc (lambda (wr) (when (string-match wr str)
3418 (goto-char (1- end))
3421 (mapc (lambda (wr) (unless (string-match wr str)
3422 (goto-char (1- end))
3425 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3429 (setq marker (org-agenda-new-marker (point))
3430 category (org-get-category)
3431 tags (org-get-tags-at (point))
3432 txt (org-format-agenda-item
3434 (buffer-substring-no-properties
3435 beg1 (point-at-eol))
3437 (org-add-props txt props
3438 'org-marker marker 'org-hd-marker marker
3439 'org-todo-regexp org-todo-regexp
3440 'org-complex-heading-regexp org-complex-heading-regexp
3441 'priority 1000 'org-category category
3444 (goto-char (1- end))))))))))
3445 (setq rtn (nreverse ee))
3446 (setq rtnall (append rtnall rtn)))
3447 (if org-agenda-overriding-header
3448 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3449 nil 'face 'org-agenda-structure) "\n")
3450 (insert "Search words: ")
3451 (add-text-properties (point-min) (1- (point))
3452 (list 'face 'org-agenda-structure))
3454 (insert string "\n")
3455 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3457 (unless org-agenda-multi
3458 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3459 (add-text-properties pos (1- (point))
3460 (list 'face 'org-agenda-structure))))
3461 (org-agenda-mark-header-line (point-min))
3463 (insert (org-finalize-agenda-entries rtnall) "\n"))
3464 (goto-char (point-min))
3465 (or org-agenda-multi (org-fit-agenda-window))
3466 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3467 (org-finalize-agenda)
3468 (setq buffer-read-only t)))
3470 ;;; Agenda TODO list
3472 (defvar org-select-this-todo-keyword nil)
3473 (defvar org-last-arg nil)
3476 (defun org-todo-list (arg)
3477 "Show all TODO entries from all agenda file in a single list.
3478 The prefix arg can be used to select a specific TODO keyword and limit
3479 the list to these. When using \\[universal-argument], you will be prompted
3480 for a keyword. A numeric prefix directly selects the Nth keyword in
3481 `org-todo-keywords-1'."
3484 (org-compile-prefix-format 'todo)
3485 (org-set-sorting-strategy 'todo)
3486 (org-prepare-agenda "TODO")
3487 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3488 (let* ((today (time-to-days (current-time)))
3489 (date (calendar-gregorian-from-absolute today))
3490 (kwds org-todo-keywords-for-agenda)
3491 (completion-ignore-case t)
3492 (org-select-this-todo-keyword
3493 (if (stringp arg) arg
3494 (and arg (integerp arg) (> arg 0)
3495 (nth (1- arg) kwds))))
3496 rtn rtnall files file pos)
3497 (when (equal arg '(4))
3498 (setq org-select-this-todo-keyword
3499 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3500 (mapcar 'list kwds) nil nil)))
3501 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3502 (org-set-local 'org-last-arg arg)
3503 (setq org-agenda-redo-command
3504 '(org-todo-list (or current-prefix-arg org-last-arg)))
3505 (setq files (org-agenda-files nil 'ifmode)
3507 (while (setq file (pop files))
3509 (org-check-agenda-file file)
3510 (setq rtn (org-agenda-get-day-entries file date :todo))
3511 (setq rtnall (append rtnall rtn))))
3512 (if org-agenda-overriding-header
3513 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3514 nil 'face 'org-agenda-structure) "\n")
3515 (insert "Global list of TODO items of type: ")
3516 (add-text-properties (point-min) (1- (point))
3517 (list 'face 'org-agenda-structure
3520 (or org-select-this-todo-keyword "ALL"))))
3521 (org-agenda-mark-header-line (point-min))
3523 (insert (or org-select-this-todo-keyword "ALL") "\n")
3524 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3526 (unless org-agenda-multi
3527 (insert "Available with `N r': (0)ALL")
3530 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3531 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3536 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3537 (org-agenda-mark-header-line (point-min))
3539 (insert (org-finalize-agenda-entries rtnall) "\n"))
3540 (goto-char (point-min))
3541 (or org-agenda-multi (org-fit-agenda-window))
3542 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3543 (org-finalize-agenda)
3544 (setq buffer-read-only t)))
3546 ;;; Agenda tags match
3549 (defun org-tags-view (&optional todo-only match)
3550 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3551 The prefix arg TODO-ONLY limits the search to TODO entries."
3553 (org-compile-prefix-format 'tags)
3554 (org-set-sorting-strategy 'tags)
3555 (let* ((org-tags-match-list-sublevels
3556 org-tags-match-list-sublevels)
3557 (completion-ignore-case t)
3558 rtn rtnall files file pos matcher
3560 (when (and (stringp match) (not (string-match "\\S-" match)))
3562 (setq matcher (org-make-tags-matcher match)
3563 match (car matcher) matcher (cdr matcher))
3564 (org-prepare-agenda (concat "TAGS " match))
3565 (setq org-agenda-query-string match)
3566 (setq org-agenda-redo-command
3567 (list 'org-tags-view (list 'quote todo-only)
3568 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3569 (setq files (org-agenda-files nil 'ifmode)
3571 (while (setq file (pop files))
3573 (org-check-agenda-file file)
3574 (setq buffer (if (file-exists-p file)
3575 (org-get-agenda-file-buffer file)
3576 (error "No such file %s" file)))
3578 ;; If file does not exist, error message to agenda
3580 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3581 rtnall (append rtnall rtn))
3582 (with-current-buffer buffer
3583 (unless (org-mode-p)
3584 (error "Agenda file %s is not in `org-mode'" file))
3587 (if org-agenda-restrict
3588 (narrow-to-region org-agenda-restrict-begin
3589 org-agenda-restrict-end)
3591 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3592 (setq rtnall (append rtnall rtn))))))))
3593 (if org-agenda-overriding-header
3594 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3595 nil 'face 'org-agenda-structure) "\n")
3596 (insert "Headlines with TAGS match: ")
3597 (add-text-properties (point-min) (1- (point))
3598 (list 'face 'org-agenda-structure
3600 (concat "Match: " match)))
3603 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3605 (unless org-agenda-multi
3606 (insert "Press `C-u r' to search again with new search string\n"))
3607 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3608 (org-agenda-mark-header-line (point-min))
3610 (insert (org-finalize-agenda-entries rtnall) "\n"))
3611 (goto-char (point-min))
3612 (or org-agenda-multi (org-fit-agenda-window))
3613 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3614 (org-finalize-agenda)
3615 (setq buffer-read-only t)))
3617 ;;; Agenda Finding stuck projects
3619 (defvar org-agenda-skip-regexp nil
3620 "Regular expression used in skipping subtrees for the agenda.
3621 This is basically a temporary global variable that can be set and then
3622 used by user-defined selections using `org-agenda-skip-function'.")
3624 (defvar org-agenda-overriding-header nil
3625 "When this is set during todo and tags searches, will replace header.
3626 This variable should not be set directly, but custom commands can bind it
3627 in the options section.")
3629 (defun org-agenda-skip-entry-when-regexp-matches ()
3630 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3631 If yes, it returns the end position of this entry, causing agenda commands
3632 to skip the entry but continuing the search in the subtree. This is a
3633 function that can be put into `org-agenda-skip-function' for the duration
3635 (let ((end (save-excursion (org-end-of-subtree t)))
3638 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3641 (defun org-agenda-skip-subtree-when-regexp-matches ()
3642 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3643 If yes, it returns the end position of this tree, causing agenda commands
3644 to skip this subtree. This is a function that can be put into
3645 `org-agenda-skip-function' for the duration of a command."
3646 (let ((end (save-excursion (org-end-of-subtree t)))
3649 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3652 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3653 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3654 If yes, it returns the end position of the current entry (NOT the tree),
3655 causing agenda commands to skip the entry but continuing the search in
3656 the subtree. This is a function that can be put into
3657 `org-agenda-skip-function' for the duration of a command. An important
3658 use of this function is for the stuck project list."
3659 (let ((end (save-excursion (org-end-of-subtree t)))
3660 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3663 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3664 (and skip entry-end)))
3666 (defun org-agenda-skip-entry-if (&rest conditions)
3667 "Skip entry if any of CONDITIONS is true.
3668 See `org-agenda-skip-if' for details."
3669 (org-agenda-skip-if nil conditions))
3671 (defun org-agenda-skip-subtree-if (&rest conditions)
3672 "Skip entry if any of CONDITIONS is true.
3673 See `org-agenda-skip-if' for details."
3674 (org-agenda-skip-if t conditions))
3676 (defun org-agenda-skip-if (subtree conditions)
3677 "Checks current entity for CONDITIONS.
3678 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3679 the entry, i.e. the text before the next heading is checked.
3681 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3682 from different tests. Valid conditions are:
3684 scheduled Check if there is a scheduled cookie
3685 notscheduled Check if there is no scheduled cookie
3686 deadline Check if there is a deadline
3687 notdeadline Check if there is no deadline
3688 timestamp Check if there is a timestamp (also deadline or scheduled)
3689 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3690 regexp Check if regexp matches
3691 notregexp Check if regexp does not match.
3693 The regexp is taken from the conditions list, it must come right after
3694 the `regexp' or `notregexp' element.
3696 If any of these conditions is met, this function returns the end point of
3697 the entity, causing the search to continue from there. This is a function
3698 that can be put into `org-agenda-skip-function' for the duration of a command."
3700 (org-back-to-heading t)
3703 (progn (org-end-of-subtree t) (point))
3704 (progn (outline-next-heading) (1- (point)))))
3708 (and (memq 'scheduled conditions)
3709 (re-search-forward org-scheduled-time-regexp end t))
3710 (and (memq 'notscheduled conditions)
3711 (not (re-search-forward org-scheduled-time-regexp end t)))
3712 (and (memq 'deadline conditions)
3713 (re-search-forward org-deadline-time-regexp end t))
3714 (and (memq 'notdeadline conditions)
3715 (not (re-search-forward org-deadline-time-regexp end t)))
3716 (and (memq 'timestamp conditions)
3717 (re-search-forward org-ts-regexp end t))
3718 (and (memq 'nottimestamp conditions)
3719 (not (re-search-forward org-ts-regexp end t)))
3720 (and (setq m (memq 'regexp conditions))
3722 (re-search-forward (nth 1 m) end t))
3723 (and (setq m (memq 'notregexp conditions))
3725 (not (re-search-forward (nth 1 m) end t))))
3729 (defun org-agenda-list-stuck-projects (&rest ignore)
3730 "Create agenda view for projects that are stuck.
3731 Stuck projects are project that have no next actions. For the definitions
3732 of what a project is and how to check if it stuck, customize the variable
3733 `org-stuck-projects'.
3734 MATCH is being ignored."
3736 (let* ((org-agenda-skip-function
3737 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
3738 ;; We could have used org-agenda-skip-if here.
3739 (org-agenda-overriding-header
3740 (or org-agenda-overriding-header "List of stuck projects: "))
3741 (matcher (nth 0 org-stuck-projects))
3742 (todo (nth 1 org-stuck-projects))
3743 (todo-wds (if (member "*" todo)
3745 (org-prepare-agenda-buffers (org-agenda-files
3748 org-done-keywords-for-agenda
3749 (copy-sequence org-todo-keywords-for-agenda)))
3751 (todo-re (concat "^\\*+[ \t]+\\("
3752 (mapconcat 'identity todo-wds "\\|")
3754 (tags (nth 2 org-stuck-projects))
3755 (tags-re (if (member "*" tags)
3756 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3758 (concat "^\\*+ .*:\\("
3759 (mapconcat 'identity tags "\\|")
3760 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3761 (gen-re (nth 3 org-stuck-projects))
3767 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
3769 (setq org-agenda-skip-regexp
3771 (mapconcat 'identity re-list "\\|")
3772 (error "No information how to identify unstuck projects")))
3773 (org-tags-view nil matcher)
3774 (with-current-buffer org-agenda-buffer-name
3775 (setq org-agenda-redo-command
3776 '(org-agenda-list-stuck-projects
3777 (or current-prefix-arg org-last-arg))))))
3779 ;;; Diary integration
3781 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
3782 (defvar list-diary-entries-hook)
3784 (defun org-get-entries-from-diary (date)
3785 "Get the (Emacs Calendar) diary entries for DATE."
3786 (require 'diary-lib)
3787 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3788 (fancy-diary-buffer diary-fancy-buffer)
3789 (diary-display-hook '(fancy-diary-display))
3790 (diary-display-function 'fancy-diary-display)
3792 (list-diary-entries-hook
3793 (cons 'org-diary-default-entry list-diary-entries-hook))
3794 (diary-file-name-prefix-function nil) ; turn this feature off
3795 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
3797 (org-disable-agenda-to-diary t))
3799 (save-window-excursion
3800 (funcall (if (fboundp 'diary-list-entries)
3801 'diary-list-entries 'list-diary-entries)
3803 (if (not (get-buffer diary-fancy-buffer))
3805 (with-current-buffer diary-fancy-buffer
3806 (setq buffer-read-only nil)
3807 (if (zerop (buffer-size))
3810 ;; Omit the date and other unnecessary stuff
3811 (org-agenda-cleanup-fancy-diary)
3812 ;; Add prefix to each line and extend the text properties
3813 (if (zerop (buffer-size))
3815 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
3816 (set-buffer-modified-p nil)
3817 (kill-buffer diary-fancy-buffer)))
3819 (setq entries (org-split-string entries "\n"))
3823 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
3824 ;; Extend the text properties to the beginning of the line
3825 (org-add-props x (text-properties-at (1- (length x)) x)
3826 'type "diary" 'date date 'face 'org-agenda-diary))
3829 (defvar org-agenda-cleanup-fancy-diary-hook nil
3830 "Hook run when the fancy diary buffer is cleaned up.")
3832 (defun org-agenda-cleanup-fancy-diary ()
3833 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3834 This gets rid of the date, the underline under the date, and
3835 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3836 date. It also removes lines that contain only whitespace."
3837 (goto-char (point-min))
3838 (if (looking-at ".*?:[ \t]*")
3841 (re-search-forward "\n=+$" nil t)
3843 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
3844 (re-search-forward "\n=+$" nil t)
3845 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3846 (goto-char (point-min))
3847 (while (re-search-forward "^ +\n" nil t)
3849 (goto-char (point-min))
3850 (if (re-search-forward "^Org-mode dummy\n?" nil t)
3852 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
3854 ;; Make sure entries from the diary have the right text properties.
3855 (eval-after-load "diary-lib"
3856 '(if (boundp 'diary-modify-entry-list-string-function)
3857 ;; We can rely on the hook, nothing to do
3859 ;; Hook not available, must use advice to make this work
3860 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
3861 "Make the position visible."
3862 (if (and org-disable-agenda-to-diary ;; called from org-agenda
3865 (setq string (org-modify-diary-entry-string string))))))
3867 (defun org-modify-diary-entry-string (string)
3868 "Add text properties to string, allowing org-mode to act on it."
3869 (org-add-props string nil
3870 'mouse-face 'highlight
3871 'help-echo (if buffer-file-name
3872 (format "mouse-2 or RET jump to diary file %s"
3873 (abbreviate-file-name buffer-file-name))
3875 'org-agenda-diary-link t
3876 'org-marker (org-agenda-new-marker (point-at-bol))))
3878 (defun org-diary-default-entry ()
3879 "Add a dummy entry to the diary.
3880 Needed to avoid empty dates which mess up holiday display."
3881 ;; Catch the error if dealing with the new add-to-diary-alist
3882 (when org-disable-agenda-to-diary
3884 (org-add-to-diary-list original-date "Org-mode dummy" "")
3886 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
3888 (defun org-add-to-diary-list (&rest args)
3889 (if (fboundp 'diary-add-to-list)
3890 (apply 'diary-add-to-list args)
3891 (apply 'add-to-diary-list args)))
3894 (defun org-diary (&rest args)
3895 "Return diary information from org-files.
3896 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3897 It accesses org files and extracts information from those files to be
3898 listed in the diary. The function accepts arguments specifying what
3899 items should be listed. The following arguments are allowed:
3901 :timestamp List the headlines of items containing a date stamp or
3902 date range matching the selected date. Deadlines will
3903 also be listed, on the expiration day.
3905 :sexp List entries resulting from diary-like sexps.
3907 :deadline List any deadlines past due, or due within
3908 `org-deadline-warning-days'. The listing occurs only
3909 in the diary for *today*, not at any other date. If
3910 an entry is marked DONE, it is no longer listed.
3912 :scheduled List all items which are scheduled for the given date.
3913 The diary for *today* also contains items which were
3914 scheduled earlier and are not yet marked DONE.
3916 :todo List all TODO items from the org-file. This may be a
3917 long list - so this is not turned on by default.
3918 Like deadlines, these entries only show up in the
3919 diary for *today*, not at any other date.
3921 The call in the diary file should look like this:
3923 &%%(org-diary) ~/path/to/some/orgfile.org
3925 Use a separate line for each org file to check. Or, if you omit the file name,
3926 all files listed in `org-agenda-files' will be checked automatically:
3930 If you don't give any arguments (as in the example above), the default
3931 arguments (:deadline :scheduled :timestamp :sexp) are used.
3932 So the example above may also be written as
3934 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3936 The function expects the lisp variables `entry' and `date' to be provided
3937 by the caller, because this is how the calendar works. Don't use this
3938 function from a program - use `org-agenda-get-day-entries' instead."
3939 (when (> (- (org-float-time)
3940 org-agenda-last-marker-time)
3942 (org-agenda-reset-markers))
3943 (org-compile-prefix-format 'agenda)
3944 (org-set-sorting-strategy 'agenda)
3945 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3946 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
3948 (org-agenda-files t)))
3950 (org-prepare-agenda-buffers files)
3951 ;; If this is called during org-agenda, don't return any entries to
3952 ;; the calendar. Org Agenda will list these entries itself.
3953 (if org-disable-agenda-to-diary (setq files nil))
3954 (while (setq file (pop files))
3955 (setq rtn (apply 'org-agenda-get-day-entries file date args))
3956 (setq results (append results rtn)))
3958 (concat (org-finalize-agenda-entries results) "\n"))))
3960 ;;; Agenda entry finders
3962 (defun org-agenda-get-day-entries (file date &rest args)
3963 "Does the work for `org-diary' and `org-agenda'.
3964 FILE is the path to a file to be checked for entries. DATE is date like
3965 the one returned by `calendar-current-date'. ARGS are symbols indicating
3966 which kind of entries should be extracted. For details about these, see
3967 the documentation of `org-diary'."
3968 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3969 (let* ((org-startup-folded nil)
3970 (org-startup-align-all-tables nil)
3971 (buffer (if (file-exists-p file)
3972 (org-get-agenda-file-buffer file)
3973 (error "No such file %s" file)))
3974 arg results rtn deadline-results)
3976 ;; If file does not exist, make sure an error message ends up in diary
3977 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3978 (with-current-buffer buffer
3979 (unless (org-mode-p)
3980 (error "Agenda file %s is not in `org-mode'" file))
3981 (let ((case-fold-search nil))
3984 (if org-agenda-restrict
3985 (narrow-to-region org-agenda-restrict-begin
3986 org-agenda-restrict-end)
3988 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3989 (while (setq arg (pop args))
3991 ((and (eq arg :todo)
3992 (equal date (calendar-current-date)))
3993 (setq rtn (org-agenda-get-todos))
3994 (setq results (append results rtn)))
3995 ((eq arg :timestamp)
3996 (setq rtn (org-agenda-get-blocks))
3997 (setq results (append results rtn))
3998 (setq rtn (org-agenda-get-timestamps))
3999 (setq results (append results rtn)))
4001 (setq rtn (org-agenda-get-sexps))
4002 (setq results (append results rtn)))
4003 ((eq arg :scheduled)
4004 (setq rtn (org-agenda-get-scheduled deadline-results))
4005 (setq results (append results rtn)))
4007 (setq rtn (org-agenda-get-progress))
4008 (setq results (append results rtn)))
4010 (setq rtn (org-agenda-get-deadlines))
4011 (setq deadline-results (copy-sequence rtn))
4012 (setq results (append results rtn))))))))
4015 (defun org-agenda-get-todos ()
4016 "Return the TODO information for agenda display."
4017 (let* ((props (list 'face nil
4018 'done-face 'org-agenda-done
4019 'org-not-done-regexp org-not-done-regexp
4020 'org-todo-regexp org-todo-regexp
4021 'org-complex-heading-regexp org-complex-heading-regexp
4022 'mouse-face 'highlight
4024 (format "mouse-2 or RET jump to org file %s"
4025 (abbreviate-file-name buffer-file-name))))
4026 (regexp (concat "^\\*+[ \t]+\\("
4027 (if org-select-this-todo-keyword
4028 (if (equal org-select-this-todo-keyword "*")
4031 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4033 org-not-done-regexp)
4035 marker priority category tags todo-state
4037 (goto-char (point-min))
4038 (while (re-search-forward regexp nil t)
4042 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4043 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4044 (goto-char (1+ beg))
4045 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4049 (goto-char (match-beginning 1))
4050 (setq marker (org-agenda-new-marker (match-beginning 0))
4051 category (org-get-category)
4052 txt (match-string 1)
4053 tags (org-get-tags-at (point))
4054 txt (org-format-agenda-item "" txt category tags)
4055 priority (1+ (org-get-priority txt))
4056 todo-state (org-get-todo-state))
4057 (org-add-props txt props
4058 'org-marker marker 'org-hd-marker marker
4059 'priority priority 'org-category category
4060 'type "todo" 'todo-state todo-state)
4062 (if org-agenda-todo-list-sublevels
4063 (goto-char (match-end 1))
4064 (org-end-of-subtree 'invisible))))
4068 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
4069 "Do we have a reason to ignore this todo entry because it has a time stamp?"
4070 (when (or org-agenda-todo-ignore-with-date
4071 org-agenda-todo-ignore-scheduled
4072 org-agenda-todo-ignore-deadlines)
4073 (setq end (or end (save-excursion (outline-next-heading) (point))))
4075 (or (and org-agenda-todo-ignore-with-date
4076 (re-search-forward org-ts-regexp end t))
4077 (and org-agenda-todo-ignore-scheduled
4078 (re-search-forward org-scheduled-time-regexp end t))
4079 (and org-agenda-todo-ignore-deadlines
4080 (re-search-forward org-deadline-time-regexp end t)
4081 (org-deadline-close (match-string 1)))))))
4083 (defconst org-agenda-no-heading-message
4084 "No heading for this item in buffer or region.")
4086 (defun org-agenda-get-timestamps ()
4087 "Return the date stamp information for agenda display."
4088 (let* ((props (list 'face nil
4089 'org-not-done-regexp org-not-done-regexp
4090 'org-todo-regexp org-todo-regexp
4091 'org-complex-heading-regexp org-complex-heading-regexp
4092 'mouse-face 'highlight
4094 (format "mouse-2 or RET jump to org file %s"
4095 (abbreviate-file-name buffer-file-name))))
4096 (d1 (calendar-absolute-from-gregorian date))
4102 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4106 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4110 (car org-time-stamp-formats)
4111 (apply 'encode-time ; DATE bound by calendar
4112 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4114 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4115 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4116 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4117 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4118 todo-state end-of-match)
4119 (goto-char (point-min))
4120 (while (setq end-of-match (re-search-forward regexp nil t))
4121 (setq b0 (match-beginning 0)
4122 b3 (match-beginning 3) e3 (match-end 3))
4124 (and (org-at-date-range-p) (throw :skip nil))
4126 (if (and (match-end 1)
4127 (not (= d1 (org-time-string-to-absolute
4128 (match-string 1) d1 nil
4129 org-agenda-repeating-timestamp-show-all))))
4132 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4134 (setq tmp (buffer-substring (max (point-min)
4135 (- b0 org-ds-keyword-length))
4137 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4138 inactivep (= (char-after b0) ?\[)
4139 deadlinep (string-match org-deadline-regexp tmp)
4140 scheduledp (string-match org-scheduled-regexp tmp)
4141 closedp (and org-agenda-include-inactive-timestamps
4142 (string-match org-closed-string tmp))
4143 clockp (and org-agenda-include-inactive-timestamps
4144 (or (string-match org-clock-string tmp)
4145 (string-match "]-+\\'" tmp)))
4146 todo-state (org-get-todo-state)
4147 donep (member todo-state org-done-keywords))
4148 (if (or scheduledp deadlinep closedp clockp
4149 (and donep org-agenda-skip-timestamp-if-done))
4151 (if (string-match ">" timestr)
4152 ;; substring should only run to end of time stamp
4153 (setq timestr (substring timestr 0 (match-end 0))))
4154 (setq marker (org-agenda-new-marker b0)
4155 category (org-get-category b0))
4157 (if (not (re-search-backward "^\\*+ " nil t))
4158 (setq txt org-agenda-no-heading-message)
4159 (goto-char (match-beginning 0))
4160 (setq hdmarker (org-agenda-new-marker)
4161 tags (org-get-tags-at))
4162 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4163 (setq head (match-string 1))
4164 (setq txt (org-format-agenda-item
4165 (if inactivep org-agenda-inactive-leader nil)
4166 head category tags timestr nil
4168 (setq priority (org-get-priority txt))
4169 (org-add-props txt props
4170 'org-marker marker 'org-hd-marker hdmarker)
4171 (org-add-props txt nil 'priority priority
4172 'org-category category 'date date
4173 'todo-state todo-state
4176 (if org-agenda-skip-additional-timestamps-same-entry
4177 (outline-next-heading)
4178 (goto-char end-of-match))))
4181 (defun org-agenda-get-sexps ()
4182 "Return the sexp information for agenda display."
4183 (require 'diary-lib)
4184 (let* ((props (list 'face nil
4185 'mouse-face 'highlight
4187 (format "mouse-2 or RET jump to org file %s"
4188 (abbreviate-file-name buffer-file-name))))
4190 marker category ee txt tags entry result beg b sexp sexp-entry
4192 (goto-char (point-min))
4193 (while (re-search-forward regexp nil t)
4196 (setq beg (match-beginning 0))
4197 (goto-char (1- (match-end 0)))
4200 (setq sexp (buffer-substring b (point)))
4201 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4202 (org-trim (match-string 1))
4204 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4206 (setq marker (org-agenda-new-marker beg)
4207 category (org-get-category beg)
4208 todo-state (org-get-todo-state))
4210 (if (string-match "\\S-" result)
4212 (setq txt "SEXP entry returned empty string"))
4214 (setq txt (org-format-agenda-item
4215 "" txt category tags 'time))
4216 (org-add-props txt props 'org-marker marker)
4217 (org-add-props txt nil
4218 'org-category category 'date date 'todo-state todo-state
4223 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4224 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4225 The order of the first 2 times 3 arguments depends on the variable
4226 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4227 So for american calendars, give this as MONTH DAY YEAR, for european as
4228 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4229 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4230 is any number of ISO weeks in the block period for which the item should
4232 (let* ((date1 (calendar-absolute-from-gregorian
4233 (org-order-calendar-date-args m1 d1 y1)))
4234 (date2 (calendar-absolute-from-gregorian
4235 (org-order-calendar-date-args m2 d2 y2)))
4236 (d (calendar-absolute-from-gregorian date)))
4240 (= (calendar-day-of-week date) dayname)
4241 (or (not skip-weeks)
4244 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4247 (defalias 'org-get-closed 'org-agenda-get-progress)
4248 (defun org-agenda-get-progress ()
4249 "Return the logged TODO entries for agenda display."
4250 (let* ((props (list 'mouse-face 'highlight
4251 'org-not-done-regexp org-not-done-regexp
4252 'org-todo-regexp org-todo-regexp
4253 'org-complex-heading-regexp org-complex-heading-regexp
4255 (format "mouse-2 or RET jump to org file %s"
4256 (abbreviate-file-name buffer-file-name))))
4257 (items (if (consp org-agenda-show-log)
4259 org-agenda-log-mode-items))
4263 (if (memq 'closed items) (concat "\\<" org-closed-string))
4264 (if (memq 'clock items) (concat "\\<" org-clock-string))
4265 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4266 (parts-re (if parts (mapconcat 'identity parts "\\|")
4267 (error "`org-agenda-log-mode-items' is empty")))
4269 "\\(" parts-re "\\)"
4274 (car org-time-stamp-formats)
4275 (apply 'encode-time ; DATE bound by calendar
4276 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4278 (org-agenda-search-headline-for-time nil)
4279 marker hdmarker priority category tags closedp statep clockp state
4280 ee txt extra timestr rest clocked)
4281 (goto-char (point-min))
4282 (while (re-search-forward regexp nil t)
4285 (setq marker (org-agenda-new-marker (match-beginning 0))
4286 closedp (equal (match-string 1) org-closed-string)
4287 statep (equal (string-to-char (match-string 1)) ?-)
4288 clockp (not (or closedp statep))
4289 state (and statep (match-string 2))
4290 category (org-get-category (match-beginning 0))
4291 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4293 (when (string-match "\\]" timestr)
4294 ;; substring should only run to end of time stamp
4295 (setq rest (substring timestr (match-end 0))
4296 timestr (substring timestr 0 (match-end 0)))
4297 (if (and (not closedp) (not statep)
4298 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4299 (progn (setq timestr (concat (substring timestr 0 -1)
4300 "-" (match-string 1 rest) "]"))
4301 (setq clocked (match-string 2 rest)))
4302 (setq clocked "-")))
4305 ((not org-agenda-log-mode-add-notes) (setq extra nil))
4307 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4308 (setq extra (match-string 1))))
4310 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4311 (setq extra (match-string 1))))
4312 (t (setq extra nil)))
4313 (if (not (re-search-backward "^\\*+ " nil t))
4314 (setq txt org-agenda-no-heading-message)
4315 (goto-char (match-beginning 0))
4316 (setq hdmarker (org-agenda-new-marker)
4317 tags (org-get-tags-at))
4318 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4319 (setq txt (match-string 1))
4321 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4322 (setq txt (concat (substring txt 0 (match-beginning 1))
4323 " - " extra " " (match-string 2 txt)))
4324 (setq txt (concat txt " - " extra))))
4325 (setq txt (org-format-agenda-item
4327 (closedp "Closed: ")
4328 (statep (concat "State: (" state ")"))
4329 (t (concat "Clocked: (" clocked ")")))
4330 txt category tags timestr)))
4331 (setq priority 100000)
4332 (org-add-props txt props
4333 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4334 'priority priority 'org-category category
4335 'type "closed" 'date date
4336 'undone-face 'org-warning 'done-face 'org-agenda-done)
4338 (goto-char (point-at-eol))))
4341 (defun org-agenda-get-deadlines ()
4342 "Return the deadline information for agenda display."
4343 (let* ((props (list 'mouse-face 'highlight
4344 'org-not-done-regexp org-not-done-regexp
4345 'org-todo-regexp org-todo-regexp
4346 'org-complex-heading-regexp org-complex-heading-regexp
4348 (format "mouse-2 or RET jump to org file %s"
4349 (abbreviate-file-name buffer-file-name))))
4350 (regexp org-deadline-time-regexp)
4351 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4352 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4353 d2 diff dfrac wdays pos pos1 category tags
4354 ee txt head face s todo-state upcomingp donep timestr)
4355 (goto-char (point-min))
4356 (while (re-search-forward regexp nil t)
4359 (setq s (match-string 1)
4361 pos (1- (match-beginning 1))
4362 d2 (org-time-string-to-absolute
4363 (match-string 1) d1 'past
4364 org-agenda-repeating-timestamp-show-all)
4366 wdays (org-get-wdays s)
4367 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4368 upcomingp (and todayp (> diff 0)))
4369 ;; When to show a deadline in the calendar:
4370 ;; If the expiration is within wdays warning time.
4371 ;; Past-due deadlines are only shown on the current date
4372 (if (and (or (and (<= diff wdays)
4373 (and todayp (not org-agenda-only-exact-dates)))
4376 (setq todo-state (org-get-todo-state))
4377 (setq donep (member todo-state org-done-keywords))
4379 (or org-agenda-skip-deadline-if-done
4382 (setq category (org-get-category))
4383 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4384 (setq txt org-agenda-no-heading-message)
4385 (goto-char (match-end 0))
4386 (setq pos1 (match-beginning 0))
4387 (setq tags (org-get-tags-at pos1))
4388 (setq head (buffer-substring-no-properties
4390 (progn (skip-chars-forward "^\r\n")
4392 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4394 (concat (substring s (match-beginning 1)) " "))
4395 (setq timestr 'time))
4396 (setq txt (org-format-agenda-item
4398 (car org-agenda-deadline-leaders)
4400 (nth 1 org-agenda-deadline-leaders))
4402 (nth 1 org-agenda-deadline-leaders)
4404 (format (nth 1 org-agenda-deadline-leaders)
4407 (if (not (= diff 0)) nil timestr)))))
4409 (setq face (org-agenda-deadline-face dfrac wdays))
4410 (org-add-props txt props
4411 'org-marker (org-agenda-new-marker pos)
4412 'org-hd-marker (org-agenda-new-marker pos1)
4413 'priority (+ (- diff)
4414 (org-get-priority txt))
4415 'org-category category
4416 'todo-state todo-state
4417 'type (if upcomingp "upcoming-deadline" "deadline")
4418 'date (if upcomingp date d2)
4419 'face (if donep 'org-agenda-done face)
4420 'undone-face face 'done-face 'org-agenda-done)
4424 (defun org-agenda-deadline-face (fraction &optional wdays)
4425 "Return the face to displaying a deadline item.
4426 FRACTION is what fraction of the head-warning time has passed."
4427 (if (equal wdays 0) (setq fraction 1.))
4428 (let ((faces org-agenda-deadline-faces) f)
4430 (while (setq f (pop faces))
4431 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4433 (defun org-agenda-get-scheduled (&optional deadline-results)
4434 "Return the scheduled information for agenda display."
4435 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4436 'org-todo-regexp org-todo-regexp
4437 'org-complex-heading-regexp org-complex-heading-regexp
4438 'done-face 'org-agenda-done
4439 'mouse-face 'highlight
4441 (format "mouse-2 or RET jump to org file %s"
4442 (abbreviate-file-name buffer-file-name))))
4443 (regexp org-scheduled-time-regexp)
4444 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4445 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4447 (deadline-position-alist
4448 (mapcar (lambda (a) (and (setq mm (get-text-property
4449 0 'org-hd-marker a))
4450 (cons (marker-position mm) a)))
4452 d2 diff pos pos1 category tags donep
4453 ee txt head pastschedp todo-state face timestr s habitp)
4454 (goto-char (point-min))
4455 (while (re-search-forward regexp nil t)
4458 (setq s (match-string 1)
4460 pos (1- (match-beginning 1))
4461 d2 (org-time-string-to-absolute
4462 (match-string 1) d1 'past
4463 org-agenda-repeating-timestamp-show-all)
4465 (setq pastschedp (and todayp (< diff 0)))
4466 ;; When to show a scheduled item in the calendar:
4467 ;; If it is on or past the date.
4468 (when (or (and (< diff 0)
4469 (< (abs diff) org-scheduled-past-days)
4470 (and todayp (not org-agenda-only-exact-dates)))
4473 (setq todo-state (org-get-todo-state))
4474 (setq donep (member todo-state org-done-keywords))
4475 (setq habitp (and (functionp 'org-is-habit-p)
4478 (or habitp org-agenda-skip-scheduled-if-done
4481 (setq category (org-get-category))
4482 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4483 (setq txt org-agenda-no-heading-message)
4484 (goto-char (match-end 0))
4485 (setq pos1 (match-beginning 0))
4487 (if (or (not org-habit-show-habits)
4489 org-habit-show-habits-only-for-today))
4492 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4493 (and org-agenda-skip-scheduled-if-deadline-is-shown
4495 (setq mm (assoc pos1 deadline-position-alist)))
4497 (setq tags (org-get-tags-at))
4498 (setq head (buffer-substring-no-properties
4500 (progn (skip-chars-forward "^\r\n") (point))))
4501 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4503 (concat (substring s (match-beginning 1)) " "))
4504 (setq timestr 'time))
4505 (setq txt (org-format-agenda-item
4507 (car org-agenda-scheduled-leaders)
4508 (format (nth 1 org-agenda-scheduled-leaders)
4511 (if (not (= diff 0)) nil timestr)
4516 ((and (not habitp) pastschedp)
4517 'org-scheduled-previously)
4518 (todayp 'org-scheduled-today)
4520 habitp (and habitp (org-habit-parse-todo)))
4521 (org-add-props txt props
4523 'face (if donep 'org-agenda-done face)
4524 'org-marker (org-agenda-new-marker pos)
4525 'org-hd-marker (org-agenda-new-marker pos1)
4526 'type (if pastschedp "past-scheduled" "scheduled")
4527 'date (if pastschedp d2 date)
4528 'priority (if habitp
4529 (org-habit-get-priority habitp)
4530 (+ 94 (- 5 diff) (org-get-priority txt)))
4531 'org-category category
4533 'todo-state todo-state)
4537 (defun org-agenda-get-blocks ()
4538 "Return the date-range information for agenda display."
4539 (let* ((props (list 'face nil
4540 'org-not-done-regexp org-not-done-regexp
4541 'org-todo-regexp org-todo-regexp
4542 'org-complex-heading-regexp org-complex-heading-regexp
4543 'mouse-face 'highlight
4545 (format "mouse-2 or RET jump to org file %s"
4546 (abbreviate-file-name buffer-file-name))))
4547 (regexp org-tr-regexp)
4548 (d0 (calendar-absolute-from-gregorian date))
4549 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4551 (goto-char (point-min))
4552 (while (re-search-forward regexp nil t)
4556 (setq timestr (match-string 0)
4559 d1 (time-to-days (org-time-string-to-time s1))
4560 d2 (time-to-days (org-time-string-to-time s2)))
4561 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4562 ;; Only allow days between the limits, because the normal
4563 ;; date stamps will catch the limits.
4565 (setq todo-state (org-get-todo-state))
4566 (setq donep (member todo-state org-done-keywords))
4567 (if (and donep org-agenda-skip-timestamp-if-done)
4569 (setq marker (org-agenda-new-marker (point)))
4570 (setq category (org-get-category))
4571 (if (not (re-search-backward "^\\*+ " nil t))
4572 (setq txt org-agenda-no-heading-message)
4573 (goto-char (match-beginning 0))
4574 (setq hdmarker (org-agenda-new-marker (point)))
4575 (setq tags (org-get-tags-at))
4576 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4577 (setq head (match-string 1))
4578 (setq txt (org-format-agenda-item
4580 (nth (if (= d1 d2) 0 1)
4581 org-agenda-timerange-leaders)
4582 (1+ (- d0 d1)) (1+ (- d2 d1)))
4585 (org-add-props txt props
4586 'org-marker marker 'org-hd-marker hdmarker
4587 'type "block" 'date date
4588 'todo-state todo-state
4589 'priority (org-get-priority txt) 'org-category category)
4592 ;; Sort the entries by expiration date.
4595 ;;; Agenda presentation and sorting
4597 (defvar org-prefix-has-time nil
4598 "A flag, set by `org-compile-prefix-format'.
4599 The flag is set if the currently compiled format contains a `%t'.")
4600 (defvar org-prefix-has-tag nil
4601 "A flag, set by `org-compile-prefix-format'.
4602 The flag is set if the currently compiled format contains a `%T'.")
4603 (defvar org-prefix-has-effort nil
4604 "A flag, set by `org-compile-prefix-format'.
4605 The flag is set if the currently compiled format contains a `%e'.")
4606 (defvar org-prefix-category-length nil
4607 "Used by `org-compile-prefix-format' to remember the category field widh.")
4608 (defvar org-prefix-category-max-length nil
4609 "Used by `org-compile-prefix-format' to remember the category field widh.")
4611 (defun org-format-agenda-item (extra txt &optional category tags dotime
4612 noprefix remove-re habitp)
4613 "Format TXT to be inserted into the agenda buffer.
4614 In particular, it adds the prefix and corresponding text properties. EXTRA
4615 must be a string and replaces the `%s' specifier in the prefix format.
4616 CATEGORY (string, symbol or nil) may be used to overrule the default
4617 category taken from local variable or file name. It will replace the `%c'
4618 specifier in the format. DOTIME, when non-nil, indicates that a
4619 time-of-day should be extracted from TXT for sorting of this entry, and for
4620 the `%t' specifier in the format. When DOTIME is a string, this string is
4621 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4622 only the correctly processes TXT should be returned - this is used by
4623 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4624 Any match of REMOVE-RE will be removed from TXT."
4626 ;; Diary entries sometimes have extra whitespace at the beginning
4627 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4629 ;; Fix the tags part in txt
4630 (setq txt (org-agenda-fix-displayed-tags
4632 org-agenda-show-inherited-tags
4633 org-agenda-hide-tags-regexp))
4634 (let* ((category (or category
4636 (if buffer-file-name
4637 (file-name-sans-extension
4638 (file-name-nondirectory buffer-file-name))
4640 ;; time, tag, effort are needed for the eval of the prefix format
4641 (tag (if tags (nth (1- (length tags)) tags) ""))
4643 (ts (if dotime (concat
4644 (if (stringp dotime) dotime "")
4645 (and org-agenda-search-headline-for-time txt))))
4646 (time-of-day (and dotime (org-get-time-of-day ts)))
4647 stamp plain s0 s1 s2 t1 t2 rtn srp l
4648 duration thecategory)
4649 (and (org-mode-p) buffer-file-name
4650 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4651 (when (and dotime time-of-day)
4652 ;; Extract starting and ending time and move them to prefix
4653 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4654 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4655 (setq s0 (match-string 0 ts)
4656 srp (and stamp (match-end 3))
4657 s1 (match-string (if plain 1 2) ts)
4658 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4660 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4661 ;; them, we might want to remove them there to avoid duplication.
4662 ;; The user can turn this off with a variable.
4663 (if (and org-prefix-has-time
4664 org-agenda-remove-times-when-in-prefix (or stamp plain)
4665 (string-match (concat (regexp-quote s0) " *") txt)
4666 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4667 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4668 (= (match-beginning 0) 0)
4670 (setq txt (replace-match "" nil nil txt))))
4671 ;; Normalize the time(s) to 24 hour
4672 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4673 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4674 ;; Compute the duration
4676 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4677 (string-to-number (substring s1 3)))
4679 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4680 (string-to-number (substring s2 3))))
4681 (org-agenda-default-appointment-duration
4682 (+ t1 org-agenda-default-appointment-duration))
4684 (setq duration (if t2 (- t2 t1)))))
4686 (when (and s1 (not s2) org-agenda-default-appointment-duration
4687 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4688 (let ((m (+ (string-to-number (match-string 2 s1))
4689 (* 60 (string-to-number (match-string 1 s1)))
4690 org-agenda-default-appointment-duration))
4692 (setq h (/ m 60) m (- m (* h 60)))
4693 (setq s2 (format "%02d:%02d" h m))))
4695 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4697 ;; Tags are in the string
4698 (if (or (eq org-agenda-remove-tags t)
4699 (and org-agenda-remove-tags
4700 org-prefix-has-tag))
4701 (setq txt (replace-match "" t t txt))
4702 (setq txt (replace-match
4703 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
4704 (match-string 2 txt))
4710 (or (get-text-property 0 'org-hd-marker txt)
4711 (get-text-property 0 'org-marker txt)))
4714 (setq neffort (org-hh:mm-string-to-minutes effort)
4715 effort (setq effort (concat "[" effort "]" )))))
4718 (while (string-match remove-re txt)
4719 (setq txt (replace-match "" t t txt))))
4721 ;; Create the final string
4724 ;; Prepare the variables needed in the eval of the compiled format
4725 (setq time (cond (s2 (concat s1 "-" s2))
4726 (s1 (concat s1 "......"))
4728 extra (or (and (not habitp) extra) "")
4729 category (if (symbolp category) (symbol-name category) category)
4730 thecategory (copy-sequence category))
4731 (if (string-match org-bracket-link-regexp category)
4733 (setq l (if (match-end 3)
4734 (- (match-end 3) (match-beginning 3))
4735 (- (match-end 1) (match-beginning 1))))
4736 (when (< l (or org-prefix-category-length 0))
4737 (setq category (copy-sequence category))
4738 (org-add-props category nil
4739 'extra-space (make-string
4740 (- org-prefix-category-length l 1) ?\ ))))
4741 (if (and org-prefix-category-max-length
4742 (>= (length category) org-prefix-category-max-length))
4743 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
4744 ;; Evaluate the compiled format
4745 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
4747 ;; And finally add the text properties
4748 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
4749 (org-add-props rtn nil
4750 'org-category (if thecategory (downcase thecategory) category)
4751 'tags (mapcar 'org-downcase-keep-props tags)
4752 'org-highest-priority org-highest-priority
4753 'org-lowest-priority org-lowest-priority
4754 'prefix-length (- (length rtn) (length txt))
4755 'time-of-day time-of-day
4758 'effort-minutes neffort
4764 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
4765 "Remove tags string from TXT, and add a modified list of tags.
4766 The modified list may contain inherited tags, and tags matched by
4767 `org-agenda-hide-tags-regexp' will be removed."
4768 (when (or add-inherited hide-re)
4769 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
4770 (setq txt (substring txt 0 (match-beginning 0))))
4773 (mapcar (lambda (tg)
4774 (if (or (and hide-re (string-match hide-re tg))
4775 (and (not add-inherited)
4776 (get-text-property 0 'inherited tg)))
4781 (let ((have-i (get-text-property 0 'inherited (car tags)))
4783 (setq txt (concat txt " :"
4786 (setq i (get-text-property 0 'inherited x))
4787 (if (and have-i (not i))
4793 (if have-i "::" ":"))))))
4796 (defun org-downcase-keep-props (s)
4797 (let ((props (text-properties-at 0 s)))
4798 (setq s (downcase s))
4799 (add-text-properties 0 (length s) props s)
4802 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
4803 (defvar org-agenda-sorting-strategy-selected nil)
4805 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
4807 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
4808 ((and todayp (member 'today (car org-agenda-time-grid))))
4809 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
4810 ((member 'weekly (car org-agenda-time-grid)))
4811 (t (throw 'exit list)))
4812 (let* ((have (delq nil (mapcar
4813 (lambda (x) (get-text-property 1 'time-of-day x))
4815 (string (nth 1 org-agenda-time-grid))
4816 (gridtimes (nth 2 org-agenda-time-grid))
4817 (req (car org-agenda-time-grid))
4818 (remove (member 'remove-match req))
4820 (if (and (member 'require-timed req) (not have))
4821 ;; don't show empty grid
4823 (while (setq time (pop gridtimes))
4824 (unless (and remove (member time have))
4825 (setq time (int-to-string time))
4826 (push (org-format-agenda-item
4828 (concat (substring time 0 -2) ":" (substring time -2)))
4831 1 (length (car new)) 'face 'org-time-grid (car new))))
4832 (if (member 'time-up org-agenda-sorting-strategy-selected)
4834 (append list new)))))
4836 (defun org-compile-prefix-format (key)
4837 "Compile the prefix format into a Lisp form that can be evaluated.
4838 The resulting form is returned and stored in the variable
4839 `org-prefix-format-compiled'."
4840 (setq org-prefix-has-time nil org-prefix-has-tag nil
4841 org-prefix-category-length nil org-prefix-has-effort nil)
4843 ((stringp org-agenda-prefix-format)
4844 org-agenda-prefix-format)
4845 ((assq key org-agenda-prefix-format)
4846 (cdr (assq key org-agenda-prefix-format)))
4847 (t " %-12:c%?-12t% s")))
4849 varform vars var e c f opt)
4850 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4852 (setq var (cdr (assoc (match-string 4 s)
4853 '(("c" . category) ("t" . time) ("s" . extra)
4854 ("T" . tag) ("e" . effort))))
4855 c (or (match-string 3 s) "")
4856 opt (match-beginning 1)
4857 start (1+ (match-beginning 0)))
4858 (if (equal var 'time) (setq org-prefix-has-time t))
4859 (if (equal var 'tag) (setq org-prefix-has-tag t))
4860 (if (equal var 'effort) (setq org-prefix-has-effort t))
4861 (setq f (concat "%" (match-string 2 s) "s"))
4862 (when (equal var 'category)
4863 (setq org-prefix-category-length
4864 (floor (abs (string-to-number (match-string 2 s)))))
4865 (setq org-prefix-category-max-length
4866 (let ((x (match-string 2 s)))
4868 (if (string-match "\\.[0-9]+" x)
4869 (string-to-number (substring (match-string 0 x) 1)))))))
4872 `(if (equal "" ,var)
4874 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
4875 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
4876 (setq s (replace-match "%s" t nil s))
4877 (push varform vars))
4878 (setq vars (nreverse vars))
4879 (setq org-prefix-format-compiled `(format ,s ,@vars))))
4881 (defun org-set-sorting-strategy (key)
4882 (if (symbolp (car org-agenda-sorting-strategy))
4884 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
4885 (setq org-agenda-sorting-strategy-selected
4886 (or (cdr (assq key org-agenda-sorting-strategy))
4887 (cdr (assq 'agenda org-agenda-sorting-strategy))
4888 '(time-up category-keep priority-down)))))
4890 (defun org-get-time-of-day (s &optional string mod24)
4891 "Check string S for a time of day.
4892 If found, return it as a military time number between 0 and 2400.
4893 If not found, return nil.
4894 The optional STRING argument forces conversion into a 5 character wide string
4898 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
4899 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
4900 (let* ((h (string-to-number (match-string 1 s)))
4901 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
4902 (ampm (if (match-end 4) (downcase (match-string 4 s))))
4903 (am-p (equal ampm "am"))
4904 (h1 (cond ((not ampm) h)
4905 ((= h 12) (if am-p 0 12))
4906 (t (+ h (if am-p 0 12)))))
4907 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
4909 (t0 (+ (* 100 h2) m))
4910 (t1 (concat (if (>= h1 24) "+" " ")
4911 (if (and org-agenda-time-leading-zero
4912 (< t0 1000)) "0" "")
4913 (if (< t0 100) "0" "")
4914 (if (< t0 10) "0" "")
4915 (int-to-string t0))))
4916 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
4918 (defun org-finalize-agenda-entries (list &optional nosort)
4919 "Sort and concatenate the agenda items."
4920 (setq list (mapcar 'org-agenda-highlight-todo list))
4923 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
4925 (defun org-agenda-highlight-todo (x)
4926 (let ((org-done-keywords org-done-keywords-for-agenda)
4927 (case-fold-search nil)
4931 (beginning-of-line 1)
4932 (setq re (org-get-at-bol 'org-todo-regexp))
4933 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
4934 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
4935 (add-text-properties (match-beginning 0) (match-end 1)
4936 (list 'face (org-get-todo-face 1)))
4937 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4938 (delete-region (match-beginning 1) (1- (match-end 0)))
4939 (goto-char (match-beginning 1))
4940 (insert (format org-agenda-todo-keyword-format s)))))
4941 (setq re (concat (get-text-property 0 'org-todo-regexp x))
4942 pl (get-text-property 0 'prefix-length x))
4944 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
4946 (add-text-properties
4947 (or (match-end 1) (match-end 0)) (match-end 0)
4948 (list 'face (org-get-todo-face (match-string 2 x)))
4950 (setq x (concat (substring x 0 (match-end 1))
4951 (format org-agenda-todo-keyword-format
4953 (org-add-props " " (text-properties-at 0 x))
4954 (substring x (match-end 3)))))
4957 (defsubst org-cmp-priority (a b)
4958 "Compare the priorities of string A and B."
4959 (let ((pa (or (get-text-property 1 'priority a) 0))
4960 (pb (or (get-text-property 1 'priority b) 0)))
4961 (cond ((> pa pb) +1)
4965 (defsubst org-cmp-effort (a b)
4966 "Compare the priorities of string A and B."
4967 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
4968 (ea (or (get-text-property 1 'effort-minutes a) def))
4969 (eb (or (get-text-property 1 'effort-minutes b) def)))
4970 (cond ((> ea eb) +1)
4974 (defsubst org-cmp-category (a b)
4975 "Compare the string values of categories of strings A and B."
4976 (let ((ca (or (get-text-property 1 'org-category a) ""))
4977 (cb (or (get-text-property 1 'org-category b) "")))
4978 (cond ((string-lessp ca cb) -1)
4979 ((string-lessp cb ca) +1)
4982 (defsubst org-cmp-todo-state (a b)
4983 "Compare the todo states of strings A and B."
4984 (let* ((ma (or (get-text-property 1 'org-marker a)
4985 (get-text-property 1 'org-hd-marker a)))
4986 (mb (or (get-text-property 1 'org-marker b)
4987 (get-text-property 1 'org-hd-marker b)))
4988 (fa (and ma (marker-buffer ma)))
4989 (fb (and mb (marker-buffer mb)))
4991 (or (and fa (with-current-buffer fa org-todo-keywords-1))
4992 (and fb (with-current-buffer fb org-todo-keywords-1))))
4993 (ta (or (get-text-property 1 'todo-state a) ""))
4994 (tb (or (get-text-property 1 'todo-state b) ""))
4995 (la (- (length (member ta todo-kwds))))
4996 (lb (- (length (member tb todo-kwds))))
4997 (donepa (member ta org-done-keywords-for-agenda))
4998 (donepb (member tb org-done-keywords-for-agenda)))
4999 (cond ((and donepa (not donepb)) -1)
5000 ((and (not donepa) donepb) +1)
5005 (defsubst org-cmp-tag (a b)
5006 "Compare the string values of the first tags of A and B."
5007 (let ((ta (car (last (get-text-property 1 'tags a))))
5008 (tb (car (last (get-text-property 1 'tags b)))))
5011 ((string-lessp ta tb) -1)
5012 ((string-lessp tb ta) +1)
5015 (defsubst org-cmp-time (a b)
5016 "Compare the time-of-day values of strings A and B."
5017 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5018 (ta (or (get-text-property 1 'time-of-day a) def))
5019 (tb (or (get-text-property 1 'time-of-day b) def)))
5020 (cond ((< ta tb) -1)
5024 (defsubst org-cmp-habit-p (a b)
5025 "Compare the todo states of strings A and B."
5026 (let ((ha (get-text-property 1 'org-habit-p a))
5027 (hb (get-text-property 1 'org-habit-p b)))
5028 (cond ((and ha (not hb)) -1)
5029 ((and (not ha) hb) +1)
5032 (defun org-entries-lessp (a b)
5033 "Predicate for sorting agenda entries."
5034 ;; The following variables will be used when the form is evaluated.
5035 ;; So even though the compiler complains, keep them.
5036 (let* ((time-up (org-cmp-time a b))
5037 (time-down (if time-up (- time-up) nil))
5038 (priority-up (org-cmp-priority a b))
5039 (priority-down (if priority-up (- priority-up) nil))
5040 (effort-up (org-cmp-effort a b))
5041 (effort-down (if effort-up (- effort-up) nil))
5042 (category-up (org-cmp-category a b))
5043 (category-down (if category-up (- category-up) nil))
5044 (category-keep (if category-up +1 nil))
5045 (tag-up (org-cmp-tag a b))
5046 (tag-down (if tag-up (- tag-up) nil))
5047 (todo-state-up (org-cmp-todo-state a b))
5048 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5049 (habit-up (org-cmp-habit-p a b))
5050 (habit-down (if habit-up (- habit-up) nil))
5051 user-defined-up user-defined-down)
5052 (if (and org-agenda-cmp-user-defined
5053 (functionp org-agenda-cmp-user-defined))
5054 (setq user-defined-up
5055 (funcall org-agenda-cmp-user-defined a b)
5056 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5058 (eval (cons 'or org-agenda-sorting-strategy-selected))
5059 '((-1 . t) (1 . nil) (nil . nil))))))
5061 ;;; Agenda restriction lock
5063 (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
5064 "Overlay to mark the headline to which agenda commands are restricted.")
5065 (org-overlay-put org-agenda-restriction-lock-overlay
5066 'face 'org-agenda-restriction-lock)
5067 (org-overlay-put org-agenda-restriction-lock-overlay
5068 'help-echo "Agendas are currently limited to this subtree.")
5069 (org-detach-overlay org-agenda-restriction-lock-overlay)
5071 (defun org-agenda-set-restriction-lock (&optional type)
5072 "Set restriction lock for agenda, to current subtree or file.
5073 Restriction will be the file if TYPE is `file', or if type is the
5074 universal prefix '(4), or if the cursor is before the first headline
5075 in the file. Otherwise, restriction will be to the current subtree."
5077 (and (equal type '(4)) (setq type 'file))
5080 ((org-at-heading-p) 'subtree)
5081 ((condition-case nil (org-back-to-heading t) (error nil))
5084 (if (eq type 'subtree)
5086 (setq org-agenda-restrict t)
5087 (setq org-agenda-overriding-restriction 'subtree)
5088 (put 'org-agenda-files 'org-restrict
5089 (list (buffer-file-name (buffer-base-buffer))))
5090 (org-back-to-heading t)
5091 (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5092 (move-marker org-agenda-restrict-begin (point))
5093 (move-marker org-agenda-restrict-end
5094 (save-excursion (org-end-of-subtree t)))
5095 (message "Locking agenda restriction to subtree"))
5096 (put 'org-agenda-files 'org-restrict
5097 (list (buffer-file-name (buffer-base-buffer))))
5098 (setq org-agenda-restrict nil)
5099 (setq org-agenda-overriding-restriction 'file)
5100 (move-marker org-agenda-restrict-begin nil)
5101 (move-marker org-agenda-restrict-end nil)
5102 (message "Locking agenda restriction to file"))
5103 (setq current-prefix-arg nil)
5104 (org-agenda-maybe-redo))
5106 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5107 "Remove the agenda restriction lock."
5109 (org-detach-overlay org-agenda-restriction-lock-overlay)
5110 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5111 (setq org-agenda-overriding-restriction nil)
5112 (setq org-agenda-restrict nil)
5113 (put 'org-agenda-files 'org-restrict nil)
5114 (move-marker org-agenda-restrict-begin nil)
5115 (move-marker org-agenda-restrict-end nil)
5116 (setq current-prefix-arg nil)
5117 (message "Agenda restriction lock removed")
5118 (or noupdate (org-agenda-maybe-redo)))
5120 (defun org-agenda-maybe-redo ()
5121 "If there is any window showing the agenda view, update it."
5122 (let ((w (get-buffer-window org-agenda-buffer-name t))
5123 (w0 (selected-window)))
5128 (if org-agenda-overriding-restriction
5129 (message "Agenda view shifted to new %s restriction"
5130 org-agenda-overriding-restriction)
5131 (message "Agenda restriction lock removed")))))
5135 (defun org-agenda-check-type (error &rest types)
5136 "Check if agenda buffer is of allowed type.
5137 If ERROR is non-nil, throw an error, otherwise just return nil."
5138 (if (memq org-agenda-type types)
5141 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5144 (defun org-agenda-quit ()
5145 "Exit agenda by removing the window or the buffer."
5147 (if org-agenda-columns-active
5149 (let ((buf (current-buffer)))
5150 (if (eq org-agenda-window-setup 'other-frame)
5153 (org-agenda-reset-markers)
5154 (org-columns-remove-overlays)
5155 (setq org-agenda-archives-mode nil)
5157 (and (not (eq org-agenda-window-setup 'current-window))
5158 (not (one-window-p))
5161 (org-agenda-reset-markers)
5162 (org-columns-remove-overlays)
5163 (setq org-agenda-archives-mode nil)))
5164 ;; Maybe restore the pre-agenda window configuration.
5165 (and org-agenda-restore-windows-after-quit
5166 (not (eq org-agenda-window-setup 'other-frame))
5167 org-pre-agenda-window-conf
5168 (set-window-configuration org-pre-agenda-window-conf))))
5170 (defun org-agenda-exit ()
5171 "Exit agenda by removing the window or the buffer.
5172 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5173 Org-mode buffers visited directly by the user will not be touched."
5175 (org-release-buffers org-agenda-new-buffers)
5176 (setq org-agenda-new-buffers nil)
5179 (defun org-agenda-execute (arg)
5180 "Execute another agenda command, keeping same window.\\<global-map>
5181 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
5183 (let ((org-agenda-window-setup 'current-window))
5186 (defun org-agenda-redo ()
5188 When this is the global TODO list, a prefix argument will be interpreted."
5190 (let* ((org-agenda-keep-modes t)
5191 (filter org-agenda-filter)
5192 (preset (get 'org-agenda-filter :preset-filter))
5193 (cols org-agenda-columns-active)
5194 (line (org-current-line))
5195 (window-line (- line (org-current-line (window-start))))
5196 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5197 (put 'org-agenda-filter :preset-filter nil)
5198 (and cols (org-columns-quit))
5199 (message "Rebuilding agenda buffer...")
5200 (org-let lprops '(eval org-agenda-redo-command))
5201 (setq org-agenda-undo-list nil
5202 org-agenda-pending-undo-list nil)
5203 (message "Rebuilding agenda buffer...done")
5204 (put 'org-agenda-filter :preset-filter preset)
5205 (and (or filter preset) (org-agenda-filter-apply filter))
5206 (and cols (interactive-p) (org-agenda-columns))
5207 (org-goto-line line)
5208 (recenter window-line)))
5211 (defvar org-global-tags-completion-table nil)
5212 (defvar org-agenda-filter-form nil)
5213 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5214 "Keep only those lines in the agenda buffer that have a specific tag.
5215 The tag is selected with its fast selection letter, as configured.
5216 With prefix argument STRIP, remove all lines that do have the tag.
5217 A lisp caller can specify CHAR. NARROW means that the new tag should be
5218 used to narrow the search - the interactive user can also press `-' or `+'
5219 to switch to narrowing."
5221 (let* ((alist org-tag-alist-for-agenda)
5222 (tag-chars (mapconcat
5223 (lambda (x) (if (and (not (symbolp (car x)))
5225 (char-to-string (cdr x))
5228 (efforts (org-split-string
5229 (or (cdr (assoc (concat org-effort-property "_ALL")
5230 org-global-properties))
5231 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5232 (effort-op org-agenda-filter-effort-default-operator)
5234 (inhibit-read-only t)
5235 (current org-agenda-filter)
5239 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5240 (if narrow "Narrow" "Filter") tag-chars
5241 (if org-agenda-auto-exclude-function "[RET], " ""))
5242 (setq char (read-char)))
5243 (when (member char '(?+ ?-))
5245 (cond ((equal char ?-) (setq strip t narrow t))
5246 ((equal char ?+) (setq strip nil narrow t)))
5248 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5249 (setq char (read-char)))
5250 (when (member char '(?< ?> ?= ??))
5251 ;; An effort operator
5252 (setq effort-op (char-to-string char))
5253 (setq alist nil) ; to make sure it will be interpreted as effort.
5254 (unless (equal char ??)
5255 (loop for i from 0 to 9 do
5259 (if (= i 9) "0" (int-to-string (1+ i)))
5260 "]" (nth i efforts))))
5261 (message "Effort%s: %s " effort-op effort-prompt)
5262 (setq char (read-char))
5263 (when (or (< char ?0) (> char ?9))
5264 (error "Need 1-9,0 to select effort" ))))
5265 (when (equal char ?\t)
5266 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5267 (org-set-local 'org-global-tags-completion-table
5268 (org-global-tags-completion-table)))
5269 (let ((completion-ignore-case t))
5270 (setq tag (org-icompleting-read
5271 "Tag: " org-global-tags-completion-table))))
5274 (org-agenda-filter-by-tag-show-all)
5275 (when org-agenda-auto-exclude-function
5276 (setq org-agenda-filter '())
5277 (dolist (tag (org-agenda-get-represented-tags))
5278 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5280 (push modifier org-agenda-filter))))
5281 (if (not (null org-agenda-filter))
5282 (org-agenda-filter-apply org-agenda-filter))))
5284 (org-agenda-filter-by-tag-show-all)
5285 (when (get 'org-agenda-filter :preset-filter)
5286 (org-agenda-filter-apply org-agenda-filter)))
5287 ((or (equal char ?\ )
5288 (setq a (rassoc char alist))
5289 (and (>= char ?0) (<= char ?9)
5290 (setq n (if (= char ?0) 9 (- char ?0 1))
5291 tag (concat effort-op (nth n efforts))
5296 (and tag (setq a (cons tag nil))))
5297 (org-agenda-filter-by-tag-show-all)
5299 (setq org-agenda-filter
5300 (cons (concat (if strip "-" "+") tag)
5301 (if narrow current nil)))
5302 (org-agenda-filter-apply org-agenda-filter))
5303 (t (error "Invalid tag selection character %c" char)))))
5305 (defun org-agenda-get-represented-tags ()
5306 "Get a list of all tags currently represented in the agenda."
5309 (goto-char (point-min))
5310 (while (setq p (next-single-property-change (point) 'tags))
5312 (mapc (lambda (x) (add-to-list 'tags x))
5313 (get-text-property (point) 'tags))))
5316 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5317 "Refine the current filter. See `org-agenda-filter-by-tag."
5319 (org-agenda-filter-by-tag strip char 'refine))
5321 (defun org-agenda-filter-make-matcher ()
5322 "Create the form that tests a line for the agenda filter."
5324 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5326 (if (member x '("-" "+"))
5327 (setq f1 (if (equal x "-") 'tags '(not tags)))
5328 (if (string-match "[<=>?]" x)
5329 (setq f1 (org-agenda-filter-effort-form x))
5330 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5331 (if (equal (string-to-char x) ?-)
5332 (setq f1 (list 'not f1))))
5334 (cons 'and (nreverse f))))
5336 (defun org-agenda-filter-effort-form (e)
5337 "Return the form to compare the effort of the current line with what E says.
5338 E looks line \"+<2:25\"."
5340 (setq e (substring e 1))
5341 (setq op (string-to-char e) e (substring e 1))
5342 (setq op (cond ((equal op ?<) '<=)
5346 (list 'org-agenda-compare-effort (list 'quote op)
5347 (org-hh:mm-string-to-minutes e))))
5349 (defun org-agenda-compare-effort (op value)
5350 "Compare the effort of the current line with VALUE, using OP.
5351 If the line does not have an effort defined, return nil."
5352 (let ((eff (org-get-at-bol 'effort-minutes)))
5355 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5358 (defun org-agenda-filter-apply (filter)
5359 "Set FILTER as the new agenda filter and apply it."
5361 (setq org-agenda-filter filter
5362 org-agenda-filter-form (org-agenda-filter-make-matcher))
5363 (org-agenda-set-mode-name)
5365 (goto-char (point-min))
5367 (if (org-get-at-bol 'org-marker)
5369 (setq tags (org-get-at-bol 'tags)) ; used in eval
5370 (if (not (eval org-agenda-filter-form))
5371 (org-agenda-filter-by-tag-hide-line))
5372 (beginning-of-line 2))
5373 (beginning-of-line 2))))))
5375 (defun org-agenda-filter-by-tag-hide-line ()
5377 (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
5379 (org-overlay-put ov 'invisible t)
5380 (org-overlay-put ov 'type 'tags-filter)
5381 (push ov org-agenda-filter-overlays)))
5383 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5384 (setq pos (or pos (point)))
5386 (dolist (ov (org-overlays-at pos))
5387 (when (and (org-overlay-get ov 'invisible)
5388 (eq (org-overlay-get ov 'type) 'tags-filter))
5390 (if (< (org-overlay-start ov) (point-at-eol))
5391 (org-move-overlay ov (point-at-eol)
5392 (org-overlay-end ov)))))))
5394 (defun org-agenda-filter-by-tag-show-all ()
5395 (mapc 'org-delete-overlay org-agenda-filter-overlays)
5396 (setq org-agenda-filter-overlays nil)
5397 (setq org-agenda-filter nil)
5398 (setq org-agenda-filter-form nil)
5399 (org-agenda-set-mode-name))
5401 (defun org-agenda-manipulate-query-add ()
5402 "Manipulate the query by adding a search term with positive selection.
5403 Positive selection means the term must be matched for selection of an entry."
5405 (org-agenda-manipulate-query ?\[))
5406 (defun org-agenda-manipulate-query-subtract ()
5407 "Manipulate the query by adding a search term with negative selection.
5408 Negative selection means term must not be matched for selection of an entry."
5410 (org-agenda-manipulate-query ?\]))
5411 (defun org-agenda-manipulate-query-add-re ()
5412 "Manipulate the query by adding a search regexp with positive selection.
5413 Positive selection means the regexp must match for selection of an entry."
5415 (org-agenda-manipulate-query ?\{))
5416 (defun org-agenda-manipulate-query-subtract-re ()
5417 "Manipulate the query by adding a search regexp with negative selection.
5418 Negative selection means regexp must not match for selection of an entry."
5420 (org-agenda-manipulate-query ?\}))
5421 (defun org-agenda-manipulate-query (char)
5423 ((memq org-agenda-type '(timeline agenda))
5424 (let ((org-agenda-include-inactive-timestamps t))
5426 (message "Display now includes inactive timestamps as well"))
5427 ((eq org-agenda-type 'search)
5429 'org-agenda-query-string
5430 (if org-agenda-last-search-view-search-was-boolean
5431 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5432 (?\{ . " +{}") (?\} . " -{}"))))
5434 (setq org-agenda-redo-command
5435 (list 'org-search-view
5437 org-agenda-query-string
5438 (+ (length org-agenda-query-string)
5439 (if (member char '(?\{ ?\})) 0 1))))
5440 (set-register org-agenda-query-register org-agenda-query-string)
5442 (t (error "Cannot manipulate query for %s-type agenda buffers"
5445 (defun org-add-to-string (var string)
5446 (set var (concat (symbol-value var) string)))
5448 (defun org-agenda-goto-date (date)
5449 "Jump to DATE in agenda."
5450 (interactive (list (org-read-date)))
5451 (org-agenda-list nil date))
5453 (defun org-agenda-goto-today ()
5456 (org-agenda-check-type t 'timeline 'agenda)
5457 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5459 (tdpos (goto-char tdpos))
5460 ((eq org-agenda-type 'agenda)
5461 (let* ((sd (time-to-days
5462 (time-subtract (current-time)
5463 (list 0 (* 3600 org-extend-today-until) 0))))
5464 (comp (org-agenda-compute-time-span sd org-agenda-span))
5465 (org-agenda-overriding-arguments org-agenda-last-arguments))
5466 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5467 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5469 (org-agenda-find-same-or-today-or-agenda)))
5470 (t (error "Cannot find today")))))
5472 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5474 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5475 (text-property-any (point-min) (point-max) 'org-today t)
5476 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5479 (defun org-agenda-later (arg)
5480 "Go forward in time by thee current span.
5481 With prefix ARG, go forward that many times the current span."
5483 (org-agenda-check-type t 'agenda)
5484 (let* ((span org-agenda-span)
5485 (sd org-starting-day)
5486 (greg (calendar-gregorian-from-absolute sd))
5487 (cnt (org-get-at-bol 'org-day-cnt))
5491 (setq sd (+ arg sd) nd 1))
5493 (setq sd (+ (* 7 arg) sd) nd 7))
5495 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5496 sd (calendar-absolute-from-gregorian greg2))
5497 (setcar greg2 (1+ (car greg2)))
5498 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5500 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5501 sd (calendar-absolute-from-gregorian greg2))
5502 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5503 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5504 (let ((org-agenda-overriding-arguments
5505 (list (car org-agenda-last-arguments) sd nd t)))
5507 (org-agenda-find-same-or-today-or-agenda cnt))))
5509 (defun org-agenda-earlier (arg)
5510 "Go backward in time by the current span.
5511 With prefix ARG, go backward that many times the current span."
5513 (org-agenda-later (- arg)))
5515 (defun org-agenda-view-mode-dispatch ()
5516 "Call one of the view mode commands."
5518 (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
5519 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
5520 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
5521 (let ((a (read-char-exclusive)))
5523 (?d (call-interactively 'org-agenda-day-view))
5524 (?w (call-interactively 'org-agenda-week-view))
5525 (?m (call-interactively 'org-agenda-month-view))
5526 (?y (call-interactively 'org-agenda-year-view))
5527 (?l (call-interactively 'org-agenda-log-mode))
5528 (?L (org-agenda-log-mode '(4)))
5529 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5530 (?a (call-interactively 'org-agenda-archives-mode))
5531 (?A (org-agenda-archives-mode 'files))
5532 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5533 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5534 (?G (call-interactively 'org-agenda-toggle-time-grid))
5535 (?D (call-interactively 'org-agenda-toggle-diary))
5536 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5537 (org-agenda-check-type t 'timeline 'agenda)
5539 (message "Display now includes inactive timestamps as well"))
5540 (?q (message "Abort"))
5541 (otherwise (error "Invalid key" )))))
5543 (defun org-agenda-day-view (&optional day-of-year)
5544 "Switch to daily view for agenda.
5545 With argument DAY-OF-YEAR, switch to that day of the year."
5547 (setq org-agenda-ndays 1)
5548 (org-agenda-change-time-span 'day day-of-year))
5549 (defun org-agenda-week-view (&optional iso-week)
5550 "Switch to daily view for agenda.
5551 With argument ISO-WEEK, switch to the corresponding ISO week.
5552 If ISO-WEEK has more then 2 digits, only the last two encode the
5553 week. Any digits before this encode a year. So 200712 means
5554 week 12 of year 2007. Years in the range 1938-2037 can also be
5555 written as 2-digit years."
5557 (setq org-agenda-ndays 7)
5558 (org-agenda-change-time-span 'week iso-week))
5559 (defun org-agenda-month-view (&optional month)
5560 "Switch to monthly view for agenda.
5561 With argument MONTH, switch to that month."
5563 (org-agenda-change-time-span 'month month))
5564 (defun org-agenda-year-view (&optional year)
5565 "Switch to yearly view for agenda.
5566 With argument YEAR, switch to that year.
5567 If MONTH has more then 2 digits, only the last two encode the
5568 month. Any digits before this encode a year. So 200712 means
5569 December year 2007. Years in the range 1938-2037 can also be
5570 written as 2-digit years."
5573 (setq year (org-small-year-to-year year)))
5574 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5575 (org-agenda-change-time-span 'year year)
5578 (defun org-agenda-change-time-span (span &optional n)
5579 "Change the agenda view to SPAN.
5580 SPAN may be `day', `week', `month', `year'."
5581 (org-agenda-check-type t 'agenda)
5582 (if (and (not n) (equal org-agenda-span span))
5583 (error "Viewing span is already \"%s\"" span))
5584 (let* ((sd (or (org-get-at-bol 'day)
5586 (computed (org-agenda-compute-time-span sd span n))
5587 (org-agenda-overriding-arguments
5588 (list (car org-agenda-last-arguments)
5589 (car computed) (cdr computed) t)))
5591 (org-agenda-find-same-or-today-or-agenda))
5592 (org-agenda-set-mode-name)
5593 (message "Switched to %s view" span))
5595 (defun org-agenda-compute-time-span (sd span &optional n)
5596 "Compute starting date and number of days for agenda.
5597 SPAN may be `day', `week', `month', `year'. The return value
5598 is a cons cell with the starting date and the number of days,
5599 so that the date SD will be in that range."
5600 (let* ((greg (calendar-gregorian-from-absolute sd))
5604 nd w1 y1 m1 thisweek)
5608 (setq sd (+ (calendar-absolute-from-gregorian
5613 (let* ((nt (calendar-day-of-week
5614 (calendar-gregorian-from-absolute sd)))
5615 (d (if org-agenda-start-on-weekday
5616 (- nt org-agenda-start-on-weekday)
5618 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5621 (setq thisweek (car (calendar-iso-from-absolute sd)))
5623 (setq y1 (org-small-year-to-year (/ n 100))
5626 (calendar-absolute-from-iso
5628 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5631 (when (and n (> n 99))
5632 (setq y1 (org-small-year-to-year (/ n 100))
5634 (setq sd (calendar-absolute-from-gregorian
5635 (list (or n mg) 1 (or y1 yg)))
5636 nd (- (calendar-absolute-from-gregorian
5637 (list (1+ (or n mg)) 1 (or y1 yg)))
5640 (setq sd (calendar-absolute-from-gregorian
5641 (list 1 1 (or n yg)))
5642 nd (- (calendar-absolute-from-gregorian
5643 (list 1 1 (1+ (or n yg))))
5647 (defun org-agenda-next-date-line (&optional arg)
5648 "Jump to the next line indicating a date in agenda buffer."
5650 (org-agenda-check-type t 'agenda 'timeline)
5651 (beginning-of-line 1)
5652 ;; This does not work if user makes date format that starts with a blank
5653 (if (looking-at "^\\S-") (forward-char 1))
5654 (if (not (re-search-forward "^\\S-" nil t arg))
5657 (error "No next date after this line in this buffer")))
5658 (goto-char (match-beginning 0)))
5660 (defun org-agenda-previous-date-line (&optional arg)
5661 "Jump to the previous line indicating a date in agenda buffer."
5663 (org-agenda-check-type t 'agenda 'timeline)
5664 (beginning-of-line 1)
5665 (if (not (re-search-backward "^\\S-" nil t arg))
5666 (error "No previous date before this line in this buffer")))
5668 ;; Initialize the highlight
5669 (defvar org-hl (org-make-overlay 1 1))
5670 (org-overlay-put org-hl 'face 'highlight)
5672 (defun org-highlight (begin end &optional buffer)
5673 "Highlight a region with overlay."
5674 (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
5675 org-hl begin end (or buffer (current-buffer))))
5677 (defun org-unhighlight ()
5678 "Detach overlay INDEX."
5679 (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
5681 ;; FIXME this is currently not used.
5682 (defun org-highlight-until-next-command (beg end &optional buffer)
5683 "Move the highlight overlay to BEG/END, remove it before the next command."
5684 (org-highlight beg end buffer)
5685 (add-hook 'pre-command-hook 'org-unhighlight-once))
5686 (defun org-unhighlight-once ()
5687 "Remove the highlight from its position, and this function from the hook."
5688 (remove-hook 'pre-command-hook 'org-unhighlight-once)
5691 (defun org-agenda-follow-mode ()
5692 "Toggle follow mode in an agenda buffer."
5694 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
5695 (org-agenda-set-mode-name)
5696 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5698 (message "Follow mode is %s"
5699 (if org-agenda-follow-mode "on" "off")))
5701 (defun org-agenda-entry-text-mode (&optional arg)
5702 "Toggle entry text mode in an agenda buffer."
5705 (setq org-agenda-entry-text-mode t)
5706 (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
5707 (org-agenda-entry-text-hide)
5708 (and org-agenda-entry-text-mode
5709 (let ((org-agenda-entry-text-maxlines
5710 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5711 (org-agenda-entry-text-show)))
5712 (org-agenda-set-mode-name)
5713 (message "Entry text mode is %s. Maximum number of lines is %d"
5714 (if org-agenda-entry-text-mode "on" "off")
5715 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5717 (defun org-agenda-clockreport-mode ()
5718 "Toggle clocktable mode in an agenda buffer."
5720 (org-agenda-check-type t 'agenda)
5721 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
5722 (org-agenda-set-mode-name)
5724 (message "Clocktable mode is %s"
5725 (if org-agenda-clockreport-mode "on" "off")))
5727 (defun org-agenda-log-mode (&optional special)
5728 "Toggle log mode in an agenda buffer.
5729 With argument SPECIAL, show all possible log items, not only the ones
5730 configured in `org-agenda-log-mode-items'.
5731 With a double `C-u' prefix arg, show *only* log items, nothing else."
5733 (org-agenda-check-type t 'agenda 'timeline)
5734 (setq org-agenda-show-log
5735 (if (equal special '(16))
5737 (if special '(closed clock state)
5738 (not org-agenda-show-log))))
5739 (org-agenda-set-mode-name)
5741 (message "Log mode is %s"
5742 (if org-agenda-show-log "on" "off")))
5744 (defun org-agenda-archives-mode (&optional with-files)
5745 "Toggle inclusion of items in trees marked with :ARCHIVE:.
5746 When called with a prefix argument, include all archive files as well."
5748 (setq org-agenda-archives-mode
5749 (if with-files t (if org-agenda-archives-mode nil 'trees)))
5750 (org-agenda-set-mode-name)
5755 ((eq org-agenda-archives-mode nil)
5756 "No archives are included")
5757 ((eq org-agenda-archives-mode 'trees)
5758 (format "Trees with :%s: tag are included" org-archive-tag))
5759 ((eq org-agenda-archives-mode t)
5760 (format "Trees with :%s: tag and all active archive files are included"
5761 org-archive-tag)))))
5763 (defun org-agenda-toggle-diary ()
5764 "Toggle diary inclusion in an agenda buffer."
5766 (org-agenda-check-type t 'agenda)
5767 (setq org-agenda-include-diary (not org-agenda-include-diary))
5769 (org-agenda-set-mode-name)
5770 (message "Diary inclusion turned %s"
5771 (if org-agenda-include-diary "on" "off")))
5773 (defun org-agenda-toggle-time-grid ()
5774 "Toggle time grid in an agenda buffer."
5776 (org-agenda-check-type t 'agenda)
5777 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
5779 (org-agenda-set-mode-name)
5780 (message "Time-grid turned %s"
5781 (if org-agenda-use-time-grid "on" "off")))
5783 (defun org-agenda-set-mode-name ()
5784 "Set the mode name to indicate all the small mode settings."
5786 (concat "Org-Agenda"
5787 (if (equal org-agenda-ndays 1) " Day" "")
5788 (if (equal org-agenda-ndays 7) " Week" "")
5789 (if org-agenda-follow-mode " Follow" "")
5790 (if org-agenda-entry-text-mode " ETxt" "")
5791 (if org-agenda-include-diary " Diary" "")
5792 (if org-agenda-use-time-grid " Grid" "")
5793 (if (and (boundp 'org-habit-show-habits)
5794 org-habit-show-habits) " Habit" "")
5795 (if (consp org-agenda-show-log) " LogAll"
5796 (if org-agenda-show-log " Log" ""))
5797 (if (or org-agenda-filter (get 'org-agenda-filter
5799 (concat " {" (mapconcat
5801 (append (get 'org-agenda-filter
5803 org-agenda-filter) "") "}")
5805 (if org-agenda-archives-mode
5806 (if (eq org-agenda-archives-mode t)
5808 (format " :%s:" org-archive-tag))
5810 (if org-agenda-clockreport-mode " Clock" "")))
5811 (force-mode-line-update))
5813 (defun org-agenda-post-command-hook ()
5814 (setq org-agenda-type
5815 (or (get-text-property (point) 'org-agenda-type)
5816 (get-text-property (max (point-min) (1- (point)))
5817 'org-agenda-type))))
5819 (defun org-agenda-next-line ()
5820 "Move cursor to the next line, and show if follow-mode is active."
5822 (call-interactively 'next-line)
5823 (org-agenda-do-context-action))
5825 (defun org-agenda-previous-line ()
5826 "Move cursor to the previous line, and show if follow-mode is active."
5829 (call-interactively 'previous-line)
5830 (org-agenda-do-context-action))
5832 (defun org-agenda-do-context-action ()
5833 "Show outline path and, maybe, follow-mode window."
5834 (let ((m (org-get-at-bol 'org-marker)))
5835 (if (and org-agenda-follow-mode m)
5837 (if (and m org-agenda-show-outline-path)
5838 (org-with-point-at m
5839 (org-display-outline-path t)))))
5841 (defun org-agenda-show-priority ()
5842 "Show the priority of the current item.
5843 This priority is composed of the main priority given with the [#A] cookies,
5844 and by additional input from the age of a schedules or deadline entry."
5846 (let* ((pri (org-get-at-bol 'priority)))
5847 (message "Priority is %d" (if pri pri -1000))))
5849 (defun org-agenda-show-tags ()
5850 "Show the tags applicable to the current item."
5852 (let* ((tags (org-get-at-bol 'tags)))
5854 (message "Tags are :%s:"
5855 (org-no-properties (mapconcat 'identity tags ":")))
5856 (message "No tags associated with this line"))))
5858 (defun org-agenda-goto (&optional highlight)
5859 "Go to the Org-mode file which contains the item at point."
5861 (let* ((marker (or (org-get-at-bol 'org-marker)
5862 (org-agenda-error)))
5863 (buffer (marker-buffer marker))
5864 (pos (marker-position marker)))
5865 (switch-to-buffer-other-window buffer)
5869 (org-show-context 'agenda)
5871 (and (outline-next-heading)
5872 (org-flag-heading nil)))) ; show the next heading
5873 (recenter (/ (window-height) 2))
5874 (run-hooks 'org-agenda-after-show-hook)
5875 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
5877 (defvar org-agenda-after-show-hook nil
5878 "Normal hook run after an item has been shown from the agenda.
5879 Point is in the buffer where the item originated.")
5881 (defun org-agenda-kill ()
5882 "Kill the entry or subtree belonging to the current agenda entry."
5884 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5885 (let* ((marker (or (org-get-at-bol 'org-marker)
5886 (org-agenda-error)))
5887 (buffer (marker-buffer marker))
5888 (pos (marker-position marker))
5889 (type (org-get-at-bol 'type))
5890 dbeg dend (n 0) conf)
5891 (org-with-remote-undo buffer
5892 (with-current-buffer buffer
5895 (if (and (org-mode-p) (not (member type '("sexp"))))
5896 (setq dbeg (progn (org-back-to-heading t) (point))
5897 dend (org-end-of-subtree t t))
5898 (setq dbeg (point-at-bol)
5899 dend (min (point-max) (1+ (point-at-eol)))))
5901 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
5902 (setq conf (or (eq t org-agenda-confirm-kill)
5903 (and (numberp org-agenda-confirm-kill)
5904 (> n org-agenda-confirm-kill))))
5907 (format "Delete entry with %d lines in buffer \"%s\"? "
5908 n (buffer-name buffer))))
5910 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
5911 (with-current-buffer buffer (delete-region dbeg dend))
5912 (message "Agenda item and source killed"))))
5914 (defvar org-archive-default-command)
5915 (defun org-agenda-archive-default ()
5916 "Archive the entry or subtree belonging to the current agenda entry."
5918 (require 'org-archive)
5919 (org-agenda-archive-with org-archive-default-command))
5921 (defun org-agenda-archive-default-with-confirmation ()
5922 "Archive the entry or subtree belonging to the current agenda entry."
5924 (require 'org-archive)
5925 (org-agenda-archive-with org-archive-default-command 'confirm))
5927 (defun org-agenda-archive ()
5928 "Archive the entry or subtree belonging to the current agenda entry."
5930 (org-agenda-archive-with 'org-archive-subtree))
5932 (defun org-agenda-archive-to-archive-sibling ()
5933 "Move the entry to the archive sibling."
5935 (org-agenda-archive-with 'org-archive-to-archive-sibling))
5937 (defun org-agenda-archive-with (cmd &optional confirm)
5938 "Move the entry to the archive sibling."
5940 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5941 (let* ((marker (or (org-get-at-bol 'org-marker)
5942 (org-agenda-error)))
5943 (buffer (marker-buffer marker))
5944 (pos (marker-position marker)))
5945 (org-with-remote-undo buffer
5946 (with-current-buffer buffer
5949 (not (y-or-n-p "Archive this subtree or entry? ")))
5953 (org-remove-subtree-entries-from-agenda)
5954 (org-back-to-heading t)
5956 (error "Archiving works only in Org-mode files"))))))
5958 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
5959 "Remove all lines in the agenda that correspond to a given subtree.
5960 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5961 If this information is not given, the function uses the tree at point."
5962 (let ((buf (or buf (current-buffer))) m p)
5964 (unless (and beg end)
5965 (org-back-to-heading t)
5967 (org-end-of-subtree t)
5969 (set-buffer (get-buffer org-agenda-buffer-name))
5971 (goto-char (point-max))
5972 (beginning-of-line 1)
5974 (when (and (setq m (org-get-at-bol 'org-marker))
5975 (equal buf (marker-buffer m))
5976 (setq p (marker-position m))
5979 (let ((inhibit-read-only t))
5980 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5981 (beginning-of-line 0))))))
5983 (defun org-agenda-refile (&optional goto rfloc)
5984 "Refile the item at point."
5986 (if (equal goto '(16))
5987 (org-refile-goto-last-stored)
5988 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
5989 (org-agenda-error)))
5990 (buffer (marker-buffer marker))
5991 (pos (marker-position marker))
5993 (org-refile-get-location
5994 (if goto "Goto: " "Refile to: ") buffer
5995 org-refile-allow-creating-parent-nodes))))
5996 (with-current-buffer buffer
6001 (org-remove-subtree-entries-from-agenda)
6002 (org-refile goto buffer rfloc)))))))
6004 (defun org-agenda-open-link (&optional arg)
6005 "Follow the link in the current line, if any.
6006 This looks for a link in the displayed line in the agenda. It also looks
6007 at the text of the entry itself."
6009 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6010 (org-get-at-bol 'org-marker)))
6011 (buffer (and marker (marker-buffer marker)))
6012 (prefix (buffer-substring
6015 (or (org-get-at-bol 'prefix-length) 0)))))
6018 (with-current-buffer buffer
6023 (org-offer-links-in-entry arg prefix)))))
6024 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6026 (beginning-of-line 1)
6027 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6028 (org-open-link-from-string (match-string 1)))
6029 (t (error "No link to open here")))))
6031 (defun org-agenda-copy-local-variable (var)
6032 "Get a variable from a referenced buffer and install it here."
6033 (let ((m (org-get-at-bol 'org-marker)))
6034 (when (and m (buffer-live-p (marker-buffer m)))
6035 (org-set-local var (with-current-buffer (marker-buffer m)
6036 (symbol-value var))))))
6038 (defun org-agenda-switch-to (&optional delete-other-windows)
6039 "Go to the Org-mode file which contains the item at point."
6041 (if (and org-return-follows-link
6042 (not (org-get-at-bol 'org-marker))
6043 (org-in-regexp org-bracket-link-regexp))
6044 (org-open-link-from-string (match-string 0))
6045 (let* ((marker (or (org-get-at-bol 'org-marker)
6046 (org-agenda-error)))
6047 (buffer (marker-buffer marker))
6048 (pos (marker-position marker)))
6049 (switch-to-buffer buffer)
6050 (and delete-other-windows (delete-other-windows))
6054 (org-show-context 'agenda)
6056 (and (outline-next-heading)
6057 (org-flag-heading nil))))))) ; show the next heading
6059 (defun org-agenda-goto-mouse (ev)
6060 "Go to the Org-mode file which contains the item at the mouse click."
6062 (mouse-set-point ev)
6065 (defun org-agenda-show (&optional full-entry)
6066 "Display the Org-mode file which contains the item at point.
6067 With prefix argument FULL-ENTRY, make the entire entry visible
6068 if it was hidden in the outline."
6070 (let ((win (selected-window)))
6072 (let ((org-show-entry-below t))
6073 (org-agenda-goto t))
6074 (org-agenda-goto t))
6075 (select-window win)))
6077 (defvar org-agenda-show-window nil)
6078 (defun org-agenda-show-and-scroll-up ()
6079 "Display the Org-mode file which contains the item at point.
6080 When called repeatedly, scroll the window that is displaying the buffer."
6082 (let ((win (selected-window)))
6083 (if (and (window-live-p org-agenda-show-window)
6084 (eq this-command last-command))
6086 (select-window org-agenda-show-window)
6087 (ignore-errors (scroll-up)))
6090 (setq org-agenda-show-window (selected-window)))
6091 (select-window win)))
6093 (defun org-agenda-show-scroll-down ()
6094 "Scroll down the window showing the agenda."
6096 (let ((win (selected-window)))
6097 (when (window-live-p org-agenda-show-window)
6098 (select-window org-agenda-show-window)
6099 (ignore-errors (scroll-down))
6100 (select-window win))))
6102 (defun org-agenda-show-1 (&optional more)
6103 "Display the Org-mode file which contains the item at point.
6104 The prefix arg selects the amount of information to display:
6107 1 just show the entry according to defaults.
6108 2 show the children view
6109 3 show the subtree view
6110 4 show the entire subtree and any LOGBOOK drawers
6111 5 show the entire subtree and any drawers
6112 With prefix argument FULL-ENTRY, make the entire entry visible
6113 if it was hidden in the outline."
6115 (let ((win (selected-window)))
6117 (org-recenter-heading 1)
6122 (org-back-to-heading)
6123 (run-hook-with-args 'org-cycle-hook 'folded))
6124 (message "Remote: FOLDED"))
6125 ((and (interactive-p) (= more 1))
6126 (message "Remote: show with default settings"))
6131 (org-back-to-heading)
6132 (run-hook-with-args 'org-cycle-hook 'children))
6133 (message "Remote: CHILDREN"))
6137 (org-back-to-heading)
6138 (run-hook-with-args 'org-cycle-hook 'subtree))
6139 (message "Remote: SUBTREE"))
6141 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6143 (concat "^[ \t]*:\\("
6144 (mapconcat 'regexp-quote org-drawers "\\|")
6148 (org-back-to-heading)
6149 (org-cycle-hide-drawers 'subtree)))
6150 (message "Remote: SUBTREE AND LOGBOOK"))
6153 (message "Remote: SUBTREE AND ALL DRAWERS")))
6154 (select-window win)))
6156 (defun org-recenter-heading (n)
6158 (org-back-to-heading)
6161 (defvar org-agenda-cycle-counter nil)
6162 (defun org-agenda-cycle-show (&optional n)
6163 "Show the current entry in another window, with default settings.
6164 Default settings are taken from `org-show-hierarchy-above' and siblings.
6165 When use repeatedly in immediate succession, the remote entry will cycle
6168 children -> subtree -> folded
6170 When called with a numeric prefix arg, that arg will be passed through to
6171 `org-agenda-show-1'. For the interpretation of that argument, see the
6172 docstring of `org-agenda-show-1'."
6175 (setq org-agenda-cycle-counter n)
6176 (if (not (eq last-command this-command))
6177 (setq org-agenda-cycle-counter 1)
6178 (if (equal org-agenda-cycle-counter 0)
6179 (setq org-agenda-cycle-counter 2)
6180 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6181 (if (> org-agenda-cycle-counter 3)
6182 (setq org-agenda-cycle-counter 0)))))
6183 (org-agenda-show-1 org-agenda-cycle-counter))
6185 (defun org-agenda-recenter (arg)
6186 "Display the Org-mode file which contains the item at point and recenter."
6188 (let ((win (selected-window)))
6191 (select-window win)))
6193 (defun org-agenda-show-mouse (ev)
6194 "Display the Org-mode file which contains the item at the mouse click."
6196 (mouse-set-point ev)
6199 (defun org-agenda-check-no-diary ()
6200 "Check if the entry is a diary link and abort if yes."
6201 (if (org-get-at-bol 'org-agenda-diary-link)
6202 (org-agenda-error)))
6204 (defun org-agenda-error ()
6205 (error "Command not allowed in this line"))
6207 (defun org-agenda-tree-to-indirect-buffer ()
6208 "Show the subtree corresponding to the current entry in an indirect buffer.
6209 This calls the command `org-tree-to-indirect-buffer' from the original
6211 With numerical prefix arg ARG, go up to this level and then take that tree.
6212 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
6215 (org-agenda-check-no-diary)
6216 (let* ((marker (or (org-get-at-bol 'org-marker)
6217 (org-agenda-error)))
6218 (buffer (marker-buffer marker))
6219 (pos (marker-position marker)))
6220 (with-current-buffer buffer
6223 (call-interactively 'org-tree-to-indirect-buffer)))))
6225 (defvar org-last-heading-marker (make-marker)
6226 "Marker pointing to the headline that last changed its TODO state
6227 by a remote command from the agenda.")
6229 (defun org-agenda-todo-nextset ()
6230 "Switch TODO entry to next sequence."
6232 (org-agenda-todo 'nextset))
6234 (defun org-agenda-todo-previousset ()
6235 "Switch TODO entry to previous sequence."
6237 (org-agenda-todo 'previousset))
6239 (defun org-agenda-todo (&optional arg)
6240 "Cycle TODO state of line at point, also in Org-mode file.
6241 This changes the line at point, all other lines in the agenda referring to
6242 the same tree node, and the headline of the tree node in the Org-mode file."
6244 (org-agenda-check-no-diary)
6245 (let* ((col (current-column))
6246 (marker (or (org-get-at-bol 'org-marker)
6247 (org-agenda-error)))
6248 (buffer (marker-buffer marker))
6249 (pos (marker-position marker))
6250 (hdmarker (org-get-at-bol 'org-hd-marker))
6251 (todayp (equal (org-get-at-bol 'day)
6252 (time-to-days (current-time))))
6253 (inhibit-read-only t)
6254 org-agenda-headline-snapshot-before-repeat newhead just-one)
6255 (org-with-remote-undo buffer
6256 (with-current-buffer buffer
6259 (org-show-context 'agenda)
6261 (and (outline-next-heading)
6262 (org-flag-heading nil))) ; show the next heading
6263 (let ((current-prefix-arg arg))
6264 (call-interactively 'org-todo))
6265 (and (bolp) (forward-char 1))
6266 (setq newhead (org-get-heading))
6267 (when (and (org-bound-and-true-p
6268 org-agenda-headline-snapshot-before-repeat)
6269 (not (equal org-agenda-headline-snapshot-before-repeat
6272 (setq newhead org-agenda-headline-snapshot-before-repeat
6275 (org-back-to-heading)
6276 (move-marker org-last-heading-marker (point))))
6277 (beginning-of-line 1)
6279 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6280 (org-move-to-column col))))
6282 (defun org-agenda-add-note (&optional arg)
6283 "Add a time-stamped note to the entry at point."
6285 (org-agenda-check-no-diary)
6286 (let* ((marker (or (org-get-at-bol 'org-marker)
6287 (org-agenda-error)))
6288 (buffer (marker-buffer marker))
6289 (pos (marker-position marker))
6290 (hdmarker (org-get-at-bol 'org-hd-marker))
6291 (inhibit-read-only t))
6292 (with-current-buffer buffer
6295 (org-show-context 'agenda)
6297 (and (outline-next-heading)
6298 (org-flag-heading nil))) ; show the next heading
6301 (defun org-agenda-change-all-lines (newhead hdmarker
6302 &optional fixface just-this)
6303 "Change all lines in the agenda buffer which match HDMARKER.
6304 The new content of the line will be NEWHEAD (as modified by
6305 `org-format-agenda-item'). HDMARKER is checked with
6306 `equal' against all `org-hd-marker' text properties in the file.
6307 If FIXFACE is non-nil, the face of each item is modified according to
6309 If JUST-THIS is non-nil, change just the current line, not all.
6310 If FORCE-TAGS is non nil, the car of it returns the new tags."
6311 (let* ((inhibit-read-only t)
6312 (line (org-current-line))
6313 (thetags (with-current-buffer (marker-buffer hdmarker)
6314 (save-excursion (save-restriction (widen)
6315 (goto-char hdmarker)
6316 (org-get-tags-at)))))
6317 props m pl undone-face done-face finish new dotime cat tags)
6319 (goto-char (point-max))
6320 (beginning-of-line 1)
6322 (setq finish (bobp))
6323 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6324 (or (not just-this) (= (org-current-line) line))
6326 (setq props (text-properties-at (point))
6327 dotime (org-get-at-bol 'dotime)
6328 cat (org-get-at-bol 'org-category)
6330 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6331 pl (org-get-at-bol 'prefix-length)
6332 undone-face (org-get-at-bol 'undone-face)
6333 done-face (org-get-at-bol 'done-face))
6334 (goto-char (+ (point) pl))
6335 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6338 (beginning-of-line 1)
6339 (and (looking-at ".*\n?") (replace-match "")))
6341 (replace-match new t t)
6342 (beginning-of-line 1)
6343 (add-text-properties (point-at-bol) (point-at-eol) props)
6345 (add-text-properties
6346 (point-at-bol) (point-at-eol)
6348 (if org-last-todo-state-is-todo
6349 undone-face done-face))))
6350 (org-agenda-highlight-todo 'line)
6351 (beginning-of-line 1))
6352 (t (error "Line update did not work"))))
6353 (beginning-of-line 0)))
6354 (org-finalize-agenda)))
6356 (defun org-agenda-align-tags (&optional line)
6357 "Align all tags in agenda items to `org-agenda-tags-column'."
6358 (let ((inhibit-read-only t) l c)
6360 (goto-char (if line (point-at-bol) (point-min)))
6361 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
6362 (if line (point-at-eol) nil) t)
6363 (add-text-properties
6364 (match-beginning 2) (match-end 2)
6365 (list 'face (delq nil (let ((prop (get-text-property
6366 (match-beginning 2) 'face)))
6367 (or (listp prop) (setq prop (list prop)))
6368 (if (memq 'org-tag prop)
6370 (cons 'org-tag prop))))))
6371 (setq l (- (match-end 2) (match-beginning 2))
6372 c (if (< org-agenda-tags-column 0)
6373 (- (abs org-agenda-tags-column) l)
6374 org-agenda-tags-column))
6375 (delete-region (match-beginning 1) (match-end 1))
6376 (goto-char (match-beginning 1))
6377 (insert (org-add-props
6378 (make-string (max 1 (- c (current-column))) ?\ )
6379 (text-properties-at (point)))))
6380 (goto-char (point-min))
6381 (org-font-lock-add-tag-faces (point-max)))))
6383 (defun org-agenda-priority-up ()
6384 "Increase the priority of line at point, also in Org-mode file."
6386 (org-agenda-priority 'up))
6388 (defun org-agenda-priority-down ()
6389 "Decrease the priority of line at point, also in Org-mode file."
6391 (org-agenda-priority 'down))
6393 (defun org-agenda-priority (&optional force-direction)
6394 "Set the priority of line at point, also in Org-mode file.
6395 This changes the line at point, all other lines in the agenda referring to
6396 the same tree node, and the headline of the tree node in the Org-mode file."
6398 (unless org-enable-priority-commands
6399 (error "Priority commands are disabled"))
6400 (org-agenda-check-no-diary)
6401 (let* ((marker (or (org-get-at-bol 'org-marker)
6402 (org-agenda-error)))
6403 (hdmarker (org-get-at-bol 'org-hd-marker))
6404 (buffer (marker-buffer hdmarker))
6405 (pos (marker-position hdmarker))
6406 (inhibit-read-only t)
6408 (org-with-remote-undo buffer
6409 (with-current-buffer buffer
6412 (org-show-context 'agenda)
6414 (and (outline-next-heading)
6415 (org-flag-heading nil))) ; show the next heading
6416 (funcall 'org-priority force-direction)
6418 (setq newhead (org-get-heading)))
6419 (org-agenda-change-all-lines newhead hdmarker)
6420 (beginning-of-line 1))))
6422 ;; FIXME: should fix the tags property of the agenda line.
6423 (defun org-agenda-set-tags (&optional tag onoff)
6424 "Set tags for the current headline."
6426 (org-agenda-check-no-diary)
6427 (if (and (org-region-active-p) (interactive-p))
6428 (call-interactively 'org-change-tag-in-region)
6429 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6430 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6431 (org-agenda-error)))
6432 (buffer (marker-buffer hdmarker))
6433 (pos (marker-position hdmarker))
6434 (inhibit-read-only t)
6436 (org-with-remote-undo buffer
6437 (with-current-buffer buffer
6441 (org-show-context 'agenda))
6443 (and (outline-next-heading)
6444 (org-flag-heading nil))) ; show the next heading
6447 (org-toggle-tag tag onoff)
6448 (call-interactively 'org-set-tags))
6450 (setq newhead (org-get-heading)))
6451 (org-agenda-change-all-lines newhead hdmarker)
6452 (beginning-of-line 1)))))
6454 (defun org-agenda-set-property ()
6455 "Set a property for the current headline."
6457 (org-agenda-check-no-diary)
6458 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6459 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6460 (org-agenda-error)))
6461 (buffer (marker-buffer hdmarker))
6462 (pos (marker-position hdmarker))
6463 (inhibit-read-only t)
6465 (org-with-remote-undo buffer
6466 (with-current-buffer buffer
6470 (org-show-context 'agenda))
6472 (and (outline-next-heading)
6473 (org-flag-heading nil))) ; show the next heading
6475 (call-interactively 'org-set-property)))))
6477 (defun org-agenda-set-effort ()
6478 "Set the effort property for the current headline."
6480 (org-agenda-check-no-diary)
6481 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6482 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6483 (org-agenda-error)))
6484 (buffer (marker-buffer hdmarker))
6485 (pos (marker-position hdmarker))
6486 (inhibit-read-only t)
6488 (org-with-remote-undo buffer
6489 (with-current-buffer buffer
6493 (org-show-context 'agenda))
6495 (and (outline-next-heading)
6496 (org-flag-heading nil))) ; show the next heading
6498 (call-interactively 'org-set-effort)
6501 (defun org-agenda-toggle-archive-tag ()
6502 "Toggle the archive tag for the current entry."
6504 (org-agenda-check-no-diary)
6505 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6506 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6507 (org-agenda-error)))
6508 (buffer (marker-buffer hdmarker))
6509 (pos (marker-position hdmarker))
6510 (inhibit-read-only t)
6512 (org-with-remote-undo buffer
6513 (with-current-buffer buffer
6516 (org-show-context 'agenda)
6518 (and (outline-next-heading)
6519 (org-flag-heading nil))) ; show the next heading
6520 (call-interactively 'org-toggle-archive-tag)
6522 (setq newhead (org-get-heading)))
6523 (org-agenda-change-all-lines newhead hdmarker)
6524 (beginning-of-line 1))))
6526 (defun org-agenda-do-date-later (arg)
6529 ((or (equal arg '(16))
6531 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6532 (setq this-command 'org-agenda-date-later-minutes)
6533 (org-agenda-date-later-minutes 1))
6534 ((or (equal arg '(4))
6536 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6537 (setq this-command 'org-agenda-date-later-hours)
6538 (org-agenda-date-later-hours 1))
6540 (org-agenda-date-later (prefix-numeric-value arg)))))
6542 (defun org-agenda-do-date-earlier (arg)
6545 ((or (equal arg '(16))
6547 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6548 (setq this-command 'org-agenda-date-earlier-minutes)
6549 (org-agenda-date-earlier-minutes 1))
6550 ((or (equal arg '(4))
6552 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6553 (setq this-command 'org-agenda-date-earlier-hours)
6554 (org-agenda-date-earlier-hours 1))
6556 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6558 (defun org-agenda-date-later (arg &optional what)
6559 "Change the date of this item to one day later."
6561 (org-agenda-check-type t 'agenda 'timeline)
6562 (org-agenda-check-no-diary)
6563 (let* ((marker (or (org-get-at-bol 'org-marker)
6564 (org-agenda-error)))
6565 (buffer (marker-buffer marker))
6566 (pos (marker-position marker)))
6567 (org-with-remote-undo buffer
6568 (with-current-buffer buffer
6571 (if (not (org-at-timestamp-p))
6572 (error "Cannot find time stamp"))
6573 (org-timestamp-change arg (or what 'day)))
6574 (org-agenda-show-new-time marker org-last-changed-timestamp))
6575 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6577 (defun org-agenda-date-earlier (arg &optional what)
6578 "Change the date of this item to one day earlier."
6580 (org-agenda-date-later (- arg) what))
6582 (defun org-agenda-date-later-minutes (arg)
6583 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6585 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6586 (org-agenda-date-later arg 'minute))
6588 (defun org-agenda-date-earlier-minutes (arg)
6589 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6591 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6592 (org-agenda-date-earlier arg 'minute))
6594 (defun org-agenda-date-later-hours (arg)
6595 "Change the time of this item, in hour steps."
6597 (org-agenda-date-later arg 'hour))
6599 (defun org-agenda-date-earlier-hours (arg)
6600 "Change the time of this item, in hour steps."
6602 (org-agenda-date-earlier arg 'hour))
6604 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6605 "Show new date stamp via text properties."
6606 ;; We use text properties to make this undoable
6607 (let ((inhibit-read-only t)
6608 (buffer-invisibility-spec))
6609 (setq stamp (concat " " prefix " => " stamp))
6611 (goto-char (point-max))
6613 (when (equal marker (org-get-at-bol 'org-marker))
6614 (org-move-to-column (- (window-width) (length stamp)) t)
6615 (org-agenda-fix-tags-filter-overlays-at (point))
6616 (if (featurep 'xemacs)
6617 ;; Use `duplicable' property to trigger undo recording
6618 (let ((ex (make-extent nil nil))
6619 (gl (make-glyph stamp)))
6620 (set-glyph-face gl 'secondary-selection)
6621 (set-extent-properties
6622 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6623 (insert-extent ex (1- (point)) (point-at-eol)))
6624 (add-text-properties
6625 (1- (point)) (point-at-eol)
6626 (list 'display (org-add-props stamp nil
6627 'face 'secondary-selection))))
6628 (beginning-of-line 1))
6629 (beginning-of-line 0)))))
6631 (defun org-agenda-date-prompt (arg)
6632 "Change the date of this item. Date is prompted for, with default today.
6633 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6634 be used to request time specification in the time stamp."
6636 (org-agenda-check-type t 'agenda 'timeline)
6637 (org-agenda-check-no-diary)
6638 (let* ((marker (or (org-get-at-bol 'org-marker)
6639 (org-agenda-error)))
6640 (buffer (marker-buffer marker))
6641 (pos (marker-position marker)))
6642 (org-with-remote-undo buffer
6643 (with-current-buffer buffer
6646 (if (not (org-at-timestamp-p t))
6647 (error "Cannot find time stamp"))
6648 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
6649 (org-agenda-show-new-time marker org-last-changed-timestamp))
6650 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6652 (defun org-agenda-schedule (arg)
6653 "Schedule the item at point.
6654 Arg is passed through to `org-schedule'."
6656 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6657 (org-agenda-check-no-diary)
6658 (let* ((marker (or (org-get-at-bol 'org-marker)
6659 (org-agenda-error)))
6660 (type (marker-insertion-type marker))
6661 (buffer (marker-buffer marker))
6662 (pos (marker-position marker))
6663 (org-insert-labeled-timestamps-at-point nil)
6665 (set-marker-insertion-type marker t)
6666 (org-with-remote-undo buffer
6667 (with-current-buffer buffer
6670 (setq ts (org-schedule arg)))
6671 (org-agenda-show-new-time marker ts "S"))
6672 (message "Item scheduled for %s" ts)))
6674 (defun org-agenda-deadline (arg)
6675 "Schedule the item at point.
6676 Arg is passed through to `org-deadline'."
6678 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6679 (org-agenda-check-no-diary)
6680 (let* ((marker (or (org-get-at-bol 'org-marker)
6681 (org-agenda-error)))
6682 (buffer (marker-buffer marker))
6683 (pos (marker-position marker))
6684 (org-insert-labeled-timestamps-at-point nil)
6686 (org-with-remote-undo buffer
6687 (with-current-buffer buffer
6690 (setq ts (org-deadline arg)))
6691 (org-agenda-show-new-time marker ts "D"))
6692 (message "Deadline for this item set to %s" ts)))
6694 (defun org-agenda-action ()
6695 "Select entry for agenda action, or execute an agenda action.
6696 This command prompts for another letter. Valid inputs are:
6698 m Mark the entry at point for an agenda action
6699 s Schedule the marked entry to the date at the cursor
6700 d Set the deadline of the marked entry to the date at the cursor
6701 r Call `org-remember' with cursor date as the default date
6702 SPC Show marked entry in other window
6703 TAB Visit marked entry in other window
6705 The cursor may be at a date in the calendar, or in the Org agenda."
6708 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
6709 (setq ans (read-char-exclusive))
6713 (if (eq major-mode 'org-agenda-mode)
6714 (let ((m (or (org-get-at-bol 'org-hd-marker)
6715 (org-get-at-bol 'org-marker))))
6718 (move-marker org-agenda-action-marker
6719 (marker-position m) (marker-buffer m))
6720 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
6721 (error "Don't know which entry to mark")))
6722 (error "This command works only in the agenda")))
6724 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
6726 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
6728 (org-agenda-do-action '(org-remember) t))
6730 (let ((cw (selected-window)))
6731 (org-switch-to-buffer-other-window
6732 (marker-buffer org-agenda-action-marker))
6733 (goto-char org-agenda-action-marker)
6734 (org-show-context 'agenda)
6735 (select-window cw)))
6737 (org-switch-to-buffer-other-window
6738 (marker-buffer org-agenda-action-marker))
6739 (goto-char org-agenda-action-marker)
6740 (org-show-context 'agenda))
6741 (t (error "Invalid agenda action %c" ans)))))
6743 (defun org-agenda-do-action (form &optional current-buffer)
6744 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
6745 (let ((org-overriding-default-time (org-get-cursor-date)))
6748 (if (not (marker-buffer org-agenda-action-marker))
6749 (error "No entry has been selected for agenda action")
6750 (with-current-buffer (marker-buffer org-agenda-action-marker)
6754 (goto-char org-agenda-action-marker)
6757 (defun org-agenda-clock-in (&optional arg)
6758 "Start the clock on the currently selected item."
6760 (org-agenda-check-no-diary)
6761 (if (equal arg '(4))
6763 (let* ((marker (or (org-get-at-bol 'org-marker)
6764 (org-agenda-error)))
6765 (hdmarker (or (org-get-at-bol 'org-hd-marker)
6767 (pos (marker-position marker))
6769 (org-with-remote-undo (marker-buffer marker)
6770 (with-current-buffer (marker-buffer marker)
6773 (org-show-context 'agenda)
6775 (org-cycle-hide-drawers 'children)
6777 (setq newhead (org-get-heading)))
6778 (org-agenda-change-all-lines newhead hdmarker)))))
6780 (defun org-agenda-clock-out (&optional arg)
6781 "Stop the currently running clock."
6783 (unless (marker-buffer org-clock-marker)
6784 (error "No running clock"))
6785 (let ((marker (make-marker)) newhead)
6786 (org-with-remote-undo (marker-buffer org-clock-marker)
6787 (with-current-buffer (marker-buffer org-clock-marker)
6791 (goto-char org-clock-marker)
6792 (org-back-to-heading t)
6793 (move-marker marker (point))
6795 (setq newhead (org-get-heading))))))
6796 (org-agenda-change-all-lines newhead marker)
6797 (move-marker marker nil)))
6799 (defun org-agenda-clock-cancel (&optional arg)
6800 "Cancel the currently running clock."
6802 (unless (marker-buffer org-clock-marker)
6803 (error "No running clock"))
6804 (org-with-remote-undo (marker-buffer org-clock-marker)
6805 (org-clock-cancel)))
6807 (defun org-agenda-diary-entry-in-org-file ()
6808 "Make a diary entry in the file `org-agenda-diary-file'."
6809 (let (d1 d2 char (text "") dp1 dp2)
6810 (if (equal (buffer-name) "*Calendar*")
6811 (setq d1 (calendar-cursor-to-date t)
6812 d2 (car calendar-mark-ring))
6813 (setq dp1 (get-text-property (point-at-bol) 'day))
6814 (unless dp1 (error "No date defined in current line"))
6815 (setq d1 (calendar-gregorian-from-absolute dp1)
6816 d2 (and (ignore-errors (mark))
6819 (setq dp2 (get-text-property (point-at-bol) 'day)))
6820 (calendar-gregorian-from-absolute dp2))))
6821 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
6822 (setq char (read-char-exclusive))
6825 (setq text (read-string "Day entry: "))
6826 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
6827 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
6829 (setq d1 (list (car d1) (nth 1 d1)
6830 (read-number (format "Reference year [%d]: " (nth 2 d1))
6832 (setq text (read-string "Anniversary (use %d to show years): "))
6833 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
6834 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
6836 (setq text (read-string "Block entry: "))
6837 (unless (and d1 d2 (not (equal d1 d2)))
6838 (error "No block of days selected"))
6839 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
6840 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
6842 (org-switch-to-buffer-other-window
6843 (find-file-noselect org-agenda-diary-file))
6844 (require 'org-datetree)
6845 (org-datetree-find-date-create d1)
6847 (t (error "Invalid selection character `%c'" char)))))
6849 (defcustom org-agenda-insert-diary-strategy 'date-tree
6850 "Where in `org-agenda-diary-file' should new entries be added?
6853 date-tree in the date tree, as child of the date
6854 top-level as top-level entries at the end of the file."
6857 (const :tag "in a date tree" date-tree)
6858 (const :tag "as top level at end of file" top-level)))
6860 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
6861 "Add a diary entry with TYPE to `org-agenda-diary-file'.
6862 If TEXT is not empty, it will become the headline of the new entry, and
6863 the resulting entry will not be shown. When TEXT is empty, switch to
6864 `org-agenda-diary-file' and let the user finish the entry there."
6865 (let ((cw (current-window-configuration)))
6866 (org-switch-to-buffer-other-window
6867 (find-file-noselect org-agenda-diary-file))
6869 (goto-char (point-min))
6871 ((eq type 'anniversary)
6872 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
6874 (or (org-on-heading-p t)
6876 (outline-next-heading)
6877 (insert "* Anniversaries\n\n")
6878 (beginning-of-line -1)))))
6879 (outline-next-heading)
6880 (org-back-over-empty-lines)
6883 (require 'diary-lib)
6884 (let ((calendar-date-display-form
6885 (if (if (boundp 'calendar-date-style)
6886 (eq calendar-date-style 'european)
6887 (org-bound-and-true-p european-calendar-style)) ; Emacs 22
6888 '(day " " month " " year)
6889 '(month " " day " " year))))
6891 (insert (format "%%%%(diary-anniversary %s) %s"
6892 (calendar-date-string d1 nil t) text))))
6894 (if (eq org-agenda-insert-diary-strategy 'top-level)
6895 (org-agenda-insert-diary-as-top-level text)
6896 (require 'org-datetree)
6897 (org-datetree-find-date-create d1)
6898 (org-agenda-insert-diary-make-new-entry text))
6899 (org-insert-time-stamp (org-time-from-absolute
6900 (calendar-absolute-from-gregorian d1)))
6903 (if (> (calendar-absolute-from-gregorian d1)
6904 (calendar-absolute-from-gregorian d2))
6905 (setq d1 (prog1 d2 (setq d2 d1))))
6906 (if (eq org-agenda-insert-diary-strategy 'top-level)
6907 (org-agenda-insert-diary-as-top-level text)
6908 (require 'org-datetree)
6909 (org-datetree-find-date-create d1)
6910 (org-agenda-insert-diary-make-new-entry text))
6911 (org-insert-time-stamp (org-time-from-absolute
6912 (calendar-absolute-from-gregorian d1)))
6914 (org-insert-time-stamp (org-time-from-absolute
6915 (calendar-absolute-from-gregorian d2)))
6917 (if (string-match "\\S-" text)
6919 (set-window-configuration cw)
6920 (message "%s entry added to %s"
6921 (capitalize (symbol-name type))
6922 (abbreviate-file-name org-agenda-diary-file)))
6924 (message "Please finish entry here"))))
6926 (defun org-agenda-insert-diary-as-top-level (text)
6927 "Make new entry as a top-level entry at the end of the file.
6928 Add TEXT as headline, and position the cursor in the second line so that
6929 a timestamp can be added there."
6931 (goto-char (point-max))
6932 (or (bolp) (insert "\n"))
6933 (insert "* " text "\n")
6934 (if org-adapt-indentation (org-indent-to-column 2)))
6936 (defun org-agenda-insert-diary-make-new-entry (text)
6937 "Make new entry as last child of current entry.
6938 Add TEXT as headline, and position the cursor in the second line so that
6939 a timestamp can be added there."
6940 (let ((org-show-following-heading t)
6941 (org-show-siblings t)
6942 (org-show-hierarchy-above t)
6943 (org-show-entry-below t)
6945 (outline-next-heading)
6946 (org-back-over-empty-lines)
6947 (or (looking-at "[ \t]*$")
6948 (progn (insert "\n") (backward-char 1)))
6949 (org-insert-heading nil t)
6951 (setq col (current-column))
6953 (if org-adapt-indentation (org-indent-to-column col))
6954 (let ((org-show-following-heading t)
6955 (org-show-siblings t)
6956 (org-show-hierarchy-above t)
6957 (org-show-entry-below t))
6958 (org-show-context))))
6960 (defun org-agenda-diary-entry ()
6961 "Make a diary entry, like the `i' command from the calendar.
6962 All the standard commands work: block, weekly etc.
6963 When `org-agenda-diary-file' points to a file,
6964 `org-agenda-diary-entry-in-org-file' is called instead to create
6965 entries in that Org-mode file."
6967 (org-agenda-check-type t 'agenda 'timeline)
6968 (if (not (eq org-agenda-diary-file 'diary-file))
6969 (org-agenda-diary-entry-in-org-file)
6970 (require 'diary-lib)
6972 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6973 (read-char-exclusive)))
6974 (cmd (cdr (assoc char
6975 '((?d . insert-diary-entry)
6976 (?w . insert-weekly-diary-entry)
6977 (?m . insert-monthly-diary-entry)
6978 (?y . insert-yearly-diary-entry)
6979 (?a . insert-anniversary-diary-entry)
6980 (?b . insert-block-diary-entry)
6981 (?c . insert-cyclic-diary-entry)))))
6982 (oldf (symbol-function 'calendar-cursor-to-date))
6983 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6985 (mark (or (mark t) (point))))
6987 (error "No command associated with <%c>" char))
6988 (unless (and (get-text-property point 'day)
6989 (or (not (equal ?b char))
6990 (get-text-property mark 'day)))
6991 (error "Don't know which date to use for diary entry"))
6992 ;; We implement this by hacking the `calendar-cursor-to-date' function
6993 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6994 (let ((calendar-mark-ring
6995 (list (calendar-gregorian-from-absolute
6996 (or (get-text-property mark 'day)
6997 (get-text-property point 'day))))))
7000 (fset 'calendar-cursor-to-date
7001 (lambda (&optional error dummy)
7002 (calendar-gregorian-from-absolute
7003 (get-text-property point 'day))))
7004 (call-interactively cmd))
7005 (fset 'calendar-cursor-to-date oldf))))))
7007 (defun org-agenda-execute-calendar-command (cmd)
7008 "Execute a calendar command from the agenda, with the date associated to
7009 the cursor position."
7010 (org-agenda-check-type t 'agenda 'timeline)
7011 (require 'diary-lib)
7012 (unless (get-text-property (point) 'day)
7013 (error "Don't know which date to use for calendar command"))
7014 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7016 (date (calendar-gregorian-from-absolute
7017 (get-text-property point 'day)))
7018 ;; the following 2 vars are needed in the calendar
7019 (displayed-month (car date))
7020 (displayed-year (nth 2 date)))
7023 (fset 'calendar-cursor-to-date
7024 (lambda (&optional error dummy)
7025 (calendar-gregorian-from-absolute
7026 (get-text-property point 'day))))
7027 (call-interactively cmd))
7028 (fset 'calendar-cursor-to-date oldf))))
7030 (defun org-agenda-phases-of-moon ()
7031 "Display the phases of the moon for the 3 months around the cursor date."
7033 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7035 (defun org-agenda-holidays ()
7036 "Display the holidays for the 3 months around the cursor date."
7038 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7040 (defvar calendar-longitude)
7041 (defvar calendar-latitude)
7042 (defvar calendar-location-name)
7044 (defun org-agenda-sunrise-sunset (arg)
7045 "Display sunrise and sunset for the cursor date.
7046 Latitude and longitude can be specified with the variables
7047 `calendar-latitude' and `calendar-longitude'. When called with prefix
7048 argument, latitude and longitude will be prompted for."
7051 (let ((calendar-longitude (if arg nil calendar-longitude))
7052 (calendar-latitude (if arg nil calendar-latitude))
7053 (calendar-location-name
7054 (if arg "the given coordinates" calendar-location-name)))
7055 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7057 (defun org-agenda-goto-calendar ()
7058 "Open the Emacs calendar with the date at the cursor."
7060 (org-agenda-check-type t 'agenda 'timeline)
7061 (let* ((day (or (get-text-property (point) 'day)
7062 (error "Don't know which date to open in calendar")))
7063 (date (calendar-gregorian-from-absolute day))
7064 (calendar-move-hook nil)
7065 (calendar-view-holidays-initially-flag nil)
7066 (calendar-view-diary-initially-flag nil)
7067 (view-calendar-holidays-initially nil)
7068 (view-diary-entries-initially nil))
7070 (calendar-goto-date date)))
7073 (defun org-calendar-goto-agenda ()
7074 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7075 This is a command that has to be installed in `calendar-mode-map'."
7077 (org-agenda-list nil (calendar-absolute-from-gregorian
7078 (calendar-cursor-to-date))
7081 (defun org-agenda-convert-date ()
7083 (org-agenda-check-type t 'agenda 'timeline)
7084 (let ((day (get-text-property (point) 'day))
7087 (error "Don't know which date to convert"))
7088 (setq date (calendar-gregorian-from-absolute day))
7090 "Gregorian: " (calendar-date-string date) "\n"
7091 "ISO: " (calendar-iso-date-string date) "\n"
7092 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7093 "Julian: " (calendar-julian-date-string date) "\n"
7094 "Astron. JD: " (calendar-astro-date-string date)
7095 " (Julian date number at noon UTC)\n"
7096 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7097 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7098 "French: " (calendar-french-date-string date) "\n"
7099 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7100 "Mayan: " (calendar-mayan-date-string date) "\n"
7101 "Coptic: " (calendar-coptic-date-string date) "\n"
7102 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7103 "Persian: " (calendar-persian-date-string date) "\n"
7104 "Chinese: " (calendar-chinese-date-string date) "\n"))
7105 (with-output-to-temp-buffer "*Dates*"
7107 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7111 (defvar org-agenda-bulk-marked-entries nil
7112 "List of markers that refer to marked entries in the agenda.")
7114 (defun org-agenda-bulk-marked-p ()
7115 (eq (get-char-property (point-at-bol) 'type)
7116 'org-marked-entry-overlay))
7118 (defun org-agenda-bulk-mark ()
7119 "Mark the entry at point for future bulk action."
7121 (org-agenda-check-no-diary)
7122 (let* ((m (org-get-at-bol 'org-hd-marker))
7124 (unless (org-agenda-bulk-marked-p)
7125 (unless m (error "Nothing to mark at point"))
7126 (push m org-agenda-bulk-marked-entries)
7127 (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7128 (org-overlay-display ov "> "
7129 (org-get-todo-face "TODO")
7131 (org-overlay-put ov 'type 'org-marked-entry-overlay))
7132 (beginning-of-line 2)
7133 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7134 (beginning-of-line 2))
7135 (message "%d entries marked for bulk action"
7136 (length org-agenda-bulk-marked-entries))))
7138 (defun org-agenda-bulk-unmark ()
7139 "Unmark the entry at point for future bulk action."
7141 (when (org-agenda-bulk-marked-p)
7142 (org-agenda-bulk-remove-overlays
7143 (point-at-bol) (+ 2 (point-at-bol)))
7144 (setq org-agenda-bulk-marked-entries
7145 (delete (org-get-at-bol 'org-hd-marker)
7146 org-agenda-bulk-marked-entries)))
7147 (beginning-of-line 2)
7148 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7149 (beginning-of-line 2))
7150 (message "%d entries marked for bulk action"
7151 (length org-agenda-bulk-marked-entries)))
7153 (defun org-agenda-bulk-toggle ()
7154 "Toggle marking the entry at point for bulk action."
7156 (if (org-agenda-bulk-marked-p)
7157 (org-agenda-bulk-unmark)
7158 (org-agenda-bulk-mark)))
7160 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7161 "Remove the mark overlays between BEG and END in the agenda buffer.
7162 BEG and END default to the buffer limits.
7164 This only removes the overlays, it does not remove the markers
7165 from the list in `org-agenda-bulk-marked-entries'."
7168 (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
7169 (org-delete-overlay ov)))
7170 (org-overlays-in (or beg (point-min)) (or end (point-max)))))
7172 (defun org-agenda-bulk-remove-all-marks ()
7173 "Remove all marks in the agenda buffer.
7174 This will remove the markers, and the overlays."
7176 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7177 (setq org-agenda-bulk-marked-entries nil)
7178 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7180 (defun org-agenda-bulk-action (&optional arg)
7181 "Execute an remote-editing action on all marked entries.
7182 The prefix arg is passed through to the command if possible."
7184 (unless org-agenda-bulk-marked-entries
7185 (error "No entries are marked"))
7186 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
7187 (let* ((action (read-char-exclusive))
7188 (entries (reverse org-agenda-bulk-marked-entries))
7189 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7192 (setq cmd '(org-agenda-archive)))
7195 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7197 ((member action '(?r ?w))
7198 (setq rfloc (org-refile-get-location
7200 (marker-buffer (car org-agenda-bulk-marked-entries))
7201 org-refile-allow-creating-parent-nodes))
7202 (setcar (nthcdr 3 rfloc)
7203 (move-marker (make-marker) (nth 3 rfloc)
7204 (or (get-file-buffer (nth 1 rfloc))
7205 (find-buffer-visiting (nth 1 rfloc))
7206 (error "This should not happen"))))
7208 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
7211 (setq state (org-icompleting-read
7213 (with-current-buffer (marker-buffer (car entries))
7214 (mapcar 'list org-todo-keywords-1))))
7215 (setq cmd `(let ((org-inhibit-blocking t)
7216 (org-inhibit-logging 'note))
7217 (org-agenda-todo ,state))))
7219 ((memq action '(?- ?+))
7220 (setq tag (org-icompleting-read
7221 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7222 (with-current-buffer (marker-buffer (car entries))
7225 (if (stringp (car x)) x)) org-tag-alist)))))
7226 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
7228 ((memq action '(?s ?d))
7229 (let* ((date (unless arg
7232 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
7233 (ans (if arg nil org-read-date-final-answer))
7234 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
7235 (setq cmd `(let* ((bound (fboundp 'read-string))
7236 (old (and bound (symbol-function 'read-string))))
7239 (fset 'read-string (lambda (&rest ignore) ,ans))
7242 (fset 'read-string old)
7243 (fmakunbound 'read-string)))))))
7244 (t (error "Invalid bulk action")))
7246 ;; Sort the markers, to make sure that parents are handled before children
7247 (setq entries (sort entries
7250 ((equal (marker-buffer a) (marker-buffer b))
7251 (< (marker-position a) (marker-position b)))
7253 (string< (buffer-name (marker-buffer a))
7254 (buffer-name (marker-buffer b))))))))
7256 ;; Now loop over all markers and apply cmd
7257 (while (setq e (pop entries))
7258 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
7260 (progn (message "Skipping removed entry at %s" e)
7261 (setq cntskip (1+ cntskip)))
7264 (setq org-agenda-bulk-marked-entries
7265 (delete e org-agenda-bulk-marked-entries))
7266 (setq cnt (1+ cnt))))
7267 (setq org-agenda-bulk-marked-entries nil)
7268 (org-agenda-bulk-remove-all-marks)
7269 (message "Acted on %d entries%s"
7273 (format ", skipped %d (disappeared before their turn)"
7278 (defun org-agenda-show-the-flagging-note ()
7279 "Display the flagging note in the other window.
7280 When called a second time in direct sequence, offer to remove the FLAGGING
7281 tag and (if present) the flagging note."
7283 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
7284 (win (selected-window))
7285 note heading newhead)
7287 (error "No linked entry at point"))
7288 (if (and (eq this-command last-command)
7289 (y-or-n-p "Unflag and remove any flagging note? "))
7291 (org-agenda-remove-flag hdmarker)
7292 (let ((win (get-buffer-window "*Flagging Note*")))
7293 (and win (delete-window win)))
7294 (message "Entry unflaged"))
7295 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
7297 (error "No flagging note"))
7299 (org-switch-to-buffer-other-window "*Flagging Note*")
7302 (goto-char (point-min))
7303 (while (re-search-forward "\\\\n" nil t)
7304 (replace-match "\n" t t))
7305 (goto-char (point-min))
7307 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
7309 (defun org-agenda-remove-flag (marker)
7310 "Remove the FLAGGED tag and any flagging note in the entry."
7312 (org-with-point-at marker
7313 (org-toggle-tag "FLAGGED" 'off)
7314 (org-entry-delete nil "THEFLAGGINGNOTE")
7315 (setq newhead (org-get-heading)))
7316 (org-agenda-change-all-lines newhead marker)
7317 (message "Entry unflaged")))
7319 (defun org-agenda-get-any-marker (&optional pos)
7320 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7321 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7323 ;;; Appointment reminders
7325 (defvar appt-time-msg-list)
7328 (defun org-agenda-to-appt (&optional refresh filter)
7329 "Activate appointments found in `org-agenda-files'.
7330 With a \\[universal-argument] prefix, refresh the list of
7333 If FILTER is t, interactively prompt the user for a regular
7334 expression, and filter out entries that don't match it.
7336 If FILTER is a string, use this string as a regular expression
7337 for filtering entries out.
7339 FILTER can also be an alist with the car of each cell being
7340 either 'headline or 'category. For example:
7342 '((headline \"IMPORTANT\")
7343 (category \"Work\"))
7345 will only add headlines containing IMPORTANT or headlines
7346 belonging to the \"Work\" category."
7349 (if refresh (setq appt-time-msg-list nil))
7351 (setq filter (read-from-minibuffer "Regexp filter: ")))
7352 (let* ((cnt 0) ; count added events
7353 (org-agenda-new-buffers nil)
7354 (org-deadline-warning-days 0)
7355 (today (org-date-to-gregorian
7356 (time-to-days (current-time))))
7357 (org-agenda-restrict nil)
7358 (files (org-agenda-files 'unrestricted)) entries file)
7359 ;; Get all entries which may contain an appt
7360 (org-prepare-agenda-buffers files)
7361 (while (setq file (pop files))
7364 (org-agenda-get-day-entries
7365 file today :timestamp :scheduled :deadline))))
7366 (setq entries (delq nil entries))
7367 ;; Map thru entries and find if we should filter them out
7370 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7371 (cat (get-text-property 1 'org-category x))
7372 (tod (get-text-property 1 'time-of-day x))
7373 (ok (or (null filter)
7374 (and (stringp filter) (string-match filter evt))
7377 (cadr (assoc 'category filter)) cat)
7379 (cadr (assoc 'headline filter)) evt))))))
7380 ;; FIXME: Shall we remove text-properties for the appt text?
7381 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7383 (setq tod (concat "00" (number-to-string tod))
7384 tod (when (string-match
7385 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7386 (concat (match-string 1 tod) ":"
7387 (match-string 2 tod))))
7389 (setq cnt (1+ cnt))))) entries)
7390 (org-release-buffers org-agenda-new-buffers)
7392 (message "No event to add")
7393 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7395 (defun org-agenda-todayp (date)
7396 "Does DATE mean today, when considering `org-extend-today-until'?"
7398 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7399 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7400 (setq h (nth 2 (decode-time (current-time))))
7401 (or (and (>= h org-extend-today-until)
7403 (and (< h org-extend-today-until)
7404 (= date (1- today))))))
7406 (provide 'org-agenda)
7408 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7410 ;;; org-agenda.el ends here