Update copyright notices for 2013.
[emacs.git] / lisp / org / org-agenda.el
blobe6e6166ffe2893a6030de45277b140043c692787
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 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 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
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 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags to not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-tags-todo-honor-ignore-options nil
744 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
745 The variables
746 `org-agenda-todo-ignore-with-date',
747 `org-agenda-todo-ignore-timestamp',
748 `org-agenda-todo-ignore-scheduled',
749 `org-agenda-todo-ignore-deadlines'
750 make the global TODO list skip entries that have time stamps of certain
751 kinds. If this option is set, the same options will also apply for the
752 tags-todo search, which is the general tags/property matcher
753 restricted to unfinished TODO entries only."
754 :group 'org-agenda-skip
755 :group 'org-agenda-todo-list
756 :group 'org-agenda-match-view
757 :type 'boolean)
759 (defcustom org-agenda-skip-scheduled-if-done nil
760 "Non-nil means don't show scheduled items in agenda when they are done.
761 This is relevant for the daily/weekly agenda, not for the TODO list. And
762 it applies only to the actual date of the scheduling. Warnings about
763 an item with a past scheduling dates are always turned off when the item
764 is DONE."
765 :group 'org-agenda-skip
766 :group 'org-agenda-daily/weekly
767 :type 'boolean)
769 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
770 "Non-nil means skip scheduling line if same entry shows because of deadline.
771 In the agenda of today, an entry can show up multiple times because
772 it is both scheduled and has a nearby deadline, and maybe a plain time
773 stamp as well.
774 When this variable is t, then only the deadline is shown and the fact that
775 the entry is scheduled today or was scheduled previously is not shown.
776 When this variable is nil, the entry will be shown several times. When
777 the variable is the symbol `not-today', then skip scheduled previously,
778 but not scheduled today."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type '(choice
782 (const :tag "Never" nil)
783 (const :tag "Always" t)
784 (const :tag "Not when scheduled today" not-today)))
786 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
787 "Non-nil means skip timestamp line if same entry shows because of deadline.
788 In the agenda of today, an entry can show up multiple times
789 because it has both a plain timestamp and has a nearby deadline.
790 When this variable is t, then only the deadline is shown and the
791 fact that the entry has a timestamp for or including today is not
792 shown. When this variable is nil, the entry will be shown
793 several times."
794 :group 'org-agenda-skip
795 :group 'org-agenda-daily/weekly
796 :version "24.1"
797 :type '(choice
798 (const :tag "Never" nil)
799 (const :tag "Always" t)))
801 (defcustom org-agenda-skip-deadline-if-done nil
802 "Non-nil means don't show deadlines when the corresponding item is done.
803 When nil, the deadline is still shown and should give you a happy feeling.
804 This is relevant for the daily/weekly agenda. And it applied only to the
805 actually date of the deadline. Warnings about approaching and past-due
806 deadlines are always turned off when the item is DONE."
807 :group 'org-agenda-skip
808 :group 'org-agenda-daily/weekly
809 :type 'boolean)
811 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
812 "Non-nil means skip deadline prewarning when entry is also scheduled.
813 This will apply on all days where a prewarning for the deadline would
814 be shown, but not at the day when the entry is actually due. On that day,
815 the deadline will be shown anyway.
816 This variable may be set to nil, t, or a number which will then give
817 the number of days before the actual deadline when the prewarnings
818 should resume.
819 This can be used in a workflow where the first showing of the deadline will
820 trigger you to schedule it, and then you don't want to be reminded of it
821 because you will take care of it on the day when scheduled."
822 :group 'org-agenda-skip
823 :group 'org-agenda-daily/weekly
824 :version "24.1"
825 :type '(choice
826 (const :tag "Always show prewarning" nil)
827 (const :tag "Remove prewarning if entry is scheduled" t)
828 (integer :tag "Restart prewarning N days before deadline")))
830 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
831 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
832 When non-nil, after the search for timestamps has matched once in an
833 entry, the rest of the entry will not be searched."
834 :group 'org-agenda-skip
835 :type 'boolean)
837 (defcustom org-agenda-skip-timestamp-if-done nil
838 "Non-nil means don't select item by timestamp or -range if it is DONE."
839 :group 'org-agenda-skip
840 :group 'org-agenda-daily/weekly
841 :type 'boolean)
843 (defcustom org-agenda-dim-blocked-tasks t
844 "Non-nil means dim blocked tasks in the agenda display.
845 This causes some overhead during agenda construction, but if you
846 have turned on `org-enforce-todo-dependencies',
847 `org-enforce-todo-checkbox-dependencies', or any other blocking
848 mechanism, this will create useful feedback in the agenda.
850 Instead of t, this variable can also have the value `invisible'.
851 Then blocked tasks will be invisible and only become visible when
852 they become unblocked. An exemption to this behavior is when a task is
853 blocked because of unchecked checkboxes below it. Since checkboxes do
854 not show up in the agenda views, making this task invisible you remove any
855 trace from agenda views that there is something to do. Therefore, a task
856 that is blocked because of checkboxes will never be made invisible, it
857 will only be dimmed."
858 :group 'org-agenda-daily/weekly
859 :group 'org-agenda-todo-list
860 :type '(choice
861 (const :tag "Do not dim" nil)
862 (const :tag "Dim to a gray face" t)
863 (const :tag "Make invisible" invisible)))
865 (defcustom org-timeline-show-empty-dates 3
866 "Non-nil means `org-timeline' also shows dates without an entry.
867 When nil, only the days which actually have entries are shown.
868 When t, all days between the first and the last date are shown.
869 When an integer, show also empty dates, but if there is a gap of more than
870 N days, just insert a special line indicating the size of the gap."
871 :group 'org-agenda-skip
872 :type '(choice
873 (const :tag "None" nil)
874 (const :tag "All" t)
875 (integer :tag "at most")))
877 (defgroup org-agenda-startup nil
878 "Options concerning initial settings in the Agenda in Org Mode."
879 :tag "Org Agenda Startup"
880 :group 'org-agenda)
882 (defcustom org-agenda-menu-show-matcher t
883 "Non-nil means show the match string in the agenda dispatcher menu.
884 When nil, the matcher string is not shown, but is put into the help-echo
885 property so than moving the mouse over the command shows it.
886 Setting it to nil is good if matcher strings are very long and/or if
887 you want to use two-columns display (see `org-agenda-menu-two-columns')."
888 :group 'org-agenda
889 :version "24.1"
890 :type 'boolean)
892 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
894 (defcustom org-agenda-menu-two-columns nil
895 "Non-nil means, use two columns to show custom commands in the dispatcher.
896 If you use this, you probably want to set `org-agenda-menu-show-matcher'
897 to nil."
898 :group 'org-agenda
899 :version "24.1"
900 :type 'boolean)
902 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
903 (defcustom org-agenda-finalize-hook nil
904 "Hook run just before displaying an agenda buffer.
905 The buffer is still writable when the hook is called.
907 You can modify some of the buffer substrings but you should be
908 extra careful not to modify the text properties of the agenda
909 headlines as the agenda display heavily relies on them."
910 :group 'org-agenda-startup
911 :type 'hook)
913 (defcustom org-agenda-mouse-1-follows-link nil
914 "Non-nil means mouse-1 on a link will follow the link in the agenda.
915 A longer mouse click will still set point. Does not work on XEmacs.
916 Needs to be set before org.el is loaded."
917 :group 'org-agenda-startup
918 :type 'boolean)
920 (defcustom org-agenda-start-with-follow-mode nil
921 "The initial value of follow mode in a newly created agenda window."
922 :group 'org-agenda-startup
923 :type 'boolean)
925 (defcustom org-agenda-follow-indirect nil
926 "Non-nil means `org-agenda-follow-mode' displays only the
927 current item's tree, in an indirect buffer."
928 :group 'org-agenda
929 :version "24.1"
930 :type 'boolean)
932 (defcustom org-agenda-show-outline-path t
933 "Non-nil means show outline path in echo area after line motion."
934 :group 'org-agenda-startup
935 :type 'boolean)
937 (defcustom org-agenda-start-with-entry-text-mode nil
938 "The initial value of entry-text-mode in a newly created agenda window."
939 :group 'org-agenda-startup
940 :type 'boolean)
942 (defcustom org-agenda-entry-text-maxlines 5
943 "Number of text lines to be added when `E' is pressed in the agenda.
945 Note that this variable only used during agenda display. Add add entry text
946 when exporting the agenda, configure the variable
947 `org-agenda-add-entry-ext-maxlines'."
948 :group 'org-agenda
949 :type 'integer)
951 (defcustom org-agenda-entry-text-exclude-regexps nil
952 "List of regular expressions to clean up entry text.
953 The complete matches of all regular expressions in this list will be
954 removed from entry text before it is shown in the agenda."
955 :group 'org-agenda
956 :type '(repeat (regexp)))
958 (defvar org-agenda-entry-text-cleanup-hook nil
959 "Hook that is run after basic cleanup of entry text to be shown in agenda.
960 This cleanup is done in a temporary buffer, so the function may inspect and
961 change the entire buffer.
962 Some default stuff like drawers and scheduling/deadline dates will already
963 have been removed when this is called, as will any matches for regular
964 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
966 (defvar org-agenda-include-inactive-timestamps nil
967 "Non-nil means include inactive time stamps in agenda and timeline.
968 Dynamically scoped.")
970 (defgroup org-agenda-windows nil
971 "Options concerning the windows used by the Agenda in Org Mode."
972 :tag "Org Agenda Windows"
973 :group 'org-agenda)
975 (defcustom org-agenda-window-setup 'reorganize-frame
976 "How the agenda buffer should be displayed.
977 Possible values for this option are:
979 current-window Show agenda in the current window, keeping all other windows.
980 other-window Use `switch-to-buffer-other-window' to display agenda.
981 reorganize-frame Show only two windows on the current frame, the current
982 window and the agenda.
983 other-frame Use `switch-to-buffer-other-frame' to display agenda.
984 Also, when exiting the agenda, kill that frame.
985 See also the variable `org-agenda-restore-windows-after-quit'."
986 :group 'org-agenda-windows
987 :type '(choice
988 (const current-window)
989 (const other-frame)
990 (const other-window)
991 (const reorganize-frame)))
993 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
994 "The min and max height of the agenda window as a fraction of frame height.
995 The value of the variable is a cons cell with two numbers between 0 and 1.
996 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
997 :group 'org-agenda-windows
998 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1000 (defcustom org-agenda-restore-windows-after-quit nil
1001 "Non-nil means restore window configuration upon exiting agenda.
1002 Before the window configuration is changed for displaying the agenda,
1003 the current status is recorded. When the agenda is exited with
1004 `q' or `x' and this option is set, the old state is restored. If
1005 `org-agenda-window-setup' is `other-frame', the value of this
1006 option will be ignored."
1007 :group 'org-agenda-windows
1008 :type 'boolean)
1010 (defcustom org-agenda-ndays nil
1011 "Number of days to include in overview display.
1012 Should be 1 or 7.
1013 Obsolete, see `org-agenda-span'."
1014 :group 'org-agenda-daily/weekly
1015 :type 'integer)
1017 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1019 (defcustom org-agenda-span 'week
1020 "Number of days to include in overview display.
1021 Can be day, week, month, year, or any number of days.
1022 Custom commands can set this variable in the options section."
1023 :group 'org-agenda-daily/weekly
1024 :type '(choice (const :tag "Day" day)
1025 (const :tag "Week" week)
1026 (const :tag "Month" month)
1027 (const :tag "Year" year)
1028 (integer :tag "Custom")))
1030 (defcustom org-agenda-start-on-weekday 1
1031 "Non-nil means start the overview always on the specified weekday.
1032 0 denotes Sunday, 1 denotes Monday etc.
1033 When nil, always start on the current day.
1034 Custom commands can set this variable in the options section."
1035 :group 'org-agenda-daily/weekly
1036 :type '(choice (const :tag "Today" nil)
1037 (integer :tag "Weekday No.")))
1039 (defcustom org-agenda-show-all-dates t
1040 "Non-nil means `org-agenda' shows every day in the selected range.
1041 When nil, only the days which actually have entries are shown."
1042 :group 'org-agenda-daily/weekly
1043 :type 'boolean)
1045 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1046 "Format string for displaying dates in the agenda.
1047 Used by the daily/weekly agenda and by the timeline. This should be
1048 a format string understood by `format-time-string', or a function returning
1049 the formatted date as a string. The function must take a single argument,
1050 a calendar-style date list like (month day year)."
1051 :group 'org-agenda-daily/weekly
1052 :type '(choice
1053 (string :tag "Format string")
1054 (function :tag "Function")))
1056 (defun org-agenda-format-date-aligned (date)
1057 "Format a date string for display in the daily/weekly agenda, or timeline.
1058 This function makes sure that dates are aligned for easy reading."
1059 (require 'cal-iso)
1060 (let* ((dayname (calendar-day-name date))
1061 (day (cadr date))
1062 (day-of-week (calendar-day-of-week date))
1063 (month (car date))
1064 (monthname (calendar-month-name month))
1065 (year (nth 2 date))
1066 (iso-week (org-days-to-iso-week
1067 (calendar-absolute-from-gregorian date)))
1068 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1069 (1- year))
1070 ((and (= month 12) (<= iso-week 1))
1071 (1+ year))
1072 (t year)))
1073 (weekstring (if (= day-of-week 1)
1074 (format " W%02d" iso-week)
1075 "")))
1076 (format "%-10s %2d %s %4d%s"
1077 dayname day monthname year weekstring)))
1079 (defcustom org-agenda-time-leading-zero nil
1080 "Non-nil means use leading zero for military times in agenda.
1081 For example, 9:30am would become 09:30 rather than 9:30."
1082 :group 'org-agenda-daily/weekly
1083 :version "24.1"
1084 :type 'boolean)
1086 (defcustom org-agenda-timegrid-use-ampm nil
1087 "When set, show AM/PM style timestamps on the timegrid."
1088 :group 'org-agenda
1089 :version "24.1"
1090 :type 'boolean)
1092 (defun org-agenda-time-of-day-to-ampm (time)
1093 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1094 (let* ((hour-number (string-to-number (substring time 0 -3)))
1095 (minute (substring time -2))
1096 (ampm "am"))
1097 (cond
1098 ((equal hour-number 12)
1099 (setq ampm "pm"))
1100 ((> hour-number 12)
1101 (setq ampm "pm")
1102 (setq hour-number (- hour-number 12))))
1103 (concat
1104 (if org-agenda-time-leading-zero
1105 (format "%02d" hour-number)
1106 (format "%02s" (number-to-string hour-number)))
1107 ":" minute ampm)))
1109 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1110 "Conditionally convert TIME to AM/PM format
1111 based on `org-agenda-timegrid-use-ampm'"
1112 (if org-agenda-timegrid-use-ampm
1113 (org-agenda-time-of-day-to-ampm time)
1114 time))
1116 (defcustom org-agenda-weekend-days '(6 0)
1117 "Which days are weekend?
1118 These days get the special face `org-agenda-date-weekend' in the agenda
1119 and timeline buffers."
1120 :group 'org-agenda-daily/weekly
1121 :type '(set :greedy t
1122 (const :tag "Monday" 1)
1123 (const :tag "Tuesday" 2)
1124 (const :tag "Wednesday" 3)
1125 (const :tag "Thursday" 4)
1126 (const :tag "Friday" 5)
1127 (const :tag "Saturday" 6)
1128 (const :tag "Sunday" 0)))
1130 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1131 "Non-nil means jump to today when moving a past date forward in time.
1132 When using S-right in the agenda to move a a date forward, and the date
1133 stamp currently points to the past, the first key press will move it
1134 to today. WHen nil, just move one day forward even if the date stays
1135 in the past."
1136 :group 'org-agenda-daily/weekly
1137 :version "24.1"
1138 :type 'boolean)
1140 (defcustom org-agenda-include-diary nil
1141 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1142 Custom commands can set this variable in the options section."
1143 :group 'org-agenda-daily/weekly
1144 :type 'boolean)
1146 (defcustom org-agenda-include-deadlines t
1147 "If non-nil, include entries within their deadline warning period.
1148 Custom commands can set this variable in the options section."
1149 :group 'org-agenda-daily/weekly
1150 :version "24.1"
1151 :type 'boolean)
1153 (defcustom org-agenda-repeating-timestamp-show-all t
1154 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1155 When set to a list of strings, only show occurrences of repeating
1156 stamps for these TODO keywords. When nil, only one occurrence is
1157 shown, either today or the nearest into the future."
1158 :group 'org-agenda-daily/weekly
1159 :type '(choice
1160 (const :tag "Show repeating stamps" t)
1161 (repeat :tag "Show repeating stamps for these TODO keywords"
1162 (string :tag "TODO Keyword"))
1163 (const :tag "Don't show repeating stamps" nil)))
1165 (defcustom org-scheduled-past-days 10000
1166 "No. of days to continue listing scheduled items that are not marked DONE.
1167 When an item is scheduled on a date, it shows up in the agenda on this
1168 day and will be listed until it is marked done for the number of days
1169 given here."
1170 :group 'org-agenda-daily/weekly
1171 :type 'integer)
1173 (defcustom org-agenda-log-mode-items '(closed clock)
1174 "List of items that should be shown in agenda log mode.
1175 This list may contain the following symbols:
1177 closed Show entries that have been closed on that day.
1178 clock Show entries that have received clocked time on that day.
1179 state Show all logged state changes.
1180 Note that instead of changing this variable, you can also press `C-u l' in
1181 the agenda to display all available LOG items temporarily."
1182 :group 'org-agenda-daily/weekly
1183 :type '(set :greedy t (const closed) (const clock) (const state)))
1185 (defcustom org-agenda-clock-consistency-checks
1186 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1187 :gap-ok-around ("4:00")
1188 :default-face ((:background "DarkRed") (:foreground "white"))
1189 :overlap-face nil :gap-face nil :no-end-time-face nil
1190 :long-face nil :short-face nil)
1191 "This is a property list, with the following keys:
1193 :max-duration Mark clocking chunks that are longer than this time.
1194 This is a time string like \"HH:MM\", or the number
1195 of minutes as an integer.
1197 :min-duration Mark clocking chunks that are shorter that this.
1198 This is a time string like \"HH:MM\", or the number
1199 of minutes as an integer.
1201 :max-gap Mark gaps between clocking chunks that are longer than
1202 this duration. A number of minutes, or a string
1203 like \"HH:MM\".
1205 :gap-ok-around List of times during the day which are usually not working
1206 times. When a gap is detected, but the gap contains any
1207 of these times, the gap is *not* reported. For example,
1208 if this is (\"4:00\" \"13:00\") then gaps that contain
1209 4:00 in the morning (i.e. the night) and 13:00
1210 (i.e. a typical lunch time) do not cause a warning.
1211 You should have at least one time during the night in this
1212 list, or otherwise the first task each morning will trigger
1213 a warning because it follows a long gap.
1215 Furthermore, the following properties can be used to define faces for
1216 issue display.
1218 :default-face the default face, if the specific face is undefined
1219 :overlap-face face for overlapping clocks
1220 :gap-face face for gaps between clocks
1221 :no-end-time-face face for incomplete clocks
1222 :long-face face for clock intervals that are too long
1223 :short-face face for clock intervals that are too short"
1224 :group 'org-agenda-daily/weekly
1225 :group 'org-clock
1226 :version "24.1"
1227 :type 'plist)
1229 (defcustom org-agenda-log-mode-add-notes t
1230 "Non-nil means add first line of notes to log entries in agenda views.
1231 If a log item like a state change or a clock entry is associated with
1232 notes, the first line of these notes will be added to the entry in the
1233 agenda display."
1234 :group 'org-agenda-daily/weekly
1235 :type 'boolean)
1237 (defcustom org-agenda-start-with-log-mode nil
1238 "The initial value of log-mode in a newly created agenda window.
1239 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1240 explanations on the possible values."
1241 :group 'org-agenda-startup
1242 :group 'org-agenda-daily/weekly
1243 :type '(choice (const :tag "Don't show log items" nil)
1244 (const :tag "Show only log items" 'only)
1245 (const :tag "Show all possible log items" 'clockcheck)
1246 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1247 (choice (const :tag "Show closed log items" 'closed)
1248 (const :tag "Show clocked log items" 'clock)
1249 (const :tag "Show all logged state changes" 'state)))))
1251 (defcustom org-agenda-start-with-clockreport-mode nil
1252 "The initial value of clockreport-mode in a newly created agenda window."
1253 :group 'org-agenda-startup
1254 :group 'org-agenda-daily/weekly
1255 :type 'boolean)
1257 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1258 "Property list with parameters for the clocktable in clockreport mode.
1259 This is the display mode that shows a clock table in the daily/weekly
1260 agenda, the properties for this dynamic block can be set here.
1261 The usual clocktable parameters are allowed here, but you cannot set
1262 the properties :name, :tstart, :tend, :block, and :scope - these will
1263 be overwritten to make sure the content accurately reflects the
1264 current display in the agenda."
1265 :group 'org-agenda-daily/weekly
1266 :type 'plist)
1268 (defcustom org-agenda-search-view-always-boolean nil
1269 "Non-nil means the search string is interpreted as individual parts.
1271 The search string for search view can either be interpreted as a phrase,
1272 or as a list of snippets that define a boolean search for a number of
1273 strings.
1275 When this is non-nil, the string will be split on whitespace, and each
1276 snippet will be searched individually, and all must match in order to
1277 select an entry. A snippet is then a single string of non-white
1278 characters, or a string in double quotes, or a regexp in {} braces.
1279 If a snippet is preceded by \"-\", the snippet must *not* match.
1280 \"+\" is syntactic sugar for positive selection. Each snippet may
1281 be found as a full word or a partial word, but see the variable
1282 `org-agenda-search-view-force-full-words'.
1284 When this is nil, search will look for the entire search phrase as one,
1285 with each space character matching any amount of whitespace, including
1286 line breaks.
1288 Even when this is nil, you can still switch to Boolean search dynamically
1289 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1290 is a regexp marked with braces like \"{abc}\", this will also switch to
1291 boolean search."
1292 :group 'org-agenda-search-view
1293 :version "24.1"
1294 :type 'boolean)
1296 (if (fboundp 'defvaralias)
1297 (defvaralias 'org-agenda-search-view-search-words-only
1298 'org-agenda-search-view-always-boolean))
1300 (defcustom org-agenda-search-view-force-full-words nil
1301 "Non-nil means, search words must be matches as complete words.
1302 When nil, they may also match part of a word."
1303 :group 'org-agenda-search-view
1304 :version "24.1"
1305 :type 'boolean)
1307 (defgroup org-agenda-time-grid nil
1308 "Options concerning the time grid in the Org-mode Agenda."
1309 :tag "Org Agenda Time Grid"
1310 :group 'org-agenda)
1312 (defcustom org-agenda-search-headline-for-time t
1313 "Non-nil means search headline for a time-of-day.
1314 If the headline contains a time-of-day in one format or another, it will
1315 be used to sort the entry into the time sequence of items for a day.
1316 Some people have time stamps in the headline that refer to the creation
1317 time or so, and then this produces an unwanted side effect. If this is
1318 the case for your, use this variable to turn off searching the headline
1319 for a time."
1320 :group 'org-agenda-time-grid
1321 :type 'boolean)
1323 (defcustom org-agenda-use-time-grid t
1324 "Non-nil means show a time grid in the agenda schedule.
1325 A time grid is a set of lines for specific times (like every two hours between
1326 8:00 and 20:00). The items scheduled for a day at specific times are
1327 sorted in between these lines.
1328 For details about when the grid will be shown, and what it will look like, see
1329 the variable `org-agenda-time-grid'."
1330 :group 'org-agenda-time-grid
1331 :type 'boolean)
1333 (defcustom org-agenda-time-grid
1334 '((daily today require-timed)
1335 "----------------"
1336 (800 1000 1200 1400 1600 1800 2000))
1338 "The settings for time grid for agenda display.
1339 This is a list of three items. The first item is again a list. It contains
1340 symbols specifying conditions when the grid should be displayed:
1342 daily if the agenda shows a single day
1343 weekly if the agenda shows an entire week
1344 today show grid on current date, independent of daily/weekly display
1345 require-timed show grid only if at least one item has a time specification
1347 The second item is a string which will be placed behind the grid time.
1349 The third item is a list of integers, indicating the times that should have
1350 a grid line."
1351 :group 'org-agenda-time-grid
1352 :type
1353 '(list
1354 (set :greedy t :tag "Grid Display Options"
1355 (const :tag "Show grid in single day agenda display" daily)
1356 (const :tag "Show grid in weekly agenda display" weekly)
1357 (const :tag "Always show grid for today" today)
1358 (const :tag "Show grid only if any timed entries are present"
1359 require-timed)
1360 (const :tag "Skip grid times already present in an entry"
1361 remove-match))
1362 (string :tag "Grid String")
1363 (repeat :tag "Grid Times" (integer :tag "Time"))))
1365 (defcustom org-agenda-show-current-time-in-grid t
1366 "Non-nil means show the current time in the time grid."
1367 :group 'org-agenda-time-grid
1368 :version "24.1"
1369 :type 'boolean)
1371 (defcustom org-agenda-current-time-string
1372 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1373 "The string for the current time marker in the agenda."
1374 :group 'org-agenda-time-grid
1375 :version "24.1"
1376 :type 'string)
1378 (defgroup org-agenda-sorting nil
1379 "Options concerning sorting in the Org-mode Agenda."
1380 :tag "Org Agenda Sorting"
1381 :group 'org-agenda)
1383 (defcustom org-agenda-sorting-strategy
1384 '((agenda habit-down time-up priority-down category-keep)
1385 (todo priority-down category-keep)
1386 (tags priority-down category-keep)
1387 (search category-keep))
1388 "Sorting structure for the agenda items of a single day.
1389 This is a list of symbols which will be used in sequence to determine
1390 if an entry should be listed before another entry. The following
1391 symbols are recognized:
1393 time-up Put entries with time-of-day indications first, early first
1394 time-down Put entries with time-of-day indications first, late first
1395 category-keep Keep the default order of categories, corresponding to the
1396 sequence in `org-agenda-files'.
1397 category-up Sort alphabetically by category, A-Z.
1398 category-down Sort alphabetically by category, Z-A.
1399 tag-up Sort alphabetically by last tag, A-Z.
1400 tag-down Sort alphabetically by last tag, Z-A.
1401 priority-up Sort numerically by priority, high priority last.
1402 priority-down Sort numerically by priority, high priority first.
1403 todo-state-up Sort by todo state, tasks that are done last.
1404 todo-state-down Sort by todo state, tasks that are done first.
1405 effort-up Sort numerically by estimated effort, high effort last.
1406 effort-down Sort numerically by estimated effort, high effort first.
1407 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1408 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1409 habit-up Put entries that are habits first
1410 habit-down Put entries that are habits last
1411 alpha-up Sort headlines alphabetically
1412 alpha-down Sort headlines alphabetically, reversed
1414 The different possibilities will be tried in sequence, and testing stops
1415 if one comparison returns a \"not-equal\". For example, the default
1416 '(time-up category-keep priority-down)
1417 means: Pull out all entries having a specified time of day and sort them,
1418 in order to make a time schedule for the current day the first thing in the
1419 agenda listing for the day. Of the entries without a time indication, keep
1420 the grouped in categories, don't sort the categories, but keep them in
1421 the sequence given in `org-agenda-files'. Within each category sort by
1422 priority.
1424 Leaving out `category-keep' would mean that items will be sorted across
1425 categories by priority.
1427 Instead of a single list, this can also be a set of list for specific
1428 contents, with a context symbol in the car of the list, any of
1429 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1431 Custom commands can bind this variable in the options section."
1432 :group 'org-agenda-sorting
1433 :type `(choice
1434 (repeat :tag "General" ,org-sorting-choice)
1435 (list :tag "Individually"
1436 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1437 (repeat ,org-sorting-choice))
1438 (cons (const :tag "Strategy for TODO lists" todo)
1439 (repeat ,org-sorting-choice))
1440 (cons (const :tag "Strategy for Tags matches" tags)
1441 (repeat ,org-sorting-choice))
1442 (cons (const :tag "Strategy for search matches" search)
1443 (repeat ,org-sorting-choice)))))
1445 (defcustom org-agenda-cmp-user-defined nil
1446 "A function to define the comparison `user-defined'.
1447 This function must receive two arguments, agenda entry a and b.
1448 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1449 the user comparison, return nil.
1450 When this is defined, you can make `user-defined-up' and `user-defined-down'
1451 part of an agenda sorting strategy."
1452 :group 'org-agenda-sorting
1453 :type 'symbol)
1455 (defcustom org-sort-agenda-notime-is-late t
1456 "Non-nil means items without time are considered late.
1457 This is only relevant for sorting. When t, items which have no explicit
1458 time like 15:30 will be considered as 99:01, i.e. later than any items which
1459 do have a time. When nil, the default time is before 0:00. You can use this
1460 option to decide if the schedule for today should come before or after timeless
1461 agenda entries."
1462 :group 'org-agenda-sorting
1463 :type 'boolean)
1465 (defcustom org-sort-agenda-noeffort-is-high t
1466 "Non-nil means items without effort estimate are sorted as high effort.
1467 This also applies when filtering an agenda view with respect to the
1468 < or > effort operator. Then, tasks with no effort defined will be treated
1469 as tasks with high effort.
1470 When nil, such items are sorted as 0 minutes effort."
1471 :group 'org-agenda-sorting
1472 :type 'boolean)
1474 (defgroup org-agenda-line-format nil
1475 "Options concerning the entry prefix in the Org-mode agenda display."
1476 :tag "Org Agenda Line Format"
1477 :group 'org-agenda)
1479 (defcustom org-agenda-prefix-format
1480 '((agenda . " %i %-12:c%?-12t% s")
1481 (timeline . " % s")
1482 (todo . " %i %-12:c")
1483 (tags . " %i %-12:c")
1484 (search . " %i %-12:c"))
1485 "Format specifications for the prefix of items in the agenda views.
1486 An alist with five entries, each for the different agenda types. The
1487 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1488 The values are format strings.
1490 This format works similar to a printf format, with the following meaning:
1492 %c the category of the item, \"Diary\" for entries from the diary,
1493 or as given by the CATEGORY keyword or derived from the file name
1494 %e the effort required by the item
1495 %i the icon category of the item, see `org-agenda-category-icon-alist'
1496 %T the last tag of the item (ignore inherited tags, which come first)
1497 %t the HH:MM time-of-day specification if one applies to the entry
1498 %s Scheduling/Deadline information, a short string
1499 %(expression) Eval EXPRESSION and replace the control string
1500 by the result
1502 All specifiers work basically like the standard `%s' of printf, but may
1503 contain two additional characters: a question mark just after the `%'
1504 and a whitespace/punctuation character just before the final letter.
1506 If the first character after `%' is a question mark, the entire field
1507 will only be included if the corresponding value applies to the current
1508 entry. This is useful for fields which should have fixed width when
1509 present, but zero width when absent. For example, \"%?-12t\" will
1510 result in a 12 character time field if a time of the day is specified,
1511 but will completely disappear in entries which do not contain a time.
1513 If there is punctuation or whitespace character just before the final
1514 format letter, this character will be appended to the field value if
1515 the value is not empty. For example, the format \"%-12:c\" leads to
1516 \"Diary: \" if the category is \"Diary\". If the category were be
1517 empty, no additional colon would be inserted.
1519 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1520 which means:
1522 - Indent the line with two space characters
1523 - Give the category a 12 chars wide field, padded with whitespace on
1524 the right (because of `-'). Append a colon if there is a category
1525 (because of `:').
1526 - If there is a time-of-day, put it into a 12 chars wide field. If no
1527 time, don't put in an empty field, just skip it (because of '?').
1528 - Finally, put the scheduling information.
1530 See also the variables `org-agenda-remove-times-when-in-prefix' and
1531 `org-agenda-remove-tags'.
1533 Custom commands can set this variable in the options section."
1534 :type '(choice
1535 (string :tag "General format")
1536 (list :greedy t :tag "View dependent"
1537 (cons (const agenda) (string :tag "Format"))
1538 (cons (const timeline) (string :tag "Format"))
1539 (cons (const todo) (string :tag "Format"))
1540 (cons (const tags) (string :tag "Format"))
1541 (cons (const search) (string :tag "Format"))))
1542 :group 'org-agenda-line-format)
1544 (defvar org-prefix-format-compiled nil
1545 "The compiled prefix format and associated variables.
1546 This is a list where first element is a list of variable bindings, and second
1547 element is the compiled format expression. See the variable
1548 `org-agenda-prefix-format'.")
1550 (defcustom org-agenda-todo-keyword-format "%-1s"
1551 "Format for the TODO keyword in agenda lines.
1552 Set this to something like \"%-12s\" if you want all TODO keywords
1553 to occupy a fixed space in the agenda display."
1554 :group 'org-agenda-line-format
1555 :type 'string)
1557 (defcustom org-agenda-diary-sexp-prefix nil
1558 "A regexp that matches part of a diary sexp entry
1559 which should be treated as scheduling/deadline information in
1560 `org-agenda'.
1562 For example, you can use this to extract the `diary-remind-message' from
1563 `diary-remind' entries."
1564 :group 'org-agenda-line-format
1565 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1567 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1568 "Text preceding timerange entries in the agenda view.
1569 This is a list with two strings. The first applies when the range
1570 is entirely on one day. The second applies if the range spans several days.
1571 The strings may have two \"%d\" format specifiers which will be filled
1572 with the sequence number of the days, and the total number of days in the
1573 range, respectively."
1574 :group 'org-agenda-line-format
1575 :type '(list
1576 (string :tag "Deadline today ")
1577 (choice :tag "Deadline relative"
1578 (string :tag "Format string")
1579 (function))))
1581 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1582 "Text preceding scheduled items in the agenda view.
1583 This is a list with two strings. The first applies when the item is
1584 scheduled on the current day. The second applies when it has been scheduled
1585 previously, it may contain a %d indicating that this is the nth time that
1586 this item is scheduled, due to automatic rescheduling of unfinished items
1587 for the following day. So this number is one larger than the number of days
1588 that passed since this item was scheduled first."
1589 :group 'org-agenda-line-format
1590 :type '(list
1591 (string :tag "Scheduled today ")
1592 (string :tag "Scheduled previously")))
1594 (defcustom org-agenda-inactive-leader "["
1595 "Text preceding item pulled into the agenda by inactive time stamps.
1596 These entries are added to the agenda when pressing \"[\"."
1597 :group 'org-agenda-line-format
1598 :version "24.1"
1599 :type '(list
1600 (string :tag "Scheduled today ")
1601 (string :tag "Scheduled previously")))
1603 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1604 "Text preceding deadline items in the agenda view.
1605 This is a list with two strings. The first applies when the item has its
1606 deadline on the current day. The second applies when it is in the past or
1607 in the future, it may contain %d to capture how many days away the deadline
1608 is (was)."
1609 :group 'org-agenda-line-format
1610 :type '(list
1611 (string :tag "Deadline today ")
1612 (choice :tag "Deadline relative"
1613 (string :tag "Format string")
1614 (function))))
1616 (defcustom org-agenda-remove-times-when-in-prefix t
1617 "Non-nil means remove duplicate time specifications in agenda items.
1618 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1619 time-of-day specification in a headline or diary entry is extracted and
1620 placed into the prefix. If this option is non-nil, the original specification
1621 \(a timestamp or -range, or just a plain time(range) specification like
1622 11:30-4pm) will be removed for agenda display. This makes the agenda less
1623 cluttered.
1624 The option can be t or nil. It may also be the symbol `beg', indicating
1625 that the time should only be removed when it is located at the beginning of
1626 the headline/diary entry."
1627 :group 'org-agenda-line-format
1628 :type '(choice
1629 (const :tag "Always" t)
1630 (const :tag "Never" nil)
1631 (const :tag "When at beginning of entry" beg)))
1633 (defcustom org-agenda-remove-timeranges-from-blocks nil
1634 "Non-nil means remove time ranges specifications in agenda
1635 items that span on several days."
1636 :group 'org-agenda-line-format
1637 :version "24.1"
1638 :type 'boolean)
1640 (defcustom org-agenda-default-appointment-duration nil
1641 "Default duration for appointments that only have a starting time.
1642 When nil, no duration is specified in such cases.
1643 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1644 :group 'org-agenda-line-format
1645 :type '(choice
1646 (integer :tag "Minutes")
1647 (const :tag "No default duration")))
1649 (defcustom org-agenda-show-inherited-tags t
1650 "Non-nil means show inherited tags in each agenda line."
1651 :group 'org-agenda-line-format
1652 :type 'boolean)
1654 (defcustom org-agenda-hide-tags-regexp nil
1655 "Regular expression used to filter away specific tags in agenda views.
1656 This means that these tags will be present, but not be shown in the agenda
1657 line. Secondary filtering will still work on the hidden tags.
1658 Nil means don't hide any tags."
1659 :group 'org-agenda-line-format
1660 :type '(choice
1661 (const :tag "Hide none" nil)
1662 (string :tag "Regexp ")))
1664 (defcustom org-agenda-remove-tags nil
1665 "Non-nil means remove the tags from the headline copy in the agenda.
1666 When this is the symbol `prefix', only remove tags when
1667 `org-agenda-prefix-format' contains a `%T' specifier."
1668 :group 'org-agenda-line-format
1669 :type '(choice
1670 (const :tag "Always" t)
1671 (const :tag "Never" nil)
1672 (const :tag "When prefix format contains %T" prefix)))
1674 (if (fboundp 'defvaralias)
1675 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1676 'org-agenda-remove-tags))
1678 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1679 "Shift tags in agenda items to this column.
1680 If this number is positive, it specifies the column. If it is negative,
1681 it means that the tags should be flushright to that column. For example,
1682 -80 works well for a normal 80 character screen."
1683 :group 'org-agenda-line-format
1684 :type 'integer)
1686 (if (fboundp 'defvaralias)
1687 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1689 (defcustom org-agenda-fontify-priorities 'cookies
1690 "Non-nil means highlight low and high priorities in agenda.
1691 When t, the highest priority entries are bold, lowest priority italic.
1692 However, settings in `org-priority-faces' will overrule these faces.
1693 When this variable is the symbol `cookies', only fontify the
1694 cookies, not the entire task.
1695 This may also be an association list of priority faces, whose
1696 keys are the character values of `org-highest-priority',
1697 `org-default-priority', and `org-lowest-priority' (the default values
1698 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1699 color as a string, or a list like `(:background \"Red\")'.
1700 If it is a color, the variable `org-faces-easy-properties'
1701 determines if it is a foreground or a background color."
1702 :group 'org-agenda-line-format
1703 :type '(choice
1704 (const :tag "Never" nil)
1705 (const :tag "Defaults" t)
1706 (const :tag "Cookies only" cookies)
1707 (repeat :tag "Specify"
1708 (list (character :tag "Priority" :value ?A)
1709 (choice :tag "Face "
1710 (string :tag "Color")
1711 (sexp :tag "Face"))))))
1713 (defcustom org-agenda-day-face-function nil
1714 "Function called to determine what face should be used to display a day.
1715 The only argument passed to that function is the day. It should
1716 returns a face, or nil if does not want to specify a face and let
1717 the normal rules apply."
1718 :group 'org-agenda-line-format
1719 :version "24.1"
1720 :type 'function)
1722 (defcustom org-agenda-category-icon-alist nil
1723 "Alist of category icon to be displayed in agenda views.
1725 Each entry should have the following format:
1727 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1729 Where CATEGORY-REGEXP is a regexp matching the categories where
1730 the icon should be displayed.
1731 FILE-OR-DATA either a file path or a string containing image data.
1733 The other fields can be omitted safely if not needed:
1734 TYPE indicates the image type.
1735 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1736 image data.
1737 PROPS are additional image attributes to assign to the image,
1738 like, e.g. `:ascent center'.
1740 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1742 If you want to set the display properties yourself, just put a
1743 list as second element:
1745 (CATEGORY-REGEXP (MY PROPERTY LIST))
1747 For example, to display a 16px horizontal space for Emacs
1748 category, you can use:
1750 (\"Emacs\" '(space . (:width (16))))"
1751 :group 'org-agenda-line-format
1752 :version "24.1"
1753 :type '(alist :key-type (string :tag "Regexp matching category")
1754 :value-type (choice (list :tag "Icon"
1755 (string :tag "File or data")
1756 (symbol :tag "Type")
1757 (boolean :tag "Data?")
1758 (repeat :tag "Extra image properties" :inline t symbol))
1759 (list :tag "Display properties" sexp))))
1761 (defgroup org-agenda-column-view nil
1762 "Options concerning column view in the agenda."
1763 :tag "Org Agenda Column View"
1764 :group 'org-agenda)
1766 (defcustom org-agenda-columns-show-summaries t
1767 "Non-nil means show summaries for columns displayed in the agenda view."
1768 :group 'org-agenda-column-view
1769 :type 'boolean)
1771 (defcustom org-agenda-columns-compute-summary-properties t
1772 "Non-nil means recompute all summary properties before column view.
1773 When column view in the agenda is listing properties that have a summary
1774 operator, it can go to all relevant buffers and recompute the summaries
1775 there. This can mean overhead for the agenda column view, but is necessary
1776 to have thing up to date.
1777 As a special case, a CLOCKSUM property also makes sure that the clock
1778 computations are current."
1779 :group 'org-agenda-column-view
1780 :type 'boolean)
1782 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1783 "Non-nil means the duration of an appointment will add to day effort.
1784 The property to which appointment durations will be added is the one given
1785 in the option `org-effort-property'. If an appointment does not have
1786 an end time, `org-agenda-default-appointment-duration' will be used. If that
1787 is not set, an appointment without end time will not contribute to the time
1788 estimate."
1789 :group 'org-agenda-column-view
1790 :type 'boolean)
1792 (defcustom org-agenda-auto-exclude-function nil
1793 "A function called with a tag to decide if it is filtered on '/ RET'.
1794 The sole argument to the function, which is called once for each
1795 possible tag, is a string giving the name of the tag. The
1796 function should return either nil if the tag should be included
1797 as normal, or \"-<TAG>\" to exclude the tag.
1798 Note that for the purpose of tag filtering, only the lower-case version of
1799 all tags will be considered, so that this function will only ever see
1800 the lower-case version of all tags."
1801 :group 'org-agenda
1802 :type 'function)
1804 (defcustom org-agenda-bulk-custom-functions nil
1805 "Alist of characters and custom functions for bulk actions.
1806 For example, this value makes those two functions available:
1808 '((?R set-category)
1809 (?C bulk-cut))
1811 With selected entries in an agenda buffer, `B R' will call
1812 the custom function `set-category' on the selected entries.
1813 Note that functions in this alist don't need to be quoted."
1814 :type 'alist
1815 :version "24.1"
1816 :group 'org-agenda)
1818 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1819 "Execute BODY with point at location given by `org-hd-marker' property.
1820 If STRING is non-nil, the text property will be fetched from position 0
1821 in that string. If STRING is nil, it will be fetched from the beginning
1822 of the current line."
1823 (org-with-gensyms (marker)
1824 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1825 'org-hd-marker ,string)))
1826 (with-current-buffer (marker-buffer ,marker)
1827 (save-excursion
1828 (goto-char ,marker)
1829 ,@body)))))
1830 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1832 (defun org-add-agenda-custom-command (entry)
1833 "Replace or add a command in `org-agenda-custom-commands'.
1834 This is mostly for hacking and trying a new command - once the command
1835 works you probably want to add it to `org-agenda-custom-commands' for good."
1836 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1837 (if ass
1838 (setcdr ass (cdr entry))
1839 (push entry org-agenda-custom-commands))))
1841 ;;; Define the org-agenda-mode
1843 (defvar org-agenda-mode-map (make-sparse-keymap)
1844 "Keymap for `org-agenda-mode'.")
1845 (if (fboundp 'defvaralias)
1846 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1848 (defvar org-agenda-menu) ; defined later in this file.
1849 (defvar org-agenda-restrict nil) ; defined later in this file.
1850 (defvar org-agenda-follow-mode nil)
1851 (defvar org-agenda-entry-text-mode nil)
1852 (defvar org-agenda-clockreport-mode nil)
1853 (defvar org-agenda-show-log nil)
1854 (defvar org-agenda-redo-command nil)
1855 (defvar org-agenda-query-string nil)
1856 (defvar org-agenda-mode-hook nil
1857 "Hook run after `org-agenda-mode' is turned on.
1858 The buffer is still writable when this hook is called.")
1859 (defvar org-agenda-type nil)
1860 (defvar org-agenda-force-single-file nil)
1861 (defvar org-agenda-bulk-marked-entries nil
1862 "List of markers that refer to marked entries in the agenda.")
1864 ;;; Multiple agenda buffers support
1866 (defcustom org-agenda-sticky nil
1867 "Non-nil means agenda q key will bury agenda buffers.
1868 Agenda commands will then show existing buffer instead of generating new ones.
1869 When nil, `q' will kill the single agenda buffer."
1870 :group 'org-agenda
1871 :version "24.3"
1872 :type 'boolean)
1875 ;;;###autoload
1876 (defun org-toggle-sticky-agenda (&optional arg)
1877 "Toggle `org-agenda-sticky'."
1878 (interactive "P")
1879 (let ((new-value (if arg
1880 (> (prefix-numeric-value arg) 0)
1881 (not org-agenda-sticky))))
1882 (if (equal new-value org-agenda-sticky)
1883 (and (org-called-interactively-p 'interactive)
1884 (message "Sticky agenda was already %s"
1885 (if org-agenda-sticky "enabled" "disabled")))
1886 (setq org-agenda-sticky new-value)
1887 (org-agenda-kill-all-agenda-buffers)
1888 (and (org-called-interactively-p 'interactive)
1889 (message "Sticky agenda was %s"
1890 (if org-agenda-sticky "enabled" "disabled"))))))
1892 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1893 Toggle `org-agenda-sticky'.
1895 \(fn &optional ARG)" t nil)
1897 (defvar org-agenda-buffer nil
1898 "Agenda buffer currently being generated.")
1900 (defvar org-agenda-last-prefix-arg nil)
1901 (defvar org-agenda-this-buffer-name nil)
1902 (defvar org-agenda-doing-sticky-redo nil)
1903 (defvar org-agenda-this-buffer-is-sticky nil)
1905 (defconst org-agenda-local-vars
1906 '(org-agenda-this-buffer-name
1907 org-agenda-undo-list
1908 org-agenda-pending-undo-list
1909 org-agenda-follow-mode
1910 org-agenda-entry-text-mode
1911 org-agenda-clockreport-mode
1912 org-agenda-show-log
1913 org-agenda-redo-command
1914 org-agenda-query-string
1915 org-agenda-type
1916 org-agenda-bulk-marked-entries
1917 org-agenda-undo-has-started-in
1918 org-agenda-info
1919 org-agenda-tag-filter-overlays
1920 org-agenda-cat-filter-overlays
1921 org-agenda-pre-window-conf
1922 org-agenda-columns-active
1923 org-agenda-tag-filter
1924 org-agenda-category-filter
1925 org-agenda-markers
1926 org-agenda-last-search-view-search-was-boolean
1927 org-agenda-filtered-by-category
1928 org-agenda-filter-form
1929 org-agenda-show-window
1930 org-agenda-cycle-counter
1931 org-agenda-last-prefix-arg)
1932 "Variables that must be local in agenda buffers to allow multiple buffers.")
1934 (defun org-agenda-mode ()
1935 "Mode for time-sorted view on action items in Org-mode files.
1937 The following commands are available:
1939 \\{org-agenda-mode-map}"
1940 (interactive)
1941 (cond (org-agenda-doing-sticky-redo
1942 ;; Refreshing sticky agenda-buffer
1944 ;; Preserve the value of `org-agenda-local-vars' variables,
1945 ;; while letting `kill-all-local-variables' kill the rest
1946 (let ((save (buffer-local-variables)))
1947 (kill-all-local-variables)
1948 (mapc 'make-local-variable org-agenda-local-vars)
1949 (dolist (elem save)
1950 (let ((var (car elem))
1951 (val (cdr elem)))
1952 (when (and val
1953 (member var org-agenda-local-vars))
1954 (set var val)))))
1955 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1956 (org-agenda-sticky
1957 ;; Creating a sticky Agenda buffer for the first time
1958 (kill-all-local-variables)
1959 (mapc 'make-local-variable org-agenda-local-vars)
1960 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1962 ;; Creating a non-sticky agenda buffer
1963 (kill-all-local-variables)
1964 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1965 (setq org-agenda-undo-list nil
1966 org-agenda-pending-undo-list nil
1967 org-agenda-bulk-marked-entries nil)
1968 (setq major-mode 'org-agenda-mode)
1969 ;; Keep global-font-lock-mode from turning on font-lock-mode
1970 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1971 (setq mode-name "Org-Agenda")
1972 (use-local-map org-agenda-mode-map)
1973 (easy-menu-add org-agenda-menu)
1974 (if org-startup-truncated (setq truncate-lines t))
1975 (org-set-local 'line-move-visual nil)
1976 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
1977 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1978 ;; Make sure properties are removed when copying text
1979 (make-local-variable 'filter-buffer-substring-functions)
1980 (add-hook 'filter-buffer-substring-functions
1981 (lambda (fun start end delete)
1982 (substring-no-properties (funcall fun start end delete))))
1983 (unless org-agenda-keep-modes
1984 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1985 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1986 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1987 org-agenda-show-log org-agenda-start-with-log-mode))
1989 (easy-menu-change
1990 '("Agenda") "Agenda Files"
1991 (append
1992 (list
1993 (vector
1994 (if (get 'org-agenda-files 'org-restrict)
1995 "Restricted to single file"
1996 "Edit File List")
1997 '(org-edit-agenda-file-list)
1998 (not (get 'org-agenda-files 'org-restrict)))
1999 "--")
2000 (mapcar 'org-file-menu-entry (org-agenda-files))))
2001 (org-agenda-set-mode-name)
2002 (apply
2003 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2004 (list 'org-agenda-mode-hook)))
2006 (substitute-key-definition 'undo 'org-agenda-undo
2007 org-agenda-mode-map global-map)
2008 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2009 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2010 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2011 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2012 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2013 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2014 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2015 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2016 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2017 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2018 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2019 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2020 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2021 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2022 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2023 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2024 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2025 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2026 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2027 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2028 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2029 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2030 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2031 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2032 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2033 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2034 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2035 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2036 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2037 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2038 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2039 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2040 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2041 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2042 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2043 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2044 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2045 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2046 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2047 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2048 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2049 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2050 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2051 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2052 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2054 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2055 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2056 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2057 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2058 (while l (org-defkey org-agenda-mode-map
2059 (int-to-string (pop l)) 'digit-argument)))
2061 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2062 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2063 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2064 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2065 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2066 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2067 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2068 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2069 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2070 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2071 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2072 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2073 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2074 'org-clock-modify-effort-estimate)
2075 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2076 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2077 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2078 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2079 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2080 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2081 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2082 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2083 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2084 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2085 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2086 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2087 (substitute-key-definition 'next-line 'org-agenda-next-line
2088 org-agenda-mode-map global-map)
2089 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2090 org-agenda-mode-map global-map)
2091 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2092 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2093 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2094 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2095 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2096 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2097 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2098 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2099 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2100 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2101 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2102 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2103 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2104 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2105 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2106 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2107 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2108 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2109 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2110 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2111 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2112 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2113 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2114 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2115 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2116 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2117 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2118 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2119 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2120 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2122 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2123 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2124 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2125 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2126 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2127 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2128 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2129 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2130 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2131 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2132 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2133 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2135 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2136 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2137 (when org-agenda-mouse-1-follows-link
2138 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2139 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2140 '("Agenda"
2141 ("Agenda Files")
2142 "--"
2143 ("Agenda Dates"
2144 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2145 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2146 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2147 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2148 "--"
2149 ("View"
2150 ["Day View" org-agenda-day-view
2151 :active (org-agenda-check-type nil 'agenda)
2152 :style radio :selected (eq org-agenda-current-span 'day)
2153 :keys "v d (or just d)"]
2154 ["Week View" org-agenda-week-view
2155 :active (org-agenda-check-type nil 'agenda)
2156 :style radio :selected (eq org-agenda-current-span 'week)
2157 :keys "v w (or just w)"]
2158 ["Month View" org-agenda-month-view
2159 :active (org-agenda-check-type nil 'agenda)
2160 :style radio :selected (eq org-agenda-current-span 'month)
2161 :keys "v m"]
2162 ["Year View" org-agenda-year-view
2163 :active (org-agenda-check-type nil 'agenda)
2164 :style radio :selected (eq org-agenda-current-span 'year)
2165 :keys "v y"]
2166 "--"
2167 ["Include Diary" org-agenda-toggle-diary
2168 :style toggle :selected org-agenda-include-diary
2169 :active (org-agenda-check-type nil 'agenda)]
2170 ["Include Deadlines" org-agenda-toggle-deadlines
2171 :style toggle :selected org-agenda-include-deadlines
2172 :active (org-agenda-check-type nil 'agenda)]
2173 ["Use Time Grid" org-agenda-toggle-time-grid
2174 :style toggle :selected org-agenda-use-time-grid
2175 :active (org-agenda-check-type nil 'agenda)]
2176 "--"
2177 ["Show clock report" org-agenda-clockreport-mode
2178 :style toggle :selected org-agenda-clockreport-mode
2179 :active (org-agenda-check-type nil 'agenda)]
2180 ["Show some entry text" org-agenda-entry-text-mode
2181 :style toggle :selected org-agenda-entry-text-mode
2182 :active t]
2183 "--"
2184 ["Show Logbook entries" org-agenda-log-mode
2185 :style toggle :selected org-agenda-show-log
2186 :active (org-agenda-check-type nil 'agenda 'timeline)
2187 :keys "v l (or just l)"]
2188 ["Include archived trees" org-agenda-archives-mode
2189 :style toggle :selected org-agenda-archives-mode :active t
2190 :keys "v a"]
2191 ["Include archive files" (org-agenda-archives-mode t)
2192 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2193 :keys "v A"]
2194 "--"
2195 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2196 ["Write view to file" org-agenda-write t]
2197 ["Rebuild buffer" org-agenda-redo t]
2198 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2199 "--"
2200 ["Show original entry" org-agenda-show t]
2201 ["Go To (other window)" org-agenda-goto t]
2202 ["Go To (this window)" org-agenda-switch-to t]
2203 ["Capture with cursor date" org-agenda-capture t]
2204 ["Follow Mode" org-agenda-follow-mode
2205 :style toggle :selected org-agenda-follow-mode :active t]
2206 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2207 "--"
2208 ("TODO"
2209 ["Cycle TODO" org-agenda-todo t]
2210 ["Next TODO set" org-agenda-todo-nextset t]
2211 ["Previous TODO set" org-agenda-todo-previousset t]
2212 ["Add note" org-agenda-add-note t])
2213 ("Archive/Refile/Delete"
2214 ["Archive default" org-agenda-archive-default t]
2215 ["Archive default" org-agenda-archive-default-with-confirmation t]
2216 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2217 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2218 ["Archive subtree" org-agenda-archive t]
2219 "--"
2220 ["Refile" org-agenda-refile t]
2221 "--"
2222 ["Delete subtree" org-agenda-kill t])
2223 ("Bulk action"
2224 ["Mark entry" org-agenda-bulk-mark t]
2225 ["Mark all" org-agenda-bulk-mark-all t]
2226 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2227 ["Unmark entry" org-agenda-bulk-unmark t]
2228 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2229 ["Act on all marked" org-agenda-bulk-action t]
2230 "--"
2231 ("Tags and Properties"
2232 ["Show all Tags" org-agenda-show-tags t]
2233 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2234 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2235 "--"
2236 ["Column View" org-columns t])
2237 ("Deadline/Schedule"
2238 ["Schedule" org-agenda-schedule t]
2239 ["Set Deadline" org-agenda-deadline t]
2240 "--"
2241 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2242 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2243 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2244 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2245 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2246 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2247 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2248 ("Clock and Effort"
2249 ["Clock in" org-agenda-clock-in t]
2250 ["Clock out" org-agenda-clock-out t]
2251 ["Clock cancel" org-agenda-clock-cancel t]
2252 ["Goto running clock" org-clock-goto t]
2253 "--"
2254 ["Set Effort" org-agenda-set-effort t]
2255 ["Change clocked effort" org-clock-modify-effort-estimate
2256 (org-clock-is-active)])
2257 ("Priority"
2258 ["Set Priority" org-agenda-priority t]
2259 ["Increase Priority" org-agenda-priority-up t]
2260 ["Decrease Priority" org-agenda-priority-down t]
2261 ["Show Priority" org-show-priority t])
2262 ("Calendar/Diary"
2263 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2264 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2265 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2266 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2267 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2268 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2269 "--"
2270 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2271 "--"
2272 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2273 "--"
2274 ("MobileOrg"
2275 ["Push Files and Views" org-mobile-push t]
2276 ["Get Captured and Flagged" org-mobile-pull t]
2277 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2278 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2279 "--"
2280 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2281 "--"
2282 ["Quit" org-agenda-quit t]
2283 ["Exit and Release Buffers" org-agenda-exit t]
2286 ;;; Agenda undo
2288 (defvar org-agenda-allow-remote-undo t
2289 "Non-nil means allow remote undo from the agenda buffer.")
2290 (defvar org-agenda-undo-has-started-in nil
2291 "Buffers that have already seen `undo-start' in the current undo sequence.")
2293 (defun org-agenda-undo ()
2294 "Undo a remote editing step in the agenda.
2295 This undoes changes both in the agenda buffer and in the remote buffer
2296 that have been changed along."
2297 (interactive)
2298 (or org-agenda-allow-remote-undo
2299 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2300 (if (not (eq this-command last-command))
2301 (setq org-agenda-undo-has-started-in nil
2302 org-agenda-pending-undo-list org-agenda-undo-list))
2303 (if (not org-agenda-pending-undo-list)
2304 (error "No further undo information"))
2305 (let* ((entry (pop org-agenda-pending-undo-list))
2306 buf line cmd rembuf)
2307 (setq cmd (pop entry) line (pop entry))
2308 (setq rembuf (nth 2 entry))
2309 (org-with-remote-undo rembuf
2310 (while (bufferp (setq buf (pop entry)))
2311 (if (pop entry)
2312 (with-current-buffer buf
2313 (let ((last-undo-buffer buf)
2314 (inhibit-read-only t))
2315 (unless (memq buf org-agenda-undo-has-started-in)
2316 (push buf org-agenda-undo-has-started-in)
2317 (make-local-variable 'pending-undo-list)
2318 (undo-start))
2319 (while (and pending-undo-list
2320 (listp pending-undo-list)
2321 (not (car pending-undo-list)))
2322 (pop pending-undo-list))
2323 (undo-more 1))))))
2324 (org-goto-line line)
2325 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2327 (defun org-verify-change-for-undo (l1 l2)
2328 "Verify that a real change occurred between the undo lists L1 and L2."
2329 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2330 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2331 (not (eq l1 l2)))
2333 ;;; Agenda dispatch
2335 (defvar org-agenda-restrict-begin (make-marker))
2336 (defvar org-agenda-restrict-end (make-marker))
2337 (defvar org-agenda-last-dispatch-buffer nil)
2338 (defvar org-agenda-overriding-restriction nil)
2340 (defcustom org-agenda-custom-commands-contexts nil
2341 "Alist of custom agenda keys and contextual rules.
2343 For example, if you have a custom agenda command \"p\" and you
2344 want this command to be accessible only from plain text files,
2345 use this:
2347 '((\"p\" (in-file . \"\\.txt\")))
2349 Here are the available contexts definitions:
2351 in-file: command displayed only in matching files
2352 in-mode: command displayed only in matching modes
2353 not-in-file: command not displayed in matching files
2354 not-in-mode: command not displayed in matching modes
2355 [function]: a custom function taking no argument
2357 If you define several checks, the agenda command will be
2358 accessible if there is at least one valid check.
2360 You can also bind a key to another agenda custom command
2361 depending on contextual rules.
2363 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2365 Here it means: in .txt files, use \"p\" as the key for the
2366 agenda command otherwise associated with \"q\". (The command
2367 originally associated with \"q\" is not displayed to avoid
2368 duplicates.)"
2369 :version "24.3"
2370 :group 'org-agenda-custom-commands
2371 :type '(repeat (list :tag "Rule"
2372 (string :tag " Agenda key")
2373 (string :tag "Replace by command")
2374 (repeat :tag "Available when"
2375 (choice
2376 (cons :tag "Condition"
2377 (choice
2378 (const :tag "In file" in-file)
2379 (const :tag "Not in file" not-in-file)
2380 (const :tag "In mode" in-mode)
2381 (const :tag "Not in mode" not-in-mode))
2382 (regexp))
2383 (function :tag "Custom function"))))))
2385 (defvar org-keys nil)
2386 (defvar org-match nil)
2387 ;;;###autoload
2388 (defun org-agenda (&optional arg org-keys restriction)
2389 "Dispatch agenda commands to collect entries to the agenda buffer.
2390 Prompts for a command to execute. Any prefix arg will be passed
2391 on to the selected command. The default selections are:
2393 a Call `org-agenda-list' to display the agenda for current day or week.
2394 t Call `org-todo-list' to display the global todo list.
2395 T Call `org-todo-list' to display the global todo list, select only
2396 entries with a specific TODO keyword (the user gets a prompt).
2397 m Call `org-tags-view' to display headlines with tags matching
2398 a condition (the user is prompted for the condition).
2399 M Like `m', but select only TODO entries, no ordinary headlines.
2400 L Create a timeline for the current buffer.
2401 e Export views to associated files.
2402 s Search entries for keywords.
2403 S Search entries for keywords, only with TODO keywords.
2404 / Multi occur across all agenda files and also files listed
2405 in `org-agenda-text-search-extra-files'.
2406 < Restrict agenda commands to buffer, subtree, or region.
2407 Press several times to get the desired effect.
2408 > Remove a previous restriction.
2409 # List \"stuck\" projects.
2410 ! Configure what \"stuck\" means.
2411 C Configure custom agenda commands.
2413 More commands can be added by configuring the variable
2414 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2415 searches can be pre-defined in this way.
2417 If the current buffer is in Org-mode and visiting a file, you can also
2418 first press `<' once to indicate that the agenda should be temporarily
2419 \(until the next use of \\[org-agenda]) restricted to the current file.
2420 Pressing `<' twice means to restrict to the current subtree or region
2421 \(if active)."
2422 (interactive "P")
2423 (catch 'exit
2424 (let* ((prefix-descriptions nil)
2425 (org-agenda-buffer-name org-agenda-buffer-name)
2426 (org-agenda-window-setup (if (equal (buffer-name)
2427 org-agenda-buffer-name)
2428 'current-window
2429 org-agenda-window-setup))
2430 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2431 (org-agenda-custom-commands
2432 ;; normalize different versions
2433 (delq nil
2434 (mapcar
2435 (lambda (x)
2436 (cond ((stringp (cdr x))
2437 (push x prefix-descriptions)
2438 nil)
2439 ((stringp (nth 1 x)) x)
2440 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2441 (t (cons (car x) (cons "" (cdr x))))))
2442 org-agenda-custom-commands)))
2443 (org-agenda-custom-commands
2444 (org-contextualize-keys
2445 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2446 (buf (current-buffer))
2447 (bfn (buffer-file-name (buffer-base-buffer)))
2448 entry key type org-match lprops ans)
2449 ;; Turn off restriction unless there is an overriding one,
2450 (unless org-agenda-overriding-restriction
2451 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2452 ;; There is a request to keep the file list in place
2453 (put 'org-agenda-files 'org-restrict nil))
2454 (setq org-agenda-restrict nil)
2455 (move-marker org-agenda-restrict-begin nil)
2456 (move-marker org-agenda-restrict-end nil))
2457 ;; Delete old local properties
2458 (put 'org-agenda-redo-command 'org-lprops nil)
2459 ;; Delete previously set last-arguments
2460 (put 'org-agenda-redo-command 'last-args nil)
2461 ;; Remember where this call originated
2462 (setq org-agenda-last-dispatch-buffer (current-buffer))
2463 (unless org-keys
2464 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2465 org-keys (car ans)
2466 restriction (cdr ans)))
2467 ;; If we have sticky agenda buffers, set a name for the buffer,
2468 ;; depending on the invoking keys. The user may still set this
2469 ;; as a command option, which will overwrite what we do here.
2470 (if org-agenda-sticky
2471 (setq org-agenda-buffer-name
2472 (format "*Org Agenda(%s)*" org-keys)))
2473 ;; Establish the restriction, if any
2474 (when (and (not org-agenda-overriding-restriction) restriction)
2475 (put 'org-agenda-files 'org-restrict (list bfn))
2476 (cond
2477 ((eq restriction 'region)
2478 (setq org-agenda-restrict t)
2479 (move-marker org-agenda-restrict-begin (region-beginning))
2480 (move-marker org-agenda-restrict-end (region-end)))
2481 ((eq restriction 'subtree)
2482 (save-excursion
2483 (setq org-agenda-restrict t)
2484 (org-back-to-heading t)
2485 (move-marker org-agenda-restrict-begin (point))
2486 (move-marker org-agenda-restrict-end
2487 (progn (org-end-of-subtree t)))))))
2489 ;; For example the todo list should not need it (but does...)
2490 (cond
2491 ((setq entry (assoc org-keys org-agenda-custom-commands))
2492 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2493 (progn
2494 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2495 lprops (nth 4 entry))
2496 (if org-agenda-sticky
2497 (setq org-agenda-buffer-name
2498 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2499 (format "*Org Agenda(%s)*" org-keys))))
2500 (put 'org-agenda-redo-command 'org-lprops lprops)
2501 (cond
2502 ((eq type 'agenda)
2503 (org-let lprops '(org-agenda-list current-prefix-arg)))
2504 ((eq type 'alltodo)
2505 (org-let lprops '(org-todo-list current-prefix-arg)))
2506 ((eq type 'search)
2507 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2508 ((eq type 'stuck)
2509 (org-let lprops '(org-agenda-list-stuck-projects
2510 current-prefix-arg)))
2511 ((eq type 'tags)
2512 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2513 ((eq type 'tags-todo)
2514 (org-let lprops '(org-tags-view '(4) org-match)))
2515 ((eq type 'todo)
2516 (org-let lprops '(org-todo-list org-match)))
2517 ((eq type 'tags-tree)
2518 (org-check-for-org-mode)
2519 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2520 ((eq type 'todo-tree)
2521 (org-check-for-org-mode)
2522 (org-let lprops
2523 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2524 (regexp-quote org-match) "\\>"))))
2525 ((eq type 'occur-tree)
2526 (org-check-for-org-mode)
2527 (org-let lprops '(org-occur org-match)))
2528 ((functionp type)
2529 (org-let lprops '(funcall type org-match)))
2530 ((fboundp type)
2531 (org-let lprops '(funcall type org-match)))
2532 (t (error "Invalid custom agenda command type %s" type))))
2533 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2534 ((equal org-keys "C")
2535 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2536 (customize-variable 'org-agenda-custom-commands))
2537 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2538 ((equal org-keys "s") (call-interactively 'org-search-view))
2539 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2540 ((equal org-keys "t") (call-interactively 'org-todo-list))
2541 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2542 ((equal org-keys "m") (call-interactively 'org-tags-view))
2543 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2544 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2545 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2546 (org-add-hook
2547 'post-command-hook
2548 (lambda ()
2549 (unless (current-message)
2550 (let* ((m (org-agenda-get-any-marker))
2551 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2552 (when note
2553 (message (concat
2554 "FLAGGING-NOTE ([?] for more info): "
2555 (org-add-props
2556 (replace-regexp-in-string
2557 "\\\\n" "//"
2558 (copy-sequence note))
2559 nil 'face 'org-warning)))))))
2560 t t))
2561 ((equal org-keys "L")
2562 (unless (derived-mode-p 'org-mode)
2563 (error "This is not an Org-mode file"))
2564 (unless restriction
2565 (put 'org-agenda-files 'org-restrict (list bfn))
2566 (org-call-with-arg 'org-timeline arg)))
2567 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2568 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2569 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2570 (t (error "Invalid agenda key"))))))
2572 (autoload 'org-agenda "org-agenda" "\
2573 Dispatch agenda commands to collect entries to the agenda buffer.
2574 Prompts for a command to execute. Any prefix arg will be passed
2575 on to the selected command. The default selections are:
2577 a Call `org-agenda-list' to display the agenda for current day or week.
2578 t Call `org-todo-list' to display the global todo list.
2579 T Call `org-todo-list' to display the global todo list, select only
2580 entries with a specific TODO keyword (the user gets a prompt).
2581 m Call `org-tags-view' to display headlines with tags matching
2582 a condition (the user is prompted for the condition).
2583 M Like `m', but select only TODO entries, no ordinary headlines.
2584 L Create a timeline for the current buffer.
2585 e Export views to associated files.
2586 s Search entries for keywords.
2587 S Search entries for keywords, only with TODO keywords.
2588 / Multi occur across all agenda files and also files listed
2589 in `org-agenda-text-search-extra-files'.
2590 < Restrict agenda commands to buffer, subtree, or region.
2591 Press several times to get the desired effect.
2592 > Remove a previous restriction.
2593 # List \"stuck\" projects.
2594 ! Configure what \"stuck\" means.
2595 C Configure custom agenda commands.
2597 More commands can be added by configuring the variable
2598 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2599 searches can be pre-defined in this way.
2601 If the current buffer is in Org-mode and visiting a file, you can also
2602 first press `<' once to indicate that the agenda should be temporarily
2603 \(until the next use of \\[org-agenda]) restricted to the current file.
2604 Pressing `<' twice means to restrict to the current subtree or region
2605 \(if active).
2607 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2609 (defun org-agenda-append-agenda ()
2610 "Append another agenda view to the current one.
2611 This function allows interactive building of block agendas.
2612 Agenda views are separated by `org-agenda-block-separator'."
2613 (interactive)
2614 (unless (derived-mode-p 'org-agenda-mode)
2615 (error "Can only append from within agenda buffer"))
2616 (let ((org-agenda-multi t))
2617 (org-agenda)
2618 (widen)
2619 (org-agenda-finalize)
2620 (org-agenda-fit-window-to-buffer)))
2622 (defun org-agenda-normalize-custom-commands (cmds)
2623 (delq nil
2624 (mapcar
2625 (lambda (x)
2626 (cond ((stringp (cdr x)) nil)
2627 ((stringp (nth 1 x)) x)
2628 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2629 (t (cons (car x) (cons "" (cdr x))))))
2630 cmds)))
2632 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2633 "The user interface for selecting an agenda command."
2634 (catch 'exit
2635 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2636 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2637 (region-p (org-region-active-p))
2638 (custom org-agenda-custom-commands)
2639 (selstring "")
2640 restriction second-time
2641 c entry key type match prefixes rmheader header-end custom1 desc
2642 line lines left right n n1)
2643 (save-window-excursion
2644 (delete-other-windows)
2645 (org-switch-to-buffer-other-window " *Agenda Commands*")
2646 (erase-buffer)
2647 (insert (eval-when-compile
2648 (let ((header
2649 "Press key for an agenda command: < Buffer, subtree/region restriction
2650 -------------------------------- > Remove restriction
2651 a Agenda for current week or day e Export agenda views
2652 t List of all TODO entries T Entries with special TODO kwd
2653 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2654 s Search for keywords S Like s, but only TODO entries
2655 L Timeline for current buffer # List stuck projects (!=configure)
2656 / Multi-occur C Configure custom agenda commands
2657 ? Find :FLAGGED: entries * Toggle sticky agenda views
2659 (start 0))
2660 (while (string-match
2661 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2662 header start)
2663 (setq start (match-end 0))
2664 (add-text-properties (match-beginning 2) (match-end 2)
2665 '(face bold) header))
2666 header)))
2667 (setq header-end (move-marker (make-marker) (point)))
2668 (while t
2669 (setq custom1 custom)
2670 (when (eq rmheader t)
2671 (org-goto-line 1)
2672 (re-search-forward ":" nil t)
2673 (delete-region (match-end 0) (point-at-eol))
2674 (forward-char 1)
2675 (looking-at "-+")
2676 (delete-region (match-end 0) (point-at-eol))
2677 (move-marker header-end (match-end 0)))
2678 (goto-char header-end)
2679 (delete-region (point) (point-max))
2681 ;; Produce all the lines that describe custom commands and prefixes
2682 (setq lines nil)
2683 (while (setq entry (pop custom1))
2684 (setq key (car entry) desc (nth 1 entry)
2685 type (nth 2 entry)
2686 match (nth 3 entry))
2687 (if (> (length key) 1)
2688 (add-to-list 'prefixes (string-to-char key))
2689 (setq line
2690 (format
2691 "%-4s%-14s"
2692 (org-add-props (copy-sequence key)
2693 '(face bold))
2694 (cond
2695 ((string-match "\\S-" desc) desc)
2696 ((eq type 'agenda) "Agenda for current week or day")
2697 ((eq type 'alltodo) "List of all TODO entries")
2698 ((eq type 'search) "Word search")
2699 ((eq type 'stuck) "List of stuck projects")
2700 ((eq type 'todo) "TODO keyword")
2701 ((eq type 'tags) "Tags query")
2702 ((eq type 'tags-todo) "Tags (TODO)")
2703 ((eq type 'tags-tree) "Tags tree")
2704 ((eq type 'todo-tree) "TODO kwd tree")
2705 ((eq type 'occur-tree) "Occur tree")
2706 ((functionp type) (if (symbolp type)
2707 (symbol-name type)
2708 "Lambda expression"))
2709 (t "???"))))
2710 (if org-agenda-menu-show-matcher
2711 (setq line
2712 (concat line ": "
2713 (cond
2714 ((stringp match)
2715 (setq match (copy-sequence match))
2716 (org-add-props match nil 'face 'org-warning))
2717 ((listp type)
2718 (format "set of %d commands" (length type))))))
2719 (if (org-string-nw-p match)
2720 (add-text-properties
2721 0 (length line) (list 'help-echo
2722 (concat "Matcher: " match)) line)))
2723 (push line lines)))
2724 (setq lines (nreverse lines))
2725 (when prefixes
2726 (mapc (lambda (x)
2727 (push
2728 (format "%s %s"
2729 (org-add-props (char-to-string x)
2730 nil 'face 'bold)
2731 (or (cdr (assoc (concat selstring
2732 (char-to-string x))
2733 prefix-descriptions))
2734 "Prefix key"))
2735 lines))
2736 prefixes))
2738 ;; Check if we should display in two columns
2739 (if org-agenda-menu-two-columns
2740 (progn
2741 (setq n (length lines)
2742 n1 (+ (/ n 2) (mod n 2))
2743 right (nthcdr n1 lines)
2744 left (copy-sequence lines))
2745 (setcdr (nthcdr (1- n1) left) nil))
2746 (setq left lines right nil))
2747 (while left
2748 (insert "\n" (pop left))
2749 (when right
2750 (if (< (current-column) 40)
2751 (move-to-column 40 t)
2752 (insert " "))
2753 (insert (pop right))))
2755 ;; Make the window the right size
2756 (goto-char (point-min))
2757 (if second-time
2758 (if (not (pos-visible-in-window-p (point-max)))
2759 (org-fit-window-to-buffer))
2760 (setq second-time t)
2761 (org-fit-window-to-buffer))
2763 ;; Ask for selection
2764 (message "Press key for agenda command%s:"
2765 (if (or restrict-ok org-agenda-overriding-restriction)
2766 (if org-agenda-overriding-restriction
2767 " (restriction lock active)"
2768 (if restriction
2769 (format " (restricted to %s)" restriction)
2770 " (unrestricted)"))
2771 ""))
2772 (setq c (read-char-exclusive))
2773 (message "")
2774 (cond
2775 ((assoc (char-to-string c) custom)
2776 (setq selstring (concat selstring (char-to-string c)))
2777 (throw 'exit (cons selstring restriction)))
2778 ((memq c prefixes)
2779 (setq selstring (concat selstring (char-to-string c))
2780 prefixes nil
2781 rmheader (or rmheader t)
2782 custom (delq nil (mapcar
2783 (lambda (x)
2784 (if (or (= (length (car x)) 1)
2785 (/= (string-to-char (car x)) c))
2787 (cons (substring (car x) 1) (cdr x))))
2788 custom))))
2789 ((eq c ?*)
2790 (call-interactively 'org-toggle-sticky-agenda)
2791 (sit-for 2))
2792 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2793 (message "Restriction is only possible in Org-mode buffers")
2794 (ding) (sit-for 1))
2795 ((eq c ?1)
2796 (org-agenda-remove-restriction-lock 'noupdate)
2797 (setq restriction 'buffer))
2798 ((eq c ?0)
2799 (org-agenda-remove-restriction-lock 'noupdate)
2800 (setq restriction (if region-p 'region 'subtree)))
2801 ((eq c ?<)
2802 (org-agenda-remove-restriction-lock 'noupdate)
2803 (setq restriction
2804 (cond
2805 ((eq restriction 'buffer)
2806 (if region-p 'region 'subtree))
2807 ((memq restriction '(subtree region))
2808 nil)
2809 (t 'buffer))))
2810 ((eq c ?>)
2811 (org-agenda-remove-restriction-lock 'noupdate)
2812 (setq restriction nil))
2813 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2814 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2815 ((and (> (length selstring) 0) (eq c ?\d))
2816 (delete-window)
2817 (org-agenda-get-restriction-and-command prefix-descriptions))
2819 ((equal c ?q) (error "Abort"))
2820 (t (error "Invalid key %c" c))))))))
2822 (defun org-agenda-fit-window-to-buffer ()
2823 "Fit the window to the buffer size."
2824 (and (memq org-agenda-window-setup '(reorganize-frame))
2825 (fboundp 'fit-window-to-buffer)
2826 (org-fit-window-to-buffer
2828 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2829 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2831 (defvar org-cmd nil)
2832 (defvar org-agenda-overriding-cmd nil)
2833 (defvar org-agenda-overriding-arguments nil)
2834 (defvar org-agenda-overriding-cmd-arguments nil)
2835 (defun org-agenda-run-series (name series)
2836 (org-let (nth 1 series) '(org-agenda-prepare name))
2837 ;; We need to reset agenda markers here, because when constructing a
2838 ;; block agenda, the individual blocks do not do that.
2839 (org-agenda-reset-markers)
2840 (let* ((org-agenda-multi t)
2841 (redo (list 'org-agenda-run-series name (list 'quote series)))
2842 (cmds (car series))
2843 (gprops (nth 1 series))
2844 match ;; The byte compiler incorrectly complains about this. Keep it!
2845 org-cmd type lprops)
2846 (while (setq org-cmd (pop cmds))
2847 (setq type (car org-cmd)
2848 match (eval (nth 1 org-cmd))
2849 lprops (nth 2 org-cmd))
2850 (let ((org-agenda-overriding-arguments
2851 (if (eq org-agenda-overriding-cmd org-cmd)
2852 (or org-agenda-overriding-arguments
2853 org-agenda-overriding-cmd-arguments))))
2854 (cond
2855 ((eq type 'agenda)
2856 (org-let2 gprops lprops
2857 '(call-interactively 'org-agenda-list)))
2858 ((eq type 'alltodo)
2859 (org-let2 gprops lprops
2860 '(call-interactively 'org-todo-list)))
2861 ((eq type 'search)
2862 (org-let2 gprops lprops
2863 '(org-search-view current-prefix-arg match nil)))
2864 ((eq type 'stuck)
2865 (org-let2 gprops lprops
2866 '(call-interactively 'org-agenda-list-stuck-projects)))
2867 ((eq type 'tags)
2868 (org-let2 gprops lprops
2869 '(org-tags-view current-prefix-arg match)))
2870 ((eq type 'tags-todo)
2871 (org-let2 gprops lprops
2872 '(org-tags-view '(4) match)))
2873 ((eq type 'todo)
2874 (org-let2 gprops lprops
2875 '(org-todo-list match)))
2876 ((fboundp type)
2877 (org-let2 gprops lprops
2878 '(funcall type match)))
2879 (t (error "Invalid type in command series")))))
2880 (widen)
2881 (let ((inhibit-read-only t))
2882 (add-text-properties (point-min) (point-max)
2883 `(org-series t org-series-redo-cmd ,redo)))
2884 (setq org-agenda-redo-command redo)
2885 (goto-char (point-min)))
2886 (org-agenda-fit-window-to-buffer)
2887 (org-let (nth 1 series) '(org-agenda-finalize)))
2889 ;;;###autoload
2890 (defmacro org-batch-agenda (cmd-key &rest parameters)
2891 "Run an agenda command in batch mode and send the result to STDOUT.
2892 If CMD-KEY is a string of length 1, it is used as a key in
2893 `org-agenda-custom-commands' and triggers this command. If it is a
2894 longer string it is used as a tags/todo match string.
2895 Parameters are alternating variable names and values that will be bound
2896 before running the agenda command."
2897 (org-eval-in-environment (org-make-parameter-alist parameters)
2898 (if (> (length cmd-key) 2)
2899 (org-tags-view nil cmd-key)
2900 (org-agenda nil cmd-key)))
2901 (set-buffer org-agenda-buffer-name)
2902 (princ (buffer-string)))
2904 (autoload 'org-batch-agenda "org-agenda" "\
2905 Run an agenda command in batch mode and send the result to STDOUT.
2906 If CMD-KEY is a string of length 1, it is used as a key in
2907 `org-agenda-custom-commands' and triggers this command. If it is a
2908 longer string it is used as a tags/todo match string.
2909 Parameters are alternating variable names and values that will be bound
2910 before running the agenda command.
2912 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2913 (def-edebug-spec org-batch-agenda (form &rest sexp))
2915 (defvar org-agenda-info nil)
2917 ;;;###autoload
2918 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2919 "Run an agenda command in batch mode and send the result to STDOUT.
2920 If CMD-KEY is a string of length 1, it is used as a key in
2921 `org-agenda-custom-commands' and triggers this command. If it is a
2922 longer string it is used as a tags/todo match string.
2923 Parameters are alternating variable names and values that will be bound
2924 before running the agenda command.
2926 The output gives a line for each selected agenda item. Each
2927 item is a list of comma-separated values, like this:
2929 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2931 category The category of the item
2932 head The headline, without TODO kwd, TAGS and PRIORITY
2933 type The type of the agenda entry, can be
2934 todo selected in TODO match
2935 tagsmatch selected in tags match
2936 diary imported from diary
2937 deadline a deadline on given date
2938 scheduled scheduled on given date
2939 timestamp entry has timestamp on given date
2940 closed entry was closed on given date
2941 upcoming-deadline warning about deadline
2942 past-scheduled forwarded scheduled item
2943 block entry has date block including g. date
2944 todo The todo keyword, if any
2945 tags All tags including inherited ones, separated by colons
2946 date The relevant date, like 2007-2-14
2947 time The time, like 15:00-16:50
2948 extra Sting with extra planning info
2949 priority-l The priority letter if any was given
2950 priority-n The computed numerical priority
2951 agenda-day The day in the agenda where this is listed"
2952 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2953 (org-make-parameter-alist parameters))
2954 (if (> (length cmd-key) 2)
2955 (org-tags-view nil cmd-key)
2956 (org-agenda nil cmd-key)))
2957 (set-buffer org-agenda-buffer-name)
2958 (let* ((lines (org-split-string (buffer-string) "\n"))
2959 line)
2960 (while (setq line (pop lines))
2961 (catch 'next
2962 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2963 (setq org-agenda-info
2964 (org-fix-agenda-info (text-properties-at 0 line)))
2965 (princ
2966 (mapconcat 'org-agenda-export-csv-mapper
2967 '(org-category txt type todo tags date time extra
2968 priority-letter priority agenda-day)
2969 ","))
2970 (princ "\n")))))
2972 (autoload 'org-batch-agenda-csv "org-agenda" "\
2973 Run an agenda command in batch mode and send the result to STDOUT.
2974 If CMD-KEY is a string of length 1, it is used as a key in
2975 `org-agenda-custom-commands' and triggers this command. If it is a
2976 longer string it is used as a tags/todo match string.
2977 Parameters are alternating variable names and values that will be bound
2978 before running the agenda command.
2980 The output gives a line for each selected agenda item. Each
2981 item is a list of comma-separated values, like this:
2983 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2985 category The category of the item
2986 head The headline, without TODO kwd, TAGS and PRIORITY
2987 type The type of the agenda entry, can be
2988 todo selected in TODO match
2989 tagsmatch selected in tags match
2990 diary imported from diary
2991 deadline a deadline on given date
2992 scheduled scheduled on given date
2993 timestamp entry has timestamp on given date
2994 closed entry was closed on given date
2995 upcoming-deadline warning about deadline
2996 past-scheduled forwarded scheduled item
2997 block entry has date block including g. date
2998 todo The todo keyword, if any
2999 tags All tags including inherited ones, separated by colons
3000 date The relevant date, like 2007-2-14
3001 time The time, like 15:00-16:50
3002 extra Sting with extra planning info
3003 priority-l The priority letter if any was given
3004 priority-n The computed numerical priority
3005 agenda-day The day in the agenda where this is listed
3007 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3008 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3010 (defun org-fix-agenda-info (props)
3011 "Make sure all properties on an agenda item have a canonical form.
3012 This ensures the export commands can easily use it."
3013 (let (tmp re)
3014 (when (setq tmp (plist-get props 'tags))
3015 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3016 (when (setq tmp (plist-get props 'date))
3017 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3018 (let ((calendar-date-display-form '(year "-" month "-" day)))
3019 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3021 (setq tmp (calendar-date-string tmp)))
3022 (setq props (plist-put props 'date tmp)))
3023 (when (setq tmp (plist-get props 'day))
3024 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3025 (let ((calendar-date-display-form '(year "-" month "-" day)))
3026 (setq tmp (calendar-date-string tmp)))
3027 (setq props (plist-put props 'day tmp))
3028 (setq props (plist-put props 'agenda-day tmp)))
3029 (when (setq tmp (plist-get props 'txt))
3030 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3031 (plist-put props 'priority-letter (match-string 1 tmp))
3032 (setq tmp (replace-match "" t t tmp)))
3033 (when (and (setq re (plist-get props 'org-todo-regexp))
3034 (setq re (concat "\\`\\.*" re " ?"))
3035 (string-match re tmp))
3036 (plist-put props 'todo (match-string 1 tmp))
3037 (setq tmp (replace-match "" t t tmp)))
3038 (plist-put props 'txt tmp)))
3039 props)
3041 (defun org-agenda-export-csv-mapper (prop)
3042 (let ((res (plist-get org-agenda-info prop)))
3043 (setq res
3044 (cond
3045 ((not res) "")
3046 ((stringp res) res)
3047 (t (prin1-to-string res))))
3048 (while (string-match "," res)
3049 (setq res (replace-match ";" t t res)))
3050 (org-trim res)))
3052 ;;;###autoload
3053 (defun org-store-agenda-views (&rest parameters)
3054 (interactive)
3055 (eval (list 'org-batch-store-agenda-views)))
3057 (autoload 'org-store-agenda-views "org-agenda" "\
3060 \(fn &rest PARAMETERS)" t nil)
3062 ;;;###autoload
3063 (defmacro org-batch-store-agenda-views (&rest parameters)
3064 "Run all custom agenda commands that have a file argument."
3065 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3066 (pop-up-frames nil)
3067 (dir default-directory)
3068 (pars (org-make-parameter-alist parameters))
3069 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3070 (save-window-excursion
3071 (while cmds
3072 (setq cmd (pop cmds)
3073 thiscmdkey (car cmd)
3074 thiscmdcmd (cdr cmd)
3075 match (nth 2 thiscmdcmd)
3076 bufname (if org-agenda-sticky
3077 (or (and (stringp match)
3078 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3079 (format "*Org Agenda(%s)*" thiscmdkey))
3080 org-agenda-buffer-name)
3081 cmd-or-set (nth 2 cmd)
3082 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3083 files (nth (if (listp cmd-or-set) 4 5) cmd))
3084 (if (stringp files) (setq files (list files)))
3085 (when files
3086 (org-eval-in-environment (append org-agenda-exporter-settings
3087 opts pars)
3088 (org-agenda nil thiscmdkey))
3089 (set-buffer bufname)
3090 (while files
3091 (org-eval-in-environment (append org-agenda-exporter-settings
3092 opts pars)
3093 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3094 (and (get-buffer bufname)
3095 (kill-buffer bufname)))))))
3097 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3098 Run all custom agenda commands that have a file argument.
3100 \(fn &rest PARAMETERS)" nil t)
3101 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3103 (defvar org-agenda-current-span nil
3104 "The current span used in the agenda view.") ; local variable in the agenda buffer
3105 (defun org-agenda-mark-header-line (pos)
3106 "Mark the line at POS as an agenda structure header."
3107 (save-excursion
3108 (goto-char pos)
3109 (put-text-property (point-at-bol) (point-at-eol)
3110 'org-agenda-structural-header t)
3111 (when org-agenda-title-append
3112 (put-text-property (point-at-bol) (point-at-eol)
3113 'org-agenda-title-append org-agenda-title-append))))
3115 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3116 (defvar org-agenda-write-buffer-name "Agenda View")
3117 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3118 "Write the current buffer (an agenda view) as a file.
3119 Depending on the extension of the file name, plain text (.txt),
3120 HTML (.html or .htm) or Postscript (.ps) is produced.
3121 If the extension is .ics, run icalendar export over all files used
3122 to construct the agenda and limit the export to entries listed in the
3123 agenda now.
3124 With prefix argument OPEN, open the new file immediately.
3125 If NOSETTINGS is given, do not scope the settings of
3126 `org-agenda-exporter-settings' into the export commands. This is used when
3127 the settings have already been scoped and we do not wish to overrule other,
3128 higher priority settings.
3129 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3130 (interactive "FWrite agenda to file: \nP")
3131 (if (not (file-writable-p file))
3132 (error "Cannot write agenda to file %s" file))
3133 (org-let (if nosettings nil org-agenda-exporter-settings)
3134 '(save-excursion
3135 (save-window-excursion
3136 (org-agenda-mark-filtered-text)
3137 (let ((bs (copy-sequence (buffer-string))) beg)
3138 (org-agenda-unmark-filtered-text)
3139 (with-temp-buffer
3140 (rename-buffer org-agenda-write-buffer-name t)
3141 (set-buffer-modified-p nil)
3142 (insert bs)
3143 (org-agenda-remove-marked-text 'org-filtered)
3144 (while (setq beg (text-property-any (point-min) (point-max)
3145 'org-filtered t))
3146 (delete-region
3147 beg (or (next-single-property-change beg 'org-filtered)
3148 (point-max))))
3149 (run-hooks 'org-agenda-before-write-hook)
3150 (cond
3151 ((org-bound-and-true-p org-mobile-creating-agendas)
3152 (org-mobile-write-agenda-for-mobile file))
3153 ((string-match "\\.html?\\'" file)
3154 (require 'htmlize)
3155 (set-buffer (htmlize-buffer (current-buffer)))
3156 (when org-agenda-export-html-style
3157 ;; replace <style> section with org-agenda-export-html-style
3158 (goto-char (point-min))
3159 (kill-region (- (search-forward "<style") 6)
3160 (search-forward "</style>"))
3161 (insert org-agenda-export-html-style))
3162 (write-file file)
3163 (kill-buffer (current-buffer))
3164 (message "HTML written to %s" file))
3165 ((string-match "\\.ps\\'" file)
3166 (require 'ps-print)
3167 (ps-print-buffer-with-faces file)
3168 (message "Postscript written to %s" file))
3169 ((string-match "\\.pdf\\'" file)
3170 (require 'ps-print)
3171 (ps-print-buffer-with-faces
3172 (concat (file-name-sans-extension file) ".ps"))
3173 (call-process "ps2pdf" nil nil nil
3174 (expand-file-name
3175 (concat (file-name-sans-extension file) ".ps"))
3176 (expand-file-name file))
3177 (delete-file (concat (file-name-sans-extension file) ".ps"))
3178 (message "PDF written to %s" file))
3179 ((string-match "\\.ics\\'" file)
3180 (require 'org-icalendar)
3181 (let ((org-agenda-marker-table
3182 (org-create-marker-find-array
3183 (org-agenda-collect-markers)))
3184 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3185 (org-combined-agenda-icalendar-file file))
3186 (apply 'org-export-icalendar 'combine
3187 (org-agenda-files nil 'ifmode))))
3189 (let ((bs (buffer-string)))
3190 (find-file file)
3191 (erase-buffer)
3192 (insert bs)
3193 (save-buffer 0)
3194 (kill-buffer (current-buffer))
3195 (message "Plain text written to %s" file))))))))
3196 (set-buffer (or agenda-bufname
3197 (and (called-interactively-p 'any) (buffer-name))
3198 org-agenda-buffer-name)))
3199 (when open (org-open-file file)))
3201 (defvar org-agenda-tag-filter-overlays nil)
3202 (defvar org-agenda-cat-filter-overlays nil)
3204 (defun org-agenda-mark-filtered-text ()
3205 "Mark all text hidden by filtering with a text property."
3206 (let ((inhibit-read-only t))
3207 (mapc
3208 (lambda (o)
3209 (when (equal (overlay-buffer o) (current-buffer))
3210 (put-text-property
3211 (overlay-start o) (overlay-end o)
3212 'org-filtered t)))
3213 (append org-agenda-tag-filter-overlays
3214 org-agenda-cat-filter-overlays))))
3216 (defun org-agenda-unmark-filtered-text ()
3217 "Remove the filtering text property."
3218 (let ((inhibit-read-only t))
3219 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3221 (defun org-agenda-remove-marked-text (property &optional value)
3222 "Delete all text marked with VALUE of PROPERTY.
3223 VALUE defaults to t."
3224 (let (beg)
3225 (setq value (or value t))
3226 (while (setq beg (text-property-any (point-min) (point-max)
3227 property value))
3228 (delete-region
3229 beg (or (next-single-property-change beg 'org-filtered)
3230 (point-max))))))
3232 (defun org-agenda-add-entry-text ()
3233 "Add entry text to agenda lines.
3234 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3235 entry text following headings shown in the agenda.
3236 Drawers will be excluded, also the line with scheduling/deadline info."
3237 (when (and (> org-agenda-add-entry-text-maxlines 0)
3238 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3239 (let (m txt)
3240 (goto-char (point-min))
3241 (while (not (eobp))
3242 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3243 (beginning-of-line 2)
3244 (setq txt (org-agenda-get-some-entry-text
3245 m org-agenda-add-entry-text-maxlines " > "))
3246 (end-of-line 1)
3247 (if (string-match "\\S-" txt)
3248 (insert "\n" txt)
3249 (or (eobp) (forward-char 1))))))))
3251 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3252 &rest keep)
3253 "Extract entry text from MARKER, at most N-LINES lines.
3254 This will ignore drawers etc, just get the text.
3255 If INDENT is given, prefix every line with this string. If KEEP is
3256 given, it is a list of symbols, defining stuff that should not be
3257 removed from the entry content. Currently only `planning' is allowed here."
3258 (let (txt drawer-re kwd-time-re ind)
3259 (save-excursion
3260 (with-current-buffer (marker-buffer marker)
3261 (if (not (derived-mode-p 'org-mode))
3262 (setq txt "")
3263 (save-excursion
3264 (save-restriction
3265 (widen)
3266 (goto-char marker)
3267 (end-of-line 1)
3268 (setq txt (buffer-substring
3269 (min (1+ (point)) (point-max))
3270 (progn (outline-next-heading) (point)))
3271 drawer-re org-drawer-regexp
3272 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3273 ".*\n?"))
3274 (with-temp-buffer
3275 (insert txt)
3276 (when org-agenda-add-entry-text-descriptive-links
3277 (goto-char (point-min))
3278 (while (org-activate-bracket-links (point-max))
3279 (add-text-properties (match-beginning 0) (match-end 0)
3280 '(face org-link))))
3281 (goto-char (point-min))
3282 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3283 (set-text-properties (match-beginning 0) (match-end 0)
3284 nil))
3285 (goto-char (point-min))
3286 (while (re-search-forward drawer-re nil t)
3287 (delete-region
3288 (match-beginning 0)
3289 (progn (re-search-forward
3290 "^[ \t]*:END:.*\n?" nil 'move)
3291 (point))))
3292 (unless (member 'planning keep)
3293 (goto-char (point-min))
3294 (while (re-search-forward kwd-time-re nil t)
3295 (replace-match "")))
3296 (goto-char (point-min))
3297 (when org-agenda-entry-text-exclude-regexps
3298 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3299 (while (setq re (pop re-list))
3300 (goto-char (point-min))
3301 (while (re-search-forward re nil t)
3302 (replace-match "")))))
3303 (goto-char (point-max))
3304 (skip-chars-backward " \t\n")
3305 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3307 ;; find and remove min common indentation
3308 (goto-char (point-min))
3309 (untabify (point-min) (point-max))
3310 (setq ind (org-get-indentation))
3311 (while (not (eobp))
3312 (unless (looking-at "[ \t]*$")
3313 (setq ind (min ind (org-get-indentation))))
3314 (beginning-of-line 2))
3315 (goto-char (point-min))
3316 (while (not (eobp))
3317 (unless (looking-at "[ \t]*$")
3318 (move-to-column ind)
3319 (delete-region (point-at-bol) (point)))
3320 (beginning-of-line 2))
3322 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3324 (goto-char (point-min))
3325 (when indent
3326 (while (and (not (eobp)) (re-search-forward "^" nil t))
3327 (replace-match indent t t)))
3328 (goto-char (point-min))
3329 (while (looking-at "[ \t]*\n") (replace-match ""))
3330 (goto-char (point-max))
3331 (when (> (org-current-line)
3332 n-lines)
3333 (org-goto-line (1+ n-lines))
3334 (backward-char 1))
3335 (setq txt (buffer-substring (point-min) (point)))))))))
3336 txt))
3338 (defun org-agenda-collect-markers ()
3339 "Collect the markers pointing to entries in the agenda buffer."
3340 (let (m markers)
3341 (save-excursion
3342 (goto-char (point-min))
3343 (while (not (eobp))
3344 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3345 (org-get-at-bol 'org-marker)))
3346 (push m markers))
3347 (beginning-of-line 2)))
3348 (nreverse markers)))
3350 (defun org-create-marker-find-array (marker-list)
3351 "Create a alist of files names with all marker positions in that file."
3352 (let (f tbl m a p)
3353 (while (setq m (pop marker-list))
3354 (setq p (marker-position m)
3355 f (buffer-file-name (or (buffer-base-buffer
3356 (marker-buffer m))
3357 (marker-buffer m))))
3358 (if (setq a (assoc f tbl))
3359 (push (marker-position m) (cdr a))
3360 (push (list f p) tbl)))
3361 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3362 tbl)))
3364 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3365 (defun org-check-agenda-marker-table ()
3366 "Check of the current entry is on the marker list."
3367 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3369 (and (setq a (assoc file org-agenda-marker-table))
3370 (save-match-data
3371 (save-excursion
3372 (org-back-to-heading t)
3373 (member (point) (cdr a)))))))
3375 (defun org-check-for-org-mode ()
3376 "Make sure current buffer is in org-mode. Error if not."
3377 (or (derived-mode-p 'org-mode)
3378 (error "Cannot execute org-mode agenda command on buffer in %s"
3379 major-mode)))
3381 ;;; Agenda prepare and finalize
3383 (defvar org-agenda-multi nil) ; dynamically scoped
3384 (defvar org-agenda-pre-window-conf nil)
3385 (defvar org-agenda-columns-active nil)
3386 (defvar org-agenda-name nil)
3387 (defvar org-agenda-tag-filter nil)
3388 (defvar org-agenda-category-filter nil)
3389 (defvar org-agenda-top-category-filter nil)
3390 (defvar org-agenda-tag-filter-while-redo nil)
3391 (defvar org-agenda-tag-filter-preset nil
3392 "A preset of the tags filter used for secondary agenda filtering.
3393 This must be a list of strings, each string must be a single tag preceded
3394 by \"+\" or \"-\".
3395 This variable should not be set directly, but agenda custom commands can
3396 bind it in the options section. The preset filter is a global property of
3397 the entire agenda view. In a block agenda, it will not work reliably to
3398 define a filter for one of the individual blocks. You need to set it in
3399 the global options and expect it to be applied to the entire view.")
3401 (defvar org-agenda-category-filter-preset nil
3402 "A preset of the category filter used for secondary agenda filtering.
3403 This must be a list of strings, each string must be a single category
3404 preceded by \"+\" or \"-\".
3405 This variable should not be set directly, but agenda custom commands can
3406 bind it in the options section. The preset filter is a global property of
3407 the entire agenda view. In a block agenda, it will not work reliably to
3408 define a filter for one of the individual blocks. You need to set it in
3409 the global options and expect it to be applied to the entire view.")
3412 (defun org-agenda-use-sticky-p ()
3413 "Return non-nil if an agenda buffer named
3414 `org-agenda-buffer-name' exists and should be shown instead of
3415 generating a new one."
3416 (and
3417 ;; turned off by user
3418 org-agenda-sticky
3419 ;; For multi-agenda buffer already exists
3420 (not org-agenda-multi)
3421 ;; buffer found
3422 (get-buffer org-agenda-buffer-name)
3423 ;; C-u parameter is same as last call
3424 (with-current-buffer (get-buffer org-agenda-buffer-name)
3425 (and
3426 (equal current-prefix-arg
3427 org-agenda-last-prefix-arg)
3428 ;; In case user turned stickiness on, while having existing
3429 ;; Agenda buffer active, don't reuse that buffer, because it
3430 ;; does not have org variables local
3431 org-agenda-this-buffer-is-sticky))))
3433 (defun org-agenda-prepare-window (abuf)
3434 "Setup agenda buffer in the window."
3435 (let* ((awin (get-buffer-window abuf))
3436 wconf)
3437 (cond
3438 ((equal (current-buffer) abuf) nil)
3439 (awin (select-window awin))
3440 ((not (setq wconf (current-window-configuration))))
3441 ((equal org-agenda-window-setup 'current-window)
3442 (org-pop-to-buffer-same-window abuf))
3443 ((equal org-agenda-window-setup 'other-window)
3444 (org-switch-to-buffer-other-window abuf))
3445 ((equal org-agenda-window-setup 'other-frame)
3446 (switch-to-buffer-other-frame abuf))
3447 ((equal org-agenda-window-setup 'reorganize-frame)
3448 (delete-other-windows)
3449 (org-switch-to-buffer-other-window abuf)))
3450 ;; additional test in case agenda is invoked from within agenda
3451 ;; buffer via elisp link
3452 (unless (equal (current-buffer) abuf)
3453 (org-pop-to-buffer-same-window abuf))
3454 (setq org-agenda-pre-window-conf
3455 (or org-agenda-pre-window-conf wconf))))
3457 (defun org-agenda-prepare (&optional name)
3458 (if (org-agenda-use-sticky-p)
3459 (progn
3460 ;; Popup existing buffer
3461 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3462 (message "Sticky Agenda buffer, use `r' to refresh")
3463 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3464 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3465 (setq org-todo-keywords-for-agenda nil)
3466 (setq org-drawers-for-agenda nil)
3467 (unless org-agenda-persistent-filter
3468 (setq org-agenda-tag-filter nil
3469 org-agenda-category-filter nil))
3470 (put 'org-agenda-tag-filter :preset-filter
3471 org-agenda-tag-filter-preset)
3472 (put 'org-agenda-category-filter :preset-filter
3473 org-agenda-category-filter-preset)
3474 (if org-agenda-multi
3475 (progn
3476 (setq buffer-read-only nil)
3477 (goto-char (point-max))
3478 (unless (or (bobp) org-agenda-compact-blocks
3479 (not org-agenda-block-separator))
3480 (insert "\n"
3481 (if (stringp org-agenda-block-separator)
3482 org-agenda-block-separator
3483 (make-string (window-width) org-agenda-block-separator))
3484 "\n"))
3485 (narrow-to-region (point) (point-max)))
3486 (setq org-done-keywords-for-agenda nil)
3488 ;; Setting any org variables that are in org-agenda-local-vars
3489 ;; list need to be done after the prepare call
3490 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3491 (setq buffer-read-only nil)
3492 (org-agenda-reset-markers)
3493 (let ((inhibit-read-only t)) (erase-buffer))
3494 (org-agenda-mode)
3495 (setq org-agenda-buffer (current-buffer))
3496 (setq org-agenda-contributing-files nil)
3497 (setq org-agenda-columns-active nil)
3498 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3499 (setq org-todo-keywords-for-agenda
3500 (org-uniquify org-todo-keywords-for-agenda))
3501 (setq org-done-keywords-for-agenda
3502 (org-uniquify org-done-keywords-for-agenda))
3503 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3504 (setq org-agenda-last-prefix-arg current-prefix-arg)
3505 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3506 (and name (not org-agenda-name)
3507 (org-set-local 'org-agenda-name name)))
3508 (setq buffer-read-only nil)))
3510 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3511 (defun org-agenda-finalize ()
3512 "Finishing touch for the agenda buffer, called just before displaying it."
3513 (unless org-agenda-multi
3514 (save-excursion
3515 (let ((inhibit-read-only t))
3516 (goto-char (point-min))
3517 (while (org-activate-bracket-links (point-max))
3518 (add-text-properties (match-beginning 0) (match-end 0)
3519 '(face org-link)))
3520 (while (org-activate-plain-links (point-max))
3521 (add-text-properties (match-beginning 0) (match-end 0)
3522 '(face org-link)))
3523 (org-agenda-align-tags)
3524 (unless org-agenda-with-colors
3525 (remove-text-properties (point-min) (point-max) '(face nil))))
3526 (if (and (boundp 'org-agenda-overriding-columns-format)
3527 org-agenda-overriding-columns-format)
3528 (org-set-local 'org-agenda-overriding-columns-format
3529 org-agenda-overriding-columns-format))
3530 (if (and (boundp 'org-agenda-view-columns-initially)
3531 org-agenda-view-columns-initially)
3532 (org-agenda-columns))
3533 (when org-agenda-fontify-priorities
3534 (org-agenda-fontify-priorities))
3535 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3536 (org-agenda-dim-blocked-tasks))
3537 ;; We need to widen when `org-agenda-finalize' is called from
3538 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3539 (save-restriction
3540 (widen)
3541 (org-agenda-mark-clocking-task))
3542 (when org-agenda-entry-text-mode
3543 (org-agenda-entry-text-hide)
3544 (org-agenda-entry-text-show))
3545 (if (functionp 'org-habit-insert-consistency-graphs)
3546 (org-habit-insert-consistency-graphs))
3547 (let ((inhibit-read-only t))
3548 (run-hooks 'org-agenda-finalize-hook))
3549 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3550 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3551 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3552 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3553 (org-agenda-filter-apply org-agenda-category-filter 'category))
3554 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3556 (defun org-agenda-mark-clocking-task ()
3557 "Mark the current clock entry in the agenda if it is present."
3558 (mapc (lambda (o)
3559 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3560 (delete-overlay o)))
3561 (overlays-in (point-min) (point-max)))
3562 (when (marker-buffer org-clock-hd-marker)
3563 (save-excursion
3564 (goto-char (point-min))
3565 (let (s ov)
3566 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3567 (goto-char s)
3568 (when (equal (org-get-at-bol 'org-hd-marker)
3569 org-clock-hd-marker)
3570 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3571 (overlay-put ov 'type 'org-agenda-clocking)
3572 (overlay-put ov 'face 'org-agenda-clocking)
3573 (overlay-put ov 'help-echo
3574 "The clock is running in this item")))))))
3576 (defun org-agenda-fontify-priorities ()
3577 "Make highest priority lines bold, and lowest italic."
3578 (interactive)
3579 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3580 (delete-overlay o)))
3581 (overlays-in (point-min) (point-max)))
3582 (save-excursion
3583 (let ((inhibit-read-only t)
3584 b e p ov h l)
3585 (goto-char (point-min))
3586 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3587 (setq h (or (get-char-property (point) 'org-highest-priority)
3588 org-highest-priority)
3589 l (or (get-char-property (point) 'org-lowest-priority)
3590 org-lowest-priority)
3591 p (string-to-char (match-string 1))
3592 b (match-beginning 0)
3593 e (if (eq org-agenda-fontify-priorities 'cookies)
3594 (match-end 0)
3595 (point-at-eol))
3596 ov (make-overlay b e))
3597 (overlay-put
3598 ov 'face
3599 (cond ((org-face-from-face-or-color
3600 'priority nil
3601 (cdr (assoc p org-priority-faces))))
3602 ((and (listp org-agenda-fontify-priorities)
3603 (org-face-from-face-or-color
3604 'priority nil
3605 (cdr (assoc p org-agenda-fontify-priorities)))))
3606 ((equal p l) 'italic)
3607 ((equal p h) 'bold)))
3608 (overlay-put ov 'org-type 'org-priority)))))
3610 (defun org-agenda-dim-blocked-tasks ()
3611 "Dim currently blocked TODO's in the agenda display."
3612 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3613 (delete-overlay o)))
3614 (overlays-in (point-min) (point-max)))
3615 (save-excursion
3616 (let ((inhibit-read-only t)
3617 (org-depend-tag-blocked nil)
3618 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3619 org-blocked-by-checkboxes
3620 invis1 b e p ov h l)
3621 (goto-char (point-min))
3622 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3623 (and pos (goto-char (1+ pos))))
3624 (setq org-blocked-by-checkboxes nil invis1 invis)
3625 (let ((marker (org-get-at-bol 'org-hd-marker)))
3626 (when (and marker
3627 (with-current-buffer (marker-buffer marker)
3628 (save-excursion (goto-char marker)
3629 (org-entry-blocked-p))))
3630 (if org-blocked-by-checkboxes (setq invis1 nil))
3631 (setq b (if invis1
3632 (max (point-min) (1- (point-at-bol)))
3633 (point-at-bol))
3634 e (point-at-eol)
3635 ov (make-overlay b e))
3636 (if invis1
3637 (overlay-put ov 'invisible t)
3638 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3639 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3641 (defvar org-agenda-skip-function nil
3642 "Function to be called at each match during agenda construction.
3643 If this function returns nil, the current match should not be skipped.
3644 Otherwise, the function must return a position from where the search
3645 should be continued.
3646 This may also be a Lisp form, it will be evaluated.
3647 Never set this variable using `setq' or so, because then it will apply
3648 to all future agenda commands. If you do want a global skipping condition,
3649 use the option `org-agenda-skip-function-global' instead.
3650 The correct usage for `org-agenda-skip-function' is to bind it with
3651 `let' to scope it dynamically into the agenda-constructing command.
3652 A good way to set it is through options in `org-agenda-custom-commands'.")
3654 (defun org-agenda-skip ()
3655 "Throw to `:skip' in places that should be skipped.
3656 Also moves point to the end of the skipped region, so that search can
3657 continue from there."
3658 (let ((p (point-at-bol)) to)
3659 (when (org-in-src-block-p) (throw :skip t))
3660 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3661 (get-text-property p :org-archived)
3662 (org-end-of-subtree t)
3663 (throw :skip t))
3664 (and org-agenda-skip-comment-trees
3665 (get-text-property p :org-comment)
3666 (org-end-of-subtree t)
3667 (throw :skip t))
3668 (if (equal (char-after p) ?#) (throw :skip t))
3669 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3670 (org-agenda-skip-eval org-agenda-skip-function)))
3671 (goto-char to)
3672 (throw :skip t))))
3674 (defun org-agenda-skip-eval (form)
3675 "If FORM is a function or a list, call (or eval) is and return result.
3676 `save-excursion' and `save-match-data' are wrapped around the call, so point
3677 and match data are returned to the previous state no matter what these
3678 functions do."
3679 (let (fp)
3680 (and form
3681 (or (setq fp (functionp form))
3682 (consp form))
3683 (save-excursion
3684 (save-match-data
3685 (if fp
3686 (funcall form)
3687 (eval form)))))))
3689 (defvar org-agenda-markers nil
3690 "List of all currently active markers created by `org-agenda'.")
3691 (defvar org-agenda-last-marker-time (org-float-time)
3692 "Creation time of the last agenda marker.")
3694 (defun org-agenda-new-marker (&optional pos)
3695 "Return a new agenda marker.
3696 Org-mode keeps a list of these markers and resets them when they are
3697 no longer in use."
3698 (let ((m (copy-marker (or pos (point)))))
3699 (setq org-agenda-last-marker-time (org-float-time))
3700 (if org-agenda-buffer
3701 (with-current-buffer org-agenda-buffer
3702 (push m org-agenda-markers))
3703 (push m org-agenda-markers))
3706 (defun org-agenda-reset-markers ()
3707 "Reset markers created by `org-agenda'."
3708 (while org-agenda-markers
3709 (move-marker (pop org-agenda-markers) nil)))
3711 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3712 "Save relative positions of markers in region.
3713 This check for agenda markers in all agenda buffers currently active."
3714 (dolist (buf (buffer-list))
3715 (with-current-buffer buf
3716 (when (eq major-mode 'org-agenda-mode)
3717 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3718 org-agenda-markers)))))
3720 ;;; Entry text mode
3722 (defun org-agenda-entry-text-show-here ()
3723 "Add some text from the entry as context to the current line."
3724 (let (m txt o)
3725 (setq m (org-get-at-bol 'org-hd-marker))
3726 (unless (marker-buffer m)
3727 (error "No marker points to an entry here"))
3728 (setq txt (concat "\n" (org-no-properties
3729 (org-agenda-get-some-entry-text
3730 m org-agenda-entry-text-maxlines " > "))))
3731 (when (string-match "\\S-" txt)
3732 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3733 (overlay-put o 'evaporate t)
3734 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3735 (overlay-put o 'after-string txt))))
3737 (defun org-agenda-entry-text-show ()
3738 "Add entry context for all agenda lines."
3739 (interactive)
3740 (save-excursion
3741 (goto-char (point-max))
3742 (beginning-of-line 1)
3743 (while (not (bobp))
3744 (when (org-get-at-bol 'org-hd-marker)
3745 (org-agenda-entry-text-show-here))
3746 (beginning-of-line 0))))
3748 (defun org-agenda-entry-text-hide ()
3749 "Remove any shown entry context."
3750 (delq nil
3751 (mapcar (lambda (o)
3752 (if (eq (overlay-get o 'org-overlay-type)
3753 'agenda-entry-content)
3754 (progn (delete-overlay o) t)))
3755 (overlays-in (point-min) (point-max)))))
3757 (defun org-agenda-get-day-face (date)
3758 "Return the face DATE should be displayed with."
3759 (or (and (functionp org-agenda-day-face-function)
3760 (funcall org-agenda-day-face-function date))
3761 (cond ((org-agenda-todayp date)
3762 'org-agenda-date-today)
3763 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3764 'org-agenda-date-weekend)
3765 (t 'org-agenda-date))))
3767 ;;; Agenda timeline
3769 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3771 (defun org-timeline (&optional dotodo)
3772 "Show a time-sorted view of the entries in the current org file.
3773 Only entries with a time stamp of today or later will be listed. With
3774 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3775 under the current date.
3776 If the buffer contains an active region, only check the region for
3777 dates."
3778 (interactive "P")
3779 (let* ((dopast t)
3780 (org-agenda-show-log-scoped org-agenda-show-log)
3781 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3782 (current-buffer))))
3783 (date (calendar-current-date))
3784 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3785 (end (if (org-region-active-p) (region-end) (point-max)))
3786 (day-numbers (org-get-all-dates
3787 beg end 'no-ranges
3788 t org-agenda-show-log-scoped ; always include today
3789 org-timeline-show-empty-dates))
3790 (org-deadline-warning-days 0)
3791 (org-agenda-only-exact-dates t)
3792 (today (org-today))
3793 (past t)
3794 args
3795 s e rtn d emptyp)
3796 (setq org-agenda-redo-command
3797 (list 'progn
3798 (list 'org-switch-to-buffer-other-window (current-buffer))
3799 (list 'org-timeline (list 'quote dotodo))))
3800 (if (not dopast)
3801 ;; Remove past dates from the list of dates.
3802 (setq day-numbers (delq nil (mapcar (lambda(x)
3803 (if (>= x today) x nil))
3804 day-numbers))))
3805 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3806 (org-compile-prefix-format 'timeline)
3807 (org-set-sorting-strategy 'timeline)
3808 (if org-agenda-show-log-scoped (push :closed args))
3809 (push :timestamp args)
3810 (push :deadline args)
3811 (push :scheduled args)
3812 (push :sexp args)
3813 (if dotodo (push :todo args))
3814 (insert "Timeline of file " entry "\n")
3815 (add-text-properties (point-min) (point)
3816 (list 'face 'org-agenda-structure))
3817 (org-agenda-mark-header-line (point-min))
3818 (while (setq d (pop day-numbers))
3819 (if (and (listp d) (eq (car d) :omitted))
3820 (progn
3821 (setq s (point))
3822 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3823 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3824 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3825 (if (and (>= d today)
3826 dopast
3827 past)
3828 (progn
3829 (setq past nil)
3830 (insert (make-string 79 ?-) "\n")))
3831 (setq date (calendar-gregorian-from-absolute d))
3832 (setq s (point))
3833 (setq rtn (and (not emptyp)
3834 (apply 'org-agenda-get-day-entries entry
3835 date args)))
3836 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3837 (progn
3838 (insert
3839 (if (stringp org-agenda-format-date)
3840 (format-time-string org-agenda-format-date
3841 (org-time-from-absolute date))
3842 (funcall org-agenda-format-date date))
3843 "\n")
3844 (put-text-property s (1- (point)) 'face
3845 (org-agenda-get-day-face date))
3846 (put-text-property s (1- (point)) 'org-date-line t)
3847 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3848 (if (equal d today)
3849 (put-text-property s (1- (point)) 'org-today t))
3850 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3851 (put-text-property s (1- (point)) 'day d)))))
3852 (goto-char (point-min))
3853 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3854 (point-min)))
3855 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3856 (org-agenda-finalize)
3857 (setq buffer-read-only t)))
3859 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3860 "Return a list of all relevant day numbers from BEG to END buffer positions.
3861 If NO-RANGES is non-nil, include only the start and end dates of a range,
3862 not every single day in the range. If FORCE-TODAY is non-nil, make
3863 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3864 inactive time stamps (those in square brackets) are included.
3865 When EMPTY is non-nil, also include days without any entries."
3866 (let ((re (concat
3867 (if pre-re pre-re "")
3868 (if inactive org-ts-regexp-both org-ts-regexp)))
3869 dates dates1 date day day1 day2 ts1 ts2 pos)
3870 (if force-today
3871 (setq dates (list (org-today))))
3872 (save-excursion
3873 (goto-char beg)
3874 (while (re-search-forward re end t)
3875 (setq day (time-to-days (org-time-string-to-time
3876 (substring (match-string 1) 0 10)
3877 (current-buffer) (match-beginning 0))))
3878 (or (memq day dates) (push day dates)))
3879 (unless no-ranges
3880 (goto-char beg)
3881 (while (re-search-forward org-tr-regexp end t)
3882 (setq pos (match-beginning 0))
3883 (setq ts1 (substring (match-string 1) 0 10)
3884 ts2 (substring (match-string 2) 0 10)
3885 day1 (time-to-days (org-time-string-to-time
3886 ts1 (current-buffer) pos))
3887 day2 (time-to-days (org-time-string-to-time
3888 ts2 (current-buffer) pos)))
3889 (while (< (setq day1 (1+ day1)) day2)
3890 (or (memq day1 dates) (push day1 dates)))))
3891 (setq dates (sort dates '<))
3892 (when empty
3893 (while (setq day (pop dates))
3894 (setq day2 (car dates))
3895 (push day dates1)
3896 (when (and day2 empty)
3897 (if (or (eq empty t)
3898 (and (numberp empty) (<= (- day2 day) empty)))
3899 (while (< (setq day (1+ day)) day2)
3900 (push (list day) dates1))
3901 (push (cons :omitted (- day2 day)) dates1))))
3902 (setq dates (nreverse dates1)))
3903 dates)))
3905 ;;; Agenda Daily/Weekly
3907 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3908 "Start day for the agenda view.
3909 Custom commands can set this variable in the options section.")
3910 (defvar org-starting-day nil) ; local variable in the agenda buffer
3911 (defvar org-arg-loc nil) ; local variable
3913 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3914 "List of types searched for when creating the daily/weekly agenda.
3915 This variable is a list of symbols that controls the types of
3916 items that appear in the daily/weekly agenda. Allowed symbols in this
3917 list are are
3919 :timestamp List items containing a date stamp or date range matching
3920 the selected date. This includes sexp entries in
3921 angular brackets.
3923 :sexp List entries resulting from plain diary-like sexps.
3925 :deadline List deadline due on that date. When the date is today,
3926 also list any deadlines past due, or due within
3927 `org-deadline-warning-days'. `:deadline' must appear before
3928 `:scheduled' if the setting of
3929 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3930 any effect.
3932 :scheduled List all items which are scheduled for the given date.
3933 The diary for *today* also contains items which were
3934 scheduled earlier and are not yet marked DONE.
3936 By default, all four types are turned on.
3938 Never set this variable globally using `setq', because then it
3939 will apply to all future agenda commands. Instead, bind it with
3940 `let' to scope it dynamically into the agenda-constructing
3941 command. A good way to set it is through options in
3942 `org-agenda-custom-commands'. For a more flexible (though
3943 somewhat less efficient) way of determining what is included in
3944 the daily/weekly agenda, see `org-agenda-skip-function'.")
3946 (defvar org-agenda-buffer-tmp-name nil)
3947 ;;;###autoload
3948 (defun org-agenda-list (&optional arg start-day span)
3949 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3950 The view will be for the current day or week, but from the overview buffer
3951 you will be able to go to other days/weeks.
3953 With a numeric prefix argument in an interactive call, the agenda will
3954 span ARG days. Lisp programs should instead specify SPAN to change
3955 the number of days. SPAN defaults to `org-agenda-span'.
3957 START-DAY defaults to TODAY, or to the most recent match for the weekday
3958 given in `org-agenda-start-on-weekday'."
3959 (interactive "P")
3960 (if org-agenda-overriding-arguments
3961 (setq arg (car org-agenda-overriding-arguments)
3962 start-day (nth 1 org-agenda-overriding-arguments)
3963 span (nth 2 org-agenda-overriding-arguments)))
3964 (if (and (integerp arg) (> arg 0))
3965 (setq span arg arg nil))
3966 (catch 'exit
3967 (setq org-agenda-buffer-name
3968 (or org-agenda-buffer-tmp-name
3969 (if org-agenda-sticky
3970 (cond ((and org-keys (stringp org-match))
3971 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3972 (org-keys
3973 (format "*Org Agenda(%s)*" org-keys))
3974 (t "*Org Agenda(a)*")))
3975 org-agenda-buffer-name))
3976 (org-agenda-prepare "Day/Week")
3977 (setq start-day (or start-day org-agenda-start-day))
3978 (if (stringp start-day)
3979 ;; Convert to an absolute day number
3980 (setq start-day (time-to-days (org-read-date nil t start-day))))
3981 (org-compile-prefix-format 'agenda)
3982 (org-set-sorting-strategy 'agenda)
3983 (let* ((span (org-agenda-ndays-to-span
3984 (or span org-agenda-ndays org-agenda-span)))
3985 (today (org-today))
3986 (sd (or start-day today))
3987 (ndays (org-agenda-span-to-ndays span sd))
3988 (org-agenda-start-on-weekday
3989 (if (eq ndays 7)
3990 org-agenda-start-on-weekday))
3991 (thefiles (org-agenda-files nil 'ifmode))
3992 (files thefiles)
3993 (start (if (or (null org-agenda-start-on-weekday)
3994 (< ndays 7))
3996 (let* ((nt (calendar-day-of-week
3997 (calendar-gregorian-from-absolute sd)))
3998 (n1 org-agenda-start-on-weekday)
3999 (d (- nt n1)))
4000 (- sd (+ (if (< d 0) 7 0) d)))))
4001 (day-numbers (list start))
4002 (day-cnt 0)
4003 (inhibit-redisplay (not debug-on-error))
4004 (org-agenda-show-log-scoped org-agenda-show-log)
4005 s e rtn rtnall file date d start-pos end-pos todayp
4006 clocktable-start clocktable-end filter)
4007 (setq org-agenda-redo-command
4008 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4009 (dotimes (n (1- ndays))
4010 (push (1+ (car day-numbers)) day-numbers))
4011 (setq day-numbers (nreverse day-numbers))
4012 (setq clocktable-start (car day-numbers)
4013 clocktable-end (1+ (or (org-last day-numbers) 0)))
4014 (org-set-local 'org-starting-day (car day-numbers))
4015 (org-set-local 'org-arg-loc arg)
4016 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4017 (unless org-agenda-compact-blocks
4018 (let* ((d1 (car day-numbers))
4019 (d2 (org-last day-numbers))
4020 (w1 (org-days-to-iso-week d1))
4021 (w2 (org-days-to-iso-week d2)))
4022 (setq s (point))
4023 (if org-agenda-overriding-header
4024 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4025 nil 'face 'org-agenda-structure) "\n")
4026 (insert (org-agenda-span-name span)
4027 "-agenda"
4028 (if (< (- d2 d1) 350)
4029 (if (= w1 w2)
4030 (format " (W%02d)" w1)
4031 (format " (W%02d-W%02d)" w1 w2))
4033 ":\n")))
4034 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4035 'org-date-line t))
4036 (org-agenda-mark-header-line s))
4037 (while (setq d (pop day-numbers))
4038 (setq date (calendar-gregorian-from-absolute d)
4039 s (point))
4040 (if (or (setq todayp (= d today))
4041 (and (not start-pos) (= d sd)))
4042 (setq start-pos (point))
4043 (if (and start-pos (not end-pos))
4044 (setq end-pos (point))))
4045 (setq files thefiles
4046 rtnall nil)
4047 (while (setq file (pop files))
4048 (catch 'nextfile
4049 (org-check-agenda-file file)
4050 (let ((org-agenda-entry-types org-agenda-entry-types))
4051 (unless org-agenda-include-deadlines
4052 (setq org-agenda-entry-types
4053 (delq :deadline org-agenda-entry-types)))
4054 (cond
4055 ((memq org-agenda-show-log-scoped '(only clockcheck))
4056 (setq rtn (org-agenda-get-day-entries
4057 file date :closed)))
4058 (org-agenda-show-log-scoped
4059 (setq rtn (apply 'org-agenda-get-day-entries
4060 file date
4061 (append '(:closed) org-agenda-entry-types))))
4063 (setq rtn (apply 'org-agenda-get-day-entries
4064 file date
4065 org-agenda-entry-types)))))
4066 (setq rtnall (append rtnall rtn)))) ;; all entries
4067 (if org-agenda-include-diary
4068 (let ((org-agenda-search-headline-for-time t))
4069 (require 'diary-lib)
4070 (setq rtn (org-get-entries-from-diary date))
4071 (setq rtnall (append rtnall rtn))))
4072 (if (or rtnall org-agenda-show-all-dates)
4073 (progn
4074 (setq day-cnt (1+ day-cnt))
4075 (insert
4076 (if (stringp org-agenda-format-date)
4077 (format-time-string org-agenda-format-date
4078 (org-time-from-absolute date))
4079 (funcall org-agenda-format-date date))
4080 "\n")
4081 (put-text-property s (1- (point)) 'face
4082 (org-agenda-get-day-face date))
4083 (put-text-property s (1- (point)) 'org-date-line t)
4084 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4085 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4086 (when todayp
4087 (put-text-property s (1- (point)) 'org-today t))
4088 (setq rtnall
4089 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4090 (if rtnall (insert ;; all entries
4091 (org-agenda-finalize-entries rtnall)
4092 "\n"))
4093 (put-text-property s (1- (point)) 'day d)
4094 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4095 (when (and org-agenda-clockreport-mode clocktable-start)
4096 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4097 ;; the above line is to ensure the restricted range!
4098 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4099 tbl)
4100 (setq p (org-plist-delete p :block))
4101 (setq p (plist-put p :tstart clocktable-start))
4102 (setq p (plist-put p :tend clocktable-end))
4103 (setq p (plist-put p :scope 'agenda))
4104 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4105 (setq filter (or org-agenda-tag-filter-while-redo
4106 (get 'org-agenda-tag-filter :preset-filter))))
4107 (setq p (plist-put p :tags (mapconcat (lambda (x)
4108 (if (string-match "[<>=]" x)
4111 filter ""))))
4112 (setq tbl (apply 'org-clock-get-clocktable p))
4113 (insert tbl)))
4114 (goto-char (point-min))
4115 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4116 (unless (and (pos-visible-in-window-p (point-min))
4117 (pos-visible-in-window-p (point-max)))
4118 (goto-char (1- (point-max)))
4119 (recenter -1)
4120 (if (not (pos-visible-in-window-p (or start-pos 1)))
4121 (progn
4122 (goto-char (or start-pos 1))
4123 (recenter 1))))
4124 (goto-char (or start-pos 1))
4125 (add-text-properties (point-min) (point-max)
4126 `(org-agenda-type agenda
4127 org-last-args (,arg ,start-day ,span)
4128 org-redo-cmd ,org-agenda-redo-command
4129 org-series-cmd ,org-cmd))
4130 (if (eq org-agenda-show-log-scoped 'clockcheck)
4131 (org-agenda-show-clocking-issues))
4132 (org-agenda-finalize)
4133 (setq buffer-read-only t)
4134 (message ""))))
4136 (autoload 'org-agenda-list "org-agenda" "\
4137 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4138 The view will be for the current day or week, but from the overview buffer
4139 you will be able to go to other days/weeks.
4141 With a numeric prefix argument in an interactive call, the agenda will
4142 span ARG days. Lisp programs should instead specify SPAN to change
4143 the number of days. SPAN defaults to `org-agenda-span'.
4145 START-DAY defaults to TODAY, or to the most recent match for the weekday
4146 given in `org-agenda-start-on-weekday'.
4148 \(fn &optional ARG START-DAY SPAN)" t nil)
4150 (defun org-agenda-ndays-to-span (n)
4151 "Return a span symbol for a span of N days, or N if none matches."
4152 (cond ((symbolp n) n)
4153 ((= n 1) 'day)
4154 ((= n 7) 'week)
4155 (t n)))
4157 (defun org-agenda-span-to-ndays (span &optional start-day)
4158 "Return ndays from SPAN, possibly starting at START-DAY."
4159 (cond ((numberp span) span)
4160 ((eq span 'day) 1)
4161 ((eq span 'week) 7)
4162 ((eq span 'month)
4163 (let ((date (calendar-gregorian-from-absolute start-day)))
4164 (calendar-last-day-of-month (car date) (caddr date))))
4165 ((eq span 'year)
4166 (let ((date (calendar-gregorian-from-absolute start-day)))
4167 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4169 (defun org-agenda-span-name (span)
4170 "Return a SPAN name."
4171 (if (null span)
4173 (if (symbolp span)
4174 (capitalize (symbol-name span))
4175 (format "%d days" span))))
4177 ;;; Agenda word search
4179 (defvar org-agenda-search-history nil)
4181 (defvar org-search-syntax-table nil
4182 "Special syntax table for org-mode search.
4183 In this table, we have single quotes not as word constituents, to
4184 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4186 (defvar org-mode-syntax-table) ; From org.el
4187 (defun org-search-syntax-table ()
4188 (unless org-search-syntax-table
4189 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4190 (modify-syntax-entry ?' "." org-search-syntax-table)
4191 (modify-syntax-entry ?` "." org-search-syntax-table))
4192 org-search-syntax-table)
4194 (defvar org-agenda-last-search-view-search-was-boolean nil)
4196 ;;;###autoload
4197 (defun org-search-view (&optional todo-only string edit-at)
4198 "Show all entries that contain a phrase or words or regular expressions.
4200 With optional prefix argument TODO-ONLY, only consider entries that are
4201 TODO entries. The argument STRING can be used to pass a default search
4202 string into this function. If EDIT-AT is non-nil, it means that the
4203 user should get a chance to edit this string, with cursor at position
4204 EDIT-AT.
4206 The search string can be viewed either as a phrase that should be found as
4207 is, or it can be broken into a number of snippets, each of which must match
4208 in a Boolean way to select an entry. The default depends on the variable
4209 `org-agenda-search-view-always-boolean'.
4210 Even if this is turned off (the default) you can always switch to
4211 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4213 The default is a direct search of the whole phrase, where each space in
4214 the search string can expand to an arbitrary amount of whitespace,
4215 including newlines.
4217 If using a Boolean search, the search string is split on whitespace and
4218 each snippet is searched separately, with logical AND to select an entry.
4219 Words prefixed with a minus must *not* occur in the entry. Words without
4220 a prefix or prefixed with a plus must occur in the entry. Matching is
4221 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4222 match whole words, not parts of a word) if
4223 `org-agenda-search-view-force-full-words' is set (default is nil).
4225 Boolean search snippets enclosed by curly braces are interpreted as
4226 regular expressions that must or (when preceded with \"-\") must not
4227 match in the entry. Snippets enclosed into double quotes will be taken
4228 as a whole, to include whitespace.
4230 - If the search string starts with an asterisk, search only in headlines.
4231 - If (possibly after the leading star) the search string starts with an
4232 exclamation mark, this also means to look at TODO entries only, an effect
4233 that can also be achieved with a prefix argument.
4234 - If (possibly after star and exclamation mark) the search string starts
4235 with a colon, this will mean that the (non-regexp) snippets of the
4236 Boolean search must match as full words.
4238 This command searches the agenda files, and in addition the files listed
4239 in `org-agenda-text-search-extra-files'."
4240 (interactive "P")
4241 (if org-agenda-overriding-arguments
4242 (setq todo-only (car org-agenda-overriding-arguments)
4243 string (nth 1 org-agenda-overriding-arguments)
4244 edit-at (nth 2 org-agenda-overriding-arguments)))
4245 (let* ((props (list 'face nil
4246 'done-face 'org-agenda-done
4247 'org-not-done-regexp org-not-done-regexp
4248 'org-todo-regexp org-todo-regexp
4249 'org-complex-heading-regexp org-complex-heading-regexp
4250 'mouse-face 'highlight
4251 'help-echo (format "mouse-2 or RET jump to location")))
4252 (full-words org-agenda-search-view-force-full-words)
4253 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4254 regexp rtn rtnall files file pos
4255 marker category category-pos tags c neg re boolean
4256 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4257 (unless (and (not edit-at)
4258 (stringp string)
4259 (string-match "\\S-" string))
4260 (setq string (read-string
4261 (if org-agenda-search-view-always-boolean
4262 "[+-]Word/{Regexp} ...: "
4263 "Phrase or [+-]Word/{Regexp} ...: ")
4264 (cond
4265 ((integerp edit-at) (cons string edit-at))
4266 (edit-at string))
4267 'org-agenda-search-history)))
4268 (catch 'exit
4269 (if org-agenda-sticky
4270 (setq org-agenda-buffer-name
4271 (if (stringp string)
4272 (format "*Org Agenda(%s:%s)*"
4273 (or org-keys (or (and todo-only "S") "s")) string)
4274 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4275 (org-agenda-prepare "SEARCH")
4276 (org-compile-prefix-format 'search)
4277 (org-set-sorting-strategy 'search)
4278 (setq org-agenda-redo-command
4279 (list 'org-search-view (if todo-only t nil)
4280 (list 'if 'current-prefix-arg nil string)))
4281 (setq org-agenda-query-string string)
4282 (if (equal (string-to-char string) ?*)
4283 (setq hdl-only t
4284 words (substring string 1))
4285 (setq words string))
4286 (when (equal (string-to-char words) ?!)
4287 (setq todo-only t
4288 words (substring words 1)))
4289 (when (equal (string-to-char words) ?:)
4290 (setq full-words t
4291 words (substring words 1)))
4292 (if (or org-agenda-search-view-always-boolean
4293 (member (string-to-char words) '(?- ?+ ?\{)))
4294 (setq boolean t))
4295 (setq words (org-split-string words))
4296 (let (www w)
4297 (while (setq w (pop words))
4298 (while (and (string-match "\\\\\\'" w) words)
4299 (setq w (concat (substring w 0 -1) " " (pop words))))
4300 (push w www))
4301 (setq words (nreverse www) www nil)
4302 (while (setq w (pop words))
4303 (when (and (string-match "\\`[-+]?{" w)
4304 (not (string-match "}\\'" w)))
4305 (while (and words (not (string-match "}\\'" (car words))))
4306 (setq w (concat w " " (pop words))))
4307 (setq w (concat w " " (pop words))))
4308 (push w www))
4309 (setq words (nreverse www)))
4310 (setq org-agenda-last-search-view-search-was-boolean boolean)
4311 (when boolean
4312 (let (wds w)
4313 (while (setq w (pop words))
4314 (if (or (equal (substring w 0 1) "\"")
4315 (and (> (length w) 1)
4316 (member (substring w 0 1) '("+" "-"))
4317 (equal (substring w 1 2) "\"")))
4318 (while (and words (not (equal (substring w -1) "\"")))
4319 (setq w (concat w " " (pop words)))))
4320 (and (string-match "\\`\\([-+]?\\)\"" w)
4321 (setq w (replace-match "\\1" nil nil w)))
4322 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4323 (push w wds))
4324 (setq words (nreverse wds))))
4325 (if boolean
4326 (mapc (lambda (w)
4327 (setq c (string-to-char w))
4328 (if (equal c ?-)
4329 (setq neg t w (substring w 1))
4330 (if (equal c ?+)
4331 (setq neg nil w (substring w 1))
4332 (setq neg nil)))
4333 (if (string-match "\\`{.*}\\'" w)
4334 (setq re (substring w 1 -1))
4335 (if full-words
4336 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4337 (setq re (regexp-quote (downcase w)))))
4338 (if neg (push re regexps-) (push re regexps+)))
4339 words)
4340 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4341 regexps+))
4342 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4343 (if (not regexps+)
4344 (setq regexp org-outline-regexp-bol)
4345 (setq regexp (pop regexps+))
4346 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4347 regexp))))
4348 (setq files (org-agenda-files nil 'ifmode))
4349 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4350 (pop org-agenda-text-search-extra-files)
4351 (setq files (org-add-archive-files files)))
4352 (setq files (append files org-agenda-text-search-extra-files)
4353 rtnall nil)
4354 (while (setq file (pop files))
4355 (setq ee nil)
4356 (catch 'nextfile
4357 (org-check-agenda-file file)
4358 (setq buffer (if (file-exists-p file)
4359 (org-get-agenda-file-buffer file)
4360 (error "No such file %s" file)))
4361 (if (not buffer)
4362 ;; If file does not exist, make sure an error message is sent
4363 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4364 file))))
4365 (with-current-buffer buffer
4366 (with-syntax-table (org-search-syntax-table)
4367 (unless (derived-mode-p 'org-mode)
4368 (error "Agenda file %s is not in `org-mode'" file))
4369 (let ((case-fold-search t))
4370 (save-excursion
4371 (save-restriction
4372 (if org-agenda-restrict
4373 (narrow-to-region org-agenda-restrict-begin
4374 org-agenda-restrict-end)
4375 (widen))
4376 (goto-char (point-min))
4377 (unless (or (org-at-heading-p)
4378 (outline-next-heading))
4379 (throw 'nextfile t))
4380 (goto-char (max (point-min) (1- (point))))
4381 (while (re-search-forward regexp nil t)
4382 (org-back-to-heading t)
4383 (skip-chars-forward "* ")
4384 (setq beg (point-at-bol)
4385 beg1 (point)
4386 end (progn (outline-next-heading) (point)))
4387 (catch :skip
4388 (goto-char beg)
4389 (org-agenda-skip)
4390 (setq str (buffer-substring-no-properties
4391 (point-at-bol)
4392 (if hdl-only (point-at-eol) end)))
4393 (mapc (lambda (wr) (when (string-match wr str)
4394 (goto-char (1- end))
4395 (throw :skip t)))
4396 regexps-)
4397 (mapc (lambda (wr) (unless (string-match wr str)
4398 (goto-char (1- end))
4399 (throw :skip t)))
4400 (if todo-only
4401 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4402 regexps+)
4403 regexps+))
4404 (goto-char beg)
4405 (setq marker (org-agenda-new-marker (point))
4406 category (org-get-category)
4407 category-pos (get-text-property (point) 'org-category-position)
4408 tags (org-get-tags-at (point))
4409 txt (org-agenda-format-item
4411 (buffer-substring-no-properties
4412 beg1 (point-at-eol))
4413 category tags t))
4414 (org-add-props txt props
4415 'org-marker marker 'org-hd-marker marker
4416 'org-todo-regexp org-todo-regexp
4417 'org-complex-heading-regexp org-complex-heading-regexp
4418 'priority 1000 'org-category category
4419 'org-category-position category-pos
4420 'type "search")
4421 (push txt ee)
4422 (goto-char (1- end))))))))))
4423 (setq rtn (nreverse ee))
4424 (setq rtnall (append rtnall rtn)))
4425 (if org-agenda-overriding-header
4426 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4427 nil 'face 'org-agenda-structure) "\n")
4428 (insert "Search words: ")
4429 (add-text-properties (point-min) (1- (point))
4430 (list 'face 'org-agenda-structure))
4431 (setq pos (point))
4432 (insert string "\n")
4433 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4434 (setq pos (point))
4435 (unless org-agenda-multi
4436 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4437 (add-text-properties pos (1- (point))
4438 (list 'face 'org-agenda-structure))))
4439 (org-agenda-mark-header-line (point-min))
4440 (when rtnall
4441 (insert (org-agenda-finalize-entries rtnall) "\n"))
4442 (goto-char (point-min))
4443 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4444 (add-text-properties (point-min) (point-max)
4445 `(org-agenda-type search
4446 org-last-args (,todo-only ,string ,edit-at)
4447 org-redo-cmd ,org-agenda-redo-command
4448 org-series-cmd ,org-cmd))
4449 (org-agenda-finalize)
4450 (setq buffer-read-only t))))
4452 (autoload 'org-search-view "org-agenda" "\
4453 Show all entries that contain a phrase or words or regular expressions.
4455 With optional prefix argument TODO-ONLY, only consider entries that are
4456 TODO entries. The argument STRING can be used to pass a default search
4457 string into this function. If EDIT-AT is non-nil, it means that the
4458 user should get a chance to edit this string, with cursor at position
4459 EDIT-AT.
4461 The search string can be viewed either as a phrase that should be found as
4462 is, or it can be broken into a number of snippets, each of which must match
4463 in a Boolean way to select an entry. The default depends on the variable
4464 `org-agenda-search-view-always-boolean'.
4465 Even if this is turned off (the default) you can always switch to
4466 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4468 The default is a direct search of the whole phrase, where each space in
4469 the search string can expand to an arbitrary amount of whitespace,
4470 including newlines.
4472 If using a Boolean search, the search string is split on whitespace and
4473 each snippet is searched separately, with logical AND to select an entry.
4474 Words prefixed with a minus must *not* occur in the entry. Words without
4475 a prefix or prefixed with a plus must occur in the entry. Matching is
4476 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4477 match whole words, not parts of a word) if
4478 `org-agenda-search-view-force-full-words' is set (default is nil).
4480 Boolean search snippets enclosed by curly braces are interpreted as
4481 regular expressions that must or (when preceded with \"-\") must not
4482 match in the entry. Snippets enclosed into double quotes will be taken
4483 as a whole, to include whitespace.
4485 - If the search string starts with an asterisk, search only in headlines.
4486 - If (possibly after the leading star) the search string starts with an
4487 exclamation mark, this also means to look at TODO entries only, an effect
4488 that can also be achieved with a prefix argument.
4489 - If (possibly after star and exclamation mark) the search string starts
4490 with a colon, this will mean that the (non-regexp) snippets of the
4491 Boolean search must match as full words.
4493 This command searches the agenda files, and in addition the files listed
4494 in `org-agenda-text-search-extra-files'.
4496 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4498 ;;; Agenda TODO list
4500 (defvar org-select-this-todo-keyword nil)
4501 (defvar org-last-arg nil)
4503 ;;;###autoload
4504 (defun org-todo-list (&optional arg)
4505 "Show all (not done) TODO entries from all agenda file in a single list.
4506 The prefix arg can be used to select a specific TODO keyword and limit
4507 the list to these. When using \\[universal-argument], you will be prompted
4508 for a keyword. A numeric prefix directly selects the Nth keyword in
4509 `org-todo-keywords-1'."
4510 (interactive "P")
4511 (if org-agenda-overriding-arguments
4512 (setq arg org-agenda-overriding-arguments))
4513 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4514 (let* ((today (org-today))
4515 (date (calendar-gregorian-from-absolute today))
4516 (kwds org-todo-keywords-for-agenda)
4517 (completion-ignore-case t)
4518 (org-select-this-todo-keyword
4519 (if (stringp arg) arg
4520 (and arg (integerp arg) (> arg 0)
4521 (nth (1- arg) kwds))))
4522 rtn rtnall files file pos)
4523 (when (equal arg '(4))
4524 (setq org-select-this-todo-keyword
4525 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4526 (mapcar 'list kwds) nil nil)))
4527 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4528 (catch 'exit
4529 (if org-agenda-sticky
4530 (setq org-agenda-buffer-name
4531 (if (stringp org-select-this-todo-keyword)
4532 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4533 org-select-this-todo-keyword)
4534 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4535 (org-agenda-prepare "TODO")
4536 (org-compile-prefix-format 'todo)
4537 (org-set-sorting-strategy 'todo)
4538 (setq org-agenda-redo-command
4539 `(org-todo-list (or (and (numberp current-prefix-arg)
4540 current-prefix-arg)
4541 ,org-select-this-todo-keyword
4542 current-prefix-arg ,arg)))
4543 (setq files (org-agenda-files nil 'ifmode)
4544 rtnall nil)
4545 (while (setq file (pop files))
4546 (catch 'nextfile
4547 (org-check-agenda-file file)
4548 (setq rtn (org-agenda-get-day-entries file date :todo))
4549 (setq rtnall (append rtnall rtn))))
4550 (if org-agenda-overriding-header
4551 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4552 nil 'face 'org-agenda-structure) "\n")
4553 (insert "Global list of TODO items of type: ")
4554 (add-text-properties (point-min) (1- (point))
4555 (list 'face 'org-agenda-structure
4556 'short-heading
4557 (concat "ToDo: "
4558 (or org-select-this-todo-keyword "ALL"))))
4559 (org-agenda-mark-header-line (point-min))
4560 (setq pos (point))
4561 (insert (or org-select-this-todo-keyword "ALL") "\n")
4562 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4563 (setq pos (point))
4564 (unless org-agenda-multi
4565 (insert "Available with `N r': (0)[ALL]")
4566 (let ((n 0) s)
4567 (mapc (lambda (x)
4568 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4569 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4570 (insert "\n "))
4571 (insert " " s))
4572 kwds))
4573 (insert "\n"))
4574 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4575 (org-agenda-mark-header-line (point-min))
4576 (when rtnall
4577 (insert (org-agenda-finalize-entries rtnall) "\n"))
4578 (goto-char (point-min))
4579 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4580 (add-text-properties (point-min) (point-max)
4581 `(org-agenda-type todo
4582 org-last-args ,arg
4583 org-redo-cmd ,org-agenda-redo-command
4584 org-series-cmd ,org-cmd))
4585 (org-agenda-finalize)
4586 (setq buffer-read-only t))))
4588 (autoload 'org-todo-list "org-agenda" "\
4589 Show all (not done) TODO entries from all agenda file in a single list.
4590 The prefix arg can be used to select a specific TODO keyword and limit
4591 the list to these. When using \\[universal-argument], you will be prompted
4592 for a keyword. A numeric prefix directly selects the Nth keyword in
4593 `org-todo-keywords-1'.
4595 \(fn &optional ARG)" t nil)
4597 ;;; Agenda tags match
4599 ;;;###autoload
4600 (defun org-tags-view (&optional todo-only match)
4601 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4602 The prefix arg TODO-ONLY limits the search to TODO entries."
4603 (interactive "P")
4604 (if org-agenda-overriding-arguments
4605 (setq todo-only (car org-agenda-overriding-arguments)
4606 match (nth 1 org-agenda-overriding-arguments)))
4607 (let* ((org-tags-match-list-sublevels
4608 org-tags-match-list-sublevels)
4609 (completion-ignore-case t)
4610 rtn rtnall files file pos matcher
4611 buffer)
4612 (when (and (stringp match) (not (string-match "\\S-" match)))
4613 (setq match nil))
4614 (setq matcher (org-make-tags-matcher match)
4615 match (car matcher) matcher (cdr matcher))
4616 (catch 'exit
4617 (if org-agenda-sticky
4618 (setq org-agenda-buffer-name
4619 (if (stringp match)
4620 (format "*Org Agenda(%s:%s)*"
4621 (or org-keys (or (and todo-only "M") "m")) match)
4622 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4623 (org-agenda-prepare (concat "TAGS " match))
4624 (org-compile-prefix-format 'tags)
4625 (org-set-sorting-strategy 'tags)
4626 (setq org-agenda-query-string match)
4627 (setq org-agenda-redo-command
4628 (list 'org-tags-view `(quote ,todo-only)
4629 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4630 (setq files (org-agenda-files nil 'ifmode)
4631 rtnall nil)
4632 (while (setq file (pop files))
4633 (catch 'nextfile
4634 (org-check-agenda-file file)
4635 (setq buffer (if (file-exists-p file)
4636 (org-get-agenda-file-buffer file)
4637 (error "No such file %s" file)))
4638 (if (not buffer)
4639 ;; If file does not exist, error message to agenda
4640 (setq rtn (list
4641 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4642 rtnall (append rtnall rtn))
4643 (with-current-buffer buffer
4644 (unless (derived-mode-p 'org-mode)
4645 (error "Agenda file %s is not in `org-mode'" file))
4646 (save-excursion
4647 (save-restriction
4648 (if org-agenda-restrict
4649 (narrow-to-region org-agenda-restrict-begin
4650 org-agenda-restrict-end)
4651 (widen))
4652 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4653 (setq rtnall (append rtnall rtn))))))))
4654 (if org-agenda-overriding-header
4655 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4656 nil 'face 'org-agenda-structure) "\n")
4657 (insert "Headlines with TAGS match: ")
4658 (add-text-properties (point-min) (1- (point))
4659 (list 'face 'org-agenda-structure
4660 'short-heading
4661 (concat "Match: " match)))
4662 (setq pos (point))
4663 (insert match "\n")
4664 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4665 (setq pos (point))
4666 (unless org-agenda-multi
4667 (insert "Press `C-u r' to search again with new search string\n"))
4668 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4669 (org-agenda-mark-header-line (point-min))
4670 (when rtnall
4671 (insert (org-agenda-finalize-entries rtnall) "\n"))
4672 (goto-char (point-min))
4673 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4674 (add-text-properties (point-min) (point-max)
4675 `(org-agenda-type tags
4676 org-last-args (,todo-only ,match)
4677 org-redo-cmd ,org-agenda-redo-command
4678 org-series-cmd ,org-cmd))
4679 (org-agenda-finalize)
4680 (setq buffer-read-only t))))
4682 (autoload 'org-tags-view "org-agenda" "\
4683 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4684 The prefix arg TODO-ONLY limits the search to TODO entries.
4686 \(fn &optional TODO-ONLY MATCH)" t nil)
4688 ;;; Agenda Finding stuck projects
4690 (defvar org-agenda-skip-regexp nil
4691 "Regular expression used in skipping subtrees for the agenda.
4692 This is basically a temporary global variable that can be set and then
4693 used by user-defined selections using `org-agenda-skip-function'.")
4695 (defvar org-agenda-overriding-header nil
4696 "When set during agenda, todo and tags searches it replaces the header.
4697 This variable should not be set directly, but custom commands can bind it
4698 in the options section.")
4700 (defun org-agenda-skip-entry-when-regexp-matches ()
4701 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4702 If yes, it returns the end position of this entry, causing agenda commands
4703 to skip the entry but continuing the search in the subtree. This is a
4704 function that can be put into `org-agenda-skip-function' for the duration
4705 of a command."
4706 (let ((end (save-excursion (org-end-of-subtree t)))
4707 skip)
4708 (save-excursion
4709 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4710 (and skip end)))
4712 (defun org-agenda-skip-subtree-when-regexp-matches ()
4713 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4714 If yes, it returns the end position of this tree, causing agenda commands
4715 to skip this subtree. This is a function that can be put into
4716 `org-agenda-skip-function' for the duration of a command."
4717 (let ((end (save-excursion (org-end-of-subtree t)))
4718 skip)
4719 (save-excursion
4720 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4721 (and skip end)))
4723 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4724 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4725 If yes, it returns the end position of the current entry (NOT the tree),
4726 causing agenda commands to skip the entry but continuing the search in
4727 the subtree. This is a function that can be put into
4728 `org-agenda-skip-function' for the duration of a command. An important
4729 use of this function is for the stuck project list."
4730 (let ((end (save-excursion (org-end-of-subtree t)))
4731 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4732 skip)
4733 (save-excursion
4734 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4735 (and skip entry-end)))
4737 (defun org-agenda-skip-entry-if (&rest conditions)
4738 "Skip entry if any of CONDITIONS is true.
4739 See `org-agenda-skip-if' for details."
4740 (org-agenda-skip-if nil conditions))
4742 (defun org-agenda-skip-subtree-if (&rest conditions)
4743 "Skip entry if any of CONDITIONS is true.
4744 See `org-agenda-skip-if' for details."
4745 (org-agenda-skip-if t conditions))
4747 (defun org-agenda-skip-if (subtree conditions)
4748 "Checks current entity for CONDITIONS.
4749 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4750 the entry (i.e. the text before the next heading) is checked.
4752 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4753 from different tests. Valid conditions are:
4755 scheduled Check if there is a scheduled cookie
4756 notscheduled Check if there is no scheduled cookie
4757 deadline Check if there is a deadline
4758 notdeadline Check if there is no deadline
4759 timestamp Check if there is a timestamp (also deadline or scheduled)
4760 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4761 regexp Check if regexp matches
4762 notregexp Check if regexp does not match.
4763 todo Check if TODO keyword matches
4764 nottodo Check if TODO keyword does not match
4766 The regexp is taken from the conditions list, it must come right after
4767 the `regexp' or `notregexp' element.
4769 `todo' and `nottodo' accept as an argument a list of todo
4770 keywords, which may include \"*\" to match any todo keyword.
4772 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4774 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4776 Instead of a list, a keyword class may be given. For example:
4778 (org-agenda-skip-entry-if 'nottodo 'done)
4780 would skip entries that haven't been marked with any of \"DONE\"
4781 keywords. Possible classes are: `todo', `done', `any'.
4783 If any of these conditions is met, this function returns the end point of
4784 the entity, causing the search to continue from there. This is a function
4785 that can be put into `org-agenda-skip-function' for the duration of a command."
4786 (let (beg end m)
4787 (org-back-to-heading t)
4788 (setq beg (point)
4789 end (if subtree
4790 (progn (org-end-of-subtree t) (point))
4791 (progn (outline-next-heading) (1- (point)))))
4792 (goto-char beg)
4793 (and
4795 (and (memq 'scheduled conditions)
4796 (re-search-forward org-scheduled-time-regexp end t))
4797 (and (memq 'notscheduled conditions)
4798 (not (re-search-forward org-scheduled-time-regexp end t)))
4799 (and (memq 'deadline conditions)
4800 (re-search-forward org-deadline-time-regexp end t))
4801 (and (memq 'notdeadline conditions)
4802 (not (re-search-forward org-deadline-time-regexp end t)))
4803 (and (memq 'timestamp conditions)
4804 (re-search-forward org-ts-regexp end t))
4805 (and (memq 'nottimestamp conditions)
4806 (not (re-search-forward org-ts-regexp end t)))
4807 (and (setq m (memq 'regexp conditions))
4808 (stringp (nth 1 m))
4809 (re-search-forward (nth 1 m) end t))
4810 (and (setq m (memq 'notregexp conditions))
4811 (stringp (nth 1 m))
4812 (not (re-search-forward (nth 1 m) end t)))
4813 (and (or
4814 (setq m (memq 'nottodo conditions))
4815 (setq m (memq 'todo-unblocked conditions))
4816 (setq m (memq 'nottodo-unblocked conditions))
4817 (setq m (memq 'todo conditions)))
4818 (org-agenda-skip-if-todo m end)))
4819 end)))
4821 (defun org-agenda-skip-if-todo (args end)
4822 "Helper function for `org-agenda-skip-if', do not use it directly.
4823 ARGS is a list with first element either `todo', `nottodo',
4824 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4825 a list of TODO keywords, or a state symbol `todo' or `done' or
4826 `any'."
4827 (let ((kw (car args))
4828 (arg (cadr args))
4829 todo-wds todo-re)
4830 (setq todo-wds
4831 (org-uniquify
4832 (cond
4833 ((listp arg) ;; list of keywords
4834 (if (member "*" arg)
4835 (mapcar 'substring-no-properties org-todo-keywords-1)
4836 arg))
4837 ((symbolp arg) ;; keyword class name
4838 (cond
4839 ((eq arg 'todo)
4840 (org-delete-all org-done-keywords
4841 (mapcar 'substring-no-properties
4842 org-todo-keywords-1)))
4843 ((eq arg 'done) org-done-keywords)
4844 ((eq arg 'any)
4845 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4846 (setq todo-re
4847 (concat "^\\*+[ \t]+\\<\\("
4848 (mapconcat 'identity todo-wds "\\|")
4849 "\\)\\>"))
4850 (cond
4851 ((eq kw 'todo) (re-search-forward todo-re end t))
4852 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4853 ((eq kw 'todo-unblocked)
4854 (catch 'unblocked
4855 (while (re-search-forward todo-re end t)
4856 (or (org-entry-blocked-p) (throw 'unblocked t)))
4857 nil))
4858 ((eq kw 'nottodo-unblocked)
4859 (catch 'unblocked
4860 (while (re-search-forward todo-re end t)
4861 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4865 ;;;###autoload
4866 (defun org-agenda-list-stuck-projects (&rest ignore)
4867 "Create agenda view for projects that are stuck.
4868 Stuck projects are project that have no next actions. For the definitions
4869 of what a project is and how to check if it stuck, customize the variable
4870 `org-stuck-projects'."
4871 (interactive)
4872 (let* ((org-agenda-skip-function
4873 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4874 ;; We could have used org-agenda-skip-if here.
4875 (org-agenda-overriding-header
4876 (or org-agenda-overriding-header "List of stuck projects: "))
4877 (matcher (nth 0 org-stuck-projects))
4878 (todo (nth 1 org-stuck-projects))
4879 (todo-wds (if (member "*" todo)
4880 (progn
4881 (org-agenda-prepare-buffers (org-agenda-files
4882 nil 'ifmode))
4883 (org-delete-all
4884 org-done-keywords-for-agenda
4885 (copy-sequence org-todo-keywords-for-agenda)))
4886 todo))
4887 (todo-re (concat "^\\*+[ \t]+\\("
4888 (mapconcat 'identity todo-wds "\\|")
4889 "\\)\\>"))
4890 (tags (nth 2 org-stuck-projects))
4891 (tags-re (if (member "*" tags)
4892 (concat org-outline-regexp-bol
4893 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4894 (if tags
4895 (concat org-outline-regexp-bol
4896 ".*:\\("
4897 (mapconcat 'identity tags "\\|")
4898 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4899 (gen-re (nth 3 org-stuck-projects))
4900 (re-list
4901 (delq nil
4902 (list
4903 (if todo todo-re)
4904 (if tags tags-re)
4905 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4906 gen-re)))))
4907 (setq org-agenda-skip-regexp
4908 (if re-list
4909 (mapconcat 'identity re-list "\\|")
4910 (error "No information how to identify unstuck projects")))
4911 (org-tags-view nil matcher)
4912 (with-current-buffer org-agenda-buffer-name
4913 (setq org-agenda-redo-command
4914 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4916 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4917 Create agenda view for projects that are stuck.
4918 Stuck projects are project that have no next actions. For the definitions
4919 of what a project is and how to check if it stuck, customize the variable
4920 `org-stuck-projects'.
4922 \(fn &rest IGNORE)" t nil)
4924 ;;; Diary integration
4926 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4927 (defvar diary-list-entries-hook)
4928 (defvar diary-time-regexp)
4929 (defun org-get-entries-from-diary (date)
4930 "Get the (Emacs Calendar) diary entries for DATE."
4931 (require 'diary-lib)
4932 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4933 (diary-display-hook '(fancy-diary-display))
4934 (diary-display-function 'fancy-diary-display)
4935 (pop-up-frames nil)
4936 (diary-list-entries-hook
4937 (cons 'org-diary-default-entry diary-list-entries-hook))
4938 (diary-file-name-prefix-function nil) ; turn this feature off
4939 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4940 entries
4941 (org-disable-agenda-to-diary t))
4942 (save-excursion
4943 (save-window-excursion
4944 (funcall (if (fboundp 'diary-list-entries)
4945 'diary-list-entries 'list-diary-entries)
4946 date 1)))
4947 (if (not (get-buffer diary-fancy-buffer))
4948 (setq entries nil)
4949 (with-current-buffer diary-fancy-buffer
4950 (setq buffer-read-only nil)
4951 (if (zerop (buffer-size))
4952 ;; No entries
4953 (setq entries nil)
4954 ;; Omit the date and other unnecessary stuff
4955 (org-agenda-cleanup-fancy-diary)
4956 ;; Add prefix to each line and extend the text properties
4957 (if (zerop (buffer-size))
4958 (setq entries nil)
4959 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4960 (setq entries
4961 (with-temp-buffer
4962 (insert entries) (goto-char (point-min))
4963 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4964 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4965 (replace-match (concat "; " (match-string 1)))))
4966 (buffer-string)))))
4967 (set-buffer-modified-p nil)
4968 (kill-buffer diary-fancy-buffer)))
4969 (when entries
4970 (setq entries (org-split-string entries "\n"))
4971 (setq entries
4972 (mapcar
4973 (lambda (x)
4974 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4975 ;; Extend the text properties to the beginning of the line
4976 (org-add-props x (text-properties-at (1- (length x)) x)
4977 'type "diary" 'date date 'face 'org-agenda-diary))
4978 entries)))))
4980 (defvar org-agenda-cleanup-fancy-diary-hook nil
4981 "Hook run when the fancy diary buffer is cleaned up.")
4983 (defun org-agenda-cleanup-fancy-diary ()
4984 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4985 This gets rid of the date, the underline under the date, and
4986 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4987 date. It also removes lines that contain only whitespace."
4988 (goto-char (point-min))
4989 (if (looking-at ".*?:[ \t]*")
4990 (progn
4991 (replace-match "")
4992 (re-search-forward "\n=+$" nil t)
4993 (replace-match "")
4994 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4995 (re-search-forward "\n=+$" nil t)
4996 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4997 (goto-char (point-min))
4998 (while (re-search-forward "^ +\n" nil t)
4999 (replace-match ""))
5000 (goto-char (point-min))
5001 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5002 (replace-match ""))
5003 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5005 ;; Make sure entries from the diary have the right text properties.
5006 (eval-after-load "diary-lib"
5007 '(if (boundp 'diary-modify-entry-list-string-function)
5008 ;; We can rely on the hook, nothing to do
5010 ;; Hook not available, must use advice to make this work
5011 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5012 "Make the position visible."
5013 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5014 (stringp string)
5015 buffer-file-name)
5016 (setq string (org-modify-diary-entry-string string))))))
5018 (defun org-modify-diary-entry-string (string)
5019 "Add text properties to string, allowing org-mode to act on it."
5020 (org-add-props string nil
5021 'mouse-face 'highlight
5022 'help-echo (if buffer-file-name
5023 (format "mouse-2 or RET jump to diary file %s"
5024 (abbreviate-file-name buffer-file-name))
5026 'org-agenda-diary-link t
5027 'org-marker (org-agenda-new-marker (point-at-bol))))
5029 (defun org-diary-default-entry ()
5030 "Add a dummy entry to the diary.
5031 Needed to avoid empty dates which mess up holiday display."
5032 ;; Catch the error if dealing with the new add-to-diary-alist
5033 (when org-disable-agenda-to-diary
5034 (condition-case nil
5035 (org-add-to-diary-list original-date "Org-mode dummy" "")
5036 (error
5037 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5039 (defun org-add-to-diary-list (&rest args)
5040 (if (fboundp 'diary-add-to-list)
5041 (apply 'diary-add-to-list args)
5042 (apply 'add-to-diary-list args)))
5044 (defvar org-diary-last-run-time nil)
5046 ;;;###autoload
5047 (defun org-diary (&rest args)
5048 "Return diary information from org files.
5049 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5050 It accesses org files and extracts information from those files to be
5051 listed in the diary. The function accepts arguments specifying what
5052 items should be listed. For a list of arguments allowed here, see the
5053 variable `org-agenda-entry-types'.
5055 The call in the diary file should look like this:
5057 &%%(org-diary) ~/path/to/some/orgfile.org
5059 Use a separate line for each org file to check. Or, if you omit the file name,
5060 all files listed in `org-agenda-files' will be checked automatically:
5062 &%%(org-diary)
5064 If you don't give any arguments (as in the example above), the default
5065 arguments (:deadline :scheduled :timestamp :sexp) are used.
5066 So the example above may also be written as
5068 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5070 The function expects the lisp variables `entry' and `date' to be provided
5071 by the caller, because this is how the calendar works. Don't use this
5072 function from a program - use `org-agenda-get-day-entries' instead."
5073 (when (> (- (org-float-time)
5074 org-agenda-last-marker-time)
5076 ;; I am not sure if this works with sticky agendas, because the marker
5077 ;; list is then no longer a global variable.
5078 (org-agenda-reset-markers))
5079 (org-compile-prefix-format 'agenda)
5080 (org-set-sorting-strategy 'agenda)
5081 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5082 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5083 (list entry)
5084 (org-agenda-files t)))
5085 (time (org-float-time))
5086 file rtn results)
5087 (when (or (not org-diary-last-run-time)
5088 (> (- time
5089 org-diary-last-run-time)
5091 (org-agenda-prepare-buffers files))
5092 (setq org-diary-last-run-time time)
5093 ;; If this is called during org-agenda, don't return any entries to
5094 ;; the calendar. Org Agenda will list these entries itself.
5095 (if org-disable-agenda-to-diary (setq files nil))
5096 (while (setq file (pop files))
5097 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5098 (setq results (append results rtn)))
5099 (if results
5100 (concat (org-agenda-finalize-entries results) "\n"))))
5102 (autoload 'org-diary "org-agenda" "\
5103 Return diary information from org files.
5104 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5105 It accesses org files and extracts information from those files to be
5106 listed in the diary. The function accepts arguments specifying what
5107 items should be listed. For a list of arguments allowed here, see the
5108 variable `org-agenda-entry-types'.
5110 The call in the diary file should look like this:
5112 &%%(org-diary) ~/path/to/some/orgfile.org
5114 Use a separate line for each org file to check. Or, if you omit the file name,
5115 all files listed in `org-agenda-files' will be checked automatically:
5117 &%%(org-diary)
5119 If you don't give any arguments (as in the example above), the default
5120 arguments (:deadline :scheduled :timestamp :sexp) are used.
5121 So the example above may also be written as
5123 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5125 The function expects the lisp variables `entry' and `date' to be provided
5126 by the caller, because this is how the calendar works. Don't use this
5127 function from a program - use `org-agenda-get-day-entries' instead.
5129 \(fn &rest ARGS)" nil nil)
5131 ;;; Agenda entry finders
5133 (defun org-agenda-get-day-entries (file date &rest args)
5134 "Does the work for `org-diary' and `org-agenda'.
5135 FILE is the path to a file to be checked for entries. DATE is date like
5136 the one returned by `calendar-current-date'. ARGS are symbols indicating
5137 which kind of entries should be extracted. For details about these, see
5138 the documentation of `org-diary'."
5139 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5140 (let* ((org-startup-folded nil)
5141 (org-startup-align-all-tables nil)
5142 (buffer (if (file-exists-p file)
5143 (org-get-agenda-file-buffer file)
5144 (error "No such file %s" file)))
5145 arg results rtn deadline-results)
5146 (if (not buffer)
5147 ;; If file does not exist, make sure an error message ends up in diary
5148 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5149 (with-current-buffer buffer
5150 (unless (derived-mode-p 'org-mode)
5151 (error "Agenda file %s is not in `org-mode'" file))
5152 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5153 (let ((case-fold-search nil))
5154 (save-excursion
5155 (save-restriction
5156 (if org-agenda-restrict
5157 (narrow-to-region org-agenda-restrict-begin
5158 org-agenda-restrict-end)
5159 (widen))
5160 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5161 (while (setq arg (pop args))
5162 (cond
5163 ((and (eq arg :todo)
5164 (equal date (calendar-gregorian-from-absolute
5165 (org-today))))
5166 (setq rtn (org-agenda-get-todos))
5167 (setq results (append results rtn)))
5168 ((eq arg :timestamp)
5169 (setq rtn (org-agenda-get-blocks))
5170 (setq results (append results rtn))
5171 (setq rtn (org-agenda-get-timestamps deadline-results))
5172 (setq results (append results rtn)))
5173 ((eq arg :sexp)
5174 (setq rtn (org-agenda-get-sexps))
5175 (setq results (append results rtn)))
5176 ((eq arg :scheduled)
5177 (setq rtn (org-agenda-get-scheduled deadline-results))
5178 (setq results (append results rtn)))
5179 ((eq arg :closed)
5180 (setq rtn (org-agenda-get-progress))
5181 (setq results (append results rtn)))
5182 ((eq arg :deadline)
5183 (setq rtn (org-agenda-get-deadlines))
5184 (setq deadline-results (copy-sequence rtn))
5185 (setq results (append results rtn))))))))
5186 results))))
5188 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5189 (defun org-agenda-get-todos ()
5190 "Return the TODO information for agenda display."
5191 (let* ((props (list 'face nil
5192 'done-face 'org-agenda-done
5193 'org-not-done-regexp org-not-done-regexp
5194 'org-todo-regexp org-todo-regexp
5195 'org-complex-heading-regexp org-complex-heading-regexp
5196 'mouse-face 'highlight
5197 'help-echo
5198 (format "mouse-2 or RET jump to org file %s"
5199 (abbreviate-file-name buffer-file-name))))
5200 (regexp (format org-heading-keyword-regexp-format
5201 (cond
5202 ((and org-select-this-todo-keyword
5203 (equal org-select-this-todo-keyword "*"))
5204 org-todo-regexp)
5205 (org-select-this-todo-keyword
5206 (concat "\\("
5207 (mapconcat 'identity
5208 (org-split-string
5209 org-select-this-todo-keyword
5210 "|")
5211 "\\|") "\\)"))
5212 (t org-not-done-regexp))))
5213 marker priority category category-pos tags todo-state
5214 ee txt beg end)
5215 (goto-char (point-min))
5216 (while (re-search-forward regexp nil t)
5217 (catch :skip
5218 (save-match-data
5219 (beginning-of-line)
5220 (org-agenda-skip)
5221 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5222 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5223 (goto-char (1+ beg))
5224 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5225 (throw :skip nil)))
5226 (goto-char (match-beginning 2))
5227 (setq marker (org-agenda-new-marker (match-beginning 0))
5228 category (org-get-category)
5229 category-pos (get-text-property (point) 'org-category-position)
5230 txt (org-trim
5231 (buffer-substring (match-beginning 2) (match-end 0)))
5232 tags (org-get-tags-at (point))
5233 txt (org-agenda-format-item "" txt category tags t)
5234 priority (1+ (org-get-priority txt))
5235 todo-state (org-get-todo-state))
5236 (org-add-props txt props
5237 'org-marker marker 'org-hd-marker marker
5238 'priority priority 'org-category category
5239 'org-category-position category-pos
5240 'type "todo" 'todo-state todo-state)
5241 (push txt ee)
5242 (if org-agenda-todo-list-sublevels
5243 (goto-char (match-end 2))
5244 (org-end-of-subtree 'invisible))))
5245 (nreverse ee)))
5247 (defun org-agenda-todo-custom-ignore-p (time n)
5248 "Check whether timestamp is farther away than n number of days.
5249 This function is invoked if `org-agenda-todo-ignore-deadlines',
5250 `org-agenda-todo-ignore-scheduled' or
5251 `org-agenda-todo-ignore-timestamp' is set to an integer."
5252 (let ((days (org-days-to-time time)))
5253 (if (>= n 0)
5254 (>= days n)
5255 (<= days n))))
5257 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5258 (&optional end)
5259 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5260 (when (or org-agenda-todo-ignore-with-date
5261 org-agenda-todo-ignore-scheduled
5262 org-agenda-todo-ignore-deadlines
5263 org-agenda-todo-ignore-timestamp)
5264 (setq end (or end (save-excursion (outline-next-heading) (point))))
5265 (save-excursion
5266 (or (and org-agenda-todo-ignore-with-date
5267 (re-search-forward org-ts-regexp end t))
5268 (and org-agenda-todo-ignore-scheduled
5269 (re-search-forward org-scheduled-time-regexp end t)
5270 (cond
5271 ((eq org-agenda-todo-ignore-scheduled 'future)
5272 (> (org-days-to-time (match-string 1)) 0))
5273 ((eq org-agenda-todo-ignore-scheduled 'past)
5274 (<= (org-days-to-time (match-string 1)) 0))
5275 ((numberp org-agenda-todo-ignore-scheduled)
5276 (org-agenda-todo-custom-ignore-p
5277 (match-string 1) org-agenda-todo-ignore-scheduled))
5278 (t)))
5279 (and org-agenda-todo-ignore-deadlines
5280 (re-search-forward org-deadline-time-regexp end t)
5281 (cond
5282 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5283 ((eq org-agenda-todo-ignore-deadlines 'far)
5284 (not (org-deadline-close (match-string 1))))
5285 ((eq org-agenda-todo-ignore-deadlines 'future)
5286 (> (org-days-to-time (match-string 1)) 0))
5287 ((eq org-agenda-todo-ignore-deadlines 'past)
5288 (<= (org-days-to-time (match-string 1)) 0))
5289 ((numberp org-agenda-todo-ignore-deadlines)
5290 (org-agenda-todo-custom-ignore-p
5291 (match-string 1) org-agenda-todo-ignore-deadlines))
5292 (t (org-deadline-close (match-string 1)))))
5293 (and org-agenda-todo-ignore-timestamp
5294 (let ((buffer (current-buffer))
5295 (regexp
5296 (concat
5297 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5298 (start (point)))
5299 ;; Copy current buffer into a temporary one
5300 (with-temp-buffer
5301 (insert-buffer-substring buffer start end)
5302 (goto-char (point-min))
5303 ;; Delete SCHEDULED and DEADLINE items
5304 (while (re-search-forward regexp end t)
5305 (delete-region (match-beginning 0) (match-end 0)))
5306 (goto-char (point-min))
5307 ;; No search for timestamp left
5308 (when (re-search-forward org-ts-regexp nil t)
5309 (cond
5310 ((eq org-agenda-todo-ignore-timestamp 'future)
5311 (> (org-days-to-time (match-string 1)) 0))
5312 ((eq org-agenda-todo-ignore-timestamp 'past)
5313 (<= (org-days-to-time (match-string 1)) 0))
5314 ((numberp org-agenda-todo-ignore-timestamp)
5315 (org-agenda-todo-custom-ignore-p
5316 (match-string 1) org-agenda-todo-ignore-timestamp))
5317 (t))))))))))
5319 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5320 Do we have a reason to ignore this TODO entry because it has a time stamp?
5322 \(fn &optional END)" nil nil)
5324 (defconst org-agenda-no-heading-message
5325 "No heading for this item in buffer or region.")
5327 (defun org-agenda-get-timestamps (&optional deadline-results)
5328 "Return the date stamp information for agenda display."
5329 (let* ((props (list 'face 'org-agenda-calendar-event
5330 'org-not-done-regexp org-not-done-regexp
5331 'org-todo-regexp org-todo-regexp
5332 'org-complex-heading-regexp org-complex-heading-regexp
5333 'mouse-face 'highlight
5334 'help-echo
5335 (format "mouse-2 or RET jump to org file %s"
5336 (abbreviate-file-name buffer-file-name))))
5337 (d1 (calendar-absolute-from-gregorian date))
5339 (deadline-position-alist
5340 (mapcar (lambda (a) (and (setq mm (get-text-property
5341 0 'org-hd-marker a))
5342 (cons (marker-position mm) a)))
5343 deadline-results))
5344 (remove-re org-ts-regexp)
5345 (regexp
5346 (concat
5347 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5348 (regexp-quote
5349 (substring
5350 (format-time-string
5351 (car org-time-stamp-formats)
5352 (apply 'encode-time ; DATE bound by calendar
5353 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5354 1 11))
5355 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5356 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5357 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5358 donep tmp priority category category-pos ee txt timestr tags
5359 b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
5360 (goto-char (point-min))
5361 (while (setq end-of-match (re-search-forward regexp nil t))
5362 (setq b0 (match-beginning 0)
5363 b3 (match-beginning 3) e3 (match-end 3)
5364 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5365 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5366 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5367 (member todo-state
5368 org-agenda-repeating-timestamp-show-all)))
5369 (catch :skip
5370 (and (org-at-date-range-p) (throw :skip nil))
5371 (org-agenda-skip)
5372 (if (and (match-end 1)
5373 (not (= d1 (org-time-string-to-absolute
5374 (match-string 1) d1 nil show-all
5375 (current-buffer) b0))))
5376 (throw :skip nil))
5377 (if (and e3
5378 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5379 (throw :skip nil))
5380 (setq tmp (buffer-substring (max (point-min)
5381 (- b0 org-ds-keyword-length))
5383 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5384 inactivep (= (char-after b0) ?\[)
5385 deadlinep (string-match org-deadline-regexp tmp)
5386 scheduledp (string-match org-scheduled-regexp tmp)
5387 closedp (and org-agenda-include-inactive-timestamps
5388 (string-match org-closed-string tmp))
5389 clockp (and org-agenda-include-inactive-timestamps
5390 (or (string-match org-clock-string tmp)
5391 (string-match "]-+\\'" tmp)))
5392 warntime (org-entry-get (point) "APPT_WARNTIME")
5393 donep (member todo-state org-done-keywords))
5394 (if (or scheduledp deadlinep closedp clockp
5395 (and donep org-agenda-skip-timestamp-if-done))
5396 (throw :skip t))
5397 (if (string-match ">" timestr)
5398 ;; substring should only run to end of time stamp
5399 (setq timestr (substring timestr 0 (match-end 0))))
5400 (setq marker (org-agenda-new-marker b0)
5401 category (org-get-category b0)
5402 category-pos (get-text-property b0 'org-category-position))
5403 (save-excursion
5404 (if (not (re-search-backward org-outline-regexp-bol nil t))
5405 (setq txt org-agenda-no-heading-message)
5406 (goto-char (match-beginning 0))
5407 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5408 (assoc (point) deadline-position-alist))
5409 (throw :skip nil))
5410 (setq hdmarker (org-agenda-new-marker)
5411 tags (org-get-tags-at))
5412 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5413 (setq head (or (match-string 1) ""))
5414 (setq txt (org-agenda-format-item
5415 (if inactivep org-agenda-inactive-leader nil)
5416 head category tags timestr
5417 remove-re habitp)))
5418 (setq priority (org-get-priority txt))
5419 (org-add-props txt props
5420 'org-marker marker 'org-hd-marker hdmarker)
5421 (org-add-props txt nil 'priority priority
5422 'org-category category 'date date
5423 'org-category-position category-pos
5424 'todo-state todo-state
5425 'warntime warntime
5426 'type "timestamp")
5427 (push txt ee))
5428 (if org-agenda-skip-additional-timestamps-same-entry
5429 (outline-next-heading)
5430 (goto-char end-of-match))))
5431 (nreverse ee)))
5433 (defun org-agenda-get-sexps ()
5434 "Return the sexp information for agenda display."
5435 (require 'diary-lib)
5436 (let* ((props (list 'face 'org-agenda-calendar-sexp
5437 'mouse-face 'highlight
5438 'help-echo
5439 (format "mouse-2 or RET jump to org file %s"
5440 (abbreviate-file-name buffer-file-name))))
5441 (regexp "^&?%%(")
5442 marker category extra category-pos ee txt tags entry
5443 result beg b sexp sexp-entry todo-state warntime)
5444 (goto-char (point-min))
5445 (while (re-search-forward regexp nil t)
5446 (catch :skip
5447 (org-agenda-skip)
5448 (setq beg (match-beginning 0))
5449 (goto-char (1- (match-end 0)))
5450 (setq b (point))
5451 (forward-sexp 1)
5452 (setq sexp (buffer-substring b (point)))
5453 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5454 (org-trim (match-string 1))
5455 ""))
5456 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5457 (when result
5458 (setq marker (org-agenda-new-marker beg)
5459 category (org-get-category beg)
5460 category-pos (get-text-property beg 'org-category-position)
5461 tags (save-excursion (org-backward-heading-same-level 0)
5462 (org-get-tags-at))
5463 todo-state (org-get-todo-state)
5464 warntime (org-entry-get (point) "APPT_WARNTIME")
5465 extra nil)
5467 (dolist (r (if (stringp result)
5468 (list result)
5469 result)) ;; we expect a list here
5470 (when (and org-agenda-diary-sexp-prefix
5471 (string-match org-agenda-diary-sexp-prefix r))
5472 (setq extra (match-string 0 r)
5473 r (replace-match "" nil nil r)))
5474 (if (string-match "\\S-" r)
5475 (setq txt r)
5476 (setq txt "SEXP entry returned empty string"))
5478 (setq txt (org-agenda-format-item
5479 extra txt category tags 'time))
5480 (org-add-props txt props 'org-marker marker)
5481 (org-add-props txt nil
5482 'org-category category 'date date 'todo-state todo-state
5483 'org-category-position category-pos 'tags tags
5484 'type "sexp" 'warntime warntime)
5485 (push txt ee)))))
5486 (nreverse ee)))
5488 ;; Calendar sanity: define some functions that are independent of
5489 ;; `calendar-date-style'.
5490 ;; Normally I would like to use ISO format when calling the diary functions,
5491 ;; but to make sure we still have Emacs 22 compatibility we bind
5492 ;; also `european-calendar-style' and use european format
5493 (defun org-anniversary (year month day &optional mark)
5494 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5495 (org-no-warnings
5496 (let ((calendar-date-style 'european) (european-calendar-style t))
5497 (diary-anniversary day month year mark))))
5498 (defun org-cyclic (N year month day &optional mark)
5499 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5500 (org-no-warnings
5501 (let ((calendar-date-style 'european) (european-calendar-style t))
5502 (diary-cyclic N day month year mark))))
5503 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5504 "Like `diary-block', but with fixed (ISO) order of arguments."
5505 (org-no-warnings
5506 (let ((calendar-date-style 'european) (european-calendar-style t))
5507 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5508 (defun org-date (year month day &optional mark)
5509 "Like `diary-date', but with fixed (ISO) order of arguments."
5510 (org-no-warnings
5511 (let ((calendar-date-style 'european) (european-calendar-style t))
5512 (diary-date day month year mark))))
5513 (defalias 'org-float 'diary-float)
5515 ;; Define the` org-class' function
5516 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5517 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5518 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5519 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5520 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5521 `holidays', then any date that is known by the Emacs calendar to be a
5522 holiday will also be skipped."
5523 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5524 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5525 (d (calendar-absolute-from-gregorian date)))
5526 (and
5527 (<= date1 d)
5528 (<= d date2)
5529 (= (calendar-day-of-week date) dayname)
5530 (or (not skip-weeks)
5531 (progn
5532 (require 'cal-iso)
5533 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5534 (not (and (memq 'holidays skip-weeks)
5535 (calendar-check-holidays date)))
5536 entry)))
5538 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5539 "Like `org-class', but honor `calendar-date-style'.
5540 The order of the first 2 times 3 arguments depends on the variable
5541 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5542 So for American calendars, give this as MONTH DAY YEAR, for European as
5543 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5544 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5545 is any number of ISO weeks in the block period for which the item should
5546 be skipped.
5548 This function is here only for backward compatibility and it is deprecated,
5549 please use `org-class' instead."
5550 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5551 (date2 (org-order-calendar-date-args m2 d2 y2)))
5552 (org-class
5553 (nth 2 date1) (car date1) (nth 1 date1)
5554 (nth 2 date2) (car date2) (nth 1 date2)
5555 dayname skip-weeks)))
5556 (make-obsolete 'org-diary-class 'org-class "")
5558 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5559 (defalias 'org-get-closed 'org-agenda-get-progress)
5560 (defun org-agenda-get-progress ()
5561 "Return the logged TODO entries for agenda display."
5562 (let* ((props (list 'mouse-face 'highlight
5563 'org-not-done-regexp org-not-done-regexp
5564 'org-todo-regexp org-todo-regexp
5565 'org-complex-heading-regexp org-complex-heading-regexp
5566 'help-echo
5567 (format "mouse-2 or RET jump to org file %s"
5568 (abbreviate-file-name buffer-file-name))))
5569 (items (if (consp org-agenda-show-log-scoped)
5570 org-agenda-show-log-scoped
5571 (if (eq org-agenda-show-log-scoped 'clockcheck)
5572 '(clock)
5573 org-agenda-log-mode-items)))
5574 (parts
5575 (delq nil
5576 (list
5577 (if (memq 'closed items) (concat "\\<" org-closed-string))
5578 (if (memq 'clock items) (concat "\\<" org-clock-string))
5579 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5580 (parts-re (if parts (mapconcat 'identity parts "\\|")
5581 (error "`org-agenda-log-mode-items' is empty")))
5582 (regexp (concat
5583 "\\(" parts-re "\\)"
5584 " *\\["
5585 (regexp-quote
5586 (substring
5587 (format-time-string
5588 (car org-time-stamp-formats)
5589 (apply 'encode-time ; DATE bound by calendar
5590 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5591 1 11))))
5592 (org-agenda-search-headline-for-time nil)
5593 marker hdmarker priority category category-pos tags closedp
5594 statep clockp state ee txt extra timestr rest clocked)
5595 (goto-char (point-min))
5596 (while (re-search-forward regexp nil t)
5597 (catch :skip
5598 (org-agenda-skip)
5599 (setq marker (org-agenda-new-marker (match-beginning 0))
5600 closedp (equal (match-string 1) org-closed-string)
5601 statep (equal (string-to-char (match-string 1)) ?-)
5602 clockp (not (or closedp statep))
5603 state (and statep (match-string 2))
5604 category (org-get-category (match-beginning 0))
5605 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5606 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5607 (when (string-match "\\]" timestr)
5608 ;; substring should only run to end of time stamp
5609 (setq rest (substring timestr (match-end 0))
5610 timestr (substring timestr 0 (match-end 0)))
5611 (if (and (not closedp) (not statep)
5612 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5613 rest))
5614 (progn (setq timestr (concat (substring timestr 0 -1)
5615 "-" (match-string 1 rest) "]"))
5616 (setq clocked (match-string 2 rest)))
5617 (setq clocked "-")))
5618 (save-excursion
5619 (setq extra
5620 (cond
5621 ((not org-agenda-log-mode-add-notes) nil)
5622 (statep
5623 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5624 (match-string 1)))
5625 (clockp
5626 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5627 (match-string 1)))))
5628 (if (not (re-search-backward org-outline-regexp-bol nil t))
5629 (setq txt org-agenda-no-heading-message)
5630 (goto-char (match-beginning 0))
5631 (setq hdmarker (org-agenda-new-marker)
5632 tags (org-get-tags-at))
5633 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5634 (setq txt (match-string 1))
5635 (when extra
5636 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5637 (setq txt (concat (substring txt 0 (match-beginning 1))
5638 " - " extra " " (match-string 2 txt)))
5639 (setq txt (concat txt " - " extra))))
5640 (setq txt (org-agenda-format-item
5641 (cond
5642 (closedp "Closed: ")
5643 (statep (concat "State: (" state ")"))
5644 (t (concat "Clocked: (" clocked ")")))
5645 txt category tags timestr)))
5646 (setq priority 100000)
5647 (org-add-props txt props
5648 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5649 'priority priority 'org-category category
5650 'org-category-position category-pos
5651 'type "closed" 'date date
5652 'undone-face 'org-warning 'done-face 'org-agenda-done)
5653 (push txt ee))
5654 (goto-char (point-at-eol))))
5655 (nreverse ee)))
5657 (defun org-agenda-show-clocking-issues ()
5658 "Add overlays, showing issues with clocking.
5659 See also the user option `org-agenda-clock-consistency-checks'."
5660 (interactive)
5661 (let* ((pl org-agenda-clock-consistency-checks)
5662 (re (concat "^[ \t]*"
5663 org-clock-string
5664 "[ \t]+"
5665 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5666 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5667 (tlstart 0.)
5668 (tlend 0.)
5669 (maxtime (org-hh:mm-string-to-minutes
5670 (or (plist-get pl :max-duration) "24:00")))
5671 (mintime (org-hh:mm-string-to-minutes
5672 (or (plist-get pl :min-duration) 0)))
5673 (maxgap (org-hh:mm-string-to-minutes
5674 ;; default 30:00 means never complain
5675 (or (plist-get pl :max-gap) "30:00")))
5676 (gapok (mapcar 'org-hh:mm-string-to-minutes
5677 (plist-get pl :gap-ok-around)))
5678 (def-face (or (plist-get pl :default-face)
5679 '((:background "DarkRed") (:foreground "white"))))
5680 issue face m te ts dt ov)
5681 (goto-char (point-min))
5682 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5683 (setq issue nil face def-face)
5684 (catch 'next
5685 (setq m (org-get-at-bol 'org-marker)
5686 te nil ts nil)
5687 (unless (and m (markerp m))
5688 (setq issue "No valid clock line") (throw 'next t))
5689 (org-with-point-at m
5690 (save-excursion
5691 (goto-char (point-at-bol))
5692 (unless (looking-at re)
5693 (error "No valid Clock line")
5694 (throw 'next t))
5695 (unless (match-end 3)
5696 (setq issue "No end time"
5697 face (or (plist-get pl :no-end-time-face) face))
5698 (throw 'next t))
5699 (setq ts (match-string 1)
5700 te (match-string 3)
5701 ts (org-float-time
5702 (apply 'encode-time (org-parse-time-string ts)))
5703 te (org-float-time
5704 (apply 'encode-time (org-parse-time-string te)))
5705 dt (- te ts))))
5706 (cond
5707 ((> dt (* 60 maxtime))
5708 ;; a very long clocking chunk
5709 (setq issue (format "Clocking interval is very long: %s"
5710 (org-minutes-to-hh:mm-string
5711 (floor (/ (float dt) 60.))))
5712 face (or (plist-get pl :long-face) face)))
5713 ((< dt (* 60 mintime))
5714 ;; a very short clocking chunk
5715 (setq issue (format "Clocking interval is very short: %s"
5716 (org-minutes-to-hh:mm-string
5717 (floor (/ (float dt) 60.))))
5718 face (or (plist-get pl :short-face) face)))
5719 ((and (> tlend 0) (< ts tlend))
5720 ;; Two clock entries are overlapping
5721 (setq issue (format "Clocking overlap: %d minutes"
5722 (/ (- tlend ts) 60))
5723 face (or (plist-get pl :overlap-face) face)))
5724 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5725 ;; There is a gap, lets see if we need to report it
5726 (unless (org-agenda-check-clock-gap tlend ts gapok)
5727 (setq issue (format "Clocking gap: %d minutes"
5728 (/ (- ts tlend) 60))
5729 face (or (plist-get pl :gap-face) face))))
5730 (t nil)))
5731 (setq tlend (or te tlend) tlstart (or ts tlstart))
5732 (when issue
5733 ;; OK, there was some issue, add an overlay to show the issue
5734 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5735 (overlay-put ov 'before-string
5736 (concat
5737 (org-add-props
5738 (format "%-43s" (concat " " issue))
5740 'face face)
5741 "\n"))
5742 (overlay-put ov 'evaporate t)))))
5744 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5745 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5746 (catch 'exit
5747 (unless ok-list
5748 ;; there are no OK times for gaps...
5749 (throw 'exit nil))
5750 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5751 ;; This is more than 24 hours, so it is OK.
5752 ;; because we have at least one OK time, that must be in the
5753 ;; 24 hour interval.
5754 (throw 'exit t))
5755 ;; We have a shorter gap.
5756 ;; Now we have to get the minute of the day when these times are
5757 (let* ((t1dec (decode-time (seconds-to-time t1)))
5758 (t2dec (decode-time (seconds-to-time t2)))
5759 ;; compute the minute on the day
5760 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5761 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5762 (when (< min2 min1)
5763 ;; if min2 is smaller than min1, this means it is on the next day.
5764 ;; Wrap it to after midnight.
5765 (setq min2 (+ min2 1440)))
5766 ;; Now check if any of the OK times is in the gap
5767 (mapc (lambda (x)
5768 ;; Wrap the time to after midnight if necessary
5769 (if (< x min1) (setq x (+ x 1440)))
5770 ;; Check if in interval
5771 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5772 ok-list)
5773 ;; Nope, this gap is not OK
5774 nil)))
5776 (defun org-agenda-get-deadlines ()
5777 "Return the deadline information for agenda display."
5778 (let* ((props (list 'mouse-face 'highlight
5779 'org-not-done-regexp org-not-done-regexp
5780 'org-todo-regexp org-todo-regexp
5781 'org-complex-heading-regexp org-complex-heading-regexp
5782 'help-echo
5783 (format "mouse-2 or RET jump to org file %s"
5784 (abbreviate-file-name buffer-file-name))))
5785 (regexp org-deadline-time-regexp)
5786 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5787 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5788 d2 diff dfrac wdays pos pos1 category category-pos
5789 tags suppress-prewarning ee txt head face s todo-state
5790 show-all upcomingp donep timestr warntime)
5791 (goto-char (point-min))
5792 (while (re-search-forward regexp nil t)
5793 (setq suppress-prewarning nil)
5794 (catch :skip
5795 (org-agenda-skip)
5796 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5797 (save-match-data
5798 (string-match org-scheduled-time-regexp
5799 (buffer-substring (point-at-bol)
5800 (point-at-eol)))))
5801 (setq suppress-prewarning
5802 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5803 org-agenda-skip-deadline-prewarning-if-scheduled
5804 0)))
5805 (setq s (match-string 1)
5806 txt nil
5807 pos (1- (match-beginning 1))
5808 todo-state (save-match-data (org-get-todo-state))
5809 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5810 (member todo-state
5811 org-agenda-repeating-timestamp-show-all))
5812 d2 (org-time-string-to-absolute
5813 (match-string 1) d1 'past show-all
5814 (current-buffer) pos)
5815 diff (- d2 d1)
5816 wdays (if suppress-prewarning
5817 (let ((org-deadline-warning-days suppress-prewarning))
5818 (org-get-wdays s))
5819 (org-get-wdays s))
5820 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5821 upcomingp (and todayp (> diff 0)))
5822 ;; When to show a deadline in the calendar:
5823 ;; If the expiration is within wdays warning time.
5824 ;; Past-due deadlines are only shown on the current date
5825 (if (and (or (and (<= diff wdays)
5826 (and todayp (not org-agenda-only-exact-dates)))
5827 (= diff 0)))
5828 (save-excursion
5829 ;; (setq todo-state (org-get-todo-state))
5830 (setq donep (member todo-state org-done-keywords))
5831 (if (and donep
5832 (or org-agenda-skip-deadline-if-done
5833 (not (= diff 0))))
5834 (setq txt nil)
5835 (setq category (org-get-category)
5836 warntime (org-entry-get (point) "APPT_WARNTIME")
5837 category-pos (get-text-property (point) 'org-category-position))
5838 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5839 (setq txt org-agenda-no-heading-message)
5840 (goto-char (match-end 0))
5841 (setq pos1 (match-beginning 0))
5842 (setq tags (org-get-tags-at pos1))
5843 (setq head (buffer-substring-no-properties
5844 (point)
5845 (progn (skip-chars-forward "^\r\n")
5846 (point))))
5847 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5848 (setq timestr
5849 (concat (substring s (match-beginning 1)) " "))
5850 (setq timestr 'time))
5851 (setq txt (org-agenda-format-item
5852 (if (= diff 0)
5853 (car org-agenda-deadline-leaders)
5854 (if (functionp
5855 (nth 1 org-agenda-deadline-leaders))
5856 (funcall
5857 (nth 1 org-agenda-deadline-leaders)
5858 diff date)
5859 (format (nth 1 org-agenda-deadline-leaders)
5860 diff)))
5861 head category tags
5862 (if (not (= diff 0)) nil timestr)))))
5863 (when txt
5864 (setq face (org-agenda-deadline-face dfrac))
5865 (org-add-props txt props
5866 'org-marker (org-agenda-new-marker pos)
5867 'warntime warntime
5868 'org-hd-marker (org-agenda-new-marker pos1)
5869 'priority (+ (- diff)
5870 (org-get-priority txt))
5871 'org-category category
5872 'org-category-position category-pos
5873 'todo-state todo-state
5874 'type (if upcomingp "upcoming-deadline" "deadline")
5875 'date (if upcomingp date d2)
5876 'face (if donep 'org-agenda-done face)
5877 'undone-face face 'done-face 'org-agenda-done)
5878 (push txt ee))))))
5879 (nreverse ee)))
5881 (defun org-agenda-deadline-face (fraction)
5882 "Return the face to displaying a deadline item.
5883 FRACTION is what fraction of the head-warning time has passed."
5884 (let ((faces org-agenda-deadline-faces) f)
5885 (catch 'exit
5886 (while (setq f (pop faces))
5887 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5889 (defun org-agenda-get-scheduled (&optional deadline-results)
5890 "Return the scheduled information for agenda display."
5891 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5892 'org-todo-regexp org-todo-regexp
5893 'org-complex-heading-regexp org-complex-heading-regexp
5894 'done-face 'org-agenda-done
5895 'mouse-face 'highlight
5896 'help-echo
5897 (format "mouse-2 or RET jump to org file %s"
5898 (abbreviate-file-name buffer-file-name))))
5899 (regexp org-scheduled-time-regexp)
5900 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5901 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5903 (deadline-position-alist
5904 (mapcar (lambda (a) (and (setq mm (get-text-property
5905 0 'org-hd-marker a))
5906 (cons (marker-position mm) a)))
5907 deadline-results))
5908 d2 diff pos pos1 category category-pos tags donep
5909 ee txt head pastschedp todo-state face timestr s habitp show-all
5910 did-habit-check-p warntime)
5911 (goto-char (point-min))
5912 (while (re-search-forward regexp nil t)
5913 (catch :skip
5914 (org-agenda-skip)
5915 (setq s (match-string 1)
5916 txt nil
5917 pos (1- (match-beginning 1))
5918 todo-state (save-match-data (org-get-todo-state))
5919 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5920 (member todo-state
5921 org-agenda-repeating-timestamp-show-all))
5922 d2 (org-time-string-to-absolute
5923 (match-string 1) d1 'past show-all
5924 (current-buffer) pos)
5925 diff (- d2 d1)
5926 warntime (org-entry-get (point) "APPT_WARNTIME"))
5927 (setq pastschedp (and todayp (< diff 0)))
5928 (setq did-habit-check-p nil)
5929 ;; When to show a scheduled item in the calendar:
5930 ;; If it is on or past the date.
5931 (when (or (and (< diff 0)
5932 (< (abs diff) org-scheduled-past-days)
5933 (and todayp (not org-agenda-only-exact-dates)))
5934 (= diff 0)
5935 ;; org-is-habit-p uses org-entry-get, which is expansive
5936 ;; so we go extra mile to only call it once
5937 (and todayp
5938 (boundp 'org-habit-show-all-today)
5939 org-habit-show-all-today
5940 (setq did-habit-check-p t)
5941 (setq habitp (and (functionp 'org-is-habit-p)
5942 (org-is-habit-p)))))
5943 (save-excursion
5944 (setq donep (member todo-state org-done-keywords))
5945 (if (and donep
5946 (or org-agenda-skip-scheduled-if-done
5947 (not (= diff 0))
5948 (and (functionp 'org-is-habit-p)
5949 (org-is-habit-p))))
5950 (setq txt nil)
5951 (setq habitp (if did-habit-check-p habitp
5952 (and (functionp 'org-is-habit-p)
5953 (org-is-habit-p))))
5954 (setq category (org-get-category)
5955 category-pos (get-text-property (point) 'org-category-position))
5956 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5957 (setq txt org-agenda-no-heading-message)
5958 (goto-char (match-end 0))
5959 (setq pos1 (match-beginning 0))
5960 (if habitp
5961 (if (or (not org-habit-show-habits)
5962 (and (not todayp)
5963 (boundp 'org-habit-show-habits-only-for-today)
5964 org-habit-show-habits-only-for-today))
5965 (throw :skip nil))
5966 (if (and
5967 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5968 (and org-agenda-skip-scheduled-if-deadline-is-shown
5969 pastschedp))
5970 (setq mm (assoc pos1 deadline-position-alist)))
5971 (throw :skip nil)))
5972 (setq tags (org-get-tags-at))
5973 (setq head (buffer-substring-no-properties
5974 (point)
5975 (progn (skip-chars-forward "^\r\n") (point))))
5976 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5977 (setq timestr
5978 (concat (substring s (match-beginning 1)) " "))
5979 (setq timestr 'time))
5980 (setq txt (org-agenda-format-item
5981 (if (= diff 0)
5982 (car org-agenda-scheduled-leaders)
5983 (format (nth 1 org-agenda-scheduled-leaders)
5984 (- 1 diff)))
5985 head category tags
5986 (if (not (= diff 0)) nil timestr)
5987 nil habitp))))
5988 (when txt
5989 (setq face
5990 (cond
5991 ((and (not habitp) pastschedp)
5992 'org-scheduled-previously)
5993 (todayp 'org-scheduled-today)
5994 (t 'org-scheduled))
5995 habitp (and habitp (org-habit-parse-todo)))
5996 (org-add-props txt props
5997 'undone-face face
5998 'face (if donep 'org-agenda-done face)
5999 'org-marker (org-agenda-new-marker pos)
6000 'org-hd-marker (org-agenda-new-marker pos1)
6001 'type (if pastschedp "past-scheduled" "scheduled")
6002 'date (if pastschedp d2 date)
6003 'warntime warntime
6004 'priority (if habitp
6005 (org-habit-get-priority habitp)
6006 (+ 94 (- 5 diff) (org-get-priority txt)))
6007 'org-category category
6008 'category-position category-pos
6009 'org-habit-p habitp
6010 'todo-state todo-state)
6011 (push txt ee))))))
6012 (nreverse ee)))
6014 (defun org-agenda-get-blocks ()
6015 "Return the date-range information for agenda display."
6016 (let* ((props (list 'face nil
6017 'org-not-done-regexp org-not-done-regexp
6018 'org-todo-regexp org-todo-regexp
6019 'org-complex-heading-regexp org-complex-heading-regexp
6020 'mouse-face 'highlight
6021 'help-echo
6022 (format "mouse-2 or RET jump to org file %s"
6023 (abbreviate-file-name buffer-file-name))))
6024 (regexp org-tr-regexp)
6025 (d0 (calendar-absolute-from-gregorian date))
6026 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6027 todo-state tags pos head donep)
6028 (goto-char (point-min))
6029 (while (re-search-forward regexp nil t)
6030 (catch :skip
6031 (org-agenda-skip)
6032 (setq pos (point))
6033 (let ((start-time (match-string 1))
6034 (end-time (match-string 2)))
6035 (setq s1 (match-string 1)
6036 s2 (match-string 2)
6037 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6038 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6039 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6040 ;; Only allow days between the limits, because the normal
6041 ;; date stamps will catch the limits.
6042 (save-excursion
6043 (setq todo-state (org-get-todo-state))
6044 (setq donep (member todo-state org-done-keywords))
6045 (if (and donep org-agenda-skip-timestamp-if-done)
6046 (throw :skip t))
6047 (setq marker (org-agenda-new-marker (point)))
6048 (setq category (org-get-category)
6049 category-pos (get-text-property (point) 'org-category-position))
6050 (if (not (re-search-backward org-outline-regexp-bol nil t))
6051 (setq txt org-agenda-no-heading-message)
6052 (goto-char (match-beginning 0))
6053 (setq hdmarker (org-agenda-new-marker (point)))
6054 (setq tags (org-get-tags-at))
6055 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6056 (setq head (match-string 1))
6057 (let ((remove-re
6058 (if org-agenda-remove-timeranges-from-blocks
6059 (concat
6060 "<" (regexp-quote s1) ".*?>"
6061 "--"
6062 "<" (regexp-quote s2) ".*?>")
6063 nil)))
6064 (setq txt (org-agenda-format-item
6065 (format
6066 (nth (if (= d1 d2) 0 1)
6067 org-agenda-timerange-leaders)
6068 (1+ (- d0 d1)) (1+ (- d2 d1)))
6069 head category tags
6070 (cond ((and (= d1 d0) (= d2 d0))
6071 (concat "<" start-time ">--<" end-time ">"))
6072 ((= d1 d0)
6073 (concat "<" start-time ">"))
6074 ((= d2 d0)
6075 (concat "<" end-time ">")))
6076 remove-re))))
6077 (org-add-props txt props
6078 'org-marker marker 'org-hd-marker hdmarker
6079 'type "block" 'date date
6080 'todo-state todo-state
6081 'priority (org-get-priority txt) 'org-category category
6082 'org-category-position category-pos)
6083 (push txt ee))))
6084 (goto-char pos)))
6085 ;; Sort the entries by expiration date.
6086 (nreverse ee)))
6088 ;;; Agenda presentation and sorting
6090 (defvar org-prefix-has-time nil
6091 "A flag, set by `org-compile-prefix-format'.
6092 The flag is set if the currently compiled format contains a `%t'.")
6093 (defvar org-prefix-has-tag nil
6094 "A flag, set by `org-compile-prefix-format'.
6095 The flag is set if the currently compiled format contains a `%T'.")
6096 (defvar org-prefix-has-effort nil
6097 "A flag, set by `org-compile-prefix-format'.
6098 The flag is set if the currently compiled format contains a `%e'.")
6099 (defvar org-prefix-category-length nil
6100 "Used by `org-compile-prefix-format' to remember the category field width.")
6101 (defvar org-prefix-category-max-length nil
6102 "Used by `org-compile-prefix-format' to remember the category field width.")
6104 (defun org-agenda-get-category-icon (category)
6105 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6106 (dolist (entry org-agenda-category-icon-alist)
6107 (when (org-string-match-p (car entry) category)
6108 (if (listp (cadr entry))
6109 (return (cadr entry))
6110 (return (apply 'create-image (cdr entry)))))))
6112 (defun org-agenda-format-item (extra txt &optional category tags dotime
6113 remove-re habitp)
6114 "Format TXT to be inserted into the agenda buffer.
6115 In particular, it adds the prefix and corresponding text properties. EXTRA
6116 must be a string and replaces the `%s' specifier in the prefix format.
6117 CATEGORY (string, symbol or nil) may be used to overrule the default
6118 category taken from local variable or file name. It will replace the `%c'
6119 specifier in the format. DOTIME, when non-nil, indicates that a
6120 time-of-day should be extracted from TXT for sorting of this entry, and for
6121 the `%t' specifier in the format. When DOTIME is a string, this string is
6122 searched for a time before TXT is. TAGS can be the tags of the headline.
6123 Any match of REMOVE-RE will be removed from TXT."
6124 ;; We keep the org-prefix-* variable values along with a compiled
6125 ;; formatter, so that multiple agendas existing at the same time, do
6126 ;; not step on each other toes.
6128 ;; It was inconvenient to make these variables buffer local in
6129 ;; Agenda buffers, because this function expects to be called with
6130 ;; the buffer where item comes from being current, and not agenda
6131 ;; buffer
6132 (let* ((bindings (car org-prefix-format-compiled))
6133 (formatter (cadr org-prefix-format-compiled)))
6134 (loop for (var value) in bindings
6135 do (set var value))
6136 (save-match-data
6137 ;; Diary entries sometimes have extra whitespace at the beginning
6138 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
6140 ;; Fix the tags part in txt
6141 (setq txt (org-agenda-fix-displayed-tags
6142 txt tags
6143 org-agenda-show-inherited-tags
6144 org-agenda-hide-tags-regexp))
6145 (let* ((category (or category
6146 (if (stringp org-category)
6147 org-category
6148 (and org-category (symbol-name org-category)))
6149 (if buffer-file-name
6150 (file-name-sans-extension
6151 (file-name-nondirectory buffer-file-name))
6152 "")))
6153 (category-icon (org-agenda-get-category-icon category))
6154 (category-icon (if category-icon
6155 (propertize " " 'display category-icon)
6156 ""))
6157 ;; time, tag, effort are needed for the eval of the prefix format
6158 (tag (if tags (nth (1- (length tags)) tags) ""))
6159 time effort neffort
6160 (ts (if dotime (concat
6161 (if (stringp dotime) dotime "")
6162 (and org-agenda-search-headline-for-time txt))))
6163 (time-of-day (and dotime (org-get-time-of-day ts)))
6164 stamp plain s0 s1 s2 rtn srp l
6165 duration thecategory)
6166 (and (derived-mode-p 'org-mode) buffer-file-name
6167 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6168 (when (and dotime time-of-day)
6169 ;; Extract starting and ending time and move them to prefix
6170 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6171 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6172 (setq s0 (match-string 0 ts)
6173 srp (and stamp (match-end 3))
6174 s1 (match-string (if plain 1 2) ts)
6175 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6177 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6178 ;; them, we might want to remove them there to avoid duplication.
6179 ;; The user can turn this off with a variable.
6180 (if (and org-prefix-has-time
6181 org-agenda-remove-times-when-in-prefix (or stamp plain)
6182 (string-match (concat (regexp-quote s0) " *") txt)
6183 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6184 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6185 (= (match-beginning 0) 0)
6187 (setq txt (replace-match "" nil nil txt))))
6188 ;; Normalize the time(s) to 24 hour
6189 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6190 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6192 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6193 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6194 (setq s2
6195 (org-minutes-to-hh:mm-string
6196 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6198 ;; Compute the duration
6199 (when s2
6200 (setq duration (- (org-hh:mm-string-to-minutes s2)
6201 (org-hh:mm-string-to-minutes s1)))))
6203 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6204 txt)
6205 ;; Tags are in the string
6206 (if (or (eq org-agenda-remove-tags t)
6207 (and org-agenda-remove-tags
6208 org-prefix-has-tag))
6209 (setq txt (replace-match "" t t txt))
6210 (setq txt (replace-match
6211 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6212 (match-string 2 txt))
6213 t t txt))))
6214 (when (derived-mode-p 'org-mode)
6215 (setq effort
6216 (condition-case nil
6217 (org-get-effort
6218 (or (get-text-property 0 'org-hd-marker txt)
6219 (get-text-property 0 'org-marker txt)))
6220 (error nil)))
6221 (when effort
6222 (setq neffort (org-duration-string-to-minutes effort)
6223 effort (setq effort (concat "[" effort "]")))))
6224 ;; prevent erroring out with %e format when there is no effort
6225 (or effort (setq effort ""))
6227 (when remove-re
6228 (while (string-match remove-re txt)
6229 (setq txt (replace-match "" t t txt))))
6231 ;; Set org-heading property on `txt' to mark the start of the
6232 ;; heading.
6233 (add-text-properties 0 (length txt) '(org-heading t) txt)
6235 ;; Prepare the variables needed in the eval of the compiled format
6236 (setq time (cond (s2 (concat
6237 (org-agenda-time-of-day-to-ampm-maybe s1)
6238 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6239 (if org-agenda-timegrid-use-ampm " ")))
6240 (s1 (concat
6241 (org-agenda-time-of-day-to-ampm-maybe s1)
6242 (if org-agenda-timegrid-use-ampm
6243 "........ "
6244 "......")))
6245 (t ""))
6246 extra (or (and (not habitp) extra) "")
6247 category (if (symbolp category) (symbol-name category) category)
6248 thecategory (copy-sequence category))
6249 (if (string-match org-bracket-link-regexp category)
6250 (progn
6251 (setq l (if (match-end 3)
6252 (- (match-end 3) (match-beginning 3))
6253 (- (match-end 1) (match-beginning 1))))
6254 (when (< l (or org-prefix-category-length 0))
6255 (setq category (copy-sequence category))
6256 (org-add-props category nil
6257 'extra-space (make-string
6258 (- org-prefix-category-length l 1) ?\ ))))
6259 (if (and org-prefix-category-max-length
6260 (>= (length category) org-prefix-category-max-length))
6261 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6262 ;; Evaluate the compiled format
6263 (setq rtn (concat (eval formatter) txt))
6265 ;; And finally add the text properties
6266 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6267 (org-add-props rtn nil
6268 'org-category (if thecategory (downcase thecategory) category)
6269 'tags (mapcar 'org-downcase-keep-props tags)
6270 'org-highest-priority org-highest-priority
6271 'org-lowest-priority org-lowest-priority
6272 'time-of-day time-of-day
6273 'duration duration
6274 'effort effort
6275 'effort-minutes neffort
6276 'txt txt
6277 'time time
6278 'extra extra
6279 'format org-prefix-format-compiled
6280 'dotime dotime)))))
6282 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6283 "Remove tags string from TXT, and add a modified list of tags.
6284 The modified list may contain inherited tags, and tags matched by
6285 `org-agenda-hide-tags-regexp' will be removed."
6286 (when (or add-inherited hide-re)
6287 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6288 (setq txt (substring txt 0 (match-beginning 0))))
6289 (setq tags
6290 (delq nil
6291 (mapcar (lambda (tg)
6292 (if (or (and hide-re (string-match hide-re tg))
6293 (and (not add-inherited)
6294 (get-text-property 0 'inherited tg)))
6296 tg))
6297 tags)))
6298 (when tags
6299 (let ((have-i (get-text-property 0 'inherited (car tags)))
6301 (setq txt (concat txt " :"
6302 (mapconcat
6303 (lambda (x)
6304 (setq i (get-text-property 0 'inherited x))
6305 (if (and have-i (not i))
6306 (progn
6307 (setq have-i nil)
6308 (concat ":" x))
6310 tags ":")
6311 (if have-i "::" ":"))))))
6312 txt)
6314 (defun org-downcase-keep-props (s)
6315 (let ((props (text-properties-at 0 s)))
6316 (setq s (downcase s))
6317 (add-text-properties 0 (length s) props s)
6320 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6321 (defvar org-agenda-sorting-strategy-selected nil)
6323 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6324 (catch 'exit
6325 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6326 ((and todayp (member 'today (car org-agenda-time-grid))))
6327 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6328 ((member 'weekly (car org-agenda-time-grid)))
6329 (t (throw 'exit list)))
6330 (let* ((have (delq nil (mapcar
6331 (lambda (x) (get-text-property 1 'time-of-day x))
6332 list)))
6333 (string (nth 1 org-agenda-time-grid))
6334 (gridtimes (nth 2 org-agenda-time-grid))
6335 (req (car org-agenda-time-grid))
6336 (remove (member 'remove-match req))
6337 new time)
6338 (if (and (member 'require-timed req) (not have))
6339 ;; don't show empty grid
6340 (throw 'exit list))
6341 (while (setq time (pop gridtimes))
6342 (unless (and remove (member time have))
6343 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6344 (push (org-agenda-format-item
6345 nil string "" nil
6346 (concat (substring time 0 -2) ":" (substring time -2)))
6347 new)
6348 (put-text-property
6349 2 (length (car new)) 'face 'org-time-grid (car new))))
6350 (when (and todayp org-agenda-show-current-time-in-grid)
6351 (push (org-agenda-format-item
6353 org-agenda-current-time-string
6354 "" nil
6355 (format-time-string "%H:%M "))
6356 new)
6357 (put-text-property
6358 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6360 (if (member 'time-up org-agenda-sorting-strategy-selected)
6361 (append new list)
6362 (append list new)))))
6364 (defun org-compile-prefix-format (key)
6365 "Compile the prefix format into a Lisp form that can be evaluated.
6366 The resulting form and associated variable bindings is returned
6367 and stored in the variable `org-prefix-format-compiled'."
6368 (setq org-prefix-has-time nil org-prefix-has-tag nil
6369 org-prefix-category-length nil
6370 org-prefix-has-effort nil)
6371 (let ((s (cond
6372 ((stringp org-agenda-prefix-format)
6373 org-agenda-prefix-format)
6374 ((assq key org-agenda-prefix-format)
6375 (cdr (assq key org-agenda-prefix-format)))
6376 (t " %-12:c%?-12t% s")))
6377 (start 0)
6378 varform vars var e c f opt)
6379 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6380 s start)
6381 (setq var (or (cdr (assoc (match-string 4 s)
6382 '(("c" . category) ("t" . time) ("s" . extra)
6383 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6384 'eval)
6385 c (or (match-string 3 s) "")
6386 opt (match-beginning 1)
6387 start (1+ (match-beginning 0)))
6388 (if (equal var 'time) (setq org-prefix-has-time t))
6389 (if (equal var 'tag) (setq org-prefix-has-tag t))
6390 (if (equal var 'effort) (setq org-prefix-has-effort t))
6391 (setq f (concat "%" (match-string 2 s) "s"))
6392 (when (equal var 'category)
6393 (setq org-prefix-category-length
6394 (floor (abs (string-to-number (match-string 2 s)))))
6395 (setq org-prefix-category-max-length
6396 (let ((x (match-string 2 s)))
6397 (save-match-data
6398 (if (string-match "\\.[0-9]+" x)
6399 (string-to-number (substring (match-string 0 x) 1)))))))
6400 (if (eq var 'eval)
6401 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6402 (if opt
6403 (setq varform
6404 `(if (equal "" ,var)
6406 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6407 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6408 (setq s (replace-match "%s" t nil s))
6409 (push varform vars))
6410 (setq vars (nreverse vars))
6411 (with-current-buffer (or org-agenda-buffer (current-buffer))
6412 (setq org-prefix-format-compiled
6413 (list
6414 `((org-prefix-has-time ,org-prefix-has-time)
6415 (org-prefix-has-tag ,org-prefix-has-tag)
6416 (org-prefix-category-length ,org-prefix-category-length)
6417 (org-prefix-has-effort ,org-prefix-has-effort))
6418 `(format ,s ,@vars))))))
6420 (defun org-set-sorting-strategy (key)
6421 (if (symbolp (car org-agenda-sorting-strategy))
6422 ;; the old format
6423 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6424 (setq org-agenda-sorting-strategy-selected
6425 (or (cdr (assq key org-agenda-sorting-strategy))
6426 (cdr (assq 'agenda org-agenda-sorting-strategy))
6427 '(time-up category-keep priority-down)))))
6429 (defun org-get-time-of-day (s &optional string mod24)
6430 "Check string S for a time of day.
6431 If found, return it as a military time number between 0 and 2400.
6432 If not found, return nil.
6433 The optional STRING argument forces conversion into a 5 character wide string
6434 HH:MM."
6435 (save-match-data
6436 (when
6437 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6438 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6439 (let* ((h (string-to-number (match-string 1 s)))
6440 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6441 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6442 (am-p (equal ampm "am"))
6443 (h1 (cond ((not ampm) h)
6444 ((= h 12) (if am-p 0 12))
6445 (t (+ h (if am-p 0 12)))))
6446 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6447 (mod h1 24) h1))
6448 (t0 (+ (* 100 h2) m))
6449 (t1 (concat (if (>= h1 24) "+" " ")
6450 (if (and org-agenda-time-leading-zero
6451 (< t0 1000)) "0" "")
6452 (if (< t0 100) "0" "")
6453 (if (< t0 10) "0" "")
6454 (int-to-string t0))))
6455 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6457 (defvar org-agenda-before-sorting-filter-function nil
6458 "Function to be applied to agenda items prior to sorting.
6459 Prior to sorting also means just before they are inserted into the agenda.
6461 To aid sorting, you may revisit the original entries and add more text
6462 properties which will later be used by the sorting functions.
6464 The function should take a string argument, an agenda line.
6465 It has access to the text properties in that line, which contain among
6466 other things, the property `org-hd-marker' that points to the entry
6467 where the line comes from. Note that not all lines going into the agenda
6468 have this property, only most.
6470 The function should return the modified string. It is probably best
6471 to ONLY change text properties.
6473 You can also use this function as a filter, by returning nil for lines
6474 you don't want to have in the agenda at all. For this application, you
6475 could bind the variable in the options section of a custom command.")
6477 (defun org-agenda-finalize-entries (list &optional nosort)
6478 "Sort and concatenate the agenda items."
6479 (setq list (mapcar 'org-agenda-highlight-todo list))
6480 (if nosort
6481 list
6482 (when org-agenda-before-sorting-filter-function
6483 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6484 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6486 (defun org-agenda-highlight-todo (x)
6487 (let ((org-done-keywords org-done-keywords-for-agenda)
6488 (case-fold-search nil)
6490 (if (eq x 'line)
6491 (save-excursion
6492 (beginning-of-line 1)
6493 (setq re (org-get-at-bol 'org-todo-regexp))
6494 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6495 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6496 (add-text-properties (match-beginning 0) (match-end 1)
6497 (list 'face (org-get-todo-face 1)))
6498 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6499 (delete-region (match-beginning 1) (1- (match-end 0)))
6500 (goto-char (match-beginning 1))
6501 (insert (format org-agenda-todo-keyword-format s)))))
6502 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6503 (setq re (get-text-property 0 'org-todo-regexp x))
6504 (when (and re
6505 ;; Test `pl' because if there's no heading content,
6506 ;; there's no point matching to highlight. Note
6507 ;; that if we didn't test `pl' first, and there
6508 ;; happened to be no keyword from `org-todo-regexp'
6509 ;; on this heading line, then the `equal' comparison
6510 ;; afterwards would spuriously succeed in the case
6511 ;; where `pl' is nil -- causing an args-out-of-range
6512 ;; error when we try to add text properties to text
6513 ;; that isn't there.
6515 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6516 x pl) pl))
6517 (add-text-properties
6518 (or (match-end 1) (match-end 0)) (match-end 0)
6519 (list 'face (org-get-todo-face (match-string 2 x)))
6521 (when (match-end 1)
6522 (setq x (concat (substring x 0 (match-end 1))
6523 (format org-agenda-todo-keyword-format
6524 (match-string 2 x))
6525 (org-add-props " " (text-properties-at 0 x))
6526 (substring x (match-end 3)))))))
6527 x)))
6529 (defsubst org-cmp-priority (a b)
6530 "Compare the priorities of string A and B."
6531 (let ((pa (or (get-text-property 1 'priority a) 0))
6532 (pb (or (get-text-property 1 'priority b) 0)))
6533 (cond ((> pa pb) +1)
6534 ((< pa pb) -1))))
6536 (defsubst org-cmp-effort (a b)
6537 "Compare the effort values of string A and B."
6538 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6539 (ea (or (get-text-property 1 'effort-minutes a) def))
6540 (eb (or (get-text-property 1 'effort-minutes b) def)))
6541 (cond ((> ea eb) +1)
6542 ((< ea eb) -1))))
6544 (defsubst org-cmp-category (a b)
6545 "Compare the string values of categories of strings A and B."
6546 (let ((ca (or (get-text-property 1 'org-category a) ""))
6547 (cb (or (get-text-property 1 'org-category b) "")))
6548 (cond ((string-lessp ca cb) -1)
6549 ((string-lessp cb ca) +1))))
6551 (defsubst org-cmp-todo-state (a b)
6552 "Compare the todo states of strings A and B."
6553 (let* ((ma (or (get-text-property 1 'org-marker a)
6554 (get-text-property 1 'org-hd-marker a)))
6555 (mb (or (get-text-property 1 'org-marker b)
6556 (get-text-property 1 'org-hd-marker b)))
6557 (fa (and ma (marker-buffer ma)))
6558 (fb (and mb (marker-buffer mb)))
6559 (todo-kwds
6560 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6561 (and fb (with-current-buffer fb org-todo-keywords-1))))
6562 (ta (or (get-text-property 1 'todo-state a) ""))
6563 (tb (or (get-text-property 1 'todo-state b) ""))
6564 (la (- (length (member ta todo-kwds))))
6565 (lb (- (length (member tb todo-kwds))))
6566 (donepa (member ta org-done-keywords-for-agenda))
6567 (donepb (member tb org-done-keywords-for-agenda)))
6568 (cond ((and donepa (not donepb)) -1)
6569 ((and (not donepa) donepb) +1)
6570 ((< la lb) -1)
6571 ((< lb la) +1))))
6573 (defsubst org-cmp-alpha (a b)
6574 "Compare the headlines, alphabetically."
6575 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6576 (plb (text-property-any 0 (length b) 'org-heading t b))
6577 (ta (and pla (substring a pla)))
6578 (tb (and plb (substring b plb))))
6579 (when pla
6580 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6581 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6582 (setq ta (substring ta (match-end 0))))
6583 (setq ta (downcase ta)))
6584 (when plb
6585 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6586 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6587 (setq tb (substring tb (match-end 0))))
6588 (setq tb (downcase tb)))
6589 (cond ((not ta) +1)
6590 ((not tb) -1)
6591 ((string-lessp ta tb) -1)
6592 ((string-lessp tb ta) +1))))
6594 (defsubst org-cmp-tag (a b)
6595 "Compare the string values of the first tags of A and B."
6596 (let ((ta (car (last (get-text-property 1 'tags a))))
6597 (tb (car (last (get-text-property 1 'tags b)))))
6598 (cond ((not ta) +1)
6599 ((not tb) -1)
6600 ((string-lessp ta tb) -1)
6601 ((string-lessp tb ta) +1))))
6603 (defsubst org-cmp-time (a b)
6604 "Compare the time-of-day values of strings A and B."
6605 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6606 (ta (or (get-text-property 1 'time-of-day a) def))
6607 (tb (or (get-text-property 1 'time-of-day b) def)))
6608 (cond ((< ta tb) -1)
6609 ((< tb ta) +1))))
6611 (defsubst org-cmp-habit-p (a b)
6612 "Compare the todo states of strings A and B."
6613 (let ((ha (get-text-property 1 'org-habit-p a))
6614 (hb (get-text-property 1 'org-habit-p b)))
6615 (cond ((and ha (not hb)) -1)
6616 ((and (not ha) hb) +1))))
6618 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6620 (defun org-entries-lessp (a b)
6621 "Predicate for sorting agenda entries."
6622 ;; The following variables will be used when the form is evaluated.
6623 ;; So even though the compiler complains, keep them.
6624 (let* ((ss org-agenda-sorting-strategy-selected)
6625 (time-up (and (org-em 'time-up 'time-down ss)
6626 (org-cmp-time a b)))
6627 (time-down (if time-up (- time-up) nil))
6628 (priority-up (and (org-em 'priority-up 'priority-down ss)
6629 (org-cmp-priority a b)))
6630 (priority-down (if priority-up (- priority-up) nil))
6631 (effort-up (and (org-em 'effort-up 'effort-down ss)
6632 (org-cmp-effort a b)))
6633 (effort-down (if effort-up (- effort-up) nil))
6634 (category-up (and (or (org-em 'category-up 'category-down ss)
6635 (memq 'category-keep ss))
6636 (org-cmp-category a b)))
6637 (category-down (if category-up (- category-up) nil))
6638 (category-keep (if category-up +1 nil))
6639 (tag-up (and (org-em 'tag-up 'tag-down ss)
6640 (org-cmp-tag a b)))
6641 (tag-down (if tag-up (- tag-up) nil))
6642 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6643 (org-cmp-todo-state a b)))
6644 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6645 (habit-up (and (org-em 'habit-up 'habit-down ss)
6646 (org-cmp-habit-p a b)))
6647 (habit-down (if habit-up (- habit-up) nil))
6648 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6649 (org-cmp-alpha a b)))
6650 (alpha-down (if alpha-up (- alpha-up) nil))
6651 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6652 user-defined-up user-defined-down)
6653 (if (and need-user-cmp org-agenda-cmp-user-defined
6654 (functionp org-agenda-cmp-user-defined))
6655 (setq user-defined-up
6656 (funcall org-agenda-cmp-user-defined a b)
6657 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6658 (cdr (assoc
6659 (eval (cons 'or org-agenda-sorting-strategy-selected))
6660 '((-1 . t) (1 . nil) (nil . nil))))))
6662 ;;; Agenda restriction lock
6664 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6665 "Overlay to mark the headline to which agenda commands are restricted.")
6666 (overlay-put org-agenda-restriction-lock-overlay
6667 'face 'org-agenda-restriction-lock)
6668 (overlay-put org-agenda-restriction-lock-overlay
6669 'help-echo "Agendas are currently limited to this subtree.")
6670 (org-detach-overlay org-agenda-restriction-lock-overlay)
6672 (defun org-agenda-set-restriction-lock (&optional type)
6673 "Set restriction lock for agenda, to current subtree or file.
6674 Restriction will be the file if TYPE is `file', or if type is the
6675 universal prefix '(4), or if the cursor is before the first headline
6676 in the file. Otherwise, restriction will be to the current subtree."
6677 (interactive "P")
6678 (and (equal type '(4)) (setq type 'file))
6679 (setq type (cond
6680 (type type)
6681 ((org-at-heading-p) 'subtree)
6682 ((condition-case nil (org-back-to-heading t) (error nil))
6683 'subtree)
6684 (t 'file)))
6685 (if (eq type 'subtree)
6686 (progn
6687 (setq org-agenda-restrict t)
6688 (setq org-agenda-overriding-restriction 'subtree)
6689 (put 'org-agenda-files 'org-restrict
6690 (list (buffer-file-name (buffer-base-buffer))))
6691 (org-back-to-heading t)
6692 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6693 (move-marker org-agenda-restrict-begin (point))
6694 (move-marker org-agenda-restrict-end
6695 (save-excursion (org-end-of-subtree t)))
6696 (message "Locking agenda restriction to subtree"))
6697 (put 'org-agenda-files 'org-restrict
6698 (list (buffer-file-name (buffer-base-buffer))))
6699 (setq org-agenda-restrict nil)
6700 (setq org-agenda-overriding-restriction 'file)
6701 (move-marker org-agenda-restrict-begin nil)
6702 (move-marker org-agenda-restrict-end nil)
6703 (message "Locking agenda restriction to file"))
6704 (setq current-prefix-arg nil)
6705 (org-agenda-maybe-redo))
6707 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6708 "Remove the agenda restriction lock."
6709 (interactive "P")
6710 (org-detach-overlay org-agenda-restriction-lock-overlay)
6711 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6712 (setq org-agenda-overriding-restriction nil)
6713 (setq org-agenda-restrict nil)
6714 (put 'org-agenda-files 'org-restrict nil)
6715 (move-marker org-agenda-restrict-begin nil)
6716 (move-marker org-agenda-restrict-end nil)
6717 (setq current-prefix-arg nil)
6718 (message "Agenda restriction lock removed")
6719 (or noupdate (org-agenda-maybe-redo)))
6721 (defun org-agenda-maybe-redo ()
6722 "If there is any window showing the agenda view, update it."
6723 (let ((w (get-buffer-window org-agenda-buffer-name t))
6724 (w0 (selected-window)))
6725 (when w
6726 (select-window w)
6727 (org-agenda-redo)
6728 (select-window w0)
6729 (if org-agenda-overriding-restriction
6730 (message "Agenda view shifted to new %s restriction"
6731 org-agenda-overriding-restriction)
6732 (message "Agenda restriction lock removed")))))
6734 ;;; Agenda commands
6736 (defun org-agenda-check-type (error &rest types)
6737 "Check if agenda buffer is of allowed type.
6738 If ERROR is non-nil, throw an error, otherwise just return nil."
6739 (if (not org-agenda-type)
6740 (error "No Org agenda currently displayed")
6741 (if (memq org-agenda-type types)
6743 (if error
6744 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6745 nil))))
6747 (defun org-agenda-Quit (&optional arg)
6748 "Exit agenda by removing the window or the buffer."
6749 (interactive)
6750 (if org-agenda-columns-active
6751 (org-columns-quit)
6752 (let ((buf (current-buffer)))
6753 (if (eq org-agenda-window-setup 'other-frame)
6754 (progn
6755 (org-agenda-reset-markers)
6756 (kill-buffer buf)
6757 (org-columns-remove-overlays)
6758 (setq org-agenda-archives-mode nil)
6759 (delete-frame))
6760 (and (not (eq org-agenda-window-setup 'current-window))
6761 (not (one-window-p))
6762 (delete-window))
6763 (org-agenda-reset-markers)
6764 (kill-buffer buf)
6765 (org-columns-remove-overlays)
6766 (setq org-agenda-archives-mode nil)))
6767 ;; Maybe restore the pre-agenda window configuration.
6768 (and org-agenda-restore-windows-after-quit
6769 (not (eq org-agenda-window-setup 'other-frame))
6770 org-agenda-pre-window-conf
6771 (set-window-configuration org-agenda-pre-window-conf)
6772 (setq org-agenda-pre-window-conf nil))))
6774 (defun org-agenda-quit ()
6775 "Exit agenda by killing agenda buffer or burying it when
6776 `org-agenda-sticky' is non-NIL"
6777 (interactive)
6778 (if (and (eq org-indirect-buffer-display 'other-window)
6779 org-last-indirect-buffer)
6780 (delete-window (get-buffer-window org-last-indirect-buffer)))
6781 (if org-agenda-columns-active
6782 (org-columns-quit)
6783 (if org-agenda-sticky
6784 (let ((buf (current-buffer)))
6785 (if (eq org-agenda-window-setup 'other-frame)
6786 (progn
6787 (delete-frame))
6788 (and (not (eq org-agenda-window-setup 'current-window))
6789 (not (one-window-p))
6790 (delete-window)))
6791 (with-current-buffer buf
6792 (bury-buffer)
6793 ;; Maybe restore the pre-agenda window configuration.
6794 (and org-agenda-restore-windows-after-quit
6795 (not (eq org-agenda-window-setup 'other-frame))
6796 org-agenda-pre-window-conf
6797 (set-window-configuration org-agenda-pre-window-conf)
6798 (setq org-agenda-pre-window-conf nil))))
6799 (org-agenda-Quit))))
6801 (defun org-agenda-exit ()
6802 "Exit agenda by removing the window or the buffer.
6803 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6804 Org-mode buffers visited directly by the user will not be touched."
6805 (interactive)
6806 (org-release-buffers org-agenda-new-buffers)
6807 (setq org-agenda-new-buffers nil)
6808 (org-agenda-Quit))
6810 (defun org-agenda-kill-all-agenda-buffers ()
6811 "Kill all buffers in `org-agenda-mode'.
6812 This is used when toggling sticky agendas. You can also explicitly invoke it
6813 with `C-c a C-k'."
6814 (interactive)
6815 (let (blist)
6816 (dolist (buf (buffer-list))
6817 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6818 (push buf blist)))
6819 (mapc 'kill-buffer blist)))
6821 (defun org-agenda-execute (arg)
6822 "Execute another agenda command, keeping same window.
6823 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6824 in the agenda."
6825 (interactive "P")
6826 (let ((org-agenda-window-setup 'current-window))
6827 (org-agenda arg)))
6829 (defun org-agenda-redo (&optional all)
6830 "Rebuild possibly ALL agenda view(s) in the current buffer."
6831 (interactive "P")
6832 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6833 (cpa (unless (eq all t) current-prefix-arg))
6834 (org-agenda-doing-sticky-redo org-agenda-sticky)
6835 (org-agenda-sticky nil)
6836 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6837 org-agenda-buffer-name))
6838 (org-agenda-keep-modes t)
6839 (tag-filter org-agenda-tag-filter)
6840 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6841 (top-cat-filter org-agenda-top-category-filter)
6842 (cat-filter org-agenda-category-filter)
6843 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6844 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6845 (cols org-agenda-columns-active)
6846 (line (org-current-line))
6847 (window-line (- line (org-current-line (window-start))))
6848 (lprops (get 'org-agenda-redo-command 'org-lprops))
6849 (redo-cmd (get-text-property p 'org-redo-cmd))
6850 (last-args (get-text-property p 'org-last-args))
6851 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6852 (org-agenda-overriding-cmd-arguments
6853 (unless (eq all t)
6854 (cond ((listp last-args)
6855 (cons (or cpa (car last-args)) (cdr last-args)))
6856 ((stringp last-args)
6857 last-args))))
6858 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6859 (put 'org-agenda-tag-filter :preset-filter nil)
6860 (put 'org-agenda-category-filter :preset-filter nil)
6861 (and cols (org-columns-quit))
6862 (message "Rebuilding agenda buffer...")
6863 (if series-redo-cmd
6864 (eval series-redo-cmd)
6865 (org-let lprops '(eval redo-cmd)))
6866 (setq org-agenda-undo-list nil
6867 org-agenda-pending-undo-list nil)
6868 (message "Rebuilding agenda buffer...done")
6869 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6870 (put 'org-agenda-category-filter :preset-filter cat-preset)
6871 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6872 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6873 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6874 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6875 (org-goto-line line)
6876 (recenter window-line)))
6878 (defvar org-global-tags-completion-table nil)
6879 (defvar org-agenda-filter-form nil)
6880 (defvar org-agenda-filtered-by-category nil)
6882 (defun org-agenda-filter-by-category (strip)
6883 "Keep only those lines in the agenda buffer that have a specific category.
6884 The category is that of the current line."
6885 (interactive "P")
6886 (if (and org-agenda-filtered-by-category
6887 org-agenda-category-filter)
6888 (org-agenda-filter-show-all-cat)
6889 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6890 (if cat (org-agenda-filter-apply
6891 (list (concat (if strip "-" "+") cat)) 'category)
6892 (error "No category at point")))))
6894 (defun org-find-top-category (&optional pos)
6895 (save-excursion
6896 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6897 (if pos (goto-char pos))
6898 ;; Skip up to the topmost parent
6899 (while (ignore-errors (outline-up-heading 1) t))
6900 (ignore-errors
6901 (nth 4 (org-heading-components))))))
6903 (defvar org-agenda-filtered-by-top-category nil)
6905 (defun org-agenda-filter-by-top-category (strip)
6906 "Keep only those lines in the agenda buffer that have a specific category.
6907 The category is that of the current line."
6908 (interactive "P")
6909 (if org-agenda-filtered-by-top-category
6910 (progn
6911 (setq org-agenda-filtered-by-top-category nil
6912 org-agenda-top-category-filter nil)
6913 (org-agenda-filter-show-all-cat))
6914 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6915 (if cat (org-agenda-filter-top-category-apply cat strip)
6916 (error "No top-level category at point")))))
6918 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6919 "Keep only those lines in the agenda buffer that have a specific tag.
6920 The tag is selected with its fast selection letter, as configured.
6921 With prefix argument STRIP, remove all lines that do have the tag.
6922 A lisp caller can specify CHAR. NARROW means that the new tag should be
6923 used to narrow the search - the interactive user can also press `-' or `+'
6924 to switch to narrowing."
6925 (interactive "P")
6926 (let* ((alist org-tag-alist-for-agenda)
6927 (tag-chars (mapconcat
6928 (lambda (x) (if (and (not (symbolp (car x)))
6929 (cdr x))
6930 (char-to-string (cdr x))
6931 ""))
6932 alist ""))
6933 (efforts (org-split-string
6934 (or (cdr (assoc (concat org-effort-property "_ALL")
6935 org-global-properties))
6936 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6937 "")))
6938 (effort-op org-agenda-filter-effort-default-operator)
6939 (effort-prompt "")
6940 (inhibit-read-only t)
6941 (current org-agenda-tag-filter)
6942 maybe-refresh a n tag)
6943 (unless char
6944 (message
6945 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6946 (if narrow "Narrow" "Filter") tag-chars
6947 (if org-agenda-auto-exclude-function "[RET], " ""))
6948 (setq char (read-char-exclusive)))
6949 (when (member char '(?+ ?-))
6950 ;; Narrowing down
6951 (cond ((equal char ?-) (setq strip t narrow t))
6952 ((equal char ?+) (setq strip nil narrow t)))
6953 (message
6954 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6955 (setq char (read-char-exclusive)))
6956 (when (member char '(?< ?> ?= ??))
6957 ;; An effort operator
6958 (setq effort-op (char-to-string char))
6959 (setq alist nil) ; to make sure it will be interpreted as effort.
6960 (unless (equal char ??)
6961 (loop for i from 0 to 9 do
6962 (setq effort-prompt
6963 (concat
6964 effort-prompt " ["
6965 (if (= i 9) "0" (int-to-string (1+ i)))
6966 "]" (nth i efforts))))
6967 (message "Effort%s: %s " effort-op effort-prompt)
6968 (setq char (read-char-exclusive))
6969 (when (or (< char ?0) (> char ?9))
6970 (error "Need 1-9,0 to select effort"))))
6971 (when (equal char ?\t)
6972 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6973 (org-set-local 'org-global-tags-completion-table
6974 (org-global-tags-completion-table)))
6975 (let ((completion-ignore-case t))
6976 (setq tag (org-icompleting-read
6977 "Tag: " org-global-tags-completion-table))))
6978 (cond
6979 ((equal char ?\r)
6980 (org-agenda-filter-show-all-tag)
6981 (when org-agenda-auto-exclude-function
6982 (setq org-agenda-tag-filter '())
6983 (dolist (tag (org-agenda-get-represented-tags))
6984 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6985 (if modifier
6986 (push modifier org-agenda-tag-filter))))
6987 (if (not (null org-agenda-tag-filter))
6988 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6989 (setq maybe-refresh t))
6990 ((equal char ?/)
6991 (org-agenda-filter-show-all-tag)
6992 (when (get 'org-agenda-tag-filter :preset-filter)
6993 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6994 (setq maybe-refresh t))
6995 ((equal char ?. )
6996 (setq org-agenda-tag-filter
6997 (mapcar (lambda(tag) (concat "+" tag))
6998 (org-get-at-bol 'tags)))
6999 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7000 (setq maybe-refresh t))
7001 ((or (equal char ?\ )
7002 (setq a (rassoc char alist))
7003 (and (>= char ?0) (<= char ?9)
7004 (setq n (if (= char ?0) 9 (- char ?0 1))
7005 tag (concat effort-op (nth n efforts))
7006 a (cons tag nil)))
7007 (and (= char ??)
7008 (setq tag "?eff")
7009 a (cons tag nil))
7010 (and tag (setq a (cons tag nil))))
7011 (org-agenda-filter-show-all-tag)
7012 (setq tag (car a))
7013 (setq org-agenda-tag-filter
7014 (cons (concat (if strip "-" "+") tag)
7015 (if narrow current nil)))
7016 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7017 (setq maybe-refresh t))
7018 (t (error "Invalid tag selection character %c" char)))
7019 (when (and maybe-refresh
7020 (eq org-agenda-clockreport-mode 'with-filter))
7021 (org-agenda-redo))))
7023 (defun org-agenda-get-represented-tags ()
7024 "Get a list of all tags currently represented in the agenda."
7025 (let (p tags)
7026 (save-excursion
7027 (goto-char (point-min))
7028 (while (setq p (next-single-property-change (point) 'tags))
7029 (goto-char p)
7030 (mapc (lambda (x) (add-to-list 'tags x))
7031 (get-text-property (point) 'tags))))
7032 tags))
7034 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7035 "Refine the current filter. See `org-agenda-filter-by-tag'."
7036 (interactive "P")
7037 (org-agenda-filter-by-tag strip char 'refine))
7039 (defun org-agenda-filter-make-matcher ()
7040 "Create the form that tests a line for agenda filter."
7041 (let (f f1)
7042 ;; first compute the tag-filter matcher
7043 (dolist (x (delete-dups
7044 (append (get 'org-agenda-tag-filter
7045 :preset-filter) org-agenda-tag-filter)))
7046 (if (member x '("-" "+"))
7047 (setq f1 (if (equal x "-") 'tags '(not tags)))
7048 (if (string-match "[<=>?]" x)
7049 (setq f1 (org-agenda-filter-effort-form x))
7050 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7051 (if (equal (string-to-char x) ?-)
7052 (setq f1 (list 'not f1))))
7053 (push f1 f))
7054 ;; then compute the category-filter matcher
7055 (dolist (x (delete-dups
7056 (append (get 'org-agenda-category-filter
7057 :preset-filter) org-agenda-category-filter)))
7058 (if (equal "-" (substring x 0 1))
7059 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7060 (setq f1 (list 'equal (substring x 1) 'cat)))
7061 (push f1 f))
7062 (cons 'and (nreverse f))))
7064 (defun org-agenda-filter-effort-form (e)
7065 "Return the form to compare the effort of the current line with what E says.
7066 E looks like \"+<2:25\"."
7067 (let (op)
7068 (setq e (substring e 1))
7069 (setq op (string-to-char e) e (substring e 1))
7070 (setq op (cond ((equal op ?<) '<=)
7071 ((equal op ?>) '>=)
7072 ((equal op ??) op)
7073 (t '=)))
7074 (list 'org-agenda-compare-effort (list 'quote op)
7075 (org-duration-string-to-minutes e))))
7077 (defun org-agenda-compare-effort (op value)
7078 "Compare the effort of the current line with VALUE, using OP.
7079 If the line does not have an effort defined, return nil."
7080 (let ((eff (org-get-at-bol 'effort-minutes)))
7081 (if (equal op ??)
7082 (not eff)
7083 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7084 value))))
7086 (defun org-agenda-filter-apply (filter type)
7087 "Set FILTER as the new agenda filter and apply it."
7088 (let (tags cat)
7089 (if (eq type 'tag)
7090 (setq org-agenda-tag-filter filter)
7091 (setq org-agenda-category-filter filter))
7092 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7093 (if (and (eq type 'category)
7094 (not (equal (substring (car filter) 0 1) "-")))
7095 ;; Only set `org-agenda-filtered-by-category' to t
7096 ;; when a unique category is used as the filter
7097 (setq org-agenda-filtered-by-category t))
7098 (org-agenda-set-mode-name)
7099 (save-excursion
7100 (goto-char (point-min))
7101 (while (not (eobp))
7102 (if (org-get-at-bol 'org-marker)
7103 (progn
7104 (setq tags (org-get-at-bol 'tags) ; used in eval
7105 cat (get-text-property (point) 'org-category))
7106 (if (not (eval org-agenda-filter-form))
7107 (org-agenda-filter-hide-line type))
7108 (beginning-of-line 2))
7109 (beginning-of-line 2))))
7110 (if (get-char-property (point) 'invisible)
7111 (ignore-errors (org-agenda-previous-line)))))
7113 (defun org-agenda-filter-top-category-apply (category &optional negative)
7114 "Set FILTER as the new agenda filter and apply it."
7115 (org-agenda-set-mode-name)
7116 (save-excursion
7117 (goto-char (point-min))
7118 (while (not (eobp))
7119 (let* ((pos (org-get-at-bol 'org-hd-marker))
7120 (topcat (and pos (org-find-top-category pos))))
7121 (if (and topcat (funcall (if negative 'identity 'not)
7122 (string= category topcat)))
7123 (org-agenda-filter-hide-line 'category)))
7124 (beginning-of-line 2)))
7125 (if (get-char-property (point) 'invisible)
7126 (org-agenda-previous-line))
7127 (setq org-agenda-top-category-filter category
7128 org-agenda-filtered-by-top-category t))
7130 (defun org-agenda-filter-hide-line (type)
7131 (let (ov)
7132 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7133 (point-at-eol)))
7134 (overlay-put ov 'invisible t)
7135 (overlay-put ov 'type type)
7136 (if (eq type 'tag)
7137 (push ov org-agenda-tag-filter-overlays)
7138 (push ov org-agenda-cat-filter-overlays))))
7140 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7141 (setq pos (or pos (point)))
7142 (save-excursion
7143 (dolist (ov (overlays-at pos))
7144 (when (and (overlay-get ov 'invisible)
7145 (eq (overlay-get ov 'type) 'tag))
7146 (goto-char pos)
7147 (if (< (overlay-start ov) (point-at-eol))
7148 (move-overlay ov (point-at-eol)
7149 (overlay-end ov)))))))
7151 (defun org-agenda-filter-show-all-tag nil
7152 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7153 (setq org-agenda-tag-filter-overlays nil
7154 org-agenda-tag-filter nil
7155 org-agenda-filter-form nil)
7156 (org-agenda-set-mode-name))
7158 (defun org-agenda-filter-show-all-cat nil
7159 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7160 (setq org-agenda-cat-filter-overlays nil
7161 org-agenda-filtered-by-category nil
7162 org-agenda-category-filter nil
7163 org-agenda-filter-form nil)
7164 (org-agenda-set-mode-name))
7166 (defun org-agenda-manipulate-query-add ()
7167 "Manipulate the query by adding a search term with positive selection.
7168 Positive selection means the term must be matched for selection of an entry."
7169 (interactive)
7170 (org-agenda-manipulate-query ?\[))
7171 (defun org-agenda-manipulate-query-subtract ()
7172 "Manipulate the query by adding a search term with negative selection.
7173 Negative selection means term must not be matched for selection of an entry."
7174 (interactive)
7175 (org-agenda-manipulate-query ?\]))
7176 (defun org-agenda-manipulate-query-add-re ()
7177 "Manipulate the query by adding a search regexp with positive selection.
7178 Positive selection means the regexp must match for selection of an entry."
7179 (interactive)
7180 (org-agenda-manipulate-query ?\{))
7181 (defun org-agenda-manipulate-query-subtract-re ()
7182 "Manipulate the query by adding a search regexp with negative selection.
7183 Negative selection means regexp must not match for selection of an entry."
7184 (interactive)
7185 (org-agenda-manipulate-query ?\}))
7186 (defun org-agenda-manipulate-query (char)
7187 (cond
7188 ((memq org-agenda-type '(timeline agenda))
7189 (let ((org-agenda-include-inactive-timestamps t))
7190 (org-agenda-redo))
7191 (message "Display now includes inactive timestamps as well"))
7192 ((eq org-agenda-type 'search)
7193 (org-add-to-string
7194 'org-agenda-query-string
7195 (if org-agenda-last-search-view-search-was-boolean
7196 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7197 (?\{ . " +{}") (?\} . " -{}"))))
7198 " "))
7199 (setq org-agenda-redo-command
7200 (list 'org-search-view
7201 (car (get-text-property (min (1- (point-max)) (point))
7202 'org-last-args))
7203 org-agenda-query-string
7204 (+ (length org-agenda-query-string)
7205 (if (member char '(?\{ ?\})) 0 1))))
7206 (set-register org-agenda-query-register org-agenda-query-string)
7207 (let ((org-agenda-overriding-arguments
7208 (cdr org-agenda-redo-command)))
7209 (org-agenda-redo)))
7210 (t (error "Cannot manipulate query for %s-type agenda buffers"
7211 org-agenda-type))))
7213 (defun org-add-to-string (var string)
7214 (set var (concat (symbol-value var) string)))
7216 (defun org-agenda-goto-date (span)
7217 "Jump to DATE in agenda."
7218 (interactive "P")
7219 (let* ((org-read-date-prefer-future
7220 (eval org-agenda-jump-prefer-future))
7221 (date (org-read-date))
7222 (org-agenda-sticky-orig org-agenda-sticky)
7223 (org-agenda-buffer-tmp-name (buffer-name))
7224 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7225 (0-arg (or current-prefix-arg (car args)))
7226 (2-arg (nth 2 args))
7227 (newcmd (list 'org-agenda-list 0-arg date
7228 (org-agenda-span-to-ndays 2-arg)))
7229 (newargs (cdr newcmd))
7230 (inhibit-read-only t)
7231 org-agenda-sticky)
7232 (if (not (org-agenda-check-type t 'agenda))
7233 (error "Not available in non-agenda blocks")
7234 (add-text-properties (point-min) (point-max)
7235 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7236 (org-agenda-redo)
7237 (setq org-agenda-sticky org-agenda-sticky-orig
7238 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7240 (defun org-agenda-goto-today ()
7241 "Go to today."
7242 (interactive)
7243 (org-agenda-check-type t 'timeline 'agenda)
7244 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7245 (curspan (nth 2 args))
7246 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7247 (cond
7248 (tdpos (goto-char tdpos))
7249 ((eq org-agenda-type 'agenda)
7250 (let* ((sd (org-agenda-compute-starting-span
7251 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7252 (org-agenda-overriding-arguments args))
7253 (setf (nth 1 org-agenda-overriding-arguments) sd)
7254 (org-agenda-redo)
7255 (org-agenda-find-same-or-today-or-agenda)))
7256 (t (error "Cannot find today")))))
7258 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7259 (goto-char
7260 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7261 (text-property-any (point-min) (point-max) 'org-today t)
7262 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7263 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7264 (org-agenda-goto-block-beginning))
7265 (point-min))))
7267 (defun org-agenda-goto-block-beginning ()
7268 "Go the agenda block beginning."
7269 (interactive)
7270 (if (not (derived-mode-p 'org-agenda-mode))
7271 (error "Cannot execute this command outside of org-agenda-mode buffers")
7272 (let (dest)
7273 (save-excursion
7274 (unless (looking-at "\\'")
7275 (forward-char))
7276 (let* ((prop 'org-agenda-structural-header)
7277 (p (previous-single-property-change (point) prop))
7278 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7279 (1- (point))) prop)))
7280 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7281 (if (not dest)
7282 (error "Cannot find the beginning of the blog")
7283 (goto-char dest)
7284 (move-beginning-of-line 1)))))
7286 (defun org-agenda-later (arg)
7287 "Go forward in time by the current span.
7288 With prefix ARG, go forward that many times the current span."
7289 (interactive "p")
7290 (org-agenda-check-type t 'agenda)
7291 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7292 (span (or (nth 2 args) org-agenda-current-span))
7293 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7294 (greg (calendar-gregorian-from-absolute sd))
7295 (cnt (org-get-at-bol 'org-day-cnt))
7296 greg2)
7297 (cond
7298 ((numberp span)
7299 (setq sd (+ (* span arg) sd)))
7300 ((eq span 'day)
7301 (setq sd (+ arg sd)))
7302 ((eq span 'week)
7303 (setq sd (+ (* 7 arg) sd)))
7304 ((eq span 'month)
7305 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7306 sd (calendar-absolute-from-gregorian greg2))
7307 (setcar greg2 (1+ (car greg2))))
7308 ((eq span 'year)
7309 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7310 sd (calendar-absolute-from-gregorian greg2))
7311 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7313 (setq sd (+ (* span arg) sd))))
7314 (let ((org-agenda-overriding-cmd
7315 ;; `cmd' may have been set by `org-agenda-run-series' which
7316 ;; uses `org-agenda-overriding-cmd' to decide whether
7317 ;; overriding is allowed for `cmd'
7318 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7319 (org-agenda-overriding-arguments
7320 (list (car args) sd span)))
7321 (org-agenda-redo)
7322 (org-agenda-find-same-or-today-or-agenda cnt))))
7324 (defun org-agenda-earlier (arg)
7325 "Go backward in time by the current span.
7326 With prefix ARG, go backward that many times the current span."
7327 (interactive "p")
7328 (org-agenda-later (- arg)))
7330 (defun org-agenda-view-mode-dispatch ()
7331 "Call one of the view mode commands."
7332 (interactive)
7333 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7334 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7335 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7336 (let ((a (read-char-exclusive)))
7337 (case a
7338 (?\ (call-interactively 'org-agenda-reset-view))
7339 (?d (call-interactively 'org-agenda-day-view))
7340 (?w (call-interactively 'org-agenda-week-view))
7341 (?m (call-interactively 'org-agenda-month-view))
7342 (?y (call-interactively 'org-agenda-year-view))
7343 (?l (call-interactively 'org-agenda-log-mode))
7344 (?L (org-agenda-log-mode '(4)))
7345 (?c (org-agenda-log-mode 'clockcheck))
7346 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7347 (?a (call-interactively 'org-agenda-archives-mode))
7348 (?A (org-agenda-archives-mode 'files))
7349 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7350 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7351 (?G (call-interactively 'org-agenda-toggle-time-grid))
7352 (?D (call-interactively 'org-agenda-toggle-diary))
7353 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7354 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7355 (org-agenda-check-type t 'timeline 'agenda)
7356 (org-agenda-redo))
7357 (message "Display now includes inactive timestamps as well"))
7358 (?q (message "Abort"))
7359 (otherwise (error "Invalid key" )))))
7361 (defun org-agenda-reset-view ()
7362 "Switch to default view for agenda."
7363 (interactive)
7364 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7365 (defun org-agenda-day-view (&optional day-of-year)
7366 "Switch to daily view for agenda.
7367 With argument DAY-OF-YEAR, switch to that day of the year."
7368 (interactive "P")
7369 (org-agenda-change-time-span 'day day-of-year))
7370 (defun org-agenda-week-view (&optional iso-week)
7371 "Switch to daily view for agenda.
7372 With argument ISO-WEEK, switch to the corresponding ISO week.
7373 If ISO-WEEK has more then 2 digits, only the last two encode the
7374 week. Any digits before this encode a year. So 200712 means
7375 week 12 of year 2007. Years in the range 1938-2037 can also be
7376 written as 2-digit years."
7377 (interactive "P")
7378 (org-agenda-change-time-span 'week iso-week))
7379 (defun org-agenda-month-view (&optional month)
7380 "Switch to monthly view for agenda.
7381 With argument MONTH, switch to that month."
7382 (interactive "P")
7383 (org-agenda-change-time-span 'month month))
7384 (defun org-agenda-year-view (&optional year)
7385 "Switch to yearly view for agenda.
7386 With argument YEAR, switch to that year.
7387 If MONTH has more then 2 digits, only the last two encode the
7388 month. Any digits before this encode a year. So 200712 means
7389 December year 2007. Years in the range 1938-2037 can also be
7390 written as 2-digit years."
7391 (interactive "P")
7392 (when year
7393 (setq year (org-small-year-to-year year)))
7394 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7395 (org-agenda-change-time-span 'year year)
7396 (error "Abort")))
7398 (defun org-agenda-change-time-span (span &optional n)
7399 "Change the agenda view to SPAN.
7400 SPAN may be `day', `week', `month', `year'."
7401 (org-agenda-check-type t 'agenda)
7402 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7403 (curspan (nth 2 args)))
7404 (if (and (not n) (equal curspan span))
7405 (error "Viewing span is already \"%s\"" span))
7406 (let* ((sd (or (org-get-at-bol 'day)
7407 (nth 1 args)
7408 org-starting-day))
7409 (sd (org-agenda-compute-starting-span sd span n))
7410 (org-agenda-overriding-cmd
7411 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7412 (org-agenda-overriding-arguments
7413 (list (car args) sd span)))
7414 (org-agenda-redo)
7415 (org-agenda-find-same-or-today-or-agenda))
7416 (org-agenda-set-mode-name)
7417 (message "Switched to %s view" span)))
7419 (defun org-agenda-compute-starting-span (sd span &optional n)
7420 "Compute starting date for agenda.
7421 SPAN may be `day', `week', `month', `year'. The return value
7422 is a cons cell with the starting date and the number of days,
7423 so that the date SD will be in that range."
7424 (let* ((greg (calendar-gregorian-from-absolute sd))
7425 (dg (nth 1 greg))
7426 (mg (car greg))
7427 (yg (nth 2 greg)))
7428 (cond
7429 ((eq span 'day)
7430 (when n
7431 (setq sd (+ (calendar-absolute-from-gregorian
7432 (list mg 1 yg))
7433 n -1))))
7434 ((eq span 'week)
7435 (let* ((nt (calendar-day-of-week
7436 (calendar-gregorian-from-absolute sd)))
7437 (d (if org-agenda-start-on-weekday
7438 (- nt org-agenda-start-on-weekday)
7441 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7442 (when n
7443 (require 'cal-iso)
7444 (when (> n 99)
7445 (setq y1 (org-small-year-to-year (/ n 100))
7446 n (mod n 100)))
7447 (setq sd
7448 (calendar-absolute-from-iso
7449 (list n 1
7450 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7451 ((eq span 'month)
7452 (let (y1)
7453 (when (and n (> n 99))
7454 (setq y1 (org-small-year-to-year (/ n 100))
7455 n (mod n 100)))
7456 (setq sd (calendar-absolute-from-gregorian
7457 (list (or n mg) 1 (or y1 yg))))))
7458 ((eq span 'year)
7459 (setq sd (calendar-absolute-from-gregorian
7460 (list 1 1 (or n yg))))))
7461 sd))
7463 (defun org-agenda-next-date-line (&optional arg)
7464 "Jump to the next line indicating a date in agenda buffer."
7465 (interactive "p")
7466 (org-agenda-check-type t 'agenda 'timeline)
7467 (beginning-of-line 1)
7468 ;; This does not work if user makes date format that starts with a blank
7469 (if (looking-at "^\\S-") (forward-char 1))
7470 (if (not (re-search-forward "^\\S-" nil t arg))
7471 (progn
7472 (backward-char 1)
7473 (error "No next date after this line in this buffer")))
7474 (goto-char (match-beginning 0)))
7476 (defun org-agenda-previous-date-line (&optional arg)
7477 "Jump to the previous line indicating a date in agenda buffer."
7478 (interactive "p")
7479 (org-agenda-check-type t 'agenda 'timeline)
7480 (beginning-of-line 1)
7481 (if (not (re-search-backward "^\\S-" nil t arg))
7482 (error "No previous date before this line in this buffer")))
7484 ;; Initialize the highlight
7485 (defvar org-hl (make-overlay 1 1))
7486 (overlay-put org-hl 'face 'highlight)
7488 (defun org-highlight (begin end &optional buffer)
7489 "Highlight a region with overlay."
7490 (move-overlay org-hl begin end (or buffer (current-buffer))))
7492 (defun org-unhighlight ()
7493 "Detach overlay INDEX."
7494 (org-detach-overlay org-hl))
7496 (defun org-unhighlight-once ()
7497 "Remove the highlight from its position, and this function from the hook."
7498 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7499 (org-unhighlight))
7501 (defvar org-agenda-pre-follow-window-conf nil)
7502 (defun org-agenda-follow-mode ()
7503 "Toggle follow mode in an agenda buffer."
7504 (interactive)
7505 (unless org-agenda-follow-mode
7506 (setq org-agenda-pre-follow-window-conf
7507 (current-window-configuration)))
7508 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7509 (unless org-agenda-follow-mode
7510 (set-window-configuration org-agenda-pre-follow-window-conf))
7511 (org-agenda-set-mode-name)
7512 (org-agenda-do-context-action)
7513 (message "Follow mode is %s"
7514 (if org-agenda-follow-mode "on" "off")))
7516 (defun org-agenda-entry-text-mode (&optional arg)
7517 "Toggle entry text mode in an agenda buffer."
7518 (interactive "P")
7519 (setq org-agenda-entry-text-mode (or (integerp arg)
7520 (not org-agenda-entry-text-mode)))
7521 (org-agenda-entry-text-hide)
7522 (and org-agenda-entry-text-mode
7523 (let ((org-agenda-entry-text-maxlines
7524 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7525 (org-agenda-entry-text-show)))
7526 (org-agenda-set-mode-name)
7527 (message "Entry text mode is %s. Maximum number of lines is %d"
7528 (if org-agenda-entry-text-mode "on" "off")
7529 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7531 (defun org-agenda-clockreport-mode (&optional with-filter)
7532 "Toggle clocktable mode in an agenda buffer.
7533 With prefix arg WITH-FILTER, make the clocktable respect the current
7534 agenda filter."
7535 (interactive "P")
7536 (org-agenda-check-type t 'agenda)
7537 (if with-filter
7538 (setq org-agenda-clockreport-mode 'with-filter)
7539 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7540 (org-agenda-set-mode-name)
7541 (org-agenda-redo)
7542 (message "Clocktable mode is %s"
7543 (if org-agenda-clockreport-mode "on" "off")))
7545 (defun org-agenda-log-mode (&optional special)
7546 "Toggle log mode in an agenda buffer.
7547 With argument SPECIAL, show all possible log items, not only the ones
7548 configured in `org-agenda-log-mode-items'.
7549 With a double `C-u' prefix arg, show *only* log items, nothing else."
7550 (interactive "P")
7551 (org-agenda-check-type t 'agenda 'timeline)
7552 (setq org-agenda-show-log
7553 (cond
7554 ((equal special '(16)) 'only)
7555 ((eq special 'clockcheck)
7556 (if (eq org-agenda-show-log 'clockcheck)
7557 nil 'clockcheck))
7558 (special '(closed clock state))
7559 (t (not org-agenda-show-log))))
7560 (org-agenda-set-mode-name)
7561 (org-agenda-redo)
7562 (message "Log mode is %s"
7563 (if org-agenda-show-log "on" "off")))
7565 (defun org-agenda-archives-mode (&optional with-files)
7566 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7567 When called with a prefix argument, include all archive files as well."
7568 (interactive "P")
7569 (setq org-agenda-archives-mode
7570 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7571 (org-agenda-set-mode-name)
7572 (org-agenda-redo)
7573 (message
7574 "%s"
7575 (cond
7576 ((eq org-agenda-archives-mode nil)
7577 "No archives are included")
7578 ((eq org-agenda-archives-mode 'trees)
7579 (format "Trees with :%s: tag are included" org-archive-tag))
7580 ((eq org-agenda-archives-mode t)
7581 (format "Trees with :%s: tag and all active archive files are included"
7582 org-archive-tag)))))
7584 (defun org-agenda-toggle-diary ()
7585 "Toggle diary inclusion in an agenda buffer."
7586 (interactive)
7587 (org-agenda-check-type t 'agenda)
7588 (setq org-agenda-include-diary (not org-agenda-include-diary))
7589 (org-agenda-redo)
7590 (org-agenda-set-mode-name)
7591 (message "Diary inclusion turned %s"
7592 (if org-agenda-include-diary "on" "off")))
7594 (defun org-agenda-toggle-deadlines ()
7595 "Toggle inclusion of entries with a deadline in an agenda buffer."
7596 (interactive)
7597 (org-agenda-check-type t 'agenda)
7598 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7599 (org-agenda-redo)
7600 (org-agenda-set-mode-name)
7601 (message "Deadlines inclusion turned %s"
7602 (if org-agenda-include-deadlines "on" "off")))
7604 (defun org-agenda-toggle-time-grid ()
7605 "Toggle time grid in an agenda buffer."
7606 (interactive)
7607 (org-agenda-check-type t 'agenda)
7608 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7609 (org-agenda-redo)
7610 (org-agenda-set-mode-name)
7611 (message "Time-grid turned %s"
7612 (if org-agenda-use-time-grid "on" "off")))
7614 (defun org-agenda-set-mode-name ()
7615 "Set the mode name to indicate all the small mode settings."
7616 (setq mode-name
7617 (list "Org-Agenda"
7618 (if (get 'org-agenda-files 'org-restrict) " []" "")
7620 '(:eval (org-agenda-span-name org-agenda-current-span))
7621 (if org-agenda-follow-mode " Follow" "")
7622 (if org-agenda-entry-text-mode " ETxt" "")
7623 (if org-agenda-include-diary " Diary" "")
7624 (if org-agenda-include-deadlines " Ddl" "")
7625 (if org-agenda-use-time-grid " Grid" "")
7626 (if (and (boundp 'org-habit-show-habits)
7627 org-habit-show-habits) " Habit" "")
7628 (cond
7629 ((consp org-agenda-show-log) " LogAll")
7630 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7631 (org-agenda-show-log " Log")
7632 (t ""))
7633 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7634 :preset-filter))
7635 '(:eval (org-propertize
7636 (concat " <"
7637 (mapconcat
7638 'identity
7639 (append
7640 (get 'org-agenda-category-filter :preset-filter)
7641 org-agenda-category-filter)
7643 ">")
7644 'face 'org-agenda-filter-category
7645 'help-echo "Category used in filtering"))
7647 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7648 :preset-filter))
7649 '(:eval (org-propertize
7650 (concat " {"
7651 (mapconcat
7652 'identity
7653 (append
7654 (get 'org-agenda-tag-filter :preset-filter)
7655 org-agenda-tag-filter)
7657 "}")
7658 'face 'org-agenda-filter-tags
7659 'help-echo "Tags used in filtering"))
7661 (if org-agenda-archives-mode
7662 (if (eq org-agenda-archives-mode t)
7663 " Archives"
7664 (format " :%s:" org-archive-tag))
7666 (if org-agenda-clockreport-mode
7667 (if (eq org-agenda-clockreport-mode 'with-filter)
7668 " Clock{}" " Clock")
7669 "")))
7670 (force-mode-line-update))
7672 (define-obsolete-function-alias
7673 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7675 (defun org-agenda-update-agenda-type ()
7676 "Update the agenda type after each command."
7677 (setq org-agenda-type
7678 (or (get-text-property (point) 'org-agenda-type)
7679 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7681 (defun org-agenda-next-line ()
7682 "Move cursor to the next line, and show if follow mode is active."
7683 (interactive)
7684 (call-interactively 'next-line)
7685 (org-agenda-do-context-action))
7687 (defun org-agenda-previous-line ()
7688 "Move cursor to the previous line, and show if follow-mode is active."
7689 (interactive)
7690 (call-interactively 'previous-line)
7691 (org-agenda-do-context-action))
7693 (defun org-agenda-next-item (n)
7694 "Move cursor to next agenda item."
7695 (interactive "p")
7696 (let ((col (current-column)))
7697 (dotimes (c n)
7698 (when (next-single-property-change (point-at-eol) 'org-marker)
7699 (move-end-of-line 1)
7700 (goto-char (next-single-property-change (point) 'org-marker))))
7701 (org-move-to-column col))
7702 (org-agenda-do-context-action))
7704 (defun org-agenda-previous-item (n)
7705 "Move cursor to next agenda item."
7706 (interactive "p")
7707 (dotimes (c n)
7708 (let ((col (current-column))
7709 (goto (save-excursion
7710 (move-end-of-line 0)
7711 (previous-single-property-change (point) 'org-marker))))
7712 (if goto (goto-char goto))
7713 (org-move-to-column col)))
7714 (org-agenda-do-context-action))
7716 (defun org-agenda-do-context-action ()
7717 "Show outline path and, maybe, follow mode window."
7718 (let ((m (org-get-at-bol 'org-marker)))
7719 (when (and (markerp m) (marker-buffer m))
7720 (and org-agenda-follow-mode
7721 (if org-agenda-follow-indirect
7722 (org-agenda-tree-to-indirect-buffer nil)
7723 (org-agenda-show)))
7724 (and org-agenda-show-outline-path
7725 (org-with-point-at m (org-display-outline-path t))))))
7727 (defun org-agenda-show-tags ()
7728 "Show the tags applicable to the current item."
7729 (interactive)
7730 (let* ((tags (org-get-at-bol 'tags)))
7731 (if tags
7732 (message "Tags are :%s:"
7733 (org-no-properties (mapconcat 'identity tags ":")))
7734 (message "No tags associated with this line"))))
7736 (defun org-agenda-goto (&optional highlight)
7737 "Go to the Org-mode file which contains the item at point."
7738 (interactive)
7739 (let* ((marker (or (org-get-at-bol 'org-marker)
7740 (org-agenda-error)))
7741 (buffer (marker-buffer marker))
7742 (pos (marker-position marker)))
7743 (switch-to-buffer-other-window buffer)
7744 (widen)
7745 (push-mark)
7746 (goto-char pos)
7747 (when (derived-mode-p 'org-mode)
7748 (org-show-context 'agenda)
7749 (save-excursion
7750 (and (outline-next-heading)
7751 (org-flag-heading nil)))) ; show the next heading
7752 (when (outline-invisible-p)
7753 (show-entry)) ; display invisible text
7754 (recenter (/ (window-height) 2))
7755 (run-hooks 'org-agenda-after-show-hook)
7756 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7758 (defvar org-agenda-after-show-hook nil
7759 "Normal hook run after an item has been shown from the agenda.
7760 Point is in the buffer where the item originated.")
7762 (defun org-agenda-kill ()
7763 "Kill the entry or subtree belonging to the current agenda entry."
7764 (interactive)
7765 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7766 (let* ((bufname-orig (buffer-name))
7767 (marker (or (org-get-at-bol 'org-marker)
7768 (org-agenda-error)))
7769 (buffer (marker-buffer marker))
7770 (pos (marker-position marker))
7771 (type (org-get-at-bol 'type))
7772 dbeg dend (n 0) conf)
7773 (org-with-remote-undo buffer
7774 (with-current-buffer buffer
7775 (save-excursion
7776 (goto-char pos)
7777 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7778 (setq dbeg (progn (org-back-to-heading t) (point))
7779 dend (org-end-of-subtree t t))
7780 (setq dbeg (point-at-bol)
7781 dend (min (point-max) (1+ (point-at-eol)))))
7782 (goto-char dbeg)
7783 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7784 (setq conf (or (eq t org-agenda-confirm-kill)
7785 (and (numberp org-agenda-confirm-kill)
7786 (> n org-agenda-confirm-kill))))
7787 (and conf
7788 (not (y-or-n-p
7789 (format "Delete entry with %d lines in buffer \"%s\"? "
7790 n (buffer-name buffer))))
7791 (error "Abort"))
7792 (let ((org-agenda-buffer-name bufname-orig))
7793 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7794 (with-current-buffer buffer (delete-region dbeg dend))
7795 (message "Agenda item and source killed"))))
7797 (defvar org-archive-default-command) ; defined in org-archive.el
7798 (defun org-agenda-archive-default ()
7799 "Archive the entry or subtree belonging to the current agenda entry."
7800 (interactive)
7801 (require 'org-archive)
7802 (org-agenda-archive-with org-archive-default-command))
7804 (defun org-agenda-archive-default-with-confirmation ()
7805 "Archive the entry or subtree belonging to the current agenda entry."
7806 (interactive)
7807 (require 'org-archive)
7808 (org-agenda-archive-with org-archive-default-command 'confirm))
7810 (defun org-agenda-archive ()
7811 "Archive the entry or subtree belonging to the current agenda entry."
7812 (interactive)
7813 (org-agenda-archive-with 'org-archive-subtree))
7815 (defun org-agenda-archive-to-archive-sibling ()
7816 "Move the entry to the archive sibling."
7817 (interactive)
7818 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7820 (defun org-agenda-archive-with (cmd &optional confirm)
7821 "Move the entry to the archive sibling."
7822 (interactive)
7823 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7824 (let* ((bufname-orig (buffer-name))
7825 (marker (or (org-get-at-bol 'org-marker)
7826 (org-agenda-error)))
7827 (buffer (marker-buffer marker))
7828 (pos (marker-position marker)))
7829 (org-with-remote-undo buffer
7830 (with-current-buffer buffer
7831 (if (derived-mode-p 'org-mode)
7832 (if (and confirm
7833 (not (y-or-n-p "Archive this subtree or entry? ")))
7834 (error "Abort")
7835 (save-excursion
7836 (goto-char pos)
7837 (let ((org-agenda-buffer-name bufname-orig))
7838 (org-remove-subtree-entries-from-agenda))
7839 (org-back-to-heading t)
7840 (funcall cmd)))
7841 (error "Archiving works only in Org-mode files"))))))
7843 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7844 "Remove all lines in the agenda that correspond to a given subtree.
7845 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7846 If this information is not given, the function uses the tree at point."
7847 (let ((buf (or buf (current-buffer))) m p)
7848 (save-excursion
7849 (unless (and beg end)
7850 (org-back-to-heading t)
7851 (setq beg (point))
7852 (org-end-of-subtree t)
7853 (setq end (point)))
7854 (set-buffer (get-buffer org-agenda-buffer-name))
7855 (save-excursion
7856 (goto-char (point-max))
7857 (beginning-of-line 1)
7858 (while (not (bobp))
7859 (when (and (setq m (org-get-at-bol 'org-marker))
7860 (equal buf (marker-buffer m))
7861 (setq p (marker-position m))
7862 (>= p beg)
7863 (< p end))
7864 (let ((inhibit-read-only t))
7865 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7866 (beginning-of-line 0))))))
7868 (defun org-agenda-refile (&optional goto rfloc no-update)
7869 "Refile the item at point."
7870 (interactive "P")
7871 (if (equal goto '(16))
7872 (org-refile-goto-last-stored)
7873 (let* ((buffer-orig (buffer-name))
7874 (marker (or (org-get-at-bol 'org-hd-marker)
7875 (org-agenda-error)))
7876 (buffer (marker-buffer marker))
7877 (pos (marker-position marker))
7878 (rfloc (or rfloc
7879 (org-refile-get-location
7880 (if goto "Goto" "Refile to") buffer
7881 org-refile-allow-creating-parent-nodes))))
7882 (with-current-buffer buffer
7883 (save-excursion
7884 (save-restriction
7885 (widen)
7886 (goto-char marker)
7887 (let ((org-agenda-buffer-name buffer-orig))
7888 (org-remove-subtree-entries-from-agenda))
7889 (org-refile goto buffer rfloc)))))
7890 (unless no-update (org-agenda-redo))))
7892 (defun org-agenda-open-link (&optional arg)
7893 "Follow the link in the current line, if any.
7894 This looks for a link in the displayed line in the agenda. It also looks
7895 at the text of the entry itself."
7896 (interactive "P")
7897 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7898 (org-get-at-bol 'org-marker)))
7899 (buffer (and marker (marker-buffer marker)))
7900 (prefix (buffer-substring
7901 (point-at-bol) (point-at-eol))))
7902 (cond
7903 (buffer
7904 (with-current-buffer buffer
7905 (save-excursion
7906 (save-restriction
7907 (widen)
7908 (goto-char marker)
7909 (org-offer-links-in-entry arg prefix)))))
7910 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7911 (save-excursion
7912 (beginning-of-line 1)
7913 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7914 (org-open-link-from-string (match-string 1)))
7915 (t (error "No link to open here")))))
7917 (defun org-agenda-copy-local-variable (var)
7918 "Get a variable from a referenced buffer and install it here."
7919 (let ((m (org-get-at-bol 'org-marker)))
7920 (when (and m (buffer-live-p (marker-buffer m)))
7921 (org-set-local var (with-current-buffer (marker-buffer m)
7922 (symbol-value var))))))
7924 (defun org-agenda-switch-to (&optional delete-other-windows)
7925 "Go to the Org-mode file which contains the item at point."
7926 (interactive)
7927 (if (and org-return-follows-link
7928 (not (org-get-at-bol 'org-marker))
7929 (org-in-regexp org-bracket-link-regexp))
7930 (org-open-link-from-string (match-string 0))
7931 (let* ((marker (or (org-get-at-bol 'org-marker)
7932 (org-agenda-error)))
7933 (buffer (marker-buffer marker))
7934 (pos (marker-position marker)))
7935 (org-pop-to-buffer-same-window buffer)
7936 (and delete-other-windows (delete-other-windows))
7937 (widen)
7938 (goto-char pos)
7939 (when (derived-mode-p 'org-mode)
7940 (org-show-context 'agenda)
7941 (save-excursion
7942 (and (outline-next-heading)
7943 (org-flag-heading nil))) ; show the next heading
7944 (when (outline-invisible-p)
7945 (show-entry)) ; display invisible text
7946 (run-hooks 'org-agenda-after-show-hook)))))
7948 (defun org-agenda-goto-mouse (ev)
7949 "Go to the Org-mode file which contains the item at the mouse click."
7950 (interactive "e")
7951 (mouse-set-point ev)
7952 (org-agenda-goto))
7954 (defun org-agenda-show (&optional full-entry)
7955 "Display the Org-mode file which contains the item at point.
7956 With prefix argument FULL-ENTRY, make the entire entry visible
7957 if it was hidden in the outline."
7958 (interactive "P")
7959 (let ((win (selected-window)))
7960 (if full-entry
7961 (let ((org-show-entry-below t))
7962 (org-agenda-goto t))
7963 (org-agenda-goto t))
7964 (select-window win)))
7966 (defvar org-agenda-show-window nil)
7967 (defun org-agenda-show-and-scroll-up (&optional arg)
7968 "Display the Org-mode file which contains the item at point.
7969 When called repeatedly, scroll the window that is displaying the buffer.
7970 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7971 `show-subtree' to display the item, so that drawers and logbooks stay
7972 folded."
7973 (interactive "P")
7974 (let ((win (selected-window)))
7975 (if (and (window-live-p org-agenda-show-window)
7976 (eq this-command last-command))
7977 (progn
7978 (select-window org-agenda-show-window)
7979 (ignore-errors (scroll-up)))
7980 (org-agenda-goto t)
7981 (if arg (org-show-entry) (show-subtree))
7982 (setq org-agenda-show-window (selected-window)))
7983 (select-window win)))
7985 (defun org-agenda-show-scroll-down ()
7986 "Scroll down the window showing the agenda."
7987 (interactive)
7988 (let ((win (selected-window)))
7989 (when (window-live-p org-agenda-show-window)
7990 (select-window org-agenda-show-window)
7991 (ignore-errors (scroll-down))
7992 (select-window win))))
7994 (defun org-agenda-show-1 (&optional more)
7995 "Display the Org-mode file which contains the item at point.
7996 The prefix arg selects the amount of information to display:
7998 0 hide the subtree
7999 1 just show the entry according to defaults.
8000 2 show the children view
8001 3 show the subtree view
8002 4 show the entire subtree and any LOGBOOK drawers
8003 5 show the entire subtree and any drawers
8004 With prefix argument FULL-ENTRY, make the entire entry visible
8005 if it was hidden in the outline."
8006 (interactive "p")
8007 (let ((win (selected-window)))
8008 (org-agenda-goto t)
8009 (org-recenter-heading 1)
8010 (cond
8011 ((= more 0)
8012 (hide-subtree)
8013 (save-excursion
8014 (org-back-to-heading)
8015 (run-hook-with-args 'org-cycle-hook 'folded))
8016 (message "Remote: FOLDED"))
8017 ((and (org-called-interactively-p 'any) (= more 1))
8018 (message "Remote: show with default settings"))
8019 ((= more 2)
8020 (show-entry)
8021 (show-children)
8022 (save-excursion
8023 (org-back-to-heading)
8024 (run-hook-with-args 'org-cycle-hook 'children))
8025 (message "Remote: CHILDREN"))
8026 ((= more 3)
8027 (show-subtree)
8028 (save-excursion
8029 (org-back-to-heading)
8030 (run-hook-with-args 'org-cycle-hook 'subtree))
8031 (message "Remote: SUBTREE"))
8032 ((= more 4)
8033 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8034 (org-drawer-regexp
8035 (concat "^[ \t]*:\\("
8036 (mapconcat 'regexp-quote org-drawers "\\|")
8037 "\\):[ \t]*$")))
8038 (show-subtree)
8039 (save-excursion
8040 (org-back-to-heading)
8041 (org-cycle-hide-drawers 'subtree)))
8042 (message "Remote: SUBTREE AND LOGBOOK"))
8043 ((> more 4)
8044 (show-subtree)
8045 (message "Remote: SUBTREE AND ALL DRAWERS")))
8046 (select-window win)))
8048 (defun org-recenter-heading (n)
8049 (save-excursion
8050 (org-back-to-heading)
8051 (recenter n)))
8053 (defvar org-agenda-cycle-counter nil)
8054 (defun org-agenda-cycle-show (&optional n)
8055 "Show the current entry in another window, with default settings.
8056 Default settings are taken from `org-show-hierarchy-above' and siblings.
8057 When use repeatedly in immediate succession, the remote entry will cycle
8058 through visibility
8060 children -> subtree -> folded
8062 When called with a numeric prefix arg, that arg will be passed through to
8063 `org-agenda-show-1'. For the interpretation of that argument, see the
8064 docstring of `org-agenda-show-1'."
8065 (interactive "P")
8066 (if (integerp n)
8067 (setq org-agenda-cycle-counter n)
8068 (if (not (eq last-command this-command))
8069 (setq org-agenda-cycle-counter 1)
8070 (if (equal org-agenda-cycle-counter 0)
8071 (setq org-agenda-cycle-counter 2)
8072 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8073 (if (> org-agenda-cycle-counter 3)
8074 (setq org-agenda-cycle-counter 0)))))
8075 (org-agenda-show-1 org-agenda-cycle-counter))
8077 (defun org-agenda-recenter (arg)
8078 "Display the Org-mode file which contains the item at point and recenter."
8079 (interactive "P")
8080 (let ((win (selected-window)))
8081 (org-agenda-goto t)
8082 (recenter arg)
8083 (select-window win)))
8085 (defun org-agenda-show-mouse (ev)
8086 "Display the Org-mode file which contains the item at the mouse click."
8087 (interactive "e")
8088 (mouse-set-point ev)
8089 (org-agenda-show))
8091 (defun org-agenda-check-no-diary ()
8092 "Check if the entry is a diary link and abort if yes."
8093 (if (org-get-at-bol 'org-agenda-diary-link)
8094 (org-agenda-error)))
8096 (defun org-agenda-error ()
8097 (error "Command not allowed in this line"))
8099 (defun org-agenda-tree-to-indirect-buffer (arg)
8100 "Show the subtree corresponding to the current entry in an indirect buffer.
8101 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8103 With a numerical prefix ARG, go up to this level and then take that tree.
8104 With a negative numeric ARG, go up by this number of levels.
8105 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8106 use the dedicated frame)."
8107 (interactive "P")
8108 (if current-prefix-arg
8109 (org-agenda-do-tree-to-indirect-buffer arg)
8110 (let ((agenda-buffer (buffer-name))
8111 (agenda-window (selected-window))
8112 (indirect-window
8113 (and org-last-indirect-buffer
8114 (get-buffer-window org-last-indirect-buffer))))
8115 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8116 (unless (or (eq org-indirect-buffer-display 'new-frame)
8117 (eq org-indirect-buffer-display 'dedicated-frame))
8118 (unwind-protect
8119 (unless (and indirect-window (window-live-p indirect-window))
8120 (setq indirect-window (split-window agenda-window)))
8121 (and indirect-window (select-window indirect-window))
8122 (switch-to-buffer org-last-indirect-buffer :norecord)
8123 (fit-window-to-buffer indirect-window)))
8124 (select-window (get-buffer-window agenda-buffer)))))
8126 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8127 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8128 (org-agenda-check-no-diary)
8129 (let* ((marker (or (org-get-at-bol 'org-marker)
8130 (org-agenda-error)))
8131 (buffer (marker-buffer marker))
8132 (pos (marker-position marker)))
8133 (with-current-buffer buffer
8134 (save-excursion
8135 (goto-char pos)
8136 (funcall 'org-tree-to-indirect-buffer arg)))))
8138 (defvar org-last-heading-marker (make-marker)
8139 "Marker pointing to the headline that last changed its TODO state
8140 by a remote command from the agenda.")
8142 (defun org-agenda-todo-nextset ()
8143 "Switch TODO entry to next sequence."
8144 (interactive)
8145 (org-agenda-todo 'nextset))
8147 (defun org-agenda-todo-previousset ()
8148 "Switch TODO entry to previous sequence."
8149 (interactive)
8150 (org-agenda-todo 'previousset))
8152 (defun org-agenda-todo (&optional arg)
8153 "Cycle TODO state of line at point, also in Org-mode file.
8154 This changes the line at point, all other lines in the agenda referring to
8155 the same tree node, and the headline of the tree node in the Org-mode file."
8156 (interactive "P")
8157 (org-agenda-check-no-diary)
8158 (let* ((col (current-column))
8159 (marker (or (org-get-at-bol 'org-marker)
8160 (org-agenda-error)))
8161 (buffer (marker-buffer marker))
8162 (pos (marker-position marker))
8163 (hdmarker (org-get-at-bol 'org-hd-marker))
8164 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8165 (inhibit-read-only t)
8166 org-agenda-headline-snapshot-before-repeat newhead just-one)
8167 (org-with-remote-undo buffer
8168 (with-current-buffer buffer
8169 (widen)
8170 (goto-char pos)
8171 (org-show-context 'agenda)
8172 (save-excursion
8173 (and (outline-next-heading)
8174 (org-flag-heading nil))) ; show the next heading
8175 (let ((current-prefix-arg arg))
8176 (call-interactively 'org-todo))
8177 (and (bolp) (forward-char 1))
8178 (setq newhead (org-get-heading))
8179 (when (and (org-bound-and-true-p
8180 org-agenda-headline-snapshot-before-repeat)
8181 (not (equal org-agenda-headline-snapshot-before-repeat
8182 newhead))
8183 todayp)
8184 (setq newhead org-agenda-headline-snapshot-before-repeat
8185 just-one t))
8186 (save-excursion
8187 (org-back-to-heading)
8188 (move-marker org-last-heading-marker (point))))
8189 (beginning-of-line 1)
8190 (save-excursion
8191 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8192 (org-move-to-column col))))
8194 (defun org-agenda-add-note (&optional arg)
8195 "Add a time-stamped note to the entry at point."
8196 (interactive "P")
8197 (org-agenda-check-no-diary)
8198 (let* ((marker (or (org-get-at-bol 'org-marker)
8199 (org-agenda-error)))
8200 (buffer (marker-buffer marker))
8201 (pos (marker-position marker))
8202 (hdmarker (org-get-at-bol 'org-hd-marker))
8203 (inhibit-read-only t))
8204 (with-current-buffer buffer
8205 (widen)
8206 (goto-char pos)
8207 (org-show-context 'agenda)
8208 (save-excursion
8209 (and (outline-next-heading)
8210 (org-flag-heading nil))) ; show the next heading
8211 (org-add-note))))
8213 (defun org-agenda-change-all-lines (newhead hdmarker
8214 &optional fixface just-this)
8215 "Change all lines in the agenda buffer which match HDMARKER.
8216 The new content of the line will be NEWHEAD (as modified by
8217 `org-agenda-format-item'). HDMARKER is checked with
8218 `equal' against all `org-hd-marker' text properties in the file.
8219 If FIXFACE is non-nil, the face of each item is modified according to
8220 the new TODO state.
8221 If JUST-THIS is non-nil, change just the current line, not all.
8222 If FORCE-TAGS is non nil, the car of it returns the new tags."
8223 (let* ((inhibit-read-only t)
8224 (line (org-current-line))
8225 (org-agenda-buffer (current-buffer))
8226 (thetags (with-current-buffer (marker-buffer hdmarker)
8227 (save-excursion (save-restriction (widen)
8228 (goto-char hdmarker)
8229 (org-get-tags-at)))))
8230 props m pl undone-face done-face finish new dotime cat tags)
8231 (save-excursion
8232 (goto-char (point-max))
8233 (beginning-of-line 1)
8234 (while (not finish)
8235 (setq finish (bobp))
8236 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8237 (or (not just-this) (= (org-current-line) line))
8238 (equal m hdmarker))
8239 (setq props (text-properties-at (point))
8240 dotime (org-get-at-bol 'dotime)
8241 cat (org-get-at-bol 'org-category)
8242 tags thetags
8244 (let ((org-prefix-format-compiled
8245 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8246 org-prefix-format-compiled))
8247 (extra (org-get-at-bol 'extra)))
8248 (with-current-buffer (marker-buffer hdmarker)
8249 (save-excursion
8250 (save-restriction
8251 (widen)
8252 (org-agenda-format-item extra newhead cat tags dotime)))))
8253 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8254 undone-face (org-get-at-bol 'undone-face)
8255 done-face (org-get-at-bol 'done-face))
8256 (beginning-of-line 1)
8257 (cond
8258 ((equal new "")
8259 (and (looking-at ".*\n?") (replace-match "")))
8260 ((looking-at ".*")
8261 (replace-match new t t)
8262 (beginning-of-line 1)
8263 (add-text-properties (point-at-bol) (point-at-eol) props)
8264 (when fixface
8265 (add-text-properties
8266 (point-at-bol) (point-at-eol)
8267 (list 'face
8268 (if org-last-todo-state-is-todo
8269 undone-face done-face))))
8270 (org-agenda-highlight-todo 'line)
8271 (beginning-of-line 1))
8272 (t (error "Line update did not work")))
8273 (save-restriction
8274 (narrow-to-region (point-at-bol) (point-at-eol))
8275 (org-agenda-finalize)))
8276 (beginning-of-line 0)))))
8278 (defun org-agenda-align-tags (&optional line)
8279 "Align all tags in agenda items to `org-agenda-tags-column'."
8280 (let ((inhibit-read-only t) l c)
8281 (save-excursion
8282 (goto-char (if line (point-at-bol) (point-min)))
8283 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8284 (if line (point-at-eol) nil) t)
8285 (add-text-properties
8286 (match-beginning 2) (match-end 2)
8287 (list 'face (delq nil (let ((prop (get-text-property
8288 (match-beginning 2) 'face)))
8289 (or (listp prop) (setq prop (list prop)))
8290 (if (memq 'org-tag prop)
8291 prop
8292 (cons 'org-tag prop))))))
8293 (setq l (- (match-end 2) (match-beginning 2))
8294 c (if (< org-agenda-tags-column 0)
8295 (- (abs org-agenda-tags-column) l)
8296 org-agenda-tags-column))
8297 (delete-region (match-beginning 1) (match-end 1))
8298 (goto-char (match-beginning 1))
8299 (insert (org-add-props
8300 (make-string (max 1 (- c (current-column))) ?\ )
8301 (plist-put (copy-sequence (text-properties-at (point)))
8302 'face nil))))
8303 (goto-char (point-min))
8304 (org-font-lock-add-tag-faces (point-max)))))
8306 (defun org-agenda-priority-up ()
8307 "Increase the priority of line at point, also in Org-mode file."
8308 (interactive)
8309 (org-agenda-priority 'up))
8311 (defun org-agenda-priority-down ()
8312 "Decrease the priority of line at point, also in Org-mode file."
8313 (interactive)
8314 (org-agenda-priority 'down))
8316 (defun org-agenda-priority (&optional force-direction show)
8317 "Set the priority of line at point, also in Org-mode file.
8318 This changes the line at point, all other lines in the agenda referring to
8319 the same tree node, and the headline of the tree node in the Org-mode file."
8320 (interactive "P")
8321 (if (equal force-direction '(4)) (setq show t))
8322 (unless org-enable-priority-commands
8323 (error "Priority commands are disabled"))
8324 (org-agenda-check-no-diary)
8325 (let* ((marker (or (org-get-at-bol 'org-marker)
8326 (org-agenda-error)))
8327 (hdmarker (org-get-at-bol 'org-hd-marker))
8328 (buffer (marker-buffer hdmarker))
8329 (pos (marker-position hdmarker))
8330 (inhibit-read-only t)
8331 newhead)
8332 (org-with-remote-undo buffer
8333 (with-current-buffer buffer
8334 (widen)
8335 (goto-char pos)
8336 (org-show-context 'agenda)
8337 (save-excursion
8338 (and (outline-next-heading)
8339 (org-flag-heading nil))) ; show the next heading
8340 (funcall 'org-priority force-direction show)
8341 (end-of-line 1)
8342 (setq newhead (org-get-heading)))
8343 (org-agenda-change-all-lines newhead hdmarker)
8344 (beginning-of-line 1))))
8346 ;; FIXME: should fix the tags property of the agenda line.
8347 (defun org-agenda-set-tags (&optional tag onoff)
8348 "Set tags for the current headline."
8349 (interactive)
8350 (org-agenda-check-no-diary)
8351 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8352 (call-interactively 'org-change-tag-in-region)
8353 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8354 (org-agenda-error)))
8355 (buffer (marker-buffer hdmarker))
8356 (pos (marker-position hdmarker))
8357 (inhibit-read-only t)
8358 newhead)
8359 (org-with-remote-undo buffer
8360 (with-current-buffer buffer
8361 (widen)
8362 (goto-char pos)
8363 (save-excursion
8364 (org-show-context 'agenda))
8365 (save-excursion
8366 (and (outline-next-heading)
8367 (org-flag-heading nil))) ; show the next heading
8368 (goto-char pos)
8369 (if tag
8370 (org-toggle-tag tag onoff)
8371 (call-interactively 'org-set-tags))
8372 (end-of-line 1)
8373 (setq newhead (org-get-heading)))
8374 (org-agenda-change-all-lines newhead hdmarker)
8375 (beginning-of-line 1)))))
8377 (defun org-agenda-set-property ()
8378 "Set a property for the current headline."
8379 (interactive)
8380 (org-agenda-check-no-diary)
8381 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8382 (org-agenda-error)))
8383 (buffer (marker-buffer hdmarker))
8384 (pos (marker-position hdmarker))
8385 (inhibit-read-only t)
8386 newhead)
8387 (org-with-remote-undo buffer
8388 (with-current-buffer buffer
8389 (widen)
8390 (goto-char pos)
8391 (save-excursion
8392 (org-show-context 'agenda))
8393 (save-excursion
8394 (and (outline-next-heading)
8395 (org-flag-heading nil))) ; show the next heading
8396 (goto-char pos)
8397 (call-interactively 'org-set-property)))))
8399 (defun org-agenda-set-effort ()
8400 "Set the effort property for the current headline."
8401 (interactive)
8402 (org-agenda-check-no-diary)
8403 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8404 (org-agenda-error)))
8405 (buffer (marker-buffer hdmarker))
8406 (pos (marker-position hdmarker))
8407 (inhibit-read-only t)
8408 newhead)
8409 (org-with-remote-undo buffer
8410 (with-current-buffer buffer
8411 (widen)
8412 (goto-char pos)
8413 (save-excursion
8414 (org-show-context 'agenda))
8415 (save-excursion
8416 (and (outline-next-heading)
8417 (org-flag-heading nil))) ; show the next heading
8418 (goto-char pos)
8419 (call-interactively 'org-set-effort)
8420 (end-of-line 1)
8421 (setq newhead (org-get-heading)))
8422 (org-agenda-change-all-lines newhead hdmarker))))
8424 (defun org-agenda-toggle-archive-tag ()
8425 "Toggle the archive tag for the current entry."
8426 (interactive)
8427 (org-agenda-check-no-diary)
8428 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8429 (org-agenda-error)))
8430 (buffer (marker-buffer hdmarker))
8431 (pos (marker-position hdmarker))
8432 (inhibit-read-only t)
8433 newhead)
8434 (org-with-remote-undo buffer
8435 (with-current-buffer buffer
8436 (widen)
8437 (goto-char pos)
8438 (org-show-context 'agenda)
8439 (save-excursion
8440 (and (outline-next-heading)
8441 (org-flag-heading nil))) ; show the next heading
8442 (call-interactively 'org-toggle-archive-tag)
8443 (end-of-line 1)
8444 (setq newhead (org-get-heading)))
8445 (org-agenda-change-all-lines newhead hdmarker)
8446 (beginning-of-line 1))))
8448 (defun org-agenda-do-date-later (arg)
8449 (interactive "P")
8450 (cond
8451 ((or (equal arg '(16))
8452 (memq last-command
8453 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8454 (setq this-command 'org-agenda-date-later-minutes)
8455 (org-agenda-date-later-minutes 1))
8456 ((or (equal arg '(4))
8457 (memq last-command
8458 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8459 (setq this-command 'org-agenda-date-later-hours)
8460 (org-agenda-date-later-hours 1))
8462 (org-agenda-date-later (prefix-numeric-value arg)))))
8464 (defun org-agenda-do-date-earlier (arg)
8465 (interactive "P")
8466 (cond
8467 ((or (equal arg '(16))
8468 (memq last-command
8469 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8470 (setq this-command 'org-agenda-date-earlier-minutes)
8471 (org-agenda-date-earlier-minutes 1))
8472 ((or (equal arg '(4))
8473 (memq last-command
8474 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8475 (setq this-command 'org-agenda-date-earlier-hours)
8476 (org-agenda-date-earlier-hours 1))
8478 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8480 (defun org-agenda-date-later (arg &optional what)
8481 "Change the date of this item to ARG day(s) later."
8482 (interactive "p")
8483 (org-agenda-check-type t 'agenda 'timeline)
8484 (org-agenda-check-no-diary)
8485 (let* ((marker (or (org-get-at-bol 'org-marker)
8486 (org-agenda-error)))
8487 (buffer (marker-buffer marker))
8488 (pos (marker-position marker))
8489 cdate today)
8490 (org-with-remote-undo buffer
8491 (with-current-buffer buffer
8492 (widen)
8493 (goto-char pos)
8494 (if (not (org-at-timestamp-p))
8495 (error "Cannot find time stamp"))
8496 (when (and org-agenda-move-date-from-past-immediately-to-today
8497 (equal arg 1)
8498 (or (not what) (eq what 'day))
8499 (not (save-match-data (org-at-date-range-p))))
8500 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8501 cdate (calendar-absolute-from-gregorian
8502 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8503 today (org-today))
8504 (if (> today cdate)
8505 ;; immediately shift to today
8506 (setq arg (- today cdate))))
8507 (org-timestamp-change arg (or what 'day))
8508 (when (and (org-at-date-range-p)
8509 (re-search-backward org-tr-regexp-both (point-at-bol)))
8510 (let ((end org-last-changed-timestamp))
8511 (org-timestamp-change arg (or what 'day))
8512 (setq org-last-changed-timestamp
8513 (concat org-last-changed-timestamp "--" end)))))
8514 (org-agenda-show-new-time marker org-last-changed-timestamp))
8515 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8517 (defun org-agenda-date-earlier (arg &optional what)
8518 "Change the date of this item to ARG day(s) earlier."
8519 (interactive "p")
8520 (org-agenda-date-later (- arg) what))
8522 (defun org-agenda-date-later-minutes (arg)
8523 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8524 (interactive "p")
8525 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8526 (org-agenda-date-later arg 'minute))
8528 (defun org-agenda-date-earlier-minutes (arg)
8529 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8530 (interactive "p")
8531 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8532 (org-agenda-date-earlier arg 'minute))
8534 (defun org-agenda-date-later-hours (arg)
8535 "Change the time of this item, in hour steps."
8536 (interactive "p")
8537 (org-agenda-date-later arg 'hour))
8539 (defun org-agenda-date-earlier-hours (arg)
8540 "Change the time of this item, in hour steps."
8541 (interactive "p")
8542 (org-agenda-date-earlier arg 'hour))
8544 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8545 "Show new date stamp via text properties."
8546 ;; We use text properties to make this undoable
8547 (let ((inhibit-read-only t)
8548 (buffer-invisibility-spec))
8549 (setq stamp (concat " " prefix " => " stamp))
8550 (save-excursion
8551 (goto-char (point-max))
8552 (while (not (bobp))
8553 (when (equal marker (org-get-at-bol 'org-marker))
8554 (org-move-to-column (- (window-width) (length stamp)) t)
8555 (org-agenda-fix-tags-filter-overlays-at (point))
8556 (if (featurep 'xemacs)
8557 ;; Use `duplicable' property to trigger undo recording
8558 (let ((ex (make-extent nil nil))
8559 (gl (make-glyph stamp)))
8560 (set-glyph-face gl 'secondary-selection)
8561 (set-extent-properties
8562 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8563 (insert-extent ex (1- (point)) (point-at-eol)))
8564 (add-text-properties
8565 (1- (point)) (point-at-eol)
8566 (list 'display (org-add-props stamp nil
8567 'face 'secondary-selection))))
8568 (beginning-of-line 1))
8569 (beginning-of-line 0)))))
8571 (defun org-agenda-date-prompt (arg)
8572 "Change the date of this item. Date is prompted for, with default today.
8573 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8574 be used to request time specification in the time stamp."
8575 (interactive "P")
8576 (org-agenda-check-type t 'agenda 'timeline)
8577 (org-agenda-check-no-diary)
8578 (let* ((marker (or (org-get-at-bol 'org-marker)
8579 (org-agenda-error)))
8580 (buffer (marker-buffer marker))
8581 (pos (marker-position marker)))
8582 (org-with-remote-undo buffer
8583 (with-current-buffer buffer
8584 (widen)
8585 (goto-char pos)
8586 (if (not (org-at-timestamp-p t))
8587 (error "Cannot find time stamp"))
8588 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8589 (org-agenda-show-new-time marker org-last-changed-timestamp))
8590 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8592 (defun org-agenda-schedule (arg &optional time)
8593 "Schedule the item at point.
8594 ARG is passed through to `org-schedule'."
8595 (interactive "P")
8596 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8597 (org-agenda-check-no-diary)
8598 (let* ((marker (or (org-get-at-bol 'org-marker)
8599 (org-agenda-error)))
8600 (type (marker-insertion-type marker))
8601 (buffer (marker-buffer marker))
8602 (pos (marker-position marker))
8603 (org-insert-labeled-timestamps-at-point nil)
8605 (set-marker-insertion-type marker t)
8606 (org-with-remote-undo buffer
8607 (with-current-buffer buffer
8608 (widen)
8609 (goto-char pos)
8610 (setq ts (org-schedule arg time)))
8611 (org-agenda-show-new-time marker ts "S"))
8612 (message "%s" ts)))
8614 (defun org-agenda-deadline (arg &optional time)
8615 "Schedule the item at point.
8616 ARG is passed through to `org-deadline'."
8617 (interactive "P")
8618 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8619 (org-agenda-check-no-diary)
8620 (let* ((marker (or (org-get-at-bol 'org-marker)
8621 (org-agenda-error)))
8622 (buffer (marker-buffer marker))
8623 (pos (marker-position marker))
8624 (org-insert-labeled-timestamps-at-point nil)
8626 (org-with-remote-undo buffer
8627 (with-current-buffer buffer
8628 (widen)
8629 (goto-char pos)
8630 (setq ts (org-deadline arg time)))
8631 (org-agenda-show-new-time marker ts "D"))
8632 (message "%s" ts)))
8634 (defun org-agenda-clock-in (&optional arg)
8635 "Start the clock on the currently selected item."
8636 (interactive "P")
8637 (org-agenda-check-no-diary)
8638 (if (equal arg '(4))
8639 (org-clock-in arg)
8640 (let* ((marker (or (org-get-at-bol 'org-marker)
8641 (org-agenda-error)))
8642 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8643 marker))
8644 (pos (marker-position marker))
8645 newhead)
8646 (org-with-remote-undo (marker-buffer marker)
8647 (with-current-buffer (marker-buffer marker)
8648 (widen)
8649 (goto-char pos)
8650 (org-show-context 'agenda)
8651 (org-show-entry)
8652 (org-cycle-hide-drawers 'children)
8653 (org-clock-in arg)
8654 (setq newhead (org-get-heading)))
8655 (org-agenda-change-all-lines newhead hdmarker)))))
8657 (defun org-agenda-clock-out ()
8658 "Stop the currently running clock."
8659 (interactive)
8660 (unless (marker-buffer org-clock-marker)
8661 (error "No running clock"))
8662 (let ((marker (make-marker)) newhead)
8663 (org-with-remote-undo (marker-buffer org-clock-marker)
8664 (with-current-buffer (marker-buffer org-clock-marker)
8665 (save-excursion
8666 (save-restriction
8667 (widen)
8668 (goto-char org-clock-marker)
8669 (org-back-to-heading t)
8670 (move-marker marker (point))
8671 (org-clock-out)
8672 (setq newhead (org-get-heading))))))
8673 (org-agenda-change-all-lines newhead marker)
8674 (move-marker marker nil)))
8676 (defun org-agenda-clock-cancel (&optional arg)
8677 "Cancel the currently running clock."
8678 (interactive "P")
8679 (unless (marker-buffer org-clock-marker)
8680 (error "No running clock"))
8681 (org-with-remote-undo (marker-buffer org-clock-marker)
8682 (org-clock-cancel)))
8684 (defun org-agenda-clock-goto ()
8685 "Jump to the currently clocked in task within the agenda.
8686 If the currently clocked in task is not listed in the agenda
8687 buffer, display it in another window."
8688 (interactive)
8689 (let (pos)
8690 (mapc (lambda (o)
8691 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8692 (setq pos (overlay-start o))))
8693 (overlays-in (point-min) (point-max)))
8694 (cond (pos (goto-char pos))
8695 ;; If the currently clocked entry is not in the agenda
8696 ;; buffer, we visit it in another window:
8697 (org-clock-current-task
8698 (org-switch-to-buffer-other-window (org-clock-goto)))
8699 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8701 (defun org-agenda-diary-entry-in-org-file ()
8702 "Make a diary entry in the file `org-agenda-diary-file'."
8703 (let (d1 d2 char (text "") dp1 dp2)
8704 (if (equal (buffer-name) "*Calendar*")
8705 (setq d1 (calendar-cursor-to-date t)
8706 d2 (car calendar-mark-ring))
8707 (setq dp1 (get-text-property (point-at-bol) 'day))
8708 (unless dp1 (error "No date defined in current line"))
8709 (setq d1 (calendar-gregorian-from-absolute dp1)
8710 d2 (and (ignore-errors (mark))
8711 (save-excursion
8712 (goto-char (mark))
8713 (setq dp2 (get-text-property (point-at-bol) 'day)))
8714 (calendar-gregorian-from-absolute dp2))))
8715 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8716 (setq char (read-char-exclusive))
8717 (cond
8718 ((equal char ?d)
8719 (setq text (read-string "Day entry: "))
8720 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8721 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8722 ((equal char ?a)
8723 (setq d1 (list (car d1) (nth 1 d1)
8724 (read-number (format "Reference year [%d]: " (nth 2 d1))
8725 (nth 2 d1))))
8726 (setq text (read-string "Anniversary (use %d to show years): "))
8727 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8728 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8729 ((equal char ?b)
8730 (setq text (read-string "Block entry: "))
8731 (unless (and d1 d2 (not (equal d1 d2)))
8732 (error "No block of days selected"))
8733 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8734 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8735 ((equal char ?j)
8736 (org-switch-to-buffer-other-window
8737 (find-file-noselect org-agenda-diary-file))
8738 (require 'org-datetree)
8739 (org-datetree-find-date-create d1)
8740 (org-reveal t))
8741 (t (error "Invalid selection character `%c'" char)))))
8743 (defcustom org-agenda-insert-diary-strategy 'date-tree
8744 "Where in `org-agenda-diary-file' should new entries be added?
8745 Valid values:
8747 date-tree in the date tree, as child of the date
8748 top-level as top-level entries at the end of the file."
8749 :group 'org-agenda
8750 :type '(choice
8751 (const :tag "in a date tree" date-tree)
8752 (const :tag "as top level at end of file" top-level)))
8754 (defcustom org-agenda-insert-diary-extract-time nil
8755 "Non-nil means extract any time specification from the diary entry."
8756 :group 'org-agenda
8757 :version "24.1"
8758 :type 'boolean)
8760 (defcustom org-agenda-bulk-mark-char ">"
8761 "A single-character string to be used as the bulk mark."
8762 :group 'org-agenda
8763 :version "24.1"
8764 :type 'string)
8766 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8767 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8768 If TEXT is not empty, it will become the headline of the new entry, and
8769 the resulting entry will not be shown. When TEXT is empty, switch to
8770 `org-agenda-diary-file' and let the user finish the entry there."
8771 (let ((cw (current-window-configuration)))
8772 (org-switch-to-buffer-other-window
8773 (find-file-noselect org-agenda-diary-file))
8774 (widen)
8775 (goto-char (point-min))
8776 (cond
8777 ((eq type 'anniversary)
8778 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8779 (progn
8780 (or (org-at-heading-p t)
8781 (progn
8782 (outline-next-heading)
8783 (insert "* Anniversaries\n\n")
8784 (beginning-of-line -1)))))
8785 (outline-next-heading)
8786 (org-back-over-empty-lines)
8787 (backward-char 1)
8788 (insert "\n")
8789 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8790 (nth 2 d1) (car d1) (nth 1 d1) text)))
8791 ((eq type 'day)
8792 (let ((org-prefix-has-time t)
8793 (org-agenda-time-leading-zero t)
8794 fmt time time2)
8795 (if org-agenda-insert-diary-extract-time
8796 ;; Use org-agenda-format-item to parse text for a time-range and
8797 ;; remove it. FIXME: This is a hack, we should refactor
8798 ;; that function to make time extraction available separately
8799 (setq fmt (org-agenda-format-item nil text nil nil t)
8800 time (get-text-property 0 'time fmt)
8801 time2 (if (> (length time) 0)
8802 ;; split-string removes trailing ...... if
8803 ;; no end time given. First space
8804 ;; separates time from date.
8805 (concat " " (car (split-string time "\\.")))
8806 nil)
8807 text (get-text-property 0 'txt fmt)))
8808 (if (eq org-agenda-insert-diary-strategy 'top-level)
8809 (org-agenda-insert-diary-as-top-level text)
8810 (require 'org-datetree)
8811 (org-datetree-find-date-create d1)
8812 (org-agenda-insert-diary-make-new-entry text))
8813 (org-insert-time-stamp (org-time-from-absolute
8814 (calendar-absolute-from-gregorian d1))
8815 nil nil nil nil time2))
8816 (end-of-line 0))
8817 ((eq type 'block)
8818 (if (> (calendar-absolute-from-gregorian d1)
8819 (calendar-absolute-from-gregorian d2))
8820 (setq d1 (prog1 d2 (setq d2 d1))))
8821 (if (eq org-agenda-insert-diary-strategy 'top-level)
8822 (org-agenda-insert-diary-as-top-level text)
8823 (require 'org-datetree)
8824 (org-datetree-find-date-create d1)
8825 (org-agenda-insert-diary-make-new-entry text))
8826 (org-insert-time-stamp (org-time-from-absolute
8827 (calendar-absolute-from-gregorian d1)))
8828 (insert "--")
8829 (org-insert-time-stamp (org-time-from-absolute
8830 (calendar-absolute-from-gregorian d2)))
8831 (end-of-line 0)))
8832 (if (string-match "\\S-" text)
8833 (progn
8834 (set-window-configuration cw)
8835 (message "%s entry added to %s"
8836 (capitalize (symbol-name type))
8837 (abbreviate-file-name org-agenda-diary-file)))
8838 (org-reveal t)
8839 (message "Please finish entry here"))))
8841 (defun org-agenda-insert-diary-as-top-level (text)
8842 "Make new entry as a top-level entry at the end of the file.
8843 Add TEXT as headline, and position the cursor in the second line so that
8844 a timestamp can be added there."
8845 (widen)
8846 (goto-char (point-max))
8847 (or (bolp) (insert "\n"))
8848 (insert "* " text "\n")
8849 (if org-adapt-indentation (org-indent-to-column 2)))
8851 (defun org-agenda-insert-diary-make-new-entry (text)
8852 "Make new entry as last child of current entry.
8853 Add TEXT as headline, and position the cursor in the second line so that
8854 a timestamp can be added there."
8855 (let ((org-show-following-heading t)
8856 (org-show-siblings t)
8857 (org-show-hierarchy-above t)
8858 (org-show-entry-below t)
8859 col)
8860 (outline-next-heading)
8861 (org-back-over-empty-lines)
8862 (or (looking-at "[ \t]*$")
8863 (progn (insert "\n") (backward-char 1)))
8864 (org-insert-heading nil t)
8865 (org-do-demote)
8866 (setq col (current-column))
8867 (insert text "\n")
8868 (if org-adapt-indentation (org-indent-to-column col))
8869 (let ((org-show-following-heading t)
8870 (org-show-siblings t)
8871 (org-show-hierarchy-above t)
8872 (org-show-entry-below t))
8873 (org-show-context))))
8875 (defun org-agenda-diary-entry ()
8876 "Make a diary entry, like the `i' command from the calendar.
8877 All the standard commands work: block, weekly etc.
8878 When `org-agenda-diary-file' points to a file,
8879 `org-agenda-diary-entry-in-org-file' is called instead to create
8880 entries in that Org-mode file."
8881 (interactive)
8882 (if (not (eq org-agenda-diary-file 'diary-file))
8883 (org-agenda-diary-entry-in-org-file)
8884 (require 'diary-lib)
8885 (let* ((char (progn
8886 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8887 (read-char-exclusive)))
8888 (cmd (cdr (assoc char
8889 '((?d . insert-diary-entry)
8890 (?w . insert-weekly-diary-entry)
8891 (?m . insert-monthly-diary-entry)
8892 (?y . insert-yearly-diary-entry)
8893 (?a . insert-anniversary-diary-entry)
8894 (?b . insert-block-diary-entry)
8895 (?c . insert-cyclic-diary-entry)))))
8896 (oldf (symbol-function 'calendar-cursor-to-date))
8897 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8898 (point (point))
8899 (mark (or (mark t) (point))))
8900 (unless cmd
8901 (error "No command associated with <%c>" char))
8902 (unless (and (get-text-property point 'day)
8903 (or (not (equal ?b char))
8904 (get-text-property mark 'day)))
8905 (error "Don't know which date to use for diary entry"))
8906 ;; We implement this by hacking the `calendar-cursor-to-date' function
8907 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8908 (let ((calendar-mark-ring
8909 (list (calendar-gregorian-from-absolute
8910 (or (get-text-property mark 'day)
8911 (get-text-property point 'day))))))
8912 (unwind-protect
8913 (progn
8914 (fset 'calendar-cursor-to-date
8915 (lambda (&optional error dummy)
8916 (calendar-gregorian-from-absolute
8917 (get-text-property point 'day))))
8918 (call-interactively cmd))
8919 (fset 'calendar-cursor-to-date oldf))))))
8921 (defun org-agenda-execute-calendar-command (cmd)
8922 "Execute a calendar command from the agenda with date from cursor."
8923 (org-agenda-check-type t 'agenda 'timeline)
8924 (require 'diary-lib)
8925 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
8926 (error "Don't know which date to use for the calendar command"))
8927 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8928 (point (point))
8929 (date (calendar-gregorian-from-absolute
8930 (get-text-property point 'day)))
8931 ;; the following 2 vars are needed in the calendar
8932 (displayed-month (car date))
8933 (displayed-year (nth 2 date)))
8934 (unwind-protect
8935 (progn
8936 (fset 'calendar-cursor-to-date
8937 (lambda (&optional error dummy)
8938 (calendar-gregorian-from-absolute
8939 (get-text-property point 'day))))
8940 (call-interactively cmd))
8941 (fset 'calendar-cursor-to-date oldf))))
8943 (defun org-agenda-phases-of-moon ()
8944 "Display the phases of the moon for the 3 months around the cursor date."
8945 (interactive)
8946 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8948 (defun org-agenda-holidays ()
8949 "Display the holidays for the 3 months around the cursor date."
8950 (interactive)
8951 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8953 (defvar calendar-longitude) ; defined in calendar.el
8954 (defvar calendar-latitude) ; defined in calendar.el
8955 (defvar calendar-location-name) ; defined in calendar.el
8957 (defun org-agenda-sunrise-sunset (arg)
8958 "Display sunrise and sunset for the cursor date.
8959 Latitude and longitude can be specified with the variables
8960 `calendar-latitude' and `calendar-longitude'. When called with prefix
8961 argument, latitude and longitude will be prompted for."
8962 (interactive "P")
8963 (require 'solar)
8964 (let ((calendar-longitude (if arg nil calendar-longitude))
8965 (calendar-latitude (if arg nil calendar-latitude))
8966 (calendar-location-name
8967 (if arg "the given coordinates" calendar-location-name)))
8968 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8970 (defun org-agenda-goto-calendar ()
8971 "Open the Emacs calendar with the date at the cursor."
8972 (interactive)
8973 (org-agenda-check-type t 'agenda 'timeline)
8974 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
8975 (error "Don't know which date to open in calendar")))
8976 (date (calendar-gregorian-from-absolute day))
8977 (calendar-move-hook nil)
8978 (calendar-view-holidays-initially-flag nil)
8979 (calendar-view-diary-initially-flag nil))
8980 (calendar)
8981 (calendar-goto-date date)))
8983 ;;;###autoload
8984 (defun org-calendar-goto-agenda ()
8985 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8986 This is a command that has to be installed in `calendar-mode-map'."
8987 (interactive)
8988 (org-agenda-list nil (calendar-absolute-from-gregorian
8989 (calendar-cursor-to-date))
8990 nil))
8992 (autoload 'org-calendar-goto-agenda "org-agenda" "\
8993 Compute the Org-mode agenda for the calendar date displayed at the cursor.
8994 This is a command that has to be installed in `calendar-mode-map'.
8996 \(fn)" t nil)
8998 (defun org-agenda-convert-date ()
8999 (interactive)
9000 (org-agenda-check-type t 'agenda 'timeline)
9001 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9002 date s)
9003 (unless day
9004 (error "Don't know which date to convert"))
9005 (setq date (calendar-gregorian-from-absolute day))
9006 (setq s (concat
9007 "Gregorian: " (calendar-date-string date) "\n"
9008 "ISO: " (calendar-iso-date-string date) "\n"
9009 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9010 "Julian: " (calendar-julian-date-string date) "\n"
9011 "Astron. JD: " (calendar-astro-date-string date)
9012 " (Julian date number at noon UTC)\n"
9013 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9014 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9015 "French: " (calendar-french-date-string date) "\n"
9016 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9017 "Mayan: " (calendar-mayan-date-string date) "\n"
9018 "Coptic: " (calendar-coptic-date-string date) "\n"
9019 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9020 "Persian: " (calendar-persian-date-string date) "\n"
9021 "Chinese: " (calendar-chinese-date-string date) "\n"))
9022 (with-output-to-temp-buffer "*Dates*"
9023 (princ s))
9024 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9026 ;;; Bulk commands
9028 (defun org-agenda-bulk-marked-p ()
9029 (eq (get-char-property (point-at-bol) 'type)
9030 'org-marked-entry-overlay))
9032 (defun org-agenda-bulk-mark (&optional arg)
9033 "Mark the entry at point for future bulk action."
9034 (interactive "p")
9035 (dotimes (i (or arg 1))
9036 (unless (org-get-at-bol 'org-agenda-diary-link)
9037 (let* ((m (org-get-at-bol 'org-hd-marker))
9039 (unless (org-agenda-bulk-marked-p)
9040 (unless m (error "Nothing to mark at point"))
9041 (push m org-agenda-bulk-marked-entries)
9042 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9043 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9044 (org-get-todo-face "TODO")
9045 'evaporate)
9046 (overlay-put ov 'type 'org-marked-entry-overlay))
9047 (beginning-of-line 2)
9048 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9049 (beginning-of-line 2))
9050 (message "%d entries marked for bulk action"
9051 (length org-agenda-bulk-marked-entries))))))
9053 (defun org-agenda-bulk-mark-all ()
9054 "Mark all entries for future agenda bulk action."
9055 (interactive)
9056 (org-agenda-bulk-mark-regexp "."))
9058 (defun org-agenda-bulk-mark-regexp (regexp)
9059 "Mark entries matching REGEXP for future agenda bulk action."
9060 (interactive "sMark entries matching regexp: ")
9061 (let ((entries-marked 0))
9062 (save-excursion
9063 (goto-char (point-min))
9064 (goto-char (next-single-property-change (point) 'txt))
9065 (while (re-search-forward regexp nil t)
9066 (when (string-match regexp (get-text-property (point) 'txt))
9067 (setq entries-marked (1+ entries-marked))
9068 (call-interactively 'org-agenda-bulk-mark))))
9069 (if (not entries-marked)
9070 (message "No entry matching this regexp."))))
9072 (defun org-agenda-bulk-unmark (&optional arg)
9073 "Unmark the entry at point for future bulk action."
9074 (interactive "P")
9075 (if arg
9076 (org-agenda-bulk-unmark-all)
9077 (cond ((org-agenda-bulk-marked-p)
9078 (org-agenda-bulk-remove-overlays
9079 (point-at-bol) (+ 2 (point-at-bol)))
9080 (setq org-agenda-bulk-marked-entries
9081 (delete (org-get-at-bol 'org-hd-marker)
9082 org-agenda-bulk-marked-entries))
9083 (beginning-of-line 2)
9084 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9085 (beginning-of-line 2))
9086 (message "%d entries left marked for bulk action"
9087 (length org-agenda-bulk-marked-entries)))
9088 (t (message "No entry to unmark here")))))
9090 (defun org-agenda-bulk-toggle ()
9091 "Toggle marking the entry at point for bulk action."
9092 (interactive)
9093 (if (org-agenda-bulk-marked-p)
9094 (org-agenda-bulk-unmark)
9095 (org-agenda-bulk-mark)))
9097 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9098 "Remove the mark overlays between BEG and END in the agenda buffer.
9099 BEG and END default to the buffer limits.
9101 This only removes the overlays, it does not remove the markers
9102 from the list in `org-agenda-bulk-marked-entries'."
9103 (interactive)
9104 (mapc (lambda (ov)
9105 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9106 (delete-overlay ov)))
9107 (overlays-in (or beg (point-min)) (or end (point-max)))))
9109 (defun org-agenda-bulk-unmark-all ()
9110 "Remove all marks in the agenda buffer.
9111 This will remove the markers and the overlays."
9112 (interactive)
9113 (if (null org-agenda-bulk-marked-entries)
9114 (message "No entry to unmark")
9115 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9116 (setq org-agenda-bulk-marked-entries nil)
9117 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9119 (defcustom org-agenda-persistent-marks nil
9120 "Non-nil means marked items will stay marked after a bulk action.
9121 You can toggle this interactively by typing `p' when prompted for a
9122 bulk action."
9123 :group 'org-agenda
9124 :version "24.1"
9125 :type 'boolean)
9127 (defun org-agenda-bulk-action (&optional arg)
9128 "Execute an remote-editing action on all marked entries.
9129 The prefix arg is passed through to the command if possible."
9130 (interactive "P")
9131 ;; Make sure we have markers, and only valid ones
9132 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9133 (mapc
9134 (lambda (m)
9135 (unless (and (markerp m)
9136 (marker-buffer m)
9137 (buffer-live-p (marker-buffer m))
9138 (marker-position m))
9139 (error "Marker %s for bulk command is invalid" m)))
9140 org-agenda-bulk-marked-entries)
9142 ;; Prompt for the bulk command
9143 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9144 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9145 "[S]catter [f]unction "
9146 (when org-agenda-bulk-custom-functions
9147 (concat " Custom: ["
9148 (mapconcat (lambda(f) (char-to-string (car f)))
9149 org-agenda-bulk-custom-functions "")
9150 "]"))))
9151 (catch 'exit
9152 (let* ((action (read-char-exclusive))
9153 (org-log-refile (if org-log-refile 'time nil))
9154 (entries (reverse org-agenda-bulk-marked-entries))
9155 (org-overriding-default-time
9156 (if (get-text-property (point) 'org-agenda-date-header)
9157 (org-get-cursor-date)))
9158 redo-at-end
9159 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9160 (cond
9161 ((equal action ?p)
9162 (let ((org-agenda-persistent-marks
9163 (not org-agenda-persistent-marks)))
9164 (org-agenda-bulk-action)
9165 (throw 'exit nil)))
9167 ((equal action ?$)
9168 (setq cmd '(org-agenda-archive)))
9170 ((equal action ?A)
9171 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9173 ((member action '(?r ?w))
9174 (setq rfloc (org-refile-get-location
9175 "Refile to"
9176 (marker-buffer (car entries))
9177 org-refile-allow-creating-parent-nodes))
9178 (if (nth 3 rfloc)
9179 (setcar (nthcdr 3 rfloc)
9180 (move-marker (make-marker) (nth 3 rfloc)
9181 (or (get-file-buffer (nth 1 rfloc))
9182 (find-buffer-visiting (nth 1 rfloc))
9183 (error "This should not happen")))))
9185 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9186 redo-at-end t))
9188 ((equal action ?t)
9189 (setq state (org-icompleting-read
9190 "Todo state: "
9191 (with-current-buffer (marker-buffer (car entries))
9192 (mapcar 'list org-todo-keywords-1))))
9193 (setq cmd `(let ((org-inhibit-blocking t)
9194 (org-inhibit-logging 'note))
9195 (org-agenda-todo ,state))))
9197 ((memq action '(?- ?+))
9198 (setq tag (org-icompleting-read
9199 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9200 (with-current-buffer (marker-buffer (car entries))
9201 (delq nil
9202 (mapcar (lambda (x)
9203 (if (stringp (car x)) x)) org-tag-alist)))))
9204 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9206 ((memq action '(?s ?d))
9207 (let* ((time
9208 (unless arg
9209 (org-read-date
9210 nil nil nil
9211 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9212 org-overriding-default-time)))
9213 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9214 (setq cmd `(eval '(,c1 arg ,time)))))
9216 ((equal action ?S)
9217 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9218 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9219 (let ((days (read-number
9220 (format "Scatter tasks across how many %sdays: "
9221 (if arg "week" "")) 7)))
9222 (setq cmd
9223 `(let ((distance (1+ (random ,days))))
9224 (if arg
9225 (let ((dist distance)
9226 (day-of-week
9227 (calendar-day-of-week
9228 (calendar-gregorian-from-absolute (org-today)))))
9229 (dotimes (i (1+ dist))
9230 (while (member day-of-week org-agenda-weekend-days)
9231 (incf distance)
9232 (incf day-of-week)
9233 (if (= day-of-week 7)
9234 (setq day-of-week 0)))
9235 (incf day-of-week)
9236 (if (= day-of-week 7)
9237 (setq day-of-week 0)))))
9238 ;; silently fail when try to replan a sexp entry
9239 (condition-case nil
9240 (let* ((date (calendar-gregorian-from-absolute
9241 (+ (org-today) distance)))
9242 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9243 (nth 2 date))))
9244 (org-agenda-schedule nil time))
9245 (error nil)))))))
9247 ((assoc action org-agenda-bulk-custom-functions)
9248 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9249 redo-at-end t))
9251 ((equal action ?f)
9252 (setq cmd (list (intern
9253 (org-icompleting-read "Function: "
9254 obarray 'fboundp t nil nil)))))
9256 (t (error "Invalid bulk action")))
9258 ;; Sort the markers, to make sure that parents are handled before children
9259 (setq entries (sort entries
9260 (lambda (a b)
9261 (cond
9262 ((equal (marker-buffer a) (marker-buffer b))
9263 (< (marker-position a) (marker-position b)))
9265 (string< (buffer-name (marker-buffer a))
9266 (buffer-name (marker-buffer b))))))))
9268 ;; Now loop over all markers and apply cmd
9269 (while (setq e (pop entries))
9270 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9271 (if (not pos)
9272 (progn (message "Skipping removed entry at %s" e)
9273 (setq cntskip (1+ cntskip)))
9274 (goto-char pos)
9275 (let (org-loop-over-headlines-in-active-region)
9276 (eval cmd))
9277 (setq cnt (1+ cnt))))
9278 (when redo-at-end (org-agenda-redo))
9279 (unless org-agenda-persistent-marks
9280 (org-agenda-bulk-unmark-all))
9281 (message "Acted on %d entries%s%s"
9283 (if (= cntskip 0)
9285 (format ", skipped %d (disappeared before their turn)"
9286 cntskip))
9287 (if (not org-agenda-persistent-marks)
9288 "" " (kept marked)"))))))
9290 (defun org-agenda-capture ()
9291 "Call `org-capture' with the date at point."
9292 (interactive)
9293 (if (not (eq major-mode 'org-agenda-mode))
9294 (error "You cannot do this outside of agenda buffers")
9295 (let ((org-overriding-default-time
9296 (org-get-cursor-date)))
9297 (call-interactively 'org-capture))))
9299 ;;; Flagging notes
9301 (defun org-agenda-show-the-flagging-note ()
9302 "Display the flagging note in the other window.
9303 When called a second time in direct sequence, offer to remove the FLAGGING
9304 tag and (if present) the flagging note."
9305 (interactive)
9306 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9307 (win (selected-window))
9308 note heading newhead)
9309 (unless hdmarker
9310 (error "No linked entry at point"))
9311 (if (and (eq this-command last-command)
9312 (y-or-n-p "Unflag and remove any flagging note? "))
9313 (progn
9314 (org-agenda-remove-flag hdmarker)
9315 (let ((win (get-buffer-window "*Flagging Note*")))
9316 (and win (delete-window win)))
9317 (message "Entry unflagged"))
9318 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9319 (unless note
9320 (error "No flagging note"))
9321 (org-kill-new note)
9322 (org-switch-to-buffer-other-window "*Flagging Note*")
9323 (erase-buffer)
9324 (insert note)
9325 (goto-char (point-min))
9326 (while (re-search-forward "\\\\n" nil t)
9327 (replace-match "\n" t t))
9328 (goto-char (point-min))
9329 (select-window win)
9330 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9332 (defun org-agenda-remove-flag (marker)
9333 "Remove the FLAGGED tag and any flagging note in the entry."
9334 (let (newhead)
9335 (org-with-point-at marker
9336 (org-toggle-tag "FLAGGED" 'off)
9337 (org-entry-delete nil "THEFLAGGINGNOTE")
9338 (setq newhead (org-get-heading)))
9339 (org-agenda-change-all-lines newhead marker)
9340 (message "Entry unflagged")))
9342 (defun org-agenda-get-any-marker (&optional pos)
9343 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9344 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9346 ;;; Appointment reminders
9348 (defvar appt-time-msg-list) ; defined in appt.el
9350 ;;;###autoload
9351 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9352 "Activate appointments found in `org-agenda-files'.
9353 With a \\[universal-argument] prefix, refresh the list of
9354 appointments.
9356 If FILTER is t, interactively prompt the user for a regular
9357 expression, and filter out entries that don't match it.
9359 If FILTER is a string, use this string as a regular expression
9360 for filtering entries out.
9362 If FILTER is a function, filter out entries against which
9363 calling the function returns nil. This function takes one
9364 argument: an entry from `org-agenda-get-day-entries'.
9366 FILTER can also be an alist with the car of each cell being
9367 either 'headline or 'category. For example:
9369 '((headline \"IMPORTANT\")
9370 (category \"Work\"))
9372 will only add headlines containing IMPORTANT or headlines
9373 belonging to the \"Work\" category.
9375 ARGS are symbols indicating what kind of entries to consider.
9376 By default `org-agenda-to-appt' will use :deadline, :scheduled
9377 and :timestamp entries. See the docstring of `org-diary' for
9378 details and examples.
9380 If an entry as a APPT_WARNTIME property, its value will be used
9381 to override `appt-message-warning-time'."
9382 (interactive "P")
9383 (if refresh (setq appt-time-msg-list nil))
9384 (if (eq filter t)
9385 (setq filter (read-from-minibuffer "Regexp filter: ")))
9386 (let* ((cnt 0) ; count added events
9387 (scope (or args '(:deadline :scheduled :timestamp)))
9388 (org-agenda-new-buffers nil)
9389 (org-deadline-warning-days 0)
9390 ;; Do not use `org-today' here because appt only takes
9391 ;; time and without date as argument, so it may pass wrong
9392 ;; information otherwise
9393 (today (org-date-to-gregorian
9394 (time-to-days (current-time))))
9395 (org-agenda-restrict nil)
9396 (files (org-agenda-files 'unrestricted)) entries file
9397 (org-agenda-buffer nil))
9398 ;; Get all entries which may contain an appt
9399 (org-agenda-prepare-buffers files)
9400 (while (setq file (pop files))
9401 (setq entries
9402 (delq nil
9403 (append entries
9404 (apply 'org-agenda-get-day-entries
9405 file today scope)))))
9406 ;; Map thru entries and find if we should filter them out
9407 (mapc
9408 (lambda(x)
9409 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9410 (cat (get-text-property 1 'org-category x))
9411 (tod (get-text-property 1 'time-of-day x))
9412 (ok (or (null filter)
9413 (and (stringp filter) (string-match filter evt))
9414 (and (functionp filter) (funcall filter x))
9415 (and (listp filter)
9416 (let ((cat-filter (cadr (assoc 'category filter)))
9417 (evt-filter (cadr (assoc 'headline filter))))
9418 (or (and (stringp cat-filter)
9419 (string-match cat-filter cat))
9420 (and (stringp evt-filter)
9421 (string-match evt-filter evt)))))))
9422 (wrn (get-text-property 1 'warntime x)))
9423 ;; FIXME: Shall we remove text-properties for the appt text?
9424 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9425 (when (and ok tod)
9426 (setq tod (concat "00" (number-to-string tod))
9427 tod (when (string-match
9428 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9429 (concat (match-string 1 tod) ":"
9430 (match-string 2 tod))))
9431 (if (version< emacs-version "23.3")
9432 (appt-add tod evt)
9433 (appt-add tod evt wrn))
9434 (setq cnt (1+ cnt))))) entries)
9435 (org-release-buffers org-agenda-new-buffers)
9436 (if (eq cnt 0)
9437 (message "No event to add")
9438 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9440 (autoload 'org-agenda-to-appt "org-agenda" "\
9441 Activate appointments found in `org-agenda-files'.
9442 With a \\[universal-argument] prefix, refresh the list of
9443 appointments.
9445 If FILTER is t, interactively prompt the user for a regular
9446 expression, and filter out entries that don't match it.
9448 If FILTER is a string, use this string as a regular expression
9449 for filtering entries out.
9451 If FILTER is a function, filter out entries against which
9452 calling the function returns nil. This function takes one
9453 argument: an entry from `org-agenda-get-day-entries'.
9455 FILTER can also be an alist with the car of each cell being
9456 either 'headline or 'category. For example:
9458 '((headline \"IMPORTANT\")
9459 (category \"Work\"))
9461 will only add headlines containing IMPORTANT or headlines
9462 belonging to the \"Work\" category.
9464 ARGS are symbols indicating what kind of entries to consider.
9465 By default `org-agenda-to-appt' will use :deadline, :scheduled
9466 and :timestamp entries. See the docstring of `org-diary' for
9467 details and examples.
9469 If an entry as a APPT_WARNTIME property, its value will be used
9470 to override `appt-message-warning-time'.
9472 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9474 (defun org-agenda-todayp (date)
9475 "Does DATE mean today, when considering `org-extend-today-until'?"
9476 (let ((today (org-today))
9477 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9478 date)))
9479 (eq date today)))
9481 (defun org-agenda-todo-yesterday (&optional arg)
9482 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9483 (interactive "P")
9484 (let* ((hour (third (decode-time
9485 (org-current-time))))
9486 (org-extend-today-until (1+ hour)))
9487 (org-agenda-todo arg)))
9489 (provide 'org-agenda)
9491 ;;; org-agenda.el ends here