1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
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.
37 (declare-function diary-add-to-list
"diary-lib"
38 (date string specifier
&optional marker globcolor literal
))
39 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
40 (declare-function calendar-astro-date-string
"cal-julian" (&optional date
))
41 (declare-function calendar-bahai-date-string
"cal-bahai" (&optional date
))
42 (declare-function calendar-chinese-date-string
"cal-china" (&optional date
))
43 (declare-function calendar-coptic-date-string
"cal-coptic" (&optional date
))
44 (declare-function calendar-ethiopic-date-string
"cal-coptic" (&optional date
))
45 (declare-function calendar-french-date-string
"cal-french" (&optional date
))
46 (declare-function calendar-goto-date
"cal-move" (date))
47 (declare-function calendar-hebrew-date-string
"cal-hebrew" (&optional date
))
48 (declare-function calendar-islamic-date-string
"cal-islam" (&optional date
))
49 (declare-function calendar-iso-date-string
"cal-iso" (&optional date
))
50 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
51 (declare-function calendar-julian-date-string
"cal-julian" (&optional date
))
52 (declare-function calendar-mayan-date-string
"cal-mayan" (&optional date
))
53 (declare-function calendar-persian-date-string
"cal-persia" (&optional date
))
54 (declare-function org-datetree-find-date-create
"org-datetree"
55 (date &optional keep-restriction
))
56 (declare-function org-columns-quit
"org-colview" ())
57 (declare-function diary-date-display-form
"diary-lib" (&optional type
))
58 (declare-function org-mobile-write-agenda-for-mobile
"org-mobile" (file))
59 (declare-function org-habit-insert-consistency-graphs
60 "org-habit" (&optional line
))
61 (declare-function org-is-habit-p
"org-habit" (&optional pom
))
62 (declare-function org-habit-parse-todo
"org-habit" (&optional pom
))
63 (declare-function org-habit-get-priority
"org-habit" (habit &optional moment
))
64 (defvar calendar-mode-map
)
65 (defvar org-clock-current-task
) ; defined in org-clock.el
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 the variables `org-agenda-entry-text-mode'
147 and `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 (defcustom org-agenda-persistent-filter nil
202 "When set, keep filters from one agenda view to the next."
206 (defgroup org-agenda-custom-commands nil
207 "Options concerning agenda views in Org-mode."
208 :tag
"Org Agenda Custom Commands"
211 (defconst org-sorting-choice
213 (const time-up
) (const time-down
)
214 (const category-keep
) (const category-up
) (const category-down
)
215 (const tag-down
) (const tag-up
)
216 (const priority-up
) (const priority-down
)
217 (const todo-state-up
) (const todo-state-down
)
218 (const effort-up
) (const effort-down
)
219 (const habit-up
) (const habit-down
)
220 (const alpha-up
) (const alpha-down
)
221 (const user-defined-up
) (const user-defined-down
))
224 (defconst org-agenda-custom-commands-local-options
225 `(repeat :tag
"Local settings for this command. Remember to quote values"
226 (choice :tag
"Setting"
227 (list :tag
"Heading for this block"
228 (const org-agenda-overriding-header
)
229 (string :tag
"Headline"))
230 (list :tag
"Files to be searched"
231 (const org-agenda-files
)
233 (const :format
"" quote
)
235 (list :tag
"Sorting strategy"
236 (const org-agenda-sorting-strategy
)
238 (const :format
"" quote
)
240 ,org-sorting-choice
)))
241 (list :tag
"Prefix format"
242 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
244 (list :tag
"Number of days in agenda"
245 (const org-agenda-ndays
)
247 (list :tag
"Fixed starting date"
248 (const org-agenda-start-day
)
249 (string :value
"2007-11-01"))
250 (list :tag
"Start on day of week"
251 (const org-agenda-start-on-weekday
)
253 (const :tag
"Today" nil
)
254 (integer :tag
"Weekday No.")))
255 (list :tag
"Include data from diary"
256 (const org-agenda-include-diary
)
258 (list :tag
"Deadline Warning days"
259 (const org-deadline-warning-days
)
261 (list :tag
"Tags filter preset"
262 (const org-agenda-filter-preset
)
264 (const :format
"" quote
)
266 (string :tag
"+tag or -tag"))))
267 (list :tag
"Set daily/weekly entry types"
268 (const org-agenda-entry-types
)
269 (set :greedy t
:value
(:deadline
:scheduled
:timestamp
:sexp
)
274 (list :tag
"Standard skipping condition"
275 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
276 (const org-agenda-skip-function
)
278 (const :format
"" quote
)
281 :tag
"Skipping range"
282 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
283 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
284 (repeat :inline t
:tag
"Conditions for skipping"
286 :tag
"Condition type"
287 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
288 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
289 (list :tag
"TODO state is" :inline t
292 (const :tag
"any not-done state" 'todo
)
293 (const :tag
"any done state" 'done
)
294 (const :tag
"any state" 'any
)
295 (list :tag
"Keyword list"
296 (const :format
"" quote
)
297 (repeat (string :tag
"Keyword")))))
298 (list :tag
"TODO state is not" :inline t
301 (const :tag
"any not-done state" 'todo
)
302 (const :tag
"any done state" 'done
)
303 (const :tag
"any state" 'any
)
304 (list :tag
"Keyword list"
305 (const :format
"" quote
)
306 (repeat (string :tag
"Keyword")))))
307 (const :tag
"scheduled" 'scheduled
)
308 (const :tag
"not scheduled" 'notscheduled
)
309 (const :tag
"deadline" 'deadline
)
310 (const :tag
"no deadline" 'notdeadline
)
311 (const :tag
"timestamp" 'timestamp
)
312 (const :tag
"no timestamp" 'nottimestamp
))))))
313 (list :tag
"Non-standard skipping condition"
314 :value
(org-agenda-skip-function)
315 (const org-agenda-skip-function
)
316 (sexp :tag
"Function or form (quoted!)"))
317 (list :tag
"Any variable"
318 (variable :tag
"Variable")
319 (sexp :tag
"Value (sexp)"))))
320 "Selection of examples for agenda command settings.
321 This will be spliced into the custom type of
322 `org-agenda-custom-commands'.")
325 (defcustom org-agenda-custom-commands nil
326 "Custom commands for the agenda.
327 These commands will be offered on the splash screen displayed by the
328 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
330 (key desc type match settings files)
332 key The key (one or more characters as a string) to be associated
334 desc A description of the command, when omitted or nil, a default
335 description is built using MATCH.
336 type The command type, any of the following symbols:
337 agenda The daily/weekly agenda.
338 todo Entries with a specific TODO keyword, in all agenda files.
339 search Entries containing search words entry or headline.
340 tags Tags/Property/TODO match in all agenda files.
341 tags-todo Tags/P/T match in all agenda files, TODO entries only.
342 todo-tree Sparse tree of specific TODO keyword in *current* file.
343 tags-tree Sparse tree with all tags matches in *current* file.
344 occur-tree Occur sparse tree for *current* file.
345 ... A user-defined function.
346 match What to search for:
347 - a single keyword for TODO keyword searches
348 - a tags match expression for tags searches
349 - a word search expression for text searches.
350 - a regular expression for occur searches
351 For all other commands, this should be the empty string.
352 settings A list of option settings, similar to that in a let form, so like
353 this: ((opt1 val1) (opt2 val2) ...). The values will be
354 evaluated at the moment of execution, so quote them when needed.
355 files A list of files file to write the produced agenda buffer to
356 with the command `org-store-agenda-views'.
357 If a file name ends in \".html\", an HTML version of the buffer
358 is written out. If it ends in \".ps\", a postscript version is
359 produced. Otherwise, only the plain text is written to the file.
361 You can also define a set of commands, to create a composite agenda buffer.
362 In this case, an entry looks like this:
364 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
368 desc A description string to be displayed in the dispatcher menu.
369 cmd An agenda command, similar to the above. However, tree commands
370 are no allowed, but instead you can get agenda and global todo list.
371 So valid commands for a set are:
372 (agenda \"\" settings)
373 (alltodo \"\" settings)
374 (stuck \"\" settings)
375 (todo \"match\" settings files)
376 (search \"match\" settings files)
377 (tags \"match\" settings files)
378 (tags-todo \"match\" settings files)
380 Each command can carry a list of options, and another set of options can be
381 given for the whole set of commands. Individual command options take
382 precedence over the general options.
384 When using several characters as key to a command, the first characters
385 are prefix commands. For the dispatcher to display useful information, you
386 should provide a description for the prefix, like
388 (setq org-agenda-custom-commands
389 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
390 (\"hl\" tags \"+HOME+Lisa\")
391 (\"hp\" tags \"+HOME+Peter\")
392 (\"hk\" tags \"+HOME+Kim\")))"
393 :group
'org-agenda-custom-commands
395 (choice :value
("x" "Describe command here" tags
"" nil
)
396 (list :tag
"Single command"
397 (string :tag
"Access Key(s) ")
398 (option (string :tag
"Description"))
400 (const :tag
"Agenda" agenda
)
401 (const :tag
"TODO list" alltodo
)
402 (const :tag
"Search words" search
)
403 (const :tag
"Stuck projects" stuck
)
404 (const :tag
"Tags/Property match (all agenda files)" tags
)
405 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
406 (const :tag
"TODO keyword search (all agenda files)" todo
)
407 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
408 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
409 (const :tag
"Occur tree (current buffer)" occur-tree
)
410 (sexp :tag
"Other, user-defined function"))
411 (string :tag
"Match (only for some commands)")
412 ,org-agenda-custom-commands-local-options
413 (option (repeat :tag
"Export" (file :tag
"Export to"))))
414 (list :tag
"Command series, all agenda files"
415 (string :tag
"Access Key(s)")
416 (string :tag
"Description ")
417 (repeat :tag
"Component"
420 (const :format
"" agenda
)
421 (const :tag
"" :format
"" "")
422 ,org-agenda-custom-commands-local-options
)
423 (list :tag
"TODO list (all keywords)"
424 (const :format
"" alltodo
)
425 (const :tag
"" :format
"" "")
426 ,org-agenda-custom-commands-local-options
)
427 (list :tag
"Search words"
428 (const :format
"" search
)
429 (string :tag
"Match")
430 ,org-agenda-custom-commands-local-options
)
431 (list :tag
"Stuck projects"
432 (const :format
"" stuck
)
433 (const :tag
"" :format
"" "")
434 ,org-agenda-custom-commands-local-options
)
435 (list :tag
"Tags search"
436 (const :format
"" tags
)
437 (string :tag
"Match")
438 ,org-agenda-custom-commands-local-options
)
439 (list :tag
"Tags search, TODO entries only"
440 (const :format
"" tags-todo
)
441 (string :tag
"Match")
442 ,org-agenda-custom-commands-local-options
)
443 (list :tag
"TODO keyword search"
444 (const :format
"" todo
)
445 (string :tag
"Match")
446 ,org-agenda-custom-commands-local-options
)
447 (list :tag
"Other, user-defined function"
448 (symbol :tag
"function")
449 (string :tag
"Match")
450 ,org-agenda-custom-commands-local-options
)))
452 (repeat :tag
"Settings for entire command set"
453 (list (variable :tag
"Any variable")
454 (sexp :tag
"Value")))
455 (option (repeat :tag
"Export" (file :tag
"Export to"))))
456 (cons :tag
"Prefix key documentation"
457 (string :tag
"Access Key(s)")
458 (string :tag
"Description ")))))
460 (defcustom org-agenda-query-register ?o
461 "The register holding the current query string.
462 The purpose of this is that if you construct a query string interactively,
463 you can then use it to define a custom command."
464 :group
'org-agenda-custom-commands
467 (defcustom org-stuck-projects
468 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
469 "How to identify stuck projects.
470 This is a list of four items:
471 1. A tags/todo/property matcher string that is used to identify a project.
472 See the manual for a description of tag and property searches.
473 The entire tree below a headline matched by this is considered one project.
474 2. A list of TODO keywords identifying non-stuck projects.
475 If the project subtree contains any headline with one of these todo
476 keywords, the project is considered to be not stuck. If you specify
477 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
478 3. A list of tags identifying non-stuck projects.
479 If the project subtree contains any headline with one of these tags,
480 the project is considered to be not stuck. If you specify \"*\" as
481 a tag, any tag will mark the project unstuck. Note that this is about
482 the explicit presence of a tag somewhere in the subtree, inherited
483 tags to not count here. If inherited tags make a project not stuck,
484 use \"-TAG\" in the tags part of the matcher under (1.) above.
485 4. An arbitrary regular expression matching non-stuck projects.
487 If the project turns out to be not stuck, search continues also in the
488 subtree to see if any of the subtasks have project status.
490 See also the variable `org-tags-match-list-sublevels' which applies
491 to projects matched by this search as well.
493 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
494 or `C-c a #' to produce the list."
495 :group
'org-agenda-custom-commands
497 (string :tag
"Tags/TODO match to identify a project")
498 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
499 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
500 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
502 (defcustom org-agenda-filter-effort-default-operator
"<"
503 "The default operator for effort estimate filtering.
504 If you select an effort estimate limit without first pressing an operator,
505 this one will be used."
506 :group
'org-agenda-custom-commands
507 :type
'(choice (const :tag
"less or equal" "<")
508 (const :tag
"greater or equal"">")
509 (const :tag
"equal" "=")))
511 (defgroup org-agenda-skip nil
512 "Options concerning skipping parts of agenda files."
513 :tag
"Org Agenda Skip"
515 (defgroup org-agenda-daily
/weekly nil
516 "Options concerning the daily/weekly agenda."
517 :tag
"Org Agenda Daily/Weekly"
519 (defgroup org-agenda-todo-list nil
520 "Options concerning the global todo list agenda view."
521 :tag
"Org Agenda Todo List"
523 (defgroup org-agenda-match-view nil
524 "Options concerning the general tags/property/todo match agenda view."
525 :tag
"Org Agenda Match View"
527 (defgroup org-agenda-search-view nil
528 "Options concerning the general tags/property/todo match agenda view."
529 :tag
"Org Agenda Match View"
532 (defvar org-agenda-archives-mode nil
533 "Non-nil means the agenda will include archived items.
534 If this is the symbol `trees', trees in the selected agenda scope
535 that are marked with the ARCHIVE tag will be included anyway. When this is
536 t, also all archive files associated with the current selection of agenda
537 files will be included.")
539 (defcustom org-agenda-skip-comment-trees t
540 "Non-nil means skip trees that start with the COMMENT keyword.
541 When nil, these trees are also scanned by agenda commands."
542 :group
'org-agenda-skip
545 (defcustom org-agenda-todo-list-sublevels t
546 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
547 When nil, the sublevels of a TODO entry are not checked, resulting in
548 potentially much shorter TODO lists."
549 :group
'org-agenda-skip
550 :group
'org-agenda-todo-list
553 (defcustom org-agenda-todo-ignore-with-date nil
554 "Non-nil means don't show entries with a date in the global todo list.
555 You can use this if you prefer to mark mere appointments with a TODO keyword,
556 but don't want them to show up in the TODO list.
557 When this is set, it also covers deadlines and scheduled items, the settings
558 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
560 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
561 :group
'org-agenda-skip
562 :group
'org-agenda-todo-list
565 (defcustom org-agenda-todo-ignore-scheduled nil
566 "Non-nil means, ignore some scheduled TODO items when making TODO list.
567 This applies when creating the global todo list.
570 past Don't show entries scheduled today or in the past.
572 future Don't show entries scheduled in the future.
573 The idea behind this is that by scheduling it, you don't want to
574 think about it until the scheduled date.
576 all Don't show any scheduled entries in the global todo list.
577 The idea behind this is that by scheduling it, you have already
578 \"taken care\" of this item.
580 t Same as `all', for backward compatibility.
582 See also `org-agenda-todo-ignore-with-date'.
583 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
584 to make his option also apply to the tags-todo list."
585 :group
'org-agenda-skip
586 :group
'org-agenda-todo-list
588 (const :tag
"Ignore future-scheduled todos" future
)
589 (const :tag
"Ignore past- or present-scheduled todos" past
)
590 (const :tag
"Ignore all scheduled todos" all
)
591 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
592 (const :tag
"Show scheduled todos" nil
)))
594 (defcustom org-agenda-todo-ignore-deadlines nil
595 "Non-nil means ignore some deadlined TODO items when making TODO list.
596 There are different motivations for using different values, please think
597 carefully when configuring this variable.
599 This applies when creating the global todo list.
602 near Don't show near deadline entries. A deadline is near when it is
603 closer than `org-deadline-warning-days' days. The idea behind this
604 is that such items will appear in the agenda anyway.
606 far Don't show TODO entries where a deadline has been defined, but
607 the deadline is not near. This is useful if you don't want to
608 use the todo list to figure out what to do now.
610 past Don't show entries with a deadline timestamp for today or in the past.
612 future Don't show entries with a deadline timestamp in the future, not even
613 when they become `near' ones. Use it with caution.
615 all Ignore all TODO entries that do have a deadline.
617 t Same as `near', for backward compatibility.
619 See also `org-agenda-todo-ignore-with-date'.
620 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
621 to make his option also apply to the tags-todo list."
622 :group
'org-agenda-skip
623 :group
'org-agenda-todo-list
625 (const :tag
"Ignore near deadlines" near
)
626 (const :tag
"Ignore near deadlines (compatibility)" t
)
627 (const :tag
"Ignore far deadlines" far
)
628 (const :tag
"Ignore all TODOs with a deadlines" all
)
629 (const :tag
"Show all TODOs, even if they have a deadline" nil
)))
631 (defcustom org-agenda-tags-todo-honor-ignore-options nil
632 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
634 `org-agenda-todo-ignore-with-date',
635 `org-agenda-todo-ignore-scheduled'
636 `org-agenda-todo-ignore-deadlines'
637 make the global TODO list skip entries that have time stamps of certain
638 kinds. If this option is set, the same options will also apply for the
639 tags-todo search, which is the general tags/property matcher
640 restricted to unfinished TODO entries only."
641 :group
'org-agenda-skip
642 :group
'org-agenda-todo-list
643 :group
'org-agenda-match-view
646 (defcustom org-agenda-skip-scheduled-if-done nil
647 "Non-nil means don't show scheduled items in agenda when they are done.
648 This is relevant for the daily/weekly agenda, not for the TODO list. And
649 it applies only to the actual date of the scheduling. Warnings about
650 an item with a past scheduling dates are always turned off when the item
652 :group
'org-agenda-skip
653 :group
'org-agenda-daily
/weekly
656 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
657 "Non-nil means skip scheduling line if same entry shows because of deadline.
658 In the agenda of today, an entry can show up multiple times because
659 it is both scheduled and has a nearby deadline, and maybe a plain time
661 When this variable is t, then only the deadline is shown and the fact that
662 the entry is scheduled today or was scheduled previously is not shown.
663 When this variable is nil, the entry will be shown several times. When
664 the variable is the symbol `not-today', then skip scheduled previously,
665 but not scheduled today."
666 :group
'org-agenda-skip
667 :group
'org-agenda-daily
/weekly
669 (const :tag
"Never" nil
)
670 (const :tag
"Always" t
)
671 (const :tag
"Not when scheduled today" not-today
)))
673 (defcustom org-agenda-skip-deadline-if-done nil
674 "Non-nil means don't show deadlines when the corresponding item is done.
675 When nil, the deadline is still shown and should give you a happy feeling.
676 This is relevant for the daily/weekly agenda. And it applied only to the
677 actually date of the deadline. Warnings about approaching and past-due
678 deadlines are always turned off when the item is DONE."
679 :group
'org-agenda-skip
680 :group
'org-agenda-daily
/weekly
683 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
684 "Non-nil means skip deadline prewarning when entry is also scheduled.
685 This will apply on all days where a prewarning for the deadline would
686 be shown, but not at the day when the entry is actually due. On that day,
687 the deadline will be shown anyway.
688 This variable may be set to nil, t, or a number which will then give
689 the number of days before the actual deadline when the prewarnings
691 This can be used in a workflow where the first showing of the deadline will
692 trigger you to schedule it, and then you don't want to be reminded of it
693 because you will take care of it on the day when scheduled."
694 :group
'org-agenda-skip
695 :group
'org-agenda-daily
/weekly
697 (const :tag
"Alwas show prewarning" nil
)
698 (const :tag
"Remove prewarning if entry is scheduled" t
)
699 (integer :tag
"Restart prewarning N days before deadline")))
701 (defcustom org-agenda-skip-additional-timestamps-same-entry t
702 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
703 When non-nil, after the search for timestamps has matched once in an
704 entry, the rest of the entry will not be searched."
705 :group
'org-agenda-skip
708 (defcustom org-agenda-skip-timestamp-if-done nil
709 "Non-nil means don't select item by timestamp or -range if it is DONE."
710 :group
'org-agenda-skip
711 :group
'org-agenda-daily
/weekly
714 (defcustom org-agenda-dim-blocked-tasks t
715 "Non-nil means dim blocked tasks in the agenda display.
716 This causes some overhead during agenda construction, but if you
717 have turned on `org-enforce-todo-dependencies',
718 `org-enforce-todo-checkbox-dependencies', or any other blocking
719 mechanism, this will create useful feedback in the agenda.
721 Instead of t, this variable can also have the value `invisible'.
722 Then blocked tasks will be invisible and only become visible when
723 they become unblocked. An exemption to this behavior is when a task is
724 blocked because of unchecked checkboxes below it. Since checkboxes do
725 not show up in the agenda views, making this task invisible you remove any
726 trace from agenda views that there is something to do. Therefore, a task
727 that is blocked because of checkboxes will never be made invisible, it
728 will only be dimmed."
729 :group
'org-agenda-daily
/weekly
730 :group
'org-agenda-todo-list
732 (const :tag
"Do not dim" nil
)
733 (const :tag
"Dim to a grey face" t
)
734 (const :tag
"Make invisible" invisible
)))
736 (defcustom org-timeline-show-empty-dates
3
737 "Non-nil means `org-timeline' also shows dates without an entry.
738 When nil, only the days which actually have entries are shown.
739 When t, all days between the first and the last date are shown.
740 When an integer, show also empty dates, but if there is a gap of more than
741 N days, just insert a special line indicating the size of the gap."
742 :group
'org-agenda-skip
744 (const :tag
"None" nil
)
746 (integer :tag
"at most")))
748 (defgroup org-agenda-startup nil
749 "Options concerning initial settings in the Agenda in Org Mode."
750 :tag
"Org Agenda Startup"
753 (defcustom org-agenda-menu-show-matcher t
754 "Non-nil menas show the match string in the agenda dispatcher menu.
755 When nil, the matcher string is not shown, but is put into the help-echo
756 property so than moving the mouse over the command shows it.
757 Setting it to nil is good if matcher strings are very long and/or if
758 you wnat to use two-column display (see `org-agenda-menu-two-column')."
762 (defcustom org-agenda-menu-two-column nil
763 "Non-nil means, use two columns to show custom commands in the dispatcher.
764 If you use this, you probably want to set `org-agenda-menu-show-matcher'
769 (defcustom org-finalize-agenda-hook nil
770 "Hook run just before displaying an agenda buffer."
771 :group
'org-agenda-startup
774 (defcustom org-agenda-mouse-1-follows-link nil
775 "Non-nil means mouse-1 on a link will follow the link in the agenda.
776 A longer mouse click will still set point. Does not work on XEmacs.
777 Needs to be set before org.el is loaded."
778 :group
'org-agenda-startup
781 (defcustom org-agenda-start-with-follow-mode nil
782 "The initial value of follow mode in a newly created agenda window."
783 :group
'org-agenda-startup
786 (defcustom org-agenda-show-outline-path t
787 "Non-nil means show outline path in echo area after line motion."
788 :group
'org-agenda-startup
791 (defcustom org-agenda-start-with-entry-text-mode nil
792 "The initial value of entry-text-mode in a newly created agenda window."
793 :group
'org-agenda-startup
796 (defcustom org-agenda-entry-text-maxlines
5
797 "Number of text lines to be added when `E' is pressed in the agenda.
799 Note that this variable only used during agenda display. Add add entry text
800 when exporting the agenda, configure the variable
801 `org-agenda-add-entry-ext-maxlines'."
805 (defcustom org-agenda-entry-text-exclude-regexps nil
806 "List of regular expressions to clean up entry text.
807 The complete matches of all regular expressions in this list will be
808 removed from entry text before it is shown in the agenda."
810 :type
'(repeat (regexp)))
812 (defvar org-agenda-entry-text-cleanup-hook nil
813 "Hook that is run after basic cleanup of entry text to be shown in agenda.
814 This cleanup is done in a temporary buffer, so the function may inspect and
815 change the entire buffer.
816 Some default stuff like drawers and scheduling/deadline dates will already
817 have been removed when this is called, as will any matches for regular
818 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
820 (defvar org-agenda-include-inactive-timestamps nil
821 "Non-nil means include inactive time stamps in agenda and timeline.")
823 (defgroup org-agenda-windows nil
824 "Options concerning the windows used by the Agenda in Org Mode."
825 :tag
"Org Agenda Windows"
828 (defcustom org-agenda-window-setup
'reorganize-frame
829 "How the agenda buffer should be displayed.
830 Possible values for this option are:
832 current-window Show agenda in the current window, keeping all other windows.
833 other-window Use `switch-to-buffer-other-window' to display agenda.
834 reorganize-frame Show only two windows on the current frame, the current
835 window and the agenda.
836 other-frame Use `switch-to-buffer-other-frame' to display agenda.
837 Also, when exiting the agenda, kill that frame.
838 See also the variable `org-agenda-restore-windows-after-quit'."
839 :group
'org-agenda-windows
841 (const current-window
)
844 (const reorganize-frame
)))
846 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
847 "The min and max height of the agenda window as a fraction of frame height.
848 The value of the variable is a cons cell with two numbers between 0 and 1.
849 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
850 :group
'org-agenda-windows
851 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
853 (defcustom org-agenda-restore-windows-after-quit nil
854 "Non-nil means restore window configuration open exiting agenda.
855 Before the window configuration is changed for displaying the agenda,
856 the current status is recorded. When the agenda is exited with
857 `q' or `x' and this option is set, the old state is restored. If
858 `org-agenda-window-setup' is `other-frame', the value of this
859 option will be ignored."
860 :group
'org-agenda-windows
863 (defcustom org-agenda-ndays
7
864 "Number of days to include in overview display.
866 Custom commands can set this variable in the options section."
867 :group
'org-agenda-daily
/weekly
870 (defcustom org-agenda-start-on-weekday
1
871 "Non-nil means start the overview always on the specified weekday.
872 0 denotes Sunday, 1 denotes Monday etc.
873 When nil, always start on the current day.
874 Custom commands can set this variable in the options section."
875 :group
'org-agenda-daily
/weekly
876 :type
'(choice (const :tag
"Today" nil
)
877 (integer :tag
"Weekday No.")))
879 (defcustom org-agenda-show-all-dates t
880 "Non-nil means `org-agenda' shows every day in the selected range.
881 When nil, only the days which actually have entries are shown."
882 :group
'org-agenda-daily
/weekly
885 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
886 "Format string for displaying dates in the agenda.
887 Used by the daily/weekly agenda and by the timeline. This should be
888 a format string understood by `format-time-string', or a function returning
889 the formatted date as a string. The function must take a single argument,
890 a calendar-style date list like (month day year)."
891 :group
'org-agenda-daily
/weekly
893 (string :tag
"Format string")
894 (function :tag
"Function")))
896 (defun org-agenda-format-date-aligned (date)
897 "Format a date string for display in the daily/weekly agenda, or timeline.
898 This function makes sure that dates are aligned for easy reading."
900 (let* ((dayname (calendar-day-name date
))
902 (day-of-week (calendar-day-of-week date
))
904 (monthname (calendar-month-name month
))
906 (iso-week (org-days-to-iso-week
907 (calendar-absolute-from-gregorian date
)))
908 (weekyear (cond ((and (= month
1) (>= iso-week
52))
910 ((and (= month
12) (<= iso-week
1))
913 (weekstring (if (= day-of-week
1)
914 (format " W%02d" iso-week
)
916 (format "%-10s %2d %s %4d%s"
917 dayname day monthname year weekstring
)))
919 (defcustom org-agenda-timegrid-use-ampm nil
920 "When set, show AM/PM style timestamps on the timegrid."
924 (defun org-agenda-time-of-day-to-ampm (time)
925 "Convert TIME of a string like '13:45' to an AM/PM style time string."
926 (let* ((hour-number (string-to-number (substring time
0 -
3)))
927 (minute (substring time -
2))
930 ((equal hour-number
12)
934 (setq hour-number
(- hour-number
12))))
936 (if org-agenda-time-leading-zero
937 (format "%02d" hour-number
)
938 (format "%02s" (number-to-string hour-number
)))
941 (defun org-agenda-time-of-day-to-ampm-maybe (time)
942 "Conditionally convert TIME to AM/PM format
943 based on `org-agenda-timegrid-use-ampm'"
944 (if org-agenda-timegrid-use-ampm
945 (org-agenda-time-of-day-to-ampm time
)
948 (defcustom org-agenda-time-leading-zero nil
949 "Non-nil means use leading zero for military times in agenda.
950 For example, 9:30am would become 09:30 rather than 9:30."
951 :group
'org-agenda-daily
/weekly
954 (defcustom org-agenda-weekend-days
'(6 0)
955 "Which days are weekend?
956 These days get the special face `org-agenda-date-weekend' in the agenda
957 and timeline buffers."
958 :group
'org-agenda-daily
/weekly
959 :type
'(set :greedy t
960 (const :tag
"Monday" 1)
961 (const :tag
"Tuesday" 2)
962 (const :tag
"Wednesday" 3)
963 (const :tag
"Thursday" 4)
964 (const :tag
"Friday" 5)
965 (const :tag
"Saturday" 6)
966 (const :tag
"Sunday" 0)))
968 (defcustom org-agenda-include-diary nil
969 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
970 Custom commands can set this variable in the options section."
971 :group
'org-agenda-daily
/weekly
974 (defcustom org-agenda-include-deadlines t
975 "If non-nil, include entries within their deadline warning period.
976 Custom commands can set this variable in the options section."
977 :group
'org-agenda-daily
/weekly
980 (defcustom org-agenda-include-all-todo nil
981 "Set means weekly/daily agenda will always contain all TODO entries.
982 The TODO entries will be listed at the top of the agenda, before
983 the entries for specific days.
984 This option is deprecated, it is better to define a block agenda instead."
985 :group
'org-agenda-daily
/weekly
988 (defcustom org-agenda-repeating-timestamp-show-all t
989 "Non-nil means show all occurrences of a repeating stamp in the agenda.
990 When nil, only one occurrence is shown, either today or the
991 nearest into the future."
992 :group
'org-agenda-daily
/weekly
995 (defcustom org-scheduled-past-days
10000
996 "No. of days to continue listing scheduled items that are not marked DONE.
997 When an item is scheduled on a date, it shows up in the agenda on this
998 day and will be listed until it is marked done for the number of days
1000 :group
'org-agenda-daily
/weekly
1003 (defcustom org-agenda-log-mode-items
'(closed clock
)
1004 "List of items that should be shown in agenda log mode.
1005 This list may contain the following symbols:
1007 closed Show entries that have been closed on that day.
1008 clock Show entries that have received clocked time on that day.
1009 state Show all logged state changes.
1010 Note that instead of changing this variable, you can also press `C-u l' in
1011 the agenda to display all available LOG items temporarily."
1012 :group
'org-agenda-daily
/weekly
1013 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
1015 (defcustom org-agenda-log-mode-add-notes t
1016 "Non-nil means add first line of notes to log entries in agenda views.
1017 If a log item like a state change or a clock entry is associated with
1018 notes, the first line of these notes will be added to the entry in the
1020 :group
'org-agenda-daily
/weekly
1023 (defcustom org-agenda-start-with-log-mode nil
1024 "The initial value of log-mode in a newly created agenda window."
1025 :group
'org-agenda-startup
1026 :group
'org-agenda-daily
/weekly
1029 (defcustom org-agenda-start-with-clockreport-mode nil
1030 "The initial value of clockreport-mode in a newly created agenda window."
1031 :group
'org-agenda-startup
1032 :group
'org-agenda-daily
/weekly
1035 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
1036 "Property list with parameters for the clocktable in clockreport mode.
1037 This is the display mode that shows a clock table in the daily/weekly
1038 agenda, the properties for this dynamic block can be set here.
1039 The usual clocktable parameters are allowed here, but you cannot set
1040 the properties :name, :tstart, :tend, :block, and :scope - these will
1041 be overwritten to make sure the content accurately reflects the
1042 current display in the agenda."
1043 :group
'org-agenda-daily
/weekly
1046 (defcustom org-agenda-search-view-always-boolean nil
1047 "Non-nil means the search string is interpreted as individual parts.
1049 The search string for search view can either be interpreted as a phrase,
1050 or as a list of snippets that define a boolean search for a number of
1053 When this is non-nil, the string will be split on whitespace, and each
1054 snippet will be searched individually, and all must match in order to
1055 select an entry. A snippet is then a single string of non-white
1056 characters, or a string in double quotes, or a regexp in {} braces.
1057 If a snippet is preceded by \"-\", the snippet must *not* match.
1058 \"+\" is syntactic sugar for positive selection. Each snippet may
1059 be found as a full word or a partial word, but see the variable
1060 `org-agenda-search-view-force-full-words'.
1062 When this is nil, search will look for the entire search phrase as one,
1063 with each space character matching any amount of whitespace, including
1066 Even when this is nil, you can still switch to Boolean search dynamically
1067 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1068 is a regexp marked with braces like \"{abc}\", this will also switch to
1070 :group
'org-agenda-search-view
1073 (if (fboundp 'defvaralias
)
1074 (defvaralias 'org-agenda-search-view-search-words-only
1075 'org-agenda-search-view-always-boolean
))
1077 (defcustom org-agenda-search-view-force-full-words nil
1078 "Non-nil means, search words must be matches as complete words.
1079 When nil, they may also match part of a word."
1080 :group
'org-agenda-search-view
1083 (defgroup org-agenda-time-grid nil
1084 "Options concerning the time grid in the Org-mode Agenda."
1085 :tag
"Org Agenda Time Grid"
1088 (defcustom org-agenda-search-headline-for-time t
1089 "Non-nil means search headline for a time-of-day.
1090 If the headline contains a time-of-day in one format or another, it will
1091 be used to sort the entry into the time sequence of items for a day.
1092 Some people have time stamps in the headline that refer to the creation
1093 time or so, and then this produces an unwanted side effect. If this is
1094 the case for your, use this variable to turn off searching the headline
1096 :group
'org-agenda-time-grid
1099 (defcustom org-agenda-use-time-grid t
1100 "Non-nil means show a time grid in the agenda schedule.
1101 A time grid is a set of lines for specific times (like every two hours between
1102 8:00 and 20:00). The items scheduled for a day at specific times are
1103 sorted in between these lines.
1104 For details about when the grid will be shown, and what it will look like, see
1105 the variable `org-agenda-time-grid'."
1106 :group
'org-agenda-time-grid
1109 (defcustom org-agenda-time-grid
1110 '((daily today require-timed
)
1112 (800 1000 1200 1400 1600 1800 2000))
1114 "The settings for time grid for agenda display.
1115 This is a list of three items. The first item is again a list. It contains
1116 symbols specifying conditions when the grid should be displayed:
1118 daily if the agenda shows a single day
1119 weekly if the agenda shows an entire week
1120 today show grid on current date, independent of daily/weekly display
1121 require-timed show grid only if at least one item has a time specification
1123 The second item is a string which will be placed behind the grid time.
1125 The third item is a list of integers, indicating the times that should have
1127 :group
'org-agenda-time-grid
1130 (set :greedy t
:tag
"Grid Display Options"
1131 (const :tag
"Show grid in single day agenda display" daily
)
1132 (const :tag
"Show grid in weekly agenda display" weekly
)
1133 (const :tag
"Always show grid for today" today
)
1134 (const :tag
"Show grid only if any timed entries are present"
1136 (const :tag
"Skip grid times already present in an entry"
1138 (string :tag
"Grid String")
1139 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1141 (defgroup org-agenda-sorting nil
1142 "Options concerning sorting in the Org-mode Agenda."
1143 :tag
"Org Agenda Sorting"
1146 (defcustom org-agenda-sorting-strategy
1147 '((agenda habit-down time-up priority-down category-keep
)
1148 (todo priority-down category-keep
)
1149 (tags priority-down category-keep
)
1150 (search category-keep
))
1151 "Sorting structure for the agenda items of a single day.
1152 This is a list of symbols which will be used in sequence to determine
1153 if an entry should be listed before another entry. The following
1154 symbols are recognized:
1156 time-up Put entries with time-of-day indications first, early first
1157 time-down Put entries with time-of-day indications first, late first
1158 category-keep Keep the default order of categories, corresponding to the
1159 sequence in `org-agenda-files'.
1160 category-up Sort alphabetically by category, A-Z.
1161 category-down Sort alphabetically by category, Z-A.
1162 tag-up Sort alphabetically by last tag, A-Z.
1163 tag-down Sort alphabetically by last tag, Z-A.
1164 priority-up Sort numerically by priority, high priority last.
1165 priority-down Sort numerically by priority, high priority first.
1166 todo-state-up Sort by todo state, tasks that are done last.
1167 todo-state-down Sort by todo state, tasks that are done first.
1168 effort-up Sort numerically by estimated effort, high effort last.
1169 effort-down Sort numerically by estimated effort, high effort first.
1170 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1171 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1172 habit-up Put entries that are habits first
1173 habit-down Put entries that are habits last
1174 alpha-up Sort headlines alphabetically
1175 alpha-down Sort headlines alphabetically, reversed
1177 The different possibilities will be tried in sequence, and testing stops
1178 if one comparison returns a \"not-equal\". For example, the default
1179 '(time-up category-keep priority-down)
1180 means: Pull out all entries having a specified time of day and sort them,
1181 in order to make a time schedule for the current day the first thing in the
1182 agenda listing for the day. Of the entries without a time indication, keep
1183 the grouped in categories, don't sort the categories, but keep them in
1184 the sequence given in `org-agenda-files'. Within each category sort by
1187 Leaving out `category-keep' would mean that items will be sorted across
1188 categories by priority.
1190 Instead of a single list, this can also be a set of list for specific
1191 contents, with a context symbol in the car of the list, any of
1192 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1194 Custom commands can bind this variable in the options section."
1195 :group
'org-agenda-sorting
1197 (repeat :tag
"General" ,org-sorting-choice
)
1198 (list :tag
"Individually"
1199 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1200 (repeat ,org-sorting-choice
))
1201 (cons (const :tag
"Strategy for TODO lists" todo
)
1202 (repeat ,org-sorting-choice
))
1203 (cons (const :tag
"Strategy for Tags matches" tags
)
1204 (repeat ,org-sorting-choice
))
1205 (cons (const :tag
"Strategy for search matches" search
)
1206 (repeat ,org-sorting-choice
)))))
1208 (defcustom org-agenda-cmp-user-defined nil
1209 "A function to define the comparison `user-defined'.
1210 This function must receive two arguments, agenda entry a and b.
1211 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1212 the user comparison, return nil.
1213 When this is defined, you can make `user-defined-up' and `user-defined-down'
1214 part of an agenda sorting strategy."
1215 :group
'org-agenda-sorting
1218 (defcustom org-sort-agenda-notime-is-late t
1219 "Non-nil means items without time are considered late.
1220 This is only relevant for sorting. When t, items which have no explicit
1221 time like 15:30 will be considered as 99:01, i.e. later than any items which
1222 do have a time. When nil, the default time is before 0:00. You can use this
1223 option to decide if the schedule for today should come before or after timeless
1225 :group
'org-agenda-sorting
1228 (defcustom org-sort-agenda-noeffort-is-high t
1229 "Non-nil means items without effort estimate are sorted as high effort.
1230 This also applies when filtering an agenda view with respect to the
1231 < or > effort operator. Then, tasks with no effort defined will be treated
1232 as tasks with high effort.
1233 When nil, such items are sorted as 0 minutes effort."
1234 :group
'org-agenda-sorting
1237 (defgroup org-agenda-line-format nil
1238 "Options concerning the entry prefix in the Org-mode agenda display."
1239 :tag
"Org Agenda Line Format"
1242 (defcustom org-agenda-prefix-format
1243 '((agenda .
" %i %-12:c%?-12t% s")
1245 (todo .
" %i %-12:c")
1246 (tags .
" %i %-12:c")
1247 (search .
" %i %-12:c"))
1248 "Format specifications for the prefix of items in the agenda views.
1249 An alist with four entries, for the different agenda types. The keys to the
1250 sublists are `agenda', `timeline', `todo', and `tags'. The values
1252 This format works similar to a printf format, with the following meaning:
1254 %c the category of the item, \"Diary\" for entries from the diary, or
1255 as given by the CATEGORY keyword or derived from the file name.
1256 %i the icon category of the item, as give in
1257 `org-agenda-category-icon-alist'.
1258 %T the *last* tag of the item. Last because inherited tags come
1260 %t the time-of-day specification if one applies to the entry, in the
1262 %s Scheduling/Deadline information, a short string
1264 All specifiers work basically like the standard `%s' of printf, but may
1265 contain two additional characters: A question mark just after the `%' and
1266 a whitespace/punctuation character just before the final letter.
1268 If the first character after `%' is a question mark, the entire field
1269 will only be included if the corresponding value applies to the
1270 current entry. This is useful for fields which should have fixed
1271 width when present, but zero width when absent. For example,
1272 \"%?-12t\" will result in a 12 character time field if a time of the
1273 day is specified, but will completely disappear in entries which do
1276 If there is punctuation or whitespace character just before the final
1277 format letter, this character will be appended to the field value if
1278 the value is not empty. For example, the format \"%-12:c\" leads to
1279 \"Diary: \" if the category is \"Diary\". If the category were be
1280 empty, no additional colon would be inserted.
1282 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1283 - Indent the line with two space characters
1284 - Give the category in a 12 chars wide field, padded with whitespace on
1285 the right (because of `-'). Append a colon if there is a category
1287 - If there is a time-of-day, put it into a 12 chars wide field. If no
1288 time, don't put in an empty field, just skip it (because of '?').
1289 - Finally, put the scheduling information and append a whitespace.
1291 As another example, if you don't want the time-of-day of entries in
1292 the prefix, you could use:
1294 (setq org-agenda-prefix-format \" %-11:c% s\")
1296 See also the variables `org-agenda-remove-times-when-in-prefix' and
1297 `org-agenda-remove-tags'.
1299 Custom commands can set this variable in the options section."
1301 (string :tag
"General format")
1302 (list :greedy t
:tag
"View dependent"
1303 (cons (const agenda
) (string :tag
"Format"))
1304 (cons (const timeline
) (string :tag
"Format"))
1305 (cons (const todo
) (string :tag
"Format"))
1306 (cons (const tags
) (string :tag
"Format"))
1307 (cons (const search
) (string :tag
"Format"))))
1308 :group
'org-agenda-line-format
)
1310 (defvar org-prefix-format-compiled nil
1311 "The compiled version of the most recently used prefix format.
1312 See the variable `org-agenda-prefix-format'.")
1314 (defcustom org-agenda-todo-keyword-format
"%-1s"
1315 "Format for the TODO keyword in agenda lines.
1316 Set this to something like \"%-12s\" if you want all TODO keywords
1317 to occupy a fixed space in the agenda display."
1318 :group
'org-agenda-line-format
1321 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1322 "Text preceding timerange entries in the agenda view.
1323 This is a list with two strings. The first applies when the range
1324 is entirely on one day. The second applies if the range spans several days.
1325 The strings may have two \"%d\" format specifiers which will be filled
1326 with the sequence number of the days, and the total number of days in the
1327 range, respectively."
1328 :group
'org-agenda-line-format
1330 (string :tag
"Deadline today ")
1331 (choice :tag
"Deadline relative"
1332 (string :tag
"Format string")
1335 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1336 "Text preceding scheduled items in the agenda view.
1337 This is a list with two strings. The first applies when the item is
1338 scheduled on the current day. The second applies when it has been scheduled
1339 previously, it may contain a %d indicating that this is the nth time that
1340 this item is scheduled, due to automatic rescheduling of unfinished items
1341 for the following day. So this number is one larger than the number of days
1342 that passed since this item was scheduled first."
1343 :group
'org-agenda-line-format
1345 (string :tag
"Scheduled today ")
1346 (string :tag
"Scheduled previously")))
1348 (defcustom org-agenda-inactive-leader
"["
1349 "Text preceding item pulled into the agenda by inactive time stamps.
1350 These entries are added to the agenda when pressing \"[\"."
1351 :group
'org-agenda-line-format
1353 (string :tag
"Scheduled today ")
1354 (string :tag
"Scheduled previously")))
1356 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1357 "Text preceding deadline items in the agenda view.
1358 This is a list with two strings. The first applies when the item has its
1359 deadline on the current day. The second applies when it is in the past or
1360 in the future, it may contain %d to capture how many days away the deadline
1362 :group
'org-agenda-line-format
1364 (string :tag
"Deadline today ")
1365 (choice :tag
"Deadline relative"
1366 (string :tag
"Format string")
1369 (defcustom org-agenda-remove-times-when-in-prefix t
1370 "Non-nil means remove duplicate time specifications in agenda items.
1371 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1372 time-of-day specification in a headline or diary entry is extracted and
1373 placed into the prefix. If this option is non-nil, the original specification
1374 \(a timestamp or -range, or just a plain time(range) specification like
1375 11:30-4pm) will be removed for agenda display. This makes the agenda less
1377 The option can be t or nil. It may also be the symbol `beg', indicating
1378 that the time should only be removed when it is located at the beginning of
1379 the headline/diary entry."
1380 :group
'org-agenda-line-format
1382 (const :tag
"Always" t
)
1383 (const :tag
"Never" nil
)
1384 (const :tag
"When at beginning of entry" beg
)))
1386 (defcustom org-agenda-remove-timeranges-from-blocks nil
1387 "Non-nil means remove time ranges specifications in agenda
1388 items that span on several days."
1389 :group
'org-agenda-line-format
1392 (defcustom org-agenda-default-appointment-duration nil
1393 "Default duration for appointments that only have a starting time.
1394 When nil, no duration is specified in such cases.
1395 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1396 :group
'org-agenda-line-format
1398 (integer :tag
"Minutes")
1399 (const :tag
"No default duration")))
1401 (defcustom org-agenda-show-inherited-tags t
1402 "Non-nil means show inherited tags in each agenda line."
1403 :group
'org-agenda-line-format
1406 (defcustom org-agenda-hide-tags-regexp nil
1407 "Regular expression used to filter away specific tags in agenda views.
1408 This means that these tags will be present, but not be shown in the agenda
1409 line. Secondary filtering will still work on the hidden tags.
1410 Nil means don't hide any tags."
1411 :group
'org-agenda-line-format
1413 (const :tag
"Hide none" nil
)
1414 (string :tag
"Regexp ")))
1416 (defcustom org-agenda-remove-tags nil
1417 "Non-nil means remove the tags from the headline copy in the agenda.
1418 When this is the symbol `prefix', only remove tags when
1419 `org-agenda-prefix-format' contains a `%T' specifier."
1420 :group
'org-agenda-line-format
1422 (const :tag
"Always" t
)
1423 (const :tag
"Never" nil
)
1424 (const :tag
"When prefix format contains %T" prefix
)))
1426 (if (fboundp 'defvaralias
)
1427 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1428 'org-agenda-remove-tags
))
1430 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1431 "Shift tags in agenda items to this column.
1432 If this number is positive, it specifies the column. If it is negative,
1433 it means that the tags should be flushright to that column. For example,
1434 -80 works well for a normal 80 character screen."
1435 :group
'org-agenda-line-format
1438 (if (fboundp 'defvaralias
)
1439 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1441 (defcustom org-agenda-fontify-priorities
'cookies
1442 "Non-nil means highlight low and high priorities in agenda.
1443 When t, the highest priority entries are bold, lowest priority italic.
1444 However, settings in `org-priority-faces' will overrule these faces.
1445 When this variable is the symbol `cookies', only fontify the
1446 cookies, not the entire task.
1447 This may also be an association list of priority faces, whose
1448 keys are the character values of `org-highest-priority',
1449 `org-default-priority', and `org-lowest-priority' (the default values
1450 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1451 color as a string, or a list like `(:background \"Red\")'.
1452 If it is a color, the variable `org-faces-easy-properties'
1453 determines if it is a foreground or a background color."
1454 :group
'org-agenda-line-format
1456 (const :tag
"Never" nil
)
1457 (const :tag
"Defaults" t
)
1458 (const :tag
"Cookies only" cookies
)
1459 (repeat :tag
"Specify"
1460 (list (character :tag
"Priority" :value ?A
)
1461 (choice :tag
"Face "
1462 (string :tag
"Color")
1463 (sexp :tag
"Face"))))))
1465 (defcustom org-agenda-day-face-function nil
1466 "Function called to determine what face should be used to display a day.
1467 The only argument passed to that function is the day. It should
1468 returns a face, or nil if does not want to specify a face and let
1469 the normal rules apply."
1470 :group
'org-agenda-line-format
1473 (defcustom org-agenda-category-icon-alist nil
1474 "Alist of category icon to be displayed in agenda views.
1476 Each entry should have the following format:
1478 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1480 Where CATEGORY-REGEXP is a regexp matching the categories where
1481 the icon should be displayed.
1482 FILE-OR-DATA either a file path or a string containing image data.
1484 The other fields can be ommited safely if not needed:
1485 TYPE indicates the image type.
1486 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1488 PROPS are additional image attributes to assign to the image,
1489 like, e.g. `:ascent center'.
1491 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1493 If you want to set the display properties yourself, just put a
1494 list as second element:
1496 (CATEGORY-REGEXP (MY PROPERTY LIST))
1498 For example, to display a 16px horizontal space for Emacs
1499 category, you can use:
1501 (\"Emacs\" '(space . (:width (16))))"
1502 :group
'org-agenda-line-format
1503 :type
'(alist :key-type
(string :tag
"Regexp matching category")
1504 :value-type
(choice (list :tag
"Icon"
1505 (string :tag
"File or data")
1506 (symbol :tag
"Type")
1507 (boolean :tag
"Data?")
1508 (repeat :tag
"Extra image properties" :inline t symbol
))
1509 (list :tag
"Display properties" sexp
))))
1511 (defgroup org-agenda-column-view nil
1512 "Options concerning column view in the agenda."
1513 :tag
"Org Agenda Column View"
1516 (defcustom org-agenda-columns-show-summaries t
1517 "Non-nil means show summaries for columns displayed in the agenda view."
1518 :group
'org-agenda-column-view
1521 (defcustom org-agenda-columns-remove-prefix-from-item t
1522 "Non-nil means remove the prefix from a headline for agenda column view.
1523 The special ITEM field in the columns format contains the current line, with
1524 all information shown in other columns (like the TODO state or a tag).
1525 When this variable is non-nil, also the agenda prefix will be removed from
1526 the content of the ITEM field, to make sure as much as possible of the
1527 headline can be shown in the limited width of the field."
1531 (defcustom org-agenda-columns-compute-summary-properties t
1532 "Non-nil means recompute all summary properties before column view.
1533 When column view in the agenda is listing properties that have a summary
1534 operator, it can go to all relevant buffers and recompute the summaries
1535 there. This can mean overhead for the agenda column view, but is necessary
1536 to have thing up to date.
1537 As a special case, a CLOCKSUM property also makes sure that the clock
1538 computations are current."
1539 :group
'org-agenda-column-view
1542 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1543 "Non-nil means the duration of an appointment will add to day effort.
1544 The property to which appointment durations will be added is the one given
1545 in the option `org-effort-property'. If an appointment does not have
1546 an end time, `org-agenda-default-appointment-duration' will be used. If that
1547 is not set, an appointment without end time will not contribute to the time
1549 :group
'org-agenda-column-view
1552 (defcustom org-agenda-auto-exclude-function nil
1553 "A function called with a tag to decide if it is filtered on '/ RET'.
1554 The sole argument to the function, which is called once for each
1555 possible tag, is a string giving the name of the tag. The
1556 function should return either nil if the tag should be included
1557 as normal, or \"-<TAG>\" to exclude the tag.
1558 Note that for the purpose of tag filtering, only the lower-case version of
1559 all tags will be considered, so that this function will only ever see
1560 the lower-case version of all tags."
1568 (defmacro org-agenda-with-point-at-orig-entry
(string &rest body
)
1569 "Execute BODY with point at location given by `org-hd-marker' property.
1570 If STRING is non-nil, the text property will be fetched from position 0
1571 in that string. If STRING is nil, it will be fetched from the beginning
1572 of the current line."
1573 `(let ((marker (get-text-property (if string
0 (point-at-bol))
1574 'org-hd-marker string
)))
1575 (with-current-buffer (marker-buffer marker
)
1580 (defun org-add-agenda-custom-command (entry)
1581 "Replace or add a command in `org-agenda-custom-commands'.
1582 This is mostly for hacking and trying a new command - once the command
1583 works you probably want to add it to `org-agenda-custom-commands' for good."
1584 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1586 (setcdr ass
(cdr entry
))
1587 (push entry org-agenda-custom-commands
))))
1589 ;;; Define the Org-agenda-mode
1591 (defvar org-agenda-mode-map
(make-sparse-keymap)
1592 "Keymap for `org-agenda-mode'.")
1593 (if (fboundp 'defvaralias
)
1594 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1596 (defvar org-agenda-menu
) ; defined later in this file.
1597 (defvar org-agenda-restrict
) ; defined later in this file.
1598 (defvar org-agenda-follow-mode nil
)
1599 (defvar org-agenda-entry-text-mode nil
)
1600 (defvar org-agenda-clockreport-mode nil
)
1601 (defvar org-agenda-show-log nil
)
1602 (defvar org-agenda-redo-command nil
)
1603 (defvar org-agenda-query-string nil
)
1604 (defvar org-agenda-mode-hook nil
1605 "Hook for `org-agenda-mode', run after the mode is turned on.")
1606 (defvar org-agenda-type nil
)
1607 (defvar org-agenda-force-single-file nil
)
1608 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1610 (defun org-agenda-mode ()
1611 "Mode for time-sorted view on action items in Org-mode files.
1613 The following commands are available:
1615 \\{org-agenda-mode-map}"
1617 (kill-all-local-variables)
1618 (setq org-agenda-undo-list nil
1619 org-agenda-pending-undo-list nil
1620 org-agenda-bulk-marked-entries nil
)
1621 (setq major-mode
'org-agenda-mode
)
1622 ;; Keep global-font-lock-mode from turning on font-lock-mode
1623 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1624 (setq mode-name
"Org-Agenda")
1625 (use-local-map org-agenda-mode-map
)
1626 (easy-menu-add org-agenda-menu
)
1627 (if org-startup-truncated
(setq truncate-lines t
))
1628 (org-set-local 'line-move-visual nil
)
1629 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1630 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1631 ;; Make sure properties are removed when copying text
1632 (when (boundp 'buffer-substring-filters
)
1633 (org-set-local 'buffer-substring-filters
1635 (set-text-properties 0 (length x
) nil x
) x
)
1636 buffer-substring-filters
)))
1637 (unless org-agenda-keep-modes
1638 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1639 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1640 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1641 org-agenda-show-log org-agenda-start-with-log-mode
))
1644 '("Agenda") "Agenda Files"
1648 (if (get 'org-agenda-files
'org-restrict
)
1649 "Restricted to single file"
1651 '(org-edit-agenda-file-list)
1652 (not (get 'org-agenda-files
'org-restrict
)))
1654 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1655 (org-agenda-set-mode-name)
1657 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1658 (list 'org-agenda-mode-hook
)))
1660 (substitute-key-definition 'undo
'org-agenda-undo
1661 org-agenda-mode-map global-map
)
1662 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1663 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1664 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1665 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1666 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1667 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1668 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1669 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1670 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1671 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1672 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
1673 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
1674 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
1675 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1676 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1677 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1678 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1679 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
1680 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
1681 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1682 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1683 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1684 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1685 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1686 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1687 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1688 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1689 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1690 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1691 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1692 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1693 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1694 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1695 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1696 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1697 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1698 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1699 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1700 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1701 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1702 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1703 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1704 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1706 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1707 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1708 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1709 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1710 (while l (org-defkey org-agenda-mode-map
1711 (int-to-string (pop l)) 'digit-argument)))
1713 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1714 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1715 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1716 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1717 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1718 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1719 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1720 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1721 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1722 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1723 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1724 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1725 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1726 'org-clock-modify-effort-estimate)
1727 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1728 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1729 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1730 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1731 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1732 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1733 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1734 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1735 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1736 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1737 (substitute-key-definition 'next-line 'org-agenda-next-line
1738 org-agenda-mode-map global-map)
1739 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1740 org-agenda-mode-map global-map)
1741 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1742 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1743 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1744 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1745 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1746 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1747 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1748 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1749 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1750 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1751 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1752 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1753 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1754 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1755 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1756 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1757 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1758 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1759 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1760 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1761 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1762 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1763 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1764 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1765 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1766 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1767 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1768 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1769 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1770 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1772 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1773 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1774 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1775 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1776 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1777 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1778 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1779 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1780 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1781 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1783 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1784 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1785 (when org-agenda-mouse-1-follows-link
1786 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1787 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1792 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1793 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1794 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1795 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1798 ["Day View" org-agenda-day-view
1799 :active (org-agenda-check-type nil 'agenda)
1800 :style radio :selected (equal org-agenda-ndays 1)
1801 :keys "v d (or just d)"]
1802 ["Week View" org-agenda-week-view
1803 :active (org-agenda-check-type nil 'agenda)
1804 :style radio :selected (equal org-agenda-ndays 7)
1805 :keys "v w (or just w)"]
1806 ["Month View" org-agenda-month-view
1807 :active (org-agenda-check-type nil 'agenda)
1808 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1810 ["Year View" org-agenda-year-view
1811 :active (org-agenda-check-type nil 'agenda)
1812 :style radio :selected (member org-agenda-ndays '(365 366))
1815 ["Include Diary" org-agenda-toggle-diary
1816 :style toggle :selected org-agenda-include-diary
1817 :active (org-agenda-check-type nil 'agenda)]
1818 ["Include Deadlines" org-agenda-toggle-deadlines
1819 :style toggle :selected org-agenda-include-deadlines
1820 :active (org-agenda-check-type nil 'agenda)]
1821 ["Use Time Grid" org-agenda-toggle-time-grid
1822 :style toggle :selected org-agenda-use-time-grid
1823 :active (org-agenda-check-type nil 'agenda)]
1825 ["Show clock report" org-agenda-clockreport-mode
1826 :style toggle :selected org-agenda-clockreport-mode
1827 :active (org-agenda-check-type nil 'agenda)]
1828 ["Show some entry text" org-agenda-entry-text-mode
1829 :style toggle :selected org-agenda-entry-text-mode
1832 ["Show Logbook entries" org-agenda-log-mode
1833 :style toggle :selected org-agenda-show-log
1834 :active (org-agenda-check-type nil 'agenda 'timeline)
1835 :keys "v l (or just l)"]
1836 ["Include archived trees" org-agenda-archives-mode
1837 :style toggle :selected org-agenda-archives-mode :active t
1839 ["Include archive files" (org-agenda-archives-mode t)
1840 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1843 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1844 ["Write view to file" org-write-agenda t]
1845 ["Rebuild buffer" org-agenda-redo t]
1846 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1848 ["Show original entry" org-agenda-show t]
1849 ["Go To (other window)" org-agenda-goto t]
1850 ["Go To (this window)" org-agenda-switch-to t]
1851 ["Follow Mode" org-agenda-follow-mode
1852 :style toggle :selected org-agenda-follow-mode :active t]
1853 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1856 ["Cycle TODO" org-agenda-todo t]
1857 ["Next TODO set" org-agenda-todo-nextset t]
1858 ["Previous TODO set" org-agenda-todo-previousset t]
1859 ["Add note" org-agenda-add-note t])
1860 ("Archive/Refile/Delete"
1861 ["Archive default" org-agenda-archive-default t]
1862 ["Archive default" org-agenda-archive-default-with-confirmation t]
1863 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1864 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1865 ["Archive subtree" org-agenda-archive t]
1867 ["Refile" org-agenda-refile t]
1869 ["Delete subtree" org-agenda-kill t])
1871 ["Mark entry" org-agenda-bulk-mark t]
1872 ["Unmark entry" org-agenda-bulk-unmark t]
1873 ["Act on all marked" org-agenda-bulk-action t]
1874 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1876 ("Tags and Properties"
1877 ["Show all Tags" org-agenda-show-tags t]
1878 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1879 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1881 ["Column View" org-columns t])
1882 ("Deadline/Schedule"
1883 ["Schedule" org-agenda-schedule t]
1884 ["Set Deadline" org-agenda-deadline t]
1886 ["Mark item" org-agenda-action :active t :keys "k m"]
1887 ["Show mark item" org-agenda-action :active t :keys "k v"]
1888 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1889 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1891 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1892 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1893 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1894 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1895 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1896 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1897 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1899 ["Clock in" org-agenda-clock-in t]
1900 ["Clock out" org-agenda-clock-out t]
1901 ["Clock cancel" org-agenda-clock-cancel t]
1902 ["Goto running clock" org-clock-goto t]
1904 ["Set Effort" org-agenda-set-effort t]
1905 ["Change clocked effort" org-clock-modify-effort-estimate
1906 (org-clock-is-active)])
1908 ["Set Priority" org-agenda-priority t]
1909 ["Increase Priority" org-agenda-priority-up t]
1910 ["Decrease Priority" org-agenda-priority-down t]
1911 ["Show Priority" org-agenda-show-priority t])
1913 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1914 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1915 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1916 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1917 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1918 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1920 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1922 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1925 ["Push Files and Views" org-mobile-push t]
1926 ["Get Captured and Flagged" org-mobile-pull t]
1927 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1928 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1930 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1932 ["Quit" org-agenda-quit t]
1933 ["Exit and Release Buffers" org-agenda-exit t]
1938 (defvar org-agenda-allow-remote-undo t
1939 "Non-nil means allow remote undo from the agenda buffer.")
1940 (defvar org-agenda-undo-list nil
1941 "List of undoable operations in the agenda since last refresh.")
1942 (defvar org-agenda-undo-has-started-in nil
1943 "Buffers that have already seen `undo-start' in the current undo sequence.")
1944 (defvar org-agenda-pending-undo-list nil
1945 "In a series of undo commands, this is the list of remaining undo items.")
1948 (defun org-agenda-undo ()
1949 "Undo a remote editing step in the agenda.
1950 This undoes changes both in the agenda buffer and in the remote buffer
1951 that have been changed along."
1953 (or org-agenda-allow-remote-undo
1954 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1955 (if (not (eq this-command last-command))
1956 (setq org-agenda-undo-has-started-in nil
1957 org-agenda-pending-undo-list org-agenda-undo-list))
1958 (if (not org-agenda-pending-undo-list)
1959 (error "No further undo information"))
1960 (let* ((entry (pop org-agenda-pending-undo-list))
1961 buf line cmd rembuf)
1962 (setq cmd (pop entry) line (pop entry))
1963 (setq rembuf (nth 2 entry))
1964 (org-with-remote-undo rembuf
1965 (while (bufferp (setq buf (pop entry)))
1967 (with-current-buffer buf
1968 (let ((last-undo-buffer buf)
1969 (inhibit-read-only t))
1970 (unless (memq buf org-agenda-undo-has-started-in)
1971 (push buf org-agenda-undo-has-started-in)
1972 (make-local-variable 'pending-undo-list)
1974 (while (and pending-undo-list
1975 (listp pending-undo-list)
1976 (not (car pending-undo-list)))
1977 (pop pending-undo-list))
1979 (org-goto-line line)
1980 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1982 (defun org-verify-change-for-undo (l1 l2)
1983 "Verify that a real change occurred between the undo lists L1 and L2."
1984 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1985 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1990 (defvar org-agenda-restrict nil)
1991 (defvar org-agenda-restrict-begin (make-marker))
1992 (defvar org-agenda-restrict-end (make-marker))
1993 (defvar org-agenda-last-dispatch-buffer nil)
1994 (defvar org-agenda-overriding-restriction nil)
1997 (defun org-agenda (&optional arg keys restriction)
1998 "Dispatch agenda commands to collect entries to the agenda buffer.
1999 Prompts for a command to execute. Any prefix arg will be passed
2000 on to the selected command. The default selections are:
2002 a Call `org-agenda-list' to display the agenda for current day or week.
2003 t Call `org-todo-list' to display the global todo list.
2004 T Call `org-todo-list' to display the global todo list, select only
2005 entries with a specific TODO keyword (the user gets a prompt).
2006 m Call `org-tags-view' to display headlines with tags matching
2007 a condition (the user is prompted for the condition).
2008 M Like `m', but select only TODO entries, no ordinary headlines.
2009 L Create a timeline for the current buffer.
2010 e Export views to associated files.
2011 s Search entries for keywords.
2012 / Multi occur across all agenda files and also files listed
2013 in `org-agenda-text-search-extra-files'.
2014 < Restrict agenda commands to buffer, subtree, or region.
2015 Press several times to get the desired effect.
2016 > Remove a previous restriction.
2017 # List \"stuck\" projects.
2018 ! Configure what \"stuck\" means.
2019 C Configure custom agenda commands.
2021 More commands can be added by configuring the variable
2022 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2023 searches can be pre-defined in this way.
2025 If the current buffer is in Org-mode and visiting a file, you can also
2026 first press `<' once to indicate that the agenda should be temporarily
2027 \(until the next use of \\[org-agenda]) restricted to the current file.
2028 Pressing `<' twice means to restrict to the current subtree or region
2032 (let* ((prefix-descriptions nil)
2033 (org-agenda-window-setup (if (equal (buffer-name)
2034 org-agenda-buffer-name)
2036 org-agenda-window-setup))
2037 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2038 (org-agenda-custom-commands
2039 ;; normalize different versions
2043 (cond ((stringp (cdr x))
2044 (push x prefix-descriptions)
2046 ((stringp (nth 1 x)) x)
2047 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2048 (t (cons (car x) (cons "" (cdr x))))))
2049 org-agenda-custom-commands)))
2050 (buf (current-buffer))
2051 (bfn (buffer-file-name (buffer-base-buffer)))
2052 entry key type match lprops ans)
2053 ;; Turn off restriction unless there is an overriding one,
2054 (unless org-agenda-overriding-restriction
2055 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2056 ;; There is a request to keep the file list in place
2057 (put 'org-agenda-files 'org-restrict nil))
2058 (setq org-agenda-restrict nil)
2059 (move-marker org-agenda-restrict-begin nil)
2060 (move-marker org-agenda-restrict-end nil))
2061 ;; Delete old local properties
2062 (put 'org-agenda-redo-command 'org-lprops nil)
2063 ;; Remember where this call originated
2064 (setq org-agenda-last-dispatch-buffer (current-buffer))
2066 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2068 restriction (cdr ans)))
2069 ;; Establish the restriction, if any
2070 (when (and (not org-agenda-overriding-restriction) restriction)
2071 (put 'org-agenda-files 'org-restrict (list bfn))
2073 ((eq restriction 'region)
2074 (setq org-agenda-restrict t)
2075 (move-marker org-agenda-restrict-begin (region-beginning))
2076 (move-marker org-agenda-restrict-end (region-end)))
2077 ((eq restriction 'subtree)
2079 (setq org-agenda-restrict t)
2080 (org-back-to-heading t)
2081 (move-marker org-agenda-restrict-begin (point))
2082 (move-marker org-agenda-restrict-end
2083 (progn (org-end-of-subtree t)))))))
2085 ;; For example the todo list should not need it (but does...)
2087 ((setq entry (assoc keys org-agenda-custom-commands))
2088 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2090 (setq type (nth 2 entry) match (eval (nth 3 entry))
2091 lprops (nth 4 entry))
2092 (put 'org-agenda-redo-command 'org-lprops lprops)
2095 (org-let lprops '(org-agenda-list current-prefix-arg)))
2097 (org-let lprops '(org-todo-list current-prefix-arg)))
2099 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2101 (org-let lprops '(org-agenda-list-stuck-projects
2102 current-prefix-arg)))
2104 (org-let lprops '(org-tags-view current-prefix-arg match)))
2105 ((eq type 'tags-todo)
2106 (org-let lprops '(org-tags-view '(4) match)))
2108 (org-let lprops '(org-todo-list match)))
2109 ((eq type 'tags-tree)
2110 (org-check-for-org-mode)
2111 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2112 ((eq type 'todo-tree)
2113 (org-check-for-org-mode)
2115 '(org-occur (concat "^" outline-regexp "[ \t]*"
2116 (regexp-quote match) "\\>"))))
2117 ((eq type 'occur-tree)
2118 (org-check-for-org-mode)
2119 (org-let lprops '(org-occur match)))
2121 (org-let lprops '(funcall type match)))
2123 (org-let lprops '(funcall type match)))
2124 (t (error "Invalid custom agenda command type %s" type))))
2125 (org-run-agenda-series (nth 1 entry) (cddr entry))))
2127 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2128 (customize-variable 'org-agenda-custom-commands))
2129 ((equal keys "a") (call-interactively 'org-agenda-list))
2130 ((equal keys "s") (call-interactively 'org-search-view))
2131 ((equal keys "t") (call-interactively 'org-todo-list))
2132 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2133 ((equal keys "m") (call-interactively 'org-tags-view))
2134 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2135 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2136 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2140 (unless (current-message)
2141 (let* ((m (org-agenda-get-any-marker))
2142 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2145 "FLAGGING-NOTE ([?] for more info): "
2147 (replace-regexp-in-string
2149 (copy-sequence note))
2150 nil 'face 'org-warning)))))))
2153 (unless (org-mode-p)
2154 (error "This is not an Org-mode file"))
2156 (put 'org-agenda-files 'org-restrict (list bfn))
2157 (org-call-with-arg 'org-timeline arg)))
2158 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2159 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2160 ((equal keys "!") (customize-variable 'org-stuck-projects))
2161 (t (error "Invalid agenda key"))))))
2163 (defun org-agenda-normalize-custom-commands (cmds)
2167 (cond ((stringp (cdr x)) nil)
2168 ((stringp (nth 1 x)) x)
2169 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2170 (t (cons (car x) (cons "" (cdr x))))))
2173 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2174 "The user interface for selecting an agenda command."
2176 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2177 (restrict-ok (and bfn (org-mode-p)))
2178 (region-p (org-region-active-p))
2179 (custom org-agenda-custom-commands)
2181 restriction second-time
2182 c entry key type match prefixes rmheader header-end custom1 desc
2183 line lines left right n n1)
2184 (save-window-excursion
2185 (delete-other-windows)
2186 (org-switch-to-buffer-other-window " *Agenda Commands*")
2188 (insert (eval-when-compile
2191 Press key for an agenda command: < Buffer, subtree/region restriction
2192 -------------------------------- > Remove restriction
2193 a Agenda for current week or day e Export agenda views
2194 t List of all TODO entries T Entries with special TODO kwd
2195 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2196 L Timeline for current buffer # List stuck projects (!=configure)
2197 s Search for keywords C Configure custom agenda commands
2198 / Multi-occur ? Find :FLAGGED: entries
2201 (while (string-match
2202 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2204 (setq start (match-end 0))
2205 (add-text-properties (match-beginning 2) (match-end 2)
2206 '(face bold) header))
2208 (setq header-end (move-marker (make-marker) (point)))
2210 (setq custom1 custom)
2211 (when (eq rmheader t)
2213 (re-search-forward ":" nil t)
2214 (delete-region (match-end 0) (point-at-eol))
2217 (delete-region (match-end 0) (point-at-eol))
2218 (move-marker header-end (match-end 0)))
2219 (goto-char header-end)
2220 (delete-region (point) (point-max))
2222 ;; Produce all the lines that describe custom commands and prefixes
2224 (while (setq entry (pop custom1))
2225 (setq key (car entry) desc (nth 1 entry)
2227 match (nth 3 entry))
2228 (if (> (length key) 1)
2229 (add-to-list 'prefixes (string-to-char key))
2233 (org-add-props (copy-sequence key)
2236 ((string-match "\\S-" desc) desc)
2237 ((eq type 'agenda) "Agenda for current week or day")
2238 ((eq type 'alltodo) "List of all TODO entries")
2239 ((eq type 'search) "Word search")
2240 ((eq type 'stuck) "List of stuck projects")
2241 ((eq type 'todo) "TODO keyword")
2242 ((eq type 'tags) "Tags query")
2243 ((eq type 'tags-todo) "Tags (TODO)")
2244 ((eq type 'tags-tree) "Tags tree")
2245 ((eq type 'todo-tree) "TODO kwd tree")
2246 ((eq type 'occur-tree) "Occur tree")
2247 ((functionp type) (if (symbolp type)
2249 "Lambda expression"))
2251 (if org-agenda-menu-show-matcher
2256 (setq match (copy-sequence match))
2257 (org-add-props match nil 'face 'org-warning))
2259 (format "set of %d commands" (length match)))
2261 (if (org-string-nw-p match)
2262 (add-text-properties
2263 0 (length line) (list 'help-echo
2264 (concat "Matcher: "match)) line)))
2266 (setq lines (nreverse lines))
2271 (org-add-props (char-to-string x)
2273 (or (cdr (assoc (concat selstring
2275 prefix-descriptions))
2280 ;; Check if we should display in two columns
2281 (if org-agenda-menu-two-column
2283 (setq n (length lines)
2284 n1 (+ (/ n 2) (mod n 2))
2285 right (nthcdr n1 lines)
2286 left (copy-sequence lines))
2287 (setcdr (nthcdr (1- n1) left) nil))
2288 (setq left lines right nil))
2290 (insert "\n" (pop left))
2292 (if (< (current-column) 40)
2293 (move-to-column 40 t)
2295 (insert (pop right))))
2297 ;; Make the window the right size
2298 (goto-char (point-min))
2300 (if (not (pos-visible-in-window-p (point-max)))
2301 (org-fit-window-to-buffer))
2302 (setq second-time t)
2303 (org-fit-window-to-buffer))
2305 ;; Ask for selection
2306 (message "Press key for agenda command%s:"
2307 (if (or restrict-ok org-agenda-overriding-restriction)
2308 (if org-agenda-overriding-restriction
2309 " (restriction lock active)"
2311 (format " (restricted to %s)" restriction)
2314 (setq c (read-char-exclusive))
2317 ((assoc (char-to-string c) custom)
2318 (setq selstring (concat selstring (char-to-string c)))
2319 (throw 'exit (cons selstring restriction)))
2321 (setq selstring (concat selstring (char-to-string c))
2323 rmheader (or rmheader t)
2324 custom (delq nil (mapcar
2326 (if (or (= (length (car x)) 1)
2327 (/= (string-to-char (car x)) c))
2329 (cons (substring (car x) 1) (cdr x))))
2331 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2332 (message "Restriction is only possible in Org-mode buffers")
2335 (org-agenda-remove-restriction-lock 'noupdate)
2336 (setq restriction 'buffer))
2338 (org-agenda-remove-restriction-lock 'noupdate)
2339 (setq restriction (if region-p 'region 'subtree)))
2341 (org-agenda-remove-restriction-lock 'noupdate)
2344 ((eq restriction 'buffer)
2345 (if region-p 'region 'subtree))
2346 ((memq restriction '(subtree region))
2350 (org-agenda-remove-restriction-lock 'noupdate)
2351 (setq restriction nil))
2352 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2353 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2354 ((and (> (length selstring) 0) (eq c ?\d))
2356 (org-agenda-get-restriction-and-command prefix-descriptions))
2358 ((equal c ?q) (error "Abort"))
2359 (t (error "Invalid key %c" c))))))))
2361 (defun org-run-agenda-series (name series)
2362 (org-let (nth 1 series) '(org-prepare-agenda name))
2363 (let* ((org-agenda-multi t)
2364 (redo (list 'org-run-agenda-series name (list 'quote series)))
2366 (gprops (nth 1 series))
2367 match ;; The byte compiler incorrectly complains about this. Keep it!
2369 (while (setq cmd (pop cmds))
2370 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2373 (org-let2 gprops lprops
2374 '(call-interactively 'org-agenda-list)))
2376 (org-let2 gprops lprops
2377 '(call-interactively 'org-todo-list)))
2379 (org-let2 gprops lprops
2380 '(org-search-view current-prefix-arg match nil)))
2382 (org-let2 gprops lprops
2383 '(call-interactively 'org-agenda-list-stuck-projects)))
2385 (org-let2 gprops lprops
2386 '(org-tags-view current-prefix-arg match)))
2387 ((eq type 'tags-todo)
2388 (org-let2 gprops lprops
2389 '(org-tags-view '(4) match)))
2391 (org-let2 gprops lprops
2392 '(org-todo-list match)))
2394 (org-let2 gprops lprops
2395 '(funcall type match)))
2396 (t (error "Invalid type in command series"))))
2398 (setq org-agenda-redo-command redo)
2399 (goto-char (point-min)))
2400 (org-fit-agenda-window)
2401 (org-let (nth 1 series) '(org-finalize-agenda)))
2404 (defmacro org-batch-agenda (cmd-key &rest parameters)
2405 "Run an agenda command in batch mode and send the result to STDOUT.
2406 If CMD-KEY is a string of length 1, it is used as a key in
2407 `org-agenda-custom-commands' and triggers this command. If it is a
2408 longer string it is used as a tags/todo match string.
2409 Parameters are alternating variable names and values that will be bound
2410 before running the agenda command."
2413 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2414 (if (> (length cmd-key) 2)
2415 (eval (list 'let (nreverse pars)
2416 (list 'org-tags-view nil cmd-key)))
2417 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2418 (set-buffer org-agenda-buffer-name)
2419 (princ (org-encode-for-stdout (buffer-string)))))
2421 ;(defun org-encode-for-stdout (string)
2422 ; (if (fboundp 'encode-coding-string)
2423 ; (encode-coding-string string buffer-file-coding-system)
2426 (defun org-encode-for-stdout (string)
2429 (defvar org-agenda-info nil)
2432 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2433 "Run an agenda command in batch mode and send the result to STDOUT.
2434 If CMD-KEY is a string of length 1, it is used as a key in
2435 `org-agenda-custom-commands' and triggers this command. If it is a
2436 longer string it is used as a tags/todo match string.
2437 Parameters are alternating variable names and values that will be bound
2438 before running the agenda command.
2440 The output gives a line for each selected agenda item. Each
2441 item is a list of comma-separated values, like this:
2443 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2445 category The category of the item
2446 head The headline, without TODO kwd, TAGS and PRIORITY
2447 type The type of the agenda entry, can be
2448 todo selected in TODO match
2449 tagsmatch selected in tags match
2450 diary imported from diary
2451 deadline a deadline on given date
2452 scheduled scheduled on given date
2453 timestamp entry has timestamp on given date
2454 closed entry was closed on given date
2455 upcoming-deadline warning about deadline
2456 past-scheduled forwarded scheduled item
2457 block entry has date block including g. date
2458 todo The todo keyword, if any
2459 tags All tags including inherited ones, separated by colons
2460 date The relevant date, like 2007-2-14
2461 time The time, like 15:00-16:50
2462 extra Sting with extra planning info
2463 priority-l The priority letter if any was given
2464 priority-n The computed numerical priority
2465 agenda-day The day in the agenda where this is listed"
2469 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2470 (push (list 'org-agenda-remove-tags t) pars)
2471 (if (> (length cmd-key) 2)
2472 (eval (list 'let (nreverse pars)
2473 (list 'org-tags-view nil cmd-key)))
2474 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2475 (set-buffer org-agenda-buffer-name)
2476 (let* ((lines (org-split-string (buffer-string) "\n"))
2478 (while (setq line (pop lines))
2480 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2481 (setq org-agenda-info
2482 (org-fix-agenda-info (text-properties-at 0 line)))
2484 (org-encode-for-stdout
2485 (mapconcat 'org-agenda-export-csv-mapper
2486 '(org-category txt type todo tags date time extra
2487 priority-letter priority agenda-day)
2491 (defun org-fix-agenda-info (props)
2492 "Make sure all properties on an agenda item have a canonical form.
2493 This ensures the export commands can easily use it."
2495 (when (setq tmp (plist-get props 'tags))
2496 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2497 (when (setq tmp (plist-get props 'date))
2498 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2499 (let ((calendar-date-display-form '(year "-" month "-" day)))
2500 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2502 (setq tmp (calendar-date-string tmp)))
2503 (setq props (plist-put props 'date tmp)))
2504 (when (setq tmp (plist-get props 'day))
2505 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2506 (let ((calendar-date-display-form '(year "-" month "-" day)))
2507 (setq tmp (calendar-date-string tmp)))
2508 (setq props (plist-put props 'day tmp))
2509 (setq props (plist-put props 'agenda-day tmp)))
2510 (when (setq tmp (plist-get props 'txt))
2511 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2512 (plist-put props 'priority-letter (match-string 1 tmp))
2513 (setq tmp (replace-match "" t t tmp)))
2514 (when (and (setq re (plist-get props 'org-todo-regexp))
2515 (setq re (concat "\\`\\.*" re " ?"))
2516 (string-match re tmp))
2517 (plist-put props 'todo (match-string 1 tmp))
2518 (setq tmp (replace-match "" t t tmp)))
2519 (plist-put props 'txt tmp)))
2522 (defun org-agenda-export-csv-mapper (prop)
2523 (let ((res (plist-get org-agenda-info prop)))
2528 (t (prin1-to-string res))))
2529 (while (string-match "," res)
2530 (setq res (replace-match ";" t t res)))
2535 (defun org-store-agenda-views (&rest parameters)
2537 (eval (list 'org-batch-store-agenda-views)))
2539 ;; FIXME, why is this a macro?????
2541 (defmacro org-batch-store-agenda-views (&rest parameters)
2542 "Run all custom agenda commands that have a file argument."
2543 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2545 (dir default-directory)
2546 pars cmd thiscmdkey files opts cmd-or-set)
2548 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2549 (setq pars (reverse pars))
2550 (save-window-excursion
2552 (setq cmd (pop cmds)
2553 thiscmdkey (car cmd)
2554 cmd-or-set (nth 2 cmd)
2555 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2556 files (nth (if (listp cmd-or-set) 4 5) cmd))
2557 (if (stringp files) (setq files (list files)))
2559 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2560 (list 'org-agenda nil thiscmdkey)))
2561 (set-buffer org-agenda-buffer-name)
2563 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2564 (list 'org-write-agenda
2565 (expand-file-name (pop files) dir) nil t))))
2566 (and (get-buffer org-agenda-buffer-name)
2567 (kill-buffer org-agenda-buffer-name)))))))
2569 (defun org-agenda-mark-header-line (pos)
2570 "Mark the line at POS as an agenda structure header."
2573 (put-text-property (point-at-bol) (point-at-eol)
2574 'org-agenda-structural-header t)
2575 (when org-agenda-title-append
2576 (put-text-property (point-at-bol) (point-at-eol)
2577 'org-agenda-title-append org-agenda-title-append))))
2579 (defvar org-mobile-creating-agendas)
2580 (defun org-write-agenda (file &optional open nosettings)
2581 "Write the current buffer (an agenda view) as a file.
2582 Depending on the extension of the file name, plain text (.txt),
2583 HTML (.html or .htm) or Postscript (.ps) is produced.
2584 If the extension is .ics, run icalendar export over all files used
2585 to construct the agenda and limit the export to entries listed in the
2587 With prefix argument OPEN, open the new file immediately.
2588 If NOSETTINGS is given, do not scope the settings of
2589 `org-agenda-exporter-settings' into the export commands. This is used when
2590 the settings have already been scoped and we do not wish to overrule other,
2591 higher priority settings."
2592 (interactive "FWrite agenda to file: \nP")
2593 (if (not (file-writable-p file))
2594 (error "Cannot write agenda to file %s" file))
2595 (org-let (if nosettings nil org-agenda-exporter-settings)
2597 (save-window-excursion
2598 (org-agenda-mark-filtered-text)
2599 (let ((bs (copy-sequence (buffer-string))) beg)
2600 (org-agenda-unmark-filtered-text)
2602 (rename-buffer "Agenda View" t)
2603 (set-buffer-modified-p nil)
2605 (org-agenda-remove-marked-text 'org-filtered)
2606 (while (setq beg (text-property-any (point-min) (point-max)
2609 beg (or (next-single-property-change beg 'org-filtered)
2611 (run-hooks 'org-agenda-before-write-hook)
2613 ((org-bound-and-true-p org-mobile-creating-agendas)
2614 (org-mobile-write-agenda-for-mobile file))
2615 ((string-match "\\.html?\\'" file)
2617 (set-buffer (htmlize-buffer (current-buffer)))
2619 (when (and org-agenda-export-html-style
2620 (string-match "<style>" org-agenda-export-html-style))
2621 ;; replace <style> section with org-agenda-export-html-style
2622 (goto-char (point-min))
2623 (kill-region (- (search-forward "<style") 6)
2624 (search-forward "</style>"))
2625 (insert org-agenda-export-html-style))
2627 (kill-buffer (current-buffer))
2628 (message "HTML written to %s" file))
2629 ((string-match "\\.ps\\'" file)
2631 (ps-print-buffer-with-faces file)
2632 (message "Postscript written to %s" file))
2633 ((string-match "\\.pdf\\'" file)
2635 (ps-print-buffer-with-faces
2636 (concat (file-name-sans-extension file) ".ps"))
2637 (call-process "ps2pdf" nil nil nil
2639 (concat (file-name-sans-extension file) ".ps"))
2640 (expand-file-name file))
2641 (delete-file (concat (file-name-sans-extension file) ".ps"))
2642 (message "PDF written to %s" file))
2643 ((string-match "\\.ics\\'" file)
2644 (require 'org-icalendar)
2645 (let ((org-agenda-marker-table
2646 (org-create-marker-find-array
2647 (org-agenda-collect-markers)))
2648 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2649 (org-combined-agenda-icalendar-file file))
2650 (apply 'org-export-icalendar 'combine
2651 (org-agenda-files nil 'ifmode))))
2653 (let ((bs (buffer-string)))
2658 (kill-buffer (current-buffer))
2659 (message "Plain text written to %s" file))))))))
2660 (set-buffer org-agenda-buffer-name))
2661 (when open (org-open-file file)))
2663 (defvar org-agenda-filter-overlays nil)
2665 (defun org-agenda-mark-filtered-text ()
2666 "Mark all text hidden by filtering with a text property."
2667 (let ((inhibit-read-only t))
2670 (when (equal (overlay-buffer o) (current-buffer))
2672 (overlay-start o) (overlay-end o)
2674 org-agenda-filter-overlays)))
2676 (defun org-agenda-unmark-filtered-text ()
2677 "Remove the filtering text property."
2678 (let ((inhibit-read-only t))
2679 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2681 (defun org-agenda-remove-marked-text (property &optional value)
2682 "Delete all text marked with VALUE of PROPERTY.
2683 VALUE defaults to t."
2685 (setq value (or value t))
2686 (while (setq beg (text-property-any (point-min) (point-max)
2689 beg (or (next-single-property-change beg 'org-filtered)
2692 (defun org-agenda-add-entry-text ()
2693 "Add entry text to agenda lines.
2694 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2695 entry text following headings shown in the agenda.
2696 Drawers will be excluded, also the line with scheduling/deadline info."
2697 (when (and (> org-agenda-add-entry-text-maxlines 0)
2698 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2700 (goto-char (point-min))
2702 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2703 (beginning-of-line 2)
2704 (setq txt (org-agenda-get-some-entry-text
2705 m org-agenda-add-entry-text-maxlines " > "))
2707 (if (string-match "\\S-" txt)
2709 (or (eobp) (forward-char 1))))))))
2711 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2713 "Extract entry text from MARKER, at most N-LINES lines.
2714 This will ignore drawers etc, just get the text.
2715 If INDENT is given, prefix every line with this string. If KEEP is
2716 given, it is a list of symbols, defining stuff that should not be
2717 removed from the entry content. Currently only `planning' is allowed here."
2718 (let (txt drawer-re kwd-time-re ind)
2720 (with-current-buffer (marker-buffer marker)
2721 (if (not (org-mode-p))
2728 (setq txt (buffer-substring
2729 (min (1+ (point)) (point-max))
2730 (progn (outline-next-heading) (point)))
2731 drawer-re org-drawer-regexp
2732 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2736 (when org-agenda-add-entry-text-descriptive-links
2737 (goto-char (point-min))
2738 (while (org-activate-bracket-links (point-max))
2739 (add-text-properties (match-beginning 0) (match-end 0)
2741 (goto-char (point-min))
2742 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2743 (set-text-properties (match-beginning 0) (match-end 0)
2745 (goto-char (point-min))
2746 (while (re-search-forward drawer-re nil t)
2749 (progn (re-search-forward
2750 "^[ \t]*:END:.*\n?" nil 'move)
2752 (unless (member 'planning keep)
2753 (goto-char (point-min))
2754 (while (re-search-forward kwd-time-re nil t)
2755 (replace-match "")))
2756 (goto-char (point-min))
2757 (when org-agenda-entry-text-exclude-regexps
2758 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2759 (while (setq re (pop re-list))
2760 (goto-char (point-min))
2761 (while (re-search-forward re nil t)
2762 (replace-match "")))))
2763 (goto-char (point-max))
2764 (skip-chars-backward " \t\n")
2765 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2767 ;; find and remove min common indentation
2768 (goto-char (point-min))
2769 (untabify (point-min) (point-max))
2770 (setq ind (org-get-indentation))
2772 (unless (looking-at "[ \t]*$")
2773 (setq ind (min ind (org-get-indentation))))
2774 (beginning-of-line 2))
2775 (goto-char (point-min))
2777 (unless (looking-at "[ \t]*$")
2778 (move-to-column ind)
2779 (delete-region (point-at-bol) (point)))
2780 (beginning-of-line 2))
2782 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2784 (goto-char (point-min))
2786 (while (and (not (eobp)) (re-search-forward "^" nil t))
2787 (replace-match indent t t)))
2788 (goto-char (point-min))
2789 (while (looking-at "[ \t]*\n") (replace-match ""))
2790 (goto-char (point-max))
2791 (when (> (org-current-line)
2793 (org-goto-line (1+ n-lines))
2795 (setq txt (buffer-substring (point-min) (point)))))))))
2798 (defun org-agenda-collect-markers ()
2799 "Collect the markers pointing to entries in the agenda buffer."
2802 (goto-char (point-min))
2804 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2805 (org-get-at-bol 'org-marker)))
2807 (beginning-of-line 2)))
2808 (nreverse markers)))
2810 (defun org-create-marker-find-array (marker-list)
2811 "Create a alist of files names with all marker positions in that file."
2813 (while (setq m (pop marker-list))
2814 (setq p (marker-position m)
2815 f (buffer-file-name (or (buffer-base-buffer
2817 (marker-buffer m))))
2818 (if (setq a (assoc f tbl))
2819 (push (marker-position m) (cdr a))
2820 (push (list f p) tbl)))
2821 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2824 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2825 (defun org-check-agenda-marker-table ()
2826 "Check of the current entry is on the marker list."
2827 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2829 (and (setq a (assoc file org-agenda-marker-table))
2832 (org-back-to-heading t)
2833 (member (point) (cdr a)))))))
2835 (defun org-check-for-org-mode ()
2836 "Make sure current buffer is in org-mode. Error if not."
2838 (error "Cannot execute org-mode agenda command on buffer in %s"
2841 (defun org-fit-agenda-window ()
2842 "Fit the window to the buffer size."
2843 (and (memq org-agenda-window-setup '(reorganize-frame))
2844 (fboundp 'fit-window-to-buffer)
2845 (org-fit-window-to-buffer
2847 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2848 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2850 ;;; Agenda prepare and finalize
2852 (defvar org-agenda-multi nil) ; dynamically scoped
2853 (defvar org-agenda-buffer-name "*Org Agenda*")
2854 (defvar org-pre-agenda-window-conf nil)
2855 (defvar org-agenda-columns-active nil)
2856 (defvar org-agenda-name nil)
2857 (defvar org-agenda-filter nil)
2858 (defvar org-agenda-filter-while-redo nil)
2859 (defvar org-agenda-filter-preset nil
2860 "A preset of the tags filter used for secondary agenda filtering.
2861 This must be a list of strings, each string must be a single tag preceded
2863 This variable should not be set directly, but agenda custom commands can
2864 bind it in the options section. The preset filter is a global property of
2865 the entire agenda view. In a block agenda, it will not work reliably to
2866 define a filter for one of the individual blocks. You need to set it in
2867 the global options and expect it to be applied to the entire view.")
2869 (defun org-prepare-agenda (&optional name)
2870 (setq org-todo-keywords-for-agenda nil)
2871 (setq org-done-keywords-for-agenda nil)
2872 (setq org-drawers-for-agenda nil)
2873 (unless org-agenda-persistent-filter
2874 (setq org-agenda-filter nil))
2875 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2876 (if org-agenda-multi
2878 (setq buffer-read-only nil)
2879 (goto-char (point-max))
2880 (unless (or (bobp) org-agenda-compact-blocks)
2882 (if (stringp org-agenda-block-separator)
2883 org-agenda-block-separator
2884 (make-string (window-width) org-agenda-block-separator))
2886 (narrow-to-region (point) (point-max)))
2887 (org-agenda-reset-markers)
2888 (setq org-agenda-contributing-files nil)
2889 (setq org-agenda-columns-active nil)
2890 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2891 (setq org-todo-keywords-for-agenda
2892 (org-uniquify org-todo-keywords-for-agenda))
2893 (setq org-done-keywords-for-agenda
2894 (org-uniquify org-done-keywords-for-agenda))
2895 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2896 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2897 (awin (get-buffer-window abuf)))
2899 ((equal (current-buffer) abuf) nil)
2900 (awin (select-window awin))
2901 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2902 ((equal org-agenda-window-setup 'current-window)
2903 (switch-to-buffer abuf))
2904 ((equal org-agenda-window-setup 'other-window)
2905 (org-switch-to-buffer-other-window abuf))
2906 ((equal org-agenda-window-setup 'other-frame)
2907 (switch-to-buffer-other-frame abuf))
2908 ((equal org-agenda-window-setup 'reorganize-frame)
2909 (delete-other-windows)
2910 (org-switch-to-buffer-other-window abuf)))
2911 ;; additional test in case agenda is invoked from within agenda
2912 ;; buffer via elisp link
2913 (unless (equal (current-buffer) abuf)
2914 (switch-to-buffer abuf)))
2915 (setq buffer-read-only nil)
2916 (let ((inhibit-read-only t)) (erase-buffer))
2918 (and name (not org-agenda-name)
2919 (org-set-local 'org-agenda-name name)))
2920 (setq buffer-read-only nil))
2922 (defun org-finalize-agenda ()
2923 "Finishing touch for the agenda buffer, called just before displaying it."
2924 (unless org-agenda-multi
2926 (let ((inhibit-read-only t))
2927 (goto-char (point-min))
2928 (while (org-activate-bracket-links (point-max))
2929 (add-text-properties (match-beginning 0) (match-end 0)
2931 (org-agenda-align-tags)
2932 (unless org-agenda-with-colors
2933 (remove-text-properties (point-min) (point-max) '(face nil))))
2934 (if (and (boundp 'org-agenda-overriding-columns-format)
2935 org-agenda-overriding-columns-format)
2936 (org-set-local 'org-agenda-overriding-columns-format
2937 org-agenda-overriding-columns-format))
2938 (if (and (boundp 'org-agenda-view-columns-initially)
2939 org-agenda-view-columns-initially)
2940 (org-agenda-columns))
2941 (when org-agenda-fontify-priorities
2942 (org-agenda-fontify-priorities))
2943 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2944 (org-agenda-dim-blocked-tasks))
2945 (org-agenda-mark-clocking-task)
2946 (when org-agenda-entry-text-mode
2947 (org-agenda-entry-text-hide)
2948 (org-agenda-entry-text-show))
2949 (if (functionp 'org-habit-insert-consistency-graphs)
2950 (org-habit-insert-consistency-graphs))
2951 (run-hooks 'org-finalize-agenda-hook)
2952 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2953 (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
2954 (org-agenda-filter-apply org-agenda-filter))
2957 (defun org-agenda-mark-clocking-task ()
2958 "Mark the current clock entry in the agenda if it is present."
2960 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
2961 (delete-overlay o)))
2962 (overlays-in (point-min) (point-max)))
2963 (when (marker-buffer org-clock-hd-marker)
2965 (goto-char (point-min))
2967 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2969 (when (equal (org-get-at-bol 'org-hd-marker)
2970 org-clock-hd-marker)
2971 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
2972 (overlay-put ov 'type 'org-agenda-clocking)
2973 (overlay-put ov 'face 'org-agenda-clocking)
2974 (overlay-put ov 'help-echo
2975 "The clock is running in this item")))))))
2977 (defun org-agenda-fontify-priorities ()
2978 "Make highest priority lines bold, and lowest italic."
2980 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
2981 (delete-overlay o)))
2982 (overlays-in (point-min) (point-max)))
2984 (let ((inhibit-read-only t)
2986 (goto-char (point-min))
2987 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2988 (setq h (or (get-char-property (point) 'org-highest-priority)
2989 org-highest-priority)
2990 l (or (get-char-property (point) 'org-lowest-priority)
2991 org-lowest-priority)
2992 p (string-to-char (match-string 1))
2993 b (match-beginning 0)
2994 e (if (eq org-agenda-fontify-priorities 'cookies)
2997 ov (make-overlay b e))
3000 (cond ((org-face-from-face-or-color
3002 (cdr (assoc p org-priority-faces))))
3003 ((and (listp org-agenda-fontify-priorities)
3004 (org-face-from-face-or-color
3006 (cdr (assoc p org-agenda-fontify-priorities)))))
3007 ((equal p l) 'italic)
3008 ((equal p h) 'bold)))
3009 (overlay-put ov 'org-type 'org-priority)))))
3011 (defun org-agenda-dim-blocked-tasks ()
3012 "Dim currently blocked TODO's in the agenda display."
3013 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3014 (delete-overlay o)))
3015 (overlays-in (point-min) (point-max)))
3017 (let ((inhibit-read-only t)
3018 (org-depend-tag-blocked nil)
3019 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3020 org-blocked-by-checkboxes
3021 invis1 b e p ov h l)
3022 (goto-char (point-min))
3023 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3024 (and pos (goto-char (1+ pos))))
3025 (setq org-blocked-by-checkboxes nil invis1 invis)
3026 (let ((marker (org-get-at-bol 'org-hd-marker)))
3028 (not (with-current-buffer (marker-buffer marker)
3031 (if (org-entry-get nil "NOBLOCKING")
3032 t ;; Never block this entry
3033 (run-hook-with-args-until-failure
3035 (list :type 'todo-state-change
3039 (if org-blocked-by-checkboxes (setq invis1 nil))
3041 (max (point-min) (1- (point-at-bol)))
3044 ov (make-overlay b e))
3046 (overlay-put ov 'invisible t)
3047 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3048 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3050 (defvar org-agenda-skip-function nil
3051 "Function to be called at each match during agenda construction.
3052 If this function returns nil, the current match should not be skipped.
3053 Otherwise, the function must return a position from where the search
3054 should be continued.
3055 This may also be a Lisp form, it will be evaluated.
3056 Never set this variable using `setq' or so, because then it will apply
3057 to all future agenda commands. Instead, bind it with `let' to scope
3058 it dynamically into the agenda-constructing command. A good way to set
3059 it is through options in `org-agenda-custom-commands'.")
3061 (defun org-agenda-skip ()
3062 "Throw to `:skip' in places that should be skipped.
3063 Also moves point to the end of the skipped region, so that search can
3064 continue from there."
3065 (let ((p (point-at-bol)) to fp)
3066 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3067 (get-text-property p :org-archived)
3068 (org-end-of-subtree t)
3070 (and org-agenda-skip-comment-trees
3071 (get-text-property p :org-comment)
3072 (org-end-of-subtree t)
3074 (if (equal (char-after p) ?#) (throw :skip t))
3075 (when (and (or (setq fp (functionp org-agenda-skip-function))
3076 (consp org-agenda-skip-function))
3077 (setq to (save-excursion
3080 (funcall org-agenda-skip-function)
3081 (eval org-agenda-skip-function))))))
3085 (defvar org-agenda-markers nil
3086 "List of all currently active markers created by `org-agenda'.")
3087 (defvar org-agenda-last-marker-time (org-float-time)
3088 "Creation time of the last agenda marker.")
3090 (defun org-agenda-new-marker (&optional pos)
3091 "Return a new agenda marker.
3092 Org-mode keeps a list of these markers and resets them when they are
3094 (let ((m (copy-marker (or pos (point)))))
3095 (setq org-agenda-last-marker-time (org-float-time))
3096 (push m org-agenda-markers)
3099 (defun org-agenda-reset-markers ()
3100 "Reset markers created by `org-agenda'."
3101 (while org-agenda-markers
3102 (move-marker (pop org-agenda-markers) nil)))
3104 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3105 "Save relative positions of markers in region."
3106 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3107 org-agenda-markers))
3111 (defun org-agenda-entry-text-show-here ()
3112 "Add some text from the entry as context to the current line."
3114 (setq m (org-get-at-bol 'org-hd-marker))
3115 (unless (marker-buffer m)
3116 (error "No marker points to an entry here"))
3117 (setq txt (concat "\n" (org-no-properties
3118 (org-agenda-get-some-entry-text
3119 m org-agenda-entry-text-maxlines " > "))))
3120 (when (string-match "\\S-" txt)
3121 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3122 (overlay-put o 'evaporate t)
3123 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3124 (overlay-put o 'after-string txt))))
3126 (defun org-agenda-entry-text-show ()
3127 "Add entry context for all agenda lines."
3130 (goto-char (point-max))
3131 (beginning-of-line 1)
3133 (when (org-get-at-bol 'org-hd-marker)
3134 (org-agenda-entry-text-show-here))
3135 (beginning-of-line 0))))
3137 (defun org-agenda-entry-text-hide ()
3138 "Remove any shown entry context."
3141 (if (eq (overlay-get o 'org-overlay-type)
3142 'agenda-entry-content)
3143 (progn (delete-overlay o) t)))
3144 (overlays-in (point-min) (point-max)))))
3146 (defun org-agenda-get-day-face (date)
3147 "Return the face DATE should be displayed with."
3148 (or (and (functionp org-agenda-day-face-function)
3149 (funcall org-agenda-day-face-function date))
3150 (cond ((org-agenda-todayp date)
3151 'org-agenda-date-today)
3152 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3153 'org-agenda-date-weekend)
3154 (t 'org-agenda-date))))
3158 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3160 (defun org-timeline (&optional include-all)
3161 "Show a time-sorted view of the entries in the current org file.
3162 Only entries with a time stamp of today or later will be listed. With
3163 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3164 under the current date.
3165 If the buffer contains an active region, only check the region for
3168 (org-compile-prefix-format 'timeline)
3169 (org-set-sorting-strategy 'timeline)
3171 (dotodo include-all)
3172 (doclosed org-agenda-show-log)
3173 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3175 (date (calendar-current-date))
3176 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3177 (end (if (org-region-active-p) (region-end) (point-max)))
3178 (day-numbers (org-get-all-dates beg end 'no-ranges
3179 t doclosed ; always include today
3180 org-timeline-show-empty-dates))
3181 (org-deadline-warning-days 0)
3182 (org-agenda-only-exact-dates t)
3183 (today (org-agenda-today))
3187 (setq org-agenda-redo-command
3189 (list 'org-switch-to-buffer-other-window (current-buffer))
3190 (list 'org-timeline (list 'quote include-all))))
3192 ;; Remove past dates from the list of dates.
3193 (setq day-numbers (delq nil (mapcar (lambda(x)
3194 (if (>= x today) x nil))
3196 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3197 (if doclosed (push :closed args))
3198 (push :timestamp args)
3199 (push :deadline args)
3200 (push :scheduled args)
3202 (if dotodo (push :todo args))
3203 (insert "Timeline of file " entry "\n")
3204 (add-text-properties (point-min) (point)
3205 (list 'face 'org-agenda-structure))
3206 (org-agenda-mark-header-line (point-min))
3207 (while (setq d (pop day-numbers))
3208 (if (and (listp d) (eq (car d) :omitted))
3211 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3212 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3213 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3214 (if (and (>= d today)
3219 (insert (make-string 79 ?-) "\n")))
3220 (setq date (calendar-gregorian-from-absolute d))
3222 (setq rtn (and (not emptyp)
3223 (apply 'org-agenda-get-day-entries entry
3225 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3228 (if (stringp org-agenda-format-date)
3229 (format-time-string org-agenda-format-date
3230 (org-time-from-absolute date))
3231 (funcall org-agenda-format-date date))
3233 (put-text-property s (1- (point)) 'face
3234 (org-agenda-get-day-face date))
3235 (put-text-property s (1- (point)) 'org-date-line t)
3236 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3238 (put-text-property s (1- (point)) 'org-today t))
3239 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3240 (put-text-property s (1- (point)) 'day d)))))
3241 (goto-char (point-min))
3242 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3244 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3245 (org-finalize-agenda)
3246 (setq buffer-read-only t)))
3248 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3249 "Return a list of all relevant day numbers from BEG to END buffer positions.
3250 If NO-RANGES is non-nil, include only the start and end dates of a range,
3251 not every single day in the range. If FORCE-TODAY is non-nil, make
3252 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3253 inactive time stamps (those in square brackets) are included.
3254 When EMPTY is non-nil, also include days without any entries."
3256 (if pre-re pre-re "")
3257 (if inactive org-ts-regexp-both org-ts-regexp)))
3258 dates dates1 date day day1 day2 ts1 ts2)
3260 (setq dates (list (org-agenda-today))))
3263 (while (re-search-forward re end t)
3264 (setq day (time-to-days (org-time-string-to-time
3265 (substring (match-string 1) 0 10))))
3266 (or (memq day dates) (push day dates)))
3269 (while (re-search-forward org-tr-regexp end t)
3270 (setq ts1 (substring (match-string 1) 0 10)
3271 ts2 (substring (match-string 2) 0 10)
3272 day1 (time-to-days (org-time-string-to-time ts1))
3273 day2 (time-to-days (org-time-string-to-time ts2)))
3274 (while (< (setq day1 (1+ day1)) day2)
3275 (or (memq day1 dates) (push day1 dates)))))
3276 (setq dates (sort dates '<))
3278 (while (setq day (pop dates))
3279 (setq day2 (car dates))
3281 (when (and day2 empty)
3282 (if (or (eq empty t)
3283 (and (numberp empty) (<= (- day2 day) empty)))
3284 (while (< (setq day (1+ day)) day2)
3285 (push (list day) dates1))
3286 (push (cons :omitted (- day2 day)) dates1))))
3287 (setq dates (nreverse dates1)))
3290 ;;; Agenda Daily/Weekly
3292 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
3293 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3294 "Custom commands can set this variable in the options section.")
3295 (defvar org-agenda-last-arguments nil
3296 "The arguments of the previous call to `org-agenda'.")
3297 (defvar org-starting-day nil) ; local variable in the agenda buffer
3298 (defvar org-agenda-span nil) ; local variable in the agenda buffer
3299 (defvar org-include-all-loc nil) ; local variable
3301 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3302 "List of types searched for when creating the daily/weekly agenda.
3303 This variable is a list of symbols that controls the types of
3304 items that appear in the daily/weekly agenda. Allowed symbols in this
3307 :timestamp List items containing a date stamp or date range matching
3308 the selected date. This includes sexp entries in
3311 :sexp List entries resulting from plain diary-like sexps.
3313 :deadline List deadline due on that date. When the date is today,
3314 also list any deadlines past due, or due within
3315 `org-deadline-warning-days'. `:deadline' must appear before
3316 `:scheduled' if the setting of
3317 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3320 :scheduled List all items which are scheduled for the given date.
3321 The diary for *today* also contains items which were
3322 scheduled earlier and are not yet marked DONE.
3324 By default, all four types are turned on.
3326 Never set this variable globally using `setq', because then it
3327 will apply to all future agenda commands. Instead, bind it with
3328 `let' to scope it dynamically into the the agenda-constructing
3329 command. A good way to set it is through options in
3330 `org-agenda-custom-commands'. For a more flexible (though
3331 somewhat less efficient) way of determining what is included in
3332 the daily/weekly agenda, see `org-agenda-skip-function'.")
3335 (defun org-agenda-list (&optional include-all start-day ndays)
3336 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3337 The view will be for the current day or week, but from the overview buffer
3338 you will be able to go to other days/weeks.
3340 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3341 all unfinished TODO items will also be shown, before the agenda.
3342 This feature is considered obsolete, please use the TODO list or a block
3345 With a numeric prefix argument in an interactive call, the agenda will
3346 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
3347 the number of days. NDAYS defaults to `org-agenda-ndays'.
3349 START-DAY defaults to TODAY, or to the most recent match for the weekday
3350 given in `org-agenda-start-on-weekday'."
3352 (if (and (integerp include-all) (> include-all 0))
3353 (setq ndays include-all include-all nil))
3354 (setq ndays (or ndays org-agenda-ndays)
3355 start-day (or start-day org-agenda-start-day))
3356 (if org-agenda-overriding-arguments
3357 (setq include-all (car org-agenda-overriding-arguments)
3358 start-day (nth 1 org-agenda-overriding-arguments)
3359 ndays (nth 2 org-agenda-overriding-arguments)))
3360 (if (stringp start-day)
3361 ;; Convert to an absolute day number
3362 (setq start-day (time-to-days (org-read-date nil t start-day))))
3363 (setq org-agenda-last-arguments (list include-all start-day ndays))
3364 (org-compile-prefix-format 'agenda)
3365 (org-set-sorting-strategy 'agenda)
3366 (let* ((org-agenda-start-on-weekday
3367 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3368 org-agenda-start-on-weekday nil))
3369 (thefiles (org-agenda-files nil 'ifmode))
3371 (today (org-agenda-today))
3372 (sd (or start-day today))
3373 (start (if (or (null org-agenda-start-on-weekday)
3374 (< org-agenda-ndays 7))
3376 (let* ((nt (calendar-day-of-week
3377 (calendar-gregorian-from-absolute sd)))
3378 (n1 org-agenda-start-on-weekday)
3380 (- sd (+ (if (< d 0) 7 0) d)))))
3381 (day-numbers (list start))
3383 (inhibit-redisplay (not debug-on-error))
3384 s e rtn rtnall file date d start-pos end-pos todayp nd
3385 clocktable-start clocktable-end filter)
3386 (setq org-agenda-redo-command
3387 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3388 ;; Make the list of days
3389 (setq ndays (or ndays org-agenda-ndays)
3392 (push (1+ (car day-numbers)) day-numbers)
3393 (setq ndays (1- ndays)))
3394 (setq day-numbers (nreverse day-numbers))
3395 (setq clocktable-start (car day-numbers)
3396 clocktable-end (1+ (or (org-last day-numbers) 0)))
3397 (org-prepare-agenda "Day/Week")
3398 (org-set-local 'org-starting-day (car day-numbers))
3399 (org-set-local 'org-include-all-loc include-all)
3400 (org-set-local 'org-agenda-span
3401 (org-agenda-ndays-to-span nd))
3402 (when (and (or include-all org-agenda-include-all-todo)
3403 (member today day-numbers))
3404 (setq files thefiles
3406 (while (setq file (pop files))
3408 (org-check-agenda-file file)
3409 (setq date (calendar-gregorian-from-absolute today)
3410 rtn (org-agenda-get-day-entries
3412 (setq rtnall (append rtnall rtn))))
3414 (insert "All currently open TODO items:\n")
3415 (add-text-properties (point-min) (1- (point))
3416 (list 'face 'org-agenda-structure
3417 'short-heading "All TODO items"))
3418 (org-agenda-mark-header-line (point-min))
3419 (insert (org-finalize-agenda-entries rtnall) "\n")))
3420 (unless org-agenda-compact-blocks
3421 (let* ((d1 (car day-numbers))
3422 (d2 (org-last day-numbers))
3423 (w1 (org-days-to-iso-week d1))
3424 (w2 (org-days-to-iso-week d2)))
3426 (if org-agenda-overriding-header
3427 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3428 nil 'face 'org-agenda-structure) "\n")
3429 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3431 (if (< (- d2 d1) 350)
3433 (format " (W%02d)" w1)
3434 (format " (W%02d-W%02d)" w1 w2))
3437 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3439 (org-agenda-mark-header-line s))
3440 (while (setq d (pop day-numbers))
3441 (setq date (calendar-gregorian-from-absolute d)
3443 (if (or (setq todayp (= d today))
3444 (and (not start-pos) (= d sd)))
3445 (setq start-pos (point))
3446 (if (and start-pos (not end-pos))
3447 (setq end-pos (point))))
3448 (setq files thefiles
3450 (while (setq file (pop files))
3452 (org-check-agenda-file file)
3453 (let ((org-agenda-entry-types org-agenda-entry-types))
3454 (unless org-agenda-include-deadlines
3455 (setq org-agenda-entry-types
3456 (delq :deadline org-agenda-entry-types)))
3458 ((eq org-agenda-show-log 'only)
3459 (setq rtn (org-agenda-get-day-entries
3460 file date :closed)))
3461 (org-agenda-show-log
3462 (setq rtn (apply 'org-agenda-get-day-entries
3464 (append '(:closed) org-agenda-entry-types))))
3466 (setq rtn (apply 'org-agenda-get-day-entries
3468 org-agenda-entry-types)))))
3469 (setq rtnall (append rtnall rtn))))
3470 (if org-agenda-include-diary
3471 (let ((org-agenda-search-headline-for-time t))
3472 (require 'diary-lib)
3473 (setq rtn (org-get-entries-from-diary date))
3474 (setq rtnall (append rtnall rtn))))
3475 (if (or rtnall org-agenda-show-all-dates)
3477 (setq day-cnt (1+ day-cnt))
3479 (if (stringp org-agenda-format-date)
3480 (format-time-string org-agenda-format-date
3481 (org-time-from-absolute date))
3482 (funcall org-agenda-format-date date))
3484 (put-text-property s (1- (point)) 'face
3485 (org-agenda-get-day-face date))
3486 (put-text-property s (1- (point)) 'org-date-line t)
3487 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3488 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3490 (put-text-property s (1- (point)) 'org-today t))
3492 (org-finalize-agenda-entries
3493 (org-agenda-add-time-grid-maybe
3496 (put-text-property s (1- (point)) 'day d)
3497 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3498 (when (and org-agenda-clockreport-mode clocktable-start)
3499 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3500 ;; the above line is to ensure the restricted range!
3501 (p org-agenda-clockreport-parameter-plist)
3503 (setq p (org-plist-delete p :block))
3504 (setq p (plist-put p :tstart clocktable-start))
3505 (setq p (plist-put p :tend clocktable-end))
3506 (setq p (plist-put p :scope 'agenda))
3507 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3508 (setq filter (or org-agenda-filter-while-redo
3509 (get 'org-agenda-filter :preset-filter))))
3510 (setq p (plist-put p :tags (mapconcat (lambda (x)
3511 (if (string-match "[<>=]" x)
3515 (message "%s" (plist-get p :tags)) (sit-for 2)
3516 (setq tbl (apply 'org-get-clocktable p))
3518 (goto-char (point-min))
3519 (or org-agenda-multi (org-fit-agenda-window))
3520 (unless (and (pos-visible-in-window-p (point-min))
3521 (pos-visible-in-window-p (point-max)))
3522 (goto-char (1- (point-max)))
3524 (if (not (pos-visible-in-window-p (or start-pos 1)))
3526 (goto-char (or start-pos 1))
3528 (goto-char (or start-pos 1))
3529 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3530 (org-finalize-agenda)
3531 (setq buffer-read-only t)
3534 (defun org-agenda-ndays-to-span (n)
3535 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3537 ;;; Agenda word search
3539 (defvar org-agenda-search-history nil)
3540 (defvar org-todo-only nil)
3542 (defvar org-search-syntax-table nil
3543 "Special syntax table for org-mode search.
3544 In this table, we have single quotes not as word constituents, to
3545 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3547 (defun org-search-syntax-table ()
3548 (unless org-search-syntax-table
3549 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3550 (modify-syntax-entry ?' "." org-search-syntax-table)
3551 (modify-syntax-entry ?` "." org-search-syntax-table))
3552 org-search-syntax-table)
3554 (defvar org-agenda-last-search-view-search-was-boolean nil)
3557 (defun org-search-view (&optional todo-only string edit-at)
3558 "Show all entries that contain a phrase or words or regular expressions.
3560 With optional prefix argument TODO-ONLY, only consider entries that are
3561 TODO entries. The argument STRING can be used to pass a default search
3562 string into this function. If EDIT-AT is non-nil, it means that the
3563 user should get a chance to edit this string, with cursor at position
3566 The search string can be viewed either as a phrase that should be found as
3567 is, or it can be broken into a number of snippets, each of which must match
3568 in a Boolean way to select an entry. The default depends on the variable
3569 `org-agenda-search-view-always-boolean'.
3570 Even if this is turned off (the default) you can always switch to
3571 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3573 The default is a direct search of the whole phrase, where each space in
3574 the search string can expand to an arbitrary amount of whitespace,
3577 If using a Boolean search, the search string is split on whitespace and
3578 each snippet is searched separately, with logical AND to select an entry.
3579 Words prefixed with a minus must *not* occur in the entry. Words without
3580 a prefix or prefixed with a plus must occur in the entry. Matching is
3581 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3582 match whole words, not parts of a word) if
3583 `org-agenda-search-view-force-full-words' is set (default is nil).
3585 Boolean search snippets enclosed by curly braces are interpreted as
3586 regular expressions that must or (when preceded with \"-\") must not
3587 match in the entry. Snippets enclosed into double quotes will be taken
3588 as a whole, to include whitespace.
3590 - If the search string starts with an asterisk, search only in headlines.
3591 - If (possibly after the leading star) the search string starts with an
3592 exclamation mark, this also means to look at TODO entries only, an effect
3593 that can also be achieved with a prefix argument.
3594 - If (possibly after star and exclamation mark) the search string starts
3595 with a colon, this will mean that the (non-regexp) snippets of the
3596 Boolean search must match as full words.
3598 This command searches the agenda files, and in addition the files listed
3599 in `org-agenda-text-search-extra-files'."
3601 (org-compile-prefix-format 'search)
3602 (org-set-sorting-strategy 'search)
3603 (org-prepare-agenda "SEARCH")
3604 (let* ((props (list 'face nil
3605 'done-face 'org-agenda-done
3606 'org-not-done-regexp org-not-done-regexp
3607 'org-todo-regexp org-todo-regexp
3608 'org-complex-heading-regexp org-complex-heading-regexp
3609 'mouse-face 'highlight
3610 'help-echo (format "mouse-2 or RET jump to location")))
3611 (full-words org-agenda-search-view-force-full-words)
3612 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3613 regexp rtn rtnall files file pos
3614 marker category tags c neg re boolean
3615 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3616 (unless (and (not edit-at)
3618 (string-match "\\S-" string))
3619 (setq string (read-string
3620 (if org-agenda-search-view-always-boolean
3621 "[+-]Word/{Regexp} ...: "
3622 "Phrase, or [+-]Word/{Regexp} ...: ")
3624 ((integerp edit-at) (cons string edit-at))
3626 'org-agenda-search-history)))
3627 (org-set-local 'org-todo-only todo-only)
3628 (setq org-agenda-redo-command
3629 (list 'org-search-view (if todo-only t nil) string
3630 '(if current-prefix-arg 1 nil)))
3631 (setq org-agenda-query-string string)
3633 (if (equal (string-to-char string) ?*)
3635 words (substring string 1))
3636 (setq words string))
3637 (when (equal (string-to-char words) ?!)
3639 words (substring words 1)))
3640 (when (equal (string-to-char words) ?:)
3642 words (substring words 1)))
3643 (if (or org-agenda-search-view-always-boolean
3644 (member (string-to-char words) '(?- ?+ ?\{)))
3646 (setq words (org-split-string words))
3648 (while (setq w (pop words))
3649 (while (and (string-match "\\\\\\'" w) words)
3650 (setq w (concat (substring w 0 -1) " " (pop words))))
3652 (setq words (nreverse www) www nil)
3653 (while (setq w (pop words))
3654 (when (and (string-match "\\`[-+]?{" w)
3655 (not (string-match "}\\'" w)))
3656 (while (and words (not (string-match "}\\'" (car words))))
3657 (setq w (concat w " " (pop words))))
3658 (setq w (concat w " " (pop words))))
3660 (setq words (nreverse www)))
3661 (setq org-agenda-last-search-view-search-was-boolean boolean)
3664 (while (setq w (pop words))
3665 (if (or (equal (substring w 0 1) "\"")
3666 (and (> (length w) 1)
3667 (member (substring w 0 1) '("+" "-"))
3668 (equal (substring w 1 2) "\"")))
3669 (while (and words (not (equal (substring w -1) "\"")))
3670 (setq w (concat w " " (pop words)))))
3671 (and (string-match "\\`\\([-+]?\\)\"" w)
3672 (setq w (replace-match "\\1" nil nil w)))
3673 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3675 (setq words (nreverse wds))))
3678 (setq c (string-to-char w))
3680 (setq neg t w (substring w 1))
3682 (setq neg nil w (substring w 1))
3684 (if (string-match "\\`{.*}\\'" w)
3685 (setq re (substring w 1 -1))
3687 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3688 (setq re (regexp-quote (downcase w)))))
3689 (if neg (push re regexps-) (push re regexps+)))
3691 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3693 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3695 (setq regexp (concat "^" org-outline-regexp))
3696 (setq regexp (pop regexps+))
3697 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3699 (setq files (org-agenda-files nil 'ifmode))
3700 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3701 (pop org-agenda-text-search-extra-files)
3702 (setq files (org-add-archive-files files)))
3703 (setq files (append files org-agenda-text-search-extra-files)
3705 (while (setq file (pop files))
3708 (org-check-agenda-file file)
3709 (setq buffer (if (file-exists-p file)
3710 (org-get-agenda-file-buffer file)
3711 (error "No such file %s" file)))
3713 ;; If file does not exist, make sure an error message is sent
3714 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3716 (with-current-buffer buffer
3717 (with-syntax-table (org-search-syntax-table)
3718 (unless (org-mode-p)
3719 (error "Agenda file %s is not in `org-mode'" file))
3720 (let ((case-fold-search t))
3723 (if org-agenda-restrict
3724 (narrow-to-region org-agenda-restrict-begin
3725 org-agenda-restrict-end)
3727 (goto-char (point-min))
3728 (unless (or (org-on-heading-p)
3729 (outline-next-heading))
3730 (throw 'nextfile t))
3731 (goto-char (max (point-min) (1- (point))))
3732 (while (re-search-forward regexp nil t)
3733 (org-back-to-heading t)
3734 (skip-chars-forward "* ")
3735 (setq beg (point-at-bol)
3737 end (progn (outline-next-heading) (point)))
3741 (setq str (buffer-substring-no-properties
3743 (if hdl-only (point-at-eol) end)))
3744 (mapc (lambda (wr) (when (string-match wr str)
3745 (goto-char (1- end))
3748 (mapc (lambda (wr) (unless (string-match wr str)
3749 (goto-char (1- end))
3752 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3756 (setq marker (org-agenda-new-marker (point))
3757 category (org-get-category)
3758 tags (org-get-tags-at (point))
3759 txt (org-format-agenda-item
3761 (buffer-substring-no-properties
3762 beg1 (point-at-eol))
3764 (org-add-props txt props
3765 'org-marker marker 'org-hd-marker marker
3766 'org-todo-regexp org-todo-regexp
3767 'org-complex-heading-regexp org-complex-heading-regexp
3768 'priority 1000 'org-category category
3771 (goto-char (1- end))))))))))
3772 (setq rtn (nreverse ee))
3773 (setq rtnall (append rtnall rtn)))
3774 (if org-agenda-overriding-header
3775 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3776 nil 'face 'org-agenda-structure) "\n")
3777 (insert "Search words: ")
3778 (add-text-properties (point-min) (1- (point))
3779 (list 'face 'org-agenda-structure))
3781 (insert string "\n")
3782 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3784 (unless org-agenda-multi
3785 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3786 (add-text-properties pos (1- (point))
3787 (list 'face 'org-agenda-structure))))
3788 (org-agenda-mark-header-line (point-min))
3790 (insert (org-finalize-agenda-entries rtnall) "\n"))
3791 (goto-char (point-min))
3792 (or org-agenda-multi (org-fit-agenda-window))
3793 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3794 (org-finalize-agenda)
3795 (setq buffer-read-only t)))
3797 ;;; Agenda TODO list
3799 (defvar org-select-this-todo-keyword nil)
3800 (defvar org-last-arg nil)
3803 (defun org-todo-list (arg)
3804 "Show all (not done) TODO entries from all agenda file in a single list.
3805 The prefix arg can be used to select a specific TODO keyword and limit
3806 the list to these. When using \\[universal-argument], you will be prompted
3807 for a keyword. A numeric prefix directly selects the Nth keyword in
3808 `org-todo-keywords-1'."
3810 (org-compile-prefix-format 'todo)
3811 (org-set-sorting-strategy 'todo)
3812 (org-prepare-agenda "TODO")
3813 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3814 (let* ((today (org-agenda-today))
3815 (date (calendar-gregorian-from-absolute today))
3816 (kwds org-todo-keywords-for-agenda)
3817 (completion-ignore-case t)
3818 (org-select-this-todo-keyword
3819 (if (stringp arg) arg
3820 (and arg (integerp arg) (> arg 0)
3821 (nth (1- arg) kwds))))
3822 rtn rtnall files file pos)
3823 (when (equal arg '(4))
3824 (setq org-select-this-todo-keyword
3825 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3826 (mapcar 'list kwds) nil nil)))
3827 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3828 (org-set-local 'org-last-arg arg)
3829 (setq org-agenda-redo-command
3830 '(org-todo-list (or current-prefix-arg org-last-arg)))
3831 (setq files (org-agenda-files nil 'ifmode)
3833 (while (setq file (pop files))
3835 (org-check-agenda-file file)
3836 (setq rtn (org-agenda-get-day-entries file date :todo))
3837 (setq rtnall (append rtnall rtn))))
3838 (if org-agenda-overriding-header
3839 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3840 nil 'face 'org-agenda-structure) "\n")
3841 (insert "Global list of TODO items of type: ")
3842 (add-text-properties (point-min) (1- (point))
3843 (list 'face 'org-agenda-structure
3846 (or org-select-this-todo-keyword "ALL"))))
3847 (org-agenda-mark-header-line (point-min))
3849 (insert (or org-select-this-todo-keyword "ALL") "\n")
3850 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3852 (unless org-agenda-multi
3853 (insert "Available with `N r': (0)ALL")
3856 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3857 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3862 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3863 (org-agenda-mark-header-line (point-min))
3865 (insert (org-finalize-agenda-entries rtnall) "\n"))
3866 (goto-char (point-min))
3867 (or org-agenda-multi (org-fit-agenda-window))
3868 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3869 (org-finalize-agenda)
3870 (setq buffer-read-only t)))
3872 ;;; Agenda tags match
3875 (defun org-tags-view (&optional todo-only match)
3876 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3877 The prefix arg TODO-ONLY limits the search to TODO entries."
3879 (org-compile-prefix-format 'tags)
3880 (org-set-sorting-strategy 'tags)
3881 (let* ((org-tags-match-list-sublevels
3882 org-tags-match-list-sublevels)
3883 (completion-ignore-case t)
3884 rtn rtnall files file pos matcher
3886 (when (and (stringp match) (not (string-match "\\S-" match)))
3888 (setq matcher (org-make-tags-matcher match)
3889 match (car matcher) matcher (cdr matcher))
3890 (org-prepare-agenda (concat "TAGS " match))
3891 (setq org-agenda-query-string match)
3892 (setq org-agenda-redo-command
3893 (list 'org-tags-view (list 'quote todo-only)
3894 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3895 (setq files (org-agenda-files nil 'ifmode)
3897 (while (setq file (pop files))
3899 (org-check-agenda-file file)
3900 (setq buffer (if (file-exists-p file)
3901 (org-get-agenda-file-buffer file)
3902 (error "No such file %s" file)))
3904 ;; If file does not exist, error message to agenda
3906 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3907 rtnall (append rtnall rtn))
3908 (with-current-buffer buffer
3909 (unless (org-mode-p)
3910 (error "Agenda file %s is not in `org-mode'" file))
3913 (if org-agenda-restrict
3914 (narrow-to-region org-agenda-restrict-begin
3915 org-agenda-restrict-end)
3917 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3918 (setq rtnall (append rtnall rtn))))))))
3919 (if org-agenda-overriding-header
3920 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3921 nil 'face 'org-agenda-structure) "\n")
3922 (insert "Headlines with TAGS match: ")
3923 (add-text-properties (point-min) (1- (point))
3924 (list 'face 'org-agenda-structure
3926 (concat "Match: " match)))
3929 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3931 (unless org-agenda-multi
3932 (insert "Press `C-u r' to search again with new search string\n"))
3933 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3934 (org-agenda-mark-header-line (point-min))
3936 (insert (org-finalize-agenda-entries rtnall) "\n"))
3937 (goto-char (point-min))
3938 (or org-agenda-multi (org-fit-agenda-window))
3939 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3940 (org-finalize-agenda)
3941 (setq buffer-read-only t)))
3943 ;;; Agenda Finding stuck projects
3945 (defvar org-agenda-skip-regexp nil
3946 "Regular expression used in skipping subtrees for the agenda.
3947 This is basically a temporary global variable that can be set and then
3948 used by user-defined selections using `org-agenda-skip-function'.")
3950 (defvar org-agenda-overriding-header nil
3951 "When this is set during todo and tags searches, will replace header.
3952 This variable should not be set directly, but custom commands can bind it
3953 in the options section.")
3955 (defun org-agenda-skip-entry-when-regexp-matches ()
3956 "Check if the current entry contains match for `org-agenda-skip-regexp'.
3957 If yes, it returns the end position of this entry, causing agenda commands
3958 to skip the entry but continuing the search in the subtree. This is a
3959 function that can be put into `org-agenda-skip-function' for the duration
3961 (let ((end (save-excursion (org-end-of-subtree t)))
3964 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3967 (defun org-agenda-skip-subtree-when-regexp-matches ()
3968 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
3969 If yes, it returns the end position of this tree, causing agenda commands
3970 to skip this subtree. This is a function that can be put into
3971 `org-agenda-skip-function' for the duration of a command."
3972 (let ((end (save-excursion (org-end-of-subtree t)))
3975 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3978 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3979 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
3980 If yes, it returns the end position of the current entry (NOT the tree),
3981 causing agenda commands to skip the entry but continuing the search in
3982 the subtree. This is a function that can be put into
3983 `org-agenda-skip-function' for the duration of a command. An important
3984 use of this function is for the stuck project list."
3985 (let ((end (save-excursion (org-end-of-subtree t)))
3986 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3989 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3990 (and skip entry-end)))
3992 (defun org-agenda-skip-entry-if (&rest conditions)
3993 "Skip entry if any of CONDITIONS is true.
3994 See `org-agenda-skip-if' for details."
3995 (org-agenda-skip-if nil conditions))
3997 (defun org-agenda-skip-subtree-if (&rest conditions)
3998 "Skip entry if any of CONDITIONS is true.
3999 See `org-agenda-skip-if' for details."
4000 (org-agenda-skip-if t conditions))
4002 (defun org-agenda-skip-if (subtree conditions)
4003 "Checks current entity for CONDITIONS.
4004 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4005 the entry, i.e. the text before the next heading is checked.
4007 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4008 from different tests. Valid conditions are:
4010 scheduled Check if there is a scheduled cookie
4011 notscheduled Check if there is no scheduled cookie
4012 deadline Check if there is a deadline
4013 notdeadline Check if there is no deadline
4014 timestamp Check if there is a timestamp (also deadline or scheduled)
4015 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4016 regexp Check if regexp matches
4017 notregexp Check if regexp does not match.
4018 todo Check if TODO keyword matches
4019 nottodo Check if TODO keyword does not match
4021 The regexp is taken from the conditions list, it must come right after
4022 the `regexp' or `notregexp' element.
4024 `todo' and `nottodo' accept as an argument a list of todo
4025 keywords, which may include \"*\" to match any todo keyword.
4027 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4029 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4031 Instead of a list a keyword class may be given
4033 (org-agenda-skip-entry-if 'nottodo 'done)
4035 would skip entries that haven't been marked with any of \"DONE\"
4036 keywords. Possible classes are: `todo', `done', `any'.
4038 If any of these conditions is met, this function returns the end point of
4039 the entity, causing the search to continue from there. This is a function
4040 that can be put into `org-agenda-skip-function' for the duration of a command."
4042 (org-back-to-heading t)
4045 (progn (org-end-of-subtree t) (point))
4046 (progn (outline-next-heading) (1- (point)))))
4050 (and (memq 'scheduled conditions)
4051 (re-search-forward org-scheduled-time-regexp end t))
4052 (and (memq 'notscheduled conditions)
4053 (not (re-search-forward org-scheduled-time-regexp end t)))
4054 (and (memq 'deadline conditions)
4055 (re-search-forward org-deadline-time-regexp end t))
4056 (and (memq 'notdeadline conditions)
4057 (not (re-search-forward org-deadline-time-regexp end t)))
4058 (and (memq 'timestamp conditions)
4059 (re-search-forward org-ts-regexp end t))
4060 (and (memq 'nottimestamp conditions)
4061 (not (re-search-forward org-ts-regexp end t)))
4062 (and (setq m (memq 'regexp conditions))
4064 (re-search-forward (nth 1 m) end t))
4065 (and (setq m (memq 'notregexp conditions))
4067 (not (re-search-forward (nth 1 m) end t)))
4069 (setq m (memq 'todo conditions))
4070 (setq m (memq 'nottodo conditions)))
4071 (org-agenda-skip-if-todo m end)))
4074 (defun org-agenda-skip-if-todo (args end)
4075 "Helper function for `org-agenda-skip-if', do not use it directly.
4076 ARGS is a list with first element either `todo' or `nottodo'.
4077 The remainder is either a list of TODO keywords, or a state symbol
4078 `todo' or `done' or `any'."
4079 (let ((kw (car args))
4085 ((listp arg) ;; list of keywords
4086 (if (member "*" arg)
4087 (mapcar 'substring-no-properties org-todo-keywords-1)
4089 ((symbolp arg) ;; keyword class name
4092 (org-delete-all org-done-keywords
4093 (mapcar 'substring-no-properties
4094 org-todo-keywords-1)))
4095 ((eq arg 'done) org-done-keywords)
4097 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4099 (concat "^\\*+[ \t]+\\<\\("
4100 (mapconcat 'identity todo-wds "\\|")
4103 (re-search-forward todo-re end t)
4104 (not (re-search-forward todo-re end t)))))
4107 (defun org-agenda-list-stuck-projects (&rest ignore)
4108 "Create agenda view for projects that are stuck.
4109 Stuck projects are project that have no next actions. For the definitions
4110 of what a project is and how to check if it stuck, customize the variable
4111 `org-stuck-projects'."
4113 (let* ((org-agenda-skip-function
4114 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4115 ;; We could have used org-agenda-skip-if here.
4116 (org-agenda-overriding-header
4117 (or org-agenda-overriding-header "List of stuck projects: "))
4118 (matcher (nth 0 org-stuck-projects))
4119 (todo (nth 1 org-stuck-projects))
4120 (todo-wds (if (member "*" todo)
4122 (org-prepare-agenda-buffers (org-agenda-files
4125 org-done-keywords-for-agenda
4126 (copy-sequence org-todo-keywords-for-agenda)))
4128 (todo-re (concat "^\\*+[ \t]+\\("
4129 (mapconcat 'identity todo-wds "\\|")
4131 (tags (nth 2 org-stuck-projects))
4132 (tags-re (if (member "*" tags)
4133 (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
4135 (concat "^\\*+ .*:\\("
4136 (mapconcat 'identity tags "\\|")
4137 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4138 (gen-re (nth 3 org-stuck-projects))
4144 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4146 (setq org-agenda-skip-regexp
4148 (mapconcat 'identity re-list "\\|")
4149 (error "No information how to identify unstuck projects")))
4150 (org-tags-view nil matcher)
4151 (with-current-buffer org-agenda-buffer-name
4152 (setq org-agenda-redo-command
4153 '(org-agenda-list-stuck-projects
4154 (or current-prefix-arg org-last-arg))))))
4156 ;;; Diary integration
4158 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4159 (defvar list-diary-entries-hook)
4161 (defun org-get-entries-from-diary (date)
4162 "Get the (Emacs Calendar) diary entries for DATE."
4163 (require 'diary-lib)
4164 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4165 (diary-display-hook '(fancy-diary-display))
4166 (diary-display-function 'fancy-diary-display)
4168 (list-diary-entries-hook
4169 (cons 'org-diary-default-entry list-diary-entries-hook))
4170 (diary-file-name-prefix-function nil) ; turn this feature off
4171 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4173 (org-disable-agenda-to-diary t))
4175 (save-window-excursion
4176 (funcall (if (fboundp 'diary-list-entries)
4177 'diary-list-entries 'list-diary-entries)
4179 (if (not (get-buffer diary-fancy-buffer))
4181 (with-current-buffer diary-fancy-buffer
4182 (setq buffer-read-only nil)
4183 (if (zerop (buffer-size))
4186 ;; Omit the date and other unnecessary stuff
4187 (org-agenda-cleanup-fancy-diary)
4188 ;; Add prefix to each line and extend the text properties
4189 (if (zerop (buffer-size))
4191 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
4192 (set-buffer-modified-p nil)
4193 (kill-buffer diary-fancy-buffer)))
4195 (setq entries (org-split-string entries "\n"))
4199 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4200 ;; Extend the text properties to the beginning of the line
4201 (org-add-props x (text-properties-at (1- (length x)) x)
4202 'type "diary" 'date date 'face 'org-agenda-diary))
4205 (defvar org-agenda-cleanup-fancy-diary-hook nil
4206 "Hook run when the fancy diary buffer is cleaned up.")
4208 (defun org-agenda-cleanup-fancy-diary ()
4209 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4210 This gets rid of the date, the underline under the date, and
4211 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4212 date. It also removes lines that contain only whitespace."
4213 (goto-char (point-min))
4214 (if (looking-at ".*?:[ \t]*")
4217 (re-search-forward "\n=+$" nil t)
4219 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4220 (re-search-forward "\n=+$" nil t)
4221 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4222 (goto-char (point-min))
4223 (while (re-search-forward "^ +\n" nil t)
4225 (goto-char (point-min))
4226 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4228 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4230 ;; Make sure entries from the diary have the right text properties.
4231 (eval-after-load "diary-lib"
4232 '(if (boundp 'diary-modify-entry-list-string-function)
4233 ;; We can rely on the hook, nothing to do
4235 ;; Hook not available, must use advice to make this work
4236 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4237 "Make the position visible."
4238 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4241 (setq string (org-modify-diary-entry-string string))))))
4243 (defun org-modify-diary-entry-string (string)
4244 "Add text properties to string, allowing org-mode to act on it."
4245 (org-add-props string nil
4246 'mouse-face 'highlight
4247 'help-echo (if buffer-file-name
4248 (format "mouse-2 or RET jump to diary file %s"
4249 (abbreviate-file-name buffer-file-name))
4251 'org-agenda-diary-link t
4252 'org-marker (org-agenda-new-marker (point-at-bol))))
4254 (defun org-diary-default-entry ()
4255 "Add a dummy entry to the diary.
4256 Needed to avoid empty dates which mess up holiday display."
4257 ;; Catch the error if dealing with the new add-to-diary-alist
4258 (when org-disable-agenda-to-diary
4260 (org-add-to-diary-list original-date "Org-mode dummy" "")
4262 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4264 (defun org-add-to-diary-list (&rest args)
4265 (if (fboundp 'diary-add-to-list)
4266 (apply 'diary-add-to-list args)
4267 (apply 'add-to-diary-list args)))
4269 (defvar org-diary-last-run-time nil)
4272 (defun org-diary (&rest args)
4273 "Return diary information from org-files.
4274 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4275 It accesses org files and extracts information from those files to be
4276 listed in the diary. The function accepts arguments specifying what
4277 items should be listed. For a list of arguments allowed here, see the
4278 variable `org-agenda-entry-types'.
4280 The call in the diary file should look like this:
4282 &%%(org-diary) ~/path/to/some/orgfile.org
4284 Use a separate line for each org file to check. Or, if you omit the file name,
4285 all files listed in `org-agenda-files' will be checked automatically:
4289 If you don't give any arguments (as in the example above), the default
4290 arguments (:deadline :scheduled :timestamp :sexp) are used.
4291 So the example above may also be written as
4293 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4295 The function expects the lisp variables `entry' and `date' to be provided
4296 by the caller, because this is how the calendar works. Don't use this
4297 function from a program - use `org-agenda-get-day-entries' instead."
4298 (when (> (- (org-float-time)
4299 org-agenda-last-marker-time)
4301 (org-agenda-reset-markers))
4302 (org-compile-prefix-format 'agenda)
4303 (org-set-sorting-strategy 'agenda)
4304 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4305 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4307 (org-agenda-files t)))
4308 (time (org-float-time))
4310 (when (or (not org-diary-last-run-time)
4312 org-diary-last-run-time)
4314 (org-prepare-agenda-buffers files))
4315 (setq org-diary-last-run-time time)
4316 ;; If this is called during org-agenda, don't return any entries to
4317 ;; the calendar. Org Agenda will list these entries itself.
4318 (if org-disable-agenda-to-diary (setq files nil))
4319 (while (setq file (pop files))
4320 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4321 (setq results (append results rtn)))
4323 (concat (org-finalize-agenda-entries results) "\n"))))
4325 ;;; Agenda entry finders
4327 (defun org-agenda-get-day-entries (file date &rest args)
4328 "Does the work for `org-diary' and `org-agenda'.
4329 FILE is the path to a file to be checked for entries. DATE is date like
4330 the one returned by `calendar-current-date'. ARGS are symbols indicating
4331 which kind of entries should be extracted. For details about these, see
4332 the documentation of `org-diary'."
4333 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4334 (let* ((org-startup-folded nil)
4335 (org-startup-align-all-tables nil)
4336 (buffer (if (file-exists-p file)
4337 (org-get-agenda-file-buffer file)
4338 (error "No such file %s" file)))
4339 arg results rtn deadline-results)
4341 ;; If file does not exist, make sure an error message ends up in diary
4342 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4343 (with-current-buffer buffer
4344 (unless (org-mode-p)
4345 (error "Agenda file %s is not in `org-mode'" file))
4346 (let ((case-fold-search nil))
4349 (if org-agenda-restrict
4350 (narrow-to-region org-agenda-restrict-begin
4351 org-agenda-restrict-end)
4353 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4354 (while (setq arg (pop args))
4356 ((and (eq arg :todo)
4357 (equal date (calendar-current-date)))
4358 (setq rtn (org-agenda-get-todos))
4359 (setq results (append results rtn)))
4360 ((eq arg :timestamp)
4361 (setq rtn (org-agenda-get-blocks))
4362 (setq results (append results rtn))
4363 (setq rtn (org-agenda-get-timestamps))
4364 (setq results (append results rtn)))
4366 (setq rtn (org-agenda-get-sexps))
4367 (setq results (append results rtn)))
4368 ((eq arg :scheduled)
4369 (setq rtn (org-agenda-get-scheduled deadline-results))
4370 (setq results (append results rtn)))
4372 (setq rtn (org-agenda-get-progress))
4373 (setq results (append results rtn)))
4375 (setq rtn (org-agenda-get-deadlines))
4376 (setq deadline-results (copy-sequence rtn))
4377 (setq results (append results rtn))))))))
4380 (defun org-agenda-get-todos ()
4381 "Return the TODO information for agenda display."
4382 (let* ((props (list 'face nil
4383 'done-face 'org-agenda-done
4384 'org-not-done-regexp org-not-done-regexp
4385 'org-todo-regexp org-todo-regexp
4386 'org-complex-heading-regexp org-complex-heading-regexp
4387 'mouse-face 'highlight
4389 (format "mouse-2 or RET jump to org file %s"
4390 (abbreviate-file-name buffer-file-name))))
4391 (regexp (concat "^\\*+[ \t]+\\("
4392 (if org-select-this-todo-keyword
4393 (if (equal org-select-this-todo-keyword "*")
4396 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4398 org-not-done-regexp)
4400 marker priority category tags todo-state
4402 (goto-char (point-min))
4403 (while (re-search-forward regexp nil t)
4407 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4408 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4409 (goto-char (1+ beg))
4410 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4414 (goto-char (match-beginning 1))
4415 (setq marker (org-agenda-new-marker (match-beginning 0))
4416 category (org-get-category)
4417 txt (match-string 1)
4418 tags (org-get-tags-at (point))
4419 txt (org-format-agenda-item "" txt category tags)
4420 priority (1+ (org-get-priority txt))
4421 todo-state (org-get-todo-state))
4422 (org-add-props txt props
4423 'org-marker marker 'org-hd-marker marker
4424 'priority priority 'org-category category
4425 'type "todo" 'todo-state todo-state)
4427 (if org-agenda-todo-list-sublevels
4428 (goto-char (match-end 1))
4429 (org-end-of-subtree 'invisible))))
4433 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4435 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4436 (when (or org-agenda-todo-ignore-with-date
4437 org-agenda-todo-ignore-scheduled
4438 org-agenda-todo-ignore-deadlines)
4439 (setq end (or end (save-excursion (outline-next-heading) (point))))
4441 (or (and org-agenda-todo-ignore-with-date
4442 (re-search-forward org-ts-regexp end t))
4443 (and org-agenda-todo-ignore-scheduled
4444 (re-search-forward org-scheduled-time-regexp end t)
4446 ((eq org-agenda-todo-ignore-scheduled 'future)
4447 (> (org-days-to-time (match-string 1)) 0))
4448 ((eq org-agenda-todo-ignore-scheduled 'past)
4449 (<= (org-days-to-time (match-string 1)) 0))
4451 (and org-agenda-todo-ignore-deadlines
4452 (re-search-forward org-deadline-time-regexp end t)
4454 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4455 ((eq org-agenda-todo-ignore-deadlines 'far)
4456 (not (org-deadline-close (match-string 1))))
4457 ((eq org-agenda-todo-ignore-deadlines 'future)
4458 (> (org-days-to-time (match-string 1)) 0))
4459 ((eq org-agenda-todo-ignore-deadlines 'past)
4460 (<= (org-days-to-time (match-string 1)) 0))
4461 (t (org-deadline-close (match-string 1)))))))))
4463 (defconst org-agenda-no-heading-message
4464 "No heading for this item in buffer or region.")
4466 (defun org-agenda-get-timestamps ()
4467 "Return the date stamp information for agenda display."
4468 (let* ((props (list 'face nil
4469 'org-not-done-regexp org-not-done-regexp
4470 'org-todo-regexp org-todo-regexp
4471 'org-complex-heading-regexp org-complex-heading-regexp
4472 'mouse-face 'highlight
4474 (format "mouse-2 or RET jump to org file %s"
4475 (abbreviate-file-name buffer-file-name))))
4476 (d1 (calendar-absolute-from-gregorian date))
4482 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4486 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4490 (car org-time-stamp-formats)
4491 (apply 'encode-time ; DATE bound by calendar
4492 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4494 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4495 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4496 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4497 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4498 todo-state end-of-match)
4499 (goto-char (point-min))
4500 (while (setq end-of-match (re-search-forward regexp nil t))
4501 (setq b0 (match-beginning 0)
4502 b3 (match-beginning 3) e3 (match-end 3))
4504 (and (org-at-date-range-p) (throw :skip nil))
4506 (if (and (match-end 1)
4507 (not (= d1 (org-time-string-to-absolute
4508 (match-string 1) d1 nil
4509 org-agenda-repeating-timestamp-show-all))))
4512 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4514 (setq tmp (buffer-substring (max (point-min)
4515 (- b0 org-ds-keyword-length))
4517 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4518 inactivep (= (char-after b0) ?\[)
4519 deadlinep (string-match org-deadline-regexp tmp)
4520 scheduledp (string-match org-scheduled-regexp tmp)
4521 closedp (and org-agenda-include-inactive-timestamps
4522 (string-match org-closed-string tmp))
4523 clockp (and org-agenda-include-inactive-timestamps
4524 (or (string-match org-clock-string tmp)
4525 (string-match "]-+\\'" tmp)))
4526 todo-state (ignore-errors (org-get-todo-state))
4527 donep (member todo-state org-done-keywords))
4528 (if (or scheduledp deadlinep closedp clockp
4529 (and donep org-agenda-skip-timestamp-if-done))
4531 (if (string-match ">" timestr)
4532 ;; substring should only run to end of time stamp
4533 (setq timestr (substring timestr 0 (match-end 0))))
4534 (setq marker (org-agenda-new-marker b0)
4535 category (org-get-category b0))
4537 (if (not (re-search-backward "^\\*+ " nil t))
4538 (setq txt org-agenda-no-heading-message)
4539 (goto-char (match-beginning 0))
4540 (setq hdmarker (org-agenda-new-marker)
4541 tags (org-get-tags-at))
4542 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4543 (setq head (match-string 1))
4544 (setq txt (org-format-agenda-item
4545 (if inactivep org-agenda-inactive-leader nil)
4546 head category tags timestr nil
4548 (setq priority (org-get-priority txt))
4549 (org-add-props txt props
4550 'org-marker marker 'org-hd-marker hdmarker)
4551 (org-add-props txt nil 'priority priority
4552 'org-category category 'date date
4553 'todo-state todo-state
4556 (if org-agenda-skip-additional-timestamps-same-entry
4557 (outline-next-heading)
4558 (goto-char end-of-match))))
4561 (defun org-agenda-get-sexps ()
4562 "Return the sexp information for agenda display."
4563 (require 'diary-lib)
4564 (let* ((props (list 'face nil
4565 'mouse-face 'highlight
4567 (format "mouse-2 or RET jump to org file %s"
4568 (abbreviate-file-name buffer-file-name))))
4570 marker category ee txt tags entry result beg b sexp sexp-entry
4572 (goto-char (point-min))
4573 (while (re-search-forward regexp nil t)
4576 (setq beg (match-beginning 0))
4577 (goto-char (1- (match-end 0)))
4580 (setq sexp (buffer-substring b (point)))
4581 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4582 (org-trim (match-string 1))
4584 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4586 (setq marker (org-agenda-new-marker beg)
4587 category (org-get-category beg)
4588 todo-state (org-get-todo-state))
4590 (dolist (r (if (stringp result)
4592 result)) ;; we expect a list here
4593 (if (string-match "\\S-" r)
4595 (setq txt "SEXP entry returned empty string"))
4597 (setq txt (org-format-agenda-item
4598 "" txt category tags 'time))
4599 (org-add-props txt props 'org-marker marker)
4600 (org-add-props txt nil
4601 'org-category category 'date date 'todo-state todo-state
4606 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4607 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4608 The order of the first 2 times 3 arguments depends on the variable
4609 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4610 So for American calendars, give this as MONTH DAY YEAR, for European as
4611 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4612 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4613 is any number of ISO weeks in the block period for which the item should
4615 (let* ((date1 (calendar-absolute-from-gregorian
4616 (org-order-calendar-date-args m1 d1 y1)))
4617 (date2 (calendar-absolute-from-gregorian
4618 (org-order-calendar-date-args m2 d2 y2)))
4619 (d (calendar-absolute-from-gregorian date)))
4623 (= (calendar-day-of-week date) dayname)
4624 (or (not skip-weeks)
4627 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4630 (defalias 'org-get-closed 'org-agenda-get-progress)
4631 (defun org-agenda-get-progress ()
4632 "Return the logged TODO entries for agenda display."
4633 (let* ((props (list 'mouse-face 'highlight
4634 'org-not-done-regexp org-not-done-regexp
4635 'org-todo-regexp org-todo-regexp
4636 'org-complex-heading-regexp org-complex-heading-regexp
4638 (format "mouse-2 or RET jump to org file %s"
4639 (abbreviate-file-name buffer-file-name))))
4640 (items (if (consp org-agenda-show-log)
4642 org-agenda-log-mode-items))
4646 (if (memq 'closed items) (concat "\\<" org-closed-string))
4647 (if (memq 'clock items) (concat "\\<" org-clock-string))
4648 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4649 (parts-re (if parts (mapconcat 'identity parts "\\|")
4650 (error "`org-agenda-log-mode-items' is empty")))
4652 "\\(" parts-re "\\)"
4657 (car org-time-stamp-formats)
4658 (apply 'encode-time ; DATE bound by calendar
4659 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4661 (org-agenda-search-headline-for-time nil)
4662 marker hdmarker priority category tags closedp statep clockp state
4663 ee txt extra timestr rest clocked)
4664 (goto-char (point-min))
4665 (while (re-search-forward regexp nil t)
4668 (setq marker (org-agenda-new-marker (match-beginning 0))
4669 closedp (equal (match-string 1) org-closed-string)
4670 statep (equal (string-to-char (match-string 1)) ?-)
4671 clockp (not (or closedp statep))
4672 state (and statep (match-string 2))
4673 category (org-get-category (match-beginning 0))
4674 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4676 (when (string-match "\\]" timestr)
4677 ;; substring should only run to end of time stamp
4678 (setq rest (substring timestr (match-end 0))
4679 timestr (substring timestr 0 (match-end 0)))
4680 (if (and (not closedp) (not statep)
4681 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4682 (progn (setq timestr (concat (substring timestr 0 -1)
4683 "-" (match-string 1 rest) "]"))
4684 (setq clocked (match-string 2 rest)))
4685 (setq clocked "-")))
4689 ((not org-agenda-log-mode-add-notes))
4691 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4692 (setq extra (match-string 1))))
4694 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4695 (setq extra (match-string 1)))))
4696 (if (not (re-search-backward "^\\*+ " nil t))
4697 (setq txt org-agenda-no-heading-message)
4698 (goto-char (match-beginning 0))
4699 (setq hdmarker (org-agenda-new-marker)
4700 tags (org-get-tags-at))
4701 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4702 (setq txt (match-string 1))
4704 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4705 (setq txt (concat (substring txt 0 (match-beginning 1))
4706 " - " extra " " (match-string 2 txt)))
4707 (setq txt (concat txt " - " extra))))
4708 (setq txt (org-format-agenda-item
4710 (closedp "Closed: ")
4711 (statep (concat "State: (" state ")"))
4712 (t (concat "Clocked: (" clocked ")")))
4713 txt category tags timestr)))
4714 (setq priority 100000)
4715 (org-add-props txt props
4716 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4717 'priority priority 'org-category category
4718 'type "closed" 'date date
4719 'undone-face 'org-warning 'done-face 'org-agenda-done)
4721 (goto-char (point-at-eol))))
4724 (defun org-agenda-get-deadlines ()
4725 "Return the deadline information for agenda display."
4726 (let* ((props (list 'mouse-face 'highlight
4727 'org-not-done-regexp org-not-done-regexp
4728 'org-todo-regexp org-todo-regexp
4729 'org-complex-heading-regexp org-complex-heading-regexp
4731 (format "mouse-2 or RET jump to org file %s"
4732 (abbreviate-file-name buffer-file-name))))
4733 (regexp org-deadline-time-regexp)
4734 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4735 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4736 d2 diff dfrac wdays pos pos1 category tags
4738 ee txt head face s todo-state upcomingp donep timestr)
4739 (goto-char (point-min))
4740 (while (re-search-forward regexp nil t)
4741 (setq suppress-prewarning nil)
4744 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4746 (string-match org-scheduled-time-regexp
4747 (buffer-substring (point-at-bol)
4749 (setq suppress-prewarning
4750 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4751 org-agenda-skip-deadline-prewarning-if-scheduled
4753 (setq s (match-string 1)
4755 pos (1- (match-beginning 1))
4756 d2 (org-time-string-to-absolute
4757 (match-string 1) d1 'past
4758 org-agenda-repeating-timestamp-show-all)
4760 wdays (if suppress-prewarning
4761 (let ((org-deadline-warning-days suppress-prewarning))
4764 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4765 upcomingp (and todayp (> diff 0)))
4766 ;; When to show a deadline in the calendar:
4767 ;; If the expiration is within wdays warning time.
4768 ;; Past-due deadlines are only shown on the current date
4769 (if (and (or (and (<= diff wdays)
4770 (and todayp (not org-agenda-only-exact-dates)))
4773 (setq todo-state (org-get-todo-state))
4774 (setq donep (member todo-state org-done-keywords))
4776 (or org-agenda-skip-deadline-if-done
4779 (setq category (org-get-category))
4780 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4781 (setq txt org-agenda-no-heading-message)
4782 (goto-char (match-end 0))
4783 (setq pos1 (match-beginning 0))
4784 (setq tags (org-get-tags-at pos1))
4785 (setq head (buffer-substring-no-properties
4787 (progn (skip-chars-forward "^\r\n")
4789 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4791 (concat (substring s (match-beginning 1)) " "))
4792 (setq timestr 'time))
4793 (setq txt (org-format-agenda-item
4795 (car org-agenda-deadline-leaders)
4797 (nth 1 org-agenda-deadline-leaders))
4799 (nth 1 org-agenda-deadline-leaders)
4801 (format (nth 1 org-agenda-deadline-leaders)
4804 (if (not (= diff 0)) nil timestr)))))
4806 (setq face (org-agenda-deadline-face dfrac wdays))
4807 (org-add-props txt props
4808 'org-marker (org-agenda-new-marker pos)
4809 'org-hd-marker (org-agenda-new-marker pos1)
4810 'priority (+ (- diff)
4811 (org-get-priority txt))
4812 'org-category category
4813 'todo-state todo-state
4814 'type (if upcomingp "upcoming-deadline" "deadline")
4815 'date (if upcomingp date d2)
4816 'face (if donep 'org-agenda-done face)
4817 'undone-face face 'done-face 'org-agenda-done)
4821 (defun org-agenda-deadline-face (fraction &optional wdays)
4822 "Return the face to displaying a deadline item.
4823 FRACTION is what fraction of the head-warning time has passed."
4824 (if (equal wdays 0) (setq fraction 1.))
4825 (let ((faces org-agenda-deadline-faces) f)
4827 (while (setq f (pop faces))
4828 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4830 (defun org-agenda-get-scheduled (&optional deadline-results)
4831 "Return the scheduled information for agenda display."
4832 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4833 'org-todo-regexp org-todo-regexp
4834 'org-complex-heading-regexp org-complex-heading-regexp
4835 'done-face 'org-agenda-done
4836 'mouse-face 'highlight
4838 (format "mouse-2 or RET jump to org file %s"
4839 (abbreviate-file-name buffer-file-name))))
4840 (regexp org-scheduled-time-regexp)
4841 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4842 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4844 (deadline-position-alist
4845 (mapcar (lambda (a) (and (setq mm (get-text-property
4846 0 'org-hd-marker a))
4847 (cons (marker-position mm) a)))
4849 d2 diff pos pos1 category tags donep
4850 ee txt head pastschedp todo-state face timestr s habitp)
4851 (goto-char (point-min))
4852 (while (re-search-forward regexp nil t)
4855 (setq s (match-string 1)
4857 pos (1- (match-beginning 1))
4858 d2 (org-time-string-to-absolute
4859 (match-string 1) d1 'past
4860 org-agenda-repeating-timestamp-show-all)
4862 (setq pastschedp (and todayp (< diff 0)))
4863 ;; When to show a scheduled item in the calendar:
4864 ;; If it is on or past the date.
4865 (when (or (and (< diff 0)
4866 (< (abs diff) org-scheduled-past-days)
4867 (and todayp (not org-agenda-only-exact-dates)))
4870 (setq todo-state (org-get-todo-state))
4871 (setq donep (member todo-state org-done-keywords))
4872 (setq habitp (and (functionp 'org-is-habit-p)
4875 (or habitp org-agenda-skip-scheduled-if-done
4878 (setq category (org-get-category))
4879 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4880 (setq txt org-agenda-no-heading-message)
4881 (goto-char (match-end 0))
4882 (setq pos1 (match-beginning 0))
4884 (if (or (not org-habit-show-habits)
4886 org-habit-show-habits-only-for-today))
4889 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4890 (and org-agenda-skip-scheduled-if-deadline-is-shown
4892 (setq mm (assoc pos1 deadline-position-alist)))
4894 (setq tags (org-get-tags-at))
4895 (setq head (buffer-substring-no-properties
4897 (progn (skip-chars-forward "^\r\n") (point))))
4898 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4900 (concat (substring s (match-beginning 1)) " "))
4901 (setq timestr 'time))
4902 (setq txt (org-format-agenda-item
4904 (car org-agenda-scheduled-leaders)
4905 (format (nth 1 org-agenda-scheduled-leaders)
4908 (if (not (= diff 0)) nil timestr)
4913 ((and (not habitp) pastschedp)
4914 'org-scheduled-previously)
4915 (todayp 'org-scheduled-today)
4917 habitp (and habitp (org-habit-parse-todo)))
4918 (org-add-props txt props
4920 'face (if donep 'org-agenda-done face)
4921 'org-marker (org-agenda-new-marker pos)
4922 'org-hd-marker (org-agenda-new-marker pos1)
4923 'type (if pastschedp "past-scheduled" "scheduled")
4924 'date (if pastschedp d2 date)
4925 'priority (if habitp
4926 (org-habit-get-priority habitp)
4927 (+ 94 (- 5 diff) (org-get-priority txt)))
4928 'org-category category
4930 'todo-state todo-state)
4934 (defun org-agenda-get-blocks ()
4935 "Return the date-range information for agenda display."
4936 (let* ((props (list 'face nil
4937 'org-not-done-regexp org-not-done-regexp
4938 'org-todo-regexp org-todo-regexp
4939 'org-complex-heading-regexp org-complex-heading-regexp
4940 'mouse-face 'highlight
4942 (format "mouse-2 or RET jump to org file %s"
4943 (abbreviate-file-name buffer-file-name))))
4944 (regexp org-tr-regexp)
4945 (d0 (calendar-absolute-from-gregorian date))
4946 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4948 (goto-char (point-min))
4949 (while (re-search-forward regexp nil t)
4953 (setq timestr (match-string 0)
4956 d1 (time-to-days (org-time-string-to-time s1))
4957 d2 (time-to-days (org-time-string-to-time s2)))
4958 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4959 ;; Only allow days between the limits, because the normal
4960 ;; date stamps will catch the limits.
4962 (setq todo-state (org-get-todo-state))
4963 (setq donep (member todo-state org-done-keywords))
4964 (if (and donep org-agenda-skip-timestamp-if-done)
4966 (setq marker (org-agenda-new-marker (point)))
4967 (setq category (org-get-category))
4968 (if (not (re-search-backward "^\\*+ " nil t))
4969 (setq txt org-agenda-no-heading-message)
4970 (goto-char (match-beginning 0))
4971 (setq hdmarker (org-agenda-new-marker (point)))
4972 (setq tags (org-get-tags-at))
4973 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4974 (setq head (match-string 1))
4976 (if org-agenda-remove-timeranges-from-blocks
4978 "<" (regexp-quote s1) ".*?>"
4980 "<" (regexp-quote s2) ".*?>")
4982 (setq txt (org-format-agenda-item
4984 (nth (if (= d1 d2) 0 1)
4985 org-agenda-timerange-leaders)
4986 (1+ (- d0 d1)) (1+ (- d2 d1)))
4988 timestr nil remove-re))))
4989 (org-add-props txt props
4990 'org-marker marker 'org-hd-marker hdmarker
4991 'type "block" 'date date
4992 'todo-state todo-state
4993 'priority (org-get-priority txt) 'org-category category)
4996 ;; Sort the entries by expiration date.
4999 ;;; Agenda presentation and sorting
5001 (defvar org-prefix-has-time nil
5002 "A flag, set by `org-compile-prefix-format'.
5003 The flag is set if the currently compiled format contains a `%t'.")
5004 (defvar org-prefix-has-tag nil
5005 "A flag, set by `org-compile-prefix-format'.
5006 The flag is set if the currently compiled format contains a `%T'.")
5007 (defvar org-prefix-has-effort nil
5008 "A flag, set by `org-compile-prefix-format'.
5009 The flag is set if the currently compiled format contains a `%e'.")
5010 (defvar org-prefix-category-length nil
5011 "Used by `org-compile-prefix-format' to remember the category field width.")
5012 (defvar org-prefix-category-max-length nil
5013 "Used by `org-compile-prefix-format' to remember the category field width.")
5015 (defun org-agenda-get-category-icon (category)
5016 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5017 (dolist (entry org-agenda-category-icon-alist)
5018 (when (org-string-match-p (car entry) category)
5019 (if (listp (cadr entry))
5020 (return (cadr entry))
5021 (return (apply 'create-image (cdr entry)))))))
5023 (defun org-format-agenda-item (extra txt &optional category tags dotime
5024 noprefix remove-re habitp)
5025 "Format TXT to be inserted into the agenda buffer.
5026 In particular, it adds the prefix and corresponding text properties. EXTRA
5027 must be a string and replaces the `%s' specifier in the prefix format.
5028 CATEGORY (string, symbol or nil) may be used to overrule the default
5029 category taken from local variable or file name. It will replace the `%c'
5030 specifier in the format. DOTIME, when non-nil, indicates that a
5031 time-of-day should be extracted from TXT for sorting of this entry, and for
5032 the `%t' specifier in the format. When DOTIME is a string, this string is
5033 searched for a time before TXT is. NOPREFIX is a flag and indicates that
5034 only the correctly processes TXT should be returned - this is used by
5035 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
5036 Any match of REMOVE-RE will be removed from TXT."
5038 ;; Diary entries sometimes have extra whitespace at the beginning
5039 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5041 ;; Fix the tags part in txt
5042 (setq txt (org-agenda-fix-displayed-tags
5044 org-agenda-show-inherited-tags
5045 org-agenda-hide-tags-regexp))
5046 (let* ((category (or category
5048 (if buffer-file-name
5049 (file-name-sans-extension
5050 (file-name-nondirectory buffer-file-name))
5052 (category-icon (org-agenda-get-category-icon category))
5053 (category-icon (if category-icon
5054 (propertize " " 'display category-icon)
5056 ;; time, tag, effort are needed for the eval of the prefix format
5057 (tag (if tags (nth (1- (length tags)) tags) ""))
5059 (ts (if dotime (concat
5060 (if (stringp dotime) dotime "")
5061 (and org-agenda-search-headline-for-time txt))))
5062 (time-of-day (and dotime (org-get-time-of-day ts)))
5063 stamp plain s0 s1 s2 t1 t2 rtn srp l
5064 duration thecategory)
5065 (and (org-mode-p) buffer-file-name
5066 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5067 (when (and dotime time-of-day)
5068 ;; Extract starting and ending time and move them to prefix
5069 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5070 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5071 (setq s0 (match-string 0 ts)
5072 srp (and stamp (match-end 3))
5073 s1 (match-string (if plain 1 2) ts)
5074 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5076 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5077 ;; them, we might want to remove them there to avoid duplication.
5078 ;; The user can turn this off with a variable.
5079 (if (and org-prefix-has-time
5080 org-agenda-remove-times-when-in-prefix (or stamp plain)
5081 (string-match (concat (regexp-quote s0) " *") txt)
5082 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5083 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5084 (= (match-beginning 0) 0)
5086 (setq txt (replace-match "" nil nil txt))))
5087 ;; Normalize the time(s) to 24 hour
5088 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5089 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5090 ;; Compute the duration
5092 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
5093 (string-to-number (substring s1 3)))
5095 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
5096 (string-to-number (substring s2 3))))
5097 (org-agenda-default-appointment-duration
5098 (+ t1 org-agenda-default-appointment-duration))
5100 (setq duration (if t2 (- t2 t1)))))
5102 (when (and s1 (not s2) org-agenda-default-appointment-duration
5103 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
5104 (let ((m (+ (string-to-number (match-string 2 s1))
5105 (* 60 (string-to-number (match-string 1 s1)))
5106 org-agenda-default-appointment-duration))
5108 (setq h (/ m 60) m (- m (* h 60)))
5109 (setq s2 (format "%02d:%02d" h m))))
5111 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5113 ;; Tags are in the string
5114 (if (or (eq org-agenda-remove-tags t)
5115 (and org-agenda-remove-tags
5116 org-prefix-has-tag))
5117 (setq txt (replace-match "" t t txt))
5118 (setq txt (replace-match
5119 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5120 (match-string 2 txt))
5126 (or (get-text-property 0 'org-hd-marker txt)
5127 (get-text-property 0 'org-marker txt)))
5130 (setq neffort (org-hh:mm-string-to-minutes effort)
5131 effort (setq effort (concat "[" effort "]" )))))
5134 (while (string-match remove-re txt)
5135 (setq txt (replace-match "" t t txt))))
5137 ;; Create the final string
5140 ;; Prepare the variables needed in the eval of the compiled format
5141 (setq time (cond (s2 (concat
5142 (org-agenda-time-of-day-to-ampm-maybe s1)
5143 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5144 (if org-agenda-timegrid-use-ampm " ")))
5146 (org-agenda-time-of-day-to-ampm-maybe s1)
5147 (if org-agenda-timegrid-use-ampm
5151 extra (or (and (not habitp) extra) "")
5152 category (if (symbolp category) (symbol-name category) category)
5153 thecategory (copy-sequence category))
5154 (if (string-match org-bracket-link-regexp category)
5156 (setq l (if (match-end 3)
5157 (- (match-end 3) (match-beginning 3))
5158 (- (match-end 1) (match-beginning 1))))
5159 (when (< l (or org-prefix-category-length 0))
5160 (setq category (copy-sequence category))
5161 (org-add-props category nil
5162 'extra-space (make-string
5163 (- org-prefix-category-length l 1) ?\ ))))
5164 (if (and org-prefix-category-max-length
5165 (>= (length category) org-prefix-category-max-length))
5166 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5167 ;; Evaluate the compiled format
5168 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
5170 ;; And finally add the text properties
5171 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5172 (org-add-props rtn nil
5173 'org-category (if thecategory (downcase thecategory) category)
5174 'tags (mapcar 'org-downcase-keep-props tags)
5175 'org-highest-priority org-highest-priority
5176 'org-lowest-priority org-lowest-priority
5177 'prefix-length (- (length rtn) (length txt))
5178 'time-of-day time-of-day
5181 'effort-minutes neffort
5187 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5188 "Remove tags string from TXT, and add a modified list of tags.
5189 The modified list may contain inherited tags, and tags matched by
5190 `org-agenda-hide-tags-regexp' will be removed."
5191 (when (or add-inherited hide-re)
5192 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5193 (setq txt (substring txt 0 (match-beginning 0))))
5196 (mapcar (lambda (tg)
5197 (if (or (and hide-re (string-match hide-re tg))
5198 (and (not add-inherited)
5199 (get-text-property 0 'inherited tg)))
5204 (let ((have-i (get-text-property 0 'inherited (car tags)))
5206 (setq txt (concat txt " :"
5209 (setq i (get-text-property 0 'inherited x))
5210 (if (and have-i (not i))
5216 (if have-i "::" ":"))))))
5219 (defun org-downcase-keep-props (s)
5220 (let ((props (text-properties-at 0 s)))
5221 (setq s (downcase s))
5222 (add-text-properties 0 (length s) props s)
5225 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5226 (defvar org-agenda-sorting-strategy-selected nil)
5228 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5230 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5231 ((and todayp (member 'today (car org-agenda-time-grid))))
5232 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5233 ((member 'weekly (car org-agenda-time-grid)))
5234 (t (throw 'exit list)))
5235 (let* ((have (delq nil (mapcar
5236 (lambda (x) (get-text-property 1 'time-of-day x))
5238 (string (nth 1 org-agenda-time-grid))
5239 (gridtimes (nth 2 org-agenda-time-grid))
5240 (req (car org-agenda-time-grid))
5241 (remove (member 'remove-match req))
5243 (if (and (member 'require-timed req) (not have))
5244 ;; don't show empty grid
5246 (while (setq time (pop gridtimes))
5247 (unless (and remove (member time have))
5248 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5249 (push (org-format-agenda-item
5251 (concat (substring time 0 -2) ":" (substring time -2)))
5254 2 (length (car new)) 'face 'org-time-grid (car new))))
5255 (if (member 'time-up org-agenda-sorting-strategy-selected)
5257 (append list new)))))
5259 (defun org-compile-prefix-format (key)
5260 "Compile the prefix format into a Lisp form that can be evaluated.
5261 The resulting form is returned and stored in the variable
5262 `org-prefix-format-compiled'."
5263 (setq org-prefix-has-time nil org-prefix-has-tag nil
5264 org-prefix-category-length nil org-prefix-has-effort nil)
5266 ((stringp org-agenda-prefix-format)
5267 org-agenda-prefix-format)
5268 ((assq key org-agenda-prefix-format)
5269 (cdr (assq key org-agenda-prefix-format)))
5270 (t " %-12:c%?-12t% s")))
5272 varform vars var e c f opt)
5273 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\)"
5275 (setq var (cdr (assoc (match-string 4 s)
5276 '(("c" . category) ("t" . time) ("s" . extra)
5277 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5278 c (or (match-string 3 s) "")
5279 opt (match-beginning 1)
5280 start (1+ (match-beginning 0)))
5281 (if (equal var 'time) (setq org-prefix-has-time t))
5282 (if (equal var 'tag) (setq org-prefix-has-tag t))
5283 (if (equal var 'effort) (setq org-prefix-has-effort t))
5284 (setq f (concat "%" (match-string 2 s) "s"))
5285 (when (equal var 'category)
5286 (setq org-prefix-category-length
5287 (floor (abs (string-to-number (match-string 2 s)))))
5288 (setq org-prefix-category-max-length
5289 (let ((x (match-string 2 s)))
5291 (if (string-match "\\.[0-9]+" x)
5292 (string-to-number (substring (match-string 0 x) 1)))))))
5295 `(if (equal "" ,var)
5297 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5298 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
5299 (setq s (replace-match "%s" t nil s))
5300 (push varform vars))
5301 (setq vars (nreverse vars))
5302 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5304 (defun org-set-sorting-strategy (key)
5305 (if (symbolp (car org-agenda-sorting-strategy))
5307 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5308 (setq org-agenda-sorting-strategy-selected
5309 (or (cdr (assq key org-agenda-sorting-strategy))
5310 (cdr (assq 'agenda org-agenda-sorting-strategy))
5311 '(time-up category-keep priority-down)))))
5313 (defun org-get-time-of-day (s &optional string mod24)
5314 "Check string S for a time of day.
5315 If found, return it as a military time number between 0 and 2400.
5316 If not found, return nil.
5317 The optional STRING argument forces conversion into a 5 character wide string
5321 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5322 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5323 (let* ((h (string-to-number (match-string 1 s)))
5324 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5325 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5326 (am-p (equal ampm "am"))
5327 (h1 (cond ((not ampm) h)
5328 ((= h 12) (if am-p 0 12))
5329 (t (+ h (if am-p 0 12)))))
5330 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5332 (t0 (+ (* 100 h2) m))
5333 (t1 (concat (if (>= h1 24) "+" " ")
5334 (if (and org-agenda-time-leading-zero
5335 (< t0 1000)) "0" "")
5336 (if (< t0 100) "0" "")
5337 (if (< t0 10) "0" "")
5338 (int-to-string t0))))
5339 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5341 (defvar org-agenda-before-sorting-filter-function nil
5342 "Function to be applied to agenda items prior to sorting.
5343 Prior to sorting also means just before they are inserted into the agenda.
5345 To aid sorting, you may revisit the original entries and add more text
5346 properties which will later be used by the sorting functions.
5348 The function should take a string argument, an agenda line.
5349 It has access to the text properties in that line, which contain among
5350 other things, the property `org-hd-marker' that points to the entry
5351 where the line comes from. Note that not all lines going into the agenda
5352 have this property, only most.
5354 The function should return the modified string. It is probably best
5355 to ONLY change text properties.
5357 You can also use this function as a filter, by returning nil for lines
5358 you don't want to have in the agenda at all. For this application, you
5359 could bind the variable in the options section of a custom command.")
5361 (defun org-finalize-agenda-entries (list &optional nosort)
5362 "Sort and concatenate the agenda items."
5363 (setq list (mapcar 'org-agenda-highlight-todo list))
5366 (when org-agenda-before-sorting-filter-function
5367 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5368 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5370 (defun org-agenda-highlight-todo (x)
5371 (let ((org-done-keywords org-done-keywords-for-agenda)
5372 (case-fold-search nil)
5376 (beginning-of-line 1)
5377 (setq re (org-get-at-bol 'org-todo-regexp))
5378 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
5379 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5380 (add-text-properties (match-beginning 0) (match-end 1)
5381 (list 'face (org-get-todo-face 1)))
5382 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5383 (delete-region (match-beginning 1) (1- (match-end 0)))
5384 (goto-char (match-beginning 1))
5385 (insert (format org-agenda-todo-keyword-format s)))))
5386 (setq re (concat (get-text-property 0 'org-todo-regexp x))
5387 pl (get-text-property 0 'prefix-length x))
5389 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5391 (add-text-properties
5392 (or (match-end 1) (match-end 0)) (match-end 0)
5393 (list 'face (org-get-todo-face (match-string 2 x)))
5396 (setq x (concat (substring x 0 (match-end 1))
5397 (format org-agenda-todo-keyword-format
5399 (org-add-props " " (text-properties-at 0 x))
5400 (substring x (match-end 3))))))
5403 (defsubst org-cmp-priority (a b)
5404 "Compare the priorities of string A and B."
5405 (let ((pa (or (get-text-property 1 'priority a) 0))
5406 (pb (or (get-text-property 1 'priority b) 0)))
5407 (cond ((> pa pb) +1)
5411 (defsubst org-cmp-effort (a b)
5412 "Compare the priorities of string A and B."
5413 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5414 (ea (or (get-text-property 1 'effort-minutes a) def))
5415 (eb (or (get-text-property 1 'effort-minutes b) def)))
5416 (cond ((> ea eb) +1)
5420 (defsubst org-cmp-category (a b)
5421 "Compare the string values of categories of strings A and B."
5422 (let ((ca (or (get-text-property 1 'org-category a) ""))
5423 (cb (or (get-text-property 1 'org-category b) "")))
5424 (cond ((string-lessp ca cb) -1)
5425 ((string-lessp cb ca) +1)
5428 (defsubst org-cmp-todo-state (a b)
5429 "Compare the todo states of strings A and B."
5430 (let* ((ma (or (get-text-property 1 'org-marker a)
5431 (get-text-property 1 'org-hd-marker a)))
5432 (mb (or (get-text-property 1 'org-marker b)
5433 (get-text-property 1 'org-hd-marker b)))
5434 (fa (and ma (marker-buffer ma)))
5435 (fb (and mb (marker-buffer mb)))
5437 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5438 (and fb (with-current-buffer fb org-todo-keywords-1))))
5439 (ta (or (get-text-property 1 'todo-state a) ""))
5440 (tb (or (get-text-property 1 'todo-state b) ""))
5441 (la (- (length (member ta todo-kwds))))
5442 (lb (- (length (member tb todo-kwds))))
5443 (donepa (member ta org-done-keywords-for-agenda))
5444 (donepb (member tb org-done-keywords-for-agenda)))
5445 (cond ((and donepa (not donepb)) -1)
5446 ((and (not donepa) donepb) +1)
5451 (defsubst org-cmp-alpha (a b)
5452 "Compare the headlines, alphabetically."
5453 (let* ((pla (get-text-property 0 'prefix-length a))
5454 (plb (get-text-property 0 'prefix-length b))
5455 (ta (and pla (substring a pla)))
5456 (tb (and plb (substring b plb))))
5458 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5459 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5460 (setq ta (substring ta (match-end 0))))
5461 (setq ta (downcase ta)))
5463 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5464 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5465 (setq tb (substring tb (match-end 0))))
5466 (setq tb (downcase tb)))
5469 ((string-lessp ta tb) -1)
5470 ((string-lessp tb ta) +1)
5473 (defsubst org-cmp-tag (a b)
5474 "Compare the string values of the first tags of A and B."
5475 (let ((ta (car (last (get-text-property 1 'tags a))))
5476 (tb (car (last (get-text-property 1 'tags b)))))
5479 ((string-lessp ta tb) -1)
5480 ((string-lessp tb ta) +1)
5483 (defsubst org-cmp-time (a b)
5484 "Compare the time-of-day values of strings A and B."
5485 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5486 (ta (or (get-text-property 1 'time-of-day a) def))
5487 (tb (or (get-text-property 1 'time-of-day b) def)))
5488 (cond ((< ta tb) -1)
5492 (defsubst org-cmp-habit-p (a b)
5493 "Compare the todo states of strings A and B."
5494 (let ((ha (get-text-property 1 'org-habit-p a))
5495 (hb (get-text-property 1 'org-habit-p b)))
5496 (cond ((and ha (not hb)) -1)
5497 ((and (not ha) hb) +1)
5500 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5502 (defun org-entries-lessp (a b)
5503 "Predicate for sorting agenda entries."
5504 ;; The following variables will be used when the form is evaluated.
5505 ;; So even though the compiler complains, keep them.
5506 (let* ((ss org-agenda-sorting-strategy-selected)
5507 (time-up (and (org-em 'time-up 'time-down ss)
5508 (org-cmp-time a b)))
5509 (time-down (if time-up (- time-up) nil))
5510 (priority-up (and (org-em 'priority-up 'priority-down ss)
5511 (org-cmp-priority a b)))
5512 (priority-down (if priority-up (- priority-up) nil))
5513 (effort-up (and (org-em 'effort-up 'effort-down ss)
5514 (org-cmp-effort a b)))
5515 (effort-down (if effort-up (- effort-up) nil))
5516 (category-up (and (or (org-em 'category-up 'category-down ss)
5517 (memq 'category-keep ss))
5518 (org-cmp-category a b)))
5519 (category-down (if category-up (- category-up) nil))
5520 (category-keep (if category-up +1 nil))
5521 (tag-up (and (org-em 'tag-up 'tag-down ss)
5523 (tag-down (if tag-up (- tag-up) nil))
5524 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5525 (org-cmp-todo-state a b)))
5526 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5527 (habit-up (and (org-em 'habit-up 'habit-down ss)
5528 (org-cmp-habit-p a b)))
5529 (habit-down (if habit-up (- habit-up) nil))
5530 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5531 (org-cmp-alpha a b)))
5532 (alpha-down (if alpha-up (- alpha-up) nil))
5533 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5534 user-defined-up user-defined-down)
5535 (if (and need-user-cmp org-agenda-cmp-user-defined
5536 (functionp org-agenda-cmp-user-defined))
5537 (setq user-defined-up
5538 (funcall org-agenda-cmp-user-defined a b)
5539 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5541 (eval (cons 'or org-agenda-sorting-strategy-selected))
5542 '((-1 . t) (1 . nil) (nil . nil))))))
5544 ;;; Agenda restriction lock
5546 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5547 "Overlay to mark the headline to which agenda commands are restricted.")
5548 (overlay-put org-agenda-restriction-lock-overlay
5549 'face 'org-agenda-restriction-lock)
5550 (overlay-put org-agenda-restriction-lock-overlay
5551 'help-echo "Agendas are currently limited to this subtree.")
5552 (org-detach-overlay org-agenda-restriction-lock-overlay)
5554 (defun org-agenda-set-restriction-lock (&optional type)
5555 "Set restriction lock for agenda, to current subtree or file.
5556 Restriction will be the file if TYPE is `file', or if type is the
5557 universal prefix '(4), or if the cursor is before the first headline
5558 in the file. Otherwise, restriction will be to the current subtree."
5560 (and (equal type '(4)) (setq type 'file))
5563 ((org-at-heading-p) 'subtree)
5564 ((condition-case nil (org-back-to-heading t) (error nil))
5567 (if (eq type 'subtree)
5569 (setq org-agenda-restrict t)
5570 (setq org-agenda-overriding-restriction 'subtree)
5571 (put 'org-agenda-files 'org-restrict
5572 (list (buffer-file-name (buffer-base-buffer))))
5573 (org-back-to-heading t)
5574 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5575 (move-marker org-agenda-restrict-begin (point))
5576 (move-marker org-agenda-restrict-end
5577 (save-excursion (org-end-of-subtree t)))
5578 (message "Locking agenda restriction to subtree"))
5579 (put 'org-agenda-files 'org-restrict
5580 (list (buffer-file-name (buffer-base-buffer))))
5581 (setq org-agenda-restrict nil)
5582 (setq org-agenda-overriding-restriction 'file)
5583 (move-marker org-agenda-restrict-begin nil)
5584 (move-marker org-agenda-restrict-end nil)
5585 (message "Locking agenda restriction to file"))
5586 (setq current-prefix-arg nil)
5587 (org-agenda-maybe-redo))
5589 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5590 "Remove the agenda restriction lock."
5592 (org-detach-overlay org-agenda-restriction-lock-overlay)
5593 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5594 (setq org-agenda-overriding-restriction nil)
5595 (setq org-agenda-restrict nil)
5596 (put 'org-agenda-files 'org-restrict nil)
5597 (move-marker org-agenda-restrict-begin nil)
5598 (move-marker org-agenda-restrict-end nil)
5599 (setq current-prefix-arg nil)
5600 (message "Agenda restriction lock removed")
5601 (or noupdate (org-agenda-maybe-redo)))
5603 (defun org-agenda-maybe-redo ()
5604 "If there is any window showing the agenda view, update it."
5605 (let ((w (get-buffer-window org-agenda-buffer-name t))
5606 (w0 (selected-window)))
5611 (if org-agenda-overriding-restriction
5612 (message "Agenda view shifted to new %s restriction"
5613 org-agenda-overriding-restriction)
5614 (message "Agenda restriction lock removed")))))
5618 (defun org-agenda-check-type (error &rest types)
5619 "Check if agenda buffer is of allowed type.
5620 If ERROR is non-nil, throw an error, otherwise just return nil."
5621 (if (memq org-agenda-type types)
5624 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5627 (defun org-agenda-quit ()
5628 "Exit agenda by removing the window or the buffer."
5630 (if org-agenda-columns-active
5632 (let ((buf (current-buffer)))
5633 (if (eq org-agenda-window-setup 'other-frame)
5636 (org-agenda-reset-markers)
5637 (org-columns-remove-overlays)
5638 (setq org-agenda-archives-mode nil)
5640 (and (not (eq org-agenda-window-setup 'current-window))
5641 (not (one-window-p))
5644 (org-agenda-reset-markers)
5645 (org-columns-remove-overlays)
5646 (setq org-agenda-archives-mode nil)))
5647 ;; Maybe restore the pre-agenda window configuration.
5648 (and org-agenda-restore-windows-after-quit
5649 (not (eq org-agenda-window-setup 'other-frame))
5650 org-pre-agenda-window-conf
5651 (set-window-configuration org-pre-agenda-window-conf))))
5653 (defun org-agenda-exit ()
5654 "Exit agenda by removing the window or the buffer.
5655 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5656 Org-mode buffers visited directly by the user will not be touched."
5658 (org-release-buffers org-agenda-new-buffers)
5659 (setq org-agenda-new-buffers nil)
5662 (defun org-agenda-execute (arg)
5663 "Execute another agenda command, keeping same window.
5664 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
5667 (let ((org-agenda-window-setup 'current-window))
5670 (defun org-agenda-redo ()
5672 When this is the global TODO list, a prefix argument will be interpreted."
5674 (let* ((org-agenda-keep-modes t)
5675 (filter org-agenda-filter)
5676 (preset (get 'org-agenda-filter :preset-filter))
5677 (org-agenda-filter-while-redo (or filter preset))
5678 (cols org-agenda-columns-active)
5679 (line (org-current-line))
5680 (window-line (- line (org-current-line (window-start))))
5681 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5682 (put 'org-agenda-filter :preset-filter nil)
5683 (and cols (org-columns-quit))
5684 (message "Rebuilding agenda buffer...")
5685 (org-let lprops '(eval org-agenda-redo-command))
5686 (setq org-agenda-undo-list nil
5687 org-agenda-pending-undo-list nil)
5688 (message "Rebuilding agenda buffer...done")
5689 (put 'org-agenda-filter :preset-filter preset)
5690 (and (or filter preset) (org-agenda-filter-apply filter))
5691 (and cols (interactive-p) (org-agenda-columns))
5692 (org-goto-line line)
5693 (recenter window-line)))
5696 (defvar org-global-tags-completion-table nil)
5697 (defvar org-agenda-filter-form nil)
5698 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5699 "Keep only those lines in the agenda buffer that have a specific tag.
5700 The tag is selected with its fast selection letter, as configured.
5701 With prefix argument STRIP, remove all lines that do have the tag.
5702 A lisp caller can specify CHAR. NARROW means that the new tag should be
5703 used to narrow the search - the interactive user can also press `-' or `+'
5704 to switch to narrowing."
5706 (let* ((alist org-tag-alist-for-agenda)
5707 (tag-chars (mapconcat
5708 (lambda (x) (if (and (not (symbolp (car x)))
5710 (char-to-string (cdr x))
5713 (efforts (org-split-string
5714 (or (cdr (assoc (concat org-effort-property "_ALL")
5715 org-global-properties))
5716 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5717 (effort-op org-agenda-filter-effort-default-operator)
5719 (inhibit-read-only t)
5720 (current org-agenda-filter)
5724 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5725 (if narrow "Narrow" "Filter") tag-chars
5726 (if org-agenda-auto-exclude-function "[RET], " ""))
5727 (setq char (read-char)))
5728 (when (member char '(?+ ?-))
5730 (cond ((equal char ?-) (setq strip t narrow t))
5731 ((equal char ?+) (setq strip nil narrow t)))
5733 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5734 (setq char (read-char)))
5735 (when (member char '(?< ?> ?= ??))
5736 ;; An effort operator
5737 (setq effort-op (char-to-string char))
5738 (setq alist nil) ; to make sure it will be interpreted as effort.
5739 (unless (equal char ??)
5740 (loop for i from 0 to 9 do
5744 (if (= i 9) "0" (int-to-string (1+ i)))
5745 "]" (nth i efforts))))
5746 (message "Effort%s: %s " effort-op effort-prompt)
5747 (setq char (read-char))
5748 (when (or (< char ?0) (> char ?9))
5749 (error "Need 1-9,0 to select effort" ))))
5750 (when (equal char ?\t)
5751 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5752 (org-set-local 'org-global-tags-completion-table
5753 (org-global-tags-completion-table)))
5754 (let ((completion-ignore-case t))
5755 (setq tag (org-icompleting-read
5756 "Tag: " org-global-tags-completion-table))))
5759 (org-agenda-filter-by-tag-show-all)
5760 (when org-agenda-auto-exclude-function
5761 (setq org-agenda-filter '())
5762 (dolist (tag (org-agenda-get-represented-tags))
5763 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5765 (push modifier org-agenda-filter))))
5766 (if (not (null org-agenda-filter))
5767 (org-agenda-filter-apply org-agenda-filter))))
5769 (org-agenda-filter-by-tag-show-all)
5770 (when (get 'org-agenda-filter :preset-filter)
5771 (org-agenda-filter-apply org-agenda-filter)))
5772 ((or (equal char ?\ )
5773 (setq a (rassoc char alist))
5774 (and (>= char ?0) (<= char ?9)
5775 (setq n (if (= char ?0) 9 (- char ?0 1))
5776 tag (concat effort-op (nth n efforts))
5781 (and tag (setq a (cons tag nil))))
5782 (org-agenda-filter-by-tag-show-all)
5784 (setq org-agenda-filter
5785 (cons (concat (if strip "-" "+") tag)
5786 (if narrow current nil)))
5787 (org-agenda-filter-apply org-agenda-filter))
5788 (t (error "Invalid tag selection character %c" char)))))
5790 (defun org-agenda-get-represented-tags ()
5791 "Get a list of all tags currently represented in the agenda."
5794 (goto-char (point-min))
5795 (while (setq p (next-single-property-change (point) 'tags))
5797 (mapc (lambda (x) (add-to-list 'tags x))
5798 (get-text-property (point) 'tags))))
5801 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5802 "Refine the current filter. See `org-agenda-filter-by-tag."
5804 (org-agenda-filter-by-tag strip char 'refine))
5806 (defun org-agenda-filter-make-matcher ()
5807 "Create the form that tests a line for the agenda filter."
5809 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5811 (if (member x '("-" "+"))
5812 (setq f1 (if (equal x "-") 'tags '(not tags)))
5813 (if (string-match "[<=>?]" x)
5814 (setq f1 (org-agenda-filter-effort-form x))
5815 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5816 (if (equal (string-to-char x) ?-)
5817 (setq f1 (list 'not f1))))
5819 (cons 'and (nreverse f))))
5821 (defun org-agenda-filter-effort-form (e)
5822 "Return the form to compare the effort of the current line with what E says.
5823 E looks like \"+<2:25\"."
5825 (setq e (substring e 1))
5826 (setq op (string-to-char e) e (substring e 1))
5827 (setq op (cond ((equal op ?<) '<=)
5831 (list 'org-agenda-compare-effort (list 'quote op)
5832 (org-hh:mm-string-to-minutes e))))
5834 (defun org-agenda-compare-effort (op value)
5835 "Compare the effort of the current line with VALUE, using OP.
5836 If the line does not have an effort defined, return nil."
5837 (let ((eff (org-get-at-bol 'effort-minutes)))
5840 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5843 (defun org-agenda-filter-apply (filter)
5844 "Set FILTER as the new agenda filter and apply it."
5846 (setq org-agenda-filter filter
5847 org-agenda-filter-form (org-agenda-filter-make-matcher))
5848 (org-agenda-set-mode-name)
5850 (goto-char (point-min))
5852 (if (org-get-at-bol 'org-marker)
5854 (setq tags (org-get-at-bol 'tags)) ; used in eval
5855 (if (not (eval org-agenda-filter-form))
5856 (org-agenda-filter-by-tag-hide-line))
5857 (beginning-of-line 2))
5858 (beginning-of-line 2))))
5859 (if (get-char-property (point) 'invisible)
5860 (org-agenda-previous-line))))
5862 (defun org-agenda-filter-by-tag-hide-line ()
5864 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
5866 (overlay-put ov 'invisible t)
5867 (overlay-put ov 'type 'tags-filter)
5868 (push ov org-agenda-filter-overlays)))
5870 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5871 (setq pos (or pos (point)))
5873 (dolist (ov (overlays-at pos))
5874 (when (and (overlay-get ov 'invisible)
5875 (eq (overlay-get ov 'type) 'tags-filter))
5877 (if (< (overlay-start ov) (point-at-eol))
5878 (move-overlay ov (point-at-eol)
5879 (overlay-end ov)))))))
5881 (defun org-agenda-filter-by-tag-show-all ()
5882 (mapc 'delete-overlay org-agenda-filter-overlays)
5883 (setq org-agenda-filter-overlays nil)
5884 (setq org-agenda-filter nil)
5885 (setq org-agenda-filter-form nil)
5886 (org-agenda-set-mode-name))
5888 (defun org-agenda-manipulate-query-add ()
5889 "Manipulate the query by adding a search term with positive selection.
5890 Positive selection means the term must be matched for selection of an entry."
5892 (org-agenda-manipulate-query ?\[))
5893 (defun org-agenda-manipulate-query-subtract ()
5894 "Manipulate the query by adding a search term with negative selection.
5895 Negative selection means term must not be matched for selection of an entry."
5897 (org-agenda-manipulate-query ?\]))
5898 (defun org-agenda-manipulate-query-add-re ()
5899 "Manipulate the query by adding a search regexp with positive selection.
5900 Positive selection means the regexp must match for selection of an entry."
5902 (org-agenda-manipulate-query ?\{))
5903 (defun org-agenda-manipulate-query-subtract-re ()
5904 "Manipulate the query by adding a search regexp with negative selection.
5905 Negative selection means regexp must not match for selection of an entry."
5907 (org-agenda-manipulate-query ?\}))
5908 (defun org-agenda-manipulate-query (char)
5910 ((memq org-agenda-type '(timeline agenda))
5911 (let ((org-agenda-include-inactive-timestamps t))
5913 (message "Display now includes inactive timestamps as well"))
5914 ((eq org-agenda-type 'search)
5916 'org-agenda-query-string
5917 (if org-agenda-last-search-view-search-was-boolean
5918 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5919 (?\{ . " +{}") (?\} . " -{}"))))
5921 (setq org-agenda-redo-command
5922 (list 'org-search-view
5924 org-agenda-query-string
5925 (+ (length org-agenda-query-string)
5926 (if (member char '(?\{ ?\})) 0 1))))
5927 (set-register org-agenda-query-register org-agenda-query-string)
5929 (t (error "Cannot manipulate query for %s-type agenda buffers"
5932 (defun org-add-to-string (var string)
5933 (set var (concat (symbol-value var) string)))
5935 (defun org-agenda-goto-date (date)
5936 "Jump to DATE in agenda."
5937 (interactive (list (let ((org-read-date-prefer-future
5938 (eval org-agenda-jump-prefer-future)))
5940 (org-agenda-list nil date))
5942 (defun org-agenda-goto-today ()
5945 (org-agenda-check-type t 'timeline 'agenda)
5946 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5948 (tdpos (goto-char tdpos))
5949 ((eq org-agenda-type 'agenda)
5950 (let* ((sd (org-agenda-today))
5951 (comp (org-agenda-compute-time-span sd org-agenda-span))
5952 (org-agenda-overriding-arguments org-agenda-last-arguments))
5953 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5954 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5956 (org-agenda-find-same-or-today-or-agenda)))
5957 (t (error "Cannot find today")))))
5959 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5961 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5962 (text-property-any (point-min) (point-max) 'org-today t)
5963 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5966 (defun org-agenda-later (arg)
5967 "Go forward in time by thee current span.
5968 With prefix ARG, go forward that many times the current span."
5970 (org-agenda-check-type t 'agenda)
5971 (let* ((span org-agenda-span)
5972 (sd org-starting-day)
5973 (greg (calendar-gregorian-from-absolute sd))
5974 (cnt (org-get-at-bol 'org-day-cnt))
5978 (setq sd (+ arg sd) nd 1))
5980 (setq sd (+ (* 7 arg) sd) nd 7))
5982 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5983 sd (calendar-absolute-from-gregorian greg2))
5984 (setcar greg2 (1+ (car greg2)))
5985 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5987 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5988 sd (calendar-absolute-from-gregorian greg2))
5989 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5990 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5991 (let ((org-agenda-overriding-arguments
5992 (list (car org-agenda-last-arguments) sd nd t)))
5994 (org-agenda-find-same-or-today-or-agenda cnt))))
5996 (defun org-agenda-earlier (arg)
5997 "Go backward in time by the current span.
5998 With prefix ARG, go backward that many times the current span."
6000 (org-agenda-later (- arg)))
6002 (defun org-agenda-view-mode-dispatch ()
6003 "Call one of the view mode commands."
6005 (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
6006 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
6007 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
6008 (let ((a (read-char-exclusive)))
6010 (?d (call-interactively 'org-agenda-day-view))
6011 (?w (call-interactively 'org-agenda-week-view))
6012 (?m (call-interactively 'org-agenda-month-view))
6013 (?y (call-interactively 'org-agenda-year-view))
6014 (?l (call-interactively 'org-agenda-log-mode))
6015 (?L (org-agenda-log-mode '(4)))
6016 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6017 (?a (call-interactively 'org-agenda-archives-mode))
6018 (?A (org-agenda-archives-mode 'files))
6019 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6020 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6021 (?G (call-interactively 'org-agenda-toggle-time-grid))
6022 (?D (call-interactively 'org-agenda-toggle-diary))
6023 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6024 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6025 (org-agenda-check-type t 'timeline 'agenda)
6027 (message "Display now includes inactive timestamps as well"))
6028 (?q (message "Abort"))
6029 (otherwise (error "Invalid key" )))))
6031 (defun org-agenda-day-view (&optional day-of-year)
6032 "Switch to daily view for agenda.
6033 With argument DAY-OF-YEAR, switch to that day of the year."
6035 (setq org-agenda-ndays 1)
6036 (org-agenda-change-time-span 'day day-of-year))
6037 (defun org-agenda-week-view (&optional iso-week)
6038 "Switch to daily view for agenda.
6039 With argument ISO-WEEK, switch to the corresponding ISO week.
6040 If ISO-WEEK has more then 2 digits, only the last two encode the
6041 week. Any digits before this encode a year. So 200712 means
6042 week 12 of year 2007. Years in the range 1938-2037 can also be
6043 written as 2-digit years."
6045 (setq org-agenda-ndays 7)
6046 (org-agenda-change-time-span 'week iso-week))
6047 (defun org-agenda-month-view (&optional month)
6048 "Switch to monthly view for agenda.
6049 With argument MONTH, switch to that month."
6051 (org-agenda-change-time-span 'month month))
6052 (defun org-agenda-year-view (&optional year)
6053 "Switch to yearly view for agenda.
6054 With argument YEAR, switch to that year.
6055 If MONTH has more then 2 digits, only the last two encode the
6056 month. Any digits before this encode a year. So 200712 means
6057 December year 2007. Years in the range 1938-2037 can also be
6058 written as 2-digit years."
6061 (setq year (org-small-year-to-year year)))
6062 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6063 (org-agenda-change-time-span 'year year)
6066 (defun org-agenda-change-time-span (span &optional n)
6067 "Change the agenda view to SPAN.
6068 SPAN may be `day', `week', `month', `year'."
6069 (org-agenda-check-type t 'agenda)
6070 (if (and (not n) (equal org-agenda-span span))
6071 (error "Viewing span is already \"%s\"" span))
6072 (let* ((sd (or (org-get-at-bol 'day)
6074 (computed (org-agenda-compute-time-span sd span n))
6075 (org-agenda-overriding-arguments
6076 (list (car org-agenda-last-arguments)
6077 (car computed) (cdr computed) t)))
6079 (org-agenda-find-same-or-today-or-agenda))
6080 (org-agenda-set-mode-name)
6081 (message "Switched to %s view" span))
6083 (defun org-agenda-compute-time-span (sd span &optional n)
6084 "Compute starting date and number of days for agenda.
6085 SPAN may be `day', `week', `month', `year'. The return value
6086 is a cons cell with the starting date and the number of days,
6087 so that the date SD will be in that range."
6088 (let* ((greg (calendar-gregorian-from-absolute sd))
6092 nd w1 y1 m1 thisweek)
6096 (setq sd (+ (calendar-absolute-from-gregorian
6101 (let* ((nt (calendar-day-of-week
6102 (calendar-gregorian-from-absolute sd)))
6103 (d (if org-agenda-start-on-weekday
6104 (- nt org-agenda-start-on-weekday)
6106 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6109 (setq thisweek (car (calendar-iso-from-absolute sd)))
6111 (setq y1 (org-small-year-to-year (/ n 100))
6114 (calendar-absolute-from-iso
6116 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
6119 (when (and n (> n 99))
6120 (setq y1 (org-small-year-to-year (/ n 100))
6122 (setq sd (calendar-absolute-from-gregorian
6123 (list (or n mg) 1 (or y1 yg)))
6124 nd (- (calendar-absolute-from-gregorian
6125 (list (1+ (or n mg)) 1 (or y1 yg)))
6128 (setq sd (calendar-absolute-from-gregorian
6129 (list 1 1 (or n yg)))
6130 nd (- (calendar-absolute-from-gregorian
6131 (list 1 1 (1+ (or n yg))))
6135 (defun org-agenda-next-date-line (&optional arg)
6136 "Jump to the next line indicating a date in agenda buffer."
6138 (org-agenda-check-type t 'agenda 'timeline)
6139 (beginning-of-line 1)
6140 ;; This does not work if user makes date format that starts with a blank
6141 (if (looking-at "^\\S-") (forward-char 1))
6142 (if (not (re-search-forward "^\\S-" nil t arg))
6145 (error "No next date after this line in this buffer")))
6146 (goto-char (match-beginning 0)))
6148 (defun org-agenda-previous-date-line (&optional arg)
6149 "Jump to the previous line indicating a date in agenda buffer."
6151 (org-agenda-check-type t 'agenda 'timeline)
6152 (beginning-of-line 1)
6153 (if (not (re-search-backward "^\\S-" nil t arg))
6154 (error "No previous date before this line in this buffer")))
6156 ;; Initialize the highlight
6157 (defvar org-hl (make-overlay 1 1))
6158 (overlay-put org-hl 'face 'highlight)
6160 (defun org-highlight (begin end &optional buffer)
6161 "Highlight a region with overlay."
6162 (move-overlay org-hl begin end (or buffer (current-buffer))))
6164 (defun org-unhighlight ()
6165 "Detach overlay INDEX."
6166 (org-detach-overlay org-hl))
6168 ;; FIXME this is currently not used.
6169 (defun org-highlight-until-next-command (beg end &optional buffer)
6170 "Move the highlight overlay to BEG/END, remove it before the next command."
6171 (org-highlight beg end buffer)
6172 (add-hook 'pre-command-hook 'org-unhighlight-once))
6173 (defun org-unhighlight-once ()
6174 "Remove the highlight from its position, and this function from the hook."
6175 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6178 (defun org-agenda-follow-mode ()
6179 "Toggle follow mode in an agenda buffer."
6181 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6182 (org-agenda-set-mode-name)
6183 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6185 (message "Follow mode is %s"
6186 (if org-agenda-follow-mode "on" "off")))
6188 (defun org-agenda-entry-text-mode (&optional arg)
6189 "Toggle entry text mode in an agenda buffer."
6191 (setq org-agenda-entry-text-mode (or (integerp arg)
6192 (not org-agenda-entry-text-mode)))
6193 (org-agenda-entry-text-hide)
6194 (and org-agenda-entry-text-mode
6195 (let ((org-agenda-entry-text-maxlines
6196 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6197 (org-agenda-entry-text-show)))
6198 (org-agenda-set-mode-name)
6199 (message "Entry text mode is %s. Maximum number of lines is %d"
6200 (if org-agenda-entry-text-mode "on" "off")
6201 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6203 (defun org-agenda-clockreport-mode (&optional with-filter)
6204 "Toggle clocktable mode in an agenda buffer.
6205 With prefix arg WITH-FILTER, make the clocktable respect the current
6208 (org-agenda-check-type t 'agenda)
6210 (setq org-agenda-clockreport-mode 'with-filter)
6211 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6212 (org-agenda-set-mode-name)
6214 (message "Clocktable mode is %s"
6215 (if org-agenda-clockreport-mode "on" "off")))
6217 (defun org-agenda-log-mode (&optional special)
6218 "Toggle log mode in an agenda buffer.
6219 With argument SPECIAL, show all possible log items, not only the ones
6220 configured in `org-agenda-log-mode-items'.
6221 With a double `C-u' prefix arg, show *only* log items, nothing else."
6223 (org-agenda-check-type t 'agenda 'timeline)
6224 (setq org-agenda-show-log
6225 (if (equal special '(16))
6227 (if special '(closed clock state)
6228 (not org-agenda-show-log))))
6229 (org-agenda-set-mode-name)
6231 (message "Log mode is %s"
6232 (if org-agenda-show-log "on" "off")))
6234 (defun org-agenda-archives-mode (&optional with-files)
6235 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6236 When called with a prefix argument, include all archive files as well."
6238 (setq org-agenda-archives-mode
6239 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6240 (org-agenda-set-mode-name)
6245 ((eq org-agenda-archives-mode nil)
6246 "No archives are included")
6247 ((eq org-agenda-archives-mode 'trees)
6248 (format "Trees with :%s: tag are included" org-archive-tag))
6249 ((eq org-agenda-archives-mode t)
6250 (format "Trees with :%s: tag and all active archive files are included"
6251 org-archive-tag)))))
6253 (defun org-agenda-toggle-diary ()
6254 "Toggle diary inclusion in an agenda buffer."
6256 (org-agenda-check-type t 'agenda)
6257 (setq org-agenda-include-diary (not org-agenda-include-diary))
6259 (org-agenda-set-mode-name)
6260 (message "Diary inclusion turned %s"
6261 (if org-agenda-include-diary "on" "off")))
6263 (defun org-agenda-toggle-deadlines ()
6264 "Toggle diary inclusion in an agenda buffer."
6266 (org-agenda-check-type t 'agenda)
6267 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6269 (org-agenda-set-mode-name)
6270 (message "Deadlines inclusion turned %s"
6271 (if org-agenda-include-deadlines "on" "off")))
6273 (defun org-agenda-toggle-time-grid ()
6274 "Toggle time grid in an agenda buffer."
6276 (org-agenda-check-type t 'agenda)
6277 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6279 (org-agenda-set-mode-name)
6280 (message "Time-grid turned %s"
6281 (if org-agenda-use-time-grid "on" "off")))
6283 (defun org-agenda-set-mode-name ()
6284 "Set the mode name to indicate all the small mode settings."
6286 (concat "Org-Agenda"
6287 (if (get 'org-agenda-files 'org-restrict) " []" "")
6288 (if (equal org-agenda-ndays 1) " Day" "")
6289 (if (equal org-agenda-ndays 7) " Week" "")
6290 (if org-agenda-follow-mode " Follow" "")
6291 (if org-agenda-entry-text-mode " ETxt" "")
6292 (if org-agenda-include-diary " Diary" "")
6293 (if org-agenda-include-deadlines " Ddl" "")
6294 (if org-agenda-use-time-grid " Grid" "")
6295 (if (and (boundp 'org-habit-show-habits)
6296 org-habit-show-habits) " Habit" "")
6297 (if (consp org-agenda-show-log) " LogAll"
6298 (if org-agenda-show-log " Log" ""))
6299 (if (or org-agenda-filter (get 'org-agenda-filter
6301 (concat " {" (mapconcat
6303 (append (get 'org-agenda-filter
6305 org-agenda-filter) "") "}")
6307 (if org-agenda-archives-mode
6308 (if (eq org-agenda-archives-mode t)
6310 (format " :%s:" org-archive-tag))
6312 (if org-agenda-clockreport-mode
6313 (if (eq org-agenda-clockreport-mode 'with-filter)
6314 " Clock{}" " Clock")
6316 (force-mode-line-update))
6318 (defun org-agenda-post-command-hook ()
6319 (setq org-agenda-type
6320 (or (get-text-property (point) 'org-agenda-type)
6321 (get-text-property (max (point-min) (1- (point)))
6322 'org-agenda-type))))
6324 (defun org-agenda-next-line ()
6325 "Move cursor to the next line, and show if follow mode is active."
6327 (call-interactively 'next-line)
6328 (org-agenda-do-context-action))
6330 (defun org-agenda-previous-line ()
6331 "Move cursor to the previous line, and show if follow-mode is active."
6334 (call-interactively 'previous-line)
6335 (org-agenda-do-context-action))
6337 (defun org-agenda-do-context-action ()
6338 "Show outline path and, maybe, follow mode window."
6339 (let ((m (org-get-at-bol 'org-marker)))
6340 (if (and org-agenda-follow-mode m)
6342 (if (and m org-agenda-show-outline-path)
6343 (org-with-point-at m
6344 (org-display-outline-path t)))))
6346 (defun org-agenda-show-priority ()
6347 "Show the priority of the current item.
6348 This priority is composed of the main priority given with the [#A] cookies,
6349 and by additional input from the age of a schedules or deadline entry."
6351 (let* ((pri (org-get-at-bol 'priority)))
6352 (message "Priority is %d" (if pri pri -1000))))
6354 (defun org-agenda-show-tags ()
6355 "Show the tags applicable to the current item."
6357 (let* ((tags (org-get-at-bol 'tags)))
6359 (message "Tags are :%s:"
6360 (org-no-properties (mapconcat 'identity tags ":")))
6361 (message "No tags associated with this line"))))
6363 (defun org-agenda-goto (&optional highlight)
6364 "Go to the Org-mode file which contains the item at point."
6366 (let* ((marker (or (org-get-at-bol 'org-marker)
6367 (org-agenda-error)))
6368 (buffer (marker-buffer marker))
6369 (pos (marker-position marker)))
6370 (switch-to-buffer-other-window buffer)
6375 (org-show-context 'agenda)
6377 (and (outline-next-heading)
6378 (org-flag-heading nil)))) ; show the next heading
6379 (recenter (/ (window-height) 2))
6380 (run-hooks 'org-agenda-after-show-hook)
6381 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6383 (defvar org-agenda-after-show-hook nil
6384 "Normal hook run after an item has been shown from the agenda.
6385 Point is in the buffer where the item originated.")
6387 (defun org-agenda-kill ()
6388 "Kill the entry or subtree belonging to the current agenda entry."
6390 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6391 (let* ((marker (or (org-get-at-bol 'org-marker)
6392 (org-agenda-error)))
6393 (buffer (marker-buffer marker))
6394 (pos (marker-position marker))
6395 (type (org-get-at-bol 'type))
6396 dbeg dend (n 0) conf)
6397 (org-with-remote-undo buffer
6398 (with-current-buffer buffer
6401 (if (and (org-mode-p) (not (member type '("sexp"))))
6402 (setq dbeg (progn (org-back-to-heading t) (point))
6403 dend (org-end-of-subtree t t))
6404 (setq dbeg (point-at-bol)
6405 dend (min (point-max) (1+ (point-at-eol)))))
6407 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6408 (setq conf (or (eq t org-agenda-confirm-kill)
6409 (and (numberp org-agenda-confirm-kill)
6410 (> n org-agenda-confirm-kill))))
6413 (format "Delete entry with %d lines in buffer \"%s\"? "
6414 n (buffer-name buffer))))
6416 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6417 (with-current-buffer buffer (delete-region dbeg dend))
6418 (message "Agenda item and source killed"))))
6420 (defvar org-archive-default-command)
6421 (defun org-agenda-archive-default ()
6422 "Archive the entry or subtree belonging to the current agenda entry."
6424 (require 'org-archive)
6425 (org-agenda-archive-with org-archive-default-command))
6427 (defun org-agenda-archive-default-with-confirmation ()
6428 "Archive the entry or subtree belonging to the current agenda entry."
6430 (require 'org-archive)
6431 (org-agenda-archive-with org-archive-default-command 'confirm))
6433 (defun org-agenda-archive ()
6434 "Archive the entry or subtree belonging to the current agenda entry."
6436 (org-agenda-archive-with 'org-archive-subtree))
6438 (defun org-agenda-archive-to-archive-sibling ()
6439 "Move the entry to the archive sibling."
6441 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6443 (defun org-agenda-archive-with (cmd &optional confirm)
6444 "Move the entry to the archive sibling."
6446 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6447 (let* ((marker (or (org-get-at-bol 'org-marker)
6448 (org-agenda-error)))
6449 (buffer (marker-buffer marker))
6450 (pos (marker-position marker)))
6451 (org-with-remote-undo buffer
6452 (with-current-buffer buffer
6455 (not (y-or-n-p "Archive this subtree or entry? ")))
6459 (org-remove-subtree-entries-from-agenda)
6460 (org-back-to-heading t)
6462 (error "Archiving works only in Org-mode files"))))))
6464 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6465 "Remove all lines in the agenda that correspond to a given subtree.
6466 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6467 If this information is not given, the function uses the tree at point."
6468 (let ((buf (or buf (current-buffer))) m p)
6470 (unless (and beg end)
6471 (org-back-to-heading t)
6473 (org-end-of-subtree t)
6475 (set-buffer (get-buffer org-agenda-buffer-name))
6477 (goto-char (point-max))
6478 (beginning-of-line 1)
6480 (when (and (setq m (org-get-at-bol 'org-marker))
6481 (equal buf (marker-buffer m))
6482 (setq p (marker-position m))
6485 (let ((inhibit-read-only t))
6486 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6487 (beginning-of-line 0))))))
6489 (defun org-agenda-refile (&optional goto rfloc no-update)
6490 "Refile the item at point."
6492 (if (equal goto '(16))
6493 (org-refile-goto-last-stored)
6494 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6495 (org-agenda-error)))
6496 (buffer (marker-buffer marker))
6497 (pos (marker-position marker))
6499 (org-refile-get-location
6500 (if goto "Goto: " "Refile to: ") buffer
6501 org-refile-allow-creating-parent-nodes))))
6502 (with-current-buffer buffer
6507 (org-remove-subtree-entries-from-agenda)
6508 (org-refile goto buffer rfloc)))))
6509 (unless no-update (org-agenda-redo))))
6511 (defun org-agenda-open-link (&optional arg)
6512 "Follow the link in the current line, if any.
6513 This looks for a link in the displayed line in the agenda. It also looks
6514 at the text of the entry itself."
6516 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6517 (org-get-at-bol 'org-marker)))
6518 (buffer (and marker (marker-buffer marker)))
6519 (prefix (buffer-substring
6522 (or (org-get-at-bol 'prefix-length) 0)))))
6525 (with-current-buffer buffer
6530 (org-offer-links-in-entry arg prefix)))))
6531 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6533 (beginning-of-line 1)
6534 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6535 (org-open-link-from-string (match-string 1)))
6536 (t (error "No link to open here")))))
6538 (defun org-agenda-copy-local-variable (var)
6539 "Get a variable from a referenced buffer and install it here."
6540 (let ((m (org-get-at-bol 'org-marker)))
6541 (when (and m (buffer-live-p (marker-buffer m)))
6542 (org-set-local var (with-current-buffer (marker-buffer m)
6543 (symbol-value var))))))
6545 (defun org-agenda-switch-to (&optional delete-other-windows)
6546 "Go to the Org-mode file which contains the item at point."
6548 (if (and org-return-follows-link
6549 (not (org-get-at-bol 'org-marker))
6550 (org-in-regexp org-bracket-link-regexp))
6551 (org-open-link-from-string (match-string 0))
6552 (let* ((marker (or (org-get-at-bol 'org-marker)
6553 (org-agenda-error)))
6554 (buffer (marker-buffer marker))
6555 (pos (marker-position marker)))
6556 (switch-to-buffer buffer)
6557 (and delete-other-windows (delete-other-windows))
6561 (org-show-context 'agenda)
6563 (and (outline-next-heading)
6564 (org-flag-heading nil))))))) ; show the next heading
6566 (defun org-agenda-goto-mouse (ev)
6567 "Go to the Org-mode file which contains the item at the mouse click."
6569 (mouse-set-point ev)
6572 (defun org-agenda-show (&optional full-entry)
6573 "Display the Org-mode file which contains the item at point.
6574 With prefix argument FULL-ENTRY, make the entire entry visible
6575 if it was hidden in the outline."
6577 (let ((win (selected-window)))
6579 (let ((org-show-entry-below t))
6580 (org-agenda-goto t))
6581 (org-agenda-goto t))
6582 (select-window win)))
6584 (defvar org-agenda-show-window nil)
6585 (defun org-agenda-show-and-scroll-up ()
6586 "Display the Org-mode file which contains the item at point.
6587 When called repeatedly, scroll the window that is displaying the buffer."
6589 (let ((win (selected-window)))
6590 (if (and (window-live-p org-agenda-show-window)
6591 (eq this-command last-command))
6593 (select-window org-agenda-show-window)
6594 (ignore-errors (scroll-up)))
6597 (setq org-agenda-show-window (selected-window)))
6598 (select-window win)))
6600 (defun org-agenda-show-scroll-down ()
6601 "Scroll down the window showing the agenda."
6603 (let ((win (selected-window)))
6604 (when (window-live-p org-agenda-show-window)
6605 (select-window org-agenda-show-window)
6606 (ignore-errors (scroll-down))
6607 (select-window win))))
6609 (defun org-agenda-show-1 (&optional more)
6610 "Display the Org-mode file which contains the item at point.
6611 The prefix arg selects the amount of information to display:
6614 1 just show the entry according to defaults.
6615 2 show the children view
6616 3 show the subtree view
6617 4 show the entire subtree and any LOGBOOK drawers
6618 5 show the entire subtree and any drawers
6619 With prefix argument FULL-ENTRY, make the entire entry visible
6620 if it was hidden in the outline."
6622 (let ((win (selected-window)))
6624 (org-recenter-heading 1)
6629 (org-back-to-heading)
6630 (run-hook-with-args 'org-cycle-hook 'folded))
6631 (message "Remote: FOLDED"))
6632 ((and (interactive-p) (= more 1))
6633 (message "Remote: show with default settings"))
6638 (org-back-to-heading)
6639 (run-hook-with-args 'org-cycle-hook 'children))
6640 (message "Remote: CHILDREN"))
6644 (org-back-to-heading)
6645 (run-hook-with-args 'org-cycle-hook 'subtree))
6646 (message "Remote: SUBTREE"))
6648 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6650 (concat "^[ \t]*:\\("
6651 (mapconcat 'regexp-quote org-drawers "\\|")
6655 (org-back-to-heading)
6656 (org-cycle-hide-drawers 'subtree)))
6657 (message "Remote: SUBTREE AND LOGBOOK"))
6660 (message "Remote: SUBTREE AND ALL DRAWERS")))
6661 (select-window win)))
6663 (defun org-recenter-heading (n)
6665 (org-back-to-heading)
6668 (defvar org-agenda-cycle-counter nil)
6669 (defun org-agenda-cycle-show (&optional n)
6670 "Show the current entry in another window, with default settings.
6671 Default settings are taken from `org-show-hierarchy-above' and siblings.
6672 When use repeatedly in immediate succession, the remote entry will cycle
6675 children -> subtree -> folded
6677 When called with a numeric prefix arg, that arg will be passed through to
6678 `org-agenda-show-1'. For the interpretation of that argument, see the
6679 docstring of `org-agenda-show-1'."
6682 (setq org-agenda-cycle-counter n)
6683 (if (not (eq last-command this-command))
6684 (setq org-agenda-cycle-counter 1)
6685 (if (equal org-agenda-cycle-counter 0)
6686 (setq org-agenda-cycle-counter 2)
6687 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6688 (if (> org-agenda-cycle-counter 3)
6689 (setq org-agenda-cycle-counter 0)))))
6690 (org-agenda-show-1 org-agenda-cycle-counter))
6692 (defun org-agenda-recenter (arg)
6693 "Display the Org-mode file which contains the item at point and recenter."
6695 (let ((win (selected-window)))
6698 (select-window win)))
6700 (defun org-agenda-show-mouse (ev)
6701 "Display the Org-mode file which contains the item at the mouse click."
6703 (mouse-set-point ev)
6706 (defun org-agenda-check-no-diary ()
6707 "Check if the entry is a diary link and abort if yes."
6708 (if (org-get-at-bol 'org-agenda-diary-link)
6709 (org-agenda-error)))
6711 (defun org-agenda-error ()
6712 (error "Command not allowed in this line"))
6714 (defun org-agenda-tree-to-indirect-buffer ()
6715 "Show the subtree corresponding to the current entry in an indirect buffer.
6716 This calls the command `org-tree-to-indirect-buffer' from the original
6718 With numerical prefix arg ARG, go up to this level and then take that tree.
6719 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
6720 use the dedicated frame)."
6722 (org-agenda-check-no-diary)
6723 (let* ((marker (or (org-get-at-bol 'org-marker)
6724 (org-agenda-error)))
6725 (buffer (marker-buffer marker))
6726 (pos (marker-position marker)))
6727 (with-current-buffer buffer
6730 (call-interactively 'org-tree-to-indirect-buffer)))))
6732 (defvar org-last-heading-marker (make-marker)
6733 "Marker pointing to the headline that last changed its TODO state
6734 by a remote command from the agenda.")
6736 (defun org-agenda-todo-nextset ()
6737 "Switch TODO entry to next sequence."
6739 (org-agenda-todo 'nextset))
6741 (defun org-agenda-todo-previousset ()
6742 "Switch TODO entry to previous sequence."
6744 (org-agenda-todo 'previousset))
6746 (defun org-agenda-todo (&optional arg)
6747 "Cycle TODO state of line at point, also in Org-mode file.
6748 This changes the line at point, all other lines in the agenda referring to
6749 the same tree node, and the headline of the tree node in the Org-mode file."
6751 (org-agenda-check-no-diary)
6752 (let* ((col (current-column))
6753 (marker (or (org-get-at-bol 'org-marker)
6754 (org-agenda-error)))
6755 (buffer (marker-buffer marker))
6756 (pos (marker-position marker))
6757 (hdmarker (org-get-at-bol 'org-hd-marker))
6758 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
6759 (inhibit-read-only t)
6760 org-agenda-headline-snapshot-before-repeat newhead just-one)
6761 (org-with-remote-undo buffer
6762 (with-current-buffer buffer
6765 (org-show-context 'agenda)
6767 (and (outline-next-heading)
6768 (org-flag-heading nil))) ; show the next heading
6769 (let ((current-prefix-arg arg))
6770 (call-interactively 'org-todo))
6771 (and (bolp) (forward-char 1))
6772 (setq newhead (org-get-heading))
6773 (when (and (org-bound-and-true-p
6774 org-agenda-headline-snapshot-before-repeat)
6775 (not (equal org-agenda-headline-snapshot-before-repeat
6778 (setq newhead org-agenda-headline-snapshot-before-repeat
6781 (org-back-to-heading)
6782 (move-marker org-last-heading-marker (point))))
6783 (beginning-of-line 1)
6785 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6786 (org-move-to-column col))))
6788 (defun org-agenda-add-note (&optional arg)
6789 "Add a time-stamped note to the entry at point."
6791 (org-agenda-check-no-diary)
6792 (let* ((marker (or (org-get-at-bol 'org-marker)
6793 (org-agenda-error)))
6794 (buffer (marker-buffer marker))
6795 (pos (marker-position marker))
6796 (hdmarker (org-get-at-bol 'org-hd-marker))
6797 (inhibit-read-only t))
6798 (with-current-buffer buffer
6801 (org-show-context 'agenda)
6803 (and (outline-next-heading)
6804 (org-flag-heading nil))) ; show the next heading
6807 (defun org-agenda-change-all-lines (newhead hdmarker
6808 &optional fixface just-this)
6809 "Change all lines in the agenda buffer which match HDMARKER.
6810 The new content of the line will be NEWHEAD (as modified by
6811 `org-format-agenda-item'). HDMARKER is checked with
6812 `equal' against all `org-hd-marker' text properties in the file.
6813 If FIXFACE is non-nil, the face of each item is modified according to
6815 If JUST-THIS is non-nil, change just the current line, not all.
6816 If FORCE-TAGS is non nil, the car of it returns the new tags."
6817 (let* ((inhibit-read-only t)
6818 (line (org-current-line))
6819 (thetags (with-current-buffer (marker-buffer hdmarker)
6820 (save-excursion (save-restriction (widen)
6821 (goto-char hdmarker)
6822 (org-get-tags-at)))))
6823 props m pl undone-face done-face finish new dotime cat tags)
6825 (goto-char (point-max))
6826 (beginning-of-line 1)
6828 (setq finish (bobp))
6829 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6830 (or (not just-this) (= (org-current-line) line))
6832 (setq props (text-properties-at (point))
6833 dotime (org-get-at-bol 'dotime)
6834 cat (org-get-at-bol 'org-category)
6836 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6837 pl (org-get-at-bol 'prefix-length)
6838 undone-face (org-get-at-bol 'undone-face)
6839 done-face (org-get-at-bol 'done-face))
6840 (goto-char (+ (point) pl))
6841 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6844 (beginning-of-line 1)
6845 (and (looking-at ".*\n?") (replace-match "")))
6847 (replace-match new t t)
6848 (beginning-of-line 1)
6849 (add-text-properties (point-at-bol) (point-at-eol) props)
6851 (add-text-properties
6852 (point-at-bol) (point-at-eol)
6854 (if org-last-todo-state-is-todo
6855 undone-face done-face))))
6856 (org-agenda-highlight-todo 'line)
6857 (beginning-of-line 1))
6858 (t (error "Line update did not work"))))
6859 (beginning-of-line 0)))
6860 (org-finalize-agenda)))
6862 (defun org-agenda-align-tags (&optional line)
6863 "Align all tags in agenda items to `org-agenda-tags-column'."
6864 (let ((inhibit-read-only t) l c)
6866 (goto-char (if line (point-at-bol) (point-min)))
6867 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6868 (if line (point-at-eol) nil) t)
6869 (add-text-properties
6870 (match-beginning 2) (match-end 2)
6871 (list 'face (delq nil (let ((prop (get-text-property
6872 (match-beginning 2) 'face)))
6873 (or (listp prop) (setq prop (list prop)))
6874 (if (memq 'org-tag prop)
6876 (cons 'org-tag prop))))))
6877 (setq l (- (match-end 2) (match-beginning 2))
6878 c (if (< org-agenda-tags-column 0)
6879 (- (abs org-agenda-tags-column) l)
6880 org-agenda-tags-column))
6881 (delete-region (match-beginning 1) (match-end 1))
6882 (goto-char (match-beginning 1))
6883 (insert (org-add-props
6884 (make-string (max 1 (- c (current-column))) ?\ )
6885 (plist-put (copy-sequence (text-properties-at (point)))
6887 (goto-char (point-min))
6888 (org-font-lock-add-tag-faces (point-max)))))
6890 (defun org-agenda-priority-up ()
6891 "Increase the priority of line at point, also in Org-mode file."
6893 (org-agenda-priority 'up))
6895 (defun org-agenda-priority-down ()
6896 "Decrease the priority of line at point, also in Org-mode file."
6898 (org-agenda-priority 'down))
6900 (defun org-agenda-priority (&optional force-direction)
6901 "Set the priority of line at point, also in Org-mode file.
6902 This changes the line at point, all other lines in the agenda referring to
6903 the same tree node, and the headline of the tree node in the Org-mode file."
6905 (unless org-enable-priority-commands
6906 (error "Priority commands are disabled"))
6907 (org-agenda-check-no-diary)
6908 (let* ((marker (or (org-get-at-bol 'org-marker)
6909 (org-agenda-error)))
6910 (hdmarker (org-get-at-bol 'org-hd-marker))
6911 (buffer (marker-buffer hdmarker))
6912 (pos (marker-position hdmarker))
6913 (inhibit-read-only t)
6915 (org-with-remote-undo buffer
6916 (with-current-buffer buffer
6919 (org-show-context 'agenda)
6921 (and (outline-next-heading)
6922 (org-flag-heading nil))) ; show the next heading
6923 (funcall 'org-priority force-direction)
6925 (setq newhead (org-get-heading)))
6926 (org-agenda-change-all-lines newhead hdmarker)
6927 (beginning-of-line 1))))
6929 ;; FIXME: should fix the tags property of the agenda line.
6930 (defun org-agenda-set-tags (&optional tag onoff)
6931 "Set tags for the current headline."
6933 (org-agenda-check-no-diary)
6934 (if (and (org-region-active-p) (interactive-p))
6935 (call-interactively 'org-change-tag-in-region)
6936 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6937 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6938 (org-agenda-error)))
6939 (buffer (marker-buffer hdmarker))
6940 (pos (marker-position hdmarker))
6941 (inhibit-read-only t)
6943 (org-with-remote-undo buffer
6944 (with-current-buffer buffer
6948 (org-show-context 'agenda))
6950 (and (outline-next-heading)
6951 (org-flag-heading nil))) ; show the next heading
6954 (org-toggle-tag tag onoff)
6955 (call-interactively 'org-set-tags))
6957 (setq newhead (org-get-heading)))
6958 (org-agenda-change-all-lines newhead hdmarker)
6959 (beginning-of-line 1)))))
6961 (defun org-agenda-set-property ()
6962 "Set a property for the current headline."
6964 (org-agenda-check-no-diary)
6965 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6966 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6967 (org-agenda-error)))
6968 (buffer (marker-buffer hdmarker))
6969 (pos (marker-position hdmarker))
6970 (inhibit-read-only t)
6972 (org-with-remote-undo buffer
6973 (with-current-buffer buffer
6977 (org-show-context 'agenda))
6979 (and (outline-next-heading)
6980 (org-flag-heading nil))) ; show the next heading
6982 (call-interactively 'org-set-property)))))
6984 (defun org-agenda-set-effort ()
6985 "Set the effort property for the current headline."
6987 (org-agenda-check-no-diary)
6988 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6989 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6990 (org-agenda-error)))
6991 (buffer (marker-buffer hdmarker))
6992 (pos (marker-position hdmarker))
6993 (inhibit-read-only t)
6995 (org-with-remote-undo buffer
6996 (with-current-buffer buffer
7000 (org-show-context 'agenda))
7002 (and (outline-next-heading)
7003 (org-flag-heading nil))) ; show the next heading
7005 (call-interactively 'org-set-effort)
7008 (defun org-agenda-toggle-archive-tag ()
7009 "Toggle the archive tag for the current entry."
7011 (org-agenda-check-no-diary)
7012 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7013 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7014 (org-agenda-error)))
7015 (buffer (marker-buffer hdmarker))
7016 (pos (marker-position hdmarker))
7017 (inhibit-read-only t)
7019 (org-with-remote-undo buffer
7020 (with-current-buffer buffer
7023 (org-show-context 'agenda)
7025 (and (outline-next-heading)
7026 (org-flag-heading nil))) ; show the next heading
7027 (call-interactively 'org-toggle-archive-tag)
7029 (setq newhead (org-get-heading)))
7030 (org-agenda-change-all-lines newhead hdmarker)
7031 (beginning-of-line 1))))
7033 (defun org-agenda-do-date-later (arg)
7036 ((or (equal arg '(16))
7038 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7039 (setq this-command 'org-agenda-date-later-minutes)
7040 (org-agenda-date-later-minutes 1))
7041 ((or (equal arg '(4))
7043 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7044 (setq this-command 'org-agenda-date-later-hours)
7045 (org-agenda-date-later-hours 1))
7047 (org-agenda-date-later (prefix-numeric-value arg)))))
7049 (defun org-agenda-do-date-earlier (arg)
7052 ((or (equal arg '(16))
7054 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7055 (setq this-command 'org-agenda-date-earlier-minutes)
7056 (org-agenda-date-earlier-minutes 1))
7057 ((or (equal arg '(4))
7059 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7060 (setq this-command 'org-agenda-date-earlier-hours)
7061 (org-agenda-date-earlier-hours 1))
7063 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7065 (defun org-agenda-date-later (arg &optional what)
7066 "Change the date of this item to one day later."
7068 (org-agenda-check-type t 'agenda 'timeline)
7069 (org-agenda-check-no-diary)
7070 (let* ((marker (or (org-get-at-bol 'org-marker)
7071 (org-agenda-error)))
7072 (buffer (marker-buffer marker))
7073 (pos (marker-position marker)))
7074 (org-with-remote-undo buffer
7075 (with-current-buffer buffer
7078 (if (not (org-at-timestamp-p))
7079 (error "Cannot find time stamp"))
7080 (org-timestamp-change arg (or what 'day)))
7081 (org-agenda-show-new-time marker org-last-changed-timestamp))
7082 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7084 (defun org-agenda-date-earlier (arg &optional what)
7085 "Change the date of this item to one day earlier."
7087 (org-agenda-date-later (- arg) what))
7089 (defun org-agenda-date-later-minutes (arg)
7090 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7092 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7093 (org-agenda-date-later arg 'minute))
7095 (defun org-agenda-date-earlier-minutes (arg)
7096 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7098 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7099 (org-agenda-date-earlier arg 'minute))
7101 (defun org-agenda-date-later-hours (arg)
7102 "Change the time of this item, in hour steps."
7104 (org-agenda-date-later arg 'hour))
7106 (defun org-agenda-date-earlier-hours (arg)
7107 "Change the time of this item, in hour steps."
7109 (org-agenda-date-earlier arg 'hour))
7111 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7112 "Show new date stamp via text properties."
7113 ;; We use text properties to make this undoable
7114 (let ((inhibit-read-only t)
7115 (buffer-invisibility-spec))
7116 (setq stamp (concat " " prefix " => " stamp))
7118 (goto-char (point-max))
7120 (when (equal marker (org-get-at-bol 'org-marker))
7121 (org-move-to-column (- (window-width) (length stamp)) t)
7122 (org-agenda-fix-tags-filter-overlays-at (point))
7123 (if (featurep 'xemacs)
7124 ;; Use `duplicable' property to trigger undo recording
7125 (let ((ex (make-extent nil nil))
7126 (gl (make-glyph stamp)))
7127 (set-glyph-face gl 'secondary-selection)
7128 (set-extent-properties
7129 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7130 (insert-extent ex (1- (point)) (point-at-eol)))
7131 (add-text-properties
7132 (1- (point)) (point-at-eol)
7133 (list 'display (org-add-props stamp nil
7134 'face 'secondary-selection))))
7135 (beginning-of-line 1))
7136 (beginning-of-line 0)))))
7138 (defun org-agenda-date-prompt (arg)
7139 "Change the date of this item. Date is prompted for, with default today.
7140 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7141 be used to request time specification in the time stamp."
7143 (org-agenda-check-type t 'agenda 'timeline)
7144 (org-agenda-check-no-diary)
7145 (let* ((marker (or (org-get-at-bol 'org-marker)
7146 (org-agenda-error)))
7147 (buffer (marker-buffer marker))
7148 (pos (marker-position marker)))
7149 (org-with-remote-undo buffer
7150 (with-current-buffer buffer
7153 (if (not (org-at-timestamp-p t))
7154 (error "Cannot find time stamp"))
7155 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7156 (org-agenda-show-new-time marker org-last-changed-timestamp))
7157 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7159 (defun org-agenda-schedule (arg)
7160 "Schedule the item at point.
7161 Arg is passed through to `org-schedule'."
7163 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7164 (org-agenda-check-no-diary)
7165 (let* ((marker (or (org-get-at-bol 'org-marker)
7166 (org-agenda-error)))
7167 (type (marker-insertion-type marker))
7168 (buffer (marker-buffer marker))
7169 (pos (marker-position marker))
7170 (org-insert-labeled-timestamps-at-point nil)
7172 (set-marker-insertion-type marker t)
7173 (org-with-remote-undo buffer
7174 (with-current-buffer buffer
7177 (setq ts (org-schedule arg)))
7178 (org-agenda-show-new-time marker ts "S"))
7179 (message "Item scheduled for %s" ts)))
7181 (defun org-agenda-deadline (arg)
7182 "Schedule the item at point.
7183 Arg is passed through to `org-deadline'."
7185 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7186 (org-agenda-check-no-diary)
7187 (let* ((marker (or (org-get-at-bol 'org-marker)
7188 (org-agenda-error)))
7189 (buffer (marker-buffer marker))
7190 (pos (marker-position marker))
7191 (org-insert-labeled-timestamps-at-point nil)
7193 (org-with-remote-undo buffer
7194 (with-current-buffer buffer
7197 (setq ts (org-deadline arg)))
7198 (org-agenda-show-new-time marker ts "D"))
7199 (message "Deadline for this item set to %s" ts)))
7201 (defun org-agenda-action ()
7202 "Select entry for agenda action, or execute an agenda action.
7203 This command prompts for another letter. Valid inputs are:
7205 m Mark the entry at point for an agenda action
7206 s Schedule the marked entry to the date at the cursor
7207 d Set the deadline of the marked entry to the date at the cursor
7208 r Call `org-remember' with cursor date as the default date
7209 c Call `org-capture' with cursor date as the default date
7210 SPC Show marked entry in other window
7211 TAB Visit marked entry in other window
7213 The cursor may be at a date in the calendar, or in the Org agenda."
7216 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7217 (setq ans (read-char-exclusive))
7221 (if (eq major-mode 'org-agenda-mode)
7222 (let ((m (or (org-get-at-bol 'org-hd-marker)
7223 (org-get-at-bol 'org-marker))))
7226 (move-marker org-agenda-action-marker
7227 (marker-position m) (marker-buffer m))
7228 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7229 (error "Don't know which entry to mark")))
7230 (error "This command works only in the agenda")))
7232 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7234 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7236 (org-agenda-do-action '(org-remember) t))
7238 (org-agenda-do-action '(org-capture) t))
7240 (let ((cw (selected-window)))
7241 (org-switch-to-buffer-other-window
7242 (marker-buffer org-agenda-action-marker))
7243 (goto-char org-agenda-action-marker)
7244 (org-show-context 'agenda)
7245 (select-window cw)))
7247 (org-switch-to-buffer-other-window
7248 (marker-buffer org-agenda-action-marker))
7249 (goto-char org-agenda-action-marker)
7250 (org-show-context 'agenda))
7251 (t (error "Invalid agenda action %c" ans)))))
7253 (defun org-agenda-do-action (form &optional current-buffer)
7254 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7255 (let ((org-overriding-default-time (org-get-cursor-date)))
7258 (if (not (marker-buffer org-agenda-action-marker))
7259 (error "No entry has been selected for agenda action")
7260 (with-current-buffer (marker-buffer org-agenda-action-marker)
7264 (goto-char org-agenda-action-marker)
7267 (defun org-agenda-clock-in (&optional arg)
7268 "Start the clock on the currently selected item."
7270 (org-agenda-check-no-diary)
7271 (if (equal arg '(4))
7273 (let* ((marker (or (org-get-at-bol 'org-marker)
7274 (org-agenda-error)))
7275 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7277 (pos (marker-position marker))
7279 (org-with-remote-undo (marker-buffer marker)
7280 (with-current-buffer (marker-buffer marker)
7283 (org-show-context 'agenda)
7285 (org-cycle-hide-drawers 'children)
7287 (setq newhead (org-get-heading)))
7288 (org-agenda-change-all-lines newhead hdmarker)))))
7290 (defun org-agenda-clock-out ()
7291 "Stop the currently running clock."
7293 (unless (marker-buffer org-clock-marker)
7294 (error "No running clock"))
7295 (let ((marker (make-marker)) newhead)
7296 (org-with-remote-undo (marker-buffer org-clock-marker)
7297 (with-current-buffer (marker-buffer org-clock-marker)
7301 (goto-char org-clock-marker)
7302 (org-back-to-heading t)
7303 (move-marker marker (point))
7305 (setq newhead (org-get-heading))))))
7306 (org-agenda-change-all-lines newhead marker)
7307 (move-marker marker nil)))
7309 (defun org-agenda-clock-cancel (&optional arg)
7310 "Cancel the currently running clock."
7312 (unless (marker-buffer org-clock-marker)
7313 (error "No running clock"))
7314 (org-with-remote-undo (marker-buffer org-clock-marker)
7315 (org-clock-cancel)))
7317 (defun org-agenda-clock-goto ()
7318 "Jump to the currently clocked in task within the agenda.
7319 If the currently clocked in task is not listed in the agenda
7320 buffer, display it in another window."
7324 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7325 (setq pos (overlay-start o))))
7326 (overlays-in (point-min) (point-max)))
7327 (cond (pos (goto-char pos))
7328 ;; If the currently clocked entry is not in the agenda
7329 ;; buffer, we visit it in another window:
7330 (org-clock-current-task
7331 (org-switch-to-buffer-other-window (org-clock-goto)))
7332 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7334 (defun org-agenda-diary-entry-in-org-file ()
7335 "Make a diary entry in the file `org-agenda-diary-file'."
7336 (let (d1 d2 char (text "") dp1 dp2)
7337 (if (equal (buffer-name) "*Calendar*")
7338 (setq d1 (calendar-cursor-to-date t)
7339 d2 (car calendar-mark-ring))
7340 (setq dp1 (get-text-property (point-at-bol) 'day))
7341 (unless dp1 (error "No date defined in current line"))
7342 (setq d1 (calendar-gregorian-from-absolute dp1)
7343 d2 (and (ignore-errors (mark))
7346 (setq dp2 (get-text-property (point-at-bol) 'day)))
7347 (calendar-gregorian-from-absolute dp2))))
7348 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7349 (setq char (read-char-exclusive))
7352 (setq text (read-string "Day entry: "))
7353 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7354 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7356 (setq d1 (list (car d1) (nth 1 d1)
7357 (read-number (format "Reference year [%d]: " (nth 2 d1))
7359 (setq text (read-string "Anniversary (use %d to show years): "))
7360 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7361 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7363 (setq text (read-string "Block entry: "))
7364 (unless (and d1 d2 (not (equal d1 d2)))
7365 (error "No block of days selected"))
7366 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7367 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7369 (org-switch-to-buffer-other-window
7370 (find-file-noselect org-agenda-diary-file))
7371 (require 'org-datetree)
7372 (org-datetree-find-date-create d1)
7374 (t (error "Invalid selection character `%c'" char)))))
7376 (defcustom org-agenda-insert-diary-strategy 'date-tree
7377 "Where in `org-agenda-diary-file' should new entries be added?
7380 date-tree in the date tree, as child of the date
7381 top-level as top-level entries at the end of the file."
7384 (const :tag "in a date tree" date-tree)
7385 (const :tag "as top level at end of file" top-level)))
7387 (defcustom org-agenda-insert-diary-extract-time nil
7388 "Non-nil means extract any time specification from the diary entry."
7392 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7393 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7394 If TEXT is not empty, it will become the headline of the new entry, and
7395 the resulting entry will not be shown. When TEXT is empty, switch to
7396 `org-agenda-diary-file' and let the user finish the entry there."
7397 (let ((cw (current-window-configuration)))
7398 (org-switch-to-buffer-other-window
7399 (find-file-noselect org-agenda-diary-file))
7401 (goto-char (point-min))
7403 ((eq type 'anniversary)
7404 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7406 (or (org-on-heading-p t)
7408 (outline-next-heading)
7409 (insert "* Anniversaries\n\n")
7410 (beginning-of-line -1)))))
7411 (outline-next-heading)
7412 (org-back-over-empty-lines)
7415 (require 'diary-lib)
7416 (let ((calendar-date-display-form
7417 (if (if (boundp 'calendar-date-style)
7418 (eq calendar-date-style 'european)
7419 (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
7420 (org-bound-and-true-p european-calendar-style))) ; Emacs 22
7421 '(day " " month " " year)
7422 '(month " " day " " year))))
7424 (insert (format "%%%%(diary-anniversary %s) %s"
7425 (calendar-date-string d1 nil t) text))))
7427 (let ((org-prefix-has-time t)
7428 (org-agenda-time-leading-zero t)
7430 (if org-agenda-insert-diary-extract-time
7431 ;; Use org-format-agenda-item to parse text for a time-range and
7432 ;; remove it. FIXME: This is a hack, we should refactor
7433 ;; that function to make time extraction available separately
7434 (setq fmt (org-format-agenda-item nil text nil nil t)
7435 time (get-text-property 0 'time fmt)
7436 time2 (if (> (length time) 0)
7437 ;; split-string removes trailing ...... if
7438 ;; no end time given. First space
7439 ;; separates time from date.
7440 (concat " " (car (split-string time "\\.")))
7442 text (get-text-property 0 'txt fmt)))
7443 (if (eq org-agenda-insert-diary-strategy 'top-level)
7444 (org-agenda-insert-diary-as-top-level text)
7445 (require 'org-datetree)
7446 (org-datetree-find-date-create d1)
7447 (org-agenda-insert-diary-make-new-entry text))
7448 (org-insert-time-stamp (org-time-from-absolute
7449 (calendar-absolute-from-gregorian d1))
7450 nil nil nil nil time2))
7453 (if (> (calendar-absolute-from-gregorian d1)
7454 (calendar-absolute-from-gregorian d2))
7455 (setq d1 (prog1 d2 (setq d2 d1))))
7456 (if (eq org-agenda-insert-diary-strategy 'top-level)
7457 (org-agenda-insert-diary-as-top-level text)
7458 (require 'org-datetree)
7459 (org-datetree-find-date-create d1)
7460 (org-agenda-insert-diary-make-new-entry text))
7461 (org-insert-time-stamp (org-time-from-absolute
7462 (calendar-absolute-from-gregorian d1)))
7464 (org-insert-time-stamp (org-time-from-absolute
7465 (calendar-absolute-from-gregorian d2)))
7467 (if (string-match "\\S-" text)
7469 (set-window-configuration cw)
7470 (message "%s entry added to %s"
7471 (capitalize (symbol-name type))
7472 (abbreviate-file-name org-agenda-diary-file)))
7474 (message "Please finish entry here"))))
7476 (defun org-agenda-insert-diary-as-top-level (text)
7477 "Make new entry as a top-level entry at the end of the file.
7478 Add TEXT as headline, and position the cursor in the second line so that
7479 a timestamp can be added there."
7481 (goto-char (point-max))
7482 (or (bolp) (insert "\n"))
7483 (insert "* " text "\n")
7484 (if org-adapt-indentation (org-indent-to-column 2)))
7486 (defun org-agenda-insert-diary-make-new-entry (text)
7487 "Make new entry as last child of current entry.
7488 Add TEXT as headline, and position the cursor in the second line so that
7489 a timestamp can be added there."
7490 (let ((org-show-following-heading t)
7491 (org-show-siblings t)
7492 (org-show-hierarchy-above t)
7493 (org-show-entry-below t)
7495 (outline-next-heading)
7496 (org-back-over-empty-lines)
7497 (or (looking-at "[ \t]*$")
7498 (progn (insert "\n") (backward-char 1)))
7499 (org-insert-heading nil t)
7501 (setq col (current-column))
7503 (if org-adapt-indentation (org-indent-to-column col))
7504 (let ((org-show-following-heading t)
7505 (org-show-siblings t)
7506 (org-show-hierarchy-above t)
7507 (org-show-entry-below t))
7508 (org-show-context))))
7510 (defun org-agenda-diary-entry ()
7511 "Make a diary entry, like the `i' command from the calendar.
7512 All the standard commands work: block, weekly etc.
7513 When `org-agenda-diary-file' points to a file,
7514 `org-agenda-diary-entry-in-org-file' is called instead to create
7515 entries in that Org-mode file."
7517 (org-agenda-check-type t 'agenda 'timeline)
7518 (if (not (eq org-agenda-diary-file 'diary-file))
7519 (org-agenda-diary-entry-in-org-file)
7520 (require 'diary-lib)
7522 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7523 (read-char-exclusive)))
7524 (cmd (cdr (assoc char
7525 '((?d . insert-diary-entry)
7526 (?w . insert-weekly-diary-entry)
7527 (?m . insert-monthly-diary-entry)
7528 (?y . insert-yearly-diary-entry)
7529 (?a . insert-anniversary-diary-entry)
7530 (?b . insert-block-diary-entry)
7531 (?c . insert-cyclic-diary-entry)))))
7532 (oldf (symbol-function 'calendar-cursor-to-date))
7533 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7535 (mark (or (mark t) (point))))
7537 (error "No command associated with <%c>" char))
7538 (unless (and (get-text-property point 'day)
7539 (or (not (equal ?b char))
7540 (get-text-property mark 'day)))
7541 (error "Don't know which date to use for diary entry"))
7542 ;; We implement this by hacking the `calendar-cursor-to-date' function
7543 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7544 (let ((calendar-mark-ring
7545 (list (calendar-gregorian-from-absolute
7546 (or (get-text-property mark 'day)
7547 (get-text-property point 'day))))))
7550 (fset 'calendar-cursor-to-date
7551 (lambda (&optional error dummy)
7552 (calendar-gregorian-from-absolute
7553 (get-text-property point 'day))))
7554 (call-interactively cmd))
7555 (fset 'calendar-cursor-to-date oldf))))))
7557 (defun org-agenda-execute-calendar-command (cmd)
7558 "Execute a calendar command from the agenda, with the date associated to
7559 the cursor position."
7560 (org-agenda-check-type t 'agenda 'timeline)
7561 (require 'diary-lib)
7562 (unless (get-text-property (point) 'day)
7563 (error "Don't know which date to use for calendar command"))
7564 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7566 (date (calendar-gregorian-from-absolute
7567 (get-text-property point 'day)))
7568 ;; the following 2 vars are needed in the calendar
7569 (displayed-month (car date))
7570 (displayed-year (nth 2 date)))
7573 (fset 'calendar-cursor-to-date
7574 (lambda (&optional error dummy)
7575 (calendar-gregorian-from-absolute
7576 (get-text-property point 'day))))
7577 (call-interactively cmd))
7578 (fset 'calendar-cursor-to-date oldf))))
7580 (defun org-agenda-phases-of-moon ()
7581 "Display the phases of the moon for the 3 months around the cursor date."
7583 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7585 (defun org-agenda-holidays ()
7586 "Display the holidays for the 3 months around the cursor date."
7588 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7590 (defvar calendar-longitude)
7591 (defvar calendar-latitude)
7592 (defvar calendar-location-name)
7594 (defun org-agenda-sunrise-sunset (arg)
7595 "Display sunrise and sunset for the cursor date.
7596 Latitude and longitude can be specified with the variables
7597 `calendar-latitude' and `calendar-longitude'. When called with prefix
7598 argument, latitude and longitude will be prompted for."
7601 (let ((calendar-longitude (if arg nil calendar-longitude))
7602 (calendar-latitude (if arg nil calendar-latitude))
7603 (calendar-location-name
7604 (if arg "the given coordinates" calendar-location-name)))
7605 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7607 (defun org-agenda-goto-calendar ()
7608 "Open the Emacs calendar with the date at the cursor."
7610 (org-agenda-check-type t 'agenda 'timeline)
7611 (let* ((day (or (get-text-property (point) 'day)
7612 (error "Don't know which date to open in calendar")))
7613 (date (calendar-gregorian-from-absolute day))
7614 (calendar-move-hook nil)
7615 (calendar-view-holidays-initially-flag nil)
7616 (calendar-view-diary-initially-flag nil))
7618 (calendar-goto-date date)))
7621 (defun org-calendar-goto-agenda ()
7622 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7623 This is a command that has to be installed in `calendar-mode-map'."
7625 (org-agenda-list nil (calendar-absolute-from-gregorian
7626 (calendar-cursor-to-date))
7629 (defun org-agenda-convert-date ()
7631 (org-agenda-check-type t 'agenda 'timeline)
7632 (let ((day (get-text-property (point) 'day))
7635 (error "Don't know which date to convert"))
7636 (setq date (calendar-gregorian-from-absolute day))
7638 "Gregorian: " (calendar-date-string date) "\n"
7639 "ISO: " (calendar-iso-date-string date) "\n"
7640 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7641 "Julian: " (calendar-julian-date-string date) "\n"
7642 "Astron. JD: " (calendar-astro-date-string date)
7643 " (Julian date number at noon UTC)\n"
7644 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7645 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7646 "French: " (calendar-french-date-string date) "\n"
7647 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7648 "Mayan: " (calendar-mayan-date-string date) "\n"
7649 "Coptic: " (calendar-coptic-date-string date) "\n"
7650 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7651 "Persian: " (calendar-persian-date-string date) "\n"
7652 "Chinese: " (calendar-chinese-date-string date) "\n"))
7653 (with-output-to-temp-buffer "*Dates*"
7655 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7659 (defvar org-agenda-bulk-marked-entries nil
7660 "List of markers that refer to marked entries in the agenda.")
7662 (defun org-agenda-bulk-marked-p ()
7663 (eq (get-char-property (point-at-bol) 'type)
7664 'org-marked-entry-overlay))
7666 (defun org-agenda-bulk-mark ()
7667 "Mark the entry at point for future bulk action."
7669 (org-agenda-check-no-diary)
7670 (let* ((m (org-get-at-bol 'org-hd-marker))
7672 (unless (org-agenda-bulk-marked-p)
7673 (unless m (error "Nothing to mark at point"))
7674 (push m org-agenda-bulk-marked-entries)
7675 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7676 (org-overlay-display ov "> "
7677 (org-get-todo-face "TODO")
7679 (overlay-put ov 'type 'org-marked-entry-overlay))
7680 (beginning-of-line 2)
7681 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7682 (beginning-of-line 2))
7683 (message "%d entries marked for bulk action"
7684 (length org-agenda-bulk-marked-entries))))
7686 (defun org-agenda-bulk-unmark ()
7687 "Unmark the entry at point for future bulk action."
7689 (when (org-agenda-bulk-marked-p)
7690 (org-agenda-bulk-remove-overlays
7691 (point-at-bol) (+ 2 (point-at-bol)))
7692 (setq org-agenda-bulk-marked-entries
7693 (delete (org-get-at-bol 'org-hd-marker)
7694 org-agenda-bulk-marked-entries)))
7695 (beginning-of-line 2)
7696 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7697 (beginning-of-line 2))
7698 (message "%d entries marked for bulk action"
7699 (length org-agenda-bulk-marked-entries)))
7701 (defun org-agenda-bulk-toggle ()
7702 "Toggle marking the entry at point for bulk action."
7704 (if (org-agenda-bulk-marked-p)
7705 (org-agenda-bulk-unmark)
7706 (org-agenda-bulk-mark)))
7708 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7709 "Remove the mark overlays between BEG and END in the agenda buffer.
7710 BEG and END default to the buffer limits.
7712 This only removes the overlays, it does not remove the markers
7713 from the list in `org-agenda-bulk-marked-entries'."
7716 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7717 (delete-overlay ov)))
7718 (overlays-in (or beg (point-min)) (or end (point-max)))))
7720 (defun org-agenda-bulk-remove-all-marks ()
7721 "Remove all marks in the agenda buffer.
7722 This will remove the markers, and the overlays."
7724 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7725 (setq org-agenda-bulk-marked-entries nil)
7726 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7728 (defun org-agenda-bulk-action (&optional arg)
7729 "Execute an remote-editing action on all marked entries.
7730 The prefix arg is passed through to the command if possible."
7732 (unless org-agenda-bulk-marked-entries
7733 (error "No entries are marked"))
7734 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
7735 (let* ((action (read-char-exclusive))
7736 (org-log-refile (if org-log-refile 'time nil))
7737 (entries (reverse org-agenda-bulk-marked-entries))
7739 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7742 (setq cmd '(org-agenda-archive)))
7745 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7747 ((member action '(?r ?w))
7748 (setq rfloc (org-refile-get-location
7750 (marker-buffer (car org-agenda-bulk-marked-entries))
7751 org-refile-allow-creating-parent-nodes))
7753 (setcar (nthcdr 3 rfloc)
7754 (move-marker (make-marker) (nth 3 rfloc)
7755 (or (get-file-buffer (nth 1 rfloc))
7756 (find-buffer-visiting (nth 1 rfloc))
7757 (error "This should not happen")))))
7759 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
7763 (setq state (org-icompleting-read
7765 (with-current-buffer (marker-buffer (car entries))
7766 (mapcar 'list org-todo-keywords-1))))
7767 (setq cmd `(let ((org-inhibit-blocking t)
7768 (org-inhibit-logging 'note))
7769 (org-agenda-todo ,state))))
7771 ((memq action '(?- ?+))
7772 (setq tag (org-icompleting-read
7773 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7774 (with-current-buffer (marker-buffer (car entries))
7777 (if (stringp (car x)) x)) org-tag-alist)))))
7778 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
7780 ((memq action '(?s ?d))
7781 (let* ((date (unless arg
7784 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
7785 (ans (if arg nil org-read-date-final-answer))
7786 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
7787 (setq cmd `(let* ((bound (fboundp 'read-string))
7788 (old (and bound (symbol-function 'read-string))))
7791 (fset 'read-string (lambda (&rest ignore) ,ans))
7794 (fset 'read-string old)
7795 (fmakunbound 'read-string)))))))
7796 (t (error "Invalid bulk action")))
7798 ;; Sort the markers, to make sure that parents are handled before children
7799 (setq entries (sort entries
7802 ((equal (marker-buffer a) (marker-buffer b))
7803 (< (marker-position a) (marker-position b)))
7805 (string< (buffer-name (marker-buffer a))
7806 (buffer-name (marker-buffer b))))))))
7808 ;; Now loop over all markers and apply cmd
7809 (while (setq e (pop entries))
7810 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
7812 (progn (message "Skipping removed entry at %s" e)
7813 (setq cntskip (1+ cntskip)))
7816 (setq org-agenda-bulk-marked-entries
7817 (delete e org-agenda-bulk-marked-entries))
7818 (setq cnt (1+ cnt))))
7819 (setq org-agenda-bulk-marked-entries nil)
7820 (org-agenda-bulk-remove-all-marks)
7821 (when redo-at-end (org-agenda-redo))
7822 (message "Acted on %d entries%s"
7826 (format ", skipped %d (disappeared before their turn)"
7831 (defun org-agenda-show-the-flagging-note ()
7832 "Display the flagging note in the other window.
7833 When called a second time in direct sequence, offer to remove the FLAGGING
7834 tag and (if present) the flagging note."
7836 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
7837 (win (selected-window))
7838 note heading newhead)
7840 (error "No linked entry at point"))
7841 (if (and (eq this-command last-command)
7842 (y-or-n-p "Unflag and remove any flagging note? "))
7844 (org-agenda-remove-flag hdmarker)
7845 (let ((win (get-buffer-window "*Flagging Note*")))
7846 (and win (delete-window win)))
7847 (message "Entry unflaged"))
7848 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
7850 (error "No flagging note"))
7852 (org-switch-to-buffer-other-window "*Flagging Note*")
7855 (goto-char (point-min))
7856 (while (re-search-forward "\\\\n" nil t)
7857 (replace-match "\n" t t))
7858 (goto-char (point-min))
7860 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
7862 (defun org-agenda-remove-flag (marker)
7863 "Remove the FLAGGED tag and any flagging note in the entry."
7865 (org-with-point-at marker
7866 (org-toggle-tag "FLAGGED" 'off)
7867 (org-entry-delete nil "THEFLAGGINGNOTE")
7868 (setq newhead (org-get-heading)))
7869 (org-agenda-change-all-lines newhead marker)
7870 (message "Entry unflaged")))
7872 (defun org-agenda-get-any-marker (&optional pos)
7873 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7874 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7876 ;;; Appointment reminders
7878 (defvar appt-time-msg-list)
7881 (defun org-agenda-to-appt (&optional refresh filter)
7882 "Activate appointments found in `org-agenda-files'.
7883 With a \\[universal-argument] prefix, refresh the list of
7886 If FILTER is t, interactively prompt the user for a regular
7887 expression, and filter out entries that don't match it.
7889 If FILTER is a string, use this string as a regular expression
7890 for filtering entries out.
7892 FILTER can also be an alist with the car of each cell being
7893 either 'headline or 'category. For example:
7895 '((headline \"IMPORTANT\")
7896 (category \"Work\"))
7898 will only add headlines containing IMPORTANT or headlines
7899 belonging to the \"Work\" category."
7901 (if refresh (setq appt-time-msg-list nil))
7903 (setq filter (read-from-minibuffer "Regexp filter: ")))
7904 (let* ((cnt 0) ; count added events
7905 (org-agenda-new-buffers nil)
7906 (org-deadline-warning-days 0)
7907 ;; Do not use `org-agenda-today' here because appt only takes
7908 ;; time and without date as argument, so it may pass wrong
7909 ;; information otherwise
7910 (today (org-date-to-gregorian
7911 (time-to-days (current-time))))
7912 (org-agenda-restrict nil)
7913 (files (org-agenda-files 'unrestricted)) entries file)
7914 ;; Get all entries which may contain an appt
7915 (org-prepare-agenda-buffers files)
7916 (while (setq file (pop files))
7919 (org-agenda-get-day-entries
7920 file today :timestamp :scheduled :deadline))))
7921 (setq entries (delq nil entries))
7922 ;; Map thru entries and find if we should filter them out
7925 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7926 (cat (get-text-property 1 'org-category x))
7927 (tod (get-text-property 1 'time-of-day x))
7928 (ok (or (null filter)
7929 (and (stringp filter) (string-match filter evt))
7932 (cadr (assoc 'category filter)) cat)
7934 (cadr (assoc 'headline filter)) evt))))))
7935 ;; FIXME: Shall we remove text-properties for the appt text?
7936 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7938 (setq tod (concat "00" (number-to-string tod))
7939 tod (when (string-match
7940 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7941 (concat (match-string 1 tod) ":"
7942 (match-string 2 tod))))
7944 (setq cnt (1+ cnt))))) entries)
7945 (org-release-buffers org-agenda-new-buffers)
7947 (message "No event to add")
7948 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7950 (defun org-agenda-today ()
7951 "Return today date, considering `org-extend-today-until'."
7953 (time-subtract (current-time)
7954 (list 0 (* 3600 org-extend-today-until) 0))))
7956 (defun org-agenda-todayp (date)
7957 "Does DATE mean today, when considering `org-extend-today-until'?"
7958 (let ((today (org-agenda-today))
7959 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
7963 (provide 'org-agenda)
7965 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7967 ;;; org-agenda.el ends here