When an agenda item with 'extra property (such as Scheduled 2x)
[org-mode.git] / lisp / org-agenda.el
blob86b9c94c2073e7049177580ce77723dc16d18e80
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (eval-when-compile
50 (require 'cl))
52 (declare-function diary-add-to-list "diary-lib"
53 (date string specifier &optional marker globcolor literal))
54 (declare-function calendar-absolute-from-iso "cal-iso" (date))
55 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
56 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
57 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
58 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
59 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-french-date-string "cal-french" (&optional date))
61 (declare-function calendar-goto-date "cal-move" (date))
62 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
63 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
64 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
65 (declare-function calendar-iso-from-absolute "cal-iso" (date))
66 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
67 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
68 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
69 (declare-function calendar-check-holidays "holidays" (date))
71 (declare-function org-datetree-find-date-create "org-datetree"
72 (date &optional keep-restriction))
73 (declare-function org-columns-quit "org-colview" ())
74 (declare-function diary-date-display-form "diary-lib" (&optional type))
75 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
76 (declare-function org-habit-insert-consistency-graphs
77 "org-habit" (&optional line))
78 (declare-function org-is-habit-p "org-habit" (&optional pom))
79 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
80 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
81 (declare-function org-pop-to-buffer-same-window "org-compat"
82 (&optional buffer-or-name norecord label))
84 (defvar calendar-mode-map)
85 (defvar org-clock-current-task) ; defined in org-clock.el
86 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
87 (defvar org-habit-show-habits)
88 (defvar org-habit-show-habits-only-for-today)
90 ;; Defined somewhere in this file, but used before definition.
91 (defvar org-agenda-buffer-name)
92 (defvar org-agenda-overriding-header)
93 (defvar org-agenda-title-append nil)
94 (defvar entry)
95 (defvar date)
96 (defvar org-agenda-undo-list)
97 (defvar org-agenda-pending-undo-list)
98 (defvar original-date) ; dynamically scoped, calendar.el does scope this
100 (defcustom org-agenda-confirm-kill 1
101 "When set, remote killing from the agenda buffer needs confirmation.
102 When t, a confirmation is always needed. When a number N, confirmation is
103 only needed when the text to be killed contains more than N non-white lines."
104 :group 'org-agenda
105 :type '(choice
106 (const :tag "Never" nil)
107 (const :tag "Always" t)
108 (integer :tag "When more than N lines")))
110 (defcustom org-agenda-compact-blocks nil
111 "Non-nil means make the block agenda more compact.
112 This is done globally by leaving out lines like the agenda span
113 name and week number or the separator lines."
114 :group 'org-agenda
115 :type 'boolean)
117 (defcustom org-agenda-block-separator ?=
118 "The separator between blocks in the agenda.
119 If this is a string, it will be used as the separator, with a newline added.
120 If it is a character, it will be repeated to fill the window width.
121 If nil the separator is disabled. In `org-agenda-custom-commands' this
122 addresses the separator between the current and the previous block."
123 :group 'org-agenda
124 :type '(choice
125 (const :tag "Disabled" nil)
126 (character)
127 (string)))
129 (defgroup org-agenda-export nil
130 "Options concerning exporting agenda views in Org-mode."
131 :tag "Org Agenda Export"
132 :group 'org-agenda)
134 (defcustom org-agenda-with-colors t
135 "Non-nil means use colors in agenda views."
136 :group 'org-agenda-export
137 :type 'boolean)
139 (defcustom org-agenda-exporter-settings nil
140 "Alist of variable/value pairs that should be active during agenda export.
141 This is a good place to set options for ps-print and for htmlize.
142 Note that the way this is implemented, the values will be evaluated
143 before assigned to the variables. So make sure to quote values you do
144 *not* want evaluated, for example
146 (setq org-agenda-exporter-settings
147 '((ps-print-color-p 'black-white)))"
148 :group 'org-agenda-export
149 :type '(repeat
150 (list
151 (variable)
152 (sexp :tag "Value"))))
154 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
155 "Hook run in temporary buffer before writing it to an export file.
156 A useful function is `org-agenda-add-entry-text'."
157 :group 'org-agenda-export
158 :type 'hook
159 :options '(org-agenda-add-entry-text))
161 (defcustom org-agenda-add-entry-text-maxlines 0
162 "Maximum number of entry text lines to be added to agenda.
163 This is only relevant when `org-agenda-add-entry-text' is part of
164 `org-agenda-before-write-hook', which it is by default.
165 When this is 0, nothing will happen. When it is greater than 0, it
166 specifies the maximum number of lines that will be added for each entry
167 that is listed in the agenda view.
169 Note that this variable is not used during display, only when exporting
170 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
171 and `org-agenda-entry-text-maxlines'."
172 :group 'org-agenda
173 :type 'integer)
175 (defcustom org-agenda-add-entry-text-descriptive-links t
176 "Non-nil means export org-links as descriptive links in agenda added text.
177 This variable applies to the text added to the agenda when
178 `org-agenda-add-entry-text-maxlines' is larger than 0.
179 When this variable nil, the URL will (also) be shown."
180 :group 'org-agenda
181 :type 'boolean)
183 (defcustom org-agenda-export-html-style ""
184 "The style specification for exported HTML Agenda files.
185 If this variable contains a string, it will replace the default <style>
186 section as produced by `htmlize'.
187 Since there are different ways of setting style information, this variable
188 needs to contain the full HTML structure to provide a style, including the
189 surrounding HTML tags. The style specifications should include definitions
190 the fonts used by the agenda, here is an example:
192 <style type=\"text/css\">
193 p { font-weight: normal; color: gray; }
194 .org-agenda-structure {
195 font-size: 110%;
196 color: #003399;
197 font-weight: 600;
199 .org-todo {
200 color: #cc6666;
201 font-weight: bold;
203 .org-agenda-done {
204 color: #339933;
206 .org-done {
207 color: #339933;
209 .title { text-align: center; }
210 .todo, .deadline { color: red; }
211 .done { color: green; }
212 </style>
214 or, if you want to keep the style in a file,
216 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
218 As the value of this option simply gets inserted into the HTML <head> header,
219 you can \"misuse\" it to also add other text to the header. However,
220 <style>...</style> is required, if not present the variable will be ignored."
221 :group 'org-agenda-export
222 :group 'org-export-html
223 :type 'string)
225 (defcustom org-agenda-persistent-filter nil
226 "When set, keep filters from one agenda view to the next."
227 :group 'org-agenda
228 :type 'boolean)
230 (defgroup org-agenda-custom-commands nil
231 "Options concerning agenda views in Org-mode."
232 :tag "Org Agenda Custom Commands"
233 :group 'org-agenda)
235 (defconst org-sorting-choice
236 '(choice
237 (const time-up) (const time-down)
238 (const category-keep) (const category-up) (const category-down)
239 (const tag-down) (const tag-up)
240 (const priority-up) (const priority-down)
241 (const todo-state-up) (const todo-state-down)
242 (const effort-up) (const effort-down)
243 (const habit-up) (const habit-down)
244 (const alpha-up) (const alpha-down)
245 (const user-defined-up) (const user-defined-down))
246 "Sorting choices.")
248 ;; Keep custom values for `org-agenda-filter-preset' compatible with
249 ;; the new variable `org-agenda-tag-filter-preset'.
250 (if (fboundp 'defvaralias)
251 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
252 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
254 (defconst org-agenda-custom-commands-local-options
255 `(repeat :tag "Local settings for this command. Remember to quote values"
256 (choice :tag "Setting"
257 (list :tag "Heading for this block"
258 (const org-agenda-overriding-header)
259 (string :tag "Headline"))
260 (list :tag "Files to be searched"
261 (const org-agenda-files)
262 (list
263 (const :format "" quote)
264 (repeat (file))))
265 (list :tag "Sorting strategy"
266 (const org-agenda-sorting-strategy)
267 (list
268 (const :format "" quote)
269 (repeat
270 ,org-sorting-choice)))
271 (list :tag "Prefix format"
272 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
273 (string))
274 (list :tag "Number of days in agenda"
275 (const org-agenda-span)
276 (choice (const :tag "Day" 'day)
277 (const :tag "Week" 'week)
278 (const :tag "Month" 'month)
279 (const :tag "Year" 'year)
280 (integer :tag "Custom")))
281 (list :tag "Fixed starting date"
282 (const org-agenda-start-day)
283 (string :value "2007-11-01"))
284 (list :tag "Start on day of week"
285 (const org-agenda-start-on-weekday)
286 (choice :value 1
287 (const :tag "Today" nil)
288 (integer :tag "Weekday No.")))
289 (list :tag "Include data from diary"
290 (const org-agenda-include-diary)
291 (boolean))
292 (list :tag "Deadline Warning days"
293 (const org-deadline-warning-days)
294 (integer :value 1))
295 (list :tag "Category filter preset"
296 (const org-agenda-category-filter-preset)
297 (list
298 (const :format "" quote)
299 (repeat
300 (string :tag "+category or -category"))))
301 (list :tag "Tags filter preset"
302 (const org-agenda-tag-filter-preset)
303 (list
304 (const :format "" quote)
305 (repeat
306 (string :tag "+tag or -tag"))))
307 (list :tag "Set daily/weekly entry types"
308 (const org-agenda-entry-types)
309 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
310 (const :deadline)
311 (const :scheduled)
312 (const :timestamp)
313 (const :sexp)))
314 (list :tag "Standard skipping condition"
315 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
316 (const org-agenda-skip-function)
317 (list
318 (const :format "" quote)
319 (list
320 (choice
321 :tag "Skipping range"
322 (const :tag "Skip entry" org-agenda-skip-entry-if)
323 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
324 (repeat :inline t :tag "Conditions for skipping"
325 (choice
326 :tag "Condition type"
327 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
328 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
329 (list :tag "TODO state is" :inline t
330 (const 'todo)
331 (choice
332 (const :tag "any not-done state" 'todo)
333 (const :tag "any done state" 'done)
334 (const :tag "any state" 'any)
335 (list :tag "Keyword list"
336 (const :format "" quote)
337 (repeat (string :tag "Keyword")))))
338 (list :tag "TODO state is not" :inline t
339 (const 'nottodo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (const :tag "scheduled" 'scheduled)
348 (const :tag "not scheduled" 'notscheduled)
349 (const :tag "deadline" 'deadline)
350 (const :tag "no deadline" 'notdeadline)
351 (const :tag "timestamp" 'timestamp)
352 (const :tag "no timestamp" 'nottimestamp))))))
353 (list :tag "Non-standard skipping condition"
354 :value (org-agenda-skip-function)
355 (const org-agenda-skip-function)
356 (sexp :tag "Function or form (quoted!)"))
357 (list :tag "Any variable"
358 (variable :tag "Variable")
359 (sexp :tag "Value (sexp)"))))
360 "Selection of examples for agenda command settings.
361 This will be spliced into the custom type of
362 `org-agenda-custom-commands'.")
365 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
366 ((agenda "") (alltodo))))
367 "Custom commands for the agenda.
368 These commands will be offered on the splash screen displayed by the
369 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
371 (key desc type match settings files)
373 key The key (one or more characters as a string) to be associated
374 with the command.
375 desc A description of the command, when omitted or nil, a default
376 description is built using MATCH.
377 type The command type, any of the following symbols:
378 agenda The daily/weekly agenda.
379 todo Entries with a specific TODO keyword, in all agenda files.
380 search Entries containing search words entry or headline.
381 tags Tags/Property/TODO match in all agenda files.
382 tags-todo Tags/P/T match in all agenda files, TODO entries only.
383 todo-tree Sparse tree of specific TODO keyword in *current* file.
384 tags-tree Sparse tree with all tags matches in *current* file.
385 occur-tree Occur sparse tree for *current* file.
386 ... A user-defined function.
387 match What to search for:
388 - a single keyword for TODO keyword searches
389 - a tags match expression for tags searches
390 - a word search expression for text searches.
391 - a regular expression for occur searches
392 For all other commands, this should be the empty string.
393 settings A list of option settings, similar to that in a let form, so like
394 this: ((opt1 val1) (opt2 val2) ...). The values will be
395 evaluated at the moment of execution, so quote them when needed.
396 files A list of files file to write the produced agenda buffer to
397 with the command `org-store-agenda-views'.
398 If a file name ends in \".html\", an HTML version of the buffer
399 is written out. If it ends in \".ps\", a postscript version is
400 produced. Otherwise, only the plain text is written to the file.
402 You can also define a set of commands, to create a composite agenda buffer.
403 In this case, an entry looks like this:
405 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
407 where
409 desc A description string to be displayed in the dispatcher menu.
410 cmd An agenda command, similar to the above. However, tree commands
411 are not allowed, but instead you can get agenda and global todo list.
412 So valid commands for a set are:
413 (agenda \"\" settings)
414 (alltodo \"\" settings)
415 (stuck \"\" settings)
416 (todo \"match\" settings files)
417 (search \"match\" settings files)
418 (tags \"match\" settings files)
419 (tags-todo \"match\" settings files)
421 Each command can carry a list of options, and another set of options can be
422 given for the whole set of commands. Individual command options take
423 precedence over the general options.
425 When using several characters as key to a command, the first characters
426 are prefix commands. For the dispatcher to display useful information, you
427 should provide a description for the prefix, like
429 (setq org-agenda-custom-commands
430 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
431 (\"hl\" tags \"+HOME+Lisa\")
432 (\"hp\" tags \"+HOME+Peter\")
433 (\"hk\" tags \"+HOME+Kim\")))"
434 :group 'org-agenda-custom-commands
435 :type `(repeat
436 (choice :value ("x" "Describe command here" tags "" nil)
437 (list :tag "Single command"
438 (string :tag "Access Key(s) ")
439 (option (string :tag "Description"))
440 (choice
441 (const :tag "Agenda" agenda)
442 (const :tag "TODO list" alltodo)
443 (const :tag "Search words" search)
444 (const :tag "Stuck projects" stuck)
445 (const :tag "Tags/Property match (all agenda files)" tags)
446 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
447 (const :tag "TODO keyword search (all agenda files)" todo)
448 (const :tag "Tags sparse tree (current buffer)" tags-tree)
449 (const :tag "TODO keyword tree (current buffer)" todo-tree)
450 (const :tag "Occur tree (current buffer)" occur-tree)
451 (sexp :tag "Other, user-defined function"))
452 (string :tag "Match (only for some commands)")
453 ,org-agenda-custom-commands-local-options
454 (option (repeat :tag "Export" (file :tag "Export to"))))
455 (list :tag "Command series, all agenda files"
456 (string :tag "Access Key(s)")
457 (string :tag "Description ")
458 (repeat :tag "Component"
459 (choice
460 (list :tag "Agenda"
461 (const :format "" agenda)
462 (const :tag "" :format "" "")
463 ,org-agenda-custom-commands-local-options)
464 (list :tag "TODO list (all keywords)"
465 (const :format "" alltodo)
466 (const :tag "" :format "" "")
467 ,org-agenda-custom-commands-local-options)
468 (list :tag "Search words"
469 (const :format "" search)
470 (string :tag "Match")
471 ,org-agenda-custom-commands-local-options)
472 (list :tag "Stuck projects"
473 (const :format "" stuck)
474 (const :tag "" :format "" "")
475 ,org-agenda-custom-commands-local-options)
476 (list :tag "Tags search"
477 (const :format "" tags)
478 (string :tag "Match")
479 ,org-agenda-custom-commands-local-options)
480 (list :tag "Tags search, TODO entries only"
481 (const :format "" tags-todo)
482 (string :tag "Match")
483 ,org-agenda-custom-commands-local-options)
484 (list :tag "TODO keyword search"
485 (const :format "" todo)
486 (string :tag "Match")
487 ,org-agenda-custom-commands-local-options)
488 (list :tag "Other, user-defined function"
489 (symbol :tag "function")
490 (string :tag "Match")
491 ,org-agenda-custom-commands-local-options)))
493 (repeat :tag "Settings for entire command set"
494 (list (variable :tag "Any variable")
495 (sexp :tag "Value")))
496 (option (repeat :tag "Export" (file :tag "Export to"))))
497 (cons :tag "Prefix key documentation"
498 (string :tag "Access Key(s)")
499 (string :tag "Description ")))))
501 (defcustom org-agenda-query-register ?o
502 "The register holding the current query string.
503 The purpose of this is that if you construct a query string interactively,
504 you can then use it to define a custom command."
505 :group 'org-agenda-custom-commands
506 :type 'character)
508 (defcustom org-stuck-projects
509 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
510 "How to identify stuck projects.
511 This is a list of four items:
512 1. A tags/todo/property matcher string that is used to identify a project.
513 See the manual for a description of tag and property searches.
514 The entire tree below a headline matched by this is considered one project.
515 2. A list of TODO keywords identifying non-stuck projects.
516 If the project subtree contains any headline with one of these todo
517 keywords, the project is considered to be not stuck. If you specify
518 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
519 3. A list of tags identifying non-stuck projects.
520 If the project subtree contains any headline with one of these tags,
521 the project is considered to be not stuck. If you specify \"*\" as
522 a tag, any tag will mark the project unstuck. Note that this is about
523 the explicit presence of a tag somewhere in the subtree, inherited
524 tags to not count here. If inherited tags make a project not stuck,
525 use \"-TAG\" in the tags part of the matcher under (1.) above.
526 4. An arbitrary regular expression matching non-stuck projects.
528 If the project turns out to be not stuck, search continues also in the
529 subtree to see if any of the subtasks have project status.
531 See also the variable `org-tags-match-list-sublevels' which applies
532 to projects matched by this search as well.
534 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
535 or `C-c a #' to produce the list."
536 :group 'org-agenda-custom-commands
537 :type '(list
538 (string :tag "Tags/TODO match to identify a project")
539 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
540 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
541 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
543 (defcustom org-agenda-filter-effort-default-operator "<"
544 "The default operator for effort estimate filtering.
545 If you select an effort estimate limit without first pressing an operator,
546 this one will be used."
547 :group 'org-agenda-custom-commands
548 :type '(choice (const :tag "less or equal" "<")
549 (const :tag "greater or equal"">")
550 (const :tag "equal" "=")))
552 (defgroup org-agenda-skip nil
553 "Options concerning skipping parts of agenda files."
554 :tag "Org Agenda Skip"
555 :group 'org-agenda)
557 (defcustom org-agenda-skip-function-global nil
558 "Function to be called at each match during agenda construction.
559 If this function returns nil, the current match should not be skipped.
560 If the function decided to skip an agenda match, is must return the
561 buffer position from which the search should be continued.
562 This may also be a Lisp form, which will be evaluated.
564 This variable will be applied to every agenda match, including
565 tags/property searches and TODO lists. So try to make the test function
566 do its checking as efficiently as possible. To implement a skipping
567 condition just for specific agenda commands, use the variable
568 `org-agenda-skip-function' which can be set in the options section
569 of custom agenda commands."
570 :group 'org-agenda-skip
571 :type 'sexp)
573 (defgroup org-agenda-daily/weekly nil
574 "Options concerning the daily/weekly agenda."
575 :tag "Org Agenda Daily/Weekly"
576 :group 'org-agenda)
577 (defgroup org-agenda-todo-list nil
578 "Options concerning the global todo list agenda view."
579 :tag "Org Agenda Todo List"
580 :group 'org-agenda)
581 (defgroup org-agenda-match-view nil
582 "Options concerning the general tags/property/todo match agenda view."
583 :tag "Org Agenda Match View"
584 :group 'org-agenda)
585 (defgroup org-agenda-search-view nil
586 "Options concerning the general tags/property/todo match agenda view."
587 :tag "Org Agenda Match View"
588 :group 'org-agenda)
590 (defvar org-agenda-archives-mode nil
591 "Non-nil means the agenda will include archived items.
592 If this is the symbol `trees', trees in the selected agenda scope
593 that are marked with the ARCHIVE tag will be included anyway. When this is
594 t, also all archive files associated with the current selection of agenda
595 files will be included.")
597 (defcustom org-agenda-skip-comment-trees t
598 "Non-nil means skip trees that start with the COMMENT keyword.
599 When nil, these trees are also scanned by agenda commands."
600 :group 'org-agenda-skip
601 :type 'boolean)
603 (defcustom org-agenda-todo-list-sublevels t
604 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
605 When nil, the sublevels of a TODO entry are not checked, resulting in
606 potentially much shorter TODO lists."
607 :group 'org-agenda-skip
608 :group 'org-agenda-todo-list
609 :type 'boolean)
611 (defcustom org-agenda-todo-ignore-with-date nil
612 "Non-nil means don't show entries with a date in the global todo list.
613 You can use this if you prefer to mark mere appointments with a TODO keyword,
614 but don't want them to show up in the TODO list.
615 When this is set, it also covers deadlines and scheduled items, the settings
616 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
617 will be ignored.
618 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
619 :group 'org-agenda-skip
620 :group 'org-agenda-todo-list
621 :type 'boolean)
623 (defcustom org-agenda-todo-ignore-timestamp nil
624 "Non-nil means don't show entries with a timestamp.
625 This applies when creating the global todo list.
626 Valid values are:
628 past Don't show entries for today or in the past.
630 future Don't show entries with a timestamp in the future.
631 The idea behind this is that if it has a future
632 timestamp, you don't want to think about it until the
633 date.
635 all Don't show any entries with a timestamp in the global todo list.
636 The idea behind this is that by setting a timestamp, you
637 have already \"taken care\" of this item.
639 This variable can also have an integer as a value. If positive (N),
640 todos with a timestamp N or more days in the future will be ignored. If
641 negative (-N), todos with a timestamp N or more days in the past will be
642 ignored. If 0, todos with a timestamp either today or in the future will
643 be ignored. For example, a value of -1 will exclude todos with a
644 timestamp in the past (yesterday or earlier), while a value of 7 will
645 exclude todos with a timestamp a week or more in the future.
647 See also `org-agenda-todo-ignore-with-date'.
648 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
649 to make his option also apply to the tags-todo list."
650 :group 'org-agenda-skip
651 :group 'org-agenda-todo-list
652 :version "24.1"
653 :type '(choice
654 (const :tag "Ignore future timestamp todos" future)
655 (const :tag "Ignore past or present timestamp todos" past)
656 (const :tag "Ignore all timestamp todos" all)
657 (const :tag "Show timestamp todos" nil)
658 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
660 (defcustom org-agenda-todo-ignore-scheduled nil
661 "Non-nil means, ignore some scheduled TODO items when making TODO list.
662 This applies when creating the global todo list.
663 Valid values are:
665 past Don't show entries scheduled today or in the past.
667 future Don't show entries scheduled in the future.
668 The idea behind this is that by scheduling it, you don't want to
669 think about it until the scheduled date.
671 all Don't show any scheduled entries in the global todo list.
672 The idea behind this is that by scheduling it, you have already
673 \"taken care\" of this item.
675 t Same as `all', for backward compatibility.
677 This variable can also have an integer as a value. See
678 `org-agenda-todo-ignore-timestamp' for more details.
680 See also `org-agenda-todo-ignore-with-date'.
681 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
682 to make his option also apply to the tags-todo list."
683 :group 'org-agenda-skip
684 :group 'org-agenda-todo-list
685 :type '(choice
686 (const :tag "Ignore future-scheduled todos" future)
687 (const :tag "Ignore past- or present-scheduled todos" past)
688 (const :tag "Ignore all scheduled todos" all)
689 (const :tag "Ignore all scheduled todos (compatibility)" t)
690 (const :tag "Show scheduled todos" nil)
691 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
693 (defcustom org-agenda-todo-ignore-deadlines nil
694 "Non-nil means ignore some deadlined TODO items when making TODO list.
695 There are different motivations for using different values, please think
696 carefully when configuring this variable.
698 This applies when creating the global todo list.
699 Valid values are:
701 near Don't show near deadline entries. A deadline is near when it is
702 closer than `org-deadline-warning-days' days. The idea behind this
703 is that such items will appear in the agenda anyway.
705 far Don't show TODO entries where a deadline has been defined, but
706 the deadline is not near. This is useful if you don't want to
707 use the todo list to figure out what to do now.
709 past Don't show entries with a deadline timestamp for today or in the past.
711 future Don't show entries with a deadline timestamp in the future, not even
712 when they become `near' ones. Use it with caution.
714 all Ignore all TODO entries that do have a deadline.
716 t Same as `near', for backward compatibility.
718 This variable can also have an integer as a value. See
719 `org-agenda-todo-ignore-timestamp' for more details.
721 See also `org-agenda-todo-ignore-with-date'.
722 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
723 to make his option also apply to the tags-todo list."
724 :group 'org-agenda-skip
725 :group 'org-agenda-todo-list
726 :type '(choice
727 (const :tag "Ignore near deadlines" near)
728 (const :tag "Ignore near deadlines (compatibility)" t)
729 (const :tag "Ignore far deadlines" far)
730 (const :tag "Ignore all TODOs with a deadlines" all)
731 (const :tag "Show all TODOs, even if they have a deadline" nil)
732 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
734 (defcustom org-agenda-tags-todo-honor-ignore-options nil
735 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
736 The variables
737 `org-agenda-todo-ignore-with-date',
738 `org-agenda-todo-ignore-timestamp',
739 `org-agenda-todo-ignore-scheduled',
740 `org-agenda-todo-ignore-deadlines'
741 make the global TODO list skip entries that have time stamps of certain
742 kinds. If this option is set, the same options will also apply for the
743 tags-todo search, which is the general tags/property matcher
744 restricted to unfinished TODO entries only."
745 :group 'org-agenda-skip
746 :group 'org-agenda-todo-list
747 :group 'org-agenda-match-view
748 :type 'boolean)
750 (defcustom org-agenda-skip-scheduled-if-done nil
751 "Non-nil means don't show scheduled items in agenda when they are done.
752 This is relevant for the daily/weekly agenda, not for the TODO list. And
753 it applies only to the actual date of the scheduling. Warnings about
754 an item with a past scheduling dates are always turned off when the item
755 is DONE."
756 :group 'org-agenda-skip
757 :group 'org-agenda-daily/weekly
758 :type 'boolean)
760 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
761 "Non-nil means skip scheduling line if same entry shows because of deadline.
762 In the agenda of today, an entry can show up multiple times because
763 it is both scheduled and has a nearby deadline, and maybe a plain time
764 stamp as well.
765 When this variable is t, then only the deadline is shown and the fact that
766 the entry is scheduled today or was scheduled previously is not shown.
767 When this variable is nil, the entry will be shown several times. When
768 the variable is the symbol `not-today', then skip scheduled previously,
769 but not scheduled today."
770 :group 'org-agenda-skip
771 :group 'org-agenda-daily/weekly
772 :type '(choice
773 (const :tag "Never" nil)
774 (const :tag "Always" t)
775 (const :tag "Not when scheduled today" not-today)))
777 (defcustom org-agenda-skip-deadline-if-done nil
778 "Non-nil means don't show deadlines when the corresponding item is done.
779 When nil, the deadline is still shown and should give you a happy feeling.
780 This is relevant for the daily/weekly agenda. And it applied only to the
781 actually date of the deadline. Warnings about approaching and past-due
782 deadlines are always turned off when the item is DONE."
783 :group 'org-agenda-skip
784 :group 'org-agenda-daily/weekly
785 :type 'boolean)
787 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
788 "Non-nil means skip deadline prewarning when entry is also scheduled.
789 This will apply on all days where a prewarning for the deadline would
790 be shown, but not at the day when the entry is actually due. On that day,
791 the deadline will be shown anyway.
792 This variable may be set to nil, t, or a number which will then give
793 the number of days before the actual deadline when the prewarnings
794 should resume.
795 This can be used in a workflow where the first showing of the deadline will
796 trigger you to schedule it, and then you don't want to be reminded of it
797 because you will take care of it on the day when scheduled."
798 :group 'org-agenda-skip
799 :group 'org-agenda-daily/weekly
800 :version "24.1"
801 :type '(choice
802 (const :tag "Alwas show prewarning" nil)
803 (const :tag "Remove prewarning if entry is scheduled" t)
804 (integer :tag "Restart prewarning N days before deadline")))
806 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
807 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
808 When non-nil, after the search for timestamps has matched once in an
809 entry, the rest of the entry will not be searched."
810 :group 'org-agenda-skip
811 :type 'boolean)
813 (defcustom org-agenda-skip-timestamp-if-done nil
814 "Non-nil means don't select item by timestamp or -range if it is DONE."
815 :group 'org-agenda-skip
816 :group 'org-agenda-daily/weekly
817 :type 'boolean)
819 (defcustom org-agenda-dim-blocked-tasks t
820 "Non-nil means dim blocked tasks in the agenda display.
821 This causes some overhead during agenda construction, but if you
822 have turned on `org-enforce-todo-dependencies',
823 `org-enforce-todo-checkbox-dependencies', or any other blocking
824 mechanism, this will create useful feedback in the agenda.
826 Instead of t, this variable can also have the value `invisible'.
827 Then blocked tasks will be invisible and only become visible when
828 they become unblocked. An exemption to this behavior is when a task is
829 blocked because of unchecked checkboxes below it. Since checkboxes do
830 not show up in the agenda views, making this task invisible you remove any
831 trace from agenda views that there is something to do. Therefore, a task
832 that is blocked because of checkboxes will never be made invisible, it
833 will only be dimmed."
834 :group 'org-agenda-daily/weekly
835 :group 'org-agenda-todo-list
836 :type '(choice
837 (const :tag "Do not dim" nil)
838 (const :tag "Dim to a gray face" t)
839 (const :tag "Make invisible" invisible)))
841 (defcustom org-timeline-show-empty-dates 3
842 "Non-nil means `org-timeline' also shows dates without an entry.
843 When nil, only the days which actually have entries are shown.
844 When t, all days between the first and the last date are shown.
845 When an integer, show also empty dates, but if there is a gap of more than
846 N days, just insert a special line indicating the size of the gap."
847 :group 'org-agenda-skip
848 :type '(choice
849 (const :tag "None" nil)
850 (const :tag "All" t)
851 (integer :tag "at most")))
853 (defgroup org-agenda-startup nil
854 "Options concerning initial settings in the Agenda in Org Mode."
855 :tag "Org Agenda Startup"
856 :group 'org-agenda)
858 (defcustom org-agenda-menu-show-matcher t
859 "Non-nil means show the match string in the agenda dispatcher menu.
860 When nil, the matcher string is not shown, but is put into the help-echo
861 property so than moving the mouse over the command shows it.
862 Setting it to nil is good if matcher strings are very long and/or if
863 you want to use two-column display (see `org-agenda-menu-two-column')."
864 :group 'org-agenda
865 :version "24.1"
866 :type 'boolean)
868 (defcustom org-agenda-menu-two-column nil
869 "Non-nil means, use two columns to show custom commands in the dispatcher.
870 If you use this, you probably want to set `org-agenda-menu-show-matcher'
871 to nil."
872 :group 'org-agenda
873 :version "24.1"
874 :type 'boolean)
876 (defcustom org-finalize-agenda-hook nil
877 "Hook run just before displaying an agenda buffer."
878 :group 'org-agenda-startup
879 :type 'hook)
881 (defcustom org-agenda-mouse-1-follows-link nil
882 "Non-nil means mouse-1 on a link will follow the link in the agenda.
883 A longer mouse click will still set point. Does not work on XEmacs.
884 Needs to be set before org.el is loaded."
885 :group 'org-agenda-startup
886 :type 'boolean)
888 (defcustom org-agenda-start-with-follow-mode nil
889 "The initial value of follow mode in a newly created agenda window."
890 :group 'org-agenda-startup
891 :type 'boolean)
893 (defcustom org-agenda-follow-indirect nil
894 "Non-nil means `org-agenda-follow-mode' displays only the
895 current item's tree, in an indirect buffer."
896 :group 'org-agenda
897 :version "24.1"
898 :type 'boolean)
900 (defcustom org-agenda-show-outline-path t
901 "Non-nil means show outline path in echo area after line motion."
902 :group 'org-agenda-startup
903 :type 'boolean)
905 (defcustom org-agenda-start-with-entry-text-mode nil
906 "The initial value of entry-text-mode in a newly created agenda window."
907 :group 'org-agenda-startup
908 :type 'boolean)
910 (defcustom org-agenda-entry-text-maxlines 5
911 "Number of text lines to be added when `E' is pressed in the agenda.
913 Note that this variable only used during agenda display. Add add entry text
914 when exporting the agenda, configure the variable
915 `org-agenda-add-entry-ext-maxlines'."
916 :group 'org-agenda
917 :type 'integer)
919 (defcustom org-agenda-entry-text-exclude-regexps nil
920 "List of regular expressions to clean up entry text.
921 The complete matches of all regular expressions in this list will be
922 removed from entry text before it is shown in the agenda."
923 :group 'org-agenda
924 :type '(repeat (regexp)))
926 (defvar org-agenda-entry-text-cleanup-hook nil
927 "Hook that is run after basic cleanup of entry text to be shown in agenda.
928 This cleanup is done in a temporary buffer, so the function may inspect and
929 change the entire buffer.
930 Some default stuff like drawers and scheduling/deadline dates will already
931 have been removed when this is called, as will any matches for regular
932 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
934 (defvar org-agenda-include-inactive-timestamps nil
935 "Non-nil means include inactive time stamps in agenda and timeline.
936 Dynamically scoped.")
938 (defgroup org-agenda-windows nil
939 "Options concerning the windows used by the Agenda in Org Mode."
940 :tag "Org Agenda Windows"
941 :group 'org-agenda)
943 (defcustom org-agenda-window-setup 'reorganize-frame
944 "How the agenda buffer should be displayed.
945 Possible values for this option are:
947 current-window Show agenda in the current window, keeping all other windows.
948 other-window Use `switch-to-buffer-other-window' to display agenda.
949 reorganize-frame Show only two windows on the current frame, the current
950 window and the agenda.
951 other-frame Use `switch-to-buffer-other-frame' to display agenda.
952 Also, when exiting the agenda, kill that frame.
953 See also the variable `org-agenda-restore-windows-after-quit'."
954 :group 'org-agenda-windows
955 :type '(choice
956 (const current-window)
957 (const other-frame)
958 (const other-window)
959 (const reorganize-frame)))
961 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
962 "The min and max height of the agenda window as a fraction of frame height.
963 The value of the variable is a cons cell with two numbers between 0 and 1.
964 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
965 :group 'org-agenda-windows
966 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
968 (defcustom org-agenda-restore-windows-after-quit nil
969 "Non-nil means restore window configuration upon exiting agenda.
970 Before the window configuration is changed for displaying the agenda,
971 the current status is recorded. When the agenda is exited with
972 `q' or `x' and this option is set, the old state is restored. If
973 `org-agenda-window-setup' is `other-frame', the value of this
974 option will be ignored."
975 :group 'org-agenda-windows
976 :type 'boolean)
978 (defcustom org-agenda-ndays nil
979 "Number of days to include in overview display.
980 Should be 1 or 7.
981 Obsolete, see `org-agenda-span'."
982 :group 'org-agenda-daily/weekly
983 :type 'integer)
985 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
987 (defcustom org-agenda-span 'week
988 "Number of days to include in overview display.
989 Can be day, week, month, year, or any number of days.
990 Custom commands can set this variable in the options section."
991 :group 'org-agenda-daily/weekly
992 :type '(choice (const :tag "Day" day)
993 (const :tag "Week" week)
994 (const :tag "Month" month)
995 (const :tag "Year" year)
996 (integer :tag "Custom")))
998 (defcustom org-agenda-start-on-weekday 1
999 "Non-nil means start the overview always on the specified weekday.
1000 0 denotes Sunday, 1 denotes Monday etc.
1001 When nil, always start on the current day.
1002 Custom commands can set this variable in the options section."
1003 :group 'org-agenda-daily/weekly
1004 :type '(choice (const :tag "Today" nil)
1005 (integer :tag "Weekday No.")))
1007 (defcustom org-agenda-show-all-dates t
1008 "Non-nil means `org-agenda' shows every day in the selected range.
1009 When nil, only the days which actually have entries are shown."
1010 :group 'org-agenda-daily/weekly
1011 :type 'boolean)
1013 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1014 "Format string for displaying dates in the agenda.
1015 Used by the daily/weekly agenda and by the timeline. This should be
1016 a format string understood by `format-time-string', or a function returning
1017 the formatted date as a string. The function must take a single argument,
1018 a calendar-style date list like (month day year)."
1019 :group 'org-agenda-daily/weekly
1020 :type '(choice
1021 (string :tag "Format string")
1022 (function :tag "Function")))
1024 (defun org-agenda-format-date-aligned (date)
1025 "Format a date string for display in the daily/weekly agenda, or timeline.
1026 This function makes sure that dates are aligned for easy reading."
1027 (require 'cal-iso)
1028 (let* ((dayname (calendar-day-name date))
1029 (day (cadr date))
1030 (day-of-week (calendar-day-of-week date))
1031 (month (car date))
1032 (monthname (calendar-month-name month))
1033 (year (nth 2 date))
1034 (iso-week (org-days-to-iso-week
1035 (calendar-absolute-from-gregorian date)))
1036 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1037 (1- year))
1038 ((and (= month 12) (<= iso-week 1))
1039 (1+ year))
1040 (t year)))
1041 (weekstring (if (= day-of-week 1)
1042 (format " W%02d" iso-week)
1043 "")))
1044 (format "%-10s %2d %s %4d%s"
1045 dayname day monthname year weekstring)))
1047 (defcustom org-agenda-time-leading-zero nil
1048 "Non-nil means use leading zero for military times in agenda.
1049 For example, 9:30am would become 09:30 rather than 9:30."
1050 :group 'org-agenda-daily/weekly
1051 :version "24.1"
1052 :type 'boolean)
1054 (defcustom org-agenda-timegrid-use-ampm nil
1055 "When set, show AM/PM style timestamps on the timegrid."
1056 :group 'org-agenda
1057 :version "24.1"
1058 :type 'boolean)
1060 (defun org-agenda-time-of-day-to-ampm (time)
1061 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1062 (let* ((hour-number (string-to-number (substring time 0 -3)))
1063 (minute (substring time -2))
1064 (ampm "am"))
1065 (cond
1066 ((equal hour-number 12)
1067 (setq ampm "pm"))
1068 ((> hour-number 12)
1069 (setq ampm "pm")
1070 (setq hour-number (- hour-number 12))))
1071 (concat
1072 (if org-agenda-time-leading-zero
1073 (format "%02d" hour-number)
1074 (format "%02s" (number-to-string hour-number)))
1075 ":" minute ampm)))
1077 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1078 "Conditionally convert TIME to AM/PM format
1079 based on `org-agenda-timegrid-use-ampm'"
1080 (if org-agenda-timegrid-use-ampm
1081 (org-agenda-time-of-day-to-ampm time)
1082 time))
1084 (defcustom org-agenda-weekend-days '(6 0)
1085 "Which days are weekend?
1086 These days get the special face `org-agenda-date-weekend' in the agenda
1087 and timeline buffers."
1088 :group 'org-agenda-daily/weekly
1089 :type '(set :greedy t
1090 (const :tag "Monday" 1)
1091 (const :tag "Tuesday" 2)
1092 (const :tag "Wednesday" 3)
1093 (const :tag "Thursday" 4)
1094 (const :tag "Friday" 5)
1095 (const :tag "Saturday" 6)
1096 (const :tag "Sunday" 0)))
1098 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1099 "Non-nil means jump to today when moving a past date forward in time.
1100 When using S-right in the agenda to move a a date forward, and the date
1101 stamp currently points to the past, the first key press will move it
1102 to today. WHen nil, just move one day forward even if the date stays
1103 in the past."
1104 :group 'org-agenda-daily/weekly
1105 :version "24.1"
1106 :type 'boolean)
1108 (defcustom org-agenda-include-diary nil
1109 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1110 Custom commands can set this variable in the options section."
1111 :group 'org-agenda-daily/weekly
1112 :type 'boolean)
1114 (defcustom org-agenda-include-deadlines t
1115 "If non-nil, include entries within their deadline warning period.
1116 Custom commands can set this variable in the options section."
1117 :group 'org-agenda-daily/weekly
1118 :version "24.1"
1119 :type 'boolean)
1121 (defcustom org-agenda-repeating-timestamp-show-all t
1122 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1123 When set to a list of strings, only show occurrences of repeating
1124 stamps for these TODO keywords. When nil, only one occurrence is
1125 shown, either today or the nearest into the future."
1126 :group 'org-agenda-daily/weekly
1127 :type '(choice
1128 (const :tag "Show repeating stamps" t)
1129 (repeat :tag "Show repeating stamps for these TODO keywords"
1130 (string :tag "TODO Keyword"))
1131 (const :tag "Don't show repeating stamps" nil)))
1133 (defcustom org-scheduled-past-days 10000
1134 "No. of days to continue listing scheduled items that are not marked DONE.
1135 When an item is scheduled on a date, it shows up in the agenda on this
1136 day and will be listed until it is marked done for the number of days
1137 given here."
1138 :group 'org-agenda-daily/weekly
1139 :type 'integer)
1141 (defcustom org-agenda-log-mode-items '(closed clock)
1142 "List of items that should be shown in agenda log mode.
1143 This list may contain the following symbols:
1145 closed Show entries that have been closed on that day.
1146 clock Show entries that have received clocked time on that day.
1147 state Show all logged state changes.
1148 Note that instead of changing this variable, you can also press `C-u l' in
1149 the agenda to display all available LOG items temporarily."
1150 :group 'org-agenda-daily/weekly
1151 :type '(set :greedy t (const closed) (const clock) (const state)))
1153 (defcustom org-agenda-clock-consistency-checks
1154 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1155 :gap-ok-around ("4:00")
1156 :default-face ((:background "DarkRed") (:foreground "white"))
1157 :overlap-face nil :gap-face nil :no-end-time-face nil
1158 :long-face nil :short-face nil)
1159 "This is a property list, with the following keys:
1161 :max-duration Mark clocking chunks that are longer than this time.
1162 This is a time string like \"HH:MM\", or the number
1163 of minutes as an integer.
1165 :min-duration Mark clocking chunks that are shorter that this.
1166 This is a time string like \"HH:MM\", or the number
1167 of minutes as an integer.
1169 :max-gap Mark gaps between clocking chunks that are longer than
1170 this duration. A number of minutes, or a string
1171 like \"HH:MM\".
1173 :gap-ok-around List of times during the day which are usually not working
1174 times. When a gap is detected, but the gap contains any
1175 of these times, the gap is *not* reported. For example,
1176 if this is (\"4:00\" \"13:00\") then gaps that contain
1177 4:00 in the morning (i.e. the night) and 13:00
1178 (i.e. a typical lunch time) do not cause a warning.
1179 You should have at least one time during the night in this
1180 list, or otherwise the first task each morning will trigger
1181 a warning because it follows a long gap.
1183 Furthermore, the following properties can be used to define faces for
1184 issue display.
1186 :default-face the default face, if the specific face is undefined
1187 :overlap-face face for overlapping clocks
1188 :gap-face face for gaps between clocks
1189 :no-end-time-face face for incomplete clocks
1190 :long-face face for clock intervals that are too long
1191 :short-face face for clock intervals that are too short"
1192 :group 'org-agenda-daily/weekly
1193 :group 'org-clock
1194 :version "24.1"
1195 :type 'plist)
1197 (defcustom org-agenda-log-mode-add-notes t
1198 "Non-nil means add first line of notes to log entries in agenda views.
1199 If a log item like a state change or a clock entry is associated with
1200 notes, the first line of these notes will be added to the entry in the
1201 agenda display."
1202 :group 'org-agenda-daily/weekly
1203 :type 'boolean)
1205 (defcustom org-agenda-start-with-log-mode nil
1206 "The initial value of log-mode in a newly created agenda window."
1207 :group 'org-agenda-startup
1208 :group 'org-agenda-daily/weekly
1209 :type 'boolean)
1211 (defcustom org-agenda-start-with-clockreport-mode nil
1212 "The initial value of clockreport-mode in a newly created agenda window."
1213 :group 'org-agenda-startup
1214 :group 'org-agenda-daily/weekly
1215 :type 'boolean)
1217 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1218 "Property list with parameters for the clocktable in clockreport mode.
1219 This is the display mode that shows a clock table in the daily/weekly
1220 agenda, the properties for this dynamic block can be set here.
1221 The usual clocktable parameters are allowed here, but you cannot set
1222 the properties :name, :tstart, :tend, :block, and :scope - these will
1223 be overwritten to make sure the content accurately reflects the
1224 current display in the agenda."
1225 :group 'org-agenda-daily/weekly
1226 :type 'plist)
1228 (defcustom org-agenda-search-view-always-boolean nil
1229 "Non-nil means the search string is interpreted as individual parts.
1231 The search string for search view can either be interpreted as a phrase,
1232 or as a list of snippets that define a boolean search for a number of
1233 strings.
1235 When this is non-nil, the string will be split on whitespace, and each
1236 snippet will be searched individually, and all must match in order to
1237 select an entry. A snippet is then a single string of non-white
1238 characters, or a string in double quotes, or a regexp in {} braces.
1239 If a snippet is preceded by \"-\", the snippet must *not* match.
1240 \"+\" is syntactic sugar for positive selection. Each snippet may
1241 be found as a full word or a partial word, but see the variable
1242 `org-agenda-search-view-force-full-words'.
1244 When this is nil, search will look for the entire search phrase as one,
1245 with each space character matching any amount of whitespace, including
1246 line breaks.
1248 Even when this is nil, you can still switch to Boolean search dynamically
1249 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1250 is a regexp marked with braces like \"{abc}\", this will also switch to
1251 boolean search."
1252 :group 'org-agenda-search-view
1253 :version "24.1"
1254 :type 'boolean)
1256 (if (fboundp 'defvaralias)
1257 (defvaralias 'org-agenda-search-view-search-words-only
1258 'org-agenda-search-view-always-boolean))
1260 (defcustom org-agenda-search-view-force-full-words nil
1261 "Non-nil means, search words must be matches as complete words.
1262 When nil, they may also match part of a word."
1263 :group 'org-agenda-search-view
1264 :version "24.1"
1265 :type 'boolean)
1267 (defgroup org-agenda-time-grid nil
1268 "Options concerning the time grid in the Org-mode Agenda."
1269 :tag "Org Agenda Time Grid"
1270 :group 'org-agenda)
1272 (defcustom org-agenda-search-headline-for-time t
1273 "Non-nil means search headline for a time-of-day.
1274 If the headline contains a time-of-day in one format or another, it will
1275 be used to sort the entry into the time sequence of items for a day.
1276 Some people have time stamps in the headline that refer to the creation
1277 time or so, and then this produces an unwanted side effect. If this is
1278 the case for your, use this variable to turn off searching the headline
1279 for a time."
1280 :group 'org-agenda-time-grid
1281 :type 'boolean)
1283 (defcustom org-agenda-use-time-grid t
1284 "Non-nil means show a time grid in the agenda schedule.
1285 A time grid is a set of lines for specific times (like every two hours between
1286 8:00 and 20:00). The items scheduled for a day at specific times are
1287 sorted in between these lines.
1288 For details about when the grid will be shown, and what it will look like, see
1289 the variable `org-agenda-time-grid'."
1290 :group 'org-agenda-time-grid
1291 :type 'boolean)
1293 (defcustom org-agenda-time-grid
1294 '((daily today require-timed)
1295 "----------------"
1296 (800 1000 1200 1400 1600 1800 2000))
1298 "The settings for time grid for agenda display.
1299 This is a list of three items. The first item is again a list. It contains
1300 symbols specifying conditions when the grid should be displayed:
1302 daily if the agenda shows a single day
1303 weekly if the agenda shows an entire week
1304 today show grid on current date, independent of daily/weekly display
1305 require-timed show grid only if at least one item has a time specification
1307 The second item is a string which will be placed behind the grid time.
1309 The third item is a list of integers, indicating the times that should have
1310 a grid line."
1311 :group 'org-agenda-time-grid
1312 :type
1313 '(list
1314 (set :greedy t :tag "Grid Display Options"
1315 (const :tag "Show grid in single day agenda display" daily)
1316 (const :tag "Show grid in weekly agenda display" weekly)
1317 (const :tag "Always show grid for today" today)
1318 (const :tag "Show grid only if any timed entries are present"
1319 require-timed)
1320 (const :tag "Skip grid times already present in an entry"
1321 remove-match))
1322 (string :tag "Grid String")
1323 (repeat :tag "Grid Times" (integer :tag "Time"))))
1325 (defcustom org-agenda-show-current-time-in-grid t
1326 "Non-nil means show the current time in the time grid."
1327 :group 'org-agenda-time-grid
1328 :version "24.1"
1329 :type 'boolean)
1331 (defcustom org-agenda-current-time-string
1332 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1333 "The string for the current time marker in the agenda."
1334 :group 'org-agenda-time-grid
1335 :version "24.1"
1336 :type 'string)
1338 (defgroup org-agenda-sorting nil
1339 "Options concerning sorting in the Org-mode Agenda."
1340 :tag "Org Agenda Sorting"
1341 :group 'org-agenda)
1343 (defcustom org-agenda-sorting-strategy
1344 '((agenda habit-down time-up priority-down category-keep)
1345 (todo priority-down category-keep)
1346 (tags priority-down category-keep)
1347 (search category-keep))
1348 "Sorting structure for the agenda items of a single day.
1349 This is a list of symbols which will be used in sequence to determine
1350 if an entry should be listed before another entry. The following
1351 symbols are recognized:
1353 time-up Put entries with time-of-day indications first, early first
1354 time-down Put entries with time-of-day indications first, late first
1355 category-keep Keep the default order of categories, corresponding to the
1356 sequence in `org-agenda-files'.
1357 category-up Sort alphabetically by category, A-Z.
1358 category-down Sort alphabetically by category, Z-A.
1359 tag-up Sort alphabetically by last tag, A-Z.
1360 tag-down Sort alphabetically by last tag, Z-A.
1361 priority-up Sort numerically by priority, high priority last.
1362 priority-down Sort numerically by priority, high priority first.
1363 todo-state-up Sort by todo state, tasks that are done last.
1364 todo-state-down Sort by todo state, tasks that are done first.
1365 effort-up Sort numerically by estimated effort, high effort last.
1366 effort-down Sort numerically by estimated effort, high effort first.
1367 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1368 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1369 habit-up Put entries that are habits first
1370 habit-down Put entries that are habits last
1371 alpha-up Sort headlines alphabetically
1372 alpha-down Sort headlines alphabetically, reversed
1374 The different possibilities will be tried in sequence, and testing stops
1375 if one comparison returns a \"not-equal\". For example, the default
1376 '(time-up category-keep priority-down)
1377 means: Pull out all entries having a specified time of day and sort them,
1378 in order to make a time schedule for the current day the first thing in the
1379 agenda listing for the day. Of the entries without a time indication, keep
1380 the grouped in categories, don't sort the categories, but keep them in
1381 the sequence given in `org-agenda-files'. Within each category sort by
1382 priority.
1384 Leaving out `category-keep' would mean that items will be sorted across
1385 categories by priority.
1387 Instead of a single list, this can also be a set of list for specific
1388 contents, with a context symbol in the car of the list, any of
1389 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1391 Custom commands can bind this variable in the options section."
1392 :group 'org-agenda-sorting
1393 :type `(choice
1394 (repeat :tag "General" ,org-sorting-choice)
1395 (list :tag "Individually"
1396 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1397 (repeat ,org-sorting-choice))
1398 (cons (const :tag "Strategy for TODO lists" todo)
1399 (repeat ,org-sorting-choice))
1400 (cons (const :tag "Strategy for Tags matches" tags)
1401 (repeat ,org-sorting-choice))
1402 (cons (const :tag "Strategy for search matches" search)
1403 (repeat ,org-sorting-choice)))))
1405 (defcustom org-agenda-cmp-user-defined nil
1406 "A function to define the comparison `user-defined'.
1407 This function must receive two arguments, agenda entry a and b.
1408 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1409 the user comparison, return nil.
1410 When this is defined, you can make `user-defined-up' and `user-defined-down'
1411 part of an agenda sorting strategy."
1412 :group 'org-agenda-sorting
1413 :type 'symbol)
1415 (defcustom org-sort-agenda-notime-is-late t
1416 "Non-nil means items without time are considered late.
1417 This is only relevant for sorting. When t, items which have no explicit
1418 time like 15:30 will be considered as 99:01, i.e. later than any items which
1419 do have a time. When nil, the default time is before 0:00. You can use this
1420 option to decide if the schedule for today should come before or after timeless
1421 agenda entries."
1422 :group 'org-agenda-sorting
1423 :type 'boolean)
1425 (defcustom org-sort-agenda-noeffort-is-high t
1426 "Non-nil means items without effort estimate are sorted as high effort.
1427 This also applies when filtering an agenda view with respect to the
1428 < or > effort operator. Then, tasks with no effort defined will be treated
1429 as tasks with high effort.
1430 When nil, such items are sorted as 0 minutes effort."
1431 :group 'org-agenda-sorting
1432 :type 'boolean)
1434 (defgroup org-agenda-line-format nil
1435 "Options concerning the entry prefix in the Org-mode agenda display."
1436 :tag "Org Agenda Line Format"
1437 :group 'org-agenda)
1439 (defcustom org-agenda-prefix-format
1440 '((agenda . " %i %-12:c%?-12t% s")
1441 (timeline . " % s")
1442 (todo . " %i %-12:c")
1443 (tags . " %i %-12:c")
1444 (search . " %i %-12:c"))
1445 "Format specifications for the prefix of items in the agenda views.
1446 An alist with five entries, each for the different agenda types. The
1447 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1448 The values are format strings.
1450 This format works similar to a printf format, with the following meaning:
1452 %c the category of the item, \"Diary\" for entries from the diary,
1453 or as given by the CATEGORY keyword or derived from the file name
1454 %e the effort required by the item
1455 %i the icon category of the item, see `org-agenda-category-icon-alist'
1456 %T the last tag of the item (ignore inherited tags, which come first)
1457 %t the HH:MM time-of-day specification if one applies to the entry
1458 %s Scheduling/Deadline information, a short string
1459 %(expression) Eval EXPRESSION and replace the control string
1460 by the result
1462 All specifiers work basically like the standard `%s' of printf, but may
1463 contain two additional characters: a question mark just after the `%'
1464 and a whitespace/punctuation character just before the final letter.
1466 If the first character after `%' is a question mark, the entire field
1467 will only be included if the corresponding value applies to the current
1468 entry. This is useful for fields which should have fixed width when
1469 present, but zero width when absent. For example, \"%?-12t\" will
1470 result in a 12 character time field if a time of the day is specified,
1471 but will completely disappear in entries which do not contain a time.
1473 If there is punctuation or whitespace character just before the final
1474 format letter, this character will be appended to the field value if
1475 the value is not empty. For example, the format \"%-12:c\" leads to
1476 \"Diary: \" if the category is \"Diary\". If the category were be
1477 empty, no additional colon would be inserted.
1479 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1480 which means:
1482 - Indent the line with two space characters
1483 - Give the category a 12 chars wide field, padded with whitespace on
1484 the right (because of `-'). Append a colon if there is a category
1485 (because of `:').
1486 - If there is a time-of-day, put it into a 12 chars wide field. If no
1487 time, don't put in an empty field, just skip it (because of '?').
1488 - Finally, put the scheduling information.
1490 See also the variables `org-agenda-remove-times-when-in-prefix' and
1491 `org-agenda-remove-tags'.
1493 Custom commands can set this variable in the options section."
1494 :type '(choice
1495 (string :tag "General format")
1496 (list :greedy t :tag "View dependent"
1497 (cons (const agenda) (string :tag "Format"))
1498 (cons (const timeline) (string :tag "Format"))
1499 (cons (const todo) (string :tag "Format"))
1500 (cons (const tags) (string :tag "Format"))
1501 (cons (const search) (string :tag "Format"))))
1502 :group 'org-agenda-line-format)
1504 (defvar org-prefix-format-compiled nil
1505 "The compiled prefix format and associated variables.
1506 This is a list where first element is a list of variable bindings, and second
1507 element is the compiled format expression. See the variable
1508 `org-agenda-prefix-format'.")
1510 (defcustom org-agenda-todo-keyword-format "%-1s"
1511 "Format for the TODO keyword in agenda lines.
1512 Set this to something like \"%-12s\" if you want all TODO keywords
1513 to occupy a fixed space in the agenda display."
1514 :group 'org-agenda-line-format
1515 :type 'string)
1517 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1518 "Text preceding timerange entries in the agenda view.
1519 This is a list with two strings. The first applies when the range
1520 is entirely on one day. The second applies if the range spans several days.
1521 The strings may have two \"%d\" format specifiers which will be filled
1522 with the sequence number of the days, and the total number of days in the
1523 range, respectively."
1524 :group 'org-agenda-line-format
1525 :type '(list
1526 (string :tag "Deadline today ")
1527 (choice :tag "Deadline relative"
1528 (string :tag "Format string")
1529 (function))))
1531 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1532 "Text preceding scheduled items in the agenda view.
1533 This is a list with two strings. The first applies when the item is
1534 scheduled on the current day. The second applies when it has been scheduled
1535 previously, it may contain a %d indicating that this is the nth time that
1536 this item is scheduled, due to automatic rescheduling of unfinished items
1537 for the following day. So this number is one larger than the number of days
1538 that passed since this item was scheduled first."
1539 :group 'org-agenda-line-format
1540 :type '(list
1541 (string :tag "Scheduled today ")
1542 (string :tag "Scheduled previously")))
1544 (defcustom org-agenda-inactive-leader "["
1545 "Text preceding item pulled into the agenda by inactive time stamps.
1546 These entries are added to the agenda when pressing \"[\"."
1547 :group 'org-agenda-line-format
1548 :version "24.1"
1549 :type '(list
1550 (string :tag "Scheduled today ")
1551 (string :tag "Scheduled previously")))
1553 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1554 "Text preceding deadline items in the agenda view.
1555 This is a list with two strings. The first applies when the item has its
1556 deadline on the current day. The second applies when it is in the past or
1557 in the future, it may contain %d to capture how many days away the deadline
1558 is (was)."
1559 :group 'org-agenda-line-format
1560 :type '(list
1561 (string :tag "Deadline today ")
1562 (choice :tag "Deadline relative"
1563 (string :tag "Format string")
1564 (function))))
1566 (defcustom org-agenda-remove-times-when-in-prefix t
1567 "Non-nil means remove duplicate time specifications in agenda items.
1568 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1569 time-of-day specification in a headline or diary entry is extracted and
1570 placed into the prefix. If this option is non-nil, the original specification
1571 \(a timestamp or -range, or just a plain time(range) specification like
1572 11:30-4pm) will be removed for agenda display. This makes the agenda less
1573 cluttered.
1574 The option can be t or nil. It may also be the symbol `beg', indicating
1575 that the time should only be removed when it is located at the beginning of
1576 the headline/diary entry."
1577 :group 'org-agenda-line-format
1578 :type '(choice
1579 (const :tag "Always" t)
1580 (const :tag "Never" nil)
1581 (const :tag "When at beginning of entry" beg)))
1583 (defcustom org-agenda-remove-timeranges-from-blocks nil
1584 "Non-nil means remove time ranges specifications in agenda
1585 items that span on several days."
1586 :group 'org-agenda-line-format
1587 :version "24.1"
1588 :type 'boolean)
1590 (defcustom org-agenda-default-appointment-duration nil
1591 "Default duration for appointments that only have a starting time.
1592 When nil, no duration is specified in such cases.
1593 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1594 :group 'org-agenda-line-format
1595 :type '(choice
1596 (integer :tag "Minutes")
1597 (const :tag "No default duration")))
1599 (defcustom org-agenda-show-inherited-tags t
1600 "Non-nil means show inherited tags in each agenda line."
1601 :group 'org-agenda-line-format
1602 :type 'boolean)
1604 (defcustom org-agenda-hide-tags-regexp nil
1605 "Regular expression used to filter away specific tags in agenda views.
1606 This means that these tags will be present, but not be shown in the agenda
1607 line. Secondary filtering will still work on the hidden tags.
1608 Nil means don't hide any tags."
1609 :group 'org-agenda-line-format
1610 :type '(choice
1611 (const :tag "Hide none" nil)
1612 (string :tag "Regexp ")))
1614 (defcustom org-agenda-remove-tags nil
1615 "Non-nil means remove the tags from the headline copy in the agenda.
1616 When this is the symbol `prefix', only remove tags when
1617 `org-agenda-prefix-format' contains a `%T' specifier."
1618 :group 'org-agenda-line-format
1619 :type '(choice
1620 (const :tag "Always" t)
1621 (const :tag "Never" nil)
1622 (const :tag "When prefix format contains %T" prefix)))
1624 (if (fboundp 'defvaralias)
1625 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1626 'org-agenda-remove-tags))
1628 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1629 "Shift tags in agenda items to this column.
1630 If this number is positive, it specifies the column. If it is negative,
1631 it means that the tags should be flushright to that column. For example,
1632 -80 works well for a normal 80 character screen."
1633 :group 'org-agenda-line-format
1634 :type 'integer)
1636 (if (fboundp 'defvaralias)
1637 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1639 (defcustom org-agenda-fontify-priorities 'cookies
1640 "Non-nil means highlight low and high priorities in agenda.
1641 When t, the highest priority entries are bold, lowest priority italic.
1642 However, settings in `org-priority-faces' will overrule these faces.
1643 When this variable is the symbol `cookies', only fontify the
1644 cookies, not the entire task.
1645 This may also be an association list of priority faces, whose
1646 keys are the character values of `org-highest-priority',
1647 `org-default-priority', and `org-lowest-priority' (the default values
1648 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1649 color as a string, or a list like `(:background \"Red\")'.
1650 If it is a color, the variable `org-faces-easy-properties'
1651 determines if it is a foreground or a background color."
1652 :group 'org-agenda-line-format
1653 :type '(choice
1654 (const :tag "Never" nil)
1655 (const :tag "Defaults" t)
1656 (const :tag "Cookies only" cookies)
1657 (repeat :tag "Specify"
1658 (list (character :tag "Priority" :value ?A)
1659 (choice :tag "Face "
1660 (string :tag "Color")
1661 (sexp :tag "Face"))))))
1663 (defcustom org-agenda-day-face-function nil
1664 "Function called to determine what face should be used to display a day.
1665 The only argument passed to that function is the day. It should
1666 returns a face, or nil if does not want to specify a face and let
1667 the normal rules apply."
1668 :group 'org-agenda-line-format
1669 :version "24.1"
1670 :type 'function)
1672 (defcustom org-agenda-category-icon-alist nil
1673 "Alist of category icon to be displayed in agenda views.
1675 Each entry should have the following format:
1677 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1679 Where CATEGORY-REGEXP is a regexp matching the categories where
1680 the icon should be displayed.
1681 FILE-OR-DATA either a file path or a string containing image data.
1683 The other fields can be omitted safely if not needed:
1684 TYPE indicates the image type.
1685 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1686 image data.
1687 PROPS are additional image attributes to assign to the image,
1688 like, e.g. `:ascent center'.
1690 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1692 If you want to set the display properties yourself, just put a
1693 list as second element:
1695 (CATEGORY-REGEXP (MY PROPERTY LIST))
1697 For example, to display a 16px horizontal space for Emacs
1698 category, you can use:
1700 (\"Emacs\" '(space . (:width (16))))"
1701 :group 'org-agenda-line-format
1702 :version "24.1"
1703 :type '(alist :key-type (string :tag "Regexp matching category")
1704 :value-type (choice (list :tag "Icon"
1705 (string :tag "File or data")
1706 (symbol :tag "Type")
1707 (boolean :tag "Data?")
1708 (repeat :tag "Extra image properties" :inline t symbol))
1709 (list :tag "Display properties" sexp))))
1711 (defgroup org-agenda-column-view nil
1712 "Options concerning column view in the agenda."
1713 :tag "Org Agenda Column View"
1714 :group 'org-agenda)
1716 (defcustom org-agenda-columns-show-summaries t
1717 "Non-nil means show summaries for columns displayed in the agenda view."
1718 :group 'org-agenda-column-view
1719 :type 'boolean)
1721 (defcustom org-agenda-columns-compute-summary-properties t
1722 "Non-nil means recompute all summary properties before column view.
1723 When column view in the agenda is listing properties that have a summary
1724 operator, it can go to all relevant buffers and recompute the summaries
1725 there. This can mean overhead for the agenda column view, but is necessary
1726 to have thing up to date.
1727 As a special case, a CLOCKSUM property also makes sure that the clock
1728 computations are current."
1729 :group 'org-agenda-column-view
1730 :type 'boolean)
1732 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1733 "Non-nil means the duration of an appointment will add to day effort.
1734 The property to which appointment durations will be added is the one given
1735 in the option `org-effort-property'. If an appointment does not have
1736 an end time, `org-agenda-default-appointment-duration' will be used. If that
1737 is not set, an appointment without end time will not contribute to the time
1738 estimate."
1739 :group 'org-agenda-column-view
1740 :type 'boolean)
1742 (defcustom org-agenda-auto-exclude-function nil
1743 "A function called with a tag to decide if it is filtered on '/ RET'.
1744 The sole argument to the function, which is called once for each
1745 possible tag, is a string giving the name of the tag. The
1746 function should return either nil if the tag should be included
1747 as normal, or \"-<TAG>\" to exclude the tag.
1748 Note that for the purpose of tag filtering, only the lower-case version of
1749 all tags will be considered, so that this function will only ever see
1750 the lower-case version of all tags."
1751 :group 'org-agenda
1752 :type 'function)
1754 (defcustom org-agenda-bulk-custom-functions nil
1755 "Alist of characters and custom functions for bulk actions.
1756 For example, this value makes those two functions available:
1758 '((?R set-category)
1759 (?C bulk-cut))
1761 With selected entries in an agenda buffer, `B R' will call
1762 the custom function `set-category' on the selected entries.
1763 Note that functions in this alist don't need to be quoted."
1764 :type 'alist
1765 :version "24.1"
1766 :group 'org-agenda)
1768 (eval-when-compile
1769 (require 'cl))
1770 (require 'org)
1772 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1773 "Execute BODY with point at location given by `org-hd-marker' property.
1774 If STRING is non-nil, the text property will be fetched from position 0
1775 in that string. If STRING is nil, it will be fetched from the beginning
1776 of the current line."
1777 (org-with-gensyms (marker)
1778 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1779 'org-hd-marker ,string)))
1780 (with-current-buffer (marker-buffer ,marker)
1781 (save-excursion
1782 (goto-char ,marker)
1783 ,@body)))))
1784 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1786 (defun org-add-agenda-custom-command (entry)
1787 "Replace or add a command in `org-agenda-custom-commands'.
1788 This is mostly for hacking and trying a new command - once the command
1789 works you probably want to add it to `org-agenda-custom-commands' for good."
1790 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1791 (if ass
1792 (setcdr ass (cdr entry))
1793 (push entry org-agenda-custom-commands))))
1795 ;;; Define the org-agenda-mode
1797 (defvar org-agenda-mode-map (make-sparse-keymap)
1798 "Keymap for `org-agenda-mode'.")
1799 (if (fboundp 'defvaralias)
1800 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1802 (defvar org-agenda-menu) ; defined later in this file.
1803 (defvar org-agenda-restrict) ; defined later in this file.
1804 (defvar org-agenda-follow-mode nil)
1805 (defvar org-agenda-entry-text-mode nil)
1806 (defvar org-agenda-clockreport-mode nil)
1807 (defvar org-agenda-show-log nil)
1808 (defvar org-agenda-show-scoped nil) ; Used for dynamically scoping
1809 (defvar org-agenda-redo-command nil)
1810 (defvar org-agenda-query-string nil)
1811 (defvar org-agenda-mode-hook nil
1812 "Hook for `org-agenda-mode', run after the mode is turned on.")
1813 (defvar org-agenda-type nil)
1814 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1817 ;;; Multiple agenda buffers support
1819 (defun org-toggle-sticky-agenda (&optional arg)
1820 "Toggle `org-agenda-sticky'."
1821 (interactive "P")
1822 (let ((new-value (if arg
1823 (> (prefix-numeric-value arg) 0)
1824 (not org-agenda-sticky))))
1825 (if (equal new-value org-agenda-sticky)
1826 (message "Sticky agenda was already %s"
1827 (if org-agenda-sticky "enabled" "disabled"))
1828 (setq org-agenda-sticky new-value)
1829 (org-agenda-kill-all-agenda-buffers)
1830 (message "Sticky agenda was %s"
1831 (if org-agenda-sticky "enabled" "disabled")))))
1833 (defcustom org-agenda-sticky nil
1834 "Non-nil means agenda q key will bury agenda buffers.
1835 Agenda commands will then show existing buffer instead of generating new ones.
1836 When nil, `q' will kill the single agenda buffer."
1837 :group 'org-agenda
1838 :type 'boolean
1839 :set (lambda (var val)
1840 (if (boundp var)
1841 (org-toggle-sticky-agenda (if val 1 0))
1842 (set var val))))
1844 (defvar org-agenda-buffer nil
1845 "Agenda buffer currently being generated.")
1847 (defvar org-agenda-last-prefix-arg nil)
1848 (defvar org-agenda-this-buffer-name nil)
1849 (defvar org-agenda-doing-sticky-redo nil)
1850 (defvar org-agenda-this-buffer-is-sticky nil)
1852 (defconst org-agenda-local-vars
1853 '(org-agenda-this-buffer-name
1854 org-agenda-undo-list
1855 org-agenda-pending-undo-list
1856 org-agenda-follow-mode
1857 org-agenda-entry-text-mode
1858 org-agenda-clockreport-mode
1859 org-agenda-show-log
1860 org-agenda-redo-command
1861 org-agenda-query-string
1862 org-agenda-type
1863 org-agenda-bulk-marked-entries
1864 org-agenda-undo-has-started-in
1865 org-agenda-last-arguments
1866 org-agenda-info
1867 org-agenda-tag-filter-overlays
1868 org-agenda-cat-filter-overlays
1869 org-pre-agenda-window-conf
1870 org-agenda-columns-active
1871 org-agenda-tag-filter
1872 org-agenda-category-filter
1873 org-agenda-markers
1874 org-agenda-last-search-view-search-was-boolean
1875 org-agenda-filtered-by-category
1876 org-agenda-filter-form
1877 org-agenda-show-window
1878 org-agenda-cycle-counter
1879 org-agenda-last-prefix-arg)
1880 "Variables that must be local in agenda buffers to allow multiple buffers.")
1882 (defun org-agenda-mode ()
1883 "Mode for time-sorted view on action items in Org-mode files.
1885 The following commands are available:
1887 \\{org-agenda-mode-map}"
1888 (interactive)
1889 (cond (org-agenda-doing-sticky-redo
1890 ;; Refreshing sticky agenda-buffer
1892 ;; Preserve the value of `org-agenda-local-vars' variables,
1893 ;; while letting `kill-all-local-variables' kill the rest
1894 (let ((save (buffer-local-variables)))
1895 (kill-all-local-variables)
1896 (mapc 'make-local-variable org-agenda-local-vars)
1897 (dolist (elem save)
1898 (let ((var (car elem))
1899 (val (cdr elem)))
1900 (when (and val
1901 (member var org-agenda-local-vars))
1902 (set var val)))))
1903 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1904 (org-agenda-sticky
1905 ;; Creating a sticky Agenda buffer for the first time
1906 (kill-all-local-variables)
1907 (mapc 'make-local-variable org-agenda-local-vars)
1908 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1910 ;; Creating a non-sticky agenda buffer
1911 (kill-all-local-variables)
1912 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1913 (setq org-agenda-undo-list nil
1914 org-agenda-pending-undo-list nil
1915 org-agenda-bulk-marked-entries nil)
1916 (setq major-mode 'org-agenda-mode)
1917 ;; Keep global-font-lock-mode from turning on font-lock-mode
1918 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1919 (setq mode-name "Org-Agenda")
1920 (use-local-map org-agenda-mode-map)
1921 (easy-menu-add org-agenda-menu)
1922 (if org-startup-truncated (setq truncate-lines t))
1923 (org-set-local 'line-move-visual nil)
1924 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1925 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1926 ;; Make sure properties are removed when copying text
1927 (when (boundp 'buffer-substring-filters)
1928 (org-set-local 'buffer-substring-filters
1929 (cons (lambda (x)
1930 (set-text-properties 0 (length x) nil x) x)
1931 buffer-substring-filters)))
1932 (unless org-agenda-keep-modes
1933 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1934 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1935 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1936 org-agenda-show-log org-agenda-start-with-log-mode))
1938 (easy-menu-change
1939 '("Agenda") "Agenda Files"
1940 (append
1941 (list
1942 (vector
1943 (if (get 'org-agenda-files 'org-restrict)
1944 "Restricted to single file"
1945 "Edit File List")
1946 '(org-edit-agenda-file-list)
1947 (not (get 'org-agenda-files 'org-restrict)))
1948 "--")
1949 (mapcar 'org-file-menu-entry (org-agenda-files))))
1950 (org-agenda-set-mode-name)
1951 (apply
1952 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1953 (list 'org-agenda-mode-hook)))
1955 (substitute-key-definition 'undo 'org-agenda-undo
1956 org-agenda-mode-map global-map)
1957 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1958 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1959 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1960 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1961 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1962 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1963 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
1964 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1965 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1966 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
1967 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1968 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1969 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1970 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1971 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1972 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1973 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1974 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1975 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1976 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1977 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1978 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1979 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1980 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1981 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1982 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1983 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1984 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1985 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1986 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1987 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1988 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1989 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1990 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1991 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1992 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1993 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1994 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1995 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1996 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1997 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1998 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1999 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2000 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2001 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2003 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2004 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2005 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2006 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2007 (while l (org-defkey org-agenda-mode-map
2008 (int-to-string (pop l)) 'digit-argument)))
2010 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2011 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2012 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2013 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2014 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2015 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2016 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2017 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2018 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2019 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
2020 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2021 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2022 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2023 'org-clock-modify-effort-estimate)
2024 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2025 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2026 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2027 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2028 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2029 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2030 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2031 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
2032 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2033 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2034 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2035 (substitute-key-definition 'next-line 'org-agenda-next-line
2036 org-agenda-mode-map global-map)
2037 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2038 org-agenda-mode-map global-map)
2039 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2040 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2041 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2042 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2043 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2044 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2045 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2046 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2047 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2048 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2049 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2050 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2051 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2052 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2053 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2054 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2055 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2056 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2057 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2058 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2059 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2060 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2061 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2062 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2063 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2064 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2065 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2066 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2067 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2068 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2070 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2071 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2072 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2073 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2074 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2075 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2076 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2077 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2078 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2079 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2080 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2082 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2083 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2084 (when org-agenda-mouse-1-follows-link
2085 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2086 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2087 '("Agenda"
2088 ("Agenda Files")
2089 "--"
2090 ("Agenda Dates"
2091 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2092 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2093 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2094 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2095 "--"
2096 ("View"
2097 ["Day View" org-agenda-day-view
2098 :active (org-agenda-check-type nil 'agenda)
2099 :style radio :selected (eq org-agenda-current-span 'day)
2100 :keys "v d (or just d)"]
2101 ["Week View" org-agenda-week-view
2102 :active (org-agenda-check-type nil 'agenda)
2103 :style radio :selected (eq org-agenda-current-span 'week)
2104 :keys "v w (or just w)"]
2105 ["Month View" org-agenda-month-view
2106 :active (org-agenda-check-type nil 'agenda)
2107 :style radio :selected (eq org-agenda-current-span 'month)
2108 :keys "v m"]
2109 ["Year View" org-agenda-year-view
2110 :active (org-agenda-check-type nil 'agenda)
2111 :style radio :selected (eq org-agenda-current-span 'year)
2112 :keys "v y"]
2113 "--"
2114 ["Include Diary" org-agenda-toggle-diary
2115 :style toggle :selected org-agenda-include-diary
2116 :active (org-agenda-check-type nil 'agenda)]
2117 ["Include Deadlines" org-agenda-toggle-deadlines
2118 :style toggle :selected org-agenda-include-deadlines
2119 :active (org-agenda-check-type nil 'agenda)]
2120 ["Use Time Grid" org-agenda-toggle-time-grid
2121 :style toggle :selected org-agenda-use-time-grid
2122 :active (org-agenda-check-type nil 'agenda)]
2123 "--"
2124 ["Show clock report" org-agenda-clockreport-mode
2125 :style toggle :selected org-agenda-clockreport-mode
2126 :active (org-agenda-check-type nil 'agenda)]
2127 ["Show some entry text" org-agenda-entry-text-mode
2128 :style toggle :selected org-agenda-entry-text-mode
2129 :active t]
2130 "--"
2131 ["Show Logbook entries" org-agenda-log-mode
2132 :style toggle :selected org-agenda-show-log
2133 :active (org-agenda-check-type nil 'agenda 'timeline)
2134 :keys "v l (or just l)"]
2135 ["Include archived trees" org-agenda-archives-mode
2136 :style toggle :selected org-agenda-archives-mode :active t
2137 :keys "v a"]
2138 ["Include archive files" (org-agenda-archives-mode t)
2139 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2140 :keys "v A"]
2141 "--"
2142 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2143 ["Write view to file" org-agenda-write t]
2144 ["Rebuild buffer" org-agenda-redo t]
2145 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2146 "--"
2147 ["Show original entry" org-agenda-show t]
2148 ["Go To (other window)" org-agenda-goto t]
2149 ["Go To (this window)" org-agenda-switch-to t]
2150 ["Follow Mode" org-agenda-follow-mode
2151 :style toggle :selected org-agenda-follow-mode :active t]
2152 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2153 "--"
2154 ("TODO"
2155 ["Cycle TODO" org-agenda-todo t]
2156 ["Next TODO set" org-agenda-todo-nextset t]
2157 ["Previous TODO set" org-agenda-todo-previousset t]
2158 ["Add note" org-agenda-add-note t])
2159 ("Archive/Refile/Delete"
2160 ["Archive default" org-agenda-archive-default t]
2161 ["Archive default" org-agenda-archive-default-with-confirmation t]
2162 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2163 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2164 ["Archive subtree" org-agenda-archive t]
2165 "--"
2166 ["Refile" org-agenda-refile t]
2167 "--"
2168 ["Delete subtree" org-agenda-kill t])
2169 ("Bulk action"
2170 ["Mark entry" org-agenda-bulk-mark t]
2171 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2172 ["Unmark entry" org-agenda-bulk-unmark t]
2173 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
2174 ["Act on all marked" org-agenda-bulk-action t]
2175 "--"
2176 ("Tags and Properties"
2177 ["Show all Tags" org-agenda-show-tags t]
2178 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2179 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2180 "--"
2181 ["Column View" org-columns t])
2182 ("Deadline/Schedule"
2183 ["Schedule" org-agenda-schedule t]
2184 ["Set Deadline" org-agenda-deadline t]
2185 "--"
2186 ["Mark item" org-agenda-action :active t :keys "k m"]
2187 ["Show mark item" org-agenda-action :active t :keys "k v"]
2188 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2189 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2190 "--"
2191 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2192 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2193 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2194 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2195 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2196 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2197 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2198 ("Clock and Effort"
2199 ["Clock in" org-agenda-clock-in t]
2200 ["Clock out" org-agenda-clock-out t]
2201 ["Clock cancel" org-agenda-clock-cancel t]
2202 ["Goto running clock" org-clock-goto t]
2203 "--"
2204 ["Set Effort" org-agenda-set-effort t]
2205 ["Change clocked effort" org-clock-modify-effort-estimate
2206 (org-clock-is-active)])
2207 ("Priority"
2208 ["Set Priority" org-agenda-priority t]
2209 ["Increase Priority" org-agenda-priority-up t]
2210 ["Decrease Priority" org-agenda-priority-down t]
2211 ["Show Priority" org-agenda-show-priority t])
2212 ("Calendar/Diary"
2213 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2214 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2215 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2216 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2217 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2218 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2219 "--"
2220 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2221 "--"
2222 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2223 "--"
2224 ("MobileOrg"
2225 ["Push Files and Views" org-mobile-push t]
2226 ["Get Captured and Flagged" org-mobile-pull t]
2227 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2228 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2229 "--"
2230 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2231 "--"
2232 ["Quit" org-agenda-quit t]
2233 ["Exit and Release Buffers" org-agenda-exit t]
2236 ;;; Agenda undo
2238 (defvar org-agenda-allow-remote-undo t
2239 "Non-nil means allow remote undo from the agenda buffer.")
2240 (defvar org-agenda-undo-list nil
2241 "List of undoable operations in the agenda since last refresh.")
2242 (defvar org-agenda-undo-has-started-in nil
2243 "Buffers that have already seen `undo-start' in the current undo sequence.")
2244 (defvar org-agenda-pending-undo-list nil
2245 "In a series of undo commands, this is the list of remaining undo items.")
2247 (defun org-agenda-undo ()
2248 "Undo a remote editing step in the agenda.
2249 This undoes changes both in the agenda buffer and in the remote buffer
2250 that have been changed along."
2251 (interactive)
2252 (or org-agenda-allow-remote-undo
2253 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2254 (if (not (eq this-command last-command))
2255 (setq org-agenda-undo-has-started-in nil
2256 org-agenda-pending-undo-list org-agenda-undo-list))
2257 (if (not org-agenda-pending-undo-list)
2258 (error "No further undo information"))
2259 (let* ((entry (pop org-agenda-pending-undo-list))
2260 buf line cmd rembuf)
2261 (setq cmd (pop entry) line (pop entry))
2262 (setq rembuf (nth 2 entry))
2263 (org-with-remote-undo rembuf
2264 (while (bufferp (setq buf (pop entry)))
2265 (if (pop entry)
2266 (with-current-buffer buf
2267 (let ((last-undo-buffer buf)
2268 (inhibit-read-only t))
2269 (unless (memq buf org-agenda-undo-has-started-in)
2270 (push buf org-agenda-undo-has-started-in)
2271 (make-local-variable 'pending-undo-list)
2272 (undo-start))
2273 (while (and pending-undo-list
2274 (listp pending-undo-list)
2275 (not (car pending-undo-list)))
2276 (pop pending-undo-list))
2277 (undo-more 1))))))
2278 (org-goto-line line)
2279 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2281 (defun org-verify-change-for-undo (l1 l2)
2282 "Verify that a real change occurred between the undo lists L1 and L2."
2283 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2284 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2285 (not (eq l1 l2)))
2287 ;;; Agenda dispatch
2289 (defvar org-agenda-restrict nil)
2290 (defvar org-agenda-restrict-begin (make-marker))
2291 (defvar org-agenda-restrict-end (make-marker))
2292 (defvar org-agenda-last-dispatch-buffer nil)
2293 (defvar org-agenda-overriding-restriction nil)
2295 ;;;###autoload
2296 (defun org-agenda (&optional arg keys restriction)
2297 "Dispatch agenda commands to collect entries to the agenda buffer.
2298 Prompts for a command to execute. Any prefix arg will be passed
2299 on to the selected command. The default selections are:
2301 a Call `org-agenda-list' to display the agenda for current day or week.
2302 t Call `org-todo-list' to display the global todo list.
2303 T Call `org-todo-list' to display the global todo list, select only
2304 entries with a specific TODO keyword (the user gets a prompt).
2305 m Call `org-tags-view' to display headlines with tags matching
2306 a condition (the user is prompted for the condition).
2307 M Like `m', but select only TODO entries, no ordinary headlines.
2308 L Create a timeline for the current buffer.
2309 e Export views to associated files.
2310 s Search entries for keywords.
2311 / Multi occur across all agenda files and also files listed
2312 in `org-agenda-text-search-extra-files'.
2313 < Restrict agenda commands to buffer, subtree, or region.
2314 Press several times to get the desired effect.
2315 > Remove a previous restriction.
2316 # List \"stuck\" projects.
2317 ! Configure what \"stuck\" means.
2318 C Configure custom agenda commands.
2320 More commands can be added by configuring the variable
2321 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2322 searches can be pre-defined in this way.
2324 If the current buffer is in Org-mode and visiting a file, you can also
2325 first press `<' once to indicate that the agenda should be temporarily
2326 \(until the next use of \\[org-agenda]) restricted to the current file.
2327 Pressing `<' twice means to restrict to the current subtree or region
2328 \(if active)."
2329 (interactive "P")
2330 (catch 'exit
2331 (let* ((prefix-descriptions nil)
2332 (org-agenda-buffer-name org-agenda-buffer-name)
2333 (org-agenda-window-setup (if (equal (buffer-name)
2334 org-agenda-buffer-name)
2335 'current-window
2336 org-agenda-window-setup))
2337 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2338 (org-agenda-custom-commands
2339 ;; normalize different versions
2340 (delq nil
2341 (mapcar
2342 (lambda (x)
2343 (cond ((stringp (cdr x))
2344 (push x prefix-descriptions)
2345 nil)
2346 ((stringp (nth 1 x)) x)
2347 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2348 (t (cons (car x) (cons "" (cdr x))))))
2349 org-agenda-custom-commands)))
2350 (buf (current-buffer))
2351 (bfn (buffer-file-name (buffer-base-buffer)))
2352 entry key type match lprops ans)
2353 ;; Turn off restriction unless there is an overriding one,
2354 (unless org-agenda-overriding-restriction
2355 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2356 ;; There is a request to keep the file list in place
2357 (put 'org-agenda-files 'org-restrict nil))
2358 (setq org-agenda-restrict nil)
2359 (move-marker org-agenda-restrict-begin nil)
2360 (move-marker org-agenda-restrict-end nil))
2361 ;; Delete old local properties
2362 (put 'org-agenda-redo-command 'org-lprops nil)
2363 ;; Delete previously set last-arguments
2364 (put 'org-agenda-redo-command 'last-args nil)
2365 ;; Remember where this call originated
2366 (setq org-agenda-last-dispatch-buffer (current-buffer))
2367 (unless keys
2368 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2369 keys (car ans)
2370 restriction (cdr ans)))
2371 ;; If we have sticky agenda buffers, set a name for the buffer,
2372 ;; depending on the invoking keys. The user may still set this
2373 ;; as a command option, which will overwrite what we do here.
2374 (if org-agenda-sticky
2375 (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
2376 ;; Establish the restriction, if any
2377 (when (and (not org-agenda-overriding-restriction) restriction)
2378 (put 'org-agenda-files 'org-restrict (list bfn))
2379 (cond
2380 ((eq restriction 'region)
2381 (setq org-agenda-restrict t)
2382 (move-marker org-agenda-restrict-begin (region-beginning))
2383 (move-marker org-agenda-restrict-end (region-end)))
2384 ((eq restriction 'subtree)
2385 (save-excursion
2386 (setq org-agenda-restrict t)
2387 (org-back-to-heading t)
2388 (move-marker org-agenda-restrict-begin (point))
2389 (move-marker org-agenda-restrict-end
2390 (progn (org-end-of-subtree t)))))))
2392 ;; For example the todo list should not need it (but does...)
2393 (cond
2394 ((setq entry (assoc keys org-agenda-custom-commands))
2395 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2396 (progn
2397 (setq type (nth 2 entry) match (eval (nth 3 entry))
2398 lprops (nth 4 entry))
2399 (put 'org-agenda-redo-command 'org-lprops lprops)
2400 (cond
2401 ((eq type 'agenda)
2402 (org-let lprops '(org-agenda-list current-prefix-arg)))
2403 ((eq type 'alltodo)
2404 (org-let lprops '(org-todo-list current-prefix-arg)))
2405 ((eq type 'search)
2406 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2407 ((eq type 'stuck)
2408 (org-let lprops '(org-agenda-list-stuck-projects
2409 current-prefix-arg)))
2410 ((eq type 'tags)
2411 (org-let lprops '(org-tags-view current-prefix-arg match)))
2412 ((eq type 'tags-todo)
2413 (org-let lprops '(org-tags-view '(4) match)))
2414 ((eq type 'todo)
2415 (org-let lprops '(org-todo-list match)))
2416 ((eq type 'tags-tree)
2417 (org-check-for-org-mode)
2418 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2419 ((eq type 'todo-tree)
2420 (org-check-for-org-mode)
2421 (org-let lprops
2422 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2423 (regexp-quote match) "\\>"))))
2424 ((eq type 'occur-tree)
2425 (org-check-for-org-mode)
2426 (org-let lprops '(org-occur match)))
2427 ((functionp type)
2428 (org-let lprops '(funcall type match)))
2429 ((fboundp type)
2430 (org-let lprops '(funcall type match)))
2431 (t (error "Invalid custom agenda command type %s" type))))
2432 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2433 ((equal keys "C")
2434 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2435 (customize-variable 'org-agenda-custom-commands))
2436 ((equal keys "a") (call-interactively 'org-agenda-list))
2437 ((equal keys "s") (call-interactively 'org-search-view))
2438 ((equal keys "t") (call-interactively 'org-todo-list))
2439 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2440 ((equal keys "m") (call-interactively 'org-tags-view))
2441 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2442 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2443 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2444 (org-add-hook
2445 'post-command-hook
2446 (lambda ()
2447 (unless (current-message)
2448 (let* ((m (org-agenda-get-any-marker))
2449 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2450 (when note
2451 (message (concat
2452 "FLAGGING-NOTE ([?] for more info): "
2453 (org-add-props
2454 (replace-regexp-in-string
2455 "\\\\n" "//"
2456 (copy-sequence note))
2457 nil 'face 'org-warning)))))))
2458 t t))
2459 ((equal keys "L")
2460 (unless (eq major-mode 'org-mode)
2461 (error "This is not an Org-mode file"))
2462 (unless restriction
2463 (put 'org-agenda-files 'org-restrict (list bfn))
2464 (org-call-with-arg 'org-timeline arg)))
2465 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2466 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2467 ((equal keys "!") (customize-variable 'org-stuck-projects))
2468 (t (error "Invalid agenda key"))))))
2470 (defun org-agenda-append-agenda ()
2471 "Append another agenda view to the current one.
2472 This function allows interactive building of block agendas.
2473 Agenda views are separated by `org-agenda-block-separator'."
2474 (interactive)
2475 (unless (string= (buffer-name) org-agenda-buffer-name)
2476 (error "Can only append from within agenda buffer"))
2477 (let ((org-agenda-multi t))
2478 (org-agenda)
2479 (widen)))
2481 (defun org-agenda-normalize-custom-commands (cmds)
2482 (delq nil
2483 (mapcar
2484 (lambda (x)
2485 (cond ((stringp (cdr x)) nil)
2486 ((stringp (nth 1 x)) x)
2487 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2488 (t (cons (car x) (cons "" (cdr x))))))
2489 cmds)))
2491 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2492 "The user interface for selecting an agenda command."
2493 (catch 'exit
2494 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2495 (restrict-ok (and bfn (eq major-mode 'org-mode)))
2496 (region-p (org-region-active-p))
2497 (custom org-agenda-custom-commands)
2498 (selstring "")
2499 restriction second-time
2500 c entry key type match prefixes rmheader header-end custom1 desc
2501 line lines left right n n1)
2502 (save-window-excursion
2503 (delete-other-windows)
2504 (org-switch-to-buffer-other-window " *Agenda Commands*")
2505 (erase-buffer)
2506 (insert (eval-when-compile
2507 (let ((header
2508 "Press key for an agenda command: < Buffer, subtree/region restriction
2509 -------------------------------- > Remove restriction
2510 a Agenda for current week or day e Export agenda views
2511 t List of all TODO entries T Entries with special TODO kwd
2512 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2513 L Timeline for current buffer # List stuck projects (!=configure)
2514 s Search for keywords * Toggle sticky agenda views
2515 / Multi-occur ? Find :FLAGGED: entries
2516 C Configure custom agenda commands
2518 (start 0))
2519 (while (string-match
2520 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2521 header start)
2522 (setq start (match-end 0))
2523 (add-text-properties (match-beginning 2) (match-end 2)
2524 '(face bold) header))
2525 header)))
2526 (setq header-end (move-marker (make-marker) (point)))
2527 (while t
2528 (setq custom1 custom)
2529 (when (eq rmheader t)
2530 (org-goto-line 1)
2531 (re-search-forward ":" nil t)
2532 (delete-region (match-end 0) (point-at-eol))
2533 (forward-char 1)
2534 (looking-at "-+")
2535 (delete-region (match-end 0) (point-at-eol))
2536 (move-marker header-end (match-end 0)))
2537 (goto-char header-end)
2538 (delete-region (point) (point-max))
2540 ;; Produce all the lines that describe custom commands and prefixes
2541 (setq lines nil)
2542 (while (setq entry (pop custom1))
2543 (setq key (car entry) desc (nth 1 entry)
2544 type (nth 2 entry)
2545 match (nth 3 entry))
2546 (if (> (length key) 1)
2547 (add-to-list 'prefixes (string-to-char key))
2548 (setq line
2549 (format
2550 "%-4s%-14s"
2551 (org-add-props (copy-sequence key)
2552 '(face bold))
2553 (cond
2554 ((string-match "\\S-" desc) desc)
2555 ((eq type 'agenda) "Agenda for current week or day")
2556 ((eq type 'alltodo) "List of all TODO entries")
2557 ((eq type 'search) "Word search")
2558 ((eq type 'stuck) "List of stuck projects")
2559 ((eq type 'todo) "TODO keyword")
2560 ((eq type 'tags) "Tags query")
2561 ((eq type 'tags-todo) "Tags (TODO)")
2562 ((eq type 'tags-tree) "Tags tree")
2563 ((eq type 'todo-tree) "TODO kwd tree")
2564 ((eq type 'occur-tree) "Occur tree")
2565 ((functionp type) (if (symbolp type)
2566 (symbol-name type)
2567 "Lambda expression"))
2568 (t "???"))))
2569 (if org-agenda-menu-show-matcher
2570 (setq line
2571 (concat line ": "
2572 (cond
2573 ((stringp match)
2574 (setq match (copy-sequence match))
2575 (org-add-props match nil 'face 'org-warning))
2576 (match
2577 (format "set of %d commands" (length match)))
2578 (t ""))))
2579 (if (org-string-nw-p match)
2580 (add-text-properties
2581 0 (length line) (list 'help-echo
2582 (concat "Matcher: "match)) line)))
2583 (push line lines)))
2584 (setq lines (nreverse lines))
2585 (when prefixes
2586 (mapc (lambda (x)
2587 (push
2588 (format "%s %s"
2589 (org-add-props (char-to-string x)
2590 nil 'face 'bold)
2591 (or (cdr (assoc (concat selstring
2592 (char-to-string x))
2593 prefix-descriptions))
2594 "Prefix key"))
2595 lines))
2596 prefixes))
2598 ;; Check if we should display in two columns
2599 (if org-agenda-menu-two-column
2600 (progn
2601 (setq n (length lines)
2602 n1 (+ (/ n 2) (mod n 2))
2603 right (nthcdr n1 lines)
2604 left (copy-sequence lines))
2605 (setcdr (nthcdr (1- n1) left) nil))
2606 (setq left lines right nil))
2607 (while left
2608 (insert "\n" (pop left))
2609 (when right
2610 (if (< (current-column) 40)
2611 (move-to-column 40 t)
2612 (insert " "))
2613 (insert (pop right))))
2615 ;; Make the window the right size
2616 (goto-char (point-min))
2617 (if second-time
2618 (if (not (pos-visible-in-window-p (point-max)))
2619 (org-fit-window-to-buffer))
2620 (setq second-time t)
2621 (org-fit-window-to-buffer))
2623 ;; Ask for selection
2624 (message "Press key for agenda command%s:"
2625 (if (or restrict-ok org-agenda-overriding-restriction)
2626 (if org-agenda-overriding-restriction
2627 " (restriction lock active)"
2628 (if restriction
2629 (format " (restricted to %s)" restriction)
2630 " (unrestricted)"))
2631 ""))
2632 (setq c (read-char-exclusive))
2633 (message "")
2634 (cond
2635 ((assoc (char-to-string c) custom)
2636 (setq selstring (concat selstring (char-to-string c)))
2637 (throw 'exit (cons selstring restriction)))
2638 ((memq c prefixes)
2639 (setq selstring (concat selstring (char-to-string c))
2640 prefixes nil
2641 rmheader (or rmheader t)
2642 custom (delq nil (mapcar
2643 (lambda (x)
2644 (if (or (= (length (car x)) 1)
2645 (/= (string-to-char (car x)) c))
2647 (cons (substring (car x) 1) (cdr x))))
2648 custom))))
2649 ((eq c ?*)
2650 (org-toggle-sticky-agenda)
2651 (sit-for 2))
2652 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2653 (message "Restriction is only possible in Org-mode buffers")
2654 (ding) (sit-for 1))
2655 ((eq c ?1)
2656 (org-agenda-remove-restriction-lock 'noupdate)
2657 (setq restriction 'buffer))
2658 ((eq c ?0)
2659 (org-agenda-remove-restriction-lock 'noupdate)
2660 (setq restriction (if region-p 'region 'subtree)))
2661 ((eq c ?<)
2662 (org-agenda-remove-restriction-lock 'noupdate)
2663 (setq restriction
2664 (cond
2665 ((eq restriction 'buffer)
2666 (if region-p 'region 'subtree))
2667 ((memq restriction '(subtree region))
2668 nil)
2669 (t 'buffer))))
2670 ((eq c ?>)
2671 (org-agenda-remove-restriction-lock 'noupdate)
2672 (setq restriction nil))
2673 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2674 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2675 ((and (> (length selstring) 0) (eq c ?\d))
2676 (delete-window)
2677 (org-agenda-get-restriction-and-command prefix-descriptions))
2679 ((equal c ?q) (error "Abort"))
2680 (t (error "Invalid key %c" c))))))))
2682 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2683 (defvar org-agenda-last-arguments nil
2684 "The arguments of the previous call to `org-agenda'.")
2685 (defun org-agenda-run-series (name series)
2686 (org-let (nth 1 series) '(org-prepare-agenda name))
2687 ;; We need to reset agenda markers heree, because when constructing a
2688 ;; block agenda, the individual blocks do not do that.
2689 (org-agenda-reset-markers)
2690 (let* ((org-agenda-multi t)
2691 (redo (list 'org-agenda-run-series name (list 'quote series)))
2692 (org-agenda-overriding-arguments
2693 (or org-agenda-overriding-arguments
2694 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2695 (get 'org-agenda-redo-command 'last-args))))
2696 (cmds (car series))
2697 (gprops (nth 1 series))
2698 match ;; The byte compiler incorrectly complains about this. Keep it!
2699 cmd type lprops)
2700 (while (setq cmd (pop cmds))
2701 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2702 (cond
2703 ((eq type 'agenda)
2704 (org-let2 gprops lprops
2705 '(call-interactively 'org-agenda-list)))
2706 ((eq type 'alltodo)
2707 (org-let2 gprops lprops
2708 '(call-interactively 'org-todo-list)))
2709 ((eq type 'search)
2710 (org-let2 gprops lprops
2711 '(org-search-view current-prefix-arg match nil)))
2712 ((eq type 'stuck)
2713 (org-let2 gprops lprops
2714 '(call-interactively 'org-agenda-list-stuck-projects)))
2715 ((eq type 'tags)
2716 (org-let2 gprops lprops
2717 '(org-tags-view current-prefix-arg match)))
2718 ((eq type 'tags-todo)
2719 (org-let2 gprops lprops
2720 '(org-tags-view '(4) match)))
2721 ((eq type 'todo)
2722 (org-let2 gprops lprops
2723 '(org-todo-list match)))
2724 ((fboundp type)
2725 (org-let2 gprops lprops
2726 '(funcall type match)))
2727 (t (error "Invalid type in command series"))))
2728 (widen)
2729 (setq org-agenda-redo-command redo)
2730 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2731 (goto-char (point-min)))
2732 (org-fit-agenda-window)
2733 (org-let (nth 1 series) '(org-finalize-agenda)))
2735 ;;;###autoload
2736 (defmacro org-batch-agenda (cmd-key &rest parameters)
2737 "Run an agenda command in batch mode and send the result to STDOUT.
2738 If CMD-KEY is a string of length 1, it is used as a key in
2739 `org-agenda-custom-commands' and triggers this command. If it is a
2740 longer string it is used as a tags/todo match string.
2741 Parameters are alternating variable names and values that will be bound
2742 before running the agenda command."
2743 (org-eval-in-environment (org-make-parameter-alist parameters)
2744 (if (> (length cmd-key) 2)
2745 (org-tags-view nil cmd-key)
2746 (org-agenda nil cmd-key)))
2747 (set-buffer org-agenda-buffer-name)
2748 (princ (buffer-string)))
2749 (def-edebug-spec org-batch-agenda (form &rest sexp))
2751 (defvar org-agenda-info nil)
2753 ;;;###autoload
2754 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2755 "Run an agenda command in batch mode and send the result to STDOUT.
2756 If CMD-KEY is a string of length 1, it is used as a key in
2757 `org-agenda-custom-commands' and triggers this command. If it is a
2758 longer string it is used as a tags/todo match string.
2759 Parameters are alternating variable names and values that will be bound
2760 before running the agenda command.
2762 The output gives a line for each selected agenda item. Each
2763 item is a list of comma-separated values, like this:
2765 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2767 category The category of the item
2768 head The headline, without TODO kwd, TAGS and PRIORITY
2769 type The type of the agenda entry, can be
2770 todo selected in TODO match
2771 tagsmatch selected in tags match
2772 diary imported from diary
2773 deadline a deadline on given date
2774 scheduled scheduled on given date
2775 timestamp entry has timestamp on given date
2776 closed entry was closed on given date
2777 upcoming-deadline warning about deadline
2778 past-scheduled forwarded scheduled item
2779 block entry has date block including g. date
2780 todo The todo keyword, if any
2781 tags All tags including inherited ones, separated by colons
2782 date The relevant date, like 2007-2-14
2783 time The time, like 15:00-16:50
2784 extra Sting with extra planning info
2785 priority-l The priority letter if any was given
2786 priority-n The computed numerical priority
2787 agenda-day The day in the agenda where this is listed"
2788 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2789 (org-make-parameter-alist parameters))
2790 (if (> (length cmd-key) 2)
2791 (org-tags-view nil cmd-key)
2792 (org-agenda nil cmd-key)))
2793 (set-buffer org-agenda-buffer-name)
2794 (let* ((lines (org-split-string (buffer-string) "\n"))
2795 line)
2796 (while (setq line (pop lines))
2797 (catch 'next
2798 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2799 (setq org-agenda-info
2800 (org-fix-agenda-info (text-properties-at 0 line)))
2801 (princ
2802 (mapconcat 'org-agenda-export-csv-mapper
2803 '(org-category txt type todo tags date time extra
2804 priority-letter priority agenda-day)
2805 ","))
2806 (princ "\n")))))
2807 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2809 (defun org-fix-agenda-info (props)
2810 "Make sure all properties on an agenda item have a canonical form.
2811 This ensures the export commands can easily use it."
2812 (let (tmp re)
2813 (when (setq tmp (plist-get props 'tags))
2814 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2815 (when (setq tmp (plist-get props 'date))
2816 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2817 (let ((calendar-date-display-form '(year "-" month "-" day)))
2818 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2820 (setq tmp (calendar-date-string tmp)))
2821 (setq props (plist-put props 'date tmp)))
2822 (when (setq tmp (plist-get props 'day))
2823 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2824 (let ((calendar-date-display-form '(year "-" month "-" day)))
2825 (setq tmp (calendar-date-string tmp)))
2826 (setq props (plist-put props 'day tmp))
2827 (setq props (plist-put props 'agenda-day tmp)))
2828 (when (setq tmp (plist-get props 'txt))
2829 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2830 (plist-put props 'priority-letter (match-string 1 tmp))
2831 (setq tmp (replace-match "" t t tmp)))
2832 (when (and (setq re (plist-get props 'org-todo-regexp))
2833 (setq re (concat "\\`\\.*" re " ?"))
2834 (string-match re tmp))
2835 (plist-put props 'todo (match-string 1 tmp))
2836 (setq tmp (replace-match "" t t tmp)))
2837 (plist-put props 'txt tmp)))
2838 props)
2840 (defun org-agenda-export-csv-mapper (prop)
2841 (let ((res (plist-get org-agenda-info prop)))
2842 (setq res
2843 (cond
2844 ((not res) "")
2845 ((stringp res) res)
2846 (t (prin1-to-string res))))
2847 (while (string-match "," res)
2848 (setq res (replace-match ";" t t res))) ;
2849 (org-trim res)))
2852 ;;;###autoload
2853 (defun org-store-agenda-views (&rest parameters)
2854 (interactive)
2855 (eval (list 'org-batch-store-agenda-views)))
2857 ;;;###autoload
2858 (defmacro org-batch-store-agenda-views (&rest parameters)
2859 "Run all custom agenda commands that have a file argument."
2860 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2861 (pop-up-frames nil)
2862 (dir default-directory)
2863 (pars (org-make-parameter-alist parameters))
2864 cmd thiscmdkey files opts cmd-or-set)
2865 (save-window-excursion
2866 (while cmds
2867 (setq cmd (pop cmds)
2868 thiscmdkey (car cmd)
2869 cmd-or-set (nth 2 cmd)
2870 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2871 files (nth (if (listp cmd-or-set) 4 5) cmd))
2872 (if (stringp files) (setq files (list files)))
2873 (when files
2874 (org-eval-in-environment (append org-agenda-exporter-settings
2875 opts pars)
2876 (org-agenda nil thiscmdkey))
2877 (set-buffer org-agenda-buffer-name)
2878 (while files
2879 (org-eval-in-environment (append org-agenda-exporter-settings
2880 opts pars)
2881 (org-agenda-write (expand-file-name (pop files) dir) nil t)))
2882 (and (get-buffer org-agenda-buffer-name)
2883 (kill-buffer org-agenda-buffer-name)))))))
2884 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2886 (defun org-agenda-mark-header-line (pos)
2887 "Mark the line at POS as an agenda structure header."
2888 (save-excursion
2889 (goto-char pos)
2890 (put-text-property (point-at-bol) (point-at-eol)
2891 'org-agenda-structural-header t)
2892 (when org-agenda-title-append
2893 (put-text-property (point-at-bol) (point-at-eol)
2894 'org-agenda-title-append org-agenda-title-append))))
2896 (defvar org-mobile-creating-agendas)
2897 (defvar org-agenda-write-buffer-name "Agenda View")
2898 (defun org-agenda-write (file &optional open nosettings)
2899 "Write the current buffer (an agenda view) as a file.
2900 Depending on the extension of the file name, plain text (.txt),
2901 HTML (.html or .htm) or Postscript (.ps) is produced.
2902 If the extension is .ics, run icalendar export over all files used
2903 to construct the agenda and limit the export to entries listed in the
2904 agenda now.
2905 With prefix argument OPEN, open the new file immediately.
2906 If NOSETTINGS is given, do not scope the settings of
2907 `org-agenda-exporter-settings' into the export commands. This is used when
2908 the settings have already been scoped and we do not wish to overrule other,
2909 higher priority settings."
2910 (interactive "FWrite agenda to file: \nP")
2911 (if (not (file-writable-p file))
2912 (error "Cannot write agenda to file %s" file))
2913 (org-let (if nosettings nil org-agenda-exporter-settings)
2914 '(save-excursion
2915 (save-window-excursion
2916 (org-agenda-mark-filtered-text)
2917 (let ((bs (copy-sequence (buffer-string))) beg)
2918 (org-agenda-unmark-filtered-text)
2919 (with-temp-buffer
2920 (rename-buffer org-agenda-write-buffer-name t)
2921 (set-buffer-modified-p nil)
2922 (insert bs)
2923 (org-agenda-remove-marked-text 'org-filtered)
2924 (while (setq beg (text-property-any (point-min) (point-max)
2925 'org-filtered t))
2926 (delete-region
2927 beg (or (next-single-property-change beg 'org-filtered)
2928 (point-max))))
2929 (run-hooks 'org-agenda-before-write-hook)
2930 (cond
2931 ((org-bound-and-true-p org-mobile-creating-agendas)
2932 (org-mobile-write-agenda-for-mobile file))
2933 ((string-match "\\.html?\\'" file)
2934 (require 'htmlize)
2935 (set-buffer (htmlize-buffer (current-buffer)))
2937 (when (and org-agenda-export-html-style
2938 (string-match "<style>" org-agenda-export-html-style))
2939 ;; replace <style> section with org-agenda-export-html-style
2940 (goto-char (point-min))
2941 (kill-region (- (search-forward "<style") 6)
2942 (search-forward "</style>"))
2943 (insert org-agenda-export-html-style))
2944 (write-file file)
2945 (kill-buffer (current-buffer))
2946 (message "HTML written to %s" file))
2947 ((string-match "\\.ps\\'" file)
2948 (require 'ps-print)
2949 (ps-print-buffer-with-faces file)
2950 (message "Postscript written to %s" file))
2951 ((string-match "\\.pdf\\'" file)
2952 (require 'ps-print)
2953 (ps-print-buffer-with-faces
2954 (concat (file-name-sans-extension file) ".ps"))
2955 (call-process "ps2pdf" nil nil nil
2956 (expand-file-name
2957 (concat (file-name-sans-extension file) ".ps"))
2958 (expand-file-name file))
2959 (delete-file (concat (file-name-sans-extension file) ".ps"))
2960 (message "PDF written to %s" file))
2961 ((string-match "\\.ics\\'" file)
2962 (require 'org-icalendar)
2963 (let ((org-agenda-marker-table
2964 (org-create-marker-find-array
2965 (org-agenda-collect-markers)))
2966 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2967 (org-combined-agenda-icalendar-file file))
2968 (apply 'org-export-icalendar 'combine
2969 (org-agenda-files nil 'ifmode))))
2971 (let ((bs (buffer-string)))
2972 (find-file file)
2973 (erase-buffer)
2974 (insert bs)
2975 (save-buffer 0)
2976 (kill-buffer (current-buffer))
2977 (message "Plain text written to %s" file))))))))
2978 (set-buffer org-agenda-buffer-name))
2979 (when open (org-open-file file)))
2981 (defvar org-agenda-tag-filter-overlays nil)
2982 (defvar org-agenda-cat-filter-overlays nil)
2984 (defun org-agenda-mark-filtered-text ()
2985 "Mark all text hidden by filtering with a text property."
2986 (let ((inhibit-read-only t))
2987 (mapc
2988 (lambda (o)
2989 (when (equal (overlay-buffer o) (current-buffer))
2990 (put-text-property
2991 (overlay-start o) (overlay-end o)
2992 'org-filtered t)))
2993 (append org-agenda-tag-filter-overlays
2994 org-agenda-cat-filter-overlays))))
2996 (defun org-agenda-unmark-filtered-text ()
2997 "Remove the filtering text property."
2998 (let ((inhibit-read-only t))
2999 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3001 (defun org-agenda-remove-marked-text (property &optional value)
3002 "Delete all text marked with VALUE of PROPERTY.
3003 VALUE defaults to t."
3004 (let (beg)
3005 (setq value (or value t))
3006 (while (setq beg (text-property-any (point-min) (point-max)
3007 property value))
3008 (delete-region
3009 beg (or (next-single-property-change beg 'org-filtered)
3010 (point-max))))))
3012 (defun org-agenda-add-entry-text ()
3013 "Add entry text to agenda lines.
3014 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3015 entry text following headings shown in the agenda.
3016 Drawers will be excluded, also the line with scheduling/deadline info."
3017 (when (and (> org-agenda-add-entry-text-maxlines 0)
3018 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3019 (let (m txt)
3020 (goto-char (point-min))
3021 (while (not (eobp))
3022 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3023 (beginning-of-line 2)
3024 (setq txt (org-agenda-get-some-entry-text
3025 m org-agenda-add-entry-text-maxlines " > "))
3026 (end-of-line 1)
3027 (if (string-match "\\S-" txt)
3028 (insert "\n" txt)
3029 (or (eobp) (forward-char 1))))))))
3031 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3032 &rest keep)
3033 "Extract entry text from MARKER, at most N-LINES lines.
3034 This will ignore drawers etc, just get the text.
3035 If INDENT is given, prefix every line with this string. If KEEP is
3036 given, it is a list of symbols, defining stuff that should not be
3037 removed from the entry content. Currently only `planning' is allowed here."
3038 (let (txt drawer-re kwd-time-re ind)
3039 (save-excursion
3040 (with-current-buffer (marker-buffer marker)
3041 (if (not (eq major-mode 'org-mode))
3042 (setq txt "")
3043 (save-excursion
3044 (save-restriction
3045 (widen)
3046 (goto-char marker)
3047 (end-of-line 1)
3048 (setq txt (buffer-substring
3049 (min (1+ (point)) (point-max))
3050 (progn (outline-next-heading) (point)))
3051 drawer-re org-drawer-regexp
3052 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3053 ".*\n?"))
3054 (with-temp-buffer
3055 (insert txt)
3056 (when org-agenda-add-entry-text-descriptive-links
3057 (goto-char (point-min))
3058 (while (org-activate-bracket-links (point-max))
3059 (add-text-properties (match-beginning 0) (match-end 0)
3060 '(face org-link))))
3061 (goto-char (point-min))
3062 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3063 (set-text-properties (match-beginning 0) (match-end 0)
3064 nil))
3065 (goto-char (point-min))
3066 (while (re-search-forward drawer-re nil t)
3067 (delete-region
3068 (match-beginning 0)
3069 (progn (re-search-forward
3070 "^[ \t]*:END:.*\n?" nil 'move)
3071 (point))))
3072 (unless (member 'planning keep)
3073 (goto-char (point-min))
3074 (while (re-search-forward kwd-time-re nil t)
3075 (replace-match "")))
3076 (goto-char (point-min))
3077 (when org-agenda-entry-text-exclude-regexps
3078 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3079 (while (setq re (pop re-list))
3080 (goto-char (point-min))
3081 (while (re-search-forward re nil t)
3082 (replace-match "")))))
3083 (goto-char (point-max))
3084 (skip-chars-backward " \t\n")
3085 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3087 ;; find and remove min common indentation
3088 (goto-char (point-min))
3089 (untabify (point-min) (point-max))
3090 (setq ind (org-get-indentation))
3091 (while (not (eobp))
3092 (unless (looking-at "[ \t]*$")
3093 (setq ind (min ind (org-get-indentation))))
3094 (beginning-of-line 2))
3095 (goto-char (point-min))
3096 (while (not (eobp))
3097 (unless (looking-at "[ \t]*$")
3098 (move-to-column ind)
3099 (delete-region (point-at-bol) (point)))
3100 (beginning-of-line 2))
3102 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3104 (goto-char (point-min))
3105 (when indent
3106 (while (and (not (eobp)) (re-search-forward "^" nil t))
3107 (replace-match indent t t)))
3108 (goto-char (point-min))
3109 (while (looking-at "[ \t]*\n") (replace-match ""))
3110 (goto-char (point-max))
3111 (when (> (org-current-line)
3112 n-lines)
3113 (org-goto-line (1+ n-lines))
3114 (backward-char 1))
3115 (setq txt (buffer-substring (point-min) (point)))))))))
3116 txt))
3118 (defun org-agenda-collect-markers ()
3119 "Collect the markers pointing to entries in the agenda buffer."
3120 (let (m markers)
3121 (save-excursion
3122 (goto-char (point-min))
3123 (while (not (eobp))
3124 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3125 (org-get-at-bol 'org-marker)))
3126 (push m markers))
3127 (beginning-of-line 2)))
3128 (nreverse markers)))
3130 (defun org-create-marker-find-array (marker-list)
3131 "Create a alist of files names with all marker positions in that file."
3132 (let (f tbl m a p)
3133 (while (setq m (pop marker-list))
3134 (setq p (marker-position m)
3135 f (buffer-file-name (or (buffer-base-buffer
3136 (marker-buffer m))
3137 (marker-buffer m))))
3138 (if (setq a (assoc f tbl))
3139 (push (marker-position m) (cdr a))
3140 (push (list f p) tbl)))
3141 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3142 tbl)))
3144 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3145 (defun org-check-agenda-marker-table ()
3146 "Check of the current entry is on the marker list."
3147 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3149 (and (setq a (assoc file org-agenda-marker-table))
3150 (save-match-data
3151 (save-excursion
3152 (org-back-to-heading t)
3153 (member (point) (cdr a)))))))
3155 (defun org-check-for-org-mode ()
3156 "Make sure current buffer is in org-mode. Error if not."
3157 (or (eq major-mode 'org-mode)
3158 (error "Cannot execute org-mode agenda command on buffer in %s"
3159 major-mode)))
3161 (defun org-fit-agenda-window ()
3162 "Fit the window to the buffer size."
3163 (and (memq org-agenda-window-setup '(reorganize-frame))
3164 (fboundp 'fit-window-to-buffer)
3165 (org-fit-window-to-buffer
3167 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3168 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3170 ;;; Agenda prepare and finalize
3172 (defvar org-agenda-multi nil) ; dynamically scoped
3173 (defvar org-agenda-buffer-name "*Org Agenda*")
3174 (defvar org-pre-agenda-window-conf nil)
3175 (defvar org-agenda-columns-active nil)
3176 (defvar org-agenda-name nil)
3177 (defvar org-agenda-tag-filter nil)
3178 (defvar org-agenda-category-filter nil)
3179 (defvar org-agenda-tag-filter-while-redo nil) ; dynamically scoped
3180 (defvar org-agenda-tag-filter-preset nil
3181 "A preset of the tags filter used for secondary agenda filtering.
3182 This must be a list of strings, each string must be a single tag preceded
3183 by \"+\" or \"-\".
3184 This variable should not be set directly, but agenda custom commands can
3185 bind it in the options section. The preset filter is a global property of
3186 the entire agenda view. In a block agenda, it will not work reliably to
3187 define a filter for one of the individual blocks. You need to set it in
3188 the global options and expect it to be applied to the entire view.")
3190 (defvar org-agenda-category-filter-preset nil
3191 "A preset of the category filter used for secondary agenda filtering.
3192 This must be a list of strings, each string must be a single category
3193 preceded by \"+\" or \"-\".
3194 This variable should not be set directly, but agenda custom commands can
3195 bind it in the options section. The preset filter is a global property of
3196 the entire agenda view. In a block agenda, it will not work reliably to
3197 define a filter for one of the individual blocks. You need to set it in
3198 the global options and expect it to be applied to the entire view.")
3201 (defun org-agenda-use-sticky-p ()
3202 "Return non-NIL if existing agenda buffer named
3203 `org-agenda-buffer-name' exists, and should be shown instead of
3204 generating a new one"
3205 (and
3206 ;; turned off by user
3207 org-agenda-sticky
3208 ;; For multi-agenda buffer already exists
3209 (not org-agenda-multi)
3210 ;; buffer found
3211 (get-buffer org-agenda-buffer-name)
3212 ;; C-u parameter is same as last call
3213 (with-current-buffer (get-buffer org-agenda-buffer-name)
3214 (and
3215 (equal current-prefix-arg
3216 org-agenda-last-prefix-arg)
3217 ;; In case user turned stickiness on, while having existing
3218 ;; Agenda buffer active, don't reuse that buffer, because it
3219 ;; does not have org variables local
3220 org-agenda-this-buffer-is-sticky))))
3222 (defun org-prepare-agenda-window (abuf)
3223 "Setup agenda buffer in the window"
3224 (let* ((awin (get-buffer-window abuf))
3225 wconf)
3226 (cond
3227 ((equal (current-buffer) abuf) nil)
3228 (awin (select-window awin))
3229 ((not (setq wconf (current-window-configuration))))
3230 ((equal org-agenda-window-setup 'current-window)
3231 (org-pop-to-buffer-same-window abuf))
3232 ((equal org-agenda-window-setup 'other-window)
3233 (org-switch-to-buffer-other-window abuf))
3234 ((equal org-agenda-window-setup 'other-frame)
3235 (switch-to-buffer-other-frame abuf))
3236 ((equal org-agenda-window-setup 'reorganize-frame)
3237 (delete-other-windows)
3238 (org-switch-to-buffer-other-window abuf)))
3239 ;; additional test in case agenda is invoked from within agenda
3240 ;; buffer via elisp link
3241 (unless (equal (current-buffer) abuf)
3242 (org-pop-to-buffer-same-window abuf))
3243 (setq org-pre-agenda-window-conf wconf)))
3245 (defun org-prepare-agenda (&optional name)
3246 (if (org-agenda-use-sticky-p)
3247 (progn
3248 ;; Popup existing buffer
3249 (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
3250 (message "Sticky Agenda buffer, use `r' to refresh")
3251 (throw 'exit nil))
3252 (setq org-todo-keywords-for-agenda nil)
3253 (setq org-done-keywords-for-agenda nil)
3254 (setq org-drawers-for-agenda nil)
3255 (unless org-agenda-persistent-filter
3256 (setq org-agenda-tag-filter nil
3257 org-agenda-category-filter nil))
3258 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3259 (put 'org-agenda-category-filter :preset-filter
3260 org-agenda-category-filter-preset)
3261 (if org-agenda-multi
3262 (progn
3263 (setq buffer-read-only nil)
3264 (goto-char (point-max))
3265 (unless (or (bobp) org-agenda-compact-blocks
3266 (not org-agenda-block-separator))
3267 (insert "\n"
3268 (if (stringp org-agenda-block-separator)
3269 org-agenda-block-separator
3270 (make-string (window-width) org-agenda-block-separator))
3271 "\n"))
3272 (narrow-to-region (point) (point-max)))
3274 ;; any org variables need to be set after being in agenda buffer
3275 ;; since they are now buffer local
3276 (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
3277 (setq buffer-read-only nil)
3278 (org-agenda-reset-markers)
3279 (let ((inhibit-read-only t)) (erase-buffer))
3280 (org-agenda-mode)
3281 (setq org-agenda-buffer (current-buffer))
3282 (setq org-agenda-contributing-files nil)
3283 (setq org-agenda-columns-active nil)
3284 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3285 (setq org-todo-keywords-for-agenda
3286 (org-uniquify org-todo-keywords-for-agenda))
3287 (setq org-done-keywords-for-agenda
3288 (org-uniquify org-done-keywords-for-agenda))
3289 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3290 (setq org-agenda-last-prefix-arg current-prefix-arg)
3291 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3292 (and name (not org-agenda-name)
3293 (org-set-local 'org-agenda-name name)))
3294 (setq buffer-read-only nil)))
3296 (defun org-finalize-agenda ()
3297 "Finishing touch for the agenda buffer, called just before displaying it."
3298 (unless org-agenda-multi
3299 (save-excursion
3300 (let ((inhibit-read-only t))
3301 (goto-char (point-min))
3302 (while (org-activate-bracket-links (point-max))
3303 (add-text-properties (match-beginning 0) (match-end 0)
3304 '(face org-link)))
3305 (org-agenda-align-tags)
3306 (unless org-agenda-with-colors
3307 (remove-text-properties (point-min) (point-max) '(face nil))))
3308 (if (and (boundp 'org-agenda-overriding-columns-format)
3309 org-agenda-overriding-columns-format)
3310 (org-set-local 'org-agenda-overriding-columns-format
3311 org-agenda-overriding-columns-format))
3312 (if (and (boundp 'org-agenda-view-columns-initially)
3313 org-agenda-view-columns-initially)
3314 (org-agenda-columns))
3315 (when org-agenda-fontify-priorities
3316 (org-agenda-fontify-priorities))
3317 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3318 (org-agenda-dim-blocked-tasks))
3319 (org-agenda-mark-clocking-task)
3320 (when org-agenda-entry-text-mode
3321 (org-agenda-entry-text-hide)
3322 (org-agenda-entry-text-show))
3323 (if (functionp 'org-habit-insert-consistency-graphs)
3324 (org-habit-insert-consistency-graphs))
3325 (run-hooks 'org-finalize-agenda-hook)
3326 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3327 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3328 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3329 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3330 (org-agenda-filter-apply org-agenda-category-filter 'category))
3331 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3334 (defun org-agenda-mark-clocking-task ()
3335 "Mark the current clock entry in the agenda if it is present."
3336 (mapc (lambda (o)
3337 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3338 (delete-overlay o)))
3339 (overlays-in (point-min) (point-max)))
3340 (when (marker-buffer org-clock-hd-marker)
3341 (save-excursion
3342 (goto-char (point-min))
3343 (let (s ov)
3344 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3345 (goto-char s)
3346 (when (equal (org-get-at-bol 'org-hd-marker)
3347 org-clock-hd-marker)
3348 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3349 (overlay-put ov 'type 'org-agenda-clocking)
3350 (overlay-put ov 'face 'org-agenda-clocking)
3351 (overlay-put ov 'help-echo
3352 "The clock is running in this item")))))))
3354 (defun org-agenda-fontify-priorities ()
3355 "Make highest priority lines bold, and lowest italic."
3356 (interactive)
3357 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3358 (delete-overlay o)))
3359 (overlays-in (point-min) (point-max)))
3360 (save-excursion
3361 (let ((inhibit-read-only t)
3362 b e p ov h l)
3363 (goto-char (point-min))
3364 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3365 (setq h (or (get-char-property (point) 'org-highest-priority)
3366 org-highest-priority)
3367 l (or (get-char-property (point) 'org-lowest-priority)
3368 org-lowest-priority)
3369 p (string-to-char (match-string 1))
3370 b (match-beginning 0)
3371 e (if (eq org-agenda-fontify-priorities 'cookies)
3372 (match-end 0)
3373 (point-at-eol))
3374 ov (make-overlay b e))
3375 (overlay-put
3376 ov 'face
3377 (cond ((org-face-from-face-or-color
3378 'priority nil
3379 (cdr (assoc p org-priority-faces))))
3380 ((and (listp org-agenda-fontify-priorities)
3381 (org-face-from-face-or-color
3382 'priority nil
3383 (cdr (assoc p org-agenda-fontify-priorities)))))
3384 ((equal p l) 'italic)
3385 ((equal p h) 'bold)))
3386 (overlay-put ov 'org-type 'org-priority)))))
3388 (defun org-agenda-dim-blocked-tasks ()
3389 "Dim currently blocked TODO's in the agenda display."
3390 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3391 (delete-overlay o)))
3392 (overlays-in (point-min) (point-max)))
3393 (save-excursion
3394 (let ((inhibit-read-only t)
3395 (org-depend-tag-blocked nil)
3396 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3397 org-blocked-by-checkboxes
3398 invis1 b e p ov h l)
3399 (goto-char (point-min))
3400 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3401 (and pos (goto-char (1+ pos))))
3402 (setq org-blocked-by-checkboxes nil invis1 invis)
3403 (let ((marker (org-get-at-bol 'org-hd-marker)))
3404 (when (and marker
3405 (with-current-buffer (marker-buffer marker)
3406 (save-excursion (goto-char marker)
3407 (org-entry-blocked-p))))
3408 (if org-blocked-by-checkboxes (setq invis1 nil))
3409 (setq b (if invis1
3410 (max (point-min) (1- (point-at-bol)))
3411 (point-at-bol))
3412 e (point-at-eol)
3413 ov (make-overlay b e))
3414 (if invis1
3415 (overlay-put ov 'invisible t)
3416 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3417 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3419 (defvar org-agenda-skip-function nil
3420 "Function to be called at each match during agenda construction.
3421 If this function returns nil, the current match should not be skipped.
3422 Otherwise, the function must return a position from where the search
3423 should be continued.
3424 This may also be a Lisp form, it will be evaluated.
3425 Never set this variable using `setq' or so, because then it will apply
3426 to all future agenda commands. If you do want a global skipping condition,
3427 use the option `org-agenda-skip-function-global' instead.
3428 The correct usage for `org-agenda-skip-function' is to bind it with
3429 `let' to scope it dynamically into the agenda-constructing command.
3430 A good way to set it is through options in `org-agenda-custom-commands'.")
3432 (defun org-agenda-skip ()
3433 "Throw to `:skip' in places that should be skipped.
3434 Also moves point to the end of the skipped region, so that search can
3435 continue from there."
3436 (let ((p (point-at-bol)) to)
3437 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3438 (get-text-property p :org-archived)
3439 (org-end-of-subtree t)
3440 (throw :skip t))
3441 (and org-agenda-skip-comment-trees
3442 (get-text-property p :org-comment)
3443 (org-end-of-subtree t)
3444 (throw :skip t))
3445 (if (equal (char-after p) ?#) (throw :skip t))
3446 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3447 (org-agenda-skip-eval org-agenda-skip-function)))
3448 (goto-char to)
3449 (throw :skip t))))
3451 (defun org-agenda-skip-eval (form)
3452 "If FORM is a function or a list, call (or eval) is and return result.
3453 `save-excursion' and `save-match-data' are wrapped around the call, so point
3454 and match data are returned to the previous state no matter what these
3455 functions do."
3456 (let (fp)
3457 (and form
3458 (or (setq fp (functionp form))
3459 (consp form))
3460 (save-excursion
3461 (save-match-data
3462 (if fp
3463 (funcall form)
3464 (eval form)))))))
3466 (defvar org-agenda-markers nil
3467 "List of all currently active markers created by `org-agenda'.")
3468 (defvar org-agenda-last-marker-time (org-float-time)
3469 "Creation time of the last agenda marker.")
3471 (defun org-agenda-new-marker (&optional pos)
3472 "Return a new agenda marker.
3473 Org-mode keeps a list of these markers and resets them when they are
3474 no longer in use."
3475 (let ((m (copy-marker (or pos (point)))))
3476 (setq org-agenda-last-marker-time (org-float-time))
3477 (with-current-buffer org-agenda-buffer
3478 (push m org-agenda-markers))
3481 (defun org-agenda-reset-markers ()
3482 "Reset markers created by `org-agenda'."
3483 (while org-agenda-markers
3484 (move-marker (pop org-agenda-markers) nil)))
3486 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3487 "Save relative positions of markers in region.
3488 This check for agenda markers in all agenda buffers currently active."
3489 (dolist (buf (buffer-list))
3490 (with-current-buffer buf
3491 (when (eq major-mode 'org-agenda-mode)
3492 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3493 org-agenda-markers)))))
3495 ;;; Entry text mode
3497 (defun org-agenda-entry-text-show-here ()
3498 "Add some text from the entry as context to the current line."
3499 (let (m txt o)
3500 (setq m (org-get-at-bol 'org-hd-marker))
3501 (unless (marker-buffer m)
3502 (error "No marker points to an entry here"))
3503 (setq txt (concat "\n" (org-no-properties
3504 (org-agenda-get-some-entry-text
3505 m org-agenda-entry-text-maxlines " > "))))
3506 (when (string-match "\\S-" txt)
3507 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3508 (overlay-put o 'evaporate t)
3509 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3510 (overlay-put o 'after-string txt))))
3512 (defun org-agenda-entry-text-show ()
3513 "Add entry context for all agenda lines."
3514 (interactive)
3515 (save-excursion
3516 (goto-char (point-max))
3517 (beginning-of-line 1)
3518 (while (not (bobp))
3519 (when (org-get-at-bol 'org-hd-marker)
3520 (org-agenda-entry-text-show-here))
3521 (beginning-of-line 0))))
3523 (defun org-agenda-entry-text-hide ()
3524 "Remove any shown entry context."
3525 (delq nil
3526 (mapcar (lambda (o)
3527 (if (eq (overlay-get o 'org-overlay-type)
3528 'agenda-entry-content)
3529 (progn (delete-overlay o) t)))
3530 (overlays-in (point-min) (point-max)))))
3532 (defun org-agenda-get-day-face (date)
3533 "Return the face DATE should be displayed with."
3534 (or (and (functionp org-agenda-day-face-function)
3535 (funcall org-agenda-day-face-function date))
3536 (cond ((org-agenda-todayp date)
3537 'org-agenda-date-today)
3538 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3539 'org-agenda-date-weekend)
3540 (t 'org-agenda-date))))
3542 ;;; Agenda timeline
3544 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3546 (defun org-timeline (&optional dotodo)
3547 "Show a time-sorted view of the entries in the current org file.
3548 Only entries with a time stamp of today or later will be listed. With
3549 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3550 under the current date.
3551 If the buffer contains an active region, only check the region for
3552 dates."
3553 (interactive "P")
3554 (let* ((dopast t)
3555 (org-agenda-show-log-scoped org-agenda-show-log)
3556 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3557 (current-buffer))))
3558 (date (calendar-current-date))
3559 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3560 (end (if (org-region-active-p) (region-end) (point-max)))
3561 (day-numbers (org-get-all-dates
3562 beg end 'no-ranges
3563 t org-agenda-show-log-scoped ; always include today
3564 org-timeline-show-empty-dates))
3565 (org-deadline-warning-days 0)
3566 (org-agenda-only-exact-dates t)
3567 (today (org-today))
3568 (past t)
3569 args
3570 s e rtn d emptyp)
3571 (setq org-agenda-redo-command
3572 (list 'progn
3573 (list 'org-switch-to-buffer-other-window (current-buffer))
3574 (list 'org-timeline (list 'quote dotodo))))
3575 (if (not dopast)
3576 ;; Remove past dates from the list of dates.
3577 (setq day-numbers (delq nil (mapcar (lambda(x)
3578 (if (>= x today) x nil))
3579 day-numbers))))
3580 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3581 (org-compile-prefix-format 'timeline)
3582 (org-set-sorting-strategy 'timeline)
3583 (if org-agenda-show-log-scoped (push :closed args))
3584 (push :timestamp args)
3585 (push :deadline args)
3586 (push :scheduled args)
3587 (push :sexp args)
3588 (if dotodo (push :todo args))
3589 (insert "Timeline of file " entry "\n")
3590 (add-text-properties (point-min) (point)
3591 (list 'face 'org-agenda-structure))
3592 (org-agenda-mark-header-line (point-min))
3593 (while (setq d (pop day-numbers))
3594 (if (and (listp d) (eq (car d) :omitted))
3595 (progn
3596 (setq s (point))
3597 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3598 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3599 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3600 (if (and (>= d today)
3601 dopast
3602 past)
3603 (progn
3604 (setq past nil)
3605 (insert (make-string 79 ?-) "\n")))
3606 (setq date (calendar-gregorian-from-absolute d))
3607 (setq s (point))
3608 (setq rtn (and (not emptyp)
3609 (apply 'org-agenda-get-day-entries entry
3610 date args)))
3611 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3612 (progn
3613 (insert
3614 (if (stringp org-agenda-format-date)
3615 (format-time-string org-agenda-format-date
3616 (org-time-from-absolute date))
3617 (funcall org-agenda-format-date date))
3618 "\n")
3619 (put-text-property s (1- (point)) 'face
3620 (org-agenda-get-day-face date))
3621 (put-text-property s (1- (point)) 'org-date-line t)
3622 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3623 (if (equal d today)
3624 (put-text-property s (1- (point)) 'org-today t))
3625 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3626 (put-text-property s (1- (point)) 'day d)))))
3627 (goto-char (point-min))
3628 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3629 (point-min)))
3630 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3631 (org-finalize-agenda)
3632 (setq buffer-read-only t)))
3634 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3635 "Return a list of all relevant day numbers from BEG to END buffer positions.
3636 If NO-RANGES is non-nil, include only the start and end dates of a range,
3637 not every single day in the range. If FORCE-TODAY is non-nil, make
3638 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3639 inactive time stamps (those in square brackets) are included.
3640 When EMPTY is non-nil, also include days without any entries."
3641 (let ((re (concat
3642 (if pre-re pre-re "")
3643 (if inactive org-ts-regexp-both org-ts-regexp)))
3644 dates dates1 date day day1 day2 ts1 ts2 pos)
3645 (if force-today
3646 (setq dates (list (org-today))))
3647 (save-excursion
3648 (goto-char beg)
3649 (while (re-search-forward re end t)
3650 (setq day (time-to-days (org-time-string-to-time
3651 (substring (match-string 1) 0 10)
3652 (current-buffer) (match-beginning 0))))
3653 (or (memq day dates) (push day dates)))
3654 (unless no-ranges
3655 (goto-char beg)
3656 (while (re-search-forward org-tr-regexp end t)
3657 (setq pos (match-beginning 0))
3658 (setq ts1 (substring (match-string 1) 0 10)
3659 ts2 (substring (match-string 2) 0 10)
3660 day1 (time-to-days (org-time-string-to-time
3661 ts1 (current-buffer) pos))
3662 day2 (time-to-days (org-time-string-to-time
3663 ts2 (current-buffer) pos)))
3664 (while (< (setq day1 (1+ day1)) day2)
3665 (or (memq day1 dates) (push day1 dates)))))
3666 (setq dates (sort dates '<))
3667 (when empty
3668 (while (setq day (pop dates))
3669 (setq day2 (car dates))
3670 (push day dates1)
3671 (when (and day2 empty)
3672 (if (or (eq empty t)
3673 (and (numberp empty) (<= (- day2 day) empty)))
3674 (while (< (setq day (1+ day)) day2)
3675 (push (list day) dates1))
3676 (push (cons :omitted (- day2 day)) dates1))))
3677 (setq dates (nreverse dates1)))
3678 dates)))
3680 ;;; Agenda Daily/Weekly
3682 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3683 "Start day for the agenda view.
3684 Custom commands can set this variable in the options section.")
3685 (defvar org-starting-day nil) ; local variable in the agenda buffer
3686 (defvar org-agenda-current-span nil
3687 "The current span used in the agenda view.") ; local variable in the agenda buffer
3688 (defvar org-arg-loc nil) ; local variable
3690 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3691 "List of types searched for when creating the daily/weekly agenda.
3692 This variable is a list of symbols that controls the types of
3693 items that appear in the daily/weekly agenda. Allowed symbols in this
3694 list are are
3696 :timestamp List items containing a date stamp or date range matching
3697 the selected date. This includes sexp entries in
3698 angular brackets.
3700 :sexp List entries resulting from plain diary-like sexps.
3702 :deadline List deadline due on that date. When the date is today,
3703 also list any deadlines past due, or due within
3704 `org-deadline-warning-days'. `:deadline' must appear before
3705 `:scheduled' if the setting of
3706 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3707 any effect.
3709 :scheduled List all items which are scheduled for the given date.
3710 The diary for *today* also contains items which were
3711 scheduled earlier and are not yet marked DONE.
3713 By default, all four types are turned on.
3715 Never set this variable globally using `setq', because then it
3716 will apply to all future agenda commands. Instead, bind it with
3717 `let' to scope it dynamically into the agenda-constructing
3718 command. A good way to set it is through options in
3719 `org-agenda-custom-commands'. For a more flexible (though
3720 somewhat less efficient) way of determining what is included in
3721 the daily/weekly agenda, see `org-agenda-skip-function'.")
3723 ;;;###autoload
3724 (defun org-agenda-list (&optional arg start-day span)
3725 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3726 The view will be for the current day or week, but from the overview buffer
3727 you will be able to go to other days/weeks.
3729 With a numeric prefix argument in an interactive call, the agenda will
3730 span ARG days. Lisp programs should instead specify SPAN to change
3731 the number of days. SPAN defaults to `org-agenda-span'.
3733 START-DAY defaults to TODAY, or to the most recent match for the weekday
3734 given in `org-agenda-start-on-weekday'."
3735 (interactive "P")
3736 (if (and (integerp arg) (> arg 0))
3737 (setq span arg arg nil))
3738 (org-prepare-agenda "Day/Week")
3739 (setq start-day (or start-day org-agenda-start-day))
3740 (if org-agenda-overriding-arguments
3741 (setq arg (car org-agenda-overriding-arguments)
3742 start-day (nth 1 org-agenda-overriding-arguments)
3743 span (nth 2 org-agenda-overriding-arguments)))
3744 (if (stringp start-day)
3745 ;; Convert to an absolute day number
3746 (setq start-day (time-to-days (org-read-date nil t start-day))))
3747 (setq org-agenda-last-arguments (list arg start-day span))
3748 (org-compile-prefix-format 'agenda)
3749 (org-set-sorting-strategy 'agenda)
3750 (let* ((span (org-agenda-ndays-to-span
3751 (or span org-agenda-ndays org-agenda-span)))
3752 (today (org-today))
3753 (sd (or start-day today))
3754 (ndays (org-agenda-span-to-ndays span sd))
3755 (org-agenda-start-on-weekday
3756 (if (eq ndays 7)
3757 org-agenda-start-on-weekday))
3758 (thefiles (org-agenda-files nil 'ifmode))
3759 (files thefiles)
3760 (start (if (or (null org-agenda-start-on-weekday)
3761 (< ndays 7))
3763 (let* ((nt (calendar-day-of-week
3764 (calendar-gregorian-from-absolute sd)))
3765 (n1 org-agenda-start-on-weekday)
3766 (d (- nt n1)))
3767 (- sd (+ (if (< d 0) 7 0) d)))))
3768 (day-numbers (list start))
3769 (day-cnt 0)
3770 (inhibit-redisplay (not debug-on-error))
3771 (org-agenda-show-log-scoped org-agenda-show-log)
3772 s e rtn rtnall file date d start-pos end-pos todayp
3773 clocktable-start clocktable-end filter)
3774 (setq org-agenda-redo-command
3775 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3776 (dotimes (n (1- ndays))
3777 (push (1+ (car day-numbers)) day-numbers))
3778 (setq day-numbers (nreverse day-numbers))
3779 (setq clocktable-start (car day-numbers)
3780 clocktable-end (1+ (or (org-last day-numbers) 0)))
3781 (org-set-local 'org-starting-day (car day-numbers))
3782 (org-set-local 'org-arg-loc arg)
3783 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3784 (unless org-agenda-compact-blocks
3785 (let* ((d1 (car day-numbers))
3786 (d2 (org-last day-numbers))
3787 (w1 (org-days-to-iso-week d1))
3788 (w2 (org-days-to-iso-week d2)))
3789 (setq s (point))
3790 (if org-agenda-overriding-header
3791 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3792 nil 'face 'org-agenda-structure) "\n")
3793 (insert (org-agenda-span-name span)
3794 "-agenda"
3795 (if (< (- d2 d1) 350)
3796 (if (= w1 w2)
3797 (format " (W%02d)" w1)
3798 (format " (W%02d-W%02d)" w1 w2))
3800 ":\n")))
3801 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3802 'org-date-line t))
3803 (org-agenda-mark-header-line s))
3804 (while (setq d (pop day-numbers))
3805 (setq date (calendar-gregorian-from-absolute d)
3806 s (point))
3807 (if (or (setq todayp (= d today))
3808 (and (not start-pos) (= d sd)))
3809 (setq start-pos (point))
3810 (if (and start-pos (not end-pos))
3811 (setq end-pos (point))))
3812 (setq files thefiles
3813 rtnall nil)
3814 (while (setq file (pop files))
3815 (catch 'nextfile
3816 (org-check-agenda-file file)
3817 (let ((org-agenda-entry-types org-agenda-entry-types))
3818 (unless org-agenda-include-deadlines
3819 (setq org-agenda-entry-types
3820 (delq :deadline org-agenda-entry-types)))
3821 (cond
3822 ((memq org-agenda-show-log-scoped '(only clockcheck))
3823 (setq rtn (org-agenda-get-day-entries
3824 file date :closed)))
3825 (org-agenda-show-log-scoped
3826 (setq rtn (apply 'org-agenda-get-day-entries
3827 file date
3828 (append '(:closed) org-agenda-entry-types))))
3830 (setq rtn (apply 'org-agenda-get-day-entries
3831 file date
3832 org-agenda-entry-types)))))
3833 (setq rtnall (append rtnall rtn)))) ;; all entries
3834 (if org-agenda-include-diary
3835 (let ((org-agenda-search-headline-for-time t))
3836 (require 'diary-lib)
3837 (setq rtn (org-get-entries-from-diary date))
3838 (setq rtnall (append rtnall rtn))))
3839 (if (or rtnall org-agenda-show-all-dates)
3840 (progn
3841 (setq day-cnt (1+ day-cnt))
3842 (insert
3843 (if (stringp org-agenda-format-date)
3844 (format-time-string org-agenda-format-date
3845 (org-time-from-absolute date))
3846 (funcall org-agenda-format-date date))
3847 "\n")
3848 (put-text-property s (1- (point)) 'face
3849 (org-agenda-get-day-face date))
3850 (put-text-property s (1- (point)) 'org-date-line t)
3851 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3852 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3853 (when todayp
3854 (put-text-property s (1- (point)) 'org-today t))
3855 (if rtnall (insert ;; all entries
3856 (org-finalize-agenda-entries
3857 (org-agenda-add-time-grid-maybe
3858 rtnall ndays todayp))
3859 "\n"))
3860 (put-text-property s (1- (point)) 'day d)
3861 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3862 (when (and org-agenda-clockreport-mode clocktable-start)
3863 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3864 ;; the above line is to ensure the restricted range!
3865 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3866 tbl)
3867 (setq p (org-plist-delete p :block))
3868 (setq p (plist-put p :tstart clocktable-start))
3869 (setq p (plist-put p :tend clocktable-end))
3870 (setq p (plist-put p :scope 'agenda))
3871 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3872 (setq filter (or org-agenda-tag-filter-while-redo
3873 (get 'org-agenda-tag-filter :preset-filter))))
3874 (setq p (plist-put p :tags (mapconcat (lambda (x)
3875 (if (string-match "[<>=]" x)
3878 filter ""))))
3879 (setq tbl (apply 'org-get-clocktable p))
3880 (insert tbl)))
3881 (goto-char (point-min))
3882 (or org-agenda-multi (org-fit-agenda-window))
3883 (unless (and (pos-visible-in-window-p (point-min))
3884 (pos-visible-in-window-p (point-max)))
3885 (goto-char (1- (point-max)))
3886 (recenter -1)
3887 (if (not (pos-visible-in-window-p (or start-pos 1)))
3888 (progn
3889 (goto-char (or start-pos 1))
3890 (recenter 1))))
3891 (goto-char (or start-pos 1))
3892 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3893 (if (eq org-agenda-show-log-scoped 'clockcheck)
3894 (org-agenda-show-clocking-issues))
3895 (org-finalize-agenda)
3896 (setq buffer-read-only t)
3897 (message "")))
3899 (defun org-agenda-ndays-to-span (n)
3900 "Return a span symbol for a span of N days, or N if none matches."
3901 (cond ((symbolp n) n)
3902 ((= n 1) 'day)
3903 ((= n 7) 'week)
3904 (t n)))
3906 (defun org-agenda-span-to-ndays (span start-day)
3907 "Return ndays from SPAN starting at START-DAY."
3908 (cond ((numberp span) span)
3909 ((eq span 'day) 1)
3910 ((eq span 'week) 7)
3911 ((eq span 'month)
3912 (let ((date (calendar-gregorian-from-absolute start-day)))
3913 (calendar-last-day-of-month (car date) (caddr date))))
3914 ((eq span 'year)
3915 (let ((date (calendar-gregorian-from-absolute start-day)))
3916 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3918 (defun org-agenda-span-name (span)
3919 "Return a SPAN name."
3920 (if (null span)
3922 (if (symbolp span)
3923 (capitalize (symbol-name span))
3924 (format "%d days" span))))
3926 ;;; Agenda word search
3928 (defvar org-agenda-search-history nil)
3929 (defvar org-todo-only nil)
3931 (defvar org-search-syntax-table nil
3932 "Special syntax table for org-mode search.
3933 In this table, we have single quotes not as word constituents, to
3934 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3936 (defun org-search-syntax-table ()
3937 (unless org-search-syntax-table
3938 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3939 (modify-syntax-entry ?' "." org-search-syntax-table)
3940 (modify-syntax-entry ?` "." org-search-syntax-table))
3941 org-search-syntax-table)
3943 (defvar org-agenda-last-search-view-search-was-boolean nil)
3945 ;;;###autoload
3946 (defun org-search-view (&optional todo-only string edit-at)
3947 "Show all entries that contain a phrase or words or regular expressions.
3949 With optional prefix argument TODO-ONLY, only consider entries that are
3950 TODO entries. The argument STRING can be used to pass a default search
3951 string into this function. If EDIT-AT is non-nil, it means that the
3952 user should get a chance to edit this string, with cursor at position
3953 EDIT-AT.
3955 The search string can be viewed either as a phrase that should be found as
3956 is, or it can be broken into a number of snippets, each of which must match
3957 in a Boolean way to select an entry. The default depends on the variable
3958 `org-agenda-search-view-always-boolean'.
3959 Even if this is turned off (the default) you can always switch to
3960 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3962 The default is a direct search of the whole phrase, where each space in
3963 the search string can expand to an arbitrary amount of whitespace,
3964 including newlines.
3966 If using a Boolean search, the search string is split on whitespace and
3967 each snippet is searched separately, with logical AND to select an entry.
3968 Words prefixed with a minus must *not* occur in the entry. Words without
3969 a prefix or prefixed with a plus must occur in the entry. Matching is
3970 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3971 match whole words, not parts of a word) if
3972 `org-agenda-search-view-force-full-words' is set (default is nil).
3974 Boolean search snippets enclosed by curly braces are interpreted as
3975 regular expressions that must or (when preceded with \"-\") must not
3976 match in the entry. Snippets enclosed into double quotes will be taken
3977 as a whole, to include whitespace.
3979 - If the search string starts with an asterisk, search only in headlines.
3980 - If (possibly after the leading star) the search string starts with an
3981 exclamation mark, this also means to look at TODO entries only, an effect
3982 that can also be achieved with a prefix argument.
3983 - If (possibly after star and exclamation mark) the search string starts
3984 with a colon, this will mean that the (non-regexp) snippets of the
3985 Boolean search must match as full words.
3987 This command searches the agenda files, and in addition the files listed
3988 in `org-agenda-text-search-extra-files'."
3989 (interactive "P")
3990 (org-prepare-agenda "SEARCH")
3991 (org-compile-prefix-format 'search)
3992 (org-set-sorting-strategy 'search)
3993 (let* ((props (list 'face nil
3994 'done-face 'org-agenda-done
3995 'org-not-done-regexp org-not-done-regexp
3996 'org-todo-regexp org-todo-regexp
3997 'org-complex-heading-regexp org-complex-heading-regexp
3998 'mouse-face 'highlight
3999 'help-echo (format "mouse-2 or RET jump to location")))
4000 (full-words org-agenda-search-view-force-full-words)
4001 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4002 regexp rtn rtnall files file pos
4003 marker category org-category-pos tags c neg re boolean
4004 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4005 (unless (and (not edit-at)
4006 (stringp string)
4007 (string-match "\\S-" string))
4008 (setq string (read-string
4009 (if org-agenda-search-view-always-boolean
4010 "[+-]Word/{Regexp} ...: "
4011 "Phrase, or [+-]Word/{Regexp} ...: ")
4012 (cond
4013 ((integerp edit-at) (cons string edit-at))
4014 (edit-at string))
4015 'org-agenda-search-history)))
4016 (org-set-local 'org-todo-only todo-only)
4017 (setq org-agenda-redo-command
4018 (list 'org-search-view (if todo-only t nil) string
4019 '(if current-prefix-arg 1 nil)))
4020 (setq org-agenda-query-string string)
4022 (if (equal (string-to-char string) ?*)
4023 (setq hdl-only t
4024 words (substring string 1))
4025 (setq words string))
4026 (when (equal (string-to-char words) ?!)
4027 (setq todo-only t
4028 words (substring words 1)))
4029 (when (equal (string-to-char words) ?:)
4030 (setq full-words t
4031 words (substring words 1)))
4032 (if (or org-agenda-search-view-always-boolean
4033 (member (string-to-char words) '(?- ?+ ?\{)))
4034 (setq boolean t))
4035 (setq words (org-split-string words))
4036 (let (www w)
4037 (while (setq w (pop words))
4038 (while (and (string-match "\\\\\\'" w) words)
4039 (setq w (concat (substring w 0 -1) " " (pop words))))
4040 (push w www))
4041 (setq words (nreverse www) www nil)
4042 (while (setq w (pop words))
4043 (when (and (string-match "\\`[-+]?{" w)
4044 (not (string-match "}\\'" w)))
4045 (while (and words (not (string-match "}\\'" (car words))))
4046 (setq w (concat w " " (pop words))))
4047 (setq w (concat w " " (pop words))))
4048 (push w www))
4049 (setq words (nreverse www)))
4050 (setq org-agenda-last-search-view-search-was-boolean boolean)
4051 (when boolean
4052 (let (wds w)
4053 (while (setq w (pop words))
4054 (if (or (equal (substring w 0 1) "\"")
4055 (and (> (length w) 1)
4056 (member (substring w 0 1) '("+" "-"))
4057 (equal (substring w 1 2) "\"")))
4058 (while (and words (not (equal (substring w -1) "\"")))
4059 (setq w (concat w " " (pop words)))))
4060 (and (string-match "\\`\\([-+]?\\)\"" w)
4061 (setq w (replace-match "\\1" nil nil w)))
4062 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4063 (push w wds))
4064 (setq words (nreverse wds))))
4065 (if boolean
4066 (mapc (lambda (w)
4067 (setq c (string-to-char w))
4068 (if (equal c ?-)
4069 (setq neg t w (substring w 1))
4070 (if (equal c ?+)
4071 (setq neg nil w (substring w 1))
4072 (setq neg nil)))
4073 (if (string-match "\\`{.*}\\'" w)
4074 (setq re (substring w 1 -1))
4075 (if full-words
4076 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4077 (setq re (regexp-quote (downcase w)))))
4078 (if neg (push re regexps-) (push re regexps+)))
4079 words)
4080 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4081 regexps+))
4082 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4083 (if (not regexps+)
4084 (setq regexp org-outline-regexp-bol)
4085 (setq regexp (pop regexps+))
4086 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4087 regexp))))
4088 (setq files (org-agenda-files nil 'ifmode))
4089 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4090 (pop org-agenda-text-search-extra-files)
4091 (setq files (org-add-archive-files files)))
4092 (setq files (append files org-agenda-text-search-extra-files)
4093 rtnall nil)
4094 (while (setq file (pop files))
4095 (setq ee nil)
4096 (catch 'nextfile
4097 (org-check-agenda-file file)
4098 (setq buffer (if (file-exists-p file)
4099 (org-get-agenda-file-buffer file)
4100 (error "No such file %s" file)))
4101 (if (not buffer)
4102 ;; If file does not exist, make sure an error message is sent
4103 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4104 file))))
4105 (with-current-buffer buffer
4106 (with-syntax-table (org-search-syntax-table)
4107 (unless (eq major-mode 'org-mode)
4108 (error "Agenda file %s is not in `org-mode'" file))
4109 (let ((case-fold-search t))
4110 (save-excursion
4111 (save-restriction
4112 (if org-agenda-restrict
4113 (narrow-to-region org-agenda-restrict-begin
4114 org-agenda-restrict-end)
4115 (widen))
4116 (goto-char (point-min))
4117 (unless (or (org-at-heading-p)
4118 (outline-next-heading))
4119 (throw 'nextfile t))
4120 (goto-char (max (point-min) (1- (point))))
4121 (while (re-search-forward regexp nil t)
4122 (org-back-to-heading t)
4123 (skip-chars-forward "* ")
4124 (setq beg (point-at-bol)
4125 beg1 (point)
4126 end (progn (outline-next-heading) (point)))
4127 (catch :skip
4128 (goto-char beg)
4129 (org-agenda-skip)
4130 (setq str (buffer-substring-no-properties
4131 (point-at-bol)
4132 (if hdl-only (point-at-eol) end)))
4133 (mapc (lambda (wr) (when (string-match wr str)
4134 (goto-char (1- end))
4135 (throw :skip t)))
4136 regexps-)
4137 (mapc (lambda (wr) (unless (string-match wr str)
4138 (goto-char (1- end))
4139 (throw :skip t)))
4140 (if todo-only
4141 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4142 regexps+)
4143 regexps+))
4144 (goto-char beg)
4145 (setq marker (org-agenda-new-marker (point))
4146 category (org-get-category)
4147 org-category-pos (get-text-property (point) 'org-category-position)
4148 tags (org-get-tags-at (point))
4149 txt (org-agenda-format-item
4151 (buffer-substring-no-properties
4152 beg1 (point-at-eol))
4153 category tags))
4154 (org-add-props txt props
4155 'org-marker marker 'org-hd-marker marker
4156 'org-todo-regexp org-todo-regexp
4157 'org-complex-heading-regexp org-complex-heading-regexp
4158 'priority 1000 'org-category category
4159 'org-category-position org-category-pos
4160 'type "search")
4161 (push txt ee)
4162 (goto-char (1- end))))))))))
4163 (setq rtn (nreverse ee))
4164 (setq rtnall (append rtnall rtn)))
4165 (if org-agenda-overriding-header
4166 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4167 nil 'face 'org-agenda-structure) "\n")
4168 (insert "Search words: ")
4169 (add-text-properties (point-min) (1- (point))
4170 (list 'face 'org-agenda-structure))
4171 (setq pos (point))
4172 (insert string "\n")
4173 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4174 (setq pos (point))
4175 (unless org-agenda-multi
4176 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4177 (add-text-properties pos (1- (point))
4178 (list 'face 'org-agenda-structure))))
4179 (org-agenda-mark-header-line (point-min))
4180 (when rtnall
4181 (insert (org-finalize-agenda-entries rtnall) "\n"))
4182 (goto-char (point-min))
4183 (or org-agenda-multi (org-fit-agenda-window))
4184 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4185 (org-finalize-agenda)
4186 (setq buffer-read-only t)))
4188 ;;; Agenda TODO list
4190 (defvar org-select-this-todo-keyword nil)
4191 (defvar org-last-arg nil)
4193 ;;;###autoload
4194 (defun org-todo-list (arg)
4195 "Show all (not done) TODO entries from all agenda file in a single list.
4196 The prefix arg can be used to select a specific TODO keyword and limit
4197 the list to these. When using \\[universal-argument], you will be prompted
4198 for a keyword. A numeric prefix directly selects the Nth keyword in
4199 `org-todo-keywords-1'."
4200 (interactive "P")
4201 (org-prepare-agenda "TODO")
4202 (org-compile-prefix-format 'todo)
4203 (org-set-sorting-strategy 'todo)
4204 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4205 (let* ((today (org-today))
4206 (date (calendar-gregorian-from-absolute today))
4207 (kwds org-todo-keywords-for-agenda)
4208 (completion-ignore-case t)
4209 (org-select-this-todo-keyword
4210 (if (stringp arg) arg
4211 (and arg (integerp arg) (> arg 0)
4212 (nth (1- arg) kwds))))
4213 rtn rtnall files file pos)
4214 (when (equal arg '(4))
4215 (setq org-select-this-todo-keyword
4216 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4217 (mapcar 'list kwds) nil nil)))
4218 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4219 (org-set-local 'org-last-arg arg)
4220 (setq org-agenda-redo-command
4221 '(org-todo-list (or current-prefix-arg org-last-arg)))
4222 (setq files (org-agenda-files nil 'ifmode)
4223 rtnall nil)
4224 (while (setq file (pop files))
4225 (catch 'nextfile
4226 (org-check-agenda-file file)
4227 (setq rtn (org-agenda-get-day-entries file date :todo))
4228 (setq rtnall (append rtnall rtn))))
4229 (if org-agenda-overriding-header
4230 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4231 nil 'face 'org-agenda-structure) "\n")
4232 (insert "Global list of TODO items of type: ")
4233 (add-text-properties (point-min) (1- (point))
4234 (list 'face 'org-agenda-structure
4235 'short-heading
4236 (concat "ToDo: "
4237 (or org-select-this-todo-keyword "ALL"))))
4238 (org-agenda-mark-header-line (point-min))
4239 (setq pos (point))
4240 (insert (or org-select-this-todo-keyword "ALL") "\n")
4241 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4242 (setq pos (point))
4243 (unless org-agenda-multi
4244 (insert "Available with `N r': (0)ALL")
4245 (let ((n 0) s)
4246 (mapc (lambda (x)
4247 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4248 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4249 (insert "\n "))
4250 (insert " " s))
4251 kwds))
4252 (insert "\n"))
4253 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4254 (org-agenda-mark-header-line (point-min))
4255 (when rtnall
4256 (insert (org-finalize-agenda-entries rtnall) "\n"))
4257 (goto-char (point-min))
4258 (or org-agenda-multi (org-fit-agenda-window))
4259 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4260 (org-finalize-agenda)
4261 (setq buffer-read-only t)))
4263 ;;; Agenda tags match
4265 ;;;###autoload
4266 (defun org-tags-view (&optional todo-only match)
4267 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4268 The prefix arg TODO-ONLY limits the search to TODO entries."
4269 (interactive "P")
4270 (let* ((org-tags-match-list-sublevels
4271 org-tags-match-list-sublevels)
4272 (completion-ignore-case t)
4273 rtn rtnall files file pos matcher
4274 buffer)
4275 (when (and (stringp match) (not (string-match "\\S-" match)))
4276 (setq match nil))
4277 (setq matcher (org-make-tags-matcher match)
4278 match (car matcher) matcher (cdr matcher))
4279 (org-prepare-agenda (concat "TAGS " match))
4280 (org-compile-prefix-format 'tags)
4281 (org-set-sorting-strategy 'tags)
4282 (setq org-agenda-query-string match)
4283 (setq org-agenda-redo-command
4284 (list 'org-tags-view (list 'quote todo-only)
4285 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4286 (setq files (org-agenda-files nil 'ifmode)
4287 rtnall nil)
4288 (while (setq file (pop files))
4289 (catch 'nextfile
4290 (org-check-agenda-file file)
4291 (setq buffer (if (file-exists-p file)
4292 (org-get-agenda-file-buffer file)
4293 (error "No such file %s" file)))
4294 (if (not buffer)
4295 ;; If file does not exist, error message to agenda
4296 (setq rtn (list
4297 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4298 rtnall (append rtnall rtn))
4299 (with-current-buffer buffer
4300 (unless (eq major-mode 'org-mode)
4301 (error "Agenda file %s is not in `org-mode'" file))
4302 (save-excursion
4303 (save-restriction
4304 (if org-agenda-restrict
4305 (narrow-to-region org-agenda-restrict-begin
4306 org-agenda-restrict-end)
4307 (widen))
4308 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4309 (setq rtnall (append rtnall rtn))))))))
4310 (if org-agenda-overriding-header
4311 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4312 nil 'face 'org-agenda-structure) "\n")
4313 (insert "Headlines with TAGS match: ")
4314 (add-text-properties (point-min) (1- (point))
4315 (list 'face 'org-agenda-structure
4316 'short-heading
4317 (concat "Match: " match)))
4318 (setq pos (point))
4319 (insert match "\n")
4320 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4321 (setq pos (point))
4322 (unless org-agenda-multi
4323 (insert "Press `C-u r' to search again with new search string\n"))
4324 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4325 (org-agenda-mark-header-line (point-min))
4326 (when rtnall
4327 (insert (org-finalize-agenda-entries rtnall) "\n"))
4328 (goto-char (point-min))
4329 (or org-agenda-multi (org-fit-agenda-window))
4330 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4331 (org-finalize-agenda)
4332 (setq buffer-read-only t)))
4334 ;;; Agenda Finding stuck projects
4336 (defvar org-agenda-skip-regexp nil
4337 "Regular expression used in skipping subtrees for the agenda.
4338 This is basically a temporary global variable that can be set and then
4339 used by user-defined selections using `org-agenda-skip-function'.")
4341 (defvar org-agenda-overriding-header nil
4342 "When set during agenda, todo and tags searches it replaces the header.
4343 This variable should not be set directly, but custom commands can bind it
4344 in the options section.")
4346 (defun org-agenda-skip-entry-when-regexp-matches ()
4347 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4348 If yes, it returns the end position of this entry, causing agenda commands
4349 to skip the entry but continuing the search in the subtree. This is a
4350 function that can be put into `org-agenda-skip-function' for the duration
4351 of a command."
4352 (let ((end (save-excursion (org-end-of-subtree t)))
4353 skip)
4354 (save-excursion
4355 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4356 (and skip end)))
4358 (defun org-agenda-skip-subtree-when-regexp-matches ()
4359 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4360 If yes, it returns the end position of this tree, causing agenda commands
4361 to skip this subtree. This is a function that can be put into
4362 `org-agenda-skip-function' for the duration of a command."
4363 (let ((end (save-excursion (org-end-of-subtree t)))
4364 skip)
4365 (save-excursion
4366 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4367 (and skip end)))
4369 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4370 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4371 If yes, it returns the end position of the current entry (NOT the tree),
4372 causing agenda commands to skip the entry but continuing the search in
4373 the subtree. This is a function that can be put into
4374 `org-agenda-skip-function' for the duration of a command. An important
4375 use of this function is for the stuck project list."
4376 (let ((end (save-excursion (org-end-of-subtree t)))
4377 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4378 skip)
4379 (save-excursion
4380 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4381 (and skip entry-end)))
4383 (defun org-agenda-skip-entry-if (&rest conditions)
4384 "Skip entry if any of CONDITIONS is true.
4385 See `org-agenda-skip-if' for details."
4386 (org-agenda-skip-if nil conditions))
4388 (defun org-agenda-skip-subtree-if (&rest conditions)
4389 "Skip entry if any of CONDITIONS is true.
4390 See `org-agenda-skip-if' for details."
4391 (org-agenda-skip-if t conditions))
4393 (defun org-agenda-skip-if (subtree conditions)
4394 "Checks current entity for CONDITIONS.
4395 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4396 the entry, i.e. the text before the next heading is checked.
4398 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4399 from different tests. Valid conditions are:
4401 scheduled Check if there is a scheduled cookie
4402 notscheduled Check if there is no scheduled cookie
4403 deadline Check if there is a deadline
4404 notdeadline Check if there is no deadline
4405 timestamp Check if there is a timestamp (also deadline or scheduled)
4406 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4407 regexp Check if regexp matches
4408 notregexp Check if regexp does not match.
4409 todo Check if TODO keyword matches
4410 nottodo Check if TODO keyword does not match
4412 The regexp is taken from the conditions list, it must come right after
4413 the `regexp' or `notregexp' element.
4415 `todo' and `nottodo' accept as an argument a list of todo
4416 keywords, which may include \"*\" to match any todo keyword.
4418 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4420 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4422 Instead of a list a keyword class may be given
4424 (org-agenda-skip-entry-if 'nottodo 'done)
4426 would skip entries that haven't been marked with any of \"DONE\"
4427 keywords. Possible classes are: `todo', `done', `any'.
4429 If any of these conditions is met, this function returns the end point of
4430 the entity, causing the search to continue from there. This is a function
4431 that can be put into `org-agenda-skip-function' for the duration of a command."
4432 (let (beg end m)
4433 (org-back-to-heading t)
4434 (setq beg (point)
4435 end (if subtree
4436 (progn (org-end-of-subtree t) (point))
4437 (progn (outline-next-heading) (1- (point)))))
4438 (goto-char beg)
4439 (and
4441 (and (memq 'scheduled conditions)
4442 (re-search-forward org-scheduled-time-regexp end t))
4443 (and (memq 'notscheduled conditions)
4444 (not (re-search-forward org-scheduled-time-regexp end t)))
4445 (and (memq 'deadline conditions)
4446 (re-search-forward org-deadline-time-regexp end t))
4447 (and (memq 'notdeadline conditions)
4448 (not (re-search-forward org-deadline-time-regexp end t)))
4449 (and (memq 'timestamp conditions)
4450 (re-search-forward org-ts-regexp end t))
4451 (and (memq 'nottimestamp conditions)
4452 (not (re-search-forward org-ts-regexp end t)))
4453 (and (setq m (memq 'regexp conditions))
4454 (stringp (nth 1 m))
4455 (re-search-forward (nth 1 m) end t))
4456 (and (setq m (memq 'notregexp conditions))
4457 (stringp (nth 1 m))
4458 (not (re-search-forward (nth 1 m) end t)))
4459 (and (or
4460 (setq m (memq 'todo conditions))
4461 (setq m (memq 'nottodo conditions)))
4462 (org-agenda-skip-if-todo m end)))
4463 end)))
4465 (defun org-agenda-skip-if-todo (args end)
4466 "Helper function for `org-agenda-skip-if', do not use it directly.
4467 ARGS is a list with first element either `todo' or `nottodo'.
4468 The remainder is either a list of TODO keywords, or a state symbol
4469 `todo' or `done' or `any'."
4470 (let ((kw (car args))
4471 (arg (cadr args))
4472 todo-wds todo-re)
4473 (setq todo-wds
4474 (org-uniquify
4475 (cond
4476 ((listp arg) ;; list of keywords
4477 (if (member "*" arg)
4478 (mapcar 'substring-no-properties org-todo-keywords-1)
4479 arg))
4480 ((symbolp arg) ;; keyword class name
4481 (cond
4482 ((eq arg 'todo)
4483 (org-delete-all org-done-keywords
4484 (mapcar 'substring-no-properties
4485 org-todo-keywords-1)))
4486 ((eq arg 'done) org-done-keywords)
4487 ((eq arg 'any)
4488 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4489 (setq todo-re
4490 (concat "^\\*+[ \t]+\\<\\("
4491 (mapconcat 'identity todo-wds "\\|")
4492 "\\)\\>"))
4493 (if (eq kw 'todo)
4494 (re-search-forward todo-re end t)
4495 (not (re-search-forward todo-re end t)))))
4497 ;;;###autoload
4498 (defun org-agenda-list-stuck-projects (&rest ignore)
4499 "Create agenda view for projects that are stuck.
4500 Stuck projects are project that have no next actions. For the definitions
4501 of what a project is and how to check if it stuck, customize the variable
4502 `org-stuck-projects'."
4503 (interactive)
4504 (let* ((org-agenda-skip-function
4505 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4506 ;; We could have used org-agenda-skip-if here.
4507 (org-agenda-overriding-header
4508 (or org-agenda-overriding-header "List of stuck projects: "))
4509 (matcher (nth 0 org-stuck-projects))
4510 (todo (nth 1 org-stuck-projects))
4511 (todo-wds (if (member "*" todo)
4512 (progn
4513 (org-prepare-agenda-buffers (org-agenda-files
4514 nil 'ifmode))
4515 (org-delete-all
4516 org-done-keywords-for-agenda
4517 (copy-sequence org-todo-keywords-for-agenda)))
4518 todo))
4519 (todo-re (concat "^\\*+[ \t]+\\("
4520 (mapconcat 'identity todo-wds "\\|")
4521 "\\)\\>"))
4522 (tags (nth 2 org-stuck-projects))
4523 (tags-re (if (member "*" tags)
4524 (concat org-outline-regexp-bol
4525 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4526 (if tags
4527 (concat org-outline-regexp-bol
4528 ".*:\\("
4529 (mapconcat 'identity tags "\\|")
4530 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4531 (gen-re (nth 3 org-stuck-projects))
4532 (re-list
4533 (delq nil
4534 (list
4535 (if todo todo-re)
4536 (if tags tags-re)
4537 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4538 gen-re)))))
4539 (setq org-agenda-skip-regexp
4540 (if re-list
4541 (mapconcat 'identity re-list "\\|")
4542 (error "No information how to identify unstuck projects")))
4543 (org-tags-view nil matcher)
4544 (with-current-buffer org-agenda-buffer-name
4545 (setq org-agenda-redo-command
4546 '(org-agenda-list-stuck-projects
4547 (or current-prefix-arg org-last-arg))))))
4549 ;;; Diary integration
4551 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4552 (defvar diary-list-entries-hook)
4553 (defvar diary-time-regexp)
4554 (defun org-get-entries-from-diary (date)
4555 "Get the (Emacs Calendar) diary entries for DATE."
4556 (require 'diary-lib)
4557 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4558 (diary-display-hook '(fancy-diary-display))
4559 (diary-display-function 'fancy-diary-display)
4560 (pop-up-frames nil)
4561 (diary-list-entries-hook
4562 (cons 'org-diary-default-entry diary-list-entries-hook))
4563 (diary-file-name-prefix-function nil) ; turn this feature off
4564 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4565 entries
4566 (org-disable-agenda-to-diary t))
4567 (save-excursion
4568 (save-window-excursion
4569 (funcall (if (fboundp 'diary-list-entries)
4570 'diary-list-entries 'list-diary-entries)
4571 date 1)))
4572 (if (not (get-buffer diary-fancy-buffer))
4573 (setq entries nil)
4574 (with-current-buffer diary-fancy-buffer
4575 (setq buffer-read-only nil)
4576 (if (zerop (buffer-size))
4577 ;; No entries
4578 (setq entries nil)
4579 ;; Omit the date and other unnecessary stuff
4580 (org-agenda-cleanup-fancy-diary)
4581 ;; Add prefix to each line and extend the text properties
4582 (if (zerop (buffer-size))
4583 (setq entries nil)
4584 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4585 (setq entries
4586 (with-temp-buffer
4587 (insert entries) (goto-char (point-min))
4588 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4589 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4590 (replace-match (concat "; " (match-string 1)))))
4591 (buffer-string)))))
4592 (set-buffer-modified-p nil)
4593 (kill-buffer diary-fancy-buffer)))
4594 (when entries
4595 (setq entries (org-split-string entries "\n"))
4596 (setq entries
4597 (mapcar
4598 (lambda (x)
4599 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4600 ;; Extend the text properties to the beginning of the line
4601 (org-add-props x (text-properties-at (1- (length x)) x)
4602 'type "diary" 'date date 'face 'org-agenda-diary))
4603 entries)))))
4605 (defvar org-agenda-cleanup-fancy-diary-hook nil
4606 "Hook run when the fancy diary buffer is cleaned up.")
4608 (defun org-agenda-cleanup-fancy-diary ()
4609 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4610 This gets rid of the date, the underline under the date, and
4611 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4612 date. It also removes lines that contain only whitespace."
4613 (goto-char (point-min))
4614 (if (looking-at ".*?:[ \t]*")
4615 (progn
4616 (replace-match "")
4617 (re-search-forward "\n=+$" nil t)
4618 (replace-match "")
4619 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4620 (re-search-forward "\n=+$" nil t)
4621 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4622 (goto-char (point-min))
4623 (while (re-search-forward "^ +\n" nil t)
4624 (replace-match ""))
4625 (goto-char (point-min))
4626 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4627 (replace-match ""))
4628 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4630 ;; Make sure entries from the diary have the right text properties.
4631 (eval-after-load "diary-lib"
4632 '(if (boundp 'diary-modify-entry-list-string-function)
4633 ;; We can rely on the hook, nothing to do
4635 ;; Hook not available, must use advice to make this work
4636 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4637 "Make the position visible."
4638 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4639 (stringp string)
4640 buffer-file-name)
4641 (setq string (org-modify-diary-entry-string string))))))
4643 (defun org-modify-diary-entry-string (string)
4644 "Add text properties to string, allowing org-mode to act on it."
4645 (org-add-props string nil
4646 'mouse-face 'highlight
4647 'help-echo (if buffer-file-name
4648 (format "mouse-2 or RET jump to diary file %s"
4649 (abbreviate-file-name buffer-file-name))
4651 'org-agenda-diary-link t
4652 'org-marker (org-agenda-new-marker (point-at-bol))))
4654 (defun org-diary-default-entry ()
4655 "Add a dummy entry to the diary.
4656 Needed to avoid empty dates which mess up holiday display."
4657 ;; Catch the error if dealing with the new add-to-diary-alist
4658 (when org-disable-agenda-to-diary
4659 (condition-case nil
4660 (org-add-to-diary-list original-date "Org-mode dummy" "")
4661 (error
4662 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4664 (defun org-add-to-diary-list (&rest args)
4665 (if (fboundp 'diary-add-to-list)
4666 (apply 'diary-add-to-list args)
4667 (apply 'add-to-diary-list args)))
4669 (defvar org-diary-last-run-time nil)
4671 ;;;###autoload
4672 (defun org-diary (&rest args)
4673 "Return diary information from org-files.
4674 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4675 It accesses org files and extracts information from those files to be
4676 listed in the diary. The function accepts arguments specifying what
4677 items should be listed. For a list of arguments allowed here, see the
4678 variable `org-agenda-entry-types'.
4680 The call in the diary file should look like this:
4682 &%%(org-diary) ~/path/to/some/orgfile.org
4684 Use a separate line for each org file to check. Or, if you omit the file name,
4685 all files listed in `org-agenda-files' will be checked automatically:
4687 &%%(org-diary)
4689 If you don't give any arguments (as in the example above), the default
4690 arguments (:deadline :scheduled :timestamp :sexp) are used.
4691 So the example above may also be written as
4693 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4695 The function expects the lisp variables `entry' and `date' to be provided
4696 by the caller, because this is how the calendar works. Don't use this
4697 function from a program - use `org-agenda-get-day-entries' instead."
4698 (when (> (- (org-float-time)
4699 org-agenda-last-marker-time)
4701 ;; I am not sure if this works with sticky agendas, because the marker
4702 ;; list is then no longer a global variable.
4703 (org-agenda-reset-markers))
4704 (org-compile-prefix-format 'agenda)
4705 (org-set-sorting-strategy 'agenda)
4706 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4707 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4708 (list entry)
4709 (org-agenda-files t)))
4710 (time (org-float-time))
4711 file rtn results)
4712 (when (or (not org-diary-last-run-time)
4713 (> (- time
4714 org-diary-last-run-time)
4716 (org-prepare-agenda-buffers files))
4717 (setq org-diary-last-run-time time)
4718 ;; If this is called during org-agenda, don't return any entries to
4719 ;; the calendar. Org Agenda will list these entries itself.
4720 (if org-disable-agenda-to-diary (setq files nil))
4721 (while (setq file (pop files))
4722 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4723 (setq results (append results rtn)))
4724 (if results
4725 (concat (org-finalize-agenda-entries results) "\n"))))
4727 ;;; Agenda entry finders
4729 (defun org-agenda-get-day-entries (file date &rest args)
4730 "Does the work for `org-diary' and `org-agenda'.
4731 FILE is the path to a file to be checked for entries. DATE is date like
4732 the one returned by `calendar-current-date'. ARGS are symbols indicating
4733 which kind of entries should be extracted. For details about these, see
4734 the documentation of `org-diary'."
4735 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4736 (let* ((org-startup-folded nil)
4737 (org-startup-align-all-tables nil)
4738 (buffer (if (file-exists-p file)
4739 (org-get-agenda-file-buffer file)
4740 (error "No such file %s" file)))
4741 arg results rtn deadline-results)
4742 (if (not buffer)
4743 ;; If file does not exist, make sure an error message ends up in diary
4744 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4745 (with-current-buffer buffer
4746 (unless (eq major-mode 'org-mode)
4747 (error "Agenda file %s is not in `org-mode'" file))
4748 (let ((case-fold-search nil))
4749 (save-excursion
4750 (save-restriction
4751 (if org-agenda-restrict
4752 (narrow-to-region org-agenda-restrict-begin
4753 org-agenda-restrict-end)
4754 (widen))
4755 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4756 (while (setq arg (pop args))
4757 (cond
4758 ((and (eq arg :todo)
4759 (equal date (calendar-gregorian-from-absolute
4760 (org-today))))
4761 (setq rtn (org-agenda-get-todos))
4762 (setq results (append results rtn)))
4763 ((eq arg :timestamp)
4764 (setq rtn (org-agenda-get-blocks))
4765 (setq results (append results rtn))
4766 (setq rtn (org-agenda-get-timestamps))
4767 (setq results (append results rtn)))
4768 ((eq arg :sexp)
4769 (setq rtn (org-agenda-get-sexps))
4770 (setq results (append results rtn)))
4771 ((eq arg :scheduled)
4772 (setq rtn (org-agenda-get-scheduled deadline-results))
4773 (setq results (append results rtn)))
4774 ((eq arg :closed)
4775 (setq rtn (org-agenda-get-progress))
4776 (setq results (append results rtn)))
4777 ((eq arg :deadline)
4778 (setq rtn (org-agenda-get-deadlines))
4779 (setq deadline-results (copy-sequence rtn))
4780 (setq results (append results rtn))))))))
4781 results))))
4783 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4784 (defun org-agenda-get-todos ()
4785 "Return the TODO information for agenda display."
4786 (let* ((props (list 'face nil
4787 'done-face 'org-agenda-done
4788 'org-not-done-regexp org-not-done-regexp
4789 'org-todo-regexp org-todo-regexp
4790 'org-complex-heading-regexp org-complex-heading-regexp
4791 'mouse-face 'highlight
4792 'help-echo
4793 (format "mouse-2 or RET jump to org file %s"
4794 (abbreviate-file-name buffer-file-name))))
4795 (regexp (format org-heading-keyword-regexp-format
4796 (cond
4797 ((and org-select-this-todo-keyword
4798 (equal org-select-this-todo-keyword "*"))
4799 org-todo-regexp)
4800 (org-select-this-todo-keyword
4801 (concat "\\("
4802 (mapconcat 'identity
4803 (org-split-string
4804 org-select-this-todo-keyword
4805 "|")
4806 "\\|") "\\)"))
4807 (t org-not-done-regexp))))
4808 marker priority category org-category-pos tags todo-state
4809 ee txt beg end)
4810 (goto-char (point-min))
4811 (while (re-search-forward regexp nil t)
4812 (catch :skip
4813 (save-match-data
4814 (beginning-of-line)
4815 (org-agenda-skip)
4816 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4817 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4818 (goto-char (1+ beg))
4819 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4820 (throw :skip nil)))
4821 (goto-char (match-beginning 2))
4822 (setq marker (org-agenda-new-marker (match-beginning 0))
4823 category (org-get-category)
4824 org-category-pos (get-text-property (point) 'org-category-position)
4825 txt (org-trim
4826 (buffer-substring (match-beginning 2) (match-end 0)))
4827 tags (org-get-tags-at (point))
4828 txt (org-agenda-format-item "" txt category tags)
4829 priority (1+ (org-get-priority txt))
4830 todo-state (org-get-todo-state))
4831 (org-add-props txt props
4832 'org-marker marker 'org-hd-marker marker
4833 'priority priority 'org-category category
4834 'org-category-position org-category-pos
4835 'type "todo" 'todo-state todo-state)
4836 (push txt ee)
4837 (if org-agenda-todo-list-sublevels
4838 (goto-char (match-end 2))
4839 (org-end-of-subtree 'invisible))))
4840 (nreverse ee)))
4842 (defun org-agenda-todo-custom-ignore-p (time n)
4843 "Check whether timestamp is farther away then n number of days.
4844 This function is invoked if `org-agenda-todo-ignore-deadlines',
4845 `org-agenda-todo-ignore-scheduled' or
4846 `org-agenda-todo-ignore-timestamp' is set to an integer."
4847 (let ((days (org-days-to-time time)))
4848 (if (>= n 0)
4849 (>= days n)
4850 (<= days n))))
4852 ;;;###autoload
4853 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4854 (&optional end)
4855 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4856 (when (or org-agenda-todo-ignore-with-date
4857 org-agenda-todo-ignore-scheduled
4858 org-agenda-todo-ignore-deadlines
4859 org-agenda-todo-ignore-timestamp)
4860 (setq end (or end (save-excursion (outline-next-heading) (point))))
4861 (save-excursion
4862 (or (and org-agenda-todo-ignore-with-date
4863 (re-search-forward org-ts-regexp end t))
4864 (and org-agenda-todo-ignore-scheduled
4865 (re-search-forward org-scheduled-time-regexp end t)
4866 (cond
4867 ((eq org-agenda-todo-ignore-scheduled 'future)
4868 (> (org-days-to-time (match-string 1)) 0))
4869 ((eq org-agenda-todo-ignore-scheduled 'past)
4870 (<= (org-days-to-time (match-string 1)) 0))
4871 ((numberp org-agenda-todo-ignore-scheduled)
4872 (org-agenda-todo-custom-ignore-p
4873 (match-string 1) org-agenda-todo-ignore-scheduled))
4874 (t)))
4875 (and org-agenda-todo-ignore-deadlines
4876 (re-search-forward org-deadline-time-regexp end t)
4877 (cond
4878 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4879 ((eq org-agenda-todo-ignore-deadlines 'far)
4880 (not (org-deadline-close (match-string 1))))
4881 ((eq org-agenda-todo-ignore-deadlines 'future)
4882 (> (org-days-to-time (match-string 1)) 0))
4883 ((eq org-agenda-todo-ignore-deadlines 'past)
4884 (<= (org-days-to-time (match-string 1)) 0))
4885 ((numberp org-agenda-todo-ignore-deadlines)
4886 (org-agenda-todo-custom-ignore-p
4887 (match-string 1) org-agenda-todo-ignore-deadlines))
4888 (t (org-deadline-close (match-string 1)))))
4889 (and org-agenda-todo-ignore-timestamp
4890 (let ((buffer (current-buffer))
4891 (regexp
4892 (concat
4893 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4894 (start (point)))
4895 ;; Copy current buffer into a temporary one
4896 (with-temp-buffer
4897 (insert-buffer-substring buffer start end)
4898 (goto-char (point-min))
4899 ;; Delete SCHEDULED and DEADLINE items
4900 (while (re-search-forward regexp end t)
4901 (delete-region (match-beginning 0) (match-end 0)))
4902 (goto-char (point-min))
4903 ;; No search for timestamp left
4904 (when (re-search-forward org-ts-regexp nil t)
4905 (cond
4906 ((eq org-agenda-todo-ignore-timestamp 'future)
4907 (> (org-days-to-time (match-string 1)) 0))
4908 ((eq org-agenda-todo-ignore-timestamp 'past)
4909 (<= (org-days-to-time (match-string 1)) 0))
4910 ((numberp org-agenda-todo-ignore-timestamp)
4911 (org-agenda-todo-custom-ignore-p
4912 (match-string 1) org-agenda-todo-ignore-timestamp))
4913 (t))))))))))
4915 (defconst org-agenda-no-heading-message
4916 "No heading for this item in buffer or region.")
4918 (defun org-agenda-get-timestamps ()
4919 "Return the date stamp information for agenda display."
4920 (let* ((props (list 'face 'org-agenda-calendar-event
4921 'org-not-done-regexp org-not-done-regexp
4922 'org-todo-regexp org-todo-regexp
4923 'org-complex-heading-regexp org-complex-heading-regexp
4924 'mouse-face 'highlight
4925 'help-echo
4926 (format "mouse-2 or RET jump to org file %s"
4927 (abbreviate-file-name buffer-file-name))))
4928 (d1 (calendar-absolute-from-gregorian date))
4929 (remove-re
4930 (concat
4931 (regexp-quote
4932 (format-time-string
4933 "<%Y-%m-%d"
4934 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4935 ".*?>"))
4936 (regexp
4937 (concat
4938 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4939 (regexp-quote
4940 (substring
4941 (format-time-string
4942 (car org-time-stamp-formats)
4943 (apply 'encode-time ; DATE bound by calendar
4944 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4945 1 11))
4946 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4947 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4948 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4949 donep tmp priority category org-category-pos ee txt timestr tags
4950 b0 b3 e3 head todo-state end-of-match show-all)
4951 (goto-char (point-min))
4952 (while (setq end-of-match (re-search-forward regexp nil t))
4953 (setq b0 (match-beginning 0)
4954 b3 (match-beginning 3) e3 (match-end 3)
4955 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4956 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4957 (member todo-state
4958 org-agenda-repeating-timestamp-show-all)))
4959 (catch :skip
4960 (and (org-at-date-range-p) (throw :skip nil))
4961 (org-agenda-skip)
4962 (if (and (match-end 1)
4963 (not (= d1 (org-time-string-to-absolute
4964 (match-string 1) d1 nil show-all
4965 (current-buffer) b0))))
4966 (throw :skip nil))
4967 (if (and e3
4968 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4969 (throw :skip nil))
4970 (setq tmp (buffer-substring (max (point-min)
4971 (- b0 org-ds-keyword-length))
4973 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4974 inactivep (= (char-after b0) ?\[)
4975 deadlinep (string-match org-deadline-regexp tmp)
4976 scheduledp (string-match org-scheduled-regexp tmp)
4977 closedp (and org-agenda-include-inactive-timestamps
4978 (string-match org-closed-string tmp))
4979 clockp (and org-agenda-include-inactive-timestamps
4980 (or (string-match org-clock-string tmp)
4981 (string-match "]-+\\'" tmp)))
4982 donep (member todo-state org-done-keywords))
4983 (if (or scheduledp deadlinep closedp clockp
4984 (and donep org-agenda-skip-timestamp-if-done))
4985 (throw :skip t))
4986 (if (string-match ">" timestr)
4987 ;; substring should only run to end of time stamp
4988 (setq timestr (substring timestr 0 (match-end 0))))
4989 (setq marker (org-agenda-new-marker b0)
4990 category (org-get-category b0)
4991 org-category-pos (get-text-property b0 'org-category-position))
4992 (save-excursion
4993 (if (not (re-search-backward org-outline-regexp-bol nil t))
4994 (setq txt org-agenda-no-heading-message)
4995 (goto-char (match-beginning 0))
4996 (setq hdmarker (org-agenda-new-marker)
4997 tags (org-get-tags-at))
4998 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4999 (setq head (or (match-string 1) ""))
5000 (setq txt (org-agenda-format-item
5001 (if inactivep org-agenda-inactive-leader nil)
5002 head category tags timestr
5003 remove-re)))
5004 (setq priority (org-get-priority txt))
5005 (org-add-props txt props
5006 'org-marker marker 'org-hd-marker hdmarker)
5007 (org-add-props txt nil 'priority priority
5008 'org-category category 'date date
5009 'org-category-position org-category-pos
5010 'todo-state todo-state
5011 'type "timestamp")
5012 (push txt ee))
5013 (if org-agenda-skip-additional-timestamps-same-entry
5014 (outline-next-heading)
5015 (goto-char end-of-match))))
5016 (nreverse ee)))
5018 (defun org-agenda-get-sexps ()
5019 "Return the sexp information for agenda display."
5020 (require 'diary-lib)
5021 (let* ((props (list 'face 'org-agenda-calendar-sexp
5022 'mouse-face 'highlight
5023 'help-echo
5024 (format "mouse-2 or RET jump to org file %s"
5025 (abbreviate-file-name buffer-file-name))))
5026 (regexp "^&?%%(")
5027 marker category org-category-pos ee txt tags entry
5028 result beg b sexp sexp-entry todo-state)
5029 (goto-char (point-min))
5030 (while (re-search-forward regexp nil t)
5031 (catch :skip
5032 (org-agenda-skip)
5033 (setq beg (match-beginning 0))
5034 (goto-char (1- (match-end 0)))
5035 (setq b (point))
5036 (forward-sexp 1)
5037 (setq sexp (buffer-substring b (point)))
5038 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5039 (org-trim (match-string 1))
5040 ""))
5041 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5042 (when result
5043 (setq marker (org-agenda-new-marker beg)
5044 category (org-get-category beg)
5045 org-category-pos (get-text-property beg 'org-category-position)
5046 todo-state (org-get-todo-state))
5048 (dolist (r (if (stringp result)
5049 (list result)
5050 result)) ;; we expect a list here
5051 (if (string-match "\\S-" r)
5052 (setq txt r)
5053 (setq txt "SEXP entry returned empty string"))
5055 (setq txt (org-agenda-format-item
5056 "" txt category tags 'time))
5057 (org-add-props txt props 'org-marker marker)
5058 (org-add-props txt nil
5059 'org-category category 'date date 'todo-state todo-state
5060 'org-category-position org-category-pos
5061 'type "sexp")
5062 (push txt ee)))))
5063 (nreverse ee)))
5065 ;; Calendar sanity: define some functions that are independent of
5066 ;; `calendar-date-style'.
5067 ;; Normally I would like to use ISO format when calling the diary functions,
5068 ;; but to make sure we still have Emacs 22 compatibility we bind
5069 ;; also `european-calendar-style' and use european format
5070 (defun org-anniversary (year month day &optional mark)
5071 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5072 (org-no-warnings
5073 (let ((calendar-date-style 'european) (european-calendar-style t))
5074 (diary-anniversary day month year mark))))
5075 (defun org-cyclic (N year month day &optional mark)
5076 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5077 (org-no-warnings
5078 (let ((calendar-date-style 'european) (european-calendar-style t))
5079 (diary-cyclic N day month year mark))))
5080 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5081 "Like `diary-block', but with fixed (ISO) order of arguments."
5082 (org-no-warnings
5083 (let ((calendar-date-style 'european) (european-calendar-style t))
5084 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5085 (defun org-date (year month day &optional mark)
5086 "Like `diary-date', but with fixed (ISO) order of arguments."
5087 (org-no-warnings
5088 (let ((calendar-date-style 'european) (european-calendar-style t))
5089 (diary-date day month year mark))))
5090 (defalias 'org-float 'diary-float)
5092 ;; Define the` org-class' function
5093 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5094 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5095 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5096 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5097 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5098 `holidays', then any date that is known by the Emacs calendar to be a
5099 holiday will also be skipped."
5100 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5101 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5102 (d (calendar-absolute-from-gregorian date)))
5103 (and
5104 (<= date1 d)
5105 (<= d date2)
5106 (= (calendar-day-of-week date) dayname)
5107 (or (not skip-weeks)
5108 (progn
5109 (require 'cal-iso)
5110 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5111 (not (and (memq 'holidays skip-weeks)
5112 (calendar-check-holidays date)))
5113 entry)))
5115 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5116 "Like `org-class', but honor `calendar-date-style'.
5117 The order of the first 2 times 3 arguments depends on the variable
5118 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5119 So for American calendars, give this as MONTH DAY YEAR, for European as
5120 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5121 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5122 is any number of ISO weeks in the block period for which the item should
5123 be skipped.
5125 This function is here only for backward compatibility and it is deprecated,
5126 please use `org-class' instead."
5127 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5128 (date2 (org-order-calendar-date-args m2 d2 y2)))
5129 (org-class
5130 (nth 2 date1) (car date1) (nth 1 date1)
5131 (nth 2 date2) (car date2) (nth 1 date2)
5132 dayname skip-weeks)))
5133 (make-obsolete 'org-diary-class 'org-class "")
5135 (defalias 'org-get-closed 'org-agenda-get-progress)
5136 (defun org-agenda-get-progress ()
5137 "Return the logged TODO entries for agenda display."
5138 (let* ((props (list 'mouse-face 'highlight
5139 'org-not-done-regexp org-not-done-regexp
5140 'org-todo-regexp org-todo-regexp
5141 'org-complex-heading-regexp org-complex-heading-regexp
5142 'help-echo
5143 (format "mouse-2 or RET jump to org file %s"
5144 (abbreviate-file-name buffer-file-name))))
5145 (items (if (consp org-agenda-show-log-scoped)
5146 org-agenda-show-log-scoped
5147 (if (eq org-agenda-show-log-scoped 'clockcheck)
5148 '(clock)
5149 org-agenda-log-mode-items)))
5150 (parts
5151 (delq nil
5152 (list
5153 (if (memq 'closed items) (concat "\\<" org-closed-string))
5154 (if (memq 'clock items) (concat "\\<" org-clock-string))
5155 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5156 (parts-re (if parts (mapconcat 'identity parts "\\|")
5157 (error "`org-agenda-log-mode-items' is empty")))
5158 (regexp (concat
5159 "\\(" parts-re "\\)"
5160 " *\\["
5161 (regexp-quote
5162 (substring
5163 (format-time-string
5164 (car org-time-stamp-formats)
5165 (apply 'encode-time ; DATE bound by calendar
5166 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5167 1 11))))
5168 (org-agenda-search-headline-for-time nil)
5169 marker hdmarker priority category org-category-pos tags closedp
5170 statep clockp state ee txt extra timestr rest clocked)
5171 (goto-char (point-min))
5172 (while (re-search-forward regexp nil t)
5173 (catch :skip
5174 (org-agenda-skip)
5175 (setq marker (org-agenda-new-marker (match-beginning 0))
5176 closedp (equal (match-string 1) org-closed-string)
5177 statep (equal (string-to-char (match-string 1)) ?-)
5178 clockp (not (or closedp statep))
5179 state (and statep (match-string 2))
5180 category (org-get-category (match-beginning 0))
5181 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5182 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5183 (when (string-match "\\]" timestr)
5184 ;; substring should only run to end of time stamp
5185 (setq rest (substring timestr (match-end 0))
5186 timestr (substring timestr 0 (match-end 0)))
5187 (if (and (not closedp) (not statep)
5188 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5189 rest))
5190 (progn (setq timestr (concat (substring timestr 0 -1)
5191 "-" (match-string 1 rest) "]"))
5192 (setq clocked (match-string 2 rest)))
5193 (setq clocked "-")))
5194 (save-excursion
5195 (setq extra
5196 (cond
5197 ((not org-agenda-log-mode-add-notes) nil)
5198 (statep
5199 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5200 (match-string 1)))
5201 (clockp
5202 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5203 (match-string 1)))))
5204 (if (not (re-search-backward org-outline-regexp-bol nil t))
5205 (setq txt org-agenda-no-heading-message)
5206 (goto-char (match-beginning 0))
5207 (setq hdmarker (org-agenda-new-marker)
5208 tags (org-get-tags-at))
5209 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5210 (setq txt (match-string 1))
5211 (when extra
5212 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5213 (setq txt (concat (substring txt 0 (match-beginning 1))
5214 " - " extra " " (match-string 2 txt)))
5215 (setq txt (concat txt " - " extra))))
5216 (setq txt (org-agenda-format-item
5217 (cond
5218 (closedp "Closed: ")
5219 (statep (concat "State: (" state ")"))
5220 (t (concat "Clocked: (" clocked ")")))
5221 txt category tags timestr)))
5222 (setq priority 100000)
5223 (org-add-props txt props
5224 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5225 'priority priority 'org-category category
5226 'org-category-position org-category-pos
5227 'type "closed" 'date date
5228 'undone-face 'org-warning 'done-face 'org-agenda-done)
5229 (push txt ee))
5230 (goto-char (point-at-eol))))
5231 (nreverse ee)))
5233 (defun org-agenda-show-clocking-issues ()
5234 "Add overlays, showing issues with clocking.
5235 See also the user option `org-agenda-clock-consistency-checks'."
5236 (interactive)
5237 (let* ((pl org-agenda-clock-consistency-checks)
5238 (re (concat "^[ \t]*"
5239 org-clock-string
5240 "[ \t]+"
5241 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5242 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5243 (tlstart 0.)
5244 (tlend 0.)
5245 (maxtime (org-hh:mm-string-to-minutes
5246 (or (plist-get pl :max-duration) "24:00")))
5247 (mintime (org-hh:mm-string-to-minutes
5248 (or (plist-get pl :min-duration) 0)))
5249 (maxgap (org-hh:mm-string-to-minutes
5250 ;; default 30:00 means never complain
5251 (or (plist-get pl :max-gap) "30:00")))
5252 (gapok (mapcar 'org-hh:mm-string-to-minutes
5253 (plist-get pl :gap-ok-around)))
5254 (def-face (or (plist-get pl :default-face)
5255 '((:background "DarkRed") (:foreground "white"))))
5256 issue face m te ts dt ov)
5257 (goto-char (point-min))
5258 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5259 (setq issue nil face def-face)
5260 (catch 'next
5261 (setq m (org-get-at-bol 'org-marker)
5262 te nil ts nil)
5263 (unless (and m (markerp m))
5264 (setq issue "No valid clock line") (throw 'next t))
5265 (org-with-point-at m
5266 (save-excursion
5267 (goto-char (point-at-bol))
5268 (unless (looking-at re)
5269 (error "No valid Clock line")
5270 (throw 'next t))
5271 (unless (match-end 3)
5272 (setq issue "No end time"
5273 face (or (plist-get pl :no-end-time-face) face))
5274 (throw 'next t))
5275 (setq ts (match-string 1)
5276 te (match-string 3)
5277 ts (org-float-time
5278 (apply 'encode-time (org-parse-time-string ts)))
5279 te (org-float-time
5280 (apply 'encode-time (org-parse-time-string te)))
5281 dt (- te ts))))
5282 (cond
5283 ((> dt (* 60 maxtime))
5284 ;; a very long clocking chunk
5285 (setq issue (format "Clocking interval is very long: %s"
5286 (org-minutes-to-hh:mm-string
5287 (floor (/ (float dt) 60.))))
5288 face (or (plist-get pl :long-face) face)))
5289 ((< dt (* 60 mintime))
5290 ;; a very short clocking chunk
5291 (setq issue (format "Clocking interval is very short: %s"
5292 (org-minutes-to-hh:mm-string
5293 (floor (/ (float dt) 60.))))
5294 face (or (plist-get pl :short-face) face)))
5295 ((and (> tlend 0) (< ts tlend))
5296 ;; Two clock entries are overlapping
5297 (setq issue (format "Clocking overlap: %d minutes"
5298 (/ (- tlend ts) 60))
5299 face (or (plist-get pl :overlap-face) face)))
5300 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5301 ;; There is a gap, lets see if we need to report it
5302 (unless (org-agenda-check-clock-gap tlend ts gapok)
5303 (setq issue (format "Clocking gap: %d minutes"
5304 (/ (- ts tlend) 60))
5305 face (or (plist-get pl :gap-face) face))))
5306 (t nil)))
5307 (setq tlend (or te tlend) tlstart (or ts tlstart))
5308 (when issue
5309 ;; OK, there was some issue, add an overlay to show the issue
5310 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5311 (overlay-put ov 'before-string
5312 (concat
5313 (org-add-props
5314 (format "%-43s" (concat " " issue))
5316 'face face)
5317 "\n"))
5318 (overlay-put ov 'evaporate t)))))
5320 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5321 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5322 (catch 'exit
5323 (unless ok-list
5324 ;; there are no OK times for gaps...
5325 (throw 'exit nil))
5326 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5327 ;; This is more than 24 hours, so it is OK.
5328 ;; because we have at least one OK time, that must be in the
5329 ;; 24 hour interval.
5330 (throw 'exit t))
5331 ;; We have a shorter gap.
5332 ;; Now we have to get the minute of the day when these times are
5333 (let* ((t1dec (decode-time (seconds-to-time t1)))
5334 (t2dec (decode-time (seconds-to-time t2)))
5335 ;; compute the minute on the day
5336 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5337 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5338 (when (< min2 min1)
5339 ;; if min2 is smaller than min1, this means it is on the next day.
5340 ;; Wrap it to after midnight.
5341 (setq min2 (+ min2 1440)))
5342 ;; Now check if any of the OK times is in the gap
5343 (mapc (lambda (x)
5344 ;; Wrap the time to after midnight if necessary
5345 (if (< x min1) (setq x (+ x 1440)))
5346 ;; Check if in interval
5347 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5348 ok-list)
5349 ;; Nope, this gap is not OK
5350 nil)))
5352 (defun org-agenda-get-deadlines ()
5353 "Return the deadline information for agenda display."
5354 (let* ((props (list 'mouse-face 'highlight
5355 'org-not-done-regexp org-not-done-regexp
5356 'org-todo-regexp org-todo-regexp
5357 'org-complex-heading-regexp org-complex-heading-regexp
5358 'help-echo
5359 (format "mouse-2 or RET jump to org file %s"
5360 (abbreviate-file-name buffer-file-name))))
5361 (regexp org-deadline-time-regexp)
5362 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5363 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5364 d2 diff dfrac wdays pos pos1 category org-category-pos
5365 tags suppress-prewarning ee txt head face s todo-state
5366 show-all upcomingp donep timestr)
5367 (goto-char (point-min))
5368 (while (re-search-forward regexp nil t)
5369 (setq suppress-prewarning nil)
5370 (catch :skip
5371 (org-agenda-skip)
5372 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5373 (save-match-data
5374 (string-match org-scheduled-time-regexp
5375 (buffer-substring (point-at-bol)
5376 (point-at-eol)))))
5377 (setq suppress-prewarning
5378 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5379 org-agenda-skip-deadline-prewarning-if-scheduled
5380 0)))
5381 (setq s (match-string 1)
5382 txt nil
5383 pos (1- (match-beginning 1))
5384 todo-state (save-match-data (org-get-todo-state))
5385 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5386 (member todo-state
5387 org-agenda-repeating-timestamp-show-all))
5388 d2 (org-time-string-to-absolute
5389 (match-string 1) d1 'past show-all
5390 (current-buffer) pos)
5391 diff (- d2 d1)
5392 wdays (if suppress-prewarning
5393 (let ((org-deadline-warning-days suppress-prewarning))
5394 (org-get-wdays s))
5395 (org-get-wdays s))
5396 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5397 upcomingp (and todayp (> diff 0)))
5398 ;; When to show a deadline in the calendar:
5399 ;; If the expiration is within wdays warning time.
5400 ;; Past-due deadlines are only shown on the current date
5401 (if (and (or (and (<= diff wdays)
5402 (and todayp (not org-agenda-only-exact-dates)))
5403 (= diff 0)))
5404 (save-excursion
5405 ;; (setq todo-state (org-get-todo-state))
5406 (setq donep (member todo-state org-done-keywords))
5407 (if (and donep
5408 (or org-agenda-skip-deadline-if-done
5409 (not (= diff 0))))
5410 (setq txt nil)
5411 (setq category (org-get-category)
5412 org-category-pos (get-text-property (point) 'org-category-position))
5413 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5414 (setq txt org-agenda-no-heading-message)
5415 (goto-char (match-end 0))
5416 (setq pos1 (match-beginning 0))
5417 (setq tags (org-get-tags-at pos1))
5418 (setq head (buffer-substring-no-properties
5419 (point)
5420 (progn (skip-chars-forward "^\r\n")
5421 (point))))
5422 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5423 (setq timestr
5424 (concat (substring s (match-beginning 1)) " "))
5425 (setq timestr 'time))
5426 (setq txt (org-agenda-format-item
5427 (if (= diff 0)
5428 (car org-agenda-deadline-leaders)
5429 (if (functionp
5430 (nth 1 org-agenda-deadline-leaders))
5431 (funcall
5432 (nth 1 org-agenda-deadline-leaders)
5433 diff date)
5434 (format (nth 1 org-agenda-deadline-leaders)
5435 diff)))
5436 head category tags
5437 (if (not (= diff 0)) nil timestr)))))
5438 (when txt
5439 (setq face (org-agenda-deadline-face dfrac))
5440 (org-add-props txt props
5441 'org-marker (org-agenda-new-marker pos)
5442 'org-hd-marker (org-agenda-new-marker pos1)
5443 'priority (+ (- diff)
5444 (org-get-priority txt))
5445 'org-category category
5446 'org-category-position org-category-pos
5447 'todo-state todo-state
5448 'type (if upcomingp "upcoming-deadline" "deadline")
5449 'date (if upcomingp date d2)
5450 'face (if donep 'org-agenda-done face)
5451 'undone-face face 'done-face 'org-agenda-done)
5452 (push txt ee))))))
5453 (nreverse ee)))
5455 (defun org-agenda-deadline-face (fraction)
5456 "Return the face to displaying a deadline item.
5457 FRACTION is what fraction of the head-warning time has passed."
5458 (let ((faces org-agenda-deadline-faces) f)
5459 (catch 'exit
5460 (while (setq f (pop faces))
5461 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5463 (defun org-agenda-get-scheduled (&optional deadline-results)
5464 "Return the scheduled information for agenda display."
5465 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5466 'org-todo-regexp org-todo-regexp
5467 'org-complex-heading-regexp org-complex-heading-regexp
5468 'done-face 'org-agenda-done
5469 'mouse-face 'highlight
5470 'help-echo
5471 (format "mouse-2 or RET jump to org file %s"
5472 (abbreviate-file-name buffer-file-name))))
5473 (regexp org-scheduled-time-regexp)
5474 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5475 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5477 (deadline-position-alist
5478 (mapcar (lambda (a) (and (setq mm (get-text-property
5479 0 'org-hd-marker a))
5480 (cons (marker-position mm) a)))
5481 deadline-results))
5482 d2 diff pos pos1 category org-category-pos tags donep
5483 ee txt head pastschedp todo-state face timestr s habitp show-all)
5484 (goto-char (point-min))
5485 (while (re-search-forward regexp nil t)
5486 (catch :skip
5487 (org-agenda-skip)
5488 (setq s (match-string 1)
5489 txt nil
5490 pos (1- (match-beginning 1))
5491 todo-state (save-match-data (org-get-todo-state))
5492 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5493 (member todo-state
5494 org-agenda-repeating-timestamp-show-all))
5495 d2 (org-time-string-to-absolute
5496 (match-string 1) d1 'past show-all
5497 (current-buffer) pos)
5498 diff (- d2 d1))
5499 (setq pastschedp (and todayp (< diff 0)))
5500 ;; When to show a scheduled item in the calendar:
5501 ;; If it is on or past the date.
5502 (when (or (and (< diff 0)
5503 (< (abs diff) org-scheduled-past-days)
5504 (and todayp (not org-agenda-only-exact-dates)))
5505 (= diff 0))
5506 (save-excursion
5507 (setq donep (member todo-state org-done-keywords))
5508 (if (and donep
5509 (or org-agenda-skip-scheduled-if-done
5510 (not (= diff 0))
5511 (and (functionp 'org-is-habit-p)
5512 (org-is-habit-p))))
5513 (setq txt nil)
5514 (setq habitp (and (functionp 'org-is-habit-p)
5515 (org-is-habit-p)))
5516 (setq category (org-get-category)
5517 org-category-pos (get-text-property (point) 'org-category-position))
5518 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5519 (setq txt org-agenda-no-heading-message)
5520 (goto-char (match-end 0))
5521 (setq pos1 (match-beginning 0))
5522 (if habitp
5523 (if (or (not org-habit-show-habits)
5524 (and (not todayp)
5525 org-habit-show-habits-only-for-today))
5526 (throw :skip nil))
5527 (if (and
5528 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5529 (and org-agenda-skip-scheduled-if-deadline-is-shown
5530 pastschedp))
5531 (setq mm (assoc pos1 deadline-position-alist)))
5532 (throw :skip nil)))
5533 (setq tags (org-get-tags-at))
5534 (setq head (buffer-substring-no-properties
5535 (point)
5536 (progn (skip-chars-forward "^\r\n") (point))))
5537 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5538 (setq timestr
5539 (concat (substring s (match-beginning 1)) " "))
5540 (setq timestr 'time))
5541 (setq txt (org-agenda-format-item
5542 (if (= diff 0)
5543 (car org-agenda-scheduled-leaders)
5544 (format (nth 1 org-agenda-scheduled-leaders)
5545 (- 1 diff)))
5546 head category tags
5547 (if (not (= diff 0)) nil timestr)
5548 nil habitp))))
5549 (when txt
5550 (setq face
5551 (cond
5552 ((and (not habitp) pastschedp)
5553 'org-scheduled-previously)
5554 (todayp 'org-scheduled-today)
5555 (t 'org-scheduled))
5556 habitp (and habitp (org-habit-parse-todo)))
5557 (org-add-props txt props
5558 'undone-face face
5559 'face (if donep 'org-agenda-done face)
5560 'org-marker (org-agenda-new-marker pos)
5561 'org-hd-marker (org-agenda-new-marker pos1)
5562 'type (if pastschedp "past-scheduled" "scheduled")
5563 'date (if pastschedp d2 date)
5564 'priority (if habitp
5565 (org-habit-get-priority habitp)
5566 (+ 94 (- 5 diff) (org-get-priority txt)))
5567 'org-category category
5568 'org-category-position org-category-pos
5569 'org-habit-p habitp
5570 'todo-state todo-state)
5571 (push txt ee))))))
5572 (nreverse ee)))
5574 (defun org-agenda-get-blocks ()
5575 "Return the date-range information for agenda display."
5576 (let* ((props (list 'face nil
5577 'org-not-done-regexp org-not-done-regexp
5578 'org-todo-regexp org-todo-regexp
5579 'org-complex-heading-regexp org-complex-heading-regexp
5580 'mouse-face 'highlight
5581 'help-echo
5582 (format "mouse-2 or RET jump to org file %s"
5583 (abbreviate-file-name buffer-file-name))))
5584 (regexp org-tr-regexp)
5585 (d0 (calendar-absolute-from-gregorian date))
5586 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5587 todo-state tags pos head donep)
5588 (goto-char (point-min))
5589 (while (re-search-forward regexp nil t)
5590 (catch :skip
5591 (org-agenda-skip)
5592 (setq pos (point))
5593 (let ((start-time (match-string 1))
5594 (end-time (match-string 2)))
5595 (setq s1 (match-string 1)
5596 s2 (match-string 2)
5597 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5598 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5599 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5600 ;; Only allow days between the limits, because the normal
5601 ;; date stamps will catch the limits.
5602 (save-excursion
5603 (setq todo-state (org-get-todo-state))
5604 (setq donep (member todo-state org-done-keywords))
5605 (if (and donep org-agenda-skip-timestamp-if-done)
5606 (throw :skip t))
5607 (setq marker (org-agenda-new-marker (point)))
5608 (setq category (org-get-category)
5609 org-category-pos (get-text-property (point) 'org-category-position))
5610 (if (not (re-search-backward org-outline-regexp-bol nil t))
5611 (setq txt org-agenda-no-heading-message)
5612 (goto-char (match-beginning 0))
5613 (setq hdmarker (org-agenda-new-marker (point)))
5614 (setq tags (org-get-tags-at))
5615 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5616 (setq head (match-string 1))
5617 (let ((remove-re
5618 (if org-agenda-remove-timeranges-from-blocks
5619 (concat
5620 "<" (regexp-quote s1) ".*?>"
5621 "--"
5622 "<" (regexp-quote s2) ".*?>")
5623 nil)))
5624 (setq txt (org-agenda-format-item
5625 (format
5626 (nth (if (= d1 d2) 0 1)
5627 org-agenda-timerange-leaders)
5628 (1+ (- d0 d1)) (1+ (- d2 d1)))
5629 head category tags
5630 (cond ((and (= d1 d0) (= d2 d0))
5631 (concat "<" start-time ">--<" end-time ">"))
5632 ((= d1 d0)
5633 (concat "<" start-time ">"))
5634 ((= d2 d0)
5635 (concat "<" end-time ">"))
5636 (t nil))
5637 remove-re))))
5638 (org-add-props txt props
5639 'org-marker marker 'org-hd-marker hdmarker
5640 'type "block" 'date date
5641 'todo-state todo-state
5642 'priority (org-get-priority txt) 'org-category category
5643 'org-category-position org-category-pos)
5644 (push txt ee))))
5645 (goto-char pos)))
5646 ;; Sort the entries by expiration date.
5647 (nreverse ee)))
5649 ;;; Agenda presentation and sorting
5651 (defvar org-prefix-has-time nil
5652 "A flag, set by `org-compile-prefix-format'.
5653 The flag is set if the currently compiled format contains a `%t'.")
5654 (defvar org-prefix-has-tag nil
5655 "A flag, set by `org-compile-prefix-format'.
5656 The flag is set if the currently compiled format contains a `%T'.")
5657 (defvar org-prefix-has-effort nil
5658 "A flag, set by `org-compile-prefix-format'.
5659 The flag is set if the currently compiled format contains a `%e'.")
5660 (defvar org-prefix-category-length nil
5661 "Used by `org-compile-prefix-format' to remember the category field width.")
5662 (defvar org-prefix-category-max-length nil
5663 "Used by `org-compile-prefix-format' to remember the category field width.")
5665 (defun org-agenda-get-category-icon (category)
5666 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5667 (dolist (entry org-agenda-category-icon-alist)
5668 (when (org-string-match-p (car entry) category)
5669 (if (listp (cadr entry))
5670 (return (cadr entry))
5671 (return (apply 'create-image (cdr entry)))))))
5673 (defun org-agenda-format-item (extra txt &optional category tags dotime
5674 remove-re habitp)
5675 "Format TXT to be inserted into the agenda buffer.
5676 In particular, it adds the prefix and corresponding text properties. EXTRA
5677 must be a string and replaces the `%s' specifier in the prefix format.
5678 CATEGORY (string, symbol or nil) may be used to overrule the default
5679 category taken from local variable or file name. It will replace the `%c'
5680 specifier in the format. DOTIME, when non-nil, indicates that a
5681 time-of-day should be extracted from TXT for sorting of this entry, and for
5682 the `%t' specifier in the format. When DOTIME is a string, this string is
5683 searched for a time before TXT is. TAGS can be the tags of the headline.
5684 Any match of REMOVE-RE will be removed from TXT."
5685 ;; We keep the org-prefix-* variable values along with a compiled
5686 ;; formatter, so that multiple agendas existing at the same time, do
5687 ;; not step on each other toes.
5689 ;; It was inconvenient to make these variables buffer local in
5690 ;; Agenda buffers, because this function expects to be called with
5691 ;; the buffer where item comes from being current, and not agenda
5692 ;; buffer
5693 (let* ((bindings (car org-prefix-format-compiled))
5694 (formatter (cadr org-prefix-format-compiled)))
5695 (loop for (var value) in bindings
5696 do (set var value))
5697 (save-match-data
5698 ;; Diary entries sometimes have extra whitespace at the beginning
5699 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5701 ;; Fix the tags part in txt
5702 (setq txt (org-agenda-fix-displayed-tags
5703 txt tags
5704 org-agenda-show-inherited-tags
5705 org-agenda-hide-tags-regexp))
5706 (let* ((category (or category
5707 (if (stringp org-category)
5708 org-category
5709 (and org-category (symbol-name org-category)))
5710 (if buffer-file-name
5711 (file-name-sans-extension
5712 (file-name-nondirectory buffer-file-name))
5713 "")))
5714 (category-icon (org-agenda-get-category-icon category))
5715 (category-icon (if category-icon
5716 (propertize " " 'display category-icon)
5717 ""))
5718 ;; time, tag, effort are needed for the eval of the prefix format
5719 (tag (if tags (nth (1- (length tags)) tags) ""))
5720 time effort neffort
5721 (ts (if dotime (concat
5722 (if (stringp dotime) dotime "")
5723 (and org-agenda-search-headline-for-time txt))))
5724 (time-of-day (and dotime (org-get-time-of-day ts)))
5725 stamp plain s0 s1 s2 rtn srp l
5726 duration thecategory)
5727 (and (eq major-mode 'org-mode) buffer-file-name
5728 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5729 (when (and dotime time-of-day)
5730 ;; Extract starting and ending time and move them to prefix
5731 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5732 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5733 (setq s0 (match-string 0 ts)
5734 srp (and stamp (match-end 3))
5735 s1 (match-string (if plain 1 2) ts)
5736 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5738 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5739 ;; them, we might want to remove them there to avoid duplication.
5740 ;; The user can turn this off with a variable.
5741 (if (and org-prefix-has-time
5742 org-agenda-remove-times-when-in-prefix (or stamp plain)
5743 (string-match (concat (regexp-quote s0) " *") txt)
5744 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5745 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5746 (= (match-beginning 0) 0)
5748 (setq txt (replace-match "" nil nil txt))))
5749 ;; Normalize the time(s) to 24 hour
5750 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5751 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5753 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5754 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5755 (setq s2
5756 (org-minutes-to-hh:mm-string
5757 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5759 ;; Compute the duration
5760 (when s2
5761 (setq duration (- (org-hh:mm-string-to-minutes s2)
5762 (org-hh:mm-string-to-minutes s1)))))
5764 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5765 txt)
5766 ;; Tags are in the string
5767 (if (or (eq org-agenda-remove-tags t)
5768 (and org-agenda-remove-tags
5769 org-prefix-has-tag))
5770 (setq txt (replace-match "" t t txt))
5771 (setq txt (replace-match
5772 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5773 (match-string 2 txt))
5774 t t txt))))
5775 (when (eq major-mode 'org-mode)
5776 (setq effort
5777 (condition-case nil
5778 (org-get-effort
5779 (or (get-text-property 0 'org-hd-marker txt)
5780 (get-text-property 0 'org-marker txt)))
5781 (error nil)))
5782 (when effort
5783 (setq neffort (org-duration-string-to-minutes effort)
5784 effort (setq effort (concat "[" effort "]")))))
5785 ;; prevent erroring out with %e format when there is no effort
5786 (or effort (setq effort ""))
5788 (when remove-re
5789 (while (string-match remove-re txt)
5790 (setq txt (replace-match "" t t txt))))
5792 ;; Set org-heading property on `txt' to mark the start of the
5793 ;; heading.
5794 (add-text-properties 0 (length txt) '(org-heading t) txt)
5796 ;; Prepare the variables needed in the eval of the compiled format
5797 (setq time (cond (s2 (concat
5798 (org-agenda-time-of-day-to-ampm-maybe s1)
5799 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5800 (if org-agenda-timegrid-use-ampm " ")))
5801 (s1 (concat
5802 (org-agenda-time-of-day-to-ampm-maybe s1)
5803 (if org-agenda-timegrid-use-ampm
5804 "........ "
5805 "......")))
5806 (t ""))
5807 extra (or (and (not habitp) extra) "")
5808 category (if (symbolp category) (symbol-name category) category)
5809 thecategory (copy-sequence category))
5810 (if (string-match org-bracket-link-regexp category)
5811 (progn
5812 (setq l (if (match-end 3)
5813 (- (match-end 3) (match-beginning 3))
5814 (- (match-end 1) (match-beginning 1))))
5815 (when (< l (or org-prefix-category-length 0))
5816 (setq category (copy-sequence category))
5817 (org-add-props category nil
5818 'extra-space (make-string
5819 (- org-prefix-category-length l 1) ?\ ))))
5820 (if (and org-prefix-category-max-length
5821 (>= (length category) org-prefix-category-max-length))
5822 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5823 ;; Evaluate the compiled format
5824 (setq rtn (concat (eval formatter) txt))
5826 ;; And finally add the text properties
5827 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5828 (org-add-props rtn nil
5829 'org-category (if thecategory (downcase thecategory) category)
5830 'tags (mapcar 'org-downcase-keep-props tags)
5831 'org-highest-priority org-highest-priority
5832 'org-lowest-priority org-lowest-priority
5833 'time-of-day time-of-day
5834 'duration duration
5835 'effort effort
5836 'effort-minutes neffort
5837 'txt txt
5838 'time time
5839 'extra extra
5840 'format org-prefix-format-compiled
5841 'dotime dotime)))))
5843 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5844 "Remove tags string from TXT, and add a modified list of tags.
5845 The modified list may contain inherited tags, and tags matched by
5846 `org-agenda-hide-tags-regexp' will be removed."
5847 (when (or add-inherited hide-re)
5848 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5849 (setq txt (substring txt 0 (match-beginning 0))))
5850 (setq tags
5851 (delq nil
5852 (mapcar (lambda (tg)
5853 (if (or (and hide-re (string-match hide-re tg))
5854 (and (not add-inherited)
5855 (get-text-property 0 'inherited tg)))
5857 tg))
5858 tags)))
5859 (when tags
5860 (let ((have-i (get-text-property 0 'inherited (car tags)))
5862 (setq txt (concat txt " :"
5863 (mapconcat
5864 (lambda (x)
5865 (setq i (get-text-property 0 'inherited x))
5866 (if (and have-i (not i))
5867 (progn
5868 (setq have-i nil)
5869 (concat ":" x))
5871 tags ":")
5872 (if have-i "::" ":"))))))
5873 txt)
5875 (defun org-downcase-keep-props (s)
5876 (let ((props (text-properties-at 0 s)))
5877 (setq s (downcase s))
5878 (add-text-properties 0 (length s) props s)
5881 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5882 (defvar org-agenda-sorting-strategy-selected nil)
5884 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5885 (catch 'exit
5886 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5887 ((and todayp (member 'today (car org-agenda-time-grid))))
5888 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5889 ((member 'weekly (car org-agenda-time-grid)))
5890 (t (throw 'exit list)))
5891 (let* ((have (delq nil (mapcar
5892 (lambda (x) (get-text-property 1 'time-of-day x))
5893 list)))
5894 (string (nth 1 org-agenda-time-grid))
5895 (gridtimes (nth 2 org-agenda-time-grid))
5896 (req (car org-agenda-time-grid))
5897 (remove (member 'remove-match req))
5898 new time)
5899 (if (and (member 'require-timed req) (not have))
5900 ;; don't show empty grid
5901 (throw 'exit list))
5902 (while (setq time (pop gridtimes))
5903 (unless (and remove (member time have))
5904 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5905 (push (org-agenda-format-item
5906 nil string "" nil
5907 (concat (substring time 0 -2) ":" (substring time -2)))
5908 new)
5909 (put-text-property
5910 2 (length (car new)) 'face 'org-time-grid (car new))))
5911 (when (and todayp org-agenda-show-current-time-in-grid)
5912 (push (org-agenda-format-item
5914 org-agenda-current-time-string
5915 "" nil
5916 (format-time-string "%H:%M "))
5917 new)
5918 (put-text-property
5919 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5921 (if (member 'time-up org-agenda-sorting-strategy-selected)
5922 (append new list)
5923 (append list new)))))
5925 (defun org-compile-prefix-format (key)
5926 "Compile the prefix format into a Lisp form that can be evaluated.
5927 The resulting form and associated variable bindings is returned
5928 and stored in the variable `org-prefix-format-compiled'."
5929 (setq org-prefix-has-time nil org-prefix-has-tag nil
5930 org-prefix-category-length nil
5931 org-prefix-has-effort nil)
5932 (let ((s (cond
5933 ((stringp org-agenda-prefix-format)
5934 org-agenda-prefix-format)
5935 ((assq key org-agenda-prefix-format)
5936 (cdr (assq key org-agenda-prefix-format)))
5937 (t " %-12:c%?-12t% s")))
5938 (start 0)
5939 varform vars var e c f opt)
5940 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5941 s start)
5942 (setq var (or (cdr (assoc (match-string 4 s)
5943 '(("c" . category) ("t" . time) ("s" . extra)
5944 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5945 'eval)
5946 c (or (match-string 3 s) "")
5947 opt (match-beginning 1)
5948 start (1+ (match-beginning 0)))
5949 (if (equal var 'time) (setq org-prefix-has-time t))
5950 (if (equal var 'tag) (setq org-prefix-has-tag t))
5951 (if (equal var 'effort) (setq org-prefix-has-effort t))
5952 (setq f (concat "%" (match-string 2 s) "s"))
5953 (when (equal var 'category)
5954 (setq org-prefix-category-length
5955 (floor (abs (string-to-number (match-string 2 s)))))
5956 (setq org-prefix-category-max-length
5957 (let ((x (match-string 2 s)))
5958 (save-match-data
5959 (if (string-match "\\.[0-9]+" x)
5960 (string-to-number (substring (match-string 0 x) 1)))))))
5961 (if (eq var 'eval)
5962 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5963 (if opt
5964 (setq varform
5965 `(if (equal "" ,var)
5967 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5968 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5969 (setq s (replace-match "%s" t nil s))
5970 (push varform vars))
5971 (setq vars (nreverse vars))
5972 (with-current-buffer org-agenda-buffer
5973 (setq org-prefix-format-compiled
5974 (list
5975 `((org-prefix-has-time ,org-prefix-has-time)
5976 (org-prefix-has-tag ,org-prefix-has-tag)
5977 (org-prefix-category-length ,org-prefix-category-length)
5978 (org-prefix-has-effort ,org-prefix-has-effort))
5979 `(format ,s ,@vars))))))
5981 (defun org-set-sorting-strategy (key)
5982 (if (symbolp (car org-agenda-sorting-strategy))
5983 ;; the old format
5984 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5985 (setq org-agenda-sorting-strategy-selected
5986 (or (cdr (assq key org-agenda-sorting-strategy))
5987 (cdr (assq 'agenda org-agenda-sorting-strategy))
5988 '(time-up category-keep priority-down)))))
5990 (defun org-get-time-of-day (s &optional string mod24)
5991 "Check string S for a time of day.
5992 If found, return it as a military time number between 0 and 2400.
5993 If not found, return nil.
5994 The optional STRING argument forces conversion into a 5 character wide string
5995 HH:MM."
5996 (save-match-data
5997 (when
5998 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5999 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6000 (let* ((h (string-to-number (match-string 1 s)))
6001 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6002 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6003 (am-p (equal ampm "am"))
6004 (h1 (cond ((not ampm) h)
6005 ((= h 12) (if am-p 0 12))
6006 (t (+ h (if am-p 0 12)))))
6007 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6008 (mod h1 24) h1))
6009 (t0 (+ (* 100 h2) m))
6010 (t1 (concat (if (>= h1 24) "+" " ")
6011 (if (and org-agenda-time-leading-zero
6012 (< t0 1000)) "0" "")
6013 (if (< t0 100) "0" "")
6014 (if (< t0 10) "0" "")
6015 (int-to-string t0))))
6016 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6018 (defvar org-agenda-before-sorting-filter-function nil
6019 "Function to be applied to agenda items prior to sorting.
6020 Prior to sorting also means just before they are inserted into the agenda.
6022 To aid sorting, you may revisit the original entries and add more text
6023 properties which will later be used by the sorting functions.
6025 The function should take a string argument, an agenda line.
6026 It has access to the text properties in that line, which contain among
6027 other things, the property `org-hd-marker' that points to the entry
6028 where the line comes from. Note that not all lines going into the agenda
6029 have this property, only most.
6031 The function should return the modified string. It is probably best
6032 to ONLY change text properties.
6034 You can also use this function as a filter, by returning nil for lines
6035 you don't want to have in the agenda at all. For this application, you
6036 could bind the variable in the options section of a custom command.")
6038 (defun org-finalize-agenda-entries (list &optional nosort)
6039 "Sort and concatenate the agenda items."
6040 (setq list (mapcar 'org-agenda-highlight-todo list))
6041 (if nosort
6042 list
6043 (when org-agenda-before-sorting-filter-function
6044 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6045 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6047 (defun org-agenda-highlight-todo (x)
6048 (let ((org-done-keywords org-done-keywords-for-agenda)
6049 (case-fold-search nil)
6051 (if (eq x 'line)
6052 (save-excursion
6053 (beginning-of-line 1)
6054 (setq re (org-get-at-bol 'org-todo-regexp))
6055 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6056 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6057 (add-text-properties (match-beginning 0) (match-end 1)
6058 (list 'face (org-get-todo-face 1)))
6059 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6060 (delete-region (match-beginning 1) (1- (match-end 0)))
6061 (goto-char (match-beginning 1))
6062 (insert (format org-agenda-todo-keyword-format s)))))
6063 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6064 (setq re (get-text-property 0 'org-todo-regexp x))
6065 (when (and re
6066 ;; Test `pl' because if there's no heading content,
6067 ;; there's no point matching to highlight. Note
6068 ;; that if we didn't test `pl' first, and there
6069 ;; happened to be no keyword from `org-todo-regexp'
6070 ;; on this heading line, then the `equal' comparison
6071 ;; afterwards would spuriously succeed in the case
6072 ;; where `pl' is nil -- causing an args-out-of-range
6073 ;; error when we try to add text properties to text
6074 ;; that isn't there.
6076 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6077 x pl) pl))
6078 (add-text-properties
6079 (or (match-end 1) (match-end 0)) (match-end 0)
6080 (list 'face (org-get-todo-face (match-string 2 x)))
6082 (when (match-end 1)
6083 (setq x (concat (substring x 0 (match-end 1))
6084 (format org-agenda-todo-keyword-format
6085 (match-string 2 x))
6086 (org-add-props " " (text-properties-at 0 x))
6087 (substring x (match-end 3)))))))
6088 x)))
6090 (defsubst org-cmp-priority (a b)
6091 "Compare the priorities of string A and B."
6092 (let ((pa (or (get-text-property 1 'priority a) 0))
6093 (pb (or (get-text-property 1 'priority b) 0)))
6094 (cond ((> pa pb) +1)
6095 ((< pa pb) -1)
6096 (t nil))))
6098 (defsubst org-cmp-effort (a b)
6099 "Compare the effort values of string A and B."
6100 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6101 (ea (or (get-text-property 1 'effort-minutes a) def))
6102 (eb (or (get-text-property 1 'effort-minutes b) def)))
6103 (cond ((> ea eb) +1)
6104 ((< ea eb) -1)
6105 (t nil))))
6107 (defsubst org-cmp-category (a b)
6108 "Compare the string values of categories of strings A and B."
6109 (let ((ca (or (get-text-property 1 'org-category a) ""))
6110 (cb (or (get-text-property 1 'org-category b) "")))
6111 (cond ((string-lessp ca cb) -1)
6112 ((string-lessp cb ca) +1)
6113 (t nil))))
6115 (defsubst org-cmp-todo-state (a b)
6116 "Compare the todo states of strings A and B."
6117 (let* ((ma (or (get-text-property 1 'org-marker a)
6118 (get-text-property 1 'org-hd-marker a)))
6119 (mb (or (get-text-property 1 'org-marker b)
6120 (get-text-property 1 'org-hd-marker b)))
6121 (fa (and ma (marker-buffer ma)))
6122 (fb (and mb (marker-buffer mb)))
6123 (todo-kwds
6124 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6125 (and fb (with-current-buffer fb org-todo-keywords-1))))
6126 (ta (or (get-text-property 1 'todo-state a) ""))
6127 (tb (or (get-text-property 1 'todo-state b) ""))
6128 (la (- (length (member ta todo-kwds))))
6129 (lb (- (length (member tb todo-kwds))))
6130 (donepa (member ta org-done-keywords-for-agenda))
6131 (donepb (member tb org-done-keywords-for-agenda)))
6132 (cond ((and donepa (not donepb)) -1)
6133 ((and (not donepa) donepb) +1)
6134 ((< la lb) -1)
6135 ((< lb la) +1)
6136 (t nil))))
6138 (defsubst org-cmp-alpha (a b)
6139 "Compare the headlines, alphabetically."
6140 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6141 (plb (text-property-any 0 (length b) 'org-heading t b))
6142 (ta (and pla (substring a pla)))
6143 (tb (and plb (substring b plb))))
6144 (when pla
6145 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6146 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6147 (setq ta (substring ta (match-end 0))))
6148 (setq ta (downcase ta)))
6149 (when plb
6150 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6151 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6152 (setq tb (substring tb (match-end 0))))
6153 (setq tb (downcase tb)))
6154 (cond ((not ta) +1)
6155 ((not tb) -1)
6156 ((string-lessp ta tb) -1)
6157 ((string-lessp tb ta) +1)
6158 (t nil))))
6160 (defsubst org-cmp-tag (a b)
6161 "Compare the string values of the first tags of A and B."
6162 (let ((ta (car (last (get-text-property 1 'tags a))))
6163 (tb (car (last (get-text-property 1 'tags b)))))
6164 (cond ((not ta) +1)
6165 ((not tb) -1)
6166 ((string-lessp ta tb) -1)
6167 ((string-lessp tb ta) +1)
6168 (t nil))))
6170 (defsubst org-cmp-time (a b)
6171 "Compare the time-of-day values of strings A and B."
6172 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6173 (ta (or (get-text-property 1 'time-of-day a) def))
6174 (tb (or (get-text-property 1 'time-of-day b) def)))
6175 (cond ((< ta tb) -1)
6176 ((< tb ta) +1)
6177 (t nil))))
6179 (defsubst org-cmp-habit-p (a b)
6180 "Compare the todo states of strings A and B."
6181 (let ((ha (get-text-property 1 'org-habit-p a))
6182 (hb (get-text-property 1 'org-habit-p b)))
6183 (cond ((and ha (not hb)) -1)
6184 ((and (not ha) hb) +1)
6185 (t nil))))
6187 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6189 (defun org-entries-lessp (a b)
6190 "Predicate for sorting agenda entries."
6191 ;; The following variables will be used when the form is evaluated.
6192 ;; So even though the compiler complains, keep them.
6193 (let* ((ss org-agenda-sorting-strategy-selected)
6194 (time-up (and (org-em 'time-up 'time-down ss)
6195 (org-cmp-time a b)))
6196 (time-down (if time-up (- time-up) nil))
6197 (priority-up (and (org-em 'priority-up 'priority-down ss)
6198 (org-cmp-priority a b)))
6199 (priority-down (if priority-up (- priority-up) nil))
6200 (effort-up (and (org-em 'effort-up 'effort-down ss)
6201 (org-cmp-effort a b)))
6202 (effort-down (if effort-up (- effort-up) nil))
6203 (category-up (and (or (org-em 'category-up 'category-down ss)
6204 (memq 'category-keep ss))
6205 (org-cmp-category a b)))
6206 (category-down (if category-up (- category-up) nil))
6207 (category-keep (if category-up +1 nil))
6208 (tag-up (and (org-em 'tag-up 'tag-down ss)
6209 (org-cmp-tag a b)))
6210 (tag-down (if tag-up (- tag-up) nil))
6211 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6212 (org-cmp-todo-state a b)))
6213 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6214 (habit-up (and (org-em 'habit-up 'habit-down ss)
6215 (org-cmp-habit-p a b)))
6216 (habit-down (if habit-up (- habit-up) nil))
6217 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6218 (org-cmp-alpha a b)))
6219 (alpha-down (if alpha-up (- alpha-up) nil))
6220 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6221 user-defined-up user-defined-down)
6222 (if (and need-user-cmp org-agenda-cmp-user-defined
6223 (functionp org-agenda-cmp-user-defined))
6224 (setq user-defined-up
6225 (funcall org-agenda-cmp-user-defined a b)
6226 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6227 (cdr (assoc
6228 (eval (cons 'or org-agenda-sorting-strategy-selected))
6229 '((-1 . t) (1 . nil) (nil . nil))))))
6231 ;;; Agenda restriction lock
6233 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6234 "Overlay to mark the headline to which agenda commands are restricted.")
6235 (overlay-put org-agenda-restriction-lock-overlay
6236 'face 'org-agenda-restriction-lock)
6237 (overlay-put org-agenda-restriction-lock-overlay
6238 'help-echo "Agendas are currently limited to this subtree.")
6239 (org-detach-overlay org-agenda-restriction-lock-overlay)
6241 (defun org-agenda-set-restriction-lock (&optional type)
6242 "Set restriction lock for agenda, to current subtree or file.
6243 Restriction will be the file if TYPE is `file', or if type is the
6244 universal prefix '(4), or if the cursor is before the first headline
6245 in the file. Otherwise, restriction will be to the current subtree."
6246 (interactive "P")
6247 (and (equal type '(4)) (setq type 'file))
6248 (setq type (cond
6249 (type type)
6250 ((org-at-heading-p) 'subtree)
6251 ((condition-case nil (org-back-to-heading t) (error nil))
6252 'subtree)
6253 (t 'file)))
6254 (if (eq type 'subtree)
6255 (progn
6256 (setq org-agenda-restrict t)
6257 (setq org-agenda-overriding-restriction 'subtree)
6258 (put 'org-agenda-files 'org-restrict
6259 (list (buffer-file-name (buffer-base-buffer))))
6260 (org-back-to-heading t)
6261 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6262 (move-marker org-agenda-restrict-begin (point))
6263 (move-marker org-agenda-restrict-end
6264 (save-excursion (org-end-of-subtree t)))
6265 (message "Locking agenda restriction to subtree"))
6266 (put 'org-agenda-files 'org-restrict
6267 (list (buffer-file-name (buffer-base-buffer))))
6268 (setq org-agenda-restrict nil)
6269 (setq org-agenda-overriding-restriction 'file)
6270 (move-marker org-agenda-restrict-begin nil)
6271 (move-marker org-agenda-restrict-end nil)
6272 (message "Locking agenda restriction to file"))
6273 (setq current-prefix-arg nil)
6274 (org-agenda-maybe-redo))
6276 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6277 "Remove the agenda restriction lock."
6278 (interactive "P")
6279 (org-detach-overlay org-agenda-restriction-lock-overlay)
6280 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6281 (setq org-agenda-overriding-restriction nil)
6282 (setq org-agenda-restrict nil)
6283 (put 'org-agenda-files 'org-restrict nil)
6284 (move-marker org-agenda-restrict-begin nil)
6285 (move-marker org-agenda-restrict-end nil)
6286 (setq current-prefix-arg nil)
6287 (message "Agenda restriction lock removed")
6288 (or noupdate (org-agenda-maybe-redo)))
6290 (defun org-agenda-maybe-redo ()
6291 "If there is any window showing the agenda view, update it."
6292 (let ((w (get-buffer-window org-agenda-buffer-name t))
6293 (w0 (selected-window)))
6294 (when w
6295 (select-window w)
6296 (org-agenda-redo)
6297 (select-window w0)
6298 (if org-agenda-overriding-restriction
6299 (message "Agenda view shifted to new %s restriction"
6300 org-agenda-overriding-restriction)
6301 (message "Agenda restriction lock removed")))))
6303 ;;; Agenda commands
6305 (defun org-agenda-check-type (error &rest types)
6306 "Check if agenda buffer is of allowed type.
6307 If ERROR is non-nil, throw an error, otherwise just return nil."
6308 (if (memq org-agenda-type types)
6310 (if error
6311 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6312 nil)))
6314 (defun org-agenda-Quit (&optional arg)
6315 "Exit agenda by removing the window or the buffer"
6316 (interactive)
6317 (if org-agenda-columns-active
6318 (org-columns-quit)
6319 (let ((buf (current-buffer)))
6320 (if (eq org-agenda-window-setup 'other-frame)
6321 (progn
6322 (org-agenda-reset-markers)
6323 (kill-buffer buf)
6324 (org-columns-remove-overlays)
6325 (setq org-agenda-archives-mode nil)
6326 (delete-frame))
6327 (and (not (eq org-agenda-window-setup 'current-window))
6328 (not (one-window-p))
6329 (delete-window))
6330 (org-agenda-reset-markers)
6331 (kill-buffer buf)
6332 (org-columns-remove-overlays)
6333 (setq org-agenda-archives-mode nil)))
6334 ;; Maybe restore the pre-agenda window configuration.
6335 (and org-agenda-restore-windows-after-quit
6336 (not (eq org-agenda-window-setup 'other-frame))
6337 org-pre-agenda-window-conf
6338 (set-window-configuration org-pre-agenda-window-conf))))
6340 (defun org-agenda-quit ()
6341 "Exit agenda by killing agenda buffer or burying it when
6342 `org-agenda-sticky' is non-NIL"
6343 (interactive)
6344 (if org-agenda-columns-active
6345 (org-columns-quit)
6346 (if org-agenda-sticky
6347 (let ((buf (current-buffer)))
6348 (if (eq org-agenda-window-setup 'other-frame)
6349 (progn
6350 (delete-frame))
6351 (and (not (eq org-agenda-window-setup 'current-window))
6352 (not (one-window-p))
6353 (delete-window)))
6354 (with-current-buffer buf
6355 (bury-buffer)))
6356 (org-agenda-Quit))))
6358 (defun org-agenda-exit ()
6359 "Exit agenda by removing the window or the buffer.
6360 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6361 Org-mode buffers visited directly by the user will not be touched."
6362 (interactive)
6363 (org-release-buffers org-agenda-new-buffers)
6364 (setq org-agenda-new-buffers nil)
6365 (org-agenda-Quit))
6367 (defun org-agenda-kill-all-agenda-buffers ()
6368 "Kill all buffers in `org-agena-mode'.
6369 This is used when toggling sticky agendas. You can also explicitly invoke it
6370 with `C-c a C-k'."
6371 (interactive)
6372 (let (blist)
6373 (dolist (buf (buffer-list))
6374 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6375 (push buf blist)))
6376 (mapc 'kill-buffer blist)))
6378 (defun org-agenda-execute (arg)
6379 "Execute another agenda command, keeping same window.
6380 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6381 in the agenda."
6382 (interactive "P")
6383 (let ((org-agenda-window-setup 'current-window))
6384 (org-agenda arg)))
6386 (defun org-agenda-redo ()
6387 "Rebuild Agenda.
6388 When this is the global TODO list, a prefix argument will be interpreted."
6389 (interactive)
6390 (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
6391 (org-agenda-sticky nil)
6392 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6393 org-agenda-buffer-name))
6394 (org-agenda-keep-modes t)
6395 (tag-filter org-agenda-tag-filter)
6396 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6397 (cat-filter org-agenda-category-filter)
6398 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6399 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6400 (cols org-agenda-columns-active)
6401 (line (org-current-line))
6402 (window-line (- line (org-current-line (window-start))))
6403 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6404 (put 'org-agenda-tag-filter :preset-filter nil)
6405 (put 'org-agenda-category-filter :preset-filter nil)
6406 (and cols (org-columns-quit))
6407 (message "Rebuilding agenda buffer...")
6408 (org-let lprops '(eval org-agenda-redo-command))
6409 (setq org-agenda-undo-list nil
6410 org-agenda-pending-undo-list nil)
6411 (message "Rebuilding agenda buffer...done")
6412 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6413 (put 'org-agenda-category-filter :preset-filter cat-preset)
6414 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6415 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6416 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6417 (org-goto-line line)
6418 (recenter window-line)))
6420 (defvar org-global-tags-completion-table nil)
6421 (defvar org-agenda-filtered-by-category nil)
6422 (defvar org-agenda-filter-form nil)
6424 (defun org-agenda-filter-by-category (strip)
6425 "Keep only those lines in the agenda buffer that have a specific category.
6426 The category is that of the current line."
6427 (interactive "P")
6428 (if org-agenda-filtered-by-category
6429 (org-agenda-filter-show-all-cat)
6430 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6431 (if cat (org-agenda-filter-apply
6432 (list (concat (if strip "-" "+") cat)) 'category)
6433 (error "No category at point")))))
6435 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6436 "Keep only those lines in the agenda buffer that have a specific tag.
6437 The tag is selected with its fast selection letter, as configured.
6438 With prefix argument STRIP, remove all lines that do have the tag.
6439 A lisp caller can specify CHAR. NARROW means that the new tag should be
6440 used to narrow the search - the interactive user can also press `-' or `+'
6441 to switch to narrowing."
6442 (interactive "P")
6443 (let* ((alist org-tag-alist-for-agenda)
6444 (tag-chars (mapconcat
6445 (lambda (x) (if (and (not (symbolp (car x)))
6446 (cdr x))
6447 (char-to-string (cdr x))
6448 ""))
6449 alist ""))
6450 (efforts (org-split-string
6451 (or (cdr (assoc (concat org-effort-property "_ALL")
6452 org-global-properties))
6453 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6454 "")))
6455 (effort-op org-agenda-filter-effort-default-operator)
6456 (effort-prompt "")
6457 (inhibit-read-only t)
6458 (current org-agenda-tag-filter)
6459 maybe-refresh a n tag)
6460 (unless char
6461 (message
6462 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6463 (if narrow "Narrow" "Filter") tag-chars
6464 (if org-agenda-auto-exclude-function "[RET], " ""))
6465 (setq char (read-char-exclusive)))
6466 (when (member char '(?+ ?-))
6467 ;; Narrowing down
6468 (cond ((equal char ?-) (setq strip t narrow t))
6469 ((equal char ?+) (setq strip nil narrow t)))
6470 (message
6471 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6472 (setq char (read-char-exclusive)))
6473 (when (member char '(?< ?> ?= ??))
6474 ;; An effort operator
6475 (setq effort-op (char-to-string char))
6476 (setq alist nil) ; to make sure it will be interpreted as effort.
6477 (unless (equal char ??)
6478 (loop for i from 0 to 9 do
6479 (setq effort-prompt
6480 (concat
6481 effort-prompt " ["
6482 (if (= i 9) "0" (int-to-string (1+ i)))
6483 "]" (nth i efforts))))
6484 (message "Effort%s: %s " effort-op effort-prompt)
6485 (setq char (read-char-exclusive))
6486 (when (or (< char ?0) (> char ?9))
6487 (error "Need 1-9,0 to select effort"))))
6488 (when (equal char ?\t)
6489 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6490 (org-set-local 'org-global-tags-completion-table
6491 (org-global-tags-completion-table)))
6492 (let ((completion-ignore-case t))
6493 (setq tag (org-icompleting-read
6494 "Tag: " org-global-tags-completion-table))))
6495 (cond
6496 ((equal char ?\r)
6497 (org-agenda-filter-show-all-tag)
6498 (when org-agenda-auto-exclude-function
6499 (setq org-agenda-tag-filter '())
6500 (dolist (tag (org-agenda-get-represented-tags))
6501 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6502 (if modifier
6503 (push modifier org-agenda-tag-filter))))
6504 (if (not (null org-agenda-tag-filter))
6505 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6506 (setq maybe-refresh t))
6507 ((equal char ?/)
6508 (org-agenda-filter-show-all-tag)
6509 (when (get 'org-agenda-tag-filter :preset-filter)
6510 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6511 (setq maybe-refresh t))
6512 ((equal char ?. )
6513 (setq org-agenda-tag-filter
6514 (mapcar (lambda(tag) (concat "+" tag))
6515 (org-get-at-bol 'tags)))
6516 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6517 (setq maybe-refresh t))
6518 ((or (equal char ?\ )
6519 (setq a (rassoc char alist))
6520 (and (>= char ?0) (<= char ?9)
6521 (setq n (if (= char ?0) 9 (- char ?0 1))
6522 tag (concat effort-op (nth n efforts))
6523 a (cons tag nil)))
6524 (and (= char ??)
6525 (setq tag "?eff")
6526 a (cons tag nil))
6527 (and tag (setq a (cons tag nil))))
6528 (org-agenda-filter-show-all-tag)
6529 (setq tag (car a))
6530 (setq org-agenda-tag-filter
6531 (cons (concat (if strip "-" "+") tag)
6532 (if narrow current nil)))
6533 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6534 (setq maybe-refresh t))
6535 (t (error "Invalid tag selection character %c" char)))
6536 (when (and maybe-refresh
6537 (eq org-agenda-clockreport-mode 'with-filter))
6538 (org-agenda-redo))))
6540 (defun org-agenda-get-represented-tags ()
6541 "Get a list of all tags currently represented in the agenda."
6542 (let (p tags)
6543 (save-excursion
6544 (goto-char (point-min))
6545 (while (setq p (next-single-property-change (point) 'tags))
6546 (goto-char p)
6547 (mapc (lambda (x) (add-to-list 'tags x))
6548 (get-text-property (point) 'tags))))
6549 tags))
6551 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6552 "Refine the current filter. See `org-agenda-filter-by-tag'."
6553 (interactive "P")
6554 (org-agenda-filter-by-tag strip char 'refine))
6556 (defun org-agenda-filter-make-matcher ()
6557 "Create the form that tests a line for agenda filter."
6558 (let (f f1)
6559 ;; first compute the tag-filter matcher
6560 (dolist (x (delete-dups
6561 (append (get 'org-agenda-tag-filter
6562 :preset-filter) org-agenda-tag-filter)))
6563 (if (member x '("-" "+"))
6564 (setq f1 (if (equal x "-") 'tags '(not tags)))
6565 (if (string-match "[<=>?]" x)
6566 (setq f1 (org-agenda-filter-effort-form x))
6567 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6568 (if (equal (string-to-char x) ?-)
6569 (setq f1 (list 'not f1))))
6570 (push f1 f))
6571 ;; then compute the category-filter matcher
6572 (dolist (x (delete-dups
6573 (append (get 'org-agenda-category-filter
6574 :preset-filter) org-agenda-category-filter)))
6575 (setq f1 (list 'equal (substring x 1) 'cat))
6576 (push f1 f))
6577 (cons 'and (nreverse f))))
6579 (defun org-agenda-filter-effort-form (e)
6580 "Return the form to compare the effort of the current line with what E says.
6581 E looks like \"+<2:25\"."
6582 (let (op)
6583 (setq e (substring e 1))
6584 (setq op (string-to-char e) e (substring e 1))
6585 (setq op (cond ((equal op ?<) '<=)
6586 ((equal op ?>) '>=)
6587 ((equal op ??) op)
6588 (t '=)))
6589 (list 'org-agenda-compare-effort (list 'quote op)
6590 (org-duration-string-to-minutes e))))
6592 (defun org-agenda-compare-effort (op value)
6593 "Compare the effort of the current line with VALUE, using OP.
6594 If the line does not have an effort defined, return nil."
6595 (let ((eff (org-get-at-bol 'effort-minutes)))
6596 (if (equal op ??)
6597 (not eff)
6598 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6599 value))))
6601 (defun org-agenda-filter-apply (filter type)
6602 "Set FILTER as the new agenda filter and apply it."
6603 (let (tags cat)
6604 (if (eq type 'tag)
6605 (setq org-agenda-tag-filter filter)
6606 (setq org-agenda-category-filter filter
6607 org-agenda-filtered-by-category t))
6608 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6609 (org-agenda-set-mode-name)
6610 (save-excursion
6611 (goto-char (point-min))
6612 (while (not (eobp))
6613 (if (org-get-at-bol 'org-marker)
6614 (progn
6615 (setq tags (org-get-at-bol 'tags) ; used in eval
6616 cat (get-text-property (point) 'org-category))
6617 (if (not (eval org-agenda-filter-form))
6618 (org-agenda-filter-hide-line type))
6619 (beginning-of-line 2))
6620 (beginning-of-line 2))))
6621 (if (get-char-property (point) 'invisible)
6622 (org-agenda-previous-line))))
6624 (defun org-agenda-filter-hide-line (type)
6625 (let (ov)
6626 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6627 (point-at-eol)))
6628 (overlay-put ov 'invisible t)
6629 (overlay-put ov 'type type)
6630 (if (eq type 'tag)
6631 (push ov org-agenda-tag-filter-overlays)
6632 (push ov org-agenda-cat-filter-overlays))))
6634 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6635 (setq pos (or pos (point)))
6636 (save-excursion
6637 (dolist (ov (overlays-at pos))
6638 (when (and (overlay-get ov 'invisible)
6639 (eq (overlay-get ov 'type) 'tag))
6640 (goto-char pos)
6641 (if (< (overlay-start ov) (point-at-eol))
6642 (move-overlay ov (point-at-eol)
6643 (overlay-end ov)))))))
6645 (defun org-agenda-filter-show-all-tag nil
6646 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6647 (setq org-agenda-tag-filter-overlays nil
6648 org-agenda-tag-filter nil
6649 org-agenda-filter-form nil)
6650 (org-agenda-set-mode-name))
6652 (defun org-agenda-filter-show-all-cat nil
6653 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6654 (setq org-agenda-cat-filter-overlays nil
6655 org-agenda-filtered-by-category nil
6656 org-agenda-category-filter nil
6657 org-agenda-filter-form nil)
6658 (org-agenda-set-mode-name))
6660 (defun org-agenda-manipulate-query-add ()
6661 "Manipulate the query by adding a search term with positive selection.
6662 Positive selection means the term must be matched for selection of an entry."
6663 (interactive)
6664 (org-agenda-manipulate-query ?\[))
6665 (defun org-agenda-manipulate-query-subtract ()
6666 "Manipulate the query by adding a search term with negative selection.
6667 Negative selection means term must not be matched for selection of an entry."
6668 (interactive)
6669 (org-agenda-manipulate-query ?\]))
6670 (defun org-agenda-manipulate-query-add-re ()
6671 "Manipulate the query by adding a search regexp with positive selection.
6672 Positive selection means the regexp must match for selection of an entry."
6673 (interactive)
6674 (org-agenda-manipulate-query ?\{))
6675 (defun org-agenda-manipulate-query-subtract-re ()
6676 "Manipulate the query by adding a search regexp with negative selection.
6677 Negative selection means regexp must not match for selection of an entry."
6678 (interactive)
6679 (org-agenda-manipulate-query ?\}))
6680 (defun org-agenda-manipulate-query (char)
6681 (cond
6682 ((memq org-agenda-type '(timeline agenda))
6683 (let ((org-agenda-include-inactive-timestamps t))
6684 (org-agenda-redo))
6685 (message "Display now includes inactive timestamps as well"))
6686 ((eq org-agenda-type 'search)
6687 (org-add-to-string
6688 'org-agenda-query-string
6689 (if org-agenda-last-search-view-search-was-boolean
6690 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6691 (?\{ . " +{}") (?\} . " -{}"))))
6692 " "))
6693 (setq org-agenda-redo-command
6694 (list 'org-search-view
6695 org-todo-only
6696 org-agenda-query-string
6697 (+ (length org-agenda-query-string)
6698 (if (member char '(?\{ ?\})) 0 1))))
6699 (set-register org-agenda-query-register org-agenda-query-string)
6700 (org-agenda-redo))
6701 (t (error "Cannot manipulate query for %s-type agenda buffers"
6702 org-agenda-type))))
6704 (defun org-add-to-string (var string)
6705 (set var (concat (symbol-value var) string)))
6707 (defun org-agenda-goto-date (date)
6708 "Jump to DATE in agenda."
6709 (interactive (list (let ((org-read-date-prefer-future
6710 (eval org-agenda-jump-prefer-future)))
6711 (org-read-date))))
6712 (org-agenda-list nil date))
6714 (defun org-agenda-goto-today ()
6715 "Go to today."
6716 (interactive)
6717 (org-agenda-check-type t 'timeline 'agenda)
6718 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6719 (cond
6720 (tdpos (goto-char tdpos))
6721 ((eq org-agenda-type 'agenda)
6722 (let* ((sd (org-agenda-compute-starting-span
6723 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6724 (org-agenda-overriding-arguments org-agenda-last-arguments))
6725 (setf (nth 1 org-agenda-overriding-arguments) sd)
6726 (org-agenda-redo)
6727 (org-agenda-find-same-or-today-or-agenda)))
6728 (t (error "Cannot find today")))))
6730 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6731 (goto-char
6732 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6733 (text-property-any (point-min) (point-max) 'org-today t)
6734 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6735 (point-min))))
6737 (defun org-agenda-later (arg)
6738 "Go forward in time by thee current span.
6739 With prefix ARG, go forward that many times the current span."
6740 (interactive "p")
6741 (org-agenda-check-type t 'agenda)
6742 (let* ((span org-agenda-current-span)
6743 (sd org-starting-day)
6744 (greg (calendar-gregorian-from-absolute sd))
6745 (cnt (org-get-at-bol 'org-day-cnt))
6746 greg2)
6747 (cond
6748 ((eq span 'day)
6749 (setq sd (+ arg sd)))
6750 ((eq span 'week)
6751 (setq sd (+ (* 7 arg) sd)))
6752 ((eq span 'month)
6753 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6754 sd (calendar-absolute-from-gregorian greg2))
6755 (setcar greg2 (1+ (car greg2))))
6756 ((eq span 'year)
6757 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6758 sd (calendar-absolute-from-gregorian greg2))
6759 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6761 (setq sd (+ (* span arg) sd))))
6762 (let ((org-agenda-overriding-arguments
6763 (list (car org-agenda-last-arguments) sd span t)))
6764 (org-agenda-redo)
6765 (org-agenda-find-same-or-today-or-agenda cnt))))
6767 (defun org-agenda-earlier (arg)
6768 "Go backward in time by the current span.
6769 With prefix ARG, go backward that many times the current span."
6770 (interactive "p")
6771 (org-agenda-later (- arg)))
6773 (defun org-agenda-view-mode-dispatch ()
6774 "Call one of the view mode commands."
6775 (interactive)
6776 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6777 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6778 [a]rch-trees [A]rch-files clock[R]eport include[D]iary
6779 [E]ntryText")
6780 (let ((a (read-char-exclusive)))
6781 (case a
6782 (?\ (call-interactively 'org-agenda-reset-view))
6783 (?d (call-interactively 'org-agenda-day-view))
6784 (?w (call-interactively 'org-agenda-week-view))
6785 (?m (call-interactively 'org-agenda-month-view))
6786 (?y (call-interactively 'org-agenda-year-view))
6787 (?l (call-interactively 'org-agenda-log-mode))
6788 (?L (org-agenda-log-mode '(4)))
6789 (?c (org-agenda-log-mode 'clockcheck))
6790 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6791 (?a (call-interactively 'org-agenda-archives-mode))
6792 (?A (org-agenda-archives-mode 'files))
6793 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6794 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6795 (?G (call-interactively 'org-agenda-toggle-time-grid))
6796 (?D (call-interactively 'org-agenda-toggle-diary))
6797 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6798 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6799 (org-agenda-check-type t 'timeline 'agenda)
6800 (org-agenda-redo))
6801 (message "Display now includes inactive timestamps as well"))
6802 (?q (message "Abort"))
6803 (otherwise (error "Invalid key" )))))
6805 (defun org-agenda-reset-view ()
6806 "Switch to default view for agenda."
6807 (interactive)
6808 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6809 (defun org-agenda-day-view (&optional day-of-year)
6810 "Switch to daily view for agenda.
6811 With argument DAY-OF-YEAR, switch to that day of the year."
6812 (interactive "P")
6813 (org-agenda-change-time-span 'day day-of-year))
6814 (defun org-agenda-week-view (&optional iso-week)
6815 "Switch to daily view for agenda.
6816 With argument ISO-WEEK, switch to the corresponding ISO week.
6817 If ISO-WEEK has more then 2 digits, only the last two encode the
6818 week. Any digits before this encode a year. So 200712 means
6819 week 12 of year 2007. Years in the range 1938-2037 can also be
6820 written as 2-digit years."
6821 (interactive "P")
6822 (org-agenda-change-time-span 'week iso-week))
6823 (defun org-agenda-month-view (&optional month)
6824 "Switch to monthly view for agenda.
6825 With argument MONTH, switch to that month."
6826 (interactive "P")
6827 (org-agenda-change-time-span 'month month))
6828 (defun org-agenda-year-view (&optional year)
6829 "Switch to yearly view for agenda.
6830 With argument YEAR, switch to that year.
6831 If MONTH has more then 2 digits, only the last two encode the
6832 month. Any digits before this encode a year. So 200712 means
6833 December year 2007. Years in the range 1938-2037 can also be
6834 written as 2-digit years."
6835 (interactive "P")
6836 (when year
6837 (setq year (org-small-year-to-year year)))
6838 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6839 (org-agenda-change-time-span 'year year)
6840 (error "Abort")))
6842 (defun org-agenda-change-time-span (span &optional n)
6843 "Change the agenda view to SPAN.
6844 SPAN may be `day', `week', `month', `year'."
6845 (org-agenda-check-type t 'agenda)
6846 (if (and (not n) (equal org-agenda-current-span span))
6847 (error "Viewing span is already \"%s\"" span))
6848 (let* ((sd (or (org-get-at-bol 'day)
6849 org-starting-day))
6850 (sd (org-agenda-compute-starting-span sd span n))
6851 (org-agenda-overriding-arguments
6852 (or org-agenda-overriding-arguments
6853 (list (car org-agenda-last-arguments) sd span t))))
6854 (org-agenda-redo)
6855 (org-agenda-find-same-or-today-or-agenda))
6856 (org-agenda-set-mode-name)
6857 (message "Switched to %s view" span))
6859 (defun org-agenda-compute-starting-span (sd span &optional n)
6860 "Compute starting date for agenda.
6861 SPAN may be `day', `week', `month', `year'. The return value
6862 is a cons cell with the starting date and the number of days,
6863 so that the date SD will be in that range."
6864 (let* ((greg (calendar-gregorian-from-absolute sd))
6865 (dg (nth 1 greg))
6866 (mg (car greg))
6867 (yg (nth 2 greg)))
6868 (cond
6869 ((eq span 'day)
6870 (when n
6871 (setq sd (+ (calendar-absolute-from-gregorian
6872 (list mg 1 yg))
6873 n -1))))
6874 ((eq span 'week)
6875 (let* ((nt (calendar-day-of-week
6876 (calendar-gregorian-from-absolute sd)))
6877 (d (if org-agenda-start-on-weekday
6878 (- nt org-agenda-start-on-weekday)
6881 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6882 (when n
6883 (require 'cal-iso)
6884 (when (> n 99)
6885 (setq y1 (org-small-year-to-year (/ n 100))
6886 n (mod n 100)))
6887 (setq sd
6888 (calendar-absolute-from-iso
6889 (list n 1
6890 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6891 ((eq span 'month)
6892 (let (y1)
6893 (when (and n (> n 99))
6894 (setq y1 (org-small-year-to-year (/ n 100))
6895 n (mod n 100)))
6896 (setq sd (calendar-absolute-from-gregorian
6897 (list (or n mg) 1 (or y1 yg))))))
6898 ((eq span 'year)
6899 (setq sd (calendar-absolute-from-gregorian
6900 (list 1 1 (or n yg))))))
6901 sd))
6903 (defun org-agenda-next-date-line (&optional arg)
6904 "Jump to the next line indicating a date in agenda buffer."
6905 (interactive "p")
6906 (org-agenda-check-type t 'agenda 'timeline)
6907 (beginning-of-line 1)
6908 ;; This does not work if user makes date format that starts with a blank
6909 (if (looking-at "^\\S-") (forward-char 1))
6910 (if (not (re-search-forward "^\\S-" nil t arg))
6911 (progn
6912 (backward-char 1)
6913 (error "No next date after this line in this buffer")))
6914 (goto-char (match-beginning 0)))
6916 (defun org-agenda-previous-date-line (&optional arg)
6917 "Jump to the previous line indicating a date in agenda buffer."
6918 (interactive "p")
6919 (org-agenda-check-type t 'agenda 'timeline)
6920 (beginning-of-line 1)
6921 (if (not (re-search-backward "^\\S-" nil t arg))
6922 (error "No previous date before this line in this buffer")))
6924 ;; Initialize the highlight
6925 (defvar org-hl (make-overlay 1 1))
6926 (overlay-put org-hl 'face 'highlight)
6928 (defun org-highlight (begin end &optional buffer)
6929 "Highlight a region with overlay."
6930 (move-overlay org-hl begin end (or buffer (current-buffer))))
6932 (defun org-unhighlight ()
6933 "Detach overlay INDEX."
6934 (org-detach-overlay org-hl))
6936 ;; FIXME this is currently not used.
6937 (defun org-highlight-until-next-command (beg end &optional buffer)
6938 "Move the highlight overlay to BEG/END, remove it before the next command."
6939 (org-highlight beg end buffer)
6940 (add-hook 'pre-command-hook 'org-unhighlight-once))
6941 (defun org-unhighlight-once ()
6942 "Remove the highlight from its position, and this function from the hook."
6943 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6944 (org-unhighlight))
6946 (defun org-agenda-follow-mode ()
6947 "Toggle follow mode in an agenda buffer."
6948 (interactive)
6949 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6950 (org-agenda-set-mode-name)
6951 (org-agenda-do-context-action)
6952 (message "Follow mode is %s"
6953 (if org-agenda-follow-mode "on" "off")))
6955 (defun org-agenda-entry-text-mode (&optional arg)
6956 "Toggle entry text mode in an agenda buffer."
6957 (interactive "P")
6958 (setq org-agenda-entry-text-mode (or (integerp arg)
6959 (not org-agenda-entry-text-mode)))
6960 (org-agenda-entry-text-hide)
6961 (and org-agenda-entry-text-mode
6962 (let ((org-agenda-entry-text-maxlines
6963 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6964 (org-agenda-entry-text-show)))
6965 (org-agenda-set-mode-name)
6966 (message "Entry text mode is %s. Maximum number of lines is %d"
6967 (if org-agenda-entry-text-mode "on" "off")
6968 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6970 (defun org-agenda-clockreport-mode (&optional with-filter)
6971 "Toggle clocktable mode in an agenda buffer.
6972 With prefix arg WITH-FILTER, make the clocktable respect the current
6973 agenda filter."
6974 (interactive "P")
6975 (org-agenda-check-type t 'agenda)
6976 (if with-filter
6977 (setq org-agenda-clockreport-mode 'with-filter)
6978 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6979 (org-agenda-set-mode-name)
6980 (org-agenda-redo)
6981 (message "Clocktable mode is %s"
6982 (if org-agenda-clockreport-mode "on" "off")))
6984 (defun org-agenda-log-mode (&optional special)
6985 "Toggle log mode in an agenda buffer.
6986 With argument SPECIAL, show all possible log items, not only the ones
6987 configured in `org-agenda-log-mode-items'.
6988 With a double `C-u' prefix arg, show *only* log items, nothing else."
6989 (interactive "P")
6990 (org-agenda-check-type t 'agenda 'timeline)
6991 (setq org-agenda-show-log
6992 (cond
6993 ((equal special '(16)) 'only)
6994 ((eq special 'clockcheck)
6995 (if (eq org-agenda-show-log 'clockcheck)
6996 nil 'clockcheck))
6997 (special '(closed clock state))
6998 (t (not org-agenda-show-log))))
6999 (org-agenda-set-mode-name)
7000 (org-agenda-redo)
7001 (message "Log mode is %s"
7002 (if org-agenda-show-log "on" "off")))
7004 (defun org-agenda-archives-mode (&optional with-files)
7005 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7006 When called with a prefix argument, include all archive files as well."
7007 (interactive "P")
7008 (setq org-agenda-archives-mode
7009 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7010 (org-agenda-set-mode-name)
7011 (org-agenda-redo)
7012 (message
7013 "%s"
7014 (cond
7015 ((eq org-agenda-archives-mode nil)
7016 "No archives are included")
7017 ((eq org-agenda-archives-mode 'trees)
7018 (format "Trees with :%s: tag are included" org-archive-tag))
7019 ((eq org-agenda-archives-mode t)
7020 (format "Trees with :%s: tag and all active archive files are included"
7021 org-archive-tag)))))
7023 (defun org-agenda-toggle-diary ()
7024 "Toggle diary inclusion in an agenda buffer."
7025 (interactive)
7026 (org-agenda-check-type t 'agenda)
7027 (setq org-agenda-include-diary (not org-agenda-include-diary))
7028 (org-agenda-redo)
7029 (org-agenda-set-mode-name)
7030 (message "Diary inclusion turned %s"
7031 (if org-agenda-include-diary "on" "off")))
7033 (defun org-agenda-toggle-deadlines ()
7034 "Toggle inclusion of entries with a deadline in an agenda buffer."
7035 (interactive)
7036 (org-agenda-check-type t 'agenda)
7037 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7038 (org-agenda-redo)
7039 (org-agenda-set-mode-name)
7040 (message "Deadlines inclusion turned %s"
7041 (if org-agenda-include-deadlines "on" "off")))
7043 (defun org-agenda-toggle-time-grid ()
7044 "Toggle time grid in an agenda buffer."
7045 (interactive)
7046 (org-agenda-check-type t 'agenda)
7047 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7048 (org-agenda-redo)
7049 (org-agenda-set-mode-name)
7050 (message "Time-grid turned %s"
7051 (if org-agenda-use-time-grid "on" "off")))
7053 (defun org-agenda-set-mode-name ()
7054 "Set the mode name to indicate all the small mode settings."
7055 (setq mode-name
7056 (list "Org-Agenda"
7057 (if (get 'org-agenda-files 'org-restrict) " []" "")
7059 '(:eval (org-agenda-span-name org-agenda-current-span))
7060 (if org-agenda-follow-mode " Follow" "")
7061 (if org-agenda-entry-text-mode " ETxt" "")
7062 (if org-agenda-include-diary " Diary" "")
7063 (if org-agenda-include-deadlines " Ddl" "")
7064 (if org-agenda-use-time-grid " Grid" "")
7065 (if (and (boundp 'org-habit-show-habits)
7066 org-habit-show-habits) " Habit" "")
7067 (cond
7068 ((consp org-agenda-show-log) " LogAll")
7069 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7070 (org-agenda-show-log " Log")
7071 (t ""))
7072 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7073 :preset-filter))
7074 '(:eval (org-propertize
7075 (concat " <"
7076 (mapconcat
7077 'identity
7078 (append
7079 (get 'org-agenda-category-filter :preset-filter)
7080 org-agenda-category-filter)
7082 ">")
7083 'face 'org-agenda-filter-category
7084 'help-echo "Category used in filtering"))
7086 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7087 :preset-filter))
7088 '(:eval (org-propertize
7089 (concat " {"
7090 (mapconcat
7091 'identity
7092 (append
7093 (get 'org-agenda-tag-filter :preset-filter)
7094 org-agenda-tag-filter)
7096 "}")
7097 'face 'org-agenda-filter-tags
7098 'help-echo "Tags used in filtering"))
7100 (if org-agenda-archives-mode
7101 (if (eq org-agenda-archives-mode t)
7102 " Archives"
7103 (format " :%s:" org-archive-tag))
7105 (if org-agenda-clockreport-mode
7106 (if (eq org-agenda-clockreport-mode 'with-filter)
7107 " Clock{}" " Clock")
7108 "")))
7109 (force-mode-line-update))
7111 (defun org-agenda-post-command-hook ()
7112 (setq org-agenda-type
7113 (or (get-text-property (point) 'org-agenda-type)
7114 (get-text-property (max (point-min) (1- (point)))
7115 'org-agenda-type))))
7117 (defun org-agenda-next-line ()
7118 "Move cursor to the next line, and show if follow mode is active."
7119 (interactive)
7120 (call-interactively 'next-line)
7121 (org-agenda-do-context-action))
7123 (defun org-agenda-previous-line ()
7124 "Move cursor to the previous line, and show if follow-mode is active."
7125 (interactive)
7126 (call-interactively 'previous-line)
7127 (org-agenda-do-context-action))
7129 (defun org-agenda-do-context-action ()
7130 "Show outline path and, maybe, follow mode window."
7131 (let ((m (org-get-at-bol 'org-marker)))
7132 (when (and (markerp m) (marker-buffer m))
7133 (and org-agenda-follow-mode
7134 (if org-agenda-follow-indirect
7135 (org-agenda-tree-to-indirect-buffer)
7136 (org-agenda-show)))
7137 (and org-agenda-show-outline-path
7138 (org-with-point-at m (org-display-outline-path t))))))
7140 (defun org-agenda-show-priority ()
7141 "Show the priority of the current item.
7142 This priority is composed of the main priority given with the [#A] cookies,
7143 and by additional input from the age of a schedules or deadline entry."
7144 (interactive)
7145 (let* ((pri (org-get-at-bol 'priority)))
7146 (message "Priority is %d" (if pri pri -1000))))
7148 (defun org-agenda-show-tags ()
7149 "Show the tags applicable to the current item."
7150 (interactive)
7151 (let* ((tags (org-get-at-bol 'tags)))
7152 (if tags
7153 (message "Tags are :%s:"
7154 (org-no-properties (mapconcat 'identity tags ":")))
7155 (message "No tags associated with this line"))))
7157 (defun org-agenda-goto (&optional highlight)
7158 "Go to the Org-mode file which contains the item at point."
7159 (interactive)
7160 (let* ((marker (or (org-get-at-bol 'org-marker)
7161 (org-agenda-error)))
7162 (buffer (marker-buffer marker))
7163 (pos (marker-position marker)))
7164 (switch-to-buffer-other-window buffer)
7165 (widen)
7166 (push-mark)
7167 (goto-char pos)
7168 (when (eq major-mode 'org-mode)
7169 (org-show-context 'agenda)
7170 (save-excursion
7171 (and (outline-next-heading)
7172 (org-flag-heading nil)))) ; show the next heading
7173 (when (outline-invisible-p)
7174 (show-entry)) ; display invisible text
7175 (recenter (/ (window-height) 2))
7176 (run-hooks 'org-agenda-after-show-hook)
7177 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7179 (defvar org-agenda-after-show-hook nil
7180 "Normal hook run after an item has been shown from the agenda.
7181 Point is in the buffer where the item originated.")
7183 (defun org-agenda-kill ()
7184 "Kill the entry or subtree belonging to the current agenda entry."
7185 (interactive)
7186 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7187 (let* ((marker (or (org-get-at-bol 'org-marker)
7188 (org-agenda-error)))
7189 (buffer (marker-buffer marker))
7190 (pos (marker-position marker))
7191 (type (org-get-at-bol 'type))
7192 dbeg dend (n 0) conf)
7193 (org-with-remote-undo buffer
7194 (with-current-buffer buffer
7195 (save-excursion
7196 (goto-char pos)
7197 (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
7198 (setq dbeg (progn (org-back-to-heading t) (point))
7199 dend (org-end-of-subtree t t))
7200 (setq dbeg (point-at-bol)
7201 dend (min (point-max) (1+ (point-at-eol)))))
7202 (goto-char dbeg)
7203 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7204 (setq conf (or (eq t org-agenda-confirm-kill)
7205 (and (numberp org-agenda-confirm-kill)
7206 (> n org-agenda-confirm-kill))))
7207 (and conf
7208 (not (y-or-n-p
7209 (format "Delete entry with %d lines in buffer \"%s\"? "
7210 n (buffer-name buffer))))
7211 (error "Abort"))
7212 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
7213 (with-current-buffer buffer (delete-region dbeg dend))
7214 (message "Agenda item and source killed"))))
7216 (defvar org-archive-default-command)
7217 (defun org-agenda-archive-default ()
7218 "Archive the entry or subtree belonging to the current agenda entry."
7219 (interactive)
7220 (require 'org-archive)
7221 (org-agenda-archive-with org-archive-default-command))
7223 (defun org-agenda-archive-default-with-confirmation ()
7224 "Archive the entry or subtree belonging to the current agenda entry."
7225 (interactive)
7226 (require 'org-archive)
7227 (org-agenda-archive-with org-archive-default-command 'confirm))
7229 (defun org-agenda-archive ()
7230 "Archive the entry or subtree belonging to the current agenda entry."
7231 (interactive)
7232 (org-agenda-archive-with 'org-archive-subtree))
7234 (defun org-agenda-archive-to-archive-sibling ()
7235 "Move the entry to the archive sibling."
7236 (interactive)
7237 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7239 (defun org-agenda-archive-with (cmd &optional confirm)
7240 "Move the entry to the archive sibling."
7241 (interactive)
7242 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7243 (let* ((marker (or (org-get-at-bol 'org-marker)
7244 (org-agenda-error)))
7245 (buffer (marker-buffer marker))
7246 (pos (marker-position marker)))
7247 (org-with-remote-undo buffer
7248 (with-current-buffer buffer
7249 (if (eq major-mode 'org-mode)
7250 (if (and confirm
7251 (not (y-or-n-p "Archive this subtree or entry? ")))
7252 (error "Abort")
7253 (save-excursion
7254 (goto-char pos)
7255 (org-remove-subtree-entries-from-agenda)
7256 (org-back-to-heading t)
7257 (funcall cmd)))
7258 (error "Archiving works only in Org-mode files"))))))
7260 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7261 "Remove all lines in the agenda that correspond to a given subtree.
7262 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7263 If this information is not given, the function uses the tree at point."
7264 (let ((buf (or buf (current-buffer))) m p)
7265 (save-excursion
7266 (unless (and beg end)
7267 (org-back-to-heading t)
7268 (setq beg (point))
7269 (org-end-of-subtree t)
7270 (setq end (point)))
7271 (set-buffer (get-buffer org-agenda-buffer-name))
7272 (save-excursion
7273 (goto-char (point-max))
7274 (beginning-of-line 1)
7275 (while (not (bobp))
7276 (when (and (setq m (org-get-at-bol 'org-marker))
7277 (equal buf (marker-buffer m))
7278 (setq p (marker-position m))
7279 (>= p beg)
7280 (< p end))
7281 (let ((inhibit-read-only t))
7282 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7283 (beginning-of-line 0))))))
7285 (defun org-agenda-refile (&optional goto rfloc no-update)
7286 "Refile the item at point."
7287 (interactive "P")
7288 (if (equal goto '(16))
7289 (org-refile-goto-last-stored)
7290 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7291 (org-agenda-error)))
7292 (buffer (marker-buffer marker))
7293 (pos (marker-position marker))
7294 (rfloc (or rfloc
7295 (org-refile-get-location
7296 (if goto "Goto" "Refile to") buffer
7297 org-refile-allow-creating-parent-nodes))))
7298 (with-current-buffer buffer
7299 (save-excursion
7300 (save-restriction
7301 (widen)
7302 (goto-char marker)
7303 (org-remove-subtree-entries-from-agenda)
7304 (org-refile goto buffer rfloc)))))
7305 (unless no-update (org-agenda-redo))))
7307 (defun org-agenda-open-link (&optional arg)
7308 "Follow the link in the current line, if any.
7309 This looks for a link in the displayed line in the agenda. It also looks
7310 at the text of the entry itself."
7311 (interactive "P")
7312 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7313 (org-get-at-bol 'org-marker)))
7314 (buffer (and marker (marker-buffer marker)))
7315 (prefix (buffer-substring
7316 (point-at-bol) (point-at-eol))))
7317 (cond
7318 (buffer
7319 (with-current-buffer buffer
7320 (save-excursion
7321 (save-restriction
7322 (widen)
7323 (goto-char marker)
7324 (org-offer-links-in-entry arg prefix)))))
7325 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7326 (save-excursion
7327 (beginning-of-line 1)
7328 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7329 (org-open-link-from-string (match-string 1)))
7330 (t (error "No link to open here")))))
7332 (defun org-agenda-copy-local-variable (var)
7333 "Get a variable from a referenced buffer and install it here."
7334 (let ((m (org-get-at-bol 'org-marker)))
7335 (when (and m (buffer-live-p (marker-buffer m)))
7336 (org-set-local var (with-current-buffer (marker-buffer m)
7337 (symbol-value var))))))
7339 (defun org-agenda-switch-to (&optional delete-other-windows)
7340 "Go to the Org-mode file which contains the item at point."
7341 (interactive)
7342 (if (and org-return-follows-link
7343 (not (org-get-at-bol 'org-marker))
7344 (org-in-regexp org-bracket-link-regexp))
7345 (org-open-link-from-string (match-string 0))
7346 (let* ((marker (or (org-get-at-bol 'org-marker)
7347 (org-agenda-error)))
7348 (buffer (marker-buffer marker))
7349 (pos (marker-position marker)))
7350 (org-pop-to-buffer-same-window buffer)
7351 (and delete-other-windows (delete-other-windows))
7352 (widen)
7353 (goto-char pos)
7354 (when (eq major-mode 'org-mode)
7355 (org-show-context 'agenda)
7356 (save-excursion
7357 (and (outline-next-heading)
7358 (org-flag-heading nil))) ; show the next heading
7359 (when (outline-invisible-p)
7360 (show-entry)))))) ; display invisible text
7362 (defun org-agenda-goto-mouse (ev)
7363 "Go to the Org-mode file which contains the item at the mouse click."
7364 (interactive "e")
7365 (mouse-set-point ev)
7366 (org-agenda-goto))
7368 (defun org-agenda-show (&optional full-entry)
7369 "Display the Org-mode file which contains the item at point.
7370 With prefix argument FULL-ENTRY, make the entire entry visible
7371 if it was hidden in the outline."
7372 (interactive "P")
7373 (let ((win (selected-window)))
7374 (if full-entry
7375 (let ((org-show-entry-below t))
7376 (org-agenda-goto t))
7377 (org-agenda-goto t))
7378 (select-window win)))
7380 (defvar org-agenda-show-window nil)
7381 (defun org-agenda-show-and-scroll-up (&optional arg)
7382 "Display the Org-mode file which contains the item at point.
7383 When called repeatedly, scroll the window that is displaying the buffer.
7384 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7385 `show-subtree' to display the item, so that drawers and logbooks stay
7386 folded."
7387 (interactive "P")
7388 (let ((win (selected-window)))
7389 (if (and (window-live-p org-agenda-show-window)
7390 (eq this-command last-command))
7391 (progn
7392 (select-window org-agenda-show-window)
7393 (ignore-errors (scroll-up)))
7394 (org-agenda-goto t)
7395 (if arg (org-show-entry) (show-subtree))
7396 (setq org-agenda-show-window (selected-window)))
7397 (select-window win)))
7399 (defun org-agenda-show-scroll-down ()
7400 "Scroll down the window showing the agenda."
7401 (interactive)
7402 (let ((win (selected-window)))
7403 (when (window-live-p org-agenda-show-window)
7404 (select-window org-agenda-show-window)
7405 (ignore-errors (scroll-down))
7406 (select-window win))))
7408 (defun org-agenda-show-1 (&optional more)
7409 "Display the Org-mode file which contains the item at point.
7410 The prefix arg selects the amount of information to display:
7412 0 hide the subtree
7413 1 just show the entry according to defaults.
7414 2 show the children view
7415 3 show the subtree view
7416 4 show the entire subtree and any LOGBOOK drawers
7417 5 show the entire subtree and any drawers
7418 With prefix argument FULL-ENTRY, make the entire entry visible
7419 if it was hidden in the outline."
7420 (interactive "p")
7421 (let ((win (selected-window)))
7422 (org-agenda-goto t)
7423 (org-recenter-heading 1)
7424 (cond
7425 ((= more 0)
7426 (hide-subtree)
7427 (save-excursion
7428 (org-back-to-heading)
7429 (run-hook-with-args 'org-cycle-hook 'folded))
7430 (message "Remote: FOLDED"))
7431 ((and (org-called-interactively-p 'any) (= more 1))
7432 (message "Remote: show with default settings"))
7433 ((= more 2)
7434 (show-entry)
7435 (show-children)
7436 (save-excursion
7437 (org-back-to-heading)
7438 (run-hook-with-args 'org-cycle-hook 'children))
7439 (message "Remote: CHILDREN"))
7440 ((= more 3)
7441 (show-subtree)
7442 (save-excursion
7443 (org-back-to-heading)
7444 (run-hook-with-args 'org-cycle-hook 'subtree))
7445 (message "Remote: SUBTREE"))
7446 ((= more 4)
7447 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7448 (org-drawer-regexp
7449 (concat "^[ \t]*:\\("
7450 (mapconcat 'regexp-quote org-drawers "\\|")
7451 "\\):[ \t]*$")))
7452 (show-subtree)
7453 (save-excursion
7454 (org-back-to-heading)
7455 (org-cycle-hide-drawers 'subtree)))
7456 (message "Remote: SUBTREE AND LOGBOOK"))
7457 ((> more 4)
7458 (show-subtree)
7459 (message "Remote: SUBTREE AND ALL DRAWERS")))
7460 (select-window win)))
7462 (defun org-recenter-heading (n)
7463 (save-excursion
7464 (org-back-to-heading)
7465 (recenter n)))
7467 (defvar org-agenda-cycle-counter nil)
7468 (defun org-agenda-cycle-show (&optional n)
7469 "Show the current entry in another window, with default settings.
7470 Default settings are taken from `org-show-hierarchy-above' and siblings.
7471 When use repeatedly in immediate succession, the remote entry will cycle
7472 through visibility
7474 children -> subtree -> folded
7476 When called with a numeric prefix arg, that arg will be passed through to
7477 `org-agenda-show-1'. For the interpretation of that argument, see the
7478 docstring of `org-agenda-show-1'."
7479 (interactive "P")
7480 (if (integerp n)
7481 (setq org-agenda-cycle-counter n)
7482 (if (not (eq last-command this-command))
7483 (setq org-agenda-cycle-counter 1)
7484 (if (equal org-agenda-cycle-counter 0)
7485 (setq org-agenda-cycle-counter 2)
7486 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7487 (if (> org-agenda-cycle-counter 3)
7488 (setq org-agenda-cycle-counter 0)))))
7489 (org-agenda-show-1 org-agenda-cycle-counter))
7491 (defun org-agenda-recenter (arg)
7492 "Display the Org-mode file which contains the item at point and recenter."
7493 (interactive "P")
7494 (let ((win (selected-window)))
7495 (org-agenda-goto t)
7496 (recenter arg)
7497 (select-window win)))
7499 (defun org-agenda-show-mouse (ev)
7500 "Display the Org-mode file which contains the item at the mouse click."
7501 (interactive "e")
7502 (mouse-set-point ev)
7503 (org-agenda-show))
7505 (defun org-agenda-check-no-diary ()
7506 "Check if the entry is a diary link and abort if yes."
7507 (if (org-get-at-bol 'org-agenda-diary-link)
7508 (org-agenda-error)))
7510 (defun org-agenda-error ()
7511 (error "Command not allowed in this line"))
7513 (defun org-agenda-tree-to-indirect-buffer ()
7514 "Show the subtree corresponding to the current entry in an indirect buffer.
7515 This calls the command `org-tree-to-indirect-buffer' from the original
7516 Org-mode buffer.
7517 With numerical prefix arg ARG, go up to this level and then take that tree.
7518 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7519 use the dedicated frame)."
7520 (interactive)
7521 (if (and current-prefix-arg (listp current-prefix-arg))
7522 (org-agenda-do-tree-to-indirect-buffer)
7523 (let ((agenda-window (selected-window))
7524 (indirect-window (and org-last-indirect-buffer (get-buffer-window org-last-indirect-buffer))))
7525 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7526 (unwind-protect
7527 (progn
7528 (unless (and indirect-window (window-live-p indirect-window))
7529 (setq indirect-window (split-window agenda-window)))
7530 (select-window indirect-window)
7531 (switch-to-buffer org-last-indirect-buffer :norecord)
7532 (fit-window-to-buffer indirect-window))
7533 (select-window agenda-window)))))
7535 (defun org-agenda-do-tree-to-indirect-buffer ()
7536 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7537 (org-agenda-check-no-diary)
7538 (let* ((marker (or (org-get-at-bol 'org-marker)
7539 (org-agenda-error)))
7540 (buffer (marker-buffer marker))
7541 (pos (marker-position marker)))
7542 (with-current-buffer buffer
7543 (save-excursion
7544 (goto-char pos)
7545 (call-interactively 'org-tree-to-indirect-buffer)))))
7547 (defvar org-last-heading-marker (make-marker)
7548 "Marker pointing to the headline that last changed its TODO state
7549 by a remote command from the agenda.")
7551 (defun org-agenda-todo-nextset ()
7552 "Switch TODO entry to next sequence."
7553 (interactive)
7554 (org-agenda-todo 'nextset))
7556 (defun org-agenda-todo-previousset ()
7557 "Switch TODO entry to previous sequence."
7558 (interactive)
7559 (org-agenda-todo 'previousset))
7561 (defun org-agenda-todo (&optional arg)
7562 "Cycle TODO state of line at point, also in Org-mode file.
7563 This changes the line at point, all other lines in the agenda referring to
7564 the same tree node, and the headline of the tree node in the Org-mode file."
7565 (interactive "P")
7566 (org-agenda-check-no-diary)
7567 (let* ((col (current-column))
7568 (marker (or (org-get-at-bol 'org-marker)
7569 (org-agenda-error)))
7570 (buffer (marker-buffer marker))
7571 (pos (marker-position marker))
7572 (hdmarker (org-get-at-bol 'org-hd-marker))
7573 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7574 (inhibit-read-only t)
7575 org-agenda-headline-snapshot-before-repeat newhead just-one)
7576 (org-with-remote-undo buffer
7577 (with-current-buffer buffer
7578 (widen)
7579 (goto-char pos)
7580 (org-show-context 'agenda)
7581 (save-excursion
7582 (and (outline-next-heading)
7583 (org-flag-heading nil))) ; show the next heading
7584 (let ((current-prefix-arg arg))
7585 (call-interactively 'org-todo))
7586 (and (bolp) (forward-char 1))
7587 (setq newhead (org-get-heading))
7588 (when (and (org-bound-and-true-p
7589 org-agenda-headline-snapshot-before-repeat)
7590 (not (equal org-agenda-headline-snapshot-before-repeat
7591 newhead))
7592 todayp)
7593 (setq newhead org-agenda-headline-snapshot-before-repeat
7594 just-one t))
7595 (save-excursion
7596 (org-back-to-heading)
7597 (move-marker org-last-heading-marker (point))))
7598 (beginning-of-line 1)
7599 (save-excursion
7600 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7601 (org-move-to-column col))))
7603 (defun org-agenda-add-note (&optional arg)
7604 "Add a time-stamped note to the entry at point."
7605 (interactive "P")
7606 (org-agenda-check-no-diary)
7607 (let* ((marker (or (org-get-at-bol 'org-marker)
7608 (org-agenda-error)))
7609 (buffer (marker-buffer marker))
7610 (pos (marker-position marker))
7611 (hdmarker (org-get-at-bol 'org-hd-marker))
7612 (inhibit-read-only t))
7613 (with-current-buffer buffer
7614 (widen)
7615 (goto-char pos)
7616 (org-show-context 'agenda)
7617 (save-excursion
7618 (and (outline-next-heading)
7619 (org-flag-heading nil))) ; show the next heading
7620 (org-add-note))))
7622 (defun org-agenda-change-all-lines (newhead hdmarker
7623 &optional fixface just-this)
7624 "Change all lines in the agenda buffer which match HDMARKER.
7625 The new content of the line will be NEWHEAD (as modified by
7626 `org-agenda-format-item'). HDMARKER is checked with
7627 `equal' against all `org-hd-marker' text properties in the file.
7628 If FIXFACE is non-nil, the face of each item is modified according to
7629 the new TODO state.
7630 If JUST-THIS is non-nil, change just the current line, not all.
7631 If FORCE-TAGS is non nil, the car of it returns the new tags."
7632 (let* ((inhibit-read-only t)
7633 (line (org-current-line))
7634 (org-agenda-buffer (current-buffer))
7635 (thetags (with-current-buffer (marker-buffer hdmarker)
7636 (save-excursion (save-restriction (widen)
7637 (goto-char hdmarker)
7638 (org-get-tags-at)))))
7639 props m pl undone-face done-face finish new dotime cat tags)
7640 (save-excursion
7641 (goto-char (point-max))
7642 (beginning-of-line 1)
7643 (while (not finish)
7644 (setq finish (bobp))
7645 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7646 (or (not just-this) (= (org-current-line) line))
7647 (equal m hdmarker))
7648 (setq props (text-properties-at (point))
7649 dotime (org-get-at-bol 'dotime)
7650 cat (org-get-at-bol 'org-category)
7651 tags thetags
7653 (let ((org-prefix-format-compiled
7654 (or (get-text-property (point) 'format)
7655 org-prefix-format-compiled))
7656 (extra (org-get-at-bol 'extra)))
7657 (with-current-buffer (marker-buffer hdmarker)
7658 (save-excursion
7659 (save-restriction
7660 (widen)
7661 (org-agenda-format-item extra newhead cat tags dotime)))))
7662 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7663 undone-face (org-get-at-bol 'undone-face)
7664 done-face (org-get-at-bol 'done-face))
7665 (beginning-of-line 1)
7666 (cond
7667 ((equal new "")
7668 (and (looking-at ".*\n?") (replace-match "")))
7669 ((looking-at ".*")
7670 (replace-match new t t)
7671 (beginning-of-line 1)
7672 (add-text-properties (point-at-bol) (point-at-eol) props)
7673 (when fixface
7674 (add-text-properties
7675 (point-at-bol) (point-at-eol)
7676 (list 'face
7677 (if org-last-todo-state-is-todo
7678 undone-face done-face))))
7679 (org-agenda-highlight-todo 'line)
7680 (beginning-of-line 1))
7681 (t (error "Line update did not work"))))
7682 (beginning-of-line 0)))
7683 (org-finalize-agenda)))
7685 (defun org-agenda-align-tags (&optional line)
7686 "Align all tags in agenda items to `org-agenda-tags-column'."
7687 (let ((inhibit-read-only t) l c)
7688 (save-excursion
7689 (goto-char (if line (point-at-bol) (point-min)))
7690 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7691 (if line (point-at-eol) nil) t)
7692 (add-text-properties
7693 (match-beginning 2) (match-end 2)
7694 (list 'face (delq nil (let ((prop (get-text-property
7695 (match-beginning 2) 'face)))
7696 (or (listp prop) (setq prop (list prop)))
7697 (if (memq 'org-tag prop)
7698 prop
7699 (cons 'org-tag prop))))))
7700 (setq l (- (match-end 2) (match-beginning 2))
7701 c (if (< org-agenda-tags-column 0)
7702 (- (abs org-agenda-tags-column) l)
7703 org-agenda-tags-column))
7704 (delete-region (match-beginning 1) (match-end 1))
7705 (goto-char (match-beginning 1))
7706 (insert (org-add-props
7707 (make-string (max 1 (- c (current-column))) ?\ )
7708 (plist-put (copy-sequence (text-properties-at (point)))
7709 'face nil))))
7710 (goto-char (point-min))
7711 (org-font-lock-add-tag-faces (point-max)))))
7713 (defun org-agenda-priority-up ()
7714 "Increase the priority of line at point, also in Org-mode file."
7715 (interactive)
7716 (org-agenda-priority 'up))
7718 (defun org-agenda-priority-down ()
7719 "Decrease the priority of line at point, also in Org-mode file."
7720 (interactive)
7721 (org-agenda-priority 'down))
7723 (defun org-agenda-priority (&optional force-direction)
7724 "Set the priority of line at point, also in Org-mode file.
7725 This changes the line at point, all other lines in the agenda referring to
7726 the same tree node, and the headline of the tree node in the Org-mode file."
7727 (interactive)
7728 (unless org-enable-priority-commands
7729 (error "Priority commands are disabled"))
7730 (org-agenda-check-no-diary)
7731 (let* ((marker (or (org-get-at-bol 'org-marker)
7732 (org-agenda-error)))
7733 (hdmarker (org-get-at-bol 'org-hd-marker))
7734 (buffer (marker-buffer hdmarker))
7735 (pos (marker-position hdmarker))
7736 (inhibit-read-only t)
7737 newhead)
7738 (org-with-remote-undo buffer
7739 (with-current-buffer buffer
7740 (widen)
7741 (goto-char pos)
7742 (org-show-context 'agenda)
7743 (save-excursion
7744 (and (outline-next-heading)
7745 (org-flag-heading nil))) ; show the next heading
7746 (funcall 'org-priority force-direction)
7747 (end-of-line 1)
7748 (setq newhead (org-get-heading)))
7749 (org-agenda-change-all-lines newhead hdmarker)
7750 (beginning-of-line 1))))
7752 ;; FIXME: should fix the tags property of the agenda line.
7753 (defun org-agenda-set-tags (&optional tag onoff)
7754 "Set tags for the current headline."
7755 (interactive)
7756 (org-agenda-check-no-diary)
7757 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7758 (call-interactively 'org-change-tag-in-region)
7759 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7760 (org-agenda-error)))
7761 (buffer (marker-buffer hdmarker))
7762 (pos (marker-position hdmarker))
7763 (inhibit-read-only t)
7764 newhead)
7765 (org-with-remote-undo buffer
7766 (with-current-buffer buffer
7767 (widen)
7768 (goto-char pos)
7769 (save-excursion
7770 (org-show-context 'agenda))
7771 (save-excursion
7772 (and (outline-next-heading)
7773 (org-flag-heading nil))) ; show the next heading
7774 (goto-char pos)
7775 (if tag
7776 (org-toggle-tag tag onoff)
7777 (call-interactively 'org-set-tags))
7778 (end-of-line 1)
7779 (setq newhead (org-get-heading)))
7780 (org-agenda-change-all-lines newhead hdmarker)
7781 (beginning-of-line 1)))))
7783 (defun org-agenda-set-property ()
7784 "Set a property for the current headline."
7785 (interactive)
7786 (org-agenda-check-no-diary)
7787 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7788 (org-agenda-error)))
7789 (buffer (marker-buffer hdmarker))
7790 (pos (marker-position hdmarker))
7791 (inhibit-read-only t)
7792 newhead)
7793 (org-with-remote-undo buffer
7794 (with-current-buffer buffer
7795 (widen)
7796 (goto-char pos)
7797 (save-excursion
7798 (org-show-context 'agenda))
7799 (save-excursion
7800 (and (outline-next-heading)
7801 (org-flag-heading nil))) ; show the next heading
7802 (goto-char pos)
7803 (call-interactively 'org-set-property)))))
7805 (defun org-agenda-set-effort ()
7806 "Set the effort property for the current headline."
7807 (interactive)
7808 (org-agenda-check-no-diary)
7809 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7810 (org-agenda-error)))
7811 (buffer (marker-buffer hdmarker))
7812 (pos (marker-position hdmarker))
7813 (inhibit-read-only t)
7814 newhead)
7815 (org-with-remote-undo buffer
7816 (with-current-buffer buffer
7817 (widen)
7818 (goto-char pos)
7819 (save-excursion
7820 (org-show-context 'agenda))
7821 (save-excursion
7822 (and (outline-next-heading)
7823 (org-flag-heading nil))) ; show the next heading
7824 (goto-char pos)
7825 (call-interactively 'org-set-effort)
7826 (end-of-line 1)
7827 (setq newhead (org-get-heading)))
7828 (org-agenda-change-all-lines newhead hdmarker))))
7830 (defun org-agenda-toggle-archive-tag ()
7831 "Toggle the archive tag for the current entry."
7832 (interactive)
7833 (org-agenda-check-no-diary)
7834 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7835 (org-agenda-error)))
7836 (buffer (marker-buffer hdmarker))
7837 (pos (marker-position hdmarker))
7838 (inhibit-read-only t)
7839 newhead)
7840 (org-with-remote-undo buffer
7841 (with-current-buffer buffer
7842 (widen)
7843 (goto-char pos)
7844 (org-show-context 'agenda)
7845 (save-excursion
7846 (and (outline-next-heading)
7847 (org-flag-heading nil))) ; show the next heading
7848 (call-interactively 'org-toggle-archive-tag)
7849 (end-of-line 1)
7850 (setq newhead (org-get-heading)))
7851 (org-agenda-change-all-lines newhead hdmarker)
7852 (beginning-of-line 1))))
7854 (defun org-agenda-do-date-later (arg)
7855 (interactive "P")
7856 (cond
7857 ((or (equal arg '(16))
7858 (memq last-command
7859 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7860 (setq this-command 'org-agenda-date-later-minutes)
7861 (org-agenda-date-later-minutes 1))
7862 ((or (equal arg '(4))
7863 (memq last-command
7864 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7865 (setq this-command 'org-agenda-date-later-hours)
7866 (org-agenda-date-later-hours 1))
7868 (org-agenda-date-later (prefix-numeric-value arg)))))
7870 (defun org-agenda-do-date-earlier (arg)
7871 (interactive "P")
7872 (cond
7873 ((or (equal arg '(16))
7874 (memq last-command
7875 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7876 (setq this-command 'org-agenda-date-earlier-minutes)
7877 (org-agenda-date-earlier-minutes 1))
7878 ((or (equal arg '(4))
7879 (memq last-command
7880 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7881 (setq this-command 'org-agenda-date-earlier-hours)
7882 (org-agenda-date-earlier-hours 1))
7884 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7886 (defun org-agenda-date-later (arg &optional what)
7887 "Change the date of this item to ARG day(s) later."
7888 (interactive "p")
7889 (org-agenda-check-type t 'agenda 'timeline)
7890 (org-agenda-check-no-diary)
7891 (let* ((marker (or (org-get-at-bol 'org-marker)
7892 (org-agenda-error)))
7893 (buffer (marker-buffer marker))
7894 (pos (marker-position marker))
7895 cdate today)
7896 (org-with-remote-undo buffer
7897 (with-current-buffer buffer
7898 (widen)
7899 (goto-char pos)
7900 (if (not (org-at-timestamp-p))
7901 (error "Cannot find time stamp"))
7902 (when (and org-agenda-move-date-from-past-immediately-to-today
7903 (equal arg 1)
7904 (or (not what) (eq what 'day))
7905 (not (save-match-data (org-at-date-range-p))))
7906 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
7907 cdate (calendar-absolute-from-gregorian
7908 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
7909 today (org-today))
7910 (if (> today cdate)
7911 ;; immediately shift to today
7912 (setq arg (- today cdate))))
7913 (org-timestamp-change arg (or what 'day))
7914 (when (and (org-at-date-range-p)
7915 (re-search-backward org-tr-regexp-both (point-at-bol)))
7916 (let ((end org-last-changed-timestamp))
7917 (org-timestamp-change arg (or what 'day))
7918 (setq org-last-changed-timestamp
7919 (concat org-last-changed-timestamp "--" end)))))
7920 (org-agenda-show-new-time marker org-last-changed-timestamp))
7921 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7923 (defun org-agenda-date-earlier (arg &optional what)
7924 "Change the date of this item to ARG day(s) earlier."
7925 (interactive "p")
7926 (org-agenda-date-later (- arg) what))
7928 (defun org-agenda-date-later-minutes (arg)
7929 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7930 (interactive "p")
7931 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7932 (org-agenda-date-later arg 'minute))
7934 (defun org-agenda-date-earlier-minutes (arg)
7935 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7936 (interactive "p")
7937 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7938 (org-agenda-date-earlier arg 'minute))
7940 (defun org-agenda-date-later-hours (arg)
7941 "Change the time of this item, in hour steps."
7942 (interactive "p")
7943 (org-agenda-date-later arg 'hour))
7945 (defun org-agenda-date-earlier-hours (arg)
7946 "Change the time of this item, in hour steps."
7947 (interactive "p")
7948 (org-agenda-date-earlier arg 'hour))
7950 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7951 "Show new date stamp via text properties."
7952 ;; We use text properties to make this undoable
7953 (let ((inhibit-read-only t)
7954 (buffer-invisibility-spec))
7955 (setq stamp (concat " " prefix " => " stamp))
7956 (save-excursion
7957 (goto-char (point-max))
7958 (while (not (bobp))
7959 (when (equal marker (org-get-at-bol 'org-marker))
7960 (org-move-to-column (- (window-width) (length stamp)) t)
7961 (org-agenda-fix-tags-filter-overlays-at (point))
7962 (if (featurep 'xemacs)
7963 ;; Use `duplicable' property to trigger undo recording
7964 (let ((ex (make-extent nil nil))
7965 (gl (make-glyph stamp)))
7966 (set-glyph-face gl 'secondary-selection)
7967 (set-extent-properties
7968 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7969 (insert-extent ex (1- (point)) (point-at-eol)))
7970 (add-text-properties
7971 (1- (point)) (point-at-eol)
7972 (list 'display (org-add-props stamp nil
7973 'face 'secondary-selection))))
7974 (beginning-of-line 1))
7975 (beginning-of-line 0)))))
7977 (defun org-agenda-date-prompt (arg)
7978 "Change the date of this item. Date is prompted for, with default today.
7979 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7980 be used to request time specification in the time stamp."
7981 (interactive "P")
7982 (org-agenda-check-type t 'agenda 'timeline)
7983 (org-agenda-check-no-diary)
7984 (let* ((marker (or (org-get-at-bol 'org-marker)
7985 (org-agenda-error)))
7986 (buffer (marker-buffer marker))
7987 (pos (marker-position marker)))
7988 (org-with-remote-undo buffer
7989 (with-current-buffer buffer
7990 (widen)
7991 (goto-char pos)
7992 (if (not (org-at-timestamp-p t))
7993 (error "Cannot find time stamp"))
7994 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7995 (org-agenda-show-new-time marker org-last-changed-timestamp))
7996 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7998 (defun org-agenda-schedule (arg &optional time)
7999 "Schedule the item at point.
8000 ARG is passed through to `org-schedule'."
8001 (interactive "P")
8002 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8003 (org-agenda-check-no-diary)
8004 (let* ((marker (or (org-get-at-bol 'org-marker)
8005 (org-agenda-error)))
8006 (type (marker-insertion-type marker))
8007 (buffer (marker-buffer marker))
8008 (pos (marker-position marker))
8009 (org-insert-labeled-timestamps-at-point nil)
8011 (set-marker-insertion-type marker t)
8012 (org-with-remote-undo buffer
8013 (with-current-buffer buffer
8014 (widen)
8015 (goto-char pos)
8016 (setq ts (org-schedule arg time)))
8017 (org-agenda-show-new-time marker ts "S"))
8018 (message "Item scheduled for %s" ts)))
8020 (defun org-agenda-deadline (arg &optional time)
8021 "Schedule the item at point.
8022 ARG is passed through to `org-deadline'."
8023 (interactive "P")
8024 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8025 (org-agenda-check-no-diary)
8026 (let* ((marker (or (org-get-at-bol 'org-marker)
8027 (org-agenda-error)))
8028 (buffer (marker-buffer marker))
8029 (pos (marker-position marker))
8030 (org-insert-labeled-timestamps-at-point nil)
8032 (org-with-remote-undo buffer
8033 (with-current-buffer buffer
8034 (widen)
8035 (goto-char pos)
8036 (setq ts (org-deadline arg time)))
8037 (org-agenda-show-new-time marker ts "D"))
8038 (message "Deadline for this item set to %s" ts)))
8040 (defun org-agenda-action ()
8041 "Select entry for agenda action, or execute an agenda action.
8042 This command prompts for another letter. Valid inputs are:
8044 m Mark the entry at point for an agenda action
8045 s Schedule the marked entry to the date at the cursor
8046 d Set the deadline of the marked entry to the date at the cursor
8047 r Call `org-remember' with cursor date as the default date
8048 c Call `org-capture' with cursor date as the default date
8049 SPC Show marked entry in other window
8050 TAB Visit marked entry in other window
8052 The cursor may be at a date in the calendar, or in the Org agenda."
8053 (interactive)
8054 (let (ans)
8055 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8056 (setq ans (read-char-exclusive))
8057 (cond
8058 ((equal ans ?m)
8059 ;; Mark this entry
8060 (if (eq major-mode 'org-agenda-mode)
8061 (let ((m (or (org-get-at-bol 'org-hd-marker)
8062 (org-get-at-bol 'org-marker))))
8063 (if m
8064 (progn
8065 (move-marker org-agenda-action-marker
8066 (marker-position m) (marker-buffer m))
8067 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8068 (error "Don't know which entry to mark")))
8069 (error "This command works only in the agenda")))
8070 ((equal ans ?s)
8071 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8072 ((equal ans ?d)
8073 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8074 ((equal ans ?r)
8075 (org-agenda-do-action '(org-remember) t))
8076 ((equal ans ?c)
8077 (org-agenda-do-action '(org-capture) t))
8078 ((equal ans ?\ )
8079 (let ((cw (selected-window)))
8080 (org-switch-to-buffer-other-window
8081 (marker-buffer org-agenda-action-marker))
8082 (goto-char org-agenda-action-marker)
8083 (org-show-context 'agenda)
8084 (select-window cw)))
8085 ((equal ans ?\C-i)
8086 (org-switch-to-buffer-other-window
8087 (marker-buffer org-agenda-action-marker))
8088 (goto-char org-agenda-action-marker)
8089 (org-show-context 'agenda))
8090 (t (error "Invalid agenda action %c" ans)))))
8092 (defun org-agenda-do-action (form &optional current-buffer)
8093 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8094 (let ((org-overriding-default-time (org-get-cursor-date)))
8095 (if current-buffer
8096 (eval form)
8097 (if (not (marker-buffer org-agenda-action-marker))
8098 (error "No entry has been selected for agenda action")
8099 (with-current-buffer (marker-buffer org-agenda-action-marker)
8100 (save-excursion
8101 (save-restriction
8102 (widen)
8103 (goto-char org-agenda-action-marker)
8104 (eval form))))))))
8106 (defun org-agenda-clock-in (&optional arg)
8107 "Start the clock on the currently selected item."
8108 (interactive "P")
8109 (org-agenda-check-no-diary)
8110 (if (equal arg '(4))
8111 (org-clock-in arg)
8112 (let* ((marker (or (org-get-at-bol 'org-marker)
8113 (org-agenda-error)))
8114 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8115 marker))
8116 (pos (marker-position marker))
8117 newhead)
8118 (org-with-remote-undo (marker-buffer marker)
8119 (with-current-buffer (marker-buffer marker)
8120 (widen)
8121 (goto-char pos)
8122 (org-show-context 'agenda)
8123 (org-show-entry)
8124 (org-cycle-hide-drawers 'children)
8125 (org-clock-in arg)
8126 (setq newhead (org-get-heading)))
8127 (org-agenda-change-all-lines newhead hdmarker)))))
8129 (defun org-agenda-clock-out ()
8130 "Stop the currently running clock."
8131 (interactive)
8132 (unless (marker-buffer org-clock-marker)
8133 (error "No running clock"))
8134 (let ((marker (make-marker)) newhead)
8135 (org-with-remote-undo (marker-buffer org-clock-marker)
8136 (with-current-buffer (marker-buffer org-clock-marker)
8137 (save-excursion
8138 (save-restriction
8139 (widen)
8140 (goto-char org-clock-marker)
8141 (org-back-to-heading t)
8142 (move-marker marker (point))
8143 (org-clock-out)
8144 (setq newhead (org-get-heading))))))
8145 (org-agenda-change-all-lines newhead marker)
8146 (move-marker marker nil)))
8148 (defun org-agenda-clock-cancel (&optional arg)
8149 "Cancel the currently running clock."
8150 (interactive "P")
8151 (unless (marker-buffer org-clock-marker)
8152 (error "No running clock"))
8153 (org-with-remote-undo (marker-buffer org-clock-marker)
8154 (org-clock-cancel)))
8156 (defun org-agenda-clock-goto ()
8157 "Jump to the currently clocked in task within the agenda.
8158 If the currently clocked in task is not listed in the agenda
8159 buffer, display it in another window."
8160 (interactive)
8161 (let (pos)
8162 (mapc (lambda (o)
8163 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8164 (setq pos (overlay-start o))))
8165 (overlays-in (point-min) (point-max)))
8166 (cond (pos (goto-char pos))
8167 ;; If the currently clocked entry is not in the agenda
8168 ;; buffer, we visit it in another window:
8169 (org-clock-current-task
8170 (org-switch-to-buffer-other-window (org-clock-goto)))
8171 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8173 (defun org-agenda-diary-entry-in-org-file ()
8174 "Make a diary entry in the file `org-agenda-diary-file'."
8175 (let (d1 d2 char (text "") dp1 dp2)
8176 (if (equal (buffer-name) "*Calendar*")
8177 (setq d1 (calendar-cursor-to-date t)
8178 d2 (car calendar-mark-ring))
8179 (setq dp1 (get-text-property (point-at-bol) 'day))
8180 (unless dp1 (error "No date defined in current line"))
8181 (setq d1 (calendar-gregorian-from-absolute dp1)
8182 d2 (and (ignore-errors (mark))
8183 (save-excursion
8184 (goto-char (mark))
8185 (setq dp2 (get-text-property (point-at-bol) 'day)))
8186 (calendar-gregorian-from-absolute dp2))))
8187 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8188 (setq char (read-char-exclusive))
8189 (cond
8190 ((equal char ?d)
8191 (setq text (read-string "Day entry: "))
8192 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8193 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8194 ((equal char ?a)
8195 (setq d1 (list (car d1) (nth 1 d1)
8196 (read-number (format "Reference year [%d]: " (nth 2 d1))
8197 (nth 2 d1))))
8198 (setq text (read-string "Anniversary (use %d to show years): "))
8199 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8200 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8201 ((equal char ?b)
8202 (setq text (read-string "Block entry: "))
8203 (unless (and d1 d2 (not (equal d1 d2)))
8204 (error "No block of days selected"))
8205 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8206 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8207 ((equal char ?j)
8208 (org-switch-to-buffer-other-window
8209 (find-file-noselect org-agenda-diary-file))
8210 (require 'org-datetree)
8211 (org-datetree-find-date-create d1)
8212 (org-reveal t))
8213 (t (error "Invalid selection character `%c'" char)))))
8215 (defcustom org-agenda-insert-diary-strategy 'date-tree
8216 "Where in `org-agenda-diary-file' should new entries be added?
8217 Valid values:
8219 date-tree in the date tree, as child of the date
8220 top-level as top-level entries at the end of the file."
8221 :group 'org-agenda
8222 :type '(choice
8223 (const :tag "in a date tree" date-tree)
8224 (const :tag "as top level at end of file" top-level)))
8226 (defcustom org-agenda-insert-diary-extract-time nil
8227 "Non-nil means extract any time specification from the diary entry."
8228 :group 'org-agenda
8229 :version "24.1"
8230 :type 'boolean)
8232 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8233 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8234 If TEXT is not empty, it will become the headline of the new entry, and
8235 the resulting entry will not be shown. When TEXT is empty, switch to
8236 `org-agenda-diary-file' and let the user finish the entry there."
8237 (let ((cw (current-window-configuration)))
8238 (org-switch-to-buffer-other-window
8239 (find-file-noselect org-agenda-diary-file))
8240 (widen)
8241 (goto-char (point-min))
8242 (cond
8243 ((eq type 'anniversary)
8244 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8245 (progn
8246 (or (org-at-heading-p t)
8247 (progn
8248 (outline-next-heading)
8249 (insert "* Anniversaries\n\n")
8250 (beginning-of-line -1)))))
8251 (outline-next-heading)
8252 (org-back-over-empty-lines)
8253 (backward-char 1)
8254 (insert "\n")
8255 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8256 (nth 2 d1) (car d1) (nth 1 d1) text)))
8257 ((eq type 'day)
8258 (let ((org-prefix-has-time t)
8259 (org-agenda-time-leading-zero t)
8260 fmt time time2)
8261 (if org-agenda-insert-diary-extract-time
8262 ;; Use org-agenda-format-item to parse text for a time-range and
8263 ;; remove it. FIXME: This is a hack, we should refactor
8264 ;; that function to make time extraction available separately
8265 (setq fmt (org-agenda-format-item nil text nil nil t)
8266 time (get-text-property 0 'time fmt)
8267 time2 (if (> (length time) 0)
8268 ;; split-string removes trailing ...... if
8269 ;; no end time given. First space
8270 ;; separates time from date.
8271 (concat " " (car (split-string time "\\.")))
8272 nil)
8273 text (get-text-property 0 'txt fmt)))
8274 (if (eq org-agenda-insert-diary-strategy 'top-level)
8275 (org-agenda-insert-diary-as-top-level text)
8276 (require 'org-datetree)
8277 (org-datetree-find-date-create d1)
8278 (org-agenda-insert-diary-make-new-entry text))
8279 (org-insert-time-stamp (org-time-from-absolute
8280 (calendar-absolute-from-gregorian d1))
8281 nil nil nil nil time2))
8282 (end-of-line 0))
8283 ((eq type 'block)
8284 (if (> (calendar-absolute-from-gregorian d1)
8285 (calendar-absolute-from-gregorian d2))
8286 (setq d1 (prog1 d2 (setq d2 d1))))
8287 (if (eq org-agenda-insert-diary-strategy 'top-level)
8288 (org-agenda-insert-diary-as-top-level text)
8289 (require 'org-datetree)
8290 (org-datetree-find-date-create d1)
8291 (org-agenda-insert-diary-make-new-entry text))
8292 (org-insert-time-stamp (org-time-from-absolute
8293 (calendar-absolute-from-gregorian d1)))
8294 (insert "--")
8295 (org-insert-time-stamp (org-time-from-absolute
8296 (calendar-absolute-from-gregorian d2)))
8297 (end-of-line 0)))
8298 (if (string-match "\\S-" text)
8299 (progn
8300 (set-window-configuration cw)
8301 (message "%s entry added to %s"
8302 (capitalize (symbol-name type))
8303 (abbreviate-file-name org-agenda-diary-file)))
8304 (org-reveal t)
8305 (message "Please finish entry here"))))
8307 (defun org-agenda-insert-diary-as-top-level (text)
8308 "Make new entry as a top-level entry at the end of the file.
8309 Add TEXT as headline, and position the cursor in the second line so that
8310 a timestamp can be added there."
8311 (widen)
8312 (goto-char (point-max))
8313 (or (bolp) (insert "\n"))
8314 (insert "* " text "\n")
8315 (if org-adapt-indentation (org-indent-to-column 2)))
8317 (defun org-agenda-insert-diary-make-new-entry (text)
8318 "Make new entry as last child of current entry.
8319 Add TEXT as headline, and position the cursor in the second line so that
8320 a timestamp can be added there."
8321 (let ((org-show-following-heading t)
8322 (org-show-siblings t)
8323 (org-show-hierarchy-above t)
8324 (org-show-entry-below t)
8325 col)
8326 (outline-next-heading)
8327 (org-back-over-empty-lines)
8328 (or (looking-at "[ \t]*$")
8329 (progn (insert "\n") (backward-char 1)))
8330 (org-insert-heading nil t)
8331 (org-do-demote)
8332 (setq col (current-column))
8333 (insert text "\n")
8334 (if org-adapt-indentation (org-indent-to-column col))
8335 (let ((org-show-following-heading t)
8336 (org-show-siblings t)
8337 (org-show-hierarchy-above t)
8338 (org-show-entry-below t))
8339 (org-show-context))))
8341 (defun org-agenda-diary-entry ()
8342 "Make a diary entry, like the `i' command from the calendar.
8343 All the standard commands work: block, weekly etc.
8344 When `org-agenda-diary-file' points to a file,
8345 `org-agenda-diary-entry-in-org-file' is called instead to create
8346 entries in that Org-mode file."
8347 (interactive)
8348 (org-agenda-check-type t 'agenda 'timeline)
8349 (if (not (eq org-agenda-diary-file 'diary-file))
8350 (org-agenda-diary-entry-in-org-file)
8351 (require 'diary-lib)
8352 (let* ((char (progn
8353 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8354 (read-char-exclusive)))
8355 (cmd (cdr (assoc char
8356 '((?d . insert-diary-entry)
8357 (?w . insert-weekly-diary-entry)
8358 (?m . insert-monthly-diary-entry)
8359 (?y . insert-yearly-diary-entry)
8360 (?a . insert-anniversary-diary-entry)
8361 (?b . insert-block-diary-entry)
8362 (?c . insert-cyclic-diary-entry)))))
8363 (oldf (symbol-function 'calendar-cursor-to-date))
8364 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8365 (point (point))
8366 (mark (or (mark t) (point))))
8367 (unless cmd
8368 (error "No command associated with <%c>" char))
8369 (unless (and (get-text-property point 'day)
8370 (or (not (equal ?b char))
8371 (get-text-property mark 'day)))
8372 (error "Don't know which date to use for diary entry"))
8373 ;; We implement this by hacking the `calendar-cursor-to-date' function
8374 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8375 (let ((calendar-mark-ring
8376 (list (calendar-gregorian-from-absolute
8377 (or (get-text-property mark 'day)
8378 (get-text-property point 'day))))))
8379 (unwind-protect
8380 (progn
8381 (fset 'calendar-cursor-to-date
8382 (lambda (&optional error dummy)
8383 (calendar-gregorian-from-absolute
8384 (get-text-property point 'day))))
8385 (call-interactively cmd))
8386 (fset 'calendar-cursor-to-date oldf))))))
8388 (defun org-agenda-execute-calendar-command (cmd)
8389 "Execute a calendar command from the agenda, with the date associated to
8390 the cursor position."
8391 (org-agenda-check-type t 'agenda 'timeline)
8392 (require 'diary-lib)
8393 (unless (get-text-property (point) 'day)
8394 (error "Don't know which date to use for calendar command"))
8395 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8396 (point (point))
8397 (date (calendar-gregorian-from-absolute
8398 (get-text-property point 'day)))
8399 ;; the following 2 vars are needed in the calendar
8400 (displayed-month (car date))
8401 (displayed-year (nth 2 date)))
8402 (unwind-protect
8403 (progn
8404 (fset 'calendar-cursor-to-date
8405 (lambda (&optional error dummy)
8406 (calendar-gregorian-from-absolute
8407 (get-text-property point 'day))))
8408 (call-interactively cmd))
8409 (fset 'calendar-cursor-to-date oldf))))
8411 (defun org-agenda-phases-of-moon ()
8412 "Display the phases of the moon for the 3 months around the cursor date."
8413 (interactive)
8414 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8416 (defun org-agenda-holidays ()
8417 "Display the holidays for the 3 months around the cursor date."
8418 (interactive)
8419 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8421 (defvar calendar-longitude)
8422 (defvar calendar-latitude)
8423 (defvar calendar-location-name)
8425 (defun org-agenda-sunrise-sunset (arg)
8426 "Display sunrise and sunset for the cursor date.
8427 Latitude and longitude can be specified with the variables
8428 `calendar-latitude' and `calendar-longitude'. When called with prefix
8429 argument, latitude and longitude will be prompted for."
8430 (interactive "P")
8431 (require 'solar)
8432 (let ((calendar-longitude (if arg nil calendar-longitude))
8433 (calendar-latitude (if arg nil calendar-latitude))
8434 (calendar-location-name
8435 (if arg "the given coordinates" calendar-location-name)))
8436 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8438 (defun org-agenda-goto-calendar ()
8439 "Open the Emacs calendar with the date at the cursor."
8440 (interactive)
8441 (org-agenda-check-type t 'agenda 'timeline)
8442 (let* ((day (or (get-text-property (point) 'day)
8443 (error "Don't know which date to open in calendar")))
8444 (date (calendar-gregorian-from-absolute day))
8445 (calendar-move-hook nil)
8446 (calendar-view-holidays-initially-flag nil)
8447 (calendar-view-diary-initially-flag nil))
8448 (calendar)
8449 (calendar-goto-date date)))
8451 ;;;###autoload
8452 (defun org-calendar-goto-agenda ()
8453 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8454 This is a command that has to be installed in `calendar-mode-map'."
8455 (interactive)
8456 (org-agenda-list nil (calendar-absolute-from-gregorian
8457 (calendar-cursor-to-date))
8458 nil))
8460 (defun org-agenda-convert-date ()
8461 (interactive)
8462 (org-agenda-check-type t 'agenda 'timeline)
8463 (let ((day (get-text-property (point) 'day))
8464 date s)
8465 (unless day
8466 (error "Don't know which date to convert"))
8467 (setq date (calendar-gregorian-from-absolute day))
8468 (setq s (concat
8469 "Gregorian: " (calendar-date-string date) "\n"
8470 "ISO: " (calendar-iso-date-string date) "\n"
8471 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8472 "Julian: " (calendar-julian-date-string date) "\n"
8473 "Astron. JD: " (calendar-astro-date-string date)
8474 " (Julian date number at noon UTC)\n"
8475 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8476 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8477 "French: " (calendar-french-date-string date) "\n"
8478 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8479 "Mayan: " (calendar-mayan-date-string date) "\n"
8480 "Coptic: " (calendar-coptic-date-string date) "\n"
8481 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8482 "Persian: " (calendar-persian-date-string date) "\n"
8483 "Chinese: " (calendar-chinese-date-string date) "\n"))
8484 (with-output-to-temp-buffer "*Dates*"
8485 (princ s))
8486 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8488 ;;; Bulk commands
8490 (defvar org-agenda-bulk-marked-entries nil
8491 "List of markers that refer to marked entries in the agenda.")
8493 (defun org-agenda-bulk-marked-p ()
8494 (eq (get-char-property (point-at-bol) 'type)
8495 'org-marked-entry-overlay))
8497 (defun org-agenda-bulk-mark (&optional arg)
8498 "Mark the entry at point for future bulk action."
8499 (interactive "p")
8500 (dotimes (i (max arg 1))
8501 (unless (org-get-at-bol 'org-agenda-diary-link)
8502 (let* ((m (org-get-at-bol 'org-hd-marker))
8504 (unless (org-agenda-bulk-marked-p)
8505 (unless m (error "Nothing to mark at point"))
8506 (push m org-agenda-bulk-marked-entries)
8507 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8508 (org-overlay-display ov "> "
8509 (org-get-todo-face "TODO")
8510 'evaporate)
8511 (overlay-put ov 'type 'org-marked-entry-overlay))
8512 (beginning-of-line 2)
8513 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8514 (beginning-of-line 2))
8515 (message "%d entries marked for bulk action"
8516 (length org-agenda-bulk-marked-entries))))))
8518 (defun org-agenda-bulk-mark-regexp (regexp)
8519 "Mark entries match REGEXP."
8520 (interactive "sMark entries matching regexp: ")
8521 (let (entries-marked)
8522 (save-excursion
8523 (goto-char (point-min))
8524 (goto-char (next-single-property-change (point) 'txt))
8525 (while (re-search-forward regexp nil t)
8526 (when (string-match regexp (get-text-property (point) 'txt))
8527 (setq entries-marked (+ entries-marked 1))
8528 (call-interactively 'org-agenda-bulk-mark))))
8529 (if (not entries-marked)
8530 (message "No entry matching this regexp."))))
8532 (defun org-agenda-bulk-unmark ()
8533 "Unmark the entry at point for future bulk action."
8534 (interactive)
8535 (when (org-agenda-bulk-marked-p)
8536 (org-agenda-bulk-remove-overlays
8537 (point-at-bol) (+ 2 (point-at-bol)))
8538 (setq org-agenda-bulk-marked-entries
8539 (delete (org-get-at-bol 'org-hd-marker)
8540 org-agenda-bulk-marked-entries)))
8541 (beginning-of-line 2)
8542 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8543 (beginning-of-line 2))
8544 (message "%d entries marked for bulk action"
8545 (length org-agenda-bulk-marked-entries)))
8547 (defun org-agenda-bulk-toggle ()
8548 "Toggle marking the entry at point for bulk action."
8549 (interactive)
8550 (if (org-agenda-bulk-marked-p)
8551 (org-agenda-bulk-unmark)
8552 (org-agenda-bulk-mark)))
8554 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8555 "Remove the mark overlays between BEG and END in the agenda buffer.
8556 BEG and END default to the buffer limits.
8558 This only removes the overlays, it does not remove the markers
8559 from the list in `org-agenda-bulk-marked-entries'."
8560 (interactive)
8561 (mapc (lambda (ov)
8562 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8563 (delete-overlay ov)))
8564 (overlays-in (or beg (point-min)) (or end (point-max)))))
8566 (defun org-agenda-bulk-remove-all-marks ()
8567 "Remove all marks in the agenda buffer.
8568 This will remove the markers, and the overlays."
8569 (interactive)
8570 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8571 (setq org-agenda-bulk-marked-entries nil)
8572 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
8574 (defun org-agenda-bulk-action (&optional arg)
8575 "Execute an remote-editing action on all marked entries.
8576 The prefix arg is passed through to the command if possible."
8577 (interactive "P")
8578 ;; Make sure we have markers, and only valid ones
8579 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8580 (mapc
8581 (lambda (m)
8582 (unless (and (markerp m)
8583 (marker-buffer m)
8584 (buffer-live-p (marker-buffer m))
8585 (marker-position m))
8586 (error "Marker %s for bulk command is invalid" m)))
8587 org-agenda-bulk-marked-entries)
8589 ;; Prompt for the bulk command
8590 (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
8591 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
8592 (when org-agenda-bulk-custom-functions
8593 (concat " Custom: ["
8594 (mapconcat (lambda(f) (char-to-string (car f)))
8595 org-agenda-bulk-custom-functions "")
8596 "]"))))
8597 (let* ((action (read-char-exclusive))
8598 (org-log-refile (if org-log-refile 'time nil))
8599 (entries (reverse org-agenda-bulk-marked-entries))
8600 redo-at-end
8601 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8602 (cond
8603 ((equal action ?$)
8604 (setq cmd '(org-agenda-archive)))
8606 ((equal action ?A)
8607 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8609 ((member action '(?r ?w))
8610 (setq rfloc (org-refile-get-location
8611 "Refile to"
8612 (marker-buffer (car org-agenda-bulk-marked-entries))
8613 org-refile-allow-creating-parent-nodes))
8614 (if (nth 3 rfloc)
8615 (setcar (nthcdr 3 rfloc)
8616 (move-marker (make-marker) (nth 3 rfloc)
8617 (or (get-file-buffer (nth 1 rfloc))
8618 (find-buffer-visiting (nth 1 rfloc))
8619 (error "This should not happen")))))
8621 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8622 redo-at-end t))
8624 ((equal action ?t)
8625 (setq state (org-icompleting-read
8626 "Todo state: "
8627 (with-current-buffer (marker-buffer (car entries))
8628 (mapcar 'list org-todo-keywords-1))))
8629 (setq cmd `(let ((org-inhibit-blocking t)
8630 (org-inhibit-logging 'note))
8631 (org-agenda-todo ,state))))
8633 ((memq action '(?- ?+))
8634 (setq tag (org-icompleting-read
8635 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8636 (with-current-buffer (marker-buffer (car entries))
8637 (delq nil
8638 (mapcar (lambda (x)
8639 (if (stringp (car x)) x)) org-tag-alist)))))
8640 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8642 ((memq action '(?s ?d))
8643 (let* ((date (unless arg
8644 (org-read-date
8645 nil nil nil
8646 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8647 (ans (if arg nil org-read-date-final-answer))
8648 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8649 (setq cmd `(let* ((bound (fboundp 'read-string))
8650 (old (and bound (symbol-function 'read-string))))
8651 (unwind-protect
8652 (progn
8653 (fset 'read-string (lambda (&rest ignore) ,ans))
8654 (eval '(,c1 arg)))
8655 (if bound
8656 (fset 'read-string old)
8657 (fmakunbound 'read-string)))))))
8659 ((equal action ?S)
8660 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8661 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8662 (let ((days (read-number
8663 (format "Scatter tasks across how many %sdays: "
8664 (if arg "week" "")) 7)))
8665 (setq cmd
8666 `(let ((distance (1+ (random ,days))))
8667 (if arg
8668 (let ((dist distance)
8669 (day-of-week
8670 (calendar-day-of-week
8671 (calendar-gregorian-from-absolute (org-today)))))
8672 (dotimes (i (1+ dist))
8673 (while (member day-of-week org-agenda-weekend-days)
8674 (incf distance)
8675 (incf day-of-week)
8676 (if (= day-of-week 7)
8677 (setq day-of-week 0)))
8678 (incf day-of-week)
8679 (if (= day-of-week 7)
8680 (setq day-of-week 0)))))
8681 ;; silently fail when try to replan a sexp entry
8682 (condition-case nil
8683 (let* ((date (calendar-gregorian-from-absolute
8684 (+ (org-today) distance)))
8685 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8686 (nth 2 date))))
8687 (org-agenda-schedule nil time))
8688 (error nil)))))))
8690 ((assoc action org-agenda-bulk-custom-functions)
8691 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8692 redo-at-end t))
8694 ((equal action ?f)
8695 (setq cmd (list (intern
8696 (org-icompleting-read "Function: "
8697 obarray 'fboundp t nil nil)))))
8699 (t (error "Invalid bulk action")))
8701 ;; Sort the markers, to make sure that parents are handled before children
8702 (setq entries (sort entries
8703 (lambda (a b)
8704 (cond
8705 ((equal (marker-buffer a) (marker-buffer b))
8706 (< (marker-position a) (marker-position b)))
8708 (string< (buffer-name (marker-buffer a))
8709 (buffer-name (marker-buffer b))))))))
8711 ;; Now loop over all markers and apply cmd
8712 (while (setq e (pop entries))
8713 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8714 (if (not pos)
8715 (progn (message "Skipping removed entry at %s" e)
8716 (setq cntskip (1+ cntskip)))
8717 (goto-char pos)
8718 (let (org-loop-over-headlines-in-active-region)
8719 (eval cmd))
8720 (setq org-agenda-bulk-marked-entries
8721 (delete e org-agenda-bulk-marked-entries))
8722 (setq cnt (1+ cnt))))
8723 (setq org-agenda-bulk-marked-entries nil)
8724 (org-agenda-bulk-remove-all-marks)
8725 (when redo-at-end (org-agenda-redo))
8726 (message "Acted on %d entries%s"
8728 (if (= cntskip 0)
8730 (format ", skipped %d (disappeared before their turn)"
8731 cntskip)))))
8733 ;;; Flagging notes
8735 (defun org-agenda-show-the-flagging-note ()
8736 "Display the flagging note in the other window.
8737 When called a second time in direct sequence, offer to remove the FLAGGING
8738 tag and (if present) the flagging note."
8739 (interactive)
8740 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8741 (win (selected-window))
8742 note heading newhead)
8743 (unless hdmarker
8744 (error "No linked entry at point"))
8745 (if (and (eq this-command last-command)
8746 (y-or-n-p "Unflag and remove any flagging note? "))
8747 (progn
8748 (org-agenda-remove-flag hdmarker)
8749 (let ((win (get-buffer-window "*Flagging Note*")))
8750 (and win (delete-window win)))
8751 (message "Entry unflagged"))
8752 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8753 (unless note
8754 (error "No flagging note"))
8755 (org-kill-new note)
8756 (org-switch-to-buffer-other-window "*Flagging Note*")
8757 (erase-buffer)
8758 (insert note)
8759 (goto-char (point-min))
8760 (while (re-search-forward "\\\\n" nil t)
8761 (replace-match "\n" t t))
8762 (goto-char (point-min))
8763 (select-window win)
8764 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8766 (defun org-agenda-remove-flag (marker)
8767 "Remove the FLAGGED tag and any flagging note in the entry."
8768 (let (newhead)
8769 (org-with-point-at marker
8770 (org-toggle-tag "FLAGGED" 'off)
8771 (org-entry-delete nil "THEFLAGGINGNOTE")
8772 (setq newhead (org-get-heading)))
8773 (org-agenda-change-all-lines newhead marker)
8774 (message "Entry unflagged")))
8776 (defun org-agenda-get-any-marker (&optional pos)
8777 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8778 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8780 ;;; Appointment reminders
8782 (defvar appt-time-msg-list)
8784 ;;;###autoload
8785 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8786 "Activate appointments found in `org-agenda-files'.
8787 With a \\[universal-argument] prefix, refresh the list of
8788 appointments.
8790 If FILTER is t, interactively prompt the user for a regular
8791 expression, and filter out entries that don't match it.
8793 If FILTER is a string, use this string as a regular expression
8794 for filtering entries out.
8796 If FILTER is a function, filter out entries against which
8797 calling the function returns nil. This function takes one
8798 argument: an entry from `org-agenda-get-day-entries'.
8800 FILTER can also be an alist with the car of each cell being
8801 either 'headline or 'category. For example:
8803 '((headline \"IMPORTANT\")
8804 (category \"Work\"))
8806 will only add headlines containing IMPORTANT or headlines
8807 belonging to the \"Work\" category.
8809 ARGS are symbols indicating what kind of entries to consider.
8810 By default `org-agenda-to-appt' will use :deadline, :scheduled
8811 and :timestamp entries. See the docstring of `org-diary' for
8812 details and examples."
8813 (interactive "P")
8814 (if refresh (setq appt-time-msg-list nil))
8815 (if (eq filter t)
8816 (setq filter (read-from-minibuffer "Regexp filter: ")))
8817 (let* ((cnt 0) ; count added events
8818 (scope (or args '(:deadline :scheduled :timestamp)))
8819 (org-agenda-new-buffers nil)
8820 (org-deadline-warning-days 0)
8821 ;; Do not use `org-today' here because appt only takes
8822 ;; time and without date as argument, so it may pass wrong
8823 ;; information otherwise
8824 (today (org-date-to-gregorian
8825 (time-to-days (current-time))))
8826 (org-agenda-restrict nil)
8827 (files (org-agenda-files 'unrestricted)) entries file)
8828 ;; Get all entries which may contain an appt
8829 (org-prepare-agenda-buffers files)
8830 (while (setq file (pop files))
8831 (setq entries
8832 (delq nil
8833 (append entries
8834 (apply 'org-agenda-get-day-entries
8835 file today scope)))))
8836 ;; Map thru entries and find if we should filter them out
8837 (mapc
8838 (lambda(x)
8839 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8840 (cat (get-text-property 1 'org-category x))
8841 (tod (get-text-property 1 'time-of-day x))
8842 (ok (or (null filter)
8843 (and (stringp filter) (string-match filter evt))
8844 (and (functionp filter) (funcall filter x))
8845 (and (listp filter)
8846 (let ((cat-filter (cadr (assoc 'category filter)))
8847 (evt-filter (cadr (assoc 'headline filter))))
8848 (or (and (stringp cat-filter)
8849 (string-match cat-filter cat))
8850 (and (stringp evt-filter)
8851 (string-match evt-filter evt))))))))
8852 ;; FIXME: Shall we remove text-properties for the appt text?
8853 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8854 (when (and ok tod)
8855 (setq tod (concat "00" (number-to-string tod))
8856 tod (when (string-match
8857 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8858 (concat (match-string 1 tod) ":"
8859 (match-string 2 tod))))
8860 (appt-add tod evt)
8861 (setq cnt (1+ cnt))))) entries)
8862 (org-release-buffers org-agenda-new-buffers)
8863 (if (eq cnt 0)
8864 (message "No event to add")
8865 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8867 (defun org-agenda-todayp (date)
8868 "Does DATE mean today, when considering `org-extend-today-until'?"
8869 (let ((today (org-today))
8870 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8871 date)))
8872 (eq date today)))
8874 (defun org-agenda-todo-yesterday (&optional arg)
8875 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
8876 (interactive "P")
8877 (let* ((hour (third (decode-time
8878 (org-current-time))))
8879 (org-extend-today-until (1+ hour)))
8880 (org-agenda-todo arg)))
8882 (provide 'org-agenda)
8884 ;;; org-agenda.el ends here