Make org-publish-attachment honor directory structure
[org-mode.git] / lisp / org-agenda.el
blob74580762d54616f96d3b1e81c57ce11127e3507c
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.01trans
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 (setq org-agenda-last-search-view-search-was-boolean boolean)
3560 (when boolean
3561 (let (wds w)
3562 (while (setq w (pop words))
3563 (if (or (equal (substring w 0 1) "\"")
3564 (and (> (length w) 1)
3565 (member (substring w 0 1) '("+" "-"))
3566 (equal (substring w 1 2) "\"")))
3567 (while (and words (not (equal (substring w -1) "\"")))
3568 (setq w (concat w " " (pop words)))))
3569 (and (string-match "\\`\\([-+]?\\)\"" w)
3570 (setq w (replace-match "\\1" nil nil w)))
3571 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3572 (push w wds))
3573 (setq words (nreverse wds))))
3574 (if boolean
3575 (mapc (lambda (w)
3576 (setq c (string-to-char w))
3577 (if (equal c ?-)
3578 (setq neg t w (substring w 1))
3579 (if (equal c ?+)
3580 (setq neg nil w (substring w 1))
3581 (setq neg nil)))
3582 (if (string-match "\\`{.*}\\'" w)
3583 (setq re (substring w 1 -1))
3584 (if full-words
3585 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3586 (setq re (regexp-quote (downcase w)))))
3587 (if neg (push re regexps-) (push re regexps+)))
3588 words)
3589 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3590 regexps+))
3591 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3592 (if (not regexps+)
3593 (setq regexp (concat "^" org-outline-regexp))
3594 (setq regexp (pop regexps+))
3595 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3596 regexp))))
3597 (setq files (org-agenda-files nil 'ifmode))
3598 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3599 (pop org-agenda-text-search-extra-files)
3600 (setq files (org-add-archive-files files)))
3601 (setq files (append files org-agenda-text-search-extra-files)
3602 rtnall nil)
3603 (while (setq file (pop files))
3604 (setq ee nil)
3605 (catch 'nextfile
3606 (org-check-agenda-file file)
3607 (setq buffer (if (file-exists-p file)
3608 (org-get-agenda-file-buffer file)
3609 (error "No such file %s" file)))
3610 (if (not buffer)
3611 ;; If file does not exist, make sure an error message is sent
3612 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3613 file))))
3614 (with-current-buffer buffer
3615 (with-syntax-table (org-search-syntax-table)
3616 (unless (org-mode-p)
3617 (error "Agenda file %s is not in `org-mode'" file))
3618 (let ((case-fold-search t))
3619 (save-excursion
3620 (save-restriction
3621 (if org-agenda-restrict
3622 (narrow-to-region org-agenda-restrict-begin
3623 org-agenda-restrict-end)
3624 (widen))
3625 (goto-char (point-min))
3626 (unless (or (org-on-heading-p)
3627 (outline-next-heading))
3628 (throw 'nextfile t))
3629 (goto-char (max (point-min) (1- (point))))
3630 (while (re-search-forward regexp nil t)
3631 (org-back-to-heading t)
3632 (skip-chars-forward "* ")
3633 (setq beg (point-at-bol)
3634 beg1 (point)
3635 end (progn (outline-next-heading) (point)))
3636 (catch :skip
3637 (goto-char beg)
3638 (org-agenda-skip)
3639 (setq str (buffer-substring-no-properties
3640 (point-at-bol)
3641 (if hdl-only (point-at-eol) end)))
3642 (mapc (lambda (wr) (when (string-match wr str)
3643 (goto-char (1- end))
3644 (throw :skip t)))
3645 regexps-)
3646 (mapc (lambda (wr) (unless (string-match wr str)
3647 (goto-char (1- end))
3648 (throw :skip t)))
3649 (if todo-only
3650 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3651 regexps+)
3652 regexps+))
3653 (goto-char beg)
3654 (setq marker (org-agenda-new-marker (point))
3655 category (org-get-category)
3656 tags (org-get-tags-at (point))
3657 txt (org-format-agenda-item
3659 (buffer-substring-no-properties
3660 beg1 (point-at-eol))
3661 category tags))
3662 (org-add-props txt props
3663 'org-marker marker 'org-hd-marker marker
3664 'org-todo-regexp org-todo-regexp
3665 'org-complex-heading-regexp org-complex-heading-regexp
3666 'priority 1000 'org-category category
3667 'type "search")
3668 (push txt ee)
3669 (goto-char (1- end))))))))))
3670 (setq rtn (nreverse ee))
3671 (setq rtnall (append rtnall rtn)))
3672 (if org-agenda-overriding-header
3673 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3674 nil 'face 'org-agenda-structure) "\n")
3675 (insert "Search words: ")
3676 (add-text-properties (point-min) (1- (point))
3677 (list 'face 'org-agenda-structure))
3678 (setq pos (point))
3679 (insert string "\n")
3680 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3681 (setq pos (point))
3682 (unless org-agenda-multi
3683 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3684 (add-text-properties pos (1- (point))
3685 (list 'face 'org-agenda-structure))))
3686 (org-agenda-mark-header-line (point-min))
3687 (when rtnall
3688 (insert (org-finalize-agenda-entries rtnall) "\n"))
3689 (goto-char (point-min))
3690 (or org-agenda-multi (org-fit-agenda-window))
3691 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3692 (org-finalize-agenda)
3693 (setq buffer-read-only t)))
3695 ;;; Agenda TODO list
3697 (defvar org-select-this-todo-keyword nil)
3698 (defvar org-last-arg nil)
3700 ;;;###autoload
3701 (defun org-todo-list (arg)
3702 "Show all (not done) TODO entries from all agenda file in a single list.
3703 The prefix arg can be used to select a specific TODO keyword and limit
3704 the list to these. When using \\[universal-argument], you will be prompted
3705 for a keyword. A numeric prefix directly selects the Nth keyword in
3706 `org-todo-keywords-1'."
3707 (interactive "P")
3708 (org-compile-prefix-format 'todo)
3709 (org-set-sorting-strategy 'todo)
3710 (org-prepare-agenda "TODO")
3711 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3712 (let* ((today (time-to-days (current-time)))
3713 (date (calendar-gregorian-from-absolute today))
3714 (kwds org-todo-keywords-for-agenda)
3715 (completion-ignore-case t)
3716 (org-select-this-todo-keyword
3717 (if (stringp arg) arg
3718 (and arg (integerp arg) (> arg 0)
3719 (nth (1- arg) kwds))))
3720 rtn rtnall files file pos)
3721 (when (equal arg '(4))
3722 (setq org-select-this-todo-keyword
3723 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3724 (mapcar 'list kwds) nil nil)))
3725 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3726 (org-set-local 'org-last-arg arg)
3727 (setq org-agenda-redo-command
3728 '(org-todo-list (or current-prefix-arg org-last-arg)))
3729 (setq files (org-agenda-files nil 'ifmode)
3730 rtnall nil)
3731 (while (setq file (pop files))
3732 (catch 'nextfile
3733 (org-check-agenda-file file)
3734 (setq rtn (org-agenda-get-day-entries file date :todo))
3735 (setq rtnall (append rtnall rtn))))
3736 (if org-agenda-overriding-header
3737 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3738 nil 'face 'org-agenda-structure) "\n")
3739 (insert "Global list of TODO items of type: ")
3740 (add-text-properties (point-min) (1- (point))
3741 (list 'face 'org-agenda-structure
3742 'short-heading
3743 (concat "ToDo: "
3744 (or org-select-this-todo-keyword "ALL"))))
3745 (org-agenda-mark-header-line (point-min))
3746 (setq pos (point))
3747 (insert (or org-select-this-todo-keyword "ALL") "\n")
3748 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3749 (setq pos (point))
3750 (unless org-agenda-multi
3751 (insert "Available with `N r': (0)ALL")
3752 (let ((n 0) s)
3753 (mapc (lambda (x)
3754 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3755 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3756 (insert "\n "))
3757 (insert " " s))
3758 kwds))
3759 (insert "\n"))
3760 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3761 (org-agenda-mark-header-line (point-min))
3762 (when rtnall
3763 (insert (org-finalize-agenda-entries rtnall) "\n"))
3764 (goto-char (point-min))
3765 (or org-agenda-multi (org-fit-agenda-window))
3766 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3767 (org-finalize-agenda)
3768 (setq buffer-read-only t)))
3770 ;;; Agenda tags match
3772 ;;;###autoload
3773 (defun org-tags-view (&optional todo-only match)
3774 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3775 The prefix arg TODO-ONLY limits the search to TODO entries."
3776 (interactive "P")
3777 (org-compile-prefix-format 'tags)
3778 (org-set-sorting-strategy 'tags)
3779 (let* ((org-tags-match-list-sublevels
3780 org-tags-match-list-sublevels)
3781 (completion-ignore-case t)
3782 rtn rtnall files file pos matcher
3783 buffer)
3784 (when (and (stringp match) (not (string-match "\\S-" match)))
3785 (setq match nil))
3786 (setq matcher (org-make-tags-matcher match)
3787 match (car matcher) matcher (cdr matcher))
3788 (org-prepare-agenda (concat "TAGS " match))
3789 (setq org-agenda-query-string match)
3790 (setq org-agenda-redo-command
3791 (list 'org-tags-view (list 'quote todo-only)
3792 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3793 (setq files (org-agenda-files nil 'ifmode)
3794 rtnall nil)
3795 (while (setq file (pop files))
3796 (catch 'nextfile
3797 (org-check-agenda-file file)
3798 (setq buffer (if (file-exists-p file)
3799 (org-get-agenda-file-buffer file)
3800 (error "No such file %s" file)))
3801 (if (not buffer)
3802 ;; If file does not exist, error message to agenda
3803 (setq rtn (list
3804 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3805 rtnall (append rtnall rtn))
3806 (with-current-buffer buffer
3807 (unless (org-mode-p)
3808 (error "Agenda file %s is not in `org-mode'" file))
3809 (save-excursion
3810 (save-restriction
3811 (if org-agenda-restrict
3812 (narrow-to-region org-agenda-restrict-begin
3813 org-agenda-restrict-end)
3814 (widen))
3815 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3816 (setq rtnall (append rtnall rtn))))))))
3817 (if org-agenda-overriding-header
3818 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3819 nil 'face 'org-agenda-structure) "\n")
3820 (insert "Headlines with TAGS match: ")
3821 (add-text-properties (point-min) (1- (point))
3822 (list 'face 'org-agenda-structure
3823 'short-heading
3824 (concat "Match: " match)))
3825 (setq pos (point))
3826 (insert match "\n")
3827 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3828 (setq pos (point))
3829 (unless org-agenda-multi
3830 (insert "Press `C-u r' to search again with new search string\n"))
3831 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3832 (org-agenda-mark-header-line (point-min))
3833 (when rtnall
3834 (insert (org-finalize-agenda-entries rtnall) "\n"))
3835 (goto-char (point-min))
3836 (or org-agenda-multi (org-fit-agenda-window))
3837 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3838 (org-finalize-agenda)
3839 (setq buffer-read-only t)))
3841 ;;; Agenda Finding stuck projects
3843 (defvar org-agenda-skip-regexp nil
3844 "Regular expression used in skipping subtrees for the agenda.
3845 This is basically a temporary global variable that can be set and then
3846 used by user-defined selections using `org-agenda-skip-function'.")
3848 (defvar org-agenda-overriding-header nil
3849 "When this is set during todo and tags searches, will replace header.
3850 This variable should not be set directly, but custom commands can bind it
3851 in the options section.")
3853 (defun org-agenda-skip-entry-when-regexp-matches ()
3854 "Check if the current entry contains match for `org-agenda-skip-regexp'.
3855 If yes, it returns the end position of this entry, causing agenda commands
3856 to skip the entry but continuing the search in the subtree. This is a
3857 function that can be put into `org-agenda-skip-function' for the duration
3858 of a command."
3859 (let ((end (save-excursion (org-end-of-subtree t)))
3860 skip)
3861 (save-excursion
3862 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3863 (and skip end)))
3865 (defun org-agenda-skip-subtree-when-regexp-matches ()
3866 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
3867 If yes, it returns the end position of this tree, causing agenda commands
3868 to skip this subtree. This is a function that can be put into
3869 `org-agenda-skip-function' for the duration of a command."
3870 (let ((end (save-excursion (org-end-of-subtree t)))
3871 skip)
3872 (save-excursion
3873 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3874 (and skip end)))
3876 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3877 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
3878 If yes, it returns the end position of the current entry (NOT the tree),
3879 causing agenda commands to skip the entry but continuing the search in
3880 the subtree. This is a function that can be put into
3881 `org-agenda-skip-function' for the duration of a command. An important
3882 use of this function is for the stuck project list."
3883 (let ((end (save-excursion (org-end-of-subtree t)))
3884 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3885 skip)
3886 (save-excursion
3887 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3888 (and skip entry-end)))
3890 (defun org-agenda-skip-entry-if (&rest conditions)
3891 "Skip entry if any of CONDITIONS is true.
3892 See `org-agenda-skip-if' for details."
3893 (org-agenda-skip-if nil conditions))
3895 (defun org-agenda-skip-subtree-if (&rest conditions)
3896 "Skip entry if any of CONDITIONS is true.
3897 See `org-agenda-skip-if' for details."
3898 (org-agenda-skip-if t conditions))
3900 (defun org-agenda-skip-if (subtree conditions)
3901 "Checks current entity for CONDITIONS.
3902 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3903 the entry, i.e. the text before the next heading is checked.
3905 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3906 from different tests. Valid conditions are:
3908 scheduled Check if there is a scheduled cookie
3909 notscheduled Check if there is no scheduled cookie
3910 deadline Check if there is a deadline
3911 notdeadline Check if there is no deadline
3912 timestamp Check if there is a timestamp (also deadline or scheduled)
3913 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3914 regexp Check if regexp matches
3915 notregexp Check if regexp does not match.
3916 todo Check if TODO keyword matches
3917 nottodo Check if TODO keyword does not match
3919 The regexp is taken from the conditions list, it must come right after
3920 the `regexp' or `notregexp' element.
3922 `todo' and `nottodo' accept as an argument a list of todo
3923 keywords, which may include \"*\" to match any todo keyword.
3925 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
3927 would skip all entries with \"TODO\" or \"WAITING\" keywords.
3929 Instead of a list a keyword class may be given
3931 (org-agenda-skip-entry-if 'nottodo 'done)
3933 would skip entries that haven't been marked with any of \"DONE\"
3934 keywords. Possible classes are: `todo', `done', `any'.
3936 If any of these conditions is met, this function returns the end point of
3937 the entity, causing the search to continue from there. This is a function
3938 that can be put into `org-agenda-skip-function' for the duration of a command."
3939 (let (beg end m)
3940 (org-back-to-heading t)
3941 (setq beg (point)
3942 end (if subtree
3943 (progn (org-end-of-subtree t) (point))
3944 (progn (outline-next-heading) (1- (point)))))
3945 (goto-char beg)
3946 (and
3948 (and (memq 'scheduled conditions)
3949 (re-search-forward org-scheduled-time-regexp end t))
3950 (and (memq 'notscheduled conditions)
3951 (not (re-search-forward org-scheduled-time-regexp end t)))
3952 (and (memq 'deadline conditions)
3953 (re-search-forward org-deadline-time-regexp end t))
3954 (and (memq 'notdeadline conditions)
3955 (not (re-search-forward org-deadline-time-regexp end t)))
3956 (and (memq 'timestamp conditions)
3957 (re-search-forward org-ts-regexp end t))
3958 (and (memq 'nottimestamp conditions)
3959 (not (re-search-forward org-ts-regexp end t)))
3960 (and (setq m (memq 'regexp conditions))
3961 (stringp (nth 1 m))
3962 (re-search-forward (nth 1 m) end t))
3963 (and (setq m (memq 'notregexp conditions))
3964 (stringp (nth 1 m))
3965 (not (re-search-forward (nth 1 m) end t)))
3966 (and (or
3967 (setq m (memq 'todo conditions))
3968 (setq m (memq 'nottodo conditions)))
3969 (org-agenda-skip-if-todo m end)))
3970 end)))
3972 (defun org-agenda-skip-if-todo (args end)
3973 "Helper function for `org-agenda-skip-if', do not use it directly.
3974 ARGS is a list with first element either `todo' or `nottodo'.
3975 The remainder is either a list of TODO keywords, or a state symbol
3976 `todo' or `done' or `any'."
3977 (let ((kw (car args))
3978 (arg (cadr args))
3979 todo-wds todo-re)
3980 (setq todo-wds
3981 (org-uniquify
3982 (cond
3983 ((listp arg) ;; list of keywords
3984 (if (member "*" arg)
3985 (mapcar 'substring-no-properties org-todo-keywords-1)
3986 arg))
3987 ((symbolp arg) ;; keyword class name
3988 (cond
3989 ((eq arg 'todo)
3990 (org-delete-all org-done-keywords
3991 (mapcar 'substring-no-properties
3992 org-todo-keywords-1)))
3993 ((eq arg 'done) org-done-keywords)
3994 ((eq arg 'any)
3995 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
3996 (setq todo-re
3997 (concat "^\\*+[ \t]+\\<\\("
3998 (mapconcat 'identity todo-wds "\\|")
3999 "\\)\\>"))
4000 (if (eq kw 'todo)
4001 (re-search-forward todo-re end t)
4002 (not (re-search-forward todo-re end t)))))
4004 ;;;###autoload
4005 (defun org-agenda-list-stuck-projects (&rest ignore)
4006 "Create agenda view for projects that are stuck.
4007 Stuck projects are project that have no next actions. For the definitions
4008 of what a project is and how to check if it stuck, customize the variable
4009 `org-stuck-projects'."
4010 (interactive)
4011 (let* ((org-agenda-skip-function
4012 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4013 ;; We could have used org-agenda-skip-if here.
4014 (org-agenda-overriding-header
4015 (or org-agenda-overriding-header "List of stuck projects: "))
4016 (matcher (nth 0 org-stuck-projects))
4017 (todo (nth 1 org-stuck-projects))
4018 (todo-wds (if (member "*" todo)
4019 (progn
4020 (org-prepare-agenda-buffers (org-agenda-files
4021 nil 'ifmode))
4022 (org-delete-all
4023 org-done-keywords-for-agenda
4024 (copy-sequence org-todo-keywords-for-agenda)))
4025 todo))
4026 (todo-re (concat "^\\*+[ \t]+\\("
4027 (mapconcat 'identity todo-wds "\\|")
4028 "\\)\\>"))
4029 (tags (nth 2 org-stuck-projects))
4030 (tags-re (if (member "*" tags)
4031 (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
4032 (if tags
4033 (concat "^\\*+ .*:\\("
4034 (mapconcat 'identity tags "\\|")
4035 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4036 (gen-re (nth 3 org-stuck-projects))
4037 (re-list
4038 (delq nil
4039 (list
4040 (if todo todo-re)
4041 (if tags tags-re)
4042 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4043 gen-re)))))
4044 (setq org-agenda-skip-regexp
4045 (if re-list
4046 (mapconcat 'identity re-list "\\|")
4047 (error "No information how to identify unstuck projects")))
4048 (org-tags-view nil matcher)
4049 (with-current-buffer org-agenda-buffer-name
4050 (setq org-agenda-redo-command
4051 '(org-agenda-list-stuck-projects
4052 (or current-prefix-arg org-last-arg))))))
4054 ;;; Diary integration
4056 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4057 (defvar list-diary-entries-hook)
4059 (defun org-get-entries-from-diary (date)
4060 "Get the (Emacs Calendar) diary entries for DATE."
4061 (require 'diary-lib)
4062 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4063 (diary-display-hook '(fancy-diary-display))
4064 (diary-display-function 'fancy-diary-display)
4065 (pop-up-frames nil)
4066 (list-diary-entries-hook
4067 (cons 'org-diary-default-entry list-diary-entries-hook))
4068 (diary-file-name-prefix-function nil) ; turn this feature off
4069 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4070 entries
4071 (org-disable-agenda-to-diary t))
4072 (save-excursion
4073 (save-window-excursion
4074 (funcall (if (fboundp 'diary-list-entries)
4075 'diary-list-entries 'list-diary-entries)
4076 date 1)))
4077 (if (not (get-buffer diary-fancy-buffer))
4078 (setq entries nil)
4079 (with-current-buffer diary-fancy-buffer
4080 (setq buffer-read-only nil)
4081 (if (zerop (buffer-size))
4082 ;; No entries
4083 (setq entries nil)
4084 ;; Omit the date and other unnecessary stuff
4085 (org-agenda-cleanup-fancy-diary)
4086 ;; Add prefix to each line and extend the text properties
4087 (if (zerop (buffer-size))
4088 (setq entries nil)
4089 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
4090 (set-buffer-modified-p nil)
4091 (kill-buffer diary-fancy-buffer)))
4092 (when entries
4093 (setq entries (org-split-string entries "\n"))
4094 (setq entries
4095 (mapcar
4096 (lambda (x)
4097 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4098 ;; Extend the text properties to the beginning of the line
4099 (org-add-props x (text-properties-at (1- (length x)) x)
4100 'type "diary" 'date date 'face 'org-agenda-diary))
4101 entries)))))
4103 (defvar org-agenda-cleanup-fancy-diary-hook nil
4104 "Hook run when the fancy diary buffer is cleaned up.")
4106 (defun org-agenda-cleanup-fancy-diary ()
4107 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4108 This gets rid of the date, the underline under the date, and
4109 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4110 date. It also removes lines that contain only whitespace."
4111 (goto-char (point-min))
4112 (if (looking-at ".*?:[ \t]*")
4113 (progn
4114 (replace-match "")
4115 (re-search-forward "\n=+$" nil t)
4116 (replace-match "")
4117 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4118 (re-search-forward "\n=+$" nil t)
4119 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4120 (goto-char (point-min))
4121 (while (re-search-forward "^ +\n" nil t)
4122 (replace-match ""))
4123 (goto-char (point-min))
4124 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4125 (replace-match ""))
4126 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4128 ;; Make sure entries from the diary have the right text properties.
4129 (eval-after-load "diary-lib"
4130 '(if (boundp 'diary-modify-entry-list-string-function)
4131 ;; We can rely on the hook, nothing to do
4133 ;; Hook not available, must use advice to make this work
4134 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4135 "Make the position visible."
4136 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4137 (stringp string)
4138 buffer-file-name)
4139 (setq string (org-modify-diary-entry-string string))))))
4141 (defun org-modify-diary-entry-string (string)
4142 "Add text properties to string, allowing org-mode to act on it."
4143 (org-add-props string nil
4144 'mouse-face 'highlight
4145 'help-echo (if buffer-file-name
4146 (format "mouse-2 or RET jump to diary file %s"
4147 (abbreviate-file-name buffer-file-name))
4149 'org-agenda-diary-link t
4150 'org-marker (org-agenda-new-marker (point-at-bol))))
4152 (defun org-diary-default-entry ()
4153 "Add a dummy entry to the diary.
4154 Needed to avoid empty dates which mess up holiday display."
4155 ;; Catch the error if dealing with the new add-to-diary-alist
4156 (when org-disable-agenda-to-diary
4157 (condition-case nil
4158 (org-add-to-diary-list original-date "Org-mode dummy" "")
4159 (error
4160 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4162 (defun org-add-to-diary-list (&rest args)
4163 (if (fboundp 'diary-add-to-list)
4164 (apply 'diary-add-to-list args)
4165 (apply 'add-to-diary-list args)))
4167 (defvar org-diary-last-run-time nil)
4169 ;;;###autoload
4170 (defun org-diary (&rest args)
4171 "Return diary information from org-files.
4172 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4173 It accesses org files and extracts information from those files to be
4174 listed in the diary. The function accepts arguments specifying what
4175 items should be listed. For a list of arguments allowed here, see the
4176 variable `org-agenda-entry-types'.
4178 The call in the diary file should look like this:
4180 &%%(org-diary) ~/path/to/some/orgfile.org
4182 Use a separate line for each org file to check. Or, if you omit the file name,
4183 all files listed in `org-agenda-files' will be checked automatically:
4185 &%%(org-diary)
4187 If you don't give any arguments (as in the example above), the default
4188 arguments (:deadline :scheduled :timestamp :sexp) are used.
4189 So the example above may also be written as
4191 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4193 The function expects the lisp variables `entry' and `date' to be provided
4194 by the caller, because this is how the calendar works. Don't use this
4195 function from a program - use `org-agenda-get-day-entries' instead."
4196 (when (> (- (org-float-time)
4197 org-agenda-last-marker-time)
4199 (org-agenda-reset-markers))
4200 (org-compile-prefix-format 'agenda)
4201 (org-set-sorting-strategy 'agenda)
4202 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4203 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4204 (list entry)
4205 (org-agenda-files t)))
4206 (time (org-float-time))
4207 file rtn results)
4208 (when (or (not org-diary-last-run-time)
4209 (> (- time
4210 org-diary-last-run-time)
4212 (org-prepare-agenda-buffers files))
4213 (setq org-diary-last-run-time time)
4214 ;; If this is called during org-agenda, don't return any entries to
4215 ;; the calendar. Org Agenda will list these entries itself.
4216 (if org-disable-agenda-to-diary (setq files nil))
4217 (while (setq file (pop files))
4218 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4219 (setq results (append results rtn)))
4220 (if results
4221 (concat (org-finalize-agenda-entries results) "\n"))))
4223 ;;; Agenda entry finders
4225 (defun org-agenda-get-day-entries (file date &rest args)
4226 "Does the work for `org-diary' and `org-agenda'.
4227 FILE is the path to a file to be checked for entries. DATE is date like
4228 the one returned by `calendar-current-date'. ARGS are symbols indicating
4229 which kind of entries should be extracted. For details about these, see
4230 the documentation of `org-diary'."
4231 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4232 (let* ((org-startup-folded nil)
4233 (org-startup-align-all-tables nil)
4234 (buffer (if (file-exists-p file)
4235 (org-get-agenda-file-buffer file)
4236 (error "No such file %s" file)))
4237 arg results rtn deadline-results)
4238 (if (not buffer)
4239 ;; If file does not exist, make sure an error message ends up in diary
4240 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4241 (with-current-buffer buffer
4242 (unless (org-mode-p)
4243 (error "Agenda file %s is not in `org-mode'" file))
4244 (let ((case-fold-search nil))
4245 (save-excursion
4246 (save-restriction
4247 (if org-agenda-restrict
4248 (narrow-to-region org-agenda-restrict-begin
4249 org-agenda-restrict-end)
4250 (widen))
4251 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4252 (while (setq arg (pop args))
4253 (cond
4254 ((and (eq arg :todo)
4255 (equal date (calendar-current-date)))
4256 (setq rtn (org-agenda-get-todos))
4257 (setq results (append results rtn)))
4258 ((eq arg :timestamp)
4259 (setq rtn (org-agenda-get-blocks))
4260 (setq results (append results rtn))
4261 (setq rtn (org-agenda-get-timestamps))
4262 (setq results (append results rtn)))
4263 ((eq arg :sexp)
4264 (setq rtn (org-agenda-get-sexps))
4265 (setq results (append results rtn)))
4266 ((eq arg :scheduled)
4267 (setq rtn (org-agenda-get-scheduled deadline-results))
4268 (setq results (append results rtn)))
4269 ((eq arg :closed)
4270 (setq rtn (org-agenda-get-progress))
4271 (setq results (append results rtn)))
4272 ((eq arg :deadline)
4273 (setq rtn (org-agenda-get-deadlines))
4274 (setq deadline-results (copy-sequence rtn))
4275 (setq results (append results rtn))))))))
4276 results))))
4278 (defun org-agenda-get-todos ()
4279 "Return the TODO information for agenda display."
4280 (let* ((props (list 'face nil
4281 'done-face 'org-agenda-done
4282 'org-not-done-regexp org-not-done-regexp
4283 'org-todo-regexp org-todo-regexp
4284 'org-complex-heading-regexp org-complex-heading-regexp
4285 'mouse-face 'highlight
4286 'help-echo
4287 (format "mouse-2 or RET jump to org file %s"
4288 (abbreviate-file-name buffer-file-name))))
4289 (regexp (concat "^\\*+[ \t]+\\("
4290 (if org-select-this-todo-keyword
4291 (if (equal org-select-this-todo-keyword "*")
4292 org-todo-regexp
4293 (concat "\\<\\("
4294 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4295 "\\)\\>"))
4296 org-not-done-regexp)
4297 "[^\n\r]*\\)"))
4298 marker priority category tags todo-state
4299 ee txt beg end)
4300 (goto-char (point-min))
4301 (while (re-search-forward regexp nil t)
4302 (catch :skip
4303 (save-match-data
4304 (beginning-of-line)
4305 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4306 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4307 (goto-char (1+ beg))
4308 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4309 (throw :skip nil)))
4310 (goto-char beg)
4311 (org-agenda-skip)
4312 (goto-char (match-beginning 1))
4313 (setq marker (org-agenda-new-marker (match-beginning 0))
4314 category (org-get-category)
4315 txt (match-string 1)
4316 tags (org-get-tags-at (point))
4317 txt (org-format-agenda-item "" txt category tags)
4318 priority (1+ (org-get-priority txt))
4319 todo-state (org-get-todo-state))
4320 (org-add-props txt props
4321 'org-marker marker 'org-hd-marker marker
4322 'priority priority 'org-category category
4323 'type "todo" 'todo-state todo-state)
4324 (push txt ee)
4325 (if org-agenda-todo-list-sublevels
4326 (goto-char (match-end 1))
4327 (org-end-of-subtree 'invisible))))
4328 (nreverse ee)))
4330 ;;;###autoload
4331 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4332 (&optional end)
4333 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4334 (when (or org-agenda-todo-ignore-with-date
4335 org-agenda-todo-ignore-scheduled
4336 org-agenda-todo-ignore-deadlines)
4337 (setq end (or end (save-excursion (outline-next-heading) (point))))
4338 (save-excursion
4339 (or (and org-agenda-todo-ignore-with-date
4340 (re-search-forward org-ts-regexp end t))
4341 (and org-agenda-todo-ignore-scheduled
4342 (re-search-forward org-scheduled-time-regexp end t)
4343 (cond
4344 ((eq org-agenda-todo-ignore-scheduled 'future)
4345 (> (org-days-to-time (match-string 1)) 0))
4346 ((eq org-agenda-todo-ignore-scheduled 'past)
4347 (<= (org-days-to-time (match-string 1)) 0))
4348 (t)))
4349 (and org-agenda-todo-ignore-deadlines
4350 (re-search-forward org-deadline-time-regexp end t)
4351 (cond
4352 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4353 ((eq org-agenda-todo-ignore-deadlines 'far)
4354 (not (org-deadline-close (match-string 1))))
4355 ((eq org-agenda-todo-ignore-deadlines 'future)
4356 (> (org-days-to-time (match-string 1)) 0))
4357 ((eq org-agenda-todo-ignore-deadlines 'past)
4358 (<= (org-days-to-time (match-string 1)) 0))
4359 (t (org-deadline-close (match-string 1)))))))))
4361 (defconst org-agenda-no-heading-message
4362 "No heading for this item in buffer or region.")
4364 (defun org-agenda-get-timestamps ()
4365 "Return the date stamp information for agenda display."
4366 (let* ((props (list 'face nil
4367 'org-not-done-regexp org-not-done-regexp
4368 'org-todo-regexp org-todo-regexp
4369 'org-complex-heading-regexp org-complex-heading-regexp
4370 'mouse-face 'highlight
4371 'help-echo
4372 (format "mouse-2 or RET jump to org file %s"
4373 (abbreviate-file-name buffer-file-name))))
4374 (d1 (calendar-absolute-from-gregorian date))
4375 (remove-re
4376 (concat
4377 (regexp-quote
4378 (format-time-string
4379 "<%Y-%m-%d"
4380 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4381 ".*?>"))
4382 (regexp
4383 (concat
4384 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4385 (regexp-quote
4386 (substring
4387 (format-time-string
4388 (car org-time-stamp-formats)
4389 (apply 'encode-time ; DATE bound by calendar
4390 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4391 1 11))
4392 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4393 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4394 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4395 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4396 todo-state end-of-match)
4397 (goto-char (point-min))
4398 (while (setq end-of-match (re-search-forward regexp nil t))
4399 (setq b0 (match-beginning 0)
4400 b3 (match-beginning 3) e3 (match-end 3))
4401 (catch :skip
4402 (and (org-at-date-range-p) (throw :skip nil))
4403 (org-agenda-skip)
4404 (if (and (match-end 1)
4405 (not (= d1 (org-time-string-to-absolute
4406 (match-string 1) d1 nil
4407 org-agenda-repeating-timestamp-show-all))))
4408 (throw :skip nil))
4409 (if (and e3
4410 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4411 (throw :skip nil))
4412 (setq tmp (buffer-substring (max (point-min)
4413 (- b0 org-ds-keyword-length))
4415 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4416 inactivep (= (char-after b0) ?\[)
4417 deadlinep (string-match org-deadline-regexp tmp)
4418 scheduledp (string-match org-scheduled-regexp tmp)
4419 closedp (and org-agenda-include-inactive-timestamps
4420 (string-match org-closed-string tmp))
4421 clockp (and org-agenda-include-inactive-timestamps
4422 (or (string-match org-clock-string tmp)
4423 (string-match "]-+\\'" tmp)))
4424 todo-state (ignore-errors (org-get-todo-state))
4425 donep (member todo-state org-done-keywords))
4426 (if (or scheduledp deadlinep closedp clockp
4427 (and donep org-agenda-skip-timestamp-if-done))
4428 (throw :skip t))
4429 (if (string-match ">" timestr)
4430 ;; substring should only run to end of time stamp
4431 (setq timestr (substring timestr 0 (match-end 0))))
4432 (setq marker (org-agenda-new-marker b0)
4433 category (org-get-category b0))
4434 (save-excursion
4435 (if (not (re-search-backward "^\\*+ " nil t))
4436 (setq txt org-agenda-no-heading-message)
4437 (goto-char (match-beginning 0))
4438 (setq hdmarker (org-agenda-new-marker)
4439 tags (org-get-tags-at))
4440 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4441 (setq head (match-string 1))
4442 (setq txt (org-format-agenda-item
4443 (if inactivep org-agenda-inactive-leader nil)
4444 head category tags timestr nil
4445 remove-re)))
4446 (setq priority (org-get-priority txt))
4447 (org-add-props txt props
4448 'org-marker marker 'org-hd-marker hdmarker)
4449 (org-add-props txt nil 'priority priority
4450 'org-category category 'date date
4451 'todo-state todo-state
4452 'type "timestamp")
4453 (push txt ee))
4454 (if org-agenda-skip-additional-timestamps-same-entry
4455 (outline-next-heading)
4456 (goto-char end-of-match))))
4457 (nreverse ee)))
4459 (defun org-agenda-get-sexps ()
4460 "Return the sexp information for agenda display."
4461 (require 'diary-lib)
4462 (let* ((props (list 'face nil
4463 'mouse-face 'highlight
4464 'help-echo
4465 (format "mouse-2 or RET jump to org file %s"
4466 (abbreviate-file-name buffer-file-name))))
4467 (regexp "^&?%%(")
4468 marker category ee txt tags entry result beg b sexp sexp-entry
4469 todo-state)
4470 (goto-char (point-min))
4471 (while (re-search-forward regexp nil t)
4472 (catch :skip
4473 (org-agenda-skip)
4474 (setq beg (match-beginning 0))
4475 (goto-char (1- (match-end 0)))
4476 (setq b (point))
4477 (forward-sexp 1)
4478 (setq sexp (buffer-substring b (point)))
4479 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4480 (org-trim (match-string 1))
4481 ""))
4482 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4483 (when result
4484 (setq marker (org-agenda-new-marker beg)
4485 category (org-get-category beg)
4486 todo-state (org-get-todo-state))
4488 (if (string-match "\\S-" result)
4489 (setq txt result)
4490 (setq txt "SEXP entry returned empty string"))
4492 (setq txt (org-format-agenda-item
4493 "" txt category tags 'time))
4494 (org-add-props txt props 'org-marker marker)
4495 (org-add-props txt nil
4496 'org-category category 'date date 'todo-state todo-state
4497 'type "sexp")
4498 (push txt ee))))
4499 (nreverse ee)))
4501 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4502 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4503 The order of the first 2 times 3 arguments depends on the variable
4504 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4505 So for American calendars, give this as MONTH DAY YEAR, for European as
4506 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4507 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4508 is any number of ISO weeks in the block period for which the item should
4509 be skipped."
4510 (let* ((date1 (calendar-absolute-from-gregorian
4511 (org-order-calendar-date-args m1 d1 y1)))
4512 (date2 (calendar-absolute-from-gregorian
4513 (org-order-calendar-date-args m2 d2 y2)))
4514 (d (calendar-absolute-from-gregorian date)))
4515 (and
4516 (<= date1 d)
4517 (<= d date2)
4518 (= (calendar-day-of-week date) dayname)
4519 (or (not skip-weeks)
4520 (progn
4521 (require 'cal-iso)
4522 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4523 entry)))
4525 (defalias 'org-get-closed 'org-agenda-get-progress)
4526 (defun org-agenda-get-progress ()
4527 "Return the logged TODO entries for agenda display."
4528 (let* ((props (list 'mouse-face 'highlight
4529 'org-not-done-regexp org-not-done-regexp
4530 'org-todo-regexp org-todo-regexp
4531 'org-complex-heading-regexp org-complex-heading-regexp
4532 'help-echo
4533 (format "mouse-2 or RET jump to org file %s"
4534 (abbreviate-file-name buffer-file-name))))
4535 (items (if (consp org-agenda-show-log)
4536 org-agenda-show-log
4537 org-agenda-log-mode-items))
4538 (parts
4539 (delq nil
4540 (list
4541 (if (memq 'closed items) (concat "\\<" org-closed-string))
4542 (if (memq 'clock items) (concat "\\<" org-clock-string))
4543 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4544 (parts-re (if parts (mapconcat 'identity parts "\\|")
4545 (error "`org-agenda-log-mode-items' is empty")))
4546 (regexp (concat
4547 "\\(" parts-re "\\)"
4548 " *\\["
4549 (regexp-quote
4550 (substring
4551 (format-time-string
4552 (car org-time-stamp-formats)
4553 (apply 'encode-time ; DATE bound by calendar
4554 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4555 1 11))))
4556 (org-agenda-search-headline-for-time nil)
4557 marker hdmarker priority category tags closedp statep clockp state
4558 ee txt extra timestr rest clocked)
4559 (goto-char (point-min))
4560 (while (re-search-forward regexp nil t)
4561 (catch :skip
4562 (org-agenda-skip)
4563 (setq marker (org-agenda-new-marker (match-beginning 0))
4564 closedp (equal (match-string 1) org-closed-string)
4565 statep (equal (string-to-char (match-string 1)) ?-)
4566 clockp (not (or closedp statep))
4567 state (and statep (match-string 2))
4568 category (org-get-category (match-beginning 0))
4569 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4571 (when (string-match "\\]" timestr)
4572 ;; substring should only run to end of time stamp
4573 (setq rest (substring timestr (match-end 0))
4574 timestr (substring timestr 0 (match-end 0)))
4575 (if (and (not closedp) (not statep)
4576 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4577 (progn (setq timestr (concat (substring timestr 0 -1)
4578 "-" (match-string 1 rest) "]"))
4579 (setq clocked (match-string 2 rest)))
4580 (setq clocked "-")))
4581 (save-excursion
4582 (setq extra nil)
4583 (cond
4584 ((not org-agenda-log-mode-add-notes))
4585 (statep
4586 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4587 (setq extra (match-string 1))))
4588 (clockp
4589 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4590 (setq extra (match-string 1)))))
4591 (if (not (re-search-backward "^\\*+ " nil t))
4592 (setq txt org-agenda-no-heading-message)
4593 (goto-char (match-beginning 0))
4594 (setq hdmarker (org-agenda-new-marker)
4595 tags (org-get-tags-at))
4596 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4597 (setq txt (match-string 1))
4598 (when extra
4599 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4600 (setq txt (concat (substring txt 0 (match-beginning 1))
4601 " - " extra " " (match-string 2 txt)))
4602 (setq txt (concat txt " - " extra))))
4603 (setq txt (org-format-agenda-item
4604 (cond
4605 (closedp "Closed: ")
4606 (statep (concat "State: (" state ")"))
4607 (t (concat "Clocked: (" clocked ")")))
4608 txt category tags timestr)))
4609 (setq priority 100000)
4610 (org-add-props txt props
4611 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4612 'priority priority 'org-category category
4613 'type "closed" 'date date
4614 'undone-face 'org-warning 'done-face 'org-agenda-done)
4615 (push txt ee))
4616 (goto-char (point-at-eol))))
4617 (nreverse ee)))
4619 (defun org-agenda-get-deadlines ()
4620 "Return the deadline information for agenda display."
4621 (let* ((props (list 'mouse-face 'highlight
4622 'org-not-done-regexp org-not-done-regexp
4623 'org-todo-regexp org-todo-regexp
4624 'org-complex-heading-regexp org-complex-heading-regexp
4625 'help-echo
4626 (format "mouse-2 or RET jump to org file %s"
4627 (abbreviate-file-name buffer-file-name))))
4628 (regexp org-deadline-time-regexp)
4629 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4630 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4631 d2 diff dfrac wdays pos pos1 category tags
4632 suppress-prewarning
4633 ee txt head face s todo-state upcomingp donep timestr)
4634 (goto-char (point-min))
4635 (while (re-search-forward regexp nil t)
4636 (setq suppress-prewarning nil)
4637 (catch :skip
4638 (org-agenda-skip)
4639 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4640 (save-match-data
4641 (string-match org-scheduled-time-regexp
4642 (buffer-substring (point-at-bol)
4643 (point-at-eol)))))
4644 (setq suppress-prewarning
4645 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4646 org-agenda-skip-deadline-prewarning-if-scheduled
4647 0)))
4648 (setq s (match-string 1)
4649 txt nil
4650 pos (1- (match-beginning 1))
4651 d2 (org-time-string-to-absolute
4652 (match-string 1) d1 'past
4653 org-agenda-repeating-timestamp-show-all)
4654 diff (- d2 d1)
4655 wdays (if suppress-prewarning
4656 (let ((org-deadline-warning-days suppress-prewarning))
4657 (org-get-wdays s))
4658 (org-get-wdays s))
4659 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4660 upcomingp (and todayp (> diff 0)))
4661 ;; When to show a deadline in the calendar:
4662 ;; If the expiration is within wdays warning time.
4663 ;; Past-due deadlines are only shown on the current date
4664 (if (and (or (and (<= diff wdays)
4665 (and todayp (not org-agenda-only-exact-dates)))
4666 (= diff 0)))
4667 (save-excursion
4668 (setq todo-state (org-get-todo-state))
4669 (setq donep (member todo-state org-done-keywords))
4670 (if (and donep
4671 (or org-agenda-skip-deadline-if-done
4672 (not (= diff 0))))
4673 (setq txt nil)
4674 (setq category (org-get-category))
4675 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4676 (setq txt org-agenda-no-heading-message)
4677 (goto-char (match-end 0))
4678 (setq pos1 (match-beginning 0))
4679 (setq tags (org-get-tags-at pos1))
4680 (setq head (buffer-substring-no-properties
4681 (point)
4682 (progn (skip-chars-forward "^\r\n")
4683 (point))))
4684 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4685 (setq timestr
4686 (concat (substring s (match-beginning 1)) " "))
4687 (setq timestr 'time))
4688 (setq txt (org-format-agenda-item
4689 (if (= diff 0)
4690 (car org-agenda-deadline-leaders)
4691 (if (functionp
4692 (nth 1 org-agenda-deadline-leaders))
4693 (funcall
4694 (nth 1 org-agenda-deadline-leaders)
4695 diff date)
4696 (format (nth 1 org-agenda-deadline-leaders)
4697 diff)))
4698 head category tags
4699 (if (not (= diff 0)) nil timestr)))))
4700 (when txt
4701 (setq face (org-agenda-deadline-face dfrac wdays))
4702 (org-add-props txt props
4703 'org-marker (org-agenda-new-marker pos)
4704 'org-hd-marker (org-agenda-new-marker pos1)
4705 'priority (+ (- diff)
4706 (org-get-priority txt))
4707 'org-category category
4708 'todo-state todo-state
4709 'type (if upcomingp "upcoming-deadline" "deadline")
4710 'date (if upcomingp date d2)
4711 'face (if donep 'org-agenda-done face)
4712 'undone-face face 'done-face 'org-agenda-done)
4713 (push txt ee))))))
4714 (nreverse ee)))
4716 (defun org-agenda-deadline-face (fraction &optional wdays)
4717 "Return the face to displaying a deadline item.
4718 FRACTION is what fraction of the head-warning time has passed."
4719 (if (equal wdays 0) (setq fraction 1.))
4720 (let ((faces org-agenda-deadline-faces) f)
4721 (catch 'exit
4722 (while (setq f (pop faces))
4723 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4725 (defun org-agenda-get-scheduled (&optional deadline-results)
4726 "Return the scheduled information for agenda display."
4727 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4728 'org-todo-regexp org-todo-regexp
4729 'org-complex-heading-regexp org-complex-heading-regexp
4730 'done-face 'org-agenda-done
4731 'mouse-face 'highlight
4732 'help-echo
4733 (format "mouse-2 or RET jump to org file %s"
4734 (abbreviate-file-name buffer-file-name))))
4735 (regexp org-scheduled-time-regexp)
4736 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4737 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4739 (deadline-position-alist
4740 (mapcar (lambda (a) (and (setq mm (get-text-property
4741 0 'org-hd-marker a))
4742 (cons (marker-position mm) a)))
4743 deadline-results))
4744 d2 diff pos pos1 category tags donep
4745 ee txt head pastschedp todo-state face timestr s habitp)
4746 (goto-char (point-min))
4747 (while (re-search-forward regexp nil t)
4748 (catch :skip
4749 (org-agenda-skip)
4750 (setq s (match-string 1)
4751 txt nil
4752 pos (1- (match-beginning 1))
4753 d2 (org-time-string-to-absolute
4754 (match-string 1) d1 'past
4755 org-agenda-repeating-timestamp-show-all)
4756 diff (- d2 d1))
4757 (setq pastschedp (and todayp (< diff 0)))
4758 ;; When to show a scheduled item in the calendar:
4759 ;; If it is on or past the date.
4760 (when (or (and (< diff 0)
4761 (< (abs diff) org-scheduled-past-days)
4762 (and todayp (not org-agenda-only-exact-dates)))
4763 (= diff 0))
4764 (save-excursion
4765 (setq todo-state (org-get-todo-state))
4766 (setq donep (member todo-state org-done-keywords))
4767 (setq habitp (and (functionp 'org-is-habit-p)
4768 (org-is-habit-p)))
4769 (if (and donep
4770 (or habitp org-agenda-skip-scheduled-if-done
4771 (not (= diff 0))))
4772 (setq txt nil)
4773 (setq category (org-get-category))
4774 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4775 (setq txt org-agenda-no-heading-message)
4776 (goto-char (match-end 0))
4777 (setq pos1 (match-beginning 0))
4778 (if habitp
4779 (if (or (not org-habit-show-habits)
4780 (and (not todayp)
4781 org-habit-show-habits-only-for-today))
4782 (throw :skip nil))
4783 (if (and
4784 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4785 (and org-agenda-skip-scheduled-if-deadline-is-shown
4786 pastschedp))
4787 (setq mm (assoc pos1 deadline-position-alist)))
4788 (throw :skip nil)))
4789 (setq tags (org-get-tags-at))
4790 (setq head (buffer-substring-no-properties
4791 (point)
4792 (progn (skip-chars-forward "^\r\n") (point))))
4793 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4794 (setq timestr
4795 (concat (substring s (match-beginning 1)) " "))
4796 (setq timestr 'time))
4797 (setq txt (org-format-agenda-item
4798 (if (= diff 0)
4799 (car org-agenda-scheduled-leaders)
4800 (format (nth 1 org-agenda-scheduled-leaders)
4801 (- 1 diff)))
4802 head category tags
4803 (if (not (= diff 0)) nil timestr)
4804 nil nil habitp))))
4805 (when txt
4806 (setq face
4807 (cond
4808 ((and (not habitp) pastschedp)
4809 'org-scheduled-previously)
4810 (todayp 'org-scheduled-today)
4811 (t 'org-scheduled))
4812 habitp (and habitp (org-habit-parse-todo)))
4813 (org-add-props txt props
4814 'undone-face face
4815 'face (if donep 'org-agenda-done face)
4816 'org-marker (org-agenda-new-marker pos)
4817 'org-hd-marker (org-agenda-new-marker pos1)
4818 'type (if pastschedp "past-scheduled" "scheduled")
4819 'date (if pastschedp d2 date)
4820 'priority (if habitp
4821 (org-habit-get-priority habitp)
4822 (+ 94 (- 5 diff) (org-get-priority txt)))
4823 'org-category category
4824 'org-habit-p habitp
4825 'todo-state todo-state)
4826 (push txt ee))))))
4827 (nreverse ee)))
4829 (defun org-agenda-get-blocks ()
4830 "Return the date-range information for agenda display."
4831 (let* ((props (list 'face nil
4832 'org-not-done-regexp org-not-done-regexp
4833 'org-todo-regexp org-todo-regexp
4834 'org-complex-heading-regexp org-complex-heading-regexp
4835 'mouse-face 'highlight
4836 'help-echo
4837 (format "mouse-2 or RET jump to org file %s"
4838 (abbreviate-file-name buffer-file-name))))
4839 (regexp org-tr-regexp)
4840 (d0 (calendar-absolute-from-gregorian date))
4841 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4842 head donep)
4843 (goto-char (point-min))
4844 (while (re-search-forward regexp nil t)
4845 (catch :skip
4846 (org-agenda-skip)
4847 (setq pos (point))
4848 (setq timestr (match-string 0)
4849 s1 (match-string 1)
4850 s2 (match-string 2)
4851 d1 (time-to-days (org-time-string-to-time s1))
4852 d2 (time-to-days (org-time-string-to-time s2)))
4853 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4854 ;; Only allow days between the limits, because the normal
4855 ;; date stamps will catch the limits.
4856 (save-excursion
4857 (setq todo-state (org-get-todo-state))
4858 (setq donep (member todo-state org-done-keywords))
4859 (if (and donep org-agenda-skip-timestamp-if-done)
4860 (throw :skip t))
4861 (setq marker (org-agenda-new-marker (point)))
4862 (setq category (org-get-category))
4863 (if (not (re-search-backward "^\\*+ " nil t))
4864 (setq txt org-agenda-no-heading-message)
4865 (goto-char (match-beginning 0))
4866 (setq hdmarker (org-agenda-new-marker (point)))
4867 (setq tags (org-get-tags-at))
4868 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4869 (setq head (match-string 1))
4870 (let ((remove-re
4871 (if org-agenda-remove-timeranges-from-blocks
4872 (concat
4873 "<" (regexp-quote s1) ".*?>"
4874 "--"
4875 "<" (regexp-quote s2) ".*?>")
4876 nil)))
4877 (setq txt (org-format-agenda-item
4878 (format
4879 (nth (if (= d1 d2) 0 1)
4880 org-agenda-timerange-leaders)
4881 (1+ (- d0 d1)) (1+ (- d2 d1)))
4882 head category tags
4883 timestr nil remove-re))))
4884 (org-add-props txt props
4885 'org-marker marker 'org-hd-marker hdmarker
4886 'type "block" 'date date
4887 'todo-state todo-state
4888 'priority (org-get-priority txt) 'org-category category)
4889 (push txt ee)))
4890 (goto-char pos)))
4891 ;; Sort the entries by expiration date.
4892 (nreverse ee)))
4894 ;;; Agenda presentation and sorting
4896 (defvar org-prefix-has-time nil
4897 "A flag, set by `org-compile-prefix-format'.
4898 The flag is set if the currently compiled format contains a `%t'.")
4899 (defvar org-prefix-has-tag nil
4900 "A flag, set by `org-compile-prefix-format'.
4901 The flag is set if the currently compiled format contains a `%T'.")
4902 (defvar org-prefix-has-effort nil
4903 "A flag, set by `org-compile-prefix-format'.
4904 The flag is set if the currently compiled format contains a `%e'.")
4905 (defvar org-prefix-category-length nil
4906 "Used by `org-compile-prefix-format' to remember the category field width.")
4907 (defvar org-prefix-category-max-length nil
4908 "Used by `org-compile-prefix-format' to remember the category field width.")
4910 (defun org-format-agenda-item (extra txt &optional category tags dotime
4911 noprefix remove-re habitp)
4912 "Format TXT to be inserted into the agenda buffer.
4913 In particular, it adds the prefix and corresponding text properties. EXTRA
4914 must be a string and replaces the `%s' specifier in the prefix format.
4915 CATEGORY (string, symbol or nil) may be used to overrule the default
4916 category taken from local variable or file name. It will replace the `%c'
4917 specifier in the format. DOTIME, when non-nil, indicates that a
4918 time-of-day should be extracted from TXT for sorting of this entry, and for
4919 the `%t' specifier in the format. When DOTIME is a string, this string is
4920 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4921 only the correctly processes TXT should be returned - this is used by
4922 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4923 Any match of REMOVE-RE will be removed from TXT."
4924 (save-match-data
4925 ;; Diary entries sometimes have extra whitespace at the beginning
4926 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4928 ;; Fix the tags part in txt
4929 (setq txt (org-agenda-fix-displayed-tags
4930 txt tags
4931 org-agenda-show-inherited-tags
4932 org-agenda-hide-tags-regexp))
4933 (let* ((category (or category
4934 org-category
4935 (if buffer-file-name
4936 (file-name-sans-extension
4937 (file-name-nondirectory buffer-file-name))
4938 "")))
4939 ;; time, tag, effort are needed for the eval of the prefix format
4940 (tag (if tags (nth (1- (length tags)) tags) ""))
4941 time effort neffort
4942 (ts (if dotime (concat
4943 (if (stringp dotime) dotime "")
4944 (and org-agenda-search-headline-for-time txt))))
4945 (time-of-day (and dotime (org-get-time-of-day ts)))
4946 stamp plain s0 s1 s2 t1 t2 rtn srp l
4947 duration thecategory)
4948 (and (org-mode-p) buffer-file-name
4949 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4950 (when (and dotime time-of-day)
4951 ;; Extract starting and ending time and move them to prefix
4952 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4953 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4954 (setq s0 (match-string 0 ts)
4955 srp (and stamp (match-end 3))
4956 s1 (match-string (if plain 1 2) ts)
4957 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4959 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4960 ;; them, we might want to remove them there to avoid duplication.
4961 ;; The user can turn this off with a variable.
4962 (if (and org-prefix-has-time
4963 org-agenda-remove-times-when-in-prefix (or stamp plain)
4964 (string-match (concat (regexp-quote s0) " *") txt)
4965 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4966 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4967 (= (match-beginning 0) 0)
4969 (setq txt (replace-match "" nil nil txt))))
4970 ;; Normalize the time(s) to 24 hour
4971 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4972 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4973 ;; Compute the duration
4974 (when s1
4975 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4976 (string-to-number (substring s1 3)))
4977 t2 (cond
4978 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4979 (string-to-number (substring s2 3))))
4980 (org-agenda-default-appointment-duration
4981 (+ t1 org-agenda-default-appointment-duration))
4982 (t nil)))
4983 (setq duration (if t2 (- t2 t1)))))
4985 (when (and s1 (not s2) org-agenda-default-appointment-duration
4986 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4987 (let ((m (+ (string-to-number (match-string 2 s1))
4988 (* 60 (string-to-number (match-string 1 s1)))
4989 org-agenda-default-appointment-duration))
4991 (setq h (/ m 60) m (- m (* h 60)))
4992 (setq s2 (format "%02d:%02d" h m))))
4994 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
4995 txt)
4996 ;; Tags are in the string
4997 (if (or (eq org-agenda-remove-tags t)
4998 (and org-agenda-remove-tags
4999 org-prefix-has-tag))
5000 (setq txt (replace-match "" t t txt))
5001 (setq txt (replace-match
5002 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5003 (match-string 2 txt))
5004 t t txt))))
5005 (when (org-mode-p)
5006 (setq effort
5007 (condition-case nil
5008 (org-get-effort
5009 (or (get-text-property 0 'org-hd-marker txt)
5010 (get-text-property 0 'org-marker txt)))
5011 (error nil)))
5012 (when effort
5013 (setq neffort (org-hh:mm-string-to-minutes effort)
5014 effort (setq effort (concat "[" effort "]" )))))
5016 (when remove-re
5017 (while (string-match remove-re txt)
5018 (setq txt (replace-match "" t t txt))))
5020 ;; Create the final string
5021 (if noprefix
5022 (setq rtn txt)
5023 ;; Prepare the variables needed in the eval of the compiled format
5024 (setq time (cond (s2 (concat s1 "-" s2))
5025 (s1 (concat s1 "......"))
5026 (t ""))
5027 extra (or (and (not habitp) extra) "")
5028 category (if (symbolp category) (symbol-name category) category)
5029 thecategory (copy-sequence category))
5030 (if (string-match org-bracket-link-regexp category)
5031 (progn
5032 (setq l (if (match-end 3)
5033 (- (match-end 3) (match-beginning 3))
5034 (- (match-end 1) (match-beginning 1))))
5035 (when (< l (or org-prefix-category-length 0))
5036 (setq category (copy-sequence category))
5037 (org-add-props category nil
5038 'extra-space (make-string
5039 (- org-prefix-category-length l 1) ?\ ))))
5040 (if (and org-prefix-category-max-length
5041 (>= (length category) org-prefix-category-max-length))
5042 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5043 ;; Evaluate the compiled format
5044 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
5046 ;; And finally add the text properties
5047 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5048 (org-add-props rtn nil
5049 'org-category (if thecategory (downcase thecategory) category)
5050 'tags (mapcar 'org-downcase-keep-props tags)
5051 'org-highest-priority org-highest-priority
5052 'org-lowest-priority org-lowest-priority
5053 'prefix-length (- (length rtn) (length txt))
5054 'time-of-day time-of-day
5055 'duration duration
5056 'effort effort
5057 'effort-minutes neffort
5058 'txt txt
5059 'time time
5060 'extra extra
5061 'dotime dotime))))
5063 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5064 "Remove tags string from TXT, and add a modified list of tags.
5065 The modified list may contain inherited tags, and tags matched by
5066 `org-agenda-hide-tags-regexp' will be removed."
5067 (when (or add-inherited hide-re)
5068 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5069 (setq txt (substring txt 0 (match-beginning 0))))
5070 (setq tags
5071 (delq nil
5072 (mapcar (lambda (tg)
5073 (if (or (and hide-re (string-match hide-re tg))
5074 (and (not add-inherited)
5075 (get-text-property 0 'inherited tg)))
5077 tg))
5078 tags)))
5079 (when tags
5080 (let ((have-i (get-text-property 0 'inherited (car tags)))
5082 (setq txt (concat txt " :"
5083 (mapconcat
5084 (lambda (x)
5085 (setq i (get-text-property 0 'inherited x))
5086 (if (and have-i (not i))
5087 (progn
5088 (setq have-i nil)
5089 (concat ":" x))
5091 tags ":")
5092 (if have-i "::" ":"))))))
5093 txt)
5095 (defun org-downcase-keep-props (s)
5096 (let ((props (text-properties-at 0 s)))
5097 (setq s (downcase s))
5098 (add-text-properties 0 (length s) props s)
5101 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5102 (defvar org-agenda-sorting-strategy-selected nil)
5104 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5105 (catch 'exit
5106 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5107 ((and todayp (member 'today (car org-agenda-time-grid))))
5108 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5109 ((member 'weekly (car org-agenda-time-grid)))
5110 (t (throw 'exit list)))
5111 (let* ((have (delq nil (mapcar
5112 (lambda (x) (get-text-property 1 'time-of-day x))
5113 list)))
5114 (string (nth 1 org-agenda-time-grid))
5115 (gridtimes (nth 2 org-agenda-time-grid))
5116 (req (car org-agenda-time-grid))
5117 (remove (member 'remove-match req))
5118 new time)
5119 (if (and (member 'require-timed req) (not have))
5120 ;; don't show empty grid
5121 (throw 'exit list))
5122 (while (setq time (pop gridtimes))
5123 (unless (and remove (member time have))
5124 (setq time (replace-regexp-in-string " " "0" (format "%4s" time)))
5125 (push (org-format-agenda-item
5126 nil string "" nil
5127 (concat (substring time 0 -2) ":" (substring time -2)))
5128 new)
5129 (put-text-property
5130 1 (length (car new)) 'face 'org-time-grid (car new))))
5131 (if (member 'time-up org-agenda-sorting-strategy-selected)
5132 (append new list)
5133 (append list new)))))
5135 (defun org-compile-prefix-format (key)
5136 "Compile the prefix format into a Lisp form that can be evaluated.
5137 The resulting form is returned and stored in the variable
5138 `org-prefix-format-compiled'."
5139 (setq org-prefix-has-time nil org-prefix-has-tag nil
5140 org-prefix-category-length nil org-prefix-has-effort nil)
5141 (let ((s (cond
5142 ((stringp org-agenda-prefix-format)
5143 org-agenda-prefix-format)
5144 ((assq key org-agenda-prefix-format)
5145 (cdr (assq key org-agenda-prefix-format)))
5146 (t " %-12:c%?-12t% s")))
5147 (start 0)
5148 varform vars var e c f opt)
5149 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
5150 s start)
5151 (setq var (cdr (assoc (match-string 4 s)
5152 '(("c" . category) ("t" . time) ("s" . extra)
5153 ("T" . tag) ("e" . effort))))
5154 c (or (match-string 3 s) "")
5155 opt (match-beginning 1)
5156 start (1+ (match-beginning 0)))
5157 (if (equal var 'time) (setq org-prefix-has-time t))
5158 (if (equal var 'tag) (setq org-prefix-has-tag t))
5159 (if (equal var 'effort) (setq org-prefix-has-effort t))
5160 (setq f (concat "%" (match-string 2 s) "s"))
5161 (when (equal var 'category)
5162 (setq org-prefix-category-length
5163 (floor (abs (string-to-number (match-string 2 s)))))
5164 (setq org-prefix-category-max-length
5165 (let ((x (match-string 2 s)))
5166 (save-match-data
5167 (if (string-match "\\.[0-9]+" x)
5168 (string-to-number (substring (match-string 0 x) 1)))))))
5169 (if opt
5170 (setq varform
5171 `(if (equal "" ,var)
5173 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5174 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
5175 (setq s (replace-match "%s" t nil s))
5176 (push varform vars))
5177 (setq vars (nreverse vars))
5178 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5180 (defun org-set-sorting-strategy (key)
5181 (if (symbolp (car org-agenda-sorting-strategy))
5182 ;; the old format
5183 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5184 (setq org-agenda-sorting-strategy-selected
5185 (or (cdr (assq key org-agenda-sorting-strategy))
5186 (cdr (assq 'agenda org-agenda-sorting-strategy))
5187 '(time-up category-keep priority-down)))))
5189 (defun org-get-time-of-day (s &optional string mod24)
5190 "Check string S for a time of day.
5191 If found, return it as a military time number between 0 and 2400.
5192 If not found, return nil.
5193 The optional STRING argument forces conversion into a 5 character wide string
5194 HH:MM."
5195 (save-match-data
5196 (when
5197 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5198 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5199 (let* ((h (string-to-number (match-string 1 s)))
5200 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5201 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5202 (am-p (equal ampm "am"))
5203 (h1 (cond ((not ampm) h)
5204 ((= h 12) (if am-p 0 12))
5205 (t (+ h (if am-p 0 12)))))
5206 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5207 (mod h1 24) h1))
5208 (t0 (+ (* 100 h2) m))
5209 (t1 (concat (if (>= h1 24) "+" " ")
5210 (if (and org-agenda-time-leading-zero
5211 (< t0 1000)) "0" "")
5212 (if (< t0 100) "0" "")
5213 (if (< t0 10) "0" "")
5214 (int-to-string t0))))
5215 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5217 (defvar org-agenda-before-sorting-filter-function nil
5218 "Function to be applied to agenda items prior to sorting.
5219 Prior to sorting also means just before they are inserted into the agenda.
5221 To aid sorting, you may revisit the original entries and add more text
5222 properties which will later be used by the sorting functions.
5224 The function should take a string argument, an agenda line.
5225 It has access to the text properties in that line, which contain among
5226 other things, the property `org-hd-marker' that points to the entry
5227 where the line comes from. Note that not all lines going into the agenda
5228 have this property, only most.
5230 The function should return the modified string. It is probably best
5231 to ONLY change text properties.
5233 You can also use this function as a filter, by returning nil for lines
5234 you don't want to have in the agenda at all. For this application, you
5235 could bind the variable in the options section of a custom command.")
5237 (defun org-finalize-agenda-entries (list &optional nosort)
5238 "Sort and concatenate the agenda items."
5239 (setq list (mapcar 'org-agenda-highlight-todo list))
5240 (if nosort
5241 list
5242 (when org-agenda-before-sorting-filter-function
5243 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5244 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5246 (defun org-agenda-highlight-todo (x)
5247 (let ((org-done-keywords org-done-keywords-for-agenda)
5248 (case-fold-search nil)
5249 re pl)
5250 (if (eq x 'line)
5251 (save-excursion
5252 (beginning-of-line 1)
5253 (setq re (org-get-at-bol 'org-todo-regexp))
5254 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
5255 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5256 (add-text-properties (match-beginning 0) (match-end 1)
5257 (list 'face (org-get-todo-face 1)))
5258 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5259 (delete-region (match-beginning 1) (1- (match-end 0)))
5260 (goto-char (match-beginning 1))
5261 (insert (format org-agenda-todo-keyword-format s)))))
5262 (setq re (concat (get-text-property 0 'org-todo-regexp x))
5263 pl (get-text-property 0 'prefix-length x))
5264 (when (and re
5265 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5266 x (or pl 0)) pl))
5267 (add-text-properties
5268 (or (match-end 1) (match-end 0)) (match-end 0)
5269 (list 'face (org-get-todo-face (match-string 2 x)))
5271 (when (match-end 1)
5272 (setq x (concat (substring x 0 (match-end 1))
5273 (format org-agenda-todo-keyword-format
5274 (match-string 2 x))
5275 (org-add-props " " (text-properties-at 0 x))
5276 (substring x (match-end 3))))))
5277 x)))
5279 (defsubst org-cmp-priority (a b)
5280 "Compare the priorities of string A and B."
5281 (let ((pa (or (get-text-property 1 'priority a) 0))
5282 (pb (or (get-text-property 1 'priority b) 0)))
5283 (cond ((> pa pb) +1)
5284 ((< pa pb) -1)
5285 (t nil))))
5287 (defsubst org-cmp-effort (a b)
5288 "Compare the priorities of string A and B."
5289 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5290 (ea (or (get-text-property 1 'effort-minutes a) def))
5291 (eb (or (get-text-property 1 'effort-minutes b) def)))
5292 (cond ((> ea eb) +1)
5293 ((< ea eb) -1)
5294 (t nil))))
5296 (defsubst org-cmp-category (a b)
5297 "Compare the string values of categories of strings A and B."
5298 (let ((ca (or (get-text-property 1 'org-category a) ""))
5299 (cb (or (get-text-property 1 'org-category b) "")))
5300 (cond ((string-lessp ca cb) -1)
5301 ((string-lessp cb ca) +1)
5302 (t nil))))
5304 (defsubst org-cmp-todo-state (a b)
5305 "Compare the todo states of strings A and B."
5306 (let* ((ma (or (get-text-property 1 'org-marker a)
5307 (get-text-property 1 'org-hd-marker a)))
5308 (mb (or (get-text-property 1 'org-marker b)
5309 (get-text-property 1 'org-hd-marker b)))
5310 (fa (and ma (marker-buffer ma)))
5311 (fb (and mb (marker-buffer mb)))
5312 (todo-kwds
5313 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5314 (and fb (with-current-buffer fb org-todo-keywords-1))))
5315 (ta (or (get-text-property 1 'todo-state a) ""))
5316 (tb (or (get-text-property 1 'todo-state b) ""))
5317 (la (- (length (member ta todo-kwds))))
5318 (lb (- (length (member tb todo-kwds))))
5319 (donepa (member ta org-done-keywords-for-agenda))
5320 (donepb (member tb org-done-keywords-for-agenda)))
5321 (cond ((and donepa (not donepb)) -1)
5322 ((and (not donepa) donepb) +1)
5323 ((< la lb) -1)
5324 ((< lb la) +1)
5325 (t nil))))
5327 (defsubst org-cmp-alpha (a b)
5328 "Compare the headlines, alphabetically."
5329 (let* ((pla (get-text-property 0 'prefix-length a))
5330 (plb (get-text-property 0 'prefix-length b))
5331 (ta (and pla (substring a pla)))
5332 (tb (and plb (substring b plb))))
5333 (when pla
5334 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5335 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5336 (setq ta (substring ta (match-end 0))))
5337 (setq ta (downcase ta)))
5338 (when plb
5339 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5340 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5341 (setq tb (substring tb (match-end 0))))
5342 (setq tb (downcase tb)))
5343 (cond ((not ta) +1)
5344 ((not tb) -1)
5345 ((string-lessp ta tb) -1)
5346 ((string-lessp tb ta) +1)
5347 (t nil))))
5349 (defsubst org-cmp-tag (a b)
5350 "Compare the string values of the first tags of A and B."
5351 (let ((ta (car (last (get-text-property 1 'tags a))))
5352 (tb (car (last (get-text-property 1 'tags b)))))
5353 (cond ((not ta) +1)
5354 ((not tb) -1)
5355 ((string-lessp ta tb) -1)
5356 ((string-lessp tb ta) +1)
5357 (t nil))))
5359 (defsubst org-cmp-time (a b)
5360 "Compare the time-of-day values of strings A and B."
5361 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5362 (ta (or (get-text-property 1 'time-of-day a) def))
5363 (tb (or (get-text-property 1 'time-of-day b) def)))
5364 (cond ((< ta tb) -1)
5365 ((< tb ta) +1)
5366 (t nil))))
5368 (defsubst org-cmp-habit-p (a b)
5369 "Compare the todo states of strings A and B."
5370 (let ((ha (get-text-property 1 'org-habit-p a))
5371 (hb (get-text-property 1 'org-habit-p b)))
5372 (cond ((and ha (not hb)) -1)
5373 ((and (not ha) hb) +1)
5374 (t nil))))
5376 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5378 (defun org-entries-lessp (a b)
5379 "Predicate for sorting agenda entries."
5380 ;; The following variables will be used when the form is evaluated.
5381 ;; So even though the compiler complains, keep them.
5382 (let* ((ss org-agenda-sorting-strategy-selected)
5383 (time-up (and (org-em 'time-up 'time-down ss)
5384 (org-cmp-time a b)))
5385 (time-down (if time-up (- time-up) nil))
5386 (priority-up (and (org-em 'priority-up 'priority-down ss)
5387 (org-cmp-priority a b)))
5388 (priority-down (if priority-up (- priority-up) nil))
5389 (effort-up (and (org-em 'effort-up 'effort-down ss)
5390 (org-cmp-effort a b)))
5391 (effort-down (if effort-up (- effort-up) nil))
5392 (category-up (and (or (org-em 'category-up 'category-down ss)
5393 (memq 'category-keep ss))
5394 (org-cmp-category a b)))
5395 (category-down (if category-up (- category-up) nil))
5396 (category-keep (if category-up +1 nil))
5397 (tag-up (and (org-em 'tag-up 'tag-down ss)
5398 (org-cmp-tag a b)))
5399 (tag-down (if tag-up (- tag-up) nil))
5400 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5401 (org-cmp-todo-state a b)))
5402 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5403 (habit-up (and (org-em 'habit-up 'habit-down ss)
5404 (org-cmp-habit-p a b)))
5405 (habit-down (if habit-up (- habit-up) nil))
5406 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5407 (org-cmp-alpha a b)))
5408 (alpha-down (if alpha-up (- alpha-up) nil))
5409 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5410 user-defined-up user-defined-down)
5411 (if (and need-user-cmp org-agenda-cmp-user-defined
5412 (functionp org-agenda-cmp-user-defined))
5413 (setq user-defined-up
5414 (funcall org-agenda-cmp-user-defined a b)
5415 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5416 (cdr (assoc
5417 (eval (cons 'or org-agenda-sorting-strategy-selected))
5418 '((-1 . t) (1 . nil) (nil . nil))))))
5420 ;;; Agenda restriction lock
5422 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5423 "Overlay to mark the headline to which agenda commands are restricted.")
5424 (overlay-put org-agenda-restriction-lock-overlay
5425 'face 'org-agenda-restriction-lock)
5426 (overlay-put org-agenda-restriction-lock-overlay
5427 'help-echo "Agendas are currently limited to this subtree.")
5428 (org-detach-overlay org-agenda-restriction-lock-overlay)
5430 (defun org-agenda-set-restriction-lock (&optional type)
5431 "Set restriction lock for agenda, to current subtree or file.
5432 Restriction will be the file if TYPE is `file', or if type is the
5433 universal prefix '(4), or if the cursor is before the first headline
5434 in the file. Otherwise, restriction will be to the current subtree."
5435 (interactive "P")
5436 (and (equal type '(4)) (setq type 'file))
5437 (setq type (cond
5438 (type type)
5439 ((org-at-heading-p) 'subtree)
5440 ((condition-case nil (org-back-to-heading t) (error nil))
5441 'subtree)
5442 (t 'file)))
5443 (if (eq type 'subtree)
5444 (progn
5445 (setq org-agenda-restrict t)
5446 (setq org-agenda-overriding-restriction 'subtree)
5447 (put 'org-agenda-files 'org-restrict
5448 (list (buffer-file-name (buffer-base-buffer))))
5449 (org-back-to-heading t)
5450 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5451 (move-marker org-agenda-restrict-begin (point))
5452 (move-marker org-agenda-restrict-end
5453 (save-excursion (org-end-of-subtree t)))
5454 (message "Locking agenda restriction to subtree"))
5455 (put 'org-agenda-files 'org-restrict
5456 (list (buffer-file-name (buffer-base-buffer))))
5457 (setq org-agenda-restrict nil)
5458 (setq org-agenda-overriding-restriction 'file)
5459 (move-marker org-agenda-restrict-begin nil)
5460 (move-marker org-agenda-restrict-end nil)
5461 (message "Locking agenda restriction to file"))
5462 (setq current-prefix-arg nil)
5463 (org-agenda-maybe-redo))
5465 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5466 "Remove the agenda restriction lock."
5467 (interactive "P")
5468 (org-detach-overlay org-agenda-restriction-lock-overlay)
5469 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5470 (setq org-agenda-overriding-restriction nil)
5471 (setq org-agenda-restrict nil)
5472 (put 'org-agenda-files 'org-restrict nil)
5473 (move-marker org-agenda-restrict-begin nil)
5474 (move-marker org-agenda-restrict-end nil)
5475 (setq current-prefix-arg nil)
5476 (message "Agenda restriction lock removed")
5477 (or noupdate (org-agenda-maybe-redo)))
5479 (defun org-agenda-maybe-redo ()
5480 "If there is any window showing the agenda view, update it."
5481 (let ((w (get-buffer-window org-agenda-buffer-name t))
5482 (w0 (selected-window)))
5483 (when w
5484 (select-window w)
5485 (org-agenda-redo)
5486 (select-window w0)
5487 (if org-agenda-overriding-restriction
5488 (message "Agenda view shifted to new %s restriction"
5489 org-agenda-overriding-restriction)
5490 (message "Agenda restriction lock removed")))))
5492 ;;; Agenda commands
5494 (defun org-agenda-check-type (error &rest types)
5495 "Check if agenda buffer is of allowed type.
5496 If ERROR is non-nil, throw an error, otherwise just return nil."
5497 (if (memq org-agenda-type types)
5499 (if error
5500 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5501 nil)))
5503 (defun org-agenda-quit ()
5504 "Exit agenda by removing the window or the buffer."
5505 (interactive)
5506 (if org-agenda-columns-active
5507 (org-columns-quit)
5508 (let ((buf (current-buffer)))
5509 (if (eq org-agenda-window-setup 'other-frame)
5510 (progn
5511 (kill-buffer buf)
5512 (org-agenda-reset-markers)
5513 (org-columns-remove-overlays)
5514 (setq org-agenda-archives-mode nil)
5515 (delete-frame))
5516 (and (not (eq org-agenda-window-setup 'current-window))
5517 (not (one-window-p))
5518 (delete-window))
5519 (kill-buffer buf)
5520 (org-agenda-reset-markers)
5521 (org-columns-remove-overlays)
5522 (setq org-agenda-archives-mode nil)))
5523 ;; Maybe restore the pre-agenda window configuration.
5524 (and org-agenda-restore-windows-after-quit
5525 (not (eq org-agenda-window-setup 'other-frame))
5526 org-pre-agenda-window-conf
5527 (set-window-configuration org-pre-agenda-window-conf))))
5529 (defun org-agenda-exit ()
5530 "Exit agenda by removing the window or the buffer.
5531 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5532 Org-mode buffers visited directly by the user will not be touched."
5533 (interactive)
5534 (org-release-buffers org-agenda-new-buffers)
5535 (setq org-agenda-new-buffers nil)
5536 (org-agenda-quit))
5538 (defun org-agenda-execute (arg)
5539 "Execute another agenda command, keeping same window.
5540 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
5541 in the agenda."
5542 (interactive "P")
5543 (let ((org-agenda-window-setup 'current-window))
5544 (org-agenda arg)))
5546 (defun org-agenda-redo ()
5547 "Rebuild Agenda.
5548 When this is the global TODO list, a prefix argument will be interpreted."
5549 (interactive)
5550 (let* ((org-agenda-keep-modes t)
5551 (filter org-agenda-filter)
5552 (preset (get 'org-agenda-filter :preset-filter))
5553 (cols org-agenda-columns-active)
5554 (line (org-current-line))
5555 (window-line (- line (org-current-line (window-start))))
5556 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5557 (put 'org-agenda-filter :preset-filter nil)
5558 (and cols (org-columns-quit))
5559 (message "Rebuilding agenda buffer...")
5560 (org-let lprops '(eval org-agenda-redo-command))
5561 (setq org-agenda-undo-list nil
5562 org-agenda-pending-undo-list nil)
5563 (message "Rebuilding agenda buffer...done")
5564 (put 'org-agenda-filter :preset-filter preset)
5565 (and (or filter preset) (org-agenda-filter-apply filter))
5566 (and cols (interactive-p) (org-agenda-columns))
5567 (org-goto-line line)
5568 (recenter window-line)))
5571 (defvar org-global-tags-completion-table nil)
5572 (defvar org-agenda-filter-form nil)
5573 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5574 "Keep only those lines in the agenda buffer that have a specific tag.
5575 The tag is selected with its fast selection letter, as configured.
5576 With prefix argument STRIP, remove all lines that do have the tag.
5577 A lisp caller can specify CHAR. NARROW means that the new tag should be
5578 used to narrow the search - the interactive user can also press `-' or `+'
5579 to switch to narrowing."
5580 (interactive "P")
5581 (let* ((alist org-tag-alist-for-agenda)
5582 (tag-chars (mapconcat
5583 (lambda (x) (if (and (not (symbolp (car x)))
5584 (cdr x))
5585 (char-to-string (cdr x))
5586 ""))
5587 alist ""))
5588 (efforts (org-split-string
5589 (or (cdr (assoc (concat org-effort-property "_ALL")
5590 org-global-properties))
5591 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5592 (effort-op org-agenda-filter-effort-default-operator)
5593 (effort-prompt "")
5594 (inhibit-read-only t)
5595 (current org-agenda-filter)
5596 a n tag)
5597 (unless char
5598 (message
5599 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5600 (if narrow "Narrow" "Filter") tag-chars
5601 (if org-agenda-auto-exclude-function "[RET], " ""))
5602 (setq char (read-char)))
5603 (when (member char '(?+ ?-))
5604 ;; Narrowing down
5605 (cond ((equal char ?-) (setq strip t narrow t))
5606 ((equal char ?+) (setq strip nil narrow t)))
5607 (message
5608 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5609 (setq char (read-char)))
5610 (when (member char '(?< ?> ?= ??))
5611 ;; An effort operator
5612 (setq effort-op (char-to-string char))
5613 (setq alist nil) ; to make sure it will be interpreted as effort.
5614 (unless (equal char ??)
5615 (loop for i from 0 to 9 do
5616 (setq effort-prompt
5617 (concat
5618 effort-prompt " ["
5619 (if (= i 9) "0" (int-to-string (1+ i)))
5620 "]" (nth i efforts))))
5621 (message "Effort%s: %s " effort-op effort-prompt)
5622 (setq char (read-char))
5623 (when (or (< char ?0) (> char ?9))
5624 (error "Need 1-9,0 to select effort" ))))
5625 (when (equal char ?\t)
5626 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5627 (org-set-local 'org-global-tags-completion-table
5628 (org-global-tags-completion-table)))
5629 (let ((completion-ignore-case t))
5630 (setq tag (org-icompleting-read
5631 "Tag: " org-global-tags-completion-table))))
5632 (cond
5633 ((equal char ?\r)
5634 (org-agenda-filter-by-tag-show-all)
5635 (when org-agenda-auto-exclude-function
5636 (setq org-agenda-filter '())
5637 (dolist (tag (org-agenda-get-represented-tags))
5638 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5639 (if modifier
5640 (push modifier org-agenda-filter))))
5641 (if (not (null org-agenda-filter))
5642 (org-agenda-filter-apply org-agenda-filter))))
5643 ((equal char ?/)
5644 (org-agenda-filter-by-tag-show-all)
5645 (when (get 'org-agenda-filter :preset-filter)
5646 (org-agenda-filter-apply org-agenda-filter)))
5647 ((or (equal char ?\ )
5648 (setq a (rassoc char alist))
5649 (and (>= char ?0) (<= char ?9)
5650 (setq n (if (= char ?0) 9 (- char ?0 1))
5651 tag (concat effort-op (nth n efforts))
5652 a (cons tag nil)))
5653 (and (= char ??)
5654 (setq tag "?eff")
5655 a (cons tag nil))
5656 (and tag (setq a (cons tag nil))))
5657 (org-agenda-filter-by-tag-show-all)
5658 (setq tag (car a))
5659 (setq org-agenda-filter
5660 (cons (concat (if strip "-" "+") tag)
5661 (if narrow current nil)))
5662 (org-agenda-filter-apply org-agenda-filter))
5663 (t (error "Invalid tag selection character %c" char)))))
5665 (defun org-agenda-get-represented-tags ()
5666 "Get a list of all tags currently represented in the agenda."
5667 (let (p tags)
5668 (save-excursion
5669 (goto-char (point-min))
5670 (while (setq p (next-single-property-change (point) 'tags))
5671 (goto-char p)
5672 (mapc (lambda (x) (add-to-list 'tags x))
5673 (get-text-property (point) 'tags))))
5674 tags))
5676 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5677 "Refine the current filter. See `org-agenda-filter-by-tag."
5678 (interactive "P")
5679 (org-agenda-filter-by-tag strip char 'refine))
5681 (defun org-agenda-filter-make-matcher ()
5682 "Create the form that tests a line for the agenda filter."
5683 (let (f f1)
5684 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5685 org-agenda-filter))
5686 (if (member x '("-" "+"))
5687 (setq f1 (if (equal x "-") 'tags '(not tags)))
5688 (if (string-match "[<=>?]" x)
5689 (setq f1 (org-agenda-filter-effort-form x))
5690 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5691 (if (equal (string-to-char x) ?-)
5692 (setq f1 (list 'not f1))))
5693 (push f1 f))
5694 (cons 'and (nreverse f))))
5696 (defun org-agenda-filter-effort-form (e)
5697 "Return the form to compare the effort of the current line with what E says.
5698 E looks like \"+<2:25\"."
5699 (let (op)
5700 (setq e (substring e 1))
5701 (setq op (string-to-char e) e (substring e 1))
5702 (setq op (cond ((equal op ?<) '<=)
5703 ((equal op ?>) '>=)
5704 ((equal op ??) op)
5705 (t '=)))
5706 (list 'org-agenda-compare-effort (list 'quote op)
5707 (org-hh:mm-string-to-minutes e))))
5709 (defun org-agenda-compare-effort (op value)
5710 "Compare the effort of the current line with VALUE, using OP.
5711 If the line does not have an effort defined, return nil."
5712 (let ((eff (org-get-at-bol 'effort-minutes)))
5713 (if (equal op ??)
5714 (not eff)
5715 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5716 value))))
5718 (defun org-agenda-filter-apply (filter)
5719 "Set FILTER as the new agenda filter and apply it."
5720 (let (tags)
5721 (setq org-agenda-filter filter
5722 org-agenda-filter-form (org-agenda-filter-make-matcher))
5723 (org-agenda-set-mode-name)
5724 (save-excursion
5725 (goto-char (point-min))
5726 (while (not (eobp))
5727 (if (org-get-at-bol 'org-marker)
5728 (progn
5729 (setq tags (org-get-at-bol 'tags)) ; used in eval
5730 (if (not (eval org-agenda-filter-form))
5731 (org-agenda-filter-by-tag-hide-line))
5732 (beginning-of-line 2))
5733 (beginning-of-line 2))))))
5735 (defun org-agenda-filter-by-tag-hide-line ()
5736 (let (ov)
5737 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
5738 (point-at-eol)))
5739 (overlay-put ov 'invisible t)
5740 (overlay-put ov 'type 'tags-filter)
5741 (push ov org-agenda-filter-overlays)))
5743 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5744 (setq pos (or pos (point)))
5745 (save-excursion
5746 (dolist (ov (overlays-at pos))
5747 (when (and (overlay-get ov 'invisible)
5748 (eq (overlay-get ov 'type) 'tags-filter))
5749 (goto-char pos)
5750 (if (< (overlay-start ov) (point-at-eol))
5751 (move-overlay ov (point-at-eol)
5752 (overlay-end ov)))))))
5754 (defun org-agenda-filter-by-tag-show-all ()
5755 (mapc 'delete-overlay org-agenda-filter-overlays)
5756 (setq org-agenda-filter-overlays nil)
5757 (setq org-agenda-filter nil)
5758 (setq org-agenda-filter-form nil)
5759 (org-agenda-set-mode-name))
5761 (defun org-agenda-manipulate-query-add ()
5762 "Manipulate the query by adding a search term with positive selection.
5763 Positive selection means the term must be matched for selection of an entry."
5764 (interactive)
5765 (org-agenda-manipulate-query ?\[))
5766 (defun org-agenda-manipulate-query-subtract ()
5767 "Manipulate the query by adding a search term with negative selection.
5768 Negative selection means term must not be matched for selection of an entry."
5769 (interactive)
5770 (org-agenda-manipulate-query ?\]))
5771 (defun org-agenda-manipulate-query-add-re ()
5772 "Manipulate the query by adding a search regexp with positive selection.
5773 Positive selection means the regexp must match for selection of an entry."
5774 (interactive)
5775 (org-agenda-manipulate-query ?\{))
5776 (defun org-agenda-manipulate-query-subtract-re ()
5777 "Manipulate the query by adding a search regexp with negative selection.
5778 Negative selection means regexp must not match for selection of an entry."
5779 (interactive)
5780 (org-agenda-manipulate-query ?\}))
5781 (defun org-agenda-manipulate-query (char)
5782 (cond
5783 ((memq org-agenda-type '(timeline agenda))
5784 (let ((org-agenda-include-inactive-timestamps t))
5785 (org-agenda-redo))
5786 (message "Display now includes inactive timestamps as well"))
5787 ((eq org-agenda-type 'search)
5788 (org-add-to-string
5789 'org-agenda-query-string
5790 (if org-agenda-last-search-view-search-was-boolean
5791 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5792 (?\{ . " +{}") (?\} . " -{}"))))
5793 " "))
5794 (setq org-agenda-redo-command
5795 (list 'org-search-view
5796 org-todo-only
5797 org-agenda-query-string
5798 (+ (length org-agenda-query-string)
5799 (if (member char '(?\{ ?\})) 0 1))))
5800 (set-register org-agenda-query-register org-agenda-query-string)
5801 (org-agenda-redo))
5802 (t (error "Cannot manipulate query for %s-type agenda buffers"
5803 org-agenda-type))))
5805 (defun org-add-to-string (var string)
5806 (set var (concat (symbol-value var) string)))
5808 (defun org-agenda-goto-date (date)
5809 "Jump to DATE in agenda."
5810 (interactive (list (org-read-date)))
5811 (org-agenda-list nil date))
5813 (defun org-agenda-goto-today ()
5814 "Go to today."
5815 (interactive)
5816 (org-agenda-check-type t 'timeline 'agenda)
5817 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5818 (cond
5819 (tdpos (goto-char tdpos))
5820 ((eq org-agenda-type 'agenda)
5821 (let* ((sd (time-to-days
5822 (time-subtract (current-time)
5823 (list 0 (* 3600 org-extend-today-until) 0))))
5824 (comp (org-agenda-compute-time-span sd org-agenda-span))
5825 (org-agenda-overriding-arguments org-agenda-last-arguments))
5826 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5827 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5828 (org-agenda-redo)
5829 (org-agenda-find-same-or-today-or-agenda)))
5830 (t (error "Cannot find today")))))
5832 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5833 (goto-char
5834 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5835 (text-property-any (point-min) (point-max) 'org-today t)
5836 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5837 (point-min))))
5839 (defun org-agenda-later (arg)
5840 "Go forward in time by thee current span.
5841 With prefix ARG, go forward that many times the current span."
5842 (interactive "p")
5843 (org-agenda-check-type t 'agenda)
5844 (let* ((span org-agenda-span)
5845 (sd org-starting-day)
5846 (greg (calendar-gregorian-from-absolute sd))
5847 (cnt (org-get-at-bol 'org-day-cnt))
5848 greg2 nd)
5849 (cond
5850 ((eq span 'day)
5851 (setq sd (+ arg sd) nd 1))
5852 ((eq span 'week)
5853 (setq sd (+ (* 7 arg) sd) nd 7))
5854 ((eq span 'month)
5855 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5856 sd (calendar-absolute-from-gregorian greg2))
5857 (setcar greg2 (1+ (car greg2)))
5858 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5859 ((eq span 'year)
5860 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5861 sd (calendar-absolute-from-gregorian greg2))
5862 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5863 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5864 (let ((org-agenda-overriding-arguments
5865 (list (car org-agenda-last-arguments) sd nd t)))
5866 (org-agenda-redo)
5867 (org-agenda-find-same-or-today-or-agenda cnt))))
5869 (defun org-agenda-earlier (arg)
5870 "Go backward in time by the current span.
5871 With prefix ARG, go backward that many times the current span."
5872 (interactive "p")
5873 (org-agenda-later (- arg)))
5875 (defun org-agenda-view-mode-dispatch ()
5876 "Call one of the view mode commands."
5877 (interactive)
5878 (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
5879 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
5880 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
5881 (let ((a (read-char-exclusive)))
5882 (case a
5883 (?d (call-interactively 'org-agenda-day-view))
5884 (?w (call-interactively 'org-agenda-week-view))
5885 (?m (call-interactively 'org-agenda-month-view))
5886 (?y (call-interactively 'org-agenda-year-view))
5887 (?l (call-interactively 'org-agenda-log-mode))
5888 (?L (org-agenda-log-mode '(4)))
5889 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5890 (?a (call-interactively 'org-agenda-archives-mode))
5891 (?A (org-agenda-archives-mode 'files))
5892 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5893 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5894 (?G (call-interactively 'org-agenda-toggle-time-grid))
5895 (?D (call-interactively 'org-agenda-toggle-diary))
5896 (?\! (call-interactively 'org-agenda-toggle-deadlines))
5897 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5898 (org-agenda-check-type t 'timeline 'agenda)
5899 (org-agenda-redo))
5900 (message "Display now includes inactive timestamps as well"))
5901 (?q (message "Abort"))
5902 (otherwise (error "Invalid key" )))))
5904 (defun org-agenda-day-view (&optional day-of-year)
5905 "Switch to daily view for agenda.
5906 With argument DAY-OF-YEAR, switch to that day of the year."
5907 (interactive "P")
5908 (setq org-agenda-ndays 1)
5909 (org-agenda-change-time-span 'day day-of-year))
5910 (defun org-agenda-week-view (&optional iso-week)
5911 "Switch to daily view for agenda.
5912 With argument ISO-WEEK, switch to the corresponding ISO week.
5913 If ISO-WEEK has more then 2 digits, only the last two encode the
5914 week. Any digits before this encode a year. So 200712 means
5915 week 12 of year 2007. Years in the range 1938-2037 can also be
5916 written as 2-digit years."
5917 (interactive "P")
5918 (setq org-agenda-ndays 7)
5919 (org-agenda-change-time-span 'week iso-week))
5920 (defun org-agenda-month-view (&optional month)
5921 "Switch to monthly view for agenda.
5922 With argument MONTH, switch to that month."
5923 (interactive "P")
5924 (org-agenda-change-time-span 'month month))
5925 (defun org-agenda-year-view (&optional year)
5926 "Switch to yearly view for agenda.
5927 With argument YEAR, switch to that year.
5928 If MONTH has more then 2 digits, only the last two encode the
5929 month. Any digits before this encode a year. So 200712 means
5930 December year 2007. Years in the range 1938-2037 can also be
5931 written as 2-digit years."
5932 (interactive "P")
5933 (when year
5934 (setq year (org-small-year-to-year year)))
5935 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5936 (org-agenda-change-time-span 'year year)
5937 (error "Abort")))
5939 (defun org-agenda-change-time-span (span &optional n)
5940 "Change the agenda view to SPAN.
5941 SPAN may be `day', `week', `month', `year'."
5942 (org-agenda-check-type t 'agenda)
5943 (if (and (not n) (equal org-agenda-span span))
5944 (error "Viewing span is already \"%s\"" span))
5945 (let* ((sd (or (org-get-at-bol 'day)
5946 org-starting-day))
5947 (computed (org-agenda-compute-time-span sd span n))
5948 (org-agenda-overriding-arguments
5949 (list (car org-agenda-last-arguments)
5950 (car computed) (cdr computed) t)))
5951 (org-agenda-redo)
5952 (org-agenda-find-same-or-today-or-agenda))
5953 (org-agenda-set-mode-name)
5954 (message "Switched to %s view" span))
5956 (defun org-agenda-compute-time-span (sd span &optional n)
5957 "Compute starting date and number of days for agenda.
5958 SPAN may be `day', `week', `month', `year'. The return value
5959 is a cons cell with the starting date and the number of days,
5960 so that the date SD will be in that range."
5961 (let* ((greg (calendar-gregorian-from-absolute sd))
5962 (dg (nth 1 greg))
5963 (mg (car greg))
5964 (yg (nth 2 greg))
5965 nd w1 y1 m1 thisweek)
5966 (cond
5967 ((eq span 'day)
5968 (when n
5969 (setq sd (+ (calendar-absolute-from-gregorian
5970 (list mg 1 yg))
5971 n -1)))
5972 (setq nd 1))
5973 ((eq span 'week)
5974 (let* ((nt (calendar-day-of-week
5975 (calendar-gregorian-from-absolute sd)))
5976 (d (if org-agenda-start-on-weekday
5977 (- nt org-agenda-start-on-weekday)
5978 0)))
5979 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5980 (when n
5981 (require 'cal-iso)
5982 (setq thisweek (car (calendar-iso-from-absolute sd)))
5983 (when (> n 99)
5984 (setq y1 (org-small-year-to-year (/ n 100))
5985 n (mod n 100)))
5986 (setq sd
5987 (calendar-absolute-from-iso
5988 (list n 1
5989 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5990 (setq nd 7)))
5991 ((eq span 'month)
5992 (when (and n (> n 99))
5993 (setq y1 (org-small-year-to-year (/ n 100))
5994 n (mod n 100)))
5995 (setq sd (calendar-absolute-from-gregorian
5996 (list (or n mg) 1 (or y1 yg)))
5997 nd (- (calendar-absolute-from-gregorian
5998 (list (1+ (or n mg)) 1 (or y1 yg)))
5999 sd)))
6000 ((eq span 'year)
6001 (setq sd (calendar-absolute-from-gregorian
6002 (list 1 1 (or n yg)))
6003 nd (- (calendar-absolute-from-gregorian
6004 (list 1 1 (1+ (or n yg))))
6005 sd))))
6006 (cons sd nd)))
6008 (defun org-agenda-next-date-line (&optional arg)
6009 "Jump to the next line indicating a date in agenda buffer."
6010 (interactive "p")
6011 (org-agenda-check-type t 'agenda 'timeline)
6012 (beginning-of-line 1)
6013 ;; This does not work if user makes date format that starts with a blank
6014 (if (looking-at "^\\S-") (forward-char 1))
6015 (if (not (re-search-forward "^\\S-" nil t arg))
6016 (progn
6017 (backward-char 1)
6018 (error "No next date after this line in this buffer")))
6019 (goto-char (match-beginning 0)))
6021 (defun org-agenda-previous-date-line (&optional arg)
6022 "Jump to the previous line indicating a date in agenda buffer."
6023 (interactive "p")
6024 (org-agenda-check-type t 'agenda 'timeline)
6025 (beginning-of-line 1)
6026 (if (not (re-search-backward "^\\S-" nil t arg))
6027 (error "No previous date before this line in this buffer")))
6029 ;; Initialize the highlight
6030 (defvar org-hl (make-overlay 1 1))
6031 (overlay-put org-hl 'face 'highlight)
6033 (defun org-highlight (begin end &optional buffer)
6034 "Highlight a region with overlay."
6035 (move-overlay org-hl begin end (or buffer (current-buffer))))
6037 (defun org-unhighlight ()
6038 "Detach overlay INDEX."
6039 (org-detach-overlay org-hl))
6041 ;; FIXME this is currently not used.
6042 (defun org-highlight-until-next-command (beg end &optional buffer)
6043 "Move the highlight overlay to BEG/END, remove it before the next command."
6044 (org-highlight beg end buffer)
6045 (add-hook 'pre-command-hook 'org-unhighlight-once))
6046 (defun org-unhighlight-once ()
6047 "Remove the highlight from its position, and this function from the hook."
6048 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6049 (org-unhighlight))
6051 (defun org-agenda-follow-mode ()
6052 "Toggle follow mode in an agenda buffer."
6053 (interactive)
6054 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6055 (org-agenda-set-mode-name)
6056 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6057 (org-agenda-show))
6058 (message "Follow mode is %s"
6059 (if org-agenda-follow-mode "on" "off")))
6061 (defun org-agenda-entry-text-mode (&optional arg)
6062 "Toggle entry text mode in an agenda buffer."
6063 (interactive "P")
6064 (setq org-agenda-entry-text-mode (or (integerp arg)
6065 (not org-agenda-entry-text-mode)))
6066 (org-agenda-entry-text-hide)
6067 (and org-agenda-entry-text-mode
6068 (let ((org-agenda-entry-text-maxlines
6069 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6070 (org-agenda-entry-text-show)))
6071 (org-agenda-set-mode-name)
6072 (message "Entry text mode is %s. Maximum number of lines is %d"
6073 (if org-agenda-entry-text-mode "on" "off")
6074 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6076 (defun org-agenda-clockreport-mode ()
6077 "Toggle clocktable mode in an agenda buffer."
6078 (interactive)
6079 (org-agenda-check-type t 'agenda)
6080 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
6081 (org-agenda-set-mode-name)
6082 (org-agenda-redo)
6083 (message "Clocktable mode is %s"
6084 (if org-agenda-clockreport-mode "on" "off")))
6086 (defun org-agenda-log-mode (&optional special)
6087 "Toggle log mode in an agenda buffer.
6088 With argument SPECIAL, show all possible log items, not only the ones
6089 configured in `org-agenda-log-mode-items'.
6090 With a double `C-u' prefix arg, show *only* log items, nothing else."
6091 (interactive "P")
6092 (org-agenda-check-type t 'agenda 'timeline)
6093 (setq org-agenda-show-log
6094 (if (equal special '(16))
6095 'only
6096 (if special '(closed clock state)
6097 (not org-agenda-show-log))))
6098 (org-agenda-set-mode-name)
6099 (org-agenda-redo)
6100 (message "Log mode is %s"
6101 (if org-agenda-show-log "on" "off")))
6103 (defun org-agenda-archives-mode (&optional with-files)
6104 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6105 When called with a prefix argument, include all archive files as well."
6106 (interactive "P")
6107 (setq org-agenda-archives-mode
6108 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6109 (org-agenda-set-mode-name)
6110 (org-agenda-redo)
6111 (message
6112 "%s"
6113 (cond
6114 ((eq org-agenda-archives-mode nil)
6115 "No archives are included")
6116 ((eq org-agenda-archives-mode 'trees)
6117 (format "Trees with :%s: tag are included" org-archive-tag))
6118 ((eq org-agenda-archives-mode t)
6119 (format "Trees with :%s: tag and all active archive files are included"
6120 org-archive-tag)))))
6122 (defun org-agenda-toggle-diary ()
6123 "Toggle diary inclusion in an agenda buffer."
6124 (interactive)
6125 (org-agenda-check-type t 'agenda)
6126 (setq org-agenda-include-diary (not org-agenda-include-diary))
6127 (org-agenda-redo)
6128 (org-agenda-set-mode-name)
6129 (message "Diary inclusion turned %s"
6130 (if org-agenda-include-diary "on" "off")))
6132 (defun org-agenda-toggle-deadlines ()
6133 "Toggle diary inclusion in an agenda buffer."
6134 (interactive)
6135 (org-agenda-check-type t 'agenda)
6136 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6137 (org-agenda-redo)
6138 (org-agenda-set-mode-name)
6139 (message "Deadlines inclusion turned %s"
6140 (if org-agenda-include-deadlines "on" "off")))
6142 (defun org-agenda-toggle-time-grid ()
6143 "Toggle time grid in an agenda buffer."
6144 (interactive)
6145 (org-agenda-check-type t 'agenda)
6146 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6147 (org-agenda-redo)
6148 (org-agenda-set-mode-name)
6149 (message "Time-grid turned %s"
6150 (if org-agenda-use-time-grid "on" "off")))
6152 (defun org-agenda-set-mode-name ()
6153 "Set the mode name to indicate all the small mode settings."
6154 (setq mode-name
6155 (concat "Org-Agenda"
6156 (if (get 'org-agenda-files 'org-restrict) " []" "")
6157 (if (equal org-agenda-ndays 1) " Day" "")
6158 (if (equal org-agenda-ndays 7) " Week" "")
6159 (if org-agenda-follow-mode " Follow" "")
6160 (if org-agenda-entry-text-mode " ETxt" "")
6161 (if org-agenda-include-diary " Diary" "")
6162 (if org-agenda-include-deadlines " Ddl" "")
6163 (if org-agenda-use-time-grid " Grid" "")
6164 (if (and (boundp 'org-habit-show-habits)
6165 org-habit-show-habits) " Habit" "")
6166 (if (consp org-agenda-show-log) " LogAll"
6167 (if org-agenda-show-log " Log" ""))
6168 (if (or org-agenda-filter (get 'org-agenda-filter
6169 :preset-filter))
6170 (concat " {" (mapconcat
6171 'identity
6172 (append (get 'org-agenda-filter
6173 :preset-filter)
6174 org-agenda-filter) "") "}")
6176 (if org-agenda-archives-mode
6177 (if (eq org-agenda-archives-mode t)
6178 " Archives"
6179 (format " :%s:" org-archive-tag))
6181 (if org-agenda-clockreport-mode " Clock" "")))
6182 (force-mode-line-update))
6184 (defun org-agenda-post-command-hook ()
6185 (setq org-agenda-type
6186 (or (get-text-property (point) 'org-agenda-type)
6187 (get-text-property (max (point-min) (1- (point)))
6188 'org-agenda-type))))
6190 (defun org-agenda-next-line ()
6191 "Move cursor to the next line, and show if follow mode is active."
6192 (interactive)
6193 (call-interactively 'next-line)
6194 (org-agenda-do-context-action))
6196 (defun org-agenda-previous-line ()
6197 "Move cursor to the previous line, and show if follow-mode is active."
6199 (interactive)
6200 (call-interactively 'previous-line)
6201 (org-agenda-do-context-action))
6203 (defun org-agenda-do-context-action ()
6204 "Show outline path and, maybe, follow mode window."
6205 (let ((m (org-get-at-bol 'org-marker)))
6206 (if (and org-agenda-follow-mode m)
6207 (org-agenda-show))
6208 (if (and m org-agenda-show-outline-path)
6209 (org-with-point-at m
6210 (org-display-outline-path t)))))
6212 (defun org-agenda-show-priority ()
6213 "Show the priority of the current item.
6214 This priority is composed of the main priority given with the [#A] cookies,
6215 and by additional input from the age of a schedules or deadline entry."
6216 (interactive)
6217 (let* ((pri (org-get-at-bol 'priority)))
6218 (message "Priority is %d" (if pri pri -1000))))
6220 (defun org-agenda-show-tags ()
6221 "Show the tags applicable to the current item."
6222 (interactive)
6223 (let* ((tags (org-get-at-bol 'tags)))
6224 (if tags
6225 (message "Tags are :%s:"
6226 (org-no-properties (mapconcat 'identity tags ":")))
6227 (message "No tags associated with this line"))))
6229 (defun org-agenda-goto (&optional highlight)
6230 "Go to the Org-mode file which contains the item at point."
6231 (interactive)
6232 (let* ((marker (or (org-get-at-bol 'org-marker)
6233 (org-agenda-error)))
6234 (buffer (marker-buffer marker))
6235 (pos (marker-position marker)))
6236 (switch-to-buffer-other-window buffer)
6237 (widen)
6238 (push-mark)
6239 (goto-char pos)
6240 (when (org-mode-p)
6241 (org-show-context 'agenda)
6242 (save-excursion
6243 (and (outline-next-heading)
6244 (org-flag-heading nil)))) ; show the next heading
6245 (recenter (/ (window-height) 2))
6246 (run-hooks 'org-agenda-after-show-hook)
6247 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6249 (defvar org-agenda-after-show-hook nil
6250 "Normal hook run after an item has been shown from the agenda.
6251 Point is in the buffer where the item originated.")
6253 (defun org-agenda-kill ()
6254 "Kill the entry or subtree belonging to the current agenda entry."
6255 (interactive)
6256 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6257 (let* ((marker (or (org-get-at-bol 'org-marker)
6258 (org-agenda-error)))
6259 (buffer (marker-buffer marker))
6260 (pos (marker-position marker))
6261 (type (org-get-at-bol 'type))
6262 dbeg dend (n 0) conf)
6263 (org-with-remote-undo buffer
6264 (with-current-buffer buffer
6265 (save-excursion
6266 (goto-char pos)
6267 (if (and (org-mode-p) (not (member type '("sexp"))))
6268 (setq dbeg (progn (org-back-to-heading t) (point))
6269 dend (org-end-of-subtree t t))
6270 (setq dbeg (point-at-bol)
6271 dend (min (point-max) (1+ (point-at-eol)))))
6272 (goto-char dbeg)
6273 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6274 (setq conf (or (eq t org-agenda-confirm-kill)
6275 (and (numberp org-agenda-confirm-kill)
6276 (> n org-agenda-confirm-kill))))
6277 (and conf
6278 (not (y-or-n-p
6279 (format "Delete entry with %d lines in buffer \"%s\"? "
6280 n (buffer-name buffer))))
6281 (error "Abort"))
6282 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6283 (with-current-buffer buffer (delete-region dbeg dend))
6284 (message "Agenda item and source killed"))))
6286 (defvar org-archive-default-command)
6287 (defun org-agenda-archive-default ()
6288 "Archive the entry or subtree belonging to the current agenda entry."
6289 (interactive)
6290 (require 'org-archive)
6291 (org-agenda-archive-with org-archive-default-command))
6293 (defun org-agenda-archive-default-with-confirmation ()
6294 "Archive the entry or subtree belonging to the current agenda entry."
6295 (interactive)
6296 (require 'org-archive)
6297 (org-agenda-archive-with org-archive-default-command 'confirm))
6299 (defun org-agenda-archive ()
6300 "Archive the entry or subtree belonging to the current agenda entry."
6301 (interactive)
6302 (org-agenda-archive-with 'org-archive-subtree))
6304 (defun org-agenda-archive-to-archive-sibling ()
6305 "Move the entry to the archive sibling."
6306 (interactive)
6307 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6309 (defun org-agenda-archive-with (cmd &optional confirm)
6310 "Move the entry to the archive sibling."
6311 (interactive)
6312 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6313 (let* ((marker (or (org-get-at-bol 'org-marker)
6314 (org-agenda-error)))
6315 (buffer (marker-buffer marker))
6316 (pos (marker-position marker)))
6317 (org-with-remote-undo buffer
6318 (with-current-buffer buffer
6319 (if (org-mode-p)
6320 (if (and confirm
6321 (not (y-or-n-p "Archive this subtree or entry? ")))
6322 (error "Abort")
6323 (save-excursion
6324 (goto-char pos)
6325 (org-remove-subtree-entries-from-agenda)
6326 (org-back-to-heading t)
6327 (funcall cmd)))
6328 (error "Archiving works only in Org-mode files"))))))
6330 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6331 "Remove all lines in the agenda that correspond to a given subtree.
6332 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6333 If this information is not given, the function uses the tree at point."
6334 (let ((buf (or buf (current-buffer))) m p)
6335 (save-excursion
6336 (unless (and beg end)
6337 (org-back-to-heading t)
6338 (setq beg (point))
6339 (org-end-of-subtree t)
6340 (setq end (point)))
6341 (set-buffer (get-buffer org-agenda-buffer-name))
6342 (save-excursion
6343 (goto-char (point-max))
6344 (beginning-of-line 1)
6345 (while (not (bobp))
6346 (when (and (setq m (org-get-at-bol 'org-marker))
6347 (equal buf (marker-buffer m))
6348 (setq p (marker-position m))
6349 (>= p beg)
6350 (< p end))
6351 (let ((inhibit-read-only t))
6352 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6353 (beginning-of-line 0))))))
6355 (defun org-agenda-refile (&optional goto rfloc no-update)
6356 "Refile the item at point."
6357 (interactive "P")
6358 (if (equal goto '(16))
6359 (org-refile-goto-last-stored)
6360 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6361 (org-agenda-error)))
6362 (buffer (marker-buffer marker))
6363 (pos (marker-position marker))
6364 (rfloc (or rfloc
6365 (org-refile-get-location
6366 (if goto "Goto: " "Refile to: ") buffer
6367 org-refile-allow-creating-parent-nodes))))
6368 (with-current-buffer buffer
6369 (save-excursion
6370 (save-restriction
6371 (widen)
6372 (goto-char marker)
6373 (org-remove-subtree-entries-from-agenda)
6374 (org-refile goto buffer rfloc)))))
6375 (unless no-update (org-agenda-redo))))
6377 (defun org-agenda-open-link (&optional arg)
6378 "Follow the link in the current line, if any.
6379 This looks for a link in the displayed line in the agenda. It also looks
6380 at the text of the entry itself."
6381 (interactive "P")
6382 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6383 (org-get-at-bol 'org-marker)))
6384 (buffer (and marker (marker-buffer marker)))
6385 (prefix (buffer-substring
6386 (point-at-bol)
6387 (+ (point-at-bol)
6388 (or (org-get-at-bol 'prefix-length) 0)))))
6389 (cond
6390 (buffer
6391 (with-current-buffer buffer
6392 (save-excursion
6393 (save-restriction
6394 (widen)
6395 (goto-char marker)
6396 (org-offer-links-in-entry arg prefix)))))
6397 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6398 (save-excursion
6399 (beginning-of-line 1)
6400 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6401 (org-open-link-from-string (match-string 1)))
6402 (t (error "No link to open here")))))
6404 (defun org-agenda-copy-local-variable (var)
6405 "Get a variable from a referenced buffer and install it here."
6406 (let ((m (org-get-at-bol 'org-marker)))
6407 (when (and m (buffer-live-p (marker-buffer m)))
6408 (org-set-local var (with-current-buffer (marker-buffer m)
6409 (symbol-value var))))))
6411 (defun org-agenda-switch-to (&optional delete-other-windows)
6412 "Go to the Org-mode file which contains the item at point."
6413 (interactive)
6414 (if (and org-return-follows-link
6415 (not (org-get-at-bol 'org-marker))
6416 (org-in-regexp org-bracket-link-regexp))
6417 (org-open-link-from-string (match-string 0))
6418 (let* ((marker (or (org-get-at-bol 'org-marker)
6419 (org-agenda-error)))
6420 (buffer (marker-buffer marker))
6421 (pos (marker-position marker)))
6422 (switch-to-buffer buffer)
6423 (and delete-other-windows (delete-other-windows))
6424 (widen)
6425 (goto-char pos)
6426 (when (org-mode-p)
6427 (org-show-context 'agenda)
6428 (save-excursion
6429 (and (outline-next-heading)
6430 (org-flag-heading nil))))))) ; show the next heading
6432 (defun org-agenda-goto-mouse (ev)
6433 "Go to the Org-mode file which contains the item at the mouse click."
6434 (interactive "e")
6435 (mouse-set-point ev)
6436 (org-agenda-goto))
6438 (defun org-agenda-show (&optional full-entry)
6439 "Display the Org-mode file which contains the item at point.
6440 With prefix argument FULL-ENTRY, make the entire entry visible
6441 if it was hidden in the outline."
6442 (interactive "P")
6443 (let ((win (selected-window)))
6444 (if full-entry
6445 (let ((org-show-entry-below t))
6446 (org-agenda-goto t))
6447 (org-agenda-goto t))
6448 (select-window win)))
6450 (defvar org-agenda-show-window nil)
6451 (defun org-agenda-show-and-scroll-up ()
6452 "Display the Org-mode file which contains the item at point.
6453 When called repeatedly, scroll the window that is displaying the buffer."
6454 (interactive)
6455 (let ((win (selected-window)))
6456 (if (and (window-live-p org-agenda-show-window)
6457 (eq this-command last-command))
6458 (progn
6459 (select-window org-agenda-show-window)
6460 (ignore-errors (scroll-up)))
6461 (org-agenda-goto t)
6462 (show-subtree)
6463 (setq org-agenda-show-window (selected-window)))
6464 (select-window win)))
6466 (defun org-agenda-show-scroll-down ()
6467 "Scroll down the window showing the agenda."
6468 (interactive)
6469 (let ((win (selected-window)))
6470 (when (window-live-p org-agenda-show-window)
6471 (select-window org-agenda-show-window)
6472 (ignore-errors (scroll-down))
6473 (select-window win))))
6475 (defun org-agenda-show-1 (&optional more)
6476 "Display the Org-mode file which contains the item at point.
6477 The prefix arg selects the amount of information to display:
6479 0 hide the subtree
6480 1 just show the entry according to defaults.
6481 2 show the children view
6482 3 show the subtree view
6483 4 show the entire subtree and any LOGBOOK drawers
6484 5 show the entire subtree and any drawers
6485 With prefix argument FULL-ENTRY, make the entire entry visible
6486 if it was hidden in the outline."
6487 (interactive "p")
6488 (let ((win (selected-window)))
6489 (org-agenda-goto t)
6490 (org-recenter-heading 1)
6491 (cond
6492 ((= more 0)
6493 (hide-subtree)
6494 (save-excursion
6495 (org-back-to-heading)
6496 (run-hook-with-args 'org-cycle-hook 'folded))
6497 (message "Remote: FOLDED"))
6498 ((and (interactive-p) (= more 1))
6499 (message "Remote: show with default settings"))
6500 ((= more 2)
6501 (show-entry)
6502 (show-children)
6503 (save-excursion
6504 (org-back-to-heading)
6505 (run-hook-with-args 'org-cycle-hook 'children))
6506 (message "Remote: CHILDREN"))
6507 ((= more 3)
6508 (show-subtree)
6509 (save-excursion
6510 (org-back-to-heading)
6511 (run-hook-with-args 'org-cycle-hook 'subtree))
6512 (message "Remote: SUBTREE"))
6513 ((= more 4)
6514 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6515 (org-drawer-regexp
6516 (concat "^[ \t]*:\\("
6517 (mapconcat 'regexp-quote org-drawers "\\|")
6518 "\\):[ \t]*$")))
6519 (show-subtree)
6520 (save-excursion
6521 (org-back-to-heading)
6522 (org-cycle-hide-drawers 'subtree)))
6523 (message "Remote: SUBTREE AND LOGBOOK"))
6524 ((> more 4)
6525 (show-subtree)
6526 (message "Remote: SUBTREE AND ALL DRAWERS")))
6527 (select-window win)))
6529 (defun org-recenter-heading (n)
6530 (save-excursion
6531 (org-back-to-heading)
6532 (recenter n)))
6534 (defvar org-agenda-cycle-counter nil)
6535 (defun org-agenda-cycle-show (&optional n)
6536 "Show the current entry in another window, with default settings.
6537 Default settings are taken from `org-show-hierarchy-above' and siblings.
6538 When use repeatedly in immediate succession, the remote entry will cycle
6539 through visibility
6541 children -> subtree -> folded
6543 When called with a numeric prefix arg, that arg will be passed through to
6544 `org-agenda-show-1'. For the interpretation of that argument, see the
6545 docstring of `org-agenda-show-1'."
6546 (interactive "P")
6547 (if (integerp n)
6548 (setq org-agenda-cycle-counter n)
6549 (if (not (eq last-command this-command))
6550 (setq org-agenda-cycle-counter 1)
6551 (if (equal org-agenda-cycle-counter 0)
6552 (setq org-agenda-cycle-counter 2)
6553 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6554 (if (> org-agenda-cycle-counter 3)
6555 (setq org-agenda-cycle-counter 0)))))
6556 (org-agenda-show-1 org-agenda-cycle-counter))
6558 (defun org-agenda-recenter (arg)
6559 "Display the Org-mode file which contains the item at point and recenter."
6560 (interactive "P")
6561 (let ((win (selected-window)))
6562 (org-agenda-goto t)
6563 (recenter arg)
6564 (select-window win)))
6566 (defun org-agenda-show-mouse (ev)
6567 "Display the Org-mode file which contains the item at the mouse click."
6568 (interactive "e")
6569 (mouse-set-point ev)
6570 (org-agenda-show))
6572 (defun org-agenda-check-no-diary ()
6573 "Check if the entry is a diary link and abort if yes."
6574 (if (org-get-at-bol 'org-agenda-diary-link)
6575 (org-agenda-error)))
6577 (defun org-agenda-error ()
6578 (error "Command not allowed in this line"))
6580 (defun org-agenda-tree-to-indirect-buffer ()
6581 "Show the subtree corresponding to the current entry in an indirect buffer.
6582 This calls the command `org-tree-to-indirect-buffer' from the original
6583 Org-mode buffer.
6584 With numerical prefix arg ARG, go up to this level and then take that tree.
6585 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
6586 use the dedicated frame)."
6587 (interactive)
6588 (org-agenda-check-no-diary)
6589 (let* ((marker (or (org-get-at-bol 'org-marker)
6590 (org-agenda-error)))
6591 (buffer (marker-buffer marker))
6592 (pos (marker-position marker)))
6593 (with-current-buffer buffer
6594 (save-excursion
6595 (goto-char pos)
6596 (call-interactively 'org-tree-to-indirect-buffer)))))
6598 (defvar org-last-heading-marker (make-marker)
6599 "Marker pointing to the headline that last changed its TODO state
6600 by a remote command from the agenda.")
6602 (defun org-agenda-todo-nextset ()
6603 "Switch TODO entry to next sequence."
6604 (interactive)
6605 (org-agenda-todo 'nextset))
6607 (defun org-agenda-todo-previousset ()
6608 "Switch TODO entry to previous sequence."
6609 (interactive)
6610 (org-agenda-todo 'previousset))
6612 (defun org-agenda-todo (&optional arg)
6613 "Cycle TODO state of line at point, also in Org-mode file.
6614 This changes the line at point, all other lines in the agenda referring to
6615 the same tree node, and the headline of the tree node in the Org-mode file."
6616 (interactive "P")
6617 (org-agenda-check-no-diary)
6618 (let* ((col (current-column))
6619 (marker (or (org-get-at-bol 'org-marker)
6620 (org-agenda-error)))
6621 (buffer (marker-buffer marker))
6622 (pos (marker-position marker))
6623 (hdmarker (org-get-at-bol 'org-hd-marker))
6624 (todayp (equal (org-get-at-bol 'day)
6625 (time-to-days (current-time))))
6626 (inhibit-read-only t)
6627 org-agenda-headline-snapshot-before-repeat newhead just-one)
6628 (org-with-remote-undo buffer
6629 (with-current-buffer buffer
6630 (widen)
6631 (goto-char pos)
6632 (org-show-context 'agenda)
6633 (save-excursion
6634 (and (outline-next-heading)
6635 (org-flag-heading nil))) ; show the next heading
6636 (let ((current-prefix-arg arg))
6637 (call-interactively 'org-todo))
6638 (and (bolp) (forward-char 1))
6639 (setq newhead (org-get-heading))
6640 (when (and (org-bound-and-true-p
6641 org-agenda-headline-snapshot-before-repeat)
6642 (not (equal org-agenda-headline-snapshot-before-repeat
6643 newhead))
6644 todayp)
6645 (setq newhead org-agenda-headline-snapshot-before-repeat
6646 just-one t))
6647 (save-excursion
6648 (org-back-to-heading)
6649 (move-marker org-last-heading-marker (point))))
6650 (beginning-of-line 1)
6651 (save-excursion
6652 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6653 (org-move-to-column col))))
6655 (defun org-agenda-add-note (&optional arg)
6656 "Add a time-stamped note to the entry at point."
6657 (interactive "P")
6658 (org-agenda-check-no-diary)
6659 (let* ((marker (or (org-get-at-bol 'org-marker)
6660 (org-agenda-error)))
6661 (buffer (marker-buffer marker))
6662 (pos (marker-position marker))
6663 (hdmarker (org-get-at-bol 'org-hd-marker))
6664 (inhibit-read-only t))
6665 (with-current-buffer buffer
6666 (widen)
6667 (goto-char pos)
6668 (org-show-context 'agenda)
6669 (save-excursion
6670 (and (outline-next-heading)
6671 (org-flag-heading nil))) ; show the next heading
6672 (org-add-note))))
6674 (defun org-agenda-change-all-lines (newhead hdmarker
6675 &optional fixface just-this)
6676 "Change all lines in the agenda buffer which match HDMARKER.
6677 The new content of the line will be NEWHEAD (as modified by
6678 `org-format-agenda-item'). HDMARKER is checked with
6679 `equal' against all `org-hd-marker' text properties in the file.
6680 If FIXFACE is non-nil, the face of each item is modified according to
6681 the new TODO state.
6682 If JUST-THIS is non-nil, change just the current line, not all.
6683 If FORCE-TAGS is non nil, the car of it returns the new tags."
6684 (let* ((inhibit-read-only t)
6685 (line (org-current-line))
6686 (thetags (with-current-buffer (marker-buffer hdmarker)
6687 (save-excursion (save-restriction (widen)
6688 (goto-char hdmarker)
6689 (org-get-tags-at)))))
6690 props m pl undone-face done-face finish new dotime cat tags)
6691 (save-excursion
6692 (goto-char (point-max))
6693 (beginning-of-line 1)
6694 (while (not finish)
6695 (setq finish (bobp))
6696 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6697 (or (not just-this) (= (org-current-line) line))
6698 (equal m hdmarker))
6699 (setq props (text-properties-at (point))
6700 dotime (org-get-at-bol 'dotime)
6701 cat (org-get-at-bol 'org-category)
6702 tags thetags
6703 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6704 pl (org-get-at-bol 'prefix-length)
6705 undone-face (org-get-at-bol 'undone-face)
6706 done-face (org-get-at-bol 'done-face))
6707 (goto-char (+ (point) pl))
6708 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6709 (cond
6710 ((equal new "")
6711 (beginning-of-line 1)
6712 (and (looking-at ".*\n?") (replace-match "")))
6713 ((looking-at ".*")
6714 (replace-match new t t)
6715 (beginning-of-line 1)
6716 (add-text-properties (point-at-bol) (point-at-eol) props)
6717 (when fixface
6718 (add-text-properties
6719 (point-at-bol) (point-at-eol)
6720 (list 'face
6721 (if org-last-todo-state-is-todo
6722 undone-face done-face))))
6723 (org-agenda-highlight-todo 'line)
6724 (beginning-of-line 1))
6725 (t (error "Line update did not work"))))
6726 (beginning-of-line 0)))
6727 (org-finalize-agenda)))
6729 (defun org-agenda-align-tags (&optional line)
6730 "Align all tags in agenda items to `org-agenda-tags-column'."
6731 (let ((inhibit-read-only t) l c)
6732 (save-excursion
6733 (goto-char (if line (point-at-bol) (point-min)))
6734 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6735 (if line (point-at-eol) nil) t)
6736 (add-text-properties
6737 (match-beginning 2) (match-end 2)
6738 (list 'face (delq nil (let ((prop (get-text-property
6739 (match-beginning 2) 'face)))
6740 (or (listp prop) (setq prop (list prop)))
6741 (if (memq 'org-tag prop)
6742 prop
6743 (cons 'org-tag prop))))))
6744 (setq l (- (match-end 2) (match-beginning 2))
6745 c (if (< org-agenda-tags-column 0)
6746 (- (abs org-agenda-tags-column) l)
6747 org-agenda-tags-column))
6748 (delete-region (match-beginning 1) (match-end 1))
6749 (goto-char (match-beginning 1))
6750 (insert (org-add-props
6751 (make-string (max 1 (- c (current-column))) ?\ )
6752 (plist-put (copy-sequence (text-properties-at (point)))
6753 'face nil))))
6754 (goto-char (point-min))
6755 (org-font-lock-add-tag-faces (point-max)))))
6757 (defun org-agenda-priority-up ()
6758 "Increase the priority of line at point, also in Org-mode file."
6759 (interactive)
6760 (org-agenda-priority 'up))
6762 (defun org-agenda-priority-down ()
6763 "Decrease the priority of line at point, also in Org-mode file."
6764 (interactive)
6765 (org-agenda-priority 'down))
6767 (defun org-agenda-priority (&optional force-direction)
6768 "Set the priority of line at point, also in Org-mode file.
6769 This changes the line at point, all other lines in the agenda referring to
6770 the same tree node, and the headline of the tree node in the Org-mode file."
6771 (interactive)
6772 (unless org-enable-priority-commands
6773 (error "Priority commands are disabled"))
6774 (org-agenda-check-no-diary)
6775 (let* ((marker (or (org-get-at-bol 'org-marker)
6776 (org-agenda-error)))
6777 (hdmarker (org-get-at-bol 'org-hd-marker))
6778 (buffer (marker-buffer hdmarker))
6779 (pos (marker-position hdmarker))
6780 (inhibit-read-only t)
6781 newhead)
6782 (org-with-remote-undo buffer
6783 (with-current-buffer buffer
6784 (widen)
6785 (goto-char pos)
6786 (org-show-context 'agenda)
6787 (save-excursion
6788 (and (outline-next-heading)
6789 (org-flag-heading nil))) ; show the next heading
6790 (funcall 'org-priority force-direction)
6791 (end-of-line 1)
6792 (setq newhead (org-get-heading)))
6793 (org-agenda-change-all-lines newhead hdmarker)
6794 (beginning-of-line 1))))
6796 ;; FIXME: should fix the tags property of the agenda line.
6797 (defun org-agenda-set-tags (&optional tag onoff)
6798 "Set tags for the current headline."
6799 (interactive)
6800 (org-agenda-check-no-diary)
6801 (if (and (org-region-active-p) (interactive-p))
6802 (call-interactively 'org-change-tag-in-region)
6803 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6804 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6805 (org-agenda-error)))
6806 (buffer (marker-buffer hdmarker))
6807 (pos (marker-position hdmarker))
6808 (inhibit-read-only t)
6809 newhead)
6810 (org-with-remote-undo buffer
6811 (with-current-buffer buffer
6812 (widen)
6813 (goto-char pos)
6814 (save-excursion
6815 (org-show-context 'agenda))
6816 (save-excursion
6817 (and (outline-next-heading)
6818 (org-flag-heading nil))) ; show the next heading
6819 (goto-char pos)
6820 (if tag
6821 (org-toggle-tag tag onoff)
6822 (call-interactively 'org-set-tags))
6823 (end-of-line 1)
6824 (setq newhead (org-get-heading)))
6825 (org-agenda-change-all-lines newhead hdmarker)
6826 (beginning-of-line 1)))))
6828 (defun org-agenda-set-property ()
6829 "Set a property for the current headline."
6830 (interactive)
6831 (org-agenda-check-no-diary)
6832 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6833 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6834 (org-agenda-error)))
6835 (buffer (marker-buffer hdmarker))
6836 (pos (marker-position hdmarker))
6837 (inhibit-read-only t)
6838 newhead)
6839 (org-with-remote-undo buffer
6840 (with-current-buffer buffer
6841 (widen)
6842 (goto-char pos)
6843 (save-excursion
6844 (org-show-context 'agenda))
6845 (save-excursion
6846 (and (outline-next-heading)
6847 (org-flag-heading nil))) ; show the next heading
6848 (goto-char pos)
6849 (call-interactively 'org-set-property)))))
6851 (defun org-agenda-set-effort ()
6852 "Set the effort property for the current headline."
6853 (interactive)
6854 (org-agenda-check-no-diary)
6855 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6856 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6857 (org-agenda-error)))
6858 (buffer (marker-buffer hdmarker))
6859 (pos (marker-position hdmarker))
6860 (inhibit-read-only t)
6861 newhead)
6862 (org-with-remote-undo buffer
6863 (with-current-buffer buffer
6864 (widen)
6865 (goto-char pos)
6866 (save-excursion
6867 (org-show-context 'agenda))
6868 (save-excursion
6869 (and (outline-next-heading)
6870 (org-flag-heading nil))) ; show the next heading
6871 (goto-char pos)
6872 (call-interactively 'org-set-effort)
6873 (end-of-line 1)))))
6875 (defun org-agenda-toggle-archive-tag ()
6876 "Toggle the archive tag for the current entry."
6877 (interactive)
6878 (org-agenda-check-no-diary)
6879 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6880 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6881 (org-agenda-error)))
6882 (buffer (marker-buffer hdmarker))
6883 (pos (marker-position hdmarker))
6884 (inhibit-read-only t)
6885 newhead)
6886 (org-with-remote-undo buffer
6887 (with-current-buffer buffer
6888 (widen)
6889 (goto-char pos)
6890 (org-show-context 'agenda)
6891 (save-excursion
6892 (and (outline-next-heading)
6893 (org-flag-heading nil))) ; show the next heading
6894 (call-interactively 'org-toggle-archive-tag)
6895 (end-of-line 1)
6896 (setq newhead (org-get-heading)))
6897 (org-agenda-change-all-lines newhead hdmarker)
6898 (beginning-of-line 1))))
6900 (defun org-agenda-do-date-later (arg)
6901 (interactive "P")
6902 (cond
6903 ((or (equal arg '(16))
6904 (memq last-command
6905 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6906 (setq this-command 'org-agenda-date-later-minutes)
6907 (org-agenda-date-later-minutes 1))
6908 ((or (equal arg '(4))
6909 (memq last-command
6910 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6911 (setq this-command 'org-agenda-date-later-hours)
6912 (org-agenda-date-later-hours 1))
6914 (org-agenda-date-later (prefix-numeric-value arg)))))
6916 (defun org-agenda-do-date-earlier (arg)
6917 (interactive "P")
6918 (cond
6919 ((or (equal arg '(16))
6920 (memq last-command
6921 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6922 (setq this-command 'org-agenda-date-earlier-minutes)
6923 (org-agenda-date-earlier-minutes 1))
6924 ((or (equal arg '(4))
6925 (memq last-command
6926 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6927 (setq this-command 'org-agenda-date-earlier-hours)
6928 (org-agenda-date-earlier-hours 1))
6930 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6932 (defun org-agenda-date-later (arg &optional what)
6933 "Change the date of this item to one day later."
6934 (interactive "p")
6935 (org-agenda-check-type t 'agenda 'timeline)
6936 (org-agenda-check-no-diary)
6937 (let* ((marker (or (org-get-at-bol 'org-marker)
6938 (org-agenda-error)))
6939 (buffer (marker-buffer marker))
6940 (pos (marker-position marker)))
6941 (org-with-remote-undo buffer
6942 (with-current-buffer buffer
6943 (widen)
6944 (goto-char pos)
6945 (if (not (org-at-timestamp-p))
6946 (error "Cannot find time stamp"))
6947 (org-timestamp-change arg (or what 'day)))
6948 (org-agenda-show-new-time marker org-last-changed-timestamp))
6949 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6951 (defun org-agenda-date-earlier (arg &optional what)
6952 "Change the date of this item to one day earlier."
6953 (interactive "p")
6954 (org-agenda-date-later (- arg) what))
6956 (defun org-agenda-date-later-minutes (arg)
6957 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6958 (interactive "p")
6959 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6960 (org-agenda-date-later arg 'minute))
6962 (defun org-agenda-date-earlier-minutes (arg)
6963 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6964 (interactive "p")
6965 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6966 (org-agenda-date-earlier arg 'minute))
6968 (defun org-agenda-date-later-hours (arg)
6969 "Change the time of this item, in hour steps."
6970 (interactive "p")
6971 (org-agenda-date-later arg 'hour))
6973 (defun org-agenda-date-earlier-hours (arg)
6974 "Change the time of this item, in hour steps."
6975 (interactive "p")
6976 (org-agenda-date-earlier arg 'hour))
6978 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6979 "Show new date stamp via text properties."
6980 ;; We use text properties to make this undoable
6981 (let ((inhibit-read-only t)
6982 (buffer-invisibility-spec))
6983 (setq stamp (concat " " prefix " => " stamp))
6984 (save-excursion
6985 (goto-char (point-max))
6986 (while (not (bobp))
6987 (when (equal marker (org-get-at-bol 'org-marker))
6988 (org-move-to-column (- (window-width) (length stamp)) t)
6989 (org-agenda-fix-tags-filter-overlays-at (point))
6990 (if (featurep 'xemacs)
6991 ;; Use `duplicable' property to trigger undo recording
6992 (let ((ex (make-extent nil nil))
6993 (gl (make-glyph stamp)))
6994 (set-glyph-face gl 'secondary-selection)
6995 (set-extent-properties
6996 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6997 (insert-extent ex (1- (point)) (point-at-eol)))
6998 (add-text-properties
6999 (1- (point)) (point-at-eol)
7000 (list 'display (org-add-props stamp nil
7001 'face 'secondary-selection))))
7002 (beginning-of-line 1))
7003 (beginning-of-line 0)))))
7005 (defun org-agenda-date-prompt (arg)
7006 "Change the date of this item. Date is prompted for, with default today.
7007 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7008 be used to request time specification in the time stamp."
7009 (interactive "P")
7010 (org-agenda-check-type t 'agenda 'timeline)
7011 (org-agenda-check-no-diary)
7012 (let* ((marker (or (org-get-at-bol 'org-marker)
7013 (org-agenda-error)))
7014 (buffer (marker-buffer marker))
7015 (pos (marker-position marker)))
7016 (org-with-remote-undo buffer
7017 (with-current-buffer buffer
7018 (widen)
7019 (goto-char pos)
7020 (if (not (org-at-timestamp-p t))
7021 (error "Cannot find time stamp"))
7022 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7023 (org-agenda-show-new-time marker org-last-changed-timestamp))
7024 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7026 (defun org-agenda-schedule (arg)
7027 "Schedule the item at point.
7028 Arg is passed through to `org-schedule'."
7029 (interactive "P")
7030 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7031 (org-agenda-check-no-diary)
7032 (let* ((marker (or (org-get-at-bol 'org-marker)
7033 (org-agenda-error)))
7034 (type (marker-insertion-type marker))
7035 (buffer (marker-buffer marker))
7036 (pos (marker-position marker))
7037 (org-insert-labeled-timestamps-at-point nil)
7039 (set-marker-insertion-type marker t)
7040 (org-with-remote-undo buffer
7041 (with-current-buffer buffer
7042 (widen)
7043 (goto-char pos)
7044 (setq ts (org-schedule arg)))
7045 (org-agenda-show-new-time marker ts "S"))
7046 (message "Item scheduled for %s" ts)))
7048 (defun org-agenda-deadline (arg)
7049 "Schedule the item at point.
7050 Arg is passed through to `org-deadline'."
7051 (interactive "P")
7052 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7053 (org-agenda-check-no-diary)
7054 (let* ((marker (or (org-get-at-bol 'org-marker)
7055 (org-agenda-error)))
7056 (buffer (marker-buffer marker))
7057 (pos (marker-position marker))
7058 (org-insert-labeled-timestamps-at-point nil)
7060 (org-with-remote-undo buffer
7061 (with-current-buffer buffer
7062 (widen)
7063 (goto-char pos)
7064 (setq ts (org-deadline arg)))
7065 (org-agenda-show-new-time marker ts "D"))
7066 (message "Deadline for this item set to %s" ts)))
7068 (defun org-agenda-action ()
7069 "Select entry for agenda action, or execute an agenda action.
7070 This command prompts for another letter. Valid inputs are:
7072 m Mark the entry at point for an agenda action
7073 s Schedule the marked entry to the date at the cursor
7074 d Set the deadline of the marked entry to the date at the cursor
7075 r Call `org-remember' with cursor date as the default date
7076 c Call `org-capture' with cursor date as the default date
7077 SPC Show marked entry in other window
7078 TAB Visit marked entry in other window
7080 The cursor may be at a date in the calendar, or in the Org agenda."
7081 (interactive)
7082 (let (ans)
7083 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7084 (setq ans (read-char-exclusive))
7085 (cond
7086 ((equal ans ?m)
7087 ;; Mark this entry
7088 (if (eq major-mode 'org-agenda-mode)
7089 (let ((m (or (org-get-at-bol 'org-hd-marker)
7090 (org-get-at-bol 'org-marker))))
7091 (if m
7092 (progn
7093 (move-marker org-agenda-action-marker
7094 (marker-position m) (marker-buffer m))
7095 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7096 (error "Don't know which entry to mark")))
7097 (error "This command works only in the agenda")))
7098 ((equal ans ?s)
7099 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7100 ((equal ans ?d)
7101 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7102 ((equal ans ?r)
7103 (org-agenda-do-action '(org-remember) t))
7104 ((equal ans ?c)
7105 (org-agenda-do-action '(org-capture) t))
7106 ((equal ans ?\ )
7107 (let ((cw (selected-window)))
7108 (org-switch-to-buffer-other-window
7109 (marker-buffer org-agenda-action-marker))
7110 (goto-char org-agenda-action-marker)
7111 (org-show-context 'agenda)
7112 (select-window cw)))
7113 ((equal ans ?\C-i)
7114 (org-switch-to-buffer-other-window
7115 (marker-buffer org-agenda-action-marker))
7116 (goto-char org-agenda-action-marker)
7117 (org-show-context 'agenda))
7118 (t (error "Invalid agenda action %c" ans)))))
7120 (defun org-agenda-do-action (form &optional current-buffer)
7121 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7122 (let ((org-overriding-default-time (org-get-cursor-date)))
7123 (if current-buffer
7124 (eval form)
7125 (if (not (marker-buffer org-agenda-action-marker))
7126 (error "No entry has been selected for agenda action")
7127 (with-current-buffer (marker-buffer org-agenda-action-marker)
7128 (save-excursion
7129 (save-restriction
7130 (widen)
7131 (goto-char org-agenda-action-marker)
7132 (eval form))))))))
7134 (defun org-agenda-clock-in (&optional arg)
7135 "Start the clock on the currently selected item."
7136 (interactive "P")
7137 (org-agenda-check-no-diary)
7138 (if (equal arg '(4))
7139 (org-clock-in arg)
7140 (let* ((marker (or (org-get-at-bol 'org-marker)
7141 (org-agenda-error)))
7142 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7143 marker))
7144 (pos (marker-position marker))
7145 newhead)
7146 (org-with-remote-undo (marker-buffer marker)
7147 (with-current-buffer (marker-buffer marker)
7148 (widen)
7149 (goto-char pos)
7150 (org-show-context 'agenda)
7151 (org-show-entry)
7152 (org-cycle-hide-drawers 'children)
7153 (org-clock-in arg)
7154 (setq newhead (org-get-heading)))
7155 (org-agenda-change-all-lines newhead hdmarker)))))
7157 (defun org-agenda-clock-out ()
7158 "Stop the currently running clock."
7159 (interactive)
7160 (unless (marker-buffer org-clock-marker)
7161 (error "No running clock"))
7162 (let ((marker (make-marker)) newhead)
7163 (org-with-remote-undo (marker-buffer org-clock-marker)
7164 (with-current-buffer (marker-buffer org-clock-marker)
7165 (save-excursion
7166 (save-restriction
7167 (widen)
7168 (goto-char org-clock-marker)
7169 (org-back-to-heading t)
7170 (move-marker marker (point))
7171 (org-clock-out)
7172 (setq newhead (org-get-heading))))))
7173 (org-agenda-change-all-lines newhead marker)
7174 (move-marker marker nil)))
7176 (defun org-agenda-clock-cancel (&optional arg)
7177 "Cancel the currently running clock."
7178 (interactive "P")
7179 (unless (marker-buffer org-clock-marker)
7180 (error "No running clock"))
7181 (org-with-remote-undo (marker-buffer org-clock-marker)
7182 (org-clock-cancel)))
7184 (defun org-agenda-clock-goto ()
7185 "Jump to the currently clocked in task within the agenda.
7186 If the currently clocked in task is not listed in the agenda
7187 buffer, display it in another window."
7188 (interactive)
7189 (let (pos)
7190 (mapc (lambda (o)
7191 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7192 (setq pos (overlay-start o))))
7193 (overlays-in (point-min) (point-max)))
7194 (cond (pos (goto-char pos))
7195 ;; If the currently clocked entry is not in the agenda
7196 ;; buffer, we visit it in another window:
7197 (org-clock-current-task
7198 (org-switch-to-buffer-other-window (org-clock-goto)))
7199 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7201 (defun org-agenda-diary-entry-in-org-file ()
7202 "Make a diary entry in the file `org-agenda-diary-file'."
7203 (let (d1 d2 char (text "") dp1 dp2)
7204 (if (equal (buffer-name) "*Calendar*")
7205 (setq d1 (calendar-cursor-to-date t)
7206 d2 (car calendar-mark-ring))
7207 (setq dp1 (get-text-property (point-at-bol) 'day))
7208 (unless dp1 (error "No date defined in current line"))
7209 (setq d1 (calendar-gregorian-from-absolute dp1)
7210 d2 (and (ignore-errors (mark))
7211 (save-excursion
7212 (goto-char (mark))
7213 (setq dp2 (get-text-property (point-at-bol) 'day)))
7214 (calendar-gregorian-from-absolute dp2))))
7215 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7216 (setq char (read-char-exclusive))
7217 (cond
7218 ((equal char ?d)
7219 (setq text (read-string "Day entry: "))
7220 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7221 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7222 ((equal char ?a)
7223 (setq d1 (list (car d1) (nth 1 d1)
7224 (read-number (format "Reference year [%d]: " (nth 2 d1))
7225 (nth 2 d1))))
7226 (setq text (read-string "Anniversary (use %d to show years): "))
7227 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7228 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7229 ((equal char ?b)
7230 (setq text (read-string "Block entry: "))
7231 (unless (and d1 d2 (not (equal d1 d2)))
7232 (error "No block of days selected"))
7233 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7234 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7235 ((equal char ?j)
7236 (org-switch-to-buffer-other-window
7237 (find-file-noselect org-agenda-diary-file))
7238 (require 'org-datetree)
7239 (org-datetree-find-date-create d1)
7240 (org-reveal t))
7241 (t (error "Invalid selection character `%c'" char)))))
7243 (defcustom org-agenda-insert-diary-strategy 'date-tree
7244 "Where in `org-agenda-diary-file' should new entries be added?
7245 Valid values:
7247 date-tree in the date tree, as child of the date
7248 top-level as top-level entries at the end of the file."
7249 :group 'org-agenda
7250 :type '(choice
7251 (const :tag "in a date tree" date-tree)
7252 (const :tag "as top level at end of file" top-level)))
7254 (defcustom org-agenda-insert-diary-extract-time nil
7255 "Non-nil means extract any time specification from the diary entry."
7256 :group 'org-agenda
7257 :type 'boolean)
7259 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7260 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7261 If TEXT is not empty, it will become the headline of the new entry, and
7262 the resulting entry will not be shown. When TEXT is empty, switch to
7263 `org-agenda-diary-file' and let the user finish the entry there."
7264 (let ((cw (current-window-configuration)))
7265 (org-switch-to-buffer-other-window
7266 (find-file-noselect org-agenda-diary-file))
7267 (widen)
7268 (goto-char (point-min))
7269 (cond
7270 ((eq type 'anniversary)
7271 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7272 (progn
7273 (or (org-on-heading-p t)
7274 (progn
7275 (outline-next-heading)
7276 (insert "* Anniversaries\n\n")
7277 (beginning-of-line -1)))))
7278 (outline-next-heading)
7279 (org-back-over-empty-lines)
7280 (backward-char 1)
7281 (insert "\n")
7282 (require 'diary-lib)
7283 (let ((calendar-date-display-form
7284 (if (if (boundp 'calendar-date-style)
7285 (eq calendar-date-style 'european)
7286 (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
7287 (org-bound-and-true-p european-calendar-style))) ; Emacs 22
7288 '(day " " month " " year)
7289 '(month " " day " " year))))
7291 (insert (format "%%%%(diary-anniversary %s) %s"
7292 (calendar-date-string d1 nil t) text))))
7293 ((eq type 'day)
7294 (let ((org-prefix-has-time t)
7295 (org-agenda-time-leading-zero t)
7296 fmt time time2)
7297 (if org-agenda-insert-diary-extract-time
7298 ;; Use org-format-agenda-item to parse text for a time-range and
7299 ;; remove it. FIXME: This is a hack, we should refactor
7300 ;; that function to make time extraction available separately
7301 (setq fmt (org-format-agenda-item nil text nil nil t)
7302 time (get-text-property 0 'time fmt)
7303 time2 (if (> (length time) 0)
7304 ;; split-string removes trailing ...... if
7305 ;; no end time given. First space
7306 ;; separates time from date.
7307 (concat " " (car (split-string time "\\.")))
7308 nil)
7309 text (get-text-property 0 'txt fmt)))
7310 (if (eq org-agenda-insert-diary-strategy 'top-level)
7311 (org-agenda-insert-diary-as-top-level text)
7312 (require 'org-datetree)
7313 (org-datetree-find-date-create d1)
7314 (org-agenda-insert-diary-make-new-entry text))
7315 (org-insert-time-stamp (org-time-from-absolute
7316 (calendar-absolute-from-gregorian d1))
7317 nil nil nil nil time2))
7318 (end-of-line 0))
7319 ((eq type 'block)
7320 (if (> (calendar-absolute-from-gregorian d1)
7321 (calendar-absolute-from-gregorian d2))
7322 (setq d1 (prog1 d2 (setq d2 d1))))
7323 (if (eq org-agenda-insert-diary-strategy 'top-level)
7324 (org-agenda-insert-diary-as-top-level text)
7325 (require 'org-datetree)
7326 (org-datetree-find-date-create d1)
7327 (org-agenda-insert-diary-make-new-entry text))
7328 (org-insert-time-stamp (org-time-from-absolute
7329 (calendar-absolute-from-gregorian d1)))
7330 (insert "--")
7331 (org-insert-time-stamp (org-time-from-absolute
7332 (calendar-absolute-from-gregorian d2)))
7333 (end-of-line 0)))
7334 (if (string-match "\\S-" text)
7335 (progn
7336 (set-window-configuration cw)
7337 (message "%s entry added to %s"
7338 (capitalize (symbol-name type))
7339 (abbreviate-file-name org-agenda-diary-file)))
7340 (org-reveal t)
7341 (message "Please finish entry here"))))
7343 (defun org-agenda-insert-diary-as-top-level (text)
7344 "Make new entry as a top-level entry at the end of the file.
7345 Add TEXT as headline, and position the cursor in the second line so that
7346 a timestamp can be added there."
7347 (widen)
7348 (goto-char (point-max))
7349 (or (bolp) (insert "\n"))
7350 (insert "* " text "\n")
7351 (if org-adapt-indentation (org-indent-to-column 2)))
7353 (defun org-agenda-insert-diary-make-new-entry (text)
7354 "Make new entry as last child of current entry.
7355 Add TEXT as headline, and position the cursor in the second line so that
7356 a timestamp can be added there."
7357 (let ((org-show-following-heading t)
7358 (org-show-siblings t)
7359 (org-show-hierarchy-above t)
7360 (org-show-entry-below t)
7361 col)
7362 (outline-next-heading)
7363 (org-back-over-empty-lines)
7364 (or (looking-at "[ \t]*$")
7365 (progn (insert "\n") (backward-char 1)))
7366 (org-insert-heading nil t)
7367 (org-do-demote)
7368 (setq col (current-column))
7369 (insert text "\n")
7370 (if org-adapt-indentation (org-indent-to-column col))
7371 (let ((org-show-following-heading t)
7372 (org-show-siblings t)
7373 (org-show-hierarchy-above t)
7374 (org-show-entry-below t))
7375 (org-show-context))))
7377 (defun org-agenda-diary-entry ()
7378 "Make a diary entry, like the `i' command from the calendar.
7379 All the standard commands work: block, weekly etc.
7380 When `org-agenda-diary-file' points to a file,
7381 `org-agenda-diary-entry-in-org-file' is called instead to create
7382 entries in that Org-mode file."
7383 (interactive)
7384 (org-agenda-check-type t 'agenda 'timeline)
7385 (if (not (eq org-agenda-diary-file 'diary-file))
7386 (org-agenda-diary-entry-in-org-file)
7387 (require 'diary-lib)
7388 (let* ((char (progn
7389 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7390 (read-char-exclusive)))
7391 (cmd (cdr (assoc char
7392 '((?d . insert-diary-entry)
7393 (?w . insert-weekly-diary-entry)
7394 (?m . insert-monthly-diary-entry)
7395 (?y . insert-yearly-diary-entry)
7396 (?a . insert-anniversary-diary-entry)
7397 (?b . insert-block-diary-entry)
7398 (?c . insert-cyclic-diary-entry)))))
7399 (oldf (symbol-function 'calendar-cursor-to-date))
7400 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7401 (point (point))
7402 (mark (or (mark t) (point))))
7403 (unless cmd
7404 (error "No command associated with <%c>" char))
7405 (unless (and (get-text-property point 'day)
7406 (or (not (equal ?b char))
7407 (get-text-property mark 'day)))
7408 (error "Don't know which date to use for diary entry"))
7409 ;; We implement this by hacking the `calendar-cursor-to-date' function
7410 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7411 (let ((calendar-mark-ring
7412 (list (calendar-gregorian-from-absolute
7413 (or (get-text-property mark 'day)
7414 (get-text-property point 'day))))))
7415 (unwind-protect
7416 (progn
7417 (fset 'calendar-cursor-to-date
7418 (lambda (&optional error dummy)
7419 (calendar-gregorian-from-absolute
7420 (get-text-property point 'day))))
7421 (call-interactively cmd))
7422 (fset 'calendar-cursor-to-date oldf))))))
7424 (defun org-agenda-execute-calendar-command (cmd)
7425 "Execute a calendar command from the agenda, with the date associated to
7426 the cursor position."
7427 (org-agenda-check-type t 'agenda 'timeline)
7428 (require 'diary-lib)
7429 (unless (get-text-property (point) 'day)
7430 (error "Don't know which date to use for calendar command"))
7431 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7432 (point (point))
7433 (date (calendar-gregorian-from-absolute
7434 (get-text-property point 'day)))
7435 ;; the following 2 vars are needed in the calendar
7436 (displayed-month (car date))
7437 (displayed-year (nth 2 date)))
7438 (unwind-protect
7439 (progn
7440 (fset 'calendar-cursor-to-date
7441 (lambda (&optional error dummy)
7442 (calendar-gregorian-from-absolute
7443 (get-text-property point 'day))))
7444 (call-interactively cmd))
7445 (fset 'calendar-cursor-to-date oldf))))
7447 (defun org-agenda-phases-of-moon ()
7448 "Display the phases of the moon for the 3 months around the cursor date."
7449 (interactive)
7450 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7452 (defun org-agenda-holidays ()
7453 "Display the holidays for the 3 months around the cursor date."
7454 (interactive)
7455 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7457 (defvar calendar-longitude)
7458 (defvar calendar-latitude)
7459 (defvar calendar-location-name)
7461 (defun org-agenda-sunrise-sunset (arg)
7462 "Display sunrise and sunset for the cursor date.
7463 Latitude and longitude can be specified with the variables
7464 `calendar-latitude' and `calendar-longitude'. When called with prefix
7465 argument, latitude and longitude will be prompted for."
7466 (interactive "P")
7467 (require 'solar)
7468 (let ((calendar-longitude (if arg nil calendar-longitude))
7469 (calendar-latitude (if arg nil calendar-latitude))
7470 (calendar-location-name
7471 (if arg "the given coordinates" calendar-location-name)))
7472 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7474 (defun org-agenda-goto-calendar ()
7475 "Open the Emacs calendar with the date at the cursor."
7476 (interactive)
7477 (org-agenda-check-type t 'agenda 'timeline)
7478 (let* ((day (or (get-text-property (point) 'day)
7479 (error "Don't know which date to open in calendar")))
7480 (date (calendar-gregorian-from-absolute day))
7481 (calendar-move-hook nil)
7482 (calendar-view-holidays-initially-flag nil)
7483 (calendar-view-diary-initially-flag nil))
7484 (calendar)
7485 (calendar-goto-date date)))
7487 ;;;###autoload
7488 (defun org-calendar-goto-agenda ()
7489 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7490 This is a command that has to be installed in `calendar-mode-map'."
7491 (interactive)
7492 (org-agenda-list nil (calendar-absolute-from-gregorian
7493 (calendar-cursor-to-date))
7494 nil))
7496 (defun org-agenda-convert-date ()
7497 (interactive)
7498 (org-agenda-check-type t 'agenda 'timeline)
7499 (let ((day (get-text-property (point) 'day))
7500 date s)
7501 (unless day
7502 (error "Don't know which date to convert"))
7503 (setq date (calendar-gregorian-from-absolute day))
7504 (setq s (concat
7505 "Gregorian: " (calendar-date-string date) "\n"
7506 "ISO: " (calendar-iso-date-string date) "\n"
7507 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7508 "Julian: " (calendar-julian-date-string date) "\n"
7509 "Astron. JD: " (calendar-astro-date-string date)
7510 " (Julian date number at noon UTC)\n"
7511 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7512 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7513 "French: " (calendar-french-date-string date) "\n"
7514 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7515 "Mayan: " (calendar-mayan-date-string date) "\n"
7516 "Coptic: " (calendar-coptic-date-string date) "\n"
7517 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7518 "Persian: " (calendar-persian-date-string date) "\n"
7519 "Chinese: " (calendar-chinese-date-string date) "\n"))
7520 (with-output-to-temp-buffer "*Dates*"
7521 (princ s))
7522 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7524 ;;; Bulk commands
7526 (defvar org-agenda-bulk-marked-entries nil
7527 "List of markers that refer to marked entries in the agenda.")
7529 (defun org-agenda-bulk-marked-p ()
7530 (eq (get-char-property (point-at-bol) 'type)
7531 'org-marked-entry-overlay))
7533 (defun org-agenda-bulk-mark ()
7534 "Mark the entry at point for future bulk action."
7535 (interactive)
7536 (org-agenda-check-no-diary)
7537 (let* ((m (org-get-at-bol 'org-hd-marker))
7539 (unless (org-agenda-bulk-marked-p)
7540 (unless m (error "Nothing to mark at point"))
7541 (push m org-agenda-bulk-marked-entries)
7542 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7543 (org-overlay-display ov "> "
7544 (org-get-todo-face "TODO")
7545 'evaporate)
7546 (overlay-put ov 'type 'org-marked-entry-overlay))
7547 (beginning-of-line 2)
7548 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7549 (beginning-of-line 2))
7550 (message "%d entries marked for bulk action"
7551 (length org-agenda-bulk-marked-entries))))
7553 (defun org-agenda-bulk-unmark ()
7554 "Unmark the entry at point for future bulk action."
7555 (interactive)
7556 (when (org-agenda-bulk-marked-p)
7557 (org-agenda-bulk-remove-overlays
7558 (point-at-bol) (+ 2 (point-at-bol)))
7559 (setq org-agenda-bulk-marked-entries
7560 (delete (org-get-at-bol 'org-hd-marker)
7561 org-agenda-bulk-marked-entries)))
7562 (beginning-of-line 2)
7563 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7564 (beginning-of-line 2))
7565 (message "%d entries marked for bulk action"
7566 (length org-agenda-bulk-marked-entries)))
7568 (defun org-agenda-bulk-toggle ()
7569 "Toggle marking the entry at point for bulk action."
7570 (interactive)
7571 (if (org-agenda-bulk-marked-p)
7572 (org-agenda-bulk-unmark)
7573 (org-agenda-bulk-mark)))
7575 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7576 "Remove the mark overlays between BEG and END in the agenda buffer.
7577 BEG and END default to the buffer limits.
7579 This only removes the overlays, it does not remove the markers
7580 from the list in `org-agenda-bulk-marked-entries'."
7581 (interactive)
7582 (mapc (lambda (ov)
7583 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7584 (delete-overlay ov)))
7585 (overlays-in (or beg (point-min)) (or end (point-max)))))
7587 (defun org-agenda-bulk-remove-all-marks ()
7588 "Remove all marks in the agenda buffer.
7589 This will remove the markers, and the overlays."
7590 (interactive)
7591 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7592 (setq org-agenda-bulk-marked-entries nil)
7593 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7595 (defun org-agenda-bulk-action (&optional arg)
7596 "Execute an remote-editing action on all marked entries.
7597 The prefix arg is passed through to the command if possible."
7598 (interactive "P")
7599 (unless org-agenda-bulk-marked-entries
7600 (error "No entries are marked"))
7601 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
7602 (let* ((action (read-char-exclusive))
7603 (org-log-refile (if org-log-refile 'time nil))
7604 (entries (reverse org-agenda-bulk-marked-entries))
7605 redo-at-end
7606 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7607 (cond
7608 ((equal action ?$)
7609 (setq cmd '(org-agenda-archive)))
7611 ((equal action ?A)
7612 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7614 ((member action '(?r ?w))
7615 (setq rfloc (org-refile-get-location
7616 "Refile to: "
7617 (marker-buffer (car org-agenda-bulk-marked-entries))
7618 org-refile-allow-creating-parent-nodes))
7619 (if (nth 3 rfloc)
7620 (setcar (nthcdr 3 rfloc)
7621 (move-marker (make-marker) (nth 3 rfloc)
7622 (or (get-file-buffer (nth 1 rfloc))
7623 (find-buffer-visiting (nth 1 rfloc))
7624 (error "This should not happen")))))
7626 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
7627 redo-at-end t))
7629 ((equal action ?t)
7630 (setq state (org-icompleting-read
7631 "Todo state: "
7632 (with-current-buffer (marker-buffer (car entries))
7633 (mapcar 'list org-todo-keywords-1))))
7634 (setq cmd `(let ((org-inhibit-blocking t)
7635 (org-inhibit-logging 'note))
7636 (org-agenda-todo ,state))))
7638 ((memq action '(?- ?+))
7639 (setq tag (org-icompleting-read
7640 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7641 (with-current-buffer (marker-buffer (car entries))
7642 (delq nil
7643 (mapcar (lambda (x)
7644 (if (stringp (car x)) x)) org-tag-alist)))))
7645 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
7647 ((memq action '(?s ?d))
7648 (let* ((date (unless arg
7649 (org-read-date
7650 nil nil nil
7651 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
7652 (ans (if arg nil org-read-date-final-answer))
7653 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
7654 (setq cmd `(let* ((bound (fboundp 'read-string))
7655 (old (and bound (symbol-function 'read-string))))
7656 (unwind-protect
7657 (progn
7658 (fset 'read-string (lambda (&rest ignore) ,ans))
7659 (eval '(,c1 arg)))
7660 (if bound
7661 (fset 'read-string old)
7662 (fmakunbound 'read-string)))))))
7663 (t (error "Invalid bulk action")))
7665 ;; Sort the markers, to make sure that parents are handled before children
7666 (setq entries (sort entries
7667 (lambda (a b)
7668 (cond
7669 ((equal (marker-buffer a) (marker-buffer b))
7670 (< (marker-position a) (marker-position b)))
7672 (string< (buffer-name (marker-buffer a))
7673 (buffer-name (marker-buffer b))))))))
7675 ;; Now loop over all markers and apply cmd
7676 (while (setq e (pop entries))
7677 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
7678 (if (not pos)
7679 (progn (message "Skipping removed entry at %s" e)
7680 (setq cntskip (1+ cntskip)))
7681 (goto-char pos)
7682 (eval cmd)
7683 (setq org-agenda-bulk-marked-entries
7684 (delete e org-agenda-bulk-marked-entries))
7685 (setq cnt (1+ cnt))))
7686 (setq org-agenda-bulk-marked-entries nil)
7687 (org-agenda-bulk-remove-all-marks)
7688 (when redo-at-end (org-agenda-redo))
7689 (message "Acted on %d entries%s"
7691 (if (= cntskip 0)
7693 (format ", skipped %d (disappeared before their turn)"
7694 cntskip)))))
7696 ;;; Flagging notes
7698 (defun org-agenda-show-the-flagging-note ()
7699 "Display the flagging note in the other window.
7700 When called a second time in direct sequence, offer to remove the FLAGGING
7701 tag and (if present) the flagging note."
7702 (interactive)
7703 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
7704 (win (selected-window))
7705 note heading newhead)
7706 (unless hdmarker
7707 (error "No linked entry at point"))
7708 (if (and (eq this-command last-command)
7709 (y-or-n-p "Unflag and remove any flagging note? "))
7710 (progn
7711 (org-agenda-remove-flag hdmarker)
7712 (let ((win (get-buffer-window "*Flagging Note*")))
7713 (and win (delete-window win)))
7714 (message "Entry unflaged"))
7715 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
7716 (unless note
7717 (error "No flagging note"))
7718 (org-kill-new note)
7719 (org-switch-to-buffer-other-window "*Flagging Note*")
7720 (erase-buffer)
7721 (insert note)
7722 (goto-char (point-min))
7723 (while (re-search-forward "\\\\n" nil t)
7724 (replace-match "\n" t t))
7725 (goto-char (point-min))
7726 (select-window win)
7727 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
7729 (defun org-agenda-remove-flag (marker)
7730 "Remove the FLAGGED tag and any flagging note in the entry."
7731 (let (newhead)
7732 (org-with-point-at marker
7733 (org-toggle-tag "FLAGGED" 'off)
7734 (org-entry-delete nil "THEFLAGGINGNOTE")
7735 (setq newhead (org-get-heading)))
7736 (org-agenda-change-all-lines newhead marker)
7737 (message "Entry unflaged")))
7739 (defun org-agenda-get-any-marker (&optional pos)
7740 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7741 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7743 ;;; Appointment reminders
7745 (defvar appt-time-msg-list)
7747 ;;;###autoload
7748 (defun org-agenda-to-appt (&optional refresh filter)
7749 "Activate appointments found in `org-agenda-files'.
7750 With a \\[universal-argument] prefix, refresh the list of
7751 appointments.
7753 If FILTER is t, interactively prompt the user for a regular
7754 expression, and filter out entries that don't match it.
7756 If FILTER is a string, use this string as a regular expression
7757 for filtering entries out.
7759 FILTER can also be an alist with the car of each cell being
7760 either 'headline or 'category. For example:
7762 '((headline \"IMPORTANT\")
7763 (category \"Work\"))
7765 will only add headlines containing IMPORTANT or headlines
7766 belonging to the \"Work\" category."
7767 (interactive "P")
7768 (if refresh (setq appt-time-msg-list nil))
7769 (if (eq filter t)
7770 (setq filter (read-from-minibuffer "Regexp filter: ")))
7771 (let* ((cnt 0) ; count added events
7772 (org-agenda-new-buffers nil)
7773 (org-deadline-warning-days 0)
7774 (today (org-date-to-gregorian
7775 (time-to-days (current-time))))
7776 (org-agenda-restrict nil)
7777 (files (org-agenda-files 'unrestricted)) entries file)
7778 ;; Get all entries which may contain an appt
7779 (org-prepare-agenda-buffers files)
7780 (while (setq file (pop files))
7781 (setq entries
7782 (append entries
7783 (org-agenda-get-day-entries
7784 file today :timestamp :scheduled :deadline))))
7785 (setq entries (delq nil entries))
7786 ;; Map thru entries and find if we should filter them out
7787 (mapc
7788 (lambda(x)
7789 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7790 (cat (get-text-property 1 'org-category x))
7791 (tod (get-text-property 1 'time-of-day x))
7792 (ok (or (null filter)
7793 (and (stringp filter) (string-match filter evt))
7794 (and (listp filter)
7795 (or (string-match
7796 (cadr (assoc 'category filter)) cat)
7797 (string-match
7798 (cadr (assoc 'headline filter)) evt))))))
7799 ;; FIXME: Shall we remove text-properties for the appt text?
7800 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7801 (when (and ok tod)
7802 (setq tod (concat "00" (number-to-string tod))
7803 tod (when (string-match
7804 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7805 (concat (match-string 1 tod) ":"
7806 (match-string 2 tod))))
7807 (appt-add tod evt)
7808 (setq cnt (1+ cnt))))) entries)
7809 (org-release-buffers org-agenda-new-buffers)
7810 (if (eq cnt 0)
7811 (message "No event to add")
7812 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7814 (defun org-agenda-todayp (date)
7815 "Does DATE mean today, when considering `org-extend-today-until'?"
7816 (let (today h)
7817 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7818 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7819 (setq h (nth 2 (decode-time (current-time))))
7820 (or (and (>= h org-extend-today-until)
7821 (= date today))
7822 (and (< h org-extend-today-until)
7823 (= date (1- today))))))
7825 (provide 'org-agenda)
7827 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7829 ;;; org-agenda.el ends here