1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
38 (declare-function diary-add-to-list
"diary-lib"
39 (date string specifier
&optional marker globcolor literal
))
40 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
41 (declare-function calendar-astro-date-string
"cal-julian" (&optional date
))
42 (declare-function calendar-bahai-date-string
"cal-bahai" (&optional date
))
43 (declare-function calendar-chinese-date-string
"cal-china" (&optional date
))
44 (declare-function calendar-coptic-date-string
"cal-coptic" (&optional date
))
45 (declare-function calendar-ethiopic-date-string
"cal-coptic" (&optional date
))
46 (declare-function calendar-french-date-string
"cal-french" (&optional date
))
47 (declare-function calendar-goto-date
"cal-move" (date))
48 (declare-function calendar-hebrew-date-string
"cal-hebrew" (&optional date
))
49 (declare-function calendar-islamic-date-string
"cal-islam" (&optional date
))
50 (declare-function calendar-iso-date-string
"cal-iso" (&optional date
))
51 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
52 (declare-function calendar-julian-date-string
"cal-julian" (&optional date
))
53 (declare-function calendar-mayan-date-string
"cal-mayan" (&optional date
))
54 (declare-function calendar-persian-date-string
"cal-persia" (&optional date
))
55 (declare-function org-datetree-find-date-create
"org-datetree"
56 (date &optional keep-restriction
))
57 (declare-function org-columns-quit
"org-colview" ())
58 (declare-function diary-date-display-form
"diary-lib" (&optional type
))
59 (declare-function org-mobile-write-agenda-for-mobile
"org-mobile" (file))
60 (declare-function org-habit-insert-consistency-graphs
61 "org-habit" (&optional line
))
62 (declare-function org-is-habit-p
"org-habit" (&optional pom
))
63 (declare-function org-habit-parse-todo
"org-habit" (&optional pom
))
64 (declare-function org-habit-get-priority
"org-habit" (habit &optional moment
))
65 (defvar calendar-mode-map
)
66 (defvar org-mobile-force-id-on-agenda-items
) ; defined in org-mobile.el
67 (defvar org-habit-show-habits
)
68 (defvar org-habit-show-habits-only-for-today
)
70 ;; Defined somewhere in this file, but used before definition.
71 (defvar org-agenda-buffer-name
)
72 (defvar org-agenda-overriding-header
)
73 (defvar org-agenda-title-append nil
)
76 (defvar org-agenda-undo-list
)
77 (defvar org-agenda-pending-undo-list
)
78 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
80 (defcustom org-agenda-confirm-kill
1
81 "When set, remote killing from the agenda buffer needs confirmation.
82 When t, a confirmation is always needed. When a number N, confirmation is
83 only needed when the text to be killed contains more than N non-white lines."
86 (const :tag
"Never" nil
)
87 (const :tag
"Always" t
)
88 (integer :tag
"When more than N lines")))
90 (defcustom org-agenda-compact-blocks nil
91 "Non-nil means, make the block agenda more compact.
92 This is done by leaving out unnecessary lines."
96 (defcustom org-agenda-block-separator ?
=
97 "The separator between blocks in the agenda.
98 If this is a string, it will be used as the separator, with a newline added.
99 If it is a character, it will be repeated to fill the window width."
105 (defgroup org-agenda-export nil
106 "Options concerning exporting agenda views in Org-mode."
107 :tag
"Org Agenda Export"
110 (defcustom org-agenda-with-colors t
111 "Non-nil means, use colors in agenda views."
112 :group
'org-agenda-export
115 (defcustom org-agenda-exporter-settings nil
116 "Alist of variable/value pairs that should be active during agenda export.
117 This is a good place to set options for ps-print and for htmlize.
118 Note that the way this is implemented, the values will be evaluated
119 before assigned to the variables. So make sure to quote values you do
120 *not* want evaluated, for example
122 (setq org-agenda-exporter-settings
123 '((ps-print-color-p 'black-white)))"
124 :group
'org-agenda-export
128 (sexp :tag
"Value"))))
130 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
131 "Hook run in temporary buffer before writing it to an export file.
132 A useful function is `org-agenda-add-entry-text'."
133 :group
'org-agenda-export
135 :options
'(org-agenda-add-entry-text))
137 (defcustom org-agenda-add-entry-text-maxlines
0
138 "Maximum number of entry text lines to be added to agenda.
139 This is only relevant when `org-agenda-add-entry-text' is part of
140 `org-agenda-before-write-hook', which it is by default.
141 When this is 0, nothing will happen. When it is greater than 0, it
142 specifies the maximum number of lines that will be added for each entry
143 that is listed in the agenda view.
145 Note that this variable is not used during display, only when exporting
146 the agenda. For agenda display, see org-agenda-entry-text-mode and the
147 variable `org-agenda-entry-text-maxlines'."
151 (defcustom org-agenda-add-entry-text-descriptive-links t
152 "Non-nil means, export org-links as descriptive links in agenda added text.
153 This variable applies to the text added to the agenda when
154 `org-agenda-add-entry-text-maxlines' is larger than 0.
155 When this variable nil, the URL will (also) be shown."
159 (defcustom org-agenda-export-html-style
""
160 "The style specification for exported HTML Agenda files.
161 If this variable contains a string, it will replace the default <style>
162 section as produced by `htmlize'.
163 Since there are different ways of setting style information, this variable
164 needs to contain the full HTML structure to provide a style, including the
165 surrounding HTML tags. The style specifications should include definitions
166 the fonts used by the agenda, here is an example:
168 <style type=\"text/css\">
169 p { font-weight: normal; color: gray; }
170 .org-agenda-structure {
185 .title { text-align: center; }
186 .todo, .deadline { color: red; }
187 .done { color: green; }
190 or, if you want to keep the style in a file,
192 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
194 As the value of this option simply gets inserted into the HTML <head> header,
195 you can \"misuse\" it to also add other text to the header. However,
196 <style>...</style> is required, if not present the variable will be ignored."
197 :group
'org-agenda-export
198 :group
'org-export-html
201 (defgroup org-agenda-custom-commands nil
202 "Options concerning agenda views in Org-mode."
203 :tag
"Org Agenda Custom Commands"
206 (defconst org-sorting-choice
208 (const time-up
) (const time-down
)
209 (const category-keep
) (const category-up
) (const category-down
)
210 (const tag-down
) (const tag-up
)
211 (const priority-up
) (const priority-down
)
212 (const todo-state-up
) (const todo-state-down
)
213 (const effort-up
) (const effort-down
)
214 (const habit-up
) (const habit-down
)
215 (const user-defined-up
) (const user-defined-down
))
218 (defconst org-agenda-custom-commands-local-options
219 `(repeat :tag
"Local settings for this command. Remember to quote values"
220 (choice :tag
"Setting"
221 (list :tag
"Heading for this block"
222 (const org-agenda-overriding-header
)
223 (string :tag
"Headline"))
224 (list :tag
"Files to be searched"
225 (const org-agenda-files
)
227 (const :format
"" quote
)
229 (list :tag
"Sorting strategy"
230 (const org-agenda-sorting-strategy
)
232 (const :format
"" quote
)
234 ,org-sorting-choice
)))
235 (list :tag
"Prefix format"
236 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
238 (list :tag
"Number of days in agenda"
239 (const org-agenda-ndays
)
241 (list :tag
"Fixed starting date"
242 (const org-agenda-start-day
)
243 (string :value
"2007-11-01"))
244 (list :tag
"Start on day of week"
245 (const org-agenda-start-on-weekday
)
247 (const :tag
"Today" nil
)
248 (integer :tag
"Weekday No.")))
249 (list :tag
"Include data from diary"
250 (const org-agenda-include-diary
)
252 (list :tag
"Deadline Warning days"
253 (const org-deadline-warning-days
)
255 (list :tag
"Tags filter preset"
256 (const org-agenda-filter-preset
)
258 (const :format
"" quote
)
260 (string :tag
"+tag or -tag"))))
261 (list :tag
"Standard skipping condition"
262 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
263 (const org-agenda-skip-function
)
265 (const :format
"" quote
)
268 :tag
"Skipping range"
269 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
270 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
271 (repeat :inline t
:tag
"Conditions for skipping"
273 :tag
"Condition type"
274 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
275 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
276 (const :tag
"scheduled" 'scheduled
)
277 (const :tag
"not scheduled" 'notscheduled
)
278 (const :tag
"deadline" 'deadline
)
279 (const :tag
"no deadline" 'notdeadline
)
280 (const :tag
"timestamp" 'timestamp
)
281 (const :tag
"no timestamp" 'nottimestamp
))))))
282 (list :tag
"Non-standard skipping condition"
283 :value
(org-agenda-skip-function)
284 (const org-agenda-skip-function
)
285 (sexp :tag
"Function or form (quoted!)"))
286 (list :tag
"Any variable"
287 (variable :tag
"Variable")
288 (sexp :tag
"Value (sexp)"))))
289 "Selection of examples for agenda command settings.
290 This will be spliced into the custom type of
291 `org-agenda-custom-commands'.")
294 (defcustom org-agenda-custom-commands nil
295 "Custom commands for the agenda.
296 These commands will be offered on the splash screen displayed by the
297 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
299 (key desc type match settings files)
301 key The key (one or more characters as a string) to be associated
303 desc A description of the command, when omitted or nil, a default
304 description is built using MATCH.
305 type The command type, any of the following symbols:
306 agenda The daily/weekly agenda.
307 todo Entries with a specific TODO keyword, in all agenda files.
308 search Entries containing search words entry or headline.
309 tags Tags/Property/TODO match in all agenda files.
310 tags-todo Tags/P/T match in all agenda files, TODO entries only.
311 todo-tree Sparse tree of specific TODO keyword in *current* file.
312 tags-tree Sparse tree with all tags matches in *current* file.
313 occur-tree Occur sparse tree for *current* file.
314 ... A user-defined function.
315 match What to search for:
316 - a single keyword for TODO keyword searches
317 - a tags match expression for tags searches
318 - a word search expression for text searches.
319 - a regular expression for occur searches
320 For all other commands, this should be the empty string.
321 settings A list of option settings, similar to that in a let form, so like
322 this: ((opt1 val1) (opt2 val2) ...). The values will be
323 evaluated at the moment of execution, so quote them when needed.
324 files A list of files file to write the produced agenda buffer to
325 with the command `org-store-agenda-views'.
326 If a file name ends in \".html\", an HTML version of the buffer
327 is written out. If it ends in \".ps\", a postscript version is
328 produced. Otherwise, only the plain text is written to the file.
330 You can also define a set of commands, to create a composite agenda buffer.
331 In this case, an entry looks like this:
333 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
337 desc A description string to be displayed in the dispatcher menu.
338 cmd An agenda command, similar to the above. However, tree commands
339 are no allowed, but instead you can get agenda and global todo list.
340 So valid commands for a set are:
341 (agenda \"\" settings)
342 (alltodo \"\" settings)
343 (stuck \"\" settings)
344 (todo \"match\" settings files)
345 (search \"match\" settings files)
346 (tags \"match\" settings files)
347 (tags-todo \"match\" settings files)
349 Each command can carry a list of options, and another set of options can be
350 given for the whole set of commands. Individual command options take
351 precedence over the general options.
353 When using several characters as key to a command, the first characters
354 are prefix commands. For the dispatcher to display useful information, you
355 should provide a description for the prefix, like
357 (setq org-agenda-custom-commands
358 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
359 (\"hl\" tags \"+HOME+Lisa\")
360 (\"hp\" tags \"+HOME+Peter\")
361 (\"hk\" tags \"+HOME+Kim\")))"
362 :group
'org-agenda-custom-commands
364 (choice :value
("x" "Describe command here" tags
"" nil
)
365 (list :tag
"Single command"
366 (string :tag
"Access Key(s) ")
367 (option (string :tag
"Description"))
369 (const :tag
"Agenda" agenda
)
370 (const :tag
"TODO list" alltodo
)
371 (const :tag
"Search words" search
)
372 (const :tag
"Stuck projects" stuck
)
373 (const :tag
"Tags/Property match (all agenda files)" tags
)
374 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
375 (const :tag
"TODO keyword search (all agenda files)" todo
)
376 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
377 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
378 (const :tag
"Occur tree (current buffer)" occur-tree
)
379 (sexp :tag
"Other, user-defined function"))
380 (string :tag
"Match (only for some commands)")
381 ,org-agenda-custom-commands-local-options
382 (option (repeat :tag
"Export" (file :tag
"Export to"))))
383 (list :tag
"Command series, all agenda files"
384 (string :tag
"Access Key(s)")
385 (string :tag
"Description ")
386 (repeat :tag
"Component"
389 (const :format
"" agenda
)
390 (const :tag
"" :format
"" "")
391 ,org-agenda-custom-commands-local-options
)
392 (list :tag
"TODO list (all keywords)"
393 (const :format
"" alltodo
)
394 (const :tag
"" :format
"" "")
395 ,org-agenda-custom-commands-local-options
)
396 (list :tag
"Search words"
397 (const :format
"" search
)
398 (string :tag
"Match")
399 ,org-agenda-custom-commands-local-options
)
400 (list :tag
"Stuck projects"
401 (const :format
"" stuck
)
402 (const :tag
"" :format
"" "")
403 ,org-agenda-custom-commands-local-options
)
404 (list :tag
"Tags search"
405 (const :format
"" tags
)
406 (string :tag
"Match")
407 ,org-agenda-custom-commands-local-options
)
408 (list :tag
"Tags search, TODO entries only"
409 (const :format
"" tags-todo
)
410 (string :tag
"Match")
411 ,org-agenda-custom-commands-local-options
)
412 (list :tag
"TODO keyword search"
413 (const :format
"" todo
)
414 (string :tag
"Match")
415 ,org-agenda-custom-commands-local-options
)
416 (list :tag
"Other, user-defined function"
417 (symbol :tag
"function")
418 (string :tag
"Match")
419 ,org-agenda-custom-commands-local-options
)))
421 (repeat :tag
"Settings for entire command set"
422 (list (variable :tag
"Any variable")
423 (sexp :tag
"Value")))
424 (option (repeat :tag
"Export" (file :tag
"Export to"))))
425 (cons :tag
"Prefix key documentation"
426 (string :tag
"Access Key(s)")
427 (string :tag
"Description ")))))
429 (defcustom org-agenda-query-register ?o
430 "The register holding the current query string.
431 The purpose of this is that if you construct a query string interactively,
432 you can then use it to define a custom command."
433 :group
'org-agenda-custom-commands
436 (defcustom org-stuck-projects
437 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
438 "How to identify stuck projects.
439 This is a list of four items:
440 1. A tags/todo/property matcher string that is used to identify a project.
441 See the manual for a description of tag and property searches.
442 The entire tree below a headline matched by this is considered one project.
443 2. A list of TODO keywords identifying non-stuck projects.
444 If the project subtree contains any headline with one of these todo
445 keywords, the project is considered to be not stuck. If you specify
446 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
447 3. A list of tags identifying non-stuck projects.
448 If the project subtree contains any headline with one of these tags,
449 the project is considered to be not stuck. If you specify \"*\" as
450 a tag, any tag will mark the project unstuck. Note that this is about
451 the explicit presence of a tag somewhere in the subtree, inherited
452 tags to not count here. If inherited tags make a project not stuck,
453 use \"-TAG\" in the tags part of the matcher under (1.) above.
454 4. An arbitrary regular expression matching non-stuck projects.
456 If the project turns out to be not stuck, search continues also in the
457 subtree to see if any of the subtasks have project status.
459 See also the variable `org-tags-match-list-sublevels' which applies
460 to projects matched by this search as well.
462 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
463 or `C-c a #' to produce the list."
464 :group
'org-agenda-custom-commands
466 (string :tag
"Tags/TODO match to identify a project")
467 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
468 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
469 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
471 (defcustom org-agenda-filter-effort-default-operator
"<"
472 "The default operator for effort estimate filtering.
473 If you select an effort estimate limit without first pressing an operator,
474 this one will be used."
475 :group
'org-agenda-custom-commands
476 :type
'(choice (const :tag
"less or equal" "<")
477 (const :tag
"greater or equal"">")
478 (const :tag
"equal" "=")))
480 (defgroup org-agenda-skip nil
481 "Options concerning skipping parts of agenda files."
482 :tag
"Org Agenda Skip"
484 (defgroup org-agenda-daily
/weekly nil
485 "Options concerning the daily/weekly agenda."
486 :tag
"Org Agenda Daily/Weekly"
488 (defgroup org-agenda-todo-list nil
489 "Options concerning the global todo list agenda view."
490 :tag
"Org Agenda Todo List"
492 (defgroup org-agenda-match-view nil
493 "Options concerning the general tags/property/todo match agenda view."
494 :tag
"Org Agenda Match View"
496 (defgroup org-agenda-search-view nil
497 "Options concerning the general tags/property/todo match agenda view."
498 :tag
"Org Agenda Match View"
501 (defvar org-agenda-archives-mode nil
502 "Non-nil means, the agenda will include archived items.
503 If this is the symbol `trees', trees in the selected agenda scope
504 that are marked with the ARCHIVE tag will be included anyway. When this is
505 t, also all archive files associated with the current selection of agenda
506 files will be included.")
508 (defcustom org-agenda-skip-comment-trees t
509 "Non-nil means, skip trees that start with the COMMENT keyword.
510 When nil, these trees are also scanned by agenda commands."
511 :group
'org-agenda-skip
514 (defcustom org-agenda-todo-list-sublevels t
515 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
516 When nil, the sublevels of a TODO entry are not checked, resulting in
517 potentially much shorter TODO lists."
518 :group
'org-agenda-skip
519 :group
'org-agenda-todo-list
522 (defcustom org-agenda-todo-ignore-with-date nil
523 "Non-nil means, don't show entries with a date in the global todo list.
524 You can use this if you prefer to mark mere appointments with a TODO keyword,
525 but don't want them to show up in the TODO list.
526 When this is set, it also covers deadlines and scheduled items, the settings
527 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
529 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
530 :group
'org-agenda-skip
531 :group
'org-agenda-todo-list
534 (defcustom org-agenda-todo-ignore-scheduled nil
535 "Non-nil means, don't show scheduled entries in the global todo list.
536 The idea behind this is that by scheduling it, you have already taken care
538 See also `org-agenda-todo-ignore-with-date'.
539 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
540 :group
'org-agenda-skip
541 :group
'org-agenda-todo-list
544 (defcustom org-agenda-todo-ignore-deadlines nil
545 "Non-nil means, don't show near deadline entries in the global todo list.
546 Near means closer than `org-deadline-warning-days' days.
547 The idea behind this is that such items will appear in the agenda anyway.
548 See also `org-agenda-todo-ignore-with-date'.
549 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
550 :group
'org-agenda-skip
551 :group
'org-agenda-todo-list
554 (defcustom org-agenda-tags-todo-honor-ignore-options nil
555 "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
557 `org-agenda-todo-ignore-with-date',
558 `org-agenda-todo-ignore-scheduled'
559 `org-agenda-todo-ignore-deadlines'
560 make the global TODO list skip entries that have time stamps of certain
561 kinds. If this option is set, the same options will also apply for the
562 tags-todo search, which is the general tags/property matcher
563 restricted to unfinished TODO entries only."
564 :group
'org-agenda-skip
565 :group
'org-agenda-todo-list
566 :group
'org-agenda-match-view
569 (defcustom org-agenda-skip-scheduled-if-done nil
570 "Non-nil means don't show scheduled items in agenda when they are done.
571 This is relevant for the daily/weekly agenda, not for the TODO list. And
572 it applies only to the actual date of the scheduling. Warnings about
573 an item with a past scheduling dates are always turned off when the item
575 :group
'org-agenda-skip
576 :group
'org-agenda-daily
/weekly
579 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
580 "Non-nil means skip scheduling line if same entry shows because of deadline.
581 In the agenda of today, an entry can show up multiple times because
582 it is both scheduled and has a nearby deadline, and maybe a plain time
584 When this variable is t, then only the deadline is shown and the fact that
585 the entry is scheduled today or was scheduled previously is not shown.
586 When this variable is nil, the entry will be shown several times. When
587 the variable is the symbol `not-today', then skip scheduled previously,
588 but not scheduled today."
589 :group
'org-agenda-skip
590 :group
'org-agenda-daily
/weekly
592 (const :tag
"Never" nil
)
593 (const :tag
"Always" t
)
594 (const :tag
"Not when scheduled today" not-today
)))
596 (defcustom org-agenda-skip-deadline-if-done nil
597 "Non-nil means don't show deadlines when the corresponding item is done.
598 When nil, the deadline is still shown and should give you a happy feeling.
599 This is relevant for the daily/weekly agenda. And it applied only to the
600 actually date of the deadline. Warnings about approaching and past-due
601 deadlines are always turned off when the item is DONE."
602 :group
'org-agenda-skip
603 :group
'org-agenda-daily
/weekly
606 (defcustom org-agenda-skip-additional-timestamps-same-entry t
607 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
608 When non-nil, after the search for timestamps has matched once in an
609 entry, the rest of the entry will not be searched."
610 :group
'org-agenda-skip
613 (defcustom org-agenda-skip-timestamp-if-done nil
614 "Non-nil means don't select item by timestamp or -range if it is DONE."
615 :group
'org-agenda-skip
616 :group
'org-agenda-daily
/weekly
619 (defcustom org-agenda-dim-blocked-tasks t
620 "Non-nil means, dim blocked tasks in the agenda display.
621 This causes some overhead during agenda construction, but if you
622 have turned on `org-enforce-todo-dependencies',
623 `org-enforce-todo-checkbox-dependencies', or any other blocking
624 mechanism, this will create useful feedback in the agenda.
626 Instead of t, this variable can also have the value `invisible'.
627 Then blocked tasks will be invisible and only become visible when
628 they become unblocked. An exemption to this behavior is when a task is
629 blocked because of unchecked checkboxes below it. Since checkboxes do
630 not show up in the agenda views, making this task invisible you remove any
631 trace from agenda views that there is something to do. Therefore, a task
632 that is blocked because of checkboxes will never be made invisible, it
633 will only be dimmed."
634 :group
'org-agenda-daily
/weekly
635 :group
'org-agenda-todo-list
637 (const :tag
"Do not dim" nil
)
638 (const :tag
"Dim to a grey face" t
)
639 (const :tag
"Make invisible" invisible
)))
641 (defcustom org-timeline-show-empty-dates
3
642 "Non-nil means, `org-timeline' also shows dates without an entry.
643 When nil, only the days which actually have entries are shown.
644 When t, all days between the first and the last date are shown.
645 When an integer, show also empty dates, but if there is a gap of more than
646 N days, just insert a special line indicating the size of the gap."
647 :group
'org-agenda-skip
649 (const :tag
"None" nil
)
651 (integer :tag
"at most")))
653 (defgroup org-agenda-startup nil
654 "Options concerning initial settings in the Agenda in Org Mode."
655 :tag
"Org Agenda Startup"
658 (defcustom org-finalize-agenda-hook nil
659 "Hook run just before displaying an agenda buffer."
660 :group
'org-agenda-startup
663 (defcustom org-agenda-mouse-1-follows-link nil
664 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
665 A longer mouse click will still set point. Does not work on XEmacs.
666 Needs to be set before org.el is loaded."
667 :group
'org-agenda-startup
670 (defcustom org-agenda-start-with-follow-mode nil
671 "The initial value of follow-mode in a newly created agenda window."
672 :group
'org-agenda-startup
675 (defcustom org-agenda-show-outline-path t
676 "Non-il means, show outline path in echo area after line motion."
677 :group
'org-agenda-startup
680 (defcustom org-agenda-start-with-entry-text-mode nil
681 "The initial value of entry-text-mode in a newly created agenda window."
682 :group
'org-agenda-startup
685 (defcustom org-agenda-entry-text-maxlines
5
686 "Number of text lines to be added when `E' is pressed in the agenda.
688 Note that this variable only used during agenda display. Add add entry text
689 when exporting the agenda, configure the variable
690 `org-agenda-add-entry-ext-maxlines'."
694 (defcustom org-agenda-entry-text-exclude-regexps nil
695 "List of regular expressions to clean up entry text.
696 The complete matches of all regular expressions in this list will be
697 removed from entry text before it is shown in the agenda."
699 :type
'(repeat (regexp)))
701 (defvar org-agenda-entry-text-cleanup-hook nil
702 "Hook that is run after basic cleanup of entry text to be shown in agenda.
703 This cleanup is done in a temporary buffer, so the function may inspect and
704 change the entire buffer.
705 Some default stuff like drawers and scheduling/deadline dates will already
706 have been removed when this is called, as will any matches for regular
707 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
709 (defvar org-agenda-include-inactive-timestamps nil
710 "Non-nil means, include inactive time stamps in agenda and timeline.")
712 (defgroup org-agenda-windows nil
713 "Options concerning the windows used by the Agenda in Org Mode."
714 :tag
"Org Agenda Windows"
717 (defcustom org-agenda-window-setup
'reorganize-frame
718 "How the agenda buffer should be displayed.
719 Possible values for this option are:
721 current-window Show agenda in the current window, keeping all other windows.
722 other-window Use `switch-to-buffer-other-window' to display agenda.
723 reorganize-frame Show only two windows on the current frame, the current
724 window and the agenda.
725 other-frame Use `switch-to-buffer-other-frame' to display agenda.
726 Also, when exiting the agenda, kill that frame.
727 See also the variable `org-agenda-restore-windows-after-quit'."
728 :group
'org-agenda-windows
730 (const current-window
)
733 (const reorganize-frame
)))
735 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
736 "The min and max height of the agenda window as a fraction of frame height.
737 The value of the variable is a cons cell with two numbers between 0 and 1.
738 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
739 :group
'org-agenda-windows
740 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
742 (defcustom org-agenda-restore-windows-after-quit nil
743 "Non-nil means, restore window configuration open exiting agenda.
744 Before the window configuration is changed for displaying the agenda,
745 the current status is recorded. When the agenda is exited with
746 `q' or `x' and this option is set, the old state is restored. If
747 `org-agenda-window-setup' is `other-frame', the value of this
748 option will be ignored."
749 :group
'org-agenda-windows
752 (defcustom org-agenda-ndays
7
753 "Number of days to include in overview display.
755 Custom commands can set this variable in the options section."
756 :group
'org-agenda-daily
/weekly
759 (defcustom org-agenda-start-on-weekday
1
760 "Non-nil means, start the overview always on the specified weekday.
761 0 denotes Sunday, 1 denotes Monday etc.
762 When nil, always start on the current day.
763 Custom commands can set this variable in the options section."
764 :group
'org-agenda-daily
/weekly
765 :type
'(choice (const :tag
"Today" nil
)
766 (integer :tag
"Weekday No.")))
768 (defcustom org-agenda-show-all-dates t
769 "Non-nil means, `org-agenda' shows every day in the selected range.
770 When nil, only the days which actually have entries are shown."
771 :group
'org-agenda-daily
/weekly
774 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
775 "Format string for displaying dates in the agenda.
776 Used by the daily/weekly agenda and by the timeline. This should be
777 a format string understood by `format-time-string', or a function returning
778 the formatted date as a string. The function must take a single argument,
779 a calendar-style date list like (month day year)."
780 :group
'org-agenda-daily
/weekly
782 (string :tag
"Format string")
783 (function :tag
"Function")))
785 (defun org-agenda-format-date-aligned (date)
786 "Format a date string for display in the daily/weekly agenda, or timeline.
787 This function makes sure that dates are aligned for easy reading."
789 (let* ((dayname (calendar-day-name date
))
791 (day-of-week (calendar-day-of-week date
))
793 (monthname (calendar-month-name month
))
795 (iso-week (org-days-to-iso-week
796 (calendar-absolute-from-gregorian date
)))
797 (weekyear (cond ((and (= month
1) (>= iso-week
52))
799 ((and (= month
12) (<= iso-week
1))
802 (weekstring (if (= day-of-week
1)
803 (format " W%02d" iso-week
)
805 (format "%-10s %2d %s %4d%s"
806 dayname day monthname year weekstring
)))
808 (defcustom org-agenda-weekend-days
'(6 0)
809 "Which days are weekend?
810 These days get the special face `org-agenda-date-weekend' in the agenda
811 and timeline buffers."
812 :group
'org-agenda-daily
/weekly
813 :type
'(set :greedy t
814 (const :tag
"Monday" 1)
815 (const :tag
"Tuesday" 2)
816 (const :tag
"Wednesday" 3)
817 (const :tag
"Thursday" 4)
818 (const :tag
"Friday" 5)
819 (const :tag
"Saturday" 6)
820 (const :tag
"Sunday" 0)))
822 (defcustom org-agenda-include-diary nil
823 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
824 Custom commands can set this variable in the options section."
825 :group
'org-agenda-daily
/weekly
828 (defcustom org-agenda-include-all-todo nil
829 "Set means weekly/daily agenda will always contain all TODO entries.
830 The TODO entries will be listed at the top of the agenda, before
831 the entries for specific days.
832 This option is deprecated, it is better to define a block agenda instead."
833 :group
'org-agenda-daily
/weekly
836 (defcustom org-agenda-repeating-timestamp-show-all t
837 "Non-nil means, show all occurrences of a repeating stamp in the agenda.
838 When nil, only one occurrence is shown, either today or the
839 nearest into the future."
840 :group
'org-agenda-daily
/weekly
843 (defcustom org-scheduled-past-days
10000
844 "No. of days to continue listing scheduled items that are not marked DONE.
845 When an item is scheduled on a date, it shows up in the agenda on this
846 day and will be listed until it is marked done for the number of days
848 :group
'org-agenda-daily
/weekly
851 (defcustom org-agenda-log-mode-items
'(closed clock
)
852 "List of items that should be shown in agenda log mode.
853 This list may contain the following symbols:
855 closed Show entries that have been closed on that day.
856 clock Show entries that have received clocked time on that day.
857 state Show all logged state changes.
858 Note that instead of changing this variable, you can also press `C-u l' in
859 the agenda to display all available LOG items temporarily."
860 :group
'org-agenda-daily
/weekly
861 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
863 (defcustom org-agenda-log-mode-add-notes t
864 "Non-nil means, add first line of notes to log entries in agenda views.
865 If a log item like a state change or a clock entry is associated with
866 notes, the first line of these notes will be added to the entry in the
868 :group
'org-agenda-daily
/weekly
871 (defcustom org-agenda-start-with-log-mode nil
872 "The initial value of log-mode in a newly created agenda window."
873 :group
'org-agenda-startup
874 :group
'org-agenda-daily
/weekly
877 (defcustom org-agenda-start-with-clockreport-mode nil
878 "The initial value of clockreport-mode in a newly created agenda window."
879 :group
'org-agenda-startup
880 :group
'org-agenda-daily
/weekly
883 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
884 "Property list with parameters for the clocktable in clockreport mode.
885 This is the display mode that shows a clock table in the daily/weekly
886 agenda, the properties for this dynamic block can be set here.
887 The usual clocktable parameters are allowed here, but you cannot set
888 the properties :name, :tstart, :tend, :block, and :scope - these will
889 be overwritten to make sure the content accurately reflects the
890 current display in the agenda."
891 :group
'org-agenda-daily
/weekly
894 (defcustom org-agenda-search-view-always-boolean nil
895 "Non-nil means, the search string is interpreted as individual parts.
897 The search string for search view can either be interpreted as a phrase,
898 or as a list of snippets that define a boolean search for a number of
901 When this is non-nil, the string will be split on whitespace, and each
902 snippet will be searched individually, and all must match in order to
903 select an entry. A snippet is then a single string of non-white
904 characters, or a string in double quotes, or a regexp in {} braces.
905 If a snippet is preceeded by \"-\", the snippet must *not* match.
906 \"+\" is syntactic sugar for positive selection. Each snippet may
907 be found as a full word or a partial word, but see the variable
908 `org-agenda-search-view-force-full-words'.
910 When this is nil, search will look for the entire search phrase as one,
911 with each space character matching any amount of whitespace, including
914 Even when this is nil, you can still switch to Boolean search dynamically
915 by preceeding the first snippet with \"+\" or \"-\". If the first snippet
916 is a regexp marked with braces like \"{abc}\", this will also switch to
918 :group
'org-agenda-search-view
921 (if (fboundp 'defvaralias
)
922 (defvaralias 'org-agenda-search-view-search-words-only
923 'org-agenda-search-view-always-boolean
))
925 (defcustom org-agenda-search-view-force-full-words nil
927 ans, search words must be matches as complete words.
928 When nil, they may also match part of a word."
929 :group
'org-agenda-search-view
932 (defgroup org-agenda-time-grid nil
933 "Options concerning the time grid in the Org-mode Agenda."
934 :tag
"Org Agenda Time Grid"
937 (defcustom org-agenda-search-headline-for-time t
938 "Non-nil means, search headline for a time-of-day.
939 If the headline contains a time-of-day in one format or another, it will
940 be used to sort the entry into the time sequence of items for a day.
941 Some people have time stamps in the headline that refer to the creation
942 time or so, and then this produces an unwanted side effect. If this is
943 the case for your, use this variable to turn off searching the headline
945 :group
'org-agenda-time-grid
948 (defcustom org-agenda-use-time-grid t
949 "Non-nil means, show a time grid in the agenda schedule.
950 A time grid is a set of lines for specific times (like every two hours between
951 8:00 and 20:00). The items scheduled for a day at specific times are
952 sorted in between these lines.
953 For details about when the grid will be shown, and what it will look like, see
954 the variable `org-agenda-time-grid'."
955 :group
'org-agenda-time-grid
958 (defcustom org-agenda-time-grid
959 '((daily today require-timed
)
961 (800 1000 1200 1400 1600 1800 2000))
963 "The settings for time grid for agenda display.
964 This is a list of three items. The first item is again a list. It contains
965 symbols specifying conditions when the grid should be displayed:
967 daily if the agenda shows a single day
968 weekly if the agenda shows an entire week
969 today show grid on current date, independent of daily/weekly display
970 require-timed show grid only if at least one item has a time specification
972 The second item is a string which will be placed behind the grid time.
974 The third item is a list of integers, indicating the times that should have
976 :group
'org-agenda-time-grid
979 (set :greedy t
:tag
"Grid Display Options"
980 (const :tag
"Show grid in single day agenda display" daily
)
981 (const :tag
"Show grid in weekly agenda display" weekly
)
982 (const :tag
"Always show grid for today" today
)
983 (const :tag
"Show grid only if any timed entries are present"
985 (const :tag
"Skip grid times already present in an entry"
987 (string :tag
"Grid String")
988 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
990 (defgroup org-agenda-sorting nil
991 "Options concerning sorting in the Org-mode Agenda."
992 :tag
"Org Agenda Sorting"
995 (defcustom org-agenda-sorting-strategy
996 '((agenda habit-down time-up priority-down category-keep
)
997 (todo priority-down category-keep
)
998 (tags priority-down category-keep
)
999 (search category-keep
))
1000 "Sorting structure for the agenda items of a single day.
1001 This is a list of symbols which will be used in sequence to determine
1002 if an entry should be listed before another entry. The following
1003 symbols are recognized:
1005 time-up Put entries with time-of-day indications first, early first
1006 time-down Put entries with time-of-day indications first, late first
1007 category-keep Keep the default order of categories, corresponding to the
1008 sequence in `org-agenda-files'.
1009 category-up Sort alphabetically by category, A-Z.
1010 category-down Sort alphabetically by category, Z-A.
1011 tag-up Sort alphabetically by last tag, A-Z.
1012 tag-down Sort alphabetically by last tag, Z-A.
1013 priority-up Sort numerically by priority, high priority last.
1014 priority-down Sort numerically by priority, high priority first.
1015 todo-state-up Sort by todo state, tasks that are done last.
1016 todo-state-down Sort by todo state, tasks that are done first.
1017 effort-up Sort numerically by estimated effort, high effort last.
1018 effort-down Sort numerically by estimated effort, high effort first.
1019 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1020 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1021 habit-up Put entries that are habits first
1022 habit-down Put entries that are habits last
1024 The different possibilities will be tried in sequence, and testing stops
1025 if one comparison returns a \"not-equal\". For example, the default
1026 '(time-up category-keep priority-down)
1027 means: Pull out all entries having a specified time of day and sort them,
1028 in order to make a time schedule for the current day the first thing in the
1029 agenda listing for the day. Of the entries without a time indication, keep
1030 the grouped in categories, don't sort the categories, but keep them in
1031 the sequence given in `org-agenda-files'. Within each category sort by
1034 Leaving out `category-keep' would mean that items will be sorted across
1035 categories by priority.
1037 Instead of a single list, this can also be a set of list for specific
1038 contents, with a context symbol in the car of the list, any of
1039 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1041 Custom commands can bind this variable in the options section."
1042 :group
'org-agenda-sorting
1044 (repeat :tag
"General" ,org-sorting-choice
)
1045 (list :tag
"Individually"
1046 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
1047 (repeat ,org-sorting-choice
))
1048 (cons (const :tag
"Strategy for TODO lists" todo
)
1049 (repeat ,org-sorting-choice
))
1050 (cons (const :tag
"Strategy for Tags matches" tags
)
1051 (repeat ,org-sorting-choice
))
1052 (cons (const :tag
"Strategy for search matches" search
)
1053 (repeat ,org-sorting-choice
)))))
1055 (defcustom org-agenda-cmp-user-defined nil
1056 "A function to define the comparison `user-defined'.
1057 This function must receive two arguments, agenda entry a and b.
1058 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1059 the user comparison, return nil.
1060 When this is defined, you can make `user-defined-up' and `user-defined-down'
1061 part of an agenda sorting strategy."
1062 :group
'org-agenda-sorting
1065 (defcustom org-sort-agenda-notime-is-late t
1066 "Non-nil means, items without time are considered late.
1067 This is only relevant for sorting. When t, items which have no explicit
1068 time like 15:30 will be considered as 99:01, i.e. later than any items which
1069 do have a time. When nil, the default time is before 0:00. You can use this
1070 option to decide if the schedule for today should come before or after timeless
1072 :group
'org-agenda-sorting
1075 (defcustom org-sort-agenda-noeffort-is-high t
1076 "Non-nil means, items without effort estimate are sorted as high effort.
1077 This also applies when filtering an agenda view with respect to the
1078 < or > effort operator. Then, tasks with no effort defined will be treated
1079 as tasks with high effort.
1080 When nil, such items are sorted as 0 minutes effort."
1081 :group
'org-agenda-sorting
1084 (defgroup org-agenda-line-format nil
1085 "Options concerning the entry prefix in the Org-mode agenda display."
1086 :tag
"Org Agenda Line Format"
1089 (defcustom org-agenda-prefix-format
1090 '((agenda .
" %-12:c%?-12t% s")
1094 (search .
" %-12:c"))
1095 "Format specifications for the prefix of items in the agenda views.
1096 An alist with four entries, for the different agenda types. The keys to the
1097 sublists are `agenda', `timeline', `todo', and `tags'. The values
1099 This format works similar to a printf format, with the following meaning:
1101 %c the category of the item, \"Diary\" for entries from the diary, or
1102 as given by the CATEGORY keyword or derived from the file name.
1103 %T the *last* tag of the item. Last because inherited tags come
1105 %t the time-of-day specification if one applies to the entry, in the
1107 %s Scheduling/Deadline information, a short string
1109 All specifiers work basically like the standard `%s' of printf, but may
1110 contain two additional characters: A question mark just after the `%' and
1111 a whitespace/punctuation character just before the final letter.
1113 If the first character after `%' is a question mark, the entire field
1114 will only be included if the corresponding value applies to the
1115 current entry. This is useful for fields which should have fixed
1116 width when present, but zero width when absent. For example,
1117 \"%?-12t\" will result in a 12 character time field if a time of the
1118 day is specified, but will completely disappear in entries which do
1121 If there is punctuation or whitespace character just before the final
1122 format letter, this character will be appended to the field value if
1123 the value is not empty. For example, the format \"%-12:c\" leads to
1124 \"Diary: \" if the category is \"Diary\". If the category were be
1125 empty, no additional colon would be inserted.
1127 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1128 - Indent the line with two space characters
1129 - Give the category in a 12 chars wide field, padded with whitespace on
1130 the right (because of `-'). Append a colon if there is a category
1132 - If there is a time-of-day, put it into a 12 chars wide field. If no
1133 time, don't put in an empty field, just skip it (because of '?').
1134 - Finally, put the scheduling information and append a whitespace.
1136 As another example, if you don't want the time-of-day of entries in
1137 the prefix, you could use:
1139 (setq org-agenda-prefix-format \" %-11:c% s\")
1141 See also the variables `org-agenda-remove-times-when-in-prefix' and
1142 `org-agenda-remove-tags'.
1144 Custom commands can set this variable in the options section."
1146 (string :tag
"General format")
1147 (list :greedy t
:tag
"View dependent"
1148 (cons (const agenda
) (string :tag
"Format"))
1149 (cons (const timeline
) (string :tag
"Format"))
1150 (cons (const todo
) (string :tag
"Format"))
1151 (cons (const tags
) (string :tag
"Format"))
1152 (cons (const search
) (string :tag
"Format"))))
1153 :group
'org-agenda-line-format
)
1155 (defvar org-prefix-format-compiled nil
1156 "The compiled version of the most recently used prefix format.
1157 See the variable `org-agenda-prefix-format'.")
1159 (defcustom org-agenda-todo-keyword-format
"%-1s"
1160 "Format for the TODO keyword in agenda lines.
1161 Set this to something like \"%-12s\" if you want all TODO keywords
1162 to occupy a fixed space in the agenda display."
1163 :group
'org-agenda-line-format
1166 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1167 "Text preceding timerange entries in the agenda view.
1168 This is a list with two strings. The first applies when the range
1169 is entirely on one day. The second applies if the range spans several days.
1170 The strings may have two \"%d\" format specifiers which will be filled
1171 with the sequence number of the days, and the total number of days in the
1172 range, respectively."
1173 :group
'org-agenda-line-format
1175 (string :tag
"Deadline today ")
1176 (choice :tag
"Deadline relative"
1177 (string :tag
"Format string")
1180 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1181 "Text preceeding scheduled items in the agenda view.
1182 This is a list with two strings. The first applies when the item is
1183 scheduled on the current day. The second applies when it has been scheduled
1184 previously, it may contain a %d indicating that this is the nth time that
1185 this item is scheduled, due to automatic rescheduling of unfinished items
1186 for the following day. So this number is one larger than the number of days
1187 that passed since this item was scheduled first."
1188 :group
'org-agenda-line-format
1190 (string :tag
"Scheduled today ")
1191 (string :tag
"Scheduled previously")))
1193 (defcustom org-agenda-inactive-leader
"["
1194 "Text preceeding item pulled into the agenda by inactive time stamps.
1195 These entries are added to the agenda when pressing \"[\"."
1196 :group
'org-agenda-line-format
1198 (string :tag
"Scheduled today ")
1199 (string :tag
"Scheduled previously")))
1201 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1202 "Text preceeding deadline items in the agenda view.
1203 This is a list with two strings. The first applies when the item has its
1204 deadline on the current day. The second applies when it is in the past or
1205 in the future, it may contain %d to capture how many days away the deadline
1207 :group
'org-agenda-line-format
1209 (string :tag
"Deadline today ")
1210 (choice :tag
"Deadline relative"
1211 (string :tag
"Format string")
1214 (defcustom org-agenda-remove-times-when-in-prefix t
1215 "Non-nil means, remove duplicate time specifications in agenda items.
1216 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1217 time-of-day specification in a headline or diary entry is extracted and
1218 placed into the prefix. If this option is non-nil, the original specification
1219 \(a timestamp or -range, or just a plain time(range) specification like
1220 11:30-4pm) will be removed for agenda display. This makes the agenda less
1222 The option can be t or nil. It may also be the symbol `beg', indicating
1223 that the time should only be removed what it is located at the beginning of
1224 the headline/diary entry."
1225 :group
'org-agenda-line-format
1227 (const :tag
"Always" t
)
1228 (const :tag
"Never" nil
)
1229 (const :tag
"When at beginning of entry" beg
)))
1232 (defcustom org-agenda-default-appointment-duration nil
1233 "Default duration for appointments that only have a starting time.
1234 When nil, no duration is specified in such cases.
1235 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1236 :group
'org-agenda-line-format
1238 (integer :tag
"Minutes")
1239 (const :tag
"No default duration")))
1241 (defcustom org-agenda-show-inherited-tags t
1242 "Non-nil means, show inherited tags in each agenda line."
1243 :group
'org-agenda-line-format
1246 (defcustom org-agenda-hide-tags-regexp nil
1247 "Regular expression used to filter away specific tags in agenda views.
1248 This means that these tags will be present, but not be shown in the agenda
1249 line. Secondayt filltering will still work on the hidden tags.
1250 Nil means don't hide any tags."
1251 :group
'org-agenda-line-format
1253 (const :tag
"Hide none" nil
)
1254 (string :tag
"Regexp ")))
1256 (defcustom org-agenda-remove-tags nil
1257 "Non-nil means, remove the tags from the headline copy in the agenda.
1258 When this is the symbol `prefix', only remove tags when
1259 `org-agenda-prefix-format' contains a `%T' specifier."
1260 :group
'org-agenda-line-format
1262 (const :tag
"Always" t
)
1263 (const :tag
"Never" nil
)
1264 (const :tag
"When prefix format contains %T" prefix
)))
1266 (if (fboundp 'defvaralias
)
1267 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1268 'org-agenda-remove-tags
))
1270 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1271 "Shift tags in agenda items to this column.
1272 If this number is positive, it specifies the column. If it is negative,
1273 it means that the tags should be flushright to that column. For example,
1274 -80 works well for a normal 80 character screen."
1275 :group
'org-agenda-line-format
1278 (if (fboundp 'defvaralias
)
1279 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1281 (defcustom org-agenda-fontify-priorities
'cookies
1282 "Non-nil means, highlight low and high priorities in agenda.
1283 When t, the highest priority entries are bold, lowest priority italic.
1284 However, settings in org-priority-faces will overrule these faces.
1285 When this variable is the symbol `cookies', only fontify the
1286 cookies, not the entire task.
1287 This may also be an association list of priority faces, whose
1288 keys are the character values of `org-highest-priority',
1289 `org-default-priority', and `org-lowest-priority' (the default values
1290 are ?A, ?B, and ?C, respectively). The face may be a named face,
1291 or a list like `(:background \"Red\")'."
1292 :group
'org-agenda-line-format
1294 (const :tag
"Never" nil
)
1295 (const :tag
"Defaults" t
)
1296 (const :tag
"Cookies only" cookies
)
1297 (repeat :tag
"Specify"
1298 (list (character :tag
"Priority" :value ?A
)
1299 (sexp :tag
"face")))))
1301 (defgroup org-agenda-column-view nil
1302 "Options concerning column view in the agenda."
1303 :tag
"Org Agenda Column View"
1306 (defcustom org-agenda-columns-show-summaries t
1307 "Non-nil means, show summaries for columns displayed in the agenda view."
1308 :group
'org-agenda-column-view
1311 (defcustom org-agenda-columns-remove-prefix-from-item t
1312 "Non-nil means, remove the prefix from a headline for agenda column view.
1313 The special ITEM field in the columns format contains the current line, with
1314 all information shown in other columns (like the TODO state or a tag).
1315 When this variable is non-nil, also the agenda prefix will be removed from
1316 the content of the ITEM field, to make sure as much as possible of the
1317 headline can be shown in the limited width of the field."
1321 (defcustom org-agenda-columns-compute-summary-properties t
1322 "Non-nil means, recompute all summary properties before column view.
1323 When column view in the agenda is listing properties that have a summary
1324 operator, it can go to all relevant buffers and recompute the summaries
1325 there. This can mean overhead for the agenda column view, but is necessary
1326 to have thing up to date.
1327 As a special case, a CLOCKSUM property also makes sure that the clock
1328 computations are current."
1329 :group
'org-agenda-column-view
1332 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1333 "Non-nil means, the duration of an appointment will add to day effort.
1334 The property to which appointment durations will be added is the one given
1335 in the option `org-effort-property'. If an appointment does not have
1336 an end time, `org-agenda-default-appointment-duration' will be used. If that
1337 is not set, an appointment without end time will not contribute to the time
1339 :group
'org-agenda-column-view
1342 (defcustom org-agenda-auto-exclude-function nil
1343 "A function called with a tag to decide if it is filtered on '/ RET'.
1344 The sole argument to the function, which is called once for each
1345 possible tag, is a string giving the name of the tag. The
1346 function should return either nil if the tag should be included
1347 as normal, or \"-<TAG>\" to exclude the tag.
1348 Note that for the purpose of tag filtering, only the lower-case version of
1349 all tags will be considered, so that this function will only ever see
1350 the lower-case version of all tags."
1358 (defun org-add-agenda-custom-command (entry)
1359 "Replace or add a command in `org-agenda-custom-commands'.
1360 This is mostly for hacking and trying a new command - once the command
1361 works you probably want to add it to `org-agenda-custom-commands' for good."
1362 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1364 (setcdr ass
(cdr entry
))
1365 (push entry org-agenda-custom-commands
))))
1367 ;;; Define the Org-agenda-mode
1369 (defvar org-agenda-mode-map
(make-sparse-keymap)
1370 "Keymap for `org-agenda-mode'.")
1371 (if (fboundp 'defvaralias
)
1372 (defvaralias 'org-agenda-keymap
'org-agenda-mode-map
))
1374 (defvar org-agenda-menu
) ; defined later in this file.
1375 (defvar org-agenda-restrict
) ; defined later in this file.
1376 (defvar org-agenda-follow-mode nil
)
1377 (defvar org-agenda-entry-text-mode nil
)
1378 (defvar org-agenda-clockreport-mode nil
)
1379 (defvar org-agenda-show-log nil
)
1380 (defvar org-agenda-redo-command nil
)
1381 (defvar org-agenda-query-string nil
)
1382 (defvar org-agenda-mode-hook nil
1383 "Hook for org-agenda-mode, run after the mode is turned on.")
1384 (defvar org-agenda-type nil
)
1385 (defvar org-agenda-force-single-file nil
)
1386 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1388 (defun org-agenda-mode ()
1389 "Mode for time-sorted view on action items in Org-mode files.
1391 The following commands are available:
1393 \\{org-agenda-mode-map}"
1395 (kill-all-local-variables)
1396 (setq org-agenda-undo-list nil
1397 org-agenda-pending-undo-list nil
1398 org-agenda-bulk-marked-entries nil
)
1399 (setq major-mode
'org-agenda-mode
)
1400 ;; Keep global-font-lock-mode from turning on font-lock-mode
1401 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1402 (setq mode-name
"Org-Agenda")
1403 (use-local-map org-agenda-mode-map
)
1404 (easy-menu-add org-agenda-menu
)
1405 (if org-startup-truncated
(setq truncate-lines t
))
1406 (org-set-local 'line-move-visual nil
)
1407 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1408 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1409 ;; Make sure properties are removed when copying text
1410 (when (boundp 'buffer-substring-filters
)
1411 (org-set-local 'buffer-substring-filters
1413 (set-text-properties 0 (length x
) nil x
) x
)
1414 buffer-substring-filters
)))
1415 (unless org-agenda-keep-modes
1416 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1417 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1418 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1419 org-agenda-show-log org-agenda-start-with-log-mode
))
1422 '("Agenda") "Agenda Files"
1426 (if (get 'org-agenda-files
'org-restrict
)
1427 "Restricted to single file"
1429 '(org-edit-agenda-file-list)
1430 (not (get 'org-agenda-files
'org-restrict
)))
1432 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1433 (org-agenda-set-mode-name)
1435 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1436 (list 'org-agenda-mode-hook
)))
1438 (substitute-key-definition 'undo
'org-agenda-undo
1439 org-agenda-mode-map global-map
)
1440 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1441 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1442 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1443 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1444 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1445 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1446 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1447 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1448 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1449 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1450 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-a" 'org-agenda-archive-default
)
1451 (org-defkey org-agenda-mode-map
"\C-c\C-xa" 'org-agenda-toggle-archive-tag
)
1452 (org-defkey org-agenda-mode-map
"\C-c\C-xA" 'org-agenda-archive-to-archive-sibling
)
1453 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1454 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1455 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1456 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1457 (org-defkey org-agenda-mode-map
" " 'org-agenda-show-and-scroll-up
)
1458 (org-defkey org-agenda-mode-map
[backspace] 'org-agenda-show-scroll-down)
1459 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1460 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1461 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1462 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1463 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1464 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1465 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1466 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1467 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1468 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1469 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1470 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1471 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1472 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1473 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1474 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1475 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1476 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1477 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1478 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1479 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1480 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1481 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1482 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1484 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1485 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1486 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1487 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1488 (while l (org-defkey org-agenda-mode-map
1489 (int-to-string (pop l)) 'digit-argument)))
1491 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1492 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1493 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1494 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1495 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1496 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1497 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1498 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1499 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1500 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1501 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1502 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1503 'org-clock-modify-effort-estimate)
1504 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1505 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1506 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1507 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1508 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1509 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1510 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1511 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1512 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1513 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1514 (substitute-key-definition 'next-line 'org-agenda-next-line
1515 org-agenda-mode-map global-map)
1516 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1517 org-agenda-mode-map global-map)
1518 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1519 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1520 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1521 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1522 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1523 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1524 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1525 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1526 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1527 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1528 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1529 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1530 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1531 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1532 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1533 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1534 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1535 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1536 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1537 (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
1538 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1539 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1540 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1541 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1542 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1543 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1544 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1545 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1546 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1547 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1549 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1550 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1551 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1552 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1553 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1554 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1555 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1556 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1557 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1558 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1560 (org-defkey org-agenda-mode-map
1561 (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
1562 (org-defkey org-agenda-mode-map
1563 (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
1564 (when org-agenda-mouse-1-follows-link
1565 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1566 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1571 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1572 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1573 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1574 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1577 ["Day View" org-agenda-day-view
1578 :active (org-agenda-check-type nil 'agenda)
1579 :style radio :selected (equal org-agenda-ndays 1)
1580 :keys "v d (or just d)"]
1581 ["Week View" org-agenda-week-view
1582 :active (org-agenda-check-type nil 'agenda)
1583 :style radio :selected (equal org-agenda-ndays 7)
1584 :keys "v w (or just w)"]
1585 ["Month View" org-agenda-month-view
1586 :active (org-agenda-check-type nil 'agenda)
1587 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1589 ["Year View" org-agenda-year-view
1590 :active (org-agenda-check-type nil 'agenda)
1591 :style radio :selected (member org-agenda-ndays '(365 366))
1594 ["Include Diary" org-agenda-toggle-diary
1595 :style toggle :selected org-agenda-include-diary
1596 :active (org-agenda-check-type nil 'agenda)]
1597 ["Use Time Grid" org-agenda-toggle-time-grid
1598 :style toggle :selected org-agenda-use-time-grid
1599 :active (org-agenda-check-type nil 'agenda)]
1601 ["Show clock report" org-agenda-clockreport-mode
1602 :style toggle :selected org-agenda-clockreport-mode
1603 :active (org-agenda-check-type nil 'agenda)]
1604 ["Show some entry text" org-agenda-entry-text-mode
1605 :style toggle :selected org-agenda-entry-text-mode
1608 ["Show Logbook entries" org-agenda-log-mode
1609 :style toggle :selected org-agenda-show-log
1610 :active (org-agenda-check-type nil 'agenda 'timeline)
1611 :keys "v l (or just l)"]
1612 ["Include archived trees" org-agenda-archives-mode
1613 :style toggle :selected org-agenda-archives-mode :active t
1615 ["Include archive files" (org-agenda-archives-mode t)
1616 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1619 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1620 ["Write view to file" org-write-agenda t]
1621 ["Rebuild buffer" org-agenda-redo t]
1622 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1624 ["Show original entry" org-agenda-show t]
1625 ["Go To (other window)" org-agenda-goto t]
1626 ["Go To (this window)" org-agenda-switch-to t]
1627 ["Follow Mode" org-agenda-follow-mode
1628 :style toggle :selected org-agenda-follow-mode :active t]
1629 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1632 ["Cycle TODO" org-agenda-todo t]
1633 ["Next TODO set" org-agenda-todo-nextset t]
1634 ["Previous TODO set" org-agenda-todo-previousset t]
1635 ["Add note" org-agenda-add-note t])
1636 ("Archive/Refile/Delete"
1637 ["Archive default" org-agenda-archive-default t]
1638 ["Archive default" org-agenda-archive-default-with-confirmation t]
1639 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1640 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1641 ["Archive subtree" org-agenda-archive t]
1643 ["Refile" org-agenda-refile t]
1645 ["Delete subtree" org-agenda-kill t])
1647 ["Mark entry" org-agenda-bulk-mark t]
1648 ["Unmark entry" org-agenda-bulk-unmark t]
1649 ["Act on all marked" org-agenda-bulk-action t]
1650 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1652 ("Tags and Properties"
1653 ["Show all Tags" org-agenda-show-tags t]
1654 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1655 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1657 ["Column View" org-columns t])
1658 ("Deadline/Schedule"
1659 ["Schedule" org-agenda-schedule t]
1660 ["Set Deadline" org-agenda-deadline t]
1662 ["Mark item" org-agenda-action :active t :keys "k m"]
1663 ["Show mark item" org-agenda-action :active t :keys "k v"]
1664 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1665 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1667 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1668 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1669 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1670 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1671 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1672 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1673 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1675 ["Clock in" org-agenda-clock-in t]
1676 ["Clock out" org-agenda-clock-out t]
1677 ["Clock cancel" org-agenda-clock-cancel t]
1678 ["Goto running clock" org-clock-goto t]
1680 ["Set Effort" org-agenda-set-effort t]
1681 ["Change clocked effort" org-clock-modify-effort-estimate
1682 (org-clock-is-active)])
1684 ["Set Priority" org-agenda-priority t]
1685 ["Increase Priority" org-agenda-priority-up t]
1686 ["Decrease Priority" org-agenda-priority-down t]
1687 ["Show Priority" org-agenda-show-priority t])
1689 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1690 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1691 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1692 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1693 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1694 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1696 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1698 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1701 ["Push Files and Views" org-mobile-push t]
1702 ["Get Captured and Flagged" org-mobile-pull t]
1703 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1704 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1706 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1708 ["Quit" org-agenda-quit t]
1709 ["Exit and Release Buffers" org-agenda-exit t]
1714 (defvar org-agenda-allow-remote-undo t
1715 "Non-nil means, allow remote undo from the agenda buffer.")
1716 (defvar org-agenda-undo-list nil
1717 "List of undoable operations in the agenda since last refresh.")
1718 (defvar org-agenda-undo-has-started-in nil
1719 "Buffers that have already seen `undo-start' in the current undo sequence.")
1720 (defvar org-agenda-pending-undo-list nil
1721 "In a series of undo commands, this is the list of remaining undo items.")
1724 (defun org-agenda-undo ()
1725 "Undo a remote editing step in the agenda.
1726 This undoes changes both in the agenda buffer and in the remote buffer
1727 that have been changed along."
1729 (or org-agenda-allow-remote-undo
1730 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1731 (if (not (eq this-command last-command))
1732 (setq org-agenda-undo-has-started-in nil
1733 org-agenda-pending-undo-list org-agenda-undo-list))
1734 (if (not org-agenda-pending-undo-list)
1735 (error "No further undo information"))
1736 (let* ((entry (pop org-agenda-pending-undo-list))
1737 buf line cmd rembuf)
1738 (setq cmd (pop entry) line (pop entry))
1739 (setq rembuf (nth 2 entry))
1740 (org-with-remote-undo rembuf
1741 (while (bufferp (setq buf (pop entry)))
1743 (with-current-buffer buf
1744 (let ((last-undo-buffer buf)
1745 (inhibit-read-only t))
1746 (unless (memq buf org-agenda-undo-has-started-in)
1747 (push buf org-agenda-undo-has-started-in)
1748 (make-local-variable 'pending-undo-list)
1750 (while (and pending-undo-list
1751 (listp pending-undo-list)
1752 (not (car pending-undo-list)))
1753 (pop pending-undo-list))
1755 (org-goto-line line)
1756 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1758 (defun org-verify-change-for-undo (l1 l2)
1759 "Verify that a real change occurred between the undo lists L1 and L2."
1760 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1761 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1766 (defvar org-agenda-restrict nil)
1767 (defvar org-agenda-restrict-begin (make-marker))
1768 (defvar org-agenda-restrict-end (make-marker))
1769 (defvar org-agenda-last-dispatch-buffer nil)
1770 (defvar org-agenda-overriding-restriction nil)
1773 (defun org-agenda (&optional arg keys restriction)
1774 "Dispatch agenda commands to collect entries to the agenda buffer.
1775 Prompts for a command to execute. Any prefix arg will be passed
1776 on to the selected command. The default selections are:
1778 a Call `org-agenda-list' to display the agenda for current day or week.
1779 t Call `org-todo-list' to display the global todo list.
1780 T Call `org-todo-list' to display the global todo list, select only
1781 entries with a specific TODO keyword (the user gets a prompt).
1782 m Call `org-tags-view' to display headlines with tags matching
1783 a condition (the user is prompted for the condition).
1784 M Like `m', but select only TODO entries, no ordinary headlines.
1785 L Create a timeline for the current buffer.
1786 e Export views to associated files.
1787 s Search entries for keywords.
1788 / Multi occur across all agenda files and also files listed
1789 in `org-agenda-text-search-extra-files'.
1790 < Restrict agenda commands to buffer, subtree, or region.
1791 Press several times to get the desired effect.
1792 > Remove a previous restriction.
1793 # List \"stuck\" projects.
1794 ! Configure what \"stuck\" means.
1795 C Configure custom agenda commands.
1797 More commands can be added by configuring the variable
1798 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1799 searches can be pre-defined in this way.
1801 If the current buffer is in Org-mode and visiting a file, you can also
1802 first press `<' once to indicate that the agenda should be temporarily
1803 \(until the next use of \\[org-agenda]) restricted to the current file.
1804 Pressing `<' twice means to restrict to the current subtree or region
1808 (let* ((prefix-descriptions nil)
1809 (org-agenda-window-setup (if (equal (buffer-name)
1810 org-agenda-buffer-name)
1812 org-agenda-window-setup))
1813 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1814 (org-agenda-custom-commands
1815 ;; normalize different versions
1819 (cond ((stringp (cdr x))
1820 (push x prefix-descriptions)
1822 ((stringp (nth 1 x)) x)
1823 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1824 (t (cons (car x) (cons "" (cdr x))))))
1825 org-agenda-custom-commands)))
1826 (buf (current-buffer))
1827 (bfn (buffer-file-name (buffer-base-buffer)))
1828 entry key type match lprops ans)
1829 ;; Turn off restriction unless there is an overriding one,
1830 (unless org-agenda-overriding-restriction
1831 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
1832 ;; There is a request to keep the file list in place
1833 (put 'org-agenda-files 'org-restrict nil))
1834 (setq org-agenda-restrict nil)
1835 (move-marker org-agenda-restrict-begin nil)
1836 (move-marker org-agenda-restrict-end nil))
1837 ;; Delete old local properties
1838 (put 'org-agenda-redo-command 'org-lprops nil)
1839 ;; Remember where this call originated
1840 (setq org-agenda-last-dispatch-buffer (current-buffer))
1842 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1844 restriction (cdr ans)))
1845 ;; Establish the restriction, if any
1846 (when (and (not org-agenda-overriding-restriction) restriction)
1847 (put 'org-agenda-files 'org-restrict (list bfn))
1849 ((eq restriction 'region)
1850 (setq org-agenda-restrict t)
1851 (move-marker org-agenda-restrict-begin (region-beginning))
1852 (move-marker org-agenda-restrict-end (region-end)))
1853 ((eq restriction 'subtree)
1855 (setq org-agenda-restrict t)
1856 (org-back-to-heading t)
1857 (move-marker org-agenda-restrict-begin (point))
1858 (move-marker org-agenda-restrict-end
1859 (progn (org-end-of-subtree t)))))))
1861 (require 'calendar) ; FIXME: can we avoid this for some commands?
1862 ;; For example the todo list should not need it (but does...)
1864 ((setq entry (assoc keys org-agenda-custom-commands))
1865 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
1867 (setq type (nth 2 entry) match (eval (nth 3 entry))
1868 lprops (nth 4 entry))
1869 (put 'org-agenda-redo-command 'org-lprops lprops)
1872 (org-let lprops '(org-agenda-list current-prefix-arg)))
1874 (org-let lprops '(org-todo-list current-prefix-arg)))
1876 (org-let lprops '(org-search-view current-prefix-arg match nil)))
1878 (org-let lprops '(org-agenda-list-stuck-projects
1879 current-prefix-arg)))
1881 (org-let lprops '(org-tags-view current-prefix-arg match)))
1882 ((eq type 'tags-todo)
1883 (org-let lprops '(org-tags-view '(4) match)))
1885 (org-let lprops '(org-todo-list match)))
1886 ((eq type 'tags-tree)
1887 (org-check-for-org-mode)
1888 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
1889 ((eq type 'todo-tree)
1890 (org-check-for-org-mode)
1892 '(org-occur (concat "^" outline-regexp "[ \t]*"
1893 (regexp-quote match) "\\>"))))
1894 ((eq type 'occur-tree)
1895 (org-check-for-org-mode)
1896 (org-let lprops '(org-occur match)))
1898 (org-let lprops '(funcall type match)))
1900 (org-let lprops '(funcall type match)))
1901 (t (error "Invalid custom agenda command type %s" type))))
1902 (org-run-agenda-series (nth 1 entry) (cddr entry))))
1904 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
1905 (customize-variable 'org-agenda-custom-commands))
1906 ((equal keys "a") (call-interactively 'org-agenda-list))
1907 ((equal keys "s") (call-interactively 'org-search-view))
1908 ((equal keys "t") (call-interactively 'org-todo-list))
1909 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
1910 ((equal keys "m") (call-interactively 'org-tags-view))
1911 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
1912 ((equal keys "e") (call-interactively 'org-store-agenda-views))
1913 ((equal keys "?") (org-tags-view nil "+FLAGGED")
1917 (unless (current-message)
1918 (let* ((m (org-agenda-get-any-marker))
1919 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
1922 "FLAGGING-NOTE ([?] for more info): "
1924 (replace-regexp-in-string
1926 (copy-sequence note))
1927 nil 'face 'org-warning)))))))
1930 (unless (org-mode-p)
1931 (error "This is not an Org-mode file"))
1933 (put 'org-agenda-files 'org-restrict (list bfn))
1934 (org-call-with-arg 'org-timeline arg)))
1935 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
1936 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
1937 ((equal keys "!") (customize-variable 'org-stuck-projects))
1938 (t (error "Invalid agenda key"))))))
1940 (defun org-agenda-normalize-custom-commands (cmds)
1944 (cond ((stringp (cdr x)) nil)
1945 ((stringp (nth 1 x)) x)
1946 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1947 (t (cons (car x) (cons "" (cdr x))))))
1950 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1951 "The user interface for selecting an agenda command."
1953 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1954 (restrict-ok (and bfn (org-mode-p)))
1955 (region-p (org-region-active-p))
1956 (custom org-agenda-custom-commands)
1958 restriction second-time
1959 c entry key type match prefixes rmheader header-end custom1 desc)
1960 (save-window-excursion
1961 (delete-other-windows)
1962 (org-switch-to-buffer-other-window " *Agenda Commands*")
1964 (insert (eval-when-compile
1967 Press key for an agenda command: < Buffer, subtree/region restriction
1968 -------------------------------- > Remove restriction
1969 a Agenda for current week or day e Export agenda views
1970 t List of all TODO entries T Entries with special TODO kwd
1971 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1972 L Timeline for current buffer # List stuck projects (!=configure)
1973 s Search for keywords C Configure custom agenda commands
1974 / Multi-occur ? Find :FLAGGED: entries
1977 (while (string-match
1978 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1980 (setq start (match-end 0))
1981 (add-text-properties (match-beginning 2) (match-end 2)
1982 '(face bold) header))
1984 (setq header-end (move-marker (make-marker) (point)))
1986 (setq custom1 custom)
1987 (when (eq rmheader t)
1989 (re-search-forward ":" nil t)
1990 (delete-region (match-end 0) (point-at-eol))
1993 (delete-region (match-end 0) (point-at-eol))
1994 (move-marker header-end (match-end 0)))
1995 (goto-char header-end)
1996 (delete-region (point) (point-max))
1997 (while (setq entry (pop custom1))
1998 (setq key (car entry) desc (nth 1 entry)
2000 match (nth 3 entry))
2001 (if (> (length key) 1)
2002 (add-to-list 'prefixes (string-to-char key))
2006 (org-add-props (copy-sequence key)
2009 ((string-match "\\S-" desc) desc)
2010 ((eq type 'agenda) "Agenda for current week or day")
2011 ((eq type 'alltodo) "List of all TODO entries")
2012 ((eq type 'search) "Word search")
2013 ((eq type 'stuck) "List of stuck projects")
2014 ((eq type 'todo) "TODO keyword")
2015 ((eq type 'tags) "Tags query")
2016 ((eq type 'tags-todo) "Tags (TODO)")
2017 ((eq type 'tags-tree) "Tags tree")
2018 ((eq type 'todo-tree) "TODO kwd tree")
2019 ((eq type 'occur-tree) "Occur tree")
2020 ((functionp type) (if (symbolp type)
2022 "Lambda expression"))
2026 (setq match (copy-sequence match))
2027 (org-add-props match nil 'face 'org-warning))
2029 (format "set of %d commands" (length match)))
2035 (org-add-props (char-to-string x)
2037 (or (cdr (assoc (concat selstring (char-to-string x))
2038 prefix-descriptions))
2041 (goto-char (point-min))
2043 (if (not (pos-visible-in-window-p (point-max)))
2044 (org-fit-window-to-buffer))
2045 (setq second-time t)
2046 (org-fit-window-to-buffer))
2047 (message "Press key for agenda command%s:"
2048 (if (or restrict-ok org-agenda-overriding-restriction)
2049 (if org-agenda-overriding-restriction
2050 " (restriction lock active)"
2052 (format " (restricted to %s)" restriction)
2055 (setq c (read-char-exclusive))
2058 ((assoc (char-to-string c) custom)
2059 (setq selstring (concat selstring (char-to-string c)))
2060 (throw 'exit (cons selstring restriction)))
2062 (setq selstring (concat selstring (char-to-string c))
2064 rmheader (or rmheader t)
2065 custom (delq nil (mapcar
2067 (if (or (= (length (car x)) 1)
2068 (/= (string-to-char (car x)) c))
2070 (cons (substring (car x) 1) (cdr x))))
2072 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2073 (message "Restriction is only possible in Org-mode buffers")
2076 (org-agenda-remove-restriction-lock 'noupdate)
2077 (setq restriction 'buffer))
2079 (org-agenda-remove-restriction-lock 'noupdate)
2080 (setq restriction (if region-p 'region 'subtree)))
2082 (org-agenda-remove-restriction-lock 'noupdate)
2085 ((eq restriction 'buffer)
2086 (if region-p 'region 'subtree))
2087 ((memq restriction '(subtree region))
2091 (org-agenda-remove-restriction-lock 'noupdate)
2092 (setq restriction nil))
2093 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2094 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2095 ((and (> (length selstring) 0) (eq c ?\d))
2097 (org-agenda-get-restriction-and-command prefix-descriptions))
2099 ((equal c ?q) (error "Abort"))
2100 (t (error "Invalid key %c" c))))))))
2102 (defun org-run-agenda-series (name series)
2103 (org-let (nth 1 series) '(org-prepare-agenda name))
2104 (let* ((org-agenda-multi t)
2105 (redo (list 'org-run-agenda-series name (list 'quote series)))
2107 (gprops (nth 1 series))
2108 match ;; The byte compiler incorrectly complains about this. Keep it!
2110 (while (setq cmd (pop cmds))
2111 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2114 (org-let2 gprops lprops
2115 '(call-interactively 'org-agenda-list)))
2117 (org-let2 gprops lprops
2118 '(call-interactively 'org-todo-list)))
2120 (org-let2 gprops lprops
2121 '(org-search-view current-prefix-arg match nil)))
2123 (org-let2 gprops lprops
2124 '(call-interactively 'org-agenda-list-stuck-projects)))
2126 (org-let2 gprops lprops
2127 '(org-tags-view current-prefix-arg match)))
2128 ((eq type 'tags-todo)
2129 (org-let2 gprops lprops
2130 '(org-tags-view '(4) match)))
2132 (org-let2 gprops lprops
2133 '(org-todo-list match)))
2135 (org-let2 gprops lprops
2136 '(funcall type match)))
2137 (t (error "Invalid type in command series"))))
2139 (setq org-agenda-redo-command redo)
2140 (goto-char (point-min)))
2141 (org-fit-agenda-window)
2142 (org-let (nth 1 series) '(org-finalize-agenda)))
2145 (defmacro org-batch-agenda (cmd-key &rest parameters)
2146 "Run an agenda command in batch mode and send the result to STDOUT.
2147 If CMD-KEY is a string of length 1, it is used as a key in
2148 `org-agenda-custom-commands' and triggers this command. If it is a
2149 longer string it is used as a tags/todo match string.
2150 Paramters are alternating variable names and values that will be bound
2151 before running the agenda command."
2154 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2155 (if (> (length cmd-key) 2)
2156 (eval (list 'let (nreverse pars)
2157 (list 'org-tags-view nil cmd-key)))
2158 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2159 (set-buffer org-agenda-buffer-name)
2160 (princ (org-encode-for-stdout (buffer-string)))))
2162 ;(defun org-encode-for-stdout (string)
2163 ; (if (fboundp 'encode-coding-string)
2164 ; (encode-coding-string string buffer-file-coding-system)
2167 (defun org-encode-for-stdout (string)
2170 (defvar org-agenda-info nil)
2173 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2174 "Run an agenda command in batch mode and send the result to STDOUT.
2175 If CMD-KEY is a string of length 1, it is used as a key in
2176 `org-agenda-custom-commands' and triggers this command. If it is a
2177 longer string it is used as a tags/todo match string.
2178 Paramters are alternating variable names and values that will be bound
2179 before running the agenda command.
2181 The output gives a line for each selected agenda item. Each
2182 item is a list of comma-separated values, like this:
2184 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2186 category The category of the item
2187 head The headline, without TODO kwd, TAGS and PRIORITY
2188 type The type of the agenda entry, can be
2189 todo selected in TODO match
2190 tagsmatch selected in tags match
2191 diary imported from diary
2192 deadline a deadline on given date
2193 scheduled scheduled on given date
2194 timestamp entry has timestamp on given date
2195 closed entry was closed on given date
2196 upcoming-deadline warning about deadline
2197 past-scheduled forwarded scheduled item
2198 block entry has date block including g. date
2199 todo The todo keyword, if any
2200 tags All tags including inherited ones, separated by colons
2201 date The relevant date, like 2007-2-14
2202 time The time, like 15:00-16:50
2203 extra Sting with extra planning info
2204 priority-l The priority letter if any was given
2205 priority-n The computed numerical priority
2206 agenda-day The day in the agenda where this is listed"
2210 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2211 (push (list 'org-agenda-remove-tags t) pars)
2212 (if (> (length cmd-key) 2)
2213 (eval (list 'let (nreverse pars)
2214 (list 'org-tags-view nil cmd-key)))
2215 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2216 (set-buffer org-agenda-buffer-name)
2217 (let* ((lines (org-split-string (buffer-string) "\n"))
2219 (while (setq line (pop lines))
2221 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2222 (setq org-agenda-info
2223 (org-fix-agenda-info (text-properties-at 0 line)))
2225 (org-encode-for-stdout
2226 (mapconcat 'org-agenda-export-csv-mapper
2227 '(org-category txt type todo tags date time-of-day extra
2228 priority-letter priority agenda-day)
2232 (defun org-fix-agenda-info (props)
2233 "Make sure all properties on an agenda item have a canonical form,
2234 so the export commands can easily use it."
2236 (when (setq tmp (plist-get props 'tags))
2237 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2238 (when (setq tmp (plist-get props 'date))
2239 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2240 (let ((calendar-date-display-form '(year "-" month "-" day)))
2241 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2243 (setq tmp (calendar-date-string tmp)))
2244 (setq props (plist-put props 'date tmp)))
2245 (when (setq tmp (plist-get props 'day))
2246 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2247 (let ((calendar-date-display-form '(year "-" month "-" day)))
2248 (setq tmp (calendar-date-string tmp)))
2249 (setq props (plist-put props 'day tmp))
2250 (setq props (plist-put props 'agenda-day tmp)))
2251 (when (setq tmp (plist-get props 'txt))
2252 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2253 (plist-put props 'priority-letter (match-string 1 tmp))
2254 (setq tmp (replace-match "" t t tmp)))
2255 (when (and (setq re (plist-get props 'org-todo-regexp))
2256 (setq re (concat "\\`\\.*" re " ?"))
2257 (string-match re tmp))
2258 (plist-put props 'todo (match-string 1 tmp))
2259 (setq tmp (replace-match "" t t tmp)))
2260 (plist-put props 'txt tmp)))
2263 (defun org-agenda-export-csv-mapper (prop)
2264 (let ((res (plist-get org-agenda-info prop)))
2269 (t (prin1-to-string res))))
2270 (while (string-match "," res)
2271 (setq res (replace-match ";" t t res)))
2276 (defun org-store-agenda-views (&rest parameters)
2278 (eval (list 'org-batch-store-agenda-views)))
2280 ;; FIXME, why is this a macro?????
2282 (defmacro org-batch-store-agenda-views (&rest parameters)
2283 "Run all custom agenda commands that have a file argument."
2284 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2286 (dir default-directory)
2287 pars cmd thiscmdkey files opts cmd-or-set)
2289 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2290 (setq pars (reverse pars))
2291 (save-window-excursion
2293 (setq cmd (pop cmds)
2294 thiscmdkey (car cmd)
2295 cmd-or-set (nth 2 cmd)
2296 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2297 files (nth (if (listp cmd-or-set) 4 5) cmd))
2298 (if (stringp files) (setq files (list files)))
2300 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2301 (list 'org-agenda nil thiscmdkey)))
2302 (set-buffer org-agenda-buffer-name)
2304 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2305 (list 'org-write-agenda
2306 (expand-file-name (pop files) dir) nil t))))
2307 (and (get-buffer org-agenda-buffer-name)
2308 (kill-buffer org-agenda-buffer-name)))))))
2310 (defun org-agenda-mark-header-line (pos)
2311 "Mark the line at POS as an agenda structure header."
2314 (put-text-property (point-at-bol) (point-at-eol)
2315 'org-agenda-structural-header t)
2316 (when org-agenda-title-append
2317 (put-text-property (point-at-bol) (point-at-eol)
2318 'org-agenda-title-append org-agenda-title-append))))
2320 (defvar org-mobile-creating-agendas)
2321 (defun org-write-agenda (file &optional open nosettings)
2322 "Write the current buffer (an agenda view) as a file.
2323 Depending on the extension of the file name, plain text (.txt),
2324 HTML (.html or .htm) or Postscript (.ps) is produced.
2325 If the extension is .ics, run icalendar export over all files used
2326 to construct the agenda and limit the export to entries listed in the
2328 With prefix argument OPEN, open the new file immediately.
2329 If NOSETTINGS is given, do not scope the settings of
2330 `org-agenda-exporter-settings' into the export commands. This is used when
2331 the settings have already been scoped and we do not wish to overrule other,
2332 higher priority settings."
2333 (interactive "FWrite agenda to file: \nP")
2334 (if (not (file-writable-p file))
2335 (error "Cannot write agenda to file %s" file))
2337 ((string-match "\\.html?\\'" file) (require 'htmlize))
2338 ((string-match "\\.ps\\'" file) (require 'ps-print)))
2339 (org-let (if nosettings nil org-agenda-exporter-settings)
2341 (save-window-excursion
2342 (org-agenda-mark-filtered-text)
2343 (let ((bs (copy-sequence (buffer-string))) beg)
2344 (org-agenda-unmark-filtered-text)
2347 (org-agenda-remove-marked-text 'org-filtered)
2348 (while (setq beg (text-property-any (point-min) (point-max)
2351 beg (or (next-single-property-change beg 'org-filtered)
2353 (run-hooks 'org-agenda-before-write-hook)
2355 ((org-bound-and-true-p org-mobile-creating-agendas)
2356 (org-mobile-write-agenda-for-mobile file))
2357 ((string-match "\\.html?\\'" file)
2358 (set-buffer (htmlize-buffer (current-buffer)))
2360 (when (and org-agenda-export-html-style
2361 (string-match "<style>" org-agenda-export-html-style))
2362 ;; replace <style> section with org-agenda-export-html-style
2363 (goto-char (point-min))
2364 (kill-region (- (search-forward "<style") 6)
2365 (search-forward "</style>"))
2366 (insert org-agenda-export-html-style))
2368 (kill-buffer (current-buffer))
2369 (message "HTML written to %s" file))
2370 ((string-match "\\.ps\\'" file)
2372 (flet ((ps-get-buffer-name () "Agenda View"))
2373 (ps-print-buffer-with-faces file))
2374 (message "Postscript written to %s" file))
2375 ((string-match "\\.pdf\\'" file)
2377 (flet ((ps-get-buffer-name () "Agenda View"))
2378 (ps-print-buffer-with-faces
2379 (concat (file-name-sans-extension file) ".ps")))
2380 (call-process "ps2pdf" nil nil nil
2382 (concat (file-name-sans-extension file) ".ps"))
2383 (expand-file-name file))
2384 (message "PDF written to %s" file))
2385 ((string-match "\\.ics\\'" file)
2386 (require 'org-icalendar)
2387 (let ((org-agenda-marker-table
2388 (org-create-marker-find-array
2389 (org-agenda-collect-markers)))
2390 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2391 (org-combined-agenda-icalendar-file file))
2392 (apply 'org-export-icalendar 'combine
2393 (org-agenda-files nil 'ifmode))))
2395 (let ((bs (buffer-string)))
2400 (kill-buffer (current-buffer))
2401 (message "Plain text written to %s" file))))))))
2402 (set-buffer org-agenda-buffer-name))
2403 (when open (org-open-file file)))
2405 (defvar org-agenda-filter-overlays nil)
2407 (defun org-agenda-mark-filtered-text ()
2408 "Mark all text hidden by filtering with a text property."
2409 (let ((inhibit-read-only t))
2412 (when (equal (org-overlay-buffer o) (current-buffer))
2414 (org-overlay-start o) (org-overlay-end o)
2416 org-agenda-filter-overlays)))
2418 (defun org-agenda-unmark-filtered-text ()
2419 "Remove the filtering text property."
2420 (let ((inhibit-read-only t))
2421 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2423 (defun org-agenda-remove-marked-text (property &optional value)
2424 "Delete all text marked with VALUE of PROPERTY.
2425 VALUE defaults to t."
2427 (setq value (or value t))
2428 (while (setq beg (text-property-any (point-min) (point-max)
2431 beg (or (next-single-property-change beg 'org-filtered)
2434 (defun org-agenda-add-entry-text ()
2435 "Add entry text to agenda lines.
2436 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2437 entry text following headings shown in the agenda.
2438 Drawers will be excluded, also the line with scheduling/deadline info."
2439 (when (and (> org-agenda-add-entry-text-maxlines 0)
2440 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2442 (goto-char (point-min))
2444 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2445 (beginning-of-line 2)
2446 (setq txt (org-agenda-get-some-entry-text
2447 m org-agenda-add-entry-text-maxlines " > "))
2449 (if (string-match "\\S-" txt) (insert "\n" txt)))))))
2451 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2453 "Extract entry text from MARKER, at most N-LINES lines.
2454 This will ignore drawers etc, just get the text.
2455 If INDENT is given, prefix every line with this string. If KEEP is
2456 given, it is a list of symbols, defining stuff that should not be
2457 removed from the entry content. Currently only `planning' is allowed here."
2458 (let (txt drawer-re kwd-time-re ind)
2460 (with-current-buffer (marker-buffer marker)
2461 (if (not (org-mode-p))
2468 (setq txt (buffer-substring
2469 (min (1+ (point)) (point-max))
2470 (progn (outline-next-heading) (point)))
2471 drawer-re org-drawer-regexp
2472 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2476 (when org-agenda-add-entry-text-descriptive-links
2477 (goto-char (point-min))
2478 (while (org-activate-bracket-links (point-max))
2479 (add-text-properties (match-beginning 0) (match-end 0)
2481 (goto-char (point-min))
2482 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2483 (set-text-properties (match-beginning 0) (match-end 0)
2485 (goto-char (point-min))
2486 (while (re-search-forward drawer-re nil t)
2489 (progn (re-search-forward
2490 "^[ \t]*:END:.*\n?" nil 'move)
2492 (unless (member 'planning keep)
2493 (goto-char (point-min))
2494 (while (re-search-forward kwd-time-re nil t)
2495 (replace-match "")))
2496 (goto-char (point-min))
2497 (when org-agenda-entry-text-exclude-regexps
2498 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2499 (while (setq re (pop re-list))
2500 (goto-char (point-min))
2501 (while (re-search-forward re nil t)
2502 (replace-match "")))))
2503 (goto-char (point-max))
2504 (skip-chars-backward " \t\n")
2505 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2507 ;; find and remove min common indentation
2508 (goto-char (point-min))
2509 (untabify (point-min) (point-max))
2510 (setq ind (org-get-indentation))
2512 (unless (looking-at "[ \t]*$")
2513 (setq ind (min ind (org-get-indentation))))
2514 (beginning-of-line 2))
2515 (goto-char (point-min))
2517 (unless (looking-at "[ \t]*$")
2518 (move-to-column ind)
2519 (delete-region (point-at-bol) (point)))
2520 (beginning-of-line 2))
2522 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2524 (goto-char (point-min))
2526 (while (and (not (eobp)) (re-search-forward "^" nil t))
2527 (replace-match indent t t)))
2528 (goto-char (point-min))
2529 (while (looking-at "[ \t]*\n") (replace-match ""))
2530 (goto-char (point-max))
2531 (when (> (org-current-line)
2533 (org-goto-line (1+ n-lines))
2535 (setq txt (buffer-substring (point-min) (point)))))))))
2538 (defun org-agenda-collect-markers ()
2539 "Collect the markers pointing to entries in the agenda buffer."
2542 (goto-char (point-min))
2544 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2545 (org-get-at-bol 'org-marker)))
2547 (beginning-of-line 2)))
2548 (nreverse markers)))
2550 (defun org-create-marker-find-array (marker-list)
2551 "Create a alist of files names with all marker positions in that file."
2553 (while (setq m (pop marker-list))
2554 (setq p (marker-position m)
2555 f (buffer-file-name (or (buffer-base-buffer
2557 (marker-buffer m))))
2558 (if (setq a (assoc f tbl))
2559 (push (marker-position m) (cdr a))
2560 (push (list f p) tbl)))
2561 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2564 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2565 (defun org-check-agenda-marker-table ()
2566 "Check of the current entry is on the marker list."
2567 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2569 (and (setq a (assoc file org-agenda-marker-table))
2572 (org-back-to-heading t)
2573 (member (point) (cdr a)))))))
2575 (defun org-check-for-org-mode ()
2576 "Make sure current buffer is in org-mode. Error if not."
2578 (error "Cannot execute org-mode agenda command on buffer in %s"
2581 (defun org-fit-agenda-window ()
2582 "Fit the window to the buffer size."
2583 (and (memq org-agenda-window-setup '(reorganize-frame))
2584 (fboundp 'fit-window-to-buffer)
2585 (org-fit-window-to-buffer
2587 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2588 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2590 ;;; Agenda prepare and finalize
2592 (defvar org-agenda-multi nil) ; dynamically scoped
2593 (defvar org-agenda-buffer-name "*Org Agenda*")
2594 (defvar org-pre-agenda-window-conf nil)
2595 (defvar org-agenda-columns-active nil)
2596 (defvar org-agenda-name nil)
2597 (defvar org-agenda-filter nil)
2598 (defvar org-agenda-filter-preset nil
2599 "A preset of the tags filter used for secondary agenda filtering.
2600 This must be a list of strings, each string must be a single tag preceeded
2602 This variable should not be set directly, but agenda custom commands can
2603 bind it in the options section.")
2605 (defun org-prepare-agenda (&optional name)
2606 (setq org-todo-keywords-for-agenda nil)
2607 (setq org-done-keywords-for-agenda nil)
2608 (setq org-drawers-for-agenda nil)
2609 (setq org-agenda-filter nil)
2610 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2611 (if org-agenda-multi
2613 (setq buffer-read-only nil)
2614 (goto-char (point-max))
2615 (unless (or (bobp) org-agenda-compact-blocks)
2617 (if (stringp org-agenda-block-separator)
2618 org-agenda-block-separator
2619 (make-string (window-width) org-agenda-block-separator))
2621 (narrow-to-region (point) (point-max)))
2622 (org-agenda-reset-markers)
2623 (setq org-agenda-contributing-files nil)
2624 (setq org-agenda-columns-active nil)
2625 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2626 (setq org-todo-keywords-for-agenda
2627 (org-uniquify org-todo-keywords-for-agenda))
2628 (setq org-done-keywords-for-agenda
2629 (org-uniquify org-done-keywords-for-agenda))
2630 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2631 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2632 (awin (get-buffer-window abuf)))
2634 ((equal (current-buffer) abuf) nil)
2635 (awin (select-window awin))
2636 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2637 ((equal org-agenda-window-setup 'current-window)
2638 (switch-to-buffer abuf))
2639 ((equal org-agenda-window-setup 'other-window)
2640 (org-switch-to-buffer-other-window abuf))
2641 ((equal org-agenda-window-setup 'other-frame)
2642 (switch-to-buffer-other-frame abuf))
2643 ((equal org-agenda-window-setup 'reorganize-frame)
2644 (delete-other-windows)
2645 (org-switch-to-buffer-other-window abuf))))
2646 (setq buffer-read-only nil)
2647 (let ((inhibit-read-only t)) (erase-buffer))
2649 (and name (not org-agenda-name)
2650 (org-set-local 'org-agenda-name name)))
2651 (setq buffer-read-only nil))
2653 (defun org-finalize-agenda ()
2654 "Finishing touch for the agenda buffer, called just before displaying it."
2655 (unless org-agenda-multi
2657 (let ((inhibit-read-only t))
2658 (goto-char (point-min))
2659 (while (org-activate-bracket-links (point-max))
2660 (add-text-properties (match-beginning 0) (match-end 0)
2662 (org-agenda-align-tags)
2663 (unless org-agenda-with-colors
2664 (remove-text-properties (point-min) (point-max) '(face nil))))
2665 (if (and (boundp 'org-agenda-overriding-columns-format)
2666 org-agenda-overriding-columns-format)
2667 (org-set-local 'org-agenda-overriding-columns-format
2668 org-agenda-overriding-columns-format))
2669 (if (and (boundp 'org-agenda-view-columns-initially)
2670 org-agenda-view-columns-initially)
2671 (org-agenda-columns))
2672 (when org-agenda-fontify-priorities
2673 (org-agenda-fontify-priorities))
2674 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2675 (org-agenda-dim-blocked-tasks))
2676 (org-agenda-mark-clocking-task)
2677 (when org-agenda-entry-text-mode
2678 (org-agenda-entry-text-hide)
2679 (org-agenda-entry-text-show))
2680 (if (functionp 'org-habit-insert-consistency-graphs)
2681 (org-habit-insert-consistency-graphs))
2682 (run-hooks 'org-finalize-agenda-hook)
2683 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2684 (when (get 'org-agenda-filter :preset-filter)
2685 (org-agenda-filter-apply org-agenda-filter))
2688 (defun org-agenda-mark-clocking-task ()
2689 "Mark the current clock entry in the agenda if it is present."
2691 (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
2692 (org-delete-overlay o)))
2693 (org-overlays-in (point-min) (point-max)))
2694 (when (marker-buffer org-clock-hd-marker)
2696 (goto-char (point-min))
2698 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2700 (when (equal (org-get-at-bol 'org-hd-marker)
2701 org-clock-hd-marker)
2702 (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
2703 (org-overlay-put ov 'type 'org-agenda-clocking)
2704 (org-overlay-put ov 'face 'org-agenda-clocking)
2705 (org-overlay-put ov 'help-echo
2706 "The clock is running in this item")))))))
2708 (defun org-agenda-fontify-priorities ()
2709 "Make highest priority lines bold, and lowest italic."
2711 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
2712 (org-delete-overlay o)))
2713 (org-overlays-in (point-min) (point-max)))
2715 (let ((inhibit-read-only t)
2717 (goto-char (point-min))
2718 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2719 (setq h (or (get-char-property (point) 'org-highest-priority)
2720 org-highest-priority)
2721 l (or (get-char-property (point) 'org-lowest-priority)
2722 org-lowest-priority)
2723 p (string-to-char (match-string 1))
2724 b (match-beginning 0)
2725 e (if (eq org-agenda-fontify-priorities 'cookies)
2728 ov (org-make-overlay b e))
2731 (cond ((cdr (assoc p org-priority-faces)))
2732 ((and (listp org-agenda-fontify-priorities)
2733 (cdr (assoc p org-agenda-fontify-priorities))))
2734 ((equal p l) 'italic)
2735 ((equal p h) 'bold)))
2736 (org-overlay-put ov 'org-type 'org-priority)))))
2738 (defun org-agenda-dim-blocked-tasks ()
2739 "Dim currently blocked TODO's in the agenda display."
2740 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
2741 (org-delete-overlay o)))
2742 (org-overlays-in (point-min) (point-max)))
2744 (let ((inhibit-read-only t)
2745 (org-depend-tag-blocked nil)
2746 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2747 org-blocked-by-checkboxes
2748 invis1 b e p ov h l)
2749 (goto-char (point-min))
2750 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2751 (and pos (goto-char (1+ pos))))
2752 (setq org-blocked-by-checkboxes nil invis1 invis)
2753 (let ((marker (org-get-at-bol 'org-hd-marker)))
2755 (not (with-current-buffer (marker-buffer marker)
2758 (if (org-entry-get nil "NOBLOCKING")
2759 t ;; Never block this entry
2760 (run-hook-with-args-until-failure
2762 (list :type 'todo-state-change
2766 (if org-blocked-by-checkboxes (setq invis1 nil))
2768 (max (point-min) (1- (point-at-bol)))
2771 ov (org-make-overlay b e))
2773 (org-overlay-put ov 'invisible t)
2774 (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2775 (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
2777 (defvar org-agenda-skip-function nil
2778 "Function to be called at each match during agenda construction.
2779 If this function returns nil, the current match should not be skipped.
2780 Otherwise, the function must return a position from where the search
2781 should be continued.
2782 This may also be a Lisp form, it will be evaluated.
2783 Never set this variable using `setq' or so, because then it will apply
2784 to all future agenda commands. Instead, bind it with `let' to scope
2785 it dynamically into the agenda-constructing command. A good way to set
2786 it is through options in org-agenda-custom-commands.")
2788 (defun org-agenda-skip ()
2789 "Throw to `:skip' in places that should be skipped.
2790 Also moves point to the end of the skipped region, so that search can
2791 continue from there."
2792 (let ((p (point-at-bol)) to fp)
2793 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2794 (get-text-property p :org-archived)
2795 (org-end-of-subtree t)
2797 (and org-agenda-skip-comment-trees
2798 (get-text-property p :org-comment)
2799 (org-end-of-subtree t)
2801 (if (equal (char-after p) ?#) (throw :skip t))
2802 (when (and (or (setq fp (functionp org-agenda-skip-function))
2803 (consp org-agenda-skip-function))
2804 (setq to (save-excursion
2807 (funcall org-agenda-skip-function)
2808 (eval org-agenda-skip-function))))))
2812 (defvar org-agenda-markers nil
2813 "List of all currently active markers created by `org-agenda'.")
2814 (defvar org-agenda-last-marker-time (org-float-time)
2815 "Creation time of the last agenda marker.")
2817 (defun org-agenda-new-marker (&optional pos)
2818 "Return a new agenda marker.
2819 Org-mode keeps a list of these markers and resets them when they are
2821 (let ((m (copy-marker (or pos (point)))))
2822 (setq org-agenda-last-marker-time (org-float-time))
2823 (push m org-agenda-markers)
2826 (defun org-agenda-reset-markers ()
2827 "Reset markers created by `org-agenda'."
2828 (while org-agenda-markers
2829 (move-marker (pop org-agenda-markers) nil)))
2831 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
2832 "Save relative positions of markers in region."
2833 (mapc (lambda (m) (org-check-and-save-marker m beg end))
2834 org-agenda-markers))
2838 (defun org-agenda-entry-text-show-here ()
2839 "Add some text from the entry as context to the current line."
2841 (setq m (org-get-at-bol 'org-hd-marker))
2842 (unless (marker-buffer m)
2843 (error "No marker points to an entry here"))
2844 (setq txt (concat "\n" (org-no-properties
2845 (org-agenda-get-some-entry-text
2846 m org-agenda-entry-text-maxlines " > "))))
2847 (when (string-match "\\S-" txt)
2848 (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
2849 (org-overlay-put o 'evaporate t)
2850 (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
2851 (org-overlay-put o 'after-string txt))))
2853 (defun org-agenda-entry-text-show ()
2854 "Add entry context for all agenda lines."
2857 (goto-char (point-max))
2858 (beginning-of-line 1)
2860 (when (org-get-at-bol 'org-hd-marker)
2861 (org-agenda-entry-text-show-here))
2862 (beginning-of-line 0))))
2864 (defun org-agenda-entry-text-hide ()
2865 "Remove any shown entry context."
2868 (if (eq (org-overlay-get o 'org-overlay-type)
2869 'agenda-entry-content)
2870 (progn (org-delete-overlay o) t)))
2871 (org-overlays-in (point-min) (point-max)))))
2875 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
2877 (defun org-timeline (&optional include-all)
2878 "Show a time-sorted view of the entries in the current org file.
2879 Only entries with a time stamp of today or later will be listed. With
2880 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2881 under the current date.
2882 If the buffer contains an active region, only check the region for
2886 (org-compile-prefix-format 'timeline)
2887 (org-set-sorting-strategy 'timeline)
2889 (dotodo include-all)
2890 (doclosed org-agenda-show-log)
2891 (entry buffer-file-name)
2892 (date (calendar-current-date))
2893 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2894 (end (if (org-region-active-p) (region-end) (point-max)))
2895 (day-numbers (org-get-all-dates beg end 'no-ranges
2896 t doclosed ; always include today
2897 org-timeline-show-empty-dates))
2898 (org-deadline-warning-days 0)
2899 (org-agenda-only-exact-dates t)
2900 (today (time-to-days (current-time)))
2903 s e rtn d emptyp wd)
2904 (setq org-agenda-redo-command
2906 (list 'org-switch-to-buffer-other-window (current-buffer))
2907 (list 'org-timeline (list 'quote include-all))))
2909 ;; Remove past dates from the list of dates.
2910 (setq day-numbers (delq nil (mapcar (lambda(x)
2911 (if (>= x today) x nil))
2913 (org-prepare-agenda (concat "Timeline "
2914 (file-name-nondirectory buffer-file-name)))
2915 (if doclosed (push :closed args))
2916 (push :timestamp args)
2917 (push :deadline args)
2918 (push :scheduled args)
2920 (if dotodo (push :todo args))
2921 (insert "Timeline of file " entry "\n")
2922 (add-text-properties (point-min) (point)
2923 (list 'face 'org-agenda-structure))
2924 (org-agenda-mark-header-line (point-min))
2925 (while (setq d (pop day-numbers))
2926 (if (and (listp d) (eq (car d) :omitted))
2929 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
2930 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
2931 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
2932 (if (and (>= d today)
2937 (insert (make-string 79 ?-) "\n")))
2938 (setq date (calendar-gregorian-from-absolute d)
2939 wd (calendar-day-of-week date))
2941 (setq rtn (and (not emptyp)
2942 (apply 'org-agenda-get-day-entries entry
2944 (if (or rtn (equal d today) org-timeline-show-empty-dates)
2947 (if (stringp org-agenda-format-date)
2948 (format-time-string org-agenda-format-date
2949 (org-time-from-absolute date))
2950 (funcall org-agenda-format-date date))
2952 (put-text-property s (1- (point)) 'face
2953 (if (member wd org-agenda-weekend-days)
2954 'org-agenda-date-weekend
2956 (put-text-property s (1- (point)) 'org-date-line t)
2957 (put-text-property s (1- (point)) 'org-agenda-date-header t)
2959 (put-text-property s (1- (point)) 'org-today t))
2960 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
2961 (put-text-property s (1- (point)) 'day d)))))
2962 (goto-char (point-min))
2963 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
2965 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
2966 (org-finalize-agenda)
2967 (setq buffer-read-only t)))
2969 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
2970 "Return a list of all relevant day numbers from BEG to END buffer positions.
2971 If NO-RANGES is non-nil, include only the start and end dates of a range,
2972 not every single day in the range. If FORCE-TODAY is non-nil, make
2973 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2974 inactive time stamps (those in square brackets) are included.
2975 When EMPTY is non-nil, also include days without any entries."
2977 (if pre-re pre-re "")
2978 (if inactive org-ts-regexp-both org-ts-regexp)))
2979 dates dates1 date day day1 day2 ts1 ts2)
2981 (setq dates (list (time-to-days (current-time)))))
2984 (while (re-search-forward re end t)
2985 (setq day (time-to-days (org-time-string-to-time
2986 (substring (match-string 1) 0 10))))
2987 (or (memq day dates) (push day dates)))
2990 (while (re-search-forward org-tr-regexp end t)
2991 (setq ts1 (substring (match-string 1) 0 10)
2992 ts2 (substring (match-string 2) 0 10)
2993 day1 (time-to-days (org-time-string-to-time ts1))
2994 day2 (time-to-days (org-time-string-to-time ts2)))
2995 (while (< (setq day1 (1+ day1)) day2)
2996 (or (memq day1 dates) (push day1 dates)))))
2997 (setq dates (sort dates '<))
2999 (while (setq day (pop dates))
3000 (setq day2 (car dates))
3002 (when (and day2 empty)
3003 (if (or (eq empty t)
3004 (and (numberp empty) (<= (- day2 day) empty)))
3005 (while (< (setq day (1+ day)) day2)
3006 (push (list day) dates1))
3007 (push (cons :omitted (- day2 day)) dates1))))
3008 (setq dates (nreverse dates1)))
3011 ;;; Agenda Daily/Weekly
3013 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
3014 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3015 "Custom commands can set this variable in the options section.")
3016 (defvar org-agenda-last-arguments nil
3017 "The arguments of the previous call to org-agenda")
3018 (defvar org-starting-day nil) ; local variable in the agenda buffer
3019 (defvar org-agenda-span nil) ; local variable in the agenda buffer
3020 (defvar org-include-all-loc nil) ; local variable
3023 (defun org-agenda-list (&optional include-all start-day ndays)
3024 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3025 The view will be for the current day or week, but from the overview buffer
3026 you will be able to go to other days/weeks.
3028 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3029 all unfinished TODO items will also be shown, before the agenda.
3030 This feature is considered obsolete, please use the TODO list or a block
3033 With a numeric prefix argument in an interactive call, the agenda will
3034 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
3035 the number of days. NDAYS defaults to `org-agenda-ndays'.
3037 START-DAY defaults to TODAY, or to the most recent match for the weekday
3038 given in `org-agenda-start-on-weekday'."
3040 (if (and (integerp include-all) (> include-all 0))
3041 (setq ndays include-all include-all nil))
3042 (setq ndays (or ndays org-agenda-ndays)
3043 start-day (or start-day org-agenda-start-day))
3044 (if org-agenda-overriding-arguments
3045 (setq include-all (car org-agenda-overriding-arguments)
3046 start-day (nth 1 org-agenda-overriding-arguments)
3047 ndays (nth 2 org-agenda-overriding-arguments)))
3048 (if (stringp start-day)
3049 ;; Convert to an absolute day number
3050 (setq start-day (time-to-days (org-read-date nil t start-day))))
3051 (setq org-agenda-last-arguments (list include-all start-day ndays))
3052 (org-compile-prefix-format 'agenda)
3053 (org-set-sorting-strategy 'agenda)
3055 (let* ((org-agenda-start-on-weekday
3056 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3057 org-agenda-start-on-weekday nil))
3058 (thefiles (org-agenda-files nil 'ifmode))
3060 (today (time-to-days
3061 (time-subtract (current-time)
3062 (list 0 (* 3600 org-extend-today-until) 0))))
3063 (sd (or start-day today))
3064 (start (if (or (null org-agenda-start-on-weekday)
3065 (< org-agenda-ndays 7))
3067 (let* ((nt (calendar-day-of-week
3068 (calendar-gregorian-from-absolute sd)))
3069 (n1 org-agenda-start-on-weekday)
3071 (- sd (+ (if (< d 0) 7 0) d)))))
3072 (day-numbers (list start))
3074 (inhibit-redisplay (not debug-on-error))
3075 s e rtn rtnall file date d start-pos end-pos todayp nd wd
3076 clocktable-start clocktable-end)
3077 (setq org-agenda-redo-command
3078 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3079 ;; Make the list of days
3080 (setq ndays (or ndays org-agenda-ndays)
3083 (push (1+ (car day-numbers)) day-numbers)
3084 (setq ndays (1- ndays)))
3085 (setq day-numbers (nreverse day-numbers))
3086 (setq clocktable-start (car day-numbers)
3087 clocktable-end (1+ (or (org-last day-numbers) 0)))
3088 (org-prepare-agenda "Day/Week")
3089 (org-set-local 'org-starting-day (car day-numbers))
3090 (org-set-local 'org-include-all-loc include-all)
3091 (org-set-local 'org-agenda-span
3092 (org-agenda-ndays-to-span nd))
3093 (when (and (or include-all org-agenda-include-all-todo)
3094 (member today day-numbers))
3095 (setq files thefiles
3097 (while (setq file (pop files))
3099 (org-check-agenda-file file)
3100 (setq date (calendar-gregorian-from-absolute today)
3101 rtn (org-agenda-get-day-entries
3103 (setq rtnall (append rtnall rtn))))
3105 (insert "All currently open TODO items:\n")
3106 (add-text-properties (point-min) (1- (point))
3107 (list 'face 'org-agenda-structure
3108 'short-heading "All TODO items"))
3109 (org-agenda-mark-header-line (point-min))
3110 (insert (org-finalize-agenda-entries rtnall) "\n")))
3111 (unless org-agenda-compact-blocks
3112 (let* ((d1 (car day-numbers))
3113 (d2 (org-last day-numbers))
3114 (w1 (org-days-to-iso-week d1))
3115 (w2 (org-days-to-iso-week d2)))
3117 (if org-agenda-overriding-header
3118 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3119 nil 'face 'org-agenda-structure) "\n")
3120 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3122 (if (< (- d2 d1) 350)
3124 (format " (W%02d)" w1)
3125 (format " (W%02d-W%02d)" w1 w2))
3128 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3130 (org-agenda-mark-header-line s))
3131 (while (setq d (pop day-numbers))
3132 (setq date (calendar-gregorian-from-absolute d)
3133 wd (calendar-day-of-week date)
3135 (if (or (setq todayp (= d today))
3136 (and (not start-pos) (= d sd)))
3137 (setq start-pos (point))
3138 (if (and start-pos (not end-pos))
3139 (setq end-pos (point))))
3140 (setq files thefiles
3142 (while (setq file (pop files))
3144 (org-check-agenda-file file)
3146 ((eq org-agenda-show-log 'only)
3147 (setq rtn (org-agenda-get-day-entries
3148 file date :closed)))
3149 (org-agenda-show-log
3150 (setq rtn (org-agenda-get-day-entries
3152 :deadline :scheduled :timestamp :sexp :closed)))
3154 (setq rtn (org-agenda-get-day-entries
3156 :deadline :scheduled :sexp :timestamp))))
3157 (setq rtnall (append rtnall rtn))))
3158 (if org-agenda-include-diary
3159 (let ((org-agenda-search-headline-for-time t))
3160 (require 'diary-lib)
3161 (setq rtn (org-get-entries-from-diary date))
3162 (setq rtnall (append rtnall rtn))))
3163 (if (or rtnall org-agenda-show-all-dates)
3165 (setq day-cnt (1+ day-cnt))
3167 (if (stringp org-agenda-format-date)
3168 (format-time-string org-agenda-format-date
3169 (org-time-from-absolute date))
3170 (funcall org-agenda-format-date date))
3172 (put-text-property s (1- (point)) 'face
3173 (if (member wd org-agenda-weekend-days)
3174 'org-agenda-date-weekend
3176 (put-text-property s (1- (point)) 'org-date-line t)
3177 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3178 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3180 (put-text-property s (1- (point)) 'org-today t)
3181 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
3183 (org-finalize-agenda-entries
3184 (org-agenda-add-time-grid-maybe
3187 (put-text-property s (1- (point)) 'day d)
3188 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3189 (when (and org-agenda-clockreport-mode clocktable-start)
3190 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3191 ;; the above line is to ensure the restricted range!
3192 (p org-agenda-clockreport-parameter-plist)
3194 (setq p (org-plist-delete p :block))
3195 (setq p (plist-put p :tstart clocktable-start))
3196 (setq p (plist-put p :tend clocktable-end))
3197 (setq p (plist-put p :scope 'agenda))
3198 (setq tbl (apply 'org-get-clocktable p))
3200 (goto-char (point-min))
3201 (or org-agenda-multi (org-fit-agenda-window))
3202 (unless (and (pos-visible-in-window-p (point-min))
3203 (pos-visible-in-window-p (point-max)))
3204 (goto-char (1- (point-max)))
3206 (if (not (pos-visible-in-window-p (or start-pos 1)))
3208 (goto-char (or start-pos 1))
3210 (goto-char (or start-pos 1))
3211 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3212 (org-finalize-agenda)
3213 (setq buffer-read-only t)
3216 (defun org-agenda-ndays-to-span (n)
3217 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3219 ;;; Agenda word search
3221 (defvar org-agenda-search-history nil)
3222 (defvar org-todo-only nil)
3224 (defvar org-search-syntax-table nil
3225 "Special syntax table for org-mode search.
3226 In this table, we have single quotes not as word constituents, to
3227 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3229 (defun org-search-syntax-table ()
3230 (unless org-search-syntax-table
3231 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3232 (modify-syntax-entry ?' "." org-search-syntax-table)
3233 (modify-syntax-entry ?` "." org-search-syntax-table))
3234 org-search-syntax-table)
3236 (defvar org-agenda-last-search-view-search-was-boolean nil)
3239 (defun org-search-view (&optional todo-only string edit-at)
3240 "Show all entries that contain a phrase or words or regular expressions.
3242 With optional prefix argument TODO-ONLY, only consider entries that are
3243 TODO entries. The argument STRING can be used to pass a default search
3244 string into this function. If EDIT-AT is non-nil, it means that the
3245 user should get a chance to edit this string, with cursor at position
3248 The search string can be viewed either as a phrase that should be found as
3249 is, or it can be broken into a number of snippets, each of which must match
3250 in a Boolean way to select an entry. The default depends on the variable
3251 `org-agenda-search-view-always-boolean'.
3252 Even if this is turned off (the default) you can always switch to
3253 Boolean search dynamically by preceeding the first word with \"+\" or \"-\".
3255 The default is a direct search of the whole phrase, where each space in
3256 the search string can expand to an arbitrary amount of whitespace,
3259 If using a Boolean search, the search string is split on whitespace and
3260 each snippet is searched separately, with logical AND to select an entry.
3261 Words prefixed with a minus must *not* occur in the entry. Words without
3262 a prefix or prefixed with a plus must occur in the entry. Matching is
3263 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3264 match whole words, not parts of a word) if
3265 `org-agenda-search-view-force-full-words' is set (default is nil).
3267 Boolean search snippets enclosed by curly braces are interpreted as
3268 regular expressions that must or (when preceeded with \"-\") must not
3269 match in the entry. Snippets enclosed into double quotes will be taken
3270 as a whole, to incude whitespace.
3272 - If the search string starts with an asterisk, search only in headlines.
3273 - If (possibly after the leading star) the search string starts with an
3274 exclamation mark, this also means to look at TODO entries only, an effect
3275 that can also be achieved with a prefix argument.
3276 - If (possibly after star and exclamation mark) the search string starts
3277 with a colon, this will mean that the (non-regexp) snippets of the
3278 Boolean search must match as full words.
3280 This command searches the agenda files, and in addition the files listed
3281 in `org-agenda-text-search-extra-files'."
3283 (org-compile-prefix-format 'search)
3284 (org-set-sorting-strategy 'search)
3285 (org-prepare-agenda "SEARCH")
3286 (let* ((props (list 'face nil
3287 'done-face 'org-agenda-done
3288 'org-not-done-regexp org-not-done-regexp
3289 'org-todo-regexp org-todo-regexp
3290 'org-complex-heading-regexp org-complex-heading-regexp
3291 'mouse-face 'highlight
3292 'help-echo (format "mouse-2 or RET jump to location")))
3293 (full-words org-agenda-search-view-force-full-words)
3294 regexp rtn rtnall files file pos
3295 marker category tags c neg re boolean
3296 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3297 (unless (and (not edit-at)
3299 (string-match "\\S-" string))
3300 (setq string (read-string
3301 (if org-agenda-search-view-always-boolean
3302 "[+-]Word/{Regexp} ...: "
3303 "Phrase, or [+-]Word/{Regexp} ...: ")
3305 ((integerp edit-at) (cons string edit-at))
3307 'org-agenda-search-history)))
3308 (org-set-local 'org-todo-only todo-only)
3309 (setq org-agenda-redo-command
3310 (list 'org-search-view (if todo-only t nil) string
3311 '(if current-prefix-arg 1 nil)))
3312 (setq org-agenda-query-string string)
3314 (if (equal (string-to-char string) ?*)
3316 words (substring string 1))
3317 (setq words string))
3318 (when (equal (string-to-char words) ?!)
3320 words (substring words 1)))
3321 (when (equal (string-to-char words) ?:)
3323 words (substring words 1)))
3324 (if (or org-agenda-search-view-always-boolean
3325 (member (string-to-char string) '(?- ?+ ?\{)))
3327 (setq words (org-split-string words))
3328 (setq org-agenda-last-search-view-search-was-boolean boolean)
3331 (while (setq w (pop words))
3332 (if (or (equal (substring w 0 1) "\"")
3333 (and (> (length w) 1)
3334 (member (substring w 0 1) '("+" "-"))
3335 (equal (substring w 1 2) "\"")))
3336 (while (and words (not (equal (substring w -1) "\"")))
3337 (setq w (concat w " " (pop words)))))
3338 (and (string-match "\\`\\([-+]?\\)\"" w)
3339 (setq w (replace-match "\\1" nil nil w)))
3340 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3342 (setq words (nreverse wds))))
3345 (setq c (string-to-char w))
3347 (setq neg t w (substring w 1))
3349 (setq neg nil w (substring w 1))
3351 (if (string-match "\\`{.*}\\'" w)
3352 (setq re (substring w 1 -1))
3354 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3355 (setq re (regexp-quote (downcase w)))))
3356 (if neg (push re regexps-) (push re regexps+)))
3358 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3360 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3362 (setq regexp (concat "^" org-outline-regexp))
3363 (setq regexp (pop regexps+))
3364 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3366 (setq files (org-agenda-files nil 'ifmode))
3367 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3368 (pop org-agenda-text-search-extra-files)
3369 (setq files (org-add-archive-files files)))
3370 (setq files (append files org-agenda-text-search-extra-files)
3372 (while (setq file (pop files))
3375 (org-check-agenda-file file)
3376 (setq buffer (if (file-exists-p file)
3377 (org-get-agenda-file-buffer file)
3378 (error "No such file %s" file)))
3380 ;; If file does not exist, make sure an error message is sent
3381 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3383 (with-current-buffer buffer
3384 (with-syntax-table (org-search-syntax-table)
3385 (unless (org-mode-p)
3386 (error "Agenda file %s is not in `org-mode'" file))
3387 (let ((case-fold-search t))
3390 (if org-agenda-restrict
3391 (narrow-to-region org-agenda-restrict-begin
3392 org-agenda-restrict-end)
3394 (goto-char (point-min))
3395 (unless (or (org-on-heading-p)
3396 (outline-next-heading))
3397 (throw 'nextfile t))
3398 (goto-char (max (point-min) (1- (point))))
3399 (while (re-search-forward regexp nil t)
3400 (org-back-to-heading t)
3401 (skip-chars-forward "* ")
3402 (setq beg (point-at-bol)
3404 end (progn (outline-next-heading) (point)))
3408 (setq str (buffer-substring-no-properties
3410 (if hdl-only (point-at-eol) end)))
3411 (mapc (lambda (wr) (when (string-match wr str)
3412 (goto-char (1- end))
3415 (mapc (lambda (wr) (unless (string-match wr str)
3416 (goto-char (1- end))
3419 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3423 (setq marker (org-agenda-new-marker (point))
3424 category (org-get-category)
3425 tags (org-get-tags-at (point))
3426 txt (org-format-agenda-item
3428 (buffer-substring-no-properties
3429 beg1 (point-at-eol))
3431 (org-add-props txt props
3432 'org-marker marker 'org-hd-marker marker
3433 'org-todo-regexp org-todo-regexp
3434 'org-complex-heading-regexp org-complex-heading-regexp
3435 'priority 1000 'org-category category
3438 (goto-char (1- end))))))))))
3439 (setq rtn (nreverse ee))
3440 (setq rtnall (append rtnall rtn)))
3441 (if org-agenda-overriding-header
3442 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3443 nil 'face 'org-agenda-structure) "\n")
3444 (insert "Search words: ")
3445 (add-text-properties (point-min) (1- (point))
3446 (list 'face 'org-agenda-structure))
3448 (insert string "\n")
3449 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3451 (unless org-agenda-multi
3452 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3453 (add-text-properties pos (1- (point))
3454 (list 'face 'org-agenda-structure))))
3455 (org-agenda-mark-header-line (point-min))
3457 (insert (org-finalize-agenda-entries rtnall) "\n"))
3458 (goto-char (point-min))
3459 (or org-agenda-multi (org-fit-agenda-window))
3460 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3461 (org-finalize-agenda)
3462 (setq buffer-read-only t)))
3464 ;;; Agenda TODO list
3466 (defvar org-select-this-todo-keyword nil)
3467 (defvar org-last-arg nil)
3470 (defun org-todo-list (arg)
3471 "Show all TODO entries from all agenda file in a single list.
3472 The prefix arg can be used to select a specific TODO keyword and limit
3473 the list to these. When using \\[universal-argument], you will be prompted
3474 for a keyword. A numeric prefix directly selects the Nth keyword in
3475 `org-todo-keywords-1'."
3478 (org-compile-prefix-format 'todo)
3479 (org-set-sorting-strategy 'todo)
3480 (org-prepare-agenda "TODO")
3481 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3482 (let* ((today (time-to-days (current-time)))
3483 (date (calendar-gregorian-from-absolute today))
3484 (kwds org-todo-keywords-for-agenda)
3485 (completion-ignore-case t)
3486 (org-select-this-todo-keyword
3487 (if (stringp arg) arg
3488 (and arg (integerp arg) (> arg 0)
3489 (nth (1- arg) kwds))))
3490 rtn rtnall files file pos)
3491 (when (equal arg '(4))
3492 (setq org-select-this-todo-keyword
3493 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3494 (mapcar 'list kwds) nil nil)))
3495 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3496 (org-set-local 'org-last-arg arg)
3497 (setq org-agenda-redo-command
3498 '(org-todo-list (or current-prefix-arg org-last-arg)))
3499 (setq files (org-agenda-files nil 'ifmode)
3501 (while (setq file (pop files))
3503 (org-check-agenda-file file)
3504 (setq rtn (org-agenda-get-day-entries file date :todo))
3505 (setq rtnall (append rtnall rtn))))
3506 (if org-agenda-overriding-header
3507 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3508 nil 'face 'org-agenda-structure) "\n")
3509 (insert "Global list of TODO items of type: ")
3510 (add-text-properties (point-min) (1- (point))
3511 (list 'face 'org-agenda-structure
3514 (or org-select-this-todo-keyword "ALL"))))
3515 (org-agenda-mark-header-line (point-min))
3517 (insert (or org-select-this-todo-keyword "ALL") "\n")
3518 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3520 (unless org-agenda-multi
3521 (insert "Available with `N r': (0)ALL")
3524 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3525 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3530 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3531 (org-agenda-mark-header-line (point-min))
3533 (insert (org-finalize-agenda-entries rtnall) "\n"))
3534 (goto-char (point-min))
3535 (or org-agenda-multi (org-fit-agenda-window))
3536 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3537 (org-finalize-agenda)
3538 (setq buffer-read-only t)))
3540 ;;; Agenda tags match
3543 (defun org-tags-view (&optional todo-only match)
3544 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3545 The prefix arg TODO-ONLY limits the search to TODO entries."
3547 (org-compile-prefix-format 'tags)
3548 (org-set-sorting-strategy 'tags)
3549 (let* ((org-tags-match-list-sublevels
3550 org-tags-match-list-sublevels)
3551 (completion-ignore-case t)
3552 rtn rtnall files file pos matcher
3554 (when (and (stringp match) (not (string-match "\\S-" match)))
3556 (setq matcher (org-make-tags-matcher match)
3557 match (car matcher) matcher (cdr matcher))
3558 (org-prepare-agenda (concat "TAGS " match))
3559 (setq org-agenda-query-string match)
3560 (setq org-agenda-redo-command
3561 (list 'org-tags-view (list 'quote todo-only)
3562 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3563 (setq files (org-agenda-files nil 'ifmode)
3565 (while (setq file (pop files))
3567 (org-check-agenda-file file)
3568 (setq buffer (if (file-exists-p file)
3569 (org-get-agenda-file-buffer file)
3570 (error "No such file %s" file)))
3572 ;; If file does not exist, error message to agenda
3574 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3575 rtnall (append rtnall rtn))
3576 (with-current-buffer buffer
3577 (unless (org-mode-p)
3578 (error "Agenda file %s is not in `org-mode'" file))
3581 (if org-agenda-restrict
3582 (narrow-to-region org-agenda-restrict-begin
3583 org-agenda-restrict-end)
3585 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3586 (setq rtnall (append rtnall rtn))))))))
3587 (if org-agenda-overriding-header
3588 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3589 nil 'face 'org-agenda-structure) "\n")
3590 (insert "Headlines with TAGS match: ")
3591 (add-text-properties (point-min) (1- (point))
3592 (list 'face 'org-agenda-structure
3594 (concat "Match: " match)))
3597 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3599 (unless org-agenda-multi
3600 (insert "Press `C-u r' to search again with new search string\n"))
3601 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3602 (org-agenda-mark-header-line (point-min))
3604 (insert (org-finalize-agenda-entries rtnall) "\n"))
3605 (goto-char (point-min))
3606 (or org-agenda-multi (org-fit-agenda-window))
3607 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3608 (org-finalize-agenda)
3609 (setq buffer-read-only t)))
3611 ;;; Agenda Finding stuck projects
3613 (defvar org-agenda-skip-regexp nil
3614 "Regular expression used in skipping subtrees for the agenda.
3615 This is basically a temporary global variable that can be set and then
3616 used by user-defined selections using `org-agenda-skip-function'.")
3618 (defvar org-agenda-overriding-header nil
3619 "When this is set during todo and tags searches, will replace header.
3620 This variable should not be set directly, but custom commands can bind it
3621 in the options section.")
3623 (defun org-agenda-skip-entry-when-regexp-matches ()
3624 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3625 If yes, it returns the end position of this entry, causing agenda commands
3626 to skip the entry but continuing the search in the subtree. This is a
3627 function that can be put into `org-agenda-skip-function' for the duration
3629 (let ((end (save-excursion (org-end-of-subtree t)))
3632 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3635 (defun org-agenda-skip-subtree-when-regexp-matches ()
3636 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3637 If yes, it returns the end position of this tree, causing agenda commands
3638 to skip this subtree. This is a function that can be put into
3639 `org-agenda-skip-function' for the duration of a command."
3640 (let ((end (save-excursion (org-end-of-subtree t)))
3643 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3646 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3647 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3648 If yes, it returns the end position of the current entry (NOT the tree),
3649 causing agenda commands to skip the entry but continuing the search in
3650 the subtree. This is a function that can be put into
3651 `org-agenda-skip-function' for the duration of a command. An important
3652 use of this function is for the stuck project list."
3653 (let ((end (save-excursion (org-end-of-subtree t)))
3654 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3657 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3658 (and skip entry-end)))
3660 (defun org-agenda-skip-entry-if (&rest conditions)
3661 "Skip entry if any of CONDITIONS is true.
3662 See `org-agenda-skip-if' for details."
3663 (org-agenda-skip-if nil conditions))
3665 (defun org-agenda-skip-subtree-if (&rest conditions)
3666 "Skip entry if any of CONDITIONS is true.
3667 See `org-agenda-skip-if' for details."
3668 (org-agenda-skip-if t conditions))
3670 (defun org-agenda-skip-if (subtree conditions)
3671 "Checks current entity for CONDITIONS.
3672 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3673 the entry, i.e. the text before the next heading is checked.
3675 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3676 from different tests. Valid conditions are:
3678 scheduled Check if there is a scheduled cookie
3679 notscheduled Check if there is no scheduled cookie
3680 deadline Check if there is a deadline
3681 notdeadline Check if there is no deadline
3682 timestamp Check if there is a timestamp (also deadline or scheduled)
3683 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3684 regexp Check if regexp matches
3685 notregexp Check if regexp does not match.
3687 The regexp is taken from the conditions list, it must come right after
3688 the `regexp' or `notregexp' element.
3690 If any of these conditions is met, this function returns the end point of
3691 the entity, causing the search to continue from there. This is a function
3692 that can be put into `org-agenda-skip-function' for the duration of a command."
3694 (org-back-to-heading t)
3697 (progn (org-end-of-subtree t) (point))
3698 (progn (outline-next-heading) (1- (point)))))
3702 (and (memq 'scheduled conditions)
3703 (re-search-forward org-scheduled-time-regexp end t))
3704 (and (memq 'notscheduled conditions)
3705 (not (re-search-forward org-scheduled-time-regexp end t)))
3706 (and (memq 'deadline conditions)
3707 (re-search-forward org-deadline-time-regexp end t))
3708 (and (memq 'notdeadline conditions)
3709 (not (re-search-forward org-deadline-time-regexp end t)))
3710 (and (memq 'timestamp conditions)
3711 (re-search-forward org-ts-regexp end t))
3712 (and (memq 'nottimestamp conditions)
3713 (not (re-search-forward org-ts-regexp end t)))
3714 (and (setq m (memq 'regexp conditions))
3716 (re-search-forward (nth 1 m) end t))
3717 (and (setq m (memq 'notregexp conditions))
3719 (not (re-search-forward (nth 1 m) end t))))
3723 (defun org-agenda-list-stuck-projects (&rest ignore)
3724 "Create agenda view for projects that are stuck.
3725 Stuck projects are project that have no next actions. For the definitions
3726 of what a project is and how to check if it stuck, customize the variable
3727 `org-stuck-projects'.
3728 MATCH is being ignored."
3730 (let* ((org-agenda-skip-function
3731 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
3732 ;; We could have used org-agenda-skip-if here.
3733 (org-agenda-overriding-header
3734 (or org-agenda-overriding-header "List of stuck projects: "))
3735 (matcher (nth 0 org-stuck-projects))
3736 (todo (nth 1 org-stuck-projects))
3737 (todo-wds (if (member "*" todo)
3739 (org-prepare-agenda-buffers (org-agenda-files
3742 org-done-keywords-for-agenda
3743 (copy-sequence org-todo-keywords-for-agenda)))
3745 (todo-re (concat "^\\*+[ \t]+\\("
3746 (mapconcat 'identity todo-wds "\\|")
3748 (tags (nth 2 org-stuck-projects))
3749 (tags-re (if (member "*" tags)
3750 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3752 (concat "^\\*+ .*:\\("
3753 (mapconcat 'identity tags "\\|")
3754 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3755 (gen-re (nth 3 org-stuck-projects))
3761 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
3763 (setq org-agenda-skip-regexp
3765 (mapconcat 'identity re-list "\\|")
3766 (error "No information how to identify unstuck projects")))
3767 (org-tags-view nil matcher)
3768 (with-current-buffer org-agenda-buffer-name
3769 (setq org-agenda-redo-command
3770 '(org-agenda-list-stuck-projects
3771 (or current-prefix-arg org-last-arg))))))
3773 ;;; Diary integration
3775 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
3776 (defvar list-diary-entries-hook)
3778 (defun org-get-entries-from-diary (date)
3779 "Get the (Emacs Calendar) diary entries for DATE."
3780 (require 'diary-lib)
3781 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3782 (fancy-diary-buffer diary-fancy-buffer)
3783 (diary-display-hook '(fancy-diary-display))
3784 (diary-display-function 'fancy-diary-display)
3786 (list-diary-entries-hook
3787 (cons 'org-diary-default-entry list-diary-entries-hook))
3788 (diary-file-name-prefix-function nil) ; turn this feature off
3789 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
3791 (org-disable-agenda-to-diary t))
3793 (save-window-excursion
3794 (funcall (if (fboundp 'diary-list-entries)
3795 'diary-list-entries 'list-diary-entries)
3797 (if (not (get-buffer diary-fancy-buffer))
3799 (with-current-buffer diary-fancy-buffer
3800 (setq buffer-read-only nil)
3801 (if (zerop (buffer-size))
3804 ;; Omit the date and other unnecessary stuff
3805 (org-agenda-cleanup-fancy-diary)
3806 ;; Add prefix to each line and extend the text properties
3807 (if (zerop (buffer-size))
3809 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
3810 (set-buffer-modified-p nil)
3811 (kill-buffer diary-fancy-buffer)))
3813 (setq entries (org-split-string entries "\n"))
3817 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
3818 ;; Extend the text properties to the beginning of the line
3819 (org-add-props x (text-properties-at (1- (length x)) x)
3820 'type "diary" 'date date 'face 'org-agenda-diary))
3823 (defvar org-agenda-cleanup-fancy-diary-hook nil
3824 "Hook run when the fancy diary buffer is cleaned up.")
3826 (defun org-agenda-cleanup-fancy-diary ()
3827 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3828 This gets rid of the date, the underline under the date, and
3829 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3830 date. It also removes lines that contain only whitespace."
3831 (goto-char (point-min))
3832 (if (looking-at ".*?:[ \t]*")
3835 (re-search-forward "\n=+$" nil t)
3837 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
3838 (re-search-forward "\n=+$" nil t)
3839 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3840 (goto-char (point-min))
3841 (while (re-search-forward "^ +\n" nil t)
3843 (goto-char (point-min))
3844 (if (re-search-forward "^Org-mode dummy\n?" nil t)
3846 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
3848 ;; Make sure entries from the diary have the right text properties.
3849 (eval-after-load "diary-lib"
3850 '(if (boundp 'diary-modify-entry-list-string-function)
3851 ;; We can rely on the hook, nothing to do
3853 ;; Hook not available, must use advice to make this work
3854 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
3855 "Make the position visible."
3856 (if (and org-disable-agenda-to-diary ;; called from org-agenda
3859 (setq string (org-modify-diary-entry-string string))))))
3861 (defun org-modify-diary-entry-string (string)
3862 "Add text properties to string, allowing org-mode to act on it."
3863 (org-add-props string nil
3864 'mouse-face 'highlight
3865 'help-echo (if buffer-file-name
3866 (format "mouse-2 or RET jump to diary file %s"
3867 (abbreviate-file-name buffer-file-name))
3869 'org-agenda-diary-link t
3870 'org-marker (org-agenda-new-marker (point-at-bol))))
3872 (defun org-diary-default-entry ()
3873 "Add a dummy entry to the diary.
3874 Needed to avoid empty dates which mess up holiday display."
3875 ;; Catch the error if dealing with the new add-to-diary-alist
3876 (when org-disable-agenda-to-diary
3878 (org-add-to-diary-list original-date "Org-mode dummy" "")
3880 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
3882 (defun org-add-to-diary-list (&rest args)
3883 (if (fboundp 'diary-add-to-list)
3884 (apply 'diary-add-to-list args)
3885 (apply 'add-to-diary-list args)))
3888 (defun org-diary (&rest args)
3889 "Return diary information from org-files.
3890 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3891 It accesses org files and extracts information from those files to be
3892 listed in the diary. The function accepts arguments specifying what
3893 items should be listed. The following arguments are allowed:
3895 :timestamp List the headlines of items containing a date stamp or
3896 date range matching the selected date. Deadlines will
3897 also be listed, on the expiration day.
3899 :sexp List entries resulting from diary-like sexps.
3901 :deadline List any deadlines past due, or due within
3902 `org-deadline-warning-days'. The listing occurs only
3903 in the diary for *today*, not at any other date. If
3904 an entry is marked DONE, it is no longer listed.
3906 :scheduled List all items which are scheduled for the given date.
3907 The diary for *today* also contains items which were
3908 scheduled earlier and are not yet marked DONE.
3910 :todo List all TODO items from the org-file. This may be a
3911 long list - so this is not turned on by default.
3912 Like deadlines, these entries only show up in the
3913 diary for *today*, not at any other date.
3915 The call in the diary file should look like this:
3917 &%%(org-diary) ~/path/to/some/orgfile.org
3919 Use a separate line for each org file to check. Or, if you omit the file name,
3920 all files listed in `org-agenda-files' will be checked automatically:
3924 If you don't give any arguments (as in the example above), the default
3925 arguments (:deadline :scheduled :timestamp :sexp) are used.
3926 So the example above may also be written as
3928 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3930 The function expects the lisp variables `entry' and `date' to be provided
3931 by the caller, because this is how the calendar works. Don't use this
3932 function from a program - use `org-agenda-get-day-entries' instead."
3933 (when (> (- (org-float-time)
3934 org-agenda-last-marker-time)
3936 (org-agenda-reset-markers))
3937 (org-compile-prefix-format 'agenda)
3938 (org-set-sorting-strategy 'agenda)
3939 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3940 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
3942 (org-agenda-files t)))
3944 (org-prepare-agenda-buffers files)
3945 ;; If this is called during org-agenda, don't return any entries to
3946 ;; the calendar. Org Agenda will list these entries itself.
3947 (if org-disable-agenda-to-diary (setq files nil))
3948 (while (setq file (pop files))
3949 (setq rtn (apply 'org-agenda-get-day-entries file date args))
3950 (setq results (append results rtn)))
3952 (concat (org-finalize-agenda-entries results) "\n"))))
3954 ;;; Agenda entry finders
3956 (defun org-agenda-get-day-entries (file date &rest args)
3957 "Does the work for `org-diary' and `org-agenda'.
3958 FILE is the path to a file to be checked for entries. DATE is date like
3959 the one returned by `calendar-current-date'. ARGS are symbols indicating
3960 which kind of entries should be extracted. For details about these, see
3961 the documentation of `org-diary'."
3962 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3963 (let* ((org-startup-folded nil)
3964 (org-startup-align-all-tables nil)
3965 (buffer (if (file-exists-p file)
3966 (org-get-agenda-file-buffer file)
3967 (error "No such file %s" file)))
3968 arg results rtn deadline-results)
3970 ;; If file does not exist, make sure an error message ends up in diary
3971 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3972 (with-current-buffer buffer
3973 (unless (org-mode-p)
3974 (error "Agenda file %s is not in `org-mode'" file))
3975 (let ((case-fold-search nil))
3978 (if org-agenda-restrict
3979 (narrow-to-region org-agenda-restrict-begin
3980 org-agenda-restrict-end)
3982 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3983 (while (setq arg (pop args))
3985 ((and (eq arg :todo)
3986 (equal date (calendar-current-date)))
3987 (setq rtn (org-agenda-get-todos))
3988 (setq results (append results rtn)))
3989 ((eq arg :timestamp)
3990 (setq rtn (org-agenda-get-blocks))
3991 (setq results (append results rtn))
3992 (setq rtn (org-agenda-get-timestamps))
3993 (setq results (append results rtn)))
3995 (setq rtn (org-agenda-get-sexps))
3996 (setq results (append results rtn)))
3997 ((eq arg :scheduled)
3998 (setq rtn (org-agenda-get-scheduled deadline-results))
3999 (setq results (append results rtn)))
4001 (setq rtn (org-agenda-get-progress))
4002 (setq results (append results rtn)))
4004 (setq rtn (org-agenda-get-deadlines))
4005 (setq deadline-results (copy-sequence rtn))
4006 (setq results (append results rtn))))))))
4009 (defun org-agenda-get-todos ()
4010 "Return the TODO information for agenda display."
4011 (let* ((props (list 'face nil
4012 'done-face 'org-agenda-done
4013 'org-not-done-regexp org-not-done-regexp
4014 'org-todo-regexp org-todo-regexp
4015 'org-complex-heading-regexp org-complex-heading-regexp
4016 'mouse-face 'highlight
4018 (format "mouse-2 or RET jump to org file %s"
4019 (abbreviate-file-name buffer-file-name))))
4020 (regexp (concat "^\\*+[ \t]+\\("
4021 (if org-select-this-todo-keyword
4022 (if (equal org-select-this-todo-keyword "*")
4025 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4027 org-not-done-regexp)
4029 marker priority category tags todo-state
4031 (goto-char (point-min))
4032 (while (re-search-forward regexp nil t)
4036 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4037 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4038 (goto-char (1+ beg))
4039 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4043 (goto-char (match-beginning 1))
4044 (setq marker (org-agenda-new-marker (match-beginning 0))
4045 category (org-get-category)
4046 txt (match-string 1)
4047 tags (org-get-tags-at (point))
4048 txt (org-format-agenda-item "" txt category tags)
4049 priority (1+ (org-get-priority txt))
4050 todo-state (org-get-todo-state))
4051 (org-add-props txt props
4052 'org-marker marker 'org-hd-marker marker
4053 'priority priority 'org-category category
4054 'type "todo" 'todo-state todo-state)
4056 (if org-agenda-todo-list-sublevels
4057 (goto-char (match-end 1))
4058 (org-end-of-subtree 'invisible))))
4062 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
4063 "Do we have a reason to ignore this todo entry because it has a time stamp?"
4064 (when (or org-agenda-todo-ignore-with-date
4065 org-agenda-todo-ignore-scheduled
4066 org-agenda-todo-ignore-deadlines)
4067 (setq end (or end (save-excursion (outline-next-heading) (point))))
4069 (or (and org-agenda-todo-ignore-with-date
4070 (re-search-forward org-ts-regexp end t))
4071 (and org-agenda-todo-ignore-scheduled
4072 (re-search-forward org-scheduled-time-regexp end t))
4073 (and org-agenda-todo-ignore-deadlines
4074 (re-search-forward org-deadline-time-regexp end t)
4075 (org-deadline-close (match-string 1)))))))
4077 (defconst org-agenda-no-heading-message
4078 "No heading for this item in buffer or region.")
4080 (defun org-agenda-get-timestamps ()
4081 "Return the date stamp information for agenda display."
4082 (let* ((props (list 'face nil
4083 'org-not-done-regexp org-not-done-regexp
4084 'org-todo-regexp org-todo-regexp
4085 'org-complex-heading-regexp org-complex-heading-regexp
4086 'mouse-face 'highlight
4088 (format "mouse-2 or RET jump to org file %s"
4089 (abbreviate-file-name buffer-file-name))))
4090 (d1 (calendar-absolute-from-gregorian date))
4096 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4100 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4104 (car org-time-stamp-formats)
4105 (apply 'encode-time ; DATE bound by calendar
4106 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4108 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4109 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4110 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4111 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4112 todo-state end-of-match)
4113 (goto-char (point-min))
4114 (while (setq end-of-match (re-search-forward regexp nil t))
4115 (setq b0 (match-beginning 0)
4116 b3 (match-beginning 3) e3 (match-end 3))
4118 (and (org-at-date-range-p) (throw :skip nil))
4120 (if (and (match-end 1)
4121 (not (= d1 (org-time-string-to-absolute
4122 (match-string 1) d1 nil
4123 org-agenda-repeating-timestamp-show-all))))
4126 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4128 (setq tmp (buffer-substring (max (point-min)
4129 (- b0 org-ds-keyword-length))
4131 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4132 inactivep (= (char-after b0) ?\[)
4133 deadlinep (string-match org-deadline-regexp tmp)
4134 scheduledp (string-match org-scheduled-regexp tmp)
4135 closedp (and org-agenda-include-inactive-timestamps
4136 (string-match org-closed-string tmp))
4137 clockp (and org-agenda-include-inactive-timestamps
4138 (or (string-match org-clock-string tmp)
4139 (string-match "]-+\\'" tmp)))
4140 todo-state (org-get-todo-state)
4141 donep (member todo-state org-done-keywords))
4142 (if (or scheduledp deadlinep closedp clockp
4143 (and donep org-agenda-skip-timestamp-if-done))
4145 (if (string-match ">" timestr)
4146 ;; substring should only run to end of time stamp
4147 (setq timestr (substring timestr 0 (match-end 0))))
4148 (setq marker (org-agenda-new-marker b0)
4149 category (org-get-category b0))
4151 (if (not (re-search-backward "^\\*+ " nil t))
4152 (setq txt org-agenda-no-heading-message)
4153 (goto-char (match-beginning 0))
4154 (setq hdmarker (org-agenda-new-marker)
4155 tags (org-get-tags-at))
4156 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4157 (setq head (match-string 1))
4158 (setq txt (org-format-agenda-item
4159 (if inactivep org-agenda-inactive-leader nil)
4160 head category tags timestr nil
4162 (setq priority (org-get-priority txt))
4163 (org-add-props txt props
4164 'org-marker marker 'org-hd-marker hdmarker)
4165 (org-add-props txt nil 'priority priority
4166 'org-category category 'date date
4167 'todo-state todo-state
4170 (if org-agenda-skip-additional-timestamps-same-entry
4171 (outline-next-heading)
4172 (goto-char end-of-match))))
4175 (defun org-agenda-get-sexps ()
4176 "Return the sexp information for agenda display."
4177 (require 'diary-lib)
4178 (let* ((props (list 'face nil
4179 'mouse-face 'highlight
4181 (format "mouse-2 or RET jump to org file %s"
4182 (abbreviate-file-name buffer-file-name))))
4184 marker category ee txt tags entry result beg b sexp sexp-entry
4186 (goto-char (point-min))
4187 (while (re-search-forward regexp nil t)
4190 (setq beg (match-beginning 0))
4191 (goto-char (1- (match-end 0)))
4194 (setq sexp (buffer-substring b (point)))
4195 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4196 (org-trim (match-string 1))
4198 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4200 (setq marker (org-agenda-new-marker beg)
4201 category (org-get-category beg)
4202 todo-state (org-get-todo-state))
4204 (if (string-match "\\S-" result)
4206 (setq txt "SEXP entry returned empty string"))
4208 (setq txt (org-format-agenda-item
4209 "" txt category tags 'time))
4210 (org-add-props txt props 'org-marker marker)
4211 (org-add-props txt nil
4212 'org-category category 'date date 'todo-state todo-state
4217 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4218 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4219 Order of the parameters is M1, D1, Y1, M2, D2, Y2 if
4220 `european-calendar-style' is nil, and D1, M1, Y1, D2, M2, Y2 if
4221 `european-calendar-style' is t.
4222 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4223 is any number of ISO weeks in the block period for which the item should
4225 (let* ((date1 (calendar-absolute-from-gregorian
4226 (if european-calendar-style
4229 (date2 (calendar-absolute-from-gregorian
4230 (if european-calendar-style
4233 (d (calendar-absolute-from-gregorian date)))
4237 (= (calendar-day-of-week date) dayname)
4238 (or (not skip-weeks)
4241 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4244 (defalias 'org-get-closed 'org-agenda-get-progress)
4245 (defun org-agenda-get-progress ()
4246 "Return the logged TODO entries for agenda display."
4247 (let* ((props (list 'mouse-face 'highlight
4248 'org-not-done-regexp org-not-done-regexp
4249 'org-todo-regexp org-todo-regexp
4250 'org-complex-heading-regexp org-complex-heading-regexp
4252 (format "mouse-2 or RET jump to org file %s"
4253 (abbreviate-file-name buffer-file-name))))
4254 (items (if (consp org-agenda-show-log)
4256 org-agenda-log-mode-items))
4260 (if (memq 'closed items) (concat "\\<" org-closed-string))
4261 (if (memq 'clock items) (concat "\\<" org-clock-string))
4262 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4263 (parts-re (if parts (mapconcat 'identity parts "\\|")
4264 (error "`org-agenda-log-mode-items' is empty")))
4266 "\\(" parts-re "\\)"
4271 (car org-time-stamp-formats)
4272 (apply 'encode-time ; DATE bound by calendar
4273 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4275 (org-agenda-search-headline-for-time nil)
4276 marker hdmarker priority category tags closedp statep clockp state
4277 ee txt extra timestr rest clocked)
4278 (goto-char (point-min))
4279 (while (re-search-forward regexp nil t)
4282 (setq marker (org-agenda-new-marker (match-beginning 0))
4283 closedp (equal (match-string 1) org-closed-string)
4284 statep (equal (string-to-char (match-string 1)) ?-)
4285 clockp (not (or closedp statep))
4286 state (and statep (match-string 2))
4287 category (org-get-category (match-beginning 0))
4288 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4290 (when (string-match "\\]" timestr)
4291 ;; substring should only run to end of time stamp
4292 (setq rest (substring timestr (match-end 0))
4293 timestr (substring timestr 0 (match-end 0)))
4294 (if (and (not closedp) (not statep)
4295 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4296 (progn (setq timestr (concat (substring timestr 0 -1)
4297 "-" (match-string 1 rest) "]"))
4298 (setq clocked (match-string 2 rest)))
4299 (setq clocked "-")))
4302 ((not org-agenda-log-mode-add-notes) (setq extra nil))
4304 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4305 (setq extra (match-string 1))))
4307 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4308 (setq extra (match-string 1))))
4309 (t (setq extra nil)))
4310 (if (not (re-search-backward "^\\*+ " nil t))
4311 (setq txt org-agenda-no-heading-message)
4312 (goto-char (match-beginning 0))
4313 (setq hdmarker (org-agenda-new-marker)
4314 tags (org-get-tags-at))
4315 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4316 (setq txt (match-string 1))
4318 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4319 (setq txt (concat (substring txt 0 (match-beginning 1))
4320 " - " extra " " (match-string 2 txt)))
4321 (setq txt (concat txt " - " extra))))
4322 (setq txt (org-format-agenda-item
4324 (closedp "Closed: ")
4325 (statep (concat "State: (" state ")"))
4326 (t (concat "Clocked: (" clocked ")")))
4327 txt category tags timestr)))
4328 (setq priority 100000)
4329 (org-add-props txt props
4330 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4331 'priority priority 'org-category category
4332 'type "closed" 'date date
4333 'undone-face 'org-warning 'done-face 'org-agenda-done)
4335 (goto-char (point-at-eol))))
4338 (defun org-agenda-get-deadlines ()
4339 "Return the deadline information for agenda display."
4340 (let* ((props (list 'mouse-face 'highlight
4341 'org-not-done-regexp org-not-done-regexp
4342 'org-todo-regexp org-todo-regexp
4343 'org-complex-heading-regexp org-complex-heading-regexp
4345 (format "mouse-2 or RET jump to org file %s"
4346 (abbreviate-file-name buffer-file-name))))
4347 (regexp org-deadline-time-regexp)
4348 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4349 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4350 d2 diff dfrac wdays pos pos1 category tags
4351 ee txt head face s todo-state upcomingp donep timestr)
4352 (goto-char (point-min))
4353 (while (re-search-forward regexp nil t)
4356 (setq s (match-string 1)
4358 pos (1- (match-beginning 1))
4359 d2 (org-time-string-to-absolute
4360 (match-string 1) d1 'past
4361 org-agenda-repeating-timestamp-show-all)
4363 wdays (org-get-wdays s)
4364 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4365 upcomingp (and todayp (> diff 0)))
4366 ;; When to show a deadline in the calendar:
4367 ;; If the expiration is within wdays warning time.
4368 ;; Past-due deadlines are only shown on the current date
4369 (if (and (or (and (<= diff wdays)
4370 (and todayp (not org-agenda-only-exact-dates)))
4373 (setq todo-state (org-get-todo-state))
4374 (setq donep (member todo-state org-done-keywords))
4376 (or org-agenda-skip-deadline-if-done
4379 (setq category (org-get-category))
4380 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4381 (setq txt org-agenda-no-heading-message)
4382 (goto-char (match-end 0))
4383 (setq pos1 (match-beginning 0))
4384 (setq tags (org-get-tags-at pos1))
4385 (setq head (buffer-substring-no-properties
4387 (progn (skip-chars-forward "^\r\n")
4389 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4391 (concat (substring s (match-beginning 1)) " "))
4392 (setq timestr 'time))
4393 (setq txt (org-format-agenda-item
4395 (car org-agenda-deadline-leaders)
4397 (nth 1 org-agenda-deadline-leaders))
4399 (nth 1 org-agenda-deadline-leaders)
4401 (format (nth 1 org-agenda-deadline-leaders)
4404 (if (not (= diff 0)) nil timestr)))))
4406 (setq face (org-agenda-deadline-face dfrac wdays))
4407 (org-add-props txt props
4408 'org-marker (org-agenda-new-marker pos)
4409 'org-hd-marker (org-agenda-new-marker pos1)
4410 'priority (+ (- diff)
4411 (org-get-priority txt))
4412 'org-category category
4413 'todo-state todo-state
4414 'type (if upcomingp "upcoming-deadline" "deadline")
4415 'date (if upcomingp date d2)
4416 'face (if donep 'org-agenda-done face)
4417 'undone-face face 'done-face 'org-agenda-done)
4421 (defun org-agenda-deadline-face (fraction &optional wdays)
4422 "Return the face to displaying a deadline item.
4423 FRACTION is what fraction of the head-warning time has passed."
4424 (if (equal wdays 0) (setq fraction 1.))
4425 (let ((faces org-agenda-deadline-faces) f)
4427 (while (setq f (pop faces))
4428 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4430 (defun org-agenda-get-scheduled (&optional deadline-results)
4431 "Return the scheduled information for agenda display."
4432 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4433 'org-todo-regexp org-todo-regexp
4434 'org-complex-heading-regexp org-complex-heading-regexp
4435 'done-face 'org-agenda-done
4436 'mouse-face 'highlight
4438 (format "mouse-2 or RET jump to org file %s"
4439 (abbreviate-file-name buffer-file-name))))
4440 (regexp org-scheduled-time-regexp)
4441 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4442 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4444 (deadline-position-alist
4445 (mapcar (lambda (a) (and (setq mm (get-text-property
4446 0 'org-hd-marker a))
4447 (cons (marker-position mm) a)))
4449 d2 diff pos pos1 category tags donep
4450 ee txt head pastschedp todo-state face timestr s habitp)
4451 (goto-char (point-min))
4452 (while (re-search-forward regexp nil t)
4455 (setq s (match-string 1)
4457 pos (1- (match-beginning 1))
4458 d2 (org-time-string-to-absolute
4459 (match-string 1) d1 'past
4460 org-agenda-repeating-timestamp-show-all)
4462 (setq pastschedp (and todayp (< diff 0)))
4463 ;; When to show a scheduled item in the calendar:
4464 ;; If it is on or past the date.
4465 (when (or (and (< diff 0)
4466 (< (abs diff) org-scheduled-past-days)
4467 (and todayp (not org-agenda-only-exact-dates)))
4470 (setq todo-state (org-get-todo-state))
4471 (setq donep (member todo-state org-done-keywords))
4472 (setq habitp (and (functionp 'org-is-habit-p)
4475 (or habitp org-agenda-skip-scheduled-if-done
4478 (setq category (org-get-category))
4479 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4480 (setq txt org-agenda-no-heading-message)
4481 (goto-char (match-end 0))
4482 (setq pos1 (match-beginning 0))
4484 (if (or (not org-habit-show-habits)
4486 org-habit-show-habits-only-for-today))
4489 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4490 (and org-agenda-skip-scheduled-if-deadline-is-shown
4492 (setq mm (assoc pos1 deadline-position-alist)))
4494 (setq tags (org-get-tags-at))
4495 (setq head (buffer-substring-no-properties
4497 (progn (skip-chars-forward "^\r\n") (point))))
4498 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4500 (concat (substring s (match-beginning 1)) " "))
4501 (setq timestr 'time))
4502 (setq txt (org-format-agenda-item
4504 (car org-agenda-scheduled-leaders)
4505 (format (nth 1 org-agenda-scheduled-leaders)
4508 (if (not (= diff 0)) nil timestr)
4513 ((and (not habitp) pastschedp)
4514 'org-scheduled-previously)
4515 (todayp 'org-scheduled-today)
4517 habitp (and habitp (org-habit-parse-todo)))
4518 (org-add-props txt props
4520 'face (if donep 'org-agenda-done face)
4521 'org-marker (org-agenda-new-marker pos)
4522 'org-hd-marker (org-agenda-new-marker pos1)
4523 'type (if pastschedp "past-scheduled" "scheduled")
4524 'date (if pastschedp d2 date)
4525 'priority (if habitp
4526 (org-habit-get-priority habitp)
4527 (+ 94 (- 5 diff) (org-get-priority txt)))
4528 'org-category category
4530 'todo-state todo-state)
4534 (defun org-agenda-get-blocks ()
4535 "Return the date-range information for agenda display."
4536 (let* ((props (list 'face nil
4537 'org-not-done-regexp org-not-done-regexp
4538 'org-todo-regexp org-todo-regexp
4539 'org-complex-heading-regexp org-complex-heading-regexp
4540 'mouse-face 'highlight
4542 (format "mouse-2 or RET jump to org file %s"
4543 (abbreviate-file-name buffer-file-name))))
4544 (regexp org-tr-regexp)
4545 (d0 (calendar-absolute-from-gregorian date))
4546 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4548 (goto-char (point-min))
4549 (while (re-search-forward regexp nil t)
4553 (setq timestr (match-string 0)
4556 d1 (time-to-days (org-time-string-to-time s1))
4557 d2 (time-to-days (org-time-string-to-time s2)))
4558 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4559 ;; Only allow days between the limits, because the normal
4560 ;; date stamps will catch the limits.
4562 (setq todo-state (org-get-todo-state))
4563 (setq donep (member todo-state org-done-keywords))
4564 (if (and donep org-agenda-skip-timestamp-if-done)
4566 (setq marker (org-agenda-new-marker (point)))
4567 (setq category (org-get-category))
4568 (if (not (re-search-backward "^\\*+ " nil t))
4569 (setq txt org-agenda-no-heading-message)
4570 (goto-char (match-beginning 0))
4571 (setq hdmarker (org-agenda-new-marker (point)))
4572 (setq tags (org-get-tags-at))
4573 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4574 (setq head (match-string 1))
4575 (setq txt (org-format-agenda-item
4577 (nth (if (= d1 d2) 0 1)
4578 org-agenda-timerange-leaders)
4579 (1+ (- d0 d1)) (1+ (- d2 d1)))
4582 (org-add-props txt props
4583 'org-marker marker 'org-hd-marker hdmarker
4584 'type "block" 'date date
4585 'todo-state todo-state
4586 'priority (org-get-priority txt) 'org-category category)
4589 ;; Sort the entries by expiration date.
4592 ;;; Agenda presentation and sorting
4594 (defvar org-prefix-has-time nil
4595 "A flag, set by `org-compile-prefix-format'.
4596 The flag is set if the currently compiled format contains a `%t'.")
4597 (defvar org-prefix-has-tag nil
4598 "A flag, set by `org-compile-prefix-format'.
4599 The flag is set if the currently compiled format contains a `%T'.")
4600 (defvar org-prefix-has-effort nil
4601 "A flag, set by `org-compile-prefix-format'.
4602 The flag is set if the currently compiled format contains a `%e'.")
4603 (defvar org-prefix-category-length nil
4604 "Used by `org-compile-prefix-format' to remember the category field widh.")
4605 (defvar org-prefix-category-max-length nil
4606 "Used by `org-compile-prefix-format' to remember the category field widh.")
4608 (defun org-format-agenda-item (extra txt &optional category tags dotime
4609 noprefix remove-re habitp)
4610 "Format TXT to be inserted into the agenda buffer.
4611 In particular, it adds the prefix and corresponding text properties. EXTRA
4612 must be a string and replaces the `%s' specifier in the prefix format.
4613 CATEGORY (string, symbol or nil) may be used to overrule the default
4614 category taken from local variable or file name. It will replace the `%c'
4615 specifier in the format. DOTIME, when non-nil, indicates that a
4616 time-of-day should be extracted from TXT for sorting of this entry, and for
4617 the `%t' specifier in the format. When DOTIME is a string, this string is
4618 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4619 only the correctly processes TXT should be returned - this is used by
4620 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4621 Any match of REMOVE-RE will be removed from TXT."
4623 ;; Diary entries sometimes have extra whitespace at the beginning
4624 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4626 ;; Fix the tags part in txt
4627 (setq txt (org-agenda-fix-displayed-tags
4629 org-agenda-show-inherited-tags
4630 org-agenda-hide-tags-regexp))
4631 (let* ((category (or category
4633 (if buffer-file-name
4634 (file-name-sans-extension
4635 (file-name-nondirectory buffer-file-name))
4637 ;; time, tag, effort are needed for the eval of the prefix format
4638 (tag (if tags (nth (1- (length tags)) tags) ""))
4640 (ts (if dotime (concat
4641 (if (stringp dotime) dotime "")
4642 (and org-agenda-search-headline-for-time txt))))
4643 (time-of-day (and dotime (org-get-time-of-day ts)))
4644 stamp plain s0 s1 s2 t1 t2 rtn srp l
4645 duration thecategory)
4646 (and (org-mode-p) buffer-file-name
4647 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4648 (when (and dotime time-of-day)
4649 ;; Extract starting and ending time and move them to prefix
4650 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4651 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4652 (setq s0 (match-string 0 ts)
4653 srp (and stamp (match-end 3))
4654 s1 (match-string (if plain 1 2) ts)
4655 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4657 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4658 ;; them, we might want to remove them there to avoid duplication.
4659 ;; The user can turn this off with a variable.
4660 (if (and org-prefix-has-time
4661 org-agenda-remove-times-when-in-prefix (or stamp plain)
4662 (string-match (concat (regexp-quote s0) " *") txt)
4663 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4664 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4665 (= (match-beginning 0) 0)
4667 (setq txt (replace-match "" nil nil txt))))
4668 ;; Normalize the time(s) to 24 hour
4669 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4670 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4671 ;; Compute the duration
4673 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4674 (string-to-number (substring s1 3)))
4676 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4677 (string-to-number (substring s2 3))))
4678 (org-agenda-default-appointment-duration
4679 (+ t1 org-agenda-default-appointment-duration))
4681 (setq duration (if t2 (- t2 t1)))))
4683 (when (and s1 (not s2) org-agenda-default-appointment-duration
4684 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4685 (let ((m (+ (string-to-number (match-string 2 s1))
4686 (* 60 (string-to-number (match-string 1 s1)))
4687 org-agenda-default-appointment-duration))
4689 (setq h (/ m 60) m (- m (* h 60)))
4690 (setq s2 (format "%02d:%02d" h m))))
4692 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4694 ;; Tags are in the string
4695 (if (or (eq org-agenda-remove-tags t)
4696 (and org-agenda-remove-tags
4697 org-prefix-has-tag))
4698 (setq txt (replace-match "" t t txt))
4699 (setq txt (replace-match
4700 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
4701 (match-string 2 txt))
4707 (or (get-text-property 0 'org-hd-marker txt)
4708 (get-text-property 0 'org-marker txt)))
4711 (setq neffort (org-hh:mm-string-to-minutes effort)
4712 effort (setq effort (concat "[" effort "]" )))))
4715 (while (string-match remove-re txt)
4716 (setq txt (replace-match "" t t txt))))
4718 ;; Create the final string
4721 ;; Prepare the variables needed in the eval of the compiled format
4722 (setq time (cond (s2 (concat s1 "-" s2))
4723 (s1 (concat s1 "......"))
4725 extra (or (and (not habitp) extra) "")
4726 category (if (symbolp category) (symbol-name category) category)
4727 thecategory (copy-sequence category))
4728 (if (string-match org-bracket-link-regexp category)
4730 (setq l (if (match-end 3)
4731 (- (match-end 3) (match-beginning 3))
4732 (- (match-end 1) (match-beginning 1))))
4733 (when (< l (or org-prefix-category-length 0))
4734 (setq category (copy-sequence category))
4735 (org-add-props category nil
4736 'extra-space (make-string
4737 (- org-prefix-category-length l 1) ?\ ))))
4738 (if (and org-prefix-category-max-length
4739 (>= (length category) org-prefix-category-max-length))
4740 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
4741 ;; Evaluate the compiled format
4742 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
4744 ;; And finally add the text properties
4745 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
4746 (org-add-props rtn nil
4747 'org-category (if thecategory (downcase thecategory) category)
4748 'tags (mapcar 'org-downcase-keep-props tags)
4749 'org-highest-priority org-highest-priority
4750 'org-lowest-priority org-lowest-priority
4751 'prefix-length (- (length rtn) (length txt))
4752 'time-of-day time-of-day
4755 'effort-minutes neffort
4761 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
4762 "Remove tags string from TXT, and add a modified list of tags.
4763 The modified list may contain inherited tags, and tags matched by
4764 `org-agenda-hide-tags-regexp' will be removed."
4765 (when (or add-inherited hide-re)
4766 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
4767 (setq txt (substring txt 0 (match-beginning 0))))
4770 (mapcar (lambda (tg)
4771 (if (or (and hide-re (string-match hide-re tg))
4772 (and (not add-inherited)
4773 (get-text-property 0 'inherited tg)))
4778 (let ((have-i (get-text-property 0 'inherited (car tags)))
4780 (setq txt (concat txt " :"
4783 (setq i (get-text-property 0 'inherited x))
4784 (if (and have-i (not i))
4790 (if have-i "::" ":"))))))
4793 (defun org-downcase-keep-props (s)
4794 (let ((props (text-properties-at 0 s)))
4795 (setq s (downcase s))
4796 (add-text-properties 0 (length s) props s)
4799 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
4800 (defvar org-agenda-sorting-strategy-selected nil)
4802 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
4804 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
4805 ((and todayp (member 'today (car org-agenda-time-grid))))
4806 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
4807 ((member 'weekly (car org-agenda-time-grid)))
4808 (t (throw 'exit list)))
4809 (let* ((have (delq nil (mapcar
4810 (lambda (x) (get-text-property 1 'time-of-day x))
4812 (string (nth 1 org-agenda-time-grid))
4813 (gridtimes (nth 2 org-agenda-time-grid))
4814 (req (car org-agenda-time-grid))
4815 (remove (member 'remove-match req))
4817 (if (and (member 'require-timed req) (not have))
4818 ;; don't show empty grid
4820 (while (setq time (pop gridtimes))
4821 (unless (and remove (member time have))
4822 (setq time (int-to-string time))
4823 (push (org-format-agenda-item
4825 (concat (substring time 0 -2) ":" (substring time -2)))
4828 1 (length (car new)) 'face 'org-time-grid (car new))))
4829 (if (member 'time-up org-agenda-sorting-strategy-selected)
4831 (append list new)))))
4833 (defun org-compile-prefix-format (key)
4834 "Compile the prefix format into a Lisp form that can be evaluated.
4835 The resulting form is returned and stored in the variable
4836 `org-prefix-format-compiled'."
4837 (setq org-prefix-has-time nil org-prefix-has-tag nil
4838 org-prefix-category-length nil org-prefix-has-effort nil)
4840 ((stringp org-agenda-prefix-format)
4841 org-agenda-prefix-format)
4842 ((assq key org-agenda-prefix-format)
4843 (cdr (assq key org-agenda-prefix-format)))
4844 (t " %-12:c%?-12t% s")))
4846 varform vars var e c f opt)
4847 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4849 (setq var (cdr (assoc (match-string 4 s)
4850 '(("c" . category) ("t" . time) ("s" . extra)
4851 ("T" . tag) ("e" . effort))))
4852 c (or (match-string 3 s) "")
4853 opt (match-beginning 1)
4854 start (1+ (match-beginning 0)))
4855 (if (equal var 'time) (setq org-prefix-has-time t))
4856 (if (equal var 'tag) (setq org-prefix-has-tag t))
4857 (if (equal var 'effort) (setq org-prefix-has-effort t))
4858 (setq f (concat "%" (match-string 2 s) "s"))
4859 (when (equal var 'category)
4860 (setq org-prefix-category-length
4861 (floor (abs (string-to-number (match-string 2 s)))))
4862 (setq org-prefix-category-max-length
4863 (let ((x (match-string 2 s)))
4865 (if (string-match "\\.[0-9]+" x)
4866 (string-to-number (substring (match-string 0 x) 1)))))))
4869 `(if (equal "" ,var)
4871 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
4872 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
4873 (setq s (replace-match "%s" t nil s))
4874 (push varform vars))
4875 (setq vars (nreverse vars))
4876 (setq org-prefix-format-compiled `(format ,s ,@vars))))
4878 (defun org-set-sorting-strategy (key)
4879 (if (symbolp (car org-agenda-sorting-strategy))
4881 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
4882 (setq org-agenda-sorting-strategy-selected
4883 (or (cdr (assq key org-agenda-sorting-strategy))
4884 (cdr (assq 'agenda org-agenda-sorting-strategy))
4885 '(time-up category-keep priority-down)))))
4887 (defun org-get-time-of-day (s &optional string mod24)
4888 "Check string S for a time of day.
4889 If found, return it as a military time number between 0 and 2400.
4890 If not found, return nil.
4891 The optional STRING argument forces conversion into a 5 character wide string
4895 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
4896 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
4897 (let* ((h (string-to-number (match-string 1 s)))
4898 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
4899 (ampm (if (match-end 4) (downcase (match-string 4 s))))
4900 (am-p (equal ampm "am"))
4901 (h1 (cond ((not ampm) h)
4902 ((= h 12) (if am-p 0 12))
4903 (t (+ h (if am-p 0 12)))))
4904 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
4906 (t0 (+ (* 100 h2) m))
4907 (t1 (concat (if (>= h1 24) "+" " ")
4908 (if (< t0 100) "0" "")
4909 (if (< t0 10) "0" "")
4910 (int-to-string t0))))
4911 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
4913 (defun org-finalize-agenda-entries (list &optional nosort)
4914 "Sort and concatenate the agenda items."
4915 (setq list (mapcar 'org-agenda-highlight-todo list))
4918 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
4920 (defun org-agenda-highlight-todo (x)
4921 (let ((org-done-keywords org-done-keywords-for-agenda)
4922 (case-fold-search nil)
4926 (beginning-of-line 1)
4927 (setq re (org-get-at-bol 'org-todo-regexp))
4928 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
4929 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
4930 (add-text-properties (match-beginning 0) (match-end 1)
4931 (list 'face (org-get-todo-face 1)))
4932 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4933 (delete-region (match-beginning 1) (1- (match-end 0)))
4934 (goto-char (match-beginning 1))
4935 (insert (format org-agenda-todo-keyword-format s)))))
4936 (setq re (concat (get-text-property 0 'org-todo-regexp x))
4937 pl (get-text-property 0 'prefix-length x))
4939 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
4941 (add-text-properties
4942 (or (match-end 1) (match-end 0)) (match-end 0)
4943 (list 'face (org-get-todo-face (match-string 2 x)))
4945 (setq x (concat (substring x 0 (match-end 1))
4946 (format org-agenda-todo-keyword-format
4948 (org-add-props " " (text-properties-at 0 x))
4949 (substring x (match-end 3)))))
4952 (defsubst org-cmp-priority (a b)
4953 "Compare the priorities of string A and B."
4954 (let ((pa (or (get-text-property 1 'priority a) 0))
4955 (pb (or (get-text-property 1 'priority b) 0)))
4956 (cond ((> pa pb) +1)
4960 (defsubst org-cmp-effort (a b)
4961 "Compare the priorities of string A and B."
4962 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
4963 (ea (or (get-text-property 1 'effort-minutes a) def))
4964 (eb (or (get-text-property 1 'effort-minutes b) def)))
4965 (cond ((> ea eb) +1)
4969 (defsubst org-cmp-category (a b)
4970 "Compare the string values of categories of strings A and B."
4971 (let ((ca (or (get-text-property 1 'org-category a) ""))
4972 (cb (or (get-text-property 1 'org-category b) "")))
4973 (cond ((string-lessp ca cb) -1)
4974 ((string-lessp cb ca) +1)
4977 (defsubst org-cmp-todo-state (a b)
4978 "Compare the todo states of strings A and B."
4979 (let* ((ma (or (get-text-property 1 'org-marker a)
4980 (get-text-property 1 'org-hd-marker a)))
4981 (mb (or (get-text-property 1 'org-marker b)
4982 (get-text-property 1 'org-hd-marker b)))
4983 (fa (and ma (marker-buffer ma)))
4984 (fb (and mb (marker-buffer mb)))
4986 (or (and fa (with-current-buffer fa org-todo-keywords-1))
4987 (and fb (with-current-buffer fb org-todo-keywords-1))))
4988 (ta (or (get-text-property 1 'todo-state a) ""))
4989 (tb (or (get-text-property 1 'todo-state b) ""))
4990 (la (- (length (member ta todo-kwds))))
4991 (lb (- (length (member tb todo-kwds))))
4992 (donepa (member ta org-done-keywords-for-agenda))
4993 (donepb (member tb org-done-keywords-for-agenda)))
4994 (cond ((and donepa (not donepb)) -1)
4995 ((and (not donepa) donepb) +1)
5000 (defsubst org-cmp-tag (a b)
5001 "Compare the string values of the first tags of A and B."
5002 (let ((ta (car (last (get-text-property 1 'tags a))))
5003 (tb (car (last (get-text-property 1 'tags b)))))
5006 ((string-lessp ta tb) -1)
5007 ((string-lessp tb ta) +1)
5010 (defsubst org-cmp-time (a b)
5011 "Compare the time-of-day values of strings A and B."
5012 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5013 (ta (or (get-text-property 1 'time-of-day a) def))
5014 (tb (or (get-text-property 1 'time-of-day b) def)))
5015 (cond ((< ta tb) -1)
5019 (defsubst org-cmp-habit-p (a b)
5020 "Compare the todo states of strings A and B."
5021 (let ((ha (get-text-property 1 'org-habit-p a))
5022 (hb (get-text-property 1 'org-habit-p b)))
5023 (cond ((and ha (not hb)) -1)
5024 ((and (not ha) hb) +1)
5027 (defun org-entries-lessp (a b)
5028 "Predicate for sorting agenda entries."
5029 ;; The following variables will be used when the form is evaluated.
5030 ;; So even though the compiler complains, keep them.
5031 (let* ((time-up (org-cmp-time a b))
5032 (time-down (if time-up (- time-up) nil))
5033 (priority-up (org-cmp-priority a b))
5034 (priority-down (if priority-up (- priority-up) nil))
5035 (effort-up (org-cmp-effort a b))
5036 (effort-down (if effort-up (- effort-up) nil))
5037 (category-up (org-cmp-category a b))
5038 (category-down (if category-up (- category-up) nil))
5039 (category-keep (if category-up +1 nil))
5040 (tag-up (org-cmp-tag a b))
5041 (tag-down (if tag-up (- tag-up) nil))
5042 (todo-state-up (org-cmp-todo-state a b))
5043 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5044 (habit-up (org-cmp-habit-p a b))
5045 (habit-down (if habit-up (- habit-up) nil))
5046 user-defined-up user-defined-down)
5047 (if (and org-agenda-cmp-user-defined
5048 (functionp org-agenda-cmp-user-defined))
5049 (setq user-defined-up
5050 (funcall org-agenda-cmp-user-defined a b)
5051 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5053 (eval (cons 'or org-agenda-sorting-strategy-selected))
5054 '((-1 . t) (1 . nil) (nil . nil))))))
5056 ;;; Agenda restriction lock
5058 (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
5059 "Overlay to mark the headline to which agenda commands are restricted.")
5060 (org-overlay-put org-agenda-restriction-lock-overlay
5061 'face 'org-agenda-restriction-lock)
5062 (org-overlay-put org-agenda-restriction-lock-overlay
5063 'help-echo "Agendas are currently limited to this subtree.")
5064 (org-detach-overlay org-agenda-restriction-lock-overlay)
5066 (defun org-agenda-set-restriction-lock (&optional type)
5067 "Set restriction lock for agenda, to current subtree or file.
5068 Restriction will be the file if TYPE is `file', or if type is the
5069 universal prefix '(4), or if the cursor is before the first headline
5070 in the file. Otherwise, restriction will be to the current subtree."
5072 (and (equal type '(4)) (setq type 'file))
5075 ((org-at-heading-p) 'subtree)
5076 ((condition-case nil (org-back-to-heading t) (error nil))
5079 (if (eq type 'subtree)
5081 (setq org-agenda-restrict t)
5082 (setq org-agenda-overriding-restriction 'subtree)
5083 (put 'org-agenda-files 'org-restrict
5084 (list (buffer-file-name (buffer-base-buffer))))
5085 (org-back-to-heading t)
5086 (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5087 (move-marker org-agenda-restrict-begin (point))
5088 (move-marker org-agenda-restrict-end
5089 (save-excursion (org-end-of-subtree t)))
5090 (message "Locking agenda restriction to subtree"))
5091 (put 'org-agenda-files 'org-restrict
5092 (list (buffer-file-name (buffer-base-buffer))))
5093 (setq org-agenda-restrict nil)
5094 (setq org-agenda-overriding-restriction 'file)
5095 (move-marker org-agenda-restrict-begin nil)
5096 (move-marker org-agenda-restrict-end nil)
5097 (message "Locking agenda restriction to file"))
5098 (setq current-prefix-arg nil)
5099 (org-agenda-maybe-redo))
5101 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5102 "Remove the agenda restriction lock."
5104 (org-detach-overlay org-agenda-restriction-lock-overlay)
5105 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5106 (setq org-agenda-overriding-restriction nil)
5107 (setq org-agenda-restrict nil)
5108 (put 'org-agenda-files 'org-restrict nil)
5109 (move-marker org-agenda-restrict-begin nil)
5110 (move-marker org-agenda-restrict-end nil)
5111 (setq current-prefix-arg nil)
5112 (message "Agenda restriction lock removed")
5113 (or noupdate (org-agenda-maybe-redo)))
5115 (defun org-agenda-maybe-redo ()
5116 "If there is any window showing the agenda view, update it."
5117 (let ((w (get-buffer-window org-agenda-buffer-name t))
5118 (w0 (selected-window)))
5123 (if org-agenda-overriding-restriction
5124 (message "Agenda view shifted to new %s restriction"
5125 org-agenda-overriding-restriction)
5126 (message "Agenda restriction lock removed")))))
5130 (defun org-agenda-check-type (error &rest types)
5131 "Check if agenda buffer is of allowed type.
5132 If ERROR is non-nil, throw an error, otherwise just return nil."
5133 (if (memq org-agenda-type types)
5136 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5139 (defun org-agenda-quit ()
5140 "Exit agenda by removing the window or the buffer."
5142 (if org-agenda-columns-active
5144 (let ((buf (current-buffer)))
5145 (if (eq org-agenda-window-setup 'other-frame)
5148 (org-agenda-reset-markers)
5149 (org-columns-remove-overlays)
5150 (setq org-agenda-archives-mode nil)
5152 (and (not (eq org-agenda-window-setup 'current-window))
5153 (not (one-window-p))
5156 (org-agenda-reset-markers)
5157 (org-columns-remove-overlays)
5158 (setq org-agenda-archives-mode nil)))
5159 ;; Maybe restore the pre-agenda window configuration.
5160 (and org-agenda-restore-windows-after-quit
5161 (not (eq org-agenda-window-setup 'other-frame))
5162 org-pre-agenda-window-conf
5163 (set-window-configuration org-pre-agenda-window-conf))))
5165 (defun org-agenda-exit ()
5166 "Exit agenda by removing the window or the buffer.
5167 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5168 Org-mode buffers visited directly by the user will not be touched."
5170 (org-release-buffers org-agenda-new-buffers)
5171 (setq org-agenda-new-buffers nil)
5174 (defun org-agenda-execute (arg)
5175 "Execute another agenda command, keeping same window.\\<global-map>
5176 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
5178 (let ((org-agenda-window-setup 'current-window))
5181 (defun org-agenda-redo ()
5183 When this is the global TODO list, a prefix argument will be interpreted."
5185 (let* ((org-agenda-keep-modes t)
5186 (filter org-agenda-filter)
5187 (preset (get 'org-agenda-filter :preset-filter))
5188 (cols org-agenda-columns-active)
5189 (line (org-current-line))
5190 (window-line (- line (org-current-line (window-start))))
5191 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5192 (put 'org-agenda-filter :preset-filter nil)
5193 (and cols (org-columns-quit))
5194 (message "Rebuilding agenda buffer...")
5195 (org-let lprops '(eval org-agenda-redo-command))
5196 (setq org-agenda-undo-list nil
5197 org-agenda-pending-undo-list nil)
5198 (message "Rebuilding agenda buffer...done")
5199 (put 'org-agenda-filter :preset-filter preset)
5200 (and (or filter preset) (org-agenda-filter-apply filter))
5201 (and cols (interactive-p) (org-agenda-columns))
5202 (org-goto-line line)
5203 (recenter window-line)))
5206 (defvar org-global-tags-completion-table nil)
5207 (defvar org-agenda-filter-form nil)
5208 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5209 "Keep only those lines in the agenda buffer that have a specific tag.
5210 The tag is selected with its fast selection letter, as configured.
5211 With prefix argument STRIP, remove all lines that do have the tag.
5212 A lisp caller can specify CHAR. NARROW means that the new tag should be
5213 used to narrow the search - the interactive user can also press `-' or `+'
5214 to switch to narrowing."
5216 (let* ((alist org-tag-alist-for-agenda)
5217 (tag-chars (mapconcat
5218 (lambda (x) (if (and (not (symbolp (car x)))
5220 (char-to-string (cdr x))
5223 (efforts (org-split-string
5224 (or (cdr (assoc (concat org-effort-property "_ALL")
5225 org-global-properties))
5226 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5227 (effort-op org-agenda-filter-effort-default-operator)
5229 (inhibit-read-only t)
5230 (current org-agenda-filter)
5234 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5235 (if narrow "Narrow" "Filter") tag-chars
5236 (if org-agenda-auto-exclude-function "[RET], " ""))
5237 (setq char (read-char)))
5238 (when (member char '(?+ ?-))
5240 (cond ((equal char ?-) (setq strip t narrow t))
5241 ((equal char ?+) (setq strip nil narrow t)))
5243 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5244 (setq char (read-char)))
5245 (when (member char '(?< ?> ?= ??))
5246 ;; An effort operator
5247 (setq effort-op (char-to-string char))
5248 (setq alist nil) ; to make sure it will be interpreted as effort.
5249 (unless (equal char ??)
5250 (loop for i from 0 to 9 do
5254 (if (= i 9) "0" (int-to-string (1+ i)))
5255 "]" (nth i efforts))))
5256 (message "Effort%s: %s " effort-op effort-prompt)
5257 (setq char (read-char))
5258 (when (or (< char ?0) (> char ?9))
5259 (error "Need 1-9,0 to select effort" ))))
5260 (when (equal char ?\t)
5261 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5262 (org-set-local 'org-global-tags-completion-table
5263 (org-global-tags-completion-table)))
5264 (let ((completion-ignore-case t))
5265 (setq tag (org-icompleting-read
5266 "Tag: " org-global-tags-completion-table))))
5269 (org-agenda-filter-by-tag-show-all)
5270 (when org-agenda-auto-exclude-function
5271 (setq org-agenda-filter '())
5272 (dolist (tag (org-agenda-get-represented-tags))
5273 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5275 (push modifier org-agenda-filter))))
5276 (if (not (null org-agenda-filter))
5277 (org-agenda-filter-apply org-agenda-filter))))
5279 (org-agenda-filter-by-tag-show-all)
5280 (when (get 'org-agenda-filter :preset-filter)
5281 (org-agenda-filter-apply org-agenda-filter)))
5282 ((or (equal char ?\ )
5283 (setq a (rassoc char alist))
5284 (and (>= char ?0) (<= char ?9)
5285 (setq n (if (= char ?0) 9 (- char ?0 1))
5286 tag (concat effort-op (nth n efforts))
5291 (and tag (setq a (cons tag nil))))
5292 (org-agenda-filter-by-tag-show-all)
5294 (setq org-agenda-filter
5295 (cons (concat (if strip "-" "+") tag)
5296 (if narrow current nil)))
5297 (org-agenda-filter-apply org-agenda-filter))
5298 (t (error "Invalid tag selection character %c" char)))))
5300 (defun org-agenda-get-represented-tags ()
5301 "Get a list of all tags currently represented in the agenda."
5304 (goto-char (point-min))
5305 (while (setq p (next-single-property-change (point) 'tags))
5307 (mapc (lambda (x) (add-to-list 'tags x))
5308 (get-text-property (point) 'tags))))
5311 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5312 "Refine the current filter. See `org-agenda-filter-by-tag."
5314 (org-agenda-filter-by-tag strip char 'refine))
5316 (defun org-agenda-filter-make-matcher ()
5317 "Create the form that tests a line for the agenda filter."
5319 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5321 (if (member x '("-" "+"))
5322 (setq f1 (if (equal x "-") 'tags '(not tags)))
5323 (if (string-match "[<=>?]" x)
5324 (setq f1 (org-agenda-filter-effort-form x))
5325 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5326 (if (equal (string-to-char x) ?-)
5327 (setq f1 (list 'not f1))))
5329 (cons 'and (nreverse f))))
5331 (defun org-agenda-filter-effort-form (e)
5332 "Return the form to compare the effort of the current line with what E says.
5333 E looks line \"+<2:25\"."
5335 (setq e (substring e 1))
5336 (setq op (string-to-char e) e (substring e 1))
5337 (setq op (cond ((equal op ?<) '<=)
5341 (list 'org-agenda-compare-effort (list 'quote op)
5342 (org-hh:mm-string-to-minutes e))))
5344 (defun org-agenda-compare-effort (op value)
5345 "Compare the effort of the current line with VALUE, using OP.
5346 If the line does not have an effort defined, return nil."
5347 (let ((eff (org-get-at-bol 'effort-minutes)))
5350 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5353 (defun org-agenda-filter-apply (filter)
5354 "Set FILTER as the new agenda filter and apply it."
5356 (setq org-agenda-filter filter
5357 org-agenda-filter-form (org-agenda-filter-make-matcher))
5358 (org-agenda-set-mode-name)
5360 (goto-char (point-min))
5362 (if (org-get-at-bol 'org-marker)
5364 (setq tags (org-get-at-bol 'tags)) ; used in eval
5365 (if (not (eval org-agenda-filter-form))
5366 (org-agenda-filter-by-tag-hide-line))
5367 (beginning-of-line 2))
5368 (beginning-of-line 2))))))
5370 (defun org-agenda-filter-by-tag-hide-line ()
5372 (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
5374 (org-overlay-put ov 'invisible t)
5375 (org-overlay-put ov 'type 'tags-filter)
5376 (push ov org-agenda-filter-overlays)))
5378 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5379 (setq pos (or pos (point)))
5381 (dolist (ov (org-overlays-at pos))
5382 (when (and (org-overlay-get ov 'invisible)
5383 (eq (org-overlay-get ov 'type) 'tags-filter))
5385 (if (< (org-overlay-start ov) (point-at-eol))
5386 (org-move-overlay ov (point-at-eol)
5387 (org-overlay-end ov)))))))
5389 (defun org-agenda-filter-by-tag-show-all ()
5390 (mapc 'org-delete-overlay org-agenda-filter-overlays)
5391 (setq org-agenda-filter-overlays nil)
5392 (setq org-agenda-filter nil)
5393 (setq org-agenda-filter-form nil)
5394 (org-agenda-set-mode-name))
5396 (defun org-agenda-manipulate-query-add ()
5397 "Manipulate the query by adding a search term with positive selection.
5398 Positive selection means, the term must be matched for selection of an entry."
5400 (org-agenda-manipulate-query ?\[))
5401 (defun org-agenda-manipulate-query-subtract ()
5402 "Manipulate the query by adding a search term with negative selection.
5403 Negative selection means, term must not be matched for selection of an entry."
5405 (org-agenda-manipulate-query ?\]))
5406 (defun org-agenda-manipulate-query-add-re ()
5407 "Manipulate the query by adding a search regexp with positive selection.
5408 Positive selection means, the regexp must match for selection of an entry."
5410 (org-agenda-manipulate-query ?\{))
5411 (defun org-agenda-manipulate-query-subtract-re ()
5412 "Manipulate the query by adding a search regexp with negative selection.
5413 Negative selection means, regexp must not match for selection of an entry."
5415 (org-agenda-manipulate-query ?\}))
5416 (defun org-agenda-manipulate-query (char)
5418 ((memq org-agenda-type '(timeline agenda))
5419 (let ((org-agenda-include-inactive-timestamps t))
5421 (message "Display now includes inactive timestamps as well"))
5422 ((eq org-agenda-type 'search)
5424 'org-agenda-query-string
5425 (if org-agenda-last-search-view-search-was-boolean
5426 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5427 (?\{ . " +{}") (?\} . " -{}"))))
5429 (setq org-agenda-redo-command
5430 (list 'org-search-view
5432 org-agenda-query-string
5433 (+ (length org-agenda-query-string)
5434 (if (member char '(?\{ ?\})) 0 1))))
5435 (set-register org-agenda-query-register org-agenda-query-string)
5437 (t (error "Cannot manipulate query for %s-type agenda buffers"
5440 (defun org-add-to-string (var string)
5441 (set var (concat (symbol-value var) string)))
5443 (defun org-agenda-goto-date (date)
5444 "Jump to DATE in agenda."
5445 (interactive (list (org-read-date)))
5446 (org-agenda-list nil date))
5448 (defun org-agenda-goto-today ()
5451 (org-agenda-check-type t 'timeline 'agenda)
5452 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5454 (tdpos (goto-char tdpos))
5455 ((eq org-agenda-type 'agenda)
5456 (let* ((sd (time-to-days
5457 (time-subtract (current-time)
5458 (list 0 (* 3600 org-extend-today-until) 0))))
5459 (comp (org-agenda-compute-time-span sd org-agenda-span))
5460 (org-agenda-overriding-arguments org-agenda-last-arguments))
5461 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5462 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5464 (org-agenda-find-same-or-today-or-agenda)))
5465 (t (error "Cannot find today")))))
5467 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5469 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5470 (text-property-any (point-min) (point-max) 'org-today t)
5471 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5474 (defun org-agenda-later (arg)
5475 "Go forward in time by thee current span.
5476 With prefix ARG, go forward that many times the current span."
5478 (org-agenda-check-type t 'agenda)
5479 (let* ((span org-agenda-span)
5480 (sd org-starting-day)
5481 (greg (calendar-gregorian-from-absolute sd))
5482 (cnt (org-get-at-bol 'org-day-cnt))
5486 (setq sd (+ arg sd) nd 1))
5488 (setq sd (+ (* 7 arg) sd) nd 7))
5490 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5491 sd (calendar-absolute-from-gregorian greg2))
5492 (setcar greg2 (1+ (car greg2)))
5493 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5495 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5496 sd (calendar-absolute-from-gregorian greg2))
5497 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5498 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5499 (let ((org-agenda-overriding-arguments
5500 (list (car org-agenda-last-arguments) sd nd t)))
5502 (org-agenda-find-same-or-today-or-agenda cnt))))
5504 (defun org-agenda-earlier (arg)
5505 "Go backward in time by the current span.
5506 With prefix ARG, go backward that many times the current span."
5508 (org-agenda-later (- arg)))
5510 (defun org-agenda-view-mode-dispatch ()
5511 "Call one of the view mode commands."
5513 (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
5514 clock[R]eport time[G]rid [[]inactive [E]ntryText include[D]iary")
5515 (let ((a (read-char-exclusive)))
5517 (?d (call-interactively 'org-agenda-day-view))
5518 (?w (call-interactively 'org-agenda-week-view))
5519 (?m (call-interactively 'org-agenda-month-view))
5520 (?y (call-interactively 'org-agenda-year-view))
5521 (?l (call-interactively 'org-agenda-log-mode))
5522 (?L (org-agenda-log-mode '(4)))
5523 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5524 (?a (call-interactively 'org-agenda-archives-mode))
5525 (?A (org-agenda-archives-mode 'files))
5526 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5527 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5528 (?G (call-interactively 'org-agenda-toggle-time-grid))
5529 (?D (call-interactively 'org-agenda-toggle-diary))
5530 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5531 (org-agenda-check-type t 'timeline 'agenda)
5533 (message "Display now includes inactive timestamps as well"))
5534 (?q (message "Abort"))
5535 (otherwise (error "Invalid key" )))))
5537 (defun org-agenda-day-view (&optional day-of-year)
5538 "Switch to daily view for agenda.
5539 With argument DAY-OF-YEAR, switch to that day of the year."
5541 (setq org-agenda-ndays 1)
5542 (org-agenda-change-time-span 'day day-of-year))
5543 (defun org-agenda-week-view (&optional iso-week)
5544 "Switch to daily view for agenda.
5545 With argument ISO-WEEK, switch to the corresponding ISO week.
5546 If ISO-WEEK has more then 2 digits, only the last two encode the
5547 week. Any digits before this encode a year. So 200712 means
5548 week 12 of year 2007. Years in the range 1938-2037 can also be
5549 written as 2-digit years."
5551 (setq org-agenda-ndays 7)
5552 (org-agenda-change-time-span 'week iso-week))
5553 (defun org-agenda-month-view (&optional month)
5554 "Switch to monthly view for agenda.
5555 With argument MONTH, switch to that month."
5557 (org-agenda-change-time-span 'month month))
5558 (defun org-agenda-year-view (&optional year)
5559 "Switch to yearly view for agenda.
5560 With argument YEAR, switch to that year.
5561 If MONTH has more then 2 digits, only the last two encode the
5562 month. Any digits before this encode a year. So 200712 means
5563 December year 2007. Years in the range 1938-2037 can also be
5564 written as 2-digit years."
5567 (setq year (org-small-year-to-year year)))
5568 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5569 (org-agenda-change-time-span 'year year)
5572 (defun org-agenda-change-time-span (span &optional n)
5573 "Change the agenda view to SPAN.
5574 SPAN may be `day', `week', `month', `year'."
5575 (org-agenda-check-type t 'agenda)
5576 (if (and (not n) (equal org-agenda-span span))
5577 (error "Viewing span is already \"%s\"" span))
5578 (let* ((sd (or (org-get-at-bol 'day)
5580 (computed (org-agenda-compute-time-span sd span n))
5581 (org-agenda-overriding-arguments
5582 (list (car org-agenda-last-arguments)
5583 (car computed) (cdr computed) t)))
5585 (org-agenda-find-same-or-today-or-agenda))
5586 (org-agenda-set-mode-name)
5587 (message "Switched to %s view" span))
5589 (defun org-agenda-compute-time-span (sd span &optional n)
5590 "Compute starting date and number of days for agenda.
5591 SPAN may be `day', `week', `month', `year'. The return value
5592 is a cons cell with the starting date and the number of days,
5593 so that the date SD will be in that range."
5594 (let* ((greg (calendar-gregorian-from-absolute sd))
5598 nd w1 y1 m1 thisweek)
5602 (setq sd (+ (calendar-absolute-from-gregorian
5607 (let* ((nt (calendar-day-of-week
5608 (calendar-gregorian-from-absolute sd)))
5609 (d (if org-agenda-start-on-weekday
5610 (- nt org-agenda-start-on-weekday)
5612 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5615 (setq thisweek (car (calendar-iso-from-absolute sd)))
5617 (setq y1 (org-small-year-to-year (/ n 100))
5620 (calendar-absolute-from-iso
5622 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5625 (when (and n (> n 99))
5626 (setq y1 (org-small-year-to-year (/ n 100))
5628 (setq sd (calendar-absolute-from-gregorian
5629 (list (or n mg) 1 (or y1 yg)))
5630 nd (- (calendar-absolute-from-gregorian
5631 (list (1+ (or n mg)) 1 (or y1 yg)))
5634 (setq sd (calendar-absolute-from-gregorian
5635 (list 1 1 (or n yg)))
5636 nd (- (calendar-absolute-from-gregorian
5637 (list 1 1 (1+ (or n yg))))
5641 (defun org-agenda-next-date-line (&optional arg)
5642 "Jump to the next line indicating a date in agenda buffer."
5644 (org-agenda-check-type t 'agenda 'timeline)
5645 (beginning-of-line 1)
5646 ;; This does not work if user makes date format that starts with a blank
5647 (if (looking-at "^\\S-") (forward-char 1))
5648 (if (not (re-search-forward "^\\S-" nil t arg))
5651 (error "No next date after this line in this buffer")))
5652 (goto-char (match-beginning 0)))
5654 (defun org-agenda-previous-date-line (&optional arg)
5655 "Jump to the previous line indicating a date in agenda buffer."
5657 (org-agenda-check-type t 'agenda 'timeline)
5658 (beginning-of-line 1)
5659 (if (not (re-search-backward "^\\S-" nil t arg))
5660 (error "No previous date before this line in this buffer")))
5662 ;; Initialize the highlight
5663 (defvar org-hl (org-make-overlay 1 1))
5664 (org-overlay-put org-hl 'face 'highlight)
5666 (defun org-highlight (begin end &optional buffer)
5667 "Highlight a region with overlay."
5668 (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
5669 org-hl begin end (or buffer (current-buffer))))
5671 (defun org-unhighlight ()
5672 "Detach overlay INDEX."
5673 (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
5675 ;; FIXME this is currently not used.
5676 (defun org-highlight-until-next-command (beg end &optional buffer)
5677 "Move the highlight overlay to BEG/END, remove it before the next command."
5678 (org-highlight beg end buffer)
5679 (add-hook 'pre-command-hook 'org-unhighlight-once))
5680 (defun org-unhighlight-once ()
5681 "Remove the highlight from its position, and this function from the hook."
5682 (remove-hook 'pre-command-hook 'org-unhighlight-once)
5685 (defun org-agenda-follow-mode ()
5686 "Toggle follow mode in an agenda buffer."
5688 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
5689 (org-agenda-set-mode-name)
5690 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5692 (message "Follow mode is %s"
5693 (if org-agenda-follow-mode "on" "off")))
5695 (defun org-agenda-entry-text-mode (&optional arg)
5696 "Toggle entry text mode in an agenda buffer."
5699 (setq org-agenda-entry-text-mode t)
5700 (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
5701 (org-agenda-entry-text-hide)
5702 (and org-agenda-entry-text-mode
5703 (let ((org-agenda-entry-text-maxlines
5704 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5705 (org-agenda-entry-text-show)))
5706 (org-agenda-set-mode-name)
5707 (message "Entry text mode is %s. Maximum number of lines is %d"
5708 (if org-agenda-entry-text-mode "on" "off")
5709 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5711 (defun org-agenda-clockreport-mode ()
5712 "Toggle clocktable mode in an agenda buffer."
5714 (org-agenda-check-type t 'agenda)
5715 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
5716 (org-agenda-set-mode-name)
5718 (message "Clocktable mode is %s"
5719 (if org-agenda-clockreport-mode "on" "off")))
5721 (defun org-agenda-log-mode (&optional special)
5722 "Toggle log mode in an agenda buffer.
5723 With argument SPECIAL, show all possible log items, not only the ones
5724 configured in `org-agenda-log-mode-items'.
5725 With a double `C-u' prefix arg, show *only* log items, nothing else."
5727 (org-agenda-check-type t 'agenda 'timeline)
5728 (setq org-agenda-show-log
5729 (if (equal special '(16))
5731 (if special '(closed clock state)
5732 (not org-agenda-show-log))))
5733 (org-agenda-set-mode-name)
5735 (message "Log mode is %s"
5736 (if org-agenda-show-log "on" "off")))
5738 (defun org-agenda-archives-mode (&optional with-files)
5739 "Toggle inclusion of items in trees marked with :ARCHIVE:.
5740 When called with a prefix argument, include all archive files as well."
5742 (setq org-agenda-archives-mode
5743 (if with-files t (if org-agenda-archives-mode nil 'trees)))
5744 (org-agenda-set-mode-name)
5749 ((eq org-agenda-archives-mode nil)
5750 "No archives are included")
5751 ((eq org-agenda-archives-mode 'trees)
5752 (format "Trees with :%s: tag are included" org-archive-tag))
5753 ((eq org-agenda-archives-mode t)
5754 (format "Trees with :%s: tag and all active archive files are included"
5755 org-archive-tag)))))
5757 (defun org-agenda-toggle-diary ()
5758 "Toggle diary inclusion in an agenda buffer."
5760 (org-agenda-check-type t 'agenda)
5761 (setq org-agenda-include-diary (not org-agenda-include-diary))
5763 (org-agenda-set-mode-name)
5764 (message "Diary inclusion turned %s"
5765 (if org-agenda-include-diary "on" "off")))
5767 (defun org-agenda-toggle-time-grid ()
5768 "Toggle time grid in an agenda buffer."
5770 (org-agenda-check-type t 'agenda)
5771 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
5773 (org-agenda-set-mode-name)
5774 (message "Time-grid turned %s"
5775 (if org-agenda-use-time-grid "on" "off")))
5777 (defun org-agenda-set-mode-name ()
5778 "Set the mode name to indicate all the small mode settings."
5780 (concat "Org-Agenda"
5781 (if (equal org-agenda-ndays 1) " Day" "")
5782 (if (equal org-agenda-ndays 7) " Week" "")
5783 (if org-agenda-follow-mode " Follow" "")
5784 (if org-agenda-entry-text-mode " ETxt" "")
5785 (if org-agenda-include-diary " Diary" "")
5786 (if org-agenda-use-time-grid " Grid" "")
5787 (if (and (boundp 'org-habit-show-habits)
5788 org-habit-show-habits) " Habit" "")
5789 (if (consp org-agenda-show-log) " LogAll"
5790 (if org-agenda-show-log " Log" ""))
5791 (if (or org-agenda-filter (get 'org-agenda-filter
5793 (concat " {" (mapconcat
5795 (append (get 'org-agenda-filter
5797 org-agenda-filter) "") "}")
5799 (if org-agenda-archives-mode
5800 (if (eq org-agenda-archives-mode t)
5802 (format " :%s:" org-archive-tag))
5804 (if org-agenda-clockreport-mode " Clock" "")))
5805 (force-mode-line-update))
5807 (defun org-agenda-post-command-hook ()
5808 (setq org-agenda-type
5809 (or (get-text-property (point) 'org-agenda-type)
5810 (get-text-property (max (point-min) (1- (point)))
5811 'org-agenda-type))))
5813 (defun org-agenda-next-line ()
5814 "Move cursor to the next line, and show if follow-mode is active."
5816 (call-interactively 'next-line)
5817 (org-agenda-do-context-action))
5819 (defun org-agenda-previous-line ()
5820 "Move cursor to the previous line, and show if follow-mode is active."
5823 (call-interactively 'previous-line)
5824 (org-agenda-do-context-action))
5826 (defun org-agenda-do-context-action ()
5827 "Show outline path and, maybe, follow-mode window."
5828 (let ((m (org-get-at-bol 'org-marker)))
5829 (if (and org-agenda-follow-mode m)
5831 (if (and m org-agenda-show-outline-path)
5832 (org-with-point-at m
5833 (org-display-outline-path t)))))
5835 (defun org-agenda-show-priority ()
5836 "Show the priority of the current item.
5837 This priority is composed of the main priority given with the [#A] cookies,
5838 and by additional input from the age of a schedules or deadline entry."
5840 (let* ((pri (org-get-at-bol 'priority)))
5841 (message "Priority is %d" (if pri pri -1000))))
5843 (defun org-agenda-show-tags ()
5844 "Show the tags applicable to the current item."
5846 (let* ((tags (org-get-at-bol 'tags)))
5848 (message "Tags are :%s:"
5849 (org-no-properties (mapconcat 'identity tags ":")))
5850 (message "No tags associated with this line"))))
5852 (defun org-agenda-goto (&optional highlight)
5853 "Go to the Org-mode file which contains the item at point."
5855 (let* ((marker (or (org-get-at-bol 'org-marker)
5856 (org-agenda-error)))
5857 (buffer (marker-buffer marker))
5858 (pos (marker-position marker)))
5859 (switch-to-buffer-other-window buffer)
5863 (org-show-context 'agenda)
5865 (and (outline-next-heading)
5866 (org-flag-heading nil)))) ; show the next heading
5867 (recenter (/ (window-height) 2))
5868 (run-hooks 'org-agenda-after-show-hook)
5869 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
5871 (defvar org-agenda-after-show-hook nil
5872 "Normal hook run after an item has been shown from the agenda.
5873 Point is in the buffer where the item originated.")
5875 (defun org-agenda-kill ()
5876 "Kill the entry or subtree belonging to the current agenda entry."
5878 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5879 (let* ((marker (or (org-get-at-bol 'org-marker)
5880 (org-agenda-error)))
5881 (buffer (marker-buffer marker))
5882 (pos (marker-position marker))
5883 (type (org-get-at-bol 'type))
5884 dbeg dend (n 0) conf)
5885 (org-with-remote-undo buffer
5886 (with-current-buffer buffer
5889 (if (and (org-mode-p) (not (member type '("sexp"))))
5890 (setq dbeg (progn (org-back-to-heading t) (point))
5891 dend (org-end-of-subtree t t))
5892 (setq dbeg (point-at-bol)
5893 dend (min (point-max) (1+ (point-at-eol)))))
5895 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
5896 (setq conf (or (eq t org-agenda-confirm-kill)
5897 (and (numberp org-agenda-confirm-kill)
5898 (> n org-agenda-confirm-kill))))
5901 (format "Delete entry with %d lines in buffer \"%s\"? "
5902 n (buffer-name buffer))))
5904 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
5905 (with-current-buffer buffer (delete-region dbeg dend))
5906 (message "Agenda item and source killed"))))
5908 (defvar org-archive-default-command)
5909 (defun org-agenda-archive-default ()
5910 "Archive the entry or subtree belonging to the current agenda entry."
5912 (require 'org-archive)
5913 (org-agenda-archive-with org-archive-default-command))
5915 (defun org-agenda-archive-default-with-confirmation ()
5916 "Archive the entry or subtree belonging to the current agenda entry."
5918 (require 'org-archive)
5919 (org-agenda-archive-with org-archive-default-command 'confirm))
5921 (defun org-agenda-archive ()
5922 "Archive the entry or subtree belonging to the current agenda entry."
5924 (org-agenda-archive-with 'org-archive-subtree))
5926 (defun org-agenda-archive-to-archive-sibling ()
5927 "Move the entry to the archive sibling."
5929 (org-agenda-archive-with 'org-archive-to-archive-sibling))
5931 (defun org-agenda-archive-with (cmd &optional confirm)
5932 "Move the entry to the archive sibling."
5934 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5935 (let* ((marker (or (org-get-at-bol 'org-marker)
5936 (org-agenda-error)))
5937 (buffer (marker-buffer marker))
5938 (pos (marker-position marker)))
5939 (org-with-remote-undo buffer
5940 (with-current-buffer buffer
5943 (not (y-or-n-p "Archive this subtree or entry? ")))
5947 (org-remove-subtree-entries-from-agenda)
5948 (org-back-to-heading t)
5950 (error "Archiving works only in Org-mode files"))))))
5952 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
5953 "Remove all lines in the agenda that correspond to a given subtree.
5954 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5955 If this information is not given, the function uses the tree at point."
5956 (let ((buf (or buf (current-buffer))) m p)
5958 (unless (and beg end)
5959 (org-back-to-heading t)
5961 (org-end-of-subtree t)
5963 (set-buffer (get-buffer org-agenda-buffer-name))
5965 (goto-char (point-max))
5966 (beginning-of-line 1)
5968 (when (and (setq m (org-get-at-bol 'org-marker))
5969 (equal buf (marker-buffer m))
5970 (setq p (marker-position m))
5973 (let ((inhibit-read-only t))
5974 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5975 (beginning-of-line 0))))))
5977 (defun org-agenda-refile (&optional goto rfloc)
5978 "Refile the item at point."
5980 (if (equal goto '(16))
5981 (org-refile-goto-last-stored)
5982 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
5983 (org-agenda-error)))
5984 (buffer (marker-buffer marker))
5985 (pos (marker-position marker))
5987 (org-refile-get-location
5988 (if goto "Goto: " "Refile to: ") buffer
5989 org-refile-allow-creating-parent-nodes))))
5990 (with-current-buffer buffer
5995 (org-remove-subtree-entries-from-agenda)
5996 (org-refile goto buffer rfloc)))))))
5998 (defun org-agenda-open-link (&optional arg)
5999 "Follow the link in the current line, if any.
6000 This looks for a link in the displayed line in the agenda. It also looks
6001 at the text of the entry itself."
6003 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6004 (org-get-at-bol 'org-marker)))
6005 (buffer (and marker (marker-buffer marker)))
6006 (prefix (buffer-substring
6009 (or (org-get-at-bol 'prefix-length) 0)))))
6012 (with-current-buffer buffer
6017 (org-offer-links-in-entry arg prefix)))))
6018 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6020 (beginning-of-line 1)
6021 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6022 (org-open-link-from-string (match-string 1)))
6023 (t (error "No link to open here")))))
6025 (defun org-agenda-copy-local-variable (var)
6026 "Get a variable from a referenced buffer and install it here."
6027 (let ((m (org-get-at-bol 'org-marker)))
6028 (when (and m (buffer-live-p (marker-buffer m)))
6029 (org-set-local var (with-current-buffer (marker-buffer m)
6030 (symbol-value var))))))
6032 (defun org-agenda-switch-to (&optional delete-other-windows)
6033 "Go to the Org-mode file which contains the item at point."
6035 (if (and org-return-follows-link
6036 (not (org-get-at-bol 'org-marker))
6037 (org-in-regexp org-bracket-link-regexp))
6038 (org-open-link-from-string (match-string 0))
6039 (let* ((marker (or (org-get-at-bol 'org-marker)
6040 (org-agenda-error)))
6041 (buffer (marker-buffer marker))
6042 (pos (marker-position marker)))
6043 (switch-to-buffer buffer)
6044 (and delete-other-windows (delete-other-windows))
6048 (org-show-context 'agenda)
6050 (and (outline-next-heading)
6051 (org-flag-heading nil))))))) ; show the next heading
6053 (defun org-agenda-goto-mouse (ev)
6054 "Go to the Org-mode file which contains the item at the mouse click."
6056 (mouse-set-point ev)
6059 (defun org-agenda-show (&optional full-entry)
6060 "Display the Org-mode file which contains the item at point.
6061 With prefix argument FULL-ENTRY, make the entire entry visible
6062 if it was hidden in the outline."
6064 (let ((win (selected-window)))
6066 (let ((org-show-entry-below t))
6067 (org-agenda-goto t))
6068 (org-agenda-goto t))
6069 (select-window win)))
6071 (defvar org-agenda-show-window nil)
6072 (defun org-agenda-show-and-scroll-up ()
6073 "Display the Org-mode file which contains the item at point.
6074 When called repeatedly, scroll the window that is displaying the buffer."
6076 (let ((win (selected-window)))
6077 (if (and (window-live-p org-agenda-show-window)
6078 (eq this-command last-command))
6080 (select-window org-agenda-show-window)
6081 (ignore-errors (scroll-up)))
6084 (setq org-agenda-show-window (selected-window)))
6085 (select-window win)))
6087 (defun org-agenda-show-scroll-down ()
6088 "Scroll down the window showing the agenda."
6090 (let ((win (selected-window)))
6091 (when (window-live-p org-agenda-show-window)
6092 (select-window org-agenda-show-window)
6093 (ignore-errors (scroll-down))
6094 (select-window win))))
6096 (defun org-agenda-show-1 (&optional more)
6097 "Display the Org-mode file which contains the item at point.
6098 The prefix arg selects the amount of information to display:
6101 1 just show the entry according to defaults.
6102 2 show the children view
6103 3 show the subtree view
6104 4 show the entire subtree and any LOGBOOK drawers
6105 5 show the entire subtree and any drawers
6106 With prefix argument FULL-ENTRY, make the entire entry visible
6107 if it was hidden in the outline."
6109 (let ((win (selected-window)))
6111 (org-recenter-heading 1)
6116 (org-back-to-heading)
6117 (run-hook-with-args 'org-cycle-hook 'folded))
6118 (message "Remote: FOLDED"))
6119 ((and (interactive-p) (= more 1))
6120 (message "Remote: show with default settings"))
6125 (org-back-to-heading)
6126 (run-hook-with-args 'org-cycle-hook 'children))
6127 (message "Remote: CHILDREN"))
6131 (org-back-to-heading)
6132 (run-hook-with-args 'org-cycle-hook 'subtree))
6133 (message "Remote: SUBTREE"))
6135 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6137 (concat "^[ \t]*:\\("
6138 (mapconcat 'regexp-quote org-drawers "\\|")
6142 (org-back-to-heading)
6143 (org-cycle-hide-drawers 'subtree)))
6144 (message "Remote: SUBTREE AND LOGBOOK"))
6147 (message "Remote: SUBTREE AND ALL DRAWERS")))
6148 (select-window win)))
6150 (defun org-recenter-heading (n)
6152 (org-back-to-heading)
6155 (defvar org-agenda-cycle-counter nil)
6156 (defun org-agenda-cycle-show (&optional n)
6157 "Show the current entry in another window, with default settings.
6158 Default settings are taken from `org-show-hierarchy-above' and siblings.
6159 When use repeatedly in immediate succession, the remote entry will cycle
6162 children -> subtree -> folded
6164 When called with a numeric prefix arg, that arg will be passed through to
6165 `org-agenda-show-1'. For the interpretation of that argument, see the
6166 docstring of `org-agenda-show-1'."
6169 (setq org-agenda-cycle-counter n)
6170 (if (not (eq last-command this-command))
6171 (setq org-agenda-cycle-counter 1)
6172 (if (equal org-agenda-cycle-counter 0)
6173 (setq org-agenda-cycle-counter 2)
6174 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6175 (if (> org-agenda-cycle-counter 3)
6176 (setq org-agenda-cycle-counter 0)))))
6177 (org-agenda-show-1 org-agenda-cycle-counter))
6179 (defun org-agenda-recenter (arg)
6180 "Display the Org-mode file which contains the item at point and recenter."
6182 (let ((win (selected-window)))
6185 (select-window win)))
6187 (defun org-agenda-show-mouse (ev)
6188 "Display the Org-mode file which contains the item at the mouse click."
6190 (mouse-set-point ev)
6193 (defun org-agenda-check-no-diary ()
6194 "Check if the entry is a diary link and abort if yes."
6195 (if (org-get-at-bol 'org-agenda-diary-link)
6196 (org-agenda-error)))
6198 (defun org-agenda-error ()
6199 (error "Command not allowed in this line"))
6201 (defun org-agenda-tree-to-indirect-buffer ()
6202 "Show the subtree corresponding to the current entry in an indirect buffer.
6203 This calls the command `org-tree-to-indirect-buffer' from the original
6205 With numerical prefix arg ARG, go up to this level and then take that tree.
6206 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
6209 (org-agenda-check-no-diary)
6210 (let* ((marker (or (org-get-at-bol 'org-marker)
6211 (org-agenda-error)))
6212 (buffer (marker-buffer marker))
6213 (pos (marker-position marker)))
6214 (with-current-buffer buffer
6217 (call-interactively 'org-tree-to-indirect-buffer)))))
6219 (defvar org-last-heading-marker (make-marker)
6220 "Marker pointing to the headline that last changed its TODO state
6221 by a remote command from the agenda.")
6223 (defun org-agenda-todo-nextset ()
6224 "Switch TODO entry to next sequence."
6226 (org-agenda-todo 'nextset))
6228 (defun org-agenda-todo-previousset ()
6229 "Switch TODO entry to previous sequence."
6231 (org-agenda-todo 'previousset))
6233 (defun org-agenda-todo (&optional arg)
6234 "Cycle TODO state of line at point, also in Org-mode file.
6235 This changes the line at point, all other lines in the agenda referring to
6236 the same tree node, and the headline of the tree node in the Org-mode file."
6238 (org-agenda-check-no-diary)
6239 (let* ((col (current-column))
6240 (marker (or (org-get-at-bol 'org-marker)
6241 (org-agenda-error)))
6242 (buffer (marker-buffer marker))
6243 (pos (marker-position marker))
6244 (hdmarker (org-get-at-bol 'org-hd-marker))
6245 (todayp (equal (org-get-at-bol 'day)
6246 (time-to-days (current-time))))
6247 (inhibit-read-only t)
6248 org-agenda-headline-snapshot-before-repeat newhead just-one)
6249 (org-with-remote-undo buffer
6250 (with-current-buffer buffer
6253 (org-show-context 'agenda)
6255 (and (outline-next-heading)
6256 (org-flag-heading nil))) ; show the next heading
6257 (let ((current-prefix-arg arg))
6258 (call-interactively 'org-todo))
6259 (and (bolp) (forward-char 1))
6260 (setq newhead (org-get-heading))
6261 (when (and (org-bound-and-true-p
6262 org-agenda-headline-snapshot-before-repeat)
6263 (not (equal org-agenda-headline-snapshot-before-repeat
6266 (setq newhead org-agenda-headline-snapshot-before-repeat
6269 (org-back-to-heading)
6270 (move-marker org-last-heading-marker (point))))
6271 (beginning-of-line 1)
6273 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6274 (org-move-to-column col))))
6276 (defun org-agenda-add-note (&optional arg)
6277 "Add a time-stamped note to the entry at point."
6279 (org-agenda-check-no-diary)
6280 (let* ((marker (or (org-get-at-bol 'org-marker)
6281 (org-agenda-error)))
6282 (buffer (marker-buffer marker))
6283 (pos (marker-position marker))
6284 (hdmarker (org-get-at-bol 'org-hd-marker))
6285 (inhibit-read-only t))
6286 (with-current-buffer buffer
6289 (org-show-context 'agenda)
6291 (and (outline-next-heading)
6292 (org-flag-heading nil))) ; show the next heading
6295 (defun org-agenda-change-all-lines (newhead hdmarker
6296 &optional fixface just-this)
6297 "Change all lines in the agenda buffer which match HDMARKER.
6298 The new content of the line will be NEWHEAD (as modified by
6299 `org-format-agenda-item'). HDMARKER is checked with
6300 `equal' against all `org-hd-marker' text properties in the file.
6301 If FIXFACE is non-nil, the face of each item is modified according to
6303 If JUST-THIS is non-nil, change just the current line, not all.
6304 If FORCE-TAGS is non nil, the car of it returns the new tags."
6305 (let* ((inhibit-read-only t)
6306 (line (org-current-line))
6307 (thetags (with-current-buffer (marker-buffer hdmarker)
6308 (save-excursion (save-restriction (widen)
6309 (goto-char hdmarker)
6310 (org-get-tags-at)))))
6311 props m pl undone-face done-face finish new dotime cat tags)
6313 (goto-char (point-max))
6314 (beginning-of-line 1)
6316 (setq finish (bobp))
6317 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6318 (or (not just-this) (= (org-current-line) line))
6320 (setq props (text-properties-at (point))
6321 dotime (org-get-at-bol 'dotime)
6322 cat (org-get-at-bol 'org-category)
6324 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6325 pl (org-get-at-bol 'prefix-length)
6326 undone-face (org-get-at-bol 'undone-face)
6327 done-face (org-get-at-bol 'done-face))
6328 (goto-char (+ (point) pl))
6329 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6332 (beginning-of-line 1)
6333 (and (looking-at ".*\n?") (replace-match "")))
6335 (replace-match new t t)
6336 (beginning-of-line 1)
6337 (add-text-properties (point-at-bol) (point-at-eol) props)
6339 (add-text-properties
6340 (point-at-bol) (point-at-eol)
6342 (if org-last-todo-state-is-todo
6343 undone-face done-face))))
6344 (org-agenda-highlight-todo 'line)
6345 (beginning-of-line 1))
6346 (t (error "Line update did not work"))))
6347 (beginning-of-line 0)))
6348 (org-finalize-agenda)))
6350 (defun org-agenda-align-tags (&optional line)
6351 "Align all tags in agenda items to `org-agenda-tags-column'."
6352 (let ((inhibit-read-only t) l c)
6354 (goto-char (if line (point-at-bol) (point-min)))
6355 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
6356 (if line (point-at-eol) nil) t)
6357 (add-text-properties
6358 (match-beginning 2) (match-end 2)
6359 (list 'face (delq nil (let ((prop (get-text-property
6360 (match-beginning 2) 'face)))
6361 (or (listp prop) (setq prop (list prop)))
6362 (if (memq 'org-tag prop)
6364 (cons 'org-tag prop))))))
6365 (setq l (- (match-end 2) (match-beginning 2))
6366 c (if (< org-agenda-tags-column 0)
6367 (- (abs org-agenda-tags-column) l)
6368 org-agenda-tags-column))
6369 (delete-region (match-beginning 1) (match-end 1))
6370 (goto-char (match-beginning 1))
6371 (insert (org-add-props
6372 (make-string (max 1 (- c (current-column))) ?\ )
6373 (text-properties-at (point)))))
6374 (goto-char (point-min))
6375 (org-font-lock-add-tag-faces (point-max)))))
6377 (defun org-agenda-priority-up ()
6378 "Increase the priority of line at point, also in Org-mode file."
6380 (org-agenda-priority 'up))
6382 (defun org-agenda-priority-down ()
6383 "Decrease the priority of line at point, also in Org-mode file."
6385 (org-agenda-priority 'down))
6387 (defun org-agenda-priority (&optional force-direction)
6388 "Set the priority of line at point, also in Org-mode file.
6389 This changes the line at point, all other lines in the agenda referring to
6390 the same tree node, and the headline of the tree node in the Org-mode file."
6392 (unless org-enable-priority-commands
6393 (error "Priority commands are disabled"))
6394 (org-agenda-check-no-diary)
6395 (let* ((marker (or (org-get-at-bol 'org-marker)
6396 (org-agenda-error)))
6397 (hdmarker (org-get-at-bol 'org-hd-marker))
6398 (buffer (marker-buffer hdmarker))
6399 (pos (marker-position hdmarker))
6400 (inhibit-read-only t)
6402 (org-with-remote-undo buffer
6403 (with-current-buffer buffer
6406 (org-show-context 'agenda)
6408 (and (outline-next-heading)
6409 (org-flag-heading nil))) ; show the next heading
6410 (funcall 'org-priority force-direction)
6412 (setq newhead (org-get-heading)))
6413 (org-agenda-change-all-lines newhead hdmarker)
6414 (beginning-of-line 1))))
6416 ;; FIXME: should fix the tags property of the agenda line.
6417 (defun org-agenda-set-tags (&optional tag onoff)
6418 "Set tags for the current headline."
6420 (org-agenda-check-no-diary)
6421 (if (and (org-region-active-p) (interactive-p))
6422 (call-interactively 'org-change-tag-in-region)
6423 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6424 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6425 (org-agenda-error)))
6426 (buffer (marker-buffer hdmarker))
6427 (pos (marker-position hdmarker))
6428 (inhibit-read-only t)
6430 (org-with-remote-undo buffer
6431 (with-current-buffer buffer
6435 (org-show-context 'agenda))
6437 (and (outline-next-heading)
6438 (org-flag-heading nil))) ; show the next heading
6441 (org-toggle-tag tag onoff)
6442 (call-interactively 'org-set-tags))
6444 (setq newhead (org-get-heading)))
6445 (org-agenda-change-all-lines newhead hdmarker)
6446 (beginning-of-line 1)))))
6448 (defun org-agenda-set-property ()
6449 "Set a property for the current headline."
6451 (org-agenda-check-no-diary)
6452 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6453 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6454 (org-agenda-error)))
6455 (buffer (marker-buffer hdmarker))
6456 (pos (marker-position hdmarker))
6457 (inhibit-read-only t)
6459 (org-with-remote-undo buffer
6460 (with-current-buffer buffer
6464 (org-show-context 'agenda))
6466 (and (outline-next-heading)
6467 (org-flag-heading nil))) ; show the next heading
6469 (call-interactively 'org-set-property)))))
6471 (defun org-agenda-set-effort ()
6472 "Set the effort property for the current headline."
6474 (org-agenda-check-no-diary)
6475 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6476 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6477 (org-agenda-error)))
6478 (buffer (marker-buffer hdmarker))
6479 (pos (marker-position hdmarker))
6480 (inhibit-read-only t)
6482 (org-with-remote-undo buffer
6483 (with-current-buffer buffer
6487 (org-show-context 'agenda))
6489 (and (outline-next-heading)
6490 (org-flag-heading nil))) ; show the next heading
6492 (call-interactively 'org-set-effort)
6495 (defun org-agenda-toggle-archive-tag ()
6496 "Toggle the archive tag for the current entry."
6498 (org-agenda-check-no-diary)
6499 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6500 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6501 (org-agenda-error)))
6502 (buffer (marker-buffer hdmarker))
6503 (pos (marker-position hdmarker))
6504 (inhibit-read-only t)
6506 (org-with-remote-undo buffer
6507 (with-current-buffer buffer
6510 (org-show-context 'agenda)
6512 (and (outline-next-heading)
6513 (org-flag-heading nil))) ; show the next heading
6514 (call-interactively 'org-toggle-archive-tag)
6516 (setq newhead (org-get-heading)))
6517 (org-agenda-change-all-lines newhead hdmarker)
6518 (beginning-of-line 1))))
6520 (defun org-agenda-do-date-later (arg)
6523 ((or (equal arg '(16))
6525 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6526 (setq this-command 'org-agenda-date-later-minutes)
6527 (org-agenda-date-later-minutes 1))
6528 ((or (equal arg '(4))
6530 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6531 (setq this-command 'org-agenda-date-later-hours)
6532 (org-agenda-date-later-hours 1))
6534 (org-agenda-date-later (prefix-numeric-value arg)))))
6536 (defun org-agenda-do-date-earlier (arg)
6539 ((or (equal arg '(16))
6541 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6542 (setq this-command 'org-agenda-date-earlier-minutes)
6543 (org-agenda-date-earlier-minutes 1))
6544 ((or (equal arg '(4))
6546 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6547 (setq this-command 'org-agenda-date-earlier-hours)
6548 (org-agenda-date-earlier-hours 1))
6550 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6552 (defun org-agenda-date-later (arg &optional what)
6553 "Change the date of this item to one day later."
6555 (org-agenda-check-type t 'agenda 'timeline)
6556 (org-agenda-check-no-diary)
6557 (let* ((marker (or (org-get-at-bol 'org-marker)
6558 (org-agenda-error)))
6559 (buffer (marker-buffer marker))
6560 (pos (marker-position marker)))
6561 (org-with-remote-undo buffer
6562 (with-current-buffer buffer
6565 (if (not (org-at-timestamp-p))
6566 (error "Cannot find time stamp"))
6567 (org-timestamp-change arg (or what 'day)))
6568 (org-agenda-show-new-time marker org-last-changed-timestamp))
6569 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6571 (defun org-agenda-date-earlier (arg &optional what)
6572 "Change the date of this item to one day earlier."
6574 (org-agenda-date-later (- arg) what))
6576 (defun org-agenda-date-later-minutes (arg)
6577 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6579 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6580 (org-agenda-date-later arg 'minute))
6582 (defun org-agenda-date-earlier-minutes (arg)
6583 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6585 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6586 (org-agenda-date-earlier arg 'minute))
6588 (defun org-agenda-date-later-hours (arg)
6589 "Change the time of this item, in hour steps."
6591 (org-agenda-date-later arg 'hour))
6593 (defun org-agenda-date-earlier-hours (arg)
6594 "Change the time of this item, in hour steps."
6596 (org-agenda-date-earlier arg 'hour))
6598 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6599 "Show new date stamp via text properties."
6600 ;; We use text properties to make this undoable
6601 (let ((inhibit-read-only t)
6602 (buffer-invisibility-spec))
6603 (setq stamp (concat " " prefix " => " stamp))
6605 (goto-char (point-max))
6607 (when (equal marker (org-get-at-bol 'org-marker))
6608 (org-move-to-column (- (window-width) (length stamp)) t)
6609 (org-agenda-fix-tags-filter-overlays-at (point))
6610 (if (featurep 'xemacs)
6611 ;; Use `duplicable' property to trigger undo recording
6612 (let ((ex (make-extent nil nil))
6613 (gl (make-glyph stamp)))
6614 (set-glyph-face gl 'secondary-selection)
6615 (set-extent-properties
6616 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6617 (insert-extent ex (1- (point)) (point-at-eol)))
6618 (add-text-properties
6619 (1- (point)) (point-at-eol)
6620 (list 'display (org-add-props stamp nil
6621 'face 'secondary-selection))))
6622 (beginning-of-line 1))
6623 (beginning-of-line 0)))))
6625 (defun org-agenda-date-prompt (arg)
6626 "Change the date of this item. Date is prompted for, with default today.
6627 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6628 be used to request time specification in the time stamp."
6630 (org-agenda-check-type t 'agenda 'timeline)
6631 (org-agenda-check-no-diary)
6632 (let* ((marker (or (org-get-at-bol 'org-marker)
6633 (org-agenda-error)))
6634 (buffer (marker-buffer marker))
6635 (pos (marker-position marker)))
6636 (org-with-remote-undo buffer
6637 (with-current-buffer buffer
6640 (if (not (org-at-timestamp-p t))
6641 (error "Cannot find time stamp"))
6642 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
6643 (org-agenda-show-new-time marker org-last-changed-timestamp))
6644 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6646 (defun org-agenda-schedule (arg)
6647 "Schedule the item at point.
6648 Arg is passed through to `org-schedule'."
6650 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6651 (org-agenda-check-no-diary)
6652 (let* ((marker (or (org-get-at-bol 'org-marker)
6653 (org-agenda-error)))
6654 (type (marker-insertion-type marker))
6655 (buffer (marker-buffer marker))
6656 (pos (marker-position marker))
6657 (org-insert-labeled-timestamps-at-point nil)
6659 (set-marker-insertion-type marker t)
6660 (org-with-remote-undo buffer
6661 (with-current-buffer buffer
6664 (setq ts (org-schedule arg)))
6665 (org-agenda-show-new-time marker ts "S"))
6666 (message "Item scheduled for %s" ts)))
6668 (defun org-agenda-deadline (arg)
6669 "Schedule the item at point.
6670 Arg is passed through to `org-deadline'."
6672 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6673 (org-agenda-check-no-diary)
6674 (let* ((marker (or (org-get-at-bol 'org-marker)
6675 (org-agenda-error)))
6676 (buffer (marker-buffer marker))
6677 (pos (marker-position marker))
6678 (org-insert-labeled-timestamps-at-point nil)
6680 (org-with-remote-undo buffer
6681 (with-current-buffer buffer
6684 (setq ts (org-deadline arg)))
6685 (org-agenda-show-new-time marker ts "D"))
6686 (message "Deadline for this item set to %s" ts)))
6688 (defun org-agenda-action ()
6689 "Select entry for agenda action, or execute an agenda action.
6690 This command prompts for another letter. Valid inputs are:
6692 m Mark the entry at point for an agenda action
6693 s Schedule the marked entry to the date at the cursor
6694 d Set the deadline of the marked entry to the date at the cursor
6695 r Call `org-remember' with cursor date as the default date
6696 SPC Show marked entry in other window
6697 TAB Visit marked entry in other window
6699 The cursor may be at a date in the calendar, or in the Org agenda."
6702 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
6703 (setq ans (read-char-exclusive))
6707 (if (eq major-mode 'org-agenda-mode)
6708 (let ((m (or (org-get-at-bol 'org-hd-marker)
6709 (org-get-at-bol 'org-marker))))
6712 (move-marker org-agenda-action-marker
6713 (marker-position m) (marker-buffer m))
6714 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
6715 (error "Don't know which entry to mark")))
6716 (error "This command works only in the agenda")))
6718 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
6720 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
6722 (org-agenda-do-action '(org-remember) t))
6724 (let ((cw (selected-window)))
6725 (org-switch-to-buffer-other-window
6726 (marker-buffer org-agenda-action-marker))
6727 (goto-char org-agenda-action-marker)
6728 (org-show-context 'agenda)
6729 (select-window cw)))
6731 (org-switch-to-buffer-other-window
6732 (marker-buffer org-agenda-action-marker))
6733 (goto-char org-agenda-action-marker)
6734 (org-show-context 'agenda))
6735 (t (error "Invalid agenda action %c" ans)))))
6737 (defun org-agenda-do-action (form &optional current-buffer)
6738 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
6739 (let ((org-overriding-default-time (org-get-cursor-date)))
6742 (if (not (marker-buffer org-agenda-action-marker))
6743 (error "No entry has been selected for agenda action")
6744 (with-current-buffer (marker-buffer org-agenda-action-marker)
6748 (goto-char org-agenda-action-marker)
6751 (defun org-agenda-clock-in (&optional arg)
6752 "Start the clock on the currently selected item."
6754 (org-agenda-check-no-diary)
6755 (if (equal arg '(4))
6757 (let* ((marker (or (org-get-at-bol 'org-marker)
6758 (org-agenda-error)))
6759 (hdmarker (or (org-get-at-bol 'org-hd-marker)
6761 (pos (marker-position marker))
6763 (org-with-remote-undo (marker-buffer marker)
6764 (with-current-buffer (marker-buffer marker)
6767 (org-show-context 'agenda)
6769 (org-cycle-hide-drawers 'children)
6771 (setq newhead (org-get-heading)))
6772 (org-agenda-change-all-lines newhead hdmarker)))))
6774 (defun org-agenda-clock-out (&optional arg)
6775 "Stop the currently running clock."
6777 (unless (marker-buffer org-clock-marker)
6778 (error "No running clock"))
6779 (let ((marker (make-marker)) newhead)
6780 (org-with-remote-undo (marker-buffer org-clock-marker)
6781 (with-current-buffer (marker-buffer org-clock-marker)
6785 (goto-char org-clock-marker)
6786 (org-back-to-heading t)
6787 (move-marker marker (point))
6789 (setq newhead (org-get-heading))))))
6790 (org-agenda-change-all-lines newhead marker)
6791 (move-marker marker nil)))
6793 (defun org-agenda-clock-cancel (&optional arg)
6794 "Cancel the currently running clock."
6796 (unless (marker-buffer org-clock-marker)
6797 (error "No running clock"))
6798 (org-with-remote-undo (marker-buffer org-clock-marker)
6799 (org-clock-cancel)))
6801 (defun org-agenda-diary-entry-in-org-file ()
6802 "Make a diary entry in the file `org-agenda-diary-file'."
6803 (let (d1 d2 char (text "") dp1 dp2)
6804 (if (equal (buffer-name) "*Calendar*")
6805 (setq d1 (calendar-cursor-to-date t)
6806 d2 (car calendar-mark-ring))
6807 (setq dp1 (get-text-property (point-at-bol) 'day))
6808 (unless dp1 (error "No date defined in current line"))
6809 (setq d1 (calendar-gregorian-from-absolute dp1)
6810 d2 (and (ignore-errors (mark))
6813 (setq dp2 (get-text-property (point-at-bol) 'day)))
6814 (calendar-gregorian-from-absolute dp2))))
6815 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
6816 (setq char (read-char-exclusive))
6819 (setq text (read-string "Day entry: "))
6820 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
6821 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
6823 (setq d1 (list (car d1) (nth 1 d1)
6824 (read-number (format "Reference year [%d]: " (nth 2 d1))
6826 (setq text (read-string "Anniversary (use %d to show years): "))
6827 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
6828 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
6830 (setq text (read-string "Block entry: "))
6831 (unless (and d1 d2 (not (equal d1 d2)))
6832 (error "No block of days selected"))
6833 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
6834 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
6836 (org-switch-to-buffer-other-window
6837 (find-file-noselect org-agenda-diary-file))
6838 (org-datetree-find-date-create d1)
6840 (t (error "Invalid selection character `%c'" char)))))
6842 (defcustom org-agenda-insert-diary-strategy 'date-tree
6843 "Where in `org-agenda-diary-file' should new entries be added?
6846 date-tree in the date tree, as child of the date
6847 top-level as top-level entries at the end of the file."
6850 (const :tag "in a date tree" date-tree)
6851 (const :tag "as top level at end of file" top-level)))
6853 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
6854 "Add a diary entry with TYPE to `org-agenda-diary-file'.
6855 If TEXT is not empty, it will become the headline of the new entry, and
6856 the resulting entry will not be shown. When TEXT is empty, switch to
6857 `org-agenda-diary-file' and let the user finish the entry there."
6858 (let ((cw (current-window-configuration)))
6859 (org-switch-to-buffer-other-window
6860 (find-file-noselect org-agenda-diary-file))
6862 (goto-char (point-min))
6864 ((eq type 'anniversary)
6865 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
6867 (or (org-on-heading-p t)
6869 (outline-next-heading)
6870 (insert "* Anniversaries\n\n")
6871 (beginning-of-line -1)))))
6872 (outline-next-heading)
6873 (org-back-over-empty-lines)
6876 (require 'diary-lib)
6877 (let ((calendar-date-display-form
6878 (if (if (boundp 'calendar-date-style)
6879 (eq calendar-date-style 'european)
6880 european-calendar-style) ; Emacs 22
6881 '(day " " month " " year)
6882 '(month " " day " " year))))
6884 (insert (format "%%%%(diary-anniversary %s) %s"
6885 (calendar-date-string d1 nil t) text))))
6887 (if (eq org-agenda-insert-diary-strategy 'top-level)
6888 (org-agenda-insert-diary-as-top-level text)
6889 (require 'org-datetree)
6890 (org-datetree-find-date-create d1)
6891 (org-agenda-insert-diary-make-new-entry text))
6892 (org-insert-time-stamp (org-time-from-absolute
6893 (calendar-absolute-from-gregorian d1)))
6896 (if (> (calendar-absolute-from-gregorian d1)
6897 (calendar-absolute-from-gregorian d2))
6898 (setq d1 (prog1 d2 (setq d2 d1))))
6899 (if (eq org-agenda-insert-diary-strategy 'top-level)
6900 (org-agenda-insert-diary-as-top-level text)
6901 (require 'org-datetree)
6902 (org-datetree-find-date-create d1)
6903 (org-agenda-insert-diary-make-new-entry text))
6904 (org-insert-time-stamp (org-time-from-absolute
6905 (calendar-absolute-from-gregorian d1)))
6907 (org-insert-time-stamp (org-time-from-absolute
6908 (calendar-absolute-from-gregorian d2)))
6910 (if (string-match "\\S-" text)
6912 (set-window-configuration cw)
6913 (message "%s entry added to %s"
6914 (capitalize (symbol-name type))
6915 (abbreviate-file-name org-agenda-diary-file)))
6917 (message "Please finish entry here"))))
6919 (defun org-agenda-insert-diary-as-top-level (text)
6920 "Make new entry as a top-level entry at the end of the file.
6921 Add TEXT as headline, and position the cursor in the second line so that
6922 a timestamp can be added there."
6924 (goto-char (point-max))
6925 (or (bolp) (insert "\n"))
6926 (insert "* " text "\n")
6927 (if org-adapt-indentation (org-indent-to-column 2)))
6929 (defun org-agenda-insert-diary-make-new-entry (text)
6930 "Make new entry as last child of current entry.
6931 Add TEXT as headline, and position the cursor in the second line so that
6932 a timestamp can be added there."
6933 (let ((org-show-following-heading t)
6934 (org-show-siblings t)
6935 (org-show-hierarchy-above t)
6936 (org-show-entry-below t)
6938 (outline-next-heading)
6939 (org-back-over-empty-lines)
6940 (or (looking-at "[ \t]*$")
6941 (progn (insert "\n") (backward-char 1)))
6942 (org-insert-heading)
6944 (setq col (current-column))
6946 (if org-adapt-indentation (org-indent-to-column col))
6947 (let ((org-show-following-heading t)
6948 (org-show-siblings t)
6949 (org-show-hierarchy-above t)
6950 (org-show-entry-below t))
6951 (org-show-context))))
6953 (defun org-agenda-diary-entry ()
6954 "Make a diary entry, like the `i' command from the calendar.
6955 All the standard commands work: block, weekly etc.
6956 When `org-agenda-diary-file' points to a file,
6957 `org-agenda-diary-entry-in-org-file' is called instead to create
6958 entries in that Org-mode file."
6960 (org-agenda-check-type t 'agenda 'timeline)
6961 (if (not (eq org-agenda-diary-file 'diary-file))
6962 (org-agenda-diary-entry-in-org-file)
6963 (require 'diary-lib)
6965 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6966 (read-char-exclusive)))
6967 (cmd (cdr (assoc char
6968 '((?d . insert-diary-entry)
6969 (?w . insert-weekly-diary-entry)
6970 (?m . insert-monthly-diary-entry)
6971 (?y . insert-yearly-diary-entry)
6972 (?a . insert-anniversary-diary-entry)
6973 (?b . insert-block-diary-entry)
6974 (?c . insert-cyclic-diary-entry)))))
6975 (oldf (symbol-function 'calendar-cursor-to-date))
6976 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6978 (mark (or (mark t) (point))))
6980 (error "No command associated with <%c>" char))
6981 (unless (and (get-text-property point 'day)
6982 (or (not (equal ?b char))
6983 (get-text-property mark 'day)))
6984 (error "Don't know which date to use for diary entry"))
6985 ;; We implement this by hacking the `calendar-cursor-to-date' function
6986 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6987 (let ((calendar-mark-ring
6988 (list (calendar-gregorian-from-absolute
6989 (or (get-text-property mark 'day)
6990 (get-text-property point 'day))))))
6993 (fset 'calendar-cursor-to-date
6994 (lambda (&optional error dummy)
6995 (calendar-gregorian-from-absolute
6996 (get-text-property point 'day))))
6997 (call-interactively cmd))
6998 (fset 'calendar-cursor-to-date oldf))))))
7000 (defun org-agenda-execute-calendar-command (cmd)
7001 "Execute a calendar command from the agenda, with the date associated to
7002 the cursor position."
7003 (org-agenda-check-type t 'agenda 'timeline)
7004 (require 'diary-lib)
7005 (unless (get-text-property (point) 'day)
7006 (error "Don't know which date to use for calendar command"))
7007 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7009 (date (calendar-gregorian-from-absolute
7010 (get-text-property point 'day)))
7011 ;; the following 2 vars are needed in the calendar
7012 (displayed-month (car date))
7013 (displayed-year (nth 2 date)))
7016 (fset 'calendar-cursor-to-date
7017 (lambda (&optional error dummy)
7018 (calendar-gregorian-from-absolute
7019 (get-text-property point 'day))))
7020 (call-interactively cmd))
7021 (fset 'calendar-cursor-to-date oldf))))
7023 (defun org-agenda-phases-of-moon ()
7024 "Display the phases of the moon for the 3 months around the cursor date."
7026 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7028 (defun org-agenda-holidays ()
7029 "Display the holidays for the 3 months around the cursor date."
7031 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7033 (defvar calendar-longitude)
7034 (defvar calendar-latitude)
7035 (defvar calendar-location-name)
7037 (defun org-agenda-sunrise-sunset (arg)
7038 "Display sunrise and sunset for the cursor date.
7039 Latitude and longitude can be specified with the variables
7040 `calendar-latitude' and `calendar-longitude'. When called with prefix
7041 argument, latitude and longitude will be prompted for."
7044 (let ((calendar-longitude (if arg nil calendar-longitude))
7045 (calendar-latitude (if arg nil calendar-latitude))
7046 (calendar-location-name
7047 (if arg "the given coordinates" calendar-location-name)))
7048 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7050 (defun org-agenda-goto-calendar ()
7051 "Open the Emacs calendar with the date at the cursor."
7053 (org-agenda-check-type t 'agenda 'timeline)
7054 (let* ((day (or (get-text-property (point) 'day)
7055 (error "Don't know which date to open in calendar")))
7056 (date (calendar-gregorian-from-absolute day))
7057 (calendar-move-hook nil)
7058 (calendar-view-holidays-initially-flag nil)
7059 (calendar-view-diary-initially-flag nil)
7060 (view-calendar-holidays-initially nil)
7061 (view-diary-entries-initially nil))
7063 (calendar-goto-date date)))
7066 (defun org-calendar-goto-agenda ()
7067 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7068 This is a command that has to be installed in `calendar-mode-map'."
7070 (org-agenda-list nil (calendar-absolute-from-gregorian
7071 (calendar-cursor-to-date))
7074 (defun org-agenda-convert-date ()
7076 (org-agenda-check-type t 'agenda 'timeline)
7077 (let ((day (get-text-property (point) 'day))
7080 (error "Don't know which date to convert"))
7081 (setq date (calendar-gregorian-from-absolute day))
7083 "Gregorian: " (calendar-date-string date) "\n"
7084 "ISO: " (calendar-iso-date-string date) "\n"
7085 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7086 "Julian: " (calendar-julian-date-string date) "\n"
7087 "Astron. JD: " (calendar-astro-date-string date)
7088 " (Julian date number at noon UTC)\n"
7089 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7090 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7091 "French: " (calendar-french-date-string date) "\n"
7092 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7093 "Mayan: " (calendar-mayan-date-string date) "\n"
7094 "Coptic: " (calendar-coptic-date-string date) "\n"
7095 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7096 "Persian: " (calendar-persian-date-string date) "\n"
7097 "Chinese: " (calendar-chinese-date-string date) "\n"))
7098 (with-output-to-temp-buffer "*Dates*"
7100 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7104 (defvar org-agenda-bulk-marked-entries nil
7105 "List of markers that refer to marked entries in the agenda.")
7107 (defun org-agenda-bulk-marked-p ()
7108 (eq (get-char-property (point-at-bol) 'type)
7109 'org-marked-entry-overlay))
7111 (defun org-agenda-bulk-mark ()
7112 "Mark the entry at point for future bulk action."
7114 (org-agenda-check-no-diary)
7115 (let* ((m (org-get-at-bol 'org-hd-marker))
7117 (unless (org-agenda-bulk-marked-p)
7118 (unless m (error "Nothing to mark at point"))
7119 (push m org-agenda-bulk-marked-entries)
7120 (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7121 (org-overlay-display ov "> "
7122 (org-get-todo-face "TODO")
7124 (org-overlay-put ov 'type 'org-marked-entry-overlay))
7125 (beginning-of-line 2)
7126 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7127 (beginning-of-line 2))
7128 (message "%d entries marked for bulk action"
7129 (length org-agenda-bulk-marked-entries))))
7131 (defun org-agenda-bulk-unmark ()
7132 "Unmark the entry at point for future bulk action."
7134 (when (org-agenda-bulk-marked-p)
7135 (org-agenda-bulk-remove-overlays
7136 (point-at-bol) (+ 2 (point-at-bol)))
7137 (setq org-agenda-bulk-marked-entries
7138 (delete (org-get-at-bol 'org-hd-marker)
7139 org-agenda-bulk-marked-entries)))
7140 (beginning-of-line 2)
7141 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7142 (beginning-of-line 2))
7143 (message "%d entries marked for bulk action"
7144 (length org-agenda-bulk-marked-entries)))
7146 (defun org-agenda-bulk-toggle ()
7147 "Toggle marking the entry at point for bulk action."
7149 (if (org-agenda-bulk-marked-p)
7150 (org-agenda-bulk-unmark)
7151 (org-agenda-bulk-mark)))
7153 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7154 "Remove the mark overlays between BEG and END in the agenda buffer.
7155 BEG and END default to the buffer limits.
7157 This only removes the overlays, it does not remove the markers
7158 from the list in `org-agenda-bulk-marked-entries'."
7161 (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
7162 (org-delete-overlay ov)))
7163 (org-overlays-in (or beg (point-min)) (or end (point-max)))))
7165 (defun org-agenda-bulk-remove-all-marks ()
7166 "Remove all marks in the agenda buffer.
7167 This will remove the markers, and the overlays."
7169 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7170 (setq org-agenda-bulk-marked-entries nil)
7171 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7173 (defun org-agenda-bulk-action (&optional arg)
7174 "Execute an remote-editing action on all marked entries.
7175 The prefix arg is passed through to the command if possible."
7177 (unless org-agenda-bulk-marked-entries
7178 (error "No entries are marked"))
7179 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
7180 (let* ((action (read-char-exclusive))
7181 (entries (reverse org-agenda-bulk-marked-entries))
7182 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7185 (setq cmd '(org-agenda-archive)))
7188 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7190 ((member action '(?r ?w))
7191 (setq rfloc (org-refile-get-location
7193 (marker-buffer (car org-agenda-bulk-marked-entries))
7194 org-refile-allow-creating-parent-nodes))
7195 (setcar (nthcdr 3 rfloc)
7196 (move-marker (make-marker) (nth 3 rfloc)
7197 (or (get-file-buffer (nth 1 rfloc))
7198 (find-buffer-visiting (nth 1 rfloc))
7199 (error "This should not happen"))))
7201 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
7204 (setq state (org-icompleting-read
7206 (with-current-buffer (marker-buffer (car entries))
7207 (mapcar 'list org-todo-keywords-1))))
7208 (setq cmd `(let ((org-inhibit-blocking t)
7209 (org-inhibit-logging 'note))
7210 (org-agenda-todo ,state))))
7212 ((memq action '(?- ?+))
7213 (setq tag (org-icompleting-read
7214 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7215 (with-current-buffer (marker-buffer (car entries))
7218 (if (stringp (car x)) x)) org-tag-alist)))))
7219 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
7221 ((memq action '(?s ?d))
7222 (let* ((date (unless arg
7225 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
7226 (ans (if arg nil org-read-date-final-answer))
7227 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
7228 (setq cmd `(let* ((bound (fboundp 'read-string))
7229 (old (and bound (symbol-function 'read-string))))
7232 (fset 'read-string (lambda (&rest ignore) ,ans))
7235 (fset 'read-string old)
7236 (fmakunbound 'read-string)))))))
7237 (t (error "Invalid bulk action")))
7239 ;; Sort the markers, to make sure that parents are handled before children
7240 (setq entries (sort entries
7243 ((equal (marker-buffer a) (marker-buffer b))
7244 (< (marker-position a) (marker-position b)))
7246 (string< (buffer-name (marker-buffer a))
7247 (buffer-name (marker-buffer b))))))))
7249 ;; Now loop over all markers and apply cmd
7250 (while (setq e (pop entries))
7251 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
7253 (progn (message "Skipping removed entry at %s" e)
7254 (setq cntskip (1+ cntskip)))
7257 (setq org-agenda-bulk-marked-entries
7258 (delete e org-agenda-bulk-marked-entries))
7259 (setq cnt (1+ cnt))))
7260 (setq org-agenda-bulk-marked-entries nil)
7261 (org-agenda-bulk-remove-all-marks)
7262 (message "Acted on %d entries%s"
7266 (format ", skipped %d (disappeared before their turn)"
7271 (defun org-agenda-show-the-flagging-note ()
7272 "Display the flagging note in the other window.
7273 When called a second time in direct sequence, offer to remove the FLAGGING
7274 tag and (if present) the flagging note."
7276 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
7277 (win (selected-window))
7278 note heading newhead)
7280 (error "No linked entry at point"))
7281 (if (and (eq this-command last-command)
7282 (y-or-n-p "Unflag and remove any flagging note? "))
7284 (org-agenda-remove-flag hdmarker)
7285 (let ((win (get-buffer-window "*Flagging Note*")))
7286 (and win (delete-window win)))
7287 (message "Entry unflaged"))
7288 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
7290 (error "No flagging note"))
7292 (org-switch-to-buffer-other-window "*Flagging Note*")
7295 (goto-char (point-min))
7296 (while (re-search-forward "\\\\n" nil t)
7297 (replace-match "\n" t t))
7298 (goto-char (point-min))
7300 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
7302 (defun org-agenda-remove-flag (marker)
7303 "Remove the FLAGGED tag and any flagging note in the entry."
7305 (org-with-point-at marker
7306 (org-toggle-tag "FLAGGED" 'off)
7307 (org-entry-delete nil "THEFLAGGINGNOTE")
7308 (setq newhead (org-get-heading)))
7309 (org-agenda-change-all-lines newhead marker)
7310 (message "Entry unflaged")))
7312 (defun org-agenda-get-any-marker (&optional pos)
7313 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7314 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7316 ;;; Appointment reminders
7318 (defvar appt-time-msg-list)
7321 (defun org-agenda-to-appt (&optional refresh filter)
7322 "Activate appointments found in `org-agenda-files'.
7323 With a \\[universal-argument] prefix, refresh the list of
7326 If FILTER is t, interactively prompt the user for a regular
7327 expression, and filter out entries that don't match it.
7329 If FILTER is a string, use this string as a regular expression
7330 for filtering entries out.
7332 FILTER can also be an alist with the car of each cell being
7333 either 'headline or 'category. For example:
7335 '((headline \"IMPORTANT\")
7336 (category \"Work\"))
7338 will only add headlines containing IMPORTANT or headlines
7339 belonging to the \"Work\" category."
7342 (if refresh (setq appt-time-msg-list nil))
7344 (setq filter (read-from-minibuffer "Regexp filter: ")))
7345 (let* ((cnt 0) ; count added events
7346 (org-agenda-new-buffers nil)
7347 (org-deadline-warning-days 0)
7348 (today (org-date-to-gregorian
7349 (time-to-days (current-time))))
7350 (org-agenda-restrict nil)
7351 (files (org-agenda-files 'unrestricted)) entries file)
7352 ;; Get all entries which may contain an appt
7353 (org-prepare-agenda-buffers files)
7354 (while (setq file (pop files))
7357 (org-agenda-get-day-entries
7358 file today :timestamp :scheduled :deadline))))
7359 (setq entries (delq nil entries))
7360 ;; Map thru entries and find if we should filter them out
7363 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7364 (cat (get-text-property 1 'org-category x))
7365 (tod (get-text-property 1 'time-of-day x))
7366 (ok (or (null filter)
7367 (and (stringp filter) (string-match filter evt))
7370 (cadr (assoc 'category filter)) cat)
7372 (cadr (assoc 'headline filter)) evt))))))
7373 ;; FIXME: Shall we remove text-properties for the appt text?
7374 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7376 (setq tod (concat "00" (number-to-string tod))
7377 tod (when (string-match
7378 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7379 (concat (match-string 1 tod) ":"
7380 (match-string 2 tod))))
7382 (setq cnt (1+ cnt))))) entries)
7383 (org-release-buffers org-agenda-new-buffers)
7385 (message "No event to add")
7386 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7388 (defun org-agenda-todayp (date)
7389 "Does DATE mean today, when considering `org-extend-today-until'?"
7391 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7392 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7393 (setq h (nth 2 (decode-time (current-time))))
7394 (or (and (>= h org-extend-today-until)
7396 (and (< h org-extend-today-until)
7397 (= date (1- today))))))
7399 (provide 'org-agenda)
7401 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7403 ;;; org-agenda.el ends here