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