Release 7.3
[org-mode/org-mode-NeilSmithlineMods.git] / lisp / org-agenda.el
blob1c9d6d4a3de8b2384abaf4bea10c6d50ca2bc00b
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 7.3
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))
37 (declare-function diary-add-to-list "diary-lib"
38 (date string specifier &optional marker globcolor literal))
39 (declare-function calendar-absolute-from-iso "cal-iso" (date))
40 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
41 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
42 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
43 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
44 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
45 (declare-function calendar-french-date-string "cal-french" (&optional date))
46 (declare-function calendar-goto-date "cal-move" (date))
47 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
48 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
49 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
50 (declare-function calendar-iso-from-absolute "cal-iso" (date))
51 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
52 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
53 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
54 (declare-function org-datetree-find-date-create "org-datetree"
55 (date &optional keep-restriction))
56 (declare-function org-columns-quit "org-colview" ())
57 (declare-function diary-date-display-form "diary-lib" (&optional type))
58 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
59 (declare-function org-habit-insert-consistency-graphs
60 "org-habit" (&optional line))
61 (declare-function org-is-habit-p "org-habit" (&optional pom))
62 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
63 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
64 (defvar calendar-mode-map)
65 (defvar org-clock-current-task) ; defined in org-clock.el
66 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
67 (defvar org-habit-show-habits)
68 (defvar org-habit-show-habits-only-for-today)
70 ;; Defined somewhere in this file, but used before definition.
71 (defvar org-agenda-buffer-name)
72 (defvar org-agenda-overriding-header)
73 (defvar org-agenda-title-append nil)
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 the variables `org-agenda-entry-text-mode'
147 and `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 (defcustom org-agenda-persistent-filter nil
202 "When set, keep filters from one agenda view to the next."
203 :group 'org-agenda
204 :type 'boolean)
206 (defgroup org-agenda-custom-commands nil
207 "Options concerning agenda views in Org-mode."
208 :tag "Org Agenda Custom Commands"
209 :group 'org-agenda)
211 (defconst org-sorting-choice
212 '(choice
213 (const time-up) (const time-down)
214 (const category-keep) (const category-up) (const category-down)
215 (const tag-down) (const tag-up)
216 (const priority-up) (const priority-down)
217 (const todo-state-up) (const todo-state-down)
218 (const effort-up) (const effort-down)
219 (const habit-up) (const habit-down)
220 (const alpha-up) (const alpha-down)
221 (const user-defined-up) (const user-defined-down))
222 "Sorting choices.")
224 (defconst org-agenda-custom-commands-local-options
225 `(repeat :tag "Local settings for this command. Remember to quote values"
226 (choice :tag "Setting"
227 (list :tag "Heading for this block"
228 (const org-agenda-overriding-header)
229 (string :tag "Headline"))
230 (list :tag "Files to be searched"
231 (const org-agenda-files)
232 (list
233 (const :format "" quote)
234 (repeat (file))))
235 (list :tag "Sorting strategy"
236 (const org-agenda-sorting-strategy)
237 (list
238 (const :format "" quote)
239 (repeat
240 ,org-sorting-choice)))
241 (list :tag "Prefix format"
242 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
243 (string))
244 (list :tag "Number of days in agenda"
245 (const org-agenda-ndays)
246 (integer :value 1))
247 (list :tag "Fixed starting date"
248 (const org-agenda-start-day)
249 (string :value "2007-11-01"))
250 (list :tag "Start on day of week"
251 (const org-agenda-start-on-weekday)
252 (choice :value 1
253 (const :tag "Today" nil)
254 (integer :tag "Weekday No.")))
255 (list :tag "Include data from diary"
256 (const org-agenda-include-diary)
257 (boolean))
258 (list :tag "Deadline Warning days"
259 (const org-deadline-warning-days)
260 (integer :value 1))
261 (list :tag "Tags filter preset"
262 (const org-agenda-filter-preset)
263 (list
264 (const :format "" quote)
265 (repeat
266 (string :tag "+tag or -tag"))))
267 (list :tag "Set daily/weekly entry types"
268 (const org-agenda-entry-types)
269 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
270 (const :deadline)
271 (const :scheduled)
272 (const :timestamp)
273 (const :sexp)))
274 (list :tag "Standard skipping condition"
275 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
276 (const org-agenda-skip-function)
277 (list
278 (const :format "" quote)
279 (list
280 (choice
281 :tag "Skipping range"
282 (const :tag "Skip entry" org-agenda-skip-entry-if)
283 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
284 (repeat :inline t :tag "Conditions for skipping"
285 (choice
286 :tag "Condition type"
287 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
288 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
289 (list :tag "TODO state is" :inline t
290 (const 'todo)
291 (choice
292 (const :tag "any not-done state" 'todo)
293 (const :tag "any done state" 'done)
294 (const :tag "any state" 'any)
295 (list :tag "Keyword list"
296 (const :format "" quote)
297 (repeat (string :tag "Keyword")))))
298 (list :tag "TODO state is not" :inline t
299 (const 'nottodo)
300 (choice
301 (const :tag "any not-done state" 'todo)
302 (const :tag "any done state" 'done)
303 (const :tag "any state" 'any)
304 (list :tag "Keyword list"
305 (const :format "" quote)
306 (repeat (string :tag "Keyword")))))
307 (const :tag "scheduled" 'scheduled)
308 (const :tag "not scheduled" 'notscheduled)
309 (const :tag "deadline" 'deadline)
310 (const :tag "no deadline" 'notdeadline)
311 (const :tag "timestamp" 'timestamp)
312 (const :tag "no timestamp" 'nottimestamp))))))
313 (list :tag "Non-standard skipping condition"
314 :value (org-agenda-skip-function)
315 (const org-agenda-skip-function)
316 (sexp :tag "Function or form (quoted!)"))
317 (list :tag "Any variable"
318 (variable :tag "Variable")
319 (sexp :tag "Value (sexp)"))))
320 "Selection of examples for agenda command settings.
321 This will be spliced into the custom type of
322 `org-agenda-custom-commands'.")
325 (defcustom org-agenda-custom-commands nil
326 "Custom commands for the agenda.
327 These commands will be offered on the splash screen displayed by the
328 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
330 (key desc type match settings files)
332 key The key (one or more characters as a string) to be associated
333 with the command.
334 desc A description of the command, when omitted or nil, a default
335 description is built using MATCH.
336 type The command type, any of the following symbols:
337 agenda The daily/weekly agenda.
338 todo Entries with a specific TODO keyword, in all agenda files.
339 search Entries containing search words entry or headline.
340 tags Tags/Property/TODO match in all agenda files.
341 tags-todo Tags/P/T match in all agenda files, TODO entries only.
342 todo-tree Sparse tree of specific TODO keyword in *current* file.
343 tags-tree Sparse tree with all tags matches in *current* file.
344 occur-tree Occur sparse tree for *current* file.
345 ... A user-defined function.
346 match What to search for:
347 - a single keyword for TODO keyword searches
348 - a tags match expression for tags searches
349 - a word search expression for text searches.
350 - a regular expression for occur searches
351 For all other commands, this should be the empty string.
352 settings A list of option settings, similar to that in a let form, so like
353 this: ((opt1 val1) (opt2 val2) ...). The values will be
354 evaluated at the moment of execution, so quote them when needed.
355 files A list of files file to write the produced agenda buffer to
356 with the command `org-store-agenda-views'.
357 If a file name ends in \".html\", an HTML version of the buffer
358 is written out. If it ends in \".ps\", a postscript version is
359 produced. Otherwise, only the plain text is written to the file.
361 You can also define a set of commands, to create a composite agenda buffer.
362 In this case, an entry looks like this:
364 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
366 where
368 desc A description string to be displayed in the dispatcher menu.
369 cmd An agenda command, similar to the above. However, tree commands
370 are no allowed, but instead you can get agenda and global todo list.
371 So valid commands for a set are:
372 (agenda \"\" settings)
373 (alltodo \"\" settings)
374 (stuck \"\" settings)
375 (todo \"match\" settings files)
376 (search \"match\" settings files)
377 (tags \"match\" settings files)
378 (tags-todo \"match\" settings files)
380 Each command can carry a list of options, and another set of options can be
381 given for the whole set of commands. Individual command options take
382 precedence over the general options.
384 When using several characters as key to a command, the first characters
385 are prefix commands. For the dispatcher to display useful information, you
386 should provide a description for the prefix, like
388 (setq org-agenda-custom-commands
389 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
390 (\"hl\" tags \"+HOME+Lisa\")
391 (\"hp\" tags \"+HOME+Peter\")
392 (\"hk\" tags \"+HOME+Kim\")))"
393 :group 'org-agenda-custom-commands
394 :type `(repeat
395 (choice :value ("x" "Describe command here" tags "" nil)
396 (list :tag "Single command"
397 (string :tag "Access Key(s) ")
398 (option (string :tag "Description"))
399 (choice
400 (const :tag "Agenda" agenda)
401 (const :tag "TODO list" alltodo)
402 (const :tag "Search words" search)
403 (const :tag "Stuck projects" stuck)
404 (const :tag "Tags/Property match (all agenda files)" tags)
405 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
406 (const :tag "TODO keyword search (all agenda files)" todo)
407 (const :tag "Tags sparse tree (current buffer)" tags-tree)
408 (const :tag "TODO keyword tree (current buffer)" todo-tree)
409 (const :tag "Occur tree (current buffer)" occur-tree)
410 (sexp :tag "Other, user-defined function"))
411 (string :tag "Match (only for some commands)")
412 ,org-agenda-custom-commands-local-options
413 (option (repeat :tag "Export" (file :tag "Export to"))))
414 (list :tag "Command series, all agenda files"
415 (string :tag "Access Key(s)")
416 (string :tag "Description ")
417 (repeat :tag "Component"
418 (choice
419 (list :tag "Agenda"
420 (const :format "" agenda)
421 (const :tag "" :format "" "")
422 ,org-agenda-custom-commands-local-options)
423 (list :tag "TODO list (all keywords)"
424 (const :format "" alltodo)
425 (const :tag "" :format "" "")
426 ,org-agenda-custom-commands-local-options)
427 (list :tag "Search words"
428 (const :format "" search)
429 (string :tag "Match")
430 ,org-agenda-custom-commands-local-options)
431 (list :tag "Stuck projects"
432 (const :format "" stuck)
433 (const :tag "" :format "" "")
434 ,org-agenda-custom-commands-local-options)
435 (list :tag "Tags search"
436 (const :format "" tags)
437 (string :tag "Match")
438 ,org-agenda-custom-commands-local-options)
439 (list :tag "Tags search, TODO entries only"
440 (const :format "" tags-todo)
441 (string :tag "Match")
442 ,org-agenda-custom-commands-local-options)
443 (list :tag "TODO keyword search"
444 (const :format "" todo)
445 (string :tag "Match")
446 ,org-agenda-custom-commands-local-options)
447 (list :tag "Other, user-defined function"
448 (symbol :tag "function")
449 (string :tag "Match")
450 ,org-agenda-custom-commands-local-options)))
452 (repeat :tag "Settings for entire command set"
453 (list (variable :tag "Any variable")
454 (sexp :tag "Value")))
455 (option (repeat :tag "Export" (file :tag "Export to"))))
456 (cons :tag "Prefix key documentation"
457 (string :tag "Access Key(s)")
458 (string :tag "Description ")))))
460 (defcustom org-agenda-query-register ?o
461 "The register holding the current query string.
462 The purpose of this is that if you construct a query string interactively,
463 you can then use it to define a custom command."
464 :group 'org-agenda-custom-commands
465 :type 'character)
467 (defcustom org-stuck-projects
468 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
469 "How to identify stuck projects.
470 This is a list of four items:
471 1. A tags/todo/property matcher string that is used to identify a project.
472 See the manual for a description of tag and property searches.
473 The entire tree below a headline matched by this is considered one project.
474 2. A list of TODO keywords identifying non-stuck projects.
475 If the project subtree contains any headline with one of these todo
476 keywords, the project is considered to be not stuck. If you specify
477 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
478 3. A list of tags identifying non-stuck projects.
479 If the project subtree contains any headline with one of these tags,
480 the project is considered to be not stuck. If you specify \"*\" as
481 a tag, any tag will mark the project unstuck. Note that this is about
482 the explicit presence of a tag somewhere in the subtree, inherited
483 tags to not count here. If inherited tags make a project not stuck,
484 use \"-TAG\" in the tags part of the matcher under (1.) above.
485 4. An arbitrary regular expression matching non-stuck projects.
487 If the project turns out to be not stuck, search continues also in the
488 subtree to see if any of the subtasks have project status.
490 See also the variable `org-tags-match-list-sublevels' which applies
491 to projects matched by this search as well.
493 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
494 or `C-c a #' to produce the list."
495 :group 'org-agenda-custom-commands
496 :type '(list
497 (string :tag "Tags/TODO match to identify a project")
498 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
499 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
500 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
502 (defcustom org-agenda-filter-effort-default-operator "<"
503 "The default operator for effort estimate filtering.
504 If you select an effort estimate limit without first pressing an operator,
505 this one will be used."
506 :group 'org-agenda-custom-commands
507 :type '(choice (const :tag "less or equal" "<")
508 (const :tag "greater or equal"">")
509 (const :tag "equal" "=")))
511 (defgroup org-agenda-skip nil
512 "Options concerning skipping parts of agenda files."
513 :tag "Org Agenda Skip"
514 :group 'org-agenda)
515 (defgroup org-agenda-daily/weekly nil
516 "Options concerning the daily/weekly agenda."
517 :tag "Org Agenda Daily/Weekly"
518 :group 'org-agenda)
519 (defgroup org-agenda-todo-list nil
520 "Options concerning the global todo list agenda view."
521 :tag "Org Agenda Todo List"
522 :group 'org-agenda)
523 (defgroup org-agenda-match-view nil
524 "Options concerning the general tags/property/todo match agenda view."
525 :tag "Org Agenda Match View"
526 :group 'org-agenda)
527 (defgroup org-agenda-search-view nil
528 "Options concerning the general tags/property/todo match agenda view."
529 :tag "Org Agenda Match View"
530 :group 'org-agenda)
532 (defvar org-agenda-archives-mode nil
533 "Non-nil means the agenda will include archived items.
534 If this is the symbol `trees', trees in the selected agenda scope
535 that are marked with the ARCHIVE tag will be included anyway. When this is
536 t, also all archive files associated with the current selection of agenda
537 files will be included.")
539 (defcustom org-agenda-skip-comment-trees t
540 "Non-nil means skip trees that start with the COMMENT keyword.
541 When nil, these trees are also scanned by agenda commands."
542 :group 'org-agenda-skip
543 :type 'boolean)
545 (defcustom org-agenda-todo-list-sublevels t
546 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
547 When nil, the sublevels of a TODO entry are not checked, resulting in
548 potentially much shorter TODO lists."
549 :group 'org-agenda-skip
550 :group 'org-agenda-todo-list
551 :type 'boolean)
553 (defcustom org-agenda-todo-ignore-with-date nil
554 "Non-nil means don't show entries with a date in the global todo list.
555 You can use this if you prefer to mark mere appointments with a TODO keyword,
556 but don't want them to show up in the TODO list.
557 When this is set, it also covers deadlines and scheduled items, the settings
558 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
559 will be ignored.
560 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
561 :group 'org-agenda-skip
562 :group 'org-agenda-todo-list
563 :type 'boolean)
565 (defcustom org-agenda-todo-ignore-scheduled nil
566 "Non-nil means, ignore some scheduled TODO items when making TODO list.
567 This applies when creating the global todo list.
568 Valid values are:
570 past Don't show entries scheduled today or in the past.
572 future Don't show entries scheduled in the future.
573 The idea behind this is that by scheduling it, you don't want to
574 think about it until the scheduled date.
576 all Don't show any scheduled entries in the global todo list.
577 The idea behind this is that by scheduling it, you have already
578 \"taken care\" of this item.
580 t Same as `all', for backward compatibility.
582 See also `org-agenda-todo-ignore-with-date'.
583 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
584 to make his option also apply to the tags-todo list."
585 :group 'org-agenda-skip
586 :group 'org-agenda-todo-list
587 :type '(choice
588 (const :tag "Ignore future-scheduled todos" future)
589 (const :tag "Ignore past- or present-scheduled todos" past)
590 (const :tag "Ignore all scheduled todos" all)
591 (const :tag "Ignore all scheduled todos (compatibility)" t)
592 (const :tag "Show scheduled todos" nil)))
594 (defcustom org-agenda-todo-ignore-deadlines nil
595 "Non-nil means ignore some deadlined TODO items when making TODO list.
596 There are different motivations for using different values, please think
597 carefully when configuring this variable.
599 This applies when creating the global todo list.
600 Valid values are:
602 near Don't show near deadline entries. A deadline is near when it is
603 closer than `org-deadline-warning-days' days. The idea behind this
604 is that such items will appear in the agenda anyway.
606 far Don't show TODO entries where a deadline has been defined, but
607 the deadline is not near. This is useful if you don't want to
608 use the todo list to figure out what to do now.
610 past Don't show entries with a deadline timestamp for today or in the past.
612 future Don't show entries with a deadline timestamp in the future, not even
613 when they become `near' ones. Use it with caution.
615 all Ignore all TODO entries that do have a deadline.
617 t Same as `near', for backward compatibility.
619 See also `org-agenda-todo-ignore-with-date'.
620 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
621 to make his option also apply to the tags-todo list."
622 :group 'org-agenda-skip
623 :group 'org-agenda-todo-list
624 :type '(choice
625 (const :tag "Ignore near deadlines" near)
626 (const :tag "Ignore near deadlines (compatibility)" t)
627 (const :tag "Ignore far deadlines" far)
628 (const :tag "Ignore all TODOs with a deadlines" all)
629 (const :tag "Show all TODOs, even if they have a deadline" nil)))
631 (defcustom org-agenda-tags-todo-honor-ignore-options nil
632 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
633 The variables
634 `org-agenda-todo-ignore-with-date',
635 `org-agenda-todo-ignore-scheduled'
636 `org-agenda-todo-ignore-deadlines'
637 make the global TODO list skip entries that have time stamps of certain
638 kinds. If this option is set, the same options will also apply for the
639 tags-todo search, which is the general tags/property matcher
640 restricted to unfinished TODO entries only."
641 :group 'org-agenda-skip
642 :group 'org-agenda-todo-list
643 :group 'org-agenda-match-view
644 :type 'boolean)
646 (defcustom org-agenda-skip-scheduled-if-done nil
647 "Non-nil means don't show scheduled items in agenda when they are done.
648 This is relevant for the daily/weekly agenda, not for the TODO list. And
649 it applies only to the actual date of the scheduling. Warnings about
650 an item with a past scheduling dates are always turned off when the item
651 is DONE."
652 :group 'org-agenda-skip
653 :group 'org-agenda-daily/weekly
654 :type 'boolean)
656 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
657 "Non-nil means skip scheduling line if same entry shows because of deadline.
658 In the agenda of today, an entry can show up multiple times because
659 it is both scheduled and has a nearby deadline, and maybe a plain time
660 stamp as well.
661 When this variable is t, then only the deadline is shown and the fact that
662 the entry is scheduled today or was scheduled previously is not shown.
663 When this variable is nil, the entry will be shown several times. When
664 the variable is the symbol `not-today', then skip scheduled previously,
665 but not scheduled today."
666 :group 'org-agenda-skip
667 :group 'org-agenda-daily/weekly
668 :type '(choice
669 (const :tag "Never" nil)
670 (const :tag "Always" t)
671 (const :tag "Not when scheduled today" not-today)))
673 (defcustom org-agenda-skip-deadline-if-done nil
674 "Non-nil means don't show deadlines when the corresponding item is done.
675 When nil, the deadline is still shown and should give you a happy feeling.
676 This is relevant for the daily/weekly agenda. And it applied only to the
677 actually date of the deadline. Warnings about approaching and past-due
678 deadlines are always turned off when the item is DONE."
679 :group 'org-agenda-skip
680 :group 'org-agenda-daily/weekly
681 :type 'boolean)
683 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
684 "Non-nil means skip deadline prewarning when entry is also scheduled.
685 This will apply on all days where a prewarning for the deadline would
686 be shown, but not at the day when the entry is actually due. On that day,
687 the deadline will be shown anyway.
688 This variable may be set to nil, t, or a number which will then give
689 the number of days before the actual deadline when the prewarnings
690 should resume.
691 This can be used in a workflow where the first showing of the deadline will
692 trigger you to schedule it, and then you don't want to be reminded of it
693 because you will take care of it on the day when scheduled."
694 :group 'org-agenda-skip
695 :group 'org-agenda-daily/weekly
696 :type '(choice
697 (const :tag "Alwas show prewarning" nil)
698 (const :tag "Remove prewarning if entry is scheduled" t)
699 (integer :tag "Restart prewarning N days before deadline")))
701 (defcustom org-agenda-skip-additional-timestamps-same-entry t
702 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
703 When non-nil, after the search for timestamps has matched once in an
704 entry, the rest of the entry will not be searched."
705 :group 'org-agenda-skip
706 :type 'boolean)
708 (defcustom org-agenda-skip-timestamp-if-done nil
709 "Non-nil means don't select item by timestamp or -range if it is DONE."
710 :group 'org-agenda-skip
711 :group 'org-agenda-daily/weekly
712 :type 'boolean)
714 (defcustom org-agenda-dim-blocked-tasks t
715 "Non-nil means dim blocked tasks in the agenda display.
716 This causes some overhead during agenda construction, but if you
717 have turned on `org-enforce-todo-dependencies',
718 `org-enforce-todo-checkbox-dependencies', or any other blocking
719 mechanism, this will create useful feedback in the agenda.
721 Instead of t, this variable can also have the value `invisible'.
722 Then blocked tasks will be invisible and only become visible when
723 they become unblocked. An exemption to this behavior is when a task is
724 blocked because of unchecked checkboxes below it. Since checkboxes do
725 not show up in the agenda views, making this task invisible you remove any
726 trace from agenda views that there is something to do. Therefore, a task
727 that is blocked because of checkboxes will never be made invisible, it
728 will only be dimmed."
729 :group 'org-agenda-daily/weekly
730 :group 'org-agenda-todo-list
731 :type '(choice
732 (const :tag "Do not dim" nil)
733 (const :tag "Dim to a grey face" t)
734 (const :tag "Make invisible" invisible)))
736 (defcustom org-timeline-show-empty-dates 3
737 "Non-nil means `org-timeline' also shows dates without an entry.
738 When nil, only the days which actually have entries are shown.
739 When t, all days between the first and the last date are shown.
740 When an integer, show also empty dates, but if there is a gap of more than
741 N days, just insert a special line indicating the size of the gap."
742 :group 'org-agenda-skip
743 :type '(choice
744 (const :tag "None" nil)
745 (const :tag "All" t)
746 (integer :tag "at most")))
748 (defgroup org-agenda-startup nil
749 "Options concerning initial settings in the Agenda in Org Mode."
750 :tag "Org Agenda Startup"
751 :group 'org-agenda)
753 (defcustom org-agenda-menu-show-matcher t
754 "Non-nil menas show the match string in the agenda dispatcher menu.
755 When nil, the matcher string is not shown, but is put into the help-echo
756 property so than moving the mouse over the command shows it.
757 Setting it to nil is good if matcher strings are very long and/or if
758 you wnat to use two-column display (see `org-agenda-menu-two-column')."
759 :group 'org-agenda
760 :type 'boolean)
762 (defcustom org-agenda-menu-two-column nil
763 "Non-nil means, use two columns to show custom commands in the dispatcher.
764 If you use this, you probably want to set `org-agenda-menu-show-matcher'
765 to nil."
766 :group 'org-agenda
767 :type 'boolean)
769 (defcustom org-finalize-agenda-hook nil
770 "Hook run just before displaying an agenda buffer."
771 :group 'org-agenda-startup
772 :type 'hook)
774 (defcustom org-agenda-mouse-1-follows-link nil
775 "Non-nil means mouse-1 on a link will follow the link in the agenda.
776 A longer mouse click will still set point. Does not work on XEmacs.
777 Needs to be set before org.el is loaded."
778 :group 'org-agenda-startup
779 :type 'boolean)
781 (defcustom org-agenda-start-with-follow-mode nil
782 "The initial value of follow mode in a newly created agenda window."
783 :group 'org-agenda-startup
784 :type 'boolean)
786 (defcustom org-agenda-show-outline-path t
787 "Non-nil means show outline path in echo area after line motion."
788 :group 'org-agenda-startup
789 :type 'boolean)
791 (defcustom org-agenda-start-with-entry-text-mode nil
792 "The initial value of entry-text-mode in a newly created agenda window."
793 :group 'org-agenda-startup
794 :type 'boolean)
796 (defcustom org-agenda-entry-text-maxlines 5
797 "Number of text lines to be added when `E' is pressed in the agenda.
799 Note that this variable only used during agenda display. Add add entry text
800 when exporting the agenda, configure the variable
801 `org-agenda-add-entry-ext-maxlines'."
802 :group 'org-agenda
803 :type 'integer)
805 (defcustom org-agenda-entry-text-exclude-regexps nil
806 "List of regular expressions to clean up entry text.
807 The complete matches of all regular expressions in this list will be
808 removed from entry text before it is shown in the agenda."
809 :group 'org-agenda
810 :type '(repeat (regexp)))
812 (defvar org-agenda-entry-text-cleanup-hook nil
813 "Hook that is run after basic cleanup of entry text to be shown in agenda.
814 This cleanup is done in a temporary buffer, so the function may inspect and
815 change the entire buffer.
816 Some default stuff like drawers and scheduling/deadline dates will already
817 have been removed when this is called, as will any matches for regular
818 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
820 (defvar org-agenda-include-inactive-timestamps nil
821 "Non-nil means include inactive time stamps in agenda and timeline.")
823 (defgroup org-agenda-windows nil
824 "Options concerning the windows used by the Agenda in Org Mode."
825 :tag "Org Agenda Windows"
826 :group 'org-agenda)
828 (defcustom org-agenda-window-setup 'reorganize-frame
829 "How the agenda buffer should be displayed.
830 Possible values for this option are:
832 current-window Show agenda in the current window, keeping all other windows.
833 other-window Use `switch-to-buffer-other-window' to display agenda.
834 reorganize-frame Show only two windows on the current frame, the current
835 window and the agenda.
836 other-frame Use `switch-to-buffer-other-frame' to display agenda.
837 Also, when exiting the agenda, kill that frame.
838 See also the variable `org-agenda-restore-windows-after-quit'."
839 :group 'org-agenda-windows
840 :type '(choice
841 (const current-window)
842 (const other-frame)
843 (const other-window)
844 (const reorganize-frame)))
846 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
847 "The min and max height of the agenda window as a fraction of frame height.
848 The value of the variable is a cons cell with two numbers between 0 and 1.
849 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
850 :group 'org-agenda-windows
851 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
853 (defcustom org-agenda-restore-windows-after-quit nil
854 "Non-nil means restore window configuration open exiting agenda.
855 Before the window configuration is changed for displaying the agenda,
856 the current status is recorded. When the agenda is exited with
857 `q' or `x' and this option is set, the old state is restored. If
858 `org-agenda-window-setup' is `other-frame', the value of this
859 option will be ignored."
860 :group 'org-agenda-windows
861 :type 'boolean)
863 (defcustom org-agenda-ndays 7
864 "Number of days to include in overview display.
865 Should be 1 or 7.
866 Custom commands can set this variable in the options section."
867 :group 'org-agenda-daily/weekly
868 :type 'integer)
870 (defcustom org-agenda-start-on-weekday 1
871 "Non-nil means start the overview always on the specified weekday.
872 0 denotes Sunday, 1 denotes Monday etc.
873 When nil, always start on the current day.
874 Custom commands can set this variable in the options section."
875 :group 'org-agenda-daily/weekly
876 :type '(choice (const :tag "Today" nil)
877 (integer :tag "Weekday No.")))
879 (defcustom org-agenda-show-all-dates t
880 "Non-nil means `org-agenda' shows every day in the selected range.
881 When nil, only the days which actually have entries are shown."
882 :group 'org-agenda-daily/weekly
883 :type 'boolean)
885 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
886 "Format string for displaying dates in the agenda.
887 Used by the daily/weekly agenda and by the timeline. This should be
888 a format string understood by `format-time-string', or a function returning
889 the formatted date as a string. The function must take a single argument,
890 a calendar-style date list like (month day year)."
891 :group 'org-agenda-daily/weekly
892 :type '(choice
893 (string :tag "Format string")
894 (function :tag "Function")))
896 (defun org-agenda-format-date-aligned (date)
897 "Format a date string for display in the daily/weekly agenda, or timeline.
898 This function makes sure that dates are aligned for easy reading."
899 (require 'cal-iso)
900 (let* ((dayname (calendar-day-name date))
901 (day (cadr date))
902 (day-of-week (calendar-day-of-week date))
903 (month (car date))
904 (monthname (calendar-month-name month))
905 (year (nth 2 date))
906 (iso-week (org-days-to-iso-week
907 (calendar-absolute-from-gregorian date)))
908 (weekyear (cond ((and (= month 1) (>= iso-week 52))
909 (1- year))
910 ((and (= month 12) (<= iso-week 1))
911 (1+ year))
912 (t year)))
913 (weekstring (if (= day-of-week 1)
914 (format " W%02d" iso-week)
915 "")))
916 (format "%-10s %2d %s %4d%s"
917 dayname day monthname year weekstring)))
919 (defcustom org-agenda-time-leading-zero nil
920 "Non-nil means use leading zero for military times in agenda.
921 For example, 9:30am would become 09:30 rather than 9:30."
922 :group 'org-agenda-daily/weekly
923 :type 'boolean)
925 (defcustom org-agenda-weekend-days '(6 0)
926 "Which days are weekend?
927 These days get the special face `org-agenda-date-weekend' in the agenda
928 and timeline buffers."
929 :group 'org-agenda-daily/weekly
930 :type '(set :greedy t
931 (const :tag "Monday" 1)
932 (const :tag "Tuesday" 2)
933 (const :tag "Wednesday" 3)
934 (const :tag "Thursday" 4)
935 (const :tag "Friday" 5)
936 (const :tag "Saturday" 6)
937 (const :tag "Sunday" 0)))
939 (defcustom org-agenda-include-diary nil
940 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
941 Custom commands can set this variable in the options section."
942 :group 'org-agenda-daily/weekly
943 :type 'boolean)
945 (defcustom org-agenda-include-deadlines t
946 "If non-nil, include entries within their deadline warning period.
947 Custom commands can set this variable in the options section."
948 :group 'org-agenda-daily/weekly
949 :type 'boolean)
951 (defcustom org-agenda-include-all-todo nil
952 "Set means weekly/daily agenda will always contain all TODO entries.
953 The TODO entries will be listed at the top of the agenda, before
954 the entries for specific days.
955 This option is deprecated, it is better to define a block agenda instead."
956 :group 'org-agenda-daily/weekly
957 :type 'boolean)
959 (defcustom org-agenda-repeating-timestamp-show-all t
960 "Non-nil means show all occurrences of a repeating stamp in the agenda.
961 When nil, only one occurrence is shown, either today or the
962 nearest into the future."
963 :group 'org-agenda-daily/weekly
964 :type 'boolean)
966 (defcustom org-scheduled-past-days 10000
967 "No. of days to continue listing scheduled items that are not marked DONE.
968 When an item is scheduled on a date, it shows up in the agenda on this
969 day and will be listed until it is marked done for the number of days
970 given here."
971 :group 'org-agenda-daily/weekly
972 :type 'integer)
974 (defcustom org-agenda-log-mode-items '(closed clock)
975 "List of items that should be shown in agenda log mode.
976 This list may contain the following symbols:
978 closed Show entries that have been closed on that day.
979 clock Show entries that have received clocked time on that day.
980 state Show all logged state changes.
981 Note that instead of changing this variable, you can also press `C-u l' in
982 the agenda to display all available LOG items temporarily."
983 :group 'org-agenda-daily/weekly
984 :type '(set :greedy t (const closed) (const clock) (const state)))
986 (defcustom org-agenda-log-mode-add-notes t
987 "Non-nil means add first line of notes to log entries in agenda views.
988 If a log item like a state change or a clock entry is associated with
989 notes, the first line of these notes will be added to the entry in the
990 agenda display."
991 :group 'org-agenda-daily/weekly
992 :type 'boolean)
994 (defcustom org-agenda-start-with-log-mode nil
995 "The initial value of log-mode in a newly created agenda window."
996 :group 'org-agenda-startup
997 :group 'org-agenda-daily/weekly
998 :type 'boolean)
1000 (defcustom org-agenda-start-with-clockreport-mode nil
1001 "The initial value of clockreport-mode in a newly created agenda window."
1002 :group 'org-agenda-startup
1003 :group 'org-agenda-daily/weekly
1004 :type 'boolean)
1006 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1007 "Property list with parameters for the clocktable in clockreport mode.
1008 This is the display mode that shows a clock table in the daily/weekly
1009 agenda, the properties for this dynamic block can be set here.
1010 The usual clocktable parameters are allowed here, but you cannot set
1011 the properties :name, :tstart, :tend, :block, and :scope - these will
1012 be overwritten to make sure the content accurately reflects the
1013 current display in the agenda."
1014 :group 'org-agenda-daily/weekly
1015 :type 'plist)
1017 (defcustom org-agenda-search-view-always-boolean nil
1018 "Non-nil means the search string is interpreted as individual parts.
1020 The search string for search view can either be interpreted as a phrase,
1021 or as a list of snippets that define a boolean search for a number of
1022 strings.
1024 When this is non-nil, the string will be split on whitespace, and each
1025 snippet will be searched individually, and all must match in order to
1026 select an entry. A snippet is then a single string of non-white
1027 characters, or a string in double quotes, or a regexp in {} braces.
1028 If a snippet is preceded by \"-\", the snippet must *not* match.
1029 \"+\" is syntactic sugar for positive selection. Each snippet may
1030 be found as a full word or a partial word, but see the variable
1031 `org-agenda-search-view-force-full-words'.
1033 When this is nil, search will look for the entire search phrase as one,
1034 with each space character matching any amount of whitespace, including
1035 line breaks.
1037 Even when this is nil, you can still switch to Boolean search dynamically
1038 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1039 is a regexp marked with braces like \"{abc}\", this will also switch to
1040 boolean search."
1041 :group 'org-agenda-search-view
1042 :type 'boolean)
1044 (if (fboundp 'defvaralias)
1045 (defvaralias 'org-agenda-search-view-search-words-only
1046 'org-agenda-search-view-always-boolean))
1048 (defcustom org-agenda-search-view-force-full-words nil
1049 "Non-nil means, search words must be matches as complete words.
1050 When nil, they may also match part of a word."
1051 :group 'org-agenda-search-view
1052 :type 'boolean)
1054 (defgroup org-agenda-time-grid nil
1055 "Options concerning the time grid in the Org-mode Agenda."
1056 :tag "Org Agenda Time Grid"
1057 :group 'org-agenda)
1059 (defcustom org-agenda-search-headline-for-time t
1060 "Non-nil means search headline for a time-of-day.
1061 If the headline contains a time-of-day in one format or another, it will
1062 be used to sort the entry into the time sequence of items for a day.
1063 Some people have time stamps in the headline that refer to the creation
1064 time or so, and then this produces an unwanted side effect. If this is
1065 the case for your, use this variable to turn off searching the headline
1066 for a time."
1067 :group 'org-agenda-time-grid
1068 :type 'boolean)
1070 (defcustom org-agenda-use-time-grid t
1071 "Non-nil means show a time grid in the agenda schedule.
1072 A time grid is a set of lines for specific times (like every two hours between
1073 8:00 and 20:00). The items scheduled for a day at specific times are
1074 sorted in between these lines.
1075 For details about when the grid will be shown, and what it will look like, see
1076 the variable `org-agenda-time-grid'."
1077 :group 'org-agenda-time-grid
1078 :type 'boolean)
1080 (defcustom org-agenda-time-grid
1081 '((daily today require-timed)
1082 "----------------"
1083 (800 1000 1200 1400 1600 1800 2000))
1085 "The settings for time grid for agenda display.
1086 This is a list of three items. The first item is again a list. It contains
1087 symbols specifying conditions when the grid should be displayed:
1089 daily if the agenda shows a single day
1090 weekly if the agenda shows an entire week
1091 today show grid on current date, independent of daily/weekly display
1092 require-timed show grid only if at least one item has a time specification
1094 The second item is a string which will be placed behind the grid time.
1096 The third item is a list of integers, indicating the times that should have
1097 a grid line."
1098 :group 'org-agenda-time-grid
1099 :type
1100 '(list
1101 (set :greedy t :tag "Grid Display Options"
1102 (const :tag "Show grid in single day agenda display" daily)
1103 (const :tag "Show grid in weekly agenda display" weekly)
1104 (const :tag "Always show grid for today" today)
1105 (const :tag "Show grid only if any timed entries are present"
1106 require-timed)
1107 (const :tag "Skip grid times already present in an entry"
1108 remove-match))
1109 (string :tag "Grid String")
1110 (repeat :tag "Grid Times" (integer :tag "Time"))))
1112 (defgroup org-agenda-sorting nil
1113 "Options concerning sorting in the Org-mode Agenda."
1114 :tag "Org Agenda Sorting"
1115 :group 'org-agenda)
1117 (defcustom org-agenda-sorting-strategy
1118 '((agenda habit-down time-up priority-down category-keep)
1119 (todo priority-down category-keep)
1120 (tags priority-down category-keep)
1121 (search category-keep))
1122 "Sorting structure for the agenda items of a single day.
1123 This is a list of symbols which will be used in sequence to determine
1124 if an entry should be listed before another entry. The following
1125 symbols are recognized:
1127 time-up Put entries with time-of-day indications first, early first
1128 time-down Put entries with time-of-day indications first, late first
1129 category-keep Keep the default order of categories, corresponding to the
1130 sequence in `org-agenda-files'.
1131 category-up Sort alphabetically by category, A-Z.
1132 category-down Sort alphabetically by category, Z-A.
1133 tag-up Sort alphabetically by last tag, A-Z.
1134 tag-down Sort alphabetically by last tag, Z-A.
1135 priority-up Sort numerically by priority, high priority last.
1136 priority-down Sort numerically by priority, high priority first.
1137 todo-state-up Sort by todo state, tasks that are done last.
1138 todo-state-down Sort by todo state, tasks that are done first.
1139 effort-up Sort numerically by estimated effort, high effort last.
1140 effort-down Sort numerically by estimated effort, high effort first.
1141 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1142 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1143 habit-up Put entries that are habits first
1144 habit-down Put entries that are habits last
1145 alpha-up Sort headlines alphabetically
1146 alpha-down Sort headlines alphabetically, reversed
1148 The different possibilities will be tried in sequence, and testing stops
1149 if one comparison returns a \"not-equal\". For example, the default
1150 '(time-up category-keep priority-down)
1151 means: Pull out all entries having a specified time of day and sort them,
1152 in order to make a time schedule for the current day the first thing in the
1153 agenda listing for the day. Of the entries without a time indication, keep
1154 the grouped in categories, don't sort the categories, but keep them in
1155 the sequence given in `org-agenda-files'. Within each category sort by
1156 priority.
1158 Leaving out `category-keep' would mean that items will be sorted across
1159 categories by priority.
1161 Instead of a single list, this can also be a set of list for specific
1162 contents, with a context symbol in the car of the list, any of
1163 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1165 Custom commands can bind this variable in the options section."
1166 :group 'org-agenda-sorting
1167 :type `(choice
1168 (repeat :tag "General" ,org-sorting-choice)
1169 (list :tag "Individually"
1170 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1171 (repeat ,org-sorting-choice))
1172 (cons (const :tag "Strategy for TODO lists" todo)
1173 (repeat ,org-sorting-choice))
1174 (cons (const :tag "Strategy for Tags matches" tags)
1175 (repeat ,org-sorting-choice))
1176 (cons (const :tag "Strategy for search matches" search)
1177 (repeat ,org-sorting-choice)))))
1179 (defcustom org-agenda-cmp-user-defined nil
1180 "A function to define the comparison `user-defined'.
1181 This function must receive two arguments, agenda entry a and b.
1182 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1183 the user comparison, return nil.
1184 When this is defined, you can make `user-defined-up' and `user-defined-down'
1185 part of an agenda sorting strategy."
1186 :group 'org-agenda-sorting
1187 :type 'symbol)
1189 (defcustom org-sort-agenda-notime-is-late t
1190 "Non-nil means items without time are considered late.
1191 This is only relevant for sorting. When t, items which have no explicit
1192 time like 15:30 will be considered as 99:01, i.e. later than any items which
1193 do have a time. When nil, the default time is before 0:00. You can use this
1194 option to decide if the schedule for today should come before or after timeless
1195 agenda entries."
1196 :group 'org-agenda-sorting
1197 :type 'boolean)
1199 (defcustom org-sort-agenda-noeffort-is-high t
1200 "Non-nil means items without effort estimate are sorted as high effort.
1201 This also applies when filtering an agenda view with respect to the
1202 < or > effort operator. Then, tasks with no effort defined will be treated
1203 as tasks with high effort.
1204 When nil, such items are sorted as 0 minutes effort."
1205 :group 'org-agenda-sorting
1206 :type 'boolean)
1208 (defgroup org-agenda-line-format nil
1209 "Options concerning the entry prefix in the Org-mode agenda display."
1210 :tag "Org Agenda Line Format"
1211 :group 'org-agenda)
1213 (defcustom org-agenda-prefix-format
1214 '((agenda . " %-12:c%?-12t% s")
1215 (timeline . " % s")
1216 (todo . " %-12:c")
1217 (tags . " %-12:c")
1218 (search . " %-12:c"))
1219 "Format specifications for the prefix of items in the agenda views.
1220 An alist with four entries, for the different agenda types. The keys to the
1221 sublists are `agenda', `timeline', `todo', and `tags'. The values
1222 are format strings.
1223 This format works similar to a printf format, with the following meaning:
1225 %c the category of the item, \"Diary\" for entries from the diary, or
1226 as given by the CATEGORY keyword or derived from the file name.
1227 %T the *last* tag of the item. Last because inherited tags come
1228 first in the list.
1229 %t the time-of-day specification if one applies to the entry, in the
1230 format HH:MM
1231 %s Scheduling/Deadline information, a short string
1233 All specifiers work basically like the standard `%s' of printf, but may
1234 contain two additional characters: A question mark just after the `%' and
1235 a whitespace/punctuation character just before the final letter.
1237 If the first character after `%' is a question mark, the entire field
1238 will only be included if the corresponding value applies to the
1239 current entry. This is useful for fields which should have fixed
1240 width when present, but zero width when absent. For example,
1241 \"%?-12t\" will result in a 12 character time field if a time of the
1242 day is specified, but will completely disappear in entries which do
1243 not contain a time.
1245 If there is punctuation or whitespace character just before the final
1246 format letter, this character will be appended to the field value if
1247 the value is not empty. For example, the format \"%-12:c\" leads to
1248 \"Diary: \" if the category is \"Diary\". If the category were be
1249 empty, no additional colon would be inserted.
1251 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1252 - Indent the line with two space characters
1253 - Give the category in a 12 chars wide field, padded with whitespace on
1254 the right (because of `-'). Append a colon if there is a category
1255 (because of `:').
1256 - If there is a time-of-day, put it into a 12 chars wide field. If no
1257 time, don't put in an empty field, just skip it (because of '?').
1258 - Finally, put the scheduling information and append a whitespace.
1260 As another example, if you don't want the time-of-day of entries in
1261 the prefix, you could use:
1263 (setq org-agenda-prefix-format \" %-11:c% s\")
1265 See also the variables `org-agenda-remove-times-when-in-prefix' and
1266 `org-agenda-remove-tags'.
1268 Custom commands can set this variable in the options section."
1269 :type '(choice
1270 (string :tag "General format")
1271 (list :greedy t :tag "View dependent"
1272 (cons (const agenda) (string :tag "Format"))
1273 (cons (const timeline) (string :tag "Format"))
1274 (cons (const todo) (string :tag "Format"))
1275 (cons (const tags) (string :tag "Format"))
1276 (cons (const search) (string :tag "Format"))))
1277 :group 'org-agenda-line-format)
1279 (defvar org-prefix-format-compiled nil
1280 "The compiled version of the most recently used prefix format.
1281 See the variable `org-agenda-prefix-format'.")
1283 (defcustom org-agenda-todo-keyword-format "%-1s"
1284 "Format for the TODO keyword in agenda lines.
1285 Set this to something like \"%-12s\" if you want all TODO keywords
1286 to occupy a fixed space in the agenda display."
1287 :group 'org-agenda-line-format
1288 :type 'string)
1290 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1291 "Text preceding timerange entries in the agenda view.
1292 This is a list with two strings. The first applies when the range
1293 is entirely on one day. The second applies if the range spans several days.
1294 The strings may have two \"%d\" format specifiers which will be filled
1295 with the sequence number of the days, and the total number of days in the
1296 range, respectively."
1297 :group 'org-agenda-line-format
1298 :type '(list
1299 (string :tag "Deadline today ")
1300 (choice :tag "Deadline relative"
1301 (string :tag "Format string")
1302 (function))))
1304 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1305 "Text preceding scheduled items in the agenda view.
1306 This is a list with two strings. The first applies when the item is
1307 scheduled on the current day. The second applies when it has been scheduled
1308 previously, it may contain a %d indicating that this is the nth time that
1309 this item is scheduled, due to automatic rescheduling of unfinished items
1310 for the following day. So this number is one larger than the number of days
1311 that passed since this item was scheduled first."
1312 :group 'org-agenda-line-format
1313 :type '(list
1314 (string :tag "Scheduled today ")
1315 (string :tag "Scheduled previously")))
1317 (defcustom org-agenda-inactive-leader "["
1318 "Text preceding item pulled into the agenda by inactive time stamps.
1319 These entries are added to the agenda when pressing \"[\"."
1320 :group 'org-agenda-line-format
1321 :type '(list
1322 (string :tag "Scheduled today ")
1323 (string :tag "Scheduled previously")))
1325 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1326 "Text preceding deadline items in the agenda view.
1327 This is a list with two strings. The first applies when the item has its
1328 deadline on the current day. The second applies when it is in the past or
1329 in the future, it may contain %d to capture how many days away the deadline
1330 is (was)."
1331 :group 'org-agenda-line-format
1332 :type '(list
1333 (string :tag "Deadline today ")
1334 (choice :tag "Deadline relative"
1335 (string :tag "Format string")
1336 (function))))
1338 (defcustom org-agenda-remove-times-when-in-prefix t
1339 "Non-nil means remove duplicate time specifications in agenda items.
1340 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1341 time-of-day specification in a headline or diary entry is extracted and
1342 placed into the prefix. If this option is non-nil, the original specification
1343 \(a timestamp or -range, or just a plain time(range) specification like
1344 11:30-4pm) will be removed for agenda display. This makes the agenda less
1345 cluttered.
1346 The option can be t or nil. It may also be the symbol `beg', indicating
1347 that the time should only be removed when it is located at the beginning of
1348 the headline/diary entry."
1349 :group 'org-agenda-line-format
1350 :type '(choice
1351 (const :tag "Always" t)
1352 (const :tag "Never" nil)
1353 (const :tag "When at beginning of entry" beg)))
1355 (defcustom org-agenda-remove-timeranges-from-blocks nil
1356 "Non-nil means remove time ranges specifications in agenda
1357 items that span on several days."
1358 :group 'org-agenda-line-format
1359 :type 'boolean)
1361 (defcustom org-agenda-default-appointment-duration nil
1362 "Default duration for appointments that only have a starting time.
1363 When nil, no duration is specified in such cases.
1364 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1365 :group 'org-agenda-line-format
1366 :type '(choice
1367 (integer :tag "Minutes")
1368 (const :tag "No default duration")))
1370 (defcustom org-agenda-show-inherited-tags t
1371 "Non-nil means show inherited tags in each agenda line."
1372 :group 'org-agenda-line-format
1373 :type 'boolean)
1375 (defcustom org-agenda-hide-tags-regexp nil
1376 "Regular expression used to filter away specific tags in agenda views.
1377 This means that these tags will be present, but not be shown in the agenda
1378 line. Secondary filtering will still work on the hidden tags.
1379 Nil means don't hide any tags."
1380 :group 'org-agenda-line-format
1381 :type '(choice
1382 (const :tag "Hide none" nil)
1383 (string :tag "Regexp ")))
1385 (defcustom org-agenda-remove-tags nil
1386 "Non-nil means remove the tags from the headline copy in the agenda.
1387 When this is the symbol `prefix', only remove tags when
1388 `org-agenda-prefix-format' contains a `%T' specifier."
1389 :group 'org-agenda-line-format
1390 :type '(choice
1391 (const :tag "Always" t)
1392 (const :tag "Never" nil)
1393 (const :tag "When prefix format contains %T" prefix)))
1395 (if (fboundp 'defvaralias)
1396 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1397 'org-agenda-remove-tags))
1399 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1400 "Shift tags in agenda items to this column.
1401 If this number is positive, it specifies the column. If it is negative,
1402 it means that the tags should be flushright to that column. For example,
1403 -80 works well for a normal 80 character screen."
1404 :group 'org-agenda-line-format
1405 :type 'integer)
1407 (if (fboundp 'defvaralias)
1408 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1410 (defcustom org-agenda-fontify-priorities 'cookies
1411 "Non-nil means highlight low and high priorities in agenda.
1412 When t, the highest priority entries are bold, lowest priority italic.
1413 However, settings in `org-priority-faces' will overrule these faces.
1414 When this variable is the symbol `cookies', only fontify the
1415 cookies, not the entire task.
1416 This may also be an association list of priority faces, whose
1417 keys are the character values of `org-highest-priority',
1418 `org-default-priority', and `org-lowest-priority' (the default values
1419 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1420 color as a string, or a list like `(:background \"Red\")'.
1421 If it is a color, the variable `org-faces-easy-properties'
1422 determines if it is a foreground or a background color."
1423 :group 'org-agenda-line-format
1424 :type '(choice
1425 (const :tag "Never" nil)
1426 (const :tag "Defaults" t)
1427 (const :tag "Cookies only" cookies)
1428 (repeat :tag "Specify"
1429 (list (character :tag "Priority" :value ?A)
1430 (choice :tag "Face "
1431 (string :tag "Color")
1432 (sexp :tag "Face"))))))
1434 (defgroup org-agenda-column-view nil
1435 "Options concerning column view in the agenda."
1436 :tag "Org Agenda Column View"
1437 :group 'org-agenda)
1439 (defcustom org-agenda-columns-show-summaries t
1440 "Non-nil means show summaries for columns displayed in the agenda view."
1441 :group 'org-agenda-column-view
1442 :type 'boolean)
1444 (defcustom org-agenda-columns-remove-prefix-from-item t
1445 "Non-nil means remove the prefix from a headline for agenda column view.
1446 The special ITEM field in the columns format contains the current line, with
1447 all information shown in other columns (like the TODO state or a tag).
1448 When this variable is non-nil, also the agenda prefix will be removed from
1449 the content of the ITEM field, to make sure as much as possible of the
1450 headline can be shown in the limited width of the field."
1451 :group 'org-agenda
1452 :type 'boolean)
1454 (defcustom org-agenda-columns-compute-summary-properties t
1455 "Non-nil means recompute all summary properties before column view.
1456 When column view in the agenda is listing properties that have a summary
1457 operator, it can go to all relevant buffers and recompute the summaries
1458 there. This can mean overhead for the agenda column view, but is necessary
1459 to have thing up to date.
1460 As a special case, a CLOCKSUM property also makes sure that the clock
1461 computations are current."
1462 :group 'org-agenda-column-view
1463 :type 'boolean)
1465 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1466 "Non-nil means the duration of an appointment will add to day effort.
1467 The property to which appointment durations will be added is the one given
1468 in the option `org-effort-property'. If an appointment does not have
1469 an end time, `org-agenda-default-appointment-duration' will be used. If that
1470 is not set, an appointment without end time will not contribute to the time
1471 estimate."
1472 :group 'org-agenda-column-view
1473 :type 'boolean)
1475 (defcustom org-agenda-auto-exclude-function nil
1476 "A function called with a tag to decide if it is filtered on '/ RET'.
1477 The sole argument to the function, which is called once for each
1478 possible tag, is a string giving the name of the tag. The
1479 function should return either nil if the tag should be included
1480 as normal, or \"-<TAG>\" to exclude the tag.
1481 Note that for the purpose of tag filtering, only the lower-case version of
1482 all tags will be considered, so that this function will only ever see
1483 the lower-case version of all tags."
1484 :group 'org-agenda
1485 :type 'function)
1487 (eval-when-compile
1488 (require 'cl))
1489 (require 'org)
1491 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1492 "Execute BODY with point at location given by `org-hd-marker' property.
1493 If STRING is non-nil, the text property will be fetched from position 0
1494 in that string. If STRING is nil, it will be fetched from the beginning
1495 of the current line."
1496 `(let ((marker (get-text-property (if string 0 (point-at-bol))
1497 'org-hd-marker string)))
1498 (with-current-buffer (marker-buffer marker)
1499 (save-excursion
1500 (goto-char marker)
1501 ,@body))))
1503 (defun org-add-agenda-custom-command (entry)
1504 "Replace or add a command in `org-agenda-custom-commands'.
1505 This is mostly for hacking and trying a new command - once the command
1506 works you probably want to add it to `org-agenda-custom-commands' for good."
1507 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1508 (if ass
1509 (setcdr ass (cdr entry))
1510 (push entry org-agenda-custom-commands))))
1512 ;;; Define the Org-agenda-mode
1514 (defvar org-agenda-mode-map (make-sparse-keymap)
1515 "Keymap for `org-agenda-mode'.")
1516 (if (fboundp 'defvaralias)
1517 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1519 (defvar org-agenda-menu) ; defined later in this file.
1520 (defvar org-agenda-restrict) ; defined later in this file.
1521 (defvar org-agenda-follow-mode nil)
1522 (defvar org-agenda-entry-text-mode nil)
1523 (defvar org-agenda-clockreport-mode nil)
1524 (defvar org-agenda-show-log nil)
1525 (defvar org-agenda-redo-command nil)
1526 (defvar org-agenda-query-string nil)
1527 (defvar org-agenda-mode-hook nil
1528 "Hook for `org-agenda-mode', run after the mode is turned on.")
1529 (defvar org-agenda-type nil)
1530 (defvar org-agenda-force-single-file nil)
1531 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1533 (defun org-agenda-mode ()
1534 "Mode for time-sorted view on action items in Org-mode files.
1536 The following commands are available:
1538 \\{org-agenda-mode-map}"
1539 (interactive)
1540 (kill-all-local-variables)
1541 (setq org-agenda-undo-list nil
1542 org-agenda-pending-undo-list nil
1543 org-agenda-bulk-marked-entries nil)
1544 (setq major-mode 'org-agenda-mode)
1545 ;; Keep global-font-lock-mode from turning on font-lock-mode
1546 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1547 (setq mode-name "Org-Agenda")
1548 (use-local-map org-agenda-mode-map)
1549 (easy-menu-add org-agenda-menu)
1550 (if org-startup-truncated (setq truncate-lines t))
1551 (org-set-local 'line-move-visual nil)
1552 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1553 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1554 ;; Make sure properties are removed when copying text
1555 (when (boundp 'buffer-substring-filters)
1556 (org-set-local 'buffer-substring-filters
1557 (cons (lambda (x)
1558 (set-text-properties 0 (length x) nil x) x)
1559 buffer-substring-filters)))
1560 (unless org-agenda-keep-modes
1561 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1562 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1563 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1564 org-agenda-show-log org-agenda-start-with-log-mode))
1566 (easy-menu-change
1567 '("Agenda") "Agenda Files"
1568 (append
1569 (list
1570 (vector
1571 (if (get 'org-agenda-files 'org-restrict)
1572 "Restricted to single file"
1573 "Edit File List")
1574 '(org-edit-agenda-file-list)
1575 (not (get 'org-agenda-files 'org-restrict)))
1576 "--")
1577 (mapcar 'org-file-menu-entry (org-agenda-files))))
1578 (org-agenda-set-mode-name)
1579 (apply
1580 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1581 (list 'org-agenda-mode-hook)))
1583 (substitute-key-definition 'undo 'org-agenda-undo
1584 org-agenda-mode-map global-map)
1585 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1586 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1587 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1588 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1589 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1590 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1591 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1592 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1593 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1594 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1595 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1596 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1597 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1598 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1599 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1600 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1601 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1602 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1603 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1604 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1605 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1606 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1607 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1608 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1609 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1610 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1611 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1612 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1613 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1614 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1615 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1616 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1617 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1618 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1619 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1620 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1621 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1622 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1623 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1624 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1625 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1626 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1627 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1629 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1630 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1631 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1632 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1633 (while l (org-defkey org-agenda-mode-map
1634 (int-to-string (pop l)) 'digit-argument)))
1636 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1637 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1638 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1639 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1640 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1641 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1642 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1643 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1644 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1645 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1646 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1647 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1648 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1649 'org-clock-modify-effort-estimate)
1650 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1651 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1652 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1653 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1654 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1655 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1656 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1657 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1658 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1659 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1660 (substitute-key-definition 'next-line 'org-agenda-next-line
1661 org-agenda-mode-map global-map)
1662 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1663 org-agenda-mode-map global-map)
1664 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1665 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1666 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1667 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1668 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1669 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1670 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1671 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1672 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1673 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1674 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1675 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1676 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1677 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1678 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1679 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1680 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1681 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1682 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1683 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1684 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1685 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1686 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1687 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1688 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1689 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1690 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1691 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1692 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1693 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1695 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1696 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1697 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1698 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1699 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1700 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1701 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1702 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1703 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1704 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1706 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1707 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1708 (when org-agenda-mouse-1-follows-link
1709 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1710 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1711 '("Agenda"
1712 ("Agenda Files")
1713 "--"
1714 ("Agenda Dates"
1715 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1716 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1717 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1718 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1719 "--"
1720 ("View"
1721 ["Day View" org-agenda-day-view
1722 :active (org-agenda-check-type nil 'agenda)
1723 :style radio :selected (equal org-agenda-ndays 1)
1724 :keys "v d (or just d)"]
1725 ["Week View" org-agenda-week-view
1726 :active (org-agenda-check-type nil 'agenda)
1727 :style radio :selected (equal org-agenda-ndays 7)
1728 :keys "v w (or just w)"]
1729 ["Month View" org-agenda-month-view
1730 :active (org-agenda-check-type nil 'agenda)
1731 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1732 :keys "v m"]
1733 ["Year View" org-agenda-year-view
1734 :active (org-agenda-check-type nil 'agenda)
1735 :style radio :selected (member org-agenda-ndays '(365 366))
1736 :keys "v y"]
1737 "--"
1738 ["Include Diary" org-agenda-toggle-diary
1739 :style toggle :selected org-agenda-include-diary
1740 :active (org-agenda-check-type nil 'agenda)]
1741 ["Include Deadlines" org-agenda-toggle-deadlines
1742 :style toggle :selected org-agenda-include-deadlines
1743 :active (org-agenda-check-type nil 'agenda)]
1744 ["Use Time Grid" org-agenda-toggle-time-grid
1745 :style toggle :selected org-agenda-use-time-grid
1746 :active (org-agenda-check-type nil 'agenda)]
1747 "--"
1748 ["Show clock report" org-agenda-clockreport-mode
1749 :style toggle :selected org-agenda-clockreport-mode
1750 :active (org-agenda-check-type nil 'agenda)]
1751 ["Show some entry text" org-agenda-entry-text-mode
1752 :style toggle :selected org-agenda-entry-text-mode
1753 :active t]
1754 "--"
1755 ["Show Logbook entries" org-agenda-log-mode
1756 :style toggle :selected org-agenda-show-log
1757 :active (org-agenda-check-type nil 'agenda 'timeline)
1758 :keys "v l (or just l)"]
1759 ["Include archived trees" org-agenda-archives-mode
1760 :style toggle :selected org-agenda-archives-mode :active t
1761 :keys "v a"]
1762 ["Include archive files" (org-agenda-archives-mode t)
1763 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1764 :keys "v A"]
1765 "--"
1766 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1767 ["Write view to file" org-write-agenda t]
1768 ["Rebuild buffer" org-agenda-redo t]
1769 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1770 "--"
1771 ["Show original entry" org-agenda-show t]
1772 ["Go To (other window)" org-agenda-goto t]
1773 ["Go To (this window)" org-agenda-switch-to t]
1774 ["Follow Mode" org-agenda-follow-mode
1775 :style toggle :selected org-agenda-follow-mode :active t]
1776 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1777 "--"
1778 ("TODO"
1779 ["Cycle TODO" org-agenda-todo t]
1780 ["Next TODO set" org-agenda-todo-nextset t]
1781 ["Previous TODO set" org-agenda-todo-previousset t]
1782 ["Add note" org-agenda-add-note t])
1783 ("Archive/Refile/Delete"
1784 ["Archive default" org-agenda-archive-default t]
1785 ["Archive default" org-agenda-archive-default-with-confirmation t]
1786 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1787 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1788 ["Archive subtree" org-agenda-archive t]
1789 "--"
1790 ["Refile" org-agenda-refile t]
1791 "--"
1792 ["Delete subtree" org-agenda-kill t])
1793 ("Bulk action"
1794 ["Mark entry" org-agenda-bulk-mark t]
1795 ["Unmark entry" org-agenda-bulk-unmark t]
1796 ["Act on all marked" org-agenda-bulk-action t]
1797 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1798 "--"
1799 ("Tags and Properties"
1800 ["Show all Tags" org-agenda-show-tags t]
1801 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1802 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1803 "--"
1804 ["Column View" org-columns t])
1805 ("Deadline/Schedule"
1806 ["Schedule" org-agenda-schedule t]
1807 ["Set Deadline" org-agenda-deadline t]
1808 "--"
1809 ["Mark item" org-agenda-action :active t :keys "k m"]
1810 ["Show mark item" org-agenda-action :active t :keys "k v"]
1811 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1812 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1813 "--"
1814 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1815 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1816 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1817 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1818 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1819 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1820 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1821 ("Clock and Effort"
1822 ["Clock in" org-agenda-clock-in t]
1823 ["Clock out" org-agenda-clock-out t]
1824 ["Clock cancel" org-agenda-clock-cancel t]
1825 ["Goto running clock" org-clock-goto t]
1826 "--"
1827 ["Set Effort" org-agenda-set-effort t]
1828 ["Change clocked effort" org-clock-modify-effort-estimate
1829 (org-clock-is-active)])
1830 ("Priority"
1831 ["Set Priority" org-agenda-priority t]
1832 ["Increase Priority" org-agenda-priority-up t]
1833 ["Decrease Priority" org-agenda-priority-down t]
1834 ["Show Priority" org-agenda-show-priority t])
1835 ("Calendar/Diary"
1836 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1837 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1838 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1839 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1840 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1841 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1842 "--"
1843 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1844 "--"
1845 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1846 "--"
1847 ("MobileOrg"
1848 ["Push Files and Views" org-mobile-push t]
1849 ["Get Captured and Flagged" org-mobile-pull t]
1850 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1851 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1852 "--"
1853 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1854 "--"
1855 ["Quit" org-agenda-quit t]
1856 ["Exit and Release Buffers" org-agenda-exit t]
1859 ;;; Agenda undo
1861 (defvar org-agenda-allow-remote-undo t
1862 "Non-nil means allow remote undo from the agenda buffer.")
1863 (defvar org-agenda-undo-list nil
1864 "List of undoable operations in the agenda since last refresh.")
1865 (defvar org-agenda-undo-has-started-in nil
1866 "Buffers that have already seen `undo-start' in the current undo sequence.")
1867 (defvar org-agenda-pending-undo-list nil
1868 "In a series of undo commands, this is the list of remaining undo items.")
1871 (defun org-agenda-undo ()
1872 "Undo a remote editing step in the agenda.
1873 This undoes changes both in the agenda buffer and in the remote buffer
1874 that have been changed along."
1875 (interactive)
1876 (or org-agenda-allow-remote-undo
1877 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1878 (if (not (eq this-command last-command))
1879 (setq org-agenda-undo-has-started-in nil
1880 org-agenda-pending-undo-list org-agenda-undo-list))
1881 (if (not org-agenda-pending-undo-list)
1882 (error "No further undo information"))
1883 (let* ((entry (pop org-agenda-pending-undo-list))
1884 buf line cmd rembuf)
1885 (setq cmd (pop entry) line (pop entry))
1886 (setq rembuf (nth 2 entry))
1887 (org-with-remote-undo rembuf
1888 (while (bufferp (setq buf (pop entry)))
1889 (if (pop entry)
1890 (with-current-buffer buf
1891 (let ((last-undo-buffer buf)
1892 (inhibit-read-only t))
1893 (unless (memq buf org-agenda-undo-has-started-in)
1894 (push buf org-agenda-undo-has-started-in)
1895 (make-local-variable 'pending-undo-list)
1896 (undo-start))
1897 (while (and pending-undo-list
1898 (listp pending-undo-list)
1899 (not (car pending-undo-list)))
1900 (pop pending-undo-list))
1901 (undo-more 1))))))
1902 (org-goto-line line)
1903 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1905 (defun org-verify-change-for-undo (l1 l2)
1906 "Verify that a real change occurred between the undo lists L1 and L2."
1907 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1908 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1909 (not (eq l1 l2)))
1911 ;;; Agenda dispatch
1913 (defvar org-agenda-restrict nil)
1914 (defvar org-agenda-restrict-begin (make-marker))
1915 (defvar org-agenda-restrict-end (make-marker))
1916 (defvar org-agenda-last-dispatch-buffer nil)
1917 (defvar org-agenda-overriding-restriction nil)
1919 ;;;###autoload
1920 (defun org-agenda (&optional arg keys restriction)
1921 "Dispatch agenda commands to collect entries to the agenda buffer.
1922 Prompts for a command to execute. Any prefix arg will be passed
1923 on to the selected command. The default selections are:
1925 a Call `org-agenda-list' to display the agenda for current day or week.
1926 t Call `org-todo-list' to display the global todo list.
1927 T Call `org-todo-list' to display the global todo list, select only
1928 entries with a specific TODO keyword (the user gets a prompt).
1929 m Call `org-tags-view' to display headlines with tags matching
1930 a condition (the user is prompted for the condition).
1931 M Like `m', but select only TODO entries, no ordinary headlines.
1932 L Create a timeline for the current buffer.
1933 e Export views to associated files.
1934 s Search entries for keywords.
1935 / Multi occur across all agenda files and also files listed
1936 in `org-agenda-text-search-extra-files'.
1937 < Restrict agenda commands to buffer, subtree, or region.
1938 Press several times to get the desired effect.
1939 > Remove a previous restriction.
1940 # List \"stuck\" projects.
1941 ! Configure what \"stuck\" means.
1942 C Configure custom agenda commands.
1944 More commands can be added by configuring the variable
1945 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1946 searches can be pre-defined in this way.
1948 If the current buffer is in Org-mode and visiting a file, you can also
1949 first press `<' once to indicate that the agenda should be temporarily
1950 \(until the next use of \\[org-agenda]) restricted to the current file.
1951 Pressing `<' twice means to restrict to the current subtree or region
1952 \(if active)."
1953 (interactive "P")
1954 (catch 'exit
1955 (let* ((prefix-descriptions nil)
1956 (org-agenda-window-setup (if (equal (buffer-name)
1957 org-agenda-buffer-name)
1958 'current-window
1959 org-agenda-window-setup))
1960 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1961 (org-agenda-custom-commands
1962 ;; normalize different versions
1963 (delq nil
1964 (mapcar
1965 (lambda (x)
1966 (cond ((stringp (cdr x))
1967 (push x prefix-descriptions)
1968 nil)
1969 ((stringp (nth 1 x)) x)
1970 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1971 (t (cons (car x) (cons "" (cdr x))))))
1972 org-agenda-custom-commands)))
1973 (buf (current-buffer))
1974 (bfn (buffer-file-name (buffer-base-buffer)))
1975 entry key type match lprops ans)
1976 ;; Turn off restriction unless there is an overriding one,
1977 (unless org-agenda-overriding-restriction
1978 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
1979 ;; There is a request to keep the file list in place
1980 (put 'org-agenda-files 'org-restrict nil))
1981 (setq org-agenda-restrict nil)
1982 (move-marker org-agenda-restrict-begin nil)
1983 (move-marker org-agenda-restrict-end nil))
1984 ;; Delete old local properties
1985 (put 'org-agenda-redo-command 'org-lprops nil)
1986 ;; Remember where this call originated
1987 (setq org-agenda-last-dispatch-buffer (current-buffer))
1988 (unless keys
1989 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1990 keys (car ans)
1991 restriction (cdr ans)))
1992 ;; Establish the restriction, if any
1993 (when (and (not org-agenda-overriding-restriction) restriction)
1994 (put 'org-agenda-files 'org-restrict (list bfn))
1995 (cond
1996 ((eq restriction 'region)
1997 (setq org-agenda-restrict t)
1998 (move-marker org-agenda-restrict-begin (region-beginning))
1999 (move-marker org-agenda-restrict-end (region-end)))
2000 ((eq restriction 'subtree)
2001 (save-excursion
2002 (setq org-agenda-restrict t)
2003 (org-back-to-heading t)
2004 (move-marker org-agenda-restrict-begin (point))
2005 (move-marker org-agenda-restrict-end
2006 (progn (org-end-of-subtree t)))))))
2008 ;; For example the todo list should not need it (but does...)
2009 (cond
2010 ((setq entry (assoc keys org-agenda-custom-commands))
2011 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2012 (progn
2013 (setq type (nth 2 entry) match (eval (nth 3 entry))
2014 lprops (nth 4 entry))
2015 (put 'org-agenda-redo-command 'org-lprops lprops)
2016 (cond
2017 ((eq type 'agenda)
2018 (org-let lprops '(org-agenda-list current-prefix-arg)))
2019 ((eq type 'alltodo)
2020 (org-let lprops '(org-todo-list current-prefix-arg)))
2021 ((eq type 'search)
2022 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2023 ((eq type 'stuck)
2024 (org-let lprops '(org-agenda-list-stuck-projects
2025 current-prefix-arg)))
2026 ((eq type 'tags)
2027 (org-let lprops '(org-tags-view current-prefix-arg match)))
2028 ((eq type 'tags-todo)
2029 (org-let lprops '(org-tags-view '(4) match)))
2030 ((eq type 'todo)
2031 (org-let lprops '(org-todo-list match)))
2032 ((eq type 'tags-tree)
2033 (org-check-for-org-mode)
2034 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2035 ((eq type 'todo-tree)
2036 (org-check-for-org-mode)
2037 (org-let lprops
2038 '(org-occur (concat "^" outline-regexp "[ \t]*"
2039 (regexp-quote match) "\\>"))))
2040 ((eq type 'occur-tree)
2041 (org-check-for-org-mode)
2042 (org-let lprops '(org-occur match)))
2043 ((functionp type)
2044 (org-let lprops '(funcall type match)))
2045 ((fboundp type)
2046 (org-let lprops '(funcall type match)))
2047 (t (error "Invalid custom agenda command type %s" type))))
2048 (org-run-agenda-series (nth 1 entry) (cddr entry))))
2049 ((equal keys "C")
2050 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2051 (customize-variable 'org-agenda-custom-commands))
2052 ((equal keys "a") (call-interactively 'org-agenda-list))
2053 ((equal keys "s") (call-interactively 'org-search-view))
2054 ((equal keys "t") (call-interactively 'org-todo-list))
2055 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2056 ((equal keys "m") (call-interactively 'org-tags-view))
2057 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2058 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2059 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2060 (org-add-hook
2061 'post-command-hook
2062 (lambda ()
2063 (unless (current-message)
2064 (let* ((m (org-agenda-get-any-marker))
2065 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2066 (when note
2067 (message (concat
2068 "FLAGGING-NOTE ([?] for more info): "
2069 (org-add-props
2070 (replace-regexp-in-string
2071 "\\\\n" "//"
2072 (copy-sequence note))
2073 nil 'face 'org-warning)))))))
2074 t t))
2075 ((equal keys "L")
2076 (unless (org-mode-p)
2077 (error "This is not an Org-mode file"))
2078 (unless restriction
2079 (put 'org-agenda-files 'org-restrict (list bfn))
2080 (org-call-with-arg 'org-timeline arg)))
2081 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2082 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2083 ((equal keys "!") (customize-variable 'org-stuck-projects))
2084 (t (error "Invalid agenda key"))))))
2086 (defun org-agenda-normalize-custom-commands (cmds)
2087 (delq nil
2088 (mapcar
2089 (lambda (x)
2090 (cond ((stringp (cdr x)) nil)
2091 ((stringp (nth 1 x)) x)
2092 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2093 (t (cons (car x) (cons "" (cdr x))))))
2094 cmds)))
2096 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2097 "The user interface for selecting an agenda command."
2098 (catch 'exit
2099 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2100 (restrict-ok (and bfn (org-mode-p)))
2101 (region-p (org-region-active-p))
2102 (custom org-agenda-custom-commands)
2103 (selstring "")
2104 restriction second-time
2105 c entry key type match prefixes rmheader header-end custom1 desc
2106 line lines left right n n1)
2107 (save-window-excursion
2108 (delete-other-windows)
2109 (org-switch-to-buffer-other-window " *Agenda Commands*")
2110 (erase-buffer)
2111 (insert (eval-when-compile
2112 (let ((header
2114 Press key for an agenda command: < Buffer, subtree/region restriction
2115 -------------------------------- > Remove restriction
2116 a Agenda for current week or day e Export agenda views
2117 t List of all TODO entries T Entries with special TODO kwd
2118 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2119 L Timeline for current buffer # List stuck projects (!=configure)
2120 s Search for keywords C Configure custom agenda commands
2121 / Multi-occur ? Find :FLAGGED: entries
2123 (start 0))
2124 (while (string-match
2125 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2126 header start)
2127 (setq start (match-end 0))
2128 (add-text-properties (match-beginning 2) (match-end 2)
2129 '(face bold) header))
2130 header)))
2131 (setq header-end (move-marker (make-marker) (point)))
2132 (while t
2133 (setq custom1 custom)
2134 (when (eq rmheader t)
2135 (org-goto-line 1)
2136 (re-search-forward ":" nil t)
2137 (delete-region (match-end 0) (point-at-eol))
2138 (forward-char 1)
2139 (looking-at "-+")
2140 (delete-region (match-end 0) (point-at-eol))
2141 (move-marker header-end (match-end 0)))
2142 (goto-char header-end)
2143 (delete-region (point) (point-max))
2145 ;; Produce all the lines that describe custom commands and prefixes
2146 (setq lines nil)
2147 (while (setq entry (pop custom1))
2148 (setq key (car entry) desc (nth 1 entry)
2149 type (nth 2 entry)
2150 match (nth 3 entry))
2151 (if (> (length key) 1)
2152 (add-to-list 'prefixes (string-to-char key))
2153 (setq line
2154 (format
2155 "%-4s%-14s"
2156 (org-add-props (copy-sequence key)
2157 '(face bold))
2158 (cond
2159 ((string-match "\\S-" desc) desc)
2160 ((eq type 'agenda) "Agenda for current week or day")
2161 ((eq type 'alltodo) "List of all TODO entries")
2162 ((eq type 'search) "Word search")
2163 ((eq type 'stuck) "List of stuck projects")
2164 ((eq type 'todo) "TODO keyword")
2165 ((eq type 'tags) "Tags query")
2166 ((eq type 'tags-todo) "Tags (TODO)")
2167 ((eq type 'tags-tree) "Tags tree")
2168 ((eq type 'todo-tree) "TODO kwd tree")
2169 ((eq type 'occur-tree) "Occur tree")
2170 ((functionp type) (if (symbolp type)
2171 (symbol-name type)
2172 "Lambda expression"))
2173 (t "???"))))
2174 (if org-agenda-menu-show-matcher
2175 (setq line
2176 (concat line ": "
2177 (cond
2178 ((stringp match)
2179 (setq match (copy-sequence match))
2180 (org-add-props match nil 'face 'org-warning))
2181 (match
2182 (format "set of %d commands" (length match)))
2183 (t ""))))
2184 (if (org-string-nw-p match)
2185 (add-text-properties
2186 0 (length line) (list 'help-echo
2187 (concat "Matcher: "match)) line)))
2188 (push line lines)))
2189 (setq lines (nreverse lines))
2190 (when prefixes
2191 (mapc (lambda (x)
2192 (push
2193 (format "%s %s"
2194 (org-add-props (char-to-string x)
2195 nil 'face 'bold)
2196 (or (cdr (assoc (concat selstring
2197 (char-to-string x))
2198 prefix-descriptions))
2199 "Prefix key"))
2200 lines))
2201 prefixes))
2203 ;; Check if we should display in two columns
2204 (if org-agenda-menu-two-column
2205 (progn
2206 (setq n (length lines)
2207 n1 (+ (/ n 2) (mod n 2))
2208 right (nthcdr n1 lines)
2209 left (copy-sequence lines))
2210 (setcdr (nthcdr (1- n1) left) nil))
2211 (setq left lines right nil))
2212 (while left
2213 (insert "\n" (pop left))
2214 (when right
2215 (if (< (current-column) 40)
2216 (move-to-column 40 t)
2217 (insert " "))
2218 (insert (pop right))))
2220 ;; Make the window the right size
2221 (goto-char (point-min))
2222 (if second-time
2223 (if (not (pos-visible-in-window-p (point-max)))
2224 (org-fit-window-to-buffer))
2225 (setq second-time t)
2226 (org-fit-window-to-buffer))
2228 ;; Ask for selection
2229 (message "Press key for agenda command%s:"
2230 (if (or restrict-ok org-agenda-overriding-restriction)
2231 (if org-agenda-overriding-restriction
2232 " (restriction lock active)"
2233 (if restriction
2234 (format " (restricted to %s)" restriction)
2235 " (unrestricted)"))
2236 ""))
2237 (setq c (read-char-exclusive))
2238 (message "")
2239 (cond
2240 ((assoc (char-to-string c) custom)
2241 (setq selstring (concat selstring (char-to-string c)))
2242 (throw 'exit (cons selstring restriction)))
2243 ((memq c prefixes)
2244 (setq selstring (concat selstring (char-to-string c))
2245 prefixes nil
2246 rmheader (or rmheader t)
2247 custom (delq nil (mapcar
2248 (lambda (x)
2249 (if (or (= (length (car x)) 1)
2250 (/= (string-to-char (car x)) c))
2252 (cons (substring (car x) 1) (cdr x))))
2253 custom))))
2254 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2255 (message "Restriction is only possible in Org-mode buffers")
2256 (ding) (sit-for 1))
2257 ((eq c ?1)
2258 (org-agenda-remove-restriction-lock 'noupdate)
2259 (setq restriction 'buffer))
2260 ((eq c ?0)
2261 (org-agenda-remove-restriction-lock 'noupdate)
2262 (setq restriction (if region-p 'region 'subtree)))
2263 ((eq c ?<)
2264 (org-agenda-remove-restriction-lock 'noupdate)
2265 (setq restriction
2266 (cond
2267 ((eq restriction 'buffer)
2268 (if region-p 'region 'subtree))
2269 ((memq restriction '(subtree region))
2270 nil)
2271 (t 'buffer))))
2272 ((eq c ?>)
2273 (org-agenda-remove-restriction-lock 'noupdate)
2274 (setq restriction nil))
2275 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2276 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2277 ((and (> (length selstring) 0) (eq c ?\d))
2278 (delete-window)
2279 (org-agenda-get-restriction-and-command prefix-descriptions))
2281 ((equal c ?q) (error "Abort"))
2282 (t (error "Invalid key %c" c))))))))
2284 (defun org-run-agenda-series (name series)
2285 (org-let (nth 1 series) '(org-prepare-agenda name))
2286 (let* ((org-agenda-multi t)
2287 (redo (list 'org-run-agenda-series name (list 'quote series)))
2288 (cmds (car series))
2289 (gprops (nth 1 series))
2290 match ;; The byte compiler incorrectly complains about this. Keep it!
2291 cmd type lprops)
2292 (while (setq cmd (pop cmds))
2293 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2294 (cond
2295 ((eq type 'agenda)
2296 (org-let2 gprops lprops
2297 '(call-interactively 'org-agenda-list)))
2298 ((eq type 'alltodo)
2299 (org-let2 gprops lprops
2300 '(call-interactively 'org-todo-list)))
2301 ((eq type 'search)
2302 (org-let2 gprops lprops
2303 '(org-search-view current-prefix-arg match nil)))
2304 ((eq type 'stuck)
2305 (org-let2 gprops lprops
2306 '(call-interactively 'org-agenda-list-stuck-projects)))
2307 ((eq type 'tags)
2308 (org-let2 gprops lprops
2309 '(org-tags-view current-prefix-arg match)))
2310 ((eq type 'tags-todo)
2311 (org-let2 gprops lprops
2312 '(org-tags-view '(4) match)))
2313 ((eq type 'todo)
2314 (org-let2 gprops lprops
2315 '(org-todo-list match)))
2316 ((fboundp type)
2317 (org-let2 gprops lprops
2318 '(funcall type match)))
2319 (t (error "Invalid type in command series"))))
2320 (widen)
2321 (setq org-agenda-redo-command redo)
2322 (goto-char (point-min)))
2323 (org-fit-agenda-window)
2324 (org-let (nth 1 series) '(org-finalize-agenda)))
2326 ;;;###autoload
2327 (defmacro org-batch-agenda (cmd-key &rest parameters)
2328 "Run an agenda command in batch mode and send the result to STDOUT.
2329 If CMD-KEY is a string of length 1, it is used as a key in
2330 `org-agenda-custom-commands' and triggers this command. If it is a
2331 longer string it is used as a tags/todo match string.
2332 Parameters are alternating variable names and values that will be bound
2333 before running the agenda command."
2334 (let (pars)
2335 (while parameters
2336 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2337 (if (> (length cmd-key) 2)
2338 (eval (list 'let (nreverse pars)
2339 (list 'org-tags-view nil cmd-key)))
2340 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2341 (set-buffer org-agenda-buffer-name)
2342 (princ (org-encode-for-stdout (buffer-string)))))
2344 ;(defun org-encode-for-stdout (string)
2345 ; (if (fboundp 'encode-coding-string)
2346 ; (encode-coding-string string buffer-file-coding-system)
2347 ; string))
2349 (defun org-encode-for-stdout (string)
2350 string)
2352 (defvar org-agenda-info nil)
2354 ;;;###autoload
2355 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2356 "Run an agenda command in batch mode and send the result to STDOUT.
2357 If CMD-KEY is a string of length 1, it is used as a key in
2358 `org-agenda-custom-commands' and triggers this command. If it is a
2359 longer string it is used as a tags/todo match string.
2360 Parameters are alternating variable names and values that will be bound
2361 before running the agenda command.
2363 The output gives a line for each selected agenda item. Each
2364 item is a list of comma-separated values, like this:
2366 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2368 category The category of the item
2369 head The headline, without TODO kwd, TAGS and PRIORITY
2370 type The type of the agenda entry, can be
2371 todo selected in TODO match
2372 tagsmatch selected in tags match
2373 diary imported from diary
2374 deadline a deadline on given date
2375 scheduled scheduled on given date
2376 timestamp entry has timestamp on given date
2377 closed entry was closed on given date
2378 upcoming-deadline warning about deadline
2379 past-scheduled forwarded scheduled item
2380 block entry has date block including g. date
2381 todo The todo keyword, if any
2382 tags All tags including inherited ones, separated by colons
2383 date The relevant date, like 2007-2-14
2384 time The time, like 15:00-16:50
2385 extra Sting with extra planning info
2386 priority-l The priority letter if any was given
2387 priority-n The computed numerical priority
2388 agenda-day The day in the agenda where this is listed"
2390 (let (pars)
2391 (while parameters
2392 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2393 (push (list 'org-agenda-remove-tags t) pars)
2394 (if (> (length cmd-key) 2)
2395 (eval (list 'let (nreverse pars)
2396 (list 'org-tags-view nil cmd-key)))
2397 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2398 (set-buffer org-agenda-buffer-name)
2399 (let* ((lines (org-split-string (buffer-string) "\n"))
2400 line)
2401 (while (setq line (pop lines))
2402 (catch 'next
2403 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2404 (setq org-agenda-info
2405 (org-fix-agenda-info (text-properties-at 0 line)))
2406 (princ
2407 (org-encode-for-stdout
2408 (mapconcat 'org-agenda-export-csv-mapper
2409 '(org-category txt type todo tags date time extra
2410 priority-letter priority agenda-day)
2411 ",")))
2412 (princ "\n"))))))
2414 (defun org-fix-agenda-info (props)
2415 "Make sure all properties on an agenda item have a canonical form.
2416 This ensures the export commands can easily use it."
2417 (let (tmp re)
2418 (when (setq tmp (plist-get props 'tags))
2419 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2420 (when (setq tmp (plist-get props 'date))
2421 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2422 (let ((calendar-date-display-form '(year "-" month "-" day)))
2423 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2425 (setq tmp (calendar-date-string tmp)))
2426 (setq props (plist-put props 'date tmp)))
2427 (when (setq tmp (plist-get props 'day))
2428 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2429 (let ((calendar-date-display-form '(year "-" month "-" day)))
2430 (setq tmp (calendar-date-string tmp)))
2431 (setq props (plist-put props 'day tmp))
2432 (setq props (plist-put props 'agenda-day tmp)))
2433 (when (setq tmp (plist-get props 'txt))
2434 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2435 (plist-put props 'priority-letter (match-string 1 tmp))
2436 (setq tmp (replace-match "" t t tmp)))
2437 (when (and (setq re (plist-get props 'org-todo-regexp))
2438 (setq re (concat "\\`\\.*" re " ?"))
2439 (string-match re tmp))
2440 (plist-put props 'todo (match-string 1 tmp))
2441 (setq tmp (replace-match "" t t tmp)))
2442 (plist-put props 'txt tmp)))
2443 props)
2445 (defun org-agenda-export-csv-mapper (prop)
2446 (let ((res (plist-get org-agenda-info prop)))
2447 (setq res
2448 (cond
2449 ((not res) "")
2450 ((stringp res) res)
2451 (t (prin1-to-string res))))
2452 (while (string-match "," res)
2453 (setq res (replace-match ";" t t res)))
2454 (org-trim res)))
2457 ;;;###autoload
2458 (defun org-store-agenda-views (&rest parameters)
2459 (interactive)
2460 (eval (list 'org-batch-store-agenda-views)))
2462 ;; FIXME, why is this a macro?????
2463 ;;;###autoload
2464 (defmacro org-batch-store-agenda-views (&rest parameters)
2465 "Run all custom agenda commands that have a file argument."
2466 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2467 (pop-up-frames nil)
2468 (dir default-directory)
2469 pars cmd thiscmdkey files opts cmd-or-set)
2470 (while parameters
2471 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2472 (setq pars (reverse pars))
2473 (save-window-excursion
2474 (while cmds
2475 (setq cmd (pop cmds)
2476 thiscmdkey (car cmd)
2477 cmd-or-set (nth 2 cmd)
2478 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2479 files (nth (if (listp cmd-or-set) 4 5) cmd))
2480 (if (stringp files) (setq files (list files)))
2481 (when files
2482 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2483 (list 'org-agenda nil thiscmdkey)))
2484 (set-buffer org-agenda-buffer-name)
2485 (while files
2486 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2487 (list 'org-write-agenda
2488 (expand-file-name (pop files) dir) nil t))))
2489 (and (get-buffer org-agenda-buffer-name)
2490 (kill-buffer org-agenda-buffer-name)))))))
2492 (defun org-agenda-mark-header-line (pos)
2493 "Mark the line at POS as an agenda structure header."
2494 (save-excursion
2495 (goto-char pos)
2496 (put-text-property (point-at-bol) (point-at-eol)
2497 'org-agenda-structural-header t)
2498 (when org-agenda-title-append
2499 (put-text-property (point-at-bol) (point-at-eol)
2500 'org-agenda-title-append org-agenda-title-append))))
2502 (defvar org-mobile-creating-agendas)
2503 (defun org-write-agenda (file &optional open nosettings)
2504 "Write the current buffer (an agenda view) as a file.
2505 Depending on the extension of the file name, plain text (.txt),
2506 HTML (.html or .htm) or Postscript (.ps) is produced.
2507 If the extension is .ics, run icalendar export over all files used
2508 to construct the agenda and limit the export to entries listed in the
2509 agenda now.
2510 With prefix argument OPEN, open the new file immediately.
2511 If NOSETTINGS is given, do not scope the settings of
2512 `org-agenda-exporter-settings' into the export commands. This is used when
2513 the settings have already been scoped and we do not wish to overrule other,
2514 higher priority settings."
2515 (interactive "FWrite agenda to file: \nP")
2516 (if (not (file-writable-p file))
2517 (error "Cannot write agenda to file %s" file))
2518 (org-let (if nosettings nil org-agenda-exporter-settings)
2519 '(save-excursion
2520 (save-window-excursion
2521 (org-agenda-mark-filtered-text)
2522 (let ((bs (copy-sequence (buffer-string))) beg)
2523 (org-agenda-unmark-filtered-text)
2524 (with-temp-buffer
2525 (rename-buffer "Agenda View" t)
2526 (set-buffer-modified-p nil)
2527 (insert bs)
2528 (org-agenda-remove-marked-text 'org-filtered)
2529 (while (setq beg (text-property-any (point-min) (point-max)
2530 'org-filtered t))
2531 (delete-region
2532 beg (or (next-single-property-change beg 'org-filtered)
2533 (point-max))))
2534 (run-hooks 'org-agenda-before-write-hook)
2535 (cond
2536 ((org-bound-and-true-p org-mobile-creating-agendas)
2537 (org-mobile-write-agenda-for-mobile file))
2538 ((string-match "\\.html?\\'" file)
2539 (require 'htmlize)
2540 (set-buffer (htmlize-buffer (current-buffer)))
2542 (when (and org-agenda-export-html-style
2543 (string-match "<style>" org-agenda-export-html-style))
2544 ;; replace <style> section with org-agenda-export-html-style
2545 (goto-char (point-min))
2546 (kill-region (- (search-forward "<style") 6)
2547 (search-forward "</style>"))
2548 (insert org-agenda-export-html-style))
2549 (write-file file)
2550 (kill-buffer (current-buffer))
2551 (message "HTML written to %s" file))
2552 ((string-match "\\.ps\\'" file)
2553 (require 'ps-print)
2554 (ps-print-buffer-with-faces file)
2555 (message "Postscript written to %s" file))
2556 ((string-match "\\.pdf\\'" file)
2557 (require 'ps-print)
2558 (ps-print-buffer-with-faces
2559 (concat (file-name-sans-extension file) ".ps"))
2560 (call-process "ps2pdf" nil nil nil
2561 (expand-file-name
2562 (concat (file-name-sans-extension file) ".ps"))
2563 (expand-file-name file))
2564 (delete-file (concat (file-name-sans-extension file) ".ps"))
2565 (message "PDF written to %s" file))
2566 ((string-match "\\.ics\\'" file)
2567 (require 'org-icalendar)
2568 (let ((org-agenda-marker-table
2569 (org-create-marker-find-array
2570 (org-agenda-collect-markers)))
2571 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2572 (org-combined-agenda-icalendar-file file))
2573 (apply 'org-export-icalendar 'combine
2574 (org-agenda-files nil 'ifmode))))
2576 (let ((bs (buffer-string)))
2577 (find-file file)
2578 (erase-buffer)
2579 (insert bs)
2580 (save-buffer 0)
2581 (kill-buffer (current-buffer))
2582 (message "Plain text written to %s" file))))))))
2583 (set-buffer org-agenda-buffer-name))
2584 (when open (org-open-file file)))
2586 (defvar org-agenda-filter-overlays nil)
2588 (defun org-agenda-mark-filtered-text ()
2589 "Mark all text hidden by filtering with a text property."
2590 (let ((inhibit-read-only t))
2591 (mapc
2592 (lambda (o)
2593 (when (equal (overlay-buffer o) (current-buffer))
2594 (put-text-property
2595 (overlay-start o) (overlay-end o)
2596 'org-filtered t)))
2597 org-agenda-filter-overlays)))
2599 (defun org-agenda-unmark-filtered-text ()
2600 "Remove the filtering text property."
2601 (let ((inhibit-read-only t))
2602 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2604 (defun org-agenda-remove-marked-text (property &optional value)
2605 "Delete all text marked with VALUE of PROPERTY.
2606 VALUE defaults to t."
2607 (let (beg)
2608 (setq value (or value t))
2609 (while (setq beg (text-property-any (point-min) (point-max)
2610 property value))
2611 (delete-region
2612 beg (or (next-single-property-change beg 'org-filtered)
2613 (point-max))))))
2615 (defun org-agenda-add-entry-text ()
2616 "Add entry text to agenda lines.
2617 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2618 entry text following headings shown in the agenda.
2619 Drawers will be excluded, also the line with scheduling/deadline info."
2620 (when (and (> org-agenda-add-entry-text-maxlines 0)
2621 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2622 (let (m txt)
2623 (goto-char (point-min))
2624 (while (not (eobp))
2625 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2626 (beginning-of-line 2)
2627 (setq txt (org-agenda-get-some-entry-text
2628 m org-agenda-add-entry-text-maxlines " > "))
2629 (end-of-line 1)
2630 (if (string-match "\\S-" txt)
2631 (insert "\n" txt)
2632 (or (eobp) (forward-char 1))))))))
2634 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2635 &rest keep)
2636 "Extract entry text from MARKER, at most N-LINES lines.
2637 This will ignore drawers etc, just get the text.
2638 If INDENT is given, prefix every line with this string. If KEEP is
2639 given, it is a list of symbols, defining stuff that should not be
2640 removed from the entry content. Currently only `planning' is allowed here."
2641 (let (txt drawer-re kwd-time-re ind)
2642 (save-excursion
2643 (with-current-buffer (marker-buffer marker)
2644 (if (not (org-mode-p))
2645 (setq txt "")
2646 (save-excursion
2647 (save-restriction
2648 (widen)
2649 (goto-char marker)
2650 (end-of-line 1)
2651 (setq txt (buffer-substring
2652 (min (1+ (point)) (point-max))
2653 (progn (outline-next-heading) (point)))
2654 drawer-re org-drawer-regexp
2655 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2656 ".*\n?"))
2657 (with-temp-buffer
2658 (insert txt)
2659 (when org-agenda-add-entry-text-descriptive-links
2660 (goto-char (point-min))
2661 (while (org-activate-bracket-links (point-max))
2662 (add-text-properties (match-beginning 0) (match-end 0)
2663 '(face org-link))))
2664 (goto-char (point-min))
2665 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2666 (set-text-properties (match-beginning 0) (match-end 0)
2667 nil))
2668 (goto-char (point-min))
2669 (while (re-search-forward drawer-re nil t)
2670 (delete-region
2671 (match-beginning 0)
2672 (progn (re-search-forward
2673 "^[ \t]*:END:.*\n?" nil 'move)
2674 (point))))
2675 (unless (member 'planning keep)
2676 (goto-char (point-min))
2677 (while (re-search-forward kwd-time-re nil t)
2678 (replace-match "")))
2679 (goto-char (point-min))
2680 (when org-agenda-entry-text-exclude-regexps
2681 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2682 (while (setq re (pop re-list))
2683 (goto-char (point-min))
2684 (while (re-search-forward re nil t)
2685 (replace-match "")))))
2686 (goto-char (point-max))
2687 (skip-chars-backward " \t\n")
2688 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2690 ;; find and remove min common indentation
2691 (goto-char (point-min))
2692 (untabify (point-min) (point-max))
2693 (setq ind (org-get-indentation))
2694 (while (not (eobp))
2695 (unless (looking-at "[ \t]*$")
2696 (setq ind (min ind (org-get-indentation))))
2697 (beginning-of-line 2))
2698 (goto-char (point-min))
2699 (while (not (eobp))
2700 (unless (looking-at "[ \t]*$")
2701 (move-to-column ind)
2702 (delete-region (point-at-bol) (point)))
2703 (beginning-of-line 2))
2705 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2707 (goto-char (point-min))
2708 (when indent
2709 (while (and (not (eobp)) (re-search-forward "^" nil t))
2710 (replace-match indent t t)))
2711 (goto-char (point-min))
2712 (while (looking-at "[ \t]*\n") (replace-match ""))
2713 (goto-char (point-max))
2714 (when (> (org-current-line)
2715 n-lines)
2716 (org-goto-line (1+ n-lines))
2717 (backward-char 1))
2718 (setq txt (buffer-substring (point-min) (point)))))))))
2719 txt))
2721 (defun org-agenda-collect-markers ()
2722 "Collect the markers pointing to entries in the agenda buffer."
2723 (let (m markers)
2724 (save-excursion
2725 (goto-char (point-min))
2726 (while (not (eobp))
2727 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2728 (org-get-at-bol 'org-marker)))
2729 (push m markers))
2730 (beginning-of-line 2)))
2731 (nreverse markers)))
2733 (defun org-create-marker-find-array (marker-list)
2734 "Create a alist of files names with all marker positions in that file."
2735 (let (f tbl m a p)
2736 (while (setq m (pop marker-list))
2737 (setq p (marker-position m)
2738 f (buffer-file-name (or (buffer-base-buffer
2739 (marker-buffer m))
2740 (marker-buffer m))))
2741 (if (setq a (assoc f tbl))
2742 (push (marker-position m) (cdr a))
2743 (push (list f p) tbl)))
2744 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2745 tbl)))
2747 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2748 (defun org-check-agenda-marker-table ()
2749 "Check of the current entry is on the marker list."
2750 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2752 (and (setq a (assoc file org-agenda-marker-table))
2753 (save-match-data
2754 (save-excursion
2755 (org-back-to-heading t)
2756 (member (point) (cdr a)))))))
2758 (defun org-check-for-org-mode ()
2759 "Make sure current buffer is in org-mode. Error if not."
2760 (or (org-mode-p)
2761 (error "Cannot execute org-mode agenda command on buffer in %s"
2762 major-mode)))
2764 (defun org-fit-agenda-window ()
2765 "Fit the window to the buffer size."
2766 (and (memq org-agenda-window-setup '(reorganize-frame))
2767 (fboundp 'fit-window-to-buffer)
2768 (org-fit-window-to-buffer
2770 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2771 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2773 ;;; Agenda prepare and finalize
2775 (defvar org-agenda-multi nil) ; dynamically scoped
2776 (defvar org-agenda-buffer-name "*Org Agenda*")
2777 (defvar org-pre-agenda-window-conf nil)
2778 (defvar org-agenda-columns-active nil)
2779 (defvar org-agenda-name nil)
2780 (defvar org-agenda-filter nil)
2781 (defvar org-agenda-filter-preset nil
2782 "A preset of the tags filter used for secondary agenda filtering.
2783 This must be a list of strings, each string must be a single tag preceded
2784 by \"+\" or \"-\".
2785 This variable should not be set directly, but agenda custom commands can
2786 bind it in the options section. The preset filter is a global property of
2787 the entire agenda view. In a block agenda, it will not work reliably to
2788 define a filter for one of the individual blocks. You need to set it in
2789 the global options and expect it to be applied to the entire view.")
2791 (defun org-prepare-agenda (&optional name)
2792 (setq org-todo-keywords-for-agenda nil)
2793 (setq org-done-keywords-for-agenda nil)
2794 (setq org-drawers-for-agenda nil)
2795 (unless org-agenda-persistent-filter
2796 (setq org-agenda-filter nil))
2797 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2798 (if org-agenda-multi
2799 (progn
2800 (setq buffer-read-only nil)
2801 (goto-char (point-max))
2802 (unless (or (bobp) org-agenda-compact-blocks)
2803 (insert "\n"
2804 (if (stringp org-agenda-block-separator)
2805 org-agenda-block-separator
2806 (make-string (window-width) org-agenda-block-separator))
2807 "\n"))
2808 (narrow-to-region (point) (point-max)))
2809 (org-agenda-reset-markers)
2810 (setq org-agenda-contributing-files nil)
2811 (setq org-agenda-columns-active nil)
2812 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2813 (setq org-todo-keywords-for-agenda
2814 (org-uniquify org-todo-keywords-for-agenda))
2815 (setq org-done-keywords-for-agenda
2816 (org-uniquify org-done-keywords-for-agenda))
2817 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2818 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2819 (awin (get-buffer-window abuf)))
2820 (cond
2821 ((equal (current-buffer) abuf) nil)
2822 (awin (select-window awin))
2823 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2824 ((equal org-agenda-window-setup 'current-window)
2825 (switch-to-buffer abuf))
2826 ((equal org-agenda-window-setup 'other-window)
2827 (org-switch-to-buffer-other-window abuf))
2828 ((equal org-agenda-window-setup 'other-frame)
2829 (switch-to-buffer-other-frame abuf))
2830 ((equal org-agenda-window-setup 'reorganize-frame)
2831 (delete-other-windows)
2832 (org-switch-to-buffer-other-window abuf)))
2833 ;; additional test in case agenda is invoked from within agenda
2834 ;; buffer via elisp link
2835 (unless (equal (current-buffer) abuf)
2836 (switch-to-buffer abuf)))
2837 (setq buffer-read-only nil)
2838 (let ((inhibit-read-only t)) (erase-buffer))
2839 (org-agenda-mode)
2840 (and name (not org-agenda-name)
2841 (org-set-local 'org-agenda-name name)))
2842 (setq buffer-read-only nil))
2844 (defun org-finalize-agenda ()
2845 "Finishing touch for the agenda buffer, called just before displaying it."
2846 (unless org-agenda-multi
2847 (save-excursion
2848 (let ((inhibit-read-only t))
2849 (goto-char (point-min))
2850 (while (org-activate-bracket-links (point-max))
2851 (add-text-properties (match-beginning 0) (match-end 0)
2852 '(face org-link)))
2853 (org-agenda-align-tags)
2854 (unless org-agenda-with-colors
2855 (remove-text-properties (point-min) (point-max) '(face nil))))
2856 (if (and (boundp 'org-agenda-overriding-columns-format)
2857 org-agenda-overriding-columns-format)
2858 (org-set-local 'org-agenda-overriding-columns-format
2859 org-agenda-overriding-columns-format))
2860 (if (and (boundp 'org-agenda-view-columns-initially)
2861 org-agenda-view-columns-initially)
2862 (org-agenda-columns))
2863 (when org-agenda-fontify-priorities
2864 (org-agenda-fontify-priorities))
2865 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2866 (org-agenda-dim-blocked-tasks))
2867 (org-agenda-mark-clocking-task)
2868 (when org-agenda-entry-text-mode
2869 (org-agenda-entry-text-hide)
2870 (org-agenda-entry-text-show))
2871 (if (functionp 'org-habit-insert-consistency-graphs)
2872 (org-habit-insert-consistency-graphs))
2873 (run-hooks 'org-finalize-agenda-hook)
2874 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2875 (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
2876 (org-agenda-filter-apply org-agenda-filter))
2879 (defun org-agenda-mark-clocking-task ()
2880 "Mark the current clock entry in the agenda if it is present."
2881 (mapc (lambda (o)
2882 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
2883 (delete-overlay o)))
2884 (overlays-in (point-min) (point-max)))
2885 (when (marker-buffer org-clock-hd-marker)
2886 (save-excursion
2887 (goto-char (point-min))
2888 (let (s ov)
2889 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2890 (goto-char s)
2891 (when (equal (org-get-at-bol 'org-hd-marker)
2892 org-clock-hd-marker)
2893 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
2894 (overlay-put ov 'type 'org-agenda-clocking)
2895 (overlay-put ov 'face 'org-agenda-clocking)
2896 (overlay-put ov 'help-echo
2897 "The clock is running in this item")))))))
2899 (defun org-agenda-fontify-priorities ()
2900 "Make highest priority lines bold, and lowest italic."
2901 (interactive)
2902 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
2903 (delete-overlay o)))
2904 (overlays-in (point-min) (point-max)))
2905 (save-excursion
2906 (let ((inhibit-read-only t)
2907 b e p ov h l)
2908 (goto-char (point-min))
2909 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2910 (setq h (or (get-char-property (point) 'org-highest-priority)
2911 org-highest-priority)
2912 l (or (get-char-property (point) 'org-lowest-priority)
2913 org-lowest-priority)
2914 p (string-to-char (match-string 1))
2915 b (match-beginning 0)
2916 e (if (eq org-agenda-fontify-priorities 'cookies)
2917 (match-end 0)
2918 (point-at-eol))
2919 ov (make-overlay b e))
2920 (overlay-put
2921 ov 'face
2922 (cond ((org-face-from-face-or-color
2923 'priority nil
2924 (cdr (assoc p org-priority-faces))))
2925 ((and (listp org-agenda-fontify-priorities)
2926 (org-face-from-face-or-color
2927 'priority nil
2928 (cdr (assoc p org-agenda-fontify-priorities)))))
2929 ((equal p l) 'italic)
2930 ((equal p h) 'bold)))
2931 (overlay-put ov 'org-type 'org-priority)))))
2933 (defun org-agenda-dim-blocked-tasks ()
2934 "Dim currently blocked TODO's in the agenda display."
2935 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
2936 (delete-overlay o)))
2937 (overlays-in (point-min) (point-max)))
2938 (save-excursion
2939 (let ((inhibit-read-only t)
2940 (org-depend-tag-blocked nil)
2941 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2942 org-blocked-by-checkboxes
2943 invis1 b e p ov h l)
2944 (goto-char (point-min))
2945 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2946 (and pos (goto-char (1+ pos))))
2947 (setq org-blocked-by-checkboxes nil invis1 invis)
2948 (let ((marker (org-get-at-bol 'org-hd-marker)))
2949 (when (and marker
2950 (not (with-current-buffer (marker-buffer marker)
2951 (save-excursion
2952 (goto-char marker)
2953 (if (org-entry-get nil "NOBLOCKING")
2954 t ;; Never block this entry
2955 (run-hook-with-args-until-failure
2956 'org-blocker-hook
2957 (list :type 'todo-state-change
2958 :position marker
2959 :from 'todo
2960 :to 'done)))))))
2961 (if org-blocked-by-checkboxes (setq invis1 nil))
2962 (setq b (if invis1
2963 (max (point-min) (1- (point-at-bol)))
2964 (point-at-bol))
2965 e (point-at-eol)
2966 ov (make-overlay b e))
2967 (if invis1
2968 (overlay-put ov 'invisible t)
2969 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2970 (overlay-put ov 'org-type 'org-blocked-todo)))))))
2972 (defvar org-agenda-skip-function nil
2973 "Function to be called at each match during agenda construction.
2974 If this function returns nil, the current match should not be skipped.
2975 Otherwise, the function must return a position from where the search
2976 should be continued.
2977 This may also be a Lisp form, it will be evaluated.
2978 Never set this variable using `setq' or so, because then it will apply
2979 to all future agenda commands. Instead, bind it with `let' to scope
2980 it dynamically into the agenda-constructing command. A good way to set
2981 it is through options in `org-agenda-custom-commands'.")
2983 (defun org-agenda-skip ()
2984 "Throw to `:skip' in places that should be skipped.
2985 Also moves point to the end of the skipped region, so that search can
2986 continue from there."
2987 (let ((p (point-at-bol)) to fp)
2988 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2989 (get-text-property p :org-archived)
2990 (org-end-of-subtree t)
2991 (throw :skip t))
2992 (and org-agenda-skip-comment-trees
2993 (get-text-property p :org-comment)
2994 (org-end-of-subtree t)
2995 (throw :skip t))
2996 (if (equal (char-after p) ?#) (throw :skip t))
2997 (when (and (or (setq fp (functionp org-agenda-skip-function))
2998 (consp org-agenda-skip-function))
2999 (setq to (save-excursion
3000 (save-match-data
3001 (if fp
3002 (funcall org-agenda-skip-function)
3003 (eval org-agenda-skip-function))))))
3004 (goto-char to)
3005 (throw :skip t))))
3007 (defvar org-agenda-markers nil
3008 "List of all currently active markers created by `org-agenda'.")
3009 (defvar org-agenda-last-marker-time (org-float-time)
3010 "Creation time of the last agenda marker.")
3012 (defun org-agenda-new-marker (&optional pos)
3013 "Return a new agenda marker.
3014 Org-mode keeps a list of these markers and resets them when they are
3015 no longer in use."
3016 (let ((m (copy-marker (or pos (point)))))
3017 (setq org-agenda-last-marker-time (org-float-time))
3018 (push m org-agenda-markers)
3021 (defun org-agenda-reset-markers ()
3022 "Reset markers created by `org-agenda'."
3023 (while org-agenda-markers
3024 (move-marker (pop org-agenda-markers) nil)))
3026 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3027 "Save relative positions of markers in region."
3028 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3029 org-agenda-markers))
3031 ;;; Entry text mode
3033 (defun org-agenda-entry-text-show-here ()
3034 "Add some text from the entry as context to the current line."
3035 (let (m txt o)
3036 (setq m (org-get-at-bol 'org-hd-marker))
3037 (unless (marker-buffer m)
3038 (error "No marker points to an entry here"))
3039 (setq txt (concat "\n" (org-no-properties
3040 (org-agenda-get-some-entry-text
3041 m org-agenda-entry-text-maxlines " > "))))
3042 (when (string-match "\\S-" txt)
3043 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3044 (overlay-put o 'evaporate t)
3045 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3046 (overlay-put o 'after-string txt))))
3048 (defun org-agenda-entry-text-show ()
3049 "Add entry context for all agenda lines."
3050 (interactive)
3051 (save-excursion
3052 (goto-char (point-max))
3053 (beginning-of-line 1)
3054 (while (not (bobp))
3055 (when (org-get-at-bol 'org-hd-marker)
3056 (org-agenda-entry-text-show-here))
3057 (beginning-of-line 0))))
3059 (defun org-agenda-entry-text-hide ()
3060 "Remove any shown entry context."
3061 (delq nil
3062 (mapcar (lambda (o)
3063 (if (eq (overlay-get o 'org-overlay-type)
3064 'agenda-entry-content)
3065 (progn (delete-overlay o) t)))
3066 (overlays-in (point-min) (point-max)))))
3068 ;;; Agenda timeline
3070 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3072 (defun org-timeline (&optional include-all)
3073 "Show a time-sorted view of the entries in the current org file.
3074 Only entries with a time stamp of today or later will be listed. With
3075 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3076 under the current date.
3077 If the buffer contains an active region, only check the region for
3078 dates."
3079 (interactive "P")
3080 (org-compile-prefix-format 'timeline)
3081 (org-set-sorting-strategy 'timeline)
3082 (let* ((dopast t)
3083 (dotodo include-all)
3084 (doclosed org-agenda-show-log)
3085 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3086 (current-buffer))))
3087 (date (calendar-current-date))
3088 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3089 (end (if (org-region-active-p) (region-end) (point-max)))
3090 (day-numbers (org-get-all-dates beg end 'no-ranges
3091 t doclosed ; always include today
3092 org-timeline-show-empty-dates))
3093 (org-deadline-warning-days 0)
3094 (org-agenda-only-exact-dates t)
3095 (today (time-to-days (current-time)))
3096 (past t)
3097 args
3098 s e rtn d emptyp wd)
3099 (setq org-agenda-redo-command
3100 (list 'progn
3101 (list 'org-switch-to-buffer-other-window (current-buffer))
3102 (list 'org-timeline (list 'quote include-all))))
3103 (if (not dopast)
3104 ;; Remove past dates from the list of dates.
3105 (setq day-numbers (delq nil (mapcar (lambda(x)
3106 (if (>= x today) x nil))
3107 day-numbers))))
3108 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3109 (if doclosed (push :closed args))
3110 (push :timestamp args)
3111 (push :deadline args)
3112 (push :scheduled args)
3113 (push :sexp args)
3114 (if dotodo (push :todo args))
3115 (insert "Timeline of file " entry "\n")
3116 (add-text-properties (point-min) (point)
3117 (list 'face 'org-agenda-structure))
3118 (org-agenda-mark-header-line (point-min))
3119 (while (setq d (pop day-numbers))
3120 (if (and (listp d) (eq (car d) :omitted))
3121 (progn
3122 (setq s (point))
3123 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3124 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3125 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3126 (if (and (>= d today)
3127 dopast
3128 past)
3129 (progn
3130 (setq past nil)
3131 (insert (make-string 79 ?-) "\n")))
3132 (setq date (calendar-gregorian-from-absolute d)
3133 wd (calendar-day-of-week date))
3134 (setq s (point))
3135 (setq rtn (and (not emptyp)
3136 (apply 'org-agenda-get-day-entries entry
3137 date args)))
3138 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3139 (progn
3140 (insert
3141 (if (stringp org-agenda-format-date)
3142 (format-time-string org-agenda-format-date
3143 (org-time-from-absolute date))
3144 (funcall org-agenda-format-date date))
3145 "\n")
3146 (put-text-property s (1- (point)) 'face
3147 (if (member wd org-agenda-weekend-days)
3148 'org-agenda-date-weekend
3149 'org-agenda-date))
3150 (put-text-property s (1- (point)) 'org-date-line t)
3151 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3152 (if (equal d today)
3153 (put-text-property s (1- (point)) 'org-today t))
3154 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3155 (put-text-property s (1- (point)) 'day d)))))
3156 (goto-char (point-min))
3157 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3158 (point-min)))
3159 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3160 (org-finalize-agenda)
3161 (setq buffer-read-only t)))
3163 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3164 "Return a list of all relevant day numbers from BEG to END buffer positions.
3165 If NO-RANGES is non-nil, include only the start and end dates of a range,
3166 not every single day in the range. If FORCE-TODAY is non-nil, make
3167 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3168 inactive time stamps (those in square brackets) are included.
3169 When EMPTY is non-nil, also include days without any entries."
3170 (let ((re (concat
3171 (if pre-re pre-re "")
3172 (if inactive org-ts-regexp-both org-ts-regexp)))
3173 dates dates1 date day day1 day2 ts1 ts2)
3174 (if force-today
3175 (setq dates (list (time-to-days (current-time)))))
3176 (save-excursion
3177 (goto-char beg)
3178 (while (re-search-forward re end t)
3179 (setq day (time-to-days (org-time-string-to-time
3180 (substring (match-string 1) 0 10))))
3181 (or (memq day dates) (push day dates)))
3182 (unless no-ranges
3183 (goto-char beg)
3184 (while (re-search-forward org-tr-regexp end t)
3185 (setq ts1 (substring (match-string 1) 0 10)
3186 ts2 (substring (match-string 2) 0 10)
3187 day1 (time-to-days (org-time-string-to-time ts1))
3188 day2 (time-to-days (org-time-string-to-time ts2)))
3189 (while (< (setq day1 (1+ day1)) day2)
3190 (or (memq day1 dates) (push day1 dates)))))
3191 (setq dates (sort dates '<))
3192 (when empty
3193 (while (setq day (pop dates))
3194 (setq day2 (car dates))
3195 (push day dates1)
3196 (when (and day2 empty)
3197 (if (or (eq empty t)
3198 (and (numberp empty) (<= (- day2 day) empty)))
3199 (while (< (setq day (1+ day)) day2)
3200 (push (list day) dates1))
3201 (push (cons :omitted (- day2 day)) dates1))))
3202 (setq dates (nreverse dates1)))
3203 dates)))
3205 ;;; Agenda Daily/Weekly
3207 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
3208 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3209 "Custom commands can set this variable in the options section.")
3210 (defvar org-agenda-last-arguments nil
3211 "The arguments of the previous call to `org-agenda'.")
3212 (defvar org-starting-day nil) ; local variable in the agenda buffer
3213 (defvar org-agenda-span nil) ; local variable in the agenda buffer
3214 (defvar org-include-all-loc nil) ; local variable
3216 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3217 "List of types searched for when creating the daily/weekly agenda.
3218 This variable is a list of symbols that controls the types of
3219 items that appear in the daily/weekly agenda. Allowed symbols in this
3220 list are are
3222 :timestamp List items containing a date stamp or date range matching
3223 the selected date. This includes sexp entries in
3224 angular brackets.
3226 :sexp List entries resulting from plain diary-like sexps.
3228 :deadline List deadline due on that date. When the date is today,
3229 also list any deadlines past due, or due within
3230 `org-deadline-warning-days'. `:deadline' must appear before
3231 `:scheduled' if the setting of
3232 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3233 any effect.
3235 :scheduled List all items which are scheduled for the given date.
3236 The diary for *today* also contains items which were
3237 scheduled earlier and are not yet marked DONE.
3239 By default, all four types are turned on.
3241 Never set this variable globally using `setq', because then it
3242 will apply to all future agenda commands. Instead, bind it with
3243 `let' to scope it dynamically into the the agenda-constructing
3244 command. A good way to set it is through options in
3245 `org-agenda-custom-commands'. For a more flexible (though
3246 somewhat less efficient) way of determining what is included in
3247 the daily/weekly agenda, see `org-agenda-skip-function'.")
3249 ;;;###autoload
3250 (defun org-agenda-list (&optional include-all start-day ndays)
3251 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3252 The view will be for the current day or week, but from the overview buffer
3253 you will be able to go to other days/weeks.
3255 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3256 all unfinished TODO items will also be shown, before the agenda.
3257 This feature is considered obsolete, please use the TODO list or a block
3258 agenda instead.
3260 With a numeric prefix argument in an interactive call, the agenda will
3261 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
3262 the number of days. NDAYS defaults to `org-agenda-ndays'.
3264 START-DAY defaults to TODAY, or to the most recent match for the weekday
3265 given in `org-agenda-start-on-weekday'."
3266 (interactive "P")
3267 (if (and (integerp include-all) (> include-all 0))
3268 (setq ndays include-all include-all nil))
3269 (setq ndays (or ndays org-agenda-ndays)
3270 start-day (or start-day org-agenda-start-day))
3271 (if org-agenda-overriding-arguments
3272 (setq include-all (car org-agenda-overriding-arguments)
3273 start-day (nth 1 org-agenda-overriding-arguments)
3274 ndays (nth 2 org-agenda-overriding-arguments)))
3275 (if (stringp start-day)
3276 ;; Convert to an absolute day number
3277 (setq start-day (time-to-days (org-read-date nil t start-day))))
3278 (setq org-agenda-last-arguments (list include-all start-day ndays))
3279 (org-compile-prefix-format 'agenda)
3280 (org-set-sorting-strategy 'agenda)
3281 (let* ((org-agenda-start-on-weekday
3282 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3283 org-agenda-start-on-weekday nil))
3284 (thefiles (org-agenda-files nil 'ifmode))
3285 (files thefiles)
3286 (today (time-to-days
3287 (time-subtract (current-time)
3288 (list 0 (* 3600 org-extend-today-until) 0))))
3289 (sd (or start-day today))
3290 (start (if (or (null org-agenda-start-on-weekday)
3291 (< org-agenda-ndays 7))
3293 (let* ((nt (calendar-day-of-week
3294 (calendar-gregorian-from-absolute sd)))
3295 (n1 org-agenda-start-on-weekday)
3296 (d (- nt n1)))
3297 (- sd (+ (if (< d 0) 7 0) d)))))
3298 (day-numbers (list start))
3299 (day-cnt 0)
3300 (inhibit-redisplay (not debug-on-error))
3301 s e rtn rtnall file date d start-pos end-pos todayp nd wd
3302 clocktable-start clocktable-end)
3303 (setq org-agenda-redo-command
3304 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3305 ;; Make the list of days
3306 (setq ndays (or ndays org-agenda-ndays)
3307 nd ndays)
3308 (while (> ndays 1)
3309 (push (1+ (car day-numbers)) day-numbers)
3310 (setq ndays (1- ndays)))
3311 (setq day-numbers (nreverse day-numbers))
3312 (setq clocktable-start (car day-numbers)
3313 clocktable-end (1+ (or (org-last day-numbers) 0)))
3314 (org-prepare-agenda "Day/Week")
3315 (org-set-local 'org-starting-day (car day-numbers))
3316 (org-set-local 'org-include-all-loc include-all)
3317 (org-set-local 'org-agenda-span
3318 (org-agenda-ndays-to-span nd))
3319 (when (and (or include-all org-agenda-include-all-todo)
3320 (member today day-numbers))
3321 (setq files thefiles
3322 rtnall nil)
3323 (while (setq file (pop files))
3324 (catch 'nextfile
3325 (org-check-agenda-file file)
3326 (setq date (calendar-gregorian-from-absolute today)
3327 rtn (org-agenda-get-day-entries
3328 file date :todo))
3329 (setq rtnall (append rtnall rtn))))
3330 (when rtnall
3331 (insert "All currently open TODO items:\n")
3332 (add-text-properties (point-min) (1- (point))
3333 (list 'face 'org-agenda-structure
3334 'short-heading "All TODO items"))
3335 (org-agenda-mark-header-line (point-min))
3336 (insert (org-finalize-agenda-entries rtnall) "\n")))
3337 (unless org-agenda-compact-blocks
3338 (let* ((d1 (car day-numbers))
3339 (d2 (org-last day-numbers))
3340 (w1 (org-days-to-iso-week d1))
3341 (w2 (org-days-to-iso-week d2)))
3342 (setq s (point))
3343 (if org-agenda-overriding-header
3344 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3345 nil 'face 'org-agenda-structure) "\n")
3346 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3347 "-agenda"
3348 (if (< (- d2 d1) 350)
3349 (if (= w1 w2)
3350 (format " (W%02d)" w1)
3351 (format " (W%02d-W%02d)" w1 w2))
3353 ":\n")))
3354 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3355 'org-date-line t))
3356 (org-agenda-mark-header-line s))
3357 (while (setq d (pop day-numbers))
3358 (setq date (calendar-gregorian-from-absolute d)
3359 wd (calendar-day-of-week date)
3360 s (point))
3361 (if (or (setq todayp (= d today))
3362 (and (not start-pos) (= d sd)))
3363 (setq start-pos (point))
3364 (if (and start-pos (not end-pos))
3365 (setq end-pos (point))))
3366 (setq files thefiles
3367 rtnall nil)
3368 (while (setq file (pop files))
3369 (catch 'nextfile
3370 (org-check-agenda-file file)
3371 (let ((org-agenda-entry-types org-agenda-entry-types))
3372 (unless org-agenda-include-deadlines
3373 (setq org-agenda-entry-types
3374 (delq :deadline org-agenda-entry-types)))
3375 (cond
3376 ((eq org-agenda-show-log 'only)
3377 (setq rtn (org-agenda-get-day-entries
3378 file date :closed)))
3379 (org-agenda-show-log
3380 (setq rtn (apply 'org-agenda-get-day-entries
3381 file date
3382 (append '(:closed) org-agenda-entry-types))))
3384 (setq rtn (apply 'org-agenda-get-day-entries
3385 file date
3386 org-agenda-entry-types)))))
3387 (setq rtnall (append rtnall rtn))))
3388 (if org-agenda-include-diary
3389 (let ((org-agenda-search-headline-for-time t))
3390 (require 'diary-lib)
3391 (setq rtn (org-get-entries-from-diary date))
3392 (setq rtnall (append rtnall rtn))))
3393 (if (or rtnall org-agenda-show-all-dates)
3394 (progn
3395 (setq day-cnt (1+ day-cnt))
3396 (insert
3397 (if (stringp org-agenda-format-date)
3398 (format-time-string org-agenda-format-date
3399 (org-time-from-absolute date))
3400 (funcall org-agenda-format-date date))
3401 "\n")
3402 (put-text-property s (1- (point)) 'face
3403 (if (member wd org-agenda-weekend-days)
3404 'org-agenda-date-weekend
3405 'org-agenda-date))
3406 (put-text-property s (1- (point)) 'org-date-line t)
3407 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3408 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3409 (when todayp
3410 (put-text-property s (1- (point)) 'org-today t)
3411 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
3412 (if rtnall (insert
3413 (org-finalize-agenda-entries
3414 (org-agenda-add-time-grid-maybe
3415 rtnall nd todayp))
3416 "\n"))
3417 (put-text-property s (1- (point)) 'day d)
3418 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3419 (when (and org-agenda-clockreport-mode clocktable-start)
3420 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3421 ;; the above line is to ensure the restricted range!
3422 (p org-agenda-clockreport-parameter-plist)
3423 tbl)
3424 (setq p (org-plist-delete p :block))
3425 (setq p (plist-put p :tstart clocktable-start))
3426 (setq p (plist-put p :tend clocktable-end))
3427 (setq p (plist-put p :scope 'agenda))
3428 (setq tbl (apply 'org-get-clocktable p))
3429 (insert tbl)))
3430 (goto-char (point-min))
3431 (or org-agenda-multi (org-fit-agenda-window))
3432 (unless (and (pos-visible-in-window-p (point-min))
3433 (pos-visible-in-window-p (point-max)))
3434 (goto-char (1- (point-max)))
3435 (recenter -1)
3436 (if (not (pos-visible-in-window-p (or start-pos 1)))
3437 (progn
3438 (goto-char (or start-pos 1))
3439 (recenter 1))))
3440 (goto-char (or start-pos 1))
3441 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3442 (org-finalize-agenda)
3443 (setq buffer-read-only t)
3444 (message "")))
3446 (defun org-agenda-ndays-to-span (n)
3447 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3449 ;;; Agenda word search
3451 (defvar org-agenda-search-history nil)
3452 (defvar org-todo-only nil)
3454 (defvar org-search-syntax-table nil
3455 "Special syntax table for org-mode search.
3456 In this table, we have single quotes not as word constituents, to
3457 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3459 (defun org-search-syntax-table ()
3460 (unless org-search-syntax-table
3461 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3462 (modify-syntax-entry ?' "." org-search-syntax-table)
3463 (modify-syntax-entry ?` "." org-search-syntax-table))
3464 org-search-syntax-table)
3466 (defvar org-agenda-last-search-view-search-was-boolean nil)
3468 ;;;###autoload
3469 (defun org-search-view (&optional todo-only string edit-at)
3470 "Show all entries that contain a phrase or words or regular expressions.
3472 With optional prefix argument TODO-ONLY, only consider entries that are
3473 TODO entries. The argument STRING can be used to pass a default search
3474 string into this function. If EDIT-AT is non-nil, it means that the
3475 user should get a chance to edit this string, with cursor at position
3476 EDIT-AT.
3478 The search string can be viewed either as a phrase that should be found as
3479 is, or it can be broken into a number of snippets, each of which must match
3480 in a Boolean way to select an entry. The default depends on the variable
3481 `org-agenda-search-view-always-boolean'.
3482 Even if this is turned off (the default) you can always switch to
3483 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3485 The default is a direct search of the whole phrase, where each space in
3486 the search string can expand to an arbitrary amount of whitespace,
3487 including newlines.
3489 If using a Boolean search, the search string is split on whitespace and
3490 each snippet is searched separately, with logical AND to select an entry.
3491 Words prefixed with a minus must *not* occur in the entry. Words without
3492 a prefix or prefixed with a plus must occur in the entry. Matching is
3493 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3494 match whole words, not parts of a word) if
3495 `org-agenda-search-view-force-full-words' is set (default is nil).
3497 Boolean search snippets enclosed by curly braces are interpreted as
3498 regular expressions that must or (when preceded with \"-\") must not
3499 match in the entry. Snippets enclosed into double quotes will be taken
3500 as a whole, to include whitespace.
3502 - If the search string starts with an asterisk, search only in headlines.
3503 - If (possibly after the leading star) the search string starts with an
3504 exclamation mark, this also means to look at TODO entries only, an effect
3505 that can also be achieved with a prefix argument.
3506 - If (possibly after star and exclamation mark) the search string starts
3507 with a colon, this will mean that the (non-regexp) snippets of the
3508 Boolean search must match as full words.
3510 This command searches the agenda files, and in addition the files listed
3511 in `org-agenda-text-search-extra-files'."
3512 (interactive "P")
3513 (org-compile-prefix-format 'search)
3514 (org-set-sorting-strategy 'search)
3515 (org-prepare-agenda "SEARCH")
3516 (let* ((props (list 'face nil
3517 'done-face 'org-agenda-done
3518 'org-not-done-regexp org-not-done-regexp
3519 'org-todo-regexp org-todo-regexp
3520 'org-complex-heading-regexp org-complex-heading-regexp
3521 'mouse-face 'highlight
3522 'help-echo (format "mouse-2 or RET jump to location")))
3523 (full-words org-agenda-search-view-force-full-words)
3524 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3525 regexp rtn rtnall files file pos
3526 marker category tags c neg re boolean
3527 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3528 (unless (and (not edit-at)
3529 (stringp string)
3530 (string-match "\\S-" string))
3531 (setq string (read-string
3532 (if org-agenda-search-view-always-boolean
3533 "[+-]Word/{Regexp} ...: "
3534 "Phrase, or [+-]Word/{Regexp} ...: ")
3535 (cond
3536 ((integerp edit-at) (cons string edit-at))
3537 (edit-at string))
3538 'org-agenda-search-history)))
3539 (org-set-local 'org-todo-only todo-only)
3540 (setq org-agenda-redo-command
3541 (list 'org-search-view (if todo-only t nil) string
3542 '(if current-prefix-arg 1 nil)))
3543 (setq org-agenda-query-string string)
3545 (if (equal (string-to-char string) ?*)
3546 (setq hdl-only t
3547 words (substring string 1))
3548 (setq words string))
3549 (when (equal (string-to-char words) ?!)
3550 (setq todo-only t
3551 words (substring words 1)))
3552 (when (equal (string-to-char words) ?:)
3553 (setq full-words t
3554 words (substring words 1)))
3555 (if (or org-agenda-search-view-always-boolean
3556 (member (string-to-char words) '(?- ?+ ?\{)))
3557 (setq boolean t))
3558 (setq words (org-split-string words))
3559 (let (www w)
3560 (while (setq w (pop words))
3561 (while (and (string-match "\\\\\\'" w) words)
3562 (setq w (concat (substring w 0 -1) " " (pop words))))
3563 (push w www))
3564 (setq words (nreverse www) www nil)
3565 (while (setq w (pop words))
3566 (when (and (string-match "\\`[-+]?{" w)
3567 (not (string-match "}\\'" w)))
3568 (while (and words (not (string-match "}\\'" (car words))))
3569 (setq w (concat w " " (pop words))))
3570 (setq w (concat w " " (pop words))))
3571 (push w www))
3572 (setq words (nreverse www)))
3573 (setq org-agenda-last-search-view-search-was-boolean boolean)
3574 (when boolean
3575 (let (wds w)
3576 (while (setq w (pop words))
3577 (if (or (equal (substring w 0 1) "\"")
3578 (and (> (length w) 1)
3579 (member (substring w 0 1) '("+" "-"))
3580 (equal (substring w 1 2) "\"")))
3581 (while (and words (not (equal (substring w -1) "\"")))
3582 (setq w (concat w " " (pop words)))))
3583 (and (string-match "\\`\\([-+]?\\)\"" w)
3584 (setq w (replace-match "\\1" nil nil w)))
3585 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3586 (push w wds))
3587 (setq words (nreverse wds))))
3588 (if boolean
3589 (mapc (lambda (w)
3590 (setq c (string-to-char w))
3591 (if (equal c ?-)
3592 (setq neg t w (substring w 1))
3593 (if (equal c ?+)
3594 (setq neg nil w (substring w 1))
3595 (setq neg nil)))
3596 (if (string-match "\\`{.*}\\'" w)
3597 (setq re (substring w 1 -1))
3598 (if full-words
3599 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3600 (setq re (regexp-quote (downcase w)))))
3601 (if neg (push re regexps-) (push re regexps+)))
3602 words)
3603 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3604 regexps+))
3605 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3606 (if (not regexps+)
3607 (setq regexp (concat "^" org-outline-regexp))
3608 (setq regexp (pop regexps+))
3609 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3610 regexp))))
3611 (setq files (org-agenda-files nil 'ifmode))
3612 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3613 (pop org-agenda-text-search-extra-files)
3614 (setq files (org-add-archive-files files)))
3615 (setq files (append files org-agenda-text-search-extra-files)
3616 rtnall nil)
3617 (while (setq file (pop files))
3618 (setq ee nil)
3619 (catch 'nextfile
3620 (org-check-agenda-file file)
3621 (setq buffer (if (file-exists-p file)
3622 (org-get-agenda-file-buffer file)
3623 (error "No such file %s" file)))
3624 (if (not buffer)
3625 ;; If file does not exist, make sure an error message is sent
3626 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3627 file))))
3628 (with-current-buffer buffer
3629 (with-syntax-table (org-search-syntax-table)
3630 (unless (org-mode-p)
3631 (error "Agenda file %s is not in `org-mode'" file))
3632 (let ((case-fold-search t))
3633 (save-excursion
3634 (save-restriction
3635 (if org-agenda-restrict
3636 (narrow-to-region org-agenda-restrict-begin
3637 org-agenda-restrict-end)
3638 (widen))
3639 (goto-char (point-min))
3640 (unless (or (org-on-heading-p)
3641 (outline-next-heading))
3642 (throw 'nextfile t))
3643 (goto-char (max (point-min) (1- (point))))
3644 (while (re-search-forward regexp nil t)
3645 (org-back-to-heading t)
3646 (skip-chars-forward "* ")
3647 (setq beg (point-at-bol)
3648 beg1 (point)
3649 end (progn (outline-next-heading) (point)))
3650 (catch :skip
3651 (goto-char beg)
3652 (org-agenda-skip)
3653 (setq str (buffer-substring-no-properties
3654 (point-at-bol)
3655 (if hdl-only (point-at-eol) end)))
3656 (mapc (lambda (wr) (when (string-match wr str)
3657 (goto-char (1- end))
3658 (throw :skip t)))
3659 regexps-)
3660 (mapc (lambda (wr) (unless (string-match wr str)
3661 (goto-char (1- end))
3662 (throw :skip t)))
3663 (if todo-only
3664 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3665 regexps+)
3666 regexps+))
3667 (goto-char beg)
3668 (setq marker (org-agenda-new-marker (point))
3669 category (org-get-category)
3670 tags (org-get-tags-at (point))
3671 txt (org-format-agenda-item
3673 (buffer-substring-no-properties
3674 beg1 (point-at-eol))
3675 category tags))
3676 (org-add-props txt props
3677 'org-marker marker 'org-hd-marker marker
3678 'org-todo-regexp org-todo-regexp
3679 'org-complex-heading-regexp org-complex-heading-regexp
3680 'priority 1000 'org-category category
3681 'type "search")
3682 (push txt ee)
3683 (goto-char (1- end))))))))))
3684 (setq rtn (nreverse ee))
3685 (setq rtnall (append rtnall rtn)))
3686 (if org-agenda-overriding-header
3687 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3688 nil 'face 'org-agenda-structure) "\n")
3689 (insert "Search words: ")
3690 (add-text-properties (point-min) (1- (point))
3691 (list 'face 'org-agenda-structure))
3692 (setq pos (point))
3693 (insert string "\n")
3694 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3695 (setq pos (point))
3696 (unless org-agenda-multi
3697 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3698 (add-text-properties pos (1- (point))
3699 (list 'face 'org-agenda-structure))))
3700 (org-agenda-mark-header-line (point-min))
3701 (when rtnall
3702 (insert (org-finalize-agenda-entries rtnall) "\n"))
3703 (goto-char (point-min))
3704 (or org-agenda-multi (org-fit-agenda-window))
3705 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3706 (org-finalize-agenda)
3707 (setq buffer-read-only t)))
3709 ;;; Agenda TODO list
3711 (defvar org-select-this-todo-keyword nil)
3712 (defvar org-last-arg nil)
3714 ;;;###autoload
3715 (defun org-todo-list (arg)
3716 "Show all (not done) TODO entries from all agenda file in a single list.
3717 The prefix arg can be used to select a specific TODO keyword and limit
3718 the list to these. When using \\[universal-argument], you will be prompted
3719 for a keyword. A numeric prefix directly selects the Nth keyword in
3720 `org-todo-keywords-1'."
3721 (interactive "P")
3722 (org-compile-prefix-format 'todo)
3723 (org-set-sorting-strategy 'todo)
3724 (org-prepare-agenda "TODO")
3725 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3726 (let* ((today (time-to-days (current-time)))
3727 (date (calendar-gregorian-from-absolute today))
3728 (kwds org-todo-keywords-for-agenda)
3729 (completion-ignore-case t)
3730 (org-select-this-todo-keyword
3731 (if (stringp arg) arg
3732 (and arg (integerp arg) (> arg 0)
3733 (nth (1- arg) kwds))))
3734 rtn rtnall files file pos)
3735 (when (equal arg '(4))
3736 (setq org-select-this-todo-keyword
3737 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3738 (mapcar 'list kwds) nil nil)))
3739 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3740 (org-set-local 'org-last-arg arg)
3741 (setq org-agenda-redo-command
3742 '(org-todo-list (or current-prefix-arg org-last-arg)))
3743 (setq files (org-agenda-files nil 'ifmode)
3744 rtnall nil)
3745 (while (setq file (pop files))
3746 (catch 'nextfile
3747 (org-check-agenda-file file)
3748 (setq rtn (org-agenda-get-day-entries file date :todo))
3749 (setq rtnall (append rtnall rtn))))
3750 (if org-agenda-overriding-header
3751 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3752 nil 'face 'org-agenda-structure) "\n")
3753 (insert "Global list of TODO items of type: ")
3754 (add-text-properties (point-min) (1- (point))
3755 (list 'face 'org-agenda-structure
3756 'short-heading
3757 (concat "ToDo: "
3758 (or org-select-this-todo-keyword "ALL"))))
3759 (org-agenda-mark-header-line (point-min))
3760 (setq pos (point))
3761 (insert (or org-select-this-todo-keyword "ALL") "\n")
3762 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3763 (setq pos (point))
3764 (unless org-agenda-multi
3765 (insert "Available with `N r': (0)ALL")
3766 (let ((n 0) s)
3767 (mapc (lambda (x)
3768 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3769 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3770 (insert "\n "))
3771 (insert " " s))
3772 kwds))
3773 (insert "\n"))
3774 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3775 (org-agenda-mark-header-line (point-min))
3776 (when rtnall
3777 (insert (org-finalize-agenda-entries rtnall) "\n"))
3778 (goto-char (point-min))
3779 (or org-agenda-multi (org-fit-agenda-window))
3780 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3781 (org-finalize-agenda)
3782 (setq buffer-read-only t)))
3784 ;;; Agenda tags match
3786 ;;;###autoload
3787 (defun org-tags-view (&optional todo-only match)
3788 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3789 The prefix arg TODO-ONLY limits the search to TODO entries."
3790 (interactive "P")
3791 (org-compile-prefix-format 'tags)
3792 (org-set-sorting-strategy 'tags)
3793 (let* ((org-tags-match-list-sublevels
3794 org-tags-match-list-sublevels)
3795 (completion-ignore-case t)
3796 rtn rtnall files file pos matcher
3797 buffer)
3798 (when (and (stringp match) (not (string-match "\\S-" match)))
3799 (setq match nil))
3800 (setq matcher (org-make-tags-matcher match)
3801 match (car matcher) matcher (cdr matcher))
3802 (org-prepare-agenda (concat "TAGS " match))
3803 (setq org-agenda-query-string match)
3804 (setq org-agenda-redo-command
3805 (list 'org-tags-view (list 'quote todo-only)
3806 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3807 (setq files (org-agenda-files nil 'ifmode)
3808 rtnall nil)
3809 (while (setq file (pop files))
3810 (catch 'nextfile
3811 (org-check-agenda-file file)
3812 (setq buffer (if (file-exists-p file)
3813 (org-get-agenda-file-buffer file)
3814 (error "No such file %s" file)))
3815 (if (not buffer)
3816 ;; If file does not exist, error message to agenda
3817 (setq rtn (list
3818 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3819 rtnall (append rtnall rtn))
3820 (with-current-buffer buffer
3821 (unless (org-mode-p)
3822 (error "Agenda file %s is not in `org-mode'" file))
3823 (save-excursion
3824 (save-restriction
3825 (if org-agenda-restrict
3826 (narrow-to-region org-agenda-restrict-begin
3827 org-agenda-restrict-end)
3828 (widen))
3829 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3830 (setq rtnall (append rtnall rtn))))))))
3831 (if org-agenda-overriding-header
3832 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3833 nil 'face 'org-agenda-structure) "\n")
3834 (insert "Headlines with TAGS match: ")
3835 (add-text-properties (point-min) (1- (point))
3836 (list 'face 'org-agenda-structure
3837 'short-heading
3838 (concat "Match: " match)))
3839 (setq pos (point))
3840 (insert match "\n")
3841 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3842 (setq pos (point))
3843 (unless org-agenda-multi
3844 (insert "Press `C-u r' to search again with new search string\n"))
3845 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3846 (org-agenda-mark-header-line (point-min))
3847 (when rtnall
3848 (insert (org-finalize-agenda-entries rtnall) "\n"))
3849 (goto-char (point-min))
3850 (or org-agenda-multi (org-fit-agenda-window))
3851 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3852 (org-finalize-agenda)
3853 (setq buffer-read-only t)))
3855 ;;; Agenda Finding stuck projects
3857 (defvar org-agenda-skip-regexp nil
3858 "Regular expression used in skipping subtrees for the agenda.
3859 This is basically a temporary global variable that can be set and then
3860 used by user-defined selections using `org-agenda-skip-function'.")
3862 (defvar org-agenda-overriding-header nil
3863 "When this is set during todo and tags searches, will replace header.
3864 This variable should not be set directly, but custom commands can bind it
3865 in the options section.")
3867 (defun org-agenda-skip-entry-when-regexp-matches ()
3868 "Check if the current entry contains match for `org-agenda-skip-regexp'.
3869 If yes, it returns the end position of this entry, causing agenda commands
3870 to skip the entry but continuing the search in the subtree. This is a
3871 function that can be put into `org-agenda-skip-function' for the duration
3872 of a command."
3873 (let ((end (save-excursion (org-end-of-subtree t)))
3874 skip)
3875 (save-excursion
3876 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3877 (and skip end)))
3879 (defun org-agenda-skip-subtree-when-regexp-matches ()
3880 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
3881 If yes, it returns the end position of this tree, causing agenda commands
3882 to skip this subtree. This is a function that can be put into
3883 `org-agenda-skip-function' for the duration of a command."
3884 (let ((end (save-excursion (org-end-of-subtree t)))
3885 skip)
3886 (save-excursion
3887 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3888 (and skip end)))
3890 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3891 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
3892 If yes, it returns the end position of the current entry (NOT the tree),
3893 causing agenda commands to skip the entry but continuing the search in
3894 the subtree. This is a function that can be put into
3895 `org-agenda-skip-function' for the duration of a command. An important
3896 use of this function is for the stuck project list."
3897 (let ((end (save-excursion (org-end-of-subtree t)))
3898 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3899 skip)
3900 (save-excursion
3901 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3902 (and skip entry-end)))
3904 (defun org-agenda-skip-entry-if (&rest conditions)
3905 "Skip entry if any of CONDITIONS is true.
3906 See `org-agenda-skip-if' for details."
3907 (org-agenda-skip-if nil conditions))
3909 (defun org-agenda-skip-subtree-if (&rest conditions)
3910 "Skip entry if any of CONDITIONS is true.
3911 See `org-agenda-skip-if' for details."
3912 (org-agenda-skip-if t conditions))
3914 (defun org-agenda-skip-if (subtree conditions)
3915 "Checks current entity for CONDITIONS.
3916 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3917 the entry, i.e. the text before the next heading is checked.
3919 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3920 from different tests. Valid conditions are:
3922 scheduled Check if there is a scheduled cookie
3923 notscheduled Check if there is no scheduled cookie
3924 deadline Check if there is a deadline
3925 notdeadline Check if there is no deadline
3926 timestamp Check if there is a timestamp (also deadline or scheduled)
3927 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3928 regexp Check if regexp matches
3929 notregexp Check if regexp does not match.
3930 todo Check if TODO keyword matches
3931 nottodo Check if TODO keyword does not match
3933 The regexp is taken from the conditions list, it must come right after
3934 the `regexp' or `notregexp' element.
3936 `todo' and `nottodo' accept as an argument a list of todo
3937 keywords, which may include \"*\" to match any todo keyword.
3939 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
3941 would skip all entries with \"TODO\" or \"WAITING\" keywords.
3943 Instead of a list a keyword class may be given
3945 (org-agenda-skip-entry-if 'nottodo 'done)
3947 would skip entries that haven't been marked with any of \"DONE\"
3948 keywords. Possible classes are: `todo', `done', `any'.
3950 If any of these conditions is met, this function returns the end point of
3951 the entity, causing the search to continue from there. This is a function
3952 that can be put into `org-agenda-skip-function' for the duration of a command."
3953 (let (beg end m)
3954 (org-back-to-heading t)
3955 (setq beg (point)
3956 end (if subtree
3957 (progn (org-end-of-subtree t) (point))
3958 (progn (outline-next-heading) (1- (point)))))
3959 (goto-char beg)
3960 (and
3962 (and (memq 'scheduled conditions)
3963 (re-search-forward org-scheduled-time-regexp end t))
3964 (and (memq 'notscheduled conditions)
3965 (not (re-search-forward org-scheduled-time-regexp end t)))
3966 (and (memq 'deadline conditions)
3967 (re-search-forward org-deadline-time-regexp end t))
3968 (and (memq 'notdeadline conditions)
3969 (not (re-search-forward org-deadline-time-regexp end t)))
3970 (and (memq 'timestamp conditions)
3971 (re-search-forward org-ts-regexp end t))
3972 (and (memq 'nottimestamp conditions)
3973 (not (re-search-forward org-ts-regexp end t)))
3974 (and (setq m (memq 'regexp conditions))
3975 (stringp (nth 1 m))
3976 (re-search-forward (nth 1 m) end t))
3977 (and (setq m (memq 'notregexp conditions))
3978 (stringp (nth 1 m))
3979 (not (re-search-forward (nth 1 m) end t)))
3980 (and (or
3981 (setq m (memq 'todo conditions))
3982 (setq m (memq 'nottodo conditions)))
3983 (org-agenda-skip-if-todo m end)))
3984 end)))
3986 (defun org-agenda-skip-if-todo (args end)
3987 "Helper function for `org-agenda-skip-if', do not use it directly.
3988 ARGS is a list with first element either `todo' or `nottodo'.
3989 The remainder is either a list of TODO keywords, or a state symbol
3990 `todo' or `done' or `any'."
3991 (let ((kw (car args))
3992 (arg (cadr args))
3993 todo-wds todo-re)
3994 (setq todo-wds
3995 (org-uniquify
3996 (cond
3997 ((listp arg) ;; list of keywords
3998 (if (member "*" arg)
3999 (mapcar 'substring-no-properties org-todo-keywords-1)
4000 arg))
4001 ((symbolp arg) ;; keyword class name
4002 (cond
4003 ((eq arg 'todo)
4004 (org-delete-all org-done-keywords
4005 (mapcar 'substring-no-properties
4006 org-todo-keywords-1)))
4007 ((eq arg 'done) org-done-keywords)
4008 ((eq arg 'any)
4009 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4010 (setq todo-re
4011 (concat "^\\*+[ \t]+\\<\\("
4012 (mapconcat 'identity todo-wds "\\|")
4013 "\\)\\>"))
4014 (if (eq kw 'todo)
4015 (re-search-forward todo-re end t)
4016 (not (re-search-forward todo-re end t)))))
4018 ;;;###autoload
4019 (defun org-agenda-list-stuck-projects (&rest ignore)
4020 "Create agenda view for projects that are stuck.
4021 Stuck projects are project that have no next actions. For the definitions
4022 of what a project is and how to check if it stuck, customize the variable
4023 `org-stuck-projects'."
4024 (interactive)
4025 (let* ((org-agenda-skip-function
4026 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4027 ;; We could have used org-agenda-skip-if here.
4028 (org-agenda-overriding-header
4029 (or org-agenda-overriding-header "List of stuck projects: "))
4030 (matcher (nth 0 org-stuck-projects))
4031 (todo (nth 1 org-stuck-projects))
4032 (todo-wds (if (member "*" todo)
4033 (progn
4034 (org-prepare-agenda-buffers (org-agenda-files
4035 nil 'ifmode))
4036 (org-delete-all
4037 org-done-keywords-for-agenda
4038 (copy-sequence org-todo-keywords-for-agenda)))
4039 todo))
4040 (todo-re (concat "^\\*+[ \t]+\\("
4041 (mapconcat 'identity todo-wds "\\|")
4042 "\\)\\>"))
4043 (tags (nth 2 org-stuck-projects))
4044 (tags-re (if (member "*" tags)
4045 (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
4046 (if tags
4047 (concat "^\\*+ .*:\\("
4048 (mapconcat 'identity tags "\\|")
4049 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4050 (gen-re (nth 3 org-stuck-projects))
4051 (re-list
4052 (delq nil
4053 (list
4054 (if todo todo-re)
4055 (if tags tags-re)
4056 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4057 gen-re)))))
4058 (setq org-agenda-skip-regexp
4059 (if re-list
4060 (mapconcat 'identity re-list "\\|")
4061 (error "No information how to identify unstuck projects")))
4062 (org-tags-view nil matcher)
4063 (with-current-buffer org-agenda-buffer-name
4064 (setq org-agenda-redo-command
4065 '(org-agenda-list-stuck-projects
4066 (or current-prefix-arg org-last-arg))))))
4068 ;;; Diary integration
4070 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4071 (defvar list-diary-entries-hook)
4073 (defun org-get-entries-from-diary (date)
4074 "Get the (Emacs Calendar) diary entries for DATE."
4075 (require 'diary-lib)
4076 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4077 (diary-display-hook '(fancy-diary-display))
4078 (diary-display-function 'fancy-diary-display)
4079 (pop-up-frames nil)
4080 (list-diary-entries-hook
4081 (cons 'org-diary-default-entry list-diary-entries-hook))
4082 (diary-file-name-prefix-function nil) ; turn this feature off
4083 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4084 entries
4085 (org-disable-agenda-to-diary t))
4086 (save-excursion
4087 (save-window-excursion
4088 (funcall (if (fboundp 'diary-list-entries)
4089 'diary-list-entries 'list-diary-entries)
4090 date 1)))
4091 (if (not (get-buffer diary-fancy-buffer))
4092 (setq entries nil)
4093 (with-current-buffer diary-fancy-buffer
4094 (setq buffer-read-only nil)
4095 (if (zerop (buffer-size))
4096 ;; No entries
4097 (setq entries nil)
4098 ;; Omit the date and other unnecessary stuff
4099 (org-agenda-cleanup-fancy-diary)
4100 ;; Add prefix to each line and extend the text properties
4101 (if (zerop (buffer-size))
4102 (setq entries nil)
4103 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
4104 (set-buffer-modified-p nil)
4105 (kill-buffer diary-fancy-buffer)))
4106 (when entries
4107 (setq entries (org-split-string entries "\n"))
4108 (setq entries
4109 (mapcar
4110 (lambda (x)
4111 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4112 ;; Extend the text properties to the beginning of the line
4113 (org-add-props x (text-properties-at (1- (length x)) x)
4114 'type "diary" 'date date 'face 'org-agenda-diary))
4115 entries)))))
4117 (defvar org-agenda-cleanup-fancy-diary-hook nil
4118 "Hook run when the fancy diary buffer is cleaned up.")
4120 (defun org-agenda-cleanup-fancy-diary ()
4121 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4122 This gets rid of the date, the underline under the date, and
4123 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4124 date. It also removes lines that contain only whitespace."
4125 (goto-char (point-min))
4126 (if (looking-at ".*?:[ \t]*")
4127 (progn
4128 (replace-match "")
4129 (re-search-forward "\n=+$" nil t)
4130 (replace-match "")
4131 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4132 (re-search-forward "\n=+$" nil t)
4133 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4134 (goto-char (point-min))
4135 (while (re-search-forward "^ +\n" nil t)
4136 (replace-match ""))
4137 (goto-char (point-min))
4138 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4139 (replace-match ""))
4140 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4142 ;; Make sure entries from the diary have the right text properties.
4143 (eval-after-load "diary-lib"
4144 '(if (boundp 'diary-modify-entry-list-string-function)
4145 ;; We can rely on the hook, nothing to do
4147 ;; Hook not available, must use advice to make this work
4148 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4149 "Make the position visible."
4150 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4151 (stringp string)
4152 buffer-file-name)
4153 (setq string (org-modify-diary-entry-string string))))))
4155 (defun org-modify-diary-entry-string (string)
4156 "Add text properties to string, allowing org-mode to act on it."
4157 (org-add-props string nil
4158 'mouse-face 'highlight
4159 'help-echo (if buffer-file-name
4160 (format "mouse-2 or RET jump to diary file %s"
4161 (abbreviate-file-name buffer-file-name))
4163 'org-agenda-diary-link t
4164 'org-marker (org-agenda-new-marker (point-at-bol))))
4166 (defun org-diary-default-entry ()
4167 "Add a dummy entry to the diary.
4168 Needed to avoid empty dates which mess up holiday display."
4169 ;; Catch the error if dealing with the new add-to-diary-alist
4170 (when org-disable-agenda-to-diary
4171 (condition-case nil
4172 (org-add-to-diary-list original-date "Org-mode dummy" "")
4173 (error
4174 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4176 (defun org-add-to-diary-list (&rest args)
4177 (if (fboundp 'diary-add-to-list)
4178 (apply 'diary-add-to-list args)
4179 (apply 'add-to-diary-list args)))
4181 (defvar org-diary-last-run-time nil)
4183 ;;;###autoload
4184 (defun org-diary (&rest args)
4185 "Return diary information from org-files.
4186 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4187 It accesses org files and extracts information from those files to be
4188 listed in the diary. The function accepts arguments specifying what
4189 items should be listed. For a list of arguments allowed here, see the
4190 variable `org-agenda-entry-types'.
4192 The call in the diary file should look like this:
4194 &%%(org-diary) ~/path/to/some/orgfile.org
4196 Use a separate line for each org file to check. Or, if you omit the file name,
4197 all files listed in `org-agenda-files' will be checked automatically:
4199 &%%(org-diary)
4201 If you don't give any arguments (as in the example above), the default
4202 arguments (:deadline :scheduled :timestamp :sexp) are used.
4203 So the example above may also be written as
4205 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4207 The function expects the lisp variables `entry' and `date' to be provided
4208 by the caller, because this is how the calendar works. Don't use this
4209 function from a program - use `org-agenda-get-day-entries' instead."
4210 (when (> (- (org-float-time)
4211 org-agenda-last-marker-time)
4213 (org-agenda-reset-markers))
4214 (org-compile-prefix-format 'agenda)
4215 (org-set-sorting-strategy 'agenda)
4216 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4217 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4218 (list entry)
4219 (org-agenda-files t)))
4220 (time (org-float-time))
4221 file rtn results)
4222 (when (or (not org-diary-last-run-time)
4223 (> (- time
4224 org-diary-last-run-time)
4226 (org-prepare-agenda-buffers files))
4227 (setq org-diary-last-run-time time)
4228 ;; If this is called during org-agenda, don't return any entries to
4229 ;; the calendar. Org Agenda will list these entries itself.
4230 (if org-disable-agenda-to-diary (setq files nil))
4231 (while (setq file (pop files))
4232 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4233 (setq results (append results rtn)))
4234 (if results
4235 (concat (org-finalize-agenda-entries results) "\n"))))
4237 ;;; Agenda entry finders
4239 (defun org-agenda-get-day-entries (file date &rest args)
4240 "Does the work for `org-diary' and `org-agenda'.
4241 FILE is the path to a file to be checked for entries. DATE is date like
4242 the one returned by `calendar-current-date'. ARGS are symbols indicating
4243 which kind of entries should be extracted. For details about these, see
4244 the documentation of `org-diary'."
4245 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4246 (let* ((org-startup-folded nil)
4247 (org-startup-align-all-tables nil)
4248 (buffer (if (file-exists-p file)
4249 (org-get-agenda-file-buffer file)
4250 (error "No such file %s" file)))
4251 arg results rtn deadline-results)
4252 (if (not buffer)
4253 ;; If file does not exist, make sure an error message ends up in diary
4254 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4255 (with-current-buffer buffer
4256 (unless (org-mode-p)
4257 (error "Agenda file %s is not in `org-mode'" file))
4258 (let ((case-fold-search nil))
4259 (save-excursion
4260 (save-restriction
4261 (if org-agenda-restrict
4262 (narrow-to-region org-agenda-restrict-begin
4263 org-agenda-restrict-end)
4264 (widen))
4265 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4266 (while (setq arg (pop args))
4267 (cond
4268 ((and (eq arg :todo)
4269 (equal date (calendar-current-date)))
4270 (setq rtn (org-agenda-get-todos))
4271 (setq results (append results rtn)))
4272 ((eq arg :timestamp)
4273 (setq rtn (org-agenda-get-blocks))
4274 (setq results (append results rtn))
4275 (setq rtn (org-agenda-get-timestamps))
4276 (setq results (append results rtn)))
4277 ((eq arg :sexp)
4278 (setq rtn (org-agenda-get-sexps))
4279 (setq results (append results rtn)))
4280 ((eq arg :scheduled)
4281 (setq rtn (org-agenda-get-scheduled deadline-results))
4282 (setq results (append results rtn)))
4283 ((eq arg :closed)
4284 (setq rtn (org-agenda-get-progress))
4285 (setq results (append results rtn)))
4286 ((eq arg :deadline)
4287 (setq rtn (org-agenda-get-deadlines))
4288 (setq deadline-results (copy-sequence rtn))
4289 (setq results (append results rtn))))))))
4290 results))))
4292 (defun org-agenda-get-todos ()
4293 "Return the TODO information for agenda display."
4294 (let* ((props (list 'face nil
4295 'done-face 'org-agenda-done
4296 'org-not-done-regexp org-not-done-regexp
4297 'org-todo-regexp org-todo-regexp
4298 'org-complex-heading-regexp org-complex-heading-regexp
4299 'mouse-face 'highlight
4300 'help-echo
4301 (format "mouse-2 or RET jump to org file %s"
4302 (abbreviate-file-name buffer-file-name))))
4303 (regexp (concat "^\\*+[ \t]+\\("
4304 (if org-select-this-todo-keyword
4305 (if (equal org-select-this-todo-keyword "*")
4306 org-todo-regexp
4307 (concat "\\<\\("
4308 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4309 "\\)\\>"))
4310 org-not-done-regexp)
4311 "[^\n\r]*\\)"))
4312 marker priority category tags todo-state
4313 ee txt beg end)
4314 (goto-char (point-min))
4315 (while (re-search-forward regexp nil t)
4316 (catch :skip
4317 (save-match-data
4318 (beginning-of-line)
4319 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4320 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4321 (goto-char (1+ beg))
4322 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4323 (throw :skip nil)))
4324 (goto-char beg)
4325 (org-agenda-skip)
4326 (goto-char (match-beginning 1))
4327 (setq marker (org-agenda-new-marker (match-beginning 0))
4328 category (org-get-category)
4329 txt (match-string 1)
4330 tags (org-get-tags-at (point))
4331 txt (org-format-agenda-item "" txt category tags)
4332 priority (1+ (org-get-priority txt))
4333 todo-state (org-get-todo-state))
4334 (org-add-props txt props
4335 'org-marker marker 'org-hd-marker marker
4336 'priority priority 'org-category category
4337 'type "todo" 'todo-state todo-state)
4338 (push txt ee)
4339 (if org-agenda-todo-list-sublevels
4340 (goto-char (match-end 1))
4341 (org-end-of-subtree 'invisible))))
4342 (nreverse ee)))
4344 ;;;###autoload
4345 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4346 (&optional end)
4347 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4348 (when (or org-agenda-todo-ignore-with-date
4349 org-agenda-todo-ignore-scheduled
4350 org-agenda-todo-ignore-deadlines)
4351 (setq end (or end (save-excursion (outline-next-heading) (point))))
4352 (save-excursion
4353 (or (and org-agenda-todo-ignore-with-date
4354 (re-search-forward org-ts-regexp end t))
4355 (and org-agenda-todo-ignore-scheduled
4356 (re-search-forward org-scheduled-time-regexp end t)
4357 (cond
4358 ((eq org-agenda-todo-ignore-scheduled 'future)
4359 (> (org-days-to-time (match-string 1)) 0))
4360 ((eq org-agenda-todo-ignore-scheduled 'past)
4361 (<= (org-days-to-time (match-string 1)) 0))
4362 (t)))
4363 (and org-agenda-todo-ignore-deadlines
4364 (re-search-forward org-deadline-time-regexp end t)
4365 (cond
4366 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4367 ((eq org-agenda-todo-ignore-deadlines 'far)
4368 (not (org-deadline-close (match-string 1))))
4369 ((eq org-agenda-todo-ignore-deadlines 'future)
4370 (> (org-days-to-time (match-string 1)) 0))
4371 ((eq org-agenda-todo-ignore-deadlines 'past)
4372 (<= (org-days-to-time (match-string 1)) 0))
4373 (t (org-deadline-close (match-string 1)))))))))
4375 (defconst org-agenda-no-heading-message
4376 "No heading for this item in buffer or region.")
4378 (defun org-agenda-get-timestamps ()
4379 "Return the date stamp information for agenda display."
4380 (let* ((props (list 'face nil
4381 'org-not-done-regexp org-not-done-regexp
4382 'org-todo-regexp org-todo-regexp
4383 'org-complex-heading-regexp org-complex-heading-regexp
4384 'mouse-face 'highlight
4385 'help-echo
4386 (format "mouse-2 or RET jump to org file %s"
4387 (abbreviate-file-name buffer-file-name))))
4388 (d1 (calendar-absolute-from-gregorian date))
4389 (remove-re
4390 (concat
4391 (regexp-quote
4392 (format-time-string
4393 "<%Y-%m-%d"
4394 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4395 ".*?>"))
4396 (regexp
4397 (concat
4398 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4399 (regexp-quote
4400 (substring
4401 (format-time-string
4402 (car org-time-stamp-formats)
4403 (apply 'encode-time ; DATE bound by calendar
4404 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4405 1 11))
4406 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4407 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4408 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4409 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4410 todo-state end-of-match)
4411 (goto-char (point-min))
4412 (while (setq end-of-match (re-search-forward regexp nil t))
4413 (setq b0 (match-beginning 0)
4414 b3 (match-beginning 3) e3 (match-end 3))
4415 (catch :skip
4416 (and (org-at-date-range-p) (throw :skip nil))
4417 (org-agenda-skip)
4418 (if (and (match-end 1)
4419 (not (= d1 (org-time-string-to-absolute
4420 (match-string 1) d1 nil
4421 org-agenda-repeating-timestamp-show-all))))
4422 (throw :skip nil))
4423 (if (and e3
4424 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4425 (throw :skip nil))
4426 (setq tmp (buffer-substring (max (point-min)
4427 (- b0 org-ds-keyword-length))
4429 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4430 inactivep (= (char-after b0) ?\[)
4431 deadlinep (string-match org-deadline-regexp tmp)
4432 scheduledp (string-match org-scheduled-regexp tmp)
4433 closedp (and org-agenda-include-inactive-timestamps
4434 (string-match org-closed-string tmp))
4435 clockp (and org-agenda-include-inactive-timestamps
4436 (or (string-match org-clock-string tmp)
4437 (string-match "]-+\\'" tmp)))
4438 todo-state (ignore-errors (org-get-todo-state))
4439 donep (member todo-state org-done-keywords))
4440 (if (or scheduledp deadlinep closedp clockp
4441 (and donep org-agenda-skip-timestamp-if-done))
4442 (throw :skip t))
4443 (if (string-match ">" timestr)
4444 ;; substring should only run to end of time stamp
4445 (setq timestr (substring timestr 0 (match-end 0))))
4446 (setq marker (org-agenda-new-marker b0)
4447 category (org-get-category b0))
4448 (save-excursion
4449 (if (not (re-search-backward "^\\*+ " nil t))
4450 (setq txt org-agenda-no-heading-message)
4451 (goto-char (match-beginning 0))
4452 (setq hdmarker (org-agenda-new-marker)
4453 tags (org-get-tags-at))
4454 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4455 (setq head (match-string 1))
4456 (setq txt (org-format-agenda-item
4457 (if inactivep org-agenda-inactive-leader nil)
4458 head category tags timestr nil
4459 remove-re)))
4460 (setq priority (org-get-priority txt))
4461 (org-add-props txt props
4462 'org-marker marker 'org-hd-marker hdmarker)
4463 (org-add-props txt nil 'priority priority
4464 'org-category category 'date date
4465 'todo-state todo-state
4466 'type "timestamp")
4467 (push txt ee))
4468 (if org-agenda-skip-additional-timestamps-same-entry
4469 (outline-next-heading)
4470 (goto-char end-of-match))))
4471 (nreverse ee)))
4473 (defun org-agenda-get-sexps ()
4474 "Return the sexp information for agenda display."
4475 (require 'diary-lib)
4476 (let* ((props (list 'face nil
4477 'mouse-face 'highlight
4478 'help-echo
4479 (format "mouse-2 or RET jump to org file %s"
4480 (abbreviate-file-name buffer-file-name))))
4481 (regexp "^&?%%(")
4482 marker category ee txt tags entry result beg b sexp sexp-entry
4483 todo-state)
4484 (goto-char (point-min))
4485 (while (re-search-forward regexp nil t)
4486 (catch :skip
4487 (org-agenda-skip)
4488 (setq beg (match-beginning 0))
4489 (goto-char (1- (match-end 0)))
4490 (setq b (point))
4491 (forward-sexp 1)
4492 (setq sexp (buffer-substring b (point)))
4493 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4494 (org-trim (match-string 1))
4495 ""))
4496 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4497 (when result
4498 (setq marker (org-agenda-new-marker beg)
4499 category (org-get-category beg)
4500 todo-state (org-get-todo-state))
4502 (dolist (r (if (stringp result)
4503 (list result)
4504 result)) ;; we expect a list here
4505 (if (string-match "\\S-" r)
4506 (setq txt r)
4507 (setq txt "SEXP entry returned empty string"))
4509 (setq txt (org-format-agenda-item
4510 "" txt category tags 'time))
4511 (org-add-props txt props 'org-marker marker)
4512 (org-add-props txt nil
4513 'org-category category 'date date 'todo-state todo-state
4514 'type "sexp")
4515 (push txt ee)))))
4516 (nreverse ee)))
4518 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4519 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4520 The order of the first 2 times 3 arguments depends on the variable
4521 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4522 So for American calendars, give this as MONTH DAY YEAR, for European as
4523 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4524 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4525 is any number of ISO weeks in the block period for which the item should
4526 be skipped."
4527 (let* ((date1 (calendar-absolute-from-gregorian
4528 (org-order-calendar-date-args m1 d1 y1)))
4529 (date2 (calendar-absolute-from-gregorian
4530 (org-order-calendar-date-args m2 d2 y2)))
4531 (d (calendar-absolute-from-gregorian date)))
4532 (and
4533 (<= date1 d)
4534 (<= d date2)
4535 (= (calendar-day-of-week date) dayname)
4536 (or (not skip-weeks)
4537 (progn
4538 (require 'cal-iso)
4539 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4540 entry)))
4542 (defalias 'org-get-closed 'org-agenda-get-progress)
4543 (defun org-agenda-get-progress ()
4544 "Return the logged TODO entries for agenda display."
4545 (let* ((props (list 'mouse-face 'highlight
4546 'org-not-done-regexp org-not-done-regexp
4547 'org-todo-regexp org-todo-regexp
4548 'org-complex-heading-regexp org-complex-heading-regexp
4549 'help-echo
4550 (format "mouse-2 or RET jump to org file %s"
4551 (abbreviate-file-name buffer-file-name))))
4552 (items (if (consp org-agenda-show-log)
4553 org-agenda-show-log
4554 org-agenda-log-mode-items))
4555 (parts
4556 (delq nil
4557 (list
4558 (if (memq 'closed items) (concat "\\<" org-closed-string))
4559 (if (memq 'clock items) (concat "\\<" org-clock-string))
4560 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4561 (parts-re (if parts (mapconcat 'identity parts "\\|")
4562 (error "`org-agenda-log-mode-items' is empty")))
4563 (regexp (concat
4564 "\\(" parts-re "\\)"
4565 " *\\["
4566 (regexp-quote
4567 (substring
4568 (format-time-string
4569 (car org-time-stamp-formats)
4570 (apply 'encode-time ; DATE bound by calendar
4571 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4572 1 11))))
4573 (org-agenda-search-headline-for-time nil)
4574 marker hdmarker priority category tags closedp statep clockp state
4575 ee txt extra timestr rest clocked)
4576 (goto-char (point-min))
4577 (while (re-search-forward regexp nil t)
4578 (catch :skip
4579 (org-agenda-skip)
4580 (setq marker (org-agenda-new-marker (match-beginning 0))
4581 closedp (equal (match-string 1) org-closed-string)
4582 statep (equal (string-to-char (match-string 1)) ?-)
4583 clockp (not (or closedp statep))
4584 state (and statep (match-string 2))
4585 category (org-get-category (match-beginning 0))
4586 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4588 (when (string-match "\\]" timestr)
4589 ;; substring should only run to end of time stamp
4590 (setq rest (substring timestr (match-end 0))
4591 timestr (substring timestr 0 (match-end 0)))
4592 (if (and (not closedp) (not statep)
4593 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4594 (progn (setq timestr (concat (substring timestr 0 -1)
4595 "-" (match-string 1 rest) "]"))
4596 (setq clocked (match-string 2 rest)))
4597 (setq clocked "-")))
4598 (save-excursion
4599 (setq extra nil)
4600 (cond
4601 ((not org-agenda-log-mode-add-notes))
4602 (statep
4603 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4604 (setq extra (match-string 1))))
4605 (clockp
4606 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4607 (setq extra (match-string 1)))))
4608 (if (not (re-search-backward "^\\*+ " nil t))
4609 (setq txt org-agenda-no-heading-message)
4610 (goto-char (match-beginning 0))
4611 (setq hdmarker (org-agenda-new-marker)
4612 tags (org-get-tags-at))
4613 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4614 (setq txt (match-string 1))
4615 (when extra
4616 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4617 (setq txt (concat (substring txt 0 (match-beginning 1))
4618 " - " extra " " (match-string 2 txt)))
4619 (setq txt (concat txt " - " extra))))
4620 (setq txt (org-format-agenda-item
4621 (cond
4622 (closedp "Closed: ")
4623 (statep (concat "State: (" state ")"))
4624 (t (concat "Clocked: (" clocked ")")))
4625 txt category tags timestr)))
4626 (setq priority 100000)
4627 (org-add-props txt props
4628 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4629 'priority priority 'org-category category
4630 'type "closed" 'date date
4631 'undone-face 'org-warning 'done-face 'org-agenda-done)
4632 (push txt ee))
4633 (goto-char (point-at-eol))))
4634 (nreverse ee)))
4636 (defun org-agenda-get-deadlines ()
4637 "Return the deadline information for agenda display."
4638 (let* ((props (list 'mouse-face 'highlight
4639 'org-not-done-regexp org-not-done-regexp
4640 'org-todo-regexp org-todo-regexp
4641 'org-complex-heading-regexp org-complex-heading-regexp
4642 'help-echo
4643 (format "mouse-2 or RET jump to org file %s"
4644 (abbreviate-file-name buffer-file-name))))
4645 (regexp org-deadline-time-regexp)
4646 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4647 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4648 d2 diff dfrac wdays pos pos1 category tags
4649 suppress-prewarning
4650 ee txt head face s todo-state upcomingp donep timestr)
4651 (goto-char (point-min))
4652 (while (re-search-forward regexp nil t)
4653 (setq suppress-prewarning nil)
4654 (catch :skip
4655 (org-agenda-skip)
4656 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4657 (save-match-data
4658 (string-match org-scheduled-time-regexp
4659 (buffer-substring (point-at-bol)
4660 (point-at-eol)))))
4661 (setq suppress-prewarning
4662 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4663 org-agenda-skip-deadline-prewarning-if-scheduled
4664 0)))
4665 (setq s (match-string 1)
4666 txt nil
4667 pos (1- (match-beginning 1))
4668 d2 (org-time-string-to-absolute
4669 (match-string 1) d1 'past
4670 org-agenda-repeating-timestamp-show-all)
4671 diff (- d2 d1)
4672 wdays (if suppress-prewarning
4673 (let ((org-deadline-warning-days suppress-prewarning))
4674 (org-get-wdays s))
4675 (org-get-wdays s))
4676 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4677 upcomingp (and todayp (> diff 0)))
4678 ;; When to show a deadline in the calendar:
4679 ;; If the expiration is within wdays warning time.
4680 ;; Past-due deadlines are only shown on the current date
4681 (if (and (or (and (<= diff wdays)
4682 (and todayp (not org-agenda-only-exact-dates)))
4683 (= diff 0)))
4684 (save-excursion
4685 (setq todo-state (org-get-todo-state))
4686 (setq donep (member todo-state org-done-keywords))
4687 (if (and donep
4688 (or org-agenda-skip-deadline-if-done
4689 (not (= diff 0))))
4690 (setq txt nil)
4691 (setq category (org-get-category))
4692 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4693 (setq txt org-agenda-no-heading-message)
4694 (goto-char (match-end 0))
4695 (setq pos1 (match-beginning 0))
4696 (setq tags (org-get-tags-at pos1))
4697 (setq head (buffer-substring-no-properties
4698 (point)
4699 (progn (skip-chars-forward "^\r\n")
4700 (point))))
4701 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4702 (setq timestr
4703 (concat (substring s (match-beginning 1)) " "))
4704 (setq timestr 'time))
4705 (setq txt (org-format-agenda-item
4706 (if (= diff 0)
4707 (car org-agenda-deadline-leaders)
4708 (if (functionp
4709 (nth 1 org-agenda-deadline-leaders))
4710 (funcall
4711 (nth 1 org-agenda-deadline-leaders)
4712 diff date)
4713 (format (nth 1 org-agenda-deadline-leaders)
4714 diff)))
4715 head category tags
4716 (if (not (= diff 0)) nil timestr)))))
4717 (when txt
4718 (setq face (org-agenda-deadline-face dfrac wdays))
4719 (org-add-props txt props
4720 'org-marker (org-agenda-new-marker pos)
4721 'org-hd-marker (org-agenda-new-marker pos1)
4722 'priority (+ (- diff)
4723 (org-get-priority txt))
4724 'org-category category
4725 'todo-state todo-state
4726 'type (if upcomingp "upcoming-deadline" "deadline")
4727 'date (if upcomingp date d2)
4728 'face (if donep 'org-agenda-done face)
4729 'undone-face face 'done-face 'org-agenda-done)
4730 (push txt ee))))))
4731 (nreverse ee)))
4733 (defun org-agenda-deadline-face (fraction &optional wdays)
4734 "Return the face to displaying a deadline item.
4735 FRACTION is what fraction of the head-warning time has passed."
4736 (if (equal wdays 0) (setq fraction 1.))
4737 (let ((faces org-agenda-deadline-faces) f)
4738 (catch 'exit
4739 (while (setq f (pop faces))
4740 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4742 (defun org-agenda-get-scheduled (&optional deadline-results)
4743 "Return the scheduled information for agenda display."
4744 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4745 'org-todo-regexp org-todo-regexp
4746 'org-complex-heading-regexp org-complex-heading-regexp
4747 'done-face 'org-agenda-done
4748 'mouse-face 'highlight
4749 'help-echo
4750 (format "mouse-2 or RET jump to org file %s"
4751 (abbreviate-file-name buffer-file-name))))
4752 (regexp org-scheduled-time-regexp)
4753 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4754 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4756 (deadline-position-alist
4757 (mapcar (lambda (a) (and (setq mm (get-text-property
4758 0 'org-hd-marker a))
4759 (cons (marker-position mm) a)))
4760 deadline-results))
4761 d2 diff pos pos1 category tags donep
4762 ee txt head pastschedp todo-state face timestr s habitp)
4763 (goto-char (point-min))
4764 (while (re-search-forward regexp nil t)
4765 (catch :skip
4766 (org-agenda-skip)
4767 (setq s (match-string 1)
4768 txt nil
4769 pos (1- (match-beginning 1))
4770 d2 (org-time-string-to-absolute
4771 (match-string 1) d1 'past
4772 org-agenda-repeating-timestamp-show-all)
4773 diff (- d2 d1))
4774 (setq pastschedp (and todayp (< diff 0)))
4775 ;; When to show a scheduled item in the calendar:
4776 ;; If it is on or past the date.
4777 (when (or (and (< diff 0)
4778 (< (abs diff) org-scheduled-past-days)
4779 (and todayp (not org-agenda-only-exact-dates)))
4780 (= diff 0))
4781 (save-excursion
4782 (setq todo-state (org-get-todo-state))
4783 (setq donep (member todo-state org-done-keywords))
4784 (setq habitp (and (functionp 'org-is-habit-p)
4785 (org-is-habit-p)))
4786 (if (and donep
4787 (or habitp org-agenda-skip-scheduled-if-done
4788 (not (= diff 0))))
4789 (setq txt nil)
4790 (setq category (org-get-category))
4791 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4792 (setq txt org-agenda-no-heading-message)
4793 (goto-char (match-end 0))
4794 (setq pos1 (match-beginning 0))
4795 (if habitp
4796 (if (or (not org-habit-show-habits)
4797 (and (not todayp)
4798 org-habit-show-habits-only-for-today))
4799 (throw :skip nil))
4800 (if (and
4801 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4802 (and org-agenda-skip-scheduled-if-deadline-is-shown
4803 pastschedp))
4804 (setq mm (assoc pos1 deadline-position-alist)))
4805 (throw :skip nil)))
4806 (setq tags (org-get-tags-at))
4807 (setq head (buffer-substring-no-properties
4808 (point)
4809 (progn (skip-chars-forward "^\r\n") (point))))
4810 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4811 (setq timestr
4812 (concat (substring s (match-beginning 1)) " "))
4813 (setq timestr 'time))
4814 (setq txt (org-format-agenda-item
4815 (if (= diff 0)
4816 (car org-agenda-scheduled-leaders)
4817 (format (nth 1 org-agenda-scheduled-leaders)
4818 (- 1 diff)))
4819 head category tags
4820 (if (not (= diff 0)) nil timestr)
4821 nil nil habitp))))
4822 (when txt
4823 (setq face
4824 (cond
4825 ((and (not habitp) pastschedp)
4826 'org-scheduled-previously)
4827 (todayp 'org-scheduled-today)
4828 (t 'org-scheduled))
4829 habitp (and habitp (org-habit-parse-todo)))
4830 (org-add-props txt props
4831 'undone-face face
4832 'face (if donep 'org-agenda-done face)
4833 'org-marker (org-agenda-new-marker pos)
4834 'org-hd-marker (org-agenda-new-marker pos1)
4835 'type (if pastschedp "past-scheduled" "scheduled")
4836 'date (if pastschedp d2 date)
4837 'priority (if habitp
4838 (org-habit-get-priority habitp)
4839 (+ 94 (- 5 diff) (org-get-priority txt)))
4840 'org-category category
4841 'org-habit-p habitp
4842 'todo-state todo-state)
4843 (push txt ee))))))
4844 (nreverse ee)))
4846 (defun org-agenda-get-blocks ()
4847 "Return the date-range information for agenda display."
4848 (let* ((props (list 'face nil
4849 'org-not-done-regexp org-not-done-regexp
4850 'org-todo-regexp org-todo-regexp
4851 'org-complex-heading-regexp org-complex-heading-regexp
4852 'mouse-face 'highlight
4853 'help-echo
4854 (format "mouse-2 or RET jump to org file %s"
4855 (abbreviate-file-name buffer-file-name))))
4856 (regexp org-tr-regexp)
4857 (d0 (calendar-absolute-from-gregorian date))
4858 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4859 head donep)
4860 (goto-char (point-min))
4861 (while (re-search-forward regexp nil t)
4862 (catch :skip
4863 (org-agenda-skip)
4864 (setq pos (point))
4865 (setq timestr (match-string 0)
4866 s1 (match-string 1)
4867 s2 (match-string 2)
4868 d1 (time-to-days (org-time-string-to-time s1))
4869 d2 (time-to-days (org-time-string-to-time s2)))
4870 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4871 ;; Only allow days between the limits, because the normal
4872 ;; date stamps will catch the limits.
4873 (save-excursion
4874 (setq todo-state (org-get-todo-state))
4875 (setq donep (member todo-state org-done-keywords))
4876 (if (and donep org-agenda-skip-timestamp-if-done)
4877 (throw :skip t))
4878 (setq marker (org-agenda-new-marker (point)))
4879 (setq category (org-get-category))
4880 (if (not (re-search-backward "^\\*+ " nil t))
4881 (setq txt org-agenda-no-heading-message)
4882 (goto-char (match-beginning 0))
4883 (setq hdmarker (org-agenda-new-marker (point)))
4884 (setq tags (org-get-tags-at))
4885 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4886 (setq head (match-string 1))
4887 (let ((remove-re
4888 (if org-agenda-remove-timeranges-from-blocks
4889 (concat
4890 "<" (regexp-quote s1) ".*?>"
4891 "--"
4892 "<" (regexp-quote s2) ".*?>")
4893 nil)))
4894 (setq txt (org-format-agenda-item
4895 (format
4896 (nth (if (= d1 d2) 0 1)
4897 org-agenda-timerange-leaders)
4898 (1+ (- d0 d1)) (1+ (- d2 d1)))
4899 head category tags
4900 timestr nil remove-re))))
4901 (org-add-props txt props
4902 'org-marker marker 'org-hd-marker hdmarker
4903 'type "block" 'date date
4904 'todo-state todo-state
4905 'priority (org-get-priority txt) 'org-category category)
4906 (push txt ee)))
4907 (goto-char pos)))
4908 ;; Sort the entries by expiration date.
4909 (nreverse ee)))
4911 ;;; Agenda presentation and sorting
4913 (defvar org-prefix-has-time nil
4914 "A flag, set by `org-compile-prefix-format'.
4915 The flag is set if the currently compiled format contains a `%t'.")
4916 (defvar org-prefix-has-tag nil
4917 "A flag, set by `org-compile-prefix-format'.
4918 The flag is set if the currently compiled format contains a `%T'.")
4919 (defvar org-prefix-has-effort nil
4920 "A flag, set by `org-compile-prefix-format'.
4921 The flag is set if the currently compiled format contains a `%e'.")
4922 (defvar org-prefix-category-length nil
4923 "Used by `org-compile-prefix-format' to remember the category field width.")
4924 (defvar org-prefix-category-max-length nil
4925 "Used by `org-compile-prefix-format' to remember the category field width.")
4927 (defun org-format-agenda-item (extra txt &optional category tags dotime
4928 noprefix remove-re habitp)
4929 "Format TXT to be inserted into the agenda buffer.
4930 In particular, it adds the prefix and corresponding text properties. EXTRA
4931 must be a string and replaces the `%s' specifier in the prefix format.
4932 CATEGORY (string, symbol or nil) may be used to overrule the default
4933 category taken from local variable or file name. It will replace the `%c'
4934 specifier in the format. DOTIME, when non-nil, indicates that a
4935 time-of-day should be extracted from TXT for sorting of this entry, and for
4936 the `%t' specifier in the format. When DOTIME is a string, this string is
4937 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4938 only the correctly processes TXT should be returned - this is used by
4939 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4940 Any match of REMOVE-RE will be removed from TXT."
4941 (save-match-data
4942 ;; Diary entries sometimes have extra whitespace at the beginning
4943 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4945 ;; Fix the tags part in txt
4946 (setq txt (org-agenda-fix-displayed-tags
4947 txt tags
4948 org-agenda-show-inherited-tags
4949 org-agenda-hide-tags-regexp))
4950 (let* ((category (or category
4951 org-category
4952 (if buffer-file-name
4953 (file-name-sans-extension
4954 (file-name-nondirectory buffer-file-name))
4955 "")))
4956 ;; time, tag, effort are needed for the eval of the prefix format
4957 (tag (if tags (nth (1- (length tags)) tags) ""))
4958 time effort neffort
4959 (ts (if dotime (concat
4960 (if (stringp dotime) dotime "")
4961 (and org-agenda-search-headline-for-time txt))))
4962 (time-of-day (and dotime (org-get-time-of-day ts)))
4963 stamp plain s0 s1 s2 t1 t2 rtn srp l
4964 duration thecategory)
4965 (and (org-mode-p) buffer-file-name
4966 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4967 (when (and dotime time-of-day)
4968 ;; Extract starting and ending time and move them to prefix
4969 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4970 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4971 (setq s0 (match-string 0 ts)
4972 srp (and stamp (match-end 3))
4973 s1 (match-string (if plain 1 2) ts)
4974 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4976 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4977 ;; them, we might want to remove them there to avoid duplication.
4978 ;; The user can turn this off with a variable.
4979 (if (and org-prefix-has-time
4980 org-agenda-remove-times-when-in-prefix (or stamp plain)
4981 (string-match (concat (regexp-quote s0) " *") txt)
4982 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4983 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4984 (= (match-beginning 0) 0)
4986 (setq txt (replace-match "" nil nil txt))))
4987 ;; Normalize the time(s) to 24 hour
4988 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4989 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4990 ;; Compute the duration
4991 (when s1
4992 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4993 (string-to-number (substring s1 3)))
4994 t2 (cond
4995 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4996 (string-to-number (substring s2 3))))
4997 (org-agenda-default-appointment-duration
4998 (+ t1 org-agenda-default-appointment-duration))
4999 (t nil)))
5000 (setq duration (if t2 (- t2 t1)))))
5002 (when (and s1 (not s2) org-agenda-default-appointment-duration
5003 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
5004 (let ((m (+ (string-to-number (match-string 2 s1))
5005 (* 60 (string-to-number (match-string 1 s1)))
5006 org-agenda-default-appointment-duration))
5008 (setq h (/ m 60) m (- m (* h 60)))
5009 (setq s2 (format "%02d:%02d" h m))))
5011 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5012 txt)
5013 ;; Tags are in the string
5014 (if (or (eq org-agenda-remove-tags t)
5015 (and org-agenda-remove-tags
5016 org-prefix-has-tag))
5017 (setq txt (replace-match "" t t txt))
5018 (setq txt (replace-match
5019 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5020 (match-string 2 txt))
5021 t t txt))))
5022 (when (org-mode-p)
5023 (setq effort
5024 (condition-case nil
5025 (org-get-effort
5026 (or (get-text-property 0 'org-hd-marker txt)
5027 (get-text-property 0 'org-marker txt)))
5028 (error nil)))
5029 (when effort
5030 (setq neffort (org-hh:mm-string-to-minutes effort)
5031 effort (setq effort (concat "[" effort "]" )))))
5033 (when remove-re
5034 (while (string-match remove-re txt)
5035 (setq txt (replace-match "" t t txt))))
5037 ;; Create the final string
5038 (if noprefix
5039 (setq rtn txt)
5040 ;; Prepare the variables needed in the eval of the compiled format
5041 (setq time (cond (s2 (concat s1 "-" s2))
5042 (s1 (concat s1 "......"))
5043 (t ""))
5044 extra (or (and (not habitp) extra) "")
5045 category (if (symbolp category) (symbol-name category) category)
5046 thecategory (copy-sequence category))
5047 (if (string-match org-bracket-link-regexp category)
5048 (progn
5049 (setq l (if (match-end 3)
5050 (- (match-end 3) (match-beginning 3))
5051 (- (match-end 1) (match-beginning 1))))
5052 (when (< l (or org-prefix-category-length 0))
5053 (setq category (copy-sequence category))
5054 (org-add-props category nil
5055 'extra-space (make-string
5056 (- org-prefix-category-length l 1) ?\ ))))
5057 (if (and org-prefix-category-max-length
5058 (>= (length category) org-prefix-category-max-length))
5059 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5060 ;; Evaluate the compiled format
5061 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
5063 ;; And finally add the text properties
5064 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5065 (org-add-props rtn nil
5066 'org-category (if thecategory (downcase thecategory) category)
5067 'tags (mapcar 'org-downcase-keep-props tags)
5068 'org-highest-priority org-highest-priority
5069 'org-lowest-priority org-lowest-priority
5070 'prefix-length (- (length rtn) (length txt))
5071 'time-of-day time-of-day
5072 'duration duration
5073 'effort effort
5074 'effort-minutes neffort
5075 'txt txt
5076 'time time
5077 'extra extra
5078 'dotime dotime))))
5080 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5081 "Remove tags string from TXT, and add a modified list of tags.
5082 The modified list may contain inherited tags, and tags matched by
5083 `org-agenda-hide-tags-regexp' will be removed."
5084 (when (or add-inherited hide-re)
5085 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5086 (setq txt (substring txt 0 (match-beginning 0))))
5087 (setq tags
5088 (delq nil
5089 (mapcar (lambda (tg)
5090 (if (or (and hide-re (string-match hide-re tg))
5091 (and (not add-inherited)
5092 (get-text-property 0 'inherited tg)))
5094 tg))
5095 tags)))
5096 (when tags
5097 (let ((have-i (get-text-property 0 'inherited (car tags)))
5099 (setq txt (concat txt " :"
5100 (mapconcat
5101 (lambda (x)
5102 (setq i (get-text-property 0 'inherited x))
5103 (if (and have-i (not i))
5104 (progn
5105 (setq have-i nil)
5106 (concat ":" x))
5108 tags ":")
5109 (if have-i "::" ":"))))))
5110 txt)
5112 (defun org-downcase-keep-props (s)
5113 (let ((props (text-properties-at 0 s)))
5114 (setq s (downcase s))
5115 (add-text-properties 0 (length s) props s)
5118 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5119 (defvar org-agenda-sorting-strategy-selected nil)
5121 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5122 (catch 'exit
5123 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5124 ((and todayp (member 'today (car org-agenda-time-grid))))
5125 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5126 ((member 'weekly (car org-agenda-time-grid)))
5127 (t (throw 'exit list)))
5128 (let* ((have (delq nil (mapcar
5129 (lambda (x) (get-text-property 1 'time-of-day x))
5130 list)))
5131 (string (nth 1 org-agenda-time-grid))
5132 (gridtimes (nth 2 org-agenda-time-grid))
5133 (req (car org-agenda-time-grid))
5134 (remove (member 'remove-match req))
5135 new time)
5136 (if (and (member 'require-timed req) (not have))
5137 ;; don't show empty grid
5138 (throw 'exit list))
5139 (while (setq time (pop gridtimes))
5140 (unless (and remove (member time have))
5141 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5142 (push (org-format-agenda-item
5143 nil string "" nil
5144 (concat (substring time 0 -2) ":" (substring time -2)))
5145 new)
5146 (put-text-property
5147 2 (length (car new)) 'face 'org-time-grid (car new))))
5148 (if (member 'time-up org-agenda-sorting-strategy-selected)
5149 (append new list)
5150 (append list new)))))
5152 (defun org-compile-prefix-format (key)
5153 "Compile the prefix format into a Lisp form that can be evaluated.
5154 The resulting form is returned and stored in the variable
5155 `org-prefix-format-compiled'."
5156 (setq org-prefix-has-time nil org-prefix-has-tag nil
5157 org-prefix-category-length nil org-prefix-has-effort nil)
5158 (let ((s (cond
5159 ((stringp org-agenda-prefix-format)
5160 org-agenda-prefix-format)
5161 ((assq key org-agenda-prefix-format)
5162 (cdr (assq key org-agenda-prefix-format)))
5163 (t " %-12:c%?-12t% s")))
5164 (start 0)
5165 varform vars var e c f opt)
5166 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
5167 s start)
5168 (setq var (cdr (assoc (match-string 4 s)
5169 '(("c" . category) ("t" . time) ("s" . extra)
5170 ("T" . tag) ("e" . effort))))
5171 c (or (match-string 3 s) "")
5172 opt (match-beginning 1)
5173 start (1+ (match-beginning 0)))
5174 (if (equal var 'time) (setq org-prefix-has-time t))
5175 (if (equal var 'tag) (setq org-prefix-has-tag t))
5176 (if (equal var 'effort) (setq org-prefix-has-effort t))
5177 (setq f (concat "%" (match-string 2 s) "s"))
5178 (when (equal var 'category)
5179 (setq org-prefix-category-length
5180 (floor (abs (string-to-number (match-string 2 s)))))
5181 (setq org-prefix-category-max-length
5182 (let ((x (match-string 2 s)))
5183 (save-match-data
5184 (if (string-match "\\.[0-9]+" x)
5185 (string-to-number (substring (match-string 0 x) 1)))))))
5186 (if opt
5187 (setq varform
5188 `(if (equal "" ,var)
5190 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5191 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
5192 (setq s (replace-match "%s" t nil s))
5193 (push varform vars))
5194 (setq vars (nreverse vars))
5195 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5197 (defun org-set-sorting-strategy (key)
5198 (if (symbolp (car org-agenda-sorting-strategy))
5199 ;; the old format
5200 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5201 (setq org-agenda-sorting-strategy-selected
5202 (or (cdr (assq key org-agenda-sorting-strategy))
5203 (cdr (assq 'agenda org-agenda-sorting-strategy))
5204 '(time-up category-keep priority-down)))))
5206 (defun org-get-time-of-day (s &optional string mod24)
5207 "Check string S for a time of day.
5208 If found, return it as a military time number between 0 and 2400.
5209 If not found, return nil.
5210 The optional STRING argument forces conversion into a 5 character wide string
5211 HH:MM."
5212 (save-match-data
5213 (when
5214 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5215 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5216 (let* ((h (string-to-number (match-string 1 s)))
5217 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5218 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5219 (am-p (equal ampm "am"))
5220 (h1 (cond ((not ampm) h)
5221 ((= h 12) (if am-p 0 12))
5222 (t (+ h (if am-p 0 12)))))
5223 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5224 (mod h1 24) h1))
5225 (t0 (+ (* 100 h2) m))
5226 (t1 (concat (if (>= h1 24) "+" " ")
5227 (if (and org-agenda-time-leading-zero
5228 (< t0 1000)) "0" "")
5229 (if (< t0 100) "0" "")
5230 (if (< t0 10) "0" "")
5231 (int-to-string t0))))
5232 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5234 (defvar org-agenda-before-sorting-filter-function nil
5235 "Function to be applied to agenda items prior to sorting.
5236 Prior to sorting also means just before they are inserted into the agenda.
5238 To aid sorting, you may revisit the original entries and add more text
5239 properties which will later be used by the sorting functions.
5241 The function should take a string argument, an agenda line.
5242 It has access to the text properties in that line, which contain among
5243 other things, the property `org-hd-marker' that points to the entry
5244 where the line comes from. Note that not all lines going into the agenda
5245 have this property, only most.
5247 The function should return the modified string. It is probably best
5248 to ONLY change text properties.
5250 You can also use this function as a filter, by returning nil for lines
5251 you don't want to have in the agenda at all. For this application, you
5252 could bind the variable in the options section of a custom command.")
5254 (defun org-finalize-agenda-entries (list &optional nosort)
5255 "Sort and concatenate the agenda items."
5256 (setq list (mapcar 'org-agenda-highlight-todo list))
5257 (if nosort
5258 list
5259 (when org-agenda-before-sorting-filter-function
5260 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5261 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5263 (defun org-agenda-highlight-todo (x)
5264 (let ((org-done-keywords org-done-keywords-for-agenda)
5265 (case-fold-search nil)
5266 re pl)
5267 (if (eq x 'line)
5268 (save-excursion
5269 (beginning-of-line 1)
5270 (setq re (org-get-at-bol 'org-todo-regexp))
5271 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
5272 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5273 (add-text-properties (match-beginning 0) (match-end 1)
5274 (list 'face (org-get-todo-face 1)))
5275 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5276 (delete-region (match-beginning 1) (1- (match-end 0)))
5277 (goto-char (match-beginning 1))
5278 (insert (format org-agenda-todo-keyword-format s)))))
5279 (setq re (concat (get-text-property 0 'org-todo-regexp x))
5280 pl (get-text-property 0 'prefix-length x))
5281 (when (and re
5282 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5283 x (or pl 0)) pl))
5284 (add-text-properties
5285 (or (match-end 1) (match-end 0)) (match-end 0)
5286 (list 'face (org-get-todo-face (match-string 2 x)))
5288 (when (match-end 1)
5289 (setq x (concat (substring x 0 (match-end 1))
5290 (format org-agenda-todo-keyword-format
5291 (match-string 2 x))
5292 (org-add-props " " (text-properties-at 0 x))
5293 (substring x (match-end 3))))))
5294 x)))
5296 (defsubst org-cmp-priority (a b)
5297 "Compare the priorities of string A and B."
5298 (let ((pa (or (get-text-property 1 'priority a) 0))
5299 (pb (or (get-text-property 1 'priority b) 0)))
5300 (cond ((> pa pb) +1)
5301 ((< pa pb) -1)
5302 (t nil))))
5304 (defsubst org-cmp-effort (a b)
5305 "Compare the priorities of string A and B."
5306 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5307 (ea (or (get-text-property 1 'effort-minutes a) def))
5308 (eb (or (get-text-property 1 'effort-minutes b) def)))
5309 (cond ((> ea eb) +1)
5310 ((< ea eb) -1)
5311 (t nil))))
5313 (defsubst org-cmp-category (a b)
5314 "Compare the string values of categories of strings A and B."
5315 (let ((ca (or (get-text-property 1 'org-category a) ""))
5316 (cb (or (get-text-property 1 'org-category b) "")))
5317 (cond ((string-lessp ca cb) -1)
5318 ((string-lessp cb ca) +1)
5319 (t nil))))
5321 (defsubst org-cmp-todo-state (a b)
5322 "Compare the todo states of strings A and B."
5323 (let* ((ma (or (get-text-property 1 'org-marker a)
5324 (get-text-property 1 'org-hd-marker a)))
5325 (mb (or (get-text-property 1 'org-marker b)
5326 (get-text-property 1 'org-hd-marker b)))
5327 (fa (and ma (marker-buffer ma)))
5328 (fb (and mb (marker-buffer mb)))
5329 (todo-kwds
5330 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5331 (and fb (with-current-buffer fb org-todo-keywords-1))))
5332 (ta (or (get-text-property 1 'todo-state a) ""))
5333 (tb (or (get-text-property 1 'todo-state b) ""))
5334 (la (- (length (member ta todo-kwds))))
5335 (lb (- (length (member tb todo-kwds))))
5336 (donepa (member ta org-done-keywords-for-agenda))
5337 (donepb (member tb org-done-keywords-for-agenda)))
5338 (cond ((and donepa (not donepb)) -1)
5339 ((and (not donepa) donepb) +1)
5340 ((< la lb) -1)
5341 ((< lb la) +1)
5342 (t nil))))
5344 (defsubst org-cmp-alpha (a b)
5345 "Compare the headlines, alphabetically."
5346 (let* ((pla (get-text-property 0 'prefix-length a))
5347 (plb (get-text-property 0 'prefix-length b))
5348 (ta (and pla (substring a pla)))
5349 (tb (and plb (substring b plb))))
5350 (when pla
5351 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5352 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5353 (setq ta (substring ta (match-end 0))))
5354 (setq ta (downcase ta)))
5355 (when plb
5356 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5357 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5358 (setq tb (substring tb (match-end 0))))
5359 (setq tb (downcase tb)))
5360 (cond ((not ta) +1)
5361 ((not tb) -1)
5362 ((string-lessp ta tb) -1)
5363 ((string-lessp tb ta) +1)
5364 (t nil))))
5366 (defsubst org-cmp-tag (a b)
5367 "Compare the string values of the first tags of A and B."
5368 (let ((ta (car (last (get-text-property 1 'tags a))))
5369 (tb (car (last (get-text-property 1 'tags b)))))
5370 (cond ((not ta) +1)
5371 ((not tb) -1)
5372 ((string-lessp ta tb) -1)
5373 ((string-lessp tb ta) +1)
5374 (t nil))))
5376 (defsubst org-cmp-time (a b)
5377 "Compare the time-of-day values of strings A and B."
5378 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5379 (ta (or (get-text-property 1 'time-of-day a) def))
5380 (tb (or (get-text-property 1 'time-of-day b) def)))
5381 (cond ((< ta tb) -1)
5382 ((< tb ta) +1)
5383 (t nil))))
5385 (defsubst org-cmp-habit-p (a b)
5386 "Compare the todo states of strings A and B."
5387 (let ((ha (get-text-property 1 'org-habit-p a))
5388 (hb (get-text-property 1 'org-habit-p b)))
5389 (cond ((and ha (not hb)) -1)
5390 ((and (not ha) hb) +1)
5391 (t nil))))
5393 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5395 (defun org-entries-lessp (a b)
5396 "Predicate for sorting agenda entries."
5397 ;; The following variables will be used when the form is evaluated.
5398 ;; So even though the compiler complains, keep them.
5399 (let* ((ss org-agenda-sorting-strategy-selected)
5400 (time-up (and (org-em 'time-up 'time-down ss)
5401 (org-cmp-time a b)))
5402 (time-down (if time-up (- time-up) nil))
5403 (priority-up (and (org-em 'priority-up 'priority-down ss)
5404 (org-cmp-priority a b)))
5405 (priority-down (if priority-up (- priority-up) nil))
5406 (effort-up (and (org-em 'effort-up 'effort-down ss)
5407 (org-cmp-effort a b)))
5408 (effort-down (if effort-up (- effort-up) nil))
5409 (category-up (and (or (org-em 'category-up 'category-down ss)
5410 (memq 'category-keep ss))
5411 (org-cmp-category a b)))
5412 (category-down (if category-up (- category-up) nil))
5413 (category-keep (if category-up +1 nil))
5414 (tag-up (and (org-em 'tag-up 'tag-down ss)
5415 (org-cmp-tag a b)))
5416 (tag-down (if tag-up (- tag-up) nil))
5417 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5418 (org-cmp-todo-state a b)))
5419 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5420 (habit-up (and (org-em 'habit-up 'habit-down ss)
5421 (org-cmp-habit-p a b)))
5422 (habit-down (if habit-up (- habit-up) nil))
5423 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5424 (org-cmp-alpha a b)))
5425 (alpha-down (if alpha-up (- alpha-up) nil))
5426 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5427 user-defined-up user-defined-down)
5428 (if (and need-user-cmp org-agenda-cmp-user-defined
5429 (functionp org-agenda-cmp-user-defined))
5430 (setq user-defined-up
5431 (funcall org-agenda-cmp-user-defined a b)
5432 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5433 (cdr (assoc
5434 (eval (cons 'or org-agenda-sorting-strategy-selected))
5435 '((-1 . t) (1 . nil) (nil . nil))))))
5437 ;;; Agenda restriction lock
5439 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5440 "Overlay to mark the headline to which agenda commands are restricted.")
5441 (overlay-put org-agenda-restriction-lock-overlay
5442 'face 'org-agenda-restriction-lock)
5443 (overlay-put org-agenda-restriction-lock-overlay
5444 'help-echo "Agendas are currently limited to this subtree.")
5445 (org-detach-overlay org-agenda-restriction-lock-overlay)
5447 (defun org-agenda-set-restriction-lock (&optional type)
5448 "Set restriction lock for agenda, to current subtree or file.
5449 Restriction will be the file if TYPE is `file', or if type is the
5450 universal prefix '(4), or if the cursor is before the first headline
5451 in the file. Otherwise, restriction will be to the current subtree."
5452 (interactive "P")
5453 (and (equal type '(4)) (setq type 'file))
5454 (setq type (cond
5455 (type type)
5456 ((org-at-heading-p) 'subtree)
5457 ((condition-case nil (org-back-to-heading t) (error nil))
5458 'subtree)
5459 (t 'file)))
5460 (if (eq type 'subtree)
5461 (progn
5462 (setq org-agenda-restrict t)
5463 (setq org-agenda-overriding-restriction 'subtree)
5464 (put 'org-agenda-files 'org-restrict
5465 (list (buffer-file-name (buffer-base-buffer))))
5466 (org-back-to-heading t)
5467 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5468 (move-marker org-agenda-restrict-begin (point))
5469 (move-marker org-agenda-restrict-end
5470 (save-excursion (org-end-of-subtree t)))
5471 (message "Locking agenda restriction to subtree"))
5472 (put 'org-agenda-files 'org-restrict
5473 (list (buffer-file-name (buffer-base-buffer))))
5474 (setq org-agenda-restrict nil)
5475 (setq org-agenda-overriding-restriction 'file)
5476 (move-marker org-agenda-restrict-begin nil)
5477 (move-marker org-agenda-restrict-end nil)
5478 (message "Locking agenda restriction to file"))
5479 (setq current-prefix-arg nil)
5480 (org-agenda-maybe-redo))
5482 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5483 "Remove the agenda restriction lock."
5484 (interactive "P")
5485 (org-detach-overlay org-agenda-restriction-lock-overlay)
5486 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5487 (setq org-agenda-overriding-restriction nil)
5488 (setq org-agenda-restrict nil)
5489 (put 'org-agenda-files 'org-restrict nil)
5490 (move-marker org-agenda-restrict-begin nil)
5491 (move-marker org-agenda-restrict-end nil)
5492 (setq current-prefix-arg nil)
5493 (message "Agenda restriction lock removed")
5494 (or noupdate (org-agenda-maybe-redo)))
5496 (defun org-agenda-maybe-redo ()
5497 "If there is any window showing the agenda view, update it."
5498 (let ((w (get-buffer-window org-agenda-buffer-name t))
5499 (w0 (selected-window)))
5500 (when w
5501 (select-window w)
5502 (org-agenda-redo)
5503 (select-window w0)
5504 (if org-agenda-overriding-restriction
5505 (message "Agenda view shifted to new %s restriction"
5506 org-agenda-overriding-restriction)
5507 (message "Agenda restriction lock removed")))))
5509 ;;; Agenda commands
5511 (defun org-agenda-check-type (error &rest types)
5512 "Check if agenda buffer is of allowed type.
5513 If ERROR is non-nil, throw an error, otherwise just return nil."
5514 (if (memq org-agenda-type types)
5516 (if error
5517 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5518 nil)))
5520 (defun org-agenda-quit ()
5521 "Exit agenda by removing the window or the buffer."
5522 (interactive)
5523 (if org-agenda-columns-active
5524 (org-columns-quit)
5525 (let ((buf (current-buffer)))
5526 (if (eq org-agenda-window-setup 'other-frame)
5527 (progn
5528 (kill-buffer buf)
5529 (org-agenda-reset-markers)
5530 (org-columns-remove-overlays)
5531 (setq org-agenda-archives-mode nil)
5532 (delete-frame))
5533 (and (not (eq org-agenda-window-setup 'current-window))
5534 (not (one-window-p))
5535 (delete-window))
5536 (kill-buffer buf)
5537 (org-agenda-reset-markers)
5538 (org-columns-remove-overlays)
5539 (setq org-agenda-archives-mode nil)))
5540 ;; Maybe restore the pre-agenda window configuration.
5541 (and org-agenda-restore-windows-after-quit
5542 (not (eq org-agenda-window-setup 'other-frame))
5543 org-pre-agenda-window-conf
5544 (set-window-configuration org-pre-agenda-window-conf))))
5546 (defun org-agenda-exit ()
5547 "Exit agenda by removing the window or the buffer.
5548 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5549 Org-mode buffers visited directly by the user will not be touched."
5550 (interactive)
5551 (org-release-buffers org-agenda-new-buffers)
5552 (setq org-agenda-new-buffers nil)
5553 (org-agenda-quit))
5555 (defun org-agenda-execute (arg)
5556 "Execute another agenda command, keeping same window.
5557 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
5558 in the agenda."
5559 (interactive "P")
5560 (let ((org-agenda-window-setup 'current-window))
5561 (org-agenda arg)))
5563 (defun org-agenda-redo ()
5564 "Rebuild Agenda.
5565 When this is the global TODO list, a prefix argument will be interpreted."
5566 (interactive)
5567 (let* ((org-agenda-keep-modes t)
5568 (filter org-agenda-filter)
5569 (preset (get 'org-agenda-filter :preset-filter))
5570 (cols org-agenda-columns-active)
5571 (line (org-current-line))
5572 (window-line (- line (org-current-line (window-start))))
5573 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5574 (put 'org-agenda-filter :preset-filter nil)
5575 (and cols (org-columns-quit))
5576 (message "Rebuilding agenda buffer...")
5577 (org-let lprops '(eval org-agenda-redo-command))
5578 (setq org-agenda-undo-list nil
5579 org-agenda-pending-undo-list nil)
5580 (message "Rebuilding agenda buffer...done")
5581 (put 'org-agenda-filter :preset-filter preset)
5582 (and (or filter preset) (org-agenda-filter-apply filter))
5583 (and cols (interactive-p) (org-agenda-columns))
5584 (org-goto-line line)
5585 (recenter window-line)))
5588 (defvar org-global-tags-completion-table nil)
5589 (defvar org-agenda-filter-form nil)
5590 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5591 "Keep only those lines in the agenda buffer that have a specific tag.
5592 The tag is selected with its fast selection letter, as configured.
5593 With prefix argument STRIP, remove all lines that do have the tag.
5594 A lisp caller can specify CHAR. NARROW means that the new tag should be
5595 used to narrow the search - the interactive user can also press `-' or `+'
5596 to switch to narrowing."
5597 (interactive "P")
5598 (let* ((alist org-tag-alist-for-agenda)
5599 (tag-chars (mapconcat
5600 (lambda (x) (if (and (not (symbolp (car x)))
5601 (cdr x))
5602 (char-to-string (cdr x))
5603 ""))
5604 alist ""))
5605 (efforts (org-split-string
5606 (or (cdr (assoc (concat org-effort-property "_ALL")
5607 org-global-properties))
5608 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5609 (effort-op org-agenda-filter-effort-default-operator)
5610 (effort-prompt "")
5611 (inhibit-read-only t)
5612 (current org-agenda-filter)
5613 a n tag)
5614 (unless char
5615 (message
5616 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5617 (if narrow "Narrow" "Filter") tag-chars
5618 (if org-agenda-auto-exclude-function "[RET], " ""))
5619 (setq char (read-char)))
5620 (when (member char '(?+ ?-))
5621 ;; Narrowing down
5622 (cond ((equal char ?-) (setq strip t narrow t))
5623 ((equal char ?+) (setq strip nil narrow t)))
5624 (message
5625 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5626 (setq char (read-char)))
5627 (when (member char '(?< ?> ?= ??))
5628 ;; An effort operator
5629 (setq effort-op (char-to-string char))
5630 (setq alist nil) ; to make sure it will be interpreted as effort.
5631 (unless (equal char ??)
5632 (loop for i from 0 to 9 do
5633 (setq effort-prompt
5634 (concat
5635 effort-prompt " ["
5636 (if (= i 9) "0" (int-to-string (1+ i)))
5637 "]" (nth i efforts))))
5638 (message "Effort%s: %s " effort-op effort-prompt)
5639 (setq char (read-char))
5640 (when (or (< char ?0) (> char ?9))
5641 (error "Need 1-9,0 to select effort" ))))
5642 (when (equal char ?\t)
5643 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5644 (org-set-local 'org-global-tags-completion-table
5645 (org-global-tags-completion-table)))
5646 (let ((completion-ignore-case t))
5647 (setq tag (org-icompleting-read
5648 "Tag: " org-global-tags-completion-table))))
5649 (cond
5650 ((equal char ?\r)
5651 (org-agenda-filter-by-tag-show-all)
5652 (when org-agenda-auto-exclude-function
5653 (setq org-agenda-filter '())
5654 (dolist (tag (org-agenda-get-represented-tags))
5655 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5656 (if modifier
5657 (push modifier org-agenda-filter))))
5658 (if (not (null org-agenda-filter))
5659 (org-agenda-filter-apply org-agenda-filter))))
5660 ((equal char ?/)
5661 (org-agenda-filter-by-tag-show-all)
5662 (when (get 'org-agenda-filter :preset-filter)
5663 (org-agenda-filter-apply org-agenda-filter)))
5664 ((or (equal char ?\ )
5665 (setq a (rassoc char alist))
5666 (and (>= char ?0) (<= char ?9)
5667 (setq n (if (= char ?0) 9 (- char ?0 1))
5668 tag (concat effort-op (nth n efforts))
5669 a (cons tag nil)))
5670 (and (= char ??)
5671 (setq tag "?eff")
5672 a (cons tag nil))
5673 (and tag (setq a (cons tag nil))))
5674 (org-agenda-filter-by-tag-show-all)
5675 (setq tag (car a))
5676 (setq org-agenda-filter
5677 (cons (concat (if strip "-" "+") tag)
5678 (if narrow current nil)))
5679 (org-agenda-filter-apply org-agenda-filter))
5680 (t (error "Invalid tag selection character %c" char)))))
5682 (defun org-agenda-get-represented-tags ()
5683 "Get a list of all tags currently represented in the agenda."
5684 (let (p tags)
5685 (save-excursion
5686 (goto-char (point-min))
5687 (while (setq p (next-single-property-change (point) 'tags))
5688 (goto-char p)
5689 (mapc (lambda (x) (add-to-list 'tags x))
5690 (get-text-property (point) 'tags))))
5691 tags))
5693 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5694 "Refine the current filter. See `org-agenda-filter-by-tag."
5695 (interactive "P")
5696 (org-agenda-filter-by-tag strip char 'refine))
5698 (defun org-agenda-filter-make-matcher ()
5699 "Create the form that tests a line for the agenda filter."
5700 (let (f f1)
5701 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5702 org-agenda-filter))
5703 (if (member x '("-" "+"))
5704 (setq f1 (if (equal x "-") 'tags '(not tags)))
5705 (if (string-match "[<=>?]" x)
5706 (setq f1 (org-agenda-filter-effort-form x))
5707 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5708 (if (equal (string-to-char x) ?-)
5709 (setq f1 (list 'not f1))))
5710 (push f1 f))
5711 (cons 'and (nreverse f))))
5713 (defun org-agenda-filter-effort-form (e)
5714 "Return the form to compare the effort of the current line with what E says.
5715 E looks like \"+<2:25\"."
5716 (let (op)
5717 (setq e (substring e 1))
5718 (setq op (string-to-char e) e (substring e 1))
5719 (setq op (cond ((equal op ?<) '<=)
5720 ((equal op ?>) '>=)
5721 ((equal op ??) op)
5722 (t '=)))
5723 (list 'org-agenda-compare-effort (list 'quote op)
5724 (org-hh:mm-string-to-minutes e))))
5726 (defun org-agenda-compare-effort (op value)
5727 "Compare the effort of the current line with VALUE, using OP.
5728 If the line does not have an effort defined, return nil."
5729 (let ((eff (org-get-at-bol 'effort-minutes)))
5730 (if (equal op ??)
5731 (not eff)
5732 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5733 value))))
5735 (defun org-agenda-filter-apply (filter)
5736 "Set FILTER as the new agenda filter and apply it."
5737 (let (tags)
5738 (setq org-agenda-filter filter
5739 org-agenda-filter-form (org-agenda-filter-make-matcher))
5740 (org-agenda-set-mode-name)
5741 (save-excursion
5742 (goto-char (point-min))
5743 (while (not (eobp))
5744 (if (org-get-at-bol 'org-marker)
5745 (progn
5746 (setq tags (org-get-at-bol 'tags)) ; used in eval
5747 (if (not (eval org-agenda-filter-form))
5748 (org-agenda-filter-by-tag-hide-line))
5749 (beginning-of-line 2))
5750 (beginning-of-line 2))))
5751 (if (get-char-property (point) 'invisible)
5752 (org-agenda-previous-line))))
5754 (defun org-agenda-filter-by-tag-hide-line ()
5755 (let (ov)
5756 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
5757 (point-at-eol)))
5758 (overlay-put ov 'invisible t)
5759 (overlay-put ov 'type 'tags-filter)
5760 (push ov org-agenda-filter-overlays)))
5762 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5763 (setq pos (or pos (point)))
5764 (save-excursion
5765 (dolist (ov (overlays-at pos))
5766 (when (and (overlay-get ov 'invisible)
5767 (eq (overlay-get ov 'type) 'tags-filter))
5768 (goto-char pos)
5769 (if (< (overlay-start ov) (point-at-eol))
5770 (move-overlay ov (point-at-eol)
5771 (overlay-end ov)))))))
5773 (defun org-agenda-filter-by-tag-show-all ()
5774 (mapc 'delete-overlay org-agenda-filter-overlays)
5775 (setq org-agenda-filter-overlays nil)
5776 (setq org-agenda-filter nil)
5777 (setq org-agenda-filter-form nil)
5778 (org-agenda-set-mode-name))
5780 (defun org-agenda-manipulate-query-add ()
5781 "Manipulate the query by adding a search term with positive selection.
5782 Positive selection means the term must be matched for selection of an entry."
5783 (interactive)
5784 (org-agenda-manipulate-query ?\[))
5785 (defun org-agenda-manipulate-query-subtract ()
5786 "Manipulate the query by adding a search term with negative selection.
5787 Negative selection means term must not be matched for selection of an entry."
5788 (interactive)
5789 (org-agenda-manipulate-query ?\]))
5790 (defun org-agenda-manipulate-query-add-re ()
5791 "Manipulate the query by adding a search regexp with positive selection.
5792 Positive selection means the regexp must match for selection of an entry."
5793 (interactive)
5794 (org-agenda-manipulate-query ?\{))
5795 (defun org-agenda-manipulate-query-subtract-re ()
5796 "Manipulate the query by adding a search regexp with negative selection.
5797 Negative selection means regexp must not match for selection of an entry."
5798 (interactive)
5799 (org-agenda-manipulate-query ?\}))
5800 (defun org-agenda-manipulate-query (char)
5801 (cond
5802 ((memq org-agenda-type '(timeline agenda))
5803 (let ((org-agenda-include-inactive-timestamps t))
5804 (org-agenda-redo))
5805 (message "Display now includes inactive timestamps as well"))
5806 ((eq org-agenda-type 'search)
5807 (org-add-to-string
5808 'org-agenda-query-string
5809 (if org-agenda-last-search-view-search-was-boolean
5810 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5811 (?\{ . " +{}") (?\} . " -{}"))))
5812 " "))
5813 (setq org-agenda-redo-command
5814 (list 'org-search-view
5815 org-todo-only
5816 org-agenda-query-string
5817 (+ (length org-agenda-query-string)
5818 (if (member char '(?\{ ?\})) 0 1))))
5819 (set-register org-agenda-query-register org-agenda-query-string)
5820 (org-agenda-redo))
5821 (t (error "Cannot manipulate query for %s-type agenda buffers"
5822 org-agenda-type))))
5824 (defun org-add-to-string (var string)
5825 (set var (concat (symbol-value var) string)))
5827 (defun org-agenda-goto-date (date)
5828 "Jump to DATE in agenda."
5829 (interactive (list (let ((org-read-date-prefer-future
5830 (eval org-agenda-jump-prefer-future)))
5831 (org-read-date))))
5832 (org-agenda-list nil date))
5834 (defun org-agenda-goto-today ()
5835 "Go to today."
5836 (interactive)
5837 (org-agenda-check-type t 'timeline 'agenda)
5838 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5839 (cond
5840 (tdpos (goto-char tdpos))
5841 ((eq org-agenda-type 'agenda)
5842 (let* ((sd (time-to-days
5843 (time-subtract (current-time)
5844 (list 0 (* 3600 org-extend-today-until) 0))))
5845 (comp (org-agenda-compute-time-span sd org-agenda-span))
5846 (org-agenda-overriding-arguments org-agenda-last-arguments))
5847 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5848 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5849 (org-agenda-redo)
5850 (org-agenda-find-same-or-today-or-agenda)))
5851 (t (error "Cannot find today")))))
5853 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5854 (goto-char
5855 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5856 (text-property-any (point-min) (point-max) 'org-today t)
5857 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5858 (point-min))))
5860 (defun org-agenda-later (arg)
5861 "Go forward in time by thee current span.
5862 With prefix ARG, go forward that many times the current span."
5863 (interactive "p")
5864 (org-agenda-check-type t 'agenda)
5865 (let* ((span org-agenda-span)
5866 (sd org-starting-day)
5867 (greg (calendar-gregorian-from-absolute sd))
5868 (cnt (org-get-at-bol 'org-day-cnt))
5869 greg2 nd)
5870 (cond
5871 ((eq span 'day)
5872 (setq sd (+ arg sd) nd 1))
5873 ((eq span 'week)
5874 (setq sd (+ (* 7 arg) sd) nd 7))
5875 ((eq span 'month)
5876 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5877 sd (calendar-absolute-from-gregorian greg2))
5878 (setcar greg2 (1+ (car greg2)))
5879 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5880 ((eq span 'year)
5881 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5882 sd (calendar-absolute-from-gregorian greg2))
5883 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5884 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5885 (let ((org-agenda-overriding-arguments
5886 (list (car org-agenda-last-arguments) sd nd t)))
5887 (org-agenda-redo)
5888 (org-agenda-find-same-or-today-or-agenda cnt))))
5890 (defun org-agenda-earlier (arg)
5891 "Go backward in time by the current span.
5892 With prefix ARG, go backward that many times the current span."
5893 (interactive "p")
5894 (org-agenda-later (- arg)))
5896 (defun org-agenda-view-mode-dispatch ()
5897 "Call one of the view mode commands."
5898 (interactive)
5899 (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
5900 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
5901 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
5902 (let ((a (read-char-exclusive)))
5903 (case a
5904 (?d (call-interactively 'org-agenda-day-view))
5905 (?w (call-interactively 'org-agenda-week-view))
5906 (?m (call-interactively 'org-agenda-month-view))
5907 (?y (call-interactively 'org-agenda-year-view))
5908 (?l (call-interactively 'org-agenda-log-mode))
5909 (?L (org-agenda-log-mode '(4)))
5910 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5911 (?a (call-interactively 'org-agenda-archives-mode))
5912 (?A (org-agenda-archives-mode 'files))
5913 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5914 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5915 (?G (call-interactively 'org-agenda-toggle-time-grid))
5916 (?D (call-interactively 'org-agenda-toggle-diary))
5917 (?\! (call-interactively 'org-agenda-toggle-deadlines))
5918 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5919 (org-agenda-check-type t 'timeline 'agenda)
5920 (org-agenda-redo))
5921 (message "Display now includes inactive timestamps as well"))
5922 (?q (message "Abort"))
5923 (otherwise (error "Invalid key" )))))
5925 (defun org-agenda-day-view (&optional day-of-year)
5926 "Switch to daily view for agenda.
5927 With argument DAY-OF-YEAR, switch to that day of the year."
5928 (interactive "P")
5929 (setq org-agenda-ndays 1)
5930 (org-agenda-change-time-span 'day day-of-year))
5931 (defun org-agenda-week-view (&optional iso-week)
5932 "Switch to daily view for agenda.
5933 With argument ISO-WEEK, switch to the corresponding ISO week.
5934 If ISO-WEEK has more then 2 digits, only the last two encode the
5935 week. Any digits before this encode a year. So 200712 means
5936 week 12 of year 2007. Years in the range 1938-2037 can also be
5937 written as 2-digit years."
5938 (interactive "P")
5939 (setq org-agenda-ndays 7)
5940 (org-agenda-change-time-span 'week iso-week))
5941 (defun org-agenda-month-view (&optional month)
5942 "Switch to monthly view for agenda.
5943 With argument MONTH, switch to that month."
5944 (interactive "P")
5945 (org-agenda-change-time-span 'month month))
5946 (defun org-agenda-year-view (&optional year)
5947 "Switch to yearly view for agenda.
5948 With argument YEAR, switch to that year.
5949 If MONTH has more then 2 digits, only the last two encode the
5950 month. Any digits before this encode a year. So 200712 means
5951 December year 2007. Years in the range 1938-2037 can also be
5952 written as 2-digit years."
5953 (interactive "P")
5954 (when year
5955 (setq year (org-small-year-to-year year)))
5956 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5957 (org-agenda-change-time-span 'year year)
5958 (error "Abort")))
5960 (defun org-agenda-change-time-span (span &optional n)
5961 "Change the agenda view to SPAN.
5962 SPAN may be `day', `week', `month', `year'."
5963 (org-agenda-check-type t 'agenda)
5964 (if (and (not n) (equal org-agenda-span span))
5965 (error "Viewing span is already \"%s\"" span))
5966 (let* ((sd (or (org-get-at-bol 'day)
5967 org-starting-day))
5968 (computed (org-agenda-compute-time-span sd span n))
5969 (org-agenda-overriding-arguments
5970 (list (car org-agenda-last-arguments)
5971 (car computed) (cdr computed) t)))
5972 (org-agenda-redo)
5973 (org-agenda-find-same-or-today-or-agenda))
5974 (org-agenda-set-mode-name)
5975 (message "Switched to %s view" span))
5977 (defun org-agenda-compute-time-span (sd span &optional n)
5978 "Compute starting date and number of days for agenda.
5979 SPAN may be `day', `week', `month', `year'. The return value
5980 is a cons cell with the starting date and the number of days,
5981 so that the date SD will be in that range."
5982 (let* ((greg (calendar-gregorian-from-absolute sd))
5983 (dg (nth 1 greg))
5984 (mg (car greg))
5985 (yg (nth 2 greg))
5986 nd w1 y1 m1 thisweek)
5987 (cond
5988 ((eq span 'day)
5989 (when n
5990 (setq sd (+ (calendar-absolute-from-gregorian
5991 (list mg 1 yg))
5992 n -1)))
5993 (setq nd 1))
5994 ((eq span 'week)
5995 (let* ((nt (calendar-day-of-week
5996 (calendar-gregorian-from-absolute sd)))
5997 (d (if org-agenda-start-on-weekday
5998 (- nt org-agenda-start-on-weekday)
5999 0)))
6000 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6001 (when n
6002 (require 'cal-iso)
6003 (setq thisweek (car (calendar-iso-from-absolute sd)))
6004 (when (> n 99)
6005 (setq y1 (org-small-year-to-year (/ n 100))
6006 n (mod n 100)))
6007 (setq sd
6008 (calendar-absolute-from-iso
6009 (list n 1
6010 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
6011 (setq nd 7)))
6012 ((eq span 'month)
6013 (when (and n (> n 99))
6014 (setq y1 (org-small-year-to-year (/ n 100))
6015 n (mod n 100)))
6016 (setq sd (calendar-absolute-from-gregorian
6017 (list (or n mg) 1 (or y1 yg)))
6018 nd (- (calendar-absolute-from-gregorian
6019 (list (1+ (or n mg)) 1 (or y1 yg)))
6020 sd)))
6021 ((eq span 'year)
6022 (setq sd (calendar-absolute-from-gregorian
6023 (list 1 1 (or n yg)))
6024 nd (- (calendar-absolute-from-gregorian
6025 (list 1 1 (1+ (or n yg))))
6026 sd))))
6027 (cons sd nd)))
6029 (defun org-agenda-next-date-line (&optional arg)
6030 "Jump to the next line indicating a date in agenda buffer."
6031 (interactive "p")
6032 (org-agenda-check-type t 'agenda 'timeline)
6033 (beginning-of-line 1)
6034 ;; This does not work if user makes date format that starts with a blank
6035 (if (looking-at "^\\S-") (forward-char 1))
6036 (if (not (re-search-forward "^\\S-" nil t arg))
6037 (progn
6038 (backward-char 1)
6039 (error "No next date after this line in this buffer")))
6040 (goto-char (match-beginning 0)))
6042 (defun org-agenda-previous-date-line (&optional arg)
6043 "Jump to the previous line indicating a date in agenda buffer."
6044 (interactive "p")
6045 (org-agenda-check-type t 'agenda 'timeline)
6046 (beginning-of-line 1)
6047 (if (not (re-search-backward "^\\S-" nil t arg))
6048 (error "No previous date before this line in this buffer")))
6050 ;; Initialize the highlight
6051 (defvar org-hl (make-overlay 1 1))
6052 (overlay-put org-hl 'face 'highlight)
6054 (defun org-highlight (begin end &optional buffer)
6055 "Highlight a region with overlay."
6056 (move-overlay org-hl begin end (or buffer (current-buffer))))
6058 (defun org-unhighlight ()
6059 "Detach overlay INDEX."
6060 (org-detach-overlay org-hl))
6062 ;; FIXME this is currently not used.
6063 (defun org-highlight-until-next-command (beg end &optional buffer)
6064 "Move the highlight overlay to BEG/END, remove it before the next command."
6065 (org-highlight beg end buffer)
6066 (add-hook 'pre-command-hook 'org-unhighlight-once))
6067 (defun org-unhighlight-once ()
6068 "Remove the highlight from its position, and this function from the hook."
6069 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6070 (org-unhighlight))
6072 (defun org-agenda-follow-mode ()
6073 "Toggle follow mode in an agenda buffer."
6074 (interactive)
6075 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6076 (org-agenda-set-mode-name)
6077 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6078 (org-agenda-show))
6079 (message "Follow mode is %s"
6080 (if org-agenda-follow-mode "on" "off")))
6082 (defun org-agenda-entry-text-mode (&optional arg)
6083 "Toggle entry text mode in an agenda buffer."
6084 (interactive "P")
6085 (setq org-agenda-entry-text-mode (or (integerp arg)
6086 (not org-agenda-entry-text-mode)))
6087 (org-agenda-entry-text-hide)
6088 (and org-agenda-entry-text-mode
6089 (let ((org-agenda-entry-text-maxlines
6090 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6091 (org-agenda-entry-text-show)))
6092 (org-agenda-set-mode-name)
6093 (message "Entry text mode is %s. Maximum number of lines is %d"
6094 (if org-agenda-entry-text-mode "on" "off")
6095 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6097 (defun org-agenda-clockreport-mode ()
6098 "Toggle clocktable mode in an agenda buffer."
6099 (interactive)
6100 (org-agenda-check-type t 'agenda)
6101 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
6102 (org-agenda-set-mode-name)
6103 (org-agenda-redo)
6104 (message "Clocktable mode is %s"
6105 (if org-agenda-clockreport-mode "on" "off")))
6107 (defun org-agenda-log-mode (&optional special)
6108 "Toggle log mode in an agenda buffer.
6109 With argument SPECIAL, show all possible log items, not only the ones
6110 configured in `org-agenda-log-mode-items'.
6111 With a double `C-u' prefix arg, show *only* log items, nothing else."
6112 (interactive "P")
6113 (org-agenda-check-type t 'agenda 'timeline)
6114 (setq org-agenda-show-log
6115 (if (equal special '(16))
6116 'only
6117 (if special '(closed clock state)
6118 (not org-agenda-show-log))))
6119 (org-agenda-set-mode-name)
6120 (org-agenda-redo)
6121 (message "Log mode is %s"
6122 (if org-agenda-show-log "on" "off")))
6124 (defun org-agenda-archives-mode (&optional with-files)
6125 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6126 When called with a prefix argument, include all archive files as well."
6127 (interactive "P")
6128 (setq org-agenda-archives-mode
6129 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6130 (org-agenda-set-mode-name)
6131 (org-agenda-redo)
6132 (message
6133 "%s"
6134 (cond
6135 ((eq org-agenda-archives-mode nil)
6136 "No archives are included")
6137 ((eq org-agenda-archives-mode 'trees)
6138 (format "Trees with :%s: tag are included" org-archive-tag))
6139 ((eq org-agenda-archives-mode t)
6140 (format "Trees with :%s: tag and all active archive files are included"
6141 org-archive-tag)))))
6143 (defun org-agenda-toggle-diary ()
6144 "Toggle diary inclusion in an agenda buffer."
6145 (interactive)
6146 (org-agenda-check-type t 'agenda)
6147 (setq org-agenda-include-diary (not org-agenda-include-diary))
6148 (org-agenda-redo)
6149 (org-agenda-set-mode-name)
6150 (message "Diary inclusion turned %s"
6151 (if org-agenda-include-diary "on" "off")))
6153 (defun org-agenda-toggle-deadlines ()
6154 "Toggle diary inclusion in an agenda buffer."
6155 (interactive)
6156 (org-agenda-check-type t 'agenda)
6157 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6158 (org-agenda-redo)
6159 (org-agenda-set-mode-name)
6160 (message "Deadlines inclusion turned %s"
6161 (if org-agenda-include-deadlines "on" "off")))
6163 (defun org-agenda-toggle-time-grid ()
6164 "Toggle time grid in an agenda buffer."
6165 (interactive)
6166 (org-agenda-check-type t 'agenda)
6167 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6168 (org-agenda-redo)
6169 (org-agenda-set-mode-name)
6170 (message "Time-grid turned %s"
6171 (if org-agenda-use-time-grid "on" "off")))
6173 (defun org-agenda-set-mode-name ()
6174 "Set the mode name to indicate all the small mode settings."
6175 (setq mode-name
6176 (concat "Org-Agenda"
6177 (if (get 'org-agenda-files 'org-restrict) " []" "")
6178 (if (equal org-agenda-ndays 1) " Day" "")
6179 (if (equal org-agenda-ndays 7) " Week" "")
6180 (if org-agenda-follow-mode " Follow" "")
6181 (if org-agenda-entry-text-mode " ETxt" "")
6182 (if org-agenda-include-diary " Diary" "")
6183 (if org-agenda-include-deadlines " Ddl" "")
6184 (if org-agenda-use-time-grid " Grid" "")
6185 (if (and (boundp 'org-habit-show-habits)
6186 org-habit-show-habits) " Habit" "")
6187 (if (consp org-agenda-show-log) " LogAll"
6188 (if org-agenda-show-log " Log" ""))
6189 (if (or org-agenda-filter (get 'org-agenda-filter
6190 :preset-filter))
6191 (concat " {" (mapconcat
6192 'identity
6193 (append (get 'org-agenda-filter
6194 :preset-filter)
6195 org-agenda-filter) "") "}")
6197 (if org-agenda-archives-mode
6198 (if (eq org-agenda-archives-mode t)
6199 " Archives"
6200 (format " :%s:" org-archive-tag))
6202 (if org-agenda-clockreport-mode " Clock" "")))
6203 (force-mode-line-update))
6205 (defun org-agenda-post-command-hook ()
6206 (setq org-agenda-type
6207 (or (get-text-property (point) 'org-agenda-type)
6208 (get-text-property (max (point-min) (1- (point)))
6209 'org-agenda-type))))
6211 (defun org-agenda-next-line ()
6212 "Move cursor to the next line, and show if follow mode is active."
6213 (interactive)
6214 (call-interactively 'next-line)
6215 (org-agenda-do-context-action))
6217 (defun org-agenda-previous-line ()
6218 "Move cursor to the previous line, and show if follow-mode is active."
6220 (interactive)
6221 (call-interactively 'previous-line)
6222 (org-agenda-do-context-action))
6224 (defun org-agenda-do-context-action ()
6225 "Show outline path and, maybe, follow mode window."
6226 (let ((m (org-get-at-bol 'org-marker)))
6227 (if (and org-agenda-follow-mode m)
6228 (org-agenda-show))
6229 (if (and m org-agenda-show-outline-path)
6230 (org-with-point-at m
6231 (org-display-outline-path t)))))
6233 (defun org-agenda-show-priority ()
6234 "Show the priority of the current item.
6235 This priority is composed of the main priority given with the [#A] cookies,
6236 and by additional input from the age of a schedules or deadline entry."
6237 (interactive)
6238 (let* ((pri (org-get-at-bol 'priority)))
6239 (message "Priority is %d" (if pri pri -1000))))
6241 (defun org-agenda-show-tags ()
6242 "Show the tags applicable to the current item."
6243 (interactive)
6244 (let* ((tags (org-get-at-bol 'tags)))
6245 (if tags
6246 (message "Tags are :%s:"
6247 (org-no-properties (mapconcat 'identity tags ":")))
6248 (message "No tags associated with this line"))))
6250 (defun org-agenda-goto (&optional highlight)
6251 "Go to the Org-mode file which contains the item at point."
6252 (interactive)
6253 (let* ((marker (or (org-get-at-bol 'org-marker)
6254 (org-agenda-error)))
6255 (buffer (marker-buffer marker))
6256 (pos (marker-position marker)))
6257 (switch-to-buffer-other-window buffer)
6258 (widen)
6259 (push-mark)
6260 (goto-char pos)
6261 (when (org-mode-p)
6262 (org-show-context 'agenda)
6263 (save-excursion
6264 (and (outline-next-heading)
6265 (org-flag-heading nil)))) ; show the next heading
6266 (recenter (/ (window-height) 2))
6267 (run-hooks 'org-agenda-after-show-hook)
6268 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6270 (defvar org-agenda-after-show-hook nil
6271 "Normal hook run after an item has been shown from the agenda.
6272 Point is in the buffer where the item originated.")
6274 (defun org-agenda-kill ()
6275 "Kill the entry or subtree belonging to the current agenda entry."
6276 (interactive)
6277 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6278 (let* ((marker (or (org-get-at-bol 'org-marker)
6279 (org-agenda-error)))
6280 (buffer (marker-buffer marker))
6281 (pos (marker-position marker))
6282 (type (org-get-at-bol 'type))
6283 dbeg dend (n 0) conf)
6284 (org-with-remote-undo buffer
6285 (with-current-buffer buffer
6286 (save-excursion
6287 (goto-char pos)
6288 (if (and (org-mode-p) (not (member type '("sexp"))))
6289 (setq dbeg (progn (org-back-to-heading t) (point))
6290 dend (org-end-of-subtree t t))
6291 (setq dbeg (point-at-bol)
6292 dend (min (point-max) (1+ (point-at-eol)))))
6293 (goto-char dbeg)
6294 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6295 (setq conf (or (eq t org-agenda-confirm-kill)
6296 (and (numberp org-agenda-confirm-kill)
6297 (> n org-agenda-confirm-kill))))
6298 (and conf
6299 (not (y-or-n-p
6300 (format "Delete entry with %d lines in buffer \"%s\"? "
6301 n (buffer-name buffer))))
6302 (error "Abort"))
6303 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6304 (with-current-buffer buffer (delete-region dbeg dend))
6305 (message "Agenda item and source killed"))))
6307 (defvar org-archive-default-command)
6308 (defun org-agenda-archive-default ()
6309 "Archive the entry or subtree belonging to the current agenda entry."
6310 (interactive)
6311 (require 'org-archive)
6312 (org-agenda-archive-with org-archive-default-command))
6314 (defun org-agenda-archive-default-with-confirmation ()
6315 "Archive the entry or subtree belonging to the current agenda entry."
6316 (interactive)
6317 (require 'org-archive)
6318 (org-agenda-archive-with org-archive-default-command 'confirm))
6320 (defun org-agenda-archive ()
6321 "Archive the entry or subtree belonging to the current agenda entry."
6322 (interactive)
6323 (org-agenda-archive-with 'org-archive-subtree))
6325 (defun org-agenda-archive-to-archive-sibling ()
6326 "Move the entry to the archive sibling."
6327 (interactive)
6328 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6330 (defun org-agenda-archive-with (cmd &optional confirm)
6331 "Move the entry to the archive sibling."
6332 (interactive)
6333 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6334 (let* ((marker (or (org-get-at-bol 'org-marker)
6335 (org-agenda-error)))
6336 (buffer (marker-buffer marker))
6337 (pos (marker-position marker)))
6338 (org-with-remote-undo buffer
6339 (with-current-buffer buffer
6340 (if (org-mode-p)
6341 (if (and confirm
6342 (not (y-or-n-p "Archive this subtree or entry? ")))
6343 (error "Abort")
6344 (save-excursion
6345 (goto-char pos)
6346 (org-remove-subtree-entries-from-agenda)
6347 (org-back-to-heading t)
6348 (funcall cmd)))
6349 (error "Archiving works only in Org-mode files"))))))
6351 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6352 "Remove all lines in the agenda that correspond to a given subtree.
6353 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6354 If this information is not given, the function uses the tree at point."
6355 (let ((buf (or buf (current-buffer))) m p)
6356 (save-excursion
6357 (unless (and beg end)
6358 (org-back-to-heading t)
6359 (setq beg (point))
6360 (org-end-of-subtree t)
6361 (setq end (point)))
6362 (set-buffer (get-buffer org-agenda-buffer-name))
6363 (save-excursion
6364 (goto-char (point-max))
6365 (beginning-of-line 1)
6366 (while (not (bobp))
6367 (when (and (setq m (org-get-at-bol 'org-marker))
6368 (equal buf (marker-buffer m))
6369 (setq p (marker-position m))
6370 (>= p beg)
6371 (< p end))
6372 (let ((inhibit-read-only t))
6373 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6374 (beginning-of-line 0))))))
6376 (defun org-agenda-refile (&optional goto rfloc no-update)
6377 "Refile the item at point."
6378 (interactive "P")
6379 (if (equal goto '(16))
6380 (org-refile-goto-last-stored)
6381 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6382 (org-agenda-error)))
6383 (buffer (marker-buffer marker))
6384 (pos (marker-position marker))
6385 (rfloc (or rfloc
6386 (org-refile-get-location
6387 (if goto "Goto: " "Refile to: ") buffer
6388 org-refile-allow-creating-parent-nodes))))
6389 (with-current-buffer buffer
6390 (save-excursion
6391 (save-restriction
6392 (widen)
6393 (goto-char marker)
6394 (org-remove-subtree-entries-from-agenda)
6395 (org-refile goto buffer rfloc)))))
6396 (unless no-update (org-agenda-redo))))
6398 (defun org-agenda-open-link (&optional arg)
6399 "Follow the link in the current line, if any.
6400 This looks for a link in the displayed line in the agenda. It also looks
6401 at the text of the entry itself."
6402 (interactive "P")
6403 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6404 (org-get-at-bol 'org-marker)))
6405 (buffer (and marker (marker-buffer marker)))
6406 (prefix (buffer-substring
6407 (point-at-bol)
6408 (+ (point-at-bol)
6409 (or (org-get-at-bol 'prefix-length) 0)))))
6410 (cond
6411 (buffer
6412 (with-current-buffer buffer
6413 (save-excursion
6414 (save-restriction
6415 (widen)
6416 (goto-char marker)
6417 (org-offer-links-in-entry arg prefix)))))
6418 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6419 (save-excursion
6420 (beginning-of-line 1)
6421 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6422 (org-open-link-from-string (match-string 1)))
6423 (t (error "No link to open here")))))
6425 (defun org-agenda-copy-local-variable (var)
6426 "Get a variable from a referenced buffer and install it here."
6427 (let ((m (org-get-at-bol 'org-marker)))
6428 (when (and m (buffer-live-p (marker-buffer m)))
6429 (org-set-local var (with-current-buffer (marker-buffer m)
6430 (symbol-value var))))))
6432 (defun org-agenda-switch-to (&optional delete-other-windows)
6433 "Go to the Org-mode file which contains the item at point."
6434 (interactive)
6435 (if (and org-return-follows-link
6436 (not (org-get-at-bol 'org-marker))
6437 (org-in-regexp org-bracket-link-regexp))
6438 (org-open-link-from-string (match-string 0))
6439 (let* ((marker (or (org-get-at-bol 'org-marker)
6440 (org-agenda-error)))
6441 (buffer (marker-buffer marker))
6442 (pos (marker-position marker)))
6443 (switch-to-buffer buffer)
6444 (and delete-other-windows (delete-other-windows))
6445 (widen)
6446 (goto-char pos)
6447 (when (org-mode-p)
6448 (org-show-context 'agenda)
6449 (save-excursion
6450 (and (outline-next-heading)
6451 (org-flag-heading nil))))))) ; show the next heading
6453 (defun org-agenda-goto-mouse (ev)
6454 "Go to the Org-mode file which contains the item at the mouse click."
6455 (interactive "e")
6456 (mouse-set-point ev)
6457 (org-agenda-goto))
6459 (defun org-agenda-show (&optional full-entry)
6460 "Display the Org-mode file which contains the item at point.
6461 With prefix argument FULL-ENTRY, make the entire entry visible
6462 if it was hidden in the outline."
6463 (interactive "P")
6464 (let ((win (selected-window)))
6465 (if full-entry
6466 (let ((org-show-entry-below t))
6467 (org-agenda-goto t))
6468 (org-agenda-goto t))
6469 (select-window win)))
6471 (defvar org-agenda-show-window nil)
6472 (defun org-agenda-show-and-scroll-up ()
6473 "Display the Org-mode file which contains the item at point.
6474 When called repeatedly, scroll the window that is displaying the buffer."
6475 (interactive)
6476 (let ((win (selected-window)))
6477 (if (and (window-live-p org-agenda-show-window)
6478 (eq this-command last-command))
6479 (progn
6480 (select-window org-agenda-show-window)
6481 (ignore-errors (scroll-up)))
6482 (org-agenda-goto t)
6483 (show-subtree)
6484 (setq org-agenda-show-window (selected-window)))
6485 (select-window win)))
6487 (defun org-agenda-show-scroll-down ()
6488 "Scroll down the window showing the agenda."
6489 (interactive)
6490 (let ((win (selected-window)))
6491 (when (window-live-p org-agenda-show-window)
6492 (select-window org-agenda-show-window)
6493 (ignore-errors (scroll-down))
6494 (select-window win))))
6496 (defun org-agenda-show-1 (&optional more)
6497 "Display the Org-mode file which contains the item at point.
6498 The prefix arg selects the amount of information to display:
6500 0 hide the subtree
6501 1 just show the entry according to defaults.
6502 2 show the children view
6503 3 show the subtree view
6504 4 show the entire subtree and any LOGBOOK drawers
6505 5 show the entire subtree and any drawers
6506 With prefix argument FULL-ENTRY, make the entire entry visible
6507 if it was hidden in the outline."
6508 (interactive "p")
6509 (let ((win (selected-window)))
6510 (org-agenda-goto t)
6511 (org-recenter-heading 1)
6512 (cond
6513 ((= more 0)
6514 (hide-subtree)
6515 (save-excursion
6516 (org-back-to-heading)
6517 (run-hook-with-args 'org-cycle-hook 'folded))
6518 (message "Remote: FOLDED"))
6519 ((and (interactive-p) (= more 1))
6520 (message "Remote: show with default settings"))
6521 ((= more 2)
6522 (show-entry)
6523 (show-children)
6524 (save-excursion
6525 (org-back-to-heading)
6526 (run-hook-with-args 'org-cycle-hook 'children))
6527 (message "Remote: CHILDREN"))
6528 ((= more 3)
6529 (show-subtree)
6530 (save-excursion
6531 (org-back-to-heading)
6532 (run-hook-with-args 'org-cycle-hook 'subtree))
6533 (message "Remote: SUBTREE"))
6534 ((= more 4)
6535 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6536 (org-drawer-regexp
6537 (concat "^[ \t]*:\\("
6538 (mapconcat 'regexp-quote org-drawers "\\|")
6539 "\\):[ \t]*$")))
6540 (show-subtree)
6541 (save-excursion
6542 (org-back-to-heading)
6543 (org-cycle-hide-drawers 'subtree)))
6544 (message "Remote: SUBTREE AND LOGBOOK"))
6545 ((> more 4)
6546 (show-subtree)
6547 (message "Remote: SUBTREE AND ALL DRAWERS")))
6548 (select-window win)))
6550 (defun org-recenter-heading (n)
6551 (save-excursion
6552 (org-back-to-heading)
6553 (recenter n)))
6555 (defvar org-agenda-cycle-counter nil)
6556 (defun org-agenda-cycle-show (&optional n)
6557 "Show the current entry in another window, with default settings.
6558 Default settings are taken from `org-show-hierarchy-above' and siblings.
6559 When use repeatedly in immediate succession, the remote entry will cycle
6560 through visibility
6562 children -> subtree -> folded
6564 When called with a numeric prefix arg, that arg will be passed through to
6565 `org-agenda-show-1'. For the interpretation of that argument, see the
6566 docstring of `org-agenda-show-1'."
6567 (interactive "P")
6568 (if (integerp n)
6569 (setq org-agenda-cycle-counter n)
6570 (if (not (eq last-command this-command))
6571 (setq org-agenda-cycle-counter 1)
6572 (if (equal org-agenda-cycle-counter 0)
6573 (setq org-agenda-cycle-counter 2)
6574 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6575 (if (> org-agenda-cycle-counter 3)
6576 (setq org-agenda-cycle-counter 0)))))
6577 (org-agenda-show-1 org-agenda-cycle-counter))
6579 (defun org-agenda-recenter (arg)
6580 "Display the Org-mode file which contains the item at point and recenter."
6581 (interactive "P")
6582 (let ((win (selected-window)))
6583 (org-agenda-goto t)
6584 (recenter arg)
6585 (select-window win)))
6587 (defun org-agenda-show-mouse (ev)
6588 "Display the Org-mode file which contains the item at the mouse click."
6589 (interactive "e")
6590 (mouse-set-point ev)
6591 (org-agenda-show))
6593 (defun org-agenda-check-no-diary ()
6594 "Check if the entry is a diary link and abort if yes."
6595 (if (org-get-at-bol 'org-agenda-diary-link)
6596 (org-agenda-error)))
6598 (defun org-agenda-error ()
6599 (error "Command not allowed in this line"))
6601 (defun org-agenda-tree-to-indirect-buffer ()
6602 "Show the subtree corresponding to the current entry in an indirect buffer.
6603 This calls the command `org-tree-to-indirect-buffer' from the original
6604 Org-mode buffer.
6605 With numerical prefix arg ARG, go up to this level and then take that tree.
6606 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
6607 use the dedicated frame)."
6608 (interactive)
6609 (org-agenda-check-no-diary)
6610 (let* ((marker (or (org-get-at-bol 'org-marker)
6611 (org-agenda-error)))
6612 (buffer (marker-buffer marker))
6613 (pos (marker-position marker)))
6614 (with-current-buffer buffer
6615 (save-excursion
6616 (goto-char pos)
6617 (call-interactively 'org-tree-to-indirect-buffer)))))
6619 (defvar org-last-heading-marker (make-marker)
6620 "Marker pointing to the headline that last changed its TODO state
6621 by a remote command from the agenda.")
6623 (defun org-agenda-todo-nextset ()
6624 "Switch TODO entry to next sequence."
6625 (interactive)
6626 (org-agenda-todo 'nextset))
6628 (defun org-agenda-todo-previousset ()
6629 "Switch TODO entry to previous sequence."
6630 (interactive)
6631 (org-agenda-todo 'previousset))
6633 (defun org-agenda-todo (&optional arg)
6634 "Cycle TODO state of line at point, also in Org-mode file.
6635 This changes the line at point, all other lines in the agenda referring to
6636 the same tree node, and the headline of the tree node in the Org-mode file."
6637 (interactive "P")
6638 (org-agenda-check-no-diary)
6639 (let* ((col (current-column))
6640 (marker (or (org-get-at-bol 'org-marker)
6641 (org-agenda-error)))
6642 (buffer (marker-buffer marker))
6643 (pos (marker-position marker))
6644 (hdmarker (org-get-at-bol 'org-hd-marker))
6645 (todayp (equal (org-get-at-bol 'day)
6646 (time-to-days (current-time))))
6647 (inhibit-read-only t)
6648 org-agenda-headline-snapshot-before-repeat newhead just-one)
6649 (org-with-remote-undo buffer
6650 (with-current-buffer buffer
6651 (widen)
6652 (goto-char pos)
6653 (org-show-context 'agenda)
6654 (save-excursion
6655 (and (outline-next-heading)
6656 (org-flag-heading nil))) ; show the next heading
6657 (let ((current-prefix-arg arg))
6658 (call-interactively 'org-todo))
6659 (and (bolp) (forward-char 1))
6660 (setq newhead (org-get-heading))
6661 (when (and (org-bound-and-true-p
6662 org-agenda-headline-snapshot-before-repeat)
6663 (not (equal org-agenda-headline-snapshot-before-repeat
6664 newhead))
6665 todayp)
6666 (setq newhead org-agenda-headline-snapshot-before-repeat
6667 just-one t))
6668 (save-excursion
6669 (org-back-to-heading)
6670 (move-marker org-last-heading-marker (point))))
6671 (beginning-of-line 1)
6672 (save-excursion
6673 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6674 (org-move-to-column col))))
6676 (defun org-agenda-add-note (&optional arg)
6677 "Add a time-stamped note to the entry at point."
6678 (interactive "P")
6679 (org-agenda-check-no-diary)
6680 (let* ((marker (or (org-get-at-bol 'org-marker)
6681 (org-agenda-error)))
6682 (buffer (marker-buffer marker))
6683 (pos (marker-position marker))
6684 (hdmarker (org-get-at-bol 'org-hd-marker))
6685 (inhibit-read-only t))
6686 (with-current-buffer buffer
6687 (widen)
6688 (goto-char pos)
6689 (org-show-context 'agenda)
6690 (save-excursion
6691 (and (outline-next-heading)
6692 (org-flag-heading nil))) ; show the next heading
6693 (org-add-note))))
6695 (defun org-agenda-change-all-lines (newhead hdmarker
6696 &optional fixface just-this)
6697 "Change all lines in the agenda buffer which match HDMARKER.
6698 The new content of the line will be NEWHEAD (as modified by
6699 `org-format-agenda-item'). HDMARKER is checked with
6700 `equal' against all `org-hd-marker' text properties in the file.
6701 If FIXFACE is non-nil, the face of each item is modified according to
6702 the new TODO state.
6703 If JUST-THIS is non-nil, change just the current line, not all.
6704 If FORCE-TAGS is non nil, the car of it returns the new tags."
6705 (let* ((inhibit-read-only t)
6706 (line (org-current-line))
6707 (thetags (with-current-buffer (marker-buffer hdmarker)
6708 (save-excursion (save-restriction (widen)
6709 (goto-char hdmarker)
6710 (org-get-tags-at)))))
6711 props m pl undone-face done-face finish new dotime cat tags)
6712 (save-excursion
6713 (goto-char (point-max))
6714 (beginning-of-line 1)
6715 (while (not finish)
6716 (setq finish (bobp))
6717 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6718 (or (not just-this) (= (org-current-line) line))
6719 (equal m hdmarker))
6720 (setq props (text-properties-at (point))
6721 dotime (org-get-at-bol 'dotime)
6722 cat (org-get-at-bol 'org-category)
6723 tags thetags
6724 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6725 pl (org-get-at-bol 'prefix-length)
6726 undone-face (org-get-at-bol 'undone-face)
6727 done-face (org-get-at-bol 'done-face))
6728 (goto-char (+ (point) pl))
6729 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6730 (cond
6731 ((equal new "")
6732 (beginning-of-line 1)
6733 (and (looking-at ".*\n?") (replace-match "")))
6734 ((looking-at ".*")
6735 (replace-match new t t)
6736 (beginning-of-line 1)
6737 (add-text-properties (point-at-bol) (point-at-eol) props)
6738 (when fixface
6739 (add-text-properties
6740 (point-at-bol) (point-at-eol)
6741 (list 'face
6742 (if org-last-todo-state-is-todo
6743 undone-face done-face))))
6744 (org-agenda-highlight-todo 'line)
6745 (beginning-of-line 1))
6746 (t (error "Line update did not work"))))
6747 (beginning-of-line 0)))
6748 (org-finalize-agenda)))
6750 (defun org-agenda-align-tags (&optional line)
6751 "Align all tags in agenda items to `org-agenda-tags-column'."
6752 (let ((inhibit-read-only t) l c)
6753 (save-excursion
6754 (goto-char (if line (point-at-bol) (point-min)))
6755 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6756 (if line (point-at-eol) nil) t)
6757 (add-text-properties
6758 (match-beginning 2) (match-end 2)
6759 (list 'face (delq nil (let ((prop (get-text-property
6760 (match-beginning 2) 'face)))
6761 (or (listp prop) (setq prop (list prop)))
6762 (if (memq 'org-tag prop)
6763 prop
6764 (cons 'org-tag prop))))))
6765 (setq l (- (match-end 2) (match-beginning 2))
6766 c (if (< org-agenda-tags-column 0)
6767 (- (abs org-agenda-tags-column) l)
6768 org-agenda-tags-column))
6769 (delete-region (match-beginning 1) (match-end 1))
6770 (goto-char (match-beginning 1))
6771 (insert (org-add-props
6772 (make-string (max 1 (- c (current-column))) ?\ )
6773 (plist-put (copy-sequence (text-properties-at (point)))
6774 'face nil))))
6775 (goto-char (point-min))
6776 (org-font-lock-add-tag-faces (point-max)))))
6778 (defun org-agenda-priority-up ()
6779 "Increase the priority of line at point, also in Org-mode file."
6780 (interactive)
6781 (org-agenda-priority 'up))
6783 (defun org-agenda-priority-down ()
6784 "Decrease the priority of line at point, also in Org-mode file."
6785 (interactive)
6786 (org-agenda-priority 'down))
6788 (defun org-agenda-priority (&optional force-direction)
6789 "Set the priority of line at point, also in Org-mode file.
6790 This changes the line at point, all other lines in the agenda referring to
6791 the same tree node, and the headline of the tree node in the Org-mode file."
6792 (interactive)
6793 (unless org-enable-priority-commands
6794 (error "Priority commands are disabled"))
6795 (org-agenda-check-no-diary)
6796 (let* ((marker (or (org-get-at-bol 'org-marker)
6797 (org-agenda-error)))
6798 (hdmarker (org-get-at-bol 'org-hd-marker))
6799 (buffer (marker-buffer hdmarker))
6800 (pos (marker-position hdmarker))
6801 (inhibit-read-only t)
6802 newhead)
6803 (org-with-remote-undo buffer
6804 (with-current-buffer buffer
6805 (widen)
6806 (goto-char pos)
6807 (org-show-context 'agenda)
6808 (save-excursion
6809 (and (outline-next-heading)
6810 (org-flag-heading nil))) ; show the next heading
6811 (funcall 'org-priority force-direction)
6812 (end-of-line 1)
6813 (setq newhead (org-get-heading)))
6814 (org-agenda-change-all-lines newhead hdmarker)
6815 (beginning-of-line 1))))
6817 ;; FIXME: should fix the tags property of the agenda line.
6818 (defun org-agenda-set-tags (&optional tag onoff)
6819 "Set tags for the current headline."
6820 (interactive)
6821 (org-agenda-check-no-diary)
6822 (if (and (org-region-active-p) (interactive-p))
6823 (call-interactively 'org-change-tag-in-region)
6824 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6825 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6826 (org-agenda-error)))
6827 (buffer (marker-buffer hdmarker))
6828 (pos (marker-position hdmarker))
6829 (inhibit-read-only t)
6830 newhead)
6831 (org-with-remote-undo buffer
6832 (with-current-buffer buffer
6833 (widen)
6834 (goto-char pos)
6835 (save-excursion
6836 (org-show-context 'agenda))
6837 (save-excursion
6838 (and (outline-next-heading)
6839 (org-flag-heading nil))) ; show the next heading
6840 (goto-char pos)
6841 (if tag
6842 (org-toggle-tag tag onoff)
6843 (call-interactively 'org-set-tags))
6844 (end-of-line 1)
6845 (setq newhead (org-get-heading)))
6846 (org-agenda-change-all-lines newhead hdmarker)
6847 (beginning-of-line 1)))))
6849 (defun org-agenda-set-property ()
6850 "Set a property for the current headline."
6851 (interactive)
6852 (org-agenda-check-no-diary)
6853 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6854 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6855 (org-agenda-error)))
6856 (buffer (marker-buffer hdmarker))
6857 (pos (marker-position hdmarker))
6858 (inhibit-read-only t)
6859 newhead)
6860 (org-with-remote-undo buffer
6861 (with-current-buffer buffer
6862 (widen)
6863 (goto-char pos)
6864 (save-excursion
6865 (org-show-context 'agenda))
6866 (save-excursion
6867 (and (outline-next-heading)
6868 (org-flag-heading nil))) ; show the next heading
6869 (goto-char pos)
6870 (call-interactively 'org-set-property)))))
6872 (defun org-agenda-set-effort ()
6873 "Set the effort property for the current headline."
6874 (interactive)
6875 (org-agenda-check-no-diary)
6876 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6877 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6878 (org-agenda-error)))
6879 (buffer (marker-buffer hdmarker))
6880 (pos (marker-position hdmarker))
6881 (inhibit-read-only t)
6882 newhead)
6883 (org-with-remote-undo buffer
6884 (with-current-buffer buffer
6885 (widen)
6886 (goto-char pos)
6887 (save-excursion
6888 (org-show-context 'agenda))
6889 (save-excursion
6890 (and (outline-next-heading)
6891 (org-flag-heading nil))) ; show the next heading
6892 (goto-char pos)
6893 (call-interactively 'org-set-effort)
6894 (end-of-line 1)))))
6896 (defun org-agenda-toggle-archive-tag ()
6897 "Toggle the archive tag for the current entry."
6898 (interactive)
6899 (org-agenda-check-no-diary)
6900 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6901 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6902 (org-agenda-error)))
6903 (buffer (marker-buffer hdmarker))
6904 (pos (marker-position hdmarker))
6905 (inhibit-read-only t)
6906 newhead)
6907 (org-with-remote-undo buffer
6908 (with-current-buffer buffer
6909 (widen)
6910 (goto-char pos)
6911 (org-show-context 'agenda)
6912 (save-excursion
6913 (and (outline-next-heading)
6914 (org-flag-heading nil))) ; show the next heading
6915 (call-interactively 'org-toggle-archive-tag)
6916 (end-of-line 1)
6917 (setq newhead (org-get-heading)))
6918 (org-agenda-change-all-lines newhead hdmarker)
6919 (beginning-of-line 1))))
6921 (defun org-agenda-do-date-later (arg)
6922 (interactive "P")
6923 (cond
6924 ((or (equal arg '(16))
6925 (memq last-command
6926 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6927 (setq this-command 'org-agenda-date-later-minutes)
6928 (org-agenda-date-later-minutes 1))
6929 ((or (equal arg '(4))
6930 (memq last-command
6931 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6932 (setq this-command 'org-agenda-date-later-hours)
6933 (org-agenda-date-later-hours 1))
6935 (org-agenda-date-later (prefix-numeric-value arg)))))
6937 (defun org-agenda-do-date-earlier (arg)
6938 (interactive "P")
6939 (cond
6940 ((or (equal arg '(16))
6941 (memq last-command
6942 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6943 (setq this-command 'org-agenda-date-earlier-minutes)
6944 (org-agenda-date-earlier-minutes 1))
6945 ((or (equal arg '(4))
6946 (memq last-command
6947 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6948 (setq this-command 'org-agenda-date-earlier-hours)
6949 (org-agenda-date-earlier-hours 1))
6951 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6953 (defun org-agenda-date-later (arg &optional what)
6954 "Change the date of this item to one day later."
6955 (interactive "p")
6956 (org-agenda-check-type t 'agenda 'timeline)
6957 (org-agenda-check-no-diary)
6958 (let* ((marker (or (org-get-at-bol 'org-marker)
6959 (org-agenda-error)))
6960 (buffer (marker-buffer marker))
6961 (pos (marker-position marker)))
6962 (org-with-remote-undo buffer
6963 (with-current-buffer buffer
6964 (widen)
6965 (goto-char pos)
6966 (if (not (org-at-timestamp-p))
6967 (error "Cannot find time stamp"))
6968 (org-timestamp-change arg (or what 'day)))
6969 (org-agenda-show-new-time marker org-last-changed-timestamp))
6970 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6972 (defun org-agenda-date-earlier (arg &optional what)
6973 "Change the date of this item to one day earlier."
6974 (interactive "p")
6975 (org-agenda-date-later (- arg) what))
6977 (defun org-agenda-date-later-minutes (arg)
6978 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6979 (interactive "p")
6980 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6981 (org-agenda-date-later arg 'minute))
6983 (defun org-agenda-date-earlier-minutes (arg)
6984 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6985 (interactive "p")
6986 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6987 (org-agenda-date-earlier arg 'minute))
6989 (defun org-agenda-date-later-hours (arg)
6990 "Change the time of this item, in hour steps."
6991 (interactive "p")
6992 (org-agenda-date-later arg 'hour))
6994 (defun org-agenda-date-earlier-hours (arg)
6995 "Change the time of this item, in hour steps."
6996 (interactive "p")
6997 (org-agenda-date-earlier arg 'hour))
6999 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7000 "Show new date stamp via text properties."
7001 ;; We use text properties to make this undoable
7002 (let ((inhibit-read-only t)
7003 (buffer-invisibility-spec))
7004 (setq stamp (concat " " prefix " => " stamp))
7005 (save-excursion
7006 (goto-char (point-max))
7007 (while (not (bobp))
7008 (when (equal marker (org-get-at-bol 'org-marker))
7009 (org-move-to-column (- (window-width) (length stamp)) t)
7010 (org-agenda-fix-tags-filter-overlays-at (point))
7011 (if (featurep 'xemacs)
7012 ;; Use `duplicable' property to trigger undo recording
7013 (let ((ex (make-extent nil nil))
7014 (gl (make-glyph stamp)))
7015 (set-glyph-face gl 'secondary-selection)
7016 (set-extent-properties
7017 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7018 (insert-extent ex (1- (point)) (point-at-eol)))
7019 (add-text-properties
7020 (1- (point)) (point-at-eol)
7021 (list 'display (org-add-props stamp nil
7022 'face 'secondary-selection))))
7023 (beginning-of-line 1))
7024 (beginning-of-line 0)))))
7026 (defun org-agenda-date-prompt (arg)
7027 "Change the date of this item. Date is prompted for, with default today.
7028 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7029 be used to request time specification in the time stamp."
7030 (interactive "P")
7031 (org-agenda-check-type t 'agenda 'timeline)
7032 (org-agenda-check-no-diary)
7033 (let* ((marker (or (org-get-at-bol 'org-marker)
7034 (org-agenda-error)))
7035 (buffer (marker-buffer marker))
7036 (pos (marker-position marker)))
7037 (org-with-remote-undo buffer
7038 (with-current-buffer buffer
7039 (widen)
7040 (goto-char pos)
7041 (if (not (org-at-timestamp-p t))
7042 (error "Cannot find time stamp"))
7043 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7044 (org-agenda-show-new-time marker org-last-changed-timestamp))
7045 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7047 (defun org-agenda-schedule (arg)
7048 "Schedule the item at point.
7049 Arg is passed through to `org-schedule'."
7050 (interactive "P")
7051 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7052 (org-agenda-check-no-diary)
7053 (let* ((marker (or (org-get-at-bol 'org-marker)
7054 (org-agenda-error)))
7055 (type (marker-insertion-type marker))
7056 (buffer (marker-buffer marker))
7057 (pos (marker-position marker))
7058 (org-insert-labeled-timestamps-at-point nil)
7060 (set-marker-insertion-type marker t)
7061 (org-with-remote-undo buffer
7062 (with-current-buffer buffer
7063 (widen)
7064 (goto-char pos)
7065 (setq ts (org-schedule arg)))
7066 (org-agenda-show-new-time marker ts "S"))
7067 (message "Item scheduled for %s" ts)))
7069 (defun org-agenda-deadline (arg)
7070 "Schedule the item at point.
7071 Arg is passed through to `org-deadline'."
7072 (interactive "P")
7073 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7074 (org-agenda-check-no-diary)
7075 (let* ((marker (or (org-get-at-bol 'org-marker)
7076 (org-agenda-error)))
7077 (buffer (marker-buffer marker))
7078 (pos (marker-position marker))
7079 (org-insert-labeled-timestamps-at-point nil)
7081 (org-with-remote-undo buffer
7082 (with-current-buffer buffer
7083 (widen)
7084 (goto-char pos)
7085 (setq ts (org-deadline arg)))
7086 (org-agenda-show-new-time marker ts "D"))
7087 (message "Deadline for this item set to %s" ts)))
7089 (defun org-agenda-action ()
7090 "Select entry for agenda action, or execute an agenda action.
7091 This command prompts for another letter. Valid inputs are:
7093 m Mark the entry at point for an agenda action
7094 s Schedule the marked entry to the date at the cursor
7095 d Set the deadline of the marked entry to the date at the cursor
7096 r Call `org-remember' with cursor date as the default date
7097 c Call `org-capture' with cursor date as the default date
7098 SPC Show marked entry in other window
7099 TAB Visit marked entry in other window
7101 The cursor may be at a date in the calendar, or in the Org agenda."
7102 (interactive)
7103 (let (ans)
7104 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7105 (setq ans (read-char-exclusive))
7106 (cond
7107 ((equal ans ?m)
7108 ;; Mark this entry
7109 (if (eq major-mode 'org-agenda-mode)
7110 (let ((m (or (org-get-at-bol 'org-hd-marker)
7111 (org-get-at-bol 'org-marker))))
7112 (if m
7113 (progn
7114 (move-marker org-agenda-action-marker
7115 (marker-position m) (marker-buffer m))
7116 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7117 (error "Don't know which entry to mark")))
7118 (error "This command works only in the agenda")))
7119 ((equal ans ?s)
7120 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7121 ((equal ans ?d)
7122 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7123 ((equal ans ?r)
7124 (org-agenda-do-action '(org-remember) t))
7125 ((equal ans ?c)
7126 (org-agenda-do-action '(org-capture) t))
7127 ((equal ans ?\ )
7128 (let ((cw (selected-window)))
7129 (org-switch-to-buffer-other-window
7130 (marker-buffer org-agenda-action-marker))
7131 (goto-char org-agenda-action-marker)
7132 (org-show-context 'agenda)
7133 (select-window cw)))
7134 ((equal ans ?\C-i)
7135 (org-switch-to-buffer-other-window
7136 (marker-buffer org-agenda-action-marker))
7137 (goto-char org-agenda-action-marker)
7138 (org-show-context 'agenda))
7139 (t (error "Invalid agenda action %c" ans)))))
7141 (defun org-agenda-do-action (form &optional current-buffer)
7142 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7143 (let ((org-overriding-default-time (org-get-cursor-date)))
7144 (if current-buffer
7145 (eval form)
7146 (if (not (marker-buffer org-agenda-action-marker))
7147 (error "No entry has been selected for agenda action")
7148 (with-current-buffer (marker-buffer org-agenda-action-marker)
7149 (save-excursion
7150 (save-restriction
7151 (widen)
7152 (goto-char org-agenda-action-marker)
7153 (eval form))))))))
7155 (defun org-agenda-clock-in (&optional arg)
7156 "Start the clock on the currently selected item."
7157 (interactive "P")
7158 (org-agenda-check-no-diary)
7159 (if (equal arg '(4))
7160 (org-clock-in arg)
7161 (let* ((marker (or (org-get-at-bol 'org-marker)
7162 (org-agenda-error)))
7163 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7164 marker))
7165 (pos (marker-position marker))
7166 newhead)
7167 (org-with-remote-undo (marker-buffer marker)
7168 (with-current-buffer (marker-buffer marker)
7169 (widen)
7170 (goto-char pos)
7171 (org-show-context 'agenda)
7172 (org-show-entry)
7173 (org-cycle-hide-drawers 'children)
7174 (org-clock-in arg)
7175 (setq newhead (org-get-heading)))
7176 (org-agenda-change-all-lines newhead hdmarker)))))
7178 (defun org-agenda-clock-out ()
7179 "Stop the currently running clock."
7180 (interactive)
7181 (unless (marker-buffer org-clock-marker)
7182 (error "No running clock"))
7183 (let ((marker (make-marker)) newhead)
7184 (org-with-remote-undo (marker-buffer org-clock-marker)
7185 (with-current-buffer (marker-buffer org-clock-marker)
7186 (save-excursion
7187 (save-restriction
7188 (widen)
7189 (goto-char org-clock-marker)
7190 (org-back-to-heading t)
7191 (move-marker marker (point))
7192 (org-clock-out)
7193 (setq newhead (org-get-heading))))))
7194 (org-agenda-change-all-lines newhead marker)
7195 (move-marker marker nil)))
7197 (defun org-agenda-clock-cancel (&optional arg)
7198 "Cancel the currently running clock."
7199 (interactive "P")
7200 (unless (marker-buffer org-clock-marker)
7201 (error "No running clock"))
7202 (org-with-remote-undo (marker-buffer org-clock-marker)
7203 (org-clock-cancel)))
7205 (defun org-agenda-clock-goto ()
7206 "Jump to the currently clocked in task within the agenda.
7207 If the currently clocked in task is not listed in the agenda
7208 buffer, display it in another window."
7209 (interactive)
7210 (let (pos)
7211 (mapc (lambda (o)
7212 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7213 (setq pos (overlay-start o))))
7214 (overlays-in (point-min) (point-max)))
7215 (cond (pos (goto-char pos))
7216 ;; If the currently clocked entry is not in the agenda
7217 ;; buffer, we visit it in another window:
7218 (org-clock-current-task
7219 (org-switch-to-buffer-other-window (org-clock-goto)))
7220 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7222 (defun org-agenda-diary-entry-in-org-file ()
7223 "Make a diary entry in the file `org-agenda-diary-file'."
7224 (let (d1 d2 char (text "") dp1 dp2)
7225 (if (equal (buffer-name) "*Calendar*")
7226 (setq d1 (calendar-cursor-to-date t)
7227 d2 (car calendar-mark-ring))
7228 (setq dp1 (get-text-property (point-at-bol) 'day))
7229 (unless dp1 (error "No date defined in current line"))
7230 (setq d1 (calendar-gregorian-from-absolute dp1)
7231 d2 (and (ignore-errors (mark))
7232 (save-excursion
7233 (goto-char (mark))
7234 (setq dp2 (get-text-property (point-at-bol) 'day)))
7235 (calendar-gregorian-from-absolute dp2))))
7236 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7237 (setq char (read-char-exclusive))
7238 (cond
7239 ((equal char ?d)
7240 (setq text (read-string "Day entry: "))
7241 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7242 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7243 ((equal char ?a)
7244 (setq d1 (list (car d1) (nth 1 d1)
7245 (read-number (format "Reference year [%d]: " (nth 2 d1))
7246 (nth 2 d1))))
7247 (setq text (read-string "Anniversary (use %d to show years): "))
7248 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7249 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7250 ((equal char ?b)
7251 (setq text (read-string "Block entry: "))
7252 (unless (and d1 d2 (not (equal d1 d2)))
7253 (error "No block of days selected"))
7254 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7255 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7256 ((equal char ?j)
7257 (org-switch-to-buffer-other-window
7258 (find-file-noselect org-agenda-diary-file))
7259 (require 'org-datetree)
7260 (org-datetree-find-date-create d1)
7261 (org-reveal t))
7262 (t (error "Invalid selection character `%c'" char)))))
7264 (defcustom org-agenda-insert-diary-strategy 'date-tree
7265 "Where in `org-agenda-diary-file' should new entries be added?
7266 Valid values:
7268 date-tree in the date tree, as child of the date
7269 top-level as top-level entries at the end of the file."
7270 :group 'org-agenda
7271 :type '(choice
7272 (const :tag "in a date tree" date-tree)
7273 (const :tag "as top level at end of file" top-level)))
7275 (defcustom org-agenda-insert-diary-extract-time nil
7276 "Non-nil means extract any time specification from the diary entry."
7277 :group 'org-agenda
7278 :type 'boolean)
7280 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7281 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7282 If TEXT is not empty, it will become the headline of the new entry, and
7283 the resulting entry will not be shown. When TEXT is empty, switch to
7284 `org-agenda-diary-file' and let the user finish the entry there."
7285 (let ((cw (current-window-configuration)))
7286 (org-switch-to-buffer-other-window
7287 (find-file-noselect org-agenda-diary-file))
7288 (widen)
7289 (goto-char (point-min))
7290 (cond
7291 ((eq type 'anniversary)
7292 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7293 (progn
7294 (or (org-on-heading-p t)
7295 (progn
7296 (outline-next-heading)
7297 (insert "* Anniversaries\n\n")
7298 (beginning-of-line -1)))))
7299 (outline-next-heading)
7300 (org-back-over-empty-lines)
7301 (backward-char 1)
7302 (insert "\n")
7303 (require 'diary-lib)
7304 (let ((calendar-date-display-form
7305 (if (if (boundp 'calendar-date-style)
7306 (eq calendar-date-style 'european)
7307 (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
7308 (org-bound-and-true-p european-calendar-style))) ; Emacs 22
7309 '(day " " month " " year)
7310 '(month " " day " " year))))
7312 (insert (format "%%%%(diary-anniversary %s) %s"
7313 (calendar-date-string d1 nil t) text))))
7314 ((eq type 'day)
7315 (let ((org-prefix-has-time t)
7316 (org-agenda-time-leading-zero t)
7317 fmt time time2)
7318 (if org-agenda-insert-diary-extract-time
7319 ;; Use org-format-agenda-item to parse text for a time-range and
7320 ;; remove it. FIXME: This is a hack, we should refactor
7321 ;; that function to make time extraction available separately
7322 (setq fmt (org-format-agenda-item nil text nil nil t)
7323 time (get-text-property 0 'time fmt)
7324 time2 (if (> (length time) 0)
7325 ;; split-string removes trailing ...... if
7326 ;; no end time given. First space
7327 ;; separates time from date.
7328 (concat " " (car (split-string time "\\.")))
7329 nil)
7330 text (get-text-property 0 'txt fmt)))
7331 (if (eq org-agenda-insert-diary-strategy 'top-level)
7332 (org-agenda-insert-diary-as-top-level text)
7333 (require 'org-datetree)
7334 (org-datetree-find-date-create d1)
7335 (org-agenda-insert-diary-make-new-entry text))
7336 (org-insert-time-stamp (org-time-from-absolute
7337 (calendar-absolute-from-gregorian d1))
7338 nil nil nil nil time2))
7339 (end-of-line 0))
7340 ((eq type 'block)
7341 (if (> (calendar-absolute-from-gregorian d1)
7342 (calendar-absolute-from-gregorian d2))
7343 (setq d1 (prog1 d2 (setq d2 d1))))
7344 (if (eq org-agenda-insert-diary-strategy 'top-level)
7345 (org-agenda-insert-diary-as-top-level text)
7346 (require 'org-datetree)
7347 (org-datetree-find-date-create d1)
7348 (org-agenda-insert-diary-make-new-entry text))
7349 (org-insert-time-stamp (org-time-from-absolute
7350 (calendar-absolute-from-gregorian d1)))
7351 (insert "--")
7352 (org-insert-time-stamp (org-time-from-absolute
7353 (calendar-absolute-from-gregorian d2)))
7354 (end-of-line 0)))
7355 (if (string-match "\\S-" text)
7356 (progn
7357 (set-window-configuration cw)
7358 (message "%s entry added to %s"
7359 (capitalize (symbol-name type))
7360 (abbreviate-file-name org-agenda-diary-file)))
7361 (org-reveal t)
7362 (message "Please finish entry here"))))
7364 (defun org-agenda-insert-diary-as-top-level (text)
7365 "Make new entry as a top-level entry at the end of the file.
7366 Add TEXT as headline, and position the cursor in the second line so that
7367 a timestamp can be added there."
7368 (widen)
7369 (goto-char (point-max))
7370 (or (bolp) (insert "\n"))
7371 (insert "* " text "\n")
7372 (if org-adapt-indentation (org-indent-to-column 2)))
7374 (defun org-agenda-insert-diary-make-new-entry (text)
7375 "Make new entry as last child of current entry.
7376 Add TEXT as headline, and position the cursor in the second line so that
7377 a timestamp can be added there."
7378 (let ((org-show-following-heading t)
7379 (org-show-siblings t)
7380 (org-show-hierarchy-above t)
7381 (org-show-entry-below t)
7382 col)
7383 (outline-next-heading)
7384 (org-back-over-empty-lines)
7385 (or (looking-at "[ \t]*$")
7386 (progn (insert "\n") (backward-char 1)))
7387 (org-insert-heading nil t)
7388 (org-do-demote)
7389 (setq col (current-column))
7390 (insert text "\n")
7391 (if org-adapt-indentation (org-indent-to-column col))
7392 (let ((org-show-following-heading t)
7393 (org-show-siblings t)
7394 (org-show-hierarchy-above t)
7395 (org-show-entry-below t))
7396 (org-show-context))))
7398 (defun org-agenda-diary-entry ()
7399 "Make a diary entry, like the `i' command from the calendar.
7400 All the standard commands work: block, weekly etc.
7401 When `org-agenda-diary-file' points to a file,
7402 `org-agenda-diary-entry-in-org-file' is called instead to create
7403 entries in that Org-mode file."
7404 (interactive)
7405 (org-agenda-check-type t 'agenda 'timeline)
7406 (if (not (eq org-agenda-diary-file 'diary-file))
7407 (org-agenda-diary-entry-in-org-file)
7408 (require 'diary-lib)
7409 (let* ((char (progn
7410 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7411 (read-char-exclusive)))
7412 (cmd (cdr (assoc char
7413 '((?d . insert-diary-entry)
7414 (?w . insert-weekly-diary-entry)
7415 (?m . insert-monthly-diary-entry)
7416 (?y . insert-yearly-diary-entry)
7417 (?a . insert-anniversary-diary-entry)
7418 (?b . insert-block-diary-entry)
7419 (?c . insert-cyclic-diary-entry)))))
7420 (oldf (symbol-function 'calendar-cursor-to-date))
7421 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7422 (point (point))
7423 (mark (or (mark t) (point))))
7424 (unless cmd
7425 (error "No command associated with <%c>" char))
7426 (unless (and (get-text-property point 'day)
7427 (or (not (equal ?b char))
7428 (get-text-property mark 'day)))
7429 (error "Don't know which date to use for diary entry"))
7430 ;; We implement this by hacking the `calendar-cursor-to-date' function
7431 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7432 (let ((calendar-mark-ring
7433 (list (calendar-gregorian-from-absolute
7434 (or (get-text-property mark 'day)
7435 (get-text-property point 'day))))))
7436 (unwind-protect
7437 (progn
7438 (fset 'calendar-cursor-to-date
7439 (lambda (&optional error dummy)
7440 (calendar-gregorian-from-absolute
7441 (get-text-property point 'day))))
7442 (call-interactively cmd))
7443 (fset 'calendar-cursor-to-date oldf))))))
7445 (defun org-agenda-execute-calendar-command (cmd)
7446 "Execute a calendar command from the agenda, with the date associated to
7447 the cursor position."
7448 (org-agenda-check-type t 'agenda 'timeline)
7449 (require 'diary-lib)
7450 (unless (get-text-property (point) 'day)
7451 (error "Don't know which date to use for calendar command"))
7452 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7453 (point (point))
7454 (date (calendar-gregorian-from-absolute
7455 (get-text-property point 'day)))
7456 ;; the following 2 vars are needed in the calendar
7457 (displayed-month (car date))
7458 (displayed-year (nth 2 date)))
7459 (unwind-protect
7460 (progn
7461 (fset 'calendar-cursor-to-date
7462 (lambda (&optional error dummy)
7463 (calendar-gregorian-from-absolute
7464 (get-text-property point 'day))))
7465 (call-interactively cmd))
7466 (fset 'calendar-cursor-to-date oldf))))
7468 (defun org-agenda-phases-of-moon ()
7469 "Display the phases of the moon for the 3 months around the cursor date."
7470 (interactive)
7471 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7473 (defun org-agenda-holidays ()
7474 "Display the holidays for the 3 months around the cursor date."
7475 (interactive)
7476 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7478 (defvar calendar-longitude)
7479 (defvar calendar-latitude)
7480 (defvar calendar-location-name)
7482 (defun org-agenda-sunrise-sunset (arg)
7483 "Display sunrise and sunset for the cursor date.
7484 Latitude and longitude can be specified with the variables
7485 `calendar-latitude' and `calendar-longitude'. When called with prefix
7486 argument, latitude and longitude will be prompted for."
7487 (interactive "P")
7488 (require 'solar)
7489 (let ((calendar-longitude (if arg nil calendar-longitude))
7490 (calendar-latitude (if arg nil calendar-latitude))
7491 (calendar-location-name
7492 (if arg "the given coordinates" calendar-location-name)))
7493 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7495 (defun org-agenda-goto-calendar ()
7496 "Open the Emacs calendar with the date at the cursor."
7497 (interactive)
7498 (org-agenda-check-type t 'agenda 'timeline)
7499 (let* ((day (or (get-text-property (point) 'day)
7500 (error "Don't know which date to open in calendar")))
7501 (date (calendar-gregorian-from-absolute day))
7502 (calendar-move-hook nil)
7503 (calendar-view-holidays-initially-flag nil)
7504 (calendar-view-diary-initially-flag nil))
7505 (calendar)
7506 (calendar-goto-date date)))
7508 ;;;###autoload
7509 (defun org-calendar-goto-agenda ()
7510 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7511 This is a command that has to be installed in `calendar-mode-map'."
7512 (interactive)
7513 (org-agenda-list nil (calendar-absolute-from-gregorian
7514 (calendar-cursor-to-date))
7515 nil))
7517 (defun org-agenda-convert-date ()
7518 (interactive)
7519 (org-agenda-check-type t 'agenda 'timeline)
7520 (let ((day (get-text-property (point) 'day))
7521 date s)
7522 (unless day
7523 (error "Don't know which date to convert"))
7524 (setq date (calendar-gregorian-from-absolute day))
7525 (setq s (concat
7526 "Gregorian: " (calendar-date-string date) "\n"
7527 "ISO: " (calendar-iso-date-string date) "\n"
7528 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7529 "Julian: " (calendar-julian-date-string date) "\n"
7530 "Astron. JD: " (calendar-astro-date-string date)
7531 " (Julian date number at noon UTC)\n"
7532 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7533 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7534 "French: " (calendar-french-date-string date) "\n"
7535 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7536 "Mayan: " (calendar-mayan-date-string date) "\n"
7537 "Coptic: " (calendar-coptic-date-string date) "\n"
7538 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7539 "Persian: " (calendar-persian-date-string date) "\n"
7540 "Chinese: " (calendar-chinese-date-string date) "\n"))
7541 (with-output-to-temp-buffer "*Dates*"
7542 (princ s))
7543 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7545 ;;; Bulk commands
7547 (defvar org-agenda-bulk-marked-entries nil
7548 "List of markers that refer to marked entries in the agenda.")
7550 (defun org-agenda-bulk-marked-p ()
7551 (eq (get-char-property (point-at-bol) 'type)
7552 'org-marked-entry-overlay))
7554 (defun org-agenda-bulk-mark ()
7555 "Mark the entry at point for future bulk action."
7556 (interactive)
7557 (org-agenda-check-no-diary)
7558 (let* ((m (org-get-at-bol 'org-hd-marker))
7560 (unless (org-agenda-bulk-marked-p)
7561 (unless m (error "Nothing to mark at point"))
7562 (push m org-agenda-bulk-marked-entries)
7563 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7564 (org-overlay-display ov "> "
7565 (org-get-todo-face "TODO")
7566 'evaporate)
7567 (overlay-put ov 'type 'org-marked-entry-overlay))
7568 (beginning-of-line 2)
7569 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7570 (beginning-of-line 2))
7571 (message "%d entries marked for bulk action"
7572 (length org-agenda-bulk-marked-entries))))
7574 (defun org-agenda-bulk-unmark ()
7575 "Unmark the entry at point for future bulk action."
7576 (interactive)
7577 (when (org-agenda-bulk-marked-p)
7578 (org-agenda-bulk-remove-overlays
7579 (point-at-bol) (+ 2 (point-at-bol)))
7580 (setq org-agenda-bulk-marked-entries
7581 (delete (org-get-at-bol 'org-hd-marker)
7582 org-agenda-bulk-marked-entries)))
7583 (beginning-of-line 2)
7584 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7585 (beginning-of-line 2))
7586 (message "%d entries marked for bulk action"
7587 (length org-agenda-bulk-marked-entries)))
7589 (defun org-agenda-bulk-toggle ()
7590 "Toggle marking the entry at point for bulk action."
7591 (interactive)
7592 (if (org-agenda-bulk-marked-p)
7593 (org-agenda-bulk-unmark)
7594 (org-agenda-bulk-mark)))
7596 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7597 "Remove the mark overlays between BEG and END in the agenda buffer.
7598 BEG and END default to the buffer limits.
7600 This only removes the overlays, it does not remove the markers
7601 from the list in `org-agenda-bulk-marked-entries'."
7602 (interactive)
7603 (mapc (lambda (ov)
7604 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7605 (delete-overlay ov)))
7606 (overlays-in (or beg (point-min)) (or end (point-max)))))
7608 (defun org-agenda-bulk-remove-all-marks ()
7609 "Remove all marks in the agenda buffer.
7610 This will remove the markers, and the overlays."
7611 (interactive)
7612 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7613 (setq org-agenda-bulk-marked-entries nil)
7614 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7616 (defun org-agenda-bulk-action (&optional arg)
7617 "Execute an remote-editing action on all marked entries.
7618 The prefix arg is passed through to the command if possible."
7619 (interactive "P")
7620 (unless org-agenda-bulk-marked-entries
7621 (error "No entries are marked"))
7622 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
7623 (let* ((action (read-char-exclusive))
7624 (org-log-refile (if org-log-refile 'time nil))
7625 (entries (reverse org-agenda-bulk-marked-entries))
7626 redo-at-end
7627 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7628 (cond
7629 ((equal action ?$)
7630 (setq cmd '(org-agenda-archive)))
7632 ((equal action ?A)
7633 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7635 ((member action '(?r ?w))
7636 (setq rfloc (org-refile-get-location
7637 "Refile to: "
7638 (marker-buffer (car org-agenda-bulk-marked-entries))
7639 org-refile-allow-creating-parent-nodes))
7640 (if (nth 3 rfloc)
7641 (setcar (nthcdr 3 rfloc)
7642 (move-marker (make-marker) (nth 3 rfloc)
7643 (or (get-file-buffer (nth 1 rfloc))
7644 (find-buffer-visiting (nth 1 rfloc))
7645 (error "This should not happen")))))
7647 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
7648 redo-at-end t))
7650 ((equal action ?t)
7651 (setq state (org-icompleting-read
7652 "Todo state: "
7653 (with-current-buffer (marker-buffer (car entries))
7654 (mapcar 'list org-todo-keywords-1))))
7655 (setq cmd `(let ((org-inhibit-blocking t)
7656 (org-inhibit-logging 'note))
7657 (org-agenda-todo ,state))))
7659 ((memq action '(?- ?+))
7660 (setq tag (org-icompleting-read
7661 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7662 (with-current-buffer (marker-buffer (car entries))
7663 (delq nil
7664 (mapcar (lambda (x)
7665 (if (stringp (car x)) x)) org-tag-alist)))))
7666 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
7668 ((memq action '(?s ?d))
7669 (let* ((date (unless arg
7670 (org-read-date
7671 nil nil nil
7672 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
7673 (ans (if arg nil org-read-date-final-answer))
7674 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
7675 (setq cmd `(let* ((bound (fboundp 'read-string))
7676 (old (and bound (symbol-function 'read-string))))
7677 (unwind-protect
7678 (progn
7679 (fset 'read-string (lambda (&rest ignore) ,ans))
7680 (eval '(,c1 arg)))
7681 (if bound
7682 (fset 'read-string old)
7683 (fmakunbound 'read-string)))))))
7684 (t (error "Invalid bulk action")))
7686 ;; Sort the markers, to make sure that parents are handled before children
7687 (setq entries (sort entries
7688 (lambda (a b)
7689 (cond
7690 ((equal (marker-buffer a) (marker-buffer b))
7691 (< (marker-position a) (marker-position b)))
7693 (string< (buffer-name (marker-buffer a))
7694 (buffer-name (marker-buffer b))))))))
7696 ;; Now loop over all markers and apply cmd
7697 (while (setq e (pop entries))
7698 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
7699 (if (not pos)
7700 (progn (message "Skipping removed entry at %s" e)
7701 (setq cntskip (1+ cntskip)))
7702 (goto-char pos)
7703 (eval cmd)
7704 (setq org-agenda-bulk-marked-entries
7705 (delete e org-agenda-bulk-marked-entries))
7706 (setq cnt (1+ cnt))))
7707 (setq org-agenda-bulk-marked-entries nil)
7708 (org-agenda-bulk-remove-all-marks)
7709 (when redo-at-end (org-agenda-redo))
7710 (message "Acted on %d entries%s"
7712 (if (= cntskip 0)
7714 (format ", skipped %d (disappeared before their turn)"
7715 cntskip)))))
7717 ;;; Flagging notes
7719 (defun org-agenda-show-the-flagging-note ()
7720 "Display the flagging note in the other window.
7721 When called a second time in direct sequence, offer to remove the FLAGGING
7722 tag and (if present) the flagging note."
7723 (interactive)
7724 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
7725 (win (selected-window))
7726 note heading newhead)
7727 (unless hdmarker
7728 (error "No linked entry at point"))
7729 (if (and (eq this-command last-command)
7730 (y-or-n-p "Unflag and remove any flagging note? "))
7731 (progn
7732 (org-agenda-remove-flag hdmarker)
7733 (let ((win (get-buffer-window "*Flagging Note*")))
7734 (and win (delete-window win)))
7735 (message "Entry unflaged"))
7736 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
7737 (unless note
7738 (error "No flagging note"))
7739 (org-kill-new note)
7740 (org-switch-to-buffer-other-window "*Flagging Note*")
7741 (erase-buffer)
7742 (insert note)
7743 (goto-char (point-min))
7744 (while (re-search-forward "\\\\n" nil t)
7745 (replace-match "\n" t t))
7746 (goto-char (point-min))
7747 (select-window win)
7748 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
7750 (defun org-agenda-remove-flag (marker)
7751 "Remove the FLAGGED tag and any flagging note in the entry."
7752 (let (newhead)
7753 (org-with-point-at marker
7754 (org-toggle-tag "FLAGGED" 'off)
7755 (org-entry-delete nil "THEFLAGGINGNOTE")
7756 (setq newhead (org-get-heading)))
7757 (org-agenda-change-all-lines newhead marker)
7758 (message "Entry unflaged")))
7760 (defun org-agenda-get-any-marker (&optional pos)
7761 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7762 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7764 ;;; Appointment reminders
7766 (defvar appt-time-msg-list)
7768 ;;;###autoload
7769 (defun org-agenda-to-appt (&optional refresh filter)
7770 "Activate appointments found in `org-agenda-files'.
7771 With a \\[universal-argument] prefix, refresh the list of
7772 appointments.
7774 If FILTER is t, interactively prompt the user for a regular
7775 expression, and filter out entries that don't match it.
7777 If FILTER is a string, use this string as a regular expression
7778 for filtering entries out.
7780 FILTER can also be an alist with the car of each cell being
7781 either 'headline or 'category. For example:
7783 '((headline \"IMPORTANT\")
7784 (category \"Work\"))
7786 will only add headlines containing IMPORTANT or headlines
7787 belonging to the \"Work\" category."
7788 (interactive "P")
7789 (if refresh (setq appt-time-msg-list nil))
7790 (if (eq filter t)
7791 (setq filter (read-from-minibuffer "Regexp filter: ")))
7792 (let* ((cnt 0) ; count added events
7793 (org-agenda-new-buffers nil)
7794 (org-deadline-warning-days 0)
7795 (today (org-date-to-gregorian
7796 (time-to-days (current-time))))
7797 (org-agenda-restrict nil)
7798 (files (org-agenda-files 'unrestricted)) entries file)
7799 ;; Get all entries which may contain an appt
7800 (org-prepare-agenda-buffers files)
7801 (while (setq file (pop files))
7802 (setq entries
7803 (append entries
7804 (org-agenda-get-day-entries
7805 file today :timestamp :scheduled :deadline))))
7806 (setq entries (delq nil entries))
7807 ;; Map thru entries and find if we should filter them out
7808 (mapc
7809 (lambda(x)
7810 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7811 (cat (get-text-property 1 'org-category x))
7812 (tod (get-text-property 1 'time-of-day x))
7813 (ok (or (null filter)
7814 (and (stringp filter) (string-match filter evt))
7815 (and (listp filter)
7816 (or (string-match
7817 (cadr (assoc 'category filter)) cat)
7818 (string-match
7819 (cadr (assoc 'headline filter)) evt))))))
7820 ;; FIXME: Shall we remove text-properties for the appt text?
7821 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7822 (when (and ok tod)
7823 (setq tod (concat "00" (number-to-string tod))
7824 tod (when (string-match
7825 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7826 (concat (match-string 1 tod) ":"
7827 (match-string 2 tod))))
7828 (appt-add tod evt)
7829 (setq cnt (1+ cnt))))) entries)
7830 (org-release-buffers org-agenda-new-buffers)
7831 (if (eq cnt 0)
7832 (message "No event to add")
7833 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7835 (defun org-agenda-todayp (date)
7836 "Does DATE mean today, when considering `org-extend-today-until'?"
7837 (let (today h)
7838 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7839 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7840 (setq h (nth 2 (decode-time (current-time))))
7841 (or (and (>= h org-extend-today-until)
7842 (= date today))
7843 (and (< h org-extend-today-until)
7844 (= date (1- today))))))
7846 (provide 'org-agenda)
7848 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7850 ;;; org-agenda.el ends here