Use LATEX_HEADER stuff also when previewing fragments
[org-mode.git] / lisp / org-agenda.el
blobda603102646d89fad1e5dbd5174d42de3700bb51
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
9 ;; Version: 6.33trans
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
31 ;;; Code:
33 (require 'org)
34 (eval-when-compile
35 (require 'cl)
36 (require 'calendar))
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)
74 (defvar entry)
75 (defvar date)
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."
84 :group 'org-agenda
85 :type '(choice
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."
93 :group 'org-agenda
94 :type 'boolean)
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."
100 :group 'org-agenda
101 :type '(choice
102 (character)
103 (string)))
105 (defgroup org-agenda-export nil
106 "Options concerning exporting agenda views in Org-mode."
107 :tag "Org Agenda Export"
108 :group 'org-agenda)
110 (defcustom org-agenda-with-colors t
111 "Non-nil means, use colors in agenda views."
112 :group 'org-agenda-export
113 :type 'boolean)
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
125 :type '(repeat
126 (list
127 (variable)
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
134 :type 'hook
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'."
148 :group 'org-agenda
149 :type 'integer)
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."
156 :group 'org-agenda
157 :type 'boolean)
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 {
171 font-size: 110%;
172 color: #003399;
173 font-weight: 600;
175 .org-todo {
176 color: #cc6666;
177 font-weight: bold;
179 .org-agenda-done {
180 color: #339933;
182 .org-done {
183 color: #339933;
185 .title { text-align: center; }
186 .todo, .deadline { color: red; }
187 .done { color: green; }
188 </style>
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
199 :type 'string)
201 (defgroup org-agenda-custom-commands nil
202 "Options concerning agenda views in Org-mode."
203 :tag "Org Agenda Custom Commands"
204 :group 'org-agenda)
206 (defconst org-sorting-choice
207 '(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))
216 "Sorting choices.")
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)
226 (list
227 (const :format "" quote)
228 (repeat (file))))
229 (list :tag "Sorting strategy"
230 (const org-agenda-sorting-strategy)
231 (list
232 (const :format "" quote)
233 (repeat
234 ,org-sorting-choice)))
235 (list :tag "Prefix format"
236 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
237 (string))
238 (list :tag "Number of days in agenda"
239 (const org-agenda-ndays)
240 (integer :value 1))
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)
246 (choice :value 1
247 (const :tag "Today" nil)
248 (integer :tag "Weekday No.")))
249 (list :tag "Include data from diary"
250 (const org-agenda-include-diary)
251 (boolean))
252 (list :tag "Deadline Warning days"
253 (const org-deadline-warning-days)
254 (integer :value 1))
255 (list :tag "Tags filter preset"
256 (const org-agenda-filter-preset)
257 (list
258 (const :format "" quote)
259 (repeat
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)
264 (list
265 (const :format "" quote)
266 (list
267 (choice
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"
272 (choice
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
302 with the command.
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)
335 where
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
363 :type `(repeat
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"))
368 (choice
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"
387 (choice
388 (list :tag "Agenda"
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
434 :type 'character)
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
465 :type '(list
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"
483 :group 'org-agenda)
484 (defgroup org-agenda-daily/weekly nil
485 "Options concerning the daily/weekly agenda."
486 :tag "Org Agenda Daily/Weekly"
487 :group 'org-agenda)
488 (defgroup org-agenda-todo-list nil
489 "Options concerning the global todo list agenda view."
490 :tag "Org Agenda Todo List"
491 :group 'org-agenda)
492 (defgroup org-agenda-match-view nil
493 "Options concerning the general tags/property/todo match agenda view."
494 :tag "Org Agenda Match View"
495 :group 'org-agenda)
496 (defgroup org-agenda-search-view nil
497 "Options concerning the general tags/property/todo match agenda view."
498 :tag "Org Agenda Match View"
499 :group 'org-agenda)
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
512 :type 'boolean)
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
520 :type 'boolean)
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'
528 will be ignored.
529 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
530 :group 'org-agenda-skip
531 :group 'org-agenda-todo-list
532 :type 'boolean)
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
537 of this item.
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
542 :type 'boolean)
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
552 :type 'boolean)
554 (defcustom org-agenda-tags-todo-honor-ignore-options nil
555 "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
556 The variables
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
567 :type 'boolean)
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
574 is DONE."
575 :group 'org-agenda-skip
576 :group 'org-agenda-daily/weekly
577 :type 'boolean)
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
583 stamp as well.
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
591 :type '(choice
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
604 :type 'boolean)
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
611 :type 'boolean)
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
617 :type 'boolean)
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
636 :type '(choice
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
648 :type '(choice
649 (const :tag "None" nil)
650 (const :tag "All" t)
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"
656 :group 'org-agenda)
658 (defcustom org-finalize-agenda-hook nil
659 "Hook run just before displaying an agenda buffer."
660 :group 'org-agenda-startup
661 :type 'hook)
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
668 :type 'boolean)
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
673 :type 'boolean)
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
678 :type 'boolean)
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
683 :type 'boolean)
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'."
691 :group 'org-agenda
692 :type 'integer)
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."
698 :group 'org-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"
715 :group 'org-agenda)
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
729 :type '(choice
730 (const current-window)
731 (const other-frame)
732 (const other-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
750 :type 'boolean)
752 (defcustom org-agenda-ndays 7
753 "Number of days to include in overview display.
754 Should be 1 or 7.
755 Custom commands can set this variable in the options section."
756 :group 'org-agenda-daily/weekly
757 :type 'integer)
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
772 :type 'boolean)
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
781 :type '(choice
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."
788 (require 'cal-iso)
789 (let* ((dayname (calendar-day-name date))
790 (day (cadr date))
791 (day-of-week (calendar-day-of-week date))
792 (month (car date))
793 (monthname (calendar-month-name month))
794 (year (nth 2 date))
795 (iso-week (org-days-to-iso-week
796 (calendar-absolute-from-gregorian date)))
797 (weekyear (cond ((and (= month 1) (>= iso-week 52))
798 (1- year))
799 ((and (= month 12) (<= iso-week 1))
800 (1+ year))
801 (t year)))
802 (weekstring (if (= day-of-week 1)
803 (format " W%02d" iso-week)
804 "")))
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
826 :type 'boolean)
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
834 :type 'boolean)
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
841 :type 'boolean)
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
847 given here."
848 :group 'org-agenda-daily/weekly
849 :type 'integer)
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
867 agenda display."
868 :group 'org-agenda-daily/weekly
869 :type 'boolean)
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
875 :type 'boolean)
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
881 :type 'boolean)
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
892 :type 'plist)
894 (defcustom org-agenda-search-view-search-words-only nil
895 "Non-nil means, the search string is interpreted as individual words
896 The search then looks for each word separately in each entry and
897 selects entries that have matches for all words.
898 When nil, matching as loose words will only take place if the first
899 word is preceded by + or -. If that is not the case, the search
900 string will just be matched as a substring in the entry, but with
901 each space character allowing for any whitespace, including newlines."
902 :group 'org-agenda-search-view
903 :type 'boolean)
905 (defgroup org-agenda-time-grid nil
906 "Options concerning the time grid in the Org-mode Agenda."
907 :tag "Org Agenda Time Grid"
908 :group 'org-agenda)
910 (defcustom org-agenda-search-headline-for-time t
911 "Non-nil means, search headline for a time-of-day.
912 If the headline contains a time-of-day in one format or another, it will
913 be used to sort the entry into the time sequence of items for a day.
914 Some people have time stamps in the headline that refer to the creation
915 time or so, and then this produces an unwanted side effect. If this is
916 the case for your, use this variable to turn off searching the headline
917 for a time."
918 :group 'org-agenda-time-grid
919 :type 'boolean)
921 (defcustom org-agenda-use-time-grid t
922 "Non-nil means, show a time grid in the agenda schedule.
923 A time grid is a set of lines for specific times (like every two hours between
924 8:00 and 20:00). The items scheduled for a day at specific times are
925 sorted in between these lines.
926 For details about when the grid will be shown, and what it will look like, see
927 the variable `org-agenda-time-grid'."
928 :group 'org-agenda-time-grid
929 :type 'boolean)
931 (defcustom org-agenda-time-grid
932 '((daily today require-timed)
933 "----------------"
934 (800 1000 1200 1400 1600 1800 2000))
936 "The settings for time grid for agenda display.
937 This is a list of three items. The first item is again a list. It contains
938 symbols specifying conditions when the grid should be displayed:
940 daily if the agenda shows a single day
941 weekly if the agenda shows an entire week
942 today show grid on current date, independent of daily/weekly display
943 require-timed show grid only if at least one item has a time specification
945 The second item is a string which will be placed behind the grid time.
947 The third item is a list of integers, indicating the times that should have
948 a grid line."
949 :group 'org-agenda-time-grid
950 :type
951 '(list
952 (set :greedy t :tag "Grid Display Options"
953 (const :tag "Show grid in single day agenda display" daily)
954 (const :tag "Show grid in weekly agenda display" weekly)
955 (const :tag "Always show grid for today" today)
956 (const :tag "Show grid only if any timed entries are present"
957 require-timed)
958 (const :tag "Skip grid times already present in an entry"
959 remove-match))
960 (string :tag "Grid String")
961 (repeat :tag "Grid Times" (integer :tag "Time"))))
963 (defgroup org-agenda-sorting nil
964 "Options concerning sorting in the Org-mode Agenda."
965 :tag "Org Agenda Sorting"
966 :group 'org-agenda)
968 (defcustom org-agenda-sorting-strategy
969 '((agenda habit-down time-up priority-down category-keep)
970 (todo priority-down category-keep)
971 (tags priority-down category-keep)
972 (search category-keep))
973 "Sorting structure for the agenda items of a single day.
974 This is a list of symbols which will be used in sequence to determine
975 if an entry should be listed before another entry. The following
976 symbols are recognized:
978 time-up Put entries with time-of-day indications first, early first
979 time-down Put entries with time-of-day indications first, late first
980 category-keep Keep the default order of categories, corresponding to the
981 sequence in `org-agenda-files'.
982 category-up Sort alphabetically by category, A-Z.
983 category-down Sort alphabetically by category, Z-A.
984 tag-up Sort alphabetically by last tag, A-Z.
985 tag-down Sort alphabetically by last tag, Z-A.
986 priority-up Sort numerically by priority, high priority last.
987 priority-down Sort numerically by priority, high priority first.
988 todo-state-up Sort by todo state, tasks that are done last.
989 todo-state-down Sort by todo state, tasks that are done first.
990 effort-up Sort numerically by estimated effort, high effort last.
991 effort-down Sort numerically by estimated effort, high effort first.
992 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
993 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
994 habit-up Put entries that are habits first
995 habit-down Put entries that are habits last
997 The different possibilities will be tried in sequence, and testing stops
998 if one comparison returns a \"not-equal\". For example, the default
999 '(time-up category-keep priority-down)
1000 means: Pull out all entries having a specified time of day and sort them,
1001 in order to make a time schedule for the current day the first thing in the
1002 agenda listing for the day. Of the entries without a time indication, keep
1003 the grouped in categories, don't sort the categories, but keep them in
1004 the sequence given in `org-agenda-files'. Within each category sort by
1005 priority.
1007 Leaving out `category-keep' would mean that items will be sorted across
1008 categories by priority.
1010 Instead of a single list, this can also be a set of list for specific
1011 contents, with a context symbol in the car of the list, any of
1012 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1014 Custom commands can bind this variable in the options section."
1015 :group 'org-agenda-sorting
1016 :type `(choice
1017 (repeat :tag "General" ,org-sorting-choice)
1018 (list :tag "Individually"
1019 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1020 (repeat ,org-sorting-choice))
1021 (cons (const :tag "Strategy for TODO lists" todo)
1022 (repeat ,org-sorting-choice))
1023 (cons (const :tag "Strategy for Tags matches" tags)
1024 (repeat ,org-sorting-choice))
1025 (cons (const :tag "Strategy for search matches" search)
1026 (repeat ,org-sorting-choice)))))
1028 (defcustom org-agenda-cmp-user-defined nil
1029 "A function to define the comparison `user-defined'.
1030 This function must receive two arguments, agenda entry a and b.
1031 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1032 the user comparison, return nil.
1033 When this is defined, you can make `user-defined-up' and `user-defined-down'
1034 part of an agenda sorting strategy."
1035 :group 'org-agenda-sorting
1036 :type 'symbol)
1038 (defcustom org-sort-agenda-notime-is-late t
1039 "Non-nil means, items without time are considered late.
1040 This is only relevant for sorting. When t, items which have no explicit
1041 time like 15:30 will be considered as 99:01, i.e. later than any items which
1042 do have a time. When nil, the default time is before 0:00. You can use this
1043 option to decide if the schedule for today should come before or after timeless
1044 agenda entries."
1045 :group 'org-agenda-sorting
1046 :type 'boolean)
1048 (defcustom org-sort-agenda-noeffort-is-high t
1049 "Non-nil means, items without effort estimate are sorted as high effort.
1050 This also applies when filtering an agenda view with respect to the
1051 < or > effort operator. Then, tasks with no effort defined will be treated
1052 as tasks with high effort.
1053 When nil, such items are sorted as 0 minutes effort."
1054 :group 'org-agenda-sorting
1055 :type 'boolean)
1057 (defgroup org-agenda-line-format nil
1058 "Options concerning the entry prefix in the Org-mode agenda display."
1059 :tag "Org Agenda Line Format"
1060 :group 'org-agenda)
1062 (defcustom org-agenda-prefix-format
1063 '((agenda . " %-12:c%?-12t% s")
1064 (timeline . " % s")
1065 (todo . " %-12:c")
1066 (tags . " %-12:c")
1067 (search . " %-12:c"))
1068 "Format specifications for the prefix of items in the agenda views.
1069 An alist with four entries, for the different agenda types. The keys to the
1070 sublists are `agenda', `timeline', `todo', and `tags'. The values
1071 are format strings.
1072 This format works similar to a printf format, with the following meaning:
1074 %c the category of the item, \"Diary\" for entries from the diary, or
1075 as given by the CATEGORY keyword or derived from the file name.
1076 %T the *last* tag of the item. Last because inherited tags come
1077 first in the list.
1078 %t the time-of-day specification if one applies to the entry, in the
1079 format HH:MM
1080 %s Scheduling/Deadline information, a short string
1082 All specifiers work basically like the standard `%s' of printf, but may
1083 contain two additional characters: A question mark just after the `%' and
1084 a whitespace/punctuation character just before the final letter.
1086 If the first character after `%' is a question mark, the entire field
1087 will only be included if the corresponding value applies to the
1088 current entry. This is useful for fields which should have fixed
1089 width when present, but zero width when absent. For example,
1090 \"%?-12t\" will result in a 12 character time field if a time of the
1091 day is specified, but will completely disappear in entries which do
1092 not contain a time.
1094 If there is punctuation or whitespace character just before the final
1095 format letter, this character will be appended to the field value if
1096 the value is not empty. For example, the format \"%-12:c\" leads to
1097 \"Diary: \" if the category is \"Diary\". If the category were be
1098 empty, no additional colon would be inserted.
1100 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1101 - Indent the line with two space characters
1102 - Give the category in a 12 chars wide field, padded with whitespace on
1103 the right (because of `-'). Append a colon if there is a category
1104 (because of `:').
1105 - If there is a time-of-day, put it into a 12 chars wide field. If no
1106 time, don't put in an empty field, just skip it (because of '?').
1107 - Finally, put the scheduling information and append a whitespace.
1109 As another example, if you don't want the time-of-day of entries in
1110 the prefix, you could use:
1112 (setq org-agenda-prefix-format \" %-11:c% s\")
1114 See also the variables `org-agenda-remove-times-when-in-prefix' and
1115 `org-agenda-remove-tags'.
1117 Custom commands can set this variable in the options section."
1118 :type '(choice
1119 (string :tag "General format")
1120 (list :greedy t :tag "View dependent"
1121 (cons (const agenda) (string :tag "Format"))
1122 (cons (const timeline) (string :tag "Format"))
1123 (cons (const todo) (string :tag "Format"))
1124 (cons (const tags) (string :tag "Format"))
1125 (cons (const search) (string :tag "Format"))))
1126 :group 'org-agenda-line-format)
1128 (defvar org-prefix-format-compiled nil
1129 "The compiled version of the most recently used prefix format.
1130 See the variable `org-agenda-prefix-format'.")
1132 (defcustom org-agenda-todo-keyword-format "%-1s"
1133 "Format for the TODO keyword in agenda lines.
1134 Set this to something like \"%-12s\" if you want all TODO keywords
1135 to occupy a fixed space in the agenda display."
1136 :group 'org-agenda-line-format
1137 :type 'string)
1139 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1140 "Text preceding timerange entries in the agenda view.
1141 This is a list with two strings. The first applies when the range
1142 is entirely on one day. The second applies if the range spans several days.
1143 The strings may have two \"%d\" format specifiers which will be filled
1144 with the sequence number of the days, and the total number of days in the
1145 range, respectively."
1146 :group 'org-agenda-line-format
1147 :type '(list
1148 (string :tag "Deadline today ")
1149 (choice :tag "Deadline relative"
1150 (string :tag "Format string")
1151 (function))))
1153 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1154 "Text preceeding scheduled items in the agenda view.
1155 This is a list with two strings. The first applies when the item is
1156 scheduled on the current day. The second applies when it has been scheduled
1157 previously, it may contain a %d indicating that this is the nth time that
1158 this item is scheduled, due to automatic rescheduling of unfinished items
1159 for the following day. So this number is one larger than the number of days
1160 that passed since this item was scheduled first."
1161 :group 'org-agenda-line-format
1162 :type '(list
1163 (string :tag "Scheduled today ")
1164 (string :tag "Scheduled previously")))
1166 (defcustom org-agenda-inactive-leader "["
1167 "Text preceeding item pulled into the agenda by inactive time stamps.
1168 These entries are added to the agenda when pressing \"[\"."
1169 :group 'org-agenda-line-format
1170 :type '(list
1171 (string :tag "Scheduled today ")
1172 (string :tag "Scheduled previously")))
1174 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1175 "Text preceeding deadline items in the agenda view.
1176 This is a list with two strings. The first applies when the item has its
1177 deadline on the current day. The second applies when it is in the past or
1178 in the future, it may contain %d to capture how many days away the deadline
1179 is (was)."
1180 :group 'org-agenda-line-format
1181 :type '(list
1182 (string :tag "Deadline today ")
1183 (choice :tag "Deadline relative"
1184 (string :tag "Format string")
1185 (function))))
1187 (defcustom org-agenda-remove-times-when-in-prefix t
1188 "Non-nil means, remove duplicate time specifications in agenda items.
1189 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1190 time-of-day specification in a headline or diary entry is extracted and
1191 placed into the prefix. If this option is non-nil, the original specification
1192 \(a timestamp or -range, or just a plain time(range) specification like
1193 11:30-4pm) will be removed for agenda display. This makes the agenda less
1194 cluttered.
1195 The option can be t or nil. It may also be the symbol `beg', indicating
1196 that the time should only be removed what it is located at the beginning of
1197 the headline/diary entry."
1198 :group 'org-agenda-line-format
1199 :type '(choice
1200 (const :tag "Always" t)
1201 (const :tag "Never" nil)
1202 (const :tag "When at beginning of entry" beg)))
1205 (defcustom org-agenda-default-appointment-duration nil
1206 "Default duration for appointments that only have a starting time.
1207 When nil, no duration is specified in such cases.
1208 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1209 :group 'org-agenda-line-format
1210 :type '(choice
1211 (integer :tag "Minutes")
1212 (const :tag "No default duration")))
1214 (defcustom org-agenda-show-inherited-tags t
1215 "Non-nil means, show inherited tags in each agenda line."
1216 :group 'org-agenda-line-format
1217 :type 'boolean)
1219 (defcustom org-agenda-hide-tags-regexp nil
1220 "Regular expression used to filter away specific tags in agenda views.
1221 This means that these tags will be present, but not be shown in the agenda
1222 line. Secondayt filltering will still work on the hidden tags.
1223 Nil means don't hide any tags."
1224 :group 'org-agenda-line-format
1225 :type '(choice
1226 (const :tag "Hide none" nil)
1227 (string :tag "Regexp ")))
1229 (defcustom org-agenda-remove-tags nil
1230 "Non-nil means, remove the tags from the headline copy in the agenda.
1231 When this is the symbol `prefix', only remove tags when
1232 `org-agenda-prefix-format' contains a `%T' specifier."
1233 :group 'org-agenda-line-format
1234 :type '(choice
1235 (const :tag "Always" t)
1236 (const :tag "Never" nil)
1237 (const :tag "When prefix format contains %T" prefix)))
1239 (if (fboundp 'defvaralias)
1240 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1241 'org-agenda-remove-tags))
1243 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1244 "Shift tags in agenda items to this column.
1245 If this number is positive, it specifies the column. If it is negative,
1246 it means that the tags should be flushright to that column. For example,
1247 -80 works well for a normal 80 character screen."
1248 :group 'org-agenda-line-format
1249 :type 'integer)
1251 (if (fboundp 'defvaralias)
1252 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1254 (defcustom org-agenda-fontify-priorities 'cookies
1255 "Non-nil means, highlight low and high priorities in agenda.
1256 When t, the highest priority entries are bold, lowest priority italic.
1257 However, settings in org-priority-faces will overrule these faces.
1258 When this variable is the symbol `cookies', only fontify the
1259 cookies, not the entire task.
1260 This may also be an association list of priority faces, whose
1261 keys are the character values of `org-highest-priority',
1262 `org-default-priority', and `org-lowest-priority' (the default values
1263 are ?A, ?B, and ?C, respectively). The face may be a named face,
1264 or a list like `(:background \"Red\")'."
1265 :group 'org-agenda-line-format
1266 :type '(choice
1267 (const :tag "Never" nil)
1268 (const :tag "Defaults" t)
1269 (const :tag "Cookies only" cookies)
1270 (repeat :tag "Specify"
1271 (list (character :tag "Priority" :value ?A)
1272 (sexp :tag "face")))))
1274 (defgroup org-agenda-column-view nil
1275 "Options concerning column view in the agenda."
1276 :tag "Org Agenda Column View"
1277 :group 'org-agenda)
1279 (defcustom org-agenda-columns-show-summaries t
1280 "Non-nil means, show summaries for columns displayed in the agenda view."
1281 :group 'org-agenda-column-view
1282 :type 'boolean)
1284 (defcustom org-agenda-columns-remove-prefix-from-item t
1285 "Non-nil means, remove the prefix from a headline for agenda column view.
1286 The special ITEM field in the columns format contains the current line, with
1287 all information shown in other columns (like the TODO state or a tag).
1288 When this variable is non-nil, also the agenda prefix will be removed from
1289 the content of the ITEM field, to make sure as much as possible of the
1290 headline can be shown in the limited width of the field."
1291 :group 'org-agenda
1292 :type 'boolean)
1294 (defcustom org-agenda-columns-compute-summary-properties t
1295 "Non-nil means, recompute all summary properties before column view.
1296 When column view in the agenda is listing properties that have a summary
1297 operator, it can go to all relevant buffers and recompute the summaries
1298 there. This can mean overhead for the agenda column view, but is necessary
1299 to have thing up to date.
1300 As a special case, a CLOCKSUM property also makes sure that the clock
1301 computations are current."
1302 :group 'org-agenda-column-view
1303 :type 'boolean)
1305 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1306 "Non-nil means, the duration of an appointment will add to day effort.
1307 The property to which appointment durations will be added is the one given
1308 in the option `org-effort-property'. If an appointment does not have
1309 an end time, `org-agenda-default-appointment-duration' will be used. If that
1310 is not set, an appointment without end time will not contribute to the time
1311 estimate."
1312 :group 'org-agenda-column-view
1313 :type 'boolean)
1315 (defcustom org-agenda-auto-exclude-function nil
1316 "A function called with a tag to decide if it is filtered on '/ RET'.
1317 The sole argument to the function, which is called once for each
1318 possible tag, is a string giving the name of the tag. The
1319 function should return either nil if the tag should be included
1320 as normal, or \"-<TAG>\" to exclude the tag.
1321 Note that for the purpose of tag filtering, only the lower-case version of
1322 all tags will be considered, so that this function will only ever see
1323 the lower-case version of all tags."
1324 :group 'org-agenda
1325 :type 'function)
1327 (eval-when-compile
1328 (require 'cl))
1329 (require 'org)
1331 (defun org-add-agenda-custom-command (entry)
1332 "Replace or add a command in `org-agenda-custom-commands'.
1333 This is mostly for hacking and trying a new command - once the command
1334 works you probably want to add it to `org-agenda-custom-commands' for good."
1335 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1336 (if ass
1337 (setcdr ass (cdr entry))
1338 (push entry org-agenda-custom-commands))))
1340 ;;; Define the Org-agenda-mode
1342 (defvar org-agenda-mode-map (make-sparse-keymap)
1343 "Keymap for `org-agenda-mode'.")
1344 (if (fboundp 'defvaralias)
1345 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1347 (defvar org-agenda-menu) ; defined later in this file.
1348 (defvar org-agenda-restrict) ; defined later in this file.
1349 (defvar org-agenda-follow-mode nil)
1350 (defvar org-agenda-entry-text-mode nil)
1351 (defvar org-agenda-clockreport-mode nil)
1352 (defvar org-agenda-show-log nil)
1353 (defvar org-agenda-redo-command nil)
1354 (defvar org-agenda-query-string nil)
1355 (defvar org-agenda-mode-hook nil
1356 "Hook for org-agenda-mode, run after the mode is turned on.")
1357 (defvar org-agenda-type nil)
1358 (defvar org-agenda-force-single-file nil)
1359 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1361 (defun org-agenda-mode ()
1362 "Mode for time-sorted view on action items in Org-mode files.
1364 The following commands are available:
1366 \\{org-agenda-mode-map}"
1367 (interactive)
1368 (kill-all-local-variables)
1369 (setq org-agenda-undo-list nil
1370 org-agenda-pending-undo-list nil
1371 org-agenda-bulk-marked-entries nil)
1372 (setq major-mode 'org-agenda-mode)
1373 ;; Keep global-font-lock-mode from turning on font-lock-mode
1374 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1375 (setq mode-name "Org-Agenda")
1376 (use-local-map org-agenda-mode-map)
1377 (easy-menu-add org-agenda-menu)
1378 (if org-startup-truncated (setq truncate-lines t))
1379 (org-set-local 'line-move-visual nil)
1380 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1381 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1382 ;; Make sure properties are removed when copying text
1383 (when (boundp 'buffer-substring-filters)
1384 (org-set-local 'buffer-substring-filters
1385 (cons (lambda (x)
1386 (set-text-properties 0 (length x) nil x) x)
1387 buffer-substring-filters)))
1388 (unless org-agenda-keep-modes
1389 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1390 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1391 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1392 org-agenda-show-log org-agenda-start-with-log-mode))
1394 (easy-menu-change
1395 '("Agenda") "Agenda Files"
1396 (append
1397 (list
1398 (vector
1399 (if (get 'org-agenda-files 'org-restrict)
1400 "Restricted to single file"
1401 "Edit File List")
1402 '(org-edit-agenda-file-list)
1403 (not (get 'org-agenda-files 'org-restrict)))
1404 "--")
1405 (mapcar 'org-file-menu-entry (org-agenda-files))))
1406 (org-agenda-set-mode-name)
1407 (apply
1408 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1409 (list 'org-agenda-mode-hook)))
1411 (substitute-key-definition 'undo 'org-agenda-undo
1412 org-agenda-mode-map global-map)
1413 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1414 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1415 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1416 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1417 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1418 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1419 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1420 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1421 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1422 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1423 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1424 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1425 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1426 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1427 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1428 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1429 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1430 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1431 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1432 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1433 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1434 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1435 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1436 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1437 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1438 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1439 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1440 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1441 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1442 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1443 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1444 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1445 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1446 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1447 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1448 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1449 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1450 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1451 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1452 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1453 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1454 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1455 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1457 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1458 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1459 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1460 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1461 (while l (org-defkey org-agenda-mode-map
1462 (int-to-string (pop l)) 'digit-argument)))
1464 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1465 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1466 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1467 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1468 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1469 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1470 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1471 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1472 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1473 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1474 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1475 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1476 'org-clock-modify-effort-estimate)
1477 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1478 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1479 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1480 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1481 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1482 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1483 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1484 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1485 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1486 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1487 (substitute-key-definition 'next-line 'org-agenda-next-line
1488 org-agenda-mode-map global-map)
1489 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1490 org-agenda-mode-map global-map)
1491 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1492 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1493 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1494 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1495 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1496 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1497 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1498 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1499 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1500 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1501 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1502 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1503 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1504 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1505 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1506 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1507 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1508 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1509 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1510 (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
1511 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1512 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1513 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1514 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1515 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1516 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1517 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1518 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1519 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1520 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1522 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1523 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1524 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1525 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1526 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1527 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1528 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1529 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1530 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1531 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1533 (org-defkey org-agenda-mode-map
1534 (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
1535 (org-defkey org-agenda-mode-map
1536 (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
1537 (when org-agenda-mouse-1-follows-link
1538 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1539 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1540 '("Agenda"
1541 ("Agenda Files")
1542 "--"
1543 ("Agenda Dates"
1544 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1545 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1546 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1547 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1548 "--"
1549 ("View"
1550 ["Day View" org-agenda-day-view
1551 :active (org-agenda-check-type nil 'agenda)
1552 :style radio :selected (equal org-agenda-ndays 1)
1553 :keys "v d (or just d)"]
1554 ["Week View" org-agenda-week-view
1555 :active (org-agenda-check-type nil 'agenda)
1556 :style radio :selected (equal org-agenda-ndays 7)
1557 :keys "v w (or just w)"]
1558 ["Month View" org-agenda-month-view
1559 :active (org-agenda-check-type nil 'agenda)
1560 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1561 :keys "v m"]
1562 ["Year View" org-agenda-year-view
1563 :active (org-agenda-check-type nil 'agenda)
1564 :style radio :selected (member org-agenda-ndays '(365 366))
1565 :keys "v y"]
1566 "--"
1567 ["Include Diary" org-agenda-toggle-diary
1568 :style toggle :selected org-agenda-include-diary
1569 :active (org-agenda-check-type nil 'agenda)]
1570 ["Use Time Grid" org-agenda-toggle-time-grid
1571 :style toggle :selected org-agenda-use-time-grid
1572 :active (org-agenda-check-type nil 'agenda)]
1573 "--"
1574 ["Show clock report" org-agenda-clockreport-mode
1575 :style toggle :selected org-agenda-clockreport-mode
1576 :active (org-agenda-check-type nil 'agenda)]
1577 ["Show some entry text" org-agenda-entry-text-mode
1578 :style toggle :selected org-agenda-entry-text-mode
1579 :active t]
1580 "--"
1581 ["Show Logbook entries" org-agenda-log-mode
1582 :style toggle :selected org-agenda-show-log
1583 :active (org-agenda-check-type nil 'agenda 'timeline)
1584 :keys "v l (or just l)"]
1585 ["Include archived trees" org-agenda-archives-mode
1586 :style toggle :selected org-agenda-archives-mode :active t
1587 :keys "v a"]
1588 ["Include archive files" (org-agenda-archives-mode t)
1589 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1590 :keys "v A"]
1591 "--"
1592 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1593 ["Write view to file" org-write-agenda t]
1594 ["Rebuild buffer" org-agenda-redo t]
1595 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1596 "--"
1597 ["Show original entry" org-agenda-show t]
1598 ["Go To (other window)" org-agenda-goto t]
1599 ["Go To (this window)" org-agenda-switch-to t]
1600 ["Follow Mode" org-agenda-follow-mode
1601 :style toggle :selected org-agenda-follow-mode :active t]
1602 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1603 "--"
1604 ("TODO"
1605 ["Cycle TODO" org-agenda-todo t]
1606 ["Next TODO set" org-agenda-todo-nextset t]
1607 ["Previous TODO set" org-agenda-todo-previousset t]
1608 ["Add note" org-agenda-add-note t])
1609 ("Archive/Refile/Delete"
1610 ["Archive default" org-agenda-archive-default t]
1611 ["Archive default" org-agenda-archive-default-with-confirmation t]
1612 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1613 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1614 ["Archive subtree" org-agenda-archive t]
1615 "--"
1616 ["Refile" org-agenda-refile t]
1617 "--"
1618 ["Delete subtree" org-agenda-kill t])
1619 ("Bulk action"
1620 ["Mark entry" org-agenda-bulk-mark t]
1621 ["Unmark entry" org-agenda-bulk-unmark t]
1622 ["Act on all marked" org-agenda-bulk-action t]
1623 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1624 "--"
1625 ("Tags and Properties"
1626 ["Show all Tags" org-agenda-show-tags t]
1627 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1628 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1629 "--"
1630 ["Column View" org-columns t])
1631 ("Deadline/Schedule"
1632 ["Schedule" org-agenda-schedule t]
1633 ["Set Deadline" org-agenda-deadline t]
1634 "--"
1635 ["Mark item" org-agenda-action :active t :keys "k m"]
1636 ["Show mark item" org-agenda-action :active t :keys "k v"]
1637 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1638 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1639 "--"
1640 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1641 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1642 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1643 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1644 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1645 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1646 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1647 ("Clock and Effort"
1648 ["Clock in" org-agenda-clock-in t]
1649 ["Clock out" org-agenda-clock-out t]
1650 ["Clock cancel" org-agenda-clock-cancel t]
1651 ["Goto running clock" org-clock-goto t]
1652 "--"
1653 ["Set Effort" org-agenda-set-effort t]
1654 ["Change clocked effort" org-clock-modify-effort-estimate
1655 (org-clock-is-active)])
1656 ("Priority"
1657 ["Set Priority" org-agenda-priority t]
1658 ["Increase Priority" org-agenda-priority-up t]
1659 ["Decrease Priority" org-agenda-priority-down t]
1660 ["Show Priority" org-agenda-show-priority t])
1661 ("Calendar/Diary"
1662 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1663 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1664 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1665 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1666 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1667 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1668 "--"
1669 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1670 "--"
1671 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1672 "--"
1673 ("MobileOrg"
1674 ["Push Files and Views" org-mobile-push t]
1675 ["Get Captured and Flagged" org-mobile-pull t]
1676 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1677 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1678 "--"
1679 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1680 "--"
1681 ["Quit" org-agenda-quit t]
1682 ["Exit and Release Buffers" org-agenda-exit t]
1685 ;;; Agenda undo
1687 (defvar org-agenda-allow-remote-undo t
1688 "Non-nil means, allow remote undo from the agenda buffer.")
1689 (defvar org-agenda-undo-list nil
1690 "List of undoable operations in the agenda since last refresh.")
1691 (defvar org-agenda-undo-has-started-in nil
1692 "Buffers that have already seen `undo-start' in the current undo sequence.")
1693 (defvar org-agenda-pending-undo-list nil
1694 "In a series of undo commands, this is the list of remaining undo items.")
1697 (defun org-agenda-undo ()
1698 "Undo a remote editing step in the agenda.
1699 This undoes changes both in the agenda buffer and in the remote buffer
1700 that have been changed along."
1701 (interactive)
1702 (or org-agenda-allow-remote-undo
1703 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1704 (if (not (eq this-command last-command))
1705 (setq org-agenda-undo-has-started-in nil
1706 org-agenda-pending-undo-list org-agenda-undo-list))
1707 (if (not org-agenda-pending-undo-list)
1708 (error "No further undo information"))
1709 (let* ((entry (pop org-agenda-pending-undo-list))
1710 buf line cmd rembuf)
1711 (setq cmd (pop entry) line (pop entry))
1712 (setq rembuf (nth 2 entry))
1713 (org-with-remote-undo rembuf
1714 (while (bufferp (setq buf (pop entry)))
1715 (if (pop entry)
1716 (with-current-buffer buf
1717 (let ((last-undo-buffer buf)
1718 (inhibit-read-only t))
1719 (unless (memq buf org-agenda-undo-has-started-in)
1720 (push buf org-agenda-undo-has-started-in)
1721 (make-local-variable 'pending-undo-list)
1722 (undo-start))
1723 (while (and pending-undo-list
1724 (listp pending-undo-list)
1725 (not (car pending-undo-list)))
1726 (pop pending-undo-list))
1727 (undo-more 1))))))
1728 (org-goto-line line)
1729 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1731 (defun org-verify-change-for-undo (l1 l2)
1732 "Verify that a real change occurred between the undo lists L1 and L2."
1733 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1734 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1735 (not (eq l1 l2)))
1737 ;;; Agenda dispatch
1739 (defvar org-agenda-restrict nil)
1740 (defvar org-agenda-restrict-begin (make-marker))
1741 (defvar org-agenda-restrict-end (make-marker))
1742 (defvar org-agenda-last-dispatch-buffer nil)
1743 (defvar org-agenda-overriding-restriction nil)
1745 ;;;###autoload
1746 (defun org-agenda (&optional arg keys restriction)
1747 "Dispatch agenda commands to collect entries to the agenda buffer.
1748 Prompts for a command to execute. Any prefix arg will be passed
1749 on to the selected command. The default selections are:
1751 a Call `org-agenda-list' to display the agenda for current day or week.
1752 t Call `org-todo-list' to display the global todo list.
1753 T Call `org-todo-list' to display the global todo list, select only
1754 entries with a specific TODO keyword (the user gets a prompt).
1755 m Call `org-tags-view' to display headlines with tags matching
1756 a condition (the user is prompted for the condition).
1757 M Like `m', but select only TODO entries, no ordinary headlines.
1758 L Create a timeline for the current buffer.
1759 e Export views to associated files.
1760 s Search entries for keywords.
1761 / Multi occur across all agenda files and also files listed
1762 in `org-agenda-text-search-extra-files'.
1763 < Restrict agenda commands to buffer, subtree, or region.
1764 Press several times to get the desired effect.
1765 > Remove a previous restriction.
1766 # List \"stuck\" projects.
1767 ! Configure what \"stuck\" means.
1768 C Configure custom agenda commands.
1770 More commands can be added by configuring the variable
1771 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1772 searches can be pre-defined in this way.
1774 If the current buffer is in Org-mode and visiting a file, you can also
1775 first press `<' once to indicate that the agenda should be temporarily
1776 \(until the next use of \\[org-agenda]) restricted to the current file.
1777 Pressing `<' twice means to restrict to the current subtree or region
1778 \(if active)."
1779 (interactive "P")
1780 (catch 'exit
1781 (let* ((prefix-descriptions nil)
1782 (org-agenda-window-setup (if (equal (buffer-name)
1783 org-agenda-buffer-name)
1784 'current-window
1785 org-agenda-window-setup))
1786 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1787 (org-agenda-custom-commands
1788 ;; normalize different versions
1789 (delq nil
1790 (mapcar
1791 (lambda (x)
1792 (cond ((stringp (cdr x))
1793 (push x prefix-descriptions)
1794 nil)
1795 ((stringp (nth 1 x)) x)
1796 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1797 (t (cons (car x) (cons "" (cdr x))))))
1798 org-agenda-custom-commands)))
1799 (buf (current-buffer))
1800 (bfn (buffer-file-name (buffer-base-buffer)))
1801 entry key type match lprops ans)
1802 ;; Turn off restriction unless there is an overriding one,
1803 (unless org-agenda-overriding-restriction
1804 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
1805 ;; There is a request to keep the file list in place
1806 (put 'org-agenda-files 'org-restrict nil))
1807 (setq org-agenda-restrict nil)
1808 (move-marker org-agenda-restrict-begin nil)
1809 (move-marker org-agenda-restrict-end nil))
1810 ;; Delete old local properties
1811 (put 'org-agenda-redo-command 'org-lprops nil)
1812 ;; Remember where this call originated
1813 (setq org-agenda-last-dispatch-buffer (current-buffer))
1814 (unless keys
1815 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1816 keys (car ans)
1817 restriction (cdr ans)))
1818 ;; Establish the restriction, if any
1819 (when (and (not org-agenda-overriding-restriction) restriction)
1820 (put 'org-agenda-files 'org-restrict (list bfn))
1821 (cond
1822 ((eq restriction 'region)
1823 (setq org-agenda-restrict t)
1824 (move-marker org-agenda-restrict-begin (region-beginning))
1825 (move-marker org-agenda-restrict-end (region-end)))
1826 ((eq restriction 'subtree)
1827 (save-excursion
1828 (setq org-agenda-restrict t)
1829 (org-back-to-heading t)
1830 (move-marker org-agenda-restrict-begin (point))
1831 (move-marker org-agenda-restrict-end
1832 (progn (org-end-of-subtree t)))))))
1834 (require 'calendar) ; FIXME: can we avoid this for some commands?
1835 ;; For example the todo list should not need it (but does...)
1836 (cond
1837 ((setq entry (assoc keys org-agenda-custom-commands))
1838 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
1839 (progn
1840 (setq type (nth 2 entry) match (eval (nth 3 entry))
1841 lprops (nth 4 entry))
1842 (put 'org-agenda-redo-command 'org-lprops lprops)
1843 (cond
1844 ((eq type 'agenda)
1845 (org-let lprops '(org-agenda-list current-prefix-arg)))
1846 ((eq type 'alltodo)
1847 (org-let lprops '(org-todo-list current-prefix-arg)))
1848 ((eq type 'search)
1849 (org-let lprops '(org-search-view current-prefix-arg match nil)))
1850 ((eq type 'stuck)
1851 (org-let lprops '(org-agenda-list-stuck-projects
1852 current-prefix-arg)))
1853 ((eq type 'tags)
1854 (org-let lprops '(org-tags-view current-prefix-arg match)))
1855 ((eq type 'tags-todo)
1856 (org-let lprops '(org-tags-view '(4) match)))
1857 ((eq type 'todo)
1858 (org-let lprops '(org-todo-list match)))
1859 ((eq type 'tags-tree)
1860 (org-check-for-org-mode)
1861 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
1862 ((eq type 'todo-tree)
1863 (org-check-for-org-mode)
1864 (org-let lprops
1865 '(org-occur (concat "^" outline-regexp "[ \t]*"
1866 (regexp-quote match) "\\>"))))
1867 ((eq type 'occur-tree)
1868 (org-check-for-org-mode)
1869 (org-let lprops '(org-occur match)))
1870 ((functionp type)
1871 (org-let lprops '(funcall type match)))
1872 ((fboundp type)
1873 (org-let lprops '(funcall type match)))
1874 (t (error "Invalid custom agenda command type %s" type))))
1875 (org-run-agenda-series (nth 1 entry) (cddr entry))))
1876 ((equal keys "C")
1877 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
1878 (customize-variable 'org-agenda-custom-commands))
1879 ((equal keys "a") (call-interactively 'org-agenda-list))
1880 ((equal keys "s") (call-interactively 'org-search-view))
1881 ((equal keys "t") (call-interactively 'org-todo-list))
1882 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
1883 ((equal keys "m") (call-interactively 'org-tags-view))
1884 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
1885 ((equal keys "e") (call-interactively 'org-store-agenda-views))
1886 ((equal keys "?") (org-tags-view nil "+FLAGGED")
1887 (org-add-hook
1888 'post-command-hook
1889 (lambda ()
1890 (unless (current-message)
1891 (let* ((m (org-agenda-get-any-marker))
1892 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
1893 (when note
1894 (message (concat
1895 "FLAGGING-NOTE ([?] for more info): "
1896 (org-add-props
1897 (replace-regexp-in-string
1898 "\\\\n" "//"
1899 (copy-sequence note))
1900 nil 'face 'org-warning)))))))
1901 t t))
1902 ((equal keys "L")
1903 (unless (org-mode-p)
1904 (error "This is not an Org-mode file"))
1905 (unless restriction
1906 (put 'org-agenda-files 'org-restrict (list bfn))
1907 (org-call-with-arg 'org-timeline arg)))
1908 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
1909 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
1910 ((equal keys "!") (customize-variable 'org-stuck-projects))
1911 (t (error "Invalid agenda key"))))))
1913 (defun org-agenda-normalize-custom-commands (cmds)
1914 (delq nil
1915 (mapcar
1916 (lambda (x)
1917 (cond ((stringp (cdr x)) nil)
1918 ((stringp (nth 1 x)) x)
1919 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1920 (t (cons (car x) (cons "" (cdr x))))))
1921 cmds)))
1923 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1924 "The user interface for selecting an agenda command."
1925 (catch 'exit
1926 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1927 (restrict-ok (and bfn (org-mode-p)))
1928 (region-p (org-region-active-p))
1929 (custom org-agenda-custom-commands)
1930 (selstring "")
1931 restriction second-time
1932 c entry key type match prefixes rmheader header-end custom1 desc)
1933 (save-window-excursion
1934 (delete-other-windows)
1935 (org-switch-to-buffer-other-window " *Agenda Commands*")
1936 (erase-buffer)
1937 (insert (eval-when-compile
1938 (let ((header
1940 Press key for an agenda command: < Buffer, subtree/region restriction
1941 -------------------------------- > Remove restriction
1942 a Agenda for current week or day e Export agenda views
1943 t List of all TODO entries T Entries with special TODO kwd
1944 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1945 L Timeline for current buffer # List stuck projects (!=configure)
1946 s Search for keywords C Configure custom agenda commands
1947 / Multi-occur ? Find :FLAGGED: entries
1949 (start 0))
1950 (while (string-match
1951 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1952 header start)
1953 (setq start (match-end 0))
1954 (add-text-properties (match-beginning 2) (match-end 2)
1955 '(face bold) header))
1956 header)))
1957 (setq header-end (move-marker (make-marker) (point)))
1958 (while t
1959 (setq custom1 custom)
1960 (when (eq rmheader t)
1961 (org-goto-line 1)
1962 (re-search-forward ":" nil t)
1963 (delete-region (match-end 0) (point-at-eol))
1964 (forward-char 1)
1965 (looking-at "-+")
1966 (delete-region (match-end 0) (point-at-eol))
1967 (move-marker header-end (match-end 0)))
1968 (goto-char header-end)
1969 (delete-region (point) (point-max))
1970 (while (setq entry (pop custom1))
1971 (setq key (car entry) desc (nth 1 entry)
1972 type (nth 2 entry)
1973 match (nth 3 entry))
1974 (if (> (length key) 1)
1975 (add-to-list 'prefixes (string-to-char key))
1976 (insert
1977 (format
1978 "\n%-4s%-14s: %s"
1979 (org-add-props (copy-sequence key)
1980 '(face bold))
1981 (cond
1982 ((string-match "\\S-" desc) desc)
1983 ((eq type 'agenda) "Agenda for current week or day")
1984 ((eq type 'alltodo) "List of all TODO entries")
1985 ((eq type 'search) "Word search")
1986 ((eq type 'stuck) "List of stuck projects")
1987 ((eq type 'todo) "TODO keyword")
1988 ((eq type 'tags) "Tags query")
1989 ((eq type 'tags-todo) "Tags (TODO)")
1990 ((eq type 'tags-tree) "Tags tree")
1991 ((eq type 'todo-tree) "TODO kwd tree")
1992 ((eq type 'occur-tree) "Occur tree")
1993 ((functionp type) (if (symbolp type)
1994 (symbol-name type)
1995 "Lambda expression"))
1996 (t "???"))
1997 (cond
1998 ((stringp match)
1999 (setq match (copy-sequence match))
2000 (org-add-props match nil 'face 'org-warning))
2001 (match
2002 (format "set of %d commands" (length match)))
2003 (t ""))))))
2004 (when prefixes
2005 (mapc (lambda (x)
2006 (insert
2007 (format "\n%s %s"
2008 (org-add-props (char-to-string x)
2009 nil 'face 'bold)
2010 (or (cdr (assoc (concat selstring (char-to-string x))
2011 prefix-descriptions))
2012 "Prefix key"))))
2013 prefixes))
2014 (goto-char (point-min))
2015 (if second-time
2016 (if (not (pos-visible-in-window-p (point-max)))
2017 (org-fit-window-to-buffer))
2018 (setq second-time t)
2019 (org-fit-window-to-buffer))
2020 (message "Press key for agenda command%s:"
2021 (if (or restrict-ok org-agenda-overriding-restriction)
2022 (if org-agenda-overriding-restriction
2023 " (restriction lock active)"
2024 (if restriction
2025 (format " (restricted to %s)" restriction)
2026 " (unrestricted)"))
2027 ""))
2028 (setq c (read-char-exclusive))
2029 (message "")
2030 (cond
2031 ((assoc (char-to-string c) custom)
2032 (setq selstring (concat selstring (char-to-string c)))
2033 (throw 'exit (cons selstring restriction)))
2034 ((memq c prefixes)
2035 (setq selstring (concat selstring (char-to-string c))
2036 prefixes nil
2037 rmheader (or rmheader t)
2038 custom (delq nil (mapcar
2039 (lambda (x)
2040 (if (or (= (length (car x)) 1)
2041 (/= (string-to-char (car x)) c))
2043 (cons (substring (car x) 1) (cdr x))))
2044 custom))))
2045 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2046 (message "Restriction is only possible in Org-mode buffers")
2047 (ding) (sit-for 1))
2048 ((eq c ?1)
2049 (org-agenda-remove-restriction-lock 'noupdate)
2050 (setq restriction 'buffer))
2051 ((eq c ?0)
2052 (org-agenda-remove-restriction-lock 'noupdate)
2053 (setq restriction (if region-p 'region 'subtree)))
2054 ((eq c ?<)
2055 (org-agenda-remove-restriction-lock 'noupdate)
2056 (setq restriction
2057 (cond
2058 ((eq restriction 'buffer)
2059 (if region-p 'region 'subtree))
2060 ((memq restriction '(subtree region))
2061 nil)
2062 (t 'buffer))))
2063 ((eq c ?>)
2064 (org-agenda-remove-restriction-lock 'noupdate)
2065 (setq restriction nil))
2066 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2067 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2068 ((and (> (length selstring) 0) (eq c ?\d))
2069 (delete-window)
2070 (org-agenda-get-restriction-and-command prefix-descriptions))
2072 ((equal c ?q) (error "Abort"))
2073 (t (error "Invalid key %c" c))))))))
2075 (defun org-run-agenda-series (name series)
2076 (org-let (nth 1 series) '(org-prepare-agenda name))
2077 (let* ((org-agenda-multi t)
2078 (redo (list 'org-run-agenda-series name (list 'quote series)))
2079 (cmds (car series))
2080 (gprops (nth 1 series))
2081 match ;; The byte compiler incorrectly complains about this. Keep it!
2082 cmd type lprops)
2083 (while (setq cmd (pop cmds))
2084 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2085 (cond
2086 ((eq type 'agenda)
2087 (org-let2 gprops lprops
2088 '(call-interactively 'org-agenda-list)))
2089 ((eq type 'alltodo)
2090 (org-let2 gprops lprops
2091 '(call-interactively 'org-todo-list)))
2092 ((eq type 'search)
2093 (org-let2 gprops lprops
2094 '(org-search-view current-prefix-arg match nil)))
2095 ((eq type 'stuck)
2096 (org-let2 gprops lprops
2097 '(call-interactively 'org-agenda-list-stuck-projects)))
2098 ((eq type 'tags)
2099 (org-let2 gprops lprops
2100 '(org-tags-view current-prefix-arg match)))
2101 ((eq type 'tags-todo)
2102 (org-let2 gprops lprops
2103 '(org-tags-view '(4) match)))
2104 ((eq type 'todo)
2105 (org-let2 gprops lprops
2106 '(org-todo-list match)))
2107 ((fboundp type)
2108 (org-let2 gprops lprops
2109 '(funcall type match)))
2110 (t (error "Invalid type in command series"))))
2111 (widen)
2112 (setq org-agenda-redo-command redo)
2113 (goto-char (point-min)))
2114 (org-fit-agenda-window)
2115 (org-let (nth 1 series) '(org-finalize-agenda)))
2117 ;;;###autoload
2118 (defmacro org-batch-agenda (cmd-key &rest parameters)
2119 "Run an agenda command in batch mode and send the result to STDOUT.
2120 If CMD-KEY is a string of length 1, it is used as a key in
2121 `org-agenda-custom-commands' and triggers this command. If it is a
2122 longer string it is used as a tags/todo match string.
2123 Paramters are alternating variable names and values that will be bound
2124 before running the agenda command."
2125 (let (pars)
2126 (while parameters
2127 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2128 (if (> (length cmd-key) 2)
2129 (eval (list 'let (nreverse pars)
2130 (list 'org-tags-view nil cmd-key)))
2131 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2132 (set-buffer org-agenda-buffer-name)
2133 (princ (org-encode-for-stdout (buffer-string)))))
2135 ;(defun org-encode-for-stdout (string)
2136 ; (if (fboundp 'encode-coding-string)
2137 ; (encode-coding-string string buffer-file-coding-system)
2138 ; string))
2140 (defun org-encode-for-stdout (string)
2141 string)
2143 (defvar org-agenda-info nil)
2145 ;;;###autoload
2146 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2147 "Run an agenda command in batch mode and send the result to STDOUT.
2148 If CMD-KEY is a string of length 1, it is used as a key in
2149 `org-agenda-custom-commands' and triggers this command. If it is a
2150 longer string it is used as a tags/todo match string.
2151 Paramters are alternating variable names and values that will be bound
2152 before running the agenda command.
2154 The output gives a line for each selected agenda item. Each
2155 item is a list of comma-separated values, like this:
2157 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2159 category The category of the item
2160 head The headline, without TODO kwd, TAGS and PRIORITY
2161 type The type of the agenda entry, can be
2162 todo selected in TODO match
2163 tagsmatch selected in tags match
2164 diary imported from diary
2165 deadline a deadline on given date
2166 scheduled scheduled on given date
2167 timestamp entry has timestamp on given date
2168 closed entry was closed on given date
2169 upcoming-deadline warning about deadline
2170 past-scheduled forwarded scheduled item
2171 block entry has date block including g. date
2172 todo The todo keyword, if any
2173 tags All tags including inherited ones, separated by colons
2174 date The relevant date, like 2007-2-14
2175 time The time, like 15:00-16:50
2176 extra Sting with extra planning info
2177 priority-l The priority letter if any was given
2178 priority-n The computed numerical priority
2179 agenda-day The day in the agenda where this is listed"
2181 (let (pars)
2182 (while parameters
2183 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2184 (push (list 'org-agenda-remove-tags t) pars)
2185 (if (> (length cmd-key) 2)
2186 (eval (list 'let (nreverse pars)
2187 (list 'org-tags-view nil cmd-key)))
2188 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2189 (set-buffer org-agenda-buffer-name)
2190 (let* ((lines (org-split-string (buffer-string) "\n"))
2191 line)
2192 (while (setq line (pop lines))
2193 (catch 'next
2194 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2195 (setq org-agenda-info
2196 (org-fix-agenda-info (text-properties-at 0 line)))
2197 (princ
2198 (org-encode-for-stdout
2199 (mapconcat 'org-agenda-export-csv-mapper
2200 '(org-category txt type todo tags date time-of-day extra
2201 priority-letter priority agenda-day)
2202 ",")))
2203 (princ "\n"))))))
2205 (defun org-fix-agenda-info (props)
2206 "Make sure all properties on an agenda item have a canonical form,
2207 so the export commands can easily use it."
2208 (let (tmp re)
2209 (when (setq tmp (plist-get props 'tags))
2210 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2211 (when (setq tmp (plist-get props 'date))
2212 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2213 (let ((calendar-date-display-form '(year "-" month "-" day)))
2214 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2216 (setq tmp (calendar-date-string tmp)))
2217 (setq props (plist-put props 'date tmp)))
2218 (when (setq tmp (plist-get props 'day))
2219 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2220 (let ((calendar-date-display-form '(year "-" month "-" day)))
2221 (setq tmp (calendar-date-string tmp)))
2222 (setq props (plist-put props 'day tmp))
2223 (setq props (plist-put props 'agenda-day tmp)))
2224 (when (setq tmp (plist-get props 'txt))
2225 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2226 (plist-put props 'priority-letter (match-string 1 tmp))
2227 (setq tmp (replace-match "" t t tmp)))
2228 (when (and (setq re (plist-get props 'org-todo-regexp))
2229 (setq re (concat "\\`\\.*" re " ?"))
2230 (string-match re tmp))
2231 (plist-put props 'todo (match-string 1 tmp))
2232 (setq tmp (replace-match "" t t tmp)))
2233 (plist-put props 'txt tmp)))
2234 props)
2236 (defun org-agenda-export-csv-mapper (prop)
2237 (let ((res (plist-get org-agenda-info prop)))
2238 (setq res
2239 (cond
2240 ((not res) "")
2241 ((stringp res) res)
2242 (t (prin1-to-string res))))
2243 (while (string-match "," res)
2244 (setq res (replace-match ";" t t res)))
2245 (org-trim res)))
2248 ;;;###autoload
2249 (defun org-store-agenda-views (&rest parameters)
2250 (interactive)
2251 (eval (list 'org-batch-store-agenda-views)))
2253 ;; FIXME, why is this a macro?????
2254 ;;;###autoload
2255 (defmacro org-batch-store-agenda-views (&rest parameters)
2256 "Run all custom agenda commands that have a file argument."
2257 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2258 (pop-up-frames nil)
2259 (dir default-directory)
2260 pars cmd thiscmdkey files opts cmd-or-set)
2261 (while parameters
2262 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2263 (setq pars (reverse pars))
2264 (save-window-excursion
2265 (while cmds
2266 (setq cmd (pop cmds)
2267 thiscmdkey (car cmd)
2268 cmd-or-set (nth 2 cmd)
2269 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2270 files (nth (if (listp cmd-or-set) 4 5) cmd))
2271 (if (stringp files) (setq files (list files)))
2272 (when files
2273 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2274 (list 'org-agenda nil thiscmdkey)))
2275 (set-buffer org-agenda-buffer-name)
2276 (while files
2277 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2278 (list 'org-write-agenda
2279 (expand-file-name (pop files) dir) nil t))))
2280 (and (get-buffer org-agenda-buffer-name)
2281 (kill-buffer org-agenda-buffer-name)))))))
2283 (defun org-agenda-mark-header-line (pos)
2284 "Mark the line at POS as an agenda structure header."
2285 (save-excursion
2286 (goto-char pos)
2287 (put-text-property (point-at-bol) (point-at-eol)
2288 'org-agenda-structural-header t)
2289 (when org-agenda-title-append
2290 (put-text-property (point-at-bol) (point-at-eol)
2291 'org-agenda-title-append org-agenda-title-append))))
2293 (defvar org-mobile-creating-agendas)
2294 (defun org-write-agenda (file &optional open nosettings)
2295 "Write the current buffer (an agenda view) as a file.
2296 Depending on the extension of the file name, plain text (.txt),
2297 HTML (.html or .htm) or Postscript (.ps) is produced.
2298 If the extension is .ics, run icalendar export over all files used
2299 to construct the agenda and limit the export to entries listed in the
2300 agenda now.
2301 With prefix argument OPEN, open the new file immediately.
2302 If NOSETTINGS is given, do not scope the settings of
2303 `org-agenda-exporter-settings' into the export commands. This is used when
2304 the settings have already been scoped and we do not wish to overrule other,
2305 higher priority settings."
2306 (interactive "FWrite agenda to file: \nP")
2307 (if (not (file-writable-p file))
2308 (error "Cannot write agenda to file %s" file))
2309 (cond
2310 ((string-match "\\.html?\\'" file) (require 'htmlize))
2311 ((string-match "\\.ps\\'" file) (require 'ps-print)))
2312 (org-let (if nosettings nil org-agenda-exporter-settings)
2313 '(save-excursion
2314 (save-window-excursion
2315 (org-agenda-mark-filtered-text)
2316 (let ((bs (copy-sequence (buffer-string))) beg)
2317 (org-agenda-unmark-filtered-text)
2318 (with-temp-buffer
2319 (insert bs)
2320 (org-agenda-remove-marked-text 'org-filtered)
2321 (while (setq beg (text-property-any (point-min) (point-max)
2322 'org-filtered t))
2323 (delete-region
2324 beg (or (next-single-property-change beg 'org-filtered)
2325 (point-max))))
2326 (run-hooks 'org-agenda-before-write-hook)
2327 (cond
2328 ((org-bound-and-true-p org-mobile-creating-agendas)
2329 (org-mobile-write-agenda-for-mobile file))
2330 ((string-match "\\.html?\\'" file)
2331 (set-buffer (htmlize-buffer (current-buffer)))
2333 (when (and org-agenda-export-html-style
2334 (string-match "<style>" org-agenda-export-html-style))
2335 ;; replace <style> section with org-agenda-export-html-style
2336 (goto-char (point-min))
2337 (kill-region (- (search-forward "<style") 6)
2338 (search-forward "</style>"))
2339 (insert org-agenda-export-html-style))
2340 (write-file file)
2341 (kill-buffer (current-buffer))
2342 (message "HTML written to %s" file))
2343 ((string-match "\\.ps\\'" file)
2344 (require 'ps-print)
2345 (flet ((ps-get-buffer-name () "Agenda View"))
2346 (ps-print-buffer-with-faces file))
2347 (message "Postscript written to %s" file))
2348 ((string-match "\\.pdf\\'" file)
2349 (require 'ps-print)
2350 (flet ((ps-get-buffer-name () "Agenda View"))
2351 (ps-print-buffer-with-faces
2352 (concat (file-name-sans-extension file) ".ps")))
2353 (call-process "ps2pdf" nil nil nil
2354 (expand-file-name
2355 (concat (file-name-sans-extension file) ".ps"))
2356 (expand-file-name file))
2357 (message "PDF written to %s" file))
2358 ((string-match "\\.ics\\'" file)
2359 (require 'org-icalendar)
2360 (let ((org-agenda-marker-table
2361 (org-create-marker-find-array
2362 (org-agenda-collect-markers)))
2363 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2364 (org-combined-agenda-icalendar-file file))
2365 (apply 'org-export-icalendar 'combine
2366 (org-agenda-files nil 'ifmode))))
2368 (let ((bs (buffer-string)))
2369 (find-file file)
2370 (erase-buffer)
2371 (insert bs)
2372 (save-buffer 0)
2373 (kill-buffer (current-buffer))
2374 (message "Plain text written to %s" file))))))))
2375 (set-buffer org-agenda-buffer-name))
2376 (when open (org-open-file file)))
2378 (defvar org-agenda-filter-overlays nil)
2380 (defun org-agenda-mark-filtered-text ()
2381 "Mark all text hidden by filtering with a text property."
2382 (let ((inhibit-read-only t))
2383 (mapc
2384 (lambda (o)
2385 (when (equal (org-overlay-buffer o) (current-buffer))
2386 (put-text-property
2387 (org-overlay-start o) (org-overlay-end o)
2388 'org-filtered t)))
2389 org-agenda-filter-overlays)))
2391 (defun org-agenda-unmark-filtered-text ()
2392 "Remove the filtering text property."
2393 (let ((inhibit-read-only t))
2394 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2396 (defun org-agenda-remove-marked-text (property &optional value)
2397 "Delete all text marked with VALUE of PROPERTY.
2398 VALUE defaults to t."
2399 (let (beg)
2400 (setq value (or value t))
2401 (while (setq beg (text-property-any (point-min) (point-max)
2402 property value))
2403 (delete-region
2404 beg (or (next-single-property-change beg 'org-filtered)
2405 (point-max))))))
2407 (defun org-agenda-add-entry-text ()
2408 "Add entry text to agenda lines.
2409 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2410 entry text following headings shown in the agenda.
2411 Drawers will be excluded, also the line with scheduling/deadline info."
2412 (when (and (> org-agenda-add-entry-text-maxlines 0)
2413 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2414 (let (m txt)
2415 (goto-char (point-min))
2416 (while (not (eobp))
2417 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2418 (beginning-of-line 2)
2419 (setq txt (org-agenda-get-some-entry-text
2420 m org-agenda-add-entry-text-maxlines " > "))
2421 (end-of-line 1)
2422 (if (string-match "\\S-" txt) (insert "\n" txt)))))))
2424 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2425 &rest keep)
2426 "Extract entry text from MARKER, at most N-LINES lines.
2427 This will ignore drawers etc, just get the text.
2428 If INDENT is given, prefix every line with this string. If KEEP is
2429 given, it is a list of symbols, defining stuff that should not be
2430 removed from the entry content. Currently only `planning' is allowed here."
2431 (let (txt drawer-re kwd-time-re ind)
2432 (save-excursion
2433 (with-current-buffer (marker-buffer marker)
2434 (if (not (org-mode-p))
2435 (setq txt "")
2436 (save-excursion
2437 (save-restriction
2438 (widen)
2439 (goto-char marker)
2440 (end-of-line 1)
2441 (setq txt (buffer-substring
2442 (min (1+ (point)) (point-max))
2443 (progn (outline-next-heading) (point)))
2444 drawer-re org-drawer-regexp
2445 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2446 ".*\n?"))
2447 (with-temp-buffer
2448 (insert txt)
2449 (when org-agenda-add-entry-text-descriptive-links
2450 (goto-char (point-min))
2451 (while (org-activate-bracket-links (point-max))
2452 (add-text-properties (match-beginning 0) (match-end 0)
2453 '(face org-link))))
2454 (goto-char (point-min))
2455 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2456 (set-text-properties (match-beginning 0) (match-end 0)
2457 nil))
2458 (goto-char (point-min))
2459 (while (re-search-forward drawer-re nil t)
2460 (delete-region
2461 (match-beginning 0)
2462 (progn (re-search-forward
2463 "^[ \t]*:END:.*\n?" nil 'move)
2464 (point))))
2465 (unless (member 'planning keep)
2466 (goto-char (point-min))
2467 (while (re-search-forward kwd-time-re nil t)
2468 (replace-match "")))
2469 (goto-char (point-min))
2470 (when org-agenda-entry-text-exclude-regexps
2471 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2472 (while (setq re (pop re-list))
2473 (goto-char (point-min))
2474 (while (re-search-forward re nil t)
2475 (replace-match "")))))
2476 (goto-char (point-max))
2477 (skip-chars-backward " \t\n")
2478 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2480 ;; find and remove min common indentation
2481 (goto-char (point-min))
2482 (untabify (point-min) (point-max))
2483 (setq ind (org-get-indentation))
2484 (while (not (eobp))
2485 (unless (looking-at "[ \t]*$")
2486 (setq ind (min ind (org-get-indentation))))
2487 (beginning-of-line 2))
2488 (goto-char (point-min))
2489 (while (not (eobp))
2490 (unless (looking-at "[ \t]*$")
2491 (move-to-column ind)
2492 (delete-region (point-at-bol) (point)))
2493 (beginning-of-line 2))
2495 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2497 (goto-char (point-min))
2498 (when indent
2499 (while (and (not (eobp)) (re-search-forward "^" nil t))
2500 (replace-match indent t t)))
2501 (goto-char (point-min))
2502 (while (looking-at "[ \t]*\n") (replace-match ""))
2503 (goto-char (point-max))
2504 (when (> (org-current-line)
2505 n-lines)
2506 (org-goto-line (1+ n-lines))
2507 (backward-char 1))
2508 (setq txt (buffer-substring (point-min) (point)))))))))
2509 txt))
2511 (defun org-agenda-collect-markers ()
2512 "Collect the markers pointing to entries in the agenda buffer."
2513 (let (m markers)
2514 (save-excursion
2515 (goto-char (point-min))
2516 (while (not (eobp))
2517 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2518 (org-get-at-bol 'org-marker)))
2519 (push m markers))
2520 (beginning-of-line 2)))
2521 (nreverse markers)))
2523 (defun org-create-marker-find-array (marker-list)
2524 "Create a alist of files names with all marker positions in that file."
2525 (let (f tbl m a p)
2526 (while (setq m (pop marker-list))
2527 (setq p (marker-position m)
2528 f (buffer-file-name (or (buffer-base-buffer
2529 (marker-buffer m))
2530 (marker-buffer m))))
2531 (if (setq a (assoc f tbl))
2532 (push (marker-position m) (cdr a))
2533 (push (list f p) tbl)))
2534 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2535 tbl)))
2537 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2538 (defun org-check-agenda-marker-table ()
2539 "Check of the current entry is on the marker list."
2540 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2542 (and (setq a (assoc file org-agenda-marker-table))
2543 (save-match-data
2544 (save-excursion
2545 (org-back-to-heading t)
2546 (member (point) (cdr a)))))))
2548 (defun org-check-for-org-mode ()
2549 "Make sure current buffer is in org-mode. Error if not."
2550 (or (org-mode-p)
2551 (error "Cannot execute org-mode agenda command on buffer in %s"
2552 major-mode)))
2554 (defun org-fit-agenda-window ()
2555 "Fit the window to the buffer size."
2556 (and (memq org-agenda-window-setup '(reorganize-frame))
2557 (fboundp 'fit-window-to-buffer)
2558 (org-fit-window-to-buffer
2560 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2561 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2563 ;;; Agenda prepare and finalize
2565 (defvar org-agenda-multi nil) ; dynamically scoped
2566 (defvar org-agenda-buffer-name "*Org Agenda*")
2567 (defvar org-pre-agenda-window-conf nil)
2568 (defvar org-agenda-columns-active nil)
2569 (defvar org-agenda-name nil)
2570 (defvar org-agenda-filter nil)
2571 (defvar org-agenda-filter-preset nil
2572 "A preset of the tags filter used for secondary agenda filtering.
2573 This must be a list of strings, each string must be a single tag preceeded
2574 by \"+\" or \"-\".
2575 This variable should not be set directly, but agenda custom commands can
2576 bind it in the options section.")
2578 (defun org-prepare-agenda (&optional name)
2579 (setq org-todo-keywords-for-agenda nil)
2580 (setq org-done-keywords-for-agenda nil)
2581 (setq org-drawers-for-agenda nil)
2582 (setq org-agenda-filter nil)
2583 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2584 (if org-agenda-multi
2585 (progn
2586 (setq buffer-read-only nil)
2587 (goto-char (point-max))
2588 (unless (or (bobp) org-agenda-compact-blocks)
2589 (insert "\n"
2590 (if (stringp org-agenda-block-separator)
2591 org-agenda-block-separator
2592 (make-string (window-width) org-agenda-block-separator))
2593 "\n"))
2594 (narrow-to-region (point) (point-max)))
2595 (org-agenda-reset-markers)
2596 (setq org-agenda-contributing-files nil)
2597 (setq org-agenda-columns-active nil)
2598 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2599 (setq org-todo-keywords-for-agenda
2600 (org-uniquify org-todo-keywords-for-agenda))
2601 (setq org-done-keywords-for-agenda
2602 (org-uniquify org-done-keywords-for-agenda))
2603 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2604 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2605 (awin (get-buffer-window abuf)))
2606 (cond
2607 ((equal (current-buffer) abuf) nil)
2608 (awin (select-window awin))
2609 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2610 ((equal org-agenda-window-setup 'current-window)
2611 (switch-to-buffer abuf))
2612 ((equal org-agenda-window-setup 'other-window)
2613 (org-switch-to-buffer-other-window abuf))
2614 ((equal org-agenda-window-setup 'other-frame)
2615 (switch-to-buffer-other-frame abuf))
2616 ((equal org-agenda-window-setup 'reorganize-frame)
2617 (delete-other-windows)
2618 (org-switch-to-buffer-other-window abuf))))
2619 (setq buffer-read-only nil)
2620 (let ((inhibit-read-only t)) (erase-buffer))
2621 (org-agenda-mode)
2622 (and name (not org-agenda-name)
2623 (org-set-local 'org-agenda-name name)))
2624 (setq buffer-read-only nil))
2626 (defun org-finalize-agenda ()
2627 "Finishing touch for the agenda buffer, called just before displaying it."
2628 (unless org-agenda-multi
2629 (save-excursion
2630 (let ((inhibit-read-only t))
2631 (goto-char (point-min))
2632 (while (org-activate-bracket-links (point-max))
2633 (add-text-properties (match-beginning 0) (match-end 0)
2634 '(face org-link)))
2635 (org-agenda-align-tags)
2636 (unless org-agenda-with-colors
2637 (remove-text-properties (point-min) (point-max) '(face nil))))
2638 (if (and (boundp 'org-agenda-overriding-columns-format)
2639 org-agenda-overriding-columns-format)
2640 (org-set-local 'org-agenda-overriding-columns-format
2641 org-agenda-overriding-columns-format))
2642 (if (and (boundp 'org-agenda-view-columns-initially)
2643 org-agenda-view-columns-initially)
2644 (org-agenda-columns))
2645 (when org-agenda-fontify-priorities
2646 (org-agenda-fontify-priorities))
2647 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2648 (org-agenda-dim-blocked-tasks))
2649 (org-agenda-mark-clocking-task)
2650 (when org-agenda-entry-text-mode
2651 (org-agenda-entry-text-hide)
2652 (org-agenda-entry-text-show))
2653 (if (functionp 'org-habit-insert-consistency-graphs)
2654 (org-habit-insert-consistency-graphs))
2655 (run-hooks 'org-finalize-agenda-hook)
2656 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2657 (when (get 'org-agenda-filter :preset-filter)
2658 (org-agenda-filter-apply org-agenda-filter))
2661 (defun org-agenda-mark-clocking-task ()
2662 "Mark the current clock entry in the agenda if it is present."
2663 (mapc (lambda (o)
2664 (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
2665 (org-delete-overlay o)))
2666 (org-overlays-in (point-min) (point-max)))
2667 (when (marker-buffer org-clock-hd-marker)
2668 (save-excursion
2669 (goto-char (point-min))
2670 (let (s ov)
2671 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2672 (goto-char s)
2673 (when (equal (org-get-at-bol 'org-hd-marker)
2674 org-clock-hd-marker)
2675 (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
2676 (org-overlay-put ov 'type 'org-agenda-clocking)
2677 (org-overlay-put ov 'face 'org-agenda-clocking)
2678 (org-overlay-put ov 'help-echo
2679 "The clock is running in this item")))))))
2681 (defun org-agenda-fontify-priorities ()
2682 "Make highest priority lines bold, and lowest italic."
2683 (interactive)
2684 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
2685 (org-delete-overlay o)))
2686 (org-overlays-in (point-min) (point-max)))
2687 (save-excursion
2688 (let ((inhibit-read-only t)
2689 b e p ov h l)
2690 (goto-char (point-min))
2691 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2692 (setq h (or (get-char-property (point) 'org-highest-priority)
2693 org-highest-priority)
2694 l (or (get-char-property (point) 'org-lowest-priority)
2695 org-lowest-priority)
2696 p (string-to-char (match-string 1))
2697 b (match-beginning 0)
2698 e (if (eq org-agenda-fontify-priorities 'cookies)
2699 (match-end 0)
2700 (point-at-eol))
2701 ov (org-make-overlay b e))
2702 (org-overlay-put
2703 ov 'face
2704 (cond ((cdr (assoc p org-priority-faces)))
2705 ((and (listp org-agenda-fontify-priorities)
2706 (cdr (assoc p org-agenda-fontify-priorities))))
2707 ((equal p l) 'italic)
2708 ((equal p h) 'bold)))
2709 (org-overlay-put ov 'org-type 'org-priority)))))
2711 (defun org-agenda-dim-blocked-tasks ()
2712 "Dim currently blocked TODO's in the agenda display."
2713 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
2714 (org-delete-overlay o)))
2715 (org-overlays-in (point-min) (point-max)))
2716 (save-excursion
2717 (let ((inhibit-read-only t)
2718 (org-depend-tag-blocked nil)
2719 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2720 org-blocked-by-checkboxes
2721 invis1 b e p ov h l)
2722 (goto-char (point-min))
2723 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2724 (and pos (goto-char (1+ pos))))
2725 (setq org-blocked-by-checkboxes nil invis1 invis)
2726 (let ((marker (org-get-at-bol 'org-hd-marker)))
2727 (when (and marker
2728 (not (with-current-buffer (marker-buffer marker)
2729 (save-excursion
2730 (goto-char marker)
2731 (if (org-entry-get nil "NOBLOCKING")
2732 t ;; Never block this entry
2733 (run-hook-with-args-until-failure
2734 'org-blocker-hook
2735 (list :type 'todo-state-change
2736 :position marker
2737 :from 'todo
2738 :to 'done)))))))
2739 (if org-blocked-by-checkboxes (setq invis1 nil))
2740 (setq b (if invis1
2741 (max (point-min) (1- (point-at-bol)))
2742 (point-at-bol))
2743 e (point-at-eol)
2744 ov (org-make-overlay b e))
2745 (if invis1
2746 (org-overlay-put ov 'invisible t)
2747 (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2748 (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
2750 (defvar org-agenda-skip-function nil
2751 "Function to be called at each match during agenda construction.
2752 If this function returns nil, the current match should not be skipped.
2753 Otherwise, the function must return a position from where the search
2754 should be continued.
2755 This may also be a Lisp form, it will be evaluated.
2756 Never set this variable using `setq' or so, because then it will apply
2757 to all future agenda commands. Instead, bind it with `let' to scope
2758 it dynamically into the agenda-constructing command. A good way to set
2759 it is through options in org-agenda-custom-commands.")
2761 (defun org-agenda-skip ()
2762 "Throw to `:skip' in places that should be skipped.
2763 Also moves point to the end of the skipped region, so that search can
2764 continue from there."
2765 (let ((p (point-at-bol)) to fp)
2766 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2767 (get-text-property p :org-archived)
2768 (org-end-of-subtree t)
2769 (throw :skip t))
2770 (and org-agenda-skip-comment-trees
2771 (get-text-property p :org-comment)
2772 (org-end-of-subtree t)
2773 (throw :skip t))
2774 (if (equal (char-after p) ?#) (throw :skip t))
2775 (when (and (or (setq fp (functionp org-agenda-skip-function))
2776 (consp org-agenda-skip-function))
2777 (setq to (save-excursion
2778 (save-match-data
2779 (if fp
2780 (funcall org-agenda-skip-function)
2781 (eval org-agenda-skip-function))))))
2782 (goto-char to)
2783 (throw :skip t))))
2785 (defvar org-agenda-markers nil
2786 "List of all currently active markers created by `org-agenda'.")
2787 (defvar org-agenda-last-marker-time (org-float-time)
2788 "Creation time of the last agenda marker.")
2790 (defun org-agenda-new-marker (&optional pos)
2791 "Return a new agenda marker.
2792 Org-mode keeps a list of these markers and resets them when they are
2793 no longer in use."
2794 (let ((m (copy-marker (or pos (point)))))
2795 (setq org-agenda-last-marker-time (org-float-time))
2796 (push m org-agenda-markers)
2799 (defun org-agenda-reset-markers ()
2800 "Reset markers created by `org-agenda'."
2801 (while org-agenda-markers
2802 (move-marker (pop org-agenda-markers) nil)))
2804 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
2805 "Save relative positions of markers in region."
2806 (mapc (lambda (m) (org-check-and-save-marker m beg end))
2807 org-agenda-markers))
2809 ;;; Entry text mode
2811 (defun org-agenda-entry-text-show-here ()
2812 "Add some text from the entry as context to the current line."
2813 (let (m txt o)
2814 (setq m (org-get-at-bol 'org-hd-marker))
2815 (unless (marker-buffer m)
2816 (error "No marker points to an entry here"))
2817 (setq txt (concat "\n" (org-no-properties
2818 (org-agenda-get-some-entry-text
2819 m org-agenda-entry-text-maxlines " > "))))
2820 (when (string-match "\\S-" txt)
2821 (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
2822 (org-overlay-put o 'evaporate t)
2823 (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
2824 (org-overlay-put o 'after-string txt))))
2826 (defun org-agenda-entry-text-show ()
2827 "Add entry context for all agenda lines."
2828 (interactive)
2829 (save-excursion
2830 (goto-char (point-max))
2831 (beginning-of-line 1)
2832 (while (not (bobp))
2833 (when (org-get-at-bol 'org-hd-marker)
2834 (org-agenda-entry-text-show-here))
2835 (beginning-of-line 0))))
2837 (defun org-agenda-entry-text-hide ()
2838 "Remove any shown entry context."
2839 (delq nil
2840 (mapcar (lambda (o)
2841 (if (eq (org-overlay-get o 'org-overlay-type)
2842 'agenda-entry-content)
2843 (progn (org-delete-overlay o) t)))
2844 (org-overlays-in (point-min) (point-max)))))
2846 ;;; Agenda timeline
2848 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
2850 (defun org-timeline (&optional include-all)
2851 "Show a time-sorted view of the entries in the current org file.
2852 Only entries with a time stamp of today or later will be listed. With
2853 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2854 under the current date.
2855 If the buffer contains an active region, only check the region for
2856 dates."
2857 (interactive "P")
2858 (require 'calendar)
2859 (org-compile-prefix-format 'timeline)
2860 (org-set-sorting-strategy 'timeline)
2861 (let* ((dopast t)
2862 (dotodo include-all)
2863 (doclosed org-agenda-show-log)
2864 (entry buffer-file-name)
2865 (date (calendar-current-date))
2866 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2867 (end (if (org-region-active-p) (region-end) (point-max)))
2868 (day-numbers (org-get-all-dates beg end 'no-ranges
2869 t doclosed ; always include today
2870 org-timeline-show-empty-dates))
2871 (org-deadline-warning-days 0)
2872 (org-agenda-only-exact-dates t)
2873 (today (time-to-days (current-time)))
2874 (past t)
2875 args
2876 s e rtn d emptyp wd)
2877 (setq org-agenda-redo-command
2878 (list 'progn
2879 (list 'org-switch-to-buffer-other-window (current-buffer))
2880 (list 'org-timeline (list 'quote include-all))))
2881 (if (not dopast)
2882 ;; Remove past dates from the list of dates.
2883 (setq day-numbers (delq nil (mapcar (lambda(x)
2884 (if (>= x today) x nil))
2885 day-numbers))))
2886 (org-prepare-agenda (concat "Timeline "
2887 (file-name-nondirectory buffer-file-name)))
2888 (if doclosed (push :closed args))
2889 (push :timestamp args)
2890 (push :deadline args)
2891 (push :scheduled args)
2892 (push :sexp args)
2893 (if dotodo (push :todo args))
2894 (insert "Timeline of file " entry "\n")
2895 (add-text-properties (point-min) (point)
2896 (list 'face 'org-agenda-structure))
2897 (org-agenda-mark-header-line (point-min))
2898 (while (setq d (pop day-numbers))
2899 (if (and (listp d) (eq (car d) :omitted))
2900 (progn
2901 (setq s (point))
2902 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
2903 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
2904 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
2905 (if (and (>= d today)
2906 dopast
2907 past)
2908 (progn
2909 (setq past nil)
2910 (insert (make-string 79 ?-) "\n")))
2911 (setq date (calendar-gregorian-from-absolute d)
2912 wd (calendar-day-of-week date))
2913 (setq s (point))
2914 (setq rtn (and (not emptyp)
2915 (apply 'org-agenda-get-day-entries entry
2916 date args)))
2917 (if (or rtn (equal d today) org-timeline-show-empty-dates)
2918 (progn
2919 (insert
2920 (if (stringp org-agenda-format-date)
2921 (format-time-string org-agenda-format-date
2922 (org-time-from-absolute date))
2923 (funcall org-agenda-format-date date))
2924 "\n")
2925 (put-text-property s (1- (point)) 'face
2926 (if (member wd org-agenda-weekend-days)
2927 'org-agenda-date-weekend
2928 'org-agenda-date))
2929 (put-text-property s (1- (point)) 'org-date-line t)
2930 (put-text-property s (1- (point)) 'org-agenda-date-header t)
2931 (if (equal d today)
2932 (put-text-property s (1- (point)) 'org-today t))
2933 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
2934 (put-text-property s (1- (point)) 'day d)))))
2935 (goto-char (point-min))
2936 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
2937 (point-min)))
2938 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
2939 (org-finalize-agenda)
2940 (setq buffer-read-only t)))
2942 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
2943 "Return a list of all relevant day numbers from BEG to END buffer positions.
2944 If NO-RANGES is non-nil, include only the start and end dates of a range,
2945 not every single day in the range. If FORCE-TODAY is non-nil, make
2946 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2947 inactive time stamps (those in square brackets) are included.
2948 When EMPTY is non-nil, also include days without any entries."
2949 (let ((re (concat
2950 (if pre-re pre-re "")
2951 (if inactive org-ts-regexp-both org-ts-regexp)))
2952 dates dates1 date day day1 day2 ts1 ts2)
2953 (if force-today
2954 (setq dates (list (time-to-days (current-time)))))
2955 (save-excursion
2956 (goto-char beg)
2957 (while (re-search-forward re end t)
2958 (setq day (time-to-days (org-time-string-to-time
2959 (substring (match-string 1) 0 10))))
2960 (or (memq day dates) (push day dates)))
2961 (unless no-ranges
2962 (goto-char beg)
2963 (while (re-search-forward org-tr-regexp end t)
2964 (setq ts1 (substring (match-string 1) 0 10)
2965 ts2 (substring (match-string 2) 0 10)
2966 day1 (time-to-days (org-time-string-to-time ts1))
2967 day2 (time-to-days (org-time-string-to-time ts2)))
2968 (while (< (setq day1 (1+ day1)) day2)
2969 (or (memq day1 dates) (push day1 dates)))))
2970 (setq dates (sort dates '<))
2971 (when empty
2972 (while (setq day (pop dates))
2973 (setq day2 (car dates))
2974 (push day dates1)
2975 (when (and day2 empty)
2976 (if (or (eq empty t)
2977 (and (numberp empty) (<= (- day2 day) empty)))
2978 (while (< (setq day (1+ day)) day2)
2979 (push (list day) dates1))
2980 (push (cons :omitted (- day2 day)) dates1))))
2981 (setq dates (nreverse dates1)))
2982 dates)))
2984 ;;; Agenda Daily/Weekly
2986 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2987 (defvar org-agenda-start-day nil ; dynamically scoped parameter
2988 "Custom commands can set this variable in the options section.")
2989 (defvar org-agenda-last-arguments nil
2990 "The arguments of the previous call to org-agenda")
2991 (defvar org-starting-day nil) ; local variable in the agenda buffer
2992 (defvar org-agenda-span nil) ; local variable in the agenda buffer
2993 (defvar org-include-all-loc nil) ; local variable
2995 ;;;###autoload
2996 (defun org-agenda-list (&optional include-all start-day ndays)
2997 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2998 The view will be for the current day or week, but from the overview buffer
2999 you will be able to go to other days/weeks.
3001 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3002 all unfinished TODO items will also be shown, before the agenda.
3003 This feature is considered obsolete, please use the TODO list or a block
3004 agenda instead.
3006 With a numeric prefix argument in an interactive call, the agenda will
3007 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
3008 the number of days. NDAYS defaults to `org-agenda-ndays'.
3010 START-DAY defaults to TODAY, or to the most recent match for the weekday
3011 given in `org-agenda-start-on-weekday'."
3012 (interactive "P")
3013 (if (and (integerp include-all) (> include-all 0))
3014 (setq ndays include-all include-all nil))
3015 (setq ndays (or ndays org-agenda-ndays)
3016 start-day (or start-day org-agenda-start-day))
3017 (if org-agenda-overriding-arguments
3018 (setq include-all (car org-agenda-overriding-arguments)
3019 start-day (nth 1 org-agenda-overriding-arguments)
3020 ndays (nth 2 org-agenda-overriding-arguments)))
3021 (if (stringp start-day)
3022 ;; Convert to an absolute day number
3023 (setq start-day (time-to-days (org-read-date nil t start-day))))
3024 (setq org-agenda-last-arguments (list include-all start-day ndays))
3025 (org-compile-prefix-format 'agenda)
3026 (org-set-sorting-strategy 'agenda)
3027 (require 'calendar)
3028 (let* ((org-agenda-start-on-weekday
3029 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3030 org-agenda-start-on-weekday nil))
3031 (thefiles (org-agenda-files nil 'ifmode))
3032 (files thefiles)
3033 (today (time-to-days
3034 (time-subtract (current-time)
3035 (list 0 (* 3600 org-extend-today-until) 0))))
3036 (sd (or start-day today))
3037 (start (if (or (null org-agenda-start-on-weekday)
3038 (< org-agenda-ndays 7))
3040 (let* ((nt (calendar-day-of-week
3041 (calendar-gregorian-from-absolute sd)))
3042 (n1 org-agenda-start-on-weekday)
3043 (d (- nt n1)))
3044 (- sd (+ (if (< d 0) 7 0) d)))))
3045 (day-numbers (list start))
3046 (day-cnt 0)
3047 (inhibit-redisplay (not debug-on-error))
3048 s e rtn rtnall file date d start-pos end-pos todayp nd wd
3049 clocktable-start clocktable-end)
3050 (setq org-agenda-redo-command
3051 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3052 ;; Make the list of days
3053 (setq ndays (or ndays org-agenda-ndays)
3054 nd ndays)
3055 (while (> ndays 1)
3056 (push (1+ (car day-numbers)) day-numbers)
3057 (setq ndays (1- ndays)))
3058 (setq day-numbers (nreverse day-numbers))
3059 (setq clocktable-start (car day-numbers)
3060 clocktable-end (1+ (or (org-last day-numbers) 0)))
3061 (org-prepare-agenda "Day/Week")
3062 (org-set-local 'org-starting-day (car day-numbers))
3063 (org-set-local 'org-include-all-loc include-all)
3064 (org-set-local 'org-agenda-span
3065 (org-agenda-ndays-to-span nd))
3066 (when (and (or include-all org-agenda-include-all-todo)
3067 (member today day-numbers))
3068 (setq files thefiles
3069 rtnall nil)
3070 (while (setq file (pop files))
3071 (catch 'nextfile
3072 (org-check-agenda-file file)
3073 (setq date (calendar-gregorian-from-absolute today)
3074 rtn (org-agenda-get-day-entries
3075 file date :todo))
3076 (setq rtnall (append rtnall rtn))))
3077 (when rtnall
3078 (insert "All currently open TODO items:\n")
3079 (add-text-properties (point-min) (1- (point))
3080 (list 'face 'org-agenda-structure
3081 'short-heading "All TODO items"))
3082 (org-agenda-mark-header-line (point-min))
3083 (insert (org-finalize-agenda-entries rtnall) "\n")))
3084 (unless org-agenda-compact-blocks
3085 (let* ((d1 (car day-numbers))
3086 (d2 (org-last day-numbers))
3087 (w1 (org-days-to-iso-week d1))
3088 (w2 (org-days-to-iso-week d2)))
3089 (setq s (point))
3090 (if org-agenda-overriding-header
3091 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3092 nil 'face 'org-agenda-structure) "\n")
3093 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3094 "-agenda"
3095 (if (< (- d2 d1) 350)
3096 (if (= w1 w2)
3097 (format " (W%02d)" w1)
3098 (format " (W%02d-W%02d)" w1 w2))
3100 ":\n")))
3101 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3102 'org-date-line t))
3103 (org-agenda-mark-header-line s))
3104 (while (setq d (pop day-numbers))
3105 (setq date (calendar-gregorian-from-absolute d)
3106 wd (calendar-day-of-week date)
3107 s (point))
3108 (if (or (setq todayp (= d today))
3109 (and (not start-pos) (= d sd)))
3110 (setq start-pos (point))
3111 (if (and start-pos (not end-pos))
3112 (setq end-pos (point))))
3113 (setq files thefiles
3114 rtnall nil)
3115 (while (setq file (pop files))
3116 (catch 'nextfile
3117 (org-check-agenda-file file)
3118 (cond
3119 ((eq org-agenda-show-log 'only)
3120 (setq rtn (org-agenda-get-day-entries
3121 file date :closed)))
3122 (org-agenda-show-log
3123 (setq rtn (org-agenda-get-day-entries
3124 file date
3125 :deadline :scheduled :timestamp :sexp :closed)))
3127 (setq rtn (org-agenda-get-day-entries
3128 file date
3129 :deadline :scheduled :sexp :timestamp))))
3130 (setq rtnall (append rtnall rtn))))
3131 (if org-agenda-include-diary
3132 (let ((org-agenda-search-headline-for-time t))
3133 (require 'diary-lib)
3134 (setq rtn (org-get-entries-from-diary date))
3135 (setq rtnall (append rtnall rtn))))
3136 (if (or rtnall org-agenda-show-all-dates)
3137 (progn
3138 (setq day-cnt (1+ day-cnt))
3139 (insert
3140 (if (stringp org-agenda-format-date)
3141 (format-time-string org-agenda-format-date
3142 (org-time-from-absolute date))
3143 (funcall org-agenda-format-date date))
3144 "\n")
3145 (put-text-property s (1- (point)) 'face
3146 (if (member wd org-agenda-weekend-days)
3147 'org-agenda-date-weekend
3148 'org-agenda-date))
3149 (put-text-property s (1- (point)) 'org-date-line t)
3150 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3151 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3152 (when todayp
3153 (put-text-property s (1- (point)) 'org-today t)
3154 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
3155 (if rtnall (insert
3156 (org-finalize-agenda-entries
3157 (org-agenda-add-time-grid-maybe
3158 rtnall nd todayp))
3159 "\n"))
3160 (put-text-property s (1- (point)) 'day d)
3161 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3162 (when (and org-agenda-clockreport-mode clocktable-start)
3163 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3164 ;; the above line is to ensure the restricted range!
3165 (p org-agenda-clockreport-parameter-plist)
3166 tbl)
3167 (setq p (org-plist-delete p :block))
3168 (setq p (plist-put p :tstart clocktable-start))
3169 (setq p (plist-put p :tend clocktable-end))
3170 (setq p (plist-put p :scope 'agenda))
3171 (setq tbl (apply 'org-get-clocktable p))
3172 (insert tbl)))
3173 (goto-char (point-min))
3174 (or org-agenda-multi (org-fit-agenda-window))
3175 (unless (and (pos-visible-in-window-p (point-min))
3176 (pos-visible-in-window-p (point-max)))
3177 (goto-char (1- (point-max)))
3178 (recenter -1)
3179 (if (not (pos-visible-in-window-p (or start-pos 1)))
3180 (progn
3181 (goto-char (or start-pos 1))
3182 (recenter 1))))
3183 (goto-char (or start-pos 1))
3184 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3185 (org-finalize-agenda)
3186 (setq buffer-read-only t)
3187 (message "")))
3189 (defun org-agenda-ndays-to-span (n)
3190 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3192 ;;; Agenda word search
3194 (defvar org-agenda-search-history nil)
3195 (defvar org-todo-only nil)
3197 (defvar org-search-syntax-table nil
3198 "Special syntax table for org-mode search.
3199 In this table, we have single quotes not as word constituents, to
3200 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3202 (defun org-search-syntax-table ()
3203 (unless org-search-syntax-table
3204 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3205 (modify-syntax-entry ?' "." org-search-syntax-table)
3206 (modify-syntax-entry ?` "." org-search-syntax-table))
3207 org-search-syntax-table)
3209 ;;;###autoload
3210 (defun org-search-view (&optional todo-only string edit-at)
3211 "Show all entries that contain words or regular expressions.
3212 If the first character of the search string is an asterisks,
3213 search only the headlines.
3215 With optional prefix argument TODO-ONLY, only consider entries that are
3216 TODO entries. The argument STRING can be used to pass a default search
3217 string into this function. If EDIT-AT is non-nil, it means that the
3218 user should get a chance to edit this string, with cursor at position
3219 EDIT-AT.
3221 The search string is broken into \"words\" by splitting at whitespace.
3222 Depending on the variable `org-agenda-search-view-search-words-only'
3223 and on whether the first character in the search string is \"+\" or \"-\",
3224 The string is then interpreted either as a substring with variable amounts
3225 of whitespace, or as a list or individual words that should be matched.
3227 The default is a substring match, where each space in the search string
3228 can expand to an arbitrary amount of whitespace, including newlines.
3230 If matching individual words, these words are then interpreted as a
3231 boolean expression with logical AND. Words prefixed with a minus must
3232 not occur in the entry. Words without a prefix or prefixed with a plus
3233 must occur in the entry. Matching is case-insensitive and the words
3234 are enclosed by word delimiters.
3236 Words enclosed by curly braces are interpreted as regular expressions
3237 that must or must not match in the entry.
3239 If the search string starts with an asterisk, search only in headlines.
3240 If (possibly after the leading star) the search string starts with an
3241 exclamation mark, this also means to look at TODO entries only, an effect
3242 that can also be achieved with a prefix argument.
3244 This command searches the agenda files, and in addition the files listed
3245 in `org-agenda-text-search-extra-files'."
3246 (interactive "P")
3247 (org-compile-prefix-format 'search)
3248 (org-set-sorting-strategy 'search)
3249 (org-prepare-agenda "SEARCH")
3250 (let* ((props (list 'face nil
3251 'done-face 'org-agenda-done
3252 'org-not-done-regexp org-not-done-regexp
3253 'org-todo-regexp org-todo-regexp
3254 'org-complex-heading-regexp org-complex-heading-regexp
3255 'mouse-face 'highlight
3256 'help-echo (format "mouse-2 or RET jump to location")))
3257 regexp rtn rtnall files file pos
3258 marker category tags c neg re as-words
3259 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3260 (unless (and (not edit-at)
3261 (stringp string)
3262 (string-match "\\S-" string))
3263 (setq string (read-string "[+-]Word/{Regexp} ...: "
3264 (cond
3265 ((integerp edit-at) (cons string edit-at))
3266 (edit-at string))
3267 'org-agenda-search-history)))
3268 (org-set-local 'org-todo-only todo-only)
3269 (setq org-agenda-redo-command
3270 (list 'org-search-view (if todo-only t nil) string
3271 '(if current-prefix-arg 1 nil)))
3272 (setq org-agenda-query-string string)
3274 (if (equal (string-to-char string) ?*)
3275 (setq hdl-only t
3276 words (substring string 1))
3277 (setq words string))
3278 (when (equal (string-to-char words) ?!)
3279 (setq todo-only t
3280 words (substring words 1)))
3281 (if (or org-agenda-search-view-search-words-only
3282 (member (string-to-char string) '(?- ?+)))
3283 (setq as-words t))
3284 (setq words (org-split-string words))
3285 (if as-words
3286 (mapc (lambda (w)
3287 (setq c (string-to-char w))
3288 (if (equal c ?-)
3289 (setq neg t w (substring w 1))
3290 (if (equal c ?+)
3291 (setq neg nil w (substring w 1))
3292 (setq neg nil)))
3293 (if (string-match "\\`{.*}\\'" w)
3294 (setq re (substring w 1 -1))
3295 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>")))
3296 (if neg (push re regexps-) (push re regexps+)))
3297 words)
3298 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3299 regexps+))
3300 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3301 (if (not regexps+)
3302 (setq regexp (concat "^" org-outline-regexp))
3303 (setq regexp (pop regexps+))
3304 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3305 regexp))))
3306 (setq files (org-agenda-files nil 'ifmode))
3307 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3308 (pop org-agenda-text-search-extra-files)
3309 (setq files (org-add-archive-files files)))
3310 (setq files (append files org-agenda-text-search-extra-files)
3311 rtnall nil)
3312 (while (setq file (pop files))
3313 (setq ee nil)
3314 (catch 'nextfile
3315 (org-check-agenda-file file)
3316 (setq buffer (if (file-exists-p file)
3317 (org-get-agenda-file-buffer file)
3318 (error "No such file %s" file)))
3319 (if (not buffer)
3320 ;; If file does not exist, make sure an error message is sent
3321 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3322 file))))
3323 (with-current-buffer buffer
3324 (with-syntax-table (org-search-syntax-table)
3325 (unless (org-mode-p)
3326 (error "Agenda file %s is not in `org-mode'" file))
3327 (let ((case-fold-search t))
3328 (save-excursion
3329 (save-restriction
3330 (if org-agenda-restrict
3331 (narrow-to-region org-agenda-restrict-begin
3332 org-agenda-restrict-end)
3333 (widen))
3334 (goto-char (point-min))
3335 (unless (or (org-on-heading-p)
3336 (outline-next-heading))
3337 (throw 'nextfile t))
3338 (goto-char (max (point-min) (1- (point))))
3339 (while (re-search-forward regexp nil t)
3340 (org-back-to-heading t)
3341 (skip-chars-forward "* ")
3342 (setq beg (point-at-bol)
3343 beg1 (point)
3344 end (progn (outline-next-heading) (point)))
3345 (catch :skip
3346 (goto-char beg)
3347 (org-agenda-skip)
3348 (setq str (buffer-substring-no-properties
3349 (point-at-bol)
3350 (if hdl-only (point-at-eol) end)))
3351 (mapc (lambda (wr) (when (string-match wr str)
3352 (goto-char (1- end))
3353 (throw :skip t)))
3354 regexps-)
3355 (mapc (lambda (wr) (unless (string-match wr str)
3356 (goto-char (1- end))
3357 (throw :skip t)))
3358 (if todo-only
3359 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3360 regexps+)
3361 regexps+))
3362 (goto-char beg)
3363 (setq marker (org-agenda-new-marker (point))
3364 category (org-get-category)
3365 tags (org-get-tags-at (point))
3366 txt (org-format-agenda-item
3368 (buffer-substring-no-properties
3369 beg1 (point-at-eol))
3370 category tags))
3371 (org-add-props txt props
3372 'org-marker marker 'org-hd-marker marker
3373 'org-todo-regexp org-todo-regexp
3374 'org-complex-heading-regexp org-complex-heading-regexp
3375 'priority 1000 'org-category category
3376 'type "search")
3377 (push txt ee)
3378 (goto-char (1- end))))))))))
3379 (setq rtn (nreverse ee))
3380 (setq rtnall (append rtnall rtn)))
3381 (if org-agenda-overriding-header
3382 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3383 nil 'face 'org-agenda-structure) "\n")
3384 (insert "Search words: ")
3385 (add-text-properties (point-min) (1- (point))
3386 (list 'face 'org-agenda-structure))
3387 (setq pos (point))
3388 (insert string "\n")
3389 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3390 (setq pos (point))
3391 (unless org-agenda-multi
3392 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3393 (add-text-properties pos (1- (point))
3394 (list 'face 'org-agenda-structure))))
3395 (org-agenda-mark-header-line (point-min))
3396 (when rtnall
3397 (insert (org-finalize-agenda-entries rtnall) "\n"))
3398 (goto-char (point-min))
3399 (or org-agenda-multi (org-fit-agenda-window))
3400 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3401 (org-finalize-agenda)
3402 (setq buffer-read-only t)))
3404 ;;; Agenda TODO list
3406 (defvar org-select-this-todo-keyword nil)
3407 (defvar org-last-arg nil)
3409 ;;;###autoload
3410 (defun org-todo-list (arg)
3411 "Show all TODO entries from all agenda file in a single list.
3412 The prefix arg can be used to select a specific TODO keyword and limit
3413 the list to these. When using \\[universal-argument], you will be prompted
3414 for a keyword. A numeric prefix directly selects the Nth keyword in
3415 `org-todo-keywords-1'."
3416 (interactive "P")
3417 (require 'calendar)
3418 (org-compile-prefix-format 'todo)
3419 (org-set-sorting-strategy 'todo)
3420 (org-prepare-agenda "TODO")
3421 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3422 (let* ((today (time-to-days (current-time)))
3423 (date (calendar-gregorian-from-absolute today))
3424 (kwds org-todo-keywords-for-agenda)
3425 (completion-ignore-case t)
3426 (org-select-this-todo-keyword
3427 (if (stringp arg) arg
3428 (and arg (integerp arg) (> arg 0)
3429 (nth (1- arg) kwds))))
3430 rtn rtnall files file pos)
3431 (when (equal arg '(4))
3432 (setq org-select-this-todo-keyword
3433 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3434 (mapcar 'list kwds) nil nil)))
3435 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3436 (org-set-local 'org-last-arg arg)
3437 (setq org-agenda-redo-command
3438 '(org-todo-list (or current-prefix-arg org-last-arg)))
3439 (setq files (org-agenda-files nil 'ifmode)
3440 rtnall nil)
3441 (while (setq file (pop files))
3442 (catch 'nextfile
3443 (org-check-agenda-file file)
3444 (setq rtn (org-agenda-get-day-entries file date :todo))
3445 (setq rtnall (append rtnall rtn))))
3446 (if org-agenda-overriding-header
3447 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3448 nil 'face 'org-agenda-structure) "\n")
3449 (insert "Global list of TODO items of type: ")
3450 (add-text-properties (point-min) (1- (point))
3451 (list 'face 'org-agenda-structure
3452 'short-heading
3453 (concat "ToDo: "
3454 (or org-select-this-todo-keyword "ALL"))))
3455 (org-agenda-mark-header-line (point-min))
3456 (setq pos (point))
3457 (insert (or org-select-this-todo-keyword "ALL") "\n")
3458 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3459 (setq pos (point))
3460 (unless org-agenda-multi
3461 (insert "Available with `N r': (0)ALL")
3462 (let ((n 0) s)
3463 (mapc (lambda (x)
3464 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3465 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3466 (insert "\n "))
3467 (insert " " s))
3468 kwds))
3469 (insert "\n"))
3470 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3471 (org-agenda-mark-header-line (point-min))
3472 (when rtnall
3473 (insert (org-finalize-agenda-entries rtnall) "\n"))
3474 (goto-char (point-min))
3475 (or org-agenda-multi (org-fit-agenda-window))
3476 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3477 (org-finalize-agenda)
3478 (setq buffer-read-only t)))
3480 ;;; Agenda tags match
3482 ;;;###autoload
3483 (defun org-tags-view (&optional todo-only match)
3484 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3485 The prefix arg TODO-ONLY limits the search to TODO entries."
3486 (interactive "P")
3487 (org-compile-prefix-format 'tags)
3488 (org-set-sorting-strategy 'tags)
3489 (let* ((org-tags-match-list-sublevels
3490 org-tags-match-list-sublevels)
3491 (completion-ignore-case t)
3492 rtn rtnall files file pos matcher
3493 buffer)
3494 (when (and (stringp match) (not (string-match "\\S-" match)))
3495 (setq match nil))
3496 (setq matcher (org-make-tags-matcher match)
3497 match (car matcher) matcher (cdr matcher))
3498 (org-prepare-agenda (concat "TAGS " match))
3499 (setq org-agenda-query-string match)
3500 (setq org-agenda-redo-command
3501 (list 'org-tags-view (list 'quote todo-only)
3502 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3503 (setq files (org-agenda-files nil 'ifmode)
3504 rtnall nil)
3505 (while (setq file (pop files))
3506 (catch 'nextfile
3507 (org-check-agenda-file file)
3508 (setq buffer (if (file-exists-p file)
3509 (org-get-agenda-file-buffer file)
3510 (error "No such file %s" file)))
3511 (if (not buffer)
3512 ;; If file does not exist, error message to agenda
3513 (setq rtn (list
3514 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3515 rtnall (append rtnall rtn))
3516 (with-current-buffer buffer
3517 (unless (org-mode-p)
3518 (error "Agenda file %s is not in `org-mode'" file))
3519 (save-excursion
3520 (save-restriction
3521 (if org-agenda-restrict
3522 (narrow-to-region org-agenda-restrict-begin
3523 org-agenda-restrict-end)
3524 (widen))
3525 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3526 (setq rtnall (append rtnall rtn))))))))
3527 (if org-agenda-overriding-header
3528 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3529 nil 'face 'org-agenda-structure) "\n")
3530 (insert "Headlines with TAGS match: ")
3531 (add-text-properties (point-min) (1- (point))
3532 (list 'face 'org-agenda-structure
3533 'short-heading
3534 (concat "Match: " match)))
3535 (setq pos (point))
3536 (insert match "\n")
3537 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3538 (setq pos (point))
3539 (unless org-agenda-multi
3540 (insert "Press `C-u r' to search again with new search string\n"))
3541 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3542 (org-agenda-mark-header-line (point-min))
3543 (when rtnall
3544 (insert (org-finalize-agenda-entries rtnall) "\n"))
3545 (goto-char (point-min))
3546 (or org-agenda-multi (org-fit-agenda-window))
3547 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3548 (org-finalize-agenda)
3549 (setq buffer-read-only t)))
3551 ;;; Agenda Finding stuck projects
3553 (defvar org-agenda-skip-regexp nil
3554 "Regular expression used in skipping subtrees for the agenda.
3555 This is basically a temporary global variable that can be set and then
3556 used by user-defined selections using `org-agenda-skip-function'.")
3558 (defvar org-agenda-overriding-header nil
3559 "When this is set during todo and tags searches, will replace header.
3560 This variable should not be set directly, but custom commands can bind it
3561 in the options section.")
3563 (defun org-agenda-skip-entry-when-regexp-matches ()
3564 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3565 If yes, it returns the end position of this entry, causing agenda commands
3566 to skip the entry but continuing the search in the subtree. This is a
3567 function that can be put into `org-agenda-skip-function' for the duration
3568 of a command."
3569 (let ((end (save-excursion (org-end-of-subtree t)))
3570 skip)
3571 (save-excursion
3572 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3573 (and skip end)))
3575 (defun org-agenda-skip-subtree-when-regexp-matches ()
3576 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3577 If yes, it returns the end position of this tree, causing agenda commands
3578 to skip this subtree. This is a function that can be put into
3579 `org-agenda-skip-function' for the duration of a command."
3580 (let ((end (save-excursion (org-end-of-subtree t)))
3581 skip)
3582 (save-excursion
3583 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3584 (and skip end)))
3586 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3587 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3588 If yes, it returns the end position of the current entry (NOT the tree),
3589 causing agenda commands to skip the entry but continuing the search in
3590 the subtree. This is a function that can be put into
3591 `org-agenda-skip-function' for the duration of a command. An important
3592 use of this function is for the stuck project list."
3593 (let ((end (save-excursion (org-end-of-subtree t)))
3594 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3595 skip)
3596 (save-excursion
3597 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3598 (and skip entry-end)))
3600 (defun org-agenda-skip-entry-if (&rest conditions)
3601 "Skip entry if any of CONDITIONS is true.
3602 See `org-agenda-skip-if' for details."
3603 (org-agenda-skip-if nil conditions))
3605 (defun org-agenda-skip-subtree-if (&rest conditions)
3606 "Skip entry if any of CONDITIONS is true.
3607 See `org-agenda-skip-if' for details."
3608 (org-agenda-skip-if t conditions))
3610 (defun org-agenda-skip-if (subtree conditions)
3611 "Checks current entity for CONDITIONS.
3612 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3613 the entry, i.e. the text before the next heading is checked.
3615 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3616 from different tests. Valid conditions are:
3618 scheduled Check if there is a scheduled cookie
3619 notscheduled Check if there is no scheduled cookie
3620 deadline Check if there is a deadline
3621 notdeadline Check if there is no deadline
3622 timestamp Check if there is a timestamp (also deadline or scheduled)
3623 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3624 regexp Check if regexp matches
3625 notregexp Check if regexp does not match.
3627 The regexp is taken from the conditions list, it must come right after
3628 the `regexp' or `notregexp' element.
3630 If any of these conditions is met, this function returns the end point of
3631 the entity, causing the search to continue from there. This is a function
3632 that can be put into `org-agenda-skip-function' for the duration of a command."
3633 (let (beg end m)
3634 (org-back-to-heading t)
3635 (setq beg (point)
3636 end (if subtree
3637 (progn (org-end-of-subtree t) (point))
3638 (progn (outline-next-heading) (1- (point)))))
3639 (goto-char beg)
3640 (and
3642 (and (memq 'scheduled conditions)
3643 (re-search-forward org-scheduled-time-regexp end t))
3644 (and (memq 'notscheduled conditions)
3645 (not (re-search-forward org-scheduled-time-regexp end t)))
3646 (and (memq 'deadline conditions)
3647 (re-search-forward org-deadline-time-regexp end t))
3648 (and (memq 'notdeadline conditions)
3649 (not (re-search-forward org-deadline-time-regexp end t)))
3650 (and (memq 'timestamp conditions)
3651 (re-search-forward org-ts-regexp end t))
3652 (and (memq 'nottimestamp conditions)
3653 (not (re-search-forward org-ts-regexp end t)))
3654 (and (setq m (memq 'regexp conditions))
3655 (stringp (nth 1 m))
3656 (re-search-forward (nth 1 m) end t))
3657 (and (setq m (memq 'notregexp conditions))
3658 (stringp (nth 1 m))
3659 (not (re-search-forward (nth 1 m) end t))))
3660 end)))
3662 ;;;###autoload
3663 (defun org-agenda-list-stuck-projects (&rest ignore)
3664 "Create agenda view for projects that are stuck.
3665 Stuck projects are project that have no next actions. For the definitions
3666 of what a project is and how to check if it stuck, customize the variable
3667 `org-stuck-projects'.
3668 MATCH is being ignored."
3669 (interactive)
3670 (let* ((org-agenda-skip-function
3671 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
3672 ;; We could have used org-agenda-skip-if here.
3673 (org-agenda-overriding-header
3674 (or org-agenda-overriding-header "List of stuck projects: "))
3675 (matcher (nth 0 org-stuck-projects))
3676 (todo (nth 1 org-stuck-projects))
3677 (todo-wds (if (member "*" todo)
3678 (progn
3679 (org-prepare-agenda-buffers (org-agenda-files
3680 nil 'ifmode))
3681 (org-delete-all
3682 org-done-keywords-for-agenda
3683 (copy-sequence org-todo-keywords-for-agenda)))
3684 todo))
3685 (todo-re (concat "^\\*+[ \t]+\\("
3686 (mapconcat 'identity todo-wds "\\|")
3687 "\\)\\>"))
3688 (tags (nth 2 org-stuck-projects))
3689 (tags-re (if (member "*" tags)
3690 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3691 (if tags
3692 (concat "^\\*+ .*:\\("
3693 (mapconcat 'identity tags "\\|")
3694 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3695 (gen-re (nth 3 org-stuck-projects))
3696 (re-list
3697 (delq nil
3698 (list
3699 (if todo todo-re)
3700 (if tags tags-re)
3701 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
3702 gen-re)))))
3703 (setq org-agenda-skip-regexp
3704 (if re-list
3705 (mapconcat 'identity re-list "\\|")
3706 (error "No information how to identify unstuck projects")))
3707 (org-tags-view nil matcher)
3708 (with-current-buffer org-agenda-buffer-name
3709 (setq org-agenda-redo-command
3710 '(org-agenda-list-stuck-projects
3711 (or current-prefix-arg org-last-arg))))))
3713 ;;; Diary integration
3715 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
3716 (defvar list-diary-entries-hook)
3718 (defun org-get-entries-from-diary (date)
3719 "Get the (Emacs Calendar) diary entries for DATE."
3720 (require 'diary-lib)
3721 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3722 (fancy-diary-buffer diary-fancy-buffer)
3723 (diary-display-hook '(fancy-diary-display))
3724 (diary-display-function 'fancy-diary-display)
3725 (pop-up-frames nil)
3726 (list-diary-entries-hook
3727 (cons 'org-diary-default-entry list-diary-entries-hook))
3728 (diary-file-name-prefix-function nil) ; turn this feature off
3729 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
3730 entries
3731 (org-disable-agenda-to-diary t))
3732 (save-excursion
3733 (save-window-excursion
3734 (funcall (if (fboundp 'diary-list-entries)
3735 'diary-list-entries 'list-diary-entries)
3736 date 1)))
3737 (if (not (get-buffer diary-fancy-buffer))
3738 (setq entries nil)
3739 (with-current-buffer diary-fancy-buffer
3740 (setq buffer-read-only nil)
3741 (if (zerop (buffer-size))
3742 ;; No entries
3743 (setq entries nil)
3744 ;; Omit the date and other unnecessary stuff
3745 (org-agenda-cleanup-fancy-diary)
3746 ;; Add prefix to each line and extend the text properties
3747 (if (zerop (buffer-size))
3748 (setq entries nil)
3749 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
3750 (set-buffer-modified-p nil)
3751 (kill-buffer diary-fancy-buffer)))
3752 (when entries
3753 (setq entries (org-split-string entries "\n"))
3754 (setq entries
3755 (mapcar
3756 (lambda (x)
3757 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
3758 ;; Extend the text properties to the beginning of the line
3759 (org-add-props x (text-properties-at (1- (length x)) x)
3760 'type "diary" 'date date))
3761 entries)))))
3763 (defvar org-agenda-cleanup-fancy-diary-hook nil
3764 "Hook run when the fancy diary buffer is cleaned up.")
3766 (defun org-agenda-cleanup-fancy-diary ()
3767 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3768 This gets rid of the date, the underline under the date, and
3769 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3770 date. It also removes lines that contain only whitespace."
3771 (goto-char (point-min))
3772 (if (looking-at ".*?:[ \t]*")
3773 (progn
3774 (replace-match "")
3775 (re-search-forward "\n=+$" nil t)
3776 (replace-match "")
3777 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
3778 (re-search-forward "\n=+$" nil t)
3779 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3780 (goto-char (point-min))
3781 (while (re-search-forward "^ +\n" nil t)
3782 (replace-match ""))
3783 (goto-char (point-min))
3784 (if (re-search-forward "^Org-mode dummy\n?" nil t)
3785 (replace-match ""))
3786 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
3788 ;; Make sure entries from the diary have the right text properties.
3789 (eval-after-load "diary-lib"
3790 '(if (boundp 'diary-modify-entry-list-string-function)
3791 ;; We can rely on the hook, nothing to do
3793 ;; Hook not available, must use advice to make this work
3794 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
3795 "Make the position visible."
3796 (if (and org-disable-agenda-to-diary ;; called from org-agenda
3797 (stringp string)
3798 buffer-file-name)
3799 (setq string (org-modify-diary-entry-string string))))))
3801 (defun org-modify-diary-entry-string (string)
3802 "Add text properties to string, allowing org-mode to act on it."
3803 (org-add-props string nil
3804 'mouse-face 'highlight
3805 'help-echo (if buffer-file-name
3806 (format "mouse-2 or RET jump to diary file %s"
3807 (abbreviate-file-name buffer-file-name))
3809 'org-agenda-diary-link t
3810 'org-marker (org-agenda-new-marker (point-at-bol))))
3812 (defun org-diary-default-entry ()
3813 "Add a dummy entry to the diary.
3814 Needed to avoid empty dates which mess up holiday display."
3815 ;; Catch the error if dealing with the new add-to-diary-alist
3816 (when org-disable-agenda-to-diary
3817 (condition-case nil
3818 (org-add-to-diary-list original-date "Org-mode dummy" "")
3819 (error
3820 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
3822 (defun org-add-to-diary-list (&rest args)
3823 (if (fboundp 'diary-add-to-list)
3824 (apply 'diary-add-to-list args)
3825 (apply 'add-to-diary-list args)))
3827 ;;;###autoload
3828 (defun org-diary (&rest args)
3829 "Return diary information from org-files.
3830 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3831 It accesses org files and extracts information from those files to be
3832 listed in the diary. The function accepts arguments specifying what
3833 items should be listed. The following arguments are allowed:
3835 :timestamp List the headlines of items containing a date stamp or
3836 date range matching the selected date. Deadlines will
3837 also be listed, on the expiration day.
3839 :sexp List entries resulting from diary-like sexps.
3841 :deadline List any deadlines past due, or due within
3842 `org-deadline-warning-days'. The listing occurs only
3843 in the diary for *today*, not at any other date. If
3844 an entry is marked DONE, it is no longer listed.
3846 :scheduled List all items which are scheduled for the given date.
3847 The diary for *today* also contains items which were
3848 scheduled earlier and are not yet marked DONE.
3850 :todo List all TODO items from the org-file. This may be a
3851 long list - so this is not turned on by default.
3852 Like deadlines, these entries only show up in the
3853 diary for *today*, not at any other date.
3855 The call in the diary file should look like this:
3857 &%%(org-diary) ~/path/to/some/orgfile.org
3859 Use a separate line for each org file to check. Or, if you omit the file name,
3860 all files listed in `org-agenda-files' will be checked automatically:
3862 &%%(org-diary)
3864 If you don't give any arguments (as in the example above), the default
3865 arguments (:deadline :scheduled :timestamp :sexp) are used.
3866 So the example above may also be written as
3868 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3870 The function expects the lisp variables `entry' and `date' to be provided
3871 by the caller, because this is how the calendar works. Don't use this
3872 function from a program - use `org-agenda-get-day-entries' instead."
3873 (when (> (- (org-float-time)
3874 org-agenda-last-marker-time)
3876 (org-agenda-reset-markers))
3877 (org-compile-prefix-format 'agenda)
3878 (org-set-sorting-strategy 'agenda)
3879 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3880 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
3881 (list entry)
3882 (org-agenda-files t)))
3883 file rtn results)
3884 (org-prepare-agenda-buffers files)
3885 ;; If this is called during org-agenda, don't return any entries to
3886 ;; the calendar. Org Agenda will list these entries itself.
3887 (if org-disable-agenda-to-diary (setq files nil))
3888 (while (setq file (pop files))
3889 (setq rtn (apply 'org-agenda-get-day-entries file date args))
3890 (setq results (append results rtn)))
3891 (if results
3892 (concat (org-finalize-agenda-entries results) "\n"))))
3894 ;;; Agenda entry finders
3896 (defun org-agenda-get-day-entries (file date &rest args)
3897 "Does the work for `org-diary' and `org-agenda'.
3898 FILE is the path to a file to be checked for entries. DATE is date like
3899 the one returned by `calendar-current-date'. ARGS are symbols indicating
3900 which kind of entries should be extracted. For details about these, see
3901 the documentation of `org-diary'."
3902 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3903 (let* ((org-startup-folded nil)
3904 (org-startup-align-all-tables nil)
3905 (buffer (if (file-exists-p file)
3906 (org-get-agenda-file-buffer file)
3907 (error "No such file %s" file)))
3908 arg results rtn deadline-results)
3909 (if (not buffer)
3910 ;; If file does not exist, make sure an error message ends up in diary
3911 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3912 (with-current-buffer buffer
3913 (unless (org-mode-p)
3914 (error "Agenda file %s is not in `org-mode'" file))
3915 (let ((case-fold-search nil))
3916 (save-excursion
3917 (save-restriction
3918 (if org-agenda-restrict
3919 (narrow-to-region org-agenda-restrict-begin
3920 org-agenda-restrict-end)
3921 (widen))
3922 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3923 (while (setq arg (pop args))
3924 (cond
3925 ((and (eq arg :todo)
3926 (equal date (calendar-current-date)))
3927 (setq rtn (org-agenda-get-todos))
3928 (setq results (append results rtn)))
3929 ((eq arg :timestamp)
3930 (setq rtn (org-agenda-get-blocks))
3931 (setq results (append results rtn))
3932 (setq rtn (org-agenda-get-timestamps))
3933 (setq results (append results rtn)))
3934 ((eq arg :sexp)
3935 (setq rtn (org-agenda-get-sexps))
3936 (setq results (append results rtn)))
3937 ((eq arg :scheduled)
3938 (setq rtn (org-agenda-get-scheduled deadline-results))
3939 (setq results (append results rtn)))
3940 ((eq arg :closed)
3941 (setq rtn (org-agenda-get-progress))
3942 (setq results (append results rtn)))
3943 ((eq arg :deadline)
3944 (setq rtn (org-agenda-get-deadlines))
3945 (setq deadline-results (copy-sequence rtn))
3946 (setq results (append results rtn))))))))
3947 results))))
3949 (defun org-agenda-get-todos ()
3950 "Return the TODO information for agenda display."
3951 (let* ((props (list 'face nil
3952 'done-face 'org-agenda-done
3953 'org-not-done-regexp org-not-done-regexp
3954 'org-todo-regexp org-todo-regexp
3955 'org-complex-heading-regexp org-complex-heading-regexp
3956 'mouse-face 'highlight
3957 'help-echo
3958 (format "mouse-2 or RET jump to org file %s"
3959 (abbreviate-file-name buffer-file-name))))
3960 (regexp (concat "^\\*+[ \t]+\\("
3961 (if org-select-this-todo-keyword
3962 (if (equal org-select-this-todo-keyword "*")
3963 org-todo-regexp
3964 (concat "\\<\\("
3965 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
3966 "\\)\\>"))
3967 org-not-done-regexp)
3968 "[^\n\r]*\\)"))
3969 marker priority category tags todo-state
3970 ee txt beg end)
3971 (goto-char (point-min))
3972 (while (re-search-forward regexp nil t)
3973 (catch :skip
3974 (save-match-data
3975 (beginning-of-line)
3976 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
3977 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
3978 (goto-char (1+ beg))
3979 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
3980 (throw :skip nil)))
3981 (goto-char beg)
3982 (org-agenda-skip)
3983 (goto-char (match-beginning 1))
3984 (setq marker (org-agenda-new-marker (match-beginning 0))
3985 category (org-get-category)
3986 txt (match-string 1)
3987 tags (org-get-tags-at (point))
3988 txt (org-format-agenda-item "" txt category tags)
3989 priority (1+ (org-get-priority txt))
3990 todo-state (org-get-todo-state))
3991 (org-add-props txt props
3992 'org-marker marker 'org-hd-marker marker
3993 'priority priority 'org-category category
3994 'type "todo" 'todo-state todo-state)
3995 (push txt ee)
3996 (if org-agenda-todo-list-sublevels
3997 (goto-char (match-end 1))
3998 (org-end-of-subtree 'invisible))))
3999 (nreverse ee)))
4001 ;;;###autoload
4002 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
4003 "Do we have a reason to ignore this todo entry because it has a time stamp?"
4004 (when (or org-agenda-todo-ignore-with-date
4005 org-agenda-todo-ignore-scheduled
4006 org-agenda-todo-ignore-deadlines)
4007 (setq end (or end (save-excursion (outline-next-heading) (point))))
4008 (save-excursion
4009 (or (and org-agenda-todo-ignore-with-date
4010 (re-search-forward org-ts-regexp end t))
4011 (and org-agenda-todo-ignore-scheduled
4012 (re-search-forward org-scheduled-time-regexp end t))
4013 (and org-agenda-todo-ignore-deadlines
4014 (re-search-forward org-deadline-time-regexp end t)
4015 (org-deadline-close (match-string 1)))))))
4017 (defconst org-agenda-no-heading-message
4018 "No heading for this item in buffer or region.")
4020 (defun org-agenda-get-timestamps ()
4021 "Return the date stamp information for agenda display."
4022 (let* ((props (list 'face nil
4023 'org-not-done-regexp org-not-done-regexp
4024 'org-todo-regexp org-todo-regexp
4025 'org-complex-heading-regexp org-complex-heading-regexp
4026 'mouse-face 'highlight
4027 'help-echo
4028 (format "mouse-2 or RET jump to org file %s"
4029 (abbreviate-file-name buffer-file-name))))
4030 (d1 (calendar-absolute-from-gregorian date))
4031 (remove-re
4032 (concat
4033 (regexp-quote
4034 (format-time-string
4035 "<%Y-%m-%d"
4036 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4037 ".*?>"))
4038 (regexp
4039 (concat
4040 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4041 (regexp-quote
4042 (substring
4043 (format-time-string
4044 (car org-time-stamp-formats)
4045 (apply 'encode-time ; DATE bound by calendar
4046 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4047 1 11))
4048 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4049 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4050 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4051 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4052 todo-state end-of-match)
4053 (goto-char (point-min))
4054 (while (setq end-of-match (re-search-forward regexp nil t))
4055 (setq b0 (match-beginning 0)
4056 b3 (match-beginning 3) e3 (match-end 3))
4057 (catch :skip
4058 (and (org-at-date-range-p) (throw :skip nil))
4059 (org-agenda-skip)
4060 (if (and (match-end 1)
4061 (not (= d1 (org-time-string-to-absolute
4062 (match-string 1) d1 nil
4063 org-agenda-repeating-timestamp-show-all))))
4064 (throw :skip nil))
4065 (if (and e3
4066 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4067 (throw :skip nil))
4068 (setq tmp (buffer-substring (max (point-min)
4069 (- b0 org-ds-keyword-length))
4071 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4072 inactivep (= (char-after b0) ?\[)
4073 deadlinep (string-match org-deadline-regexp tmp)
4074 scheduledp (string-match org-scheduled-regexp tmp)
4075 closedp (and org-agenda-include-inactive-timestamps
4076 (string-match org-closed-string tmp))
4077 clockp (and org-agenda-include-inactive-timestamps
4078 (or (string-match org-clock-string tmp)
4079 (string-match "]-+\\'" tmp)))
4080 todo-state (org-get-todo-state)
4081 donep (member todo-state org-done-keywords))
4082 (if (or scheduledp deadlinep closedp clockp
4083 (and donep org-agenda-skip-timestamp-if-done))
4084 (throw :skip t))
4085 (if (string-match ">" timestr)
4086 ;; substring should only run to end of time stamp
4087 (setq timestr (substring timestr 0 (match-end 0))))
4088 (setq marker (org-agenda-new-marker b0)
4089 category (org-get-category b0))
4090 (save-excursion
4091 (if (not (re-search-backward "^\\*+ " nil t))
4092 (setq txt org-agenda-no-heading-message)
4093 (goto-char (match-beginning 0))
4094 (setq hdmarker (org-agenda-new-marker)
4095 tags (org-get-tags-at))
4096 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4097 (setq head (match-string 1))
4098 (setq txt (org-format-agenda-item
4099 (if inactivep org-agenda-inactive-leader nil)
4100 head category tags timestr nil
4101 remove-re)))
4102 (setq priority (org-get-priority txt))
4103 (org-add-props txt props
4104 'org-marker marker 'org-hd-marker hdmarker)
4105 (org-add-props txt nil 'priority priority
4106 'org-category category 'date date
4107 'todo-state todo-state
4108 'type "timestamp")
4109 (push txt ee))
4110 (if org-agenda-skip-additional-timestamps-same-entry
4111 (outline-next-heading)
4112 (goto-char end-of-match))))
4113 (nreverse ee)))
4115 (defun org-agenda-get-sexps ()
4116 "Return the sexp information for agenda display."
4117 (require 'diary-lib)
4118 (let* ((props (list 'face nil
4119 'mouse-face 'highlight
4120 'help-echo
4121 (format "mouse-2 or RET jump to org file %s"
4122 (abbreviate-file-name buffer-file-name))))
4123 (regexp "^&?%%(")
4124 marker category ee txt tags entry result beg b sexp sexp-entry
4125 todo-state)
4126 (goto-char (point-min))
4127 (while (re-search-forward regexp nil t)
4128 (catch :skip
4129 (org-agenda-skip)
4130 (setq beg (match-beginning 0))
4131 (goto-char (1- (match-end 0)))
4132 (setq b (point))
4133 (forward-sexp 1)
4134 (setq sexp (buffer-substring b (point)))
4135 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4136 (org-trim (match-string 1))
4137 ""))
4138 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4139 (when result
4140 (setq marker (org-agenda-new-marker beg)
4141 category (org-get-category beg)
4142 todo-state (org-get-todo-state))
4144 (if (string-match "\\S-" result)
4145 (setq txt result)
4146 (setq txt "SEXP entry returned empty string"))
4148 (setq txt (org-format-agenda-item
4149 "" txt category tags 'time))
4150 (org-add-props txt props 'org-marker marker)
4151 (org-add-props txt nil
4152 'org-category category 'date date 'todo-state todo-state
4153 'type "sexp")
4154 (push txt ee))))
4155 (nreverse ee)))
4157 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4158 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4159 Order of the parameters is M1, D1, Y1, M2, D2, Y2 if
4160 `european-calendar-style' is nil, and D1, M1, Y1, D2, M2, Y2 if
4161 `european-calendar-style' is t.
4162 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4163 is any number of ISO weeks in the block period for which the item should
4164 be skipped."
4165 (let* ((date1 (calendar-absolute-from-gregorian
4166 (if european-calendar-style
4167 (list d1 m1 y1)
4168 (list m1 d1 y1))))
4169 (date2 (calendar-absolute-from-gregorian
4170 (if european-calendar-style
4171 (list d2 m2 y2)
4172 (list m2 d2 y2))))
4173 (d (calendar-absolute-from-gregorian date)))
4174 (and
4175 (<= date1 d)
4176 (<= d date2)
4177 (= (calendar-day-of-week date) dayname)
4178 (or (not skip-weeks)
4179 (progn
4180 (require 'cal-iso)
4181 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4182 entry)))
4184 (defalias 'org-get-closed 'org-agenda-get-progress)
4185 (defun org-agenda-get-progress ()
4186 "Return the logged TODO entries for agenda display."
4187 (let* ((props (list 'mouse-face 'highlight
4188 'org-not-done-regexp org-not-done-regexp
4189 'org-todo-regexp org-todo-regexp
4190 'org-complex-heading-regexp org-complex-heading-regexp
4191 'help-echo
4192 (format "mouse-2 or RET jump to org file %s"
4193 (abbreviate-file-name buffer-file-name))))
4194 (items (if (consp org-agenda-show-log)
4195 org-agenda-show-log
4196 org-agenda-log-mode-items))
4197 (parts
4198 (delq nil
4199 (list
4200 (if (memq 'closed items) (concat "\\<" org-closed-string))
4201 (if (memq 'clock items) (concat "\\<" org-clock-string))
4202 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4203 (parts-re (if parts (mapconcat 'identity parts "\\|")
4204 (error "`org-agenda-log-mode-items' is empty")))
4205 (regexp (concat
4206 "\\(" parts-re "\\)"
4207 " *\\["
4208 (regexp-quote
4209 (substring
4210 (format-time-string
4211 (car org-time-stamp-formats)
4212 (apply 'encode-time ; DATE bound by calendar
4213 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4214 1 11))))
4215 (org-agenda-search-headline-for-time nil)
4216 marker hdmarker priority category tags closedp statep clockp state
4217 ee txt extra timestr rest clocked)
4218 (goto-char (point-min))
4219 (while (re-search-forward regexp nil t)
4220 (catch :skip
4221 (org-agenda-skip)
4222 (setq marker (org-agenda-new-marker (match-beginning 0))
4223 closedp (equal (match-string 1) org-closed-string)
4224 statep (equal (string-to-char (match-string 1)) ?-)
4225 clockp (not (or closedp statep))
4226 state (and statep (match-string 2))
4227 category (org-get-category (match-beginning 0))
4228 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4230 (when (string-match "\\]" timestr)
4231 ;; substring should only run to end of time stamp
4232 (setq rest (substring timestr (match-end 0))
4233 timestr (substring timestr 0 (match-end 0)))
4234 (if (and (not closedp) (not statep)
4235 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4236 (progn (setq timestr (concat (substring timestr 0 -1)
4237 "-" (match-string 1 rest) "]"))
4238 (setq clocked (match-string 2 rest)))
4239 (setq clocked "-")))
4240 (save-excursion
4241 (cond
4242 ((not org-agenda-log-mode-add-notes) (setq extra nil))
4243 (statep
4244 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4245 (setq extra (match-string 1))))
4246 (clockp
4247 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4248 (setq extra (match-string 1))))
4249 (t (setq extra nil)))
4250 (if (not (re-search-backward "^\\*+ " nil t))
4251 (setq txt org-agenda-no-heading-message)
4252 (goto-char (match-beginning 0))
4253 (setq hdmarker (org-agenda-new-marker)
4254 tags (org-get-tags-at))
4255 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4256 (setq txt (match-string 1))
4257 (when extra
4258 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4259 (setq txt (concat (substring txt 0 (match-beginning 1))
4260 " - " extra " " (match-string 2 txt)))
4261 (setq txt (concat txt " - " extra))))
4262 (setq txt (org-format-agenda-item
4263 (cond
4264 (closedp "Closed: ")
4265 (statep (concat "State: (" state ")"))
4266 (t (concat "Clocked: (" clocked ")")))
4267 txt category tags timestr)))
4268 (setq priority 100000)
4269 (org-add-props txt props
4270 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4271 'priority priority 'org-category category
4272 'type "closed" 'date date
4273 'undone-face 'org-warning 'done-face 'org-agenda-done)
4274 (push txt ee))
4275 (goto-char (point-at-eol))))
4276 (nreverse ee)))
4278 (defun org-agenda-get-deadlines ()
4279 "Return the deadline information for agenda display."
4280 (let* ((props (list 'mouse-face 'highlight
4281 'org-not-done-regexp org-not-done-regexp
4282 'org-todo-regexp org-todo-regexp
4283 'org-complex-heading-regexp org-complex-heading-regexp
4284 'help-echo
4285 (format "mouse-2 or RET jump to org file %s"
4286 (abbreviate-file-name buffer-file-name))))
4287 (regexp org-deadline-time-regexp)
4288 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4289 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4290 d2 diff dfrac wdays pos pos1 category tags
4291 ee txt head face s todo-state upcomingp donep timestr)
4292 (goto-char (point-min))
4293 (while (re-search-forward regexp nil t)
4294 (catch :skip
4295 (org-agenda-skip)
4296 (setq s (match-string 1)
4297 txt nil
4298 pos (1- (match-beginning 1))
4299 d2 (org-time-string-to-absolute
4300 (match-string 1) d1 'past
4301 org-agenda-repeating-timestamp-show-all)
4302 diff (- d2 d1)
4303 wdays (org-get-wdays s)
4304 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4305 upcomingp (and todayp (> diff 0)))
4306 ;; When to show a deadline in the calendar:
4307 ;; If the expiration is within wdays warning time.
4308 ;; Past-due deadlines are only shown on the current date
4309 (if (and (or (and (<= diff wdays)
4310 (and todayp (not org-agenda-only-exact-dates)))
4311 (= diff 0)))
4312 (save-excursion
4313 (setq todo-state (org-get-todo-state))
4314 (setq donep (member todo-state org-done-keywords))
4315 (if (and donep
4316 (or org-agenda-skip-deadline-if-done
4317 (not (= diff 0))))
4318 (setq txt nil)
4319 (setq category (org-get-category))
4320 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4321 (setq txt org-agenda-no-heading-message)
4322 (goto-char (match-end 0))
4323 (setq pos1 (match-beginning 0))
4324 (setq tags (org-get-tags-at pos1))
4325 (setq head (buffer-substring-no-properties
4326 (point)
4327 (progn (skip-chars-forward "^\r\n")
4328 (point))))
4329 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4330 (setq timestr
4331 (concat (substring s (match-beginning 1)) " "))
4332 (setq timestr 'time))
4333 (setq txt (org-format-agenda-item
4334 (if (= diff 0)
4335 (car org-agenda-deadline-leaders)
4336 (if (functionp
4337 (nth 1 org-agenda-deadline-leaders))
4338 (funcall
4339 (nth 1 org-agenda-deadline-leaders)
4340 diff date)
4341 (format (nth 1 org-agenda-deadline-leaders)
4342 diff)))
4343 head category tags
4344 (if (not (= diff 0)) nil timestr)))))
4345 (when txt
4346 (setq face (org-agenda-deadline-face dfrac wdays))
4347 (org-add-props txt props
4348 'org-marker (org-agenda-new-marker pos)
4349 'org-hd-marker (org-agenda-new-marker pos1)
4350 'priority (+ (- diff)
4351 (org-get-priority txt))
4352 'org-category category
4353 'todo-state todo-state
4354 'type (if upcomingp "upcoming-deadline" "deadline")
4355 'date (if upcomingp date d2)
4356 'face (if donep 'org-agenda-done face)
4357 'undone-face face 'done-face 'org-agenda-done)
4358 (push txt ee))))))
4359 (nreverse ee)))
4361 (defun org-agenda-deadline-face (fraction &optional wdays)
4362 "Return the face to displaying a deadline item.
4363 FRACTION is what fraction of the head-warning time has passed."
4364 (if (equal wdays 0) (setq fraction 1.))
4365 (let ((faces org-agenda-deadline-faces) f)
4366 (catch 'exit
4367 (while (setq f (pop faces))
4368 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4370 (defun org-agenda-get-scheduled (&optional deadline-results)
4371 "Return the scheduled information for agenda display."
4372 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4373 'org-todo-regexp org-todo-regexp
4374 'org-complex-heading-regexp org-complex-heading-regexp
4375 'done-face 'org-agenda-done
4376 'mouse-face 'highlight
4377 'help-echo
4378 (format "mouse-2 or RET jump to org file %s"
4379 (abbreviate-file-name buffer-file-name))))
4380 (regexp org-scheduled-time-regexp)
4381 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4382 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4384 (deadline-position-alist
4385 (mapcar (lambda (a) (and (setq mm (get-text-property
4386 0 'org-hd-marker a))
4387 (cons (marker-position mm) a)))
4388 deadline-results))
4389 d2 diff pos pos1 category tags donep
4390 ee txt head pastschedp todo-state face timestr s habitp)
4391 (goto-char (point-min))
4392 (while (re-search-forward regexp nil t)
4393 (catch :skip
4394 (org-agenda-skip)
4395 (setq s (match-string 1)
4396 txt nil
4397 pos (1- (match-beginning 1))
4398 d2 (org-time-string-to-absolute
4399 (match-string 1) d1 'past
4400 org-agenda-repeating-timestamp-show-all)
4401 diff (- d2 d1))
4402 (setq pastschedp (and todayp (< diff 0)))
4403 ;; When to show a scheduled item in the calendar:
4404 ;; If it is on or past the date.
4405 (when (or (and (< diff 0)
4406 (< (abs diff) org-scheduled-past-days)
4407 (and todayp (not org-agenda-only-exact-dates)))
4408 (= diff 0))
4409 (save-excursion
4410 (setq todo-state (org-get-todo-state))
4411 (setq donep (member todo-state org-done-keywords))
4412 (setq habitp (and (functionp 'org-is-habit-p)
4413 (org-is-habit-p)))
4414 (if (and donep
4415 (or habitp org-agenda-skip-scheduled-if-done
4416 (not (= diff 0))))
4417 (setq txt nil)
4418 (setq category (org-get-category))
4419 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4420 (setq txt org-agenda-no-heading-message)
4421 (goto-char (match-end 0))
4422 (setq pos1 (match-beginning 0))
4423 (if habitp
4424 (if (or (not org-habit-show-habits)
4425 (and (not todayp)
4426 org-habit-show-habits-only-for-today))
4427 (throw :skip nil))
4428 (if (and
4429 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4430 (and org-agenda-skip-scheduled-if-deadline-is-shown
4431 pastschedp))
4432 (setq mm (assoc pos1 deadline-position-alist)))
4433 (throw :skip nil)))
4434 (setq tags (org-get-tags-at))
4435 (setq head (buffer-substring-no-properties
4436 (point)
4437 (progn (skip-chars-forward "^\r\n") (point))))
4438 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4439 (setq timestr
4440 (concat (substring s (match-beginning 1)) " "))
4441 (setq timestr 'time))
4442 (setq txt (org-format-agenda-item
4443 (if (= diff 0)
4444 (car org-agenda-scheduled-leaders)
4445 (format (nth 1 org-agenda-scheduled-leaders)
4446 (- 1 diff)))
4447 head category tags
4448 (if (not (= diff 0)) nil timestr)
4449 nil nil habitp))))
4450 (when txt
4451 (setq face
4452 (cond
4453 ((and (not habitp) pastschedp)
4454 'org-scheduled-previously)
4455 (todayp 'org-scheduled-today)
4456 (t 'org-scheduled))
4457 habitp (and habitp (org-habit-parse-todo)))
4458 (org-add-props txt props
4459 'undone-face face
4460 'face (if donep 'org-agenda-done face)
4461 'org-marker (org-agenda-new-marker pos)
4462 'org-hd-marker (org-agenda-new-marker pos1)
4463 'type (if pastschedp "past-scheduled" "scheduled")
4464 'date (if pastschedp d2 date)
4465 'priority (if habitp
4466 (org-habit-get-priority habitp)
4467 (+ 94 (- 5 diff) (org-get-priority txt)))
4468 'org-category category
4469 'org-habit-p habitp
4470 'todo-state todo-state)
4471 (push txt ee))))))
4472 (nreverse ee)))
4474 (defun org-agenda-get-blocks ()
4475 "Return the date-range information for agenda display."
4476 (let* ((props (list 'face nil
4477 'org-not-done-regexp org-not-done-regexp
4478 'org-todo-regexp org-todo-regexp
4479 'org-complex-heading-regexp org-complex-heading-regexp
4480 'mouse-face 'highlight
4481 'help-echo
4482 (format "mouse-2 or RET jump to org file %s"
4483 (abbreviate-file-name buffer-file-name))))
4484 (regexp org-tr-regexp)
4485 (d0 (calendar-absolute-from-gregorian date))
4486 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4487 head donep)
4488 (goto-char (point-min))
4489 (while (re-search-forward regexp nil t)
4490 (catch :skip
4491 (org-agenda-skip)
4492 (setq pos (point))
4493 (setq timestr (match-string 0)
4494 s1 (match-string 1)
4495 s2 (match-string 2)
4496 d1 (time-to-days (org-time-string-to-time s1))
4497 d2 (time-to-days (org-time-string-to-time s2)))
4498 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4499 ;; Only allow days between the limits, because the normal
4500 ;; date stamps will catch the limits.
4501 (save-excursion
4502 (setq todo-state (org-get-todo-state))
4503 (setq donep (member todo-state org-done-keywords))
4504 (if (and donep org-agenda-skip-timestamp-if-done)
4505 (throw :skip t))
4506 (setq marker (org-agenda-new-marker (point)))
4507 (setq category (org-get-category))
4508 (if (not (re-search-backward "^\\*+ " nil t))
4509 (setq txt org-agenda-no-heading-message)
4510 (goto-char (match-beginning 0))
4511 (setq hdmarker (org-agenda-new-marker (point)))
4512 (setq tags (org-get-tags-at))
4513 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4514 (setq head (match-string 1))
4515 (setq txt (org-format-agenda-item
4516 (format
4517 (nth (if (= d1 d2) 0 1)
4518 org-agenda-timerange-leaders)
4519 (1+ (- d0 d1)) (1+ (- d2 d1)))
4520 head category tags
4521 timestr)))
4522 (org-add-props txt props
4523 'org-marker marker 'org-hd-marker hdmarker
4524 'type "block" 'date date
4525 'todo-state todo-state
4526 'priority (org-get-priority txt) 'org-category category)
4527 (push txt ee)))
4528 (goto-char pos)))
4529 ;; Sort the entries by expiration date.
4530 (nreverse ee)))
4532 ;;; Agenda presentation and sorting
4534 (defvar org-prefix-has-time nil
4535 "A flag, set by `org-compile-prefix-format'.
4536 The flag is set if the currently compiled format contains a `%t'.")
4537 (defvar org-prefix-has-tag nil
4538 "A flag, set by `org-compile-prefix-format'.
4539 The flag is set if the currently compiled format contains a `%T'.")
4540 (defvar org-prefix-has-effort nil
4541 "A flag, set by `org-compile-prefix-format'.
4542 The flag is set if the currently compiled format contains a `%e'.")
4543 (defvar org-prefix-category-length nil
4544 "Used by `org-compile-prefix-format' to remember the category field widh.")
4545 (defvar org-prefix-category-max-length nil
4546 "Used by `org-compile-prefix-format' to remember the category field widh.")
4548 (defun org-format-agenda-item (extra txt &optional category tags dotime
4549 noprefix remove-re habitp)
4550 "Format TXT to be inserted into the agenda buffer.
4551 In particular, it adds the prefix and corresponding text properties. EXTRA
4552 must be a string and replaces the `%s' specifier in the prefix format.
4553 CATEGORY (string, symbol or nil) may be used to overrule the default
4554 category taken from local variable or file name. It will replace the `%c'
4555 specifier in the format. DOTIME, when non-nil, indicates that a
4556 time-of-day should be extracted from TXT for sorting of this entry, and for
4557 the `%t' specifier in the format. When DOTIME is a string, this string is
4558 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4559 only the correctly processes TXT should be returned - this is used by
4560 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4561 Any match of REMOVE-RE will be removed from TXT."
4562 (save-match-data
4563 ;; Diary entries sometimes have extra whitespace at the beginning
4564 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4566 ;; Fix the tags part in txt
4567 (setq txt (org-agenda-fix-displayed-tags
4568 txt tags
4569 org-agenda-show-inherited-tags
4570 org-agenda-hide-tags-regexp))
4571 (let* ((category (or category
4572 org-category
4573 (if buffer-file-name
4574 (file-name-sans-extension
4575 (file-name-nondirectory buffer-file-name))
4576 "")))
4577 ;; time, tag, effort are needed for the eval of the prefix format
4578 (tag (if tags (nth (1- (length tags)) tags) ""))
4579 time effort neffort
4580 (ts (if dotime (concat
4581 (if (stringp dotime) dotime "")
4582 (and org-agenda-search-headline-for-time txt))))
4583 (time-of-day (and dotime (org-get-time-of-day ts)))
4584 stamp plain s0 s1 s2 t1 t2 rtn srp l
4585 duration thecategory)
4586 (and (org-mode-p) buffer-file-name
4587 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4588 (when (and dotime time-of-day)
4589 ;; Extract starting and ending time and move them to prefix
4590 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4591 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4592 (setq s0 (match-string 0 ts)
4593 srp (and stamp (match-end 3))
4594 s1 (match-string (if plain 1 2) ts)
4595 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4597 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4598 ;; them, we might want to remove them there to avoid duplication.
4599 ;; The user can turn this off with a variable.
4600 (if (and org-prefix-has-time
4601 org-agenda-remove-times-when-in-prefix (or stamp plain)
4602 (string-match (concat (regexp-quote s0) " *") txt)
4603 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4604 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4605 (= (match-beginning 0) 0)
4607 (setq txt (replace-match "" nil nil txt))))
4608 ;; Normalize the time(s) to 24 hour
4609 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4610 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4611 ;; Compute the duration
4612 (when s1
4613 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4614 (string-to-number (substring s1 3)))
4615 t2 (cond
4616 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4617 (string-to-number (substring s2 3))))
4618 (org-agenda-default-appointment-duration
4619 (+ t1 org-agenda-default-appointment-duration))
4620 (t nil)))
4621 (setq duration (if t2 (- t2 t1)))))
4623 (when (and s1 (not s2) org-agenda-default-appointment-duration
4624 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4625 (let ((m (+ (string-to-number (match-string 2 s1))
4626 (* 60 (string-to-number (match-string 1 s1)))
4627 org-agenda-default-appointment-duration))
4629 (setq h (/ m 60) m (- m (* h 60)))
4630 (setq s2 (format "%02d:%02d" h m))))
4632 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4633 txt)
4634 ;; Tags are in the string
4635 (if (or (eq org-agenda-remove-tags t)
4636 (and org-agenda-remove-tags
4637 org-prefix-has-tag))
4638 (setq txt (replace-match "" t t txt))
4639 (setq txt (replace-match
4640 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
4641 (match-string 2 txt))
4642 t t txt))))
4643 (when (org-mode-p)
4644 (setq effort
4645 (condition-case nil
4646 (org-get-effort
4647 (or (get-text-property 0 'org-hd-marker txt)
4648 (get-text-property 0 'org-marker txt)))
4649 (error nil)))
4650 (when effort
4651 (setq neffort (org-hh:mm-string-to-minutes effort)
4652 effort (setq effort (concat "[" effort "]" )))))
4654 (when remove-re
4655 (while (string-match remove-re txt)
4656 (setq txt (replace-match "" t t txt))))
4658 ;; Create the final string
4659 (if noprefix
4660 (setq rtn txt)
4661 ;; Prepare the variables needed in the eval of the compiled format
4662 (setq time (cond (s2 (concat s1 "-" s2))
4663 (s1 (concat s1 "......"))
4664 (t ""))
4665 extra (or (and (not habitp) extra) "")
4666 category (if (symbolp category) (symbol-name category) category)
4667 thecategory (copy-sequence category))
4668 (if (string-match org-bracket-link-regexp category)
4669 (progn
4670 (setq l (if (match-end 3)
4671 (- (match-end 3) (match-beginning 3))
4672 (- (match-end 1) (match-beginning 1))))
4673 (when (< l (or org-prefix-category-length 0))
4674 (setq category (copy-sequence category))
4675 (org-add-props category nil
4676 'extra-space (make-string
4677 (- org-prefix-category-length l 1) ?\ ))))
4678 (if (and org-prefix-category-max-length
4679 (>= (length category) org-prefix-category-max-length))
4680 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
4681 ;; Evaluate the compiled format
4682 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
4684 ;; And finally add the text properties
4685 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
4686 (org-add-props rtn nil
4687 'org-category (if thecategory (downcase thecategory) category)
4688 'tags (mapcar 'org-downcase-keep-props tags)
4689 'org-highest-priority org-highest-priority
4690 'org-lowest-priority org-lowest-priority
4691 'prefix-length (- (length rtn) (length txt))
4692 'time-of-day time-of-day
4693 'duration duration
4694 'effort effort
4695 'effort-minutes neffort
4696 'txt txt
4697 'time time
4698 'extra extra
4699 'dotime dotime))))
4701 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
4702 "Remove tags string from TXT, and add a modified list of tags.
4703 The modified list may contain inherited tags, and tags matched by
4704 `org-agenda-hide-tags-regexp' will be removed."
4705 (when (or add-inherited hide-re)
4706 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
4707 (setq txt (substring txt 0 (match-beginning 0))))
4708 (when tags
4709 (setq tags
4710 (delq nil
4711 (mapcar (lambda (tg)
4712 (if (or (and hide-re (string-match hide-re tg))
4713 (and (not add-inherited)
4714 (get-text-property 0 'inherited tg)))
4716 tg))
4717 tags)))
4718 (let ((have-i (get-text-property 0 'inherited (car tags)))
4720 (setq txt (concat txt " :"
4721 (mapconcat
4722 (lambda (x)
4723 (setq i (get-text-property 0 'inherited x))
4724 (if (and have-i (not i))
4725 (progn
4726 (setq have-i nil)
4727 (concat ":" x))
4729 tags ":")
4730 (if have-i "::" ":"))))))
4731 txt)
4733 (defun org-downcase-keep-props (s)
4734 (let ((props (text-properties-at 0 s)))
4735 (setq s (downcase s))
4736 (add-text-properties 0 (length s) props s)
4739 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
4740 (defvar org-agenda-sorting-strategy-selected nil)
4742 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
4743 (catch 'exit
4744 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
4745 ((and todayp (member 'today (car org-agenda-time-grid))))
4746 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
4747 ((member 'weekly (car org-agenda-time-grid)))
4748 (t (throw 'exit list)))
4749 (let* ((have (delq nil (mapcar
4750 (lambda (x) (get-text-property 1 'time-of-day x))
4751 list)))
4752 (string (nth 1 org-agenda-time-grid))
4753 (gridtimes (nth 2 org-agenda-time-grid))
4754 (req (car org-agenda-time-grid))
4755 (remove (member 'remove-match req))
4756 new time)
4757 (if (and (member 'require-timed req) (not have))
4758 ;; don't show empty grid
4759 (throw 'exit list))
4760 (while (setq time (pop gridtimes))
4761 (unless (and remove (member time have))
4762 (setq time (int-to-string time))
4763 (push (org-format-agenda-item
4764 nil string "" nil
4765 (concat (substring time 0 -2) ":" (substring time -2)))
4766 new)
4767 (put-text-property
4768 1 (length (car new)) 'face 'org-time-grid (car new))))
4769 (if (member 'time-up org-agenda-sorting-strategy-selected)
4770 (append new list)
4771 (append list new)))))
4773 (defun org-compile-prefix-format (key)
4774 "Compile the prefix format into a Lisp form that can be evaluated.
4775 The resulting form is returned and stored in the variable
4776 `org-prefix-format-compiled'."
4777 (setq org-prefix-has-time nil org-prefix-has-tag nil
4778 org-prefix-category-length nil org-prefix-has-effort nil)
4779 (let ((s (cond
4780 ((stringp org-agenda-prefix-format)
4781 org-agenda-prefix-format)
4782 ((assq key org-agenda-prefix-format)
4783 (cdr (assq key org-agenda-prefix-format)))
4784 (t " %-12:c%?-12t% s")))
4785 (start 0)
4786 varform vars var e c f opt)
4787 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4788 s start)
4789 (setq var (cdr (assoc (match-string 4 s)
4790 '(("c" . category) ("t" . time) ("s" . extra)
4791 ("T" . tag) ("e" . effort))))
4792 c (or (match-string 3 s) "")
4793 opt (match-beginning 1)
4794 start (1+ (match-beginning 0)))
4795 (if (equal var 'time) (setq org-prefix-has-time t))
4796 (if (equal var 'tag) (setq org-prefix-has-tag t))
4797 (if (equal var 'effort) (setq org-prefix-has-effort t))
4798 (setq f (concat "%" (match-string 2 s) "s"))
4799 (when (equal var 'category)
4800 (setq org-prefix-category-length
4801 (floor (abs (string-to-number (match-string 2 s)))))
4802 (setq org-prefix-category-max-length
4803 (let ((x (match-string 2 s)))
4804 (save-match-data
4805 (if (string-match "\\.[0-9]+" x)
4806 (string-to-number (substring (match-string 0 x) 1)))))))
4807 (if opt
4808 (setq varform
4809 `(if (equal "" ,var)
4811 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
4812 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
4813 (setq s (replace-match "%s" t nil s))
4814 (push varform vars))
4815 (setq vars (nreverse vars))
4816 (setq org-prefix-format-compiled `(format ,s ,@vars))))
4818 (defun org-set-sorting-strategy (key)
4819 (if (symbolp (car org-agenda-sorting-strategy))
4820 ;; the old format
4821 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
4822 (setq org-agenda-sorting-strategy-selected
4823 (or (cdr (assq key org-agenda-sorting-strategy))
4824 (cdr (assq 'agenda org-agenda-sorting-strategy))
4825 '(time-up category-keep priority-down)))))
4827 (defun org-get-time-of-day (s &optional string mod24)
4828 "Check string S for a time of day.
4829 If found, return it as a military time number between 0 and 2400.
4830 If not found, return nil.
4831 The optional STRING argument forces conversion into a 5 character wide string
4832 HH:MM."
4833 (save-match-data
4834 (when
4835 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
4836 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
4837 (let* ((h (string-to-number (match-string 1 s)))
4838 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
4839 (ampm (if (match-end 4) (downcase (match-string 4 s))))
4840 (am-p (equal ampm "am"))
4841 (h1 (cond ((not ampm) h)
4842 ((= h 12) (if am-p 0 12))
4843 (t (+ h (if am-p 0 12)))))
4844 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
4845 (mod h1 24) h1))
4846 (t0 (+ (* 100 h2) m))
4847 (t1 (concat (if (>= h1 24) "+" " ")
4848 (if (< t0 100) "0" "")
4849 (if (< t0 10) "0" "")
4850 (int-to-string t0))))
4851 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
4853 (defun org-finalize-agenda-entries (list &optional nosort)
4854 "Sort and concatenate the agenda items."
4855 (setq list (mapcar 'org-agenda-highlight-todo list))
4856 (if nosort
4857 list
4858 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
4860 (defun org-agenda-highlight-todo (x)
4861 (let ((org-done-keywords org-done-keywords-for-agenda)
4862 (case-fold-search nil)
4863 re pl)
4864 (if (eq x 'line)
4865 (save-excursion
4866 (beginning-of-line 1)
4867 (setq re (org-get-at-bol 'org-todo-regexp))
4868 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
4869 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
4870 (add-text-properties (match-beginning 0) (match-end 1)
4871 (list 'face (org-get-todo-face 1)))
4872 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4873 (delete-region (match-beginning 1) (1- (match-end 0)))
4874 (goto-char (match-beginning 1))
4875 (insert (format org-agenda-todo-keyword-format s)))))
4876 (setq re (concat (get-text-property 0 'org-todo-regexp x))
4877 pl (get-text-property 0 'prefix-length x))
4878 (when (and re
4879 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
4880 x (or pl 0)) pl))
4881 (add-text-properties
4882 (or (match-end 1) (match-end 0)) (match-end 0)
4883 (list 'face (org-get-todo-face (match-string 2 x)))
4885 (setq x (concat (substring x 0 (match-end 1))
4886 (format org-agenda-todo-keyword-format
4887 (match-string 2 x))
4888 (org-add-props " " (text-properties-at 0 x))
4889 (substring x (match-end 3)))))
4890 x)))
4892 (defsubst org-cmp-priority (a b)
4893 "Compare the priorities of string A and B."
4894 (let ((pa (or (get-text-property 1 'priority a) 0))
4895 (pb (or (get-text-property 1 'priority b) 0)))
4896 (cond ((> pa pb) +1)
4897 ((< pa pb) -1)
4898 (t nil))))
4900 (defsubst org-cmp-effort (a b)
4901 "Compare the priorities of string A and B."
4902 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
4903 (ea (or (get-text-property 1 'effort-minutes a) def))
4904 (eb (or (get-text-property 1 'effort-minutes b) def)))
4905 (cond ((> ea eb) +1)
4906 ((< ea eb) -1)
4907 (t nil))))
4909 (defsubst org-cmp-category (a b)
4910 "Compare the string values of categories of strings A and B."
4911 (let ((ca (or (get-text-property 1 'org-category a) ""))
4912 (cb (or (get-text-property 1 'org-category b) "")))
4913 (cond ((string-lessp ca cb) -1)
4914 ((string-lessp cb ca) +1)
4915 (t nil))))
4917 (defsubst org-cmp-todo-state (a b)
4918 "Compare the todo states of strings A and B."
4919 (let* ((ma (or (get-text-property 1 'org-marker a)
4920 (get-text-property 1 'org-hd-marker a)))
4921 (mb (or (get-text-property 1 'org-marker b)
4922 (get-text-property 1 'org-hd-marker b)))
4923 (fa (and ma (marker-buffer ma)))
4924 (fb (and mb (marker-buffer mb)))
4925 (todo-kwds
4926 (or (and fa (with-current-buffer fa org-todo-keywords-1))
4927 (and fb (with-current-buffer fb org-todo-keywords-1))))
4928 (ta (or (get-text-property 1 'todo-state a) ""))
4929 (tb (or (get-text-property 1 'todo-state b) ""))
4930 (la (- (length (member ta todo-kwds))))
4931 (lb (- (length (member tb todo-kwds))))
4932 (donepa (member ta org-done-keywords-for-agenda))
4933 (donepb (member tb org-done-keywords-for-agenda)))
4934 (cond ((and donepa (not donepb)) -1)
4935 ((and (not donepa) donepb) +1)
4936 ((< la lb) -1)
4937 ((< lb la) +1)
4938 (t nil))))
4940 (defsubst org-cmp-tag (a b)
4941 "Compare the string values of the first tags of A and B."
4942 (let ((ta (car (last (get-text-property 1 'tags a))))
4943 (tb (car (last (get-text-property 1 'tags b)))))
4944 (cond ((not ta) +1)
4945 ((not tb) -1)
4946 ((string-lessp ta tb) -1)
4947 ((string-lessp tb ta) +1)
4948 (t nil))))
4950 (defsubst org-cmp-time (a b)
4951 "Compare the time-of-day values of strings A and B."
4952 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
4953 (ta (or (get-text-property 1 'time-of-day a) def))
4954 (tb (or (get-text-property 1 'time-of-day b) def)))
4955 (cond ((< ta tb) -1)
4956 ((< tb ta) +1)
4957 (t nil))))
4959 (defsubst org-cmp-habit-p (a b)
4960 "Compare the todo states of strings A and B."
4961 (let ((ha (get-text-property 1 'org-habit-p a))
4962 (hb (get-text-property 1 'org-habit-p b)))
4963 (cond ((and ha (not hb)) -1)
4964 ((and (not ha) hb) +1)
4965 (t nil))))
4967 (defun org-entries-lessp (a b)
4968 "Predicate for sorting agenda entries."
4969 ;; The following variables will be used when the form is evaluated.
4970 ;; So even though the compiler complains, keep them.
4971 (let* ((time-up (org-cmp-time a b))
4972 (time-down (if time-up (- time-up) nil))
4973 (priority-up (org-cmp-priority a b))
4974 (priority-down (if priority-up (- priority-up) nil))
4975 (effort-up (org-cmp-effort a b))
4976 (effort-down (if effort-up (- effort-up) nil))
4977 (category-up (org-cmp-category a b))
4978 (category-down (if category-up (- category-up) nil))
4979 (category-keep (if category-up +1 nil))
4980 (tag-up (org-cmp-tag a b))
4981 (tag-down (if tag-up (- tag-up) nil))
4982 (todo-state-up (org-cmp-todo-state a b))
4983 (todo-state-down (if todo-state-up (- todo-state-up) nil))
4984 (habit-up (org-cmp-habit-p a b))
4985 (habit-down (if habit-up (- habit-up) nil))
4986 user-defined-up user-defined-down)
4987 (if (and org-agenda-cmp-user-defined
4988 (functionp org-agenda-cmp-user-defined))
4989 (setq user-defined-up
4990 (funcall org-agenda-cmp-user-defined a b)
4991 user-defined-down (if user-defined-up (- user-defined-up) nil)))
4992 (cdr (assoc
4993 (eval (cons 'or org-agenda-sorting-strategy-selected))
4994 '((-1 . t) (1 . nil) (nil . nil))))))
4996 ;;; Agenda restriction lock
4998 (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
4999 "Overlay to mark the headline to which agenda commands are restricted.")
5000 (org-overlay-put org-agenda-restriction-lock-overlay
5001 'face 'org-agenda-restriction-lock)
5002 (org-overlay-put org-agenda-restriction-lock-overlay
5003 'help-echo "Agendas are currently limited to this subtree.")
5004 (org-detach-overlay org-agenda-restriction-lock-overlay)
5006 (defun org-agenda-set-restriction-lock (&optional type)
5007 "Set restriction lock for agenda, to current subtree or file.
5008 Restriction will be the file if TYPE is `file', or if type is the
5009 universal prefix '(4), or if the cursor is before the first headline
5010 in the file. Otherwise, restriction will be to the current subtree."
5011 (interactive "P")
5012 (and (equal type '(4)) (setq type 'file))
5013 (setq type (cond
5014 (type type)
5015 ((org-at-heading-p) 'subtree)
5016 ((condition-case nil (org-back-to-heading t) (error nil))
5017 'subtree)
5018 (t 'file)))
5019 (if (eq type 'subtree)
5020 (progn
5021 (setq org-agenda-restrict t)
5022 (setq org-agenda-overriding-restriction 'subtree)
5023 (put 'org-agenda-files 'org-restrict
5024 (list (buffer-file-name (buffer-base-buffer))))
5025 (org-back-to-heading t)
5026 (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5027 (move-marker org-agenda-restrict-begin (point))
5028 (move-marker org-agenda-restrict-end
5029 (save-excursion (org-end-of-subtree t)))
5030 (message "Locking agenda restriction to subtree"))
5031 (put 'org-agenda-files 'org-restrict
5032 (list (buffer-file-name (buffer-base-buffer))))
5033 (setq org-agenda-restrict nil)
5034 (setq org-agenda-overriding-restriction 'file)
5035 (move-marker org-agenda-restrict-begin nil)
5036 (move-marker org-agenda-restrict-end nil)
5037 (message "Locking agenda restriction to file"))
5038 (setq current-prefix-arg nil)
5039 (org-agenda-maybe-redo))
5041 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5042 "Remove the agenda restriction lock."
5043 (interactive "P")
5044 (org-detach-overlay org-agenda-restriction-lock-overlay)
5045 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5046 (setq org-agenda-overriding-restriction nil)
5047 (setq org-agenda-restrict nil)
5048 (put 'org-agenda-files 'org-restrict nil)
5049 (move-marker org-agenda-restrict-begin nil)
5050 (move-marker org-agenda-restrict-end nil)
5051 (setq current-prefix-arg nil)
5052 (message "Agenda restriction lock removed")
5053 (or noupdate (org-agenda-maybe-redo)))
5055 (defun org-agenda-maybe-redo ()
5056 "If there is any window showing the agenda view, update it."
5057 (let ((w (get-buffer-window org-agenda-buffer-name t))
5058 (w0 (selected-window)))
5059 (when w
5060 (select-window w)
5061 (org-agenda-redo)
5062 (select-window w0)
5063 (if org-agenda-overriding-restriction
5064 (message "Agenda view shifted to new %s restriction"
5065 org-agenda-overriding-restriction)
5066 (message "Agenda restriction lock removed")))))
5068 ;;; Agenda commands
5070 (defun org-agenda-check-type (error &rest types)
5071 "Check if agenda buffer is of allowed type.
5072 If ERROR is non-nil, throw an error, otherwise just return nil."
5073 (if (memq org-agenda-type types)
5075 (if error
5076 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5077 nil)))
5079 (defun org-agenda-quit ()
5080 "Exit agenda by removing the window or the buffer."
5081 (interactive)
5082 (if org-agenda-columns-active
5083 (org-columns-quit)
5084 (let ((buf (current-buffer)))
5085 (if (eq org-agenda-window-setup 'other-frame)
5086 (progn
5087 (kill-buffer buf)
5088 (org-agenda-reset-markers)
5089 (org-columns-remove-overlays)
5090 (setq org-agenda-archives-mode nil)
5091 (delete-frame))
5092 (and (not (eq org-agenda-window-setup 'current-window))
5093 (not (one-window-p))
5094 (delete-window))
5095 (kill-buffer buf)
5096 (org-agenda-reset-markers)
5097 (org-columns-remove-overlays)
5098 (setq org-agenda-archives-mode nil)))
5099 ;; Maybe restore the pre-agenda window configuration.
5100 (and org-agenda-restore-windows-after-quit
5101 (not (eq org-agenda-window-setup 'other-frame))
5102 org-pre-agenda-window-conf
5103 (set-window-configuration org-pre-agenda-window-conf))))
5105 (defun org-agenda-exit ()
5106 "Exit agenda by removing the window or the buffer.
5107 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5108 Org-mode buffers visited directly by the user will not be touched."
5109 (interactive)
5110 (org-release-buffers org-agenda-new-buffers)
5111 (setq org-agenda-new-buffers nil)
5112 (org-agenda-quit))
5114 (defun org-agenda-execute (arg)
5115 "Execute another agenda command, keeping same window.\\<global-map>
5116 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
5117 (interactive "P")
5118 (let ((org-agenda-window-setup 'current-window))
5119 (org-agenda arg)))
5121 (defun org-agenda-redo ()
5122 "Rebuild Agenda.
5123 When this is the global TODO list, a prefix argument will be interpreted."
5124 (interactive)
5125 (let* ((org-agenda-keep-modes t)
5126 (filter org-agenda-filter)
5127 (preset (get 'org-agenda-filter :preset-filter))
5128 (cols org-agenda-columns-active)
5129 (line (org-current-line))
5130 (window-line (- line (org-current-line (window-start))))
5131 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5132 (put 'org-agenda-filter :preset-filter nil)
5133 (and cols (org-columns-quit))
5134 (message "Rebuilding agenda buffer...")
5135 (org-let lprops '(eval org-agenda-redo-command))
5136 (setq org-agenda-undo-list nil
5137 org-agenda-pending-undo-list nil)
5138 (message "Rebuilding agenda buffer...done")
5139 (put 'org-agenda-filter :preset-filter preset)
5140 (and (or filter preset) (org-agenda-filter-apply filter))
5141 (and cols (interactive-p) (org-agenda-columns))
5142 (org-goto-line line)
5143 (recenter window-line)))
5146 (defvar org-global-tags-completion-table nil)
5147 (defvar org-agenda-filter-form nil)
5148 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5149 "Keep only those lines in the agenda buffer that have a specific tag.
5150 The tag is selected with its fast selection letter, as configured.
5151 With prefix argument STRIP, remove all lines that do have the tag.
5152 A lisp caller can specify CHAR. NARROW means that the new tag should be
5153 used to narrow the search - the interactive user can also press `-' or `+'
5154 to switch to narrowing."
5155 (interactive "P")
5156 (let* ((alist org-tag-alist-for-agenda)
5157 (tag-chars (mapconcat
5158 (lambda (x) (if (and (not (symbolp (car x)))
5159 (cdr x))
5160 (char-to-string (cdr x))
5161 ""))
5162 alist ""))
5163 (efforts (org-split-string
5164 (or (cdr (assoc (concat org-effort-property "_ALL")
5165 org-global-properties))
5166 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5167 (effort-op org-agenda-filter-effort-default-operator)
5168 (effort-prompt "")
5169 (inhibit-read-only t)
5170 (current org-agenda-filter)
5171 a n tag)
5172 (unless char
5173 (message
5174 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5175 (if narrow "Narrow" "Filter") tag-chars
5176 (if org-agenda-auto-exclude-function "[RET], " ""))
5177 (setq char (read-char)))
5178 (when (member char '(?+ ?-))
5179 ;; Narrowing down
5180 (cond ((equal char ?-) (setq strip t narrow t))
5181 ((equal char ?+) (setq strip nil narrow t)))
5182 (message
5183 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5184 (setq char (read-char)))
5185 (when (member char '(?< ?> ?= ??))
5186 ;; An effort operator
5187 (setq effort-op (char-to-string char))
5188 (setq alist nil) ; to make sure it will be interpreted as effort.
5189 (unless (equal char ??)
5190 (loop for i from 0 to 9 do
5191 (setq effort-prompt
5192 (concat
5193 effort-prompt " ["
5194 (if (= i 9) "0" (int-to-string (1+ i)))
5195 "]" (nth i efforts))))
5196 (message "Effort%s: %s " effort-op effort-prompt)
5197 (setq char (read-char))
5198 (when (or (< char ?0) (> char ?9))
5199 (error "Need 1-9,0 to select effort" ))))
5200 (when (equal char ?\t)
5201 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5202 (org-set-local 'org-global-tags-completion-table
5203 (org-global-tags-completion-table)))
5204 (let ((completion-ignore-case t))
5205 (setq tag (org-icompleting-read
5206 "Tag: " org-global-tags-completion-table))))
5207 (cond
5208 ((equal char ?\r)
5209 (org-agenda-filter-by-tag-show-all)
5210 (when org-agenda-auto-exclude-function
5211 (setq org-agenda-filter '())
5212 (dolist (tag (org-agenda-get-represented-tags))
5213 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5214 (if modifier
5215 (push modifier org-agenda-filter))))
5216 (if (not (null org-agenda-filter))
5217 (org-agenda-filter-apply org-agenda-filter))))
5218 ((equal char ?/)
5219 (org-agenda-filter-by-tag-show-all)
5220 (when (get 'org-agenda-filter :preset-filter)
5221 (org-agenda-filter-apply org-agenda-filter)))
5222 ((or (equal char ?\ )
5223 (setq a (rassoc char alist))
5224 (and (>= char ?0) (<= char ?9)
5225 (setq n (if (= char ?0) 9 (- char ?0 1))
5226 tag (concat effort-op (nth n efforts))
5227 a (cons tag nil)))
5228 (and (= char ??)
5229 (setq tag "?eff")
5230 a (cons tag nil))
5231 (and tag (setq a (cons tag nil))))
5232 (org-agenda-filter-by-tag-show-all)
5233 (setq tag (car a))
5234 (setq org-agenda-filter
5235 (cons (concat (if strip "-" "+") tag)
5236 (if narrow current nil)))
5237 (org-agenda-filter-apply org-agenda-filter))
5238 (t (error "Invalid tag selection character %c" char)))))
5240 (defun org-agenda-get-represented-tags ()
5241 "Get a list of all tags currently represented in the agenda."
5242 (let (p tags)
5243 (save-excursion
5244 (goto-char (point-min))
5245 (while (setq p (next-single-property-change (point) 'tags))
5246 (goto-char p)
5247 (mapc (lambda (x) (add-to-list 'tags x))
5248 (get-text-property (point) 'tags))))
5249 tags))
5251 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5252 "Refine the current filter. See `org-agenda-filter-by-tag."
5253 (interactive "P")
5254 (org-agenda-filter-by-tag strip char 'refine))
5256 (defun org-agenda-filter-make-matcher ()
5257 "Create the form that tests a line for the agenda filter."
5258 (let (f f1)
5259 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5260 org-agenda-filter))
5261 (if (member x '("-" "+"))
5262 (setq f1 (if (equal x "-") 'tags '(not tags)))
5263 (if (string-match "[<=>?]" x)
5264 (setq f1 (org-agenda-filter-effort-form x))
5265 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5266 (if (equal (string-to-char x) ?-)
5267 (setq f1 (list 'not f1))))
5268 (push f1 f))
5269 (cons 'and (nreverse f))))
5271 (defun org-agenda-filter-effort-form (e)
5272 "Return the form to compare the effort of the current line with what E says.
5273 E looks line \"+<2:25\"."
5274 (let (op)
5275 (setq e (substring e 1))
5276 (setq op (string-to-char e) e (substring e 1))
5277 (setq op (cond ((equal op ?<) '<=)
5278 ((equal op ?>) '>=)
5279 ((equal op ??) op)
5280 (t '=)))
5281 (list 'org-agenda-compare-effort (list 'quote op)
5282 (org-hh:mm-string-to-minutes e))))
5284 (defun org-agenda-compare-effort (op value)
5285 "Compare the effort of the current line with VALUE, using OP.
5286 If the line does not have an effort defined, return nil."
5287 (let ((eff (org-get-at-bol 'effort-minutes)))
5288 (if (equal op ??)
5289 (not eff)
5290 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5291 value))))
5293 (defun org-agenda-filter-apply (filter)
5294 "Set FILTER as the new agenda filter and apply it."
5295 (let (tags)
5296 (setq org-agenda-filter filter
5297 org-agenda-filter-form (org-agenda-filter-make-matcher))
5298 (org-agenda-set-mode-name)
5299 (save-excursion
5300 (goto-char (point-min))
5301 (while (not (eobp))
5302 (if (org-get-at-bol 'org-marker)
5303 (progn
5304 (setq tags (org-get-at-bol 'tags)) ; used in eval
5305 (if (not (eval org-agenda-filter-form))
5306 (org-agenda-filter-by-tag-hide-line))
5307 (beginning-of-line 2))
5308 (beginning-of-line 2))))))
5310 (defun org-agenda-filter-by-tag-hide-line ()
5311 (let (ov)
5312 (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
5313 (point-at-eol)))
5314 (org-overlay-put ov 'invisible t)
5315 (org-overlay-put ov 'type 'tags-filter)
5316 (push ov org-agenda-filter-overlays)))
5318 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5319 (setq pos (or pos (point)))
5320 (save-excursion
5321 (dolist (ov (org-overlays-at pos))
5322 (when (and (org-overlay-get ov 'invisible)
5323 (eq (org-overlay-get ov 'type) 'tags-filter))
5324 (goto-char pos)
5325 (if (< (org-overlay-start ov) (point-at-eol))
5326 (org-move-overlay ov (point-at-eol)
5327 (org-overlay-end ov)))))))
5329 (defun org-agenda-filter-by-tag-show-all ()
5330 (mapc 'org-delete-overlay org-agenda-filter-overlays)
5331 (setq org-agenda-filter-overlays nil)
5332 (setq org-agenda-filter nil)
5333 (setq org-agenda-filter-form nil)
5334 (org-agenda-set-mode-name))
5336 (defun org-agenda-manipulate-query-add ()
5337 "Manipulate the query by adding a search term with positive selection.
5338 Positive selection means, the term must be matched for selection of an entry."
5339 (interactive)
5340 (org-agenda-manipulate-query ?\[))
5341 (defun org-agenda-manipulate-query-subtract ()
5342 "Manipulate the query by adding a search term with negative selection.
5343 Negative selection means, term must not be matched for selection of an entry."
5344 (interactive)
5345 (org-agenda-manipulate-query ?\]))
5346 (defun org-agenda-manipulate-query-add-re ()
5347 "Manipulate the query by adding a search regexp with positive selection.
5348 Positive selection means, the regexp must match for selection of an entry."
5349 (interactive)
5350 (org-agenda-manipulate-query ?\{))
5351 (defun org-agenda-manipulate-query-subtract-re ()
5352 "Manipulate the query by adding a search regexp with negative selection.
5353 Negative selection means, regexp must not match for selection of an entry."
5354 (interactive)
5355 (org-agenda-manipulate-query ?\}))
5356 (defun org-agenda-manipulate-query (char)
5357 (cond
5358 ((memq org-agenda-type '(timeline agenda))
5359 (let ((org-agenda-include-inactive-timestamps t))
5360 (org-agenda-redo))
5361 (message "Display now includes inactive timestamps as well"))
5362 ((eq org-agenda-type 'search)
5363 (org-add-to-string
5364 'org-agenda-query-string
5365 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5366 (?\{ . " +{}") (?\} . " -{}")))))
5367 (setq org-agenda-redo-command
5368 (list 'org-search-view
5369 org-todo-only
5370 org-agenda-query-string
5371 (+ (length org-agenda-query-string)
5372 (if (member char '(?\{ ?\})) 0 1))))
5373 (set-register org-agenda-query-register org-agenda-query-string)
5374 (org-agenda-redo))
5375 (t (error "Cannot manipulate query for %s-type agenda buffers"
5376 org-agenda-type))))
5378 (defun org-add-to-string (var string)
5379 (set var (concat (symbol-value var) string)))
5381 (defun org-agenda-goto-date (date)
5382 "Jump to DATE in agenda."
5383 (interactive (list (org-read-date)))
5384 (org-agenda-list nil date))
5386 (defun org-agenda-goto-today ()
5387 "Go to today."
5388 (interactive)
5389 (org-agenda-check-type t 'timeline 'agenda)
5390 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5391 (cond
5392 (tdpos (goto-char tdpos))
5393 ((eq org-agenda-type 'agenda)
5394 (let* ((sd (time-to-days
5395 (time-subtract (current-time)
5396 (list 0 (* 3600 org-extend-today-until) 0))))
5397 (comp (org-agenda-compute-time-span sd org-agenda-span))
5398 (org-agenda-overriding-arguments org-agenda-last-arguments))
5399 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5400 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5401 (org-agenda-redo)
5402 (org-agenda-find-same-or-today-or-agenda)))
5403 (t (error "Cannot find today")))))
5405 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5406 (goto-char
5407 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5408 (text-property-any (point-min) (point-max) 'org-today t)
5409 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5410 (point-min))))
5412 (defun org-agenda-later (arg)
5413 "Go forward in time by thee current span.
5414 With prefix ARG, go forward that many times the current span."
5415 (interactive "p")
5416 (org-agenda-check-type t 'agenda)
5417 (let* ((span org-agenda-span)
5418 (sd org-starting-day)
5419 (greg (calendar-gregorian-from-absolute sd))
5420 (cnt (org-get-at-bol 'org-day-cnt))
5421 greg2 nd)
5422 (cond
5423 ((eq span 'day)
5424 (setq sd (+ arg sd) nd 1))
5425 ((eq span 'week)
5426 (setq sd (+ (* 7 arg) sd) nd 7))
5427 ((eq span 'month)
5428 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5429 sd (calendar-absolute-from-gregorian greg2))
5430 (setcar greg2 (1+ (car greg2)))
5431 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5432 ((eq span 'year)
5433 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5434 sd (calendar-absolute-from-gregorian greg2))
5435 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5436 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5437 (let ((org-agenda-overriding-arguments
5438 (list (car org-agenda-last-arguments) sd nd t)))
5439 (org-agenda-redo)
5440 (org-agenda-find-same-or-today-or-agenda cnt))))
5442 (defun org-agenda-earlier (arg)
5443 "Go backward in time by the current span.
5444 With prefix ARG, go backward that many times the current span."
5445 (interactive "p")
5446 (org-agenda-later (- arg)))
5448 (defun org-agenda-view-mode-dispatch ()
5449 "Call one of the view mode commands."
5450 (interactive)
5451 (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
5452 clock[R]eport time[G]rid [[]inactive [E]ntryText include[D]iary")
5453 (let ((a (read-char-exclusive)))
5454 (case a
5455 (?d (call-interactively 'org-agenda-day-view))
5456 (?w (call-interactively 'org-agenda-week-view))
5457 (?m (call-interactively 'org-agenda-month-view))
5458 (?y (call-interactively 'org-agenda-year-view))
5459 (?l (call-interactively 'org-agenda-log-mode))
5460 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5461 (?a (call-interactively 'org-agenda-archives-mode))
5462 (?A (org-agenda-archives-mode 'files))
5463 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5464 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5465 (?G (call-interactively 'org-agenda-toggle-time-grid))
5466 (?D (call-interactively 'org-agenda-toggle-diary))
5467 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5468 (org-agenda-check-type t 'timeline 'agenda)
5469 (org-agenda-redo))
5470 (message "Display now includes inactive timestamps as well"))
5471 (?q (message "Abort"))
5472 (otherwise (error "Invalid key" )))))
5474 (defun org-agenda-day-view (&optional day-of-year)
5475 "Switch to daily view for agenda.
5476 With argument DAY-OF-YEAR, switch to that day of the year."
5477 (interactive "P")
5478 (setq org-agenda-ndays 1)
5479 (org-agenda-change-time-span 'day day-of-year))
5480 (defun org-agenda-week-view (&optional iso-week)
5481 "Switch to daily view for agenda.
5482 With argument ISO-WEEK, switch to the corresponding ISO week.
5483 If ISO-WEEK has more then 2 digits, only the last two encode the
5484 week. Any digits before this encode a year. So 200712 means
5485 week 12 of year 2007. Years in the range 1938-2037 can also be
5486 written as 2-digit years."
5487 (interactive "P")
5488 (setq org-agenda-ndays 7)
5489 (org-agenda-change-time-span 'week iso-week))
5490 (defun org-agenda-month-view (&optional month)
5491 "Switch to monthly view for agenda.
5492 With argument MONTH, switch to that month."
5493 (interactive "P")
5494 (org-agenda-change-time-span 'month month))
5495 (defun org-agenda-year-view (&optional year)
5496 "Switch to yearly view for agenda.
5497 With argument YEAR, switch to that year.
5498 If MONTH has more then 2 digits, only the last two encode the
5499 month. Any digits before this encode a year. So 200712 means
5500 December year 2007. Years in the range 1938-2037 can also be
5501 written as 2-digit years."
5502 (interactive "P")
5503 (when year
5504 (setq year (org-small-year-to-year year)))
5505 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5506 (org-agenda-change-time-span 'year year)
5507 (error "Abort")))
5509 (defun org-agenda-change-time-span (span &optional n)
5510 "Change the agenda view to SPAN.
5511 SPAN may be `day', `week', `month', `year'."
5512 (org-agenda-check-type t 'agenda)
5513 (if (and (not n) (equal org-agenda-span span))
5514 (error "Viewing span is already \"%s\"" span))
5515 (let* ((sd (or (org-get-at-bol 'day)
5516 org-starting-day))
5517 (computed (org-agenda-compute-time-span sd span n))
5518 (org-agenda-overriding-arguments
5519 (list (car org-agenda-last-arguments)
5520 (car computed) (cdr computed) t)))
5521 (org-agenda-redo)
5522 (org-agenda-find-same-or-today-or-agenda))
5523 (org-agenda-set-mode-name)
5524 (message "Switched to %s view" span))
5526 (defun org-agenda-compute-time-span (sd span &optional n)
5527 "Compute starting date and number of days for agenda.
5528 SPAN may be `day', `week', `month', `year'. The return value
5529 is a cons cell with the starting date and the number of days,
5530 so that the date SD will be in that range."
5531 (let* ((greg (calendar-gregorian-from-absolute sd))
5532 (dg (nth 1 greg))
5533 (mg (car greg))
5534 (yg (nth 2 greg))
5535 nd w1 y1 m1 thisweek)
5536 (cond
5537 ((eq span 'day)
5538 (when n
5539 (setq sd (+ (calendar-absolute-from-gregorian
5540 (list mg 1 yg))
5541 n -1)))
5542 (setq nd 1))
5543 ((eq span 'week)
5544 (let* ((nt (calendar-day-of-week
5545 (calendar-gregorian-from-absolute sd)))
5546 (d (if org-agenda-start-on-weekday
5547 (- nt org-agenda-start-on-weekday)
5548 0)))
5549 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5550 (when n
5551 (require 'cal-iso)
5552 (setq thisweek (car (calendar-iso-from-absolute sd)))
5553 (when (> n 99)
5554 (setq y1 (org-small-year-to-year (/ n 100))
5555 n (mod n 100)))
5556 (setq sd
5557 (calendar-absolute-from-iso
5558 (list n 1
5559 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5560 (setq nd 7)))
5561 ((eq span 'month)
5562 (when (and n (> n 99))
5563 (setq y1 (org-small-year-to-year (/ n 100))
5564 n (mod n 100)))
5565 (setq sd (calendar-absolute-from-gregorian
5566 (list (or n mg) 1 (or y1 yg)))
5567 nd (- (calendar-absolute-from-gregorian
5568 (list (1+ (or n mg)) 1 (or y1 yg)))
5569 sd)))
5570 ((eq span 'year)
5571 (setq sd (calendar-absolute-from-gregorian
5572 (list 1 1 (or n yg)))
5573 nd (- (calendar-absolute-from-gregorian
5574 (list 1 1 (1+ (or n yg))))
5575 sd))))
5576 (cons sd nd)))
5578 (defun org-agenda-next-date-line (&optional arg)
5579 "Jump to the next line indicating a date in agenda buffer."
5580 (interactive "p")
5581 (org-agenda-check-type t 'agenda 'timeline)
5582 (beginning-of-line 1)
5583 ;; This does not work if user makes date format that starts with a blank
5584 (if (looking-at "^\\S-") (forward-char 1))
5585 (if (not (re-search-forward "^\\S-" nil t arg))
5586 (progn
5587 (backward-char 1)
5588 (error "No next date after this line in this buffer")))
5589 (goto-char (match-beginning 0)))
5591 (defun org-agenda-previous-date-line (&optional arg)
5592 "Jump to the previous line indicating a date in agenda buffer."
5593 (interactive "p")
5594 (org-agenda-check-type t 'agenda 'timeline)
5595 (beginning-of-line 1)
5596 (if (not (re-search-backward "^\\S-" nil t arg))
5597 (error "No previous date before this line in this buffer")))
5599 ;; Initialize the highlight
5600 (defvar org-hl (org-make-overlay 1 1))
5601 (org-overlay-put org-hl 'face 'highlight)
5603 (defun org-highlight (begin end &optional buffer)
5604 "Highlight a region with overlay."
5605 (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
5606 org-hl begin end (or buffer (current-buffer))))
5608 (defun org-unhighlight ()
5609 "Detach overlay INDEX."
5610 (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
5612 ;; FIXME this is currently not used.
5613 (defun org-highlight-until-next-command (beg end &optional buffer)
5614 "Move the highlight overlay to BEG/END, remove it before the next command."
5615 (org-highlight beg end buffer)
5616 (add-hook 'pre-command-hook 'org-unhighlight-once))
5617 (defun org-unhighlight-once ()
5618 "Remove the highlight from its position, and this function from the hook."
5619 (remove-hook 'pre-command-hook 'org-unhighlight-once)
5620 (org-unhighlight))
5622 (defun org-agenda-follow-mode ()
5623 "Toggle follow mode in an agenda buffer."
5624 (interactive)
5625 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
5626 (org-agenda-set-mode-name)
5627 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5628 (org-agenda-show))
5629 (message "Follow mode is %s"
5630 (if org-agenda-follow-mode "on" "off")))
5632 (defun org-agenda-entry-text-mode (&optional arg)
5633 "Toggle entry text mode in an agenda buffer."
5634 (interactive "P")
5635 (if (integerp arg)
5636 (setq org-agenda-entry-text-mode t)
5637 (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
5638 (org-agenda-entry-text-hide)
5639 (and org-agenda-entry-text-mode
5640 (let ((org-agenda-entry-text-maxlines
5641 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5642 (org-agenda-entry-text-show)))
5643 (org-agenda-set-mode-name)
5644 (message "Entry text mode is %s. Maximum number of lines is %d"
5645 (if org-agenda-entry-text-mode "on" "off")
5646 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5648 (defun org-agenda-clockreport-mode ()
5649 "Toggle clocktable mode in an agenda buffer."
5650 (interactive)
5651 (org-agenda-check-type t 'agenda)
5652 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
5653 (org-agenda-set-mode-name)
5654 (org-agenda-redo)
5655 (message "Clocktable mode is %s"
5656 (if org-agenda-clockreport-mode "on" "off")))
5658 (defun org-agenda-log-mode (&optional special)
5659 "Toggle log mode in an agenda buffer.
5660 With argument SPECIAL, show all possible log items, not only the ones
5661 configured in `org-agenda-log-mode-items'.
5662 With a double `C-u' prefix arg, show *only* log items, nothing else."
5663 (interactive "P")
5664 (org-agenda-check-type t 'agenda 'timeline)
5665 (setq org-agenda-show-log
5666 (if (equal special '(16))
5667 'only
5668 (if special '(closed clock state)
5669 (not org-agenda-show-log))))
5670 (org-agenda-set-mode-name)
5671 (org-agenda-redo)
5672 (message "Log mode is %s"
5673 (if org-agenda-show-log "on" "off")))
5675 (defun org-agenda-archives-mode (&optional with-files)
5676 "Toggle inclusion of items in trees marked with :ARCHIVE:.
5677 When called with a prefix argument, include all archive files as well."
5678 (interactive "P")
5679 (setq org-agenda-archives-mode
5680 (if with-files t (if org-agenda-archives-mode nil 'trees)))
5681 (org-agenda-set-mode-name)
5682 (org-agenda-redo)
5683 (message
5684 "%s"
5685 (cond
5686 ((eq org-agenda-archives-mode nil)
5687 "No archives are included")
5688 ((eq org-agenda-archives-mode 'trees)
5689 (format "Trees with :%s: tag are included" org-archive-tag))
5690 ((eq org-agenda-archives-mode t)
5691 (format "Trees with :%s: tag and all active archive files are included"
5692 org-archive-tag)))))
5694 (defun org-agenda-toggle-diary ()
5695 "Toggle diary inclusion in an agenda buffer."
5696 (interactive)
5697 (org-agenda-check-type t 'agenda)
5698 (setq org-agenda-include-diary (not org-agenda-include-diary))
5699 (org-agenda-redo)
5700 (org-agenda-set-mode-name)
5701 (message "Diary inclusion turned %s"
5702 (if org-agenda-include-diary "on" "off")))
5704 (defun org-agenda-toggle-time-grid ()
5705 "Toggle time grid in an agenda buffer."
5706 (interactive)
5707 (org-agenda-check-type t 'agenda)
5708 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
5709 (org-agenda-redo)
5710 (org-agenda-set-mode-name)
5711 (message "Time-grid turned %s"
5712 (if org-agenda-use-time-grid "on" "off")))
5714 (defun org-agenda-set-mode-name ()
5715 "Set the mode name to indicate all the small mode settings."
5716 (setq mode-name
5717 (concat "Org-Agenda"
5718 (if (equal org-agenda-ndays 1) " Day" "")
5719 (if (equal org-agenda-ndays 7) " Week" "")
5720 (if org-agenda-follow-mode " Follow" "")
5721 (if org-agenda-entry-text-mode " ETxt" "")
5722 (if org-agenda-include-diary " Diary" "")
5723 (if org-agenda-use-time-grid " Grid" "")
5724 (if (and (boundp 'org-habit-show-habits)
5725 org-habit-show-habits) " Habit" "")
5726 (if (consp org-agenda-show-log) " LogAll"
5727 (if org-agenda-show-log " Log" ""))
5728 (if (or org-agenda-filter (get 'org-agenda-filter
5729 :preset-filter))
5730 (concat " {" (mapconcat
5731 'identity
5732 (append (get 'org-agenda-filter
5733 :preset-filter)
5734 org-agenda-filter) "") "}")
5736 (if org-agenda-archives-mode
5737 (if (eq org-agenda-archives-mode t)
5738 " Archives"
5739 (format " :%s:" org-archive-tag))
5741 (if org-agenda-clockreport-mode " Clock" "")))
5742 (force-mode-line-update))
5744 (defun org-agenda-post-command-hook ()
5745 (setq org-agenda-type
5746 (or (get-text-property (point) 'org-agenda-type)
5747 (get-text-property (max (point-min) (1- (point)))
5748 'org-agenda-type))))
5750 (defun org-agenda-next-line ()
5751 "Move cursor to the next line, and show if follow-mode is active."
5752 (interactive)
5753 (call-interactively 'next-line)
5754 (org-agenda-do-context-action))
5756 (defun org-agenda-previous-line ()
5757 "Move cursor to the previous line, and show if follow-mode is active."
5759 (interactive)
5760 (call-interactively 'previous-line)
5761 (org-agenda-do-context-action))
5763 (defun org-agenda-do-context-action ()
5764 "Show outline path and, maybe, follow-mode window."
5765 (let ((m (org-get-at-bol 'org-marker)))
5766 (if (and org-agenda-follow-mode m)
5767 (org-agenda-show))
5768 (if (and m org-agenda-show-outline-path)
5769 (org-with-point-at m
5770 (org-display-outline-path t)))))
5772 (defun org-agenda-show-priority ()
5773 "Show the priority of the current item.
5774 This priority is composed of the main priority given with the [#A] cookies,
5775 and by additional input from the age of a schedules or deadline entry."
5776 (interactive)
5777 (let* ((pri (org-get-at-bol 'priority)))
5778 (message "Priority is %d" (if pri pri -1000))))
5780 (defun org-agenda-show-tags ()
5781 "Show the tags applicable to the current item."
5782 (interactive)
5783 (let* ((tags (org-get-at-bol 'tags)))
5784 (if tags
5785 (message "Tags are :%s:"
5786 (org-no-properties (mapconcat 'identity tags ":")))
5787 (message "No tags associated with this line"))))
5789 (defun org-agenda-goto (&optional highlight)
5790 "Go to the Org-mode file which contains the item at point."
5791 (interactive)
5792 (let* ((marker (or (org-get-at-bol 'org-marker)
5793 (org-agenda-error)))
5794 (buffer (marker-buffer marker))
5795 (pos (marker-position marker)))
5796 (switch-to-buffer-other-window buffer)
5797 (widen)
5798 (goto-char pos)
5799 (when (org-mode-p)
5800 (org-show-context 'agenda)
5801 (save-excursion
5802 (and (outline-next-heading)
5803 (org-flag-heading nil)))) ; show the next heading
5804 (recenter (/ (window-height) 2))
5805 (run-hooks 'org-agenda-after-show-hook)
5806 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
5808 (defvar org-agenda-after-show-hook nil
5809 "Normal hook run after an item has been shown from the agenda.
5810 Point is in the buffer where the item originated.")
5812 (defun org-agenda-kill ()
5813 "Kill the entry or subtree belonging to the current agenda entry."
5814 (interactive)
5815 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5816 (let* ((marker (or (org-get-at-bol 'org-marker)
5817 (org-agenda-error)))
5818 (buffer (marker-buffer marker))
5819 (pos (marker-position marker))
5820 (type (org-get-at-bol 'type))
5821 dbeg dend (n 0) conf)
5822 (org-with-remote-undo buffer
5823 (with-current-buffer buffer
5824 (save-excursion
5825 (goto-char pos)
5826 (if (and (org-mode-p) (not (member type '("sexp"))))
5827 (setq dbeg (progn (org-back-to-heading t) (point))
5828 dend (org-end-of-subtree t t))
5829 (setq dbeg (point-at-bol)
5830 dend (min (point-max) (1+ (point-at-eol)))))
5831 (goto-char dbeg)
5832 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
5833 (setq conf (or (eq t org-agenda-confirm-kill)
5834 (and (numberp org-agenda-confirm-kill)
5835 (> n org-agenda-confirm-kill))))
5836 (and conf
5837 (not (y-or-n-p
5838 (format "Delete entry with %d lines in buffer \"%s\"? "
5839 n (buffer-name buffer))))
5840 (error "Abort"))
5841 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
5842 (with-current-buffer buffer (delete-region dbeg dend))
5843 (message "Agenda item and source killed"))))
5845 (defvar org-archive-default-command)
5846 (defun org-agenda-archive-default ()
5847 "Archive the entry or subtree belonging to the current agenda entry."
5848 (interactive)
5849 (require 'org-archive)
5850 (org-agenda-archive-with org-archive-default-command))
5852 (defun org-agenda-archive-default-with-confirmation ()
5853 "Archive the entry or subtree belonging to the current agenda entry."
5854 (interactive)
5855 (require 'org-archive)
5856 (org-agenda-archive-with org-archive-default-command 'confirm))
5858 (defun org-agenda-archive ()
5859 "Archive the entry or subtree belonging to the current agenda entry."
5860 (interactive)
5861 (org-agenda-archive-with 'org-archive-subtree))
5863 (defun org-agenda-archive-to-archive-sibling ()
5864 "Move the entry to the archive sibling."
5865 (interactive)
5866 (org-agenda-archive-with 'org-archive-to-archive-sibling))
5868 (defun org-agenda-archive-with (cmd &optional confirm)
5869 "Move the entry to the archive sibling."
5870 (interactive)
5871 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5872 (let* ((marker (or (org-get-at-bol 'org-marker)
5873 (org-agenda-error)))
5874 (buffer (marker-buffer marker))
5875 (pos (marker-position marker)))
5876 (org-with-remote-undo buffer
5877 (with-current-buffer buffer
5878 (if (org-mode-p)
5879 (if (and confirm
5880 (not (y-or-n-p "Archive this subtree or entry? ")))
5881 (error "Abort")
5882 (save-excursion
5883 (goto-char pos)
5884 (org-remove-subtree-entries-from-agenda)
5885 (org-back-to-heading t)
5886 (funcall cmd)))
5887 (error "Archiving works only in Org-mode files"))))))
5889 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
5890 "Remove all lines in the agenda that correspond to a given subtree.
5891 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5892 If this information is not given, the function uses the tree at point."
5893 (let ((buf (or buf (current-buffer))) m p)
5894 (save-excursion
5895 (unless (and beg end)
5896 (org-back-to-heading t)
5897 (setq beg (point))
5898 (org-end-of-subtree t)
5899 (setq end (point)))
5900 (set-buffer (get-buffer org-agenda-buffer-name))
5901 (save-excursion
5902 (goto-char (point-max))
5903 (beginning-of-line 1)
5904 (while (not (bobp))
5905 (when (and (setq m (org-get-at-bol 'org-marker))
5906 (equal buf (marker-buffer m))
5907 (setq p (marker-position m))
5908 (>= p beg)
5909 (< p end))
5910 (let ((inhibit-read-only t))
5911 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5912 (beginning-of-line 0))))))
5914 (defun org-agenda-refile (&optional goto rfloc)
5915 "Refile the item at point."
5916 (interactive "P")
5917 (if (equal goto '(16))
5918 (org-refile-goto-last-stored)
5919 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
5920 (org-agenda-error)))
5921 (buffer (marker-buffer marker))
5922 (pos (marker-position marker))
5923 (rfloc (or rfloc
5924 (org-refile-get-location
5925 (if goto "Goto: " "Refile to: ") buffer
5926 org-refile-allow-creating-parent-nodes))))
5927 (with-current-buffer buffer
5928 (save-excursion
5929 (save-restriction
5930 (widen)
5931 (goto-char marker)
5932 (org-remove-subtree-entries-from-agenda)
5933 (org-refile goto buffer rfloc)))))))
5935 (defun org-agenda-open-link (&optional arg)
5936 "Follow the link in the current line, if any.
5937 This looks for a link in the displayed line in the agenda. It also looks
5938 at the text of the entry itself."
5939 (interactive "P")
5940 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
5941 (org-get-at-bol 'org-marker)))
5942 (buffer (and marker (marker-buffer marker)))
5943 (prefix (buffer-substring
5944 (point-at-bol)
5945 (+ (point-at-bol)
5946 (or (org-get-at-bol 'prefix-length) 0)))))
5947 (cond
5948 (buffer
5949 (with-current-buffer buffer
5950 (save-excursion
5951 (save-restriction
5952 (widen)
5953 (goto-char marker)
5954 (org-offer-links-in-entry arg prefix)))))
5955 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
5956 (save-excursion
5957 (beginning-of-line 1)
5958 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
5959 (org-open-link-from-string (match-string 1)))
5960 (t (error "No link to open here")))))
5962 (defun org-agenda-copy-local-variable (var)
5963 "Get a variable from a referenced buffer and install it here."
5964 (let ((m (org-get-at-bol 'org-marker)))
5965 (when (and m (buffer-live-p (marker-buffer m)))
5966 (org-set-local var (with-current-buffer (marker-buffer m)
5967 (symbol-value var))))))
5969 (defun org-agenda-switch-to (&optional delete-other-windows)
5970 "Go to the Org-mode file which contains the item at point."
5971 (interactive)
5972 (if (and org-return-follows-link
5973 (not (org-get-at-bol 'org-marker))
5974 (org-in-regexp org-bracket-link-regexp))
5975 (org-open-link-from-string (match-string 0))
5976 (let* ((marker (or (org-get-at-bol 'org-marker)
5977 (org-agenda-error)))
5978 (buffer (marker-buffer marker))
5979 (pos (marker-position marker)))
5980 (switch-to-buffer buffer)
5981 (and delete-other-windows (delete-other-windows))
5982 (widen)
5983 (goto-char pos)
5984 (when (org-mode-p)
5985 (org-show-context 'agenda)
5986 (save-excursion
5987 (and (outline-next-heading)
5988 (org-flag-heading nil))))))) ; show the next heading
5990 (defun org-agenda-goto-mouse (ev)
5991 "Go to the Org-mode file which contains the item at the mouse click."
5992 (interactive "e")
5993 (mouse-set-point ev)
5994 (org-agenda-goto))
5996 (defun org-agenda-show (&optional full-entry)
5997 "Display the Org-mode file which contains the item at point.
5998 With prefix argument FULL-ENTRY, make the entire entry visible
5999 if it was hidden in the outline."
6000 (interactive "P")
6001 (let ((win (selected-window)))
6002 (if full-entry
6003 (let ((org-show-entry-below t))
6004 (org-agenda-goto t))
6005 (org-agenda-goto t))
6006 (select-window win)))
6008 (defvar org-agenda-show-window nil)
6009 (defun org-agenda-show-and-scroll-up ()
6010 "Display the Org-mode file which contains the item at point.
6011 When called repeatedly, scroll the window that is displaying the buffer."
6012 (interactive)
6013 (let ((win (selected-window)))
6014 (if (and (window-live-p org-agenda-show-window)
6015 (eq this-command last-command))
6016 (progn
6017 (select-window org-agenda-show-window)
6018 (ignore-errors (scroll-up)))
6019 (org-agenda-goto t)
6020 (show-subtree)
6021 (setq org-agenda-show-window (selected-window)))
6022 (select-window win)))
6024 (defun org-agenda-show-scroll-down ()
6025 "Scroll down the window showing the agenda."
6026 (interactive)
6027 (let ((win (selected-window)))
6028 (when (window-live-p org-agenda-show-window)
6029 (select-window org-agenda-show-window)
6030 (ignore-errors (scroll-down))
6031 (select-window win))))
6033 (defun org-agenda-show-1 (&optional more)
6034 "Display the Org-mode file which contains the item at point.
6035 The prefix arg selects the amount of information to display:
6037 0 hide the subtree
6038 1 just show the entry according to defaults.
6039 2 show the children view
6040 3 show the subtree view
6041 4 show the entire subtree and any LOGBOOK drawers
6042 5 show the entire subtree and any drawers
6043 With prefix argument FULL-ENTRY, make the entire entry visible
6044 if it was hidden in the outline."
6045 (interactive "p")
6046 (let ((win (selected-window)))
6047 (org-agenda-goto t)
6048 (org-recenter-heading 1)
6049 (cond
6050 ((= more 0)
6051 (hide-subtree)
6052 (save-excursion
6053 (org-back-to-heading)
6054 (run-hook-with-args 'org-cycle-hook 'folded))
6055 (message "Remote: FOLDED"))
6056 ((and (interactive-p) (= more 1))
6057 (message "Remote: show with default settings"))
6058 ((= more 2)
6059 (show-entry)
6060 (show-children)
6061 (save-excursion
6062 (org-back-to-heading)
6063 (run-hook-with-args 'org-cycle-hook 'children))
6064 (message "Remote: CHILDREN"))
6065 ((= more 3)
6066 (show-subtree)
6067 (save-excursion
6068 (org-back-to-heading)
6069 (run-hook-with-args 'org-cycle-hook 'subtree))
6070 (message "Remote: SUBTREE"))
6071 ((= more 4)
6072 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6073 (org-drawer-regexp
6074 (concat "^[ \t]*:\\("
6075 (mapconcat 'regexp-quote org-drawers "\\|")
6076 "\\):[ \t]*$")))
6077 (show-subtree)
6078 (save-excursion
6079 (org-back-to-heading)
6080 (org-cycle-hide-drawers 'subtree)))
6081 (message "Remote: SUBTREE AND LOGBOOK"))
6082 ((> more 4)
6083 (show-subtree)
6084 (message "Remote: SUBTREE AND ALL DRAWERS")))
6085 (select-window win)))
6087 (defun org-recenter-heading (n)
6088 (save-excursion
6089 (org-back-to-heading)
6090 (recenter n)))
6092 (defvar org-agenda-cycle-counter nil)
6093 (defun org-agenda-cycle-show (&optional n)
6094 "Show the current entry in another window, with default settings.
6095 Default settings are taken from `org-show-hierarchy-above' and siblings.
6096 When use repeatedly in immediate succession, the remote entry will cycle
6097 through visibility
6099 children -> subtree -> folded
6101 When called with a numeric prefix arg, that arg will be passed through to
6102 `org-agenda-show-1'. For the interpretation of that argument, see the
6103 docstring of `org-agenda-show-1'."
6104 (interactive "P")
6105 (if (integerp n)
6106 (setq org-agenda-cycle-counter n)
6107 (if (not (eq last-command this-command))
6108 (setq org-agenda-cycle-counter 1)
6109 (if (equal org-agenda-cycle-counter 0)
6110 (setq org-agenda-cycle-counter 2)
6111 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6112 (if (> org-agenda-cycle-counter 3)
6113 (setq org-agenda-cycle-counter 0)))))
6114 (org-agenda-show-1 org-agenda-cycle-counter))
6116 (defun org-agenda-recenter (arg)
6117 "Display the Org-mode file which contains the item at point and recenter."
6118 (interactive "P")
6119 (let ((win (selected-window)))
6120 (org-agenda-goto t)
6121 (recenter arg)
6122 (select-window win)))
6124 (defun org-agenda-show-mouse (ev)
6125 "Display the Org-mode file which contains the item at the mouse click."
6126 (interactive "e")
6127 (mouse-set-point ev)
6128 (org-agenda-show))
6130 (defun org-agenda-check-no-diary ()
6131 "Check if the entry is a diary link and abort if yes."
6132 (if (org-get-at-bol 'org-agenda-diary-link)
6133 (org-agenda-error)))
6135 (defun org-agenda-error ()
6136 (error "Command not allowed in this line"))
6138 (defun org-agenda-tree-to-indirect-buffer ()
6139 "Show the subtree corresponding to the current entry in an indirect buffer.
6140 This calls the command `org-tree-to-indirect-buffer' from the original
6141 Org-mode buffer.
6142 With numerical prefix arg ARG, go up to this level and then take that tree.
6143 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
6144 dedicated frame)."
6145 (interactive)
6146 (org-agenda-check-no-diary)
6147 (let* ((marker (or (org-get-at-bol 'org-marker)
6148 (org-agenda-error)))
6149 (buffer (marker-buffer marker))
6150 (pos (marker-position marker)))
6151 (with-current-buffer buffer
6152 (save-excursion
6153 (goto-char pos)
6154 (call-interactively 'org-tree-to-indirect-buffer)))))
6156 (defvar org-last-heading-marker (make-marker)
6157 "Marker pointing to the headline that last changed its TODO state
6158 by a remote command from the agenda.")
6160 (defun org-agenda-todo-nextset ()
6161 "Switch TODO entry to next sequence."
6162 (interactive)
6163 (org-agenda-todo 'nextset))
6165 (defun org-agenda-todo-previousset ()
6166 "Switch TODO entry to previous sequence."
6167 (interactive)
6168 (org-agenda-todo 'previousset))
6170 (defun org-agenda-todo (&optional arg)
6171 "Cycle TODO state of line at point, also in Org-mode file.
6172 This changes the line at point, all other lines in the agenda referring to
6173 the same tree node, and the headline of the tree node in the Org-mode file."
6174 (interactive "P")
6175 (org-agenda-check-no-diary)
6176 (let* ((col (current-column))
6177 (marker (or (org-get-at-bol 'org-marker)
6178 (org-agenda-error)))
6179 (buffer (marker-buffer marker))
6180 (pos (marker-position marker))
6181 (hdmarker (org-get-at-bol 'org-hd-marker))
6182 (todayp (equal (org-get-at-bol 'day)
6183 (time-to-days (current-time))))
6184 (inhibit-read-only t)
6185 org-agenda-headline-snapshot-before-repeat newhead just-one)
6186 (org-with-remote-undo buffer
6187 (with-current-buffer buffer
6188 (widen)
6189 (goto-char pos)
6190 (org-show-context 'agenda)
6191 (save-excursion
6192 (and (outline-next-heading)
6193 (org-flag-heading nil))) ; show the next heading
6194 (let ((current-prefix-arg arg))
6195 (call-interactively 'org-todo))
6196 (and (bolp) (forward-char 1))
6197 (setq newhead (org-get-heading))
6198 (when (and (org-bound-and-true-p
6199 org-agenda-headline-snapshot-before-repeat)
6200 (not (equal org-agenda-headline-snapshot-before-repeat
6201 newhead))
6202 todayp)
6203 (setq newhead org-agenda-headline-snapshot-before-repeat
6204 just-one t))
6205 (save-excursion
6206 (org-back-to-heading)
6207 (move-marker org-last-heading-marker (point))))
6208 (beginning-of-line 1)
6209 (save-excursion
6210 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6211 (org-move-to-column col))))
6213 (defun org-agenda-add-note (&optional arg)
6214 "Add a time-stamped note to the entry at point."
6215 (interactive "P")
6216 (org-agenda-check-no-diary)
6217 (let* ((marker (or (org-get-at-bol 'org-marker)
6218 (org-agenda-error)))
6219 (buffer (marker-buffer marker))
6220 (pos (marker-position marker))
6221 (hdmarker (org-get-at-bol 'org-hd-marker))
6222 (inhibit-read-only t))
6223 (with-current-buffer buffer
6224 (widen)
6225 (goto-char pos)
6226 (org-show-context 'agenda)
6227 (save-excursion
6228 (and (outline-next-heading)
6229 (org-flag-heading nil))) ; show the next heading
6230 (org-add-note))))
6232 (defun org-agenda-change-all-lines (newhead hdmarker
6233 &optional fixface just-this)
6234 "Change all lines in the agenda buffer which match HDMARKER.
6235 The new content of the line will be NEWHEAD (as modified by
6236 `org-format-agenda-item'). HDMARKER is checked with
6237 `equal' against all `org-hd-marker' text properties in the file.
6238 If FIXFACE is non-nil, the face of each item is modified according to
6239 the new TODO state.
6240 If JUST-THIS is non-nil, change just the current line, not all.
6241 If FORCE-TAGS is non nil, the car of it returns the new tags."
6242 (let* ((inhibit-read-only t)
6243 (line (org-current-line))
6244 (thetags (with-current-buffer (marker-buffer hdmarker)
6245 (save-excursion (save-restriction (widen)
6246 (goto-char hdmarker)
6247 (org-get-tags-at)))))
6248 props m pl undone-face done-face finish new dotime cat tags)
6249 (save-excursion
6250 (goto-char (point-max))
6251 (beginning-of-line 1)
6252 (while (not finish)
6253 (setq finish (bobp))
6254 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6255 (or (not just-this) (= (org-current-line) line))
6256 (equal m hdmarker))
6257 (setq props (text-properties-at (point))
6258 dotime (org-get-at-bol 'dotime)
6259 cat (org-get-at-bol 'org-category)
6260 tags thetags
6261 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6262 pl (org-get-at-bol 'prefix-length)
6263 undone-face (org-get-at-bol 'undone-face)
6264 done-face (org-get-at-bol 'done-face))
6265 (goto-char (+ (point) pl))
6266 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6267 (cond
6268 ((equal new "")
6269 (beginning-of-line 1)
6270 (and (looking-at ".*\n?") (replace-match "")))
6271 ((looking-at ".*")
6272 (replace-match new t t)
6273 (beginning-of-line 1)
6274 (add-text-properties (point-at-bol) (point-at-eol) props)
6275 (when fixface
6276 (add-text-properties
6277 (point-at-bol) (point-at-eol)
6278 (list 'face
6279 (if org-last-todo-state-is-todo
6280 undone-face done-face))))
6281 (org-agenda-highlight-todo 'line)
6282 (beginning-of-line 1))
6283 (t (error "Line update did not work"))))
6284 (beginning-of-line 0)))
6285 (org-finalize-agenda)))
6287 (defun org-agenda-align-tags (&optional line)
6288 "Align all tags in agenda items to `org-agenda-tags-column'."
6289 (let ((inhibit-read-only t) l c)
6290 (save-excursion
6291 (goto-char (if line (point-at-bol) (point-min)))
6292 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
6293 (if line (point-at-eol) nil) t)
6294 (add-text-properties
6295 (match-beginning 2) (match-end 2)
6296 (list 'face (delq nil (let ((prop (get-text-property
6297 (match-beginning 2) 'face)))
6298 (or (listp prop) (setq prop (list prop)))
6299 (if (memq 'org-tag prop)
6300 prop
6301 (cons 'org-tag prop))))))
6302 (setq l (- (match-end 2) (match-beginning 2))
6303 c (if (< org-agenda-tags-column 0)
6304 (- (abs org-agenda-tags-column) l)
6305 org-agenda-tags-column))
6306 (delete-region (match-beginning 1) (match-end 1))
6307 (goto-char (match-beginning 1))
6308 (insert (org-add-props
6309 (make-string (max 1 (- c (current-column))) ?\ )
6310 (text-properties-at (point)))))
6311 (goto-char (point-min))
6312 (org-font-lock-add-tag-faces (point-max)))))
6314 (defun org-agenda-priority-up ()
6315 "Increase the priority of line at point, also in Org-mode file."
6316 (interactive)
6317 (org-agenda-priority 'up))
6319 (defun org-agenda-priority-down ()
6320 "Decrease the priority of line at point, also in Org-mode file."
6321 (interactive)
6322 (org-agenda-priority 'down))
6324 (defun org-agenda-priority (&optional force-direction)
6325 "Set the priority of line at point, also in Org-mode file.
6326 This changes the line at point, all other lines in the agenda referring to
6327 the same tree node, and the headline of the tree node in the Org-mode file."
6328 (interactive)
6329 (unless org-enable-priority-commands
6330 (error "Priority commands are disabled"))
6331 (org-agenda-check-no-diary)
6332 (let* ((marker (or (org-get-at-bol 'org-marker)
6333 (org-agenda-error)))
6334 (hdmarker (org-get-at-bol 'org-hd-marker))
6335 (buffer (marker-buffer hdmarker))
6336 (pos (marker-position hdmarker))
6337 (inhibit-read-only t)
6338 newhead)
6339 (org-with-remote-undo buffer
6340 (with-current-buffer buffer
6341 (widen)
6342 (goto-char pos)
6343 (org-show-context 'agenda)
6344 (save-excursion
6345 (and (outline-next-heading)
6346 (org-flag-heading nil))) ; show the next heading
6347 (funcall 'org-priority force-direction)
6348 (end-of-line 1)
6349 (setq newhead (org-get-heading)))
6350 (org-agenda-change-all-lines newhead hdmarker)
6351 (beginning-of-line 1))))
6353 ;; FIXME: should fix the tags property of the agenda line.
6354 (defun org-agenda-set-tags (&optional tag onoff)
6355 "Set tags for the current headline."
6356 (interactive)
6357 (org-agenda-check-no-diary)
6358 (if (and (org-region-active-p) (interactive-p))
6359 (call-interactively 'org-change-tag-in-region)
6360 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6361 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6362 (org-agenda-error)))
6363 (buffer (marker-buffer hdmarker))
6364 (pos (marker-position hdmarker))
6365 (inhibit-read-only t)
6366 newhead)
6367 (org-with-remote-undo buffer
6368 (with-current-buffer buffer
6369 (widen)
6370 (goto-char pos)
6371 (save-excursion
6372 (org-show-context 'agenda))
6373 (save-excursion
6374 (and (outline-next-heading)
6375 (org-flag-heading nil))) ; show the next heading
6376 (goto-char pos)
6377 (if tag
6378 (org-toggle-tag tag onoff)
6379 (call-interactively 'org-set-tags))
6380 (end-of-line 1)
6381 (setq newhead (org-get-heading)))
6382 (org-agenda-change-all-lines newhead hdmarker)
6383 (beginning-of-line 1)))))
6385 (defun org-agenda-set-property ()
6386 "Set a property for the current headline."
6387 (interactive)
6388 (org-agenda-check-no-diary)
6389 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6390 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6391 (org-agenda-error)))
6392 (buffer (marker-buffer hdmarker))
6393 (pos (marker-position hdmarker))
6394 (inhibit-read-only t)
6395 newhead)
6396 (org-with-remote-undo buffer
6397 (with-current-buffer buffer
6398 (widen)
6399 (goto-char pos)
6400 (save-excursion
6401 (org-show-context 'agenda))
6402 (save-excursion
6403 (and (outline-next-heading)
6404 (org-flag-heading nil))) ; show the next heading
6405 (goto-char pos)
6406 (call-interactively 'org-set-property)))))
6408 (defun org-agenda-set-effort ()
6409 "Set the effort property for the current headline."
6410 (interactive)
6411 (org-agenda-check-no-diary)
6412 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6413 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6414 (org-agenda-error)))
6415 (buffer (marker-buffer hdmarker))
6416 (pos (marker-position hdmarker))
6417 (inhibit-read-only t)
6418 newhead)
6419 (org-with-remote-undo buffer
6420 (with-current-buffer buffer
6421 (widen)
6422 (goto-char pos)
6423 (save-excursion
6424 (org-show-context 'agenda))
6425 (save-excursion
6426 (and (outline-next-heading)
6427 (org-flag-heading nil))) ; show the next heading
6428 (goto-char pos)
6429 (call-interactively 'org-set-effort)
6430 (end-of-line 1)))))
6432 (defun org-agenda-toggle-archive-tag ()
6433 "Toggle the archive tag for the current entry."
6434 (interactive)
6435 (org-agenda-check-no-diary)
6436 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6437 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6438 (org-agenda-error)))
6439 (buffer (marker-buffer hdmarker))
6440 (pos (marker-position hdmarker))
6441 (inhibit-read-only t)
6442 newhead)
6443 (org-with-remote-undo buffer
6444 (with-current-buffer buffer
6445 (widen)
6446 (goto-char pos)
6447 (org-show-context 'agenda)
6448 (save-excursion
6449 (and (outline-next-heading)
6450 (org-flag-heading nil))) ; show the next heading
6451 (call-interactively 'org-toggle-archive-tag)
6452 (end-of-line 1)
6453 (setq newhead (org-get-heading)))
6454 (org-agenda-change-all-lines newhead hdmarker)
6455 (beginning-of-line 1))))
6457 (defun org-agenda-do-date-later (arg)
6458 (interactive "P")
6459 (cond
6460 ((or (equal arg '(16))
6461 (memq last-command
6462 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6463 (setq this-command 'org-agenda-date-later-minutes)
6464 (org-agenda-date-later-minutes 1))
6465 ((or (equal arg '(4))
6466 (memq last-command
6467 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6468 (setq this-command 'org-agenda-date-later-hours)
6469 (org-agenda-date-later-hours 1))
6471 (org-agenda-date-later (prefix-numeric-value arg)))))
6473 (defun org-agenda-do-date-earlier (arg)
6474 (interactive "P")
6475 (cond
6476 ((or (equal arg '(16))
6477 (memq last-command
6478 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6479 (setq this-command 'org-agenda-date-earlier-minutes)
6480 (org-agenda-date-earlier-minutes 1))
6481 ((or (equal arg '(4))
6482 (memq last-command
6483 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6484 (setq this-command 'org-agenda-date-earlier-hours)
6485 (org-agenda-date-earlier-hours 1))
6487 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6489 (defun org-agenda-date-later (arg &optional what)
6490 "Change the date of this item to one day later."
6491 (interactive "p")
6492 (org-agenda-check-type t 'agenda 'timeline)
6493 (org-agenda-check-no-diary)
6494 (let* ((marker (or (org-get-at-bol 'org-marker)
6495 (org-agenda-error)))
6496 (buffer (marker-buffer marker))
6497 (pos (marker-position marker)))
6498 (org-with-remote-undo buffer
6499 (with-current-buffer buffer
6500 (widen)
6501 (goto-char pos)
6502 (if (not (org-at-timestamp-p))
6503 (error "Cannot find time stamp"))
6504 (org-timestamp-change arg (or what 'day)))
6505 (org-agenda-show-new-time marker org-last-changed-timestamp))
6506 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6508 (defun org-agenda-date-earlier (arg &optional what)
6509 "Change the date of this item to one day earlier."
6510 (interactive "p")
6511 (org-agenda-date-later (- arg) what))
6513 (defun org-agenda-date-later-minutes (arg)
6514 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6515 (interactive "p")
6516 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6517 (org-agenda-date-later arg 'minute))
6519 (defun org-agenda-date-earlier-minutes (arg)
6520 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6521 (interactive "p")
6522 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6523 (org-agenda-date-earlier arg 'minute))
6525 (defun org-agenda-date-later-hours (arg)
6526 "Change the time of this item, in hour steps."
6527 (interactive "p")
6528 (org-agenda-date-later arg 'hour))
6530 (defun org-agenda-date-earlier-hours (arg)
6531 "Change the time of this item, in hour steps."
6532 (interactive "p")
6533 (org-agenda-date-earlier arg 'hour))
6535 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6536 "Show new date stamp via text properties."
6537 ;; We use text properties to make this undoable
6538 (let ((inhibit-read-only t)
6539 (buffer-invisibility-spec))
6540 (setq stamp (concat " " prefix " => " stamp))
6541 (save-excursion
6542 (goto-char (point-max))
6543 (while (not (bobp))
6544 (when (equal marker (org-get-at-bol 'org-marker))
6545 (org-move-to-column (- (window-width) (length stamp)) t)
6546 (org-agenda-fix-tags-filter-overlays-at (point))
6547 (if (featurep 'xemacs)
6548 ;; Use `duplicable' property to trigger undo recording
6549 (let ((ex (make-extent nil nil))
6550 (gl (make-glyph stamp)))
6551 (set-glyph-face gl 'secondary-selection)
6552 (set-extent-properties
6553 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6554 (insert-extent ex (1- (point)) (point-at-eol)))
6555 (add-text-properties
6556 (1- (point)) (point-at-eol)
6557 (list 'display (org-add-props stamp nil
6558 'face 'secondary-selection))))
6559 (beginning-of-line 1))
6560 (beginning-of-line 0)))))
6562 (defun org-agenda-date-prompt (arg)
6563 "Change the date of this item. Date is prompted for, with default today.
6564 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6565 be used to request time specification in the time stamp."
6566 (interactive "P")
6567 (org-agenda-check-type t 'agenda 'timeline)
6568 (org-agenda-check-no-diary)
6569 (let* ((marker (or (org-get-at-bol 'org-marker)
6570 (org-agenda-error)))
6571 (buffer (marker-buffer marker))
6572 (pos (marker-position marker)))
6573 (org-with-remote-undo buffer
6574 (with-current-buffer buffer
6575 (widen)
6576 (goto-char pos)
6577 (if (not (org-at-timestamp-p t))
6578 (error "Cannot find time stamp"))
6579 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
6580 (org-agenda-show-new-time marker org-last-changed-timestamp))
6581 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6583 (defun org-agenda-schedule (arg)
6584 "Schedule the item at point."
6585 (interactive "P")
6586 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6587 (org-agenda-check-no-diary)
6588 (let* ((marker (or (org-get-at-bol 'org-marker)
6589 (org-agenda-error)))
6590 (type (marker-insertion-type marker))
6591 (buffer (marker-buffer marker))
6592 (pos (marker-position marker))
6593 (org-insert-labeled-timestamps-at-point nil)
6595 (set-marker-insertion-type marker t)
6596 (org-with-remote-undo buffer
6597 (with-current-buffer buffer
6598 (widen)
6599 (goto-char pos)
6600 (setq ts (org-schedule arg)))
6601 (org-agenda-show-new-time marker ts "S"))
6602 (message "Item scheduled for %s" ts)))
6604 (defun org-agenda-deadline (arg)
6605 "Schedule the item at point."
6606 (interactive "P")
6607 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6608 (org-agenda-check-no-diary)
6609 (let* ((marker (or (org-get-at-bol 'org-marker)
6610 (org-agenda-error)))
6611 (buffer (marker-buffer marker))
6612 (pos (marker-position marker))
6613 (org-insert-labeled-timestamps-at-point nil)
6615 (org-with-remote-undo buffer
6616 (with-current-buffer buffer
6617 (widen)
6618 (goto-char pos)
6619 (setq ts (org-deadline arg)))
6620 (org-agenda-show-new-time marker ts "D"))
6621 (message "Deadline for this item set to %s" ts)))
6623 (defun org-agenda-action ()
6624 "Select entry for agenda action, or execute an agenda action.
6625 This command prompts for another letter. Valid inputs are:
6627 m Mark the entry at point for an agenda action
6628 s Schedule the marked entry to the date at the cursor
6629 d Set the deadline of the marked entry to the date at the cursor
6630 r Call `org-remember' with cursor date as the default date
6631 SPC Show marked entry in other window
6632 TAB Visit marked entry in other window
6634 The cursor may be at a date in the calendar, or in the Org agenda."
6635 (interactive)
6636 (let (ans)
6637 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
6638 (setq ans (read-char-exclusive))
6639 (cond
6640 ((equal ans ?m)
6641 ;; Mark this entry
6642 (if (eq major-mode 'org-agenda-mode)
6643 (let ((m (or (org-get-at-bol 'org-hd-marker)
6644 (org-get-at-bol 'org-marker))))
6645 (if m
6646 (progn
6647 (move-marker org-agenda-action-marker
6648 (marker-position m) (marker-buffer m))
6649 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
6650 (error "Don't know which entry to mark")))
6651 (error "This command works only in the agenda")))
6652 ((equal ans ?s)
6653 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
6654 ((equal ans ?d)
6655 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
6656 ((equal ans ?r)
6657 (org-agenda-do-action '(org-remember) t))
6658 ((equal ans ?\ )
6659 (let ((cw (selected-window)))
6660 (org-switch-to-buffer-other-window
6661 (marker-buffer org-agenda-action-marker))
6662 (goto-char org-agenda-action-marker)
6663 (org-show-context 'agenda)
6664 (select-window cw)))
6665 ((equal ans ?\C-i)
6666 (org-switch-to-buffer-other-window
6667 (marker-buffer org-agenda-action-marker))
6668 (goto-char org-agenda-action-marker)
6669 (org-show-context 'agenda))
6670 (t (error "Invalid agenda action %c" ans)))))
6672 (defun org-agenda-do-action (form &optional current-buffer)
6673 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
6674 (let ((org-overriding-default-time (org-get-cursor-date)))
6675 (if current-buffer
6676 (eval form)
6677 (if (not (marker-buffer org-agenda-action-marker))
6678 (error "No entry has been selected for agenda action")
6679 (with-current-buffer (marker-buffer org-agenda-action-marker)
6680 (save-excursion
6681 (save-restriction
6682 (widen)
6683 (goto-char org-agenda-action-marker)
6684 (eval form))))))))
6686 (defun org-agenda-clock-in (&optional arg)
6687 "Start the clock on the currently selected item."
6688 (interactive "P")
6689 (org-agenda-check-no-diary)
6690 (if (equal arg '(4))
6691 (org-clock-in arg)
6692 (let* ((marker (or (org-get-at-bol 'org-marker)
6693 (org-agenda-error)))
6694 (hdmarker (or (org-get-at-bol 'org-hd-marker)
6695 marker))
6696 (pos (marker-position marker))
6697 newhead)
6698 (org-with-remote-undo (marker-buffer marker)
6699 (with-current-buffer (marker-buffer marker)
6700 (widen)
6701 (goto-char pos)
6702 (org-show-context 'agenda)
6703 (org-show-entry)
6704 (org-cycle-hide-drawers 'children)
6705 (org-clock-in arg)
6706 (setq newhead (org-get-heading)))
6707 (org-agenda-change-all-lines newhead hdmarker)))))
6709 (defun org-agenda-clock-out (&optional arg)
6710 "Stop the currently running clock."
6711 (interactive "P")
6712 (unless (marker-buffer org-clock-marker)
6713 (error "No running clock"))
6714 (let ((marker (make-marker)) newhead)
6715 (org-with-remote-undo (marker-buffer org-clock-marker)
6716 (with-current-buffer (marker-buffer org-clock-marker)
6717 (save-excursion
6718 (save-restriction
6719 (widen)
6720 (goto-char org-clock-marker)
6721 (org-back-to-heading t)
6722 (move-marker marker (point))
6723 (org-clock-out)
6724 (setq newhead (org-get-heading))))))
6725 (org-agenda-change-all-lines newhead marker)
6726 (move-marker marker nil)))
6728 (defun org-agenda-clock-cancel (&optional arg)
6729 "Cancel the currently running clock."
6730 (interactive "P")
6731 (unless (marker-buffer org-clock-marker)
6732 (error "No running clock"))
6733 (org-with-remote-undo (marker-buffer org-clock-marker)
6734 (org-clock-cancel)))
6736 (defun org-agenda-diary-entry-in-org-file ()
6737 "Make a diary entry in the file `org-agenda-diary-file'."
6738 (let (d1 d2 char (text "") dp1 dp2)
6739 (if (equal (buffer-name) "*Calendar*")
6740 (setq d1 (calendar-cursor-to-date t)
6741 d2 (car calendar-mark-ring))
6742 (setq dp1 (get-text-property (point-at-bol) 'day))
6743 (unless dp1 (error "No date defined in current line"))
6744 (setq d1 (calendar-gregorian-from-absolute dp1)
6745 d2 (and (ignore-errors (mark))
6746 (save-excursion
6747 (goto-char (mark))
6748 (setq dp2 (get-text-property (point-at-bol) 'day)))
6749 (calendar-gregorian-from-absolute dp2))))
6750 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
6751 (setq char (read-char-exclusive))
6752 (cond
6753 ((equal char ?d)
6754 (setq text (read-string "Day entry: "))
6755 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
6756 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
6757 ((equal char ?a)
6758 (setq d1 (list (car d1) (nth 1 d1)
6759 (read-number (format "Reference year [%d]: " (nth 2 d1))
6760 (nth 2 d1))))
6761 (setq text (read-string "Anniversary (use %d to show years): "))
6762 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
6763 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
6764 ((equal char ?b)
6765 (setq text (read-string "Block entry: "))
6766 (unless (and d1 d2 (not (equal d1 d2)))
6767 (error "No block of days selected"))
6768 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
6769 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
6770 ((equal char ?j)
6771 (org-switch-to-buffer-other-window
6772 (find-file-noselect org-agenda-diary-file))
6773 (org-datetree-find-date-create d1)
6774 (org-reveal t))
6775 (t (error "Invalid selection character `%c'" char)))))
6777 (defcustom org-agenda-insert-diary-strategy 'date-tree
6778 "Where in `org-agenda-diary-file' should new entries be added?
6779 Valid values:
6781 date-tree in the date tree, as child of the date
6782 top-level as top-level entries at the end of the file."
6783 :group 'org-agenda
6784 :type '(choice
6785 (const :tag "in a date tree" date-tree)
6786 (const :tag "as top level at end of file" top-level)))
6788 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
6789 "Add a diary entry with TYPE to `org-agenda-diary-file'.
6790 If TEXT is not empty, it will become the headline of the new entry, and
6791 the resulting entry will not be shown. When TEXT is empty, switch to
6792 `org-agenda-diary-file' and let the user finish the entry there."
6793 (let ((cw (current-window-configuration)))
6794 (org-switch-to-buffer-other-window
6795 (find-file-noselect org-agenda-diary-file))
6796 (widen)
6797 (goto-char (point-min))
6798 (cond
6799 ((eq type 'anniversary)
6800 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
6801 (progn
6802 (or (org-on-heading-p t)
6803 (progn
6804 (outline-next-heading)
6805 (insert "* Anniversaries\n\n")
6806 (beginning-of-line -1)))))
6807 (outline-next-heading)
6808 (org-back-over-empty-lines)
6809 (backward-char 1)
6810 (insert "\n")
6811 (require 'diary-lib)
6812 (let ((calendar-date-display-form
6813 (if (if (boundp 'calendar-date-style)
6814 (eq calendar-date-style 'european)
6815 european-calendar-style) ; Emacs 22
6816 '(day " " month " " year)
6817 '(month " " day " " year))))
6819 (insert (format "%%%%(diary-anniversary %s) %s"
6820 (calendar-date-string d1 nil t) text))))
6821 ((eq type 'day)
6822 (if (eq org-agenda-insert-diary-strategy 'top-level)
6823 (org-agenda-insert-diary-as-top-level text)
6824 (require 'org-datetree)
6825 (org-datetree-find-date-create d1)
6826 (org-agenda-insert-diary-make-new-entry text))
6827 (org-insert-time-stamp (org-time-from-absolute
6828 (calendar-absolute-from-gregorian d1)))
6829 (end-of-line 0))
6830 ((eq type 'block)
6831 (if (> (calendar-absolute-from-gregorian d1)
6832 (calendar-absolute-from-gregorian d2))
6833 (setq d1 (prog1 d2 (setq d2 d1))))
6834 (if (eq org-agenda-insert-diary-strategy 'top-level)
6835 (org-agenda-insert-diary-as-top-level text)
6836 (require 'org-datetree)
6837 (org-datetree-find-date-create d1)
6838 (org-agenda-insert-diary-make-new-entry text))
6839 (org-insert-time-stamp (org-time-from-absolute
6840 (calendar-absolute-from-gregorian d1)))
6841 (insert "--")
6842 (org-insert-time-stamp (org-time-from-absolute
6843 (calendar-absolute-from-gregorian d2)))
6844 (end-of-line 0)))
6845 (if (string-match "\\S-" text)
6846 (progn
6847 (set-window-configuration cw)
6848 (message "%s entry added to %s"
6849 (capitalize (symbol-name type))
6850 (abbreviate-file-name org-agenda-diary-file)))
6851 (org-reveal t)
6852 (message "Please finish entry here"))))
6854 (defun org-agenda-insert-diary-as-top-level (text)
6855 "Make new entry as a top-level entry at the end of the file.
6856 Add TEXT as headline, and position the cursor in the second line so that
6857 a timestamp can be added there."
6858 (widen)
6859 (goto-char (point-max))
6860 (or (bolp) (insert "\n"))
6861 (insert "* " text "\n")
6862 (if org-adapt-indentation (org-indent-to-column 2)))
6864 (defun org-agenda-insert-diary-make-new-entry (text)
6865 "Make new entry as last child of current entry.
6866 Add TEXT as headline, and position the cursor in the second line so that
6867 a timestamp can be added there."
6868 (let ((org-show-following-heading t)
6869 (org-show-siblings t)
6870 (org-show-hierarchy-above t)
6871 (org-show-entry-below t)
6872 col)
6873 (outline-next-heading)
6874 (org-back-over-empty-lines)
6875 (or (looking-at "[ \t]*$")
6876 (progn (insert "\n") (backward-char 1)))
6877 (org-insert-heading)
6878 (org-do-demote)
6879 (setq col (current-column))
6880 (insert text "\n")
6881 (if org-adapt-indentation (org-indent-to-column col))
6882 (let ((org-show-following-heading t)
6883 (org-show-siblings t)
6884 (org-show-hierarchy-above t)
6885 (org-show-entry-below t))
6886 (org-show-context))))
6888 (defun org-agenda-diary-entry ()
6889 "Make a diary entry, like the `i' command from the calendar.
6890 All the standard commands work: block, weekly etc.
6891 When `org-agenda-diary-file' points to a file,
6892 `org-agenda-diary-entry-in-org-file' is called instead to create
6893 entries in that Org-mode file."
6894 (interactive)
6895 (org-agenda-check-type t 'agenda 'timeline)
6896 (if (not (eq org-agenda-diary-file 'diary-file))
6897 (org-agenda-diary-entry-in-org-file)
6898 (require 'diary-lib)
6899 (let* ((char (progn
6900 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6901 (read-char-exclusive)))
6902 (cmd (cdr (assoc char
6903 '((?d . insert-diary-entry)
6904 (?w . insert-weekly-diary-entry)
6905 (?m . insert-monthly-diary-entry)
6906 (?y . insert-yearly-diary-entry)
6907 (?a . insert-anniversary-diary-entry)
6908 (?b . insert-block-diary-entry)
6909 (?c . insert-cyclic-diary-entry)))))
6910 (oldf (symbol-function 'calendar-cursor-to-date))
6911 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6912 (point (point))
6913 (mark (or (mark t) (point))))
6914 (unless cmd
6915 (error "No command associated with <%c>" char))
6916 (unless (and (get-text-property point 'day)
6917 (or (not (equal ?b char))
6918 (get-text-property mark 'day)))
6919 (error "Don't know which date to use for diary entry"))
6920 ;; We implement this by hacking the `calendar-cursor-to-date' function
6921 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6922 (let ((calendar-mark-ring
6923 (list (calendar-gregorian-from-absolute
6924 (or (get-text-property mark 'day)
6925 (get-text-property point 'day))))))
6926 (unwind-protect
6927 (progn
6928 (fset 'calendar-cursor-to-date
6929 (lambda (&optional error dummy)
6930 (calendar-gregorian-from-absolute
6931 (get-text-property point 'day))))
6932 (call-interactively cmd))
6933 (fset 'calendar-cursor-to-date oldf))))))
6935 (defun org-agenda-execute-calendar-command (cmd)
6936 "Execute a calendar command from the agenda, with the date associated to
6937 the cursor position."
6938 (org-agenda-check-type t 'agenda 'timeline)
6939 (require 'diary-lib)
6940 (unless (get-text-property (point) 'day)
6941 (error "Don't know which date to use for calendar command"))
6942 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
6943 (point (point))
6944 (date (calendar-gregorian-from-absolute
6945 (get-text-property point 'day)))
6946 ;; the following 2 vars are needed in the calendar
6947 (displayed-month (car date))
6948 (displayed-year (nth 2 date)))
6949 (unwind-protect
6950 (progn
6951 (fset 'calendar-cursor-to-date
6952 (lambda (&optional error dummy)
6953 (calendar-gregorian-from-absolute
6954 (get-text-property point 'day))))
6955 (call-interactively cmd))
6956 (fset 'calendar-cursor-to-date oldf))))
6958 (defun org-agenda-phases-of-moon ()
6959 "Display the phases of the moon for the 3 months around the cursor date."
6960 (interactive)
6961 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
6963 (defun org-agenda-holidays ()
6964 "Display the holidays for the 3 months around the cursor date."
6965 (interactive)
6966 (org-agenda-execute-calendar-command 'list-calendar-holidays))
6968 (defvar calendar-longitude)
6969 (defvar calendar-latitude)
6970 (defvar calendar-location-name)
6972 (defun org-agenda-sunrise-sunset (arg)
6973 "Display sunrise and sunset for the cursor date.
6974 Latitude and longitude can be specified with the variables
6975 `calendar-latitude' and `calendar-longitude'. When called with prefix
6976 argument, latitude and longitude will be prompted for."
6977 (interactive "P")
6978 (require 'solar)
6979 (let ((calendar-longitude (if arg nil calendar-longitude))
6980 (calendar-latitude (if arg nil calendar-latitude))
6981 (calendar-location-name
6982 (if arg "the given coordinates" calendar-location-name)))
6983 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
6985 (defun org-agenda-goto-calendar ()
6986 "Open the Emacs calendar with the date at the cursor."
6987 (interactive)
6988 (org-agenda-check-type t 'agenda 'timeline)
6989 (let* ((day (or (get-text-property (point) 'day)
6990 (error "Don't know which date to open in calendar")))
6991 (date (calendar-gregorian-from-absolute day))
6992 (calendar-move-hook nil)
6993 (calendar-view-holidays-initially-flag nil)
6994 (calendar-view-diary-initially-flag nil)
6995 (view-calendar-holidays-initially nil)
6996 (view-diary-entries-initially nil))
6997 (calendar)
6998 (calendar-goto-date date)))
7000 ;;;###autoload
7001 (defun org-calendar-goto-agenda ()
7002 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7003 This is a command that has to be installed in `calendar-mode-map'."
7004 (interactive)
7005 (org-agenda-list nil (calendar-absolute-from-gregorian
7006 (calendar-cursor-to-date))
7007 nil))
7009 (defun org-agenda-convert-date ()
7010 (interactive)
7011 (org-agenda-check-type t 'agenda 'timeline)
7012 (let ((day (get-text-property (point) 'day))
7013 date s)
7014 (unless day
7015 (error "Don't know which date to convert"))
7016 (setq date (calendar-gregorian-from-absolute day))
7017 (setq s (concat
7018 "Gregorian: " (calendar-date-string date) "\n"
7019 "ISO: " (calendar-iso-date-string date) "\n"
7020 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7021 "Julian: " (calendar-julian-date-string date) "\n"
7022 "Astron. JD: " (calendar-astro-date-string date)
7023 " (Julian date number at noon UTC)\n"
7024 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7025 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7026 "French: " (calendar-french-date-string date) "\n"
7027 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7028 "Mayan: " (calendar-mayan-date-string date) "\n"
7029 "Coptic: " (calendar-coptic-date-string date) "\n"
7030 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7031 "Persian: " (calendar-persian-date-string date) "\n"
7032 "Chinese: " (calendar-chinese-date-string date) "\n"))
7033 (with-output-to-temp-buffer "*Dates*"
7034 (princ s))
7035 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7037 ;;; Bulk commands
7039 (defvar org-agenda-bulk-marked-entries nil
7040 "List of markers that refer to marked entries in the agenda.")
7042 (defun org-agenda-bulk-marked-p ()
7043 (eq (get-char-property (point-at-bol) 'type)
7044 'org-marked-entry-overlay))
7046 (defun org-agenda-bulk-mark ()
7047 "Mark the entry at point for future bulk action."
7048 (interactive)
7049 (org-agenda-check-no-diary)
7050 (let* ((m (org-get-at-bol 'org-hd-marker))
7052 (unless (org-agenda-bulk-marked-p)
7053 (unless m (error "Nothing to mark at point"))
7054 (push m org-agenda-bulk-marked-entries)
7055 (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7056 (org-overlay-display ov "> "
7057 (org-get-todo-face "TODO")
7058 'evaporate)
7059 (org-overlay-put ov 'type 'org-marked-entry-overlay))
7060 (beginning-of-line 2)
7061 (message "%d entries marked for bulk action"
7062 (length org-agenda-bulk-marked-entries))))
7064 (defun org-agenda-bulk-unmark ()
7065 "Unmark the entry at point for future bulk action."
7066 (interactive)
7067 (when (org-agenda-bulk-marked-p)
7068 (org-agenda-bulk-remove-overlays
7069 (point-at-bol) (+ 2 (point-at-bol)))
7070 (setq org-agenda-bulk-marked-entries
7071 (delete (org-get-at-bol 'org-hd-marker)
7072 org-agenda-bulk-marked-entries)))
7073 (beginning-of-line 2)
7074 (message "%d entries marked for bulk action"
7075 (length org-agenda-bulk-marked-entries)))
7077 (defun org-agenda-bulk-toggle ()
7078 "Toggle marking the entry at point for bulk action."
7079 (interactive)
7080 (if (org-agenda-bulk-marked-p)
7081 (org-agenda-bulk-unmark)
7082 (org-agenda-bulk-mark)))
7084 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7085 "Remove the mark overlays between BEG and END in the agenda buffer.
7086 BEG and END default to the buffer limits.
7088 This only removes the overlays, it does not remove the markers
7089 from the list in `org-agenda-bulk-marked-entries'."
7090 (interactive)
7091 (mapc (lambda (ov)
7092 (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
7093 (org-delete-overlay ov)))
7094 (org-overlays-in (or beg (point-min)) (or end (point-max)))))
7096 (defun org-agenda-bulk-remove-all-marks ()
7097 "Remove all marks in the agenda buffer.
7098 This will remove the markers, and the overlays."
7099 (interactive)
7100 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7101 (setq org-agenda-bulk-marked-entries nil)
7102 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7104 (defun org-agenda-bulk-action ()
7105 "Execute an remote-editing action on all marked entries."
7106 (interactive)
7107 (unless org-agenda-bulk-marked-entries
7108 (error "No entries are marked"))
7109 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
7110 (let* ((action (read-char-exclusive))
7111 (entries (reverse org-agenda-bulk-marked-entries))
7112 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7113 (cond
7114 ((equal action ?$)
7115 (setq cmd '(org-agenda-archive)))
7117 ((equal action ?A)
7118 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7120 ((member action '(?r ?w))
7121 (setq rfloc (org-refile-get-location
7122 "Refile to: "
7123 (marker-buffer (car org-agenda-bulk-marked-entries))
7124 org-refile-allow-creating-parent-nodes))
7125 (setcar (nthcdr 3 rfloc)
7126 (move-marker (make-marker) (nth 3 rfloc)
7127 (or (get-file-buffer (nth 1 rfloc))
7128 (find-buffer-visiting (nth 1 rfloc))
7129 (error "This should not happen"))))
7131 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
7133 ((equal action ?t)
7134 (setq state (org-icompleting-read
7135 "Todo state: "
7136 (with-current-buffer (marker-buffer (car entries))
7137 (mapcar 'list org-todo-keywords-1))))
7138 (setq cmd `(let ((org-inhibit-blocking t)
7139 (org-inhibit-logging 'note))
7140 (org-agenda-todo ,state))))
7142 ((memq action '(?- ?+))
7143 (setq tag (org-icompleting-read
7144 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7145 (with-current-buffer (marker-buffer (car entries))
7146 (delq nil
7147 (mapcar (lambda (x)
7148 (if (stringp (car x)) x)) org-tag-alist)))))
7149 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
7151 ((memq action '(?s ?d))
7152 (let* ((date (org-read-date
7153 nil nil nil
7154 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to")))
7155 (ans org-read-date-final-answer)
7156 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
7157 (setq cmd `(let* ((bound (fboundp 'read-string))
7158 (old (and bound (symbol-function 'read-string))))
7159 (unwind-protect
7160 (progn
7161 (fset 'read-string (lambda (&rest ignore) ,ans))
7162 (call-interactively ',c1))
7163 (if bound
7164 (fset 'read-string old)
7165 (fmakunbound 'read-string)))))))
7166 (t (error "Invalid bulk action")))
7168 ;; Sort the markers, to make sure that parents are handled before children
7169 (setq entries (sort entries
7170 (lambda (a b)
7171 (cond
7172 ((equal (marker-buffer a) (marker-buffer b))
7173 (< (marker-position a) (marker-position b)))
7175 (string< (buffer-name (marker-buffer a))
7176 (buffer-name (marker-buffer b))))))))
7178 ;; Now loop over all markers and apply cmd
7179 (while (setq e (pop entries))
7180 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
7181 (if (not pos)
7182 (progn (message "Skipping removed entry at %s" e)
7183 (setq cntskip (1+ cntskip)))
7184 (goto-char pos)
7185 (eval cmd)
7186 (setq org-agenda-bulk-marked-entries
7187 (delete e org-agenda-bulk-marked-entries))
7188 (setq cnt (1+ cnt))))
7189 (setq org-agenda-bulk-marked-entries nil)
7190 (org-agenda-bulk-remove-all-marks)
7191 (message "Acted on %d entries%s"
7193 (if (= cntskip 0)
7195 (format ", skipped %d (disappeared before their turn)"
7196 cntskip)))))
7198 ;;; Flagging notes
7200 (defun org-agenda-show-the-flagging-note ()
7201 "Display the flagging note in the other window.
7202 When called a second time in direct sequence, offer to remove the FLAGGING
7203 tag and (if present) the flagging note."
7204 (interactive)
7205 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
7206 (win (selected-window))
7207 note heading newhead)
7208 (unless hdmarker
7209 (error "No linked entry at point"))
7210 (if (and (eq this-command last-command)
7211 (y-or-n-p "Unflag and remove any flagging note? "))
7212 (progn
7213 (org-agenda-remove-flag hdmarker)
7214 (let ((win (get-buffer-window "*Flagging Note*")))
7215 (and win (delete-window win)))
7216 (message "Entry unflaged"))
7217 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
7218 (unless note
7219 (error "No flagging note"))
7220 (org-kill-new note)
7221 (org-switch-to-buffer-other-window "*Flagging Note*")
7222 (erase-buffer)
7223 (insert note)
7224 (goto-char (point-min))
7225 (while (re-search-forward "\\\\n" nil t)
7226 (replace-match "\n" t t))
7227 (goto-char (point-min))
7228 (select-window win)
7229 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
7231 (defun org-agenda-remove-flag (marker)
7232 "Remove the FLAGGED tag and any flagging note in the entry."
7233 (let (newhead)
7234 (org-with-point-at marker
7235 (org-toggle-tag "FLAGGED" 'off)
7236 (org-entry-delete nil "THEFLAGGINGNOTE")
7237 (setq newhead (org-get-heading)))
7238 (org-agenda-change-all-lines newhead marker)
7239 (message "Entry unflaged")))
7241 (defun org-agenda-get-any-marker (&optional pos)
7242 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7243 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7245 ;;; Appointment reminders
7247 (defvar appt-time-msg-list)
7249 ;;;###autoload
7250 (defun org-agenda-to-appt (&optional refresh filter)
7251 "Activate appointments found in `org-agenda-files'.
7252 With a \\[universal-argument] prefix, refresh the list of
7253 appointments.
7255 If FILTER is t, interactively prompt the user for a regular
7256 expression, and filter out entries that don't match it.
7258 If FILTER is a string, use this string as a regular expression
7259 for filtering entries out.
7261 FILTER can also be an alist with the car of each cell being
7262 either 'headline or 'category. For example:
7264 '((headline \"IMPORTANT\")
7265 (category \"Work\"))
7267 will only add headlines containing IMPORTANT or headlines
7268 belonging to the \"Work\" category."
7269 (interactive "P")
7270 (require 'calendar)
7271 (if refresh (setq appt-time-msg-list nil))
7272 (if (eq filter t)
7273 (setq filter (read-from-minibuffer "Regexp filter: ")))
7274 (let* ((cnt 0) ; count added events
7275 (org-agenda-new-buffers nil)
7276 (org-deadline-warning-days 0)
7277 (today (org-date-to-gregorian
7278 (time-to-days (current-time))))
7279 (org-agenda-restrict nil)
7280 (files (org-agenda-files 'unrestricted)) entries file)
7281 ;; Get all entries which may contain an appt
7282 (org-prepare-agenda-buffers files)
7283 (while (setq file (pop files))
7284 (setq entries
7285 (append entries
7286 (org-agenda-get-day-entries
7287 file today :timestamp :scheduled :deadline))))
7288 (setq entries (delq nil entries))
7289 ;; Map thru entries and find if we should filter them out
7290 (mapc
7291 (lambda(x)
7292 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7293 (cat (get-text-property 1 'org-category x))
7294 (tod (get-text-property 1 'time-of-day x))
7295 (ok (or (null filter)
7296 (and (stringp filter) (string-match filter evt))
7297 (and (listp filter)
7298 (or (string-match
7299 (cadr (assoc 'category filter)) cat)
7300 (string-match
7301 (cadr (assoc 'headline filter)) evt))))))
7302 ;; FIXME: Shall we remove text-properties for the appt text?
7303 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7304 (when (and ok tod)
7305 (setq tod (concat "00" (number-to-string tod))
7306 tod (when (string-match
7307 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7308 (concat (match-string 1 tod) ":"
7309 (match-string 2 tod))))
7310 (appt-add tod evt)
7311 (setq cnt (1+ cnt))))) entries)
7312 (org-release-buffers org-agenda-new-buffers)
7313 (if (eq cnt 0)
7314 (message "No event to add")
7315 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7317 (defun org-agenda-todayp (date)
7318 "Does DATE mean today, when considering `org-extend-today-until'?"
7319 (let (today h)
7320 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7321 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7322 (setq h (nth 2 (decode-time (current-time))))
7323 (or (and (>= h org-extend-today-until)
7324 (= date today))
7325 (and (< h org-extend-today-until)
7326 (= date (1- today))))))
7328 (provide 'org-agenda)
7330 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7332 ;;; org-agenda.el ends here