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-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
66 (defvar org-habit-show-habits
)
67 (defvar org-habit-show-habits-only-for-today
)
69 ;; Defined somewhere in this file, but used before definition.
70 (defvar org-agenda-buffer-name
)
71 (defvar org-agenda-overriding-header
)
72 (defvar org-agenda-title-append nil
)
75 (defvar org-agenda-undo-list
)
76 (defvar org-agenda-pending-undo-list
)
77 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
79 (defcustom org-agenda-confirm-kill
1
80 "When set, remote killing from the agenda buffer needs confirmation.
81 When t, a confirmation is always needed. When a number N, confirmation is
82 only needed when the text to be killed contains more than N non-white lines."
85 (const :tag
"Never" nil
)
86 (const :tag
"Always" t
)
87 (integer :tag
"When more than N lines")))
89 (defcustom org-agenda-compact-blocks nil
90 "Non-nil means make the block agenda more compact.
91 This is done by leaving out unnecessary lines."
95 (defcustom org-agenda-block-separator ?
=
96 "The separator between blocks in the agenda.
97 If this is a string, it will be used as the separator, with a newline added.
98 If it is a character, it will be repeated to fill the window width."
104 (defgroup org-agenda-export nil
105 "Options concerning exporting agenda views in Org-mode."
106 :tag
"Org Agenda Export"
109 (defcustom org-agenda-with-colors t
110 "Non-nil means use colors in agenda views."
111 :group
'org-agenda-export
114 (defcustom org-agenda-exporter-settings nil
115 "Alist of variable/value pairs that should be active during agenda export.
116 This is a good place to set options for ps-print and for htmlize.
117 Note that the way this is implemented, the values will be evaluated
118 before assigned to the variables. So make sure to quote values you do
119 *not* want evaluated, for example
121 (setq org-agenda-exporter-settings
122 '((ps-print-color-p 'black-white)))"
123 :group
'org-agenda-export
127 (sexp :tag
"Value"))))
129 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
130 "Hook run in temporary buffer before writing it to an export file.
131 A useful function is `org-agenda-add-entry-text'."
132 :group
'org-agenda-export
134 :options
'(org-agenda-add-entry-text))
136 (defcustom org-agenda-add-entry-text-maxlines
0
137 "Maximum number of entry text lines to be added to agenda.
138 This is only relevant when `org-agenda-add-entry-text' is part of
139 `org-agenda-before-write-hook', which it is by default.
140 When this is 0, nothing will happen. When it is greater than 0, it
141 specifies the maximum number of lines that will be added for each entry
142 that is listed in the agenda view.
144 Note that this variable is not used during display, only when exporting
145 the agenda. For agenda display, see org-agenda-entry-text-mode and the
146 variable `org-agenda-entry-text-maxlines'."
150 (defcustom org-agenda-add-entry-text-descriptive-links t
151 "Non-nil means export org-links as descriptive links in agenda added text.
152 This variable applies to the text added to the agenda when
153 `org-agenda-add-entry-text-maxlines' is larger than 0.
154 When this variable nil, the URL will (also) be shown."
158 (defcustom org-agenda-export-html-style
""
159 "The style specification for exported HTML Agenda files.
160 If this variable contains a string, it will replace the default <style>
161 section as produced by `htmlize'.
162 Since there are different ways of setting style information, this variable
163 needs to contain the full HTML structure to provide a style, including the
164 surrounding HTML tags. The style specifications should include definitions
165 the fonts used by the agenda, here is an example:
167 <style type=\"text/css\">
168 p { font-weight: normal; color: gray; }
169 .org-agenda-structure {
184 .title { text-align: center; }
185 .todo, .deadline { color: red; }
186 .done { color: green; }
189 or, if you want to keep the style in a file,
191 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
193 As the value of this option simply gets inserted into the HTML <head> header,
194 you can \"misuse\" it to also add other text to the header. However,
195 <style>...</style> is required, if not present the variable will be ignored."
196 :group
'org-agenda-export
197 :group
'org-export-html
200 (defcustom org-agenda-persistent-filter nil
201 "When set, keep filters from one agenda view to the next."
205 (defgroup org-agenda-custom-commands nil
206 "Options concerning agenda views in Org-mode."
207 :tag
"Org Agenda Custom Commands"
210 (defconst org-sorting-choice
212 (const time-up
) (const time-down
)
213 (const category-keep
) (const category-up
) (const category-down
)
214 (const tag-down
) (const tag-up
)
215 (const priority-up
) (const priority-down
)
216 (const todo-state-up
) (const todo-state-down
)
217 (const effort-up
) (const effort-down
)
218 (const habit-up
) (const habit-down
)
219 (const alpha-up
) (const alpha-down
)
220 (const user-defined-up
) (const user-defined-down
))
223 (defconst org-agenda-custom-commands-local-options
224 `(repeat :tag
"Local settings for this command. Remember to quote values"
225 (choice :tag
"Setting"
226 (list :tag
"Heading for this block"
227 (const org-agenda-overriding-header
)
228 (string :tag
"Headline"))
229 (list :tag
"Files to be searched"
230 (const org-agenda-files
)
232 (const :format
"" quote
)
234 (list :tag
"Sorting strategy"
235 (const org-agenda-sorting-strategy
)
237 (const :format
"" quote
)
239 ,org-sorting-choice
)))
240 (list :tag
"Prefix format"
241 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
243 (list :tag
"Number of days in agenda"
244 (const org-agenda-ndays
)
246 (list :tag
"Fixed starting date"
247 (const org-agenda-start-day
)
248 (string :value
"2007-11-01"))
249 (list :tag
"Start on day of week"
250 (const org-agenda-start-on-weekday
)
252 (const :tag
"Today" nil
)
253 (integer :tag
"Weekday No.")))
254 (list :tag
"Include data from diary"
255 (const org-agenda-include-diary
)
257 (list :tag
"Deadline Warning days"
258 (const org-deadline-warning-days
)
260 (list :tag
"Tags filter preset"
261 (const org-agenda-filter-preset
)
263 (const :format
"" quote
)
265 (string :tag
"+tag or -tag"))))
266 (list :tag
"Set daily/weekly entry types"
267 (const org-agenda-entry-types
)
268 (set :greedy t
:value
(:deadline
:scheduled
:timestamp
:sexp
)
273 (list :tag
"Standard skipping condition"
274 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
275 (const org-agenda-skip-function
)
277 (const :format
"" quote
)
280 :tag
"Skipping range"
281 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
282 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
283 (repeat :inline t
:tag
"Conditions for skipping"
285 :tag
"Condition type"
286 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
287 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
288 (list :tag
"TODO state is" :inline t
291 (const :tag
"any not-done state" 'todo
)
292 (const :tag
"any done state" 'done
)
293 (const :tag
"any state" 'any
)
294 (list :tag
"Keyword list"
295 (const :format
"" quote
)
296 (repeat (string :tag
"Keyword")))))
297 (list :tag
"TODO state is not" :inline t
300 (const :tag
"any not-done state" 'todo
)
301 (const :tag
"any done state" 'done
)
302 (const :tag
"any state" 'any
)
303 (list :tag
"Keyword list"
304 (const :format
"" quote
)
305 (repeat (string :tag
"Keyword")))))
306 (const :tag
"scheduled" 'scheduled
)
307 (const :tag
"not scheduled" 'notscheduled
)
308 (const :tag
"deadline" 'deadline
)
309 (const :tag
"no deadline" 'notdeadline
)
310 (const :tag
"timestamp" 'timestamp
)
311 (const :tag
"no timestamp" 'nottimestamp
))))))
312 (list :tag
"Non-standard skipping condition"
313 :value
(org-agenda-skip-function)
314 (const org-agenda-skip-function
)
315 (sexp :tag
"Function or form (quoted!)"))
316 (list :tag
"Any variable"
317 (variable :tag
"Variable")
318 (sexp :tag
"Value (sexp)"))))
319 "Selection of examples for agenda command settings.
320 This will be spliced into the custom type of
321 `org-agenda-custom-commands'.")
324 (defcustom org-agenda-custom-commands nil
325 "Custom commands for the agenda.
326 These commands will be offered on the splash screen displayed by the
327 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
329 (key desc type match settings files)
331 key The key (one or more characters as a string) to be associated
333 desc A description of the command, when omitted or nil, a default
334 description is built using MATCH.
335 type The command type, any of the following symbols:
336 agenda The daily/weekly agenda.
337 todo Entries with a specific TODO keyword, in all agenda files.
338 search Entries containing search words entry or headline.
339 tags Tags/Property/TODO match in all agenda files.
340 tags-todo Tags/P/T match in all agenda files, TODO entries only.
341 todo-tree Sparse tree of specific TODO keyword in *current* file.
342 tags-tree Sparse tree with all tags matches in *current* file.
343 occur-tree Occur sparse tree for *current* file.
344 ... A user-defined function.
345 match What to search for:
346 - a single keyword for TODO keyword searches
347 - a tags match expression for tags searches
348 - a word search expression for text searches.
349 - a regular expression for occur searches
350 For all other commands, this should be the empty string.
351 settings A list of option settings, similar to that in a let form, so like
352 this: ((opt1 val1) (opt2 val2) ...). The values will be
353 evaluated at the moment of execution, so quote them when needed.
354 files A list of files file to write the produced agenda buffer to
355 with the command `org-store-agenda-views'.
356 If a file name ends in \".html\", an HTML version of the buffer
357 is written out. If it ends in \".ps\", a postscript version is
358 produced. Otherwise, only the plain text is written to the file.
360 You can also define a set of commands, to create a composite agenda buffer.
361 In this case, an entry looks like this:
363 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
367 desc A description string to be displayed in the dispatcher menu.
368 cmd An agenda command, similar to the above. However, tree commands
369 are no allowed, but instead you can get agenda and global todo list.
370 So valid commands for a set are:
371 (agenda \"\" settings)
372 (alltodo \"\" settings)
373 (stuck \"\" settings)
374 (todo \"match\" settings files)
375 (search \"match\" settings files)
376 (tags \"match\" settings files)
377 (tags-todo \"match\" settings files)
379 Each command can carry a list of options, and another set of options can be
380 given for the whole set of commands. Individual command options take
381 precedence over the general options.
383 When using several characters as key to a command, the first characters
384 are prefix commands. For the dispatcher to display useful information, you
385 should provide a description for the prefix, like
387 (setq org-agenda-custom-commands
388 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
389 (\"hl\" tags \"+HOME+Lisa\")
390 (\"hp\" tags \"+HOME+Peter\")
391 (\"hk\" tags \"+HOME+Kim\")))"
392 :group
'org-agenda-custom-commands
394 (choice :value
("x" "Describe command here" tags
"" nil
)
395 (list :tag
"Single command"
396 (string :tag
"Access Key(s) ")
397 (option (string :tag
"Description"))
399 (const :tag
"Agenda" agenda
)
400 (const :tag
"TODO list" alltodo
)
401 (const :tag
"Search words" search
)
402 (const :tag
"Stuck projects" stuck
)
403 (const :tag
"Tags/Property match (all agenda files)" tags
)
404 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
405 (const :tag
"TODO keyword search (all agenda files)" todo
)
406 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
407 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
408 (const :tag
"Occur tree (current buffer)" occur-tree
)
409 (sexp :tag
"Other, user-defined function"))
410 (string :tag
"Match (only for some commands)")
411 ,org-agenda-custom-commands-local-options
412 (option (repeat :tag
"Export" (file :tag
"Export to"))))
413 (list :tag
"Command series, all agenda files"
414 (string :tag
"Access Key(s)")
415 (string :tag
"Description ")
416 (repeat :tag
"Component"
419 (const :format
"" agenda
)
420 (const :tag
"" :format
"" "")
421 ,org-agenda-custom-commands-local-options
)
422 (list :tag
"TODO list (all keywords)"
423 (const :format
"" alltodo
)
424 (const :tag
"" :format
"" "")
425 ,org-agenda-custom-commands-local-options
)
426 (list :tag
"Search words"
427 (const :format
"" search
)
428 (string :tag
"Match")
429 ,org-agenda-custom-commands-local-options
)
430 (list :tag
"Stuck projects"
431 (const :format
"" stuck
)
432 (const :tag
"" :format
"" "")
433 ,org-agenda-custom-commands-local-options
)
434 (list :tag
"Tags search"
435 (const :format
"" tags
)
436 (string :tag
"Match")
437 ,org-agenda-custom-commands-local-options
)
438 (list :tag
"Tags search, TODO entries only"
439 (const :format
"" tags-todo
)
440 (string :tag
"Match")
441 ,org-agenda-custom-commands-local-options
)
442 (list :tag
"TODO keyword search"
443 (const :format
"" todo
)
444 (string :tag
"Match")
445 ,org-agenda-custom-commands-local-options
)
446 (list :tag
"Other, user-defined function"
447 (symbol :tag
"function")
448 (string :tag
"Match")
449 ,org-agenda-custom-commands-local-options
)))
451 (repeat :tag
"Settings for entire command set"
452 (list (variable :tag
"Any variable")
453 (sexp :tag
"Value")))
454 (option (repeat :tag
"Export" (file :tag
"Export to"))))
455 (cons :tag
"Prefix key documentation"
456 (string :tag
"Access Key(s)")
457 (string :tag
"Description ")))))
459 (defcustom org-agenda-query-register ?o
460 "The register holding the current query string.
461 The purpose of this is that if you construct a query string interactively,
462 you can then use it to define a custom command."
463 :group
'org-agenda-custom-commands
466 (defcustom org-stuck-projects
467 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
468 "How to identify stuck projects.
469 This is a list of four items:
470 1. A tags/todo/property matcher string that is used to identify a project.
471 See the manual for a description of tag and property searches.
472 The entire tree below a headline matched by this is considered one project.
473 2. A list of TODO keywords identifying non-stuck projects.
474 If the project subtree contains any headline with one of these todo
475 keywords, the project is considered to be not stuck. If you specify
476 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
477 3. A list of tags identifying non-stuck projects.
478 If the project subtree contains any headline with one of these tags,
479 the project is considered to be not stuck. If you specify \"*\" as
480 a tag, any tag will mark the project unstuck. Note that this is about
481 the explicit presence of a tag somewhere in the subtree, inherited
482 tags to not count here. If inherited tags make a project not stuck,
483 use \"-TAG\" in the tags part of the matcher under (1.) above.
484 4. An arbitrary regular expression matching non-stuck projects.
486 If the project turns out to be not stuck, search continues also in the
487 subtree to see if any of the subtasks have project status.
489 See also the variable `org-tags-match-list-sublevels' which applies
490 to projects matched by this search as well.
492 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
493 or `C-c a #' to produce the list."
494 :group
'org-agenda-custom-commands
496 (string :tag
"Tags/TODO match to identify a project")
497 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
498 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
499 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
501 (defcustom org-agenda-filter-effort-default-operator
"<"
502 "The default operator for effort estimate filtering.
503 If you select an effort estimate limit without first pressing an operator,
504 this one will be used."
505 :group
'org-agenda-custom-commands
506 :type
'(choice (const :tag
"less or equal" "<")
507 (const :tag
"greater or equal"">")
508 (const :tag
"equal" "=")))
510 (defgroup org-agenda-skip nil
511 "Options concerning skipping parts of agenda files."
512 :tag
"Org Agenda Skip"
514 (defgroup org-agenda-daily
/weekly nil
515 "Options concerning the daily/weekly agenda."
516 :tag
"Org Agenda Daily/Weekly"
518 (defgroup org-agenda-todo-list nil
519 "Options concerning the global todo list agenda view."
520 :tag
"Org Agenda Todo List"
522 (defgroup org-agenda-match-view nil
523 "Options concerning the general tags/property/todo match agenda view."
524 :tag
"Org Agenda Match View"
526 (defgroup org-agenda-search-view nil
527 "Options concerning the general tags/property/todo match agenda view."
528 :tag
"Org Agenda Match View"
531 (defvar org-agenda-archives-mode nil
532 "Non-nil means the agenda will include archived items.
533 If this is the symbol `trees', trees in the selected agenda scope
534 that are marked with the ARCHIVE tag will be included anyway. When this is
535 t, also all archive files associated with the current selection of agenda
536 files will be included.")
538 (defcustom org-agenda-skip-comment-trees t
539 "Non-nil means skip trees that start with the COMMENT keyword.
540 When nil, these trees are also scanned by agenda commands."
541 :group
'org-agenda-skip
544 (defcustom org-agenda-todo-list-sublevels t
545 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
546 When nil, the sublevels of a TODO entry are not checked, resulting in
547 potentially much shorter TODO lists."
548 :group
'org-agenda-skip
549 :group
'org-agenda-todo-list
552 (defcustom org-agenda-todo-ignore-with-date nil
553 "Non-nil means don't show entries with a date in the global todo list.
554 You can use this if you prefer to mark mere appointments with a TODO keyword,
555 but don't want them to show up in the TODO list.
556 When this is set, it also covers deadlines and scheduled items, the settings
557 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
559 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
560 :group
'org-agenda-skip
561 :group
'org-agenda-todo-list
564 (defcustom org-agenda-todo-ignore-scheduled nil
565 "Non-nil means, ignore some scheduled TODO items when making TODO list.
566 This applies when creating the global todo list.
569 past Don't show entries scheduled today or in the past.
571 future Don't show entries scheduled in the future.
572 The idea behind this is that by scheduling it, you don't want to
573 think about it until the scheduled date.
575 all Don't show any scheduled entries in the global todo list.
576 The idea behind this is that by scheduling it, you have already
577 \"taken care\" of this item.
579 t Same as `all', for backward compatibility.
581 See also `org-agenda-todo-ignore-with-date'.
582 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
583 to make his option also apply to the tags-todo list."
584 :group
'org-agenda-skip
585 :group
'org-agenda-todo-list
587 (const :tag
"Ignore future-scheduled todos" future
)
588 (const :tag
"Ignore past- or present-scheduled todos" past
)
589 (const :tag
"Ignore all scheduled todos" all
)
590 (const :tag
"Ignore all scheduled todos (compatibility)" t
)
591 (const :tag
"Show scheduled todos" nil
)))
593 (defcustom org-agenda-todo-ignore-deadlines nil
594 "Non-nil means ignore some deadlined TODO items when making TODO list.
595 There are different motivations for using different values, please think
596 carefully when configuring this variable.
598 This applie when creating the global todo list.
601 near Don't show near deadline entries. A deadline is near when it is
602 closer than `org-deadline-warning-days' days. The idea behind this
603 is that such items will appear in the agenda anyway.
605 far Don't show TODO entries where a deadline has been defined, but
606 the deadline is not near. This is useful if you don't want to
607 use the todo list to figure out what to do now.
609 past Don't show entries with a deadline timestamp for today or in the past.
611 future Don't show entries with a deadline timestamp in the future, not even
612 when they become `near' ones. Use it with caution.
614 all Ignore all TODO entries that do have a deadline.
616 t Same as `near', for backward compatibility.
618 See also `org-agenda-todo-ignore-with-date'.
619 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
620 to make his option also apply to the tags-todo list."
621 :group
'org-agenda-skip
622 :group
'org-agenda-todo-list
624 (const :tag
"Ignore near deadlines" near
)
625 (const :tag
"Ignore near deadlines (compatibility)" t
)
626 (const :tag
"Ignore far deadlines" far
)
627 (const :tag
"Ignore all TODOs with a deadlines" all
)
628 (const :tag
"Show all TODOs, even if they have a deadline" nil
)))
630 (defcustom org-agenda-tags-todo-honor-ignore-options nil
631 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
633 `org-agenda-todo-ignore-with-date',
634 `org-agenda-todo-ignore-scheduled'
635 `org-agenda-todo-ignore-deadlines'
636 make the global TODO list skip entries that have time stamps of certain
637 kinds. If this option is set, the same options will also apply for the
638 tags-todo search, which is the general tags/property matcher
639 restricted to unfinished TODO entries only."
640 :group
'org-agenda-skip
641 :group
'org-agenda-todo-list
642 :group
'org-agenda-match-view
645 (defcustom org-agenda-skip-scheduled-if-done nil
646 "Non-nil means don't show scheduled items in agenda when they are done.
647 This is relevant for the daily/weekly agenda, not for the TODO list. And
648 it applies only to the actual date of the scheduling. Warnings about
649 an item with a past scheduling dates are always turned off when the item
651 :group
'org-agenda-skip
652 :group
'org-agenda-daily
/weekly
655 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
656 "Non-nil means skip scheduling line if same entry shows because of deadline.
657 In the agenda of today, an entry can show up multiple times because
658 it is both scheduled and has a nearby deadline, and maybe a plain time
660 When this variable is t, then only the deadline is shown and the fact that
661 the entry is scheduled today or was scheduled previously is not shown.
662 When this variable is nil, the entry will be shown several times. When
663 the variable is the symbol `not-today', then skip scheduled previously,
664 but not scheduled today."
665 :group
'org-agenda-skip
666 :group
'org-agenda-daily
/weekly
668 (const :tag
"Never" nil
)
669 (const :tag
"Always" t
)
670 (const :tag
"Not when scheduled today" not-today
)))
672 (defcustom org-agenda-skip-deadline-if-done nil
673 "Non-nil means don't show deadlines when the corresponding item is done.
674 When nil, the deadline is still shown and should give you a happy feeling.
675 This is relevant for the daily/weekly agenda. And it applied only to the
676 actually date of the deadline. Warnings about approaching and past-due
677 deadlines are always turned off when the item is DONE."
678 :group
'org-agenda-skip
679 :group
'org-agenda-daily
/weekly
682 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
683 "Non-nil means skip deadline prewarning when entry is also scheduled.
684 This will apply on all days where a prewarning for the deadline would
685 be shown, but not at the day when the entry is actually due. On that day,
686 the deadline will be shown anyway.
687 This variable may be set to nil, t, or a number which will then give
688 the number of days before the actual deadline when the prewarnings
690 This can be used in a workflow where the first showing of the deadline will
691 trigger you to schedule it, and then you don't want to be reminded of it
692 because you will take care of it on the day when scheduled."
693 :group
'org-agenda-skip
694 :group
'org-agenda-daily
/weekly
696 (const :tag
"Alwas show prewarning" nil
)
697 (const :tag
"Remove prewarning if entry is scheduled" t
)
698 (integer :tag
"Restart prewarning N days before deadline")))
700 (defcustom org-agenda-skip-additional-timestamps-same-entry t
701 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
702 When non-nil, after the search for timestamps has matched once in an
703 entry, the rest of the entry will not be searched."
704 :group
'org-agenda-skip
707 (defcustom org-agenda-skip-timestamp-if-done nil
708 "Non-nil means don't select item by timestamp or -range if it is DONE."
709 :group
'org-agenda-skip
710 :group
'org-agenda-daily
/weekly
713 (defcustom org-agenda-dim-blocked-tasks t
714 "Non-nil means dim blocked tasks in the agenda display.
715 This causes some overhead during agenda construction, but if you
716 have turned on `org-enforce-todo-dependencies',
717 `org-enforce-todo-checkbox-dependencies', or any other blocking
718 mechanism, this will create useful feedback in the agenda.
720 Instead of t, this variable can also have the value `invisible'.
721 Then blocked tasks will be invisible and only become visible when
722 they become unblocked. An exemption to this behavior is when a task is
723 blocked because of unchecked checkboxes below it. Since checkboxes do
724 not show up in the agenda views, making this task invisible you remove any
725 trace from agenda views that there is something to do. Therefore, a task
726 that is blocked because of checkboxes will never be made invisible, it
727 will only be dimmed."
728 :group
'org-agenda-daily
/weekly
729 :group
'org-agenda-todo-list
731 (const :tag
"Do not dim" nil
)
732 (const :tag
"Dim to a grey face" t
)
733 (const :tag
"Make invisible" invisible
)))
735 (defcustom org-timeline-show-empty-dates
3
736 "Non-nil means `org-timeline' also shows dates without an entry.
737 When nil, only the days which actually have entries are shown.
738 When t, all days between the first and the last date are shown.
739 When an integer, show also empty dates, but if there is a gap of more than
740 N days, just insert a special line indicating the size of the gap."
741 :group
'org-agenda-skip
743 (const :tag
"None" nil
)
745 (integer :tag
"at most")))
747 (defgroup org-agenda-startup nil
748 "Options concerning initial settings in the Agenda in Org Mode."
749 :tag
"Org Agenda Startup"
752 (defcustom org-finalize-agenda-hook nil
753 "Hook run just before displaying an agenda buffer."
754 :group
'org-agenda-startup
757 (defcustom org-agenda-mouse-1-follows-link nil
758 "Non-nil means mouse-1 on a link will follow the link in the agenda.
759 A longer mouse click will still set point. Does not work on XEmacs.
760 Needs to be set before org.el is loaded."
761 :group
'org-agenda-startup
764 (defcustom org-agenda-start-with-follow-mode nil
765 "The initial value of follow-mode in a newly created agenda window."
766 :group
'org-agenda-startup
769 (defcustom org-agenda-show-outline-path t
770 "Non-nil means show outline path in echo area after line motion."
771 :group
'org-agenda-startup
774 (defcustom org-agenda-start-with-entry-text-mode nil
775 "The initial value of entry-text-mode in a newly created agenda window."
776 :group
'org-agenda-startup
779 (defcustom org-agenda-entry-text-maxlines
5
780 "Number of text lines to be added when `E' is pressed in the agenda.
782 Note that this variable only used during agenda display. Add add entry text
783 when exporting the agenda, configure the variable
784 `org-agenda-add-entry-ext-maxlines'."
788 (defcustom org-agenda-entry-text-exclude-regexps nil
789 "List of regular expressions to clean up entry text.
790 The complete matches of all regular expressions in this list will be
791 removed from entry text before it is shown in the agenda."
793 :type
'(repeat (regexp)))
795 (defvar org-agenda-entry-text-cleanup-hook nil
796 "Hook that is run after basic cleanup of entry text to be shown in agenda.
797 This cleanup is done in a temporary buffer, so the function may inspect and
798 change the entire buffer.
799 Some default stuff like drawers and scheduling/deadline dates will already
800 have been removed when this is called, as will any matches for regular
801 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
803 (defvar org-agenda-include-inactive-timestamps nil
804 "Non-nil means include inactive time stamps in agenda and timeline.")
806 (defgroup org-agenda-windows nil
807 "Options concerning the windows used by the Agenda in Org Mode."
808 :tag
"Org Agenda Windows"
811 (defcustom org-agenda-window-setup
'reorganize-frame
812 "How the agenda buffer should be displayed.
813 Possible values for this option are:
815 current-window Show agenda in the current window, keeping all other windows.
816 other-window Use `switch-to-buffer-other-window' to display agenda.
817 reorganize-frame Show only two windows on the current frame, the current
818 window and the agenda.
819 other-frame Use `switch-to-buffer-other-frame' to display agenda.
820 Also, when exiting the agenda, kill that frame.
821 See also the variable `org-agenda-restore-windows-after-quit'."
822 :group
'org-agenda-windows
824 (const current-window
)
827 (const reorganize-frame
)))
829 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
830 "The min and max height of the agenda window as a fraction of frame height.
831 The value of the variable is a cons cell with two numbers between 0 and 1.
832 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
833 :group
'org-agenda-windows
834 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
836 (defcustom org-agenda-restore-windows-after-quit nil
837 "Non-nil means restore window configuration open exiting agenda.
838 Before the window configuration is changed for displaying the agenda,
839 the current status is recorded. When the agenda is exited with
840 `q' or `x' and this option is set, the old state is restored. If
841 `org-agenda-window-setup' is `other-frame', the value of this
842 option will be ignored."
843 :group
'org-agenda-windows
846 (defcustom org-agenda-ndays
7
847 "Number of days to include in overview display.
849 Custom commands can set this variable in the options section."
850 :group
'org-agenda-daily
/weekly
853 (defcustom org-agenda-start-on-weekday
1
854 "Non-nil means start the overview always on the specified weekday.
855 0 denotes Sunday, 1 denotes Monday etc.
856 When nil, always start on the current day.
857 Custom commands can set this variable in the options section."
858 :group
'org-agenda-daily
/weekly
859 :type
'(choice (const :tag
"Today" nil
)
860 (integer :tag
"Weekday No.")))
862 (defcustom org-agenda-show-all-dates t
863 "Non-nil means `org-agenda' shows every day in the selected range.
864 When nil, only the days which actually have entries are shown."
865 :group
'org-agenda-daily
/weekly
868 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
869 "Format string for displaying dates in the agenda.
870 Used by the daily/weekly agenda and by the timeline. This should be
871 a format string understood by `format-time-string', or a function returning
872 the formatted date as a string. The function must take a single argument,
873 a calendar-style date list like (month day year)."
874 :group
'org-agenda-daily
/weekly
876 (string :tag
"Format string")
877 (function :tag
"Function")))
879 (defun org-agenda-format-date-aligned (date)
880 "Format a date string for display in the daily/weekly agenda, or timeline.
881 This function makes sure that dates are aligned for easy reading."
883 (let* ((dayname (calendar-day-name date
))
885 (day-of-week (calendar-day-of-week date
))
887 (monthname (calendar-month-name month
))
889 (iso-week (org-days-to-iso-week
890 (calendar-absolute-from-gregorian date
)))
891 (weekyear (cond ((and (= month
1) (>= iso-week
52))
893 ((and (= month
12) (<= iso-week
1))
896 (weekstring (if (= day-of-week
1)
897 (format " W%02d" iso-week
)
899 (format "%-10s %2d %s %4d%s"
900 dayname day monthname year weekstring
)))
902 (defcustom org-agenda-time-leading-zero nil
903 "Non-nil means use leading zero for military times in agenda.
904 For example, 9:30am would become 09:30 rather than 9:30."
905 :group
'org-agenda-daily
/weekly
908 (defcustom org-agenda-weekend-days
'(6 0)
909 "Which days are weekend?
910 These days get the special face `org-agenda-date-weekend' in the agenda
911 and timeline buffers."
912 :group
'org-agenda-daily
/weekly
913 :type
'(set :greedy t
914 (const :tag
"Monday" 1)
915 (const :tag
"Tuesday" 2)
916 (const :tag
"Wednesday" 3)
917 (const :tag
"Thursday" 4)
918 (const :tag
"Friday" 5)
919 (const :tag
"Saturday" 6)
920 (const :tag
"Sunday" 0)))
922 (defcustom org-agenda-include-diary nil
923 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
924 Custom commands can set this variable in the options section."
925 :group
'org-agenda-daily
/weekly
928 (defcustom org-agenda-include-deadlines t
929 "If non-nil, include entries within their deadline warning period.
930 Custom commands can set this variable in the options section."
931 :group
'org-agenda-daily
/weekly
934 (defcustom org-agenda-include-all-todo nil
935 "Set means weekly/daily agenda will always contain all TODO entries.
936 The TODO entries will be listed at the top of the agenda, before
937 the entries for specific days.
938 This option is deprecated, it is better to define a block agenda instead."
939 :group
'org-agenda-daily
/weekly
942 (defcustom org-agenda-repeating-timestamp-show-all t
943 "Non-nil means show all occurrences of a repeating stamp in the agenda.
944 When nil, only one occurrence is shown, either today or the
945 nearest into the future."
946 :group
'org-agenda-daily
/weekly
949 (defcustom org-scheduled-past-days
10000
950 "No. of days to continue listing scheduled items that are not marked DONE.
951 When an item is scheduled on a date, it shows up in the agenda on this
952 day and will be listed until it is marked done for the number of days
954 :group
'org-agenda-daily
/weekly
957 (defcustom org-agenda-log-mode-items
'(closed clock
)
958 "List of items that should be shown in agenda log mode.
959 This list may contain the following symbols:
961 closed Show entries that have been closed on that day.
962 clock Show entries that have received clocked time on that day.
963 state Show all logged state changes.
964 Note that instead of changing this variable, you can also press `C-u l' in
965 the agenda to display all available LOG items temporarily."
966 :group
'org-agenda-daily
/weekly
967 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
969 (defcustom org-agenda-log-mode-add-notes t
970 "Non-nil means add first line of notes to log entries in agenda views.
971 If a log item like a state change or a clock entry is associated with
972 notes, the first line of these notes will be added to the entry in the
974 :group
'org-agenda-daily
/weekly
977 (defcustom org-agenda-start-with-log-mode nil
978 "The initial value of log-mode in a newly created agenda window."
979 :group
'org-agenda-startup
980 :group
'org-agenda-daily
/weekly
983 (defcustom org-agenda-start-with-clockreport-mode nil
984 "The initial value of clockreport-mode in a newly created agenda window."
985 :group
'org-agenda-startup
986 :group
'org-agenda-daily
/weekly
989 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
990 "Property list with parameters for the clocktable in clockreport mode.
991 This is the display mode that shows a clock table in the daily/weekly
992 agenda, the properties for this dynamic block can be set here.
993 The usual clocktable parameters are allowed here, but you cannot set
994 the properties :name, :tstart, :tend, :block, and :scope - these will
995 be overwritten to make sure the content accurately reflects the
996 current display in the agenda."
997 :group
'org-agenda-daily
/weekly
1000 (defcustom org-agenda-search-view-always-boolean nil
1001 "Non-nil means the search string is interpreted as individual parts.
1003 The search string for search view can either be interpreted as a phrase,
1004 or as a list of snippets that define a boolean search for a number of
1007 When this is non-nil, the string will be split on whitespace, and each
1008 snippet will be searched individually, and all must match in order to
1009 select an entry. A snippet is then a single string of non-white
1010 characters, or a string in double quotes, or a regexp in {} braces.
1011 If a snippet is preceeded by \"-\", the snippet must *not* match.
1012 \"+\" is syntactic sugar for positive selection. Each snippet may
1013 be found as a full word or a partial word, but see the variable
1014 `org-agenda-search-view-force-full-words'.
1016 When this is nil, search will look for the entire search phrase as one,
1017 with each space character matching any amount of whitespace, including
1020 Even when this is nil, you can still switch to Boolean search dynamically
1021 by preceeding the first snippet with \"+\" or \"-\". If the first snippet
1022 is a regexp marked with braces like \"{abc}\", this will also switch to
1024 :group
'org-agenda-search-view
1027 (if (fboundp 'defvaralias
)
1028 (defvaralias 'org-agenda-search-view-search-words-only
1029 'org-agenda-search-view-always-boolean
))
1031 (defcustom org-agenda-search-view-force-full-words nil
1033 ans, search words must be matches as complete words.
1034 When nil, they may also match part of a word."
1035 :group
'org-agenda-search-view
1038 (defgroup org-agenda-time-grid nil
1039 "Options concerning the time grid in the Org-mode Agenda."
1040 :tag
"Org Agenda Time Grid"
1043 (defcustom org-agenda-search-headline-for-time t
1044 "Non-nil means search headline for a time-of-day.
1045 If the headline contains a time-of-day in one format or another, it will
1046 be used to sort the entry into the time sequence of items for a day.
1047 Some people have time stamps in the headline that refer to the creation
1048 time or so, and then this produces an unwanted side effect. If this is
1049 the case for your, use this variable to turn off searching the headline
1051 :group
'org-agenda-time-grid
1054 (defcustom org-agenda-use-time-grid t
1055 "Non-nil means show a time grid in the agenda schedule.
1056 A time grid is a set of lines for specific times (like every two hours between
1057 8:00 and 20:00). The items scheduled for a day at specific times are
1058 sorted in between these lines.
1059 For details about when the grid will be shown, and what it will look like, see
1060 the variable `org-agenda-time-grid'."
1061 :group
'org-agenda-time-grid
1064 (defcustom org-agenda-time-grid
1065 '((daily today require-timed
)
1067 (800 1000 1200 1400 1600 1800 2000))
1069 "The settings for time grid for agenda display.
1070 This is a list of three items. The first item is again a list. It contains
1071 symbols specifying conditions when the grid should be displayed:
1073 daily if the agenda shows a single day
1074 weekly if the agenda shows an entire week
1075 today show grid on current date, independent of daily/weekly display
1076 require-timed show grid only if at least one item has a time specification
1078 The second item is a string which will be placed behind the grid time.
1080 The third item is a list of integers, indicating the times that should have
1082 :group
'org-agenda-time-grid
1085 (set :greedy t
:tag
"Grid Display Options"
1086 (const :tag
"Show grid in single day agenda display" daily
)
1087 (const :tag
"Show grid in weekly agenda display" weekly
)
1088 (const :tag
"Always show grid for today" today
)
1089 (const :tag
"Show grid only if any timed entries are present"
1091 (const :tag
"Skip grid times already present in an entry"
1093 (string :tag
"Grid String")
1094 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1096 (defgroup org-agenda-sorting nil
1097 "Options concerning sorting in the Org-mode Agenda."
1098 :tag
"Org Agenda Sorting"
1101 (defcustom org-agenda-sorting-strategy
1102 '((agenda habit-down time-up priority-down category-keep
)
1103 (todo priority-down category-keep
)
1104 (tags priority-down category-keep
)
1105 (search category-keep
))
1106 "Sorting structure for the agenda items of a single day.
1107 This is a list of symbols which will be used in sequence to determine
1108 if an entry should be listed before another entry. The following
1109 symbols are recognized:
1111 time-up Put entries with time-of-day indications first, early first
1112 time-down Put entries with time-of-day indications first, late first
1113 category-keep Keep the default order of categories, corresponding to the
1114 sequence in `org-agenda-files'.
1115 category-up Sort alphabetically by category, A-Z.
1116 category-down Sort alphabetically by category, Z-A.
1117 tag-up Sort alphabetically by last tag, A-Z.
1118 tag-down Sort alphabetically by last tag, Z-A.
1119 priority-up Sort numerically by priority, high priority last.
1120 priority-down Sort numerically by priority, high priority first.
1121 todo-state-up Sort by todo state, tasks that are done last.
1122 todo-state-down Sort by todo state, tasks that are done first.
1123 effort-up Sort numerically by estimated effort, high effort last.
1124 effort-down Sort numerically by estimated effort, high effort first.
1125 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1126 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1127 habit-up Put entries that are habits first
1128 habit-down Put entries that are habits last
1129 alpha-up Sort headlines alphabetically
1130 alpha-down Sort headlines alphabetically, reversed
1132 The different possibilities will be tried in sequence, and testing stops
1133 if one comparison returns a \"not-equal\". For example, the default
1134 '(time-up category-keep priority-down)
1135 means: Pull out all entries having a specified time of day and sort them,
1136 in order to make a time schedule for the current day the first thing in the
1137 agenda listing for the day. Of the entries without a time indication, keep
1138 the grouped in categories, don't sort the categories, but keep them in
1139 the sequence given in `org-agenda-files'. Within each category sort by
1142 Leaving out `category-keep' would mean that items will be sorted across
1143 categories by priority.
1145 Instead of a single list, this can also be a set of list for specific
1146 contents, with a context symbol in the car of the list, any of
1147 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1149 Custom commands can bind this variable in the options section."
1150 :group
'org-agenda-sorting
1152 (repeat :tag
"General" ,org-sorting-choice
)
1153 (list :tag
"Individually"
1154 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1155 (repeat ,org-sorting-choice
))
1156 (cons (const :tag
"Strategy for TODO lists" todo
)
1157 (repeat ,org-sorting-choice
))
1158 (cons (const :tag
"Strategy for Tags matches" tags
)
1159 (repeat ,org-sorting-choice
))
1160 (cons (const :tag
"Strategy for search matches" search
)
1161 (repeat ,org-sorting-choice
)))))
1163 (defcustom org-agenda-cmp-user-defined nil
1164 "A function to define the comparison `user-defined'.
1165 This function must receive two arguments, agenda entry a and b.
1166 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1167 the user comparison, return nil.
1168 When this is defined, you can make `user-defined-up' and `user-defined-down'
1169 part of an agenda sorting strategy."
1170 :group
'org-agenda-sorting
1173 (defcustom org-sort-agenda-notime-is-late t
1174 "Non-nil means items without time are considered late.
1175 This is only relevant for sorting. When t, items which have no explicit
1176 time like 15:30 will be considered as 99:01, i.e. later than any items which
1177 do have a time. When nil, the default time is before 0:00. You can use this
1178 option to decide if the schedule for today should come before or after timeless
1180 :group
'org-agenda-sorting
1183 (defcustom org-sort-agenda-noeffort-is-high t
1184 "Non-nil means items without effort estimate are sorted as high effort.
1185 This also applies when filtering an agenda view with respect to the
1186 < or > effort operator. Then, tasks with no effort defined will be treated
1187 as tasks with high effort.
1188 When nil, such items are sorted as 0 minutes effort."
1189 :group
'org-agenda-sorting
1192 (defgroup org-agenda-line-format nil
1193 "Options concerning the entry prefix in the Org-mode agenda display."
1194 :tag
"Org Agenda Line Format"
1197 (defcustom org-agenda-prefix-format
1198 '((agenda .
" %-12:c%?-12t% s")
1202 (search .
" %-12:c"))
1203 "Format specifications for the prefix of items in the agenda views.
1204 An alist with four entries, for the different agenda types. The keys to the
1205 sublists are `agenda', `timeline', `todo', and `tags'. The values
1207 This format works similar to a printf format, with the following meaning:
1209 %c the category of the item, \"Diary\" for entries from the diary, or
1210 as given by the CATEGORY keyword or derived from the file name.
1211 %T the *last* tag of the item. Last because inherited tags come
1213 %t the time-of-day specification if one applies to the entry, in the
1215 %s Scheduling/Deadline information, a short string
1217 All specifiers work basically like the standard `%s' of printf, but may
1218 contain two additional characters: A question mark just after the `%' and
1219 a whitespace/punctuation character just before the final letter.
1221 If the first character after `%' is a question mark, the entire field
1222 will only be included if the corresponding value applies to the
1223 current entry. This is useful for fields which should have fixed
1224 width when present, but zero width when absent. For example,
1225 \"%?-12t\" will result in a 12 character time field if a time of the
1226 day is specified, but will completely disappear in entries which do
1229 If there is punctuation or whitespace character just before the final
1230 format letter, this character will be appended to the field value if
1231 the value is not empty. For example, the format \"%-12:c\" leads to
1232 \"Diary: \" if the category is \"Diary\". If the category were be
1233 empty, no additional colon would be inserted.
1235 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1236 - Indent the line with two space characters
1237 - Give the category in a 12 chars wide field, padded with whitespace on
1238 the right (because of `-'). Append a colon if there is a category
1240 - If there is a time-of-day, put it into a 12 chars wide field. If no
1241 time, don't put in an empty field, just skip it (because of '?').
1242 - Finally, put the scheduling information and append a whitespace.
1244 As another example, if you don't want the time-of-day of entries in
1245 the prefix, you could use:
1247 (setq org-agenda-prefix-format \" %-11:c% s\")
1249 See also the variables `org-agenda-remove-times-when-in-prefix' and
1250 `org-agenda-remove-tags'.
1252 Custom commands can set this variable in the options section."
1254 (string :tag
"General format")
1255 (list :greedy t
:tag
"View dependent"
1256 (cons (const agenda
) (string :tag
"Format"))
1257 (cons (const timeline
) (string :tag
"Format"))
1258 (cons (const todo
) (string :tag
"Format"))
1259 (cons (const tags
) (string :tag
"Format"))
1260 (cons (const search
) (string :tag
"Format"))))
1261 :group
'org-agenda-line-format
)
1263 (defvar org-prefix-format-compiled nil
1264 "The compiled version of the most recently used prefix format.
1265 See the variable `org-agenda-prefix-format'.")
1267 (defcustom org-agenda-todo-keyword-format
"%-1s"
1268 "Format for the TODO keyword in agenda lines.
1269 Set this to something like \"%-12s\" if you want all TODO keywords
1270 to occupy a fixed space in the agenda display."
1271 :group
'org-agenda-line-format
1274 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1275 "Text preceding timerange entries in the agenda view.
1276 This is a list with two strings. The first applies when the range
1277 is entirely on one day. The second applies if the range spans several days.
1278 The strings may have two \"%d\" format specifiers which will be filled
1279 with the sequence number of the days, and the total number of days in the
1280 range, respectively."
1281 :group
'org-agenda-line-format
1283 (string :tag
"Deadline today ")
1284 (choice :tag
"Deadline relative"
1285 (string :tag
"Format string")
1288 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1289 "Text preceeding scheduled items in the agenda view.
1290 This is a list with two strings. The first applies when the item is
1291 scheduled on the current day. The second applies when it has been scheduled
1292 previously, it may contain a %d indicating that this is the nth time that
1293 this item is scheduled, due to automatic rescheduling of unfinished items
1294 for the following day. So this number is one larger than the number of days
1295 that passed since this item was scheduled first."
1296 :group
'org-agenda-line-format
1298 (string :tag
"Scheduled today ")
1299 (string :tag
"Scheduled previously")))
1301 (defcustom org-agenda-inactive-leader
"["
1302 "Text preceeding item pulled into the agenda by inactive time stamps.
1303 These entries are added to the agenda when pressing \"[\"."
1304 :group
'org-agenda-line-format
1306 (string :tag
"Scheduled today ")
1307 (string :tag
"Scheduled previously")))
1309 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1310 "Text preceeding deadline items in the agenda view.
1311 This is a list with two strings. The first applies when the item has its
1312 deadline on the current day. The second applies when it is in the past or
1313 in the future, it may contain %d to capture how many days away the deadline
1315 :group
'org-agenda-line-format
1317 (string :tag
"Deadline today ")
1318 (choice :tag
"Deadline relative"
1319 (string :tag
"Format string")
1322 (defcustom org-agenda-remove-times-when-in-prefix t
1323 "Non-nil means remove duplicate time specifications in agenda items.
1324 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1325 time-of-day specification in a headline or diary entry is extracted and
1326 placed into the prefix. If this option is non-nil, the original specification
1327 \(a timestamp or -range, or just a plain time(range) specification like
1328 11:30-4pm) will be removed for agenda display. This makes the agenda less
1330 The option can be t or nil. It may also be the symbol `beg', indicating
1331 that the time should only be removed when it is located at the beginning of
1332 the headline/diary entry."
1333 :group
'org-agenda-line-format
1335 (const :tag
"Always" t
)
1336 (const :tag
"Never" nil
)
1337 (const :tag
"When at beginning of entry" beg
)))
1340 (defcustom org-agenda-default-appointment-duration nil
1341 "Default duration for appointments that only have a starting time.
1342 When nil, no duration is specified in such cases.
1343 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1344 :group
'org-agenda-line-format
1346 (integer :tag
"Minutes")
1347 (const :tag
"No default duration")))
1349 (defcustom org-agenda-show-inherited-tags t
1350 "Non-nil means show inherited tags in each agenda line."
1351 :group
'org-agenda-line-format
1354 (defcustom org-agenda-hide-tags-regexp nil
1355 "Regular expression used to filter away specific tags in agenda views.
1356 This means that these tags will be present, but not be shown in the agenda
1357 line. Secondayt filltering will still work on the hidden tags.
1358 Nil means don't hide any tags."
1359 :group
'org-agenda-line-format
1361 (const :tag
"Hide none" nil
)
1362 (string :tag
"Regexp ")))
1364 (defcustom org-agenda-remove-tags nil
1365 "Non-nil means remove the tags from the headline copy in the agenda.
1366 When this is the symbol `prefix', only remove tags when
1367 `org-agenda-prefix-format' contains a `%T' specifier."
1368 :group
'org-agenda-line-format
1370 (const :tag
"Always" t
)
1371 (const :tag
"Never" nil
)
1372 (const :tag
"When prefix format contains %T" prefix
)))
1374 (if (fboundp 'defvaralias
)
1375 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1376 'org-agenda-remove-tags
))
1378 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1379 "Shift tags in agenda items to this column.
1380 If this number is positive, it specifies the column. If it is negative,
1381 it means that the tags should be flushright to that column. For example,
1382 -80 works well for a normal 80 character screen."
1383 :group
'org-agenda-line-format
1386 (if (fboundp 'defvaralias
)
1387 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1389 (defcustom org-agenda-fontify-priorities
'cookies
1390 "Non-nil means highlight low and high priorities in agenda.
1391 When t, the highest priority entries are bold, lowest priority italic.
1392 However, settings in org-priority-faces will overrule these faces.
1393 When this variable is the symbol `cookies', only fontify the
1394 cookies, not the entire task.
1395 This may also be an association list of priority faces, whose
1396 keys are the character values of `org-highest-priority',
1397 `org-default-priority', and `org-lowest-priority' (the default values
1398 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1399 color as a string, or a list like `(:background \"Red\")'.
1400 If it is a color, the variable `org-faces-easy-properties'
1401 determines if it is a foreground or a background color."
1402 :group
'org-agenda-line-format
1404 (const :tag
"Never" nil
)
1405 (const :tag
"Defaults" t
)
1406 (const :tag
"Cookies only" cookies
)
1407 (repeat :tag
"Specify"
1408 (list (character :tag
"Priority" :value ?A
)
1409 (choice :tag
"Face "
1410 (string :tag
"Color")
1411 (sexp :tag
"Face"))))))
1413 (defgroup org-agenda-column-view nil
1414 "Options concerning column view in the agenda."
1415 :tag
"Org Agenda Column View"
1418 (defcustom org-agenda-columns-show-summaries t
1419 "Non-nil means show summaries for columns displayed in the agenda view."
1420 :group
'org-agenda-column-view
1423 (defcustom org-agenda-columns-remove-prefix-from-item t
1424 "Non-nil means remove the prefix from a headline for agenda column view.
1425 The special ITEM field in the columns format contains the current line, with
1426 all information shown in other columns (like the TODO state or a tag).
1427 When this variable is non-nil, also the agenda prefix will be removed from
1428 the content of the ITEM field, to make sure as much as possible of the
1429 headline can be shown in the limited width of the field."
1433 (defcustom org-agenda-columns-compute-summary-properties t
1434 "Non-nil means recompute all summary properties before column view.
1435 When column view in the agenda is listing properties that have a summary
1436 operator, it can go to all relevant buffers and recompute the summaries
1437 there. This can mean overhead for the agenda column view, but is necessary
1438 to have thing up to date.
1439 As a special case, a CLOCKSUM property also makes sure that the clock
1440 computations are current."
1441 :group
'org-agenda-column-view
1444 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1445 "Non-nil means the duration of an appointment will add to day effort.
1446 The property to which appointment durations will be added is the one given
1447 in the option `org-effort-property'. If an appointment does not have
1448 an end time, `org-agenda-default-appointment-duration' will be used. If that
1449 is not set, an appointment without end time will not contribute to the time
1451 :group
'org-agenda-column-view
1454 (defcustom org-agenda-auto-exclude-function nil
1455 "A function called with a tag to decide if it is filtered on '/ RET'.
1456 The sole argument to the function, which is called once for each
1457 possible tag, is a string giving the name of the tag. The
1458 function should return either nil if the tag should be included
1459 as normal, or \"-<TAG>\" to exclude the tag.
1460 Note that for the purpose of tag filtering, only the lower-case version of
1461 all tags will be considered, so that this function will only ever see
1462 the lower-case version of all tags."
1470 (defun org-add-agenda-custom-command (entry)
1471 "Replace or add a command in `org-agenda-custom-commands'.
1472 This is mostly for hacking and trying a new command - once the command
1473 works you probably want to add it to `org-agenda-custom-commands' for good."
1474 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1476 (setcdr ass
(cdr entry
))
1477 (push entry org-agenda-custom-commands
))))
1479 ;;; Define the Org-agenda-mode
1481 (defvar org-agenda-mode-map
(make-sparse-keymap)
1482 "Keymap for `org-agenda-mode'.")
1483 (if (fboundp 'defvaralias
)
1484 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1486 (defvar org-agenda-menu
) ; defined later in this file.
1487 (defvar org-agenda-restrict
) ; defined later in this file.
1488 (defvar org-agenda-follow-mode nil
)
1489 (defvar org-agenda-entry-text-mode nil
)
1490 (defvar org-agenda-clockreport-mode nil
)
1491 (defvar org-agenda-show-log nil
)
1492 (defvar org-agenda-redo-command nil
)
1493 (defvar org-agenda-query-string nil
)
1494 (defvar org-agenda-mode-hook nil
1495 "Hook for org-agenda-mode, run after the mode is turned on.")
1496 (defvar org-agenda-type nil
)
1497 (defvar org-agenda-force-single-file nil
)
1498 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1500 (defun org-agenda-mode ()
1501 "Mode for time-sorted view on action items in Org-mode files.
1503 The following commands are available:
1505 \\{org-agenda-mode-map}"
1507 (kill-all-local-variables)
1508 (setq org-agenda-undo-list nil
1509 org-agenda-pending-undo-list nil
1510 org-agenda-bulk-marked-entries nil
)
1511 (setq major-mode
'org-agenda-mode
)
1512 ;; Keep global-font-lock-mode from turning on font-lock-mode
1513 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1514 (setq mode-name
"Org-Agenda")
1515 (use-local-map org-agenda-mode-map
)
1516 (easy-menu-add org-agenda-menu
)
1517 (if org-startup-truncated
(setq truncate-lines t
))
1518 (org-set-local 'line-move-visual nil
)
1519 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1520 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1521 ;; Make sure properties are removed when copying text
1522 (when (boundp 'buffer-substring-filters
)
1523 (org-set-local 'buffer-substring-filters
1525 (set-text-properties 0 (length x
) nil x
) x
)
1526 buffer-substring-filters
)))
1527 (unless org-agenda-keep-modes
1528 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1529 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1530 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1531 org-agenda-show-log org-agenda-start-with-log-mode
))
1534 '("Agenda") "Agenda Files"
1538 (if (get 'org-agenda-files
'org-restrict
)
1539 "Restricted to single file"
1541 '(org-edit-agenda-file-list)
1542 (not (get 'org-agenda-files
'org-restrict
)))
1544 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1545 (org-agenda-set-mode-name)
1547 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1548 (list 'org-agenda-mode-hook
)))
1550 (substitute-key-definition 'undo
'org-agenda-undo
1551 org-agenda-mode-map global-map
)
1552 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1553 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1554 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1555 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1556 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1557 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1558 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1559 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1560 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1561 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1562 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
1563 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
1564 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
1565 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1566 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1567 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1568 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1569 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
1570 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
1571 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1572 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1573 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1574 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1575 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1576 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1577 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1578 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1579 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1580 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1581 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1582 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1583 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1584 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1585 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1586 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1587 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1588 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1589 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1590 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1591 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1592 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1593 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1594 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1596 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1597 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1598 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1599 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1600 (while l (org-defkey org-agenda-mode-map
1601 (int-to-string (pop l)) 'digit-argument)))
1603 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1604 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1605 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1606 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1607 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1608 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1609 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1610 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1611 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1612 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1613 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1614 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1615 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1616 'org-clock-modify-effort-estimate)
1617 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1618 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1619 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1620 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1621 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1622 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1623 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1624 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1625 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1626 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1627 (substitute-key-definition 'next-line 'org-agenda-next-line
1628 org-agenda-mode-map global-map)
1629 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1630 org-agenda-mode-map global-map)
1631 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1632 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1633 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1634 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1635 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1636 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1637 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1638 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1639 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1640 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1641 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1642 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1643 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1644 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1645 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1646 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1647 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1648 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1649 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1650 (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
1651 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1652 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1653 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1654 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1655 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1656 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1657 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1658 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1659 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1660 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1662 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1663 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1664 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1665 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1666 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1667 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1668 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1669 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1670 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1671 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1673 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1674 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1675 (when org-agenda-mouse-1-follows-link
1676 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1677 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1682 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1683 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1684 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1685 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1688 ["Day View" org-agenda-day-view
1689 :active (org-agenda-check-type nil 'agenda)
1690 :style radio :selected (equal org-agenda-ndays 1)
1691 :keys "v d (or just d)"]
1692 ["Week View" org-agenda-week-view
1693 :active (org-agenda-check-type nil 'agenda)
1694 :style radio :selected (equal org-agenda-ndays 7)
1695 :keys "v w (or just w)"]
1696 ["Month View" org-agenda-month-view
1697 :active (org-agenda-check-type nil 'agenda)
1698 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1700 ["Year View" org-agenda-year-view
1701 :active (org-agenda-check-type nil 'agenda)
1702 :style radio :selected (member org-agenda-ndays '(365 366))
1705 ["Include Diary" org-agenda-toggle-diary
1706 :style toggle :selected org-agenda-include-diary
1707 :active (org-agenda-check-type nil 'agenda)]
1708 ["Include Deadlines" org-agenda-toggle-deadlines
1709 :style toggle :selected org-agenda-include-deadlines
1710 :active (org-agenda-check-type nil 'agenda)]
1711 ["Use Time Grid" org-agenda-toggle-time-grid
1712 :style toggle :selected org-agenda-use-time-grid
1713 :active (org-agenda-check-type nil 'agenda)]
1715 ["Show clock report" org-agenda-clockreport-mode
1716 :style toggle :selected org-agenda-clockreport-mode
1717 :active (org-agenda-check-type nil 'agenda)]
1718 ["Show some entry text" org-agenda-entry-text-mode
1719 :style toggle :selected org-agenda-entry-text-mode
1722 ["Show Logbook entries" org-agenda-log-mode
1723 :style toggle :selected org-agenda-show-log
1724 :active (org-agenda-check-type nil 'agenda 'timeline)
1725 :keys "v l (or just l)"]
1726 ["Include archived trees" org-agenda-archives-mode
1727 :style toggle :selected org-agenda-archives-mode :active t
1729 ["Include archive files" (org-agenda-archives-mode t)
1730 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1733 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1734 ["Write view to file" org-write-agenda t]
1735 ["Rebuild buffer" org-agenda-redo t]
1736 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1738 ["Show original entry" org-agenda-show t]
1739 ["Go To (other window)" org-agenda-goto t]
1740 ["Go To (this window)" org-agenda-switch-to t]
1741 ["Follow Mode" org-agenda-follow-mode
1742 :style toggle :selected org-agenda-follow-mode :active t]
1743 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1746 ["Cycle TODO" org-agenda-todo t]
1747 ["Next TODO set" org-agenda-todo-nextset t]
1748 ["Previous TODO set" org-agenda-todo-previousset t]
1749 ["Add note" org-agenda-add-note t])
1750 ("Archive/Refile/Delete"
1751 ["Archive default" org-agenda-archive-default t]
1752 ["Archive default" org-agenda-archive-default-with-confirmation t]
1753 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1754 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1755 ["Archive subtree" org-agenda-archive t]
1757 ["Refile" org-agenda-refile t]
1759 ["Delete subtree" org-agenda-kill t])
1761 ["Mark entry" org-agenda-bulk-mark t]
1762 ["Unmark entry" org-agenda-bulk-unmark t]
1763 ["Act on all marked" org-agenda-bulk-action t]
1764 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1766 ("Tags and Properties"
1767 ["Show all Tags" org-agenda-show-tags t]
1768 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1769 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1771 ["Column View" org-columns t])
1772 ("Deadline/Schedule"
1773 ["Schedule" org-agenda-schedule t]
1774 ["Set Deadline" org-agenda-deadline t]
1776 ["Mark item" org-agenda-action :active t :keys "k m"]
1777 ["Show mark item" org-agenda-action :active t :keys "k v"]
1778 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1779 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1781 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1782 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1783 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1784 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1785 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1786 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1787 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1789 ["Clock in" org-agenda-clock-in t]
1790 ["Clock out" org-agenda-clock-out t]
1791 ["Clock cancel" org-agenda-clock-cancel t]
1792 ["Goto running clock" org-clock-goto t]
1794 ["Set Effort" org-agenda-set-effort t]
1795 ["Change clocked effort" org-clock-modify-effort-estimate
1796 (org-clock-is-active)])
1798 ["Set Priority" org-agenda-priority t]
1799 ["Increase Priority" org-agenda-priority-up t]
1800 ["Decrease Priority" org-agenda-priority-down t]
1801 ["Show Priority" org-agenda-show-priority t])
1803 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1804 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1805 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1806 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1807 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1808 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1810 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1812 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1815 ["Push Files and Views" org-mobile-push t]
1816 ["Get Captured and Flagged" org-mobile-pull t]
1817 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1818 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1820 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1822 ["Quit" org-agenda-quit t]
1823 ["Exit and Release Buffers" org-agenda-exit t]
1828 (defvar org-agenda-allow-remote-undo t
1829 "Non-nil means allow remote undo from the agenda buffer.")
1830 (defvar org-agenda-undo-list nil
1831 "List of undoable operations in the agenda since last refresh.")
1832 (defvar org-agenda-undo-has-started-in nil
1833 "Buffers that have already seen `undo-start' in the current undo sequence.")
1834 (defvar org-agenda-pending-undo-list nil
1835 "In a series of undo commands, this is the list of remaining undo items.")
1838 (defun org-agenda-undo ()
1839 "Undo a remote editing step in the agenda.
1840 This undoes changes both in the agenda buffer and in the remote buffer
1841 that have been changed along."
1843 (or org-agenda-allow-remote-undo
1844 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1845 (if (not (eq this-command last-command))
1846 (setq org-agenda-undo-has-started-in nil
1847 org-agenda-pending-undo-list org-agenda-undo-list))
1848 (if (not org-agenda-pending-undo-list)
1849 (error "No further undo information"))
1850 (let* ((entry (pop org-agenda-pending-undo-list))
1851 buf line cmd rembuf)
1852 (setq cmd (pop entry) line (pop entry))
1853 (setq rembuf (nth 2 entry))
1854 (org-with-remote-undo rembuf
1855 (while (bufferp (setq buf (pop entry)))
1857 (with-current-buffer buf
1858 (let ((last-undo-buffer buf)
1859 (inhibit-read-only t))
1860 (unless (memq buf org-agenda-undo-has-started-in)
1861 (push buf org-agenda-undo-has-started-in)
1862 (make-local-variable 'pending-undo-list)
1864 (while (and pending-undo-list
1865 (listp pending-undo-list)
1866 (not (car pending-undo-list)))
1867 (pop pending-undo-list))
1869 (org-goto-line line)
1870 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1872 (defun org-verify-change-for-undo (l1 l2)
1873 "Verify that a real change occurred between the undo lists L1 and L2."
1874 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1875 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1880 (defvar org-agenda-restrict nil)
1881 (defvar org-agenda-restrict-begin (make-marker))
1882 (defvar org-agenda-restrict-end (make-marker))
1883 (defvar org-agenda-last-dispatch-buffer nil)
1884 (defvar org-agenda-overriding-restriction nil)
1887 (defun org-agenda (&optional arg keys restriction)
1888 "Dispatch agenda commands to collect entries to the agenda buffer.
1889 Prompts for a command to execute. Any prefix arg will be passed
1890 on to the selected command. The default selections are:
1892 a Call `org-agenda-list' to display the agenda for current day or week.
1893 t Call `org-todo-list' to display the global todo list.
1894 T Call `org-todo-list' to display the global todo list, select only
1895 entries with a specific TODO keyword (the user gets a prompt).
1896 m Call `org-tags-view' to display headlines with tags matching
1897 a condition (the user is prompted for the condition).
1898 M Like `m', but select only TODO entries, no ordinary headlines.
1899 L Create a timeline for the current buffer.
1900 e Export views to associated files.
1901 s Search entries for keywords.
1902 / Multi occur across all agenda files and also files listed
1903 in `org-agenda-text-search-extra-files'.
1904 < Restrict agenda commands to buffer, subtree, or region.
1905 Press several times to get the desired effect.
1906 > Remove a previous restriction.
1907 # List \"stuck\" projects.
1908 ! Configure what \"stuck\" means.
1909 C Configure custom agenda commands.
1911 More commands can be added by configuring the variable
1912 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1913 searches can be pre-defined in this way.
1915 If the current buffer is in Org-mode and visiting a file, you can also
1916 first press `<' once to indicate that the agenda should be temporarily
1917 \(until the next use of \\[org-agenda]) restricted to the current file.
1918 Pressing `<' twice means to restrict to the current subtree or region
1922 (let* ((prefix-descriptions nil)
1923 (org-agenda-window-setup (if (equal (buffer-name)
1924 org-agenda-buffer-name)
1926 org-agenda-window-setup))
1927 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1928 (org-agenda-custom-commands
1929 ;; normalize different versions
1933 (cond ((stringp (cdr x))
1934 (push x prefix-descriptions)
1936 ((stringp (nth 1 x)) x)
1937 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1938 (t (cons (car x) (cons "" (cdr x))))))
1939 org-agenda-custom-commands)))
1940 (buf (current-buffer))
1941 (bfn (buffer-file-name (buffer-base-buffer)))
1942 entry key type match lprops ans)
1943 ;; Turn off restriction unless there is an overriding one,
1944 (unless org-agenda-overriding-restriction
1945 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
1946 ;; There is a request to keep the file list in place
1947 (put 'org-agenda-files 'org-restrict nil))
1948 (setq org-agenda-restrict nil)
1949 (move-marker org-agenda-restrict-begin nil)
1950 (move-marker org-agenda-restrict-end nil))
1951 ;; Delete old local properties
1952 (put 'org-agenda-redo-command 'org-lprops nil)
1953 ;; Remember where this call originated
1954 (setq org-agenda-last-dispatch-buffer (current-buffer))
1956 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1958 restriction (cdr ans)))
1959 ;; Establish the restriction, if any
1960 (when (and (not org-agenda-overriding-restriction) restriction)
1961 (put 'org-agenda-files 'org-restrict (list bfn))
1963 ((eq restriction 'region)
1964 (setq org-agenda-restrict t)
1965 (move-marker org-agenda-restrict-begin (region-beginning))
1966 (move-marker org-agenda-restrict-end (region-end)))
1967 ((eq restriction 'subtree)
1969 (setq org-agenda-restrict t)
1970 (org-back-to-heading t)
1971 (move-marker org-agenda-restrict-begin (point))
1972 (move-marker org-agenda-restrict-end
1973 (progn (org-end-of-subtree t)))))))
1975 ;; For example the todo list should not need it (but does...)
1977 ((setq entry (assoc keys org-agenda-custom-commands))
1978 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
1980 (setq type (nth 2 entry) match (eval (nth 3 entry))
1981 lprops (nth 4 entry))
1982 (put 'org-agenda-redo-command 'org-lprops lprops)
1985 (org-let lprops '(org-agenda-list current-prefix-arg)))
1987 (org-let lprops '(org-todo-list current-prefix-arg)))
1989 (org-let lprops '(org-search-view current-prefix-arg match nil)))
1991 (org-let lprops '(org-agenda-list-stuck-projects
1992 current-prefix-arg)))
1994 (org-let lprops '(org-tags-view current-prefix-arg match)))
1995 ((eq type 'tags-todo)
1996 (org-let lprops '(org-tags-view '(4) match)))
1998 (org-let lprops '(org-todo-list match)))
1999 ((eq type 'tags-tree)
2000 (org-check-for-org-mode)
2001 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2002 ((eq type 'todo-tree)
2003 (org-check-for-org-mode)
2005 '(org-occur (concat "^" outline-regexp "[ \t]*"
2006 (regexp-quote match) "\\>"))))
2007 ((eq type 'occur-tree)
2008 (org-check-for-org-mode)
2009 (org-let lprops '(org-occur match)))
2011 (org-let lprops '(funcall type match)))
2013 (org-let lprops '(funcall type match)))
2014 (t (error "Invalid custom agenda command type %s" type))))
2015 (org-run-agenda-series (nth 1 entry) (cddr entry))))
2017 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2018 (customize-variable 'org-agenda-custom-commands))
2019 ((equal keys "a") (call-interactively 'org-agenda-list))
2020 ((equal keys "s") (call-interactively 'org-search-view))
2021 ((equal keys "t") (call-interactively 'org-todo-list))
2022 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2023 ((equal keys "m") (call-interactively 'org-tags-view))
2024 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2025 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2026 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2030 (unless (current-message)
2031 (let* ((m (org-agenda-get-any-marker))
2032 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2035 "FLAGGING-NOTE ([?] for more info): "
2037 (replace-regexp-in-string
2039 (copy-sequence note))
2040 nil 'face 'org-warning)))))))
2043 (unless (org-mode-p)
2044 (error "This is not an Org-mode file"))
2046 (put 'org-agenda-files 'org-restrict (list bfn))
2047 (org-call-with-arg 'org-timeline arg)))
2048 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2049 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2050 ((equal keys "!") (customize-variable 'org-stuck-projects))
2051 (t (error "Invalid agenda key"))))))
2053 (defun org-agenda-normalize-custom-commands (cmds)
2057 (cond ((stringp (cdr x)) nil)
2058 ((stringp (nth 1 x)) x)
2059 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2060 (t (cons (car x) (cons "" (cdr x))))))
2063 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2064 "The user interface for selecting an agenda command."
2066 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2067 (restrict-ok (and bfn (org-mode-p)))
2068 (region-p (org-region-active-p))
2069 (custom org-agenda-custom-commands)
2071 restriction second-time
2072 c entry key type match prefixes rmheader header-end custom1 desc)
2073 (save-window-excursion
2074 (delete-other-windows)
2075 (org-switch-to-buffer-other-window " *Agenda Commands*")
2077 (insert (eval-when-compile
2080 Press key for an agenda command: < Buffer, subtree/region restriction
2081 -------------------------------- > Remove restriction
2082 a Agenda for current week or day e Export agenda views
2083 t List of all TODO entries T Entries with special TODO kwd
2084 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2085 L Timeline for current buffer # List stuck projects (!=configure)
2086 s Search for keywords C Configure custom agenda commands
2087 / Multi-occur ? Find :FLAGGED: entries
2090 (while (string-match
2091 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2093 (setq start (match-end 0))
2094 (add-text-properties (match-beginning 2) (match-end 2)
2095 '(face bold) header))
2097 (setq header-end (move-marker (make-marker) (point)))
2099 (setq custom1 custom)
2100 (when (eq rmheader t)
2102 (re-search-forward ":" nil t)
2103 (delete-region (match-end 0) (point-at-eol))
2106 (delete-region (match-end 0) (point-at-eol))
2107 (move-marker header-end (match-end 0)))
2108 (goto-char header-end)
2109 (delete-region (point) (point-max))
2110 (while (setq entry (pop custom1))
2111 (setq key (car entry) desc (nth 1 entry)
2113 match (nth 3 entry))
2114 (if (> (length key) 1)
2115 (add-to-list 'prefixes (string-to-char key))
2119 (org-add-props (copy-sequence key)
2122 ((string-match "\\S-" desc) desc)
2123 ((eq type 'agenda) "Agenda for current week or day")
2124 ((eq type 'alltodo) "List of all TODO entries")
2125 ((eq type 'search) "Word search")
2126 ((eq type 'stuck) "List of stuck projects")
2127 ((eq type 'todo) "TODO keyword")
2128 ((eq type 'tags) "Tags query")
2129 ((eq type 'tags-todo) "Tags (TODO)")
2130 ((eq type 'tags-tree) "Tags tree")
2131 ((eq type 'todo-tree) "TODO kwd tree")
2132 ((eq type 'occur-tree) "Occur tree")
2133 ((functionp type) (if (symbolp type)
2135 "Lambda expression"))
2139 (setq match (copy-sequence match))
2140 (org-add-props match nil 'face 'org-warning))
2142 (format "set of %d commands" (length match)))
2148 (org-add-props (char-to-string x)
2150 (or (cdr (assoc (concat selstring (char-to-string x))
2151 prefix-descriptions))
2154 (goto-char (point-min))
2156 (if (not (pos-visible-in-window-p (point-max)))
2157 (org-fit-window-to-buffer))
2158 (setq second-time t)
2159 (org-fit-window-to-buffer))
2160 (message "Press key for agenda command%s:"
2161 (if (or restrict-ok org-agenda-overriding-restriction)
2162 (if org-agenda-overriding-restriction
2163 " (restriction lock active)"
2165 (format " (restricted to %s)" restriction)
2168 (setq c (read-char-exclusive))
2171 ((assoc (char-to-string c) custom)
2172 (setq selstring (concat selstring (char-to-string c)))
2173 (throw 'exit (cons selstring restriction)))
2175 (setq selstring (concat selstring (char-to-string c))
2177 rmheader (or rmheader t)
2178 custom (delq nil (mapcar
2180 (if (or (= (length (car x)) 1)
2181 (/= (string-to-char (car x)) c))
2183 (cons (substring (car x) 1) (cdr x))))
2185 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2186 (message "Restriction is only possible in Org-mode buffers")
2189 (org-agenda-remove-restriction-lock 'noupdate)
2190 (setq restriction 'buffer))
2192 (org-agenda-remove-restriction-lock 'noupdate)
2193 (setq restriction (if region-p 'region 'subtree)))
2195 (org-agenda-remove-restriction-lock 'noupdate)
2198 ((eq restriction 'buffer)
2199 (if region-p 'region 'subtree))
2200 ((memq restriction '(subtree region))
2204 (org-agenda-remove-restriction-lock 'noupdate)
2205 (setq restriction nil))
2206 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2207 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2208 ((and (> (length selstring) 0) (eq c ?\d))
2210 (org-agenda-get-restriction-and-command prefix-descriptions))
2212 ((equal c ?q) (error "Abort"))
2213 (t (error "Invalid key %c" c))))))))
2215 (defun org-run-agenda-series (name series)
2216 (org-let (nth 1 series) '(org-prepare-agenda name))
2217 (let* ((org-agenda-multi t)
2218 (redo (list 'org-run-agenda-series name (list 'quote series)))
2220 (gprops (nth 1 series))
2221 match ;; The byte compiler incorrectly complains about this. Keep it!
2223 (while (setq cmd (pop cmds))
2224 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2227 (org-let2 gprops lprops
2228 '(call-interactively 'org-agenda-list)))
2230 (org-let2 gprops lprops
2231 '(call-interactively 'org-todo-list)))
2233 (org-let2 gprops lprops
2234 '(org-search-view current-prefix-arg match nil)))
2236 (org-let2 gprops lprops
2237 '(call-interactively 'org-agenda-list-stuck-projects)))
2239 (org-let2 gprops lprops
2240 '(org-tags-view current-prefix-arg match)))
2241 ((eq type 'tags-todo)
2242 (org-let2 gprops lprops
2243 '(org-tags-view '(4) match)))
2245 (org-let2 gprops lprops
2246 '(org-todo-list match)))
2248 (org-let2 gprops lprops
2249 '(funcall type match)))
2250 (t (error "Invalid type in command series"))))
2252 (setq org-agenda-redo-command redo)
2253 (goto-char (point-min)))
2254 (org-fit-agenda-window)
2255 (org-let (nth 1 series) '(org-finalize-agenda)))
2258 (defmacro org-batch-agenda (cmd-key &rest parameters)
2259 "Run an agenda command in batch mode and send the result to STDOUT.
2260 If CMD-KEY is a string of length 1, it is used as a key in
2261 `org-agenda-custom-commands' and triggers this command. If it is a
2262 longer string it is used as a tags/todo match string.
2263 Paramters are alternating variable names and values that will be bound
2264 before running the agenda command."
2267 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2268 (if (> (length cmd-key) 2)
2269 (eval (list 'let (nreverse pars)
2270 (list 'org-tags-view nil cmd-key)))
2271 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2272 (set-buffer org-agenda-buffer-name)
2273 (princ (org-encode-for-stdout (buffer-string)))))
2275 ;(defun org-encode-for-stdout (string)
2276 ; (if (fboundp 'encode-coding-string)
2277 ; (encode-coding-string string buffer-file-coding-system)
2280 (defun org-encode-for-stdout (string)
2283 (defvar org-agenda-info nil)
2286 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2287 "Run an agenda command in batch mode and send the result to STDOUT.
2288 If CMD-KEY is a string of length 1, it is used as a key in
2289 `org-agenda-custom-commands' and triggers this command. If it is a
2290 longer string it is used as a tags/todo match string.
2291 Paramters are alternating variable names and values that will be bound
2292 before running the agenda command.
2294 The output gives a line for each selected agenda item. Each
2295 item is a list of comma-separated values, like this:
2297 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2299 category The category of the item
2300 head The headline, without TODO kwd, TAGS and PRIORITY
2301 type The type of the agenda entry, can be
2302 todo selected in TODO match
2303 tagsmatch selected in tags match
2304 diary imported from diary
2305 deadline a deadline on given date
2306 scheduled scheduled on given date
2307 timestamp entry has timestamp on given date
2308 closed entry was closed on given date
2309 upcoming-deadline warning about deadline
2310 past-scheduled forwarded scheduled item
2311 block entry has date block including g. date
2312 todo The todo keyword, if any
2313 tags All tags including inherited ones, separated by colons
2314 date The relevant date, like 2007-2-14
2315 time The time, like 15:00-16:50
2316 extra Sting with extra planning info
2317 priority-l The priority letter if any was given
2318 priority-n The computed numerical priority
2319 agenda-day The day in the agenda where this is listed"
2323 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2324 (push (list 'org-agenda-remove-tags t) pars)
2325 (if (> (length cmd-key) 2)
2326 (eval (list 'let (nreverse pars)
2327 (list 'org-tags-view nil cmd-key)))
2328 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2329 (set-buffer org-agenda-buffer-name)
2330 (let* ((lines (org-split-string (buffer-string) "\n"))
2332 (while (setq line (pop lines))
2334 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2335 (setq org-agenda-info
2336 (org-fix-agenda-info (text-properties-at 0 line)))
2338 (org-encode-for-stdout
2339 (mapconcat 'org-agenda-export-csv-mapper
2340 '(org-category txt type todo tags date time extra
2341 priority-letter priority agenda-day)
2345 (defun org-fix-agenda-info (props)
2346 "Make sure all properties on an agenda item have a canonical form,
2347 so the export commands can easily use it."
2349 (when (setq tmp (plist-get props 'tags))
2350 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2351 (when (setq tmp (plist-get props 'date))
2352 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2353 (let ((calendar-date-display-form '(year "-" month "-" day)))
2354 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2356 (setq tmp (calendar-date-string tmp)))
2357 (setq props (plist-put props 'date tmp)))
2358 (when (setq tmp (plist-get props 'day))
2359 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2360 (let ((calendar-date-display-form '(year "-" month "-" day)))
2361 (setq tmp (calendar-date-string tmp)))
2362 (setq props (plist-put props 'day tmp))
2363 (setq props (plist-put props 'agenda-day tmp)))
2364 (when (setq tmp (plist-get props 'txt))
2365 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2366 (plist-put props 'priority-letter (match-string 1 tmp))
2367 (setq tmp (replace-match "" t t tmp)))
2368 (when (and (setq re (plist-get props 'org-todo-regexp))
2369 (setq re (concat "\\`\\.*" re " ?"))
2370 (string-match re tmp))
2371 (plist-put props 'todo (match-string 1 tmp))
2372 (setq tmp (replace-match "" t t tmp)))
2373 (plist-put props 'txt tmp)))
2376 (defun org-agenda-export-csv-mapper (prop)
2377 (let ((res (plist-get org-agenda-info prop)))
2382 (t (prin1-to-string res))))
2383 (while (string-match "," res)
2384 (setq res (replace-match ";" t t res)))
2389 (defun org-store-agenda-views (&rest parameters)
2391 (eval (list 'org-batch-store-agenda-views)))
2393 ;; FIXME, why is this a macro?????
2395 (defmacro org-batch-store-agenda-views (&rest parameters)
2396 "Run all custom agenda commands that have a file argument."
2397 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2399 (dir default-directory)
2400 pars cmd thiscmdkey files opts cmd-or-set)
2402 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2403 (setq pars (reverse pars))
2404 (save-window-excursion
2406 (setq cmd (pop cmds)
2407 thiscmdkey (car cmd)
2408 cmd-or-set (nth 2 cmd)
2409 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2410 files (nth (if (listp cmd-or-set) 4 5) cmd))
2411 (if (stringp files) (setq files (list files)))
2413 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2414 (list 'org-agenda nil thiscmdkey)))
2415 (set-buffer org-agenda-buffer-name)
2417 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2418 (list 'org-write-agenda
2419 (expand-file-name (pop files) dir) nil t))))
2420 (and (get-buffer org-agenda-buffer-name)
2421 (kill-buffer org-agenda-buffer-name)))))))
2423 (defun org-agenda-mark-header-line (pos)
2424 "Mark the line at POS as an agenda structure header."
2427 (put-text-property (point-at-bol) (point-at-eol)
2428 'org-agenda-structural-header t)
2429 (when org-agenda-title-append
2430 (put-text-property (point-at-bol) (point-at-eol)
2431 'org-agenda-title-append org-agenda-title-append))))
2433 (defvar org-mobile-creating-agendas)
2434 (defun org-write-agenda (file &optional open nosettings)
2435 "Write the current buffer (an agenda view) as a file.
2436 Depending on the extension of the file name, plain text (.txt),
2437 HTML (.html or .htm) or Postscript (.ps) is produced.
2438 If the extension is .ics, run icalendar export over all files used
2439 to construct the agenda and limit the export to entries listed in the
2441 With prefix argument OPEN, open the new file immediately.
2442 If NOSETTINGS is given, do not scope the settings of
2443 `org-agenda-exporter-settings' into the export commands. This is used when
2444 the settings have already been scoped and we do not wish to overrule other,
2445 higher priority settings."
2446 (interactive "FWrite agenda to file: \nP")
2447 (if (not (file-writable-p file))
2448 (error "Cannot write agenda to file %s" file))
2450 ((string-match "\\.html?\\'" file) (require 'htmlize))
2451 ((string-match "\\.ps\\'" file) (require 'ps-print)))
2452 (org-let (if nosettings nil org-agenda-exporter-settings)
2454 (save-window-excursion
2455 (org-agenda-mark-filtered-text)
2456 (let ((bs (copy-sequence (buffer-string))) beg)
2457 (org-agenda-unmark-filtered-text)
2460 (org-agenda-remove-marked-text 'org-filtered)
2461 (while (setq beg (text-property-any (point-min) (point-max)
2464 beg (or (next-single-property-change beg 'org-filtered)
2466 (run-hooks 'org-agenda-before-write-hook)
2468 ((org-bound-and-true-p org-mobile-creating-agendas)
2469 (org-mobile-write-agenda-for-mobile file))
2470 ((string-match "\\.html?\\'" file)
2471 (set-buffer (htmlize-buffer (current-buffer)))
2473 (when (and org-agenda-export-html-style
2474 (string-match "<style>" org-agenda-export-html-style))
2475 ;; replace <style> section with org-agenda-export-html-style
2476 (goto-char (point-min))
2477 (kill-region (- (search-forward "<style") 6)
2478 (search-forward "</style>"))
2479 (insert org-agenda-export-html-style))
2481 (kill-buffer (current-buffer))
2482 (message "HTML written to %s" file))
2483 ((string-match "\\.ps\\'" file)
2485 ,(flet ((ps-get-buffer-name () "Agenda View"))
2486 (ps-print-buffer-with-faces file))
2487 (message "Postscript written to %s" file))
2488 ((string-match "\\.pdf\\'" file)
2490 ,(flet ((ps-get-buffer-name () "Agenda View"))
2491 (ps-print-buffer-with-faces
2492 (concat (file-name-sans-extension file) ".ps")))
2493 (call-process "ps2pdf" nil nil nil
2495 (concat (file-name-sans-extension file) ".ps"))
2496 (expand-file-name file))
2497 (message "PDF written to %s" file))
2498 ((string-match "\\.ics\\'" file)
2499 (require 'org-icalendar)
2500 (let ((org-agenda-marker-table
2501 (org-create-marker-find-array
2502 (org-agenda-collect-markers)))
2503 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2504 (org-combined-agenda-icalendar-file file))
2505 (apply 'org-export-icalendar 'combine
2506 (org-agenda-files nil 'ifmode))))
2508 (let ((bs (buffer-string)))
2513 (kill-buffer (current-buffer))
2514 (message "Plain text written to %s" file))))))))
2515 (set-buffer org-agenda-buffer-name))
2516 (when open (org-open-file file)))
2518 (defvar org-agenda-filter-overlays nil)
2520 (defun org-agenda-mark-filtered-text ()
2521 "Mark all text hidden by filtering with a text property."
2522 (let ((inhibit-read-only t))
2525 (when (equal (overlay-buffer o) (current-buffer))
2527 (overlay-start o) (overlay-end o)
2529 org-agenda-filter-overlays)))
2531 (defun org-agenda-unmark-filtered-text ()
2532 "Remove the filtering text property."
2533 (let ((inhibit-read-only t))
2534 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2536 (defun org-agenda-remove-marked-text (property &optional value)
2537 "Delete all text marked with VALUE of PROPERTY.
2538 VALUE defaults to t."
2540 (setq value (or value t))
2541 (while (setq beg (text-property-any (point-min) (point-max)
2544 beg (or (next-single-property-change beg 'org-filtered)
2547 (defun org-agenda-add-entry-text ()
2548 "Add entry text to agenda lines.
2549 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2550 entry text following headings shown in the agenda.
2551 Drawers will be excluded, also the line with scheduling/deadline info."
2552 (when (and (> org-agenda-add-entry-text-maxlines 0)
2553 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2555 (goto-char (point-min))
2557 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2558 (beginning-of-line 2)
2559 (setq txt (org-agenda-get-some-entry-text
2560 m org-agenda-add-entry-text-maxlines " > "))
2562 (if (string-match "\\S-" txt) (insert "\n" txt)))))))
2564 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2566 "Extract entry text from MARKER, at most N-LINES lines.
2567 This will ignore drawers etc, just get the text.
2568 If INDENT is given, prefix every line with this string. If KEEP is
2569 given, it is a list of symbols, defining stuff that should not be
2570 removed from the entry content. Currently only `planning' is allowed here."
2571 (let (txt drawer-re kwd-time-re ind)
2573 (with-current-buffer (marker-buffer marker)
2574 (if (not (org-mode-p))
2581 (setq txt (buffer-substring
2582 (min (1+ (point)) (point-max))
2583 (progn (outline-next-heading) (point)))
2584 drawer-re org-drawer-regexp
2585 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2589 (when org-agenda-add-entry-text-descriptive-links
2590 (goto-char (point-min))
2591 (while (org-activate-bracket-links (point-max))
2592 (add-text-properties (match-beginning 0) (match-end 0)
2594 (goto-char (point-min))
2595 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2596 (set-text-properties (match-beginning 0) (match-end 0)
2598 (goto-char (point-min))
2599 (while (re-search-forward drawer-re nil t)
2602 (progn (re-search-forward
2603 "^[ \t]*:END:.*\n?" nil 'move)
2605 (unless (member 'planning keep)
2606 (goto-char (point-min))
2607 (while (re-search-forward kwd-time-re nil t)
2608 (replace-match "")))
2609 (goto-char (point-min))
2610 (when org-agenda-entry-text-exclude-regexps
2611 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2612 (while (setq re (pop re-list))
2613 (goto-char (point-min))
2614 (while (re-search-forward re nil t)
2615 (replace-match "")))))
2616 (goto-char (point-max))
2617 (skip-chars-backward " \t\n")
2618 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2620 ;; find and remove min common indentation
2621 (goto-char (point-min))
2622 (untabify (point-min) (point-max))
2623 (setq ind (org-get-indentation))
2625 (unless (looking-at "[ \t]*$")
2626 (setq ind (min ind (org-get-indentation))))
2627 (beginning-of-line 2))
2628 (goto-char (point-min))
2630 (unless (looking-at "[ \t]*$")
2631 (move-to-column ind)
2632 (delete-region (point-at-bol) (point)))
2633 (beginning-of-line 2))
2635 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2637 (goto-char (point-min))
2639 (while (and (not (eobp)) (re-search-forward "^" nil t))
2640 (replace-match indent t t)))
2641 (goto-char (point-min))
2642 (while (looking-at "[ \t]*\n") (replace-match ""))
2643 (goto-char (point-max))
2644 (when (> (org-current-line)
2646 (org-goto-line (1+ n-lines))
2648 (setq txt (buffer-substring (point-min) (point)))))))))
2651 (defun org-agenda-collect-markers ()
2652 "Collect the markers pointing to entries in the agenda buffer."
2655 (goto-char (point-min))
2657 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2658 (org-get-at-bol 'org-marker)))
2660 (beginning-of-line 2)))
2661 (nreverse markers)))
2663 (defun org-create-marker-find-array (marker-list)
2664 "Create a alist of files names with all marker positions in that file."
2666 (while (setq m (pop marker-list))
2667 (setq p (marker-position m)
2668 f (buffer-file-name (or (buffer-base-buffer
2670 (marker-buffer m))))
2671 (if (setq a (assoc f tbl))
2672 (push (marker-position m) (cdr a))
2673 (push (list f p) tbl)))
2674 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2677 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2678 (defun org-check-agenda-marker-table ()
2679 "Check of the current entry is on the marker list."
2680 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2682 (and (setq a (assoc file org-agenda-marker-table))
2685 (org-back-to-heading t)
2686 (member (point) (cdr a)))))))
2688 (defun org-check-for-org-mode ()
2689 "Make sure current buffer is in org-mode. Error if not."
2691 (error "Cannot execute org-mode agenda command on buffer in %s"
2694 (defun org-fit-agenda-window ()
2695 "Fit the window to the buffer size."
2696 (and (memq org-agenda-window-setup '(reorganize-frame))
2697 (fboundp 'fit-window-to-buffer)
2698 (org-fit-window-to-buffer
2700 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2701 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2703 ;;; Agenda prepare and finalize
2705 (defvar org-agenda-multi nil) ; dynamically scoped
2706 (defvar org-agenda-buffer-name "*Org Agenda*")
2707 (defvar org-pre-agenda-window-conf nil)
2708 (defvar org-agenda-columns-active nil)
2709 (defvar org-agenda-name nil)
2710 (defvar org-agenda-filter nil)
2711 (defvar org-agenda-filter-preset nil
2712 "A preset of the tags filter used for secondary agenda filtering.
2713 This must be a list of strings, each string must be a single tag preceeded
2715 This variable should not be set directly, but agenda custom commands can
2716 bind it in the options section.")
2718 (defun org-prepare-agenda (&optional name)
2719 (setq org-todo-keywords-for-agenda nil)
2720 (setq org-done-keywords-for-agenda nil)
2721 (setq org-drawers-for-agenda nil)
2722 (unless org-agenda-persistent-filter
2723 (setq org-agenda-filter nil))
2724 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2725 (if org-agenda-multi
2727 (setq buffer-read-only nil)
2728 (goto-char (point-max))
2729 (unless (or (bobp) org-agenda-compact-blocks)
2731 (if (stringp org-agenda-block-separator)
2732 org-agenda-block-separator
2733 (make-string (window-width) org-agenda-block-separator))
2735 (narrow-to-region (point) (point-max)))
2736 (org-agenda-reset-markers)
2737 (setq org-agenda-contributing-files nil)
2738 (setq org-agenda-columns-active nil)
2739 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2740 (setq org-todo-keywords-for-agenda
2741 (org-uniquify org-todo-keywords-for-agenda))
2742 (setq org-done-keywords-for-agenda
2743 (org-uniquify org-done-keywords-for-agenda))
2744 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2745 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2746 (awin (get-buffer-window abuf)))
2748 ((equal (current-buffer) abuf) nil)
2749 (awin (select-window awin))
2750 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2751 ((equal org-agenda-window-setup 'current-window)
2752 (switch-to-buffer abuf))
2753 ((equal org-agenda-window-setup 'other-window)
2754 (org-switch-to-buffer-other-window abuf))
2755 ((equal org-agenda-window-setup 'other-frame)
2756 (switch-to-buffer-other-frame abuf))
2757 ((equal org-agenda-window-setup 'reorganize-frame)
2758 (delete-other-windows)
2759 (org-switch-to-buffer-other-window abuf))))
2760 (setq buffer-read-only nil)
2761 (let ((inhibit-read-only t)) (erase-buffer))
2763 (and name (not org-agenda-name)
2764 (org-set-local 'org-agenda-name name)))
2765 (setq buffer-read-only nil))
2767 (defun org-finalize-agenda ()
2768 "Finishing touch for the agenda buffer, called just before displaying it."
2769 (unless org-agenda-multi
2771 (let ((inhibit-read-only t))
2772 (goto-char (point-min))
2773 (while (org-activate-bracket-links (point-max))
2774 (add-text-properties (match-beginning 0) (match-end 0)
2776 (org-agenda-align-tags)
2777 (unless org-agenda-with-colors
2778 (remove-text-properties (point-min) (point-max) '(face nil))))
2779 (if (and (boundp 'org-agenda-overriding-columns-format)
2780 org-agenda-overriding-columns-format)
2781 (org-set-local 'org-agenda-overriding-columns-format
2782 org-agenda-overriding-columns-format))
2783 (if (and (boundp 'org-agenda-view-columns-initially)
2784 org-agenda-view-columns-initially)
2785 (org-agenda-columns))
2786 (when org-agenda-fontify-priorities
2787 (org-agenda-fontify-priorities))
2788 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2789 (org-agenda-dim-blocked-tasks))
2790 (org-agenda-mark-clocking-task)
2791 (when org-agenda-entry-text-mode
2792 (org-agenda-entry-text-hide)
2793 (org-agenda-entry-text-show))
2794 (if (functionp 'org-habit-insert-consistency-graphs)
2795 (org-habit-insert-consistency-graphs))
2796 (run-hooks 'org-finalize-agenda-hook)
2797 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2798 (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
2799 (org-agenda-filter-apply org-agenda-filter))
2802 (defun org-agenda-mark-clocking-task ()
2803 "Mark the current clock entry in the agenda if it is present."
2805 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
2806 (delete-overlay o)))
2807 (overlays-in (point-min) (point-max)))
2808 (when (marker-buffer org-clock-hd-marker)
2810 (goto-char (point-min))
2812 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2814 (when (equal (org-get-at-bol 'org-hd-marker)
2815 org-clock-hd-marker)
2816 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
2817 (overlay-put ov 'type 'org-agenda-clocking)
2818 (overlay-put ov 'face 'org-agenda-clocking)
2819 (overlay-put ov 'help-echo
2820 "The clock is running in this item")))))))
2822 (defun org-agenda-fontify-priorities ()
2823 "Make highest priority lines bold, and lowest italic."
2825 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
2826 (delete-overlay o)))
2827 (overlays-in (point-min) (point-max)))
2829 (let ((inhibit-read-only t)
2831 (goto-char (point-min))
2832 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2833 (setq h (or (get-char-property (point) 'org-highest-priority)
2834 org-highest-priority)
2835 l (or (get-char-property (point) 'org-lowest-priority)
2836 org-lowest-priority)
2837 p (string-to-char (match-string 1))
2838 b (match-beginning 0)
2839 e (if (eq org-agenda-fontify-priorities 'cookies)
2842 ov (make-overlay b e))
2845 (cond ((org-face-from-face-or-color
2847 (cdr (assoc p org-priority-faces))))
2848 ((and (listp org-agenda-fontify-priorities)
2849 (org-face-from-face-or-color
2851 (cdr (assoc p org-agenda-fontify-priorities)))))
2852 ((equal p l) 'italic)
2853 ((equal p h) 'bold)))
2854 (overlay-put ov 'org-type 'org-priority)))))
2856 (defun org-agenda-dim-blocked-tasks ()
2857 "Dim currently blocked TODO's in the agenda display."
2858 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
2859 (delete-overlay o)))
2860 (overlays-in (point-min) (point-max)))
2862 (let ((inhibit-read-only t)
2863 (org-depend-tag-blocked nil)
2864 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2865 org-blocked-by-checkboxes
2866 invis1 b e p ov h l)
2867 (goto-char (point-min))
2868 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2869 (and pos (goto-char (1+ pos))))
2870 (setq org-blocked-by-checkboxes nil invis1 invis)
2871 (let ((marker (org-get-at-bol 'org-hd-marker)))
2873 (not (with-current-buffer (marker-buffer marker)
2876 (if (org-entry-get nil "NOBLOCKING")
2877 t ;; Never block this entry
2878 (run-hook-with-args-until-failure
2880 (list :type 'todo-state-change
2884 (if org-blocked-by-checkboxes (setq invis1 nil))
2886 (max (point-min) (1- (point-at-bol)))
2889 ov (make-overlay b e))
2891 (overlay-put ov 'invisible t)
2892 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2893 (overlay-put ov 'org-type 'org-blocked-todo)))))))
2895 (defvar org-agenda-skip-function nil
2896 "Function to be called at each match during agenda construction.
2897 If this function returns nil, the current match should not be skipped.
2898 Otherwise, the function must return a position from where the search
2899 should be continued.
2900 This may also be a Lisp form, it will be evaluated.
2901 Never set this variable using `setq' or so, because then it will apply
2902 to all future agenda commands. Instead, bind it with `let' to scope
2903 it dynamically into the agenda-constructing command. A good way to set
2904 it is through options in org-agenda-custom-commands.")
2906 (defun org-agenda-skip ()
2907 "Throw to `:skip' in places that should be skipped.
2908 Also moves point to the end of the skipped region, so that search can
2909 continue from there."
2910 (let ((p (point-at-bol)) to fp)
2911 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2912 (get-text-property p :org-archived)
2913 (org-end-of-subtree t)
2915 (and org-agenda-skip-comment-trees
2916 (get-text-property p :org-comment)
2917 (org-end-of-subtree t)
2919 (if (equal (char-after p) ?#) (throw :skip t))
2920 (when (and (or (setq fp (functionp org-agenda-skip-function))
2921 (consp org-agenda-skip-function))
2922 (setq to (save-excursion
2925 (funcall org-agenda-skip-function)
2926 (eval org-agenda-skip-function))))))
2930 (defvar org-agenda-markers nil
2931 "List of all currently active markers created by `org-agenda'.")
2932 (defvar org-agenda-last-marker-time (org-float-time)
2933 "Creation time of the last agenda marker.")
2935 (defun org-agenda-new-marker (&optional pos)
2936 "Return a new agenda marker.
2937 Org-mode keeps a list of these markers and resets them when they are
2939 (let ((m (copy-marker (or pos (point)))))
2940 (setq org-agenda-last-marker-time (org-float-time))
2941 (push m org-agenda-markers)
2944 (defun org-agenda-reset-markers ()
2945 "Reset markers created by `org-agenda'."
2946 (while org-agenda-markers
2947 (move-marker (pop org-agenda-markers) nil)))
2949 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
2950 "Save relative positions of markers in region."
2951 (mapc (lambda (m) (org-check-and-save-marker m beg end))
2952 org-agenda-markers))
2956 (defun org-agenda-entry-text-show-here ()
2957 "Add some text from the entry as context to the current line."
2959 (setq m (org-get-at-bol 'org-hd-marker))
2960 (unless (marker-buffer m)
2961 (error "No marker points to an entry here"))
2962 (setq txt (concat "\n" (org-no-properties
2963 (org-agenda-get-some-entry-text
2964 m org-agenda-entry-text-maxlines " > "))))
2965 (when (string-match "\\S-" txt)
2966 (setq o (make-overlay (point-at-bol) (point-at-eol)))
2967 (overlay-put o 'evaporate t)
2968 (overlay-put o 'org-overlay-type 'agenda-entry-content)
2969 (overlay-put o 'after-string txt))))
2971 (defun org-agenda-entry-text-show ()
2972 "Add entry context for all agenda lines."
2975 (goto-char (point-max))
2976 (beginning-of-line 1)
2978 (when (org-get-at-bol 'org-hd-marker)
2979 (org-agenda-entry-text-show-here))
2980 (beginning-of-line 0))))
2982 (defun org-agenda-entry-text-hide ()
2983 "Remove any shown entry context."
2986 (if (eq (overlay-get o 'org-overlay-type)
2987 'agenda-entry-content)
2988 (progn (delete-overlay o) t)))
2989 (overlays-in (point-min) (point-max)))))
2993 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
2995 (defun org-timeline (&optional include-all)
2996 "Show a time-sorted view of the entries in the current org file.
2997 Only entries with a time stamp of today or later will be listed. With
2998 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2999 under the current date.
3000 If the buffer contains an active region, only check the region for
3003 (org-compile-prefix-format 'timeline)
3004 (org-set-sorting-strategy 'timeline)
3006 (dotodo include-all)
3007 (doclosed org-agenda-show-log)
3008 (entry buffer-file-name)
3009 (date (calendar-current-date))
3010 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3011 (end (if (org-region-active-p) (region-end) (point-max)))
3012 (day-numbers (org-get-all-dates beg end 'no-ranges
3013 t doclosed ; always include today
3014 org-timeline-show-empty-dates))
3015 (org-deadline-warning-days 0)
3016 (org-agenda-only-exact-dates t)
3017 (today (time-to-days (current-time)))
3020 s e rtn d emptyp wd)
3021 (setq org-agenda-redo-command
3023 (list 'org-switch-to-buffer-other-window (current-buffer))
3024 (list 'org-timeline (list 'quote include-all))))
3026 ;; Remove past dates from the list of dates.
3027 (setq day-numbers (delq nil (mapcar (lambda(x)
3028 (if (>= x today) x nil))
3030 (org-prepare-agenda (concat "Timeline "
3031 (file-name-nondirectory buffer-file-name)))
3032 (if doclosed (push :closed args))
3033 (push :timestamp args)
3034 (push :deadline args)
3035 (push :scheduled args)
3037 (if dotodo (push :todo args))
3038 (insert "Timeline of file " entry "\n")
3039 (add-text-properties (point-min) (point)
3040 (list 'face 'org-agenda-structure))
3041 (org-agenda-mark-header-line (point-min))
3042 (while (setq d (pop day-numbers))
3043 (if (and (listp d) (eq (car d) :omitted))
3046 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3047 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3048 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3049 (if (and (>= d today)
3054 (insert (make-string 79 ?-) "\n")))
3055 (setq date (calendar-gregorian-from-absolute d)
3056 wd (calendar-day-of-week date))
3058 (setq rtn (and (not emptyp)
3059 (apply 'org-agenda-get-day-entries entry
3061 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3064 (if (stringp org-agenda-format-date)
3065 (format-time-string org-agenda-format-date
3066 (org-time-from-absolute date))
3067 (funcall org-agenda-format-date date))
3069 (put-text-property s (1- (point)) 'face
3070 (if (member wd org-agenda-weekend-days)
3071 'org-agenda-date-weekend
3073 (put-text-property s (1- (point)) 'org-date-line t)
3074 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3076 (put-text-property s (1- (point)) 'org-today t))
3077 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3078 (put-text-property s (1- (point)) 'day d)))))
3079 (goto-char (point-min))
3080 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3082 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3083 (org-finalize-agenda)
3084 (setq buffer-read-only t)))
3086 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3087 "Return a list of all relevant day numbers from BEG to END buffer positions.
3088 If NO-RANGES is non-nil, include only the start and end dates of a range,
3089 not every single day in the range. If FORCE-TODAY is non-nil, make
3090 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3091 inactive time stamps (those in square brackets) are included.
3092 When EMPTY is non-nil, also include days without any entries."
3094 (if pre-re pre-re "")
3095 (if inactive org-ts-regexp-both org-ts-regexp)))
3096 dates dates1 date day day1 day2 ts1 ts2)
3098 (setq dates (list (time-to-days (current-time)))))
3101 (while (re-search-forward re end t)
3102 (setq day (time-to-days (org-time-string-to-time
3103 (substring (match-string 1) 0 10))))
3104 (or (memq day dates) (push day dates)))
3107 (while (re-search-forward org-tr-regexp end t)
3108 (setq ts1 (substring (match-string 1) 0 10)
3109 ts2 (substring (match-string 2) 0 10)
3110 day1 (time-to-days (org-time-string-to-time ts1))
3111 day2 (time-to-days (org-time-string-to-time ts2)))
3112 (while (< (setq day1 (1+ day1)) day2)
3113 (or (memq day1 dates) (push day1 dates)))))
3114 (setq dates (sort dates '<))
3116 (while (setq day (pop dates))
3117 (setq day2 (car dates))
3119 (when (and day2 empty)
3120 (if (or (eq empty t)
3121 (and (numberp empty) (<= (- day2 day) empty)))
3122 (while (< (setq day (1+ day)) day2)
3123 (push (list day) dates1))
3124 (push (cons :omitted (- day2 day)) dates1))))
3125 (setq dates (nreverse dates1)))
3128 ;;; Agenda Daily/Weekly
3130 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
3131 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3132 "Custom commands can set this variable in the options section.")
3133 (defvar org-agenda-last-arguments nil
3134 "The arguments of the previous call to org-agenda")
3135 (defvar org-starting-day nil) ; local variable in the agenda buffer
3136 (defvar org-agenda-span nil) ; local variable in the agenda buffer
3137 (defvar org-include-all-loc nil) ; local variable
3139 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3140 "List of types searched for when creating the daily/weekly agenda.
3141 This variable is a list of symbols that controls the types of
3142 items that appear in the daily/weekly agenda. Allowed symbols in this
3145 :timestamp List items containing a date stamp or date range matching
3146 the selected date. This includes sexp entries in
3149 :sexp List entries resulting from plain diary-like sexps.
3151 :deadline List deadline due on that date. When the date is today,
3152 also list any deadlines past due, or due within
3153 `org-deadline-warning-days'. `:deadline' must appear before
3154 `:scheduled' if the setting of
3155 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3158 :scheduled List all items which are scheduled for the given date.
3159 The diary for *today* also contains items which were
3160 scheduled earlier and are not yet marked DONE.
3162 By default, all four types are turned on.
3164 Never set this variable globally using `setq', because then it
3165 will apply to all future agenda commands. Instead, bind it with
3166 `let' to scope it dynamically into the the agenda-constructing
3167 command. A good way to set it is through options in
3168 `org-agenda-custom-commands'. For a more flexible (though
3169 somewhat less efficient) way of determining what is included in
3170 the daily/weekly agenda, see `org-agenda-skip-function'.")
3173 (defun org-agenda-list (&optional include-all start-day ndays)
3174 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3175 The view will be for the current day or week, but from the overview buffer
3176 you will be able to go to other days/weeks.
3178 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3179 all unfinished TODO items will also be shown, before the agenda.
3180 This feature is considered obsolete, please use the TODO list or a block
3183 With a numeric prefix argument in an interactive call, the agenda will
3184 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
3185 the number of days. NDAYS defaults to `org-agenda-ndays'.
3187 START-DAY defaults to TODAY, or to the most recent match for the weekday
3188 given in `org-agenda-start-on-weekday'."
3190 (if (and (integerp include-all) (> include-all 0))
3191 (setq ndays include-all include-all nil))
3192 (setq ndays (or ndays org-agenda-ndays)
3193 start-day (or start-day org-agenda-start-day))
3194 (if org-agenda-overriding-arguments
3195 (setq include-all (car org-agenda-overriding-arguments)
3196 start-day (nth 1 org-agenda-overriding-arguments)
3197 ndays (nth 2 org-agenda-overriding-arguments)))
3198 (if (stringp start-day)
3199 ;; Convert to an absolute day number
3200 (setq start-day (time-to-days (org-read-date nil t start-day))))
3201 (setq org-agenda-last-arguments (list include-all start-day ndays))
3202 (org-compile-prefix-format 'agenda)
3203 (org-set-sorting-strategy 'agenda)
3204 (let* ((org-agenda-start-on-weekday
3205 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3206 org-agenda-start-on-weekday nil))
3207 (thefiles (org-agenda-files nil 'ifmode))
3209 (today (time-to-days
3210 (time-subtract (current-time)
3211 (list 0 (* 3600 org-extend-today-until) 0))))
3212 (sd (or start-day today))
3213 (start (if (or (null org-agenda-start-on-weekday)
3214 (< org-agenda-ndays 7))
3216 (let* ((nt (calendar-day-of-week
3217 (calendar-gregorian-from-absolute sd)))
3218 (n1 org-agenda-start-on-weekday)
3220 (- sd (+ (if (< d 0) 7 0) d)))))
3221 (day-numbers (list start))
3223 (inhibit-redisplay (not debug-on-error))
3224 s e rtn rtnall file date d start-pos end-pos todayp nd wd
3225 clocktable-start clocktable-end)
3226 (setq org-agenda-redo-command
3227 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3228 ;; Make the list of days
3229 (setq ndays (or ndays org-agenda-ndays)
3232 (push (1+ (car day-numbers)) day-numbers)
3233 (setq ndays (1- ndays)))
3234 (setq day-numbers (nreverse day-numbers))
3235 (setq clocktable-start (car day-numbers)
3236 clocktable-end (1+ (or (org-last day-numbers) 0)))
3237 (org-prepare-agenda "Day/Week")
3238 (org-set-local 'org-starting-day (car day-numbers))
3239 (org-set-local 'org-include-all-loc include-all)
3240 (org-set-local 'org-agenda-span
3241 (org-agenda-ndays-to-span nd))
3242 (when (and (or include-all org-agenda-include-all-todo)
3243 (member today day-numbers))
3244 (setq files thefiles
3246 (while (setq file (pop files))
3248 (org-check-agenda-file file)
3249 (setq date (calendar-gregorian-from-absolute today)
3250 rtn (org-agenda-get-day-entries
3252 (setq rtnall (append rtnall rtn))))
3254 (insert "All currently open TODO items:\n")
3255 (add-text-properties (point-min) (1- (point))
3256 (list 'face 'org-agenda-structure
3257 'short-heading "All TODO items"))
3258 (org-agenda-mark-header-line (point-min))
3259 (insert (org-finalize-agenda-entries rtnall) "\n")))
3260 (unless org-agenda-compact-blocks
3261 (let* ((d1 (car day-numbers))
3262 (d2 (org-last day-numbers))
3263 (w1 (org-days-to-iso-week d1))
3264 (w2 (org-days-to-iso-week d2)))
3266 (if org-agenda-overriding-header
3267 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3268 nil 'face 'org-agenda-structure) "\n")
3269 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3271 (if (< (- d2 d1) 350)
3273 (format " (W%02d)" w1)
3274 (format " (W%02d-W%02d)" w1 w2))
3277 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3279 (org-agenda-mark-header-line s))
3280 (while (setq d (pop day-numbers))
3281 (setq date (calendar-gregorian-from-absolute d)
3282 wd (calendar-day-of-week date)
3284 (if (or (setq todayp (= d today))
3285 (and (not start-pos) (= d sd)))
3286 (setq start-pos (point))
3287 (if (and start-pos (not end-pos))
3288 (setq end-pos (point))))
3289 (setq files thefiles
3291 (while (setq file (pop files))
3293 (org-check-agenda-file file)
3294 (let ((org-agenda-entry-types org-agenda-entry-types))
3295 (unless org-agenda-include-deadlines
3296 (setq org-agenda-entry-types
3297 (delq :deadline org-agenda-entry-types)))
3299 ((eq org-agenda-show-log 'only)
3300 (setq rtn (org-agenda-get-day-entries
3301 file date :closed)))
3302 (org-agenda-show-log
3303 (setq rtn (apply 'org-agenda-get-day-entries
3305 (append '(:closed) org-agenda-entry-types))))
3307 (setq rtn (apply 'org-agenda-get-day-entries
3309 org-agenda-entry-types)))))
3310 (setq rtnall (append rtnall rtn))))
3311 (if org-agenda-include-diary
3312 (let ((org-agenda-search-headline-for-time t))
3313 (require 'diary-lib)
3314 (setq rtn (org-get-entries-from-diary date))
3315 (setq rtnall (append rtnall rtn))))
3316 (if (or rtnall org-agenda-show-all-dates)
3318 (setq day-cnt (1+ day-cnt))
3320 (if (stringp org-agenda-format-date)
3321 (format-time-string org-agenda-format-date
3322 (org-time-from-absolute date))
3323 (funcall org-agenda-format-date date))
3325 (put-text-property s (1- (point)) 'face
3326 (if (member wd org-agenda-weekend-days)
3327 'org-agenda-date-weekend
3329 (put-text-property s (1- (point)) 'org-date-line t)
3330 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3331 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3333 (put-text-property s (1- (point)) 'org-today t)
3334 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
3336 (org-finalize-agenda-entries
3337 (org-agenda-add-time-grid-maybe
3340 (put-text-property s (1- (point)) 'day d)
3341 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3342 (when (and org-agenda-clockreport-mode clocktable-start)
3343 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3344 ;; the above line is to ensure the restricted range!
3345 (p org-agenda-clockreport-parameter-plist)
3347 (setq p (org-plist-delete p :block))
3348 (setq p (plist-put p :tstart clocktable-start))
3349 (setq p (plist-put p :tend clocktable-end))
3350 (setq p (plist-put p :scope 'agenda))
3351 (setq tbl (apply 'org-get-clocktable p))
3353 (goto-char (point-min))
3354 (or org-agenda-multi (org-fit-agenda-window))
3355 (unless (and (pos-visible-in-window-p (point-min))
3356 (pos-visible-in-window-p (point-max)))
3357 (goto-char (1- (point-max)))
3359 (if (not (pos-visible-in-window-p (or start-pos 1)))
3361 (goto-char (or start-pos 1))
3363 (goto-char (or start-pos 1))
3364 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3365 (org-finalize-agenda)
3366 (setq buffer-read-only t)
3369 (defun org-agenda-ndays-to-span (n)
3370 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3372 ;;; Agenda word search
3374 (defvar org-agenda-search-history nil)
3375 (defvar org-todo-only nil)
3377 (defvar org-search-syntax-table nil
3378 "Special syntax table for org-mode search.
3379 In this table, we have single quotes not as word constituents, to
3380 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3382 (defun org-search-syntax-table ()
3383 (unless org-search-syntax-table
3384 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3385 (modify-syntax-entry ?' "." org-search-syntax-table)
3386 (modify-syntax-entry ?` "." org-search-syntax-table))
3387 org-search-syntax-table)
3389 (defvar org-agenda-last-search-view-search-was-boolean nil)
3392 (defun org-search-view (&optional todo-only string edit-at)
3393 "Show all entries that contain a phrase or words or regular expressions.
3395 With optional prefix argument TODO-ONLY, only consider entries that are
3396 TODO entries. The argument STRING can be used to pass a default search
3397 string into this function. If EDIT-AT is non-nil, it means that the
3398 user should get a chance to edit this string, with cursor at position
3401 The search string can be viewed either as a phrase that should be found as
3402 is, or it can be broken into a number of snippets, each of which must match
3403 in a Boolean way to select an entry. The default depends on the variable
3404 `org-agenda-search-view-always-boolean'.
3405 Even if this is turned off (the default) you can always switch to
3406 Boolean search dynamically by preceeding the first word with \"+\" or \"-\".
3408 The default is a direct search of the whole phrase, where each space in
3409 the search string can expand to an arbitrary amount of whitespace,
3412 If using a Boolean search, the search string is split on whitespace and
3413 each snippet is searched separately, with logical AND to select an entry.
3414 Words prefixed with a minus must *not* occur in the entry. Words without
3415 a prefix or prefixed with a plus must occur in the entry. Matching is
3416 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3417 match whole words, not parts of a word) if
3418 `org-agenda-search-view-force-full-words' is set (default is nil).
3420 Boolean search snippets enclosed by curly braces are interpreted as
3421 regular expressions that must or (when preceeded with \"-\") must not
3422 match in the entry. Snippets enclosed into double quotes will be taken
3423 as a whole, to incude whitespace.
3425 - If the search string starts with an asterisk, search only in headlines.
3426 - If (possibly after the leading star) the search string starts with an
3427 exclamation mark, this also means to look at TODO entries only, an effect
3428 that can also be achieved with a prefix argument.
3429 - If (possibly after star and exclamation mark) the search string starts
3430 with a colon, this will mean that the (non-regexp) snippets of the
3431 Boolean search must match as full words.
3433 This command searches the agenda files, and in addition the files listed
3434 in `org-agenda-text-search-extra-files'."
3436 (org-compile-prefix-format 'search)
3437 (org-set-sorting-strategy 'search)
3438 (org-prepare-agenda "SEARCH")
3439 (let* ((props (list 'face nil
3440 'done-face 'org-agenda-done
3441 'org-not-done-regexp org-not-done-regexp
3442 'org-todo-regexp org-todo-regexp
3443 'org-complex-heading-regexp org-complex-heading-regexp
3444 'mouse-face 'highlight
3445 'help-echo (format "mouse-2 or RET jump to location")))
3446 (full-words org-agenda-search-view-force-full-words)
3447 regexp rtn rtnall files file pos
3448 marker category tags c neg re boolean
3449 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3450 (unless (and (not edit-at)
3452 (string-match "\\S-" string))
3453 (setq string (read-string
3454 (if org-agenda-search-view-always-boolean
3455 "[+-]Word/{Regexp} ...: "
3456 "Phrase, or [+-]Word/{Regexp} ...: ")
3458 ((integerp edit-at) (cons string edit-at))
3460 'org-agenda-search-history)))
3461 (org-set-local 'org-todo-only todo-only)
3462 (setq org-agenda-redo-command
3463 (list 'org-search-view (if todo-only t nil) string
3464 '(if current-prefix-arg 1 nil)))
3465 (setq org-agenda-query-string string)
3467 (if (equal (string-to-char string) ?*)
3469 words (substring string 1))
3470 (setq words string))
3471 (when (equal (string-to-char words) ?!)
3473 words (substring words 1)))
3474 (when (equal (string-to-char words) ?:)
3476 words (substring words 1)))
3477 (if (or org-agenda-search-view-always-boolean
3478 (member (string-to-char words) '(?- ?+ ?\{)))
3480 (setq words (org-split-string words))
3481 (setq org-agenda-last-search-view-search-was-boolean boolean)
3484 (while (setq w (pop words))
3485 (if (or (equal (substring w 0 1) "\"")
3486 (and (> (length w) 1)
3487 (member (substring w 0 1) '("+" "-"))
3488 (equal (substring w 1 2) "\"")))
3489 (while (and words (not (equal (substring w -1) "\"")))
3490 (setq w (concat w " " (pop words)))))
3491 (and (string-match "\\`\\([-+]?\\)\"" w)
3492 (setq w (replace-match "\\1" nil nil w)))
3493 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3495 (setq words (nreverse wds))))
3498 (setq c (string-to-char w))
3500 (setq neg t w (substring w 1))
3502 (setq neg nil w (substring w 1))
3504 (if (string-match "\\`{.*}\\'" w)
3505 (setq re (substring w 1 -1))
3507 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3508 (setq re (regexp-quote (downcase w)))))
3509 (if neg (push re regexps-) (push re regexps+)))
3511 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3513 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3515 (setq regexp (concat "^" org-outline-regexp))
3516 (setq regexp (pop regexps+))
3517 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3519 (setq files (org-agenda-files nil 'ifmode))
3520 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3521 (pop org-agenda-text-search-extra-files)
3522 (setq files (org-add-archive-files files)))
3523 (setq files (append files org-agenda-text-search-extra-files)
3525 (while (setq file (pop files))
3528 (org-check-agenda-file file)
3529 (setq buffer (if (file-exists-p file)
3530 (org-get-agenda-file-buffer file)
3531 (error "No such file %s" file)))
3533 ;; If file does not exist, make sure an error message is sent
3534 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3536 (with-current-buffer buffer
3537 (with-syntax-table (org-search-syntax-table)
3538 (unless (org-mode-p)
3539 (error "Agenda file %s is not in `org-mode'" file))
3540 (let ((case-fold-search t))
3543 (if org-agenda-restrict
3544 (narrow-to-region org-agenda-restrict-begin
3545 org-agenda-restrict-end)
3547 (goto-char (point-min))
3548 (unless (or (org-on-heading-p)
3549 (outline-next-heading))
3550 (throw 'nextfile t))
3551 (goto-char (max (point-min) (1- (point))))
3552 (while (re-search-forward regexp nil t)
3553 (org-back-to-heading t)
3554 (skip-chars-forward "* ")
3555 (setq beg (point-at-bol)
3557 end (progn (outline-next-heading) (point)))
3561 (setq str (buffer-substring-no-properties
3563 (if hdl-only (point-at-eol) end)))
3564 (mapc (lambda (wr) (when (string-match wr str)
3565 (goto-char (1- end))
3568 (mapc (lambda (wr) (unless (string-match wr str)
3569 (goto-char (1- end))
3572 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3576 (setq marker (org-agenda-new-marker (point))
3577 category (org-get-category)
3578 tags (org-get-tags-at (point))
3579 txt (org-format-agenda-item
3581 (buffer-substring-no-properties
3582 beg1 (point-at-eol))
3584 (org-add-props txt props
3585 'org-marker marker 'org-hd-marker marker
3586 'org-todo-regexp org-todo-regexp
3587 'org-complex-heading-regexp org-complex-heading-regexp
3588 'priority 1000 'org-category category
3591 (goto-char (1- end))))))))))
3592 (setq rtn (nreverse ee))
3593 (setq rtnall (append rtnall rtn)))
3594 (if org-agenda-overriding-header
3595 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3596 nil 'face 'org-agenda-structure) "\n")
3597 (insert "Search words: ")
3598 (add-text-properties (point-min) (1- (point))
3599 (list 'face 'org-agenda-structure))
3601 (insert string "\n")
3602 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3604 (unless org-agenda-multi
3605 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3606 (add-text-properties pos (1- (point))
3607 (list 'face 'org-agenda-structure))))
3608 (org-agenda-mark-header-line (point-min))
3610 (insert (org-finalize-agenda-entries rtnall) "\n"))
3611 (goto-char (point-min))
3612 (or org-agenda-multi (org-fit-agenda-window))
3613 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3614 (org-finalize-agenda)
3615 (setq buffer-read-only t)))
3617 ;;; Agenda TODO list
3619 (defvar org-select-this-todo-keyword nil)
3620 (defvar org-last-arg nil)
3623 (defun org-todo-list (arg)
3624 "Show all (not done) TODO entries from all agenda file in a single list.
3625 The prefix arg can be used to select a specific TODO keyword and limit
3626 the list to these. When using \\[universal-argument], you will be prompted
3627 for a keyword. A numeric prefix directly selects the Nth keyword in
3628 `org-todo-keywords-1'."
3630 (org-compile-prefix-format 'todo)
3631 (org-set-sorting-strategy 'todo)
3632 (org-prepare-agenda "TODO")
3633 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3634 (let* ((today (time-to-days (current-time)))
3635 (date (calendar-gregorian-from-absolute today))
3636 (kwds org-todo-keywords-for-agenda)
3637 (completion-ignore-case t)
3638 (org-select-this-todo-keyword
3639 (if (stringp arg) arg
3640 (and arg (integerp arg) (> arg 0)
3641 (nth (1- arg) kwds))))
3642 rtn rtnall files file pos)
3643 (when (equal arg '(4))
3644 (setq org-select-this-todo-keyword
3645 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3646 (mapcar 'list kwds) nil nil)))
3647 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3648 (org-set-local 'org-last-arg arg)
3649 (setq org-agenda-redo-command
3650 '(org-todo-list (or current-prefix-arg org-last-arg)))
3651 (setq files (org-agenda-files nil 'ifmode)
3653 (while (setq file (pop files))
3655 (org-check-agenda-file file)
3656 (setq rtn (org-agenda-get-day-entries file date :todo))
3657 (setq rtnall (append rtnall rtn))))
3658 (if org-agenda-overriding-header
3659 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3660 nil 'face 'org-agenda-structure) "\n")
3661 (insert "Global list of TODO items of type: ")
3662 (add-text-properties (point-min) (1- (point))
3663 (list 'face 'org-agenda-structure
3666 (or org-select-this-todo-keyword "ALL"))))
3667 (org-agenda-mark-header-line (point-min))
3669 (insert (or org-select-this-todo-keyword "ALL") "\n")
3670 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3672 (unless org-agenda-multi
3673 (insert "Available with `N r': (0)ALL")
3676 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3677 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3682 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3683 (org-agenda-mark-header-line (point-min))
3685 (insert (org-finalize-agenda-entries rtnall) "\n"))
3686 (goto-char (point-min))
3687 (or org-agenda-multi (org-fit-agenda-window))
3688 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3689 (org-finalize-agenda)
3690 (setq buffer-read-only t)))
3692 ;;; Agenda tags match
3695 (defun org-tags-view (&optional todo-only match)
3696 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3697 The prefix arg TODO-ONLY limits the search to TODO entries."
3699 (org-compile-prefix-format 'tags)
3700 (org-set-sorting-strategy 'tags)
3701 (let* ((org-tags-match-list-sublevels
3702 org-tags-match-list-sublevels)
3703 (completion-ignore-case t)
3704 rtn rtnall files file pos matcher
3706 (when (and (stringp match) (not (string-match "\\S-" match)))
3708 (setq matcher (org-make-tags-matcher match)
3709 match (car matcher) matcher (cdr matcher))
3710 (org-prepare-agenda (concat "TAGS " match))
3711 (setq org-agenda-query-string match)
3712 (setq org-agenda-redo-command
3713 (list 'org-tags-view (list 'quote todo-only)
3714 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3715 (setq files (org-agenda-files nil 'ifmode)
3717 (while (setq file (pop files))
3719 (org-check-agenda-file file)
3720 (setq buffer (if (file-exists-p file)
3721 (org-get-agenda-file-buffer file)
3722 (error "No such file %s" file)))
3724 ;; If file does not exist, error message to agenda
3726 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3727 rtnall (append rtnall rtn))
3728 (with-current-buffer buffer
3729 (unless (org-mode-p)
3730 (error "Agenda file %s is not in `org-mode'" file))
3733 (if org-agenda-restrict
3734 (narrow-to-region org-agenda-restrict-begin
3735 org-agenda-restrict-end)
3737 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3738 (setq rtnall (append rtnall rtn))))))))
3739 (if org-agenda-overriding-header
3740 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3741 nil 'face 'org-agenda-structure) "\n")
3742 (insert "Headlines with TAGS match: ")
3743 (add-text-properties (point-min) (1- (point))
3744 (list 'face 'org-agenda-structure
3746 (concat "Match: " match)))
3749 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3751 (unless org-agenda-multi
3752 (insert "Press `C-u r' to search again with new search string\n"))
3753 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3754 (org-agenda-mark-header-line (point-min))
3756 (insert (org-finalize-agenda-entries rtnall) "\n"))
3757 (goto-char (point-min))
3758 (or org-agenda-multi (org-fit-agenda-window))
3759 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3760 (org-finalize-agenda)
3761 (setq buffer-read-only t)))
3763 ;;; Agenda Finding stuck projects
3765 (defvar org-agenda-skip-regexp nil
3766 "Regular expression used in skipping subtrees for the agenda.
3767 This is basically a temporary global variable that can be set and then
3768 used by user-defined selections using `org-agenda-skip-function'.")
3770 (defvar org-agenda-overriding-header nil
3771 "When this is set during todo and tags searches, will replace header.
3772 This variable should not be set directly, but custom commands can bind it
3773 in the options section.")
3775 (defun org-agenda-skip-entry-when-regexp-matches ()
3776 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3777 If yes, it returns the end position of this entry, causing agenda commands
3778 to skip the entry but continuing the search in the subtree. This is a
3779 function that can be put into `org-agenda-skip-function' for the duration
3781 (let ((end (save-excursion (org-end-of-subtree t)))
3784 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3787 (defun org-agenda-skip-subtree-when-regexp-matches ()
3788 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3789 If yes, it returns the end position of this tree, causing agenda commands
3790 to skip this subtree. This is a function that can be put into
3791 `org-agenda-skip-function' for the duration of a command."
3792 (let ((end (save-excursion (org-end-of-subtree t)))
3795 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3798 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3799 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3800 If yes, it returns the end position of the current entry (NOT the tree),
3801 causing agenda commands to skip the entry but continuing the search in
3802 the subtree. This is a function that can be put into
3803 `org-agenda-skip-function' for the duration of a command. An important
3804 use of this function is for the stuck project list."
3805 (let ((end (save-excursion (org-end-of-subtree t)))
3806 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3809 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3810 (and skip entry-end)))
3812 (defun org-agenda-skip-entry-if (&rest conditions)
3813 "Skip entry if any of CONDITIONS is true.
3814 See `org-agenda-skip-if' for details."
3815 (org-agenda-skip-if nil conditions))
3817 (defun org-agenda-skip-subtree-if (&rest conditions)
3818 "Skip entry if any of CONDITIONS is true.
3819 See `org-agenda-skip-if' for details."
3820 (org-agenda-skip-if t conditions))
3822 (defun org-agenda-skip-if (subtree conditions)
3823 "Checks current entity for CONDITIONS.
3824 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3825 the entry, i.e. the text before the next heading is checked.
3827 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3828 from different tests. Valid conditions are:
3830 scheduled Check if there is a scheduled cookie
3831 notscheduled Check if there is no scheduled cookie
3832 deadline Check if there is a deadline
3833 notdeadline Check if there is no deadline
3834 timestamp Check if there is a timestamp (also deadline or scheduled)
3835 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3836 regexp Check if regexp matches
3837 notregexp Check if regexp does not match.
3838 todo Check if TODO keyword matches
3839 nottodo Check if TODO keyword does not match
3841 The regexp is taken from the conditions list, it must come right after
3842 the `regexp' or `notregexp' element.
3844 `todo' and `nottodo' accept as an argument a list of todo
3845 keywords, which may include \"*\" to match any todo keyword.
3847 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
3849 would skip all entries with \"TODO\" or \"WAITING\" keywords.
3851 Instead of a list a keyword class may be given
3853 (org-agenda-skip-entry-if 'nottodo 'done)
3855 would skip entries that haven't been marked with any of \"DONE\"
3856 keywords. Possible classes are: `todo', `done', `any'.
3858 If any of these conditions is met, this function returns the end point of
3859 the entity, causing the search to continue from there. This is a function
3860 that can be put into `org-agenda-skip-function' for the duration of a command."
3862 (org-back-to-heading t)
3865 (progn (org-end-of-subtree t) (point))
3866 (progn (outline-next-heading) (1- (point)))))
3870 (and (memq 'scheduled conditions)
3871 (re-search-forward org-scheduled-time-regexp end t))
3872 (and (memq 'notscheduled conditions)
3873 (not (re-search-forward org-scheduled-time-regexp end t)))
3874 (and (memq 'deadline conditions)
3875 (re-search-forward org-deadline-time-regexp end t))
3876 (and (memq 'notdeadline conditions)
3877 (not (re-search-forward org-deadline-time-regexp end t)))
3878 (and (memq 'timestamp conditions)
3879 (re-search-forward org-ts-regexp end t))
3880 (and (memq 'nottimestamp conditions)
3881 (not (re-search-forward org-ts-regexp end t)))
3882 (and (setq m (memq 'regexp conditions))
3884 (re-search-forward (nth 1 m) end t))
3885 (and (setq m (memq 'notregexp conditions))
3887 (not (re-search-forward (nth 1 m) end t)))
3889 (setq m (memq 'todo conditions))
3890 (setq m (memq 'nottodo conditions)))
3891 (org-agenda-skip-if-todo m end)))
3894 (defun org-agenda-skip-if-todo (args end)
3895 "Helper function for `org-agenda-skip-if', do not use it directly.
3896 ARGS is a list with first element either `todo' or `nottodo'.
3897 The remainder is either a list of TODO keywords, or a state symbol
3898 `todo' or `done' or `any'."
3899 (let ((kw (car args))
3905 ((listp arg) ;; list of keywords
3906 (if (member "*" arg)
3907 (mapcar 'substring-no-properties org-todo-keywords-1)
3909 ((symbolp arg) ;; keyword class name
3912 (org-delete-all org-done-keywords
3913 (mapcar 'substring-no-properties
3914 org-todo-keywords-1)))
3915 ((eq arg 'done) org-done-keywords)
3917 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
3919 (concat "^\\*+[ \t]+\\<\\("
3920 (mapconcat 'identity todo-wds "\\|")
3923 (re-search-forward todo-re end t)
3924 (not (re-search-forward todo-re end t)))))
3927 (defun org-agenda-list-stuck-projects (&rest ignore)
3928 "Create agenda view for projects that are stuck.
3929 Stuck projects are project that have no next actions. For the definitions
3930 of what a project is and how to check if it stuck, customize the variable
3931 `org-stuck-projects'.
3932 MATCH is being ignored."
3934 (let* ((org-agenda-skip-function
3935 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
3936 ;; We could have used org-agenda-skip-if here.
3937 (org-agenda-overriding-header
3938 (or org-agenda-overriding-header "List of stuck projects: "))
3939 (matcher (nth 0 org-stuck-projects))
3940 (todo (nth 1 org-stuck-projects))
3941 (todo-wds (if (member "*" todo)
3943 (org-prepare-agenda-buffers (org-agenda-files
3946 org-done-keywords-for-agenda
3947 (copy-sequence org-todo-keywords-for-agenda)))
3949 (todo-re (concat "^\\*+[ \t]+\\("
3950 (mapconcat 'identity todo-wds "\\|")
3952 (tags (nth 2 org-stuck-projects))
3953 (tags-re (if (member "*" tags)
3954 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3956 (concat "^\\*+ .*:\\("
3957 (mapconcat 'identity tags "\\|")
3958 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3959 (gen-re (nth 3 org-stuck-projects))
3965 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
3967 (setq org-agenda-skip-regexp
3969 (mapconcat 'identity re-list "\\|")
3970 (error "No information how to identify unstuck projects")))
3971 (org-tags-view nil matcher)
3972 (with-current-buffer org-agenda-buffer-name
3973 (setq org-agenda-redo-command
3974 '(org-agenda-list-stuck-projects
3975 (or current-prefix-arg org-last-arg))))))
3977 ;;; Diary integration
3979 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
3980 (defvar list-diary-entries-hook)
3982 (defun org-get-entries-from-diary (date)
3983 "Get the (Emacs Calendar) diary entries for DATE."
3984 (require 'diary-lib)
3985 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3986 (diary-display-hook '(fancy-diary-display))
3987 (diary-display-function 'fancy-diary-display)
3989 (list-diary-entries-hook
3990 (cons 'org-diary-default-entry list-diary-entries-hook))
3991 (diary-file-name-prefix-function nil) ; turn this feature off
3992 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
3994 (org-disable-agenda-to-diary t))
3996 (save-window-excursion
3997 (funcall (if (fboundp 'diary-list-entries)
3998 'diary-list-entries 'list-diary-entries)
4000 (if (not (get-buffer diary-fancy-buffer))
4002 (with-current-buffer diary-fancy-buffer
4003 (setq buffer-read-only nil)
4004 (if (zerop (buffer-size))
4007 ;; Omit the date and other unnecessary stuff
4008 (org-agenda-cleanup-fancy-diary)
4009 ;; Add prefix to each line and extend the text properties
4010 (if (zerop (buffer-size))
4012 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
4013 (set-buffer-modified-p nil)
4014 (kill-buffer diary-fancy-buffer)))
4016 (setq entries (org-split-string entries "\n"))
4020 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4021 ;; Extend the text properties to the beginning of the line
4022 (org-add-props x (text-properties-at (1- (length x)) x)
4023 'type "diary" 'date date 'face 'org-agenda-diary))
4026 (defvar org-agenda-cleanup-fancy-diary-hook nil
4027 "Hook run when the fancy diary buffer is cleaned up.")
4029 (defun org-agenda-cleanup-fancy-diary ()
4030 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4031 This gets rid of the date, the underline under the date, and
4032 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4033 date. It also removes lines that contain only whitespace."
4034 (goto-char (point-min))
4035 (if (looking-at ".*?:[ \t]*")
4038 (re-search-forward "\n=+$" nil t)
4040 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4041 (re-search-forward "\n=+$" nil t)
4042 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4043 (goto-char (point-min))
4044 (while (re-search-forward "^ +\n" nil t)
4046 (goto-char (point-min))
4047 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4049 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4051 ;; Make sure entries from the diary have the right text properties.
4052 (eval-after-load "diary-lib"
4053 '(if (boundp 'diary-modify-entry-list-string-function)
4054 ;; We can rely on the hook, nothing to do
4056 ;; Hook not available, must use advice to make this work
4057 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4058 "Make the position visible."
4059 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4062 (setq string (org-modify-diary-entry-string string))))))
4064 (defun org-modify-diary-entry-string (string)
4065 "Add text properties to string, allowing org-mode to act on it."
4066 (org-add-props string nil
4067 'mouse-face 'highlight
4068 'help-echo (if buffer-file-name
4069 (format "mouse-2 or RET jump to diary file %s"
4070 (abbreviate-file-name buffer-file-name))
4072 'org-agenda-diary-link t
4073 'org-marker (org-agenda-new-marker (point-at-bol))))
4075 (defun org-diary-default-entry ()
4076 "Add a dummy entry to the diary.
4077 Needed to avoid empty dates which mess up holiday display."
4078 ;; Catch the error if dealing with the new add-to-diary-alist
4079 (when org-disable-agenda-to-diary
4081 (org-add-to-diary-list original-date "Org-mode dummy" "")
4083 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4085 (defun org-add-to-diary-list (&rest args)
4086 (if (fboundp 'diary-add-to-list)
4087 (apply 'diary-add-to-list args)
4088 (apply 'add-to-diary-list args)))
4090 (defvar org-diary-last-run-time nil)
4093 (defun org-diary (&rest args)
4094 "Return diary information from org-files.
4095 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4096 It accesses org files and extracts information from those files to be
4097 listed in the diary. The function accepts arguments specifying what
4098 items should be listed. For a list of arguments allowed here, see the
4099 variable `org-agenda-entry-types'.
4101 The call in the diary file should look like this:
4103 &%%(org-diary) ~/path/to/some/orgfile.org
4105 Use a separate line for each org file to check. Or, if you omit the file name,
4106 all files listed in `org-agenda-files' will be checked automatically:
4110 If you don't give any arguments (as in the example above), the default
4111 arguments (:deadline :scheduled :timestamp :sexp) are used.
4112 So the example above may also be written as
4114 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4116 The function expects the lisp variables `entry' and `date' to be provided
4117 by the caller, because this is how the calendar works. Don't use this
4118 function from a program - use `org-agenda-get-day-entries' instead."
4119 (when (> (- (org-float-time)
4120 org-agenda-last-marker-time)
4122 (org-agenda-reset-markers))
4123 (org-compile-prefix-format 'agenda)
4124 (org-set-sorting-strategy 'agenda)
4125 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4126 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4128 (org-agenda-files t)))
4129 (time (org-float-time))
4131 (when (or (not org-diary-last-run-time)
4133 org-diary-last-run-time)
4135 (org-prepare-agenda-buffers files))
4136 (setq org-diary-last-run-time time)
4137 ;; If this is called during org-agenda, don't return any entries to
4138 ;; the calendar. Org Agenda will list these entries itself.
4139 (if org-disable-agenda-to-diary (setq files nil))
4140 (while (setq file (pop files))
4141 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4142 (setq results (append results rtn)))
4144 (concat (org-finalize-agenda-entries results) "\n"))))
4146 ;;; Agenda entry finders
4148 (defun org-agenda-get-day-entries (file date &rest args)
4149 "Does the work for `org-diary' and `org-agenda'.
4150 FILE is the path to a file to be checked for entries. DATE is date like
4151 the one returned by `calendar-current-date'. ARGS are symbols indicating
4152 which kind of entries should be extracted. For details about these, see
4153 the documentation of `org-diary'."
4154 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4155 (let* ((org-startup-folded nil)
4156 (org-startup-align-all-tables nil)
4157 (buffer (if (file-exists-p file)
4158 (org-get-agenda-file-buffer file)
4159 (error "No such file %s" file)))
4160 arg results rtn deadline-results)
4162 ;; If file does not exist, make sure an error message ends up in diary
4163 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4164 (with-current-buffer buffer
4165 (unless (org-mode-p)
4166 (error "Agenda file %s is not in `org-mode'" file))
4167 (let ((case-fold-search nil))
4170 (if org-agenda-restrict
4171 (narrow-to-region org-agenda-restrict-begin
4172 org-agenda-restrict-end)
4174 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4175 (while (setq arg (pop args))
4177 ((and (eq arg :todo)
4178 (equal date (calendar-current-date)))
4179 (setq rtn (org-agenda-get-todos))
4180 (setq results (append results rtn)))
4181 ((eq arg :timestamp)
4182 (setq rtn (org-agenda-get-blocks))
4183 (setq results (append results rtn))
4184 (setq rtn (org-agenda-get-timestamps))
4185 (setq results (append results rtn)))
4187 (setq rtn (org-agenda-get-sexps))
4188 (setq results (append results rtn)))
4189 ((eq arg :scheduled)
4190 (setq rtn (org-agenda-get-scheduled deadline-results))
4191 (setq results (append results rtn)))
4193 (setq rtn (org-agenda-get-progress))
4194 (setq results (append results rtn)))
4196 (setq rtn (org-agenda-get-deadlines))
4197 (setq deadline-results (copy-sequence rtn))
4198 (setq results (append results rtn))))))))
4201 (defun org-agenda-get-todos ()
4202 "Return the TODO information for agenda display."
4203 (let* ((props (list 'face nil
4204 'done-face 'org-agenda-done
4205 'org-not-done-regexp org-not-done-regexp
4206 'org-todo-regexp org-todo-regexp
4207 'org-complex-heading-regexp org-complex-heading-regexp
4208 'mouse-face 'highlight
4210 (format "mouse-2 or RET jump to org file %s"
4211 (abbreviate-file-name buffer-file-name))))
4212 (regexp (concat "^\\*+[ \t]+\\("
4213 (if org-select-this-todo-keyword
4214 (if (equal org-select-this-todo-keyword "*")
4217 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4219 org-not-done-regexp)
4221 marker priority category tags todo-state
4223 (goto-char (point-min))
4224 (while (re-search-forward regexp nil t)
4228 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4229 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4230 (goto-char (1+ beg))
4231 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4235 (goto-char (match-beginning 1))
4236 (setq marker (org-agenda-new-marker (match-beginning 0))
4237 category (org-get-category)
4238 txt (match-string 1)
4239 tags (org-get-tags-at (point))
4240 txt (org-format-agenda-item "" txt category tags)
4241 priority (1+ (org-get-priority txt))
4242 todo-state (org-get-todo-state))
4243 (org-add-props txt props
4244 'org-marker marker 'org-hd-marker marker
4245 'priority priority 'org-category category
4246 'type "todo" 'todo-state todo-state)
4248 (if org-agenda-todo-list-sublevels
4249 (goto-char (match-end 1))
4250 (org-end-of-subtree 'invisible))))
4254 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4256 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4257 (when (or org-agenda-todo-ignore-with-date
4258 org-agenda-todo-ignore-scheduled
4259 org-agenda-todo-ignore-deadlines)
4260 (setq end (or end (save-excursion (outline-next-heading) (point))))
4262 (or (and org-agenda-todo-ignore-with-date
4263 (re-search-forward org-ts-regexp end t))
4264 (and org-agenda-todo-ignore-scheduled
4265 (re-search-forward org-scheduled-time-regexp end t)
4267 ((eq org-agenda-todo-ignore-scheduled 'future)
4268 (> (org-days-to-time (match-string 1)) 0))
4269 ((eq org-agenda-todo-ignore-scheduled 'past)
4270 (<= (org-days-to-time (match-string 1)) 0))
4272 (and org-agenda-todo-ignore-deadlines
4273 (re-search-forward org-deadline-time-regexp end t)
4275 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4276 ((eq org-agenda-todo-ignore-deadlines 'far)
4277 (not (org-deadline-close (match-string 1))))
4278 ((eq org-agenda-todo-ignore-deadlines 'future)
4279 (> (org-days-to-time (match-string 1)) 0))
4280 ((eq org-agenda-todo-ignore-deadlines 'past)
4281 (<= (org-days-to-time (match-string 1)) 0))
4282 (t (org-deadline-close (match-string 1)))))))))
4284 (defconst org-agenda-no-heading-message
4285 "No heading for this item in buffer or region.")
4287 (defun org-agenda-get-timestamps ()
4288 "Return the date stamp information for agenda display."
4289 (let* ((props (list 'face nil
4290 'org-not-done-regexp org-not-done-regexp
4291 'org-todo-regexp org-todo-regexp
4292 'org-complex-heading-regexp org-complex-heading-regexp
4293 'mouse-face 'highlight
4295 (format "mouse-2 or RET jump to org file %s"
4296 (abbreviate-file-name buffer-file-name))))
4297 (d1 (calendar-absolute-from-gregorian date))
4303 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4307 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4311 (car org-time-stamp-formats)
4312 (apply 'encode-time ; DATE bound by calendar
4313 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4315 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4316 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4317 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4318 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4319 todo-state end-of-match)
4320 (goto-char (point-min))
4321 (while (setq end-of-match (re-search-forward regexp nil t))
4322 (setq b0 (match-beginning 0)
4323 b3 (match-beginning 3) e3 (match-end 3))
4325 (and (org-at-date-range-p) (throw :skip nil))
4327 (if (and (match-end 1)
4328 (not (= d1 (org-time-string-to-absolute
4329 (match-string 1) d1 nil
4330 org-agenda-repeating-timestamp-show-all))))
4333 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4335 (setq tmp (buffer-substring (max (point-min)
4336 (- b0 org-ds-keyword-length))
4338 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4339 inactivep (= (char-after b0) ?\[)
4340 deadlinep (string-match org-deadline-regexp tmp)
4341 scheduledp (string-match org-scheduled-regexp tmp)
4342 closedp (and org-agenda-include-inactive-timestamps
4343 (string-match org-closed-string tmp))
4344 clockp (and org-agenda-include-inactive-timestamps
4345 (or (string-match org-clock-string tmp)
4346 (string-match "]-+\\'" tmp)))
4347 todo-state (ignore-errors (org-get-todo-state))
4348 donep (member todo-state org-done-keywords))
4349 (if (or scheduledp deadlinep closedp clockp
4350 (and donep org-agenda-skip-timestamp-if-done))
4352 (if (string-match ">" timestr)
4353 ;; substring should only run to end of time stamp
4354 (setq timestr (substring timestr 0 (match-end 0))))
4355 (setq marker (org-agenda-new-marker b0)
4356 category (org-get-category b0))
4358 (if (not (re-search-backward "^\\*+ " nil t))
4359 (setq txt org-agenda-no-heading-message)
4360 (goto-char (match-beginning 0))
4361 (setq hdmarker (org-agenda-new-marker)
4362 tags (org-get-tags-at))
4363 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4364 (setq head (match-string 1))
4365 (setq txt (org-format-agenda-item
4366 (if inactivep org-agenda-inactive-leader nil)
4367 head category tags timestr nil
4369 (setq priority (org-get-priority txt))
4370 (org-add-props txt props
4371 'org-marker marker 'org-hd-marker hdmarker)
4372 (org-add-props txt nil 'priority priority
4373 'org-category category 'date date
4374 'todo-state todo-state
4377 (if org-agenda-skip-additional-timestamps-same-entry
4378 (outline-next-heading)
4379 (goto-char end-of-match))))
4382 (defun org-agenda-get-sexps ()
4383 "Return the sexp information for agenda display."
4384 (require 'diary-lib)
4385 (let* ((props (list 'face nil
4386 'mouse-face 'highlight
4388 (format "mouse-2 or RET jump to org file %s"
4389 (abbreviate-file-name buffer-file-name))))
4391 marker category ee txt tags entry result beg b sexp sexp-entry
4393 (goto-char (point-min))
4394 (while (re-search-forward regexp nil t)
4397 (setq beg (match-beginning 0))
4398 (goto-char (1- (match-end 0)))
4401 (setq sexp (buffer-substring b (point)))
4402 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4403 (org-trim (match-string 1))
4405 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4407 (setq marker (org-agenda-new-marker beg)
4408 category (org-get-category beg)
4409 todo-state (org-get-todo-state))
4411 (if (string-match "\\S-" result)
4413 (setq txt "SEXP entry returned empty string"))
4415 (setq txt (org-format-agenda-item
4416 "" txt category tags 'time))
4417 (org-add-props txt props 'org-marker marker)
4418 (org-add-props txt nil
4419 'org-category category 'date date 'todo-state todo-state
4424 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4425 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4426 The order of the first 2 times 3 arguments depends on the variable
4427 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4428 So for american calendars, give this as MONTH DAY YEAR, for european as
4429 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4430 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4431 is any number of ISO weeks in the block period for which the item should
4433 (let* ((date1 (calendar-absolute-from-gregorian
4434 (org-order-calendar-date-args m1 d1 y1)))
4435 (date2 (calendar-absolute-from-gregorian
4436 (org-order-calendar-date-args m2 d2 y2)))
4437 (d (calendar-absolute-from-gregorian date)))
4441 (= (calendar-day-of-week date) dayname)
4442 (or (not skip-weeks)
4445 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4448 (defalias 'org-get-closed 'org-agenda-get-progress)
4449 (defun org-agenda-get-progress ()
4450 "Return the logged TODO entries for agenda display."
4451 (let* ((props (list 'mouse-face 'highlight
4452 'org-not-done-regexp org-not-done-regexp
4453 'org-todo-regexp org-todo-regexp
4454 'org-complex-heading-regexp org-complex-heading-regexp
4456 (format "mouse-2 or RET jump to org file %s"
4457 (abbreviate-file-name buffer-file-name))))
4458 (items (if (consp org-agenda-show-log)
4460 org-agenda-log-mode-items))
4464 (if (memq 'closed items) (concat "\\<" org-closed-string))
4465 (if (memq 'clock items) (concat "\\<" org-clock-string))
4466 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4467 (parts-re (if parts (mapconcat 'identity parts "\\|")
4468 (error "`org-agenda-log-mode-items' is empty")))
4470 "\\(" parts-re "\\)"
4475 (car org-time-stamp-formats)
4476 (apply 'encode-time ; DATE bound by calendar
4477 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4479 (org-agenda-search-headline-for-time nil)
4480 marker hdmarker priority category tags closedp statep clockp state
4481 ee txt extra timestr rest clocked)
4482 (goto-char (point-min))
4483 (while (re-search-forward regexp nil t)
4486 (setq marker (org-agenda-new-marker (match-beginning 0))
4487 closedp (equal (match-string 1) org-closed-string)
4488 statep (equal (string-to-char (match-string 1)) ?-)
4489 clockp (not (or closedp statep))
4490 state (and statep (match-string 2))
4491 category (org-get-category (match-beginning 0))
4492 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4494 (when (string-match "\\]" timestr)
4495 ;; substring should only run to end of time stamp
4496 (setq rest (substring timestr (match-end 0))
4497 timestr (substring timestr 0 (match-end 0)))
4498 (if (and (not closedp) (not statep)
4499 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4500 (progn (setq timestr (concat (substring timestr 0 -1)
4501 "-" (match-string 1 rest) "]"))
4502 (setq clocked (match-string 2 rest)))
4503 (setq clocked "-")))
4507 ((not org-agenda-log-mode-add-notes))
4509 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4510 (setq extra (match-string 1))))
4512 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4513 (setq extra (match-string 1)))))
4514 (if (not (re-search-backward "^\\*+ " nil t))
4515 (setq txt org-agenda-no-heading-message)
4516 (goto-char (match-beginning 0))
4517 (setq hdmarker (org-agenda-new-marker)
4518 tags (org-get-tags-at))
4519 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4520 (setq txt (match-string 1))
4522 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4523 (setq txt (concat (substring txt 0 (match-beginning 1))
4524 " - " extra " " (match-string 2 txt)))
4525 (setq txt (concat txt " - " extra))))
4526 (setq txt (org-format-agenda-item
4528 (closedp "Closed: ")
4529 (statep (concat "State: (" state ")"))
4530 (t (concat "Clocked: (" clocked ")")))
4531 txt category tags timestr)))
4532 (setq priority 100000)
4533 (org-add-props txt props
4534 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4535 'priority priority 'org-category category
4536 'type "closed" 'date date
4537 'undone-face 'org-warning 'done-face 'org-agenda-done)
4539 (goto-char (point-at-eol))))
4542 (defun org-agenda-get-deadlines ()
4543 "Return the deadline information for agenda display."
4544 (let* ((props (list 'mouse-face 'highlight
4545 'org-not-done-regexp org-not-done-regexp
4546 'org-todo-regexp org-todo-regexp
4547 'org-complex-heading-regexp org-complex-heading-regexp
4549 (format "mouse-2 or RET jump to org file %s"
4550 (abbreviate-file-name buffer-file-name))))
4551 (regexp org-deadline-time-regexp)
4552 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4553 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4554 d2 diff dfrac wdays pos pos1 category tags
4556 ee txt head face s todo-state upcomingp donep timestr)
4557 (goto-char (point-min))
4558 (while (re-search-forward regexp nil t)
4559 (setq suppress-prewarning nil)
4562 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4564 (string-match org-scheduled-time-regexp
4565 (buffer-substring (point-at-bol)
4567 (setq suppress-prewarning
4568 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4569 org-agenda-skip-deadline-prewarning-if-scheduled
4571 (setq s (match-string 1)
4573 pos (1- (match-beginning 1))
4574 d2 (org-time-string-to-absolute
4575 (match-string 1) d1 'past
4576 org-agenda-repeating-timestamp-show-all)
4578 wdays (if suppress-prewarning
4579 (let ((org-deadline-warning-days suppress-prewarning))
4582 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4583 upcomingp (and todayp (> diff 0)))
4584 ;; When to show a deadline in the calendar:
4585 ;; If the expiration is within wdays warning time.
4586 ;; Past-due deadlines are only shown on the current date
4587 (if (and (or (and (<= diff wdays)
4588 (and todayp (not org-agenda-only-exact-dates)))
4591 (setq todo-state (org-get-todo-state))
4592 (setq donep (member todo-state org-done-keywords))
4594 (or org-agenda-skip-deadline-if-done
4597 (setq category (org-get-category))
4598 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4599 (setq txt org-agenda-no-heading-message)
4600 (goto-char (match-end 0))
4601 (setq pos1 (match-beginning 0))
4602 (setq tags (org-get-tags-at pos1))
4603 (setq head (buffer-substring-no-properties
4605 (progn (skip-chars-forward "^\r\n")
4607 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4609 (concat (substring s (match-beginning 1)) " "))
4610 (setq timestr 'time))
4611 (setq txt (org-format-agenda-item
4613 (car org-agenda-deadline-leaders)
4615 (nth 1 org-agenda-deadline-leaders))
4617 (nth 1 org-agenda-deadline-leaders)
4619 (format (nth 1 org-agenda-deadline-leaders)
4622 (if (not (= diff 0)) nil timestr)))))
4624 (setq face (org-agenda-deadline-face dfrac wdays))
4625 (org-add-props txt props
4626 'org-marker (org-agenda-new-marker pos)
4627 'org-hd-marker (org-agenda-new-marker pos1)
4628 'priority (+ (- diff)
4629 (org-get-priority txt))
4630 'org-category category
4631 'todo-state todo-state
4632 'type (if upcomingp "upcoming-deadline" "deadline")
4633 'date (if upcomingp date d2)
4634 'face (if donep 'org-agenda-done face)
4635 'undone-face face 'done-face 'org-agenda-done)
4639 (defun org-agenda-deadline-face (fraction &optional wdays)
4640 "Return the face to displaying a deadline item.
4641 FRACTION is what fraction of the head-warning time has passed."
4642 (if (equal wdays 0) (setq fraction 1.))
4643 (let ((faces org-agenda-deadline-faces) f)
4645 (while (setq f (pop faces))
4646 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4648 (defun org-agenda-get-scheduled (&optional deadline-results)
4649 "Return the scheduled information for agenda display."
4650 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4651 'org-todo-regexp org-todo-regexp
4652 'org-complex-heading-regexp org-complex-heading-regexp
4653 'done-face 'org-agenda-done
4654 'mouse-face 'highlight
4656 (format "mouse-2 or RET jump to org file %s"
4657 (abbreviate-file-name buffer-file-name))))
4658 (regexp org-scheduled-time-regexp)
4659 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4660 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4662 (deadline-position-alist
4663 (mapcar (lambda (a) (and (setq mm (get-text-property
4664 0 'org-hd-marker a))
4665 (cons (marker-position mm) a)))
4667 d2 diff pos pos1 category tags donep
4668 ee txt head pastschedp todo-state face timestr s habitp)
4669 (goto-char (point-min))
4670 (while (re-search-forward regexp nil t)
4673 (setq s (match-string 1)
4675 pos (1- (match-beginning 1))
4676 d2 (org-time-string-to-absolute
4677 (match-string 1) d1 'past
4678 org-agenda-repeating-timestamp-show-all)
4680 (setq pastschedp (and todayp (< diff 0)))
4681 ;; When to show a scheduled item in the calendar:
4682 ;; If it is on or past the date.
4683 (when (or (and (< diff 0)
4684 (< (abs diff) org-scheduled-past-days)
4685 (and todayp (not org-agenda-only-exact-dates)))
4688 (setq todo-state (org-get-todo-state))
4689 (setq donep (member todo-state org-done-keywords))
4690 (setq habitp (and (functionp 'org-is-habit-p)
4693 (or habitp org-agenda-skip-scheduled-if-done
4696 (setq category (org-get-category))
4697 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4698 (setq txt org-agenda-no-heading-message)
4699 (goto-char (match-end 0))
4700 (setq pos1 (match-beginning 0))
4702 (if (or (not org-habit-show-habits)
4704 org-habit-show-habits-only-for-today))
4707 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4708 (and org-agenda-skip-scheduled-if-deadline-is-shown
4710 (setq mm (assoc pos1 deadline-position-alist)))
4712 (setq tags (org-get-tags-at))
4713 (setq head (buffer-substring-no-properties
4715 (progn (skip-chars-forward "^\r\n") (point))))
4716 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4718 (concat (substring s (match-beginning 1)) " "))
4719 (setq timestr 'time))
4720 (setq txt (org-format-agenda-item
4722 (car org-agenda-scheduled-leaders)
4723 (format (nth 1 org-agenda-scheduled-leaders)
4726 (if (not (= diff 0)) nil timestr)
4731 ((and (not habitp) pastschedp)
4732 'org-scheduled-previously)
4733 (todayp 'org-scheduled-today)
4735 habitp (and habitp (org-habit-parse-todo)))
4736 (org-add-props txt props
4738 'face (if donep 'org-agenda-done face)
4739 'org-marker (org-agenda-new-marker pos)
4740 'org-hd-marker (org-agenda-new-marker pos1)
4741 'type (if pastschedp "past-scheduled" "scheduled")
4742 'date (if pastschedp d2 date)
4743 'priority (if habitp
4744 (org-habit-get-priority habitp)
4745 (+ 94 (- 5 diff) (org-get-priority txt)))
4746 'org-category category
4748 'todo-state todo-state)
4752 (defun org-agenda-get-blocks ()
4753 "Return the date-range information for agenda display."
4754 (let* ((props (list 'face nil
4755 'org-not-done-regexp org-not-done-regexp
4756 'org-todo-regexp org-todo-regexp
4757 'org-complex-heading-regexp org-complex-heading-regexp
4758 'mouse-face 'highlight
4760 (format "mouse-2 or RET jump to org file %s"
4761 (abbreviate-file-name buffer-file-name))))
4762 (regexp org-tr-regexp)
4763 (d0 (calendar-absolute-from-gregorian date))
4764 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4766 (goto-char (point-min))
4767 (while (re-search-forward regexp nil t)
4771 (setq timestr (match-string 0)
4774 d1 (time-to-days (org-time-string-to-time s1))
4775 d2 (time-to-days (org-time-string-to-time s2)))
4776 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4777 ;; Only allow days between the limits, because the normal
4778 ;; date stamps will catch the limits.
4780 (setq todo-state (org-get-todo-state))
4781 (setq donep (member todo-state org-done-keywords))
4782 (if (and donep org-agenda-skip-timestamp-if-done)
4784 (setq marker (org-agenda-new-marker (point)))
4785 (setq category (org-get-category))
4786 (if (not (re-search-backward "^\\*+ " nil t))
4787 (setq txt org-agenda-no-heading-message)
4788 (goto-char (match-beginning 0))
4789 (setq hdmarker (org-agenda-new-marker (point)))
4790 (setq tags (org-get-tags-at))
4791 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4792 (setq head (match-string 1))
4793 (setq txt (org-format-agenda-item
4795 (nth (if (= d1 d2) 0 1)
4796 org-agenda-timerange-leaders)
4797 (1+ (- d0 d1)) (1+ (- d2 d1)))
4800 (org-add-props txt props
4801 'org-marker marker 'org-hd-marker hdmarker
4802 'type "block" 'date date
4803 'todo-state todo-state
4804 'priority (org-get-priority txt) 'org-category category)
4807 ;; Sort the entries by expiration date.
4810 ;;; Agenda presentation and sorting
4812 (defvar org-prefix-has-time nil
4813 "A flag, set by `org-compile-prefix-format'.
4814 The flag is set if the currently compiled format contains a `%t'.")
4815 (defvar org-prefix-has-tag nil
4816 "A flag, set by `org-compile-prefix-format'.
4817 The flag is set if the currently compiled format contains a `%T'.")
4818 (defvar org-prefix-has-effort nil
4819 "A flag, set by `org-compile-prefix-format'.
4820 The flag is set if the currently compiled format contains a `%e'.")
4821 (defvar org-prefix-category-length nil
4822 "Used by `org-compile-prefix-format' to remember the category field widh.")
4823 (defvar org-prefix-category-max-length nil
4824 "Used by `org-compile-prefix-format' to remember the category field widh.")
4826 (defun org-format-agenda-item (extra txt &optional category tags dotime
4827 noprefix remove-re habitp)
4828 "Format TXT to be inserted into the agenda buffer.
4829 In particular, it adds the prefix and corresponding text properties. EXTRA
4830 must be a string and replaces the `%s' specifier in the prefix format.
4831 CATEGORY (string, symbol or nil) may be used to overrule the default
4832 category taken from local variable or file name. It will replace the `%c'
4833 specifier in the format. DOTIME, when non-nil, indicates that a
4834 time-of-day should be extracted from TXT for sorting of this entry, and for
4835 the `%t' specifier in the format. When DOTIME is a string, this string is
4836 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4837 only the correctly processes TXT should be returned - this is used by
4838 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4839 Any match of REMOVE-RE will be removed from TXT."
4841 ;; Diary entries sometimes have extra whitespace at the beginning
4842 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4844 ;; Fix the tags part in txt
4845 (setq txt (org-agenda-fix-displayed-tags
4847 org-agenda-show-inherited-tags
4848 org-agenda-hide-tags-regexp))
4849 (let* ((category (or category
4851 (if buffer-file-name
4852 (file-name-sans-extension
4853 (file-name-nondirectory buffer-file-name))
4855 ;; time, tag, effort are needed for the eval of the prefix format
4856 (tag (if tags (nth (1- (length tags)) tags) ""))
4858 (ts (if dotime (concat
4859 (if (stringp dotime) dotime "")
4860 (and org-agenda-search-headline-for-time txt))))
4861 (time-of-day (and dotime (org-get-time-of-day ts)))
4862 stamp plain s0 s1 s2 t1 t2 rtn srp l
4863 duration thecategory)
4864 (and (org-mode-p) buffer-file-name
4865 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4866 (when (and dotime time-of-day)
4867 ;; Extract starting and ending time and move them to prefix
4868 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4869 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4870 (setq s0 (match-string 0 ts)
4871 srp (and stamp (match-end 3))
4872 s1 (match-string (if plain 1 2) ts)
4873 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4875 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4876 ;; them, we might want to remove them there to avoid duplication.
4877 ;; The user can turn this off with a variable.
4878 (if (and org-prefix-has-time
4879 org-agenda-remove-times-when-in-prefix (or stamp plain)
4880 (string-match (concat (regexp-quote s0) " *") txt)
4881 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4882 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4883 (= (match-beginning 0) 0)
4885 (setq txt (replace-match "" nil nil txt))))
4886 ;; Normalize the time(s) to 24 hour
4887 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4888 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4889 ;; Compute the duration
4891 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4892 (string-to-number (substring s1 3)))
4894 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4895 (string-to-number (substring s2 3))))
4896 (org-agenda-default-appointment-duration
4897 (+ t1 org-agenda-default-appointment-duration))
4899 (setq duration (if t2 (- t2 t1)))))
4901 (when (and s1 (not s2) org-agenda-default-appointment-duration
4902 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4903 (let ((m (+ (string-to-number (match-string 2 s1))
4904 (* 60 (string-to-number (match-string 1 s1)))
4905 org-agenda-default-appointment-duration))
4907 (setq h (/ m 60) m (- m (* h 60)))
4908 (setq s2 (format "%02d:%02d" h m))))
4910 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4912 ;; Tags are in the string
4913 (if (or (eq org-agenda-remove-tags t)
4914 (and org-agenda-remove-tags
4915 org-prefix-has-tag))
4916 (setq txt (replace-match "" t t txt))
4917 (setq txt (replace-match
4918 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
4919 (match-string 2 txt))
4925 (or (get-text-property 0 'org-hd-marker txt)
4926 (get-text-property 0 'org-marker txt)))
4929 (setq neffort (org-hh:mm-string-to-minutes effort)
4930 effort (setq effort (concat "[" effort "]" )))))
4933 (while (string-match remove-re txt)
4934 (setq txt (replace-match "" t t txt))))
4936 ;; Create the final string
4939 ;; Prepare the variables needed in the eval of the compiled format
4940 (setq time (cond (s2 (concat s1 "-" s2))
4941 (s1 (concat s1 "......"))
4943 extra (or (and (not habitp) extra) "")
4944 category (if (symbolp category) (symbol-name category) category)
4945 thecategory (copy-sequence category))
4946 (if (string-match org-bracket-link-regexp category)
4948 (setq l (if (match-end 3)
4949 (- (match-end 3) (match-beginning 3))
4950 (- (match-end 1) (match-beginning 1))))
4951 (when (< l (or org-prefix-category-length 0))
4952 (setq category (copy-sequence category))
4953 (org-add-props category nil
4954 'extra-space (make-string
4955 (- org-prefix-category-length l 1) ?\ ))))
4956 (if (and org-prefix-category-max-length
4957 (>= (length category) org-prefix-category-max-length))
4958 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
4959 ;; Evaluate the compiled format
4960 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
4962 ;; And finally add the text properties
4963 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
4964 (org-add-props rtn nil
4965 'org-category (if thecategory (downcase thecategory) category)
4966 'tags (mapcar 'org-downcase-keep-props tags)
4967 'org-highest-priority org-highest-priority
4968 'org-lowest-priority org-lowest-priority
4969 'prefix-length (- (length rtn) (length txt))
4970 'time-of-day time-of-day
4973 'effort-minutes neffort
4979 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
4980 "Remove tags string from TXT, and add a modified list of tags.
4981 The modified list may contain inherited tags, and tags matched by
4982 `org-agenda-hide-tags-regexp' will be removed."
4983 (when (or add-inherited hide-re)
4984 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
4985 (setq txt (substring txt 0 (match-beginning 0))))
4988 (mapcar (lambda (tg)
4989 (if (or (and hide-re (string-match hide-re tg))
4990 (and (not add-inherited)
4991 (get-text-property 0 'inherited tg)))
4996 (let ((have-i (get-text-property 0 'inherited (car tags)))
4998 (setq txt (concat txt " :"
5001 (setq i (get-text-property 0 'inherited x))
5002 (if (and have-i (not i))
5008 (if have-i "::" ":"))))))
5011 (defun org-downcase-keep-props (s)
5012 (let ((props (text-properties-at 0 s)))
5013 (setq s (downcase s))
5014 (add-text-properties 0 (length s) props s)
5017 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5018 (defvar org-agenda-sorting-strategy-selected nil)
5020 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5022 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5023 ((and todayp (member 'today (car org-agenda-time-grid))))
5024 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5025 ((member 'weekly (car org-agenda-time-grid)))
5026 (t (throw 'exit list)))
5027 (let* ((have (delq nil (mapcar
5028 (lambda (x) (get-text-property 1 'time-of-day x))
5030 (string (nth 1 org-agenda-time-grid))
5031 (gridtimes (nth 2 org-agenda-time-grid))
5032 (req (car org-agenda-time-grid))
5033 (remove (member 'remove-match req))
5035 (if (and (member 'require-timed req) (not have))
5036 ;; don't show empty grid
5038 (while (setq time (pop gridtimes))
5039 (unless (and remove (member time have))
5040 (setq time (int-to-string time))
5041 (push (org-format-agenda-item
5043 (concat (substring time 0 -2) ":" (substring time -2)))
5046 1 (length (car new)) 'face 'org-time-grid (car new))))
5047 (if (member 'time-up org-agenda-sorting-strategy-selected)
5049 (append list new)))))
5051 (defun org-compile-prefix-format (key)
5052 "Compile the prefix format into a Lisp form that can be evaluated.
5053 The resulting form is returned and stored in the variable
5054 `org-prefix-format-compiled'."
5055 (setq org-prefix-has-time nil org-prefix-has-tag nil
5056 org-prefix-category-length nil org-prefix-has-effort nil)
5058 ((stringp org-agenda-prefix-format)
5059 org-agenda-prefix-format)
5060 ((assq key org-agenda-prefix-format)
5061 (cdr (assq key org-agenda-prefix-format)))
5062 (t " %-12:c%?-12t% s")))
5064 varform vars var e c f opt)
5065 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
5067 (setq var (cdr (assoc (match-string 4 s)
5068 '(("c" . category) ("t" . time) ("s" . extra)
5069 ("T" . tag) ("e" . effort))))
5070 c (or (match-string 3 s) "")
5071 opt (match-beginning 1)
5072 start (1+ (match-beginning 0)))
5073 (if (equal var 'time) (setq org-prefix-has-time t))
5074 (if (equal var 'tag) (setq org-prefix-has-tag t))
5075 (if (equal var 'effort) (setq org-prefix-has-effort t))
5076 (setq f (concat "%" (match-string 2 s) "s"))
5077 (when (equal var 'category)
5078 (setq org-prefix-category-length
5079 (floor (abs (string-to-number (match-string 2 s)))))
5080 (setq org-prefix-category-max-length
5081 (let ((x (match-string 2 s)))
5083 (if (string-match "\\.[0-9]+" x)
5084 (string-to-number (substring (match-string 0 x) 1)))))))
5087 `(if (equal "" ,var)
5089 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5090 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
5091 (setq s (replace-match "%s" t nil s))
5092 (push varform vars))
5093 (setq vars (nreverse vars))
5094 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5096 (defun org-set-sorting-strategy (key)
5097 (if (symbolp (car org-agenda-sorting-strategy))
5099 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5100 (setq org-agenda-sorting-strategy-selected
5101 (or (cdr (assq key org-agenda-sorting-strategy))
5102 (cdr (assq 'agenda org-agenda-sorting-strategy))
5103 '(time-up category-keep priority-down)))))
5105 (defun org-get-time-of-day (s &optional string mod24)
5106 "Check string S for a time of day.
5107 If found, return it as a military time number between 0 and 2400.
5108 If not found, return nil.
5109 The optional STRING argument forces conversion into a 5 character wide string
5113 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5114 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5115 (let* ((h (string-to-number (match-string 1 s)))
5116 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5117 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5118 (am-p (equal ampm "am"))
5119 (h1 (cond ((not ampm) h)
5120 ((= h 12) (if am-p 0 12))
5121 (t (+ h (if am-p 0 12)))))
5122 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5124 (t0 (+ (* 100 h2) m))
5125 (t1 (concat (if (>= h1 24) "+" " ")
5126 (if (and org-agenda-time-leading-zero
5127 (< t0 1000)) "0" "")
5128 (if (< t0 100) "0" "")
5129 (if (< t0 10) "0" "")
5130 (int-to-string t0))))
5131 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5133 (defun org-finalize-agenda-entries (list &optional nosort)
5134 "Sort and concatenate the agenda items."
5135 (setq list (mapcar 'org-agenda-highlight-todo list))
5138 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5140 (defun org-agenda-highlight-todo (x)
5141 (let ((org-done-keywords org-done-keywords-for-agenda)
5142 (case-fold-search nil)
5146 (beginning-of-line 1)
5147 (setq re (org-get-at-bol 'org-todo-regexp))
5148 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
5149 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5150 (add-text-properties (match-beginning 0) (match-end 1)
5151 (list 'face (org-get-todo-face 1)))
5152 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5153 (delete-region (match-beginning 1) (1- (match-end 0)))
5154 (goto-char (match-beginning 1))
5155 (insert (format org-agenda-todo-keyword-format s)))))
5156 (setq re (concat (get-text-property 0 'org-todo-regexp x))
5157 pl (get-text-property 0 'prefix-length x))
5159 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5161 (add-text-properties
5162 (or (match-end 1) (match-end 0)) (match-end 0)
5163 (list 'face (org-get-todo-face (match-string 2 x)))
5166 (setq x (concat (substring x 0 (match-end 1))
5167 (format org-agenda-todo-keyword-format
5169 (org-add-props " " (text-properties-at 0 x))
5170 (substring x (match-end 3))))))
5173 (defsubst org-cmp-priority (a b)
5174 "Compare the priorities of string A and B."
5175 (let ((pa (or (get-text-property 1 'priority a) 0))
5176 (pb (or (get-text-property 1 'priority b) 0)))
5177 (cond ((> pa pb) +1)
5181 (defsubst org-cmp-effort (a b)
5182 "Compare the priorities of string A and B."
5183 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5184 (ea (or (get-text-property 1 'effort-minutes a) def))
5185 (eb (or (get-text-property 1 'effort-minutes b) def)))
5186 (cond ((> ea eb) +1)
5190 (defsubst org-cmp-category (a b)
5191 "Compare the string values of categories of strings A and B."
5192 (let ((ca (or (get-text-property 1 'org-category a) ""))
5193 (cb (or (get-text-property 1 'org-category b) "")))
5194 (cond ((string-lessp ca cb) -1)
5195 ((string-lessp cb ca) +1)
5198 (defsubst org-cmp-todo-state (a b)
5199 "Compare the todo states of strings A and B."
5200 (let* ((ma (or (get-text-property 1 'org-marker a)
5201 (get-text-property 1 'org-hd-marker a)))
5202 (mb (or (get-text-property 1 'org-marker b)
5203 (get-text-property 1 'org-hd-marker b)))
5204 (fa (and ma (marker-buffer ma)))
5205 (fb (and mb (marker-buffer mb)))
5207 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5208 (and fb (with-current-buffer fb org-todo-keywords-1))))
5209 (ta (or (get-text-property 1 'todo-state a) ""))
5210 (tb (or (get-text-property 1 'todo-state b) ""))
5211 (la (- (length (member ta todo-kwds))))
5212 (lb (- (length (member tb todo-kwds))))
5213 (donepa (member ta org-done-keywords-for-agenda))
5214 (donepb (member tb org-done-keywords-for-agenda)))
5215 (cond ((and donepa (not donepb)) -1)
5216 ((and (not donepa) donepb) +1)
5221 (defsubst org-cmp-alpha (a b)
5222 "Compare the headlines, alphabetically."
5223 (let* ((pla (get-text-property 0 'prefix-length a))
5224 (plb (get-text-property 0 'prefix-length b))
5225 (ta (and pla (substring a pla)))
5226 (tb (and plb (substring b plb))))
5228 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5229 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5230 (setq ta (substring ta (match-end 0))))
5231 (setq ta (downcase ta)))
5233 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5234 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5235 (setq tb (substring tb (match-end 0))))
5236 (setq tb (downcase tb)))
5239 ((string-lessp ta tb) -1)
5240 ((string-lessp tb ta) +1)
5243 (defsubst org-cmp-tag (a b)
5244 "Compare the string values of the first tags of A and B."
5245 (let ((ta (car (last (get-text-property 1 'tags a))))
5246 (tb (car (last (get-text-property 1 'tags b)))))
5249 ((string-lessp ta tb) -1)
5250 ((string-lessp tb ta) +1)
5253 (defsubst org-cmp-time (a b)
5254 "Compare the time-of-day values of strings A and B."
5255 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5256 (ta (or (get-text-property 1 'time-of-day a) def))
5257 (tb (or (get-text-property 1 'time-of-day b) def)))
5258 (cond ((< ta tb) -1)
5262 (defsubst org-cmp-habit-p (a b)
5263 "Compare the todo states of strings A and B."
5264 (let ((ha (get-text-property 1 'org-habit-p a))
5265 (hb (get-text-property 1 'org-habit-p b)))
5266 (cond ((and ha (not hb)) -1)
5267 ((and (not ha) hb) +1)
5270 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5272 (defun org-entries-lessp (a b)
5273 "Predicate for sorting agenda entries."
5274 ;; The following variables will be used when the form is evaluated.
5275 ;; So even though the compiler complains, keep them.
5276 (let* ((ss org-agenda-sorting-strategy-selected)
5277 (time-up (and (org-em 'time-up 'time-down ss)
5278 (org-cmp-time a b)))
5279 (time-down (if time-up (- time-up) nil))
5280 (priority-up (and (org-em 'priority-up 'priority-down ss)
5281 (org-cmp-priority a b)))
5282 (priority-down (if priority-up (- priority-up) nil))
5283 (effort-up (and (org-em 'effort-up 'effort-down ss)
5284 (org-cmp-effort a b)))
5285 (effort-down (if effort-up (- effort-up) nil))
5286 (category-up (and (or (org-em 'category-up 'category-down ss)
5287 (memq 'category-keep ss))
5288 (org-cmp-category a b)))
5289 (category-down (if category-up (- category-up) nil))
5290 (category-keep (if category-up +1 nil))
5291 (tag-up (and (org-em 'tag-up 'tag-down ss)
5293 (tag-down (if tag-up (- tag-up) nil))
5294 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5295 (org-cmp-todo-state a b)))
5296 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5297 (habit-up (and (org-em 'habit-up 'habit-down ss)
5298 (org-cmp-habit-p a b)))
5299 (habit-down (if habit-up (- habit-up) nil))
5300 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5301 (org-cmp-alpha a b)))
5302 (alpha-down (if alpha-up (- alpha-up) nil))
5303 user-defined-up user-defined-down)
5304 (if (and org-agenda-cmp-user-defined
5305 (functionp org-agenda-cmp-user-defined))
5306 (setq user-defined-up
5307 (funcall org-agenda-cmp-user-defined a b)
5308 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5310 (eval (cons 'or org-agenda-sorting-strategy-selected))
5311 '((-1 . t) (1 . nil) (nil . nil))))))
5313 ;;; Agenda restriction lock
5315 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5316 "Overlay to mark the headline to which agenda commands are restricted.")
5317 (overlay-put org-agenda-restriction-lock-overlay
5318 'face 'org-agenda-restriction-lock)
5319 (overlay-put org-agenda-restriction-lock-overlay
5320 'help-echo "Agendas are currently limited to this subtree.")
5321 (org-detach-overlay org-agenda-restriction-lock-overlay)
5323 (defun org-agenda-set-restriction-lock (&optional type)
5324 "Set restriction lock for agenda, to current subtree or file.
5325 Restriction will be the file if TYPE is `file', or if type is the
5326 universal prefix '(4), or if the cursor is before the first headline
5327 in the file. Otherwise, restriction will be to the current subtree."
5329 (and (equal type '(4)) (setq type 'file))
5332 ((org-at-heading-p) 'subtree)
5333 ((condition-case nil (org-back-to-heading t) (error nil))
5336 (if (eq type 'subtree)
5338 (setq org-agenda-restrict t)
5339 (setq org-agenda-overriding-restriction 'subtree)
5340 (put 'org-agenda-files 'org-restrict
5341 (list (buffer-file-name (buffer-base-buffer))))
5342 (org-back-to-heading t)
5343 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5344 (move-marker org-agenda-restrict-begin (point))
5345 (move-marker org-agenda-restrict-end
5346 (save-excursion (org-end-of-subtree t)))
5347 (message "Locking agenda restriction to subtree"))
5348 (put 'org-agenda-files 'org-restrict
5349 (list (buffer-file-name (buffer-base-buffer))))
5350 (setq org-agenda-restrict nil)
5351 (setq org-agenda-overriding-restriction 'file)
5352 (move-marker org-agenda-restrict-begin nil)
5353 (move-marker org-agenda-restrict-end nil)
5354 (message "Locking agenda restriction to file"))
5355 (setq current-prefix-arg nil)
5356 (org-agenda-maybe-redo))
5358 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5359 "Remove the agenda restriction lock."
5361 (org-detach-overlay org-agenda-restriction-lock-overlay)
5362 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5363 (setq org-agenda-overriding-restriction nil)
5364 (setq org-agenda-restrict nil)
5365 (put 'org-agenda-files 'org-restrict nil)
5366 (move-marker org-agenda-restrict-begin nil)
5367 (move-marker org-agenda-restrict-end nil)
5368 (setq current-prefix-arg nil)
5369 (message "Agenda restriction lock removed")
5370 (or noupdate (org-agenda-maybe-redo)))
5372 (defun org-agenda-maybe-redo ()
5373 "If there is any window showing the agenda view, update it."
5374 (let ((w (get-buffer-window org-agenda-buffer-name t))
5375 (w0 (selected-window)))
5380 (if org-agenda-overriding-restriction
5381 (message "Agenda view shifted to new %s restriction"
5382 org-agenda-overriding-restriction)
5383 (message "Agenda restriction lock removed")))))
5387 (defun org-agenda-check-type (error &rest types)
5388 "Check if agenda buffer is of allowed type.
5389 If ERROR is non-nil, throw an error, otherwise just return nil."
5390 (if (memq org-agenda-type types)
5393 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5396 (defun org-agenda-quit ()
5397 "Exit agenda by removing the window or the buffer."
5399 (if org-agenda-columns-active
5401 (let ((buf (current-buffer)))
5402 (if (eq org-agenda-window-setup 'other-frame)
5405 (org-agenda-reset-markers)
5406 (org-columns-remove-overlays)
5407 (setq org-agenda-archives-mode nil)
5409 (and (not (eq org-agenda-window-setup 'current-window))
5410 (not (one-window-p))
5413 (org-agenda-reset-markers)
5414 (org-columns-remove-overlays)
5415 (setq org-agenda-archives-mode nil)))
5416 ;; Maybe restore the pre-agenda window configuration.
5417 (and org-agenda-restore-windows-after-quit
5418 (not (eq org-agenda-window-setup 'other-frame))
5419 org-pre-agenda-window-conf
5420 (set-window-configuration org-pre-agenda-window-conf))))
5422 (defun org-agenda-exit ()
5423 "Exit agenda by removing the window or the buffer.
5424 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5425 Org-mode buffers visited directly by the user will not be touched."
5427 (org-release-buffers org-agenda-new-buffers)
5428 (setq org-agenda-new-buffers nil)
5431 (defun org-agenda-execute (arg)
5432 "Execute another agenda command, keeping same window.\\<global-map>
5433 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
5435 (let ((org-agenda-window-setup 'current-window))
5438 (defun org-agenda-redo ()
5440 When this is the global TODO list, a prefix argument will be interpreted."
5442 (let* ((org-agenda-keep-modes t)
5443 (filter org-agenda-filter)
5444 (preset (get 'org-agenda-filter :preset-filter))
5445 (cols org-agenda-columns-active)
5446 (line (org-current-line))
5447 (window-line (- line (org-current-line (window-start))))
5448 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5449 (put 'org-agenda-filter :preset-filter nil)
5450 (and cols (org-columns-quit))
5451 (message "Rebuilding agenda buffer...")
5452 (org-let lprops '(eval org-agenda-redo-command))
5453 (setq org-agenda-undo-list nil
5454 org-agenda-pending-undo-list nil)
5455 (message "Rebuilding agenda buffer...done")
5456 (put 'org-agenda-filter :preset-filter preset)
5457 (and (or filter preset) (org-agenda-filter-apply filter))
5458 (and cols (interactive-p) (org-agenda-columns))
5459 (org-goto-line line)
5460 (recenter window-line)))
5463 (defvar org-global-tags-completion-table nil)
5464 (defvar org-agenda-filter-form nil)
5465 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5466 "Keep only those lines in the agenda buffer that have a specific tag.
5467 The tag is selected with its fast selection letter, as configured.
5468 With prefix argument STRIP, remove all lines that do have the tag.
5469 A lisp caller can specify CHAR. NARROW means that the new tag should be
5470 used to narrow the search - the interactive user can also press `-' or `+'
5471 to switch to narrowing."
5473 (let* ((alist org-tag-alist-for-agenda)
5474 (tag-chars (mapconcat
5475 (lambda (x) (if (and (not (symbolp (car x)))
5477 (char-to-string (cdr x))
5480 (efforts (org-split-string
5481 (or (cdr (assoc (concat org-effort-property "_ALL")
5482 org-global-properties))
5483 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5484 (effort-op org-agenda-filter-effort-default-operator)
5486 (inhibit-read-only t)
5487 (current org-agenda-filter)
5491 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5492 (if narrow "Narrow" "Filter") tag-chars
5493 (if org-agenda-auto-exclude-function "[RET], " ""))
5494 (setq char (read-char)))
5495 (when (member char '(?+ ?-))
5497 (cond ((equal char ?-) (setq strip t narrow t))
5498 ((equal char ?+) (setq strip nil narrow t)))
5500 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5501 (setq char (read-char)))
5502 (when (member char '(?< ?> ?= ??))
5503 ;; An effort operator
5504 (setq effort-op (char-to-string char))
5505 (setq alist nil) ; to make sure it will be interpreted as effort.
5506 (unless (equal char ??)
5507 (loop for i from 0 to 9 do
5511 (if (= i 9) "0" (int-to-string (1+ i)))
5512 "]" (nth i efforts))))
5513 (message "Effort%s: %s " effort-op effort-prompt)
5514 (setq char (read-char))
5515 (when (or (< char ?0) (> char ?9))
5516 (error "Need 1-9,0 to select effort" ))))
5517 (when (equal char ?\t)
5518 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5519 (org-set-local 'org-global-tags-completion-table
5520 (org-global-tags-completion-table)))
5521 (let ((completion-ignore-case t))
5522 (setq tag (org-icompleting-read
5523 "Tag: " org-global-tags-completion-table))))
5526 (org-agenda-filter-by-tag-show-all)
5527 (when org-agenda-auto-exclude-function
5528 (setq org-agenda-filter '())
5529 (dolist (tag (org-agenda-get-represented-tags))
5530 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5532 (push modifier org-agenda-filter))))
5533 (if (not (null org-agenda-filter))
5534 (org-agenda-filter-apply org-agenda-filter))))
5536 (org-agenda-filter-by-tag-show-all)
5537 (when (get 'org-agenda-filter :preset-filter)
5538 (org-agenda-filter-apply org-agenda-filter)))
5539 ((or (equal char ?\ )
5540 (setq a (rassoc char alist))
5541 (and (>= char ?0) (<= char ?9)
5542 (setq n (if (= char ?0) 9 (- char ?0 1))
5543 tag (concat effort-op (nth n efforts))
5548 (and tag (setq a (cons tag nil))))
5549 (org-agenda-filter-by-tag-show-all)
5551 (setq org-agenda-filter
5552 (cons (concat (if strip "-" "+") tag)
5553 (if narrow current nil)))
5554 (org-agenda-filter-apply org-agenda-filter))
5555 (t (error "Invalid tag selection character %c" char)))))
5557 (defun org-agenda-get-represented-tags ()
5558 "Get a list of all tags currently represented in the agenda."
5561 (goto-char (point-min))
5562 (while (setq p (next-single-property-change (point) 'tags))
5564 (mapc (lambda (x) (add-to-list 'tags x))
5565 (get-text-property (point) 'tags))))
5568 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5569 "Refine the current filter. See `org-agenda-filter-by-tag."
5571 (org-agenda-filter-by-tag strip char 'refine))
5573 (defun org-agenda-filter-make-matcher ()
5574 "Create the form that tests a line for the agenda filter."
5576 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5578 (if (member x '("-" "+"))
5579 (setq f1 (if (equal x "-") 'tags '(not tags)))
5580 (if (string-match "[<=>?]" x)
5581 (setq f1 (org-agenda-filter-effort-form x))
5582 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5583 (if (equal (string-to-char x) ?-)
5584 (setq f1 (list 'not f1))))
5586 (cons 'and (nreverse f))))
5588 (defun org-agenda-filter-effort-form (e)
5589 "Return the form to compare the effort of the current line with what E says.
5590 E looks line \"+<2:25\"."
5592 (setq e (substring e 1))
5593 (setq op (string-to-char e) e (substring e 1))
5594 (setq op (cond ((equal op ?<) '<=)
5598 (list 'org-agenda-compare-effort (list 'quote op)
5599 (org-hh:mm-string-to-minutes e))))
5601 (defun org-agenda-compare-effort (op value)
5602 "Compare the effort of the current line with VALUE, using OP.
5603 If the line does not have an effort defined, return nil."
5604 (let ((eff (org-get-at-bol 'effort-minutes)))
5607 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5610 (defun org-agenda-filter-apply (filter)
5611 "Set FILTER as the new agenda filter and apply it."
5613 (setq org-agenda-filter filter
5614 org-agenda-filter-form (org-agenda-filter-make-matcher))
5615 (org-agenda-set-mode-name)
5617 (goto-char (point-min))
5619 (if (org-get-at-bol 'org-marker)
5621 (setq tags (org-get-at-bol 'tags)) ; used in eval
5622 (if (not (eval org-agenda-filter-form))
5623 (org-agenda-filter-by-tag-hide-line))
5624 (beginning-of-line 2))
5625 (beginning-of-line 2))))))
5627 (defun org-agenda-filter-by-tag-hide-line ()
5629 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
5631 (overlay-put ov 'invisible t)
5632 (overlay-put ov 'type 'tags-filter)
5633 (push ov org-agenda-filter-overlays)))
5635 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5636 (setq pos (or pos (point)))
5638 (dolist (ov (overlays-at pos))
5639 (when (and (overlay-get ov 'invisible)
5640 (eq (overlay-get ov 'type) 'tags-filter))
5642 (if (< (overlay-start ov) (point-at-eol))
5643 (move-overlay ov (point-at-eol)
5644 (overlay-end ov)))))))
5646 (defun org-agenda-filter-by-tag-show-all ()
5647 (mapc 'delete-overlay org-agenda-filter-overlays)
5648 (setq org-agenda-filter-overlays nil)
5649 (setq org-agenda-filter nil)
5650 (setq org-agenda-filter-form nil)
5651 (org-agenda-set-mode-name))
5653 (defun org-agenda-manipulate-query-add ()
5654 "Manipulate the query by adding a search term with positive selection.
5655 Positive selection means the term must be matched for selection of an entry."
5657 (org-agenda-manipulate-query ?\[))
5658 (defun org-agenda-manipulate-query-subtract ()
5659 "Manipulate the query by adding a search term with negative selection.
5660 Negative selection means term must not be matched for selection of an entry."
5662 (org-agenda-manipulate-query ?\]))
5663 (defun org-agenda-manipulate-query-add-re ()
5664 "Manipulate the query by adding a search regexp with positive selection.
5665 Positive selection means the regexp must match for selection of an entry."
5667 (org-agenda-manipulate-query ?\{))
5668 (defun org-agenda-manipulate-query-subtract-re ()
5669 "Manipulate the query by adding a search regexp with negative selection.
5670 Negative selection means regexp must not match for selection of an entry."
5672 (org-agenda-manipulate-query ?\}))
5673 (defun org-agenda-manipulate-query (char)
5675 ((memq org-agenda-type '(timeline agenda))
5676 (let ((org-agenda-include-inactive-timestamps t))
5678 (message "Display now includes inactive timestamps as well"))
5679 ((eq org-agenda-type 'search)
5681 'org-agenda-query-string
5682 (if org-agenda-last-search-view-search-was-boolean
5683 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5684 (?\{ . " +{}") (?\} . " -{}"))))
5686 (setq org-agenda-redo-command
5687 (list 'org-search-view
5689 org-agenda-query-string
5690 (+ (length org-agenda-query-string)
5691 (if (member char '(?\{ ?\})) 0 1))))
5692 (set-register org-agenda-query-register org-agenda-query-string)
5694 (t (error "Cannot manipulate query for %s-type agenda buffers"
5697 (defun org-add-to-string (var string)
5698 (set var (concat (symbol-value var) string)))
5700 (defun org-agenda-goto-date (date)
5701 "Jump to DATE in agenda."
5702 (interactive (list (org-read-date)))
5703 (org-agenda-list nil date))
5705 (defun org-agenda-goto-today ()
5708 (org-agenda-check-type t 'timeline 'agenda)
5709 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5711 (tdpos (goto-char tdpos))
5712 ((eq org-agenda-type 'agenda)
5713 (let* ((sd (time-to-days
5714 (time-subtract (current-time)
5715 (list 0 (* 3600 org-extend-today-until) 0))))
5716 (comp (org-agenda-compute-time-span sd org-agenda-span))
5717 (org-agenda-overriding-arguments org-agenda-last-arguments))
5718 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5719 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5721 (org-agenda-find-same-or-today-or-agenda)))
5722 (t (error "Cannot find today")))))
5724 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5726 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5727 (text-property-any (point-min) (point-max) 'org-today t)
5728 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5731 (defun org-agenda-later (arg)
5732 "Go forward in time by thee current span.
5733 With prefix ARG, go forward that many times the current span."
5735 (org-agenda-check-type t 'agenda)
5736 (let* ((span org-agenda-span)
5737 (sd org-starting-day)
5738 (greg (calendar-gregorian-from-absolute sd))
5739 (cnt (org-get-at-bol 'org-day-cnt))
5743 (setq sd (+ arg sd) nd 1))
5745 (setq sd (+ (* 7 arg) sd) nd 7))
5747 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5748 sd (calendar-absolute-from-gregorian greg2))
5749 (setcar greg2 (1+ (car greg2)))
5750 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5752 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5753 sd (calendar-absolute-from-gregorian greg2))
5754 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5755 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5756 (let ((org-agenda-overriding-arguments
5757 (list (car org-agenda-last-arguments) sd nd t)))
5759 (org-agenda-find-same-or-today-or-agenda cnt))))
5761 (defun org-agenda-earlier (arg)
5762 "Go backward in time by the current span.
5763 With prefix ARG, go backward that many times the current span."
5765 (org-agenda-later (- arg)))
5767 (defun org-agenda-view-mode-dispatch ()
5768 "Call one of the view mode commands."
5770 (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
5771 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
5772 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
5773 (let ((a (read-char-exclusive)))
5775 (?d (call-interactively 'org-agenda-day-view))
5776 (?w (call-interactively 'org-agenda-week-view))
5777 (?m (call-interactively 'org-agenda-month-view))
5778 (?y (call-interactively 'org-agenda-year-view))
5779 (?l (call-interactively 'org-agenda-log-mode))
5780 (?L (org-agenda-log-mode '(4)))
5781 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5782 (?a (call-interactively 'org-agenda-archives-mode))
5783 (?A (org-agenda-archives-mode 'files))
5784 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5785 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5786 (?G (call-interactively 'org-agenda-toggle-time-grid))
5787 (?D (call-interactively 'org-agenda-toggle-diary))
5788 (?\! (call-interactively 'org-agenda-toggle-deadlines))
5789 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5790 (org-agenda-check-type t 'timeline 'agenda)
5792 (message "Display now includes inactive timestamps as well"))
5793 (?q (message "Abort"))
5794 (otherwise (error "Invalid key" )))))
5796 (defun org-agenda-day-view (&optional day-of-year)
5797 "Switch to daily view for agenda.
5798 With argument DAY-OF-YEAR, switch to that day of the year."
5800 (setq org-agenda-ndays 1)
5801 (org-agenda-change-time-span 'day day-of-year))
5802 (defun org-agenda-week-view (&optional iso-week)
5803 "Switch to daily view for agenda.
5804 With argument ISO-WEEK, switch to the corresponding ISO week.
5805 If ISO-WEEK has more then 2 digits, only the last two encode the
5806 week. Any digits before this encode a year. So 200712 means
5807 week 12 of year 2007. Years in the range 1938-2037 can also be
5808 written as 2-digit years."
5810 (setq org-agenda-ndays 7)
5811 (org-agenda-change-time-span 'week iso-week))
5812 (defun org-agenda-month-view (&optional month)
5813 "Switch to monthly view for agenda.
5814 With argument MONTH, switch to that month."
5816 (org-agenda-change-time-span 'month month))
5817 (defun org-agenda-year-view (&optional year)
5818 "Switch to yearly view for agenda.
5819 With argument YEAR, switch to that year.
5820 If MONTH has more then 2 digits, only the last two encode the
5821 month. Any digits before this encode a year. So 200712 means
5822 December year 2007. Years in the range 1938-2037 can also be
5823 written as 2-digit years."
5826 (setq year (org-small-year-to-year year)))
5827 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5828 (org-agenda-change-time-span 'year year)
5831 (defun org-agenda-change-time-span (span &optional n)
5832 "Change the agenda view to SPAN.
5833 SPAN may be `day', `week', `month', `year'."
5834 (org-agenda-check-type t 'agenda)
5835 (if (and (not n) (equal org-agenda-span span))
5836 (error "Viewing span is already \"%s\"" span))
5837 (let* ((sd (or (org-get-at-bol 'day)
5839 (computed (org-agenda-compute-time-span sd span n))
5840 (org-agenda-overriding-arguments
5841 (list (car org-agenda-last-arguments)
5842 (car computed) (cdr computed) t)))
5844 (org-agenda-find-same-or-today-or-agenda))
5845 (org-agenda-set-mode-name)
5846 (message "Switched to %s view" span))
5848 (defun org-agenda-compute-time-span (sd span &optional n)
5849 "Compute starting date and number of days for agenda.
5850 SPAN may be `day', `week', `month', `year'. The return value
5851 is a cons cell with the starting date and the number of days,
5852 so that the date SD will be in that range."
5853 (let* ((greg (calendar-gregorian-from-absolute sd))
5857 nd w1 y1 m1 thisweek)
5861 (setq sd (+ (calendar-absolute-from-gregorian
5866 (let* ((nt (calendar-day-of-week
5867 (calendar-gregorian-from-absolute sd)))
5868 (d (if org-agenda-start-on-weekday
5869 (- nt org-agenda-start-on-weekday)
5871 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5874 (setq thisweek (car (calendar-iso-from-absolute sd)))
5876 (setq y1 (org-small-year-to-year (/ n 100))
5879 (calendar-absolute-from-iso
5881 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5884 (when (and n (> n 99))
5885 (setq y1 (org-small-year-to-year (/ n 100))
5887 (setq sd (calendar-absolute-from-gregorian
5888 (list (or n mg) 1 (or y1 yg)))
5889 nd (- (calendar-absolute-from-gregorian
5890 (list (1+ (or n mg)) 1 (or y1 yg)))
5893 (setq sd (calendar-absolute-from-gregorian
5894 (list 1 1 (or n yg)))
5895 nd (- (calendar-absolute-from-gregorian
5896 (list 1 1 (1+ (or n yg))))
5900 (defun org-agenda-next-date-line (&optional arg)
5901 "Jump to the next line indicating a date in agenda buffer."
5903 (org-agenda-check-type t 'agenda 'timeline)
5904 (beginning-of-line 1)
5905 ;; This does not work if user makes date format that starts with a blank
5906 (if (looking-at "^\\S-") (forward-char 1))
5907 (if (not (re-search-forward "^\\S-" nil t arg))
5910 (error "No next date after this line in this buffer")))
5911 (goto-char (match-beginning 0)))
5913 (defun org-agenda-previous-date-line (&optional arg)
5914 "Jump to the previous line indicating a date in agenda buffer."
5916 (org-agenda-check-type t 'agenda 'timeline)
5917 (beginning-of-line 1)
5918 (if (not (re-search-backward "^\\S-" nil t arg))
5919 (error "No previous date before this line in this buffer")))
5921 ;; Initialize the highlight
5922 (defvar org-hl (make-overlay 1 1))
5923 (overlay-put org-hl 'face 'highlight)
5925 (defun org-highlight (begin end &optional buffer)
5926 "Highlight a region with overlay."
5927 (move-overlay org-hl begin end (or buffer (current-buffer))))
5929 (defun org-unhighlight ()
5930 "Detach overlay INDEX."
5931 (org-detach-overlay org-hl))
5933 ;; FIXME this is currently not used.
5934 (defun org-highlight-until-next-command (beg end &optional buffer)
5935 "Move the highlight overlay to BEG/END, remove it before the next command."
5936 (org-highlight beg end buffer)
5937 (add-hook 'pre-command-hook 'org-unhighlight-once))
5938 (defun org-unhighlight-once ()
5939 "Remove the highlight from its position, and this function from the hook."
5940 (remove-hook 'pre-command-hook 'org-unhighlight-once)
5943 (defun org-agenda-follow-mode ()
5944 "Toggle follow mode in an agenda buffer."
5946 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
5947 (org-agenda-set-mode-name)
5948 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5950 (message "Follow mode is %s"
5951 (if org-agenda-follow-mode "on" "off")))
5953 (defun org-agenda-entry-text-mode (&optional arg)
5954 "Toggle entry text mode in an agenda buffer."
5956 (setq org-agenda-entry-text-mode (or (integerp arg)
5957 (not org-agenda-entry-text-mode)))
5958 (org-agenda-entry-text-hide)
5959 (and org-agenda-entry-text-mode
5960 (let ((org-agenda-entry-text-maxlines
5961 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5962 (org-agenda-entry-text-show)))
5963 (org-agenda-set-mode-name)
5964 (message "Entry text mode is %s. Maximum number of lines is %d"
5965 (if org-agenda-entry-text-mode "on" "off")
5966 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5968 (defun org-agenda-clockreport-mode ()
5969 "Toggle clocktable mode in an agenda buffer."
5971 (org-agenda-check-type t 'agenda)
5972 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
5973 (org-agenda-set-mode-name)
5975 (message "Clocktable mode is %s"
5976 (if org-agenda-clockreport-mode "on" "off")))
5978 (defun org-agenda-log-mode (&optional special)
5979 "Toggle log mode in an agenda buffer.
5980 With argument SPECIAL, show all possible log items, not only the ones
5981 configured in `org-agenda-log-mode-items'.
5982 With a double `C-u' prefix arg, show *only* log items, nothing else."
5984 (org-agenda-check-type t 'agenda 'timeline)
5985 (setq org-agenda-show-log
5986 (if (equal special '(16))
5988 (if special '(closed clock state)
5989 (not org-agenda-show-log))))
5990 (org-agenda-set-mode-name)
5992 (message "Log mode is %s"
5993 (if org-agenda-show-log "on" "off")))
5995 (defun org-agenda-archives-mode (&optional with-files)
5996 "Toggle inclusion of items in trees marked with :ARCHIVE:.
5997 When called with a prefix argument, include all archive files as well."
5999 (setq org-agenda-archives-mode
6000 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6001 (org-agenda-set-mode-name)
6006 ((eq org-agenda-archives-mode nil)
6007 "No archives are included")
6008 ((eq org-agenda-archives-mode 'trees)
6009 (format "Trees with :%s: tag are included" org-archive-tag))
6010 ((eq org-agenda-archives-mode t)
6011 (format "Trees with :%s: tag and all active archive files are included"
6012 org-archive-tag)))))
6014 (defun org-agenda-toggle-diary ()
6015 "Toggle diary inclusion in an agenda buffer."
6017 (org-agenda-check-type t 'agenda)
6018 (setq org-agenda-include-diary (not org-agenda-include-diary))
6020 (org-agenda-set-mode-name)
6021 (message "Diary inclusion turned %s"
6022 (if org-agenda-include-diary "on" "off")))
6024 (defun org-agenda-toggle-deadlines ()
6025 "Toggle diary inclusion in an agenda buffer."
6027 (org-agenda-check-type t 'agenda)
6028 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6030 (org-agenda-set-mode-name)
6031 (message "Deadlines inclusion turned %s"
6032 (if org-agenda-include-deadlines "on" "off")))
6034 (defun org-agenda-toggle-time-grid ()
6035 "Toggle time grid in an agenda buffer."
6037 (org-agenda-check-type t 'agenda)
6038 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6040 (org-agenda-set-mode-name)
6041 (message "Time-grid turned %s"
6042 (if org-agenda-use-time-grid "on" "off")))
6044 (defun org-agenda-set-mode-name ()
6045 "Set the mode name to indicate all the small mode settings."
6047 (concat "Org-Agenda"
6048 (if (get 'org-agenda-files 'org-restrict) " []" "")
6049 (if (equal org-agenda-ndays 1) " Day" "")
6050 (if (equal org-agenda-ndays 7) " Week" "")
6051 (if org-agenda-follow-mode " Follow" "")
6052 (if org-agenda-entry-text-mode " ETxt" "")
6053 (if org-agenda-include-diary " Diary" "")
6054 (if org-agenda-include-deadlines " Ddl" "")
6055 (if org-agenda-use-time-grid " Grid" "")
6056 (if (and (boundp 'org-habit-show-habits)
6057 org-habit-show-habits) " Habit" "")
6058 (if (consp org-agenda-show-log) " LogAll"
6059 (if org-agenda-show-log " Log" ""))
6060 (if (or org-agenda-filter (get 'org-agenda-filter
6062 (concat " {" (mapconcat
6064 (append (get 'org-agenda-filter
6066 org-agenda-filter) "") "}")
6068 (if org-agenda-archives-mode
6069 (if (eq org-agenda-archives-mode t)
6071 (format " :%s:" org-archive-tag))
6073 (if org-agenda-clockreport-mode " Clock" "")))
6074 (force-mode-line-update))
6076 (defun org-agenda-post-command-hook ()
6077 (setq org-agenda-type
6078 (or (get-text-property (point) 'org-agenda-type)
6079 (get-text-property (max (point-min) (1- (point)))
6080 'org-agenda-type))))
6082 (defun org-agenda-next-line ()
6083 "Move cursor to the next line, and show if follow-mode is active."
6085 (call-interactively 'next-line)
6086 (org-agenda-do-context-action))
6088 (defun org-agenda-previous-line ()
6089 "Move cursor to the previous line, and show if follow-mode is active."
6092 (call-interactively 'previous-line)
6093 (org-agenda-do-context-action))
6095 (defun org-agenda-do-context-action ()
6096 "Show outline path and, maybe, follow-mode window."
6097 (let ((m (org-get-at-bol 'org-marker)))
6098 (if (and org-agenda-follow-mode m)
6100 (if (and m org-agenda-show-outline-path)
6101 (org-with-point-at m
6102 (org-display-outline-path t)))))
6104 (defun org-agenda-show-priority ()
6105 "Show the priority of the current item.
6106 This priority is composed of the main priority given with the [#A] cookies,
6107 and by additional input from the age of a schedules or deadline entry."
6109 (let* ((pri (org-get-at-bol 'priority)))
6110 (message "Priority is %d" (if pri pri -1000))))
6112 (defun org-agenda-show-tags ()
6113 "Show the tags applicable to the current item."
6115 (let* ((tags (org-get-at-bol 'tags)))
6117 (message "Tags are :%s:"
6118 (org-no-properties (mapconcat 'identity tags ":")))
6119 (message "No tags associated with this line"))))
6121 (defun org-agenda-goto (&optional highlight)
6122 "Go to the Org-mode file which contains the item at point."
6124 (let* ((marker (or (org-get-at-bol 'org-marker)
6125 (org-agenda-error)))
6126 (buffer (marker-buffer marker))
6127 (pos (marker-position marker)))
6128 (switch-to-buffer-other-window buffer)
6133 (org-show-context 'agenda)
6135 (and (outline-next-heading)
6136 (org-flag-heading nil)))) ; show the next heading
6137 (recenter (/ (window-height) 2))
6138 (run-hooks 'org-agenda-after-show-hook)
6139 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6141 (defvar org-agenda-after-show-hook nil
6142 "Normal hook run after an item has been shown from the agenda.
6143 Point is in the buffer where the item originated.")
6145 (defun org-agenda-kill ()
6146 "Kill the entry or subtree belonging to the current agenda entry."
6148 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6149 (let* ((marker (or (org-get-at-bol 'org-marker)
6150 (org-agenda-error)))
6151 (buffer (marker-buffer marker))
6152 (pos (marker-position marker))
6153 (type (org-get-at-bol 'type))
6154 dbeg dend (n 0) conf)
6155 (org-with-remote-undo buffer
6156 (with-current-buffer buffer
6159 (if (and (org-mode-p) (not (member type '("sexp"))))
6160 (setq dbeg (progn (org-back-to-heading t) (point))
6161 dend (org-end-of-subtree t t))
6162 (setq dbeg (point-at-bol)
6163 dend (min (point-max) (1+ (point-at-eol)))))
6165 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6166 (setq conf (or (eq t org-agenda-confirm-kill)
6167 (and (numberp org-agenda-confirm-kill)
6168 (> n org-agenda-confirm-kill))))
6171 (format "Delete entry with %d lines in buffer \"%s\"? "
6172 n (buffer-name buffer))))
6174 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6175 (with-current-buffer buffer (delete-region dbeg dend))
6176 (message "Agenda item and source killed"))))
6178 (defvar org-archive-default-command)
6179 (defun org-agenda-archive-default ()
6180 "Archive the entry or subtree belonging to the current agenda entry."
6182 (require 'org-archive)
6183 (org-agenda-archive-with org-archive-default-command))
6185 (defun org-agenda-archive-default-with-confirmation ()
6186 "Archive the entry or subtree belonging to the current agenda entry."
6188 (require 'org-archive)
6189 (org-agenda-archive-with org-archive-default-command 'confirm))
6191 (defun org-agenda-archive ()
6192 "Archive the entry or subtree belonging to the current agenda entry."
6194 (org-agenda-archive-with 'org-archive-subtree))
6196 (defun org-agenda-archive-to-archive-sibling ()
6197 "Move the entry to the archive sibling."
6199 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6201 (defun org-agenda-archive-with (cmd &optional confirm)
6202 "Move the entry to the archive sibling."
6204 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6205 (let* ((marker (or (org-get-at-bol 'org-marker)
6206 (org-agenda-error)))
6207 (buffer (marker-buffer marker))
6208 (pos (marker-position marker)))
6209 (org-with-remote-undo buffer
6210 (with-current-buffer buffer
6213 (not (y-or-n-p "Archive this subtree or entry? ")))
6217 (org-remove-subtree-entries-from-agenda)
6218 (org-back-to-heading t)
6220 (error "Archiving works only in Org-mode files"))))))
6222 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6223 "Remove all lines in the agenda that correspond to a given subtree.
6224 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6225 If this information is not given, the function uses the tree at point."
6226 (let ((buf (or buf (current-buffer))) m p)
6228 (unless (and beg end)
6229 (org-back-to-heading t)
6231 (org-end-of-subtree t)
6233 (set-buffer (get-buffer org-agenda-buffer-name))
6235 (goto-char (point-max))
6236 (beginning-of-line 1)
6238 (when (and (setq m (org-get-at-bol 'org-marker))
6239 (equal buf (marker-buffer m))
6240 (setq p (marker-position m))
6243 (let ((inhibit-read-only t))
6244 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6245 (beginning-of-line 0))))))
6247 (defun org-agenda-refile (&optional goto rfloc no-update)
6248 "Refile the item at point."
6250 (if (equal goto '(16))
6251 (org-refile-goto-last-stored)
6252 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6253 (org-agenda-error)))
6254 (buffer (marker-buffer marker))
6255 (pos (marker-position marker))
6257 (org-refile-get-location
6258 (if goto "Goto: " "Refile to: ") buffer
6259 org-refile-allow-creating-parent-nodes))))
6260 (with-current-buffer buffer
6265 (org-remove-subtree-entries-from-agenda)
6266 (org-refile goto buffer rfloc)))))
6267 (unless no-update (org-agenda-redo))))
6269 (defun org-agenda-open-link (&optional arg)
6270 "Follow the link in the current line, if any.
6271 This looks for a link in the displayed line in the agenda. It also looks
6272 at the text of the entry itself."
6274 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6275 (org-get-at-bol 'org-marker)))
6276 (buffer (and marker (marker-buffer marker)))
6277 (prefix (buffer-substring
6280 (or (org-get-at-bol 'prefix-length) 0)))))
6283 (with-current-buffer buffer
6288 (org-offer-links-in-entry arg prefix)))))
6289 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6291 (beginning-of-line 1)
6292 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6293 (org-open-link-from-string (match-string 1)))
6294 (t (error "No link to open here")))))
6296 (defun org-agenda-copy-local-variable (var)
6297 "Get a variable from a referenced buffer and install it here."
6298 (let ((m (org-get-at-bol 'org-marker)))
6299 (when (and m (buffer-live-p (marker-buffer m)))
6300 (org-set-local var (with-current-buffer (marker-buffer m)
6301 (symbol-value var))))))
6303 (defun org-agenda-switch-to (&optional delete-other-windows)
6304 "Go to the Org-mode file which contains the item at point."
6306 (if (and org-return-follows-link
6307 (not (org-get-at-bol 'org-marker))
6308 (org-in-regexp org-bracket-link-regexp))
6309 (org-open-link-from-string (match-string 0))
6310 (let* ((marker (or (org-get-at-bol 'org-marker)
6311 (org-agenda-error)))
6312 (buffer (marker-buffer marker))
6313 (pos (marker-position marker)))
6314 (switch-to-buffer buffer)
6315 (and delete-other-windows (delete-other-windows))
6319 (org-show-context 'agenda)
6321 (and (outline-next-heading)
6322 (org-flag-heading nil))))))) ; show the next heading
6324 (defun org-agenda-goto-mouse (ev)
6325 "Go to the Org-mode file which contains the item at the mouse click."
6327 (mouse-set-point ev)
6330 (defun org-agenda-show (&optional full-entry)
6331 "Display the Org-mode file which contains the item at point.
6332 With prefix argument FULL-ENTRY, make the entire entry visible
6333 if it was hidden in the outline."
6335 (let ((win (selected-window)))
6337 (let ((org-show-entry-below t))
6338 (org-agenda-goto t))
6339 (org-agenda-goto t))
6340 (select-window win)))
6342 (defvar org-agenda-show-window nil)
6343 (defun org-agenda-show-and-scroll-up ()
6344 "Display the Org-mode file which contains the item at point.
6345 When called repeatedly, scroll the window that is displaying the buffer."
6347 (let ((win (selected-window)))
6348 (if (and (window-live-p org-agenda-show-window)
6349 (eq this-command last-command))
6351 (select-window org-agenda-show-window)
6352 (ignore-errors (scroll-up)))
6355 (setq org-agenda-show-window (selected-window)))
6356 (select-window win)))
6358 (defun org-agenda-show-scroll-down ()
6359 "Scroll down the window showing the agenda."
6361 (let ((win (selected-window)))
6362 (when (window-live-p org-agenda-show-window)
6363 (select-window org-agenda-show-window)
6364 (ignore-errors (scroll-down))
6365 (select-window win))))
6367 (defun org-agenda-show-1 (&optional more)
6368 "Display the Org-mode file which contains the item at point.
6369 The prefix arg selects the amount of information to display:
6372 1 just show the entry according to defaults.
6373 2 show the children view
6374 3 show the subtree view
6375 4 show the entire subtree and any LOGBOOK drawers
6376 5 show the entire subtree and any drawers
6377 With prefix argument FULL-ENTRY, make the entire entry visible
6378 if it was hidden in the outline."
6380 (let ((win (selected-window)))
6382 (org-recenter-heading 1)
6387 (org-back-to-heading)
6388 (run-hook-with-args 'org-cycle-hook 'folded))
6389 (message "Remote: FOLDED"))
6390 ((and (interactive-p) (= more 1))
6391 (message "Remote: show with default settings"))
6396 (org-back-to-heading)
6397 (run-hook-with-args 'org-cycle-hook 'children))
6398 (message "Remote: CHILDREN"))
6402 (org-back-to-heading)
6403 (run-hook-with-args 'org-cycle-hook 'subtree))
6404 (message "Remote: SUBTREE"))
6406 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6408 (concat "^[ \t]*:\\("
6409 (mapconcat 'regexp-quote org-drawers "\\|")
6413 (org-back-to-heading)
6414 (org-cycle-hide-drawers 'subtree)))
6415 (message "Remote: SUBTREE AND LOGBOOK"))
6418 (message "Remote: SUBTREE AND ALL DRAWERS")))
6419 (select-window win)))
6421 (defun org-recenter-heading (n)
6423 (org-back-to-heading)
6426 (defvar org-agenda-cycle-counter nil)
6427 (defun org-agenda-cycle-show (&optional n)
6428 "Show the current entry in another window, with default settings.
6429 Default settings are taken from `org-show-hierarchy-above' and siblings.
6430 When use repeatedly in immediate succession, the remote entry will cycle
6433 children -> subtree -> folded
6435 When called with a numeric prefix arg, that arg will be passed through to
6436 `org-agenda-show-1'. For the interpretation of that argument, see the
6437 docstring of `org-agenda-show-1'."
6440 (setq org-agenda-cycle-counter n)
6441 (if (not (eq last-command this-command))
6442 (setq org-agenda-cycle-counter 1)
6443 (if (equal org-agenda-cycle-counter 0)
6444 (setq org-agenda-cycle-counter 2)
6445 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6446 (if (> org-agenda-cycle-counter 3)
6447 (setq org-agenda-cycle-counter 0)))))
6448 (org-agenda-show-1 org-agenda-cycle-counter))
6450 (defun org-agenda-recenter (arg)
6451 "Display the Org-mode file which contains the item at point and recenter."
6453 (let ((win (selected-window)))
6456 (select-window win)))
6458 (defun org-agenda-show-mouse (ev)
6459 "Display the Org-mode file which contains the item at the mouse click."
6461 (mouse-set-point ev)
6464 (defun org-agenda-check-no-diary ()
6465 "Check if the entry is a diary link and abort if yes."
6466 (if (org-get-at-bol 'org-agenda-diary-link)
6467 (org-agenda-error)))
6469 (defun org-agenda-error ()
6470 (error "Command not allowed in this line"))
6472 (defun org-agenda-tree-to-indirect-buffer ()
6473 "Show the subtree corresponding to the current entry in an indirect buffer.
6474 This calls the command `org-tree-to-indirect-buffer' from the original
6476 With numerical prefix arg ARG, go up to this level and then take that tree.
6477 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
6480 (org-agenda-check-no-diary)
6481 (let* ((marker (or (org-get-at-bol 'org-marker)
6482 (org-agenda-error)))
6483 (buffer (marker-buffer marker))
6484 (pos (marker-position marker)))
6485 (with-current-buffer buffer
6488 (call-interactively 'org-tree-to-indirect-buffer)))))
6490 (defvar org-last-heading-marker (make-marker)
6491 "Marker pointing to the headline that last changed its TODO state
6492 by a remote command from the agenda.")
6494 (defun org-agenda-todo-nextset ()
6495 "Switch TODO entry to next sequence."
6497 (org-agenda-todo 'nextset))
6499 (defun org-agenda-todo-previousset ()
6500 "Switch TODO entry to previous sequence."
6502 (org-agenda-todo 'previousset))
6504 (defun org-agenda-todo (&optional arg)
6505 "Cycle TODO state of line at point, also in Org-mode file.
6506 This changes the line at point, all other lines in the agenda referring to
6507 the same tree node, and the headline of the tree node in the Org-mode file."
6509 (org-agenda-check-no-diary)
6510 (let* ((col (current-column))
6511 (marker (or (org-get-at-bol 'org-marker)
6512 (org-agenda-error)))
6513 (buffer (marker-buffer marker))
6514 (pos (marker-position marker))
6515 (hdmarker (org-get-at-bol 'org-hd-marker))
6516 (todayp (equal (org-get-at-bol 'day)
6517 (time-to-days (current-time))))
6518 (inhibit-read-only t)
6519 org-agenda-headline-snapshot-before-repeat newhead just-one)
6520 (org-with-remote-undo buffer
6521 (with-current-buffer buffer
6524 (org-show-context 'agenda)
6526 (and (outline-next-heading)
6527 (org-flag-heading nil))) ; show the next heading
6528 (let ((current-prefix-arg arg))
6529 (call-interactively 'org-todo))
6530 (and (bolp) (forward-char 1))
6531 (setq newhead (org-get-heading))
6532 (when (and (org-bound-and-true-p
6533 org-agenda-headline-snapshot-before-repeat)
6534 (not (equal org-agenda-headline-snapshot-before-repeat
6537 (setq newhead org-agenda-headline-snapshot-before-repeat
6540 (org-back-to-heading)
6541 (move-marker org-last-heading-marker (point))))
6542 (beginning-of-line 1)
6544 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6545 (org-move-to-column col))))
6547 (defun org-agenda-add-note (&optional arg)
6548 "Add a time-stamped note to the entry at point."
6550 (org-agenda-check-no-diary)
6551 (let* ((marker (or (org-get-at-bol 'org-marker)
6552 (org-agenda-error)))
6553 (buffer (marker-buffer marker))
6554 (pos (marker-position marker))
6555 (hdmarker (org-get-at-bol 'org-hd-marker))
6556 (inhibit-read-only t))
6557 (with-current-buffer buffer
6560 (org-show-context 'agenda)
6562 (and (outline-next-heading)
6563 (org-flag-heading nil))) ; show the next heading
6566 (defun org-agenda-change-all-lines (newhead hdmarker
6567 &optional fixface just-this)
6568 "Change all lines in the agenda buffer which match HDMARKER.
6569 The new content of the line will be NEWHEAD (as modified by
6570 `org-format-agenda-item'). HDMARKER is checked with
6571 `equal' against all `org-hd-marker' text properties in the file.
6572 If FIXFACE is non-nil, the face of each item is modified according to
6574 If JUST-THIS is non-nil, change just the current line, not all.
6575 If FORCE-TAGS is non nil, the car of it returns the new tags."
6576 (let* ((inhibit-read-only t)
6577 (line (org-current-line))
6578 (thetags (with-current-buffer (marker-buffer hdmarker)
6579 (save-excursion (save-restriction (widen)
6580 (goto-char hdmarker)
6581 (org-get-tags-at)))))
6582 props m pl undone-face done-face finish new dotime cat tags)
6584 (goto-char (point-max))
6585 (beginning-of-line 1)
6587 (setq finish (bobp))
6588 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6589 (or (not just-this) (= (org-current-line) line))
6591 (setq props (text-properties-at (point))
6592 dotime (org-get-at-bol 'dotime)
6593 cat (org-get-at-bol 'org-category)
6595 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6596 pl (org-get-at-bol 'prefix-length)
6597 undone-face (org-get-at-bol 'undone-face)
6598 done-face (org-get-at-bol 'done-face))
6599 (goto-char (+ (point) pl))
6600 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6603 (beginning-of-line 1)
6604 (and (looking-at ".*\n?") (replace-match "")))
6606 (replace-match new t t)
6607 (beginning-of-line 1)
6608 (add-text-properties (point-at-bol) (point-at-eol) props)
6610 (add-text-properties
6611 (point-at-bol) (point-at-eol)
6613 (if org-last-todo-state-is-todo
6614 undone-face done-face))))
6615 (org-agenda-highlight-todo 'line)
6616 (beginning-of-line 1))
6617 (t (error "Line update did not work"))))
6618 (beginning-of-line 0)))
6619 (org-finalize-agenda)))
6621 (defun org-agenda-align-tags (&optional line)
6622 "Align all tags in agenda items to `org-agenda-tags-column'."
6623 (let ((inhibit-read-only t) l c)
6625 (goto-char (if line (point-at-bol) (point-min)))
6626 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
6627 (if line (point-at-eol) nil) t)
6628 (add-text-properties
6629 (match-beginning 2) (match-end 2)
6630 (list 'face (delq nil (let ((prop (get-text-property
6631 (match-beginning 2) 'face)))
6632 (or (listp prop) (setq prop (list prop)))
6633 (if (memq 'org-tag prop)
6635 (cons 'org-tag prop))))))
6636 (setq l (- (match-end 2) (match-beginning 2))
6637 c (if (< org-agenda-tags-column 0)
6638 (- (abs org-agenda-tags-column) l)
6639 org-agenda-tags-column))
6640 (delete-region (match-beginning 1) (match-end 1))
6641 (goto-char (match-beginning 1))
6642 (insert (org-add-props
6643 (make-string (max 1 (- c (current-column))) ?\ )
6644 (plist-put (copy-sequence (text-properties-at (point)))
6646 (goto-char (point-min))
6647 (org-font-lock-add-tag-faces (point-max)))))
6649 (defun org-agenda-priority-up ()
6650 "Increase the priority of line at point, also in Org-mode file."
6652 (org-agenda-priority 'up))
6654 (defun org-agenda-priority-down ()
6655 "Decrease the priority of line at point, also in Org-mode file."
6657 (org-agenda-priority 'down))
6659 (defun org-agenda-priority (&optional force-direction)
6660 "Set the priority of line at point, also in Org-mode file.
6661 This changes the line at point, all other lines in the agenda referring to
6662 the same tree node, and the headline of the tree node in the Org-mode file."
6664 (unless org-enable-priority-commands
6665 (error "Priority commands are disabled"))
6666 (org-agenda-check-no-diary)
6667 (let* ((marker (or (org-get-at-bol 'org-marker)
6668 (org-agenda-error)))
6669 (hdmarker (org-get-at-bol 'org-hd-marker))
6670 (buffer (marker-buffer hdmarker))
6671 (pos (marker-position hdmarker))
6672 (inhibit-read-only t)
6674 (org-with-remote-undo buffer
6675 (with-current-buffer buffer
6678 (org-show-context 'agenda)
6680 (and (outline-next-heading)
6681 (org-flag-heading nil))) ; show the next heading
6682 (funcall 'org-priority force-direction)
6684 (setq newhead (org-get-heading)))
6685 (org-agenda-change-all-lines newhead hdmarker)
6686 (beginning-of-line 1))))
6688 ;; FIXME: should fix the tags property of the agenda line.
6689 (defun org-agenda-set-tags (&optional tag onoff)
6690 "Set tags for the current headline."
6692 (org-agenda-check-no-diary)
6693 (if (and (org-region-active-p) (interactive-p))
6694 (call-interactively 'org-change-tag-in-region)
6695 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6696 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6697 (org-agenda-error)))
6698 (buffer (marker-buffer hdmarker))
6699 (pos (marker-position hdmarker))
6700 (inhibit-read-only t)
6702 (org-with-remote-undo buffer
6703 (with-current-buffer buffer
6707 (org-show-context 'agenda))
6709 (and (outline-next-heading)
6710 (org-flag-heading nil))) ; show the next heading
6713 (org-toggle-tag tag onoff)
6714 (call-interactively 'org-set-tags))
6716 (setq newhead (org-get-heading)))
6717 (org-agenda-change-all-lines newhead hdmarker)
6718 (beginning-of-line 1)))))
6720 (defun org-agenda-set-property ()
6721 "Set a property for the current headline."
6723 (org-agenda-check-no-diary)
6724 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6725 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6726 (org-agenda-error)))
6727 (buffer (marker-buffer hdmarker))
6728 (pos (marker-position hdmarker))
6729 (inhibit-read-only t)
6731 (org-with-remote-undo buffer
6732 (with-current-buffer buffer
6736 (org-show-context 'agenda))
6738 (and (outline-next-heading)
6739 (org-flag-heading nil))) ; show the next heading
6741 (call-interactively 'org-set-property)))))
6743 (defun org-agenda-set-effort ()
6744 "Set the effort property for the current headline."
6746 (org-agenda-check-no-diary)
6747 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6748 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6749 (org-agenda-error)))
6750 (buffer (marker-buffer hdmarker))
6751 (pos (marker-position hdmarker))
6752 (inhibit-read-only t)
6754 (org-with-remote-undo buffer
6755 (with-current-buffer buffer
6759 (org-show-context 'agenda))
6761 (and (outline-next-heading)
6762 (org-flag-heading nil))) ; show the next heading
6764 (call-interactively 'org-set-effort)
6767 (defun org-agenda-toggle-archive-tag ()
6768 "Toggle the archive tag for the current entry."
6770 (org-agenda-check-no-diary)
6771 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6772 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6773 (org-agenda-error)))
6774 (buffer (marker-buffer hdmarker))
6775 (pos (marker-position hdmarker))
6776 (inhibit-read-only t)
6778 (org-with-remote-undo buffer
6779 (with-current-buffer buffer
6782 (org-show-context 'agenda)
6784 (and (outline-next-heading)
6785 (org-flag-heading nil))) ; show the next heading
6786 (call-interactively 'org-toggle-archive-tag)
6788 (setq newhead (org-get-heading)))
6789 (org-agenda-change-all-lines newhead hdmarker)
6790 (beginning-of-line 1))))
6792 (defun org-agenda-do-date-later (arg)
6795 ((or (equal arg '(16))
6797 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6798 (setq this-command 'org-agenda-date-later-minutes)
6799 (org-agenda-date-later-minutes 1))
6800 ((or (equal arg '(4))
6802 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6803 (setq this-command 'org-agenda-date-later-hours)
6804 (org-agenda-date-later-hours 1))
6806 (org-agenda-date-later (prefix-numeric-value arg)))))
6808 (defun org-agenda-do-date-earlier (arg)
6811 ((or (equal arg '(16))
6813 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6814 (setq this-command 'org-agenda-date-earlier-minutes)
6815 (org-agenda-date-earlier-minutes 1))
6816 ((or (equal arg '(4))
6818 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6819 (setq this-command 'org-agenda-date-earlier-hours)
6820 (org-agenda-date-earlier-hours 1))
6822 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6824 (defun org-agenda-date-later (arg &optional what)
6825 "Change the date of this item to one day later."
6827 (org-agenda-check-type t 'agenda 'timeline)
6828 (org-agenda-check-no-diary)
6829 (let* ((marker (or (org-get-at-bol 'org-marker)
6830 (org-agenda-error)))
6831 (buffer (marker-buffer marker))
6832 (pos (marker-position marker)))
6833 (org-with-remote-undo buffer
6834 (with-current-buffer buffer
6837 (if (not (org-at-timestamp-p))
6838 (error "Cannot find time stamp"))
6839 (org-timestamp-change arg (or what 'day)))
6840 (org-agenda-show-new-time marker org-last-changed-timestamp))
6841 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6843 (defun org-agenda-date-earlier (arg &optional what)
6844 "Change the date of this item to one day earlier."
6846 (org-agenda-date-later (- arg) what))
6848 (defun org-agenda-date-later-minutes (arg)
6849 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6851 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6852 (org-agenda-date-later arg 'minute))
6854 (defun org-agenda-date-earlier-minutes (arg)
6855 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6857 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6858 (org-agenda-date-earlier arg 'minute))
6860 (defun org-agenda-date-later-hours (arg)
6861 "Change the time of this item, in hour steps."
6863 (org-agenda-date-later arg 'hour))
6865 (defun org-agenda-date-earlier-hours (arg)
6866 "Change the time of this item, in hour steps."
6868 (org-agenda-date-earlier arg 'hour))
6870 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6871 "Show new date stamp via text properties."
6872 ;; We use text properties to make this undoable
6873 (let ((inhibit-read-only t)
6874 (buffer-invisibility-spec))
6875 (setq stamp (concat " " prefix " => " stamp))
6877 (goto-char (point-max))
6879 (when (equal marker (org-get-at-bol 'org-marker))
6880 (org-move-to-column (- (window-width) (length stamp)) t)
6881 (org-agenda-fix-tags-filter-overlays-at (point))
6882 (if (featurep 'xemacs)
6883 ;; Use `duplicable' property to trigger undo recording
6884 (let ((ex (make-extent nil nil))
6885 (gl (make-glyph stamp)))
6886 (set-glyph-face gl 'secondary-selection)
6887 (set-extent-properties
6888 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6889 (insert-extent ex (1- (point)) (point-at-eol)))
6890 (add-text-properties
6891 (1- (point)) (point-at-eol)
6892 (list 'display (org-add-props stamp nil
6893 'face 'secondary-selection))))
6894 (beginning-of-line 1))
6895 (beginning-of-line 0)))))
6897 (defun org-agenda-date-prompt (arg)
6898 "Change the date of this item. Date is prompted for, with default today.
6899 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6900 be used to request time specification in the time stamp."
6902 (org-agenda-check-type t 'agenda 'timeline)
6903 (org-agenda-check-no-diary)
6904 (let* ((marker (or (org-get-at-bol 'org-marker)
6905 (org-agenda-error)))
6906 (buffer (marker-buffer marker))
6907 (pos (marker-position marker)))
6908 (org-with-remote-undo buffer
6909 (with-current-buffer buffer
6912 (if (not (org-at-timestamp-p t))
6913 (error "Cannot find time stamp"))
6914 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
6915 (org-agenda-show-new-time marker org-last-changed-timestamp))
6916 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6918 (defun org-agenda-schedule (arg)
6919 "Schedule the item at point.
6920 Arg is passed through to `org-schedule'."
6922 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6923 (org-agenda-check-no-diary)
6924 (let* ((marker (or (org-get-at-bol 'org-marker)
6925 (org-agenda-error)))
6926 (type (marker-insertion-type marker))
6927 (buffer (marker-buffer marker))
6928 (pos (marker-position marker))
6929 (org-insert-labeled-timestamps-at-point nil)
6931 (set-marker-insertion-type marker t)
6932 (org-with-remote-undo buffer
6933 (with-current-buffer buffer
6936 (setq ts (org-schedule arg)))
6937 (org-agenda-show-new-time marker ts "S"))
6938 (message "Item scheduled for %s" ts)))
6940 (defun org-agenda-deadline (arg)
6941 "Schedule the item at point.
6942 Arg is passed through to `org-deadline'."
6944 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6945 (org-agenda-check-no-diary)
6946 (let* ((marker (or (org-get-at-bol 'org-marker)
6947 (org-agenda-error)))
6948 (buffer (marker-buffer marker))
6949 (pos (marker-position marker))
6950 (org-insert-labeled-timestamps-at-point nil)
6952 (org-with-remote-undo buffer
6953 (with-current-buffer buffer
6956 (setq ts (org-deadline arg)))
6957 (org-agenda-show-new-time marker ts "D"))
6958 (message "Deadline for this item set to %s" ts)))
6960 (defun org-agenda-action ()
6961 "Select entry for agenda action, or execute an agenda action.
6962 This command prompts for another letter. Valid inputs are:
6964 m Mark the entry at point for an agenda action
6965 s Schedule the marked entry to the date at the cursor
6966 d Set the deadline of the marked entry to the date at the cursor
6967 r Call `org-remember' with cursor date as the default date
6968 SPC Show marked entry in other window
6969 TAB Visit marked entry in other window
6971 The cursor may be at a date in the calendar, or in the Org agenda."
6974 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
6975 (setq ans (read-char-exclusive))
6979 (if (eq major-mode 'org-agenda-mode)
6980 (let ((m (or (org-get-at-bol 'org-hd-marker)
6981 (org-get-at-bol 'org-marker))))
6984 (move-marker org-agenda-action-marker
6985 (marker-position m) (marker-buffer m))
6986 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
6987 (error "Don't know which entry to mark")))
6988 (error "This command works only in the agenda")))
6990 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
6992 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
6994 (org-agenda-do-action '(org-remember) t))
6996 (org-agenda-do-action '(org-capture) t))
6998 (let ((cw (selected-window)))
6999 (org-switch-to-buffer-other-window
7000 (marker-buffer org-agenda-action-marker))
7001 (goto-char org-agenda-action-marker)
7002 (org-show-context 'agenda)
7003 (select-window cw)))
7005 (org-switch-to-buffer-other-window
7006 (marker-buffer org-agenda-action-marker))
7007 (goto-char org-agenda-action-marker)
7008 (org-show-context 'agenda))
7009 (t (error "Invalid agenda action %c" ans)))))
7011 (defun org-agenda-do-action (form &optional current-buffer)
7012 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7013 (let ((org-overriding-default-time (org-get-cursor-date)))
7016 (if (not (marker-buffer org-agenda-action-marker))
7017 (error "No entry has been selected for agenda action")
7018 (with-current-buffer (marker-buffer org-agenda-action-marker)
7022 (goto-char org-agenda-action-marker)
7025 (defun org-agenda-clock-in (&optional arg)
7026 "Start the clock on the currently selected item."
7028 (org-agenda-check-no-diary)
7029 (if (equal arg '(4))
7031 (let* ((marker (or (org-get-at-bol 'org-marker)
7032 (org-agenda-error)))
7033 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7035 (pos (marker-position marker))
7037 (org-with-remote-undo (marker-buffer marker)
7038 (with-current-buffer (marker-buffer marker)
7041 (org-show-context 'agenda)
7043 (org-cycle-hide-drawers 'children)
7045 (setq newhead (org-get-heading)))
7046 (org-agenda-change-all-lines newhead hdmarker)))))
7048 (defun org-agenda-clock-out (&optional arg)
7049 "Stop the currently running clock."
7051 (unless (marker-buffer org-clock-marker)
7052 (error "No running clock"))
7053 (let ((marker (make-marker)) newhead)
7054 (org-with-remote-undo (marker-buffer org-clock-marker)
7055 (with-current-buffer (marker-buffer org-clock-marker)
7059 (goto-char org-clock-marker)
7060 (org-back-to-heading t)
7061 (move-marker marker (point))
7063 (setq newhead (org-get-heading))))))
7064 (org-agenda-change-all-lines newhead marker)
7065 (move-marker marker nil)))
7067 (defun org-agenda-clock-cancel (&optional arg)
7068 "Cancel the currently running clock."
7070 (unless (marker-buffer org-clock-marker)
7071 (error "No running clock"))
7072 (org-with-remote-undo (marker-buffer org-clock-marker)
7073 (org-clock-cancel)))
7075 (defun org-agenda-diary-entry-in-org-file ()
7076 "Make a diary entry in the file `org-agenda-diary-file'."
7077 (let (d1 d2 char (text "") dp1 dp2)
7078 (if (equal (buffer-name) "*Calendar*")
7079 (setq d1 (calendar-cursor-to-date t)
7080 d2 (car calendar-mark-ring))
7081 (setq dp1 (get-text-property (point-at-bol) 'day))
7082 (unless dp1 (error "No date defined in current line"))
7083 (setq d1 (calendar-gregorian-from-absolute dp1)
7084 d2 (and (ignore-errors (mark))
7087 (setq dp2 (get-text-property (point-at-bol) 'day)))
7088 (calendar-gregorian-from-absolute dp2))))
7089 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7090 (setq char (read-char-exclusive))
7093 (setq text (read-string "Day entry: "))
7094 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7095 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7097 (setq d1 (list (car d1) (nth 1 d1)
7098 (read-number (format "Reference year [%d]: " (nth 2 d1))
7100 (setq text (read-string "Anniversary (use %d to show years): "))
7101 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7102 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7104 (setq text (read-string "Block entry: "))
7105 (unless (and d1 d2 (not (equal d1 d2)))
7106 (error "No block of days selected"))
7107 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7108 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7110 (org-switch-to-buffer-other-window
7111 (find-file-noselect org-agenda-diary-file))
7112 (require 'org-datetree)
7113 (org-datetree-find-date-create d1)
7115 (t (error "Invalid selection character `%c'" char)))))
7117 (defcustom org-agenda-insert-diary-strategy 'date-tree
7118 "Where in `org-agenda-diary-file' should new entries be added?
7121 date-tree in the date tree, as child of the date
7122 top-level as top-level entries at the end of the file."
7125 (const :tag "in a date tree" date-tree)
7126 (const :tag "as top level at end of file" top-level)))
7128 (defcustom org-agenda-insert-diary-extract-time nil
7129 "Non-nil means extract any time specification from the diary entry."
7133 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7134 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7135 If TEXT is not empty, it will become the headline of the new entry, and
7136 the resulting entry will not be shown. When TEXT is empty, switch to
7137 `org-agenda-diary-file' and let the user finish the entry there."
7138 (let ((cw (current-window-configuration)))
7139 (org-switch-to-buffer-other-window
7140 (find-file-noselect org-agenda-diary-file))
7142 (goto-char (point-min))
7144 ((eq type 'anniversary)
7145 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7147 (or (org-on-heading-p t)
7149 (outline-next-heading)
7150 (insert "* Anniversaries\n\n")
7151 (beginning-of-line -1)))))
7152 (outline-next-heading)
7153 (org-back-over-empty-lines)
7156 (require 'diary-lib)
7157 (let ((calendar-date-display-form
7158 (if (if (boundp 'calendar-date-style)
7159 (eq calendar-date-style 'european)
7160 (org-bound-and-true-p european-calendar-style)) ; Emacs 22
7161 '(day " " month " " year)
7162 '(month " " day " " year))))
7164 (insert (format "%%%%(diary-anniversary %s) %s"
7165 (calendar-date-string d1 nil t) text))))
7167 (let ((org-prefix-has-time t)
7168 (org-agenda-time-leading-zero t)
7170 (if org-agenda-insert-diary-extract-time
7171 ;; Use org-format-agenda-item to parse text for a time-range and
7172 ;; remove it. FIXME: This is a hack, we should refactor
7173 ;; that function to make time extraction available separately
7174 (setq fmt (org-format-agenda-item nil text nil nil t)
7175 time (get-text-property 0 'time fmt)
7176 time2 (if (> (length time) 0)
7177 ;; split-string removes trailing ...... if
7178 ;; no end time given. First space
7179 ;; separates time from date.
7180 (concat " " (car (split-string time "\\.")))
7182 text (get-text-property 0 'txt fmt)))
7183 (if (eq org-agenda-insert-diary-strategy 'top-level)
7184 (org-agenda-insert-diary-as-top-level text)
7185 (require 'org-datetree)
7186 (org-datetree-find-date-create d1)
7187 (org-agenda-insert-diary-make-new-entry text))
7188 (org-insert-time-stamp (org-time-from-absolute
7189 (calendar-absolute-from-gregorian d1))
7190 nil nil nil nil time2))
7193 (if (> (calendar-absolute-from-gregorian d1)
7194 (calendar-absolute-from-gregorian d2))
7195 (setq d1 (prog1 d2 (setq d2 d1))))
7196 (if (eq org-agenda-insert-diary-strategy 'top-level)
7197 (org-agenda-insert-diary-as-top-level text)
7198 (require 'org-datetree)
7199 (org-datetree-find-date-create d1)
7200 (org-agenda-insert-diary-make-new-entry text))
7201 (org-insert-time-stamp (org-time-from-absolute
7202 (calendar-absolute-from-gregorian d1)))
7204 (org-insert-time-stamp (org-time-from-absolute
7205 (calendar-absolute-from-gregorian d2)))
7207 (if (string-match "\\S-" text)
7209 (set-window-configuration cw)
7210 (message "%s entry added to %s"
7211 (capitalize (symbol-name type))
7212 (abbreviate-file-name org-agenda-diary-file)))
7214 (message "Please finish entry here"))))
7216 (defun org-agenda-insert-diary-as-top-level (text)
7217 "Make new entry as a top-level entry at the end of the file.
7218 Add TEXT as headline, and position the cursor in the second line so that
7219 a timestamp can be added there."
7221 (goto-char (point-max))
7222 (or (bolp) (insert "\n"))
7223 (insert "* " text "\n")
7224 (if org-adapt-indentation (org-indent-to-column 2)))
7226 (defun org-agenda-insert-diary-make-new-entry (text)
7227 "Make new entry as last child of current entry.
7228 Add TEXT as headline, and position the cursor in the second line so that
7229 a timestamp can be added there."
7230 (let ((org-show-following-heading t)
7231 (org-show-siblings t)
7232 (org-show-hierarchy-above t)
7233 (org-show-entry-below t)
7235 (outline-next-heading)
7236 (org-back-over-empty-lines)
7237 (or (looking-at "[ \t]*$")
7238 (progn (insert "\n") (backward-char 1)))
7239 (org-insert-heading nil t)
7241 (setq col (current-column))
7243 (if org-adapt-indentation (org-indent-to-column col))
7244 (let ((org-show-following-heading t)
7245 (org-show-siblings t)
7246 (org-show-hierarchy-above t)
7247 (org-show-entry-below t))
7248 (org-show-context))))
7250 (defun org-agenda-diary-entry ()
7251 "Make a diary entry, like the `i' command from the calendar.
7252 All the standard commands work: block, weekly etc.
7253 When `org-agenda-diary-file' points to a file,
7254 `org-agenda-diary-entry-in-org-file' is called instead to create
7255 entries in that Org-mode file."
7257 (org-agenda-check-type t 'agenda 'timeline)
7258 (if (not (eq org-agenda-diary-file 'diary-file))
7259 (org-agenda-diary-entry-in-org-file)
7260 (require 'diary-lib)
7262 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7263 (read-char-exclusive)))
7264 (cmd (cdr (assoc char
7265 '((?d . insert-diary-entry)
7266 (?w . insert-weekly-diary-entry)
7267 (?m . insert-monthly-diary-entry)
7268 (?y . insert-yearly-diary-entry)
7269 (?a . insert-anniversary-diary-entry)
7270 (?b . insert-block-diary-entry)
7271 (?c . insert-cyclic-diary-entry)))))
7272 (oldf (symbol-function 'calendar-cursor-to-date))
7273 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7275 (mark (or (mark t) (point))))
7277 (error "No command associated with <%c>" char))
7278 (unless (and (get-text-property point 'day)
7279 (or (not (equal ?b char))
7280 (get-text-property mark 'day)))
7281 (error "Don't know which date to use for diary entry"))
7282 ;; We implement this by hacking the `calendar-cursor-to-date' function
7283 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7284 (let ((calendar-mark-ring
7285 (list (calendar-gregorian-from-absolute
7286 (or (get-text-property mark 'day)
7287 (get-text-property point 'day))))))
7290 (fset 'calendar-cursor-to-date
7291 (lambda (&optional error dummy)
7292 (calendar-gregorian-from-absolute
7293 (get-text-property point 'day))))
7294 (call-interactively cmd))
7295 (fset 'calendar-cursor-to-date oldf))))))
7297 (defun org-agenda-execute-calendar-command (cmd)
7298 "Execute a calendar command from the agenda, with the date associated to
7299 the cursor position."
7300 (org-agenda-check-type t 'agenda 'timeline)
7301 (require 'diary-lib)
7302 (unless (get-text-property (point) 'day)
7303 (error "Don't know which date to use for calendar command"))
7304 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7306 (date (calendar-gregorian-from-absolute
7307 (get-text-property point 'day)))
7308 ;; the following 2 vars are needed in the calendar
7309 (displayed-month (car date))
7310 (displayed-year (nth 2 date)))
7313 (fset 'calendar-cursor-to-date
7314 (lambda (&optional error dummy)
7315 (calendar-gregorian-from-absolute
7316 (get-text-property point 'day))))
7317 (call-interactively cmd))
7318 (fset 'calendar-cursor-to-date oldf))))
7320 (defun org-agenda-phases-of-moon ()
7321 "Display the phases of the moon for the 3 months around the cursor date."
7323 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7325 (defun org-agenda-holidays ()
7326 "Display the holidays for the 3 months around the cursor date."
7328 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7330 (defvar calendar-longitude)
7331 (defvar calendar-latitude)
7332 (defvar calendar-location-name)
7334 (defun org-agenda-sunrise-sunset (arg)
7335 "Display sunrise and sunset for the cursor date.
7336 Latitude and longitude can be specified with the variables
7337 `calendar-latitude' and `calendar-longitude'. When called with prefix
7338 argument, latitude and longitude will be prompted for."
7341 (let ((calendar-longitude (if arg nil calendar-longitude))
7342 (calendar-latitude (if arg nil calendar-latitude))
7343 (calendar-location-name
7344 (if arg "the given coordinates" calendar-location-name)))
7345 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7347 (defun org-agenda-goto-calendar ()
7348 "Open the Emacs calendar with the date at the cursor."
7350 (org-agenda-check-type t 'agenda 'timeline)
7351 (let* ((day (or (get-text-property (point) 'day)
7352 (error "Don't know which date to open in calendar")))
7353 (date (calendar-gregorian-from-absolute day))
7354 (calendar-move-hook nil)
7355 (calendar-view-holidays-initially-flag nil)
7356 (calendar-view-diary-initially-flag nil))
7358 (calendar-goto-date date)))
7361 (defun org-calendar-goto-agenda ()
7362 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7363 This is a command that has to be installed in `calendar-mode-map'."
7365 (org-agenda-list nil (calendar-absolute-from-gregorian
7366 (calendar-cursor-to-date))
7369 (defun org-agenda-convert-date ()
7371 (org-agenda-check-type t 'agenda 'timeline)
7372 (let ((day (get-text-property (point) 'day))
7375 (error "Don't know which date to convert"))
7376 (setq date (calendar-gregorian-from-absolute day))
7378 "Gregorian: " (calendar-date-string date) "\n"
7379 "ISO: " (calendar-iso-date-string date) "\n"
7380 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7381 "Julian: " (calendar-julian-date-string date) "\n"
7382 "Astron. JD: " (calendar-astro-date-string date)
7383 " (Julian date number at noon UTC)\n"
7384 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7385 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7386 "French: " (calendar-french-date-string date) "\n"
7387 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7388 "Mayan: " (calendar-mayan-date-string date) "\n"
7389 "Coptic: " (calendar-coptic-date-string date) "\n"
7390 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7391 "Persian: " (calendar-persian-date-string date) "\n"
7392 "Chinese: " (calendar-chinese-date-string date) "\n"))
7393 (with-output-to-temp-buffer "*Dates*"
7395 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7399 (defvar org-agenda-bulk-marked-entries nil
7400 "List of markers that refer to marked entries in the agenda.")
7402 (defun org-agenda-bulk-marked-p ()
7403 (eq (get-char-property (point-at-bol) 'type)
7404 'org-marked-entry-overlay))
7406 (defun org-agenda-bulk-mark ()
7407 "Mark the entry at point for future bulk action."
7409 (org-agenda-check-no-diary)
7410 (let* ((m (org-get-at-bol 'org-hd-marker))
7412 (unless (org-agenda-bulk-marked-p)
7413 (unless m (error "Nothing to mark at point"))
7414 (push m org-agenda-bulk-marked-entries)
7415 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7416 (org-overlay-display ov "> "
7417 (org-get-todo-face "TODO")
7419 (overlay-put ov 'type 'org-marked-entry-overlay))
7420 (beginning-of-line 2)
7421 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7422 (beginning-of-line 2))
7423 (message "%d entries marked for bulk action"
7424 (length org-agenda-bulk-marked-entries))))
7426 (defun org-agenda-bulk-unmark ()
7427 "Unmark the entry at point for future bulk action."
7429 (when (org-agenda-bulk-marked-p)
7430 (org-agenda-bulk-remove-overlays
7431 (point-at-bol) (+ 2 (point-at-bol)))
7432 (setq org-agenda-bulk-marked-entries
7433 (delete (org-get-at-bol 'org-hd-marker)
7434 org-agenda-bulk-marked-entries)))
7435 (beginning-of-line 2)
7436 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7437 (beginning-of-line 2))
7438 (message "%d entries marked for bulk action"
7439 (length org-agenda-bulk-marked-entries)))
7441 (defun org-agenda-bulk-toggle ()
7442 "Toggle marking the entry at point for bulk action."
7444 (if (org-agenda-bulk-marked-p)
7445 (org-agenda-bulk-unmark)
7446 (org-agenda-bulk-mark)))
7448 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7449 "Remove the mark overlays between BEG and END in the agenda buffer.
7450 BEG and END default to the buffer limits.
7452 This only removes the overlays, it does not remove the markers
7453 from the list in `org-agenda-bulk-marked-entries'."
7456 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7457 (delete-overlay ov)))
7458 (overlays-in (or beg (point-min)) (or end (point-max)))))
7460 (defun org-agenda-bulk-remove-all-marks ()
7461 "Remove all marks in the agenda buffer.
7462 This will remove the markers, and the overlays."
7464 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7465 (setq org-agenda-bulk-marked-entries nil)
7466 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7468 (defun org-agenda-bulk-action (&optional arg)
7469 "Execute an remote-editing action on all marked entries.
7470 The prefix arg is passed through to the command if possible."
7472 (unless org-agenda-bulk-marked-entries
7473 (error "No entries are marked"))
7474 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
7475 (let* ((action (read-char-exclusive))
7476 (org-log-refile (if org-log-refile 'time nil))
7477 (entries (reverse org-agenda-bulk-marked-entries))
7479 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7482 (setq cmd '(org-agenda-archive)))
7485 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7487 ((member action '(?r ?w))
7488 (setq rfloc (org-refile-get-location
7490 (marker-buffer (car org-agenda-bulk-marked-entries))
7491 org-refile-allow-creating-parent-nodes))
7492 (setcar (nthcdr 3 rfloc)
7493 (move-marker (make-marker) (nth 3 rfloc)
7494 (or (get-file-buffer (nth 1 rfloc))
7495 (find-buffer-visiting (nth 1 rfloc))
7496 (error "This should not happen"))))
7498 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
7502 (setq state (org-icompleting-read
7504 (with-current-buffer (marker-buffer (car entries))
7505 (mapcar 'list org-todo-keywords-1))))
7506 (setq cmd `(let ((org-inhibit-blocking t)
7507 (org-inhibit-logging 'note))
7508 (org-agenda-todo ,state))))
7510 ((memq action '(?- ?+))
7511 (setq tag (org-icompleting-read
7512 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7513 (with-current-buffer (marker-buffer (car entries))
7516 (if (stringp (car x)) x)) org-tag-alist)))))
7517 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
7519 ((memq action '(?s ?d))
7520 (let* ((date (unless arg
7523 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
7524 (ans (if arg nil org-read-date-final-answer))
7525 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
7526 (setq cmd `(let* ((bound (fboundp 'read-string))
7527 (old (and bound (symbol-function 'read-string))))
7530 (fset 'read-string (lambda (&rest ignore) ,ans))
7533 (fset 'read-string old)
7534 (fmakunbound 'read-string)))))))
7535 (t (error "Invalid bulk action")))
7537 ;; Sort the markers, to make sure that parents are handled before children
7538 (setq entries (sort entries
7541 ((equal (marker-buffer a) (marker-buffer b))
7542 (< (marker-position a) (marker-position b)))
7544 (string< (buffer-name (marker-buffer a))
7545 (buffer-name (marker-buffer b))))))))
7547 ;; Now loop over all markers and apply cmd
7548 (while (setq e (pop entries))
7549 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
7551 (progn (message "Skipping removed entry at %s" e)
7552 (setq cntskip (1+ cntskip)))
7555 (setq org-agenda-bulk-marked-entries
7556 (delete e org-agenda-bulk-marked-entries))
7557 (setq cnt (1+ cnt))))
7558 (setq org-agenda-bulk-marked-entries nil)
7559 (org-agenda-bulk-remove-all-marks)
7560 (when redo-at-end (org-agenda-redo))
7561 (message "Acted on %d entries%s"
7565 (format ", skipped %d (disappeared before their turn)"
7570 (defun org-agenda-show-the-flagging-note ()
7571 "Display the flagging note in the other window.
7572 When called a second time in direct sequence, offer to remove the FLAGGING
7573 tag and (if present) the flagging note."
7575 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
7576 (win (selected-window))
7577 note heading newhead)
7579 (error "No linked entry at point"))
7580 (if (and (eq this-command last-command)
7581 (y-or-n-p "Unflag and remove any flagging note? "))
7583 (org-agenda-remove-flag hdmarker)
7584 (let ((win (get-buffer-window "*Flagging Note*")))
7585 (and win (delete-window win)))
7586 (message "Entry unflaged"))
7587 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
7589 (error "No flagging note"))
7591 (org-switch-to-buffer-other-window "*Flagging Note*")
7594 (goto-char (point-min))
7595 (while (re-search-forward "\\\\n" nil t)
7596 (replace-match "\n" t t))
7597 (goto-char (point-min))
7599 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
7601 (defun org-agenda-remove-flag (marker)
7602 "Remove the FLAGGED tag and any flagging note in the entry."
7604 (org-with-point-at marker
7605 (org-toggle-tag "FLAGGED" 'off)
7606 (org-entry-delete nil "THEFLAGGINGNOTE")
7607 (setq newhead (org-get-heading)))
7608 (org-agenda-change-all-lines newhead marker)
7609 (message "Entry unflaged")))
7611 (defun org-agenda-get-any-marker (&optional pos)
7612 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7613 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7615 ;;; Appointment reminders
7617 (defvar appt-time-msg-list)
7620 (defun org-agenda-to-appt (&optional refresh filter)
7621 "Activate appointments found in `org-agenda-files'.
7622 With a \\[universal-argument] prefix, refresh the list of
7625 If FILTER is t, interactively prompt the user for a regular
7626 expression, and filter out entries that don't match it.
7628 If FILTER is a string, use this string as a regular expression
7629 for filtering entries out.
7631 FILTER can also be an alist with the car of each cell being
7632 either 'headline or 'category. For example:
7634 '((headline \"IMPORTANT\")
7635 (category \"Work\"))
7637 will only add headlines containing IMPORTANT or headlines
7638 belonging to the \"Work\" category."
7640 (if refresh (setq appt-time-msg-list nil))
7642 (setq filter (read-from-minibuffer "Regexp filter: ")))
7643 (let* ((cnt 0) ; count added events
7644 (org-agenda-new-buffers nil)
7645 (org-deadline-warning-days 0)
7646 (today (org-date-to-gregorian
7647 (time-to-days (current-time))))
7648 (org-agenda-restrict nil)
7649 (files (org-agenda-files 'unrestricted)) entries file)
7650 ;; Get all entries which may contain an appt
7651 (org-prepare-agenda-buffers files)
7652 (while (setq file (pop files))
7655 (org-agenda-get-day-entries
7656 file today :timestamp :scheduled :deadline))))
7657 (setq entries (delq nil entries))
7658 ;; Map thru entries and find if we should filter them out
7661 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7662 (cat (get-text-property 1 'org-category x))
7663 (tod (get-text-property 1 'time-of-day x))
7664 (ok (or (null filter)
7665 (and (stringp filter) (string-match filter evt))
7668 (cadr (assoc 'category filter)) cat)
7670 (cadr (assoc 'headline filter)) evt))))))
7671 ;; FIXME: Shall we remove text-properties for the appt text?
7672 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7674 (setq tod (concat "00" (number-to-string tod))
7675 tod (when (string-match
7676 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7677 (concat (match-string 1 tod) ":"
7678 (match-string 2 tod))))
7680 (setq cnt (1+ cnt))))) entries)
7681 (org-release-buffers org-agenda-new-buffers)
7683 (message "No event to add")
7684 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7686 (defun org-agenda-todayp (date)
7687 "Does DATE mean today, when considering `org-extend-today-until'?"
7689 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7690 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7691 (setq h (nth 2 (decode-time (current-time))))
7692 (or (and (>= h org-extend-today-until)
7694 (and (< h org-extend-today-until)
7695 (= date (1- today))))))
7697 (provide 'org-agenda)
7699 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7701 ;;; org-agenda.el ends here