org-e-latex: Change syntax for images attributes
[org-mode.git] / lisp / org-agenda.el
blob2c484b5fa5164f344b9524273a4fe5cebc37171f
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (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-todo-ignore-time-comparison-use-seconds nil
744 "Time unit to use when possibly ignoring an agenda item.
746 See the docstring of various `org-agenda-todo-ignore-*' options.
747 The default is to compare time stamps using days. An item is thus
748 considered to be in the future if it is at least one day after today.
749 Non-nil means to compare time stamps using seconds. An item is then
750 considered future if it has a time value later than current time."
751 :group 'org-agenda-skip
752 :group 'org-agenda-todo-list
753 :type '(choice
754 (const :tag "Compare time with days" nil)
755 (const :tag "Compare time with seconds" t)))
757 (defcustom org-agenda-tags-todo-honor-ignore-options nil
758 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
759 The variables
760 `org-agenda-todo-ignore-with-date',
761 `org-agenda-todo-ignore-timestamp',
762 `org-agenda-todo-ignore-scheduled',
763 `org-agenda-todo-ignore-deadlines'
764 make the global TODO list skip entries that have time stamps of certain
765 kinds. If this option is set, the same options will also apply for the
766 tags-todo search, which is the general tags/property matcher
767 restricted to unfinished TODO entries only."
768 :group 'org-agenda-skip
769 :group 'org-agenda-todo-list
770 :group 'org-agenda-match-view
771 :type 'boolean)
773 (defcustom org-agenda-skip-scheduled-if-done nil
774 "Non-nil means don't show scheduled items in agenda when they are done.
775 This is relevant for the daily/weekly agenda, not for the TODO list. And
776 it applies only to the actual date of the scheduling. Warnings about
777 an item with a past scheduling dates are always turned off when the item
778 is DONE."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type 'boolean)
783 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
784 "Non-nil means skip scheduling line if same entry shows because of deadline.
785 In the agenda of today, an entry can show up multiple times because
786 it is both scheduled and has a nearby deadline, and maybe a plain time
787 stamp as well.
788 When this variable is t, then only the deadline is shown and the fact that
789 the entry is scheduled today or was scheduled previously is not shown.
790 When this variable is nil, the entry will be shown several times. When
791 the variable is the symbol `not-today', then skip scheduled previously,
792 but not scheduled today."
793 :group 'org-agenda-skip
794 :group 'org-agenda-daily/weekly
795 :type '(choice
796 (const :tag "Never" nil)
797 (const :tag "Always" t)
798 (const :tag "Not when scheduled today" not-today)))
800 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
801 "Non-nil means skip timestamp line if same entry shows because of deadline.
802 In the agenda of today, an entry can show up multiple times
803 because it has both a plain timestamp and has a nearby deadline.
804 When this variable is t, then only the deadline is shown and the
805 fact that the entry has a timestamp for or including today is not
806 shown. When this variable is nil, the entry will be shown
807 several times."
808 :group 'org-agenda-skip
809 :group 'org-agenda-daily/weekly
810 :version "24.1"
811 :type '(choice
812 (const :tag "Never" nil)
813 (const :tag "Always" t)))
815 (defcustom org-agenda-skip-deadline-if-done nil
816 "Non-nil means don't show deadlines when the corresponding item is done.
817 When nil, the deadline is still shown and should give you a happy feeling.
818 This is relevant for the daily/weekly agenda. And it applied only to the
819 actually date of the deadline. Warnings about approaching and past-due
820 deadlines are always turned off when the item is DONE."
821 :group 'org-agenda-skip
822 :group 'org-agenda-daily/weekly
823 :type 'boolean)
825 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
826 "Non-nil means skip deadline prewarning when entry is also scheduled.
827 This will apply on all days where a prewarning for the deadline would
828 be shown, but not at the day when the entry is actually due. On that day,
829 the deadline will be shown anyway.
830 This variable may be set to nil, t, the symbol `pre-scheduled',
831 or a number which will then give the number of days before the actual
832 deadline when the prewarnings should resume. The symbol `pre-scheduled'
833 eliminates the deadline prewarning only prior to the scheduled date.
834 This can be used in a workflow where the first showing of the deadline will
835 trigger you to schedule it, and then you don't want to be reminded of it
836 because you will take care of it on the day when scheduled."
837 :group 'org-agenda-skip
838 :group 'org-agenda-daily/weekly
839 :version "24.1"
840 :type '(choice
841 (const :tag "Always show prewarning" nil)
842 (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
843 (const :tag "Remove prewarning if entry is scheduled" t)
844 (integer :tag "Restart prewarning N days before deadline")))
846 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
847 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
848 When non-nil, after the search for timestamps has matched once in an
849 entry, the rest of the entry will not be searched."
850 :group 'org-agenda-skip
851 :type 'boolean)
853 (defcustom org-agenda-skip-timestamp-if-done nil
854 "Non-nil means don't select item by timestamp or -range if it is DONE."
855 :group 'org-agenda-skip
856 :group 'org-agenda-daily/weekly
857 :type 'boolean)
859 (defcustom org-agenda-dim-blocked-tasks t
860 "Non-nil means dim blocked tasks in the agenda display.
861 This causes some overhead during agenda construction, but if you
862 have turned on `org-enforce-todo-dependencies',
863 `org-enforce-todo-checkbox-dependencies', or any other blocking
864 mechanism, this will create useful feedback in the agenda.
866 Instead of t, this variable can also have the value `invisible'.
867 Then blocked tasks will be invisible and only become visible when
868 they become unblocked. An exemption to this behavior is when a task is
869 blocked because of unchecked checkboxes below it. Since checkboxes do
870 not show up in the agenda views, making this task invisible you remove any
871 trace from agenda views that there is something to do. Therefore, a task
872 that is blocked because of checkboxes will never be made invisible, it
873 will only be dimmed."
874 :group 'org-agenda-daily/weekly
875 :group 'org-agenda-todo-list
876 :type '(choice
877 (const :tag "Do not dim" nil)
878 (const :tag "Dim to a gray face" t)
879 (const :tag "Make invisible" invisible)))
881 (defcustom org-timeline-show-empty-dates 3
882 "Non-nil means `org-timeline' also shows dates without an entry.
883 When nil, only the days which actually have entries are shown.
884 When t, all days between the first and the last date are shown.
885 When an integer, show also empty dates, but if there is a gap of more than
886 N days, just insert a special line indicating the size of the gap."
887 :group 'org-agenda-skip
888 :type '(choice
889 (const :tag "None" nil)
890 (const :tag "All" t)
891 (integer :tag "at most")))
893 (defgroup org-agenda-startup nil
894 "Options concerning initial settings in the Agenda in Org Mode."
895 :tag "Org Agenda Startup"
896 :group 'org-agenda)
898 (defcustom org-agenda-menu-show-matcher t
899 "Non-nil means show the match string in the agenda dispatcher menu.
900 When nil, the matcher string is not shown, but is put into the help-echo
901 property so than moving the mouse over the command shows it.
902 Setting it to nil is good if matcher strings are very long and/or if
903 you want to use two-columns display (see `org-agenda-menu-two-columns')."
904 :group 'org-agenda
905 :version "24.1"
906 :type 'boolean)
908 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
910 (defcustom org-agenda-menu-two-columns nil
911 "Non-nil means, use two columns to show custom commands in the dispatcher.
912 If you use this, you probably want to set `org-agenda-menu-show-matcher'
913 to nil."
914 :group 'org-agenda
915 :version "24.1"
916 :type 'boolean)
918 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
919 (defcustom org-agenda-finalize-hook nil
920 "Hook run just before displaying an agenda buffer.
921 The buffer is still writable when the hook is called.
923 You can modify some of the buffer substrings but you should be
924 extra careful not to modify the text properties of the agenda
925 headlines as the agenda display heavily relies on them."
926 :group 'org-agenda-startup
927 :type 'hook)
929 (defcustom org-agenda-mouse-1-follows-link nil
930 "Non-nil means mouse-1 on a link will follow the link in the agenda.
931 A longer mouse click will still set point. Does not work on XEmacs.
932 Needs to be set before org.el is loaded."
933 :group 'org-agenda-startup
934 :type 'boolean)
936 (defcustom org-agenda-start-with-follow-mode nil
937 "The initial value of follow mode in a newly created agenda window."
938 :group 'org-agenda-startup
939 :type 'boolean)
941 (defcustom org-agenda-follow-indirect nil
942 "Non-nil means `org-agenda-follow-mode' displays only the
943 current item's tree, in an indirect buffer."
944 :group 'org-agenda
945 :version "24.1"
946 :type 'boolean)
948 (defcustom org-agenda-show-outline-path t
949 "Non-nil means show outline path in echo area after line motion."
950 :group 'org-agenda-startup
951 :type 'boolean)
953 (defcustom org-agenda-start-with-entry-text-mode nil
954 "The initial value of entry-text-mode in a newly created agenda window."
955 :group 'org-agenda-startup
956 :type 'boolean)
958 (defcustom org-agenda-entry-text-maxlines 5
959 "Number of text lines to be added when `E' is pressed in the agenda.
961 Note that this variable only used during agenda display. Add add entry text
962 when exporting the agenda, configure the variable
963 `org-agenda-add-entry-ext-maxlines'."
964 :group 'org-agenda
965 :type 'integer)
967 (defcustom org-agenda-entry-text-exclude-regexps nil
968 "List of regular expressions to clean up entry text.
969 The complete matches of all regular expressions in this list will be
970 removed from entry text before it is shown in the agenda."
971 :group 'org-agenda
972 :type '(repeat (regexp)))
974 (defvar org-agenda-entry-text-cleanup-hook nil
975 "Hook that is run after basic cleanup of entry text to be shown in agenda.
976 This cleanup is done in a temporary buffer, so the function may inspect and
977 change the entire buffer.
978 Some default stuff like drawers and scheduling/deadline dates will already
979 have been removed when this is called, as will any matches for regular
980 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
982 (defvar org-agenda-include-inactive-timestamps nil
983 "Non-nil means include inactive time stamps in agenda and timeline.
984 Dynamically scoped.")
986 (defgroup org-agenda-windows nil
987 "Options concerning the windows used by the Agenda in Org Mode."
988 :tag "Org Agenda Windows"
989 :group 'org-agenda)
991 (defcustom org-agenda-window-setup 'reorganize-frame
992 "How the agenda buffer should be displayed.
993 Possible values for this option are:
995 current-window Show agenda in the current window, keeping all other windows.
996 other-window Use `switch-to-buffer-other-window' to display agenda.
997 reorganize-frame Show only two windows on the current frame, the current
998 window and the agenda.
999 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1000 Also, when exiting the agenda, kill that frame.
1001 See also the variable `org-agenda-restore-windows-after-quit'."
1002 :group 'org-agenda-windows
1003 :type '(choice
1004 (const current-window)
1005 (const other-frame)
1006 (const other-window)
1007 (const reorganize-frame)))
1009 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1010 "The min and max height of the agenda window as a fraction of frame height.
1011 The value of the variable is a cons cell with two numbers between 0 and 1.
1012 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1013 :group 'org-agenda-windows
1014 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1016 (defcustom org-agenda-restore-windows-after-quit nil
1017 "Non-nil means restore window configuration upon exiting agenda.
1018 Before the window configuration is changed for displaying the agenda,
1019 the current status is recorded. When the agenda is exited with
1020 `q' or `x' and this option is set, the old state is restored. If
1021 `org-agenda-window-setup' is `other-frame', the value of this
1022 option will be ignored."
1023 :group 'org-agenda-windows
1024 :type 'boolean)
1026 (defcustom org-agenda-ndays nil
1027 "Number of days to include in overview display.
1028 Should be 1 or 7.
1029 Obsolete, see `org-agenda-span'."
1030 :group 'org-agenda-daily/weekly
1031 :type 'integer)
1033 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1035 (defcustom org-agenda-span 'week
1036 "Number of days to include in overview display.
1037 Can be day, week, month, year, or any number of days.
1038 Custom commands can set this variable in the options section."
1039 :group 'org-agenda-daily/weekly
1040 :type '(choice (const :tag "Day" day)
1041 (const :tag "Week" week)
1042 (const :tag "Month" month)
1043 (const :tag "Year" year)
1044 (integer :tag "Custom")))
1046 (defcustom org-agenda-start-on-weekday 1
1047 "Non-nil means start the overview always on the specified weekday.
1048 0 denotes Sunday, 1 denotes Monday etc.
1049 When nil, always start on the current day.
1050 Custom commands can set this variable in the options section."
1051 :group 'org-agenda-daily/weekly
1052 :type '(choice (const :tag "Today" nil)
1053 (integer :tag "Weekday No.")))
1055 (defcustom org-agenda-show-all-dates t
1056 "Non-nil means `org-agenda' shows every day in the selected range.
1057 When nil, only the days which actually have entries are shown."
1058 :group 'org-agenda-daily/weekly
1059 :type 'boolean)
1061 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1062 "Format string for displaying dates in the agenda.
1063 Used by the daily/weekly agenda and by the timeline. This should be
1064 a format string understood by `format-time-string', or a function returning
1065 the formatted date as a string. The function must take a single argument,
1066 a calendar-style date list like (month day year)."
1067 :group 'org-agenda-daily/weekly
1068 :type '(choice
1069 (string :tag "Format string")
1070 (function :tag "Function")))
1072 (defun org-agenda-format-date-aligned (date)
1073 "Format a date string for display in the daily/weekly agenda, or timeline.
1074 This function makes sure that dates are aligned for easy reading."
1075 (require 'cal-iso)
1076 (let* ((dayname (calendar-day-name date))
1077 (day (cadr date))
1078 (day-of-week (calendar-day-of-week date))
1079 (month (car date))
1080 (monthname (calendar-month-name month))
1081 (year (nth 2 date))
1082 (iso-week (org-days-to-iso-week
1083 (calendar-absolute-from-gregorian date)))
1084 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1085 (1- year))
1086 ((and (= month 12) (<= iso-week 1))
1087 (1+ year))
1088 (t year)))
1089 (weekstring (if (= day-of-week 1)
1090 (format " W%02d" iso-week)
1091 "")))
1092 (format "%-10s %2d %s %4d%s"
1093 dayname day monthname year weekstring)))
1095 (defcustom org-agenda-time-leading-zero nil
1096 "Non-nil means use leading zero for military times in agenda.
1097 For example, 9:30am would become 09:30 rather than 9:30."
1098 :group 'org-agenda-daily/weekly
1099 :version "24.1"
1100 :type 'boolean)
1102 (defcustom org-agenda-timegrid-use-ampm nil
1103 "When set, show AM/PM style timestamps on the timegrid."
1104 :group 'org-agenda
1105 :version "24.1"
1106 :type 'boolean)
1108 (defun org-agenda-time-of-day-to-ampm (time)
1109 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1110 (let* ((hour-number (string-to-number (substring time 0 -3)))
1111 (minute (substring time -2))
1112 (ampm "am"))
1113 (cond
1114 ((equal hour-number 12)
1115 (setq ampm "pm"))
1116 ((> hour-number 12)
1117 (setq ampm "pm")
1118 (setq hour-number (- hour-number 12))))
1119 (concat
1120 (if org-agenda-time-leading-zero
1121 (format "%02d" hour-number)
1122 (format "%02s" (number-to-string hour-number)))
1123 ":" minute ampm)))
1125 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1126 "Conditionally convert TIME to AM/PM format
1127 based on `org-agenda-timegrid-use-ampm'"
1128 (if org-agenda-timegrid-use-ampm
1129 (org-agenda-time-of-day-to-ampm time)
1130 time))
1132 (defcustom org-agenda-weekend-days '(6 0)
1133 "Which days are weekend?
1134 These days get the special face `org-agenda-date-weekend' in the agenda
1135 and timeline buffers."
1136 :group 'org-agenda-daily/weekly
1137 :type '(set :greedy t
1138 (const :tag "Monday" 1)
1139 (const :tag "Tuesday" 2)
1140 (const :tag "Wednesday" 3)
1141 (const :tag "Thursday" 4)
1142 (const :tag "Friday" 5)
1143 (const :tag "Saturday" 6)
1144 (const :tag "Sunday" 0)))
1146 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1147 "Non-nil means jump to today when moving a past date forward in time.
1148 When using S-right in the agenda to move a a date forward, and the date
1149 stamp currently points to the past, the first key press will move it
1150 to today. WHen nil, just move one day forward even if the date stays
1151 in the past."
1152 :group 'org-agenda-daily/weekly
1153 :version "24.1"
1154 :type 'boolean)
1156 (defcustom org-agenda-include-diary nil
1157 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1158 Custom commands can set this variable in the options section."
1159 :group 'org-agenda-daily/weekly
1160 :type 'boolean)
1162 (defcustom org-agenda-include-deadlines t
1163 "If non-nil, include entries within their deadline warning period.
1164 Custom commands can set this variable in the options section."
1165 :group 'org-agenda-daily/weekly
1166 :version "24.1"
1167 :type 'boolean)
1169 (defcustom org-agenda-repeating-timestamp-show-all t
1170 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1171 When set to a list of strings, only show occurrences of repeating
1172 stamps for these TODO keywords. When nil, only one occurrence is
1173 shown, either today or the nearest into the future."
1174 :group 'org-agenda-daily/weekly
1175 :type '(choice
1176 (const :tag "Show repeating stamps" t)
1177 (repeat :tag "Show repeating stamps for these TODO keywords"
1178 (string :tag "TODO Keyword"))
1179 (const :tag "Don't show repeating stamps" nil)))
1181 (defcustom org-scheduled-past-days 10000
1182 "No. of days to continue listing scheduled items that are not marked DONE.
1183 When an item is scheduled on a date, it shows up in the agenda on this
1184 day and will be listed until it is marked done for the number of days
1185 given here."
1186 :group 'org-agenda-daily/weekly
1187 :type 'integer)
1189 (defcustom org-agenda-log-mode-items '(closed clock)
1190 "List of items that should be shown in agenda log mode.
1191 This list may contain the following symbols:
1193 closed Show entries that have been closed on that day.
1194 clock Show entries that have received clocked time on that day.
1195 state Show all logged state changes.
1196 Note that instead of changing this variable, you can also press `C-u l' in
1197 the agenda to display all available LOG items temporarily."
1198 :group 'org-agenda-daily/weekly
1199 :type '(set :greedy t (const closed) (const clock) (const state)))
1201 (defcustom org-agenda-clock-consistency-checks
1202 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1203 :gap-ok-around ("4:00")
1204 :default-face ((:background "DarkRed") (:foreground "white"))
1205 :overlap-face nil :gap-face nil :no-end-time-face nil
1206 :long-face nil :short-face nil)
1207 "This is a property list, with the following keys:
1209 :max-duration Mark clocking chunks that are longer than this time.
1210 This is a time string like \"HH:MM\", or the number
1211 of minutes as an integer.
1213 :min-duration Mark clocking chunks that are shorter that this.
1214 This is a time string like \"HH:MM\", or the number
1215 of minutes as an integer.
1217 :max-gap Mark gaps between clocking chunks that are longer than
1218 this duration. A number of minutes, or a string
1219 like \"HH:MM\".
1221 :gap-ok-around List of times during the day which are usually not working
1222 times. When a gap is detected, but the gap contains any
1223 of these times, the gap is *not* reported. For example,
1224 if this is (\"4:00\" \"13:00\") then gaps that contain
1225 4:00 in the morning (i.e. the night) and 13:00
1226 (i.e. a typical lunch time) do not cause a warning.
1227 You should have at least one time during the night in this
1228 list, or otherwise the first task each morning will trigger
1229 a warning because it follows a long gap.
1231 Furthermore, the following properties can be used to define faces for
1232 issue display.
1234 :default-face the default face, if the specific face is undefined
1235 :overlap-face face for overlapping clocks
1236 :gap-face face for gaps between clocks
1237 :no-end-time-face face for incomplete clocks
1238 :long-face face for clock intervals that are too long
1239 :short-face face for clock intervals that are too short"
1240 :group 'org-agenda-daily/weekly
1241 :group 'org-clock
1242 :version "24.1"
1243 :type 'plist)
1245 (defcustom org-agenda-log-mode-add-notes t
1246 "Non-nil means add first line of notes to log entries in agenda views.
1247 If a log item like a state change or a clock entry is associated with
1248 notes, the first line of these notes will be added to the entry in the
1249 agenda display."
1250 :group 'org-agenda-daily/weekly
1251 :type 'boolean)
1253 (defcustom org-agenda-start-with-log-mode nil
1254 "The initial value of log-mode in a newly created agenda window.
1255 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1256 explanations on the possible values."
1257 :group 'org-agenda-startup
1258 :group 'org-agenda-daily/weekly
1259 :type '(choice (const :tag "Don't show log items" nil)
1260 (const :tag "Show only log items" 'only)
1261 (const :tag "Show all possible log items" 'clockcheck)
1262 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1263 (choice (const :tag "Show closed log items" 'closed)
1264 (const :tag "Show clocked log items" 'clock)
1265 (const :tag "Show all logged state changes" 'state)))))
1267 (defcustom org-agenda-start-with-clockreport-mode nil
1268 "The initial value of clockreport-mode in a newly created agenda window."
1269 :group 'org-agenda-startup
1270 :group 'org-agenda-daily/weekly
1271 :type 'boolean)
1273 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1274 "Property list with parameters for the clocktable in clockreport mode.
1275 This is the display mode that shows a clock table in the daily/weekly
1276 agenda, the properties for this dynamic block can be set here.
1277 The usual clocktable parameters are allowed here, but you cannot set
1278 the properties :name, :tstart, :tend, :block, and :scope - these will
1279 be overwritten to make sure the content accurately reflects the
1280 current display in the agenda."
1281 :group 'org-agenda-daily/weekly
1282 :type 'plist)
1284 (defcustom org-agenda-search-view-always-boolean nil
1285 "Non-nil means the search string is interpreted as individual parts.
1287 The search string for search view can either be interpreted as a phrase,
1288 or as a list of snippets that define a boolean search for a number of
1289 strings.
1291 When this is non-nil, the string will be split on whitespace, and each
1292 snippet will be searched individually, and all must match in order to
1293 select an entry. A snippet is then a single string of non-white
1294 characters, or a string in double quotes, or a regexp in {} braces.
1295 If a snippet is preceded by \"-\", the snippet must *not* match.
1296 \"+\" is syntactic sugar for positive selection. Each snippet may
1297 be found as a full word or a partial word, but see the variable
1298 `org-agenda-search-view-force-full-words'.
1300 When this is nil, search will look for the entire search phrase as one,
1301 with each space character matching any amount of whitespace, including
1302 line breaks.
1304 Even when this is nil, you can still switch to Boolean search dynamically
1305 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1306 is a regexp marked with braces like \"{abc}\", this will also switch to
1307 boolean search."
1308 :group 'org-agenda-search-view
1309 :version "24.1"
1310 :type 'boolean)
1312 (if (fboundp 'defvaralias)
1313 (defvaralias 'org-agenda-search-view-search-words-only
1314 'org-agenda-search-view-always-boolean))
1316 (defcustom org-agenda-search-view-force-full-words nil
1317 "Non-nil means, search words must be matches as complete words.
1318 When nil, they may also match part of a word."
1319 :group 'org-agenda-search-view
1320 :version "24.1"
1321 :type 'boolean)
1323 (defgroup org-agenda-time-grid nil
1324 "Options concerning the time grid in the Org-mode Agenda."
1325 :tag "Org Agenda Time Grid"
1326 :group 'org-agenda)
1328 (defcustom org-agenda-search-headline-for-time t
1329 "Non-nil means search headline for a time-of-day.
1330 If the headline contains a time-of-day in one format or another, it will
1331 be used to sort the entry into the time sequence of items for a day.
1332 Some people have time stamps in the headline that refer to the creation
1333 time or so, and then this produces an unwanted side effect. If this is
1334 the case for your, use this variable to turn off searching the headline
1335 for a time."
1336 :group 'org-agenda-time-grid
1337 :type 'boolean)
1339 (defcustom org-agenda-use-time-grid t
1340 "Non-nil means show a time grid in the agenda schedule.
1341 A time grid is a set of lines for specific times (like every two hours between
1342 8:00 and 20:00). The items scheduled for a day at specific times are
1343 sorted in between these lines.
1344 For details about when the grid will be shown, and what it will look like, see
1345 the variable `org-agenda-time-grid'."
1346 :group 'org-agenda-time-grid
1347 :type 'boolean)
1349 (defcustom org-agenda-time-grid
1350 '((daily today require-timed)
1351 "----------------"
1352 (800 1000 1200 1400 1600 1800 2000))
1354 "The settings for time grid for agenda display.
1355 This is a list of three items. The first item is again a list. It contains
1356 symbols specifying conditions when the grid should be displayed:
1358 daily if the agenda shows a single day
1359 weekly if the agenda shows an entire week
1360 today show grid on current date, independent of daily/weekly display
1361 require-timed show grid only if at least one item has a time specification
1363 The second item is a string which will be placed behind the grid time.
1365 The third item is a list of integers, indicating the times that should have
1366 a grid line."
1367 :group 'org-agenda-time-grid
1368 :type
1369 '(list
1370 (set :greedy t :tag "Grid Display Options"
1371 (const :tag "Show grid in single day agenda display" daily)
1372 (const :tag "Show grid in weekly agenda display" weekly)
1373 (const :tag "Always show grid for today" today)
1374 (const :tag "Show grid only if any timed entries are present"
1375 require-timed)
1376 (const :tag "Skip grid times already present in an entry"
1377 remove-match))
1378 (string :tag "Grid String")
1379 (repeat :tag "Grid Times" (integer :tag "Time"))))
1381 (defcustom org-agenda-show-current-time-in-grid t
1382 "Non-nil means show the current time in the time grid."
1383 :group 'org-agenda-time-grid
1384 :version "24.1"
1385 :type 'boolean)
1387 (defcustom org-agenda-current-time-string
1388 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1389 "The string for the current time marker in the agenda."
1390 :group 'org-agenda-time-grid
1391 :version "24.1"
1392 :type 'string)
1394 (defgroup org-agenda-sorting nil
1395 "Options concerning sorting in the Org-mode Agenda."
1396 :tag "Org Agenda Sorting"
1397 :group 'org-agenda)
1399 (defcustom org-agenda-sorting-strategy
1400 '((agenda habit-down time-up priority-down category-keep)
1401 (todo priority-down category-keep)
1402 (tags priority-down category-keep)
1403 (search category-keep))
1404 "Sorting structure for the agenda items of a single day.
1405 This is a list of symbols which will be used in sequence to determine
1406 if an entry should be listed before another entry. The following
1407 symbols are recognized:
1409 time-up Put entries with time-of-day indications first, early first
1410 time-down Put entries with time-of-day indications first, late first
1411 category-keep Keep the default order of categories, corresponding to the
1412 sequence in `org-agenda-files'.
1413 category-up Sort alphabetically by category, A-Z.
1414 category-down Sort alphabetically by category, Z-A.
1415 tag-up Sort alphabetically by last tag, A-Z.
1416 tag-down Sort alphabetically by last tag, Z-A.
1417 priority-up Sort numerically by priority, high priority last.
1418 priority-down Sort numerically by priority, high priority first.
1419 todo-state-up Sort by todo state, tasks that are done last.
1420 todo-state-down Sort by todo state, tasks that are done first.
1421 effort-up Sort numerically by estimated effort, high effort last.
1422 effort-down Sort numerically by estimated effort, high effort first.
1423 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1424 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1425 habit-up Put entries that are habits first
1426 habit-down Put entries that are habits last
1427 alpha-up Sort headlines alphabetically
1428 alpha-down Sort headlines alphabetically, reversed
1430 The different possibilities will be tried in sequence, and testing stops
1431 if one comparison returns a \"not-equal\". For example, the default
1432 '(time-up category-keep priority-down)
1433 means: Pull out all entries having a specified time of day and sort them,
1434 in order to make a time schedule for the current day the first thing in the
1435 agenda listing for the day. Of the entries without a time indication, keep
1436 the grouped in categories, don't sort the categories, but keep them in
1437 the sequence given in `org-agenda-files'. Within each category sort by
1438 priority.
1440 Leaving out `category-keep' would mean that items will be sorted across
1441 categories by priority.
1443 Instead of a single list, this can also be a set of list for specific
1444 contents, with a context symbol in the car of the list, any of
1445 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1447 Custom commands can bind this variable in the options section."
1448 :group 'org-agenda-sorting
1449 :type `(choice
1450 (repeat :tag "General" ,org-sorting-choice)
1451 (list :tag "Individually"
1452 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1453 (repeat ,org-sorting-choice))
1454 (cons (const :tag "Strategy for TODO lists" todo)
1455 (repeat ,org-sorting-choice))
1456 (cons (const :tag "Strategy for Tags matches" tags)
1457 (repeat ,org-sorting-choice))
1458 (cons (const :tag "Strategy for search matches" search)
1459 (repeat ,org-sorting-choice)))))
1461 (defcustom org-agenda-cmp-user-defined nil
1462 "A function to define the comparison `user-defined'.
1463 This function must receive two arguments, agenda entry a and b.
1464 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1465 the user comparison, return nil.
1466 When this is defined, you can make `user-defined-up' and `user-defined-down'
1467 part of an agenda sorting strategy."
1468 :group 'org-agenda-sorting
1469 :type 'symbol)
1471 (defcustom org-sort-agenda-notime-is-late t
1472 "Non-nil means items without time are considered late.
1473 This is only relevant for sorting. When t, items which have no explicit
1474 time like 15:30 will be considered as 99:01, i.e. later than any items which
1475 do have a time. When nil, the default time is before 0:00. You can use this
1476 option to decide if the schedule for today should come before or after timeless
1477 agenda entries."
1478 :group 'org-agenda-sorting
1479 :type 'boolean)
1481 (defcustom org-sort-agenda-noeffort-is-high t
1482 "Non-nil means items without effort estimate are sorted as high effort.
1483 This also applies when filtering an agenda view with respect to the
1484 < or > effort operator. Then, tasks with no effort defined will be treated
1485 as tasks with high effort.
1486 When nil, such items are sorted as 0 minutes effort."
1487 :group 'org-agenda-sorting
1488 :type 'boolean)
1490 (defgroup org-agenda-line-format nil
1491 "Options concerning the entry prefix in the Org-mode agenda display."
1492 :tag "Org Agenda Line Format"
1493 :group 'org-agenda)
1495 (defcustom org-agenda-prefix-format
1496 '((agenda . " %i %-12:c%?-12t% s")
1497 (timeline . " % s")
1498 (todo . " %i %-12:c")
1499 (tags . " %i %-12:c")
1500 (search . " %i %-12:c"))
1501 "Format specifications for the prefix of items in the agenda views.
1502 An alist with five entries, each for the different agenda types. The
1503 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1504 The values are format strings.
1506 This format works similar to a printf format, with the following meaning:
1508 %c the category of the item, \"Diary\" for entries from the diary,
1509 or as given by the CATEGORY keyword or derived from the file name
1510 %e the effort required by the item
1511 %l the level of the item (insert X space(s) if item is of level X)
1512 %i the icon category of the item, see `org-agenda-category-icon-alist'
1513 %T the last tag of the item (ignore inherited tags, which come first)
1514 %t the HH:MM time-of-day specification if one applies to the entry
1515 %s Scheduling/Deadline information, a short string
1516 %(expression) Eval EXPRESSION and replace the control string
1517 by the result
1519 All specifiers work basically like the standard `%s' of printf, but may
1520 contain two additional characters: a question mark just after the `%'
1521 and a whitespace/punctuation character just before the final letter.
1523 If the first character after `%' is a question mark, the entire field
1524 will only be included if the corresponding value applies to the current
1525 entry. This is useful for fields which should have fixed width when
1526 present, but zero width when absent. For example, \"%?-12t\" will
1527 result in a 12 character time field if a time of the day is specified,
1528 but will completely disappear in entries which do not contain a time.
1530 If there is punctuation or whitespace character just before the final
1531 format letter, this character will be appended to the field value if
1532 the value is not empty. For example, the format \"%-12:c\" leads to
1533 \"Diary: \" if the category is \"Diary\". If the category were be
1534 empty, no additional colon would be inserted.
1536 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1537 which means:
1539 - Indent the line with two space characters
1540 - Give the category a 12 chars wide field, padded with whitespace on
1541 the right (because of `-'). Append a colon if there is a category
1542 (because of `:').
1543 - If there is a time-of-day, put it into a 12 chars wide field. If no
1544 time, don't put in an empty field, just skip it (because of '?').
1545 - Finally, put the scheduling information.
1547 See also the variables `org-agenda-remove-times-when-in-prefix' and
1548 `org-agenda-remove-tags'.
1550 Custom commands can set this variable in the options section."
1551 :type '(choice
1552 (string :tag "General format")
1553 (list :greedy t :tag "View dependent"
1554 (cons (const agenda) (string :tag "Format"))
1555 (cons (const timeline) (string :tag "Format"))
1556 (cons (const todo) (string :tag "Format"))
1557 (cons (const tags) (string :tag "Format"))
1558 (cons (const search) (string :tag "Format"))))
1559 :group 'org-agenda-line-format)
1561 (defvar org-prefix-format-compiled nil
1562 "The compiled prefix format and associated variables.
1563 This is a list where first element is a list of variable bindings, and second
1564 element is the compiled format expression. See the variable
1565 `org-agenda-prefix-format'.")
1567 (defcustom org-agenda-todo-keyword-format "%-1s"
1568 "Format for the TODO keyword in agenda lines.
1569 Set this to something like \"%-12s\" if you want all TODO keywords
1570 to occupy a fixed space in the agenda display."
1571 :group 'org-agenda-line-format
1572 :type 'string)
1574 (defcustom org-agenda-diary-sexp-prefix nil
1575 "A regexp that matches part of a diary sexp entry
1576 which should be treated as scheduling/deadline information in
1577 `org-agenda'.
1579 For example, you can use this to extract the `diary-remind-message' from
1580 `diary-remind' entries."
1581 :group 'org-agenda-line-format
1582 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1584 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1585 "Text preceding timerange entries in the agenda view.
1586 This is a list with two strings. The first applies when the range
1587 is entirely on one day. The second applies if the range spans several days.
1588 The strings may have two \"%d\" format specifiers which will be filled
1589 with the sequence number of the days, and the total number of days in the
1590 range, respectively."
1591 :group 'org-agenda-line-format
1592 :type '(list
1593 (string :tag "Deadline today ")
1594 (choice :tag "Deadline relative"
1595 (string :tag "Format string")
1596 (function))))
1598 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1599 "Text preceding scheduled items in the agenda view.
1600 This is a list with two strings. The first applies when the item is
1601 scheduled on the current day. The second applies when it has been scheduled
1602 previously, it may contain a %d indicating that this is the nth time that
1603 this item is scheduled, due to automatic rescheduling of unfinished items
1604 for the following day. So this number is one larger than the number of days
1605 that passed since this item was scheduled first."
1606 :group 'org-agenda-line-format
1607 :type '(list
1608 (string :tag "Scheduled today ")
1609 (string :tag "Scheduled previously")))
1611 (defcustom org-agenda-inactive-leader "["
1612 "Text preceding item pulled into the agenda by inactive time stamps.
1613 These entries are added to the agenda when pressing \"[\"."
1614 :group 'org-agenda-line-format
1615 :version "24.1"
1616 :type '(list
1617 (string :tag "Scheduled today ")
1618 (string :tag "Scheduled previously")))
1620 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1621 "Text preceding deadline items in the agenda view.
1622 This is a list with two strings. The first applies when the item has its
1623 deadline on the current day. The second applies when it is in the past or
1624 in the future, it may contain %d to capture how many days away the deadline
1625 is (was)."
1626 :group 'org-agenda-line-format
1627 :type '(list
1628 (string :tag "Deadline today ")
1629 (choice :tag "Deadline relative"
1630 (string :tag "Format string")
1631 (function))))
1633 (defcustom org-agenda-remove-times-when-in-prefix t
1634 "Non-nil means remove duplicate time specifications in agenda items.
1635 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1636 time-of-day specification in a headline or diary entry is extracted and
1637 placed into the prefix. If this option is non-nil, the original specification
1638 \(a timestamp or -range, or just a plain time(range) specification like
1639 11:30-4pm) will be removed for agenda display. This makes the agenda less
1640 cluttered.
1641 The option can be t or nil. It may also be the symbol `beg', indicating
1642 that the time should only be removed when it is located at the beginning of
1643 the headline/diary entry."
1644 :group 'org-agenda-line-format
1645 :type '(choice
1646 (const :tag "Always" t)
1647 (const :tag "Never" nil)
1648 (const :tag "When at beginning of entry" beg)))
1650 (defcustom org-agenda-remove-timeranges-from-blocks nil
1651 "Non-nil means remove time ranges specifications in agenda
1652 items that span on several days."
1653 :group 'org-agenda-line-format
1654 :version "24.1"
1655 :type 'boolean)
1657 (defcustom org-agenda-default-appointment-duration nil
1658 "Default duration for appointments that only have a starting time.
1659 When nil, no duration is specified in such cases.
1660 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1661 :group 'org-agenda-line-format
1662 :type '(choice
1663 (integer :tag "Minutes")
1664 (const :tag "No default duration")))
1666 (defcustom org-agenda-show-inherited-tags t
1667 "Non-nil means show inherited tags in each agenda line."
1668 :group 'org-agenda-line-format
1669 :type 'boolean)
1671 (defcustom org-agenda-hide-tags-regexp nil
1672 "Regular expression used to filter away specific tags in agenda views.
1673 This means that these tags will be present, but not be shown in the agenda
1674 line. Secondary filtering will still work on the hidden tags.
1675 Nil means don't hide any tags."
1676 :group 'org-agenda-line-format
1677 :type '(choice
1678 (const :tag "Hide none" nil)
1679 (string :tag "Regexp ")))
1681 (defcustom org-agenda-remove-tags nil
1682 "Non-nil means remove the tags from the headline copy in the agenda.
1683 When this is the symbol `prefix', only remove tags when
1684 `org-agenda-prefix-format' contains a `%T' specifier."
1685 :group 'org-agenda-line-format
1686 :type '(choice
1687 (const :tag "Always" t)
1688 (const :tag "Never" nil)
1689 (const :tag "When prefix format contains %T" prefix)))
1691 (if (fboundp 'defvaralias)
1692 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1693 'org-agenda-remove-tags))
1695 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1696 "Shift tags in agenda items to this column.
1697 If this number is positive, it specifies the column. If it is negative,
1698 it means that the tags should be flushright to that column. For example,
1699 -80 works well for a normal 80 character screen."
1700 :group 'org-agenda-line-format
1701 :type 'integer)
1703 (if (fboundp 'defvaralias)
1704 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1706 (defcustom org-agenda-fontify-priorities 'cookies
1707 "Non-nil means highlight low and high priorities in agenda.
1708 When t, the highest priority entries are bold, lowest priority italic.
1709 However, settings in `org-priority-faces' will overrule these faces.
1710 When this variable is the symbol `cookies', only fontify the
1711 cookies, not the entire task.
1712 This may also be an association list of priority faces, whose
1713 keys are the character values of `org-highest-priority',
1714 `org-default-priority', and `org-lowest-priority' (the default values
1715 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1716 color as a string, or a list like `(:background \"Red\")'.
1717 If it is a color, the variable `org-faces-easy-properties'
1718 determines if it is a foreground or a background color."
1719 :group 'org-agenda-line-format
1720 :type '(choice
1721 (const :tag "Never" nil)
1722 (const :tag "Defaults" t)
1723 (const :tag "Cookies only" cookies)
1724 (repeat :tag "Specify"
1725 (list (character :tag "Priority" :value ?A)
1726 (choice :tag "Face "
1727 (string :tag "Color")
1728 (sexp :tag "Face"))))))
1730 (defcustom org-agenda-day-face-function nil
1731 "Function called to determine what face should be used to display a day.
1732 The only argument passed to that function is the day. It should
1733 returns a face, or nil if does not want to specify a face and let
1734 the normal rules apply."
1735 :group 'org-agenda-line-format
1736 :version "24.1"
1737 :type 'function)
1739 (defcustom org-agenda-category-icon-alist nil
1740 "Alist of category icon to be displayed in agenda views.
1742 Each entry should have the following format:
1744 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1746 Where CATEGORY-REGEXP is a regexp matching the categories where
1747 the icon should be displayed.
1748 FILE-OR-DATA either a file path or a string containing image data.
1750 The other fields can be omitted safely if not needed:
1751 TYPE indicates the image type.
1752 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1753 image data.
1754 PROPS are additional image attributes to assign to the image,
1755 like, e.g. `:ascent center'.
1757 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1759 If you want to set the display properties yourself, just put a
1760 list as second element:
1762 (CATEGORY-REGEXP (MY PROPERTY LIST))
1764 For example, to display a 16px horizontal space for Emacs
1765 category, you can use:
1767 (\"Emacs\" '(space . (:width (16))))"
1768 :group 'org-agenda-line-format
1769 :version "24.1"
1770 :type '(alist :key-type (string :tag "Regexp matching category")
1771 :value-type (choice (list :tag "Icon"
1772 (string :tag "File or data")
1773 (symbol :tag "Type")
1774 (boolean :tag "Data?")
1775 (repeat :tag "Extra image properties" :inline t symbol))
1776 (list :tag "Display properties" sexp))))
1778 (defgroup org-agenda-column-view nil
1779 "Options concerning column view in the agenda."
1780 :tag "Org Agenda Column View"
1781 :group 'org-agenda)
1783 (defcustom org-agenda-columns-show-summaries t
1784 "Non-nil means show summaries for columns displayed in the agenda view."
1785 :group 'org-agenda-column-view
1786 :type 'boolean)
1788 (defcustom org-agenda-columns-compute-summary-properties t
1789 "Non-nil means recompute all summary properties before column view.
1790 When column view in the agenda is listing properties that have a summary
1791 operator, it can go to all relevant buffers and recompute the summaries
1792 there. This can mean overhead for the agenda column view, but is necessary
1793 to have thing up to date.
1794 As a special case, a CLOCKSUM property also makes sure that the clock
1795 computations are current."
1796 :group 'org-agenda-column-view
1797 :type 'boolean)
1799 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1800 "Non-nil means the duration of an appointment will add to day effort.
1801 The property to which appointment durations will be added is the one given
1802 in the option `org-effort-property'. If an appointment does not have
1803 an end time, `org-agenda-default-appointment-duration' will be used. If that
1804 is not set, an appointment without end time will not contribute to the time
1805 estimate."
1806 :group 'org-agenda-column-view
1807 :type 'boolean)
1809 (defcustom org-agenda-auto-exclude-function nil
1810 "A function called with a tag to decide if it is filtered on '/ RET'.
1811 The sole argument to the function, which is called once for each
1812 possible tag, is a string giving the name of the tag. The
1813 function should return either nil if the tag should be included
1814 as normal, or \"-<TAG>\" to exclude the tag.
1815 Note that for the purpose of tag filtering, only the lower-case version of
1816 all tags will be considered, so that this function will only ever see
1817 the lower-case version of all tags."
1818 :group 'org-agenda
1819 :type 'function)
1821 (defcustom org-agenda-bulk-custom-functions nil
1822 "Alist of characters and custom functions for bulk actions.
1823 For example, this value makes those two functions available:
1825 '((?R set-category)
1826 (?C bulk-cut))
1828 With selected entries in an agenda buffer, `B R' will call
1829 the custom function `set-category' on the selected entries.
1830 Note that functions in this alist don't need to be quoted."
1831 :type 'alist
1832 :version "24.1"
1833 :group 'org-agenda)
1835 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1836 "Execute BODY with point at location given by `org-hd-marker' property.
1837 If STRING is non-nil, the text property will be fetched from position 0
1838 in that string. If STRING is nil, it will be fetched from the beginning
1839 of the current line."
1840 (org-with-gensyms (marker)
1841 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1842 'org-hd-marker ,string)))
1843 (with-current-buffer (marker-buffer ,marker)
1844 (save-excursion
1845 (goto-char ,marker)
1846 ,@body)))))
1847 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1849 (defun org-add-agenda-custom-command (entry)
1850 "Replace or add a command in `org-agenda-custom-commands'.
1851 This is mostly for hacking and trying a new command - once the command
1852 works you probably want to add it to `org-agenda-custom-commands' for good."
1853 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1854 (if ass
1855 (setcdr ass (cdr entry))
1856 (push entry org-agenda-custom-commands))))
1858 ;;; Define the org-agenda-mode
1860 (defvar org-agenda-mode-map (make-sparse-keymap)
1861 "Keymap for `org-agenda-mode'.")
1862 (if (fboundp 'defvaralias)
1863 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1865 (defvar org-agenda-menu) ; defined later in this file.
1866 (defvar org-agenda-restrict nil) ; defined later in this file.
1867 (defvar org-agenda-follow-mode nil)
1868 (defvar org-agenda-entry-text-mode nil)
1869 (defvar org-agenda-clockreport-mode nil)
1870 (defvar org-agenda-show-log nil)
1871 (defvar org-agenda-redo-command nil)
1872 (defvar org-agenda-query-string nil)
1873 (defvar org-agenda-mode-hook nil
1874 "Hook run after `org-agenda-mode' is turned on.
1875 The buffer is still writable when this hook is called.")
1876 (defvar org-agenda-type nil)
1877 (defvar org-agenda-force-single-file nil)
1878 (defvar org-agenda-bulk-marked-entries nil
1879 "List of markers that refer to marked entries in the agenda.")
1881 ;;; Multiple agenda buffers support
1883 (defcustom org-agenda-sticky nil
1884 "Non-nil means agenda q key will bury agenda buffers.
1885 Agenda commands will then show existing buffer instead of generating new ones.
1886 When nil, `q' will kill the single agenda buffer."
1887 :group 'org-agenda
1888 :version "24.3"
1889 :type 'boolean)
1892 ;;;###autoload
1893 (defun org-toggle-sticky-agenda (&optional arg)
1894 "Toggle `org-agenda-sticky'."
1895 (interactive "P")
1896 (let ((new-value (if arg
1897 (> (prefix-numeric-value arg) 0)
1898 (not org-agenda-sticky))))
1899 (if (equal new-value org-agenda-sticky)
1900 (and (org-called-interactively-p 'interactive)
1901 (message "Sticky agenda was already %s"
1902 (if org-agenda-sticky "enabled" "disabled")))
1903 (setq org-agenda-sticky new-value)
1904 (org-agenda-kill-all-agenda-buffers)
1905 (and (org-called-interactively-p 'interactive)
1906 (message "Sticky agenda was %s"
1907 (if org-agenda-sticky "enabled" "disabled"))))))
1909 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1910 Toggle `org-agenda-sticky'.
1912 \(fn &optional ARG)" t nil)
1914 (defvar org-agenda-buffer nil
1915 "Agenda buffer currently being generated.")
1917 (defvar org-agenda-last-prefix-arg nil)
1918 (defvar org-agenda-this-buffer-name nil)
1919 (defvar org-agenda-doing-sticky-redo nil)
1920 (defvar org-agenda-this-buffer-is-sticky nil)
1922 (defconst org-agenda-local-vars
1923 '(org-agenda-this-buffer-name
1924 org-agenda-undo-list
1925 org-agenda-pending-undo-list
1926 org-agenda-follow-mode
1927 org-agenda-entry-text-mode
1928 org-agenda-clockreport-mode
1929 org-agenda-show-log
1930 org-agenda-redo-command
1931 org-agenda-query-string
1932 org-agenda-type
1933 org-agenda-bulk-marked-entries
1934 org-agenda-undo-has-started-in
1935 org-agenda-info
1936 org-agenda-tag-filter-overlays
1937 org-agenda-cat-filter-overlays
1938 org-agenda-pre-window-conf
1939 org-agenda-columns-active
1940 org-agenda-tag-filter
1941 org-agenda-category-filter
1942 org-agenda-markers
1943 org-agenda-last-search-view-search-was-boolean
1944 org-agenda-filtered-by-category
1945 org-agenda-filter-form
1946 org-agenda-show-window
1947 org-agenda-cycle-counter
1948 org-agenda-last-prefix-arg)
1949 "Variables that must be local in agenda buffers to allow multiple buffers.")
1951 (defun org-agenda-mode ()
1952 "Mode for time-sorted view on action items in Org-mode files.
1954 The following commands are available:
1956 \\{org-agenda-mode-map}"
1957 (interactive)
1958 (cond (org-agenda-doing-sticky-redo
1959 ;; Refreshing sticky agenda-buffer
1961 ;; Preserve the value of `org-agenda-local-vars' variables,
1962 ;; while letting `kill-all-local-variables' kill the rest
1963 (let ((save (buffer-local-variables)))
1964 (kill-all-local-variables)
1965 (mapc 'make-local-variable org-agenda-local-vars)
1966 (dolist (elem save)
1967 (let ((var (car elem))
1968 (val (cdr elem)))
1969 (when (and val
1970 (member var org-agenda-local-vars))
1971 (set var val)))))
1972 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1973 (org-agenda-sticky
1974 ;; Creating a sticky Agenda buffer for the first time
1975 (kill-all-local-variables)
1976 (mapc 'make-local-variable org-agenda-local-vars)
1977 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1979 ;; Creating a non-sticky agenda buffer
1980 (kill-all-local-variables)
1981 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1982 (setq org-agenda-undo-list nil
1983 org-agenda-pending-undo-list nil
1984 org-agenda-bulk-marked-entries nil)
1985 (setq major-mode 'org-agenda-mode)
1986 ;; Keep global-font-lock-mode from turning on font-lock-mode
1987 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1988 (setq mode-name "Org-Agenda")
1989 (use-local-map org-agenda-mode-map)
1990 (easy-menu-add org-agenda-menu)
1991 (if org-startup-truncated (setq truncate-lines t))
1992 (org-set-local 'line-move-visual nil)
1993 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
1994 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1995 ;; Make sure properties are removed when copying text
1996 (make-local-variable 'filter-buffer-substring-functions)
1997 (add-hook 'filter-buffer-substring-functions
1998 (lambda (fun start end delete)
1999 (substring-no-properties (funcall fun start end delete))))
2000 (unless org-agenda-keep-modes
2001 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2002 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2003 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2004 org-agenda-show-log org-agenda-start-with-log-mode))
2006 (easy-menu-change
2007 '("Agenda") "Agenda Files"
2008 (append
2009 (list
2010 (vector
2011 (if (get 'org-agenda-files 'org-restrict)
2012 "Restricted to single file"
2013 "Edit File List")
2014 '(org-edit-agenda-file-list)
2015 (not (get 'org-agenda-files 'org-restrict)))
2016 "--")
2017 (mapcar 'org-file-menu-entry (org-agenda-files))))
2018 (org-agenda-set-mode-name)
2019 (apply
2020 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2021 (list 'org-agenda-mode-hook)))
2023 (substitute-key-definition 'undo 'org-agenda-undo
2024 org-agenda-mode-map global-map)
2025 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2026 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2027 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2028 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2029 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2030 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2031 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2032 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2033 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2034 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2035 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2036 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2037 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2038 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2039 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2040 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2041 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2042 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2043 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2044 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2045 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2046 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2047 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2048 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2049 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2050 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2051 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2052 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2053 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2054 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2055 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2056 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2057 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2058 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2059 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2060 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2061 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2062 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2063 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2064 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2065 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2066 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2067 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2068 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2069 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2071 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2072 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2073 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2074 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2075 (while l (org-defkey org-agenda-mode-map
2076 (int-to-string (pop l)) 'digit-argument)))
2078 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2079 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2080 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2081 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2082 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2083 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2084 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2085 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2086 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2087 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2088 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2089 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2090 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2091 'org-clock-modify-effort-estimate)
2092 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2093 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2094 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2095 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2096 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2097 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2098 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2099 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2100 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2101 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2102 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2103 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2104 (substitute-key-definition 'next-line 'org-agenda-next-line
2105 org-agenda-mode-map global-map)
2106 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2107 org-agenda-mode-map global-map)
2108 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2109 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2110 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2111 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2112 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2113 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2114 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2115 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2116 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2117 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2118 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2119 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2120 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2121 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2122 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2123 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2124 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2125 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2126 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2127 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2128 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2129 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2130 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2131 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2132 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2133 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2134 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2135 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2136 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2137 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2139 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2140 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2141 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2142 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2143 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2144 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2145 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2146 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2147 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2148 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2149 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2150 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2152 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2153 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2154 (when org-agenda-mouse-1-follows-link
2155 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2156 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2157 '("Agenda"
2158 ("Agenda Files")
2159 "--"
2160 ("Agenda Dates"
2161 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2162 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2163 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2164 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2165 "--"
2166 ("View"
2167 ["Day View" org-agenda-day-view
2168 :active (org-agenda-check-type nil 'agenda)
2169 :style radio :selected (eq org-agenda-current-span 'day)
2170 :keys "v d (or just d)"]
2171 ["Week View" org-agenda-week-view
2172 :active (org-agenda-check-type nil 'agenda)
2173 :style radio :selected (eq org-agenda-current-span 'week)
2174 :keys "v w (or just w)"]
2175 ["Month View" org-agenda-month-view
2176 :active (org-agenda-check-type nil 'agenda)
2177 :style radio :selected (eq org-agenda-current-span 'month)
2178 :keys "v m"]
2179 ["Year View" org-agenda-year-view
2180 :active (org-agenda-check-type nil 'agenda)
2181 :style radio :selected (eq org-agenda-current-span 'year)
2182 :keys "v y"]
2183 "--"
2184 ["Include Diary" org-agenda-toggle-diary
2185 :style toggle :selected org-agenda-include-diary
2186 :active (org-agenda-check-type nil 'agenda)]
2187 ["Include Deadlines" org-agenda-toggle-deadlines
2188 :style toggle :selected org-agenda-include-deadlines
2189 :active (org-agenda-check-type nil 'agenda)]
2190 ["Use Time Grid" org-agenda-toggle-time-grid
2191 :style toggle :selected org-agenda-use-time-grid
2192 :active (org-agenda-check-type nil 'agenda)]
2193 "--"
2194 ["Show clock report" org-agenda-clockreport-mode
2195 :style toggle :selected org-agenda-clockreport-mode
2196 :active (org-agenda-check-type nil 'agenda)]
2197 ["Show some entry text" org-agenda-entry-text-mode
2198 :style toggle :selected org-agenda-entry-text-mode
2199 :active t]
2200 "--"
2201 ["Show Logbook entries" org-agenda-log-mode
2202 :style toggle :selected org-agenda-show-log
2203 :active (org-agenda-check-type nil 'agenda 'timeline)
2204 :keys "v l (or just l)"]
2205 ["Include archived trees" org-agenda-archives-mode
2206 :style toggle :selected org-agenda-archives-mode :active t
2207 :keys "v a"]
2208 ["Include archive files" (org-agenda-archives-mode t)
2209 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2210 :keys "v A"]
2211 "--"
2212 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2213 ["Write view to file" org-agenda-write t]
2214 ["Rebuild buffer" org-agenda-redo t]
2215 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2216 "--"
2217 ["Show original entry" org-agenda-show t]
2218 ["Go To (other window)" org-agenda-goto t]
2219 ["Go To (this window)" org-agenda-switch-to t]
2220 ["Capture with cursor date" org-agenda-capture t]
2221 ["Follow Mode" org-agenda-follow-mode
2222 :style toggle :selected org-agenda-follow-mode :active t]
2223 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2224 "--"
2225 ("TODO"
2226 ["Cycle TODO" org-agenda-todo t]
2227 ["Next TODO set" org-agenda-todo-nextset t]
2228 ["Previous TODO set" org-agenda-todo-previousset t]
2229 ["Add note" org-agenda-add-note t])
2230 ("Archive/Refile/Delete"
2231 ["Archive default" org-agenda-archive-default t]
2232 ["Archive default" org-agenda-archive-default-with-confirmation t]
2233 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2234 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2235 ["Archive subtree" org-agenda-archive t]
2236 "--"
2237 ["Refile" org-agenda-refile t]
2238 "--"
2239 ["Delete subtree" org-agenda-kill t])
2240 ("Bulk action"
2241 ["Mark entry" org-agenda-bulk-mark t]
2242 ["Mark all" org-agenda-bulk-mark-all t]
2243 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2244 ["Unmark entry" org-agenda-bulk-unmark t]
2245 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2246 ["Act on all marked" org-agenda-bulk-action t]
2247 "--"
2248 ("Tags and Properties"
2249 ["Show all Tags" org-agenda-show-tags t]
2250 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2251 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2252 "--"
2253 ["Column View" org-columns t])
2254 ("Deadline/Schedule"
2255 ["Schedule" org-agenda-schedule t]
2256 ["Set Deadline" org-agenda-deadline t]
2257 "--"
2258 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2259 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2260 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2261 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2262 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2263 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2264 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2265 ("Clock and Effort"
2266 ["Clock in" org-agenda-clock-in t]
2267 ["Clock out" org-agenda-clock-out t]
2268 ["Clock cancel" org-agenda-clock-cancel t]
2269 ["Goto running clock" org-clock-goto t]
2270 "--"
2271 ["Set Effort" org-agenda-set-effort t]
2272 ["Change clocked effort" org-clock-modify-effort-estimate
2273 (org-clock-is-active)])
2274 ("Priority"
2275 ["Set Priority" org-agenda-priority t]
2276 ["Increase Priority" org-agenda-priority-up t]
2277 ["Decrease Priority" org-agenda-priority-down t]
2278 ["Show Priority" org-show-priority t])
2279 ("Calendar/Diary"
2280 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2281 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2282 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2283 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2284 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2285 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2286 "--"
2287 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2288 "--"
2289 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2290 "--"
2291 ("MobileOrg"
2292 ["Push Files and Views" org-mobile-push t]
2293 ["Get Captured and Flagged" org-mobile-pull t]
2294 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2295 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2296 "--"
2297 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2298 "--"
2299 ["Quit" org-agenda-quit t]
2300 ["Exit and Release Buffers" org-agenda-exit t]
2303 ;;; Agenda undo
2305 (defvar org-agenda-allow-remote-undo t
2306 "Non-nil means allow remote undo from the agenda buffer.")
2307 (defvar org-agenda-undo-has-started-in nil
2308 "Buffers that have already seen `undo-start' in the current undo sequence.")
2310 (defun org-agenda-undo ()
2311 "Undo a remote editing step in the agenda.
2312 This undoes changes both in the agenda buffer and in the remote buffer
2313 that have been changed along."
2314 (interactive)
2315 (or org-agenda-allow-remote-undo
2316 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2317 (if (not (eq this-command last-command))
2318 (setq org-agenda-undo-has-started-in nil
2319 org-agenda-pending-undo-list org-agenda-undo-list))
2320 (if (not org-agenda-pending-undo-list)
2321 (error "No further undo information"))
2322 (let* ((entry (pop org-agenda-pending-undo-list))
2323 buf line cmd rembuf)
2324 (setq cmd (pop entry) line (pop entry))
2325 (setq rembuf (nth 2 entry))
2326 (org-with-remote-undo rembuf
2327 (while (bufferp (setq buf (pop entry)))
2328 (if (pop entry)
2329 (with-current-buffer buf
2330 (let ((last-undo-buffer buf)
2331 (inhibit-read-only t))
2332 (unless (memq buf org-agenda-undo-has-started-in)
2333 (push buf org-agenda-undo-has-started-in)
2334 (make-local-variable 'pending-undo-list)
2335 (undo-start))
2336 (while (and pending-undo-list
2337 (listp pending-undo-list)
2338 (not (car pending-undo-list)))
2339 (pop pending-undo-list))
2340 (undo-more 1))))))
2341 (org-goto-line line)
2342 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2344 (defun org-verify-change-for-undo (l1 l2)
2345 "Verify that a real change occurred between the undo lists L1 and L2."
2346 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2347 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2348 (not (eq l1 l2)))
2350 ;;; Agenda dispatch
2352 (defvar org-agenda-restrict-begin (make-marker))
2353 (defvar org-agenda-restrict-end (make-marker))
2354 (defvar org-agenda-last-dispatch-buffer nil)
2355 (defvar org-agenda-overriding-restriction nil)
2357 (defcustom org-agenda-custom-commands-contexts nil
2358 "Alist of custom agenda keys and contextual rules.
2360 For example, if you have a custom agenda command \"p\" and you
2361 want this command to be accessible only from plain text files,
2362 use this:
2364 '((\"p\" (in-file . \"\\.txt\")))
2366 Here are the available contexts definitions:
2368 in-file: command displayed only in matching files
2369 in-mode: command displayed only in matching modes
2370 not-in-file: command not displayed in matching files
2371 not-in-mode: command not displayed in matching modes
2372 [function]: a custom function taking no argument
2374 If you define several checks, the agenda command will be
2375 accessible if there is at least one valid check.
2377 You can also bind a key to another agenda custom command
2378 depending on contextual rules.
2380 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2382 Here it means: in .txt files, use \"p\" as the key for the
2383 agenda command otherwise associated with \"q\". (The command
2384 originally associated with \"q\" is not displayed to avoid
2385 duplicates.)"
2386 :version "24.3"
2387 :group 'org-agenda-custom-commands
2388 :type '(repeat (list :tag "Rule"
2389 (string :tag " Agenda key")
2390 (string :tag "Replace by command")
2391 (repeat :tag "Available when"
2392 (choice
2393 (cons :tag "Condition"
2394 (choice
2395 (const :tag "In file" in-file)
2396 (const :tag "Not in file" not-in-file)
2397 (const :tag "In mode" in-mode)
2398 (const :tag "Not in mode" not-in-mode))
2399 (regexp))
2400 (function :tag "Custom function"))))))
2402 (defvar org-keys nil)
2403 (defvar org-match nil)
2404 ;;;###autoload
2405 (defun org-agenda (&optional arg org-keys restriction)
2406 "Dispatch agenda commands to collect entries to the agenda buffer.
2407 Prompts for a command to execute. Any prefix arg will be passed
2408 on to the selected command. The default selections are:
2410 a Call `org-agenda-list' to display the agenda for current day or week.
2411 t Call `org-todo-list' to display the global todo list.
2412 T Call `org-todo-list' to display the global todo list, select only
2413 entries with a specific TODO keyword (the user gets a prompt).
2414 m Call `org-tags-view' to display headlines with tags matching
2415 a condition (the user is prompted for the condition).
2416 M Like `m', but select only TODO entries, no ordinary headlines.
2417 L Create a timeline for the current buffer.
2418 e Export views to associated files.
2419 s Search entries for keywords.
2420 S Search entries for keywords, only with TODO keywords.
2421 / Multi occur across all agenda files and also files listed
2422 in `org-agenda-text-search-extra-files'.
2423 < Restrict agenda commands to buffer, subtree, or region.
2424 Press several times to get the desired effect.
2425 > Remove a previous restriction.
2426 # List \"stuck\" projects.
2427 ! Configure what \"stuck\" means.
2428 C Configure custom agenda commands.
2430 More commands can be added by configuring the variable
2431 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2432 searches can be pre-defined in this way.
2434 If the current buffer is in Org-mode and visiting a file, you can also
2435 first press `<' once to indicate that the agenda should be temporarily
2436 \(until the next use of \\[org-agenda]) restricted to the current file.
2437 Pressing `<' twice means to restrict to the current subtree or region
2438 \(if active)."
2439 (interactive "P")
2440 (catch 'exit
2441 (let* ((prefix-descriptions nil)
2442 (org-agenda-buffer-name org-agenda-buffer-name)
2443 (org-agenda-window-setup (if (equal (buffer-name)
2444 org-agenda-buffer-name)
2445 'current-window
2446 org-agenda-window-setup))
2447 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2448 (org-agenda-custom-commands
2449 ;; normalize different versions
2450 (delq nil
2451 (mapcar
2452 (lambda (x)
2453 (cond ((stringp (cdr x))
2454 (push x prefix-descriptions)
2455 nil)
2456 ((stringp (nth 1 x)) x)
2457 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2458 (t (cons (car x) (cons "" (cdr x))))))
2459 org-agenda-custom-commands)))
2460 (org-agenda-custom-commands
2461 (org-contextualize-keys
2462 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2463 (buf (current-buffer))
2464 (bfn (buffer-file-name (buffer-base-buffer)))
2465 entry key type org-match lprops ans)
2466 ;; Turn off restriction unless there is an overriding one,
2467 (unless org-agenda-overriding-restriction
2468 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2469 ;; There is a request to keep the file list in place
2470 (put 'org-agenda-files 'org-restrict nil))
2471 (setq org-agenda-restrict nil)
2472 (move-marker org-agenda-restrict-begin nil)
2473 (move-marker org-agenda-restrict-end nil))
2474 ;; Delete old local properties
2475 (put 'org-agenda-redo-command 'org-lprops nil)
2476 ;; Delete previously set last-arguments
2477 (put 'org-agenda-redo-command 'last-args nil)
2478 ;; Remember where this call originated
2479 (setq org-agenda-last-dispatch-buffer (current-buffer))
2480 (unless org-keys
2481 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2482 org-keys (car ans)
2483 restriction (cdr ans)))
2484 ;; If we have sticky agenda buffers, set a name for the buffer,
2485 ;; depending on the invoking keys. The user may still set this
2486 ;; as a command option, which will overwrite what we do here.
2487 (if org-agenda-sticky
2488 (setq org-agenda-buffer-name
2489 (format "*Org Agenda(%s)*" org-keys)))
2490 ;; Establish the restriction, if any
2491 (when (and (not org-agenda-overriding-restriction) restriction)
2492 (put 'org-agenda-files 'org-restrict (list bfn))
2493 (cond
2494 ((eq restriction 'region)
2495 (setq org-agenda-restrict t)
2496 (move-marker org-agenda-restrict-begin (region-beginning))
2497 (move-marker org-agenda-restrict-end (region-end)))
2498 ((eq restriction 'subtree)
2499 (save-excursion
2500 (setq org-agenda-restrict t)
2501 (org-back-to-heading t)
2502 (move-marker org-agenda-restrict-begin (point))
2503 (move-marker org-agenda-restrict-end
2504 (progn (org-end-of-subtree t)))))))
2506 ;; For example the todo list should not need it (but does...)
2507 (cond
2508 ((setq entry (assoc org-keys org-agenda-custom-commands))
2509 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2510 (progn
2511 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2512 lprops (nth 4 entry))
2513 (if org-agenda-sticky
2514 (setq org-agenda-buffer-name
2515 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2516 (format "*Org Agenda(%s)*" org-keys))))
2517 (put 'org-agenda-redo-command 'org-lprops lprops)
2518 (cond
2519 ((eq type 'agenda)
2520 (org-let lprops '(org-agenda-list current-prefix-arg)))
2521 ((eq type 'alltodo)
2522 (org-let lprops '(org-todo-list current-prefix-arg)))
2523 ((eq type 'search)
2524 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2525 ((eq type 'stuck)
2526 (org-let lprops '(org-agenda-list-stuck-projects
2527 current-prefix-arg)))
2528 ((eq type 'tags)
2529 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2530 ((eq type 'tags-todo)
2531 (org-let lprops '(org-tags-view '(4) org-match)))
2532 ((eq type 'todo)
2533 (org-let lprops '(org-todo-list org-match)))
2534 ((eq type 'tags-tree)
2535 (org-check-for-org-mode)
2536 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2537 ((eq type 'todo-tree)
2538 (org-check-for-org-mode)
2539 (org-let lprops
2540 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2541 (regexp-quote org-match) "\\>"))))
2542 ((eq type 'occur-tree)
2543 (org-check-for-org-mode)
2544 (org-let lprops '(org-occur org-match)))
2545 ((functionp type)
2546 (org-let lprops '(funcall type org-match)))
2547 ((fboundp type)
2548 (org-let lprops '(funcall type org-match)))
2549 (t (error "Invalid custom agenda command type %s" type))))
2550 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2551 ((equal org-keys "C")
2552 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2553 (customize-variable 'org-agenda-custom-commands))
2554 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2555 ((equal org-keys "s") (call-interactively 'org-search-view))
2556 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2557 ((equal org-keys "t") (call-interactively 'org-todo-list))
2558 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2559 ((equal org-keys "m") (call-interactively 'org-tags-view))
2560 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2561 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2562 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2563 (org-add-hook
2564 'post-command-hook
2565 (lambda ()
2566 (unless (current-message)
2567 (let* ((m (org-agenda-get-any-marker))
2568 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2569 (when note
2570 (message (concat
2571 "FLAGGING-NOTE ([?] for more info): "
2572 (org-add-props
2573 (replace-regexp-in-string
2574 "\\\\n" "//"
2575 (copy-sequence note))
2576 nil 'face 'org-warning)))))))
2577 t t))
2578 ((equal org-keys "L")
2579 (unless (derived-mode-p 'org-mode)
2580 (error "This is not an Org-mode file"))
2581 (unless restriction
2582 (put 'org-agenda-files 'org-restrict (list bfn))
2583 (org-call-with-arg 'org-timeline arg)))
2584 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2585 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2586 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2587 (t (error "Invalid agenda key"))))))
2589 (autoload 'org-agenda "org-agenda" "\
2590 Dispatch agenda commands to collect entries to the agenda buffer.
2591 Prompts for a command to execute. Any prefix arg will be passed
2592 on to the selected command. The default selections are:
2594 a Call `org-agenda-list' to display the agenda for current day or week.
2595 t Call `org-todo-list' to display the global todo list.
2596 T Call `org-todo-list' to display the global todo list, select only
2597 entries with a specific TODO keyword (the user gets a prompt).
2598 m Call `org-tags-view' to display headlines with tags matching
2599 a condition (the user is prompted for the condition).
2600 M Like `m', but select only TODO entries, no ordinary headlines.
2601 L Create a timeline for the current buffer.
2602 e Export views to associated files.
2603 s Search entries for keywords.
2604 S Search entries for keywords, only with TODO keywords.
2605 / Multi occur across all agenda files and also files listed
2606 in `org-agenda-text-search-extra-files'.
2607 < Restrict agenda commands to buffer, subtree, or region.
2608 Press several times to get the desired effect.
2609 > Remove a previous restriction.
2610 # List \"stuck\" projects.
2611 ! Configure what \"stuck\" means.
2612 C Configure custom agenda commands.
2614 More commands can be added by configuring the variable
2615 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2616 searches can be pre-defined in this way.
2618 If the current buffer is in Org-mode and visiting a file, you can also
2619 first press `<' once to indicate that the agenda should be temporarily
2620 \(until the next use of \\[org-agenda]) restricted to the current file.
2621 Pressing `<' twice means to restrict to the current subtree or region
2622 \(if active).
2624 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2626 (defun org-agenda-append-agenda ()
2627 "Append another agenda view to the current one.
2628 This function allows interactive building of block agendas.
2629 Agenda views are separated by `org-agenda-block-separator'."
2630 (interactive)
2631 (unless (derived-mode-p 'org-agenda-mode)
2632 (error "Can only append from within agenda buffer"))
2633 (let ((org-agenda-multi t))
2634 (org-agenda)
2635 (widen)
2636 (org-agenda-finalize)
2637 (org-agenda-fit-window-to-buffer)))
2639 (defun org-agenda-normalize-custom-commands (cmds)
2640 (delq nil
2641 (mapcar
2642 (lambda (x)
2643 (cond ((stringp (cdr x)) nil)
2644 ((stringp (nth 1 x)) x)
2645 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2646 (t (cons (car x) (cons "" (cdr x))))))
2647 cmds)))
2649 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2650 "The user interface for selecting an agenda command."
2651 (catch 'exit
2652 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2653 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2654 (region-p (org-region-active-p))
2655 (custom org-agenda-custom-commands)
2656 (selstring "")
2657 restriction second-time
2658 c entry key type match prefixes rmheader header-end custom1 desc
2659 line lines left right n n1)
2660 (save-window-excursion
2661 (delete-other-windows)
2662 (org-switch-to-buffer-other-window " *Agenda Commands*")
2663 (erase-buffer)
2664 (insert (eval-when-compile
2665 (let ((header
2666 "Press key for an agenda command: < Buffer, subtree/region restriction
2667 -------------------------------- > Remove restriction
2668 a Agenda for current week or day e Export agenda views
2669 t List of all TODO entries T Entries with special TODO kwd
2670 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2671 s Search for keywords S Like s, but only TODO entries
2672 L Timeline for current buffer # List stuck projects (!=configure)
2673 / Multi-occur C Configure custom agenda commands
2674 ? Find :FLAGGED: entries * Toggle sticky agenda views
2676 (start 0))
2677 (while (string-match
2678 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2679 header start)
2680 (setq start (match-end 0))
2681 (add-text-properties (match-beginning 2) (match-end 2)
2682 '(face bold) header))
2683 header)))
2684 (setq header-end (move-marker (make-marker) (point)))
2685 (while t
2686 (setq custom1 custom)
2687 (when (eq rmheader t)
2688 (org-goto-line 1)
2689 (re-search-forward ":" nil t)
2690 (delete-region (match-end 0) (point-at-eol))
2691 (forward-char 1)
2692 (looking-at "-+")
2693 (delete-region (match-end 0) (point-at-eol))
2694 (move-marker header-end (match-end 0)))
2695 (goto-char header-end)
2696 (delete-region (point) (point-max))
2698 ;; Produce all the lines that describe custom commands and prefixes
2699 (setq lines nil)
2700 (while (setq entry (pop custom1))
2701 (setq key (car entry) desc (nth 1 entry)
2702 type (nth 2 entry)
2703 match (nth 3 entry))
2704 (if (> (length key) 1)
2705 (add-to-list 'prefixes (string-to-char key))
2706 (setq line
2707 (format
2708 "%-4s%-14s"
2709 (org-add-props (copy-sequence key)
2710 '(face bold))
2711 (cond
2712 ((string-match "\\S-" desc) desc)
2713 ((eq type 'agenda) "Agenda for current week or day")
2714 ((eq type 'alltodo) "List of all TODO entries")
2715 ((eq type 'search) "Word search")
2716 ((eq type 'stuck) "List of stuck projects")
2717 ((eq type 'todo) "TODO keyword")
2718 ((eq type 'tags) "Tags query")
2719 ((eq type 'tags-todo) "Tags (TODO)")
2720 ((eq type 'tags-tree) "Tags tree")
2721 ((eq type 'todo-tree) "TODO kwd tree")
2722 ((eq type 'occur-tree) "Occur tree")
2723 ((functionp type) (if (symbolp type)
2724 (symbol-name type)
2725 "Lambda expression"))
2726 (t "???"))))
2727 (if org-agenda-menu-show-matcher
2728 (setq line
2729 (concat line ": "
2730 (cond
2731 ((stringp match)
2732 (setq match (copy-sequence match))
2733 (org-add-props match nil 'face 'org-warning))
2734 ((listp type)
2735 (format "set of %d commands" (length type))))))
2736 (if (org-string-nw-p match)
2737 (add-text-properties
2738 0 (length line) (list 'help-echo
2739 (concat "Matcher: " match)) line)))
2740 (push line lines)))
2741 (setq lines (nreverse lines))
2742 (when prefixes
2743 (mapc (lambda (x)
2744 (push
2745 (format "%s %s"
2746 (org-add-props (char-to-string x)
2747 nil 'face 'bold)
2748 (or (cdr (assoc (concat selstring
2749 (char-to-string x))
2750 prefix-descriptions))
2751 "Prefix key"))
2752 lines))
2753 prefixes))
2755 ;; Check if we should display in two columns
2756 (if org-agenda-menu-two-columns
2757 (progn
2758 (setq n (length lines)
2759 n1 (+ (/ n 2) (mod n 2))
2760 right (nthcdr n1 lines)
2761 left (copy-sequence lines))
2762 (setcdr (nthcdr (1- n1) left) nil))
2763 (setq left lines right nil))
2764 (while left
2765 (insert "\n" (pop left))
2766 (when right
2767 (if (< (current-column) 40)
2768 (move-to-column 40 t)
2769 (insert " "))
2770 (insert (pop right))))
2772 ;; Make the window the right size
2773 (goto-char (point-min))
2774 (if second-time
2775 (if (not (pos-visible-in-window-p (point-max)))
2776 (org-fit-window-to-buffer))
2777 (setq second-time t)
2778 (org-fit-window-to-buffer))
2780 ;; Ask for selection
2781 (message "Press key for agenda command%s:"
2782 (if (or restrict-ok org-agenda-overriding-restriction)
2783 (if org-agenda-overriding-restriction
2784 " (restriction lock active)"
2785 (if restriction
2786 (format " (restricted to %s)" restriction)
2787 " (unrestricted)"))
2788 ""))
2789 (setq c (read-char-exclusive))
2790 (message "")
2791 (cond
2792 ((assoc (char-to-string c) custom)
2793 (setq selstring (concat selstring (char-to-string c)))
2794 (throw 'exit (cons selstring restriction)))
2795 ((memq c prefixes)
2796 (setq selstring (concat selstring (char-to-string c))
2797 prefixes nil
2798 rmheader (or rmheader t)
2799 custom (delq nil (mapcar
2800 (lambda (x)
2801 (if (or (= (length (car x)) 1)
2802 (/= (string-to-char (car x)) c))
2804 (cons (substring (car x) 1) (cdr x))))
2805 custom))))
2806 ((eq c ?*)
2807 (call-interactively 'org-toggle-sticky-agenda)
2808 (sit-for 2))
2809 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2810 (message "Restriction is only possible in Org-mode buffers")
2811 (ding) (sit-for 1))
2812 ((eq c ?1)
2813 (org-agenda-remove-restriction-lock 'noupdate)
2814 (setq restriction 'buffer))
2815 ((eq c ?0)
2816 (org-agenda-remove-restriction-lock 'noupdate)
2817 (setq restriction (if region-p 'region 'subtree)))
2818 ((eq c ?<)
2819 (org-agenda-remove-restriction-lock 'noupdate)
2820 (setq restriction
2821 (cond
2822 ((eq restriction 'buffer)
2823 (if region-p 'region 'subtree))
2824 ((memq restriction '(subtree region))
2825 nil)
2826 (t 'buffer))))
2827 ((eq c ?>)
2828 (org-agenda-remove-restriction-lock 'noupdate)
2829 (setq restriction nil))
2830 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2831 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2832 ((and (> (length selstring) 0) (eq c ?\d))
2833 (delete-window)
2834 (org-agenda-get-restriction-and-command prefix-descriptions))
2836 ((equal c ?q) (error "Abort"))
2837 (t (error "Invalid key %c" c))))))))
2839 (defun org-agenda-fit-window-to-buffer ()
2840 "Fit the window to the buffer size."
2841 (and (memq org-agenda-window-setup '(reorganize-frame))
2842 (fboundp 'fit-window-to-buffer)
2843 (org-fit-window-to-buffer
2845 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2846 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2848 (defvar org-cmd nil)
2849 (defvar org-agenda-overriding-cmd nil)
2850 (defvar org-agenda-overriding-arguments nil)
2851 (defvar org-agenda-overriding-cmd-arguments nil)
2852 (defun org-agenda-run-series (name series)
2853 (org-let (nth 1 series) '(org-agenda-prepare name))
2854 ;; We need to reset agenda markers here, because when constructing a
2855 ;; block agenda, the individual blocks do not do that.
2856 (org-agenda-reset-markers)
2857 (let* ((org-agenda-multi t)
2858 (redo (list 'org-agenda-run-series name (list 'quote series)))
2859 (cmds (car series))
2860 (gprops (nth 1 series))
2861 match ;; The byte compiler incorrectly complains about this. Keep it!
2862 org-cmd type lprops)
2863 (while (setq org-cmd (pop cmds))
2864 (setq type (car org-cmd)
2865 match (eval (nth 1 org-cmd))
2866 lprops (nth 2 org-cmd))
2867 (let ((org-agenda-overriding-arguments
2868 (if (eq org-agenda-overriding-cmd org-cmd)
2869 (or org-agenda-overriding-arguments
2870 org-agenda-overriding-cmd-arguments))))
2871 (cond
2872 ((eq type 'agenda)
2873 (org-let2 gprops lprops
2874 '(call-interactively 'org-agenda-list)))
2875 ((eq type 'alltodo)
2876 (org-let2 gprops lprops
2877 '(call-interactively 'org-todo-list)))
2878 ((eq type 'search)
2879 (org-let2 gprops lprops
2880 '(org-search-view current-prefix-arg match nil)))
2881 ((eq type 'stuck)
2882 (org-let2 gprops lprops
2883 '(call-interactively 'org-agenda-list-stuck-projects)))
2884 ((eq type 'tags)
2885 (org-let2 gprops lprops
2886 '(org-tags-view current-prefix-arg match)))
2887 ((eq type 'tags-todo)
2888 (org-let2 gprops lprops
2889 '(org-tags-view '(4) match)))
2890 ((eq type 'todo)
2891 (org-let2 gprops lprops
2892 '(org-todo-list match)))
2893 ((fboundp type)
2894 (org-let2 gprops lprops
2895 '(funcall type match)))
2896 (t (error "Invalid type in command series")))))
2897 (widen)
2898 (let ((inhibit-read-only t))
2899 (add-text-properties (point-min) (point-max)
2900 `(org-series t org-series-redo-cmd ,redo)))
2901 (setq org-agenda-redo-command redo)
2902 (goto-char (point-min)))
2903 (org-agenda-fit-window-to-buffer)
2904 (org-let (nth 1 series) '(org-agenda-finalize)))
2906 ;;;###autoload
2907 (defmacro org-batch-agenda (cmd-key &rest parameters)
2908 "Run an agenda command in batch mode and send the result to STDOUT.
2909 If CMD-KEY is a string of length 1, it is used as a key in
2910 `org-agenda-custom-commands' and triggers this command. If it is a
2911 longer string it is used as a tags/todo match string.
2912 Parameters are alternating variable names and values that will be bound
2913 before running the agenda command."
2914 (org-eval-in-environment (org-make-parameter-alist parameters)
2915 (if (> (length cmd-key) 2)
2916 (org-tags-view nil cmd-key)
2917 (org-agenda nil cmd-key)))
2918 (set-buffer org-agenda-buffer-name)
2919 (princ (buffer-string)))
2921 (autoload 'org-batch-agenda "org-agenda" "\
2922 Run an agenda command in batch mode and send the result to STDOUT.
2923 If CMD-KEY is a string of length 1, it is used as a key in
2924 `org-agenda-custom-commands' and triggers this command. If it is a
2925 longer string it is used as a tags/todo match string.
2926 Parameters are alternating variable names and values that will be bound
2927 before running the agenda command.
2929 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2930 (def-edebug-spec org-batch-agenda (form &rest sexp))
2932 (defvar org-agenda-info nil)
2934 ;;;###autoload
2935 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2936 "Run an agenda command in batch mode and send the result to STDOUT.
2937 If CMD-KEY is a string of length 1, it is used as a key in
2938 `org-agenda-custom-commands' and triggers this command. If it is a
2939 longer string it is used as a tags/todo match string.
2940 Parameters are alternating variable names and values that will be bound
2941 before running the agenda command.
2943 The output gives a line for each selected agenda item. Each
2944 item is a list of comma-separated values, like this:
2946 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2948 category The category of the item
2949 head The headline, without TODO kwd, TAGS and PRIORITY
2950 type The type of the agenda entry, can be
2951 todo selected in TODO match
2952 tagsmatch selected in tags match
2953 diary imported from diary
2954 deadline a deadline on given date
2955 scheduled scheduled on given date
2956 timestamp entry has timestamp on given date
2957 closed entry was closed on given date
2958 upcoming-deadline warning about deadline
2959 past-scheduled forwarded scheduled item
2960 block entry has date block including g. date
2961 todo The todo keyword, if any
2962 tags All tags including inherited ones, separated by colons
2963 date The relevant date, like 2007-2-14
2964 time The time, like 15:00-16:50
2965 extra Sting with extra planning info
2966 priority-l The priority letter if any was given
2967 priority-n The computed numerical priority
2968 agenda-day The day in the agenda where this is listed"
2969 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2970 (org-make-parameter-alist parameters))
2971 (if (> (length cmd-key) 2)
2972 (org-tags-view nil cmd-key)
2973 (org-agenda nil cmd-key)))
2974 (set-buffer org-agenda-buffer-name)
2975 (let* ((lines (org-split-string (buffer-string) "\n"))
2976 line)
2977 (while (setq line (pop lines))
2978 (catch 'next
2979 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2980 (setq org-agenda-info
2981 (org-fix-agenda-info (text-properties-at 0 line)))
2982 (princ
2983 (mapconcat 'org-agenda-export-csv-mapper
2984 '(org-category txt type todo tags date time extra
2985 priority-letter priority agenda-day)
2986 ","))
2987 (princ "\n")))))
2989 (autoload 'org-batch-agenda-csv "org-agenda" "\
2990 Run an agenda command in batch mode and send the result to STDOUT.
2991 If CMD-KEY is a string of length 1, it is used as a key in
2992 `org-agenda-custom-commands' and triggers this command. If it is a
2993 longer string it is used as a tags/todo match string.
2994 Parameters are alternating variable names and values that will be bound
2995 before running the agenda command.
2997 The output gives a line for each selected agenda item. Each
2998 item is a list of comma-separated values, like this:
3000 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3002 category The category of the item
3003 head The headline, without TODO kwd, TAGS and PRIORITY
3004 type The type of the agenda entry, can be
3005 todo selected in TODO match
3006 tagsmatch selected in tags match
3007 diary imported from diary
3008 deadline a deadline on given date
3009 scheduled scheduled on given date
3010 timestamp entry has timestamp on given date
3011 closed entry was closed on given date
3012 upcoming-deadline warning about deadline
3013 past-scheduled forwarded scheduled item
3014 block entry has date block including g. date
3015 todo The todo keyword, if any
3016 tags All tags including inherited ones, separated by colons
3017 date The relevant date, like 2007-2-14
3018 time The time, like 15:00-16:50
3019 extra Sting with extra planning info
3020 priority-l The priority letter if any was given
3021 priority-n The computed numerical priority
3022 agenda-day The day in the agenda where this is listed
3024 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3025 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3027 (defun org-fix-agenda-info (props)
3028 "Make sure all properties on an agenda item have a canonical form.
3029 This ensures the export commands can easily use it."
3030 (let (tmp re)
3031 (when (setq tmp (plist-get props 'tags))
3032 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3033 (when (setq tmp (plist-get props 'date))
3034 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3035 (let ((calendar-date-display-form '(year "-" month "-" day)))
3036 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3038 (setq tmp (calendar-date-string tmp)))
3039 (setq props (plist-put props 'date tmp)))
3040 (when (setq tmp (plist-get props 'day))
3041 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3042 (let ((calendar-date-display-form '(year "-" month "-" day)))
3043 (setq tmp (calendar-date-string tmp)))
3044 (setq props (plist-put props 'day tmp))
3045 (setq props (plist-put props 'agenda-day tmp)))
3046 (when (setq tmp (plist-get props 'txt))
3047 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3048 (plist-put props 'priority-letter (match-string 1 tmp))
3049 (setq tmp (replace-match "" t t tmp)))
3050 (when (and (setq re (plist-get props 'org-todo-regexp))
3051 (setq re (concat "\\`\\.*" re " ?"))
3052 (string-match re tmp))
3053 (plist-put props 'todo (match-string 1 tmp))
3054 (setq tmp (replace-match "" t t tmp)))
3055 (plist-put props 'txt tmp)))
3056 props)
3058 (defun org-agenda-export-csv-mapper (prop)
3059 (let ((res (plist-get org-agenda-info prop)))
3060 (setq res
3061 (cond
3062 ((not res) "")
3063 ((stringp res) res)
3064 (t (prin1-to-string res))))
3065 (while (string-match "," res)
3066 (setq res (replace-match ";" t t res)))
3067 (org-trim res)))
3069 ;;;###autoload
3070 (defun org-store-agenda-views (&rest parameters)
3071 (interactive)
3072 (eval (list 'org-batch-store-agenda-views)))
3074 (autoload 'org-store-agenda-views "org-agenda" "\
3077 \(fn &rest PARAMETERS)" t nil)
3079 ;;;###autoload
3080 (defmacro org-batch-store-agenda-views (&rest parameters)
3081 "Run all custom agenda commands that have a file argument."
3082 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3083 (pop-up-frames nil)
3084 (dir default-directory)
3085 (pars (org-make-parameter-alist parameters))
3086 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3087 (save-window-excursion
3088 (while cmds
3089 (setq cmd (pop cmds)
3090 thiscmdkey (car cmd)
3091 thiscmdcmd (cdr cmd)
3092 match (nth 2 thiscmdcmd)
3093 bufname (if org-agenda-sticky
3094 (or (and (stringp match)
3095 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3096 (format "*Org Agenda(%s)*" thiscmdkey))
3097 org-agenda-buffer-name)
3098 cmd-or-set (nth 2 cmd)
3099 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3100 files (nth (if (listp cmd-or-set) 4 5) cmd))
3101 (if (stringp files) (setq files (list files)))
3102 (when files
3103 (org-eval-in-environment (append org-agenda-exporter-settings
3104 opts pars)
3105 (org-agenda nil thiscmdkey))
3106 (set-buffer bufname)
3107 (while files
3108 (org-eval-in-environment (append org-agenda-exporter-settings
3109 opts pars)
3110 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3111 (and (get-buffer bufname)
3112 (kill-buffer bufname)))))))
3114 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3115 Run all custom agenda commands that have a file argument.
3117 \(fn &rest PARAMETERS)" nil t)
3118 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3120 (defvar org-agenda-current-span nil
3121 "The current span used in the agenda view.") ; local variable in the agenda buffer
3122 (defun org-agenda-mark-header-line (pos)
3123 "Mark the line at POS as an agenda structure header."
3124 (save-excursion
3125 (goto-char pos)
3126 (put-text-property (point-at-bol) (point-at-eol)
3127 'org-agenda-structural-header t)
3128 (when org-agenda-title-append
3129 (put-text-property (point-at-bol) (point-at-eol)
3130 'org-agenda-title-append org-agenda-title-append))))
3132 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3133 (defvar org-agenda-write-buffer-name "Agenda View")
3134 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3135 "Write the current buffer (an agenda view) as a file.
3136 Depending on the extension of the file name, plain text (.txt),
3137 HTML (.html or .htm) or Postscript (.ps) is produced.
3138 If the extension is .ics, run icalendar export over all files used
3139 to construct the agenda and limit the export to entries listed in the
3140 agenda now.
3141 With prefix argument OPEN, open the new file immediately.
3142 If NOSETTINGS is given, do not scope the settings of
3143 `org-agenda-exporter-settings' into the export commands. This is used when
3144 the settings have already been scoped and we do not wish to overrule other,
3145 higher priority settings.
3146 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3147 (interactive "FWrite agenda to file: \nP")
3148 (if (not (file-writable-p file))
3149 (error "Cannot write agenda to file %s" file))
3150 (org-let (if nosettings nil org-agenda-exporter-settings)
3151 '(save-excursion
3152 (save-window-excursion
3153 (org-agenda-mark-filtered-text)
3154 (let ((bs (copy-sequence (buffer-string))) beg)
3155 (org-agenda-unmark-filtered-text)
3156 (with-temp-buffer
3157 (rename-buffer org-agenda-write-buffer-name t)
3158 (set-buffer-modified-p nil)
3159 (insert bs)
3160 (org-agenda-remove-marked-text 'org-filtered)
3161 (while (setq beg (text-property-any (point-min) (point-max)
3162 'org-filtered t))
3163 (delete-region
3164 beg (or (next-single-property-change beg 'org-filtered)
3165 (point-max))))
3166 (run-hooks 'org-agenda-before-write-hook)
3167 (cond
3168 ((org-bound-and-true-p org-mobile-creating-agendas)
3169 (org-mobile-write-agenda-for-mobile file))
3170 ((string-match "\\.html?\\'" file)
3171 (require 'htmlize)
3172 (set-buffer (htmlize-buffer (current-buffer)))
3173 (when org-agenda-export-html-style
3174 ;; replace <style> section with org-agenda-export-html-style
3175 (goto-char (point-min))
3176 (kill-region (- (search-forward "<style") 6)
3177 (search-forward "</style>"))
3178 (insert org-agenda-export-html-style))
3179 (write-file file)
3180 (kill-buffer (current-buffer))
3181 (message "HTML written to %s" file))
3182 ((string-match "\\.ps\\'" file)
3183 (require 'ps-print)
3184 (ps-print-buffer-with-faces file)
3185 (message "Postscript written to %s" file))
3186 ((string-match "\\.pdf\\'" file)
3187 (require 'ps-print)
3188 (ps-print-buffer-with-faces
3189 (concat (file-name-sans-extension file) ".ps"))
3190 (call-process "ps2pdf" nil nil nil
3191 (expand-file-name
3192 (concat (file-name-sans-extension file) ".ps"))
3193 (expand-file-name file))
3194 (delete-file (concat (file-name-sans-extension file) ".ps"))
3195 (message "PDF written to %s" file))
3196 ((string-match "\\.ics\\'" file)
3197 (require 'org-icalendar)
3198 (let ((org-agenda-marker-table
3199 (org-create-marker-find-array
3200 (org-agenda-collect-markers)))
3201 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3202 (org-combined-agenda-icalendar-file file))
3203 (apply 'org-export-icalendar 'combine
3204 (org-agenda-files nil 'ifmode))))
3206 (let ((bs (buffer-string)))
3207 (find-file file)
3208 (erase-buffer)
3209 (insert bs)
3210 (save-buffer 0)
3211 (kill-buffer (current-buffer))
3212 (message "Plain text written to %s" file))))))))
3213 (set-buffer (or agenda-bufname
3214 (and (called-interactively-p 'any) (buffer-name))
3215 org-agenda-buffer-name)))
3216 (when open (org-open-file file)))
3218 (defvar org-agenda-tag-filter-overlays nil)
3219 (defvar org-agenda-cat-filter-overlays nil)
3221 (defun org-agenda-mark-filtered-text ()
3222 "Mark all text hidden by filtering with a text property."
3223 (let ((inhibit-read-only t))
3224 (mapc
3225 (lambda (o)
3226 (when (equal (overlay-buffer o) (current-buffer))
3227 (put-text-property
3228 (overlay-start o) (overlay-end o)
3229 'org-filtered t)))
3230 (append org-agenda-tag-filter-overlays
3231 org-agenda-cat-filter-overlays))))
3233 (defun org-agenda-unmark-filtered-text ()
3234 "Remove the filtering text property."
3235 (let ((inhibit-read-only t))
3236 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3238 (defun org-agenda-remove-marked-text (property &optional value)
3239 "Delete all text marked with VALUE of PROPERTY.
3240 VALUE defaults to t."
3241 (let (beg)
3242 (setq value (or value t))
3243 (while (setq beg (text-property-any (point-min) (point-max)
3244 property value))
3245 (delete-region
3246 beg (or (next-single-property-change beg 'org-filtered)
3247 (point-max))))))
3249 (defun org-agenda-add-entry-text ()
3250 "Add entry text to agenda lines.
3251 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3252 entry text following headings shown in the agenda.
3253 Drawers will be excluded, also the line with scheduling/deadline info."
3254 (when (and (> org-agenda-add-entry-text-maxlines 0)
3255 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3256 (let (m txt)
3257 (goto-char (point-min))
3258 (while (not (eobp))
3259 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3260 (beginning-of-line 2)
3261 (setq txt (org-agenda-get-some-entry-text
3262 m org-agenda-add-entry-text-maxlines " > "))
3263 (end-of-line 1)
3264 (if (string-match "\\S-" txt)
3265 (insert "\n" txt)
3266 (or (eobp) (forward-char 1))))))))
3268 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3269 &rest keep)
3270 "Extract entry text from MARKER, at most N-LINES lines.
3271 This will ignore drawers etc, just get the text.
3272 If INDENT is given, prefix every line with this string. If KEEP is
3273 given, it is a list of symbols, defining stuff that should not be
3274 removed from the entry content. Currently only `planning' is allowed here."
3275 (let (txt drawer-re kwd-time-re ind)
3276 (save-excursion
3277 (with-current-buffer (marker-buffer marker)
3278 (if (not (derived-mode-p 'org-mode))
3279 (setq txt "")
3280 (save-excursion
3281 (save-restriction
3282 (widen)
3283 (goto-char marker)
3284 (end-of-line 1)
3285 (setq txt (buffer-substring
3286 (min (1+ (point)) (point-max))
3287 (progn (outline-next-heading) (point)))
3288 drawer-re org-drawer-regexp
3289 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3290 ".*\n?"))
3291 (with-temp-buffer
3292 (insert txt)
3293 (when org-agenda-add-entry-text-descriptive-links
3294 (goto-char (point-min))
3295 (while (org-activate-bracket-links (point-max))
3296 (add-text-properties (match-beginning 0) (match-end 0)
3297 '(face org-link))))
3298 (goto-char (point-min))
3299 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3300 (set-text-properties (match-beginning 0) (match-end 0)
3301 nil))
3302 (goto-char (point-min))
3303 (while (re-search-forward drawer-re nil t)
3304 (delete-region
3305 (match-beginning 0)
3306 (progn (re-search-forward
3307 "^[ \t]*:END:.*\n?" nil 'move)
3308 (point))))
3309 (unless (member 'planning keep)
3310 (goto-char (point-min))
3311 (while (re-search-forward kwd-time-re nil t)
3312 (replace-match "")))
3313 (goto-char (point-min))
3314 (when org-agenda-entry-text-exclude-regexps
3315 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3316 (while (setq re (pop re-list))
3317 (goto-char (point-min))
3318 (while (re-search-forward re nil t)
3319 (replace-match "")))))
3320 (goto-char (point-max))
3321 (skip-chars-backward " \t\n")
3322 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3324 ;; find and remove min common indentation
3325 (goto-char (point-min))
3326 (untabify (point-min) (point-max))
3327 (setq ind (org-get-indentation))
3328 (while (not (eobp))
3329 (unless (looking-at "[ \t]*$")
3330 (setq ind (min ind (org-get-indentation))))
3331 (beginning-of-line 2))
3332 (goto-char (point-min))
3333 (while (not (eobp))
3334 (unless (looking-at "[ \t]*$")
3335 (move-to-column ind)
3336 (delete-region (point-at-bol) (point)))
3337 (beginning-of-line 2))
3339 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3341 (goto-char (point-min))
3342 (when indent
3343 (while (and (not (eobp)) (re-search-forward "^" nil t))
3344 (replace-match indent t t)))
3345 (goto-char (point-min))
3346 (while (looking-at "[ \t]*\n") (replace-match ""))
3347 (goto-char (point-max))
3348 (when (> (org-current-line)
3349 n-lines)
3350 (org-goto-line (1+ n-lines))
3351 (backward-char 1))
3352 (setq txt (buffer-substring (point-min) (point)))))))))
3353 txt))
3355 (defun org-agenda-collect-markers ()
3356 "Collect the markers pointing to entries in the agenda buffer."
3357 (let (m markers)
3358 (save-excursion
3359 (goto-char (point-min))
3360 (while (not (eobp))
3361 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3362 (org-get-at-bol 'org-marker)))
3363 (push m markers))
3364 (beginning-of-line 2)))
3365 (nreverse markers)))
3367 (defun org-create-marker-find-array (marker-list)
3368 "Create a alist of files names with all marker positions in that file."
3369 (let (f tbl m a p)
3370 (while (setq m (pop marker-list))
3371 (setq p (marker-position m)
3372 f (buffer-file-name (or (buffer-base-buffer
3373 (marker-buffer m))
3374 (marker-buffer m))))
3375 (if (setq a (assoc f tbl))
3376 (push (marker-position m) (cdr a))
3377 (push (list f p) tbl)))
3378 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3379 tbl)))
3381 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3382 (defun org-check-agenda-marker-table ()
3383 "Check of the current entry is on the marker list."
3384 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3386 (and (setq a (assoc file org-agenda-marker-table))
3387 (save-match-data
3388 (save-excursion
3389 (org-back-to-heading t)
3390 (member (point) (cdr a)))))))
3392 (defun org-check-for-org-mode ()
3393 "Make sure current buffer is in org-mode. Error if not."
3394 (or (derived-mode-p 'org-mode)
3395 (error "Cannot execute org-mode agenda command on buffer in %s"
3396 major-mode)))
3398 ;;; Agenda prepare and finalize
3400 (defvar org-agenda-multi nil) ; dynamically scoped
3401 (defvar org-agenda-pre-window-conf nil)
3402 (defvar org-agenda-columns-active nil)
3403 (defvar org-agenda-name nil)
3404 (defvar org-agenda-tag-filter nil)
3405 (defvar org-agenda-category-filter nil)
3406 (defvar org-agenda-top-category-filter nil)
3407 (defvar org-agenda-tag-filter-while-redo nil)
3408 (defvar org-agenda-tag-filter-preset nil
3409 "A preset of the tags filter used for secondary agenda filtering.
3410 This must be a list of strings, each string must be a single tag preceded
3411 by \"+\" or \"-\".
3412 This variable should not be set directly, but agenda custom commands can
3413 bind it in the options section. The preset filter is a global property of
3414 the entire agenda view. In a block agenda, it will not work reliably to
3415 define a filter for one of the individual blocks. You need to set it in
3416 the global options and expect it to be applied to the entire view.")
3418 (defvar org-agenda-category-filter-preset nil
3419 "A preset of the category filter used for secondary agenda filtering.
3420 This must be a list of strings, each string must be a single category
3421 preceded by \"+\" or \"-\".
3422 This variable should not be set directly, but agenda custom commands can
3423 bind it in the options section. The preset filter is a global property of
3424 the entire agenda view. In a block agenda, it will not work reliably to
3425 define a filter for one of the individual blocks. You need to set it in
3426 the global options and expect it to be applied to the entire view.")
3429 (defun org-agenda-use-sticky-p ()
3430 "Return non-nil if an agenda buffer named
3431 `org-agenda-buffer-name' exists and should be shown instead of
3432 generating a new one."
3433 (and
3434 ;; turned off by user
3435 org-agenda-sticky
3436 ;; For multi-agenda buffer already exists
3437 (not org-agenda-multi)
3438 ;; buffer found
3439 (get-buffer org-agenda-buffer-name)
3440 ;; C-u parameter is same as last call
3441 (with-current-buffer (get-buffer org-agenda-buffer-name)
3442 (and
3443 (equal current-prefix-arg
3444 org-agenda-last-prefix-arg)
3445 ;; In case user turned stickiness on, while having existing
3446 ;; Agenda buffer active, don't reuse that buffer, because it
3447 ;; does not have org variables local
3448 org-agenda-this-buffer-is-sticky))))
3450 (defun org-agenda-prepare-window (abuf)
3451 "Setup agenda buffer in the window."
3452 (let* ((awin (get-buffer-window abuf))
3453 wconf)
3454 (cond
3455 ((equal (current-buffer) abuf) nil)
3456 (awin (select-window awin))
3457 ((not (setq wconf (current-window-configuration))))
3458 ((equal org-agenda-window-setup 'current-window)
3459 (org-pop-to-buffer-same-window abuf))
3460 ((equal org-agenda-window-setup 'other-window)
3461 (org-switch-to-buffer-other-window abuf))
3462 ((equal org-agenda-window-setup 'other-frame)
3463 (switch-to-buffer-other-frame abuf))
3464 ((equal org-agenda-window-setup 'reorganize-frame)
3465 (delete-other-windows)
3466 (org-switch-to-buffer-other-window abuf)))
3467 ;; additional test in case agenda is invoked from within agenda
3468 ;; buffer via elisp link
3469 (unless (equal (current-buffer) abuf)
3470 (org-pop-to-buffer-same-window abuf))
3471 (setq org-agenda-pre-window-conf
3472 (or org-agenda-pre-window-conf wconf))))
3474 (defun org-agenda-prepare (&optional name)
3475 (if (org-agenda-use-sticky-p)
3476 (progn
3477 ;; Popup existing buffer
3478 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3479 (message "Sticky Agenda buffer, use `r' to refresh")
3480 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3481 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3482 (setq org-todo-keywords-for-agenda nil)
3483 (setq org-drawers-for-agenda nil)
3484 (unless org-agenda-persistent-filter
3485 (setq org-agenda-tag-filter nil
3486 org-agenda-category-filter nil))
3487 (put 'org-agenda-tag-filter :preset-filter
3488 org-agenda-tag-filter-preset)
3489 (put 'org-agenda-category-filter :preset-filter
3490 org-agenda-category-filter-preset)
3491 (if org-agenda-multi
3492 (progn
3493 (setq buffer-read-only nil)
3494 (goto-char (point-max))
3495 (unless (or (bobp) org-agenda-compact-blocks
3496 (not org-agenda-block-separator))
3497 (insert "\n"
3498 (if (stringp org-agenda-block-separator)
3499 org-agenda-block-separator
3500 (make-string (window-width) org-agenda-block-separator))
3501 "\n"))
3502 (narrow-to-region (point) (point-max)))
3503 (setq org-done-keywords-for-agenda nil)
3505 ;; Setting any org variables that are in org-agenda-local-vars
3506 ;; list need to be done after the prepare call
3507 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3508 (setq buffer-read-only nil)
3509 (org-agenda-reset-markers)
3510 (let ((inhibit-read-only t)) (erase-buffer))
3511 (org-agenda-mode)
3512 (setq org-agenda-buffer (current-buffer))
3513 (setq org-agenda-contributing-files nil)
3514 (setq org-agenda-columns-active nil)
3515 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3516 (setq org-todo-keywords-for-agenda
3517 (org-uniquify org-todo-keywords-for-agenda))
3518 (setq org-done-keywords-for-agenda
3519 (org-uniquify org-done-keywords-for-agenda))
3520 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3521 (setq org-agenda-last-prefix-arg current-prefix-arg)
3522 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3523 (and name (not org-agenda-name)
3524 (org-set-local 'org-agenda-name name)))
3525 (setq buffer-read-only nil)))
3527 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3528 (defun org-agenda-finalize ()
3529 "Finishing touch for the agenda buffer, called just before displaying it."
3530 (unless org-agenda-multi
3531 (save-excursion
3532 (let ((inhibit-read-only t))
3533 (goto-char (point-min))
3534 (while (org-activate-bracket-links (point-max))
3535 (add-text-properties (match-beginning 0) (match-end 0)
3536 '(face org-link)))
3537 (org-agenda-align-tags)
3538 (unless org-agenda-with-colors
3539 (remove-text-properties (point-min) (point-max) '(face nil))))
3540 (if (and (boundp 'org-agenda-overriding-columns-format)
3541 org-agenda-overriding-columns-format)
3542 (org-set-local 'org-agenda-overriding-columns-format
3543 org-agenda-overriding-columns-format))
3544 (if (and (boundp 'org-agenda-view-columns-initially)
3545 org-agenda-view-columns-initially)
3546 (org-agenda-columns))
3547 (when org-agenda-fontify-priorities
3548 (org-agenda-fontify-priorities))
3549 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3550 (org-agenda-dim-blocked-tasks))
3551 (org-agenda-mark-clocking-task)
3552 (when org-agenda-entry-text-mode
3553 (org-agenda-entry-text-hide)
3554 (org-agenda-entry-text-show))
3555 (if (functionp 'org-habit-insert-consistency-graphs)
3556 (org-habit-insert-consistency-graphs))
3557 (let ((inhibit-read-only t))
3558 (run-hooks 'org-agenda-finalize-hook))
3559 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3560 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3561 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3562 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3563 (org-agenda-filter-apply org-agenda-category-filter 'category))
3564 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3566 (defun org-agenda-mark-clocking-task ()
3567 "Mark the current clock entry in the agenda if it is present."
3568 (mapc (lambda (o)
3569 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3570 (delete-overlay o)))
3571 (overlays-in (point-min) (point-max)))
3572 (when (marker-buffer org-clock-hd-marker)
3573 (save-excursion
3574 (goto-char (point-min))
3575 (let (s ov)
3576 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3577 (goto-char s)
3578 (when (equal (org-get-at-bol 'org-hd-marker)
3579 org-clock-hd-marker)
3580 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3581 (overlay-put ov 'type 'org-agenda-clocking)
3582 (overlay-put ov 'face 'org-agenda-clocking)
3583 (overlay-put ov 'help-echo
3584 "The clock is running in this item")))))))
3586 (defun org-agenda-fontify-priorities ()
3587 "Make highest priority lines bold, and lowest italic."
3588 (interactive)
3589 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3590 (delete-overlay o)))
3591 (overlays-in (point-min) (point-max)))
3592 (save-excursion
3593 (let ((inhibit-read-only t)
3594 b e p ov h l)
3595 (goto-char (point-min))
3596 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3597 (setq h (or (get-char-property (point) 'org-highest-priority)
3598 org-highest-priority)
3599 l (or (get-char-property (point) 'org-lowest-priority)
3600 org-lowest-priority)
3601 p (string-to-char (match-string 1))
3602 b (match-beginning 0)
3603 e (if (eq org-agenda-fontify-priorities 'cookies)
3604 (match-end 0)
3605 (point-at-eol))
3606 ov (make-overlay b e))
3607 (overlay-put
3608 ov 'face
3609 (cond ((org-face-from-face-or-color
3610 'priority nil
3611 (cdr (assoc p org-priority-faces))))
3612 ((and (listp org-agenda-fontify-priorities)
3613 (org-face-from-face-or-color
3614 'priority nil
3615 (cdr (assoc p org-agenda-fontify-priorities)))))
3616 ((equal p l) 'italic)
3617 ((equal p h) 'bold)))
3618 (overlay-put ov 'org-type 'org-priority)))))
3620 (defun org-agenda-dim-blocked-tasks ()
3621 "Dim currently blocked TODO's in the agenda display."
3622 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3623 (delete-overlay o)))
3624 (overlays-in (point-min) (point-max)))
3625 (save-excursion
3626 (let ((inhibit-read-only t)
3627 (org-depend-tag-blocked nil)
3628 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3629 org-blocked-by-checkboxes
3630 invis1 b e p ov h l)
3631 (goto-char (point-min))
3632 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3633 (and pos (goto-char (1+ pos))))
3634 (setq org-blocked-by-checkboxes nil invis1 invis)
3635 (let ((marker (org-get-at-bol 'org-hd-marker)))
3636 (when (and marker
3637 (with-current-buffer (marker-buffer marker)
3638 (save-excursion (goto-char marker)
3639 (org-entry-blocked-p))))
3640 (if org-blocked-by-checkboxes (setq invis1 nil))
3641 (setq b (if invis1
3642 (max (point-min) (1- (point-at-bol)))
3643 (point-at-bol))
3644 e (point-at-eol)
3645 ov (make-overlay b e))
3646 (if invis1
3647 (overlay-put ov 'invisible t)
3648 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3649 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3651 (defvar org-agenda-skip-function nil
3652 "Function to be called at each match during agenda construction.
3653 If this function returns nil, the current match should not be skipped.
3654 Otherwise, the function must return a position from where the search
3655 should be continued.
3656 This may also be a Lisp form, it will be evaluated.
3657 Never set this variable using `setq' or so, because then it will apply
3658 to all future agenda commands. If you do want a global skipping condition,
3659 use the option `org-agenda-skip-function-global' instead.
3660 The correct usage for `org-agenda-skip-function' is to bind it with
3661 `let' to scope it dynamically into the agenda-constructing command.
3662 A good way to set it is through options in `org-agenda-custom-commands'.")
3664 (defun org-agenda-skip ()
3665 "Throw to `:skip' in places that should be skipped.
3666 Also moves point to the end of the skipped region, so that search can
3667 continue from there."
3668 (let ((p (point-at-bol)) to)
3669 (when (org-in-src-block-p) (throw :skip t))
3670 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3671 (get-text-property p :org-archived)
3672 (org-end-of-subtree t)
3673 (throw :skip t))
3674 (and org-agenda-skip-comment-trees
3675 (get-text-property p :org-comment)
3676 (org-end-of-subtree t)
3677 (throw :skip t))
3678 (if (equal (char-after p) ?#) (throw :skip t))
3679 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3680 (org-agenda-skip-eval org-agenda-skip-function)))
3681 (goto-char to)
3682 (throw :skip t))))
3684 (defun org-agenda-skip-eval (form)
3685 "If FORM is a function or a list, call (or eval) is and return result.
3686 `save-excursion' and `save-match-data' are wrapped around the call, so point
3687 and match data are returned to the previous state no matter what these
3688 functions do."
3689 (let (fp)
3690 (and form
3691 (or (setq fp (functionp form))
3692 (consp form))
3693 (save-excursion
3694 (save-match-data
3695 (if fp
3696 (funcall form)
3697 (eval form)))))))
3699 (defvar org-agenda-markers nil
3700 "List of all currently active markers created by `org-agenda'.")
3701 (defvar org-agenda-last-marker-time (org-float-time)
3702 "Creation time of the last agenda marker.")
3704 (defun org-agenda-new-marker (&optional pos)
3705 "Return a new agenda marker.
3706 Org-mode keeps a list of these markers and resets them when they are
3707 no longer in use."
3708 (let ((m (copy-marker (or pos (point)))))
3709 (setq org-agenda-last-marker-time (org-float-time))
3710 (if org-agenda-buffer
3711 (with-current-buffer org-agenda-buffer
3712 (push m org-agenda-markers))
3713 (push m org-agenda-markers))
3716 (defun org-agenda-reset-markers ()
3717 "Reset markers created by `org-agenda'."
3718 (while org-agenda-markers
3719 (move-marker (pop org-agenda-markers) nil)))
3721 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3722 "Save relative positions of markers in region.
3723 This check for agenda markers in all agenda buffers currently active."
3724 (dolist (buf (buffer-list))
3725 (with-current-buffer buf
3726 (when (eq major-mode 'org-agenda-mode)
3727 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3728 org-agenda-markers)))))
3730 ;;; Entry text mode
3732 (defun org-agenda-entry-text-show-here ()
3733 "Add some text from the entry as context to the current line."
3734 (let (m txt o)
3735 (setq m (org-get-at-bol 'org-hd-marker))
3736 (unless (marker-buffer m)
3737 (error "No marker points to an entry here"))
3738 (setq txt (concat "\n" (org-no-properties
3739 (org-agenda-get-some-entry-text
3740 m org-agenda-entry-text-maxlines " > "))))
3741 (when (string-match "\\S-" txt)
3742 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3743 (overlay-put o 'evaporate t)
3744 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3745 (overlay-put o 'after-string txt))))
3747 (defun org-agenda-entry-text-show ()
3748 "Add entry context for all agenda lines."
3749 (interactive)
3750 (save-excursion
3751 (goto-char (point-max))
3752 (beginning-of-line 1)
3753 (while (not (bobp))
3754 (when (org-get-at-bol 'org-hd-marker)
3755 (org-agenda-entry-text-show-here))
3756 (beginning-of-line 0))))
3758 (defun org-agenda-entry-text-hide ()
3759 "Remove any shown entry context."
3760 (delq nil
3761 (mapcar (lambda (o)
3762 (if (eq (overlay-get o 'org-overlay-type)
3763 'agenda-entry-content)
3764 (progn (delete-overlay o) t)))
3765 (overlays-in (point-min) (point-max)))))
3767 (defun org-agenda-get-day-face (date)
3768 "Return the face DATE should be displayed with."
3769 (or (and (functionp org-agenda-day-face-function)
3770 (funcall org-agenda-day-face-function date))
3771 (cond ((org-agenda-todayp date)
3772 'org-agenda-date-today)
3773 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3774 'org-agenda-date-weekend)
3775 (t 'org-agenda-date))))
3777 ;;; Agenda timeline
3779 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3781 (defun org-timeline (&optional dotodo)
3782 "Show a time-sorted view of the entries in the current org file.
3783 Only entries with a time stamp of today or later will be listed. With
3784 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3785 under the current date.
3786 If the buffer contains an active region, only check the region for
3787 dates."
3788 (interactive "P")
3789 (let* ((dopast t)
3790 (org-agenda-show-log-scoped org-agenda-show-log)
3791 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3792 (current-buffer))))
3793 (date (calendar-current-date))
3794 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3795 (end (if (org-region-active-p) (region-end) (point-max)))
3796 (day-numbers (org-get-all-dates
3797 beg end 'no-ranges
3798 t org-agenda-show-log-scoped ; always include today
3799 org-timeline-show-empty-dates))
3800 (org-deadline-warning-days 0)
3801 (org-agenda-only-exact-dates t)
3802 (today (org-today))
3803 (past t)
3804 args
3805 s e rtn d emptyp)
3806 (setq org-agenda-redo-command
3807 (list 'progn
3808 (list 'org-switch-to-buffer-other-window (current-buffer))
3809 (list 'org-timeline (list 'quote dotodo))))
3810 (if (not dopast)
3811 ;; Remove past dates from the list of dates.
3812 (setq day-numbers (delq nil (mapcar (lambda(x)
3813 (if (>= x today) x nil))
3814 day-numbers))))
3815 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3816 (org-compile-prefix-format 'timeline)
3817 (org-set-sorting-strategy 'timeline)
3818 (if org-agenda-show-log-scoped (push :closed args))
3819 (push :timestamp args)
3820 (push :deadline args)
3821 (push :scheduled args)
3822 (push :sexp args)
3823 (if dotodo (push :todo args))
3824 (insert "Timeline of file " entry "\n")
3825 (add-text-properties (point-min) (point)
3826 (list 'face 'org-agenda-structure))
3827 (org-agenda-mark-header-line (point-min))
3828 (while (setq d (pop day-numbers))
3829 (if (and (listp d) (eq (car d) :omitted))
3830 (progn
3831 (setq s (point))
3832 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3833 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3834 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3835 (if (and (>= d today)
3836 dopast
3837 past)
3838 (progn
3839 (setq past nil)
3840 (insert (make-string 79 ?-) "\n")))
3841 (setq date (calendar-gregorian-from-absolute d))
3842 (setq s (point))
3843 (setq rtn (and (not emptyp)
3844 (apply 'org-agenda-get-day-entries entry
3845 date args)))
3846 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3847 (progn
3848 (insert
3849 (if (stringp org-agenda-format-date)
3850 (format-time-string org-agenda-format-date
3851 (org-time-from-absolute date))
3852 (funcall org-agenda-format-date date))
3853 "\n")
3854 (put-text-property s (1- (point)) 'face
3855 (org-agenda-get-day-face date))
3856 (put-text-property s (1- (point)) 'org-date-line t)
3857 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3858 (if (equal d today)
3859 (put-text-property s (1- (point)) 'org-today t))
3860 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3861 (put-text-property s (1- (point)) 'day d)))))
3862 (goto-char (point-min))
3863 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3864 (point-min)))
3865 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3866 (org-agenda-finalize)
3867 (setq buffer-read-only t)))
3869 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3870 "Return a list of all relevant day numbers from BEG to END buffer positions.
3871 If NO-RANGES is non-nil, include only the start and end dates of a range,
3872 not every single day in the range. If FORCE-TODAY is non-nil, make
3873 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3874 inactive time stamps (those in square brackets) are included.
3875 When EMPTY is non-nil, also include days without any entries."
3876 (let ((re (concat
3877 (if pre-re pre-re "")
3878 (if inactive org-ts-regexp-both org-ts-regexp)))
3879 dates dates1 date day day1 day2 ts1 ts2 pos)
3880 (if force-today
3881 (setq dates (list (org-today))))
3882 (save-excursion
3883 (goto-char beg)
3884 (while (re-search-forward re end t)
3885 (setq day (time-to-days (org-time-string-to-time
3886 (substring (match-string 1) 0 10)
3887 (current-buffer) (match-beginning 0))))
3888 (or (memq day dates) (push day dates)))
3889 (unless no-ranges
3890 (goto-char beg)
3891 (while (re-search-forward org-tr-regexp end t)
3892 (setq pos (match-beginning 0))
3893 (setq ts1 (substring (match-string 1) 0 10)
3894 ts2 (substring (match-string 2) 0 10)
3895 day1 (time-to-days (org-time-string-to-time
3896 ts1 (current-buffer) pos))
3897 day2 (time-to-days (org-time-string-to-time
3898 ts2 (current-buffer) pos)))
3899 (while (< (setq day1 (1+ day1)) day2)
3900 (or (memq day1 dates) (push day1 dates)))))
3901 (setq dates (sort dates '<))
3902 (when empty
3903 (while (setq day (pop dates))
3904 (setq day2 (car dates))
3905 (push day dates1)
3906 (when (and day2 empty)
3907 (if (or (eq empty t)
3908 (and (numberp empty) (<= (- day2 day) empty)))
3909 (while (< (setq day (1+ day)) day2)
3910 (push (list day) dates1))
3911 (push (cons :omitted (- day2 day)) dates1))))
3912 (setq dates (nreverse dates1)))
3913 dates)))
3915 ;;; Agenda Daily/Weekly
3917 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3918 "Start day for the agenda view.
3919 Custom commands can set this variable in the options section.")
3920 (defvar org-starting-day nil) ; local variable in the agenda buffer
3921 (defvar org-arg-loc nil) ; local variable
3923 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3924 "List of types searched for when creating the daily/weekly agenda.
3925 This variable is a list of symbols that controls the types of
3926 items that appear in the daily/weekly agenda. Allowed symbols in this
3927 list are are
3929 :timestamp List items containing a date stamp or date range matching
3930 the selected date. This includes sexp entries in
3931 angular brackets.
3933 :sexp List entries resulting from plain diary-like sexps.
3935 :deadline List deadline due on that date. When the date is today,
3936 also list any deadlines past due, or due within
3937 `org-deadline-warning-days'. `:deadline' must appear before
3938 `:scheduled' if the setting of
3939 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3940 any effect.
3942 :scheduled List all items which are scheduled for the given date.
3943 The diary for *today* also contains items which were
3944 scheduled earlier and are not yet marked DONE.
3946 By default, all four types are turned on.
3948 Never set this variable globally using `setq', because then it
3949 will apply to all future agenda commands. Instead, bind it with
3950 `let' to scope it dynamically into the agenda-constructing
3951 command. A good way to set it is through options in
3952 `org-agenda-custom-commands'. For a more flexible (though
3953 somewhat less efficient) way of determining what is included in
3954 the daily/weekly agenda, see `org-agenda-skip-function'.")
3956 (defvar org-agenda-buffer-tmp-name nil)
3957 ;;;###autoload
3958 (defun org-agenda-list (&optional arg start-day span)
3959 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3960 The view will be for the current day or week, but from the overview buffer
3961 you will be able to go to other days/weeks.
3963 With a numeric prefix argument in an interactive call, the agenda will
3964 span ARG days. Lisp programs should instead specify SPAN to change
3965 the number of days. SPAN defaults to `org-agenda-span'.
3967 START-DAY defaults to TODAY, or to the most recent match for the weekday
3968 given in `org-agenda-start-on-weekday'."
3969 (interactive "P")
3970 (if org-agenda-overriding-arguments
3971 (setq arg (car org-agenda-overriding-arguments)
3972 start-day (nth 1 org-agenda-overriding-arguments)
3973 span (nth 2 org-agenda-overriding-arguments)))
3974 (if (and (integerp arg) (> arg 0))
3975 (setq span arg arg nil))
3976 (catch 'exit
3977 (setq org-agenda-buffer-name
3978 (or org-agenda-buffer-tmp-name
3979 (if org-agenda-sticky
3980 (cond ((and org-keys (stringp org-match))
3981 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3982 (org-keys
3983 (format "*Org Agenda(%s)*" org-keys))
3984 (t "*Org Agenda(a)*")))
3985 org-agenda-buffer-name))
3986 (org-agenda-prepare "Day/Week")
3987 (setq start-day (or start-day org-agenda-start-day))
3988 (if (stringp start-day)
3989 ;; Convert to an absolute day number
3990 (setq start-day (time-to-days (org-read-date nil t start-day))))
3991 (org-compile-prefix-format 'agenda)
3992 (org-set-sorting-strategy 'agenda)
3993 (let* ((span (org-agenda-ndays-to-span
3994 (or span org-agenda-ndays org-agenda-span)))
3995 (today (org-today))
3996 (sd (or start-day today))
3997 (ndays (org-agenda-span-to-ndays span sd))
3998 (org-agenda-start-on-weekday
3999 (if (eq ndays 7)
4000 org-agenda-start-on-weekday))
4001 (thefiles (org-agenda-files nil 'ifmode))
4002 (files thefiles)
4003 (start (if (or (null org-agenda-start-on-weekday)
4004 (< ndays 7))
4006 (let* ((nt (calendar-day-of-week
4007 (calendar-gregorian-from-absolute sd)))
4008 (n1 org-agenda-start-on-weekday)
4009 (d (- nt n1)))
4010 (- sd (+ (if (< d 0) 7 0) d)))))
4011 (day-numbers (list start))
4012 (day-cnt 0)
4013 (inhibit-redisplay (not debug-on-error))
4014 (org-agenda-show-log-scoped org-agenda-show-log)
4015 s e rtn rtnall file date d start-pos end-pos todayp
4016 clocktable-start clocktable-end filter)
4017 (setq org-agenda-redo-command
4018 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4019 (dotimes (n (1- ndays))
4020 (push (1+ (car day-numbers)) day-numbers))
4021 (setq day-numbers (nreverse day-numbers))
4022 (setq clocktable-start (car day-numbers)
4023 clocktable-end (1+ (or (org-last day-numbers) 0)))
4024 (org-set-local 'org-starting-day (car day-numbers))
4025 (org-set-local 'org-arg-loc arg)
4026 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4027 (unless org-agenda-compact-blocks
4028 (let* ((d1 (car day-numbers))
4029 (d2 (org-last day-numbers))
4030 (w1 (org-days-to-iso-week d1))
4031 (w2 (org-days-to-iso-week d2)))
4032 (setq s (point))
4033 (if org-agenda-overriding-header
4034 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4035 nil 'face 'org-agenda-structure) "\n")
4036 (insert (org-agenda-span-name span)
4037 "-agenda"
4038 (if (< (- d2 d1) 350)
4039 (if (= w1 w2)
4040 (format " (W%02d)" w1)
4041 (format " (W%02d-W%02d)" w1 w2))
4043 ":\n")))
4044 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4045 'org-date-line t))
4046 (org-agenda-mark-header-line s))
4047 (while (setq d (pop day-numbers))
4048 (setq date (calendar-gregorian-from-absolute d)
4049 s (point))
4050 (if (or (setq todayp (= d today))
4051 (and (not start-pos) (= d sd)))
4052 (setq start-pos (point))
4053 (if (and start-pos (not end-pos))
4054 (setq end-pos (point))))
4055 (setq files thefiles
4056 rtnall nil)
4057 (while (setq file (pop files))
4058 (catch 'nextfile
4059 (org-check-agenda-file file)
4060 (let ((org-agenda-entry-types org-agenda-entry-types))
4061 (unless org-agenda-include-deadlines
4062 (setq org-agenda-entry-types
4063 (delq :deadline org-agenda-entry-types)))
4064 (cond
4065 ((memq org-agenda-show-log-scoped '(only clockcheck))
4066 (setq rtn (org-agenda-get-day-entries
4067 file date :closed)))
4068 (org-agenda-show-log-scoped
4069 (setq rtn (apply 'org-agenda-get-day-entries
4070 file date
4071 (append '(:closed) org-agenda-entry-types))))
4073 (setq rtn (apply 'org-agenda-get-day-entries
4074 file date
4075 org-agenda-entry-types)))))
4076 (setq rtnall (append rtnall rtn)))) ;; all entries
4077 (if org-agenda-include-diary
4078 (let ((org-agenda-search-headline-for-time t))
4079 (require 'diary-lib)
4080 (setq rtn (org-get-entries-from-diary date))
4081 (setq rtnall (append rtnall rtn))))
4082 (if (or rtnall org-agenda-show-all-dates)
4083 (progn
4084 (setq day-cnt (1+ day-cnt))
4085 (insert
4086 (if (stringp org-agenda-format-date)
4087 (format-time-string org-agenda-format-date
4088 (org-time-from-absolute date))
4089 (funcall org-agenda-format-date date))
4090 "\n")
4091 (put-text-property s (1- (point)) 'face
4092 (org-agenda-get-day-face date))
4093 (put-text-property s (1- (point)) 'org-date-line t)
4094 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4095 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4096 (when todayp
4097 (put-text-property s (1- (point)) 'org-today t))
4098 (setq rtnall
4099 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4100 (if rtnall (insert ;; all entries
4101 (org-agenda-finalize-entries rtnall)
4102 "\n"))
4103 (put-text-property s (1- (point)) 'day d)
4104 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4105 (when (and org-agenda-clockreport-mode clocktable-start)
4106 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4107 ;; the above line is to ensure the restricted range!
4108 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4109 tbl)
4110 (setq p (org-plist-delete p :block))
4111 (setq p (plist-put p :tstart clocktable-start))
4112 (setq p (plist-put p :tend clocktable-end))
4113 (setq p (plist-put p :scope 'agenda))
4114 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4115 (setq filter (or org-agenda-tag-filter-while-redo
4116 (get 'org-agenda-tag-filter :preset-filter))))
4117 (setq p (plist-put p :tags (mapconcat (lambda (x)
4118 (if (string-match "[<>=]" x)
4121 filter ""))))
4122 (setq tbl (apply 'org-clock-get-clocktable p))
4123 (insert tbl)))
4124 (goto-char (point-min))
4125 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4126 (unless (and (pos-visible-in-window-p (point-min))
4127 (pos-visible-in-window-p (point-max)))
4128 (goto-char (1- (point-max)))
4129 (recenter -1)
4130 (if (not (pos-visible-in-window-p (or start-pos 1)))
4131 (progn
4132 (goto-char (or start-pos 1))
4133 (recenter 1))))
4134 (goto-char (or start-pos 1))
4135 (add-text-properties (point-min) (point-max)
4136 `(org-agenda-type agenda
4137 org-last-args (,arg ,start-day ,span)
4138 org-redo-cmd ,org-agenda-redo-command
4139 org-series-cmd ,org-cmd))
4140 (if (eq org-agenda-show-log-scoped 'clockcheck)
4141 (org-agenda-show-clocking-issues))
4142 (org-agenda-finalize)
4143 (setq buffer-read-only t)
4144 (message ""))))
4146 (autoload 'org-agenda-list "org-agenda" "\
4147 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4148 The view will be for the current day or week, but from the overview buffer
4149 you will be able to go to other days/weeks.
4151 With a numeric prefix argument in an interactive call, the agenda will
4152 span ARG days. Lisp programs should instead specify SPAN to change
4153 the number of days. SPAN defaults to `org-agenda-span'.
4155 START-DAY defaults to TODAY, or to the most recent match for the weekday
4156 given in `org-agenda-start-on-weekday'.
4158 \(fn &optional ARG START-DAY SPAN)" t nil)
4160 (defun org-agenda-ndays-to-span (n)
4161 "Return a span symbol for a span of N days, or N if none matches."
4162 (cond ((symbolp n) n)
4163 ((= n 1) 'day)
4164 ((= n 7) 'week)
4165 (t n)))
4167 (defun org-agenda-span-to-ndays (span &optional start-day)
4168 "Return ndays from SPAN, possibly starting at START-DAY."
4169 (cond ((numberp span) span)
4170 ((eq span 'day) 1)
4171 ((eq span 'week) 7)
4172 ((eq span 'month)
4173 (let ((date (calendar-gregorian-from-absolute start-day)))
4174 (calendar-last-day-of-month (car date) (caddr date))))
4175 ((eq span 'year)
4176 (let ((date (calendar-gregorian-from-absolute start-day)))
4177 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4179 (defun org-agenda-span-name (span)
4180 "Return a SPAN name."
4181 (if (null span)
4183 (if (symbolp span)
4184 (capitalize (symbol-name span))
4185 (format "%d days" span))))
4187 ;;; Agenda word search
4189 (defvar org-agenda-search-history nil)
4191 (defvar org-search-syntax-table nil
4192 "Special syntax table for org-mode search.
4193 In this table, we have single quotes not as word constituents, to
4194 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4196 (defvar org-mode-syntax-table) ; From org.el
4197 (defun org-search-syntax-table ()
4198 (unless org-search-syntax-table
4199 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4200 (modify-syntax-entry ?' "." org-search-syntax-table)
4201 (modify-syntax-entry ?` "." org-search-syntax-table))
4202 org-search-syntax-table)
4204 (defvar org-agenda-last-search-view-search-was-boolean nil)
4206 ;;;###autoload
4207 (defun org-search-view (&optional todo-only string edit-at)
4208 "Show all entries that contain a phrase or words or regular expressions.
4210 With optional prefix argument TODO-ONLY, only consider entries that are
4211 TODO entries. The argument STRING can be used to pass a default search
4212 string into this function. If EDIT-AT is non-nil, it means that the
4213 user should get a chance to edit this string, with cursor at position
4214 EDIT-AT.
4216 The search string can be viewed either as a phrase that should be found as
4217 is, or it can be broken into a number of snippets, each of which must match
4218 in a Boolean way to select an entry. The default depends on the variable
4219 `org-agenda-search-view-always-boolean'.
4220 Even if this is turned off (the default) you can always switch to
4221 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4223 The default is a direct search of the whole phrase, where each space in
4224 the search string can expand to an arbitrary amount of whitespace,
4225 including newlines.
4227 If using a Boolean search, the search string is split on whitespace and
4228 each snippet is searched separately, with logical AND to select an entry.
4229 Words prefixed with a minus must *not* occur in the entry. Words without
4230 a prefix or prefixed with a plus must occur in the entry. Matching is
4231 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4232 match whole words, not parts of a word) if
4233 `org-agenda-search-view-force-full-words' is set (default is nil).
4235 Boolean search snippets enclosed by curly braces are interpreted as
4236 regular expressions that must or (when preceded with \"-\") must not
4237 match in the entry. Snippets enclosed into double quotes will be taken
4238 as a whole, to include whitespace.
4240 - If the search string starts with an asterisk, search only in headlines.
4241 - If (possibly after the leading star) the search string starts with an
4242 exclamation mark, this also means to look at TODO entries only, an effect
4243 that can also be achieved with a prefix argument.
4244 - If (possibly after star and exclamation mark) the search string starts
4245 with a colon, this will mean that the (non-regexp) snippets of the
4246 Boolean search must match as full words.
4248 This command searches the agenda files, and in addition the files listed
4249 in `org-agenda-text-search-extra-files'."
4250 (interactive "P")
4251 (if org-agenda-overriding-arguments
4252 (setq todo-only (car org-agenda-overriding-arguments)
4253 string (nth 1 org-agenda-overriding-arguments)
4254 edit-at (nth 2 org-agenda-overriding-arguments)))
4255 (let* ((props (list 'face nil
4256 'done-face 'org-agenda-done
4257 'org-not-done-regexp org-not-done-regexp
4258 'org-todo-regexp org-todo-regexp
4259 'org-complex-heading-regexp org-complex-heading-regexp
4260 'mouse-face 'highlight
4261 'help-echo (format "mouse-2 or RET jump to location")))
4262 (full-words org-agenda-search-view-force-full-words)
4263 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4264 regexp rtn rtnall files file pos
4265 marker category category-pos level tags c neg re boolean
4266 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4267 (unless (and (not edit-at)
4268 (stringp string)
4269 (string-match "\\S-" string))
4270 (setq string (read-string
4271 (if org-agenda-search-view-always-boolean
4272 "[+-]Word/{Regexp} ...: "
4273 "Phrase or [+-]Word/{Regexp} ...: ")
4274 (cond
4275 ((integerp edit-at) (cons string edit-at))
4276 (edit-at string))
4277 'org-agenda-search-history)))
4278 (catch 'exit
4279 (if org-agenda-sticky
4280 (setq org-agenda-buffer-name
4281 (if (stringp string)
4282 (format "*Org Agenda(%s:%s)*"
4283 (or org-keys (or (and todo-only "S") "s")) string)
4284 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4285 (org-agenda-prepare "SEARCH")
4286 (org-compile-prefix-format 'search)
4287 (org-set-sorting-strategy 'search)
4288 (setq org-agenda-redo-command
4289 (list 'org-search-view (if todo-only t nil)
4290 (list 'if 'current-prefix-arg nil string)))
4291 (setq org-agenda-query-string string)
4292 (if (equal (string-to-char string) ?*)
4293 (setq hdl-only t
4294 words (substring string 1))
4295 (setq words string))
4296 (when (equal (string-to-char words) ?!)
4297 (setq todo-only t
4298 words (substring words 1)))
4299 (when (equal (string-to-char words) ?:)
4300 (setq full-words t
4301 words (substring words 1)))
4302 (if (or org-agenda-search-view-always-boolean
4303 (member (string-to-char words) '(?- ?+ ?\{)))
4304 (setq boolean t))
4305 (setq words (org-split-string words))
4306 (let (www w)
4307 (while (setq w (pop words))
4308 (while (and (string-match "\\\\\\'" w) words)
4309 (setq w (concat (substring w 0 -1) " " (pop words))))
4310 (push w www))
4311 (setq words (nreverse www) www nil)
4312 (while (setq w (pop words))
4313 (when (and (string-match "\\`[-+]?{" w)
4314 (not (string-match "}\\'" w)))
4315 (while (and words (not (string-match "}\\'" (car words))))
4316 (setq w (concat w " " (pop words))))
4317 (setq w (concat w " " (pop words))))
4318 (push w www))
4319 (setq words (nreverse www)))
4320 (setq org-agenda-last-search-view-search-was-boolean boolean)
4321 (when boolean
4322 (let (wds w)
4323 (while (setq w (pop words))
4324 (if (or (equal (substring w 0 1) "\"")
4325 (and (> (length w) 1)
4326 (member (substring w 0 1) '("+" "-"))
4327 (equal (substring w 1 2) "\"")))
4328 (while (and words (not (equal (substring w -1) "\"")))
4329 (setq w (concat w " " (pop words)))))
4330 (and (string-match "\\`\\([-+]?\\)\"" w)
4331 (setq w (replace-match "\\1" nil nil w)))
4332 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4333 (push w wds))
4334 (setq words (nreverse wds))))
4335 (if boolean
4336 (mapc (lambda (w)
4337 (setq c (string-to-char w))
4338 (if (equal c ?-)
4339 (setq neg t w (substring w 1))
4340 (if (equal c ?+)
4341 (setq neg nil w (substring w 1))
4342 (setq neg nil)))
4343 (if (string-match "\\`{.*}\\'" w)
4344 (setq re (substring w 1 -1))
4345 (if full-words
4346 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4347 (setq re (regexp-quote (downcase w)))))
4348 (if neg (push re regexps-) (push re regexps+)))
4349 words)
4350 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4351 regexps+))
4352 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4353 (if (not regexps+)
4354 (setq regexp org-outline-regexp-bol)
4355 (setq regexp (pop regexps+))
4356 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4357 regexp))))
4358 (setq files (org-agenda-files nil 'ifmode))
4359 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4360 (pop org-agenda-text-search-extra-files)
4361 (setq files (org-add-archive-files files)))
4362 (setq files (append files org-agenda-text-search-extra-files)
4363 rtnall nil)
4364 (while (setq file (pop files))
4365 (setq ee nil)
4366 (catch 'nextfile
4367 (org-check-agenda-file file)
4368 (setq buffer (if (file-exists-p file)
4369 (org-get-agenda-file-buffer file)
4370 (error "No such file %s" file)))
4371 (if (not buffer)
4372 ;; If file does not exist, make sure an error message is sent
4373 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4374 file))))
4375 (with-current-buffer buffer
4376 (with-syntax-table (org-search-syntax-table)
4377 (unless (derived-mode-p 'org-mode)
4378 (error "Agenda file %s is not in `org-mode'" file))
4379 (let ((case-fold-search t))
4380 (save-excursion
4381 (save-restriction
4382 (if org-agenda-restrict
4383 (narrow-to-region org-agenda-restrict-begin
4384 org-agenda-restrict-end)
4385 (widen))
4386 (goto-char (point-min))
4387 (unless (or (org-at-heading-p)
4388 (outline-next-heading))
4389 (throw 'nextfile t))
4390 (goto-char (max (point-min) (1- (point))))
4391 (while (re-search-forward regexp nil t)
4392 (org-back-to-heading t)
4393 (skip-chars-forward "* ")
4394 (setq beg (point-at-bol)
4395 beg1 (point)
4396 end (progn (outline-next-heading) (point)))
4397 (catch :skip
4398 (goto-char beg)
4399 (org-agenda-skip)
4400 (setq str (buffer-substring-no-properties
4401 (point-at-bol)
4402 (if hdl-only (point-at-eol) end)))
4403 (mapc (lambda (wr) (when (string-match wr str)
4404 (goto-char (1- end))
4405 (throw :skip t)))
4406 regexps-)
4407 (mapc (lambda (wr) (unless (string-match wr str)
4408 (goto-char (1- end))
4409 (throw :skip t)))
4410 (if todo-only
4411 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4412 regexps+)
4413 regexps+))
4414 (goto-char beg)
4415 (setq marker (org-agenda-new-marker (point))
4416 category (org-get-category)
4417 level (make-string (org-reduced-level (org-outline-level)) ? )
4418 category-pos (get-text-property (point) 'org-category-position)
4419 tags (org-get-tags-at (point))
4420 txt (org-agenda-format-item
4422 (buffer-substring-no-properties
4423 beg1 (point-at-eol))
4424 level category tags t))
4425 (org-add-props txt props
4426 'org-marker marker 'org-hd-marker marker
4427 'org-todo-regexp org-todo-regexp
4428 'level level
4429 'org-complex-heading-regexp org-complex-heading-regexp
4430 'priority 1000 'org-category category
4431 'org-category-position category-pos
4432 'type "search")
4433 (push txt ee)
4434 (goto-char (1- end))))))))))
4435 (setq rtn (nreverse ee))
4436 (setq rtnall (append rtnall rtn)))
4437 (if org-agenda-overriding-header
4438 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4439 nil 'face 'org-agenda-structure) "\n")
4440 (insert "Search words: ")
4441 (add-text-properties (point-min) (1- (point))
4442 (list 'face 'org-agenda-structure))
4443 (setq pos (point))
4444 (insert string "\n")
4445 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4446 (setq pos (point))
4447 (unless org-agenda-multi
4448 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4449 (add-text-properties pos (1- (point))
4450 (list 'face 'org-agenda-structure))))
4451 (org-agenda-mark-header-line (point-min))
4452 (when rtnall
4453 (insert (org-agenda-finalize-entries rtnall) "\n"))
4454 (goto-char (point-min))
4455 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4456 (add-text-properties (point-min) (point-max)
4457 `(org-agenda-type search
4458 org-last-args (,todo-only ,string ,edit-at)
4459 org-redo-cmd ,org-agenda-redo-command
4460 org-series-cmd ,org-cmd))
4461 (org-agenda-finalize)
4462 (setq buffer-read-only t))))
4464 (autoload 'org-search-view "org-agenda" "\
4465 Show all entries that contain a phrase or words or regular expressions.
4467 With optional prefix argument TODO-ONLY, only consider entries that are
4468 TODO entries. The argument STRING can be used to pass a default search
4469 string into this function. If EDIT-AT is non-nil, it means that the
4470 user should get a chance to edit this string, with cursor at position
4471 EDIT-AT.
4473 The search string can be viewed either as a phrase that should be found as
4474 is, or it can be broken into a number of snippets, each of which must match
4475 in a Boolean way to select an entry. The default depends on the variable
4476 `org-agenda-search-view-always-boolean'.
4477 Even if this is turned off (the default) you can always switch to
4478 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4480 The default is a direct search of the whole phrase, where each space in
4481 the search string can expand to an arbitrary amount of whitespace,
4482 including newlines.
4484 If using a Boolean search, the search string is split on whitespace and
4485 each snippet is searched separately, with logical AND to select an entry.
4486 Words prefixed with a minus must *not* occur in the entry. Words without
4487 a prefix or prefixed with a plus must occur in the entry. Matching is
4488 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4489 match whole words, not parts of a word) if
4490 `org-agenda-search-view-force-full-words' is set (default is nil).
4492 Boolean search snippets enclosed by curly braces are interpreted as
4493 regular expressions that must or (when preceded with \"-\") must not
4494 match in the entry. Snippets enclosed into double quotes will be taken
4495 as a whole, to include whitespace.
4497 - If the search string starts with an asterisk, search only in headlines.
4498 - If (possibly after the leading star) the search string starts with an
4499 exclamation mark, this also means to look at TODO entries only, an effect
4500 that can also be achieved with a prefix argument.
4501 - If (possibly after star and exclamation mark) the search string starts
4502 with a colon, this will mean that the (non-regexp) snippets of the
4503 Boolean search must match as full words.
4505 This command searches the agenda files, and in addition the files listed
4506 in `org-agenda-text-search-extra-files'.
4508 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4510 ;;; Agenda TODO list
4512 (defvar org-select-this-todo-keyword nil)
4513 (defvar org-last-arg nil)
4515 ;;;###autoload
4516 (defun org-todo-list (&optional arg)
4517 "Show all (not done) TODO entries from all agenda file in a single list.
4518 The prefix arg can be used to select a specific TODO keyword and limit
4519 the list to these. When using \\[universal-argument], you will be prompted
4520 for a keyword. A numeric prefix directly selects the Nth keyword in
4521 `org-todo-keywords-1'."
4522 (interactive "P")
4523 (if org-agenda-overriding-arguments
4524 (setq arg org-agenda-overriding-arguments))
4525 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4526 (let* ((today (org-today))
4527 (date (calendar-gregorian-from-absolute today))
4528 (kwds org-todo-keywords-for-agenda)
4529 (completion-ignore-case t)
4530 (org-select-this-todo-keyword
4531 (if (stringp arg) arg
4532 (and arg (integerp arg) (> arg 0)
4533 (nth (1- arg) kwds))))
4534 rtn rtnall files file pos)
4535 (when (equal arg '(4))
4536 (setq org-select-this-todo-keyword
4537 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4538 (mapcar 'list kwds) nil nil)))
4539 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4540 (catch 'exit
4541 (if org-agenda-sticky
4542 (setq org-agenda-buffer-name
4543 (if (stringp org-select-this-todo-keyword)
4544 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4545 org-select-this-todo-keyword)
4546 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4547 (org-agenda-prepare "TODO")
4548 (org-compile-prefix-format 'todo)
4549 (org-set-sorting-strategy 'todo)
4550 (setq org-agenda-redo-command
4551 `(org-todo-list (or (and (numberp current-prefix-arg)
4552 current-prefix-arg)
4553 ,org-select-this-todo-keyword
4554 current-prefix-arg ,arg)))
4555 (setq files (org-agenda-files nil 'ifmode)
4556 rtnall nil)
4557 (while (setq file (pop files))
4558 (catch 'nextfile
4559 (org-check-agenda-file file)
4560 (setq rtn (org-agenda-get-day-entries file date :todo))
4561 (setq rtnall (append rtnall rtn))))
4562 (if org-agenda-overriding-header
4563 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4564 nil 'face 'org-agenda-structure) "\n")
4565 (insert "Global list of TODO items of type: ")
4566 (add-text-properties (point-min) (1- (point))
4567 (list 'face 'org-agenda-structure
4568 'short-heading
4569 (concat "ToDo: "
4570 (or org-select-this-todo-keyword "ALL"))))
4571 (org-agenda-mark-header-line (point-min))
4572 (setq pos (point))
4573 (insert (or org-select-this-todo-keyword "ALL") "\n")
4574 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4575 (setq pos (point))
4576 (unless org-agenda-multi
4577 (insert "Available with `N r': (0)[ALL]")
4578 (let ((n 0) s)
4579 (mapc (lambda (x)
4580 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4581 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4582 (insert "\n "))
4583 (insert " " s))
4584 kwds))
4585 (insert "\n"))
4586 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4587 (org-agenda-mark-header-line (point-min))
4588 (when rtnall
4589 (insert (org-agenda-finalize-entries rtnall) "\n"))
4590 (goto-char (point-min))
4591 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4592 (add-text-properties (point-min) (point-max)
4593 `(org-agenda-type todo
4594 org-last-args ,arg
4595 org-redo-cmd ,org-agenda-redo-command
4596 org-series-cmd ,org-cmd))
4597 (org-agenda-finalize)
4598 (setq buffer-read-only t))))
4600 (autoload 'org-todo-list "org-agenda" "\
4601 Show all (not done) TODO entries from all agenda file in a single list.
4602 The prefix arg can be used to select a specific TODO keyword and limit
4603 the list to these. When using \\[universal-argument], you will be prompted
4604 for a keyword. A numeric prefix directly selects the Nth keyword in
4605 `org-todo-keywords-1'.
4607 \(fn &optional ARG)" t nil)
4609 ;;; Agenda tags match
4611 ;;;###autoload
4612 (defun org-tags-view (&optional todo-only match)
4613 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4614 The prefix arg TODO-ONLY limits the search to TODO entries."
4615 (interactive "P")
4616 (if org-agenda-overriding-arguments
4617 (setq todo-only (car org-agenda-overriding-arguments)
4618 match (nth 1 org-agenda-overriding-arguments)))
4619 (let* ((org-tags-match-list-sublevels
4620 org-tags-match-list-sublevels)
4621 (completion-ignore-case t)
4622 rtn rtnall files file pos matcher
4623 buffer)
4624 (when (and (stringp match) (not (string-match "\\S-" match)))
4625 (setq match nil))
4626 (setq matcher (org-make-tags-matcher match)
4627 match (car matcher) matcher (cdr matcher))
4628 (catch 'exit
4629 (if org-agenda-sticky
4630 (setq org-agenda-buffer-name
4631 (if (stringp match)
4632 (format "*Org Agenda(%s:%s)*"
4633 (or org-keys (or (and todo-only "M") "m")) match)
4634 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4635 (org-agenda-prepare (concat "TAGS " match))
4636 (org-compile-prefix-format 'tags)
4637 (org-set-sorting-strategy 'tags)
4638 (setq org-agenda-query-string match)
4639 (setq org-agenda-redo-command
4640 (list 'org-tags-view `(quote ,todo-only)
4641 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4642 (setq files (org-agenda-files nil 'ifmode)
4643 rtnall nil)
4644 (while (setq file (pop files))
4645 (catch 'nextfile
4646 (org-check-agenda-file file)
4647 (setq buffer (if (file-exists-p file)
4648 (org-get-agenda-file-buffer file)
4649 (error "No such file %s" file)))
4650 (if (not buffer)
4651 ;; If file does not exist, error message to agenda
4652 (setq rtn (list
4653 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4654 rtnall (append rtnall rtn))
4655 (with-current-buffer buffer
4656 (unless (derived-mode-p 'org-mode)
4657 (error "Agenda file %s is not in `org-mode'" file))
4658 (save-excursion
4659 (save-restriction
4660 (if org-agenda-restrict
4661 (narrow-to-region org-agenda-restrict-begin
4662 org-agenda-restrict-end)
4663 (widen))
4664 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4665 (setq rtnall (append rtnall rtn))))))))
4666 (if org-agenda-overriding-header
4667 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4668 nil 'face 'org-agenda-structure) "\n")
4669 (insert "Headlines with TAGS match: ")
4670 (add-text-properties (point-min) (1- (point))
4671 (list 'face 'org-agenda-structure
4672 'short-heading
4673 (concat "Match: " match)))
4674 (setq pos (point))
4675 (insert match "\n")
4676 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4677 (setq pos (point))
4678 (unless org-agenda-multi
4679 (insert "Press `C-u r' to search again with new search string\n"))
4680 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4681 (org-agenda-mark-header-line (point-min))
4682 (when rtnall
4683 (insert (org-agenda-finalize-entries rtnall) "\n"))
4684 (goto-char (point-min))
4685 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4686 (add-text-properties (point-min) (point-max)
4687 `(org-agenda-type tags
4688 org-last-args (,todo-only ,match)
4689 org-redo-cmd ,org-agenda-redo-command
4690 org-series-cmd ,org-cmd))
4691 (org-agenda-finalize)
4692 (setq buffer-read-only t))))
4694 (autoload 'org-tags-view "org-agenda" "\
4695 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4696 The prefix arg TODO-ONLY limits the search to TODO entries.
4698 \(fn &optional TODO-ONLY MATCH)" t nil)
4700 ;;; Agenda Finding stuck projects
4702 (defvar org-agenda-skip-regexp nil
4703 "Regular expression used in skipping subtrees for the agenda.
4704 This is basically a temporary global variable that can be set and then
4705 used by user-defined selections using `org-agenda-skip-function'.")
4707 (defvar org-agenda-overriding-header nil
4708 "When set during agenda, todo and tags searches it replaces the header.
4709 This variable should not be set directly, but custom commands can bind it
4710 in the options section.")
4712 (defun org-agenda-skip-entry-when-regexp-matches ()
4713 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4714 If yes, it returns the end position of this entry, causing agenda commands
4715 to skip the entry but continuing the search in the subtree. This is a
4716 function that can be put into `org-agenda-skip-function' for the duration
4717 of a command."
4718 (let ((end (save-excursion (org-end-of-subtree t)))
4719 skip)
4720 (save-excursion
4721 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4722 (and skip end)))
4724 (defun org-agenda-skip-subtree-when-regexp-matches ()
4725 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4726 If yes, it returns the end position of this tree, causing agenda commands
4727 to skip this subtree. This is a function that can be put into
4728 `org-agenda-skip-function' for the duration of a command."
4729 (let ((end (save-excursion (org-end-of-subtree t)))
4730 skip)
4731 (save-excursion
4732 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4733 (and skip end)))
4735 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4736 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4737 If yes, it returns the end position of the current entry (NOT the tree),
4738 causing agenda commands to skip the entry but continuing the search in
4739 the subtree. This is a function that can be put into
4740 `org-agenda-skip-function' for the duration of a command. An important
4741 use of this function is for the stuck project list."
4742 (let ((end (save-excursion (org-end-of-subtree t)))
4743 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4744 skip)
4745 (save-excursion
4746 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4747 (and skip entry-end)))
4749 (defun org-agenda-skip-entry-if (&rest conditions)
4750 "Skip entry if any of CONDITIONS is true.
4751 See `org-agenda-skip-if' for details."
4752 (org-agenda-skip-if nil conditions))
4754 (defun org-agenda-skip-subtree-if (&rest conditions)
4755 "Skip entry if any of CONDITIONS is true.
4756 See `org-agenda-skip-if' for details."
4757 (org-agenda-skip-if t conditions))
4759 (defun org-agenda-skip-if (subtree conditions)
4760 "Checks current entity for CONDITIONS.
4761 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4762 the entry (i.e. the text before the next heading) is checked.
4764 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4765 from different tests. Valid conditions are:
4767 scheduled Check if there is a scheduled cookie
4768 notscheduled Check if there is no scheduled cookie
4769 deadline Check if there is a deadline
4770 notdeadline Check if there is no deadline
4771 timestamp Check if there is a timestamp (also deadline or scheduled)
4772 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4773 regexp Check if regexp matches
4774 notregexp Check if regexp does not match.
4775 todo Check if TODO keyword matches
4776 nottodo Check if TODO keyword does not match
4778 The regexp is taken from the conditions list, it must come right after
4779 the `regexp' or `notregexp' element.
4781 `todo' and `nottodo' accept as an argument a list of todo
4782 keywords, which may include \"*\" to match any todo keyword.
4784 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4786 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4788 Instead of a list, a keyword class may be given. For example:
4790 (org-agenda-skip-entry-if 'nottodo 'done)
4792 would skip entries that haven't been marked with any of \"DONE\"
4793 keywords. Possible classes are: `todo', `done', `any'.
4795 If any of these conditions is met, this function returns the end point of
4796 the entity, causing the search to continue from there. This is a function
4797 that can be put into `org-agenda-skip-function' for the duration of a command."
4798 (let (beg end m)
4799 (org-back-to-heading t)
4800 (setq beg (point)
4801 end (if subtree
4802 (progn (org-end-of-subtree t) (point))
4803 (progn (outline-next-heading) (1- (point)))))
4804 (goto-char beg)
4805 (and
4807 (and (memq 'scheduled conditions)
4808 (re-search-forward org-scheduled-time-regexp end t))
4809 (and (memq 'notscheduled conditions)
4810 (not (re-search-forward org-scheduled-time-regexp end t)))
4811 (and (memq 'deadline conditions)
4812 (re-search-forward org-deadline-time-regexp end t))
4813 (and (memq 'notdeadline conditions)
4814 (not (re-search-forward org-deadline-time-regexp end t)))
4815 (and (memq 'timestamp conditions)
4816 (re-search-forward org-ts-regexp end t))
4817 (and (memq 'nottimestamp conditions)
4818 (not (re-search-forward org-ts-regexp end t)))
4819 (and (setq m (memq 'regexp conditions))
4820 (stringp (nth 1 m))
4821 (re-search-forward (nth 1 m) end t))
4822 (and (setq m (memq 'notregexp conditions))
4823 (stringp (nth 1 m))
4824 (not (re-search-forward (nth 1 m) end t)))
4825 (and (or
4826 (setq m (memq 'nottodo conditions))
4827 (setq m (memq 'todo-unblocked conditions))
4828 (setq m (memq 'nottodo-unblocked conditions))
4829 (setq m (memq 'todo conditions)))
4830 (org-agenda-skip-if-todo m end)))
4831 end)))
4833 (defun org-agenda-skip-if-todo (args end)
4834 "Helper function for `org-agenda-skip-if', do not use it directly.
4835 ARGS is a list with first element either `todo', `nottodo',
4836 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4837 a list of TODO keywords, or a state symbol `todo' or `done' or
4838 `any'."
4839 (let ((kw (car args))
4840 (arg (cadr args))
4841 todo-wds todo-re)
4842 (setq todo-wds
4843 (org-uniquify
4844 (cond
4845 ((listp arg) ;; list of keywords
4846 (if (member "*" arg)
4847 (mapcar 'substring-no-properties org-todo-keywords-1)
4848 arg))
4849 ((symbolp arg) ;; keyword class name
4850 (cond
4851 ((eq arg 'todo)
4852 (org-delete-all org-done-keywords
4853 (mapcar 'substring-no-properties
4854 org-todo-keywords-1)))
4855 ((eq arg 'done) org-done-keywords)
4856 ((eq arg 'any)
4857 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4858 (setq todo-re
4859 (concat "^\\*+[ \t]+\\<\\("
4860 (mapconcat 'identity todo-wds "\\|")
4861 "\\)\\>"))
4862 (cond
4863 ((eq kw 'todo) (re-search-forward todo-re end t))
4864 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4865 ((eq kw 'todo-unblocked)
4866 (catch 'unblocked
4867 (while (re-search-forward todo-re end t)
4868 (or (org-entry-blocked-p) (throw 'unblocked t)))
4869 nil))
4870 ((eq kw 'nottodo-unblocked)
4871 (catch 'unblocked
4872 (while (re-search-forward todo-re end t)
4873 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4877 ;;;###autoload
4878 (defun org-agenda-list-stuck-projects (&rest ignore)
4879 "Create agenda view for projects that are stuck.
4880 Stuck projects are project that have no next actions. For the definitions
4881 of what a project is and how to check if it stuck, customize the variable
4882 `org-stuck-projects'."
4883 (interactive)
4884 (let* ((org-agenda-skip-function
4885 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4886 ;; We could have used org-agenda-skip-if here.
4887 (org-agenda-overriding-header
4888 (or org-agenda-overriding-header "List of stuck projects: "))
4889 (matcher (nth 0 org-stuck-projects))
4890 (todo (nth 1 org-stuck-projects))
4891 (todo-wds (if (member "*" todo)
4892 (progn
4893 (org-agenda-prepare-buffers (org-agenda-files
4894 nil 'ifmode))
4895 (org-delete-all
4896 org-done-keywords-for-agenda
4897 (copy-sequence org-todo-keywords-for-agenda)))
4898 todo))
4899 (todo-re (concat "^\\*+[ \t]+\\("
4900 (mapconcat 'identity todo-wds "\\|")
4901 "\\)\\>"))
4902 (tags (nth 2 org-stuck-projects))
4903 (tags-re (if (member "*" tags)
4904 (concat org-outline-regexp-bol
4905 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4906 (if tags
4907 (concat org-outline-regexp-bol
4908 ".*:\\("
4909 (mapconcat 'identity tags "\\|")
4910 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4911 (gen-re (nth 3 org-stuck-projects))
4912 (re-list
4913 (delq nil
4914 (list
4915 (if todo todo-re)
4916 (if tags tags-re)
4917 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4918 gen-re)))))
4919 (setq org-agenda-skip-regexp
4920 (if re-list
4921 (mapconcat 'identity re-list "\\|")
4922 (error "No information how to identify unstuck projects")))
4923 (org-tags-view nil matcher)
4924 (with-current-buffer org-agenda-buffer-name
4925 (setq org-agenda-redo-command
4926 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4928 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4929 Create agenda view for projects that are stuck.
4930 Stuck projects are project that have no next actions. For the definitions
4931 of what a project is and how to check if it stuck, customize the variable
4932 `org-stuck-projects'.
4934 \(fn &rest IGNORE)" t nil)
4936 ;;; Diary integration
4938 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4939 (defvar diary-list-entries-hook)
4940 (defvar diary-time-regexp)
4941 (defun org-get-entries-from-diary (date)
4942 "Get the (Emacs Calendar) diary entries for DATE."
4943 (require 'diary-lib)
4944 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4945 (diary-display-hook '(fancy-diary-display))
4946 (diary-display-function 'fancy-diary-display)
4947 (pop-up-frames nil)
4948 (diary-list-entries-hook
4949 (cons 'org-diary-default-entry diary-list-entries-hook))
4950 (diary-file-name-prefix-function nil) ; turn this feature off
4951 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4952 entries
4953 (org-disable-agenda-to-diary t))
4954 (save-excursion
4955 (save-window-excursion
4956 (funcall (if (fboundp 'diary-list-entries)
4957 'diary-list-entries 'list-diary-entries)
4958 date 1)))
4959 (if (not (get-buffer diary-fancy-buffer))
4960 (setq entries nil)
4961 (with-current-buffer diary-fancy-buffer
4962 (setq buffer-read-only nil)
4963 (if (zerop (buffer-size))
4964 ;; No entries
4965 (setq entries nil)
4966 ;; Omit the date and other unnecessary stuff
4967 (org-agenda-cleanup-fancy-diary)
4968 ;; Add prefix to each line and extend the text properties
4969 (if (zerop (buffer-size))
4970 (setq entries nil)
4971 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4972 (setq entries
4973 (with-temp-buffer
4974 (insert entries) (goto-char (point-min))
4975 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4976 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4977 (replace-match (concat "; " (match-string 1)))))
4978 (buffer-string)))))
4979 (set-buffer-modified-p nil)
4980 (kill-buffer diary-fancy-buffer)))
4981 (when entries
4982 (setq entries (org-split-string entries "\n"))
4983 (setq entries
4984 (mapcar
4985 (lambda (x)
4986 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
4987 ;; Extend the text properties to the beginning of the line
4988 (org-add-props x (text-properties-at (1- (length x)) x)
4989 'type "diary" 'date date 'face 'org-agenda-diary))
4990 entries)))))
4992 (defvar org-agenda-cleanup-fancy-diary-hook nil
4993 "Hook run when the fancy diary buffer is cleaned up.")
4995 (defun org-agenda-cleanup-fancy-diary ()
4996 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4997 This gets rid of the date, the underline under the date, and
4998 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4999 date. It also removes lines that contain only whitespace."
5000 (goto-char (point-min))
5001 (if (looking-at ".*?:[ \t]*")
5002 (progn
5003 (replace-match "")
5004 (re-search-forward "\n=+$" nil t)
5005 (replace-match "")
5006 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5007 (re-search-forward "\n=+$" nil t)
5008 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5009 (goto-char (point-min))
5010 (while (re-search-forward "^ +\n" nil t)
5011 (replace-match ""))
5012 (goto-char (point-min))
5013 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5014 (replace-match ""))
5015 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5017 ;; Make sure entries from the diary have the right text properties.
5018 (eval-after-load "diary-lib"
5019 '(if (boundp 'diary-modify-entry-list-string-function)
5020 ;; We can rely on the hook, nothing to do
5022 ;; Hook not available, must use advice to make this work
5023 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5024 "Make the position visible."
5025 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5026 (stringp string)
5027 buffer-file-name)
5028 (setq string (org-modify-diary-entry-string string))))))
5030 (defun org-modify-diary-entry-string (string)
5031 "Add text properties to string, allowing org-mode to act on it."
5032 (org-add-props string nil
5033 'mouse-face 'highlight
5034 'help-echo (if buffer-file-name
5035 (format "mouse-2 or RET jump to diary file %s"
5036 (abbreviate-file-name buffer-file-name))
5038 'org-agenda-diary-link t
5039 'org-marker (org-agenda-new-marker (point-at-bol))))
5041 (defun org-diary-default-entry ()
5042 "Add a dummy entry to the diary.
5043 Needed to avoid empty dates which mess up holiday display."
5044 ;; Catch the error if dealing with the new add-to-diary-alist
5045 (when org-disable-agenda-to-diary
5046 (condition-case nil
5047 (org-add-to-diary-list original-date "Org-mode dummy" "")
5048 (error
5049 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5051 (defun org-add-to-diary-list (&rest args)
5052 (if (fboundp 'diary-add-to-list)
5053 (apply 'diary-add-to-list args)
5054 (apply 'add-to-diary-list args)))
5056 (defvar org-diary-last-run-time nil)
5058 ;;;###autoload
5059 (defun org-diary (&rest args)
5060 "Return diary information from org files.
5061 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5062 It accesses org files and extracts information from those files to be
5063 listed in the diary. The function accepts arguments specifying what
5064 items should be listed. For a list of arguments allowed here, see the
5065 variable `org-agenda-entry-types'.
5067 The call in the diary file should look like this:
5069 &%%(org-diary) ~/path/to/some/orgfile.org
5071 Use a separate line for each org file to check. Or, if you omit the file name,
5072 all files listed in `org-agenda-files' will be checked automatically:
5074 &%%(org-diary)
5076 If you don't give any arguments (as in the example above), the default
5077 arguments (:deadline :scheduled :timestamp :sexp) are used.
5078 So the example above may also be written as
5080 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5082 The function expects the lisp variables `entry' and `date' to be provided
5083 by the caller, because this is how the calendar works. Don't use this
5084 function from a program - use `org-agenda-get-day-entries' instead."
5085 (when (> (- (org-float-time)
5086 org-agenda-last-marker-time)
5088 ;; I am not sure if this works with sticky agendas, because the marker
5089 ;; list is then no longer a global variable.
5090 (org-agenda-reset-markers))
5091 (org-compile-prefix-format 'agenda)
5092 (org-set-sorting-strategy 'agenda)
5093 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5094 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5095 (list entry)
5096 (org-agenda-files t)))
5097 (time (org-float-time))
5098 file rtn results)
5099 (when (or (not org-diary-last-run-time)
5100 (> (- time
5101 org-diary-last-run-time)
5103 (org-agenda-prepare-buffers files))
5104 (setq org-diary-last-run-time time)
5105 ;; If this is called during org-agenda, don't return any entries to
5106 ;; the calendar. Org Agenda will list these entries itself.
5107 (if org-disable-agenda-to-diary (setq files nil))
5108 (while (setq file (pop files))
5109 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5110 (setq results (append results rtn)))
5111 (if results
5112 (concat (org-agenda-finalize-entries results) "\n"))))
5114 (autoload 'org-diary "org-agenda" "\
5115 Return diary information from org files.
5116 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5117 It accesses org files and extracts information from those files to be
5118 listed in the diary. The function accepts arguments specifying what
5119 items should be listed. For a list of arguments allowed here, see the
5120 variable `org-agenda-entry-types'.
5122 The call in the diary file should look like this:
5124 &%%(org-diary) ~/path/to/some/orgfile.org
5126 Use a separate line for each org file to check. Or, if you omit the file name,
5127 all files listed in `org-agenda-files' will be checked automatically:
5129 &%%(org-diary)
5131 If you don't give any arguments (as in the example above), the default
5132 arguments (:deadline :scheduled :timestamp :sexp) are used.
5133 So the example above may also be written as
5135 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5137 The function expects the lisp variables `entry' and `date' to be provided
5138 by the caller, because this is how the calendar works. Don't use this
5139 function from a program - use `org-agenda-get-day-entries' instead.
5141 \(fn &rest ARGS)" nil nil)
5143 ;;; Agenda entry finders
5145 (defun org-agenda-get-day-entries (file date &rest args)
5146 "Does the work for `org-diary' and `org-agenda'.
5147 FILE is the path to a file to be checked for entries. DATE is date like
5148 the one returned by `calendar-current-date'. ARGS are symbols indicating
5149 which kind of entries should be extracted. For details about these, see
5150 the documentation of `org-diary'."
5151 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5152 (let* ((org-startup-folded nil)
5153 (org-startup-align-all-tables nil)
5154 (buffer (if (file-exists-p file)
5155 (org-get-agenda-file-buffer file)
5156 (error "No such file %s" file)))
5157 arg results rtn deadline-results)
5158 (if (not buffer)
5159 ;; If file does not exist, make sure an error message ends up in diary
5160 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5161 (with-current-buffer buffer
5162 (unless (derived-mode-p 'org-mode)
5163 (error "Agenda file %s is not in `org-mode'" file))
5164 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5165 (let ((case-fold-search nil))
5166 (save-excursion
5167 (save-restriction
5168 (if org-agenda-restrict
5169 (narrow-to-region org-agenda-restrict-begin
5170 org-agenda-restrict-end)
5171 (widen))
5172 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5173 (while (setq arg (pop args))
5174 (cond
5175 ((and (eq arg :todo)
5176 (equal date (calendar-gregorian-from-absolute
5177 (org-today))))
5178 (setq rtn (org-agenda-get-todos))
5179 (setq results (append results rtn)))
5180 ((eq arg :timestamp)
5181 (setq rtn (org-agenda-get-blocks))
5182 (setq results (append results rtn))
5183 (setq rtn (org-agenda-get-timestamps deadline-results))
5184 (setq results (append results rtn)))
5185 ((eq arg :sexp)
5186 (setq rtn (org-agenda-get-sexps))
5187 (setq results (append results rtn)))
5188 ((eq arg :scheduled)
5189 (setq rtn (org-agenda-get-scheduled deadline-results))
5190 (setq results (append results rtn)))
5191 ((eq arg :closed)
5192 (setq rtn (org-agenda-get-progress))
5193 (setq results (append results rtn)))
5194 ((eq arg :deadline)
5195 (setq rtn (org-agenda-get-deadlines))
5196 (setq deadline-results (copy-sequence rtn))
5197 (setq results (append results rtn))))))))
5198 results))))
5200 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5201 (defun org-agenda-get-todos ()
5202 "Return the TODO information for agenda display."
5203 (let* ((props (list 'face nil
5204 'done-face 'org-agenda-done
5205 'org-not-done-regexp org-not-done-regexp
5206 'org-todo-regexp org-todo-regexp
5207 'org-complex-heading-regexp org-complex-heading-regexp
5208 'mouse-face 'highlight
5209 'help-echo
5210 (format "mouse-2 or RET jump to org file %s"
5211 (abbreviate-file-name buffer-file-name))))
5212 (regexp (format org-heading-keyword-regexp-format
5213 (cond
5214 ((and org-select-this-todo-keyword
5215 (equal org-select-this-todo-keyword "*"))
5216 org-todo-regexp)
5217 (org-select-this-todo-keyword
5218 (concat "\\("
5219 (mapconcat 'identity
5220 (org-split-string
5221 org-select-this-todo-keyword
5222 "|")
5223 "\\|") "\\)"))
5224 (t org-not-done-regexp))))
5225 marker priority category category-pos level tags todo-state
5226 ee txt beg end)
5227 (goto-char (point-min))
5228 (while (re-search-forward regexp nil t)
5229 (catch :skip
5230 (save-match-data
5231 (beginning-of-line)
5232 (org-agenda-skip)
5233 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5234 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5235 (goto-char (1+ beg))
5236 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5237 (throw :skip nil)))
5238 (goto-char (match-beginning 2))
5239 (setq marker (org-agenda-new-marker (match-beginning 0))
5240 category (org-get-category)
5241 category-pos (get-text-property (point) 'org-category-position)
5242 txt (org-trim
5243 (buffer-substring (match-beginning 2) (match-end 0)))
5244 tags (org-get-tags-at (point))
5245 level (make-string (org-reduced-level (org-outline-level)) ? )
5246 txt (org-agenda-format-item "" txt level category tags t)
5247 priority (1+ (org-get-priority txt))
5248 todo-state (org-get-todo-state))
5249 (org-add-props txt props
5250 'org-marker marker 'org-hd-marker marker
5251 'priority priority 'org-category category
5252 'level level
5253 'org-category-position category-pos
5254 'type "todo" 'todo-state todo-state)
5255 (push txt ee)
5256 (if org-agenda-todo-list-sublevels
5257 (goto-char (match-end 2))
5258 (org-end-of-subtree 'invisible))))
5259 (nreverse ee)))
5261 (defun org-agenda-todo-custom-ignore-p (time n)
5262 "Check whether timestamp is farther away than n number of days.
5263 This function is invoked if `org-agenda-todo-ignore-deadlines',
5264 `org-agenda-todo-ignore-scheduled' or
5265 `org-agenda-todo-ignore-timestamp' is set to an integer."
5266 (let ((days (org-time-stamp-to-now
5267 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5268 (if (>= n 0)
5269 (>= days n)
5270 (<= days n))))
5272 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5273 (&optional end)
5274 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5275 (when (or org-agenda-todo-ignore-with-date
5276 org-agenda-todo-ignore-scheduled
5277 org-agenda-todo-ignore-deadlines
5278 org-agenda-todo-ignore-timestamp)
5279 (setq end (or end (save-excursion (outline-next-heading) (point))))
5280 (save-excursion
5281 (or (and org-agenda-todo-ignore-with-date
5282 (re-search-forward org-ts-regexp end t))
5283 (and org-agenda-todo-ignore-scheduled
5284 (re-search-forward org-scheduled-time-regexp end t)
5285 (cond
5286 ((eq org-agenda-todo-ignore-scheduled 'future)
5287 (> (org-time-stamp-to-now
5288 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5289 ((eq org-agenda-todo-ignore-scheduled 'past)
5290 (<= (org-time-stamp-to-now
5291 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5292 ((numberp org-agenda-todo-ignore-scheduled)
5293 (org-agenda-todo-custom-ignore-p
5294 (match-string 1) org-agenda-todo-ignore-scheduled))
5295 (t)))
5296 (and org-agenda-todo-ignore-deadlines
5297 (re-search-forward org-deadline-time-regexp end t)
5298 (cond
5299 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5300 ((eq org-agenda-todo-ignore-deadlines 'far)
5301 (not (org-deadline-close (match-string 1))))
5302 ((eq org-agenda-todo-ignore-deadlines 'future)
5303 (> (org-time-stamp-to-now
5304 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5305 ((eq org-agenda-todo-ignore-deadlines 'past)
5306 (<= (org-time-stamp-to-now
5307 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5308 ((numberp org-agenda-todo-ignore-deadlines)
5309 (org-agenda-todo-custom-ignore-p
5310 (match-string 1) org-agenda-todo-ignore-deadlines))
5311 (t (org-deadline-close (match-string 1)))))
5312 (and org-agenda-todo-ignore-timestamp
5313 (let ((buffer (current-buffer))
5314 (regexp
5315 (concat
5316 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5317 (start (point)))
5318 ;; Copy current buffer into a temporary one
5319 (with-temp-buffer
5320 (insert-buffer-substring buffer start end)
5321 (goto-char (point-min))
5322 ;; Delete SCHEDULED and DEADLINE items
5323 (while (re-search-forward regexp end t)
5324 (delete-region (match-beginning 0) (match-end 0)))
5325 (goto-char (point-min))
5326 ;; No search for timestamp left
5327 (when (re-search-forward org-ts-regexp nil t)
5328 (cond
5329 ((eq org-agenda-todo-ignore-timestamp 'future)
5330 (> (org-time-stamp-to-now
5331 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5332 ((eq org-agenda-todo-ignore-timestamp 'past)
5333 (<= (org-time-stamp-to-now
5334 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5335 ((numberp org-agenda-todo-ignore-timestamp)
5336 (org-agenda-todo-custom-ignore-p
5337 (match-string 1) org-agenda-todo-ignore-timestamp))
5338 (t))))))))))
5340 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5341 Do we have a reason to ignore this TODO entry because it has a time stamp?
5343 \(fn &optional END)" nil nil)
5345 (defconst org-agenda-no-heading-message
5346 "No heading for this item in buffer or region.")
5348 (defun org-agenda-get-timestamps (&optional deadline-results)
5349 "Return the date stamp information for agenda display."
5350 (let* ((props (list 'face 'org-agenda-calendar-event
5351 'org-not-done-regexp org-not-done-regexp
5352 'org-todo-regexp org-todo-regexp
5353 'org-complex-heading-regexp org-complex-heading-regexp
5354 'mouse-face 'highlight
5355 'help-echo
5356 (format "mouse-2 or RET jump to org file %s"
5357 (abbreviate-file-name buffer-file-name))))
5358 (d1 (calendar-absolute-from-gregorian date))
5360 (deadline-position-alist
5361 (mapcar (lambda (a) (and (setq mm (get-text-property
5362 0 'org-hd-marker a))
5363 (cons (marker-position mm) a)))
5364 deadline-results))
5365 (remove-re org-ts-regexp)
5366 (regexp
5367 (concat
5368 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5369 (regexp-quote
5370 (substring
5371 (format-time-string
5372 (car org-time-stamp-formats)
5373 (apply 'encode-time ; DATE bound by calendar
5374 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5375 1 11))
5376 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5377 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5378 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5379 donep tmp priority category category-pos level ee txt timestr tags
5380 b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
5381 (goto-char (point-min))
5382 (while (setq end-of-match (re-search-forward regexp nil t))
5383 (setq b0 (match-beginning 0)
5384 b3 (match-beginning 3) e3 (match-end 3)
5385 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5386 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5387 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5388 (member todo-state
5389 org-agenda-repeating-timestamp-show-all)))
5390 (catch :skip
5391 (and (org-at-date-range-p) (throw :skip nil))
5392 (org-agenda-skip)
5393 (if (and (match-end 1)
5394 (not (= d1 (org-time-string-to-absolute
5395 (match-string 1) d1 nil show-all
5396 (current-buffer) b0))))
5397 (throw :skip nil))
5398 (if (and e3
5399 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5400 (throw :skip nil))
5401 (setq tmp (buffer-substring (max (point-min)
5402 (- b0 org-ds-keyword-length))
5404 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5405 inactivep (= (char-after b0) ?\[)
5406 deadlinep (string-match org-deadline-regexp tmp)
5407 scheduledp (string-match org-scheduled-regexp tmp)
5408 closedp (and org-agenda-include-inactive-timestamps
5409 (string-match org-closed-string tmp))
5410 clockp (and org-agenda-include-inactive-timestamps
5411 (or (string-match org-clock-string tmp)
5412 (string-match "]-+\\'" tmp)))
5413 warntime (org-entry-get (point) "APPT_WARNTIME")
5414 donep (member todo-state org-done-keywords))
5415 (if (or scheduledp deadlinep closedp clockp
5416 (and donep org-agenda-skip-timestamp-if-done))
5417 (throw :skip t))
5418 (if (string-match ">" timestr)
5419 ;; substring should only run to end of time stamp
5420 (setq timestr (substring timestr 0 (match-end 0))))
5421 (setq marker (org-agenda-new-marker b0)
5422 category (org-get-category b0)
5423 category-pos (get-text-property b0 'org-category-position))
5424 (save-excursion
5425 (if (not (re-search-backward org-outline-regexp-bol nil t))
5426 (setq txt org-agenda-no-heading-message)
5427 (goto-char (match-beginning 0))
5428 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5429 (assoc (point) deadline-position-alist))
5430 (throw :skip nil))
5431 (setq hdmarker (org-agenda-new-marker)
5432 tags (org-get-tags-at)
5433 level (make-string (org-reduced-level (org-outline-level)) ? ))
5434 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5435 (setq head (or (match-string 1) ""))
5436 (setq txt (org-agenda-format-item
5437 (if inactivep org-agenda-inactive-leader nil)
5438 head level category tags timestr
5439 remove-re habitp)))
5440 (setq priority (org-get-priority txt))
5441 (org-add-props txt props 'priority priority
5442 'org-marker marker 'org-hd-marker hdmarker
5443 'org-category category 'date date
5444 'level level
5445 'org-category-position category-pos
5446 'todo-state todo-state
5447 'warntime warntime
5448 'type "timestamp")
5449 (push txt ee))
5450 (if org-agenda-skip-additional-timestamps-same-entry
5451 (outline-next-heading)
5452 (goto-char end-of-match))))
5453 (nreverse ee)))
5455 (defun org-agenda-get-sexps ()
5456 "Return the sexp information for agenda display."
5457 (require 'diary-lib)
5458 (let* ((props (list 'face 'org-agenda-calendar-sexp
5459 'mouse-face 'highlight
5460 'help-echo
5461 (format "mouse-2 or RET jump to org file %s"
5462 (abbreviate-file-name buffer-file-name))))
5463 (regexp "^&?%%(")
5464 marker category extra category-pos level ee txt tags entry
5465 result beg b sexp sexp-entry todo-state warntime)
5466 (goto-char (point-min))
5467 (while (re-search-forward regexp nil t)
5468 (catch :skip
5469 (org-agenda-skip)
5470 (setq beg (match-beginning 0))
5471 (goto-char (1- (match-end 0)))
5472 (setq b (point))
5473 (forward-sexp 1)
5474 (setq sexp (buffer-substring b (point)))
5475 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5476 (org-trim (match-string 1))
5477 ""))
5478 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5479 (when result
5480 (setq marker (org-agenda-new-marker beg)
5481 level (make-string (org-reduced-level (org-outline-level)) ? )
5482 category (org-get-category beg)
5483 category-pos (get-text-property beg 'org-category-position)
5484 tags (save-excursion (org-backward-heading-same-level 0)
5485 (org-get-tags-at))
5486 todo-state (org-get-todo-state)
5487 warntime (org-entry-get (point) "APPT_WARNTIME")
5488 extra nil)
5490 (dolist (r (if (stringp result)
5491 (list result)
5492 result)) ;; we expect a list here
5493 (when (and org-agenda-diary-sexp-prefix
5494 (string-match org-agenda-diary-sexp-prefix r))
5495 (setq extra (match-string 0 r)
5496 r (replace-match "" nil nil r)))
5497 (if (string-match "\\S-" r)
5498 (setq txt r)
5499 (setq txt "SEXP entry returned empty string"))
5500 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5501 (org-add-props txt props 'org-marker marker
5502 'org-category category 'date date 'todo-state todo-state
5503 'org-category-position category-pos 'tags tags
5504 'level level
5505 'type "sexp" 'warntime warntime)
5506 (push txt ee)))))
5507 (nreverse ee)))
5509 ;; Calendar sanity: define some functions that are independent of
5510 ;; `calendar-date-style'.
5511 ;; Normally I would like to use ISO format when calling the diary functions,
5512 ;; but to make sure we still have Emacs 22 compatibility we bind
5513 ;; also `european-calendar-style' and use european format
5514 (defun org-anniversary (year month day &optional mark)
5515 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5516 (org-no-warnings
5517 (let ((calendar-date-style 'european) (european-calendar-style t))
5518 (diary-anniversary day month year mark))))
5519 (defun org-cyclic (N year month day &optional mark)
5520 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5521 (org-no-warnings
5522 (let ((calendar-date-style 'european) (european-calendar-style t))
5523 (diary-cyclic N day month year mark))))
5524 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5525 "Like `diary-block', but with fixed (ISO) order of arguments."
5526 (org-no-warnings
5527 (let ((calendar-date-style 'european) (european-calendar-style t))
5528 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5529 (defun org-date (year month day &optional mark)
5530 "Like `diary-date', but with fixed (ISO) order of arguments."
5531 (org-no-warnings
5532 (let ((calendar-date-style 'european) (european-calendar-style t))
5533 (diary-date day month year mark))))
5534 (defalias 'org-float 'diary-float)
5536 ;; Define the` org-class' function
5537 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5538 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5539 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5540 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5541 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5542 `holidays', then any date that is known by the Emacs calendar to be a
5543 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5544 then those holidays will be skipped."
5545 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5546 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5547 (d (calendar-absolute-from-gregorian date))
5548 (h (when skip-weeks (calendar-check-holidays date))))
5549 (and
5550 (<= date1 d)
5551 (<= d date2)
5552 (= (calendar-day-of-week date) dayname)
5553 (or (not skip-weeks)
5554 (progn
5555 (require 'cal-iso)
5556 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5557 (not (or (and h (memq 'holidays skip-weeks))
5558 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5559 entry)))
5561 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5562 "Like `org-class', but honor `calendar-date-style'.
5563 The order of the first 2 times 3 arguments depends on the variable
5564 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5565 So for American calendars, give this as MONTH DAY YEAR, for European as
5566 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5567 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5568 is any number of ISO weeks in the block period for which the item should
5569 be skipped.
5571 This function is here only for backward compatibility and it is deprecated,
5572 please use `org-class' instead."
5573 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5574 (date2 (org-order-calendar-date-args m2 d2 y2)))
5575 (org-class
5576 (nth 2 date1) (car date1) (nth 1 date1)
5577 (nth 2 date2) (car date2) (nth 1 date2)
5578 dayname skip-weeks)))
5579 (make-obsolete 'org-diary-class 'org-class "")
5581 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5582 (defalias 'org-get-closed 'org-agenda-get-progress)
5583 (defun org-agenda-get-progress ()
5584 "Return the logged TODO entries for agenda display."
5585 (let* ((props (list 'mouse-face 'highlight
5586 'org-not-done-regexp org-not-done-regexp
5587 'org-todo-regexp org-todo-regexp
5588 'org-complex-heading-regexp org-complex-heading-regexp
5589 'help-echo
5590 (format "mouse-2 or RET jump to org file %s"
5591 (abbreviate-file-name buffer-file-name))))
5592 (items (if (consp org-agenda-show-log-scoped)
5593 org-agenda-show-log-scoped
5594 (if (eq org-agenda-show-log-scoped 'clockcheck)
5595 '(clock)
5596 org-agenda-log-mode-items)))
5597 (parts
5598 (delq nil
5599 (list
5600 (if (memq 'closed items) (concat "\\<" org-closed-string))
5601 (if (memq 'clock items) (concat "\\<" org-clock-string))
5602 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5603 (parts-re (if parts (mapconcat 'identity parts "\\|")
5604 (error "`org-agenda-log-mode-items' is empty")))
5605 (regexp (concat
5606 "\\(" parts-re "\\)"
5607 " *\\["
5608 (regexp-quote
5609 (substring
5610 (format-time-string
5611 (car org-time-stamp-formats)
5612 (apply 'encode-time ; DATE bound by calendar
5613 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5614 1 11))))
5615 (org-agenda-search-headline-for-time nil)
5616 marker hdmarker priority category category-pos level tags closedp
5617 statep clockp state ee txt extra timestr rest clocked)
5618 (goto-char (point-min))
5619 (while (re-search-forward regexp nil t)
5620 (catch :skip
5621 (org-agenda-skip)
5622 (setq marker (org-agenda-new-marker (match-beginning 0))
5623 closedp (equal (match-string 1) org-closed-string)
5624 statep (equal (string-to-char (match-string 1)) ?-)
5625 clockp (not (or closedp statep))
5626 state (and statep (match-string 2))
5627 category (org-get-category (match-beginning 0))
5628 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5629 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5630 (when (string-match "\\]" timestr)
5631 ;; substring should only run to end of time stamp
5632 (setq rest (substring timestr (match-end 0))
5633 timestr (substring timestr 0 (match-end 0)))
5634 (if (and (not closedp) (not statep)
5635 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5636 rest))
5637 (progn (setq timestr (concat (substring timestr 0 -1)
5638 "-" (match-string 1 rest) "]"))
5639 (setq clocked (match-string 2 rest)))
5640 (setq clocked "-")))
5641 (save-excursion
5642 (setq extra
5643 (cond
5644 ((not org-agenda-log-mode-add-notes) nil)
5645 (statep
5646 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5647 (match-string 1)))
5648 (clockp
5649 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5650 (match-string 1)))))
5651 (if (not (re-search-backward org-outline-regexp-bol nil t))
5652 (setq txt org-agenda-no-heading-message)
5653 (goto-char (match-beginning 0))
5654 (setq hdmarker (org-agenda-new-marker)
5655 tags (org-get-tags-at)
5656 level (make-string (org-reduced-level (org-outline-level)) ? ))
5657 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5658 (setq txt (match-string 1))
5659 (when extra
5660 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5661 (setq txt (concat (substring txt 0 (match-beginning 1))
5662 " - " extra " " (match-string 2 txt)))
5663 (setq txt (concat txt " - " extra))))
5664 (setq txt (org-agenda-format-item
5665 (cond
5666 (closedp "Closed: ")
5667 (statep (concat "State: (" state ")"))
5668 (t (concat "Clocked: (" clocked ")")))
5669 txt level category tags timestr)))
5670 (setq priority 100000)
5671 (org-add-props txt props
5672 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5673 'priority priority 'org-category category
5674 'org-category-position category-pos
5675 'level level
5676 'type "closed" 'date date
5677 'undone-face 'org-warning 'done-face 'org-agenda-done)
5678 (push txt ee))
5679 (goto-char (point-at-eol))))
5680 (nreverse ee)))
5682 (defun org-agenda-show-clocking-issues ()
5683 "Add overlays, showing issues with clocking.
5684 See also the user option `org-agenda-clock-consistency-checks'."
5685 (interactive)
5686 (let* ((pl org-agenda-clock-consistency-checks)
5687 (re (concat "^[ \t]*"
5688 org-clock-string
5689 "[ \t]+"
5690 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5691 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5692 (tlstart 0.)
5693 (tlend 0.)
5694 (maxtime (org-hh:mm-string-to-minutes
5695 (or (plist-get pl :max-duration) "24:00")))
5696 (mintime (org-hh:mm-string-to-minutes
5697 (or (plist-get pl :min-duration) 0)))
5698 (maxgap (org-hh:mm-string-to-minutes
5699 ;; default 30:00 means never complain
5700 (or (plist-get pl :max-gap) "30:00")))
5701 (gapok (mapcar 'org-hh:mm-string-to-minutes
5702 (plist-get pl :gap-ok-around)))
5703 (def-face (or (plist-get pl :default-face)
5704 '((:background "DarkRed") (:foreground "white"))))
5705 issue face m te ts dt ov)
5706 (goto-char (point-min))
5707 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5708 (setq issue nil face def-face)
5709 (catch 'next
5710 (setq m (org-get-at-bol 'org-marker)
5711 te nil ts nil)
5712 (unless (and m (markerp m))
5713 (setq issue "No valid clock line") (throw 'next t))
5714 (org-with-point-at m
5715 (save-excursion
5716 (goto-char (point-at-bol))
5717 (unless (looking-at re)
5718 (error "No valid Clock line")
5719 (throw 'next t))
5720 (unless (match-end 3)
5721 (setq issue "No end time"
5722 face (or (plist-get pl :no-end-time-face) face))
5723 (throw 'next t))
5724 (setq ts (match-string 1)
5725 te (match-string 3)
5726 ts (org-float-time
5727 (apply 'encode-time (org-parse-time-string ts)))
5728 te (org-float-time
5729 (apply 'encode-time (org-parse-time-string te)))
5730 dt (- te ts))))
5731 (cond
5732 ((> dt (* 60 maxtime))
5733 ;; a very long clocking chunk
5734 (setq issue (format "Clocking interval is very long: %s"
5735 (org-minutes-to-clocksum-string
5736 (floor (/ (float dt) 60.))))
5737 face (or (plist-get pl :long-face) face)))
5738 ((< dt (* 60 mintime))
5739 ;; a very short clocking chunk
5740 (setq issue (format "Clocking interval is very short: %s"
5741 (org-minutes-to-clocksum-string
5742 (floor (/ (float dt) 60.))))
5743 face (or (plist-get pl :short-face) face)))
5744 ((and (> tlend 0) (< ts tlend))
5745 ;; Two clock entries are overlapping
5746 (setq issue (format "Clocking overlap: %d minutes"
5747 (/ (- tlend ts) 60))
5748 face (or (plist-get pl :overlap-face) face)))
5749 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5750 ;; There is a gap, lets see if we need to report it
5751 (unless (org-agenda-check-clock-gap tlend ts gapok)
5752 (setq issue (format "Clocking gap: %d minutes"
5753 (/ (- ts tlend) 60))
5754 face (or (plist-get pl :gap-face) face))))
5755 (t nil)))
5756 (setq tlend (or te tlend) tlstart (or ts tlstart))
5757 (when issue
5758 ;; OK, there was some issue, add an overlay to show the issue
5759 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5760 (overlay-put ov 'before-string
5761 (concat
5762 (org-add-props
5763 (format "%-43s" (concat " " issue))
5765 'face face)
5766 "\n"))
5767 (overlay-put ov 'evaporate t)))))
5769 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5770 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5771 (catch 'exit
5772 (unless ok-list
5773 ;; there are no OK times for gaps...
5774 (throw 'exit nil))
5775 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5776 ;; This is more than 24 hours, so it is OK.
5777 ;; because we have at least one OK time, that must be in the
5778 ;; 24 hour interval.
5779 (throw 'exit t))
5780 ;; We have a shorter gap.
5781 ;; Now we have to get the minute of the day when these times are
5782 (let* ((t1dec (decode-time (seconds-to-time t1)))
5783 (t2dec (decode-time (seconds-to-time t2)))
5784 ;; compute the minute on the day
5785 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5786 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5787 (when (< min2 min1)
5788 ;; if min2 is smaller than min1, this means it is on the next day.
5789 ;; Wrap it to after midnight.
5790 (setq min2 (+ min2 1440)))
5791 ;; Now check if any of the OK times is in the gap
5792 (mapc (lambda (x)
5793 ;; Wrap the time to after midnight if necessary
5794 (if (< x min1) (setq x (+ x 1440)))
5795 ;; Check if in interval
5796 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5797 ok-list)
5798 ;; Nope, this gap is not OK
5799 nil)))
5801 (defun org-agenda-get-deadlines ()
5802 "Return the deadline information for agenda display."
5803 (let* ((props (list 'mouse-face 'highlight
5804 'org-not-done-regexp org-not-done-regexp
5805 'org-todo-regexp org-todo-regexp
5806 'org-complex-heading-regexp org-complex-heading-regexp
5807 'help-echo
5808 (format "mouse-2 or RET jump to org file %s"
5809 (abbreviate-file-name buffer-file-name))))
5810 (regexp org-deadline-time-regexp)
5811 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5812 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5813 d2 diff dfrac wdays pos pos1 category category-pos level
5814 tags suppress-prewarning ee txt head face s todo-state
5815 show-all upcomingp donep timestr warntime)
5816 (goto-char (point-min))
5817 (while (re-search-forward regexp nil t)
5818 (catch :skip
5819 (org-agenda-skip)
5820 (setq s (match-string 1)
5821 txt nil
5822 pos (1- (match-beginning 1))
5823 todo-state (save-match-data (org-get-todo-state))
5824 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5825 (member todo-state
5826 org-agenda-repeating-timestamp-show-all))
5827 d2 (org-time-string-to-absolute
5828 (match-string 1) d1 'past show-all
5829 (current-buffer) pos)
5830 diff (- d2 d1))
5831 (setq suppress-prewarning
5832 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
5833 (let ((item (buffer-substring (point-at-bol)
5834 (point-at-eol))))
5835 (save-match-data
5836 (and (string-match
5837 org-scheduled-time-regexp item)
5838 (match-string 1 item)))))))
5839 (cond
5840 ((not ds) nil)
5841 ;; The current item has a scheduled date (in ds), so
5842 ;; evaluate its prewarning lead time.
5843 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5844 ;; Use global prewarning-restart lead time.
5845 org-agenda-skip-deadline-prewarning-if-scheduled)
5846 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
5847 'pre-scheduled)
5848 ;; Set prewarning to no earlier than scheduled.
5849 (min (- d2 (org-time-string-to-absolute
5850 ds d1 'past show-all (current-buffer) pos))
5851 org-deadline-warning-days))
5852 ;; Set prewarning to deadline.
5853 (t 0))))
5854 (setq wdays (if suppress-prewarning
5855 (let ((org-deadline-warning-days suppress-prewarning))
5856 (org-get-wdays s))
5857 (org-get-wdays s))
5858 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5859 upcomingp (and todayp (> diff 0)))
5860 ;; When to show a deadline in the calendar:
5861 ;; If the expiration is within wdays warning time.
5862 ;; Past-due deadlines are only shown on the current date
5863 (if (and (or (and (<= diff wdays)
5864 (and todayp (not org-agenda-only-exact-dates)))
5865 (= diff 0)))
5866 (save-excursion
5867 ;; (setq todo-state (org-get-todo-state))
5868 (setq donep (member todo-state org-done-keywords))
5869 (if (and donep
5870 (or org-agenda-skip-deadline-if-done
5871 (not (= diff 0))))
5872 (setq txt nil)
5873 (setq category (org-get-category)
5874 warntime (org-entry-get (point) "APPT_WARNTIME")
5875 category-pos (get-text-property (point) 'org-category-position))
5876 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5877 (setq txt org-agenda-no-heading-message)
5878 (goto-char (match-end 0))
5879 (setq pos1 (match-beginning 0))
5880 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5881 (setq tags (org-get-tags-at pos1))
5882 (setq head (buffer-substring-no-properties
5883 (point)
5884 (progn (skip-chars-forward "^\r\n")
5885 (point))))
5886 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5887 (setq timestr
5888 (concat (substring s (match-beginning 1)) " "))
5889 (setq timestr 'time))
5890 (setq txt (org-agenda-format-item
5891 (if (= diff 0)
5892 (car org-agenda-deadline-leaders)
5893 (if (functionp
5894 (nth 1 org-agenda-deadline-leaders))
5895 (funcall
5896 (nth 1 org-agenda-deadline-leaders)
5897 diff date)
5898 (format (nth 1 org-agenda-deadline-leaders)
5899 diff)))
5900 head level category tags
5901 (if (not (= diff 0)) nil timestr)))))
5902 (when txt
5903 (setq face (org-agenda-deadline-face dfrac))
5904 (org-add-props txt props
5905 'org-marker (org-agenda-new-marker pos)
5906 'warntime warntime
5907 'level level
5908 'org-hd-marker (org-agenda-new-marker pos1)
5909 'priority (+ (- diff)
5910 (org-get-priority txt))
5911 'org-category category
5912 'org-category-position category-pos
5913 'todo-state todo-state
5914 'type (if upcomingp "upcoming-deadline" "deadline")
5915 'date (if upcomingp date d2)
5916 'face (if donep 'org-agenda-done face)
5917 'undone-face face 'done-face 'org-agenda-done)
5918 (push txt ee))))))
5919 (nreverse ee)))
5921 (defun org-agenda-deadline-face (fraction)
5922 "Return the face to displaying a deadline item.
5923 FRACTION is what fraction of the head-warning time has passed."
5924 (let ((faces org-agenda-deadline-faces) f)
5925 (catch 'exit
5926 (while (setq f (pop faces))
5927 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5929 (defun org-agenda-get-scheduled (&optional deadline-results)
5930 "Return the scheduled information for agenda display."
5931 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5932 'org-todo-regexp org-todo-regexp
5933 'org-complex-heading-regexp org-complex-heading-regexp
5934 'done-face 'org-agenda-done
5935 'mouse-face 'highlight
5936 'help-echo
5937 (format "mouse-2 or RET jump to org file %s"
5938 (abbreviate-file-name buffer-file-name))))
5939 (regexp org-scheduled-time-regexp)
5940 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5941 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5943 (deadline-position-alist
5944 (mapcar (lambda (a) (and (setq mm (get-text-property
5945 0 'org-hd-marker a))
5946 (cons (marker-position mm) a)))
5947 deadline-results))
5948 d2 diff pos pos1 category category-pos level tags donep
5949 ee txt head pastschedp todo-state face timestr s habitp show-all
5950 did-habit-check-p warntime)
5951 (goto-char (point-min))
5952 (while (re-search-forward regexp nil t)
5953 (catch :skip
5954 (org-agenda-skip)
5955 (setq s (match-string 1)
5956 txt nil
5957 pos (1- (match-beginning 1))
5958 todo-state (save-match-data (org-get-todo-state))
5959 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5960 (member todo-state
5961 org-agenda-repeating-timestamp-show-all))
5962 d2 (org-time-string-to-absolute
5963 (match-string 1) d1 'past show-all
5964 (current-buffer) pos)
5965 diff (- d2 d1)
5966 warntime (org-entry-get (point) "APPT_WARNTIME"))
5967 (setq pastschedp (and todayp (< diff 0)))
5968 (setq did-habit-check-p nil)
5969 ;; When to show a scheduled item in the calendar:
5970 ;; If it is on or past the date.
5971 (when (or (and (< diff 0)
5972 (< (abs diff) org-scheduled-past-days)
5973 (and todayp (not org-agenda-only-exact-dates)))
5974 (= diff 0)
5975 ;; org-is-habit-p uses org-entry-get, which is expansive
5976 ;; so we go extra mile to only call it once
5977 (and todayp
5978 (boundp 'org-habit-show-all-today)
5979 org-habit-show-all-today
5980 (setq did-habit-check-p t)
5981 (setq habitp (and (functionp 'org-is-habit-p)
5982 (org-is-habit-p)))))
5983 (save-excursion
5984 (setq donep (member todo-state org-done-keywords))
5985 (if (and donep
5986 (or org-agenda-skip-scheduled-if-done
5987 (not (= diff 0))
5988 (and (functionp 'org-is-habit-p)
5989 (org-is-habit-p))))
5990 (setq txt nil)
5991 (setq habitp (if did-habit-check-p habitp
5992 (and (functionp 'org-is-habit-p)
5993 (org-is-habit-p))))
5994 (setq category (org-get-category)
5995 category-pos (get-text-property (point) 'org-category-position))
5996 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5997 (setq txt org-agenda-no-heading-message)
5998 (goto-char (match-end 0))
5999 (setq pos1 (match-beginning 0))
6000 (if habitp
6001 (if (or (not org-habit-show-habits)
6002 (and (not todayp)
6003 (boundp 'org-habit-show-habits-only-for-today)
6004 org-habit-show-habits-only-for-today))
6005 (throw :skip nil))
6006 (if (and
6007 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6008 (and org-agenda-skip-scheduled-if-deadline-is-shown
6009 pastschedp))
6010 (setq mm (assoc pos1 deadline-position-alist)))
6011 (throw :skip nil)))
6012 (setq tags (org-get-tags-at))
6013 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6014 (setq head (buffer-substring-no-properties
6015 (point)
6016 (progn (skip-chars-forward "^\r\n") (point))))
6017 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6018 (setq timestr
6019 (concat (substring s (match-beginning 1)) " "))
6020 (setq timestr 'time))
6021 (setq txt (org-agenda-format-item
6022 (if (= diff 0)
6023 (car org-agenda-scheduled-leaders)
6024 (format (nth 1 org-agenda-scheduled-leaders)
6025 (- 1 diff)))
6026 head level category tags
6027 (if (not (= diff 0)) nil timestr)
6028 nil habitp))))
6029 (when txt
6030 (setq face
6031 (cond
6032 ((and (not habitp) pastschedp)
6033 'org-scheduled-previously)
6034 (todayp 'org-scheduled-today)
6035 (t 'org-scheduled))
6036 habitp (and habitp (org-habit-parse-todo)))
6037 (org-add-props txt props
6038 'undone-face face
6039 'face (if donep 'org-agenda-done face)
6040 'org-marker (org-agenda-new-marker pos)
6041 'org-hd-marker (org-agenda-new-marker pos1)
6042 'type (if pastschedp "past-scheduled" "scheduled")
6043 'date (if pastschedp d2 date)
6044 'warntime warntime
6045 'level level
6046 'priority (if habitp
6047 (org-habit-get-priority habitp)
6048 (+ 94 (- 5 diff) (org-get-priority txt)))
6049 'org-category category
6050 'category-position category-pos
6051 'org-habit-p habitp
6052 'todo-state todo-state)
6053 (push txt ee))))))
6054 (nreverse ee)))
6056 (defun org-agenda-get-blocks ()
6057 "Return the date-range information for agenda display."
6058 (let* ((props (list 'face nil
6059 'org-not-done-regexp org-not-done-regexp
6060 'org-todo-regexp org-todo-regexp
6061 'org-complex-heading-regexp org-complex-heading-regexp
6062 'mouse-face 'highlight
6063 'help-echo
6064 (format "mouse-2 or RET jump to org file %s"
6065 (abbreviate-file-name buffer-file-name))))
6066 (regexp org-tr-regexp)
6067 (d0 (calendar-absolute-from-gregorian date))
6068 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6069 level todo-state tags pos head donep)
6070 (goto-char (point-min))
6071 (while (re-search-forward regexp nil t)
6072 (catch :skip
6073 (org-agenda-skip)
6074 (setq pos (point))
6075 (let ((start-time (match-string 1))
6076 (end-time (match-string 2)))
6077 (setq s1 (match-string 1)
6078 s2 (match-string 2)
6079 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6080 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6081 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6082 ;; Only allow days between the limits, because the normal
6083 ;; date stamps will catch the limits.
6084 (save-excursion
6085 (setq todo-state (org-get-todo-state))
6086 (setq donep (member todo-state org-done-keywords))
6087 (if (and donep org-agenda-skip-timestamp-if-done)
6088 (throw :skip t))
6089 (setq marker (org-agenda-new-marker (point)))
6090 (setq category (org-get-category)
6091 category-pos (get-text-property (point) 'org-category-position))
6092 (if (not (re-search-backward org-outline-regexp-bol nil t))
6093 (setq txt org-agenda-no-heading-message)
6094 (goto-char (match-beginning 0))
6095 (setq hdmarker (org-agenda-new-marker (point)))
6096 (setq tags (org-get-tags-at))
6097 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6098 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6099 (setq head (match-string 1))
6100 (let ((remove-re
6101 (if org-agenda-remove-timeranges-from-blocks
6102 (concat
6103 "<" (regexp-quote s1) ".*?>"
6104 "--"
6105 "<" (regexp-quote s2) ".*?>")
6106 nil)))
6107 (setq txt (org-agenda-format-item
6108 (format
6109 (nth (if (= d1 d2) 0 1)
6110 org-agenda-timerange-leaders)
6111 (1+ (- d0 d1)) (1+ (- d2 d1)))
6112 head level category tags
6113 (cond ((and (= d1 d0) (= d2 d0))
6114 (concat "<" start-time ">--<" end-time ">"))
6115 ((= d1 d0)
6116 (concat "<" start-time ">"))
6117 ((= d2 d0)
6118 (concat "<" end-time ">")))
6119 remove-re))))
6120 (org-add-props txt props
6121 'org-marker marker 'org-hd-marker hdmarker
6122 'type "block" 'date date
6123 'level level
6124 'todo-state todo-state
6125 'priority (org-get-priority txt) 'org-category category
6126 'org-category-position category-pos)
6127 (push txt ee))))
6128 (goto-char pos)))
6129 ;; Sort the entries by expiration date.
6130 (nreverse ee)))
6132 ;;; Agenda presentation and sorting
6134 (defvar org-prefix-has-time nil
6135 "A flag, set by `org-compile-prefix-format'.
6136 The flag is set if the currently compiled format contains a `%t'.")
6137 (defvar org-prefix-has-tag nil
6138 "A flag, set by `org-compile-prefix-format'.
6139 The flag is set if the currently compiled format contains a `%T'.")
6140 (defvar org-prefix-has-effort nil
6141 "A flag, set by `org-compile-prefix-format'.
6142 The flag is set if the currently compiled format contains a `%e'.")
6143 (defvar org-prefix-category-length nil
6144 "Used by `org-compile-prefix-format' to remember the category field width.")
6145 (defvar org-prefix-category-max-length nil
6146 "Used by `org-compile-prefix-format' to remember the category field width.")
6148 (defun org-agenda-get-category-icon (category)
6149 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6150 (dolist (entry org-agenda-category-icon-alist)
6151 (when (org-string-match-p (car entry) category)
6152 (if (listp (cadr entry))
6153 (return (cadr entry))
6154 (return (apply 'create-image (cdr entry)))))))
6156 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6157 remove-re habitp)
6158 "Format TXT to be inserted into the agenda buffer.
6159 In particular, add the prefix and corresponding text properties.
6161 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6162 LEVEL may be a string to replace the `%l' specifier.
6163 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6164 category taken from local variable or file name. It will replace the `%c'
6165 specifier in the format.
6166 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6167 TXT for sorting of this entry, and for the `%t' specifier in the format.
6168 When DOTIME is a string, this string is searched for a time before TXT is.
6169 TAGS can be the tags of the headline.
6170 Any match of REMOVE-RE will be removed from TXT."
6171 ;; We keep the org-prefix-* variable values along with a compiled
6172 ;; formatter, so that multiple agendas existing at the same time do
6173 ;; not step on each other toes.
6175 ;; It was inconvenient to make these variables buffer local in
6176 ;; Agenda buffers, because this function expects to be called with
6177 ;; the buffer where item comes from being current, and not agenda
6178 ;; buffer
6179 (let* ((bindings (car org-prefix-format-compiled))
6180 (formatter (cadr org-prefix-format-compiled)))
6181 (loop for (var value) in bindings
6182 do (set var value))
6183 (save-match-data
6184 ;; Diary entries sometimes have extra whitespace at the beginning
6185 (setq txt (org-trim txt))
6187 ;; Fix the tags part in txt
6188 (setq txt (org-agenda-fix-displayed-tags
6189 txt tags
6190 org-agenda-show-inherited-tags
6191 org-agenda-hide-tags-regexp))
6193 (let* ((category (or category
6194 (if (stringp org-category)
6195 org-category
6196 (and org-category (symbol-name org-category)))
6197 (if buffer-file-name
6198 (file-name-sans-extension
6199 (file-name-nondirectory buffer-file-name))
6200 "")))
6201 (category-icon (org-agenda-get-category-icon category))
6202 (category-icon (if category-icon
6203 (propertize " " 'display category-icon)
6204 ""))
6205 ;; time, tag, effort are needed for the eval of the prefix format
6206 (tag (if tags (nth (1- (length tags)) tags) ""))
6207 time effort neffort
6208 (ts (if dotime (concat
6209 (if (stringp dotime) dotime "")
6210 (and org-agenda-search-headline-for-time txt))))
6211 (time-of-day (and dotime (org-get-time-of-day ts)))
6212 stamp plain s0 s1 s2 rtn srp l
6213 duration thecategory)
6214 (and (derived-mode-p 'org-mode) buffer-file-name
6215 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6216 (when (and dotime time-of-day)
6217 ;; Extract starting and ending time and move them to prefix
6218 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6219 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6220 (setq s0 (match-string 0 ts)
6221 srp (and stamp (match-end 3))
6222 s1 (match-string (if plain 1 2) ts)
6223 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6225 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6226 ;; them, we might want to remove them there to avoid duplication.
6227 ;; The user can turn this off with a variable.
6228 (if (and org-prefix-has-time
6229 org-agenda-remove-times-when-in-prefix (or stamp plain)
6230 (string-match (concat (regexp-quote s0) " *") txt)
6231 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6232 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6233 (= (match-beginning 0) 0)
6235 (setq txt (replace-match "" nil nil txt))))
6236 ;; Normalize the time(s) to 24 hour
6237 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6238 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6240 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6241 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6242 (setq s2
6243 (org-minutes-to-clocksum-string
6244 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6246 ;; Compute the duration
6247 (when s2
6248 (setq duration (- (org-hh:mm-string-to-minutes s2)
6249 (org-hh:mm-string-to-minutes s1)))))
6251 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6252 txt)
6253 ;; Tags are in the string
6254 (if (or (eq org-agenda-remove-tags t)
6255 (and org-agenda-remove-tags
6256 org-prefix-has-tag))
6257 (setq txt (replace-match "" t t txt))
6258 (setq txt (replace-match
6259 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6260 (match-string 2 txt))
6261 t t txt))))
6262 (when (derived-mode-p 'org-mode)
6263 (setq effort
6264 (condition-case nil
6265 (org-get-effort
6266 (or (get-text-property 0 'org-hd-marker txt)
6267 (get-text-property 0 'org-marker txt)))
6268 (error nil)))
6269 (when effort
6270 (setq neffort (org-duration-string-to-minutes effort)
6271 effort (setq effort (concat "[" effort "]")))))
6272 ;; prevent erroring out with %e format when there is no effort
6273 (or effort (setq effort ""))
6275 (when remove-re
6276 (while (string-match remove-re txt)
6277 (setq txt (replace-match "" t t txt))))
6279 ;; Set org-heading property on `txt' to mark the start of the
6280 ;; heading.
6281 (add-text-properties 0 (length txt) '(org-heading t) txt)
6283 ;; Prepare the variables needed in the eval of the compiled format
6284 (setq time (cond (s2 (concat
6285 (org-agenda-time-of-day-to-ampm-maybe s1)
6286 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6287 (if org-agenda-timegrid-use-ampm " ")))
6288 (s1 (concat
6289 (org-agenda-time-of-day-to-ampm-maybe s1)
6290 (if org-agenda-timegrid-use-ampm
6291 "........ "
6292 "......")))
6293 (t ""))
6294 extra (or (and (not habitp) extra) "")
6295 category (if (symbolp category) (symbol-name category) category)
6296 thecategory (copy-sequence category)
6297 level (or level ""))
6298 (if (string-match org-bracket-link-regexp category)
6299 (progn
6300 (setq l (if (match-end 3)
6301 (- (match-end 3) (match-beginning 3))
6302 (- (match-end 1) (match-beginning 1))))
6303 (when (< l (or org-prefix-category-length 0))
6304 (setq category (copy-sequence category))
6305 (org-add-props category nil
6306 'extra-space (make-string
6307 (- org-prefix-category-length l 1) ?\ ))))
6308 (if (and org-prefix-category-max-length
6309 (>= (length category) org-prefix-category-max-length))
6310 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6311 ;; Evaluate the compiled format
6312 (setq rtn (concat (eval formatter) txt))
6314 ;; And finally add the text properties
6315 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6316 (org-add-props rtn nil
6317 'org-category (if thecategory (downcase thecategory) category)
6318 'tags (mapcar 'org-downcase-keep-props tags)
6319 'org-highest-priority org-highest-priority
6320 'org-lowest-priority org-lowest-priority
6321 'time-of-day time-of-day
6322 'duration duration
6323 'effort effort
6324 'effort-minutes neffort
6325 'txt txt
6326 'level level
6327 'time time
6328 'extra extra
6329 'format org-prefix-format-compiled
6330 'dotime dotime)))))
6332 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6333 "Remove tags string from TXT, and add a modified list of tags.
6334 The modified list may contain inherited tags, and tags matched by
6335 `org-agenda-hide-tags-regexp' will be removed."
6336 (when (or add-inherited hide-re)
6337 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6338 (setq txt (substring txt 0 (match-beginning 0))))
6339 (setq tags
6340 (delq nil
6341 (mapcar (lambda (tg)
6342 (if (or (and hide-re (string-match hide-re tg))
6343 (and (not add-inherited)
6344 (get-text-property 0 'inherited tg)))
6346 tg))
6347 tags)))
6348 (when tags
6349 (let ((have-i (get-text-property 0 'inherited (car tags)))
6351 (setq txt (concat txt " :"
6352 (mapconcat
6353 (lambda (x)
6354 (setq i (get-text-property 0 'inherited x))
6355 (if (and have-i (not i))
6356 (progn
6357 (setq have-i nil)
6358 (concat ":" x))
6360 tags ":")
6361 (if have-i "::" ":"))))))
6362 txt)
6364 (defun org-downcase-keep-props (s)
6365 (let ((props (text-properties-at 0 s)))
6366 (setq s (downcase s))
6367 (add-text-properties 0 (length s) props s)
6370 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6371 (defvar org-agenda-sorting-strategy-selected nil)
6373 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6374 "Add a time-grid for agenda items which need it.
6376 LIST is the list of agenda items formatted by `org-agenda-list'.
6377 NDAYS is the span of the current agenda view.
6378 TODAYP is `t' when the current agenda view is on today."
6379 (catch 'exit
6380 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6381 ((and todayp (member 'today (car org-agenda-time-grid))))
6382 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6383 ((member 'weekly (car org-agenda-time-grid)))
6384 (t (throw 'exit list)))
6385 (let* ((have (delq nil (mapcar
6386 (lambda (x) (get-text-property 1 'time-of-day x))
6387 list)))
6388 (string (nth 1 org-agenda-time-grid))
6389 (gridtimes (nth 2 org-agenda-time-grid))
6390 (req (car org-agenda-time-grid))
6391 (remove (member 'remove-match req))
6392 new time)
6393 (if (and (member 'require-timed req) (not have))
6394 ;; don't show empty grid
6395 (throw 'exit list))
6396 (while (setq time (pop gridtimes))
6397 (unless (and remove (member time have))
6398 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6399 (push (org-agenda-format-item
6400 nil string nil "" nil
6401 (concat (substring time 0 -2) ":" (substring time -2)))
6402 new)
6403 (put-text-property
6404 2 (length (car new)) 'face 'org-time-grid (car new))))
6405 (when (and todayp org-agenda-show-current-time-in-grid)
6406 (push (org-agenda-format-item
6407 nil org-agenda-current-time-string nil "" nil
6408 (format-time-string "%H:%M "))
6409 new)
6410 (put-text-property
6411 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6413 (if (member 'time-up org-agenda-sorting-strategy-selected)
6414 (append new list)
6415 (append list new)))))
6417 (defun org-compile-prefix-format (key)
6418 "Compile the prefix format into a Lisp form that can be evaluated.
6419 The resulting form and associated variable bindings is returned
6420 and stored in the variable `org-prefix-format-compiled'."
6421 (setq org-prefix-has-time nil
6422 org-prefix-has-tag nil
6423 org-prefix-category-length nil
6424 org-prefix-has-effort nil)
6425 (let ((s (cond
6426 ((stringp org-agenda-prefix-format)
6427 org-agenda-prefix-format)
6428 ((assq key org-agenda-prefix-format)
6429 (cdr (assq key org-agenda-prefix-format)))
6430 (t " %-12:c%?-12t% s")))
6431 (start 0)
6432 varform vars var e c f opt)
6433 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
6434 s start)
6435 (setq var (or (cdr (assoc (match-string 4 s)
6436 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6437 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6438 'eval)
6439 c (or (match-string 3 s) "")
6440 opt (match-beginning 1)
6441 start (1+ (match-beginning 0)))
6442 (if (equal var 'time) (setq org-prefix-has-time t))
6443 (if (equal var 'tag) (setq org-prefix-has-tag t))
6444 (if (equal var 'effort) (setq org-prefix-has-effort t))
6445 (setq f (concat "%" (match-string 2 s) "s"))
6446 (when (equal var 'category)
6447 (setq org-prefix-category-length
6448 (floor (abs (string-to-number (match-string 2 s)))))
6449 (setq org-prefix-category-max-length
6450 (let ((x (match-string 2 s)))
6451 (save-match-data
6452 (if (string-match "\\.[0-9]+" x)
6453 (string-to-number (substring (match-string 0 x) 1)))))))
6454 (if (eq var 'eval)
6455 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6456 (if opt
6457 (setq varform
6458 `(if (equal "" ,var)
6460 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6461 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6462 (setq s (replace-match "%s" t nil s))
6463 (push varform vars))
6464 (setq vars (nreverse vars))
6465 (with-current-buffer (or org-agenda-buffer (current-buffer))
6466 (setq org-prefix-format-compiled
6467 (list
6468 `((org-prefix-has-time ,org-prefix-has-time)
6469 (org-prefix-has-tag ,org-prefix-has-tag)
6470 (org-prefix-category-length ,org-prefix-category-length)
6471 (org-prefix-has-effort ,org-prefix-has-effort))
6472 `(format ,s ,@vars))))))
6474 (defun org-set-sorting-strategy (key)
6475 (if (symbolp (car org-agenda-sorting-strategy))
6476 ;; the old format
6477 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6478 (setq org-agenda-sorting-strategy-selected
6479 (or (cdr (assq key org-agenda-sorting-strategy))
6480 (cdr (assq 'agenda org-agenda-sorting-strategy))
6481 '(time-up category-keep priority-down)))))
6483 (defun org-get-time-of-day (s &optional string mod24)
6484 "Check string S for a time of day.
6485 If found, return it as a military time number between 0 and 2400.
6486 If not found, return nil.
6487 The optional STRING argument forces conversion into a 5 character wide string
6488 HH:MM."
6489 (save-match-data
6490 (when
6491 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6492 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6493 (let* ((h (string-to-number (match-string 1 s)))
6494 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6495 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6496 (am-p (equal ampm "am"))
6497 (h1 (cond ((not ampm) h)
6498 ((= h 12) (if am-p 0 12))
6499 (t (+ h (if am-p 0 12)))))
6500 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6501 (mod h1 24) h1))
6502 (t0 (+ (* 100 h2) m))
6503 (t1 (concat (if (>= h1 24) "+" " ")
6504 (if (and org-agenda-time-leading-zero
6505 (< t0 1000)) "0" "")
6506 (if (< t0 100) "0" "")
6507 (if (< t0 10) "0" "")
6508 (int-to-string t0))))
6509 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6511 (defvar org-agenda-before-sorting-filter-function nil
6512 "Function to be applied to agenda items prior to sorting.
6513 Prior to sorting also means just before they are inserted into the agenda.
6515 To aid sorting, you may revisit the original entries and add more text
6516 properties which will later be used by the sorting functions.
6518 The function should take a string argument, an agenda line.
6519 It has access to the text properties in that line, which contain among
6520 other things, the property `org-hd-marker' that points to the entry
6521 where the line comes from. Note that not all lines going into the agenda
6522 have this property, only most.
6524 The function should return the modified string. It is probably best
6525 to ONLY change text properties.
6527 You can also use this function as a filter, by returning nil for lines
6528 you don't want to have in the agenda at all. For this application, you
6529 could bind the variable in the options section of a custom command.")
6531 (defun org-agenda-finalize-entries (list &optional nosort)
6532 "Sort and concatenate the agenda items."
6533 (setq list (mapcar 'org-agenda-highlight-todo list))
6534 (if nosort
6535 list
6536 (when org-agenda-before-sorting-filter-function
6537 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6538 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6540 (defun org-agenda-highlight-todo (x)
6541 (let ((org-done-keywords org-done-keywords-for-agenda)
6542 (case-fold-search nil)
6544 (if (eq x 'line)
6545 (save-excursion
6546 (beginning-of-line 1)
6547 (setq re (org-get-at-bol 'org-todo-regexp))
6548 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6549 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6550 (add-text-properties (match-beginning 0) (match-end 1)
6551 (list 'face (org-get-todo-face 1)))
6552 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6553 (delete-region (match-beginning 1) (1- (match-end 0)))
6554 (goto-char (match-beginning 1))
6555 (insert (format org-agenda-todo-keyword-format s)))))
6556 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6557 (setq re (get-text-property 0 'org-todo-regexp x))
6558 (when (and re
6559 ;; Test `pl' because if there's no heading content,
6560 ;; there's no point matching to highlight. Note
6561 ;; that if we didn't test `pl' first, and there
6562 ;; happened to be no keyword from `org-todo-regexp'
6563 ;; on this heading line, then the `equal' comparison
6564 ;; afterwards would spuriously succeed in the case
6565 ;; where `pl' is nil -- causing an args-out-of-range
6566 ;; error when we try to add text properties to text
6567 ;; that isn't there.
6569 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6570 x pl) pl))
6571 (add-text-properties
6572 (or (match-end 1) (match-end 0)) (match-end 0)
6573 (list 'face (org-get-todo-face (match-string 2 x)))
6575 (when (match-end 1)
6576 (setq x (concat (substring x 0 (match-end 1))
6577 (format org-agenda-todo-keyword-format
6578 (match-string 2 x))
6579 (org-add-props " " (text-properties-at 0 x))
6580 (substring x (match-end 3)))))))
6581 x)))
6583 (defsubst org-cmp-priority (a b)
6584 "Compare the priorities of string A and B."
6585 (let ((pa (or (get-text-property 1 'priority a) 0))
6586 (pb (or (get-text-property 1 'priority b) 0)))
6587 (cond ((> pa pb) +1)
6588 ((< pa pb) -1))))
6590 (defsubst org-cmp-effort (a b)
6591 "Compare the effort values of string A and B."
6592 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6593 (ea (or (get-text-property 1 'effort-minutes a) def))
6594 (eb (or (get-text-property 1 'effort-minutes b) def)))
6595 (cond ((> ea eb) +1)
6596 ((< ea eb) -1))))
6598 (defsubst org-cmp-category (a b)
6599 "Compare the string values of categories of strings A and B."
6600 (let ((ca (or (get-text-property 1 'org-category a) ""))
6601 (cb (or (get-text-property 1 'org-category b) "")))
6602 (cond ((string-lessp ca cb) -1)
6603 ((string-lessp cb ca) +1))))
6605 (defsubst org-cmp-todo-state (a b)
6606 "Compare the todo states of strings A and B."
6607 (let* ((ma (or (get-text-property 1 'org-marker a)
6608 (get-text-property 1 'org-hd-marker a)))
6609 (mb (or (get-text-property 1 'org-marker b)
6610 (get-text-property 1 'org-hd-marker b)))
6611 (fa (and ma (marker-buffer ma)))
6612 (fb (and mb (marker-buffer mb)))
6613 (todo-kwds
6614 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6615 (and fb (with-current-buffer fb org-todo-keywords-1))))
6616 (ta (or (get-text-property 1 'todo-state a) ""))
6617 (tb (or (get-text-property 1 'todo-state b) ""))
6618 (la (- (length (member ta todo-kwds))))
6619 (lb (- (length (member tb todo-kwds))))
6620 (donepa (member ta org-done-keywords-for-agenda))
6621 (donepb (member tb org-done-keywords-for-agenda)))
6622 (cond ((and donepa (not donepb)) -1)
6623 ((and (not donepa) donepb) +1)
6624 ((< la lb) -1)
6625 ((< lb la) +1))))
6627 (defsubst org-cmp-alpha (a b)
6628 "Compare the headlines, alphabetically."
6629 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6630 (plb (text-property-any 0 (length b) 'org-heading t b))
6631 (ta (and pla (substring a pla)))
6632 (tb (and plb (substring b plb))))
6633 (when pla
6634 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6635 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6636 (setq ta (substring ta (match-end 0))))
6637 (setq ta (downcase ta)))
6638 (when plb
6639 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6640 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6641 (setq tb (substring tb (match-end 0))))
6642 (setq tb (downcase tb)))
6643 (cond ((not ta) +1)
6644 ((not tb) -1)
6645 ((string-lessp ta tb) -1)
6646 ((string-lessp tb ta) +1))))
6648 (defsubst org-cmp-tag (a b)
6649 "Compare the string values of the first tags of A and B."
6650 (let ((ta (car (last (get-text-property 1 'tags a))))
6651 (tb (car (last (get-text-property 1 'tags b)))))
6652 (cond ((not ta) +1)
6653 ((not tb) -1)
6654 ((string-lessp ta tb) -1)
6655 ((string-lessp tb ta) +1))))
6657 (defsubst org-cmp-time (a b)
6658 "Compare the time-of-day values of strings A and B."
6659 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6660 (ta (or (get-text-property 1 'time-of-day a) def))
6661 (tb (or (get-text-property 1 'time-of-day b) def)))
6662 (cond ((< ta tb) -1)
6663 ((< tb ta) +1))))
6665 (defsubst org-cmp-habit-p (a b)
6666 "Compare the todo states of strings A and B."
6667 (let ((ha (get-text-property 1 'org-habit-p a))
6668 (hb (get-text-property 1 'org-habit-p b)))
6669 (cond ((and ha (not hb)) -1)
6670 ((and (not ha) hb) +1))))
6672 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6674 (defun org-entries-lessp (a b)
6675 "Predicate for sorting agenda entries."
6676 ;; The following variables will be used when the form is evaluated.
6677 ;; So even though the compiler complains, keep them.
6678 (let* ((ss org-agenda-sorting-strategy-selected)
6679 (time-up (and (org-em 'time-up 'time-down ss)
6680 (org-cmp-time a b)))
6681 (time-down (if time-up (- time-up) nil))
6682 (priority-up (and (org-em 'priority-up 'priority-down ss)
6683 (org-cmp-priority a b)))
6684 (priority-down (if priority-up (- priority-up) nil))
6685 (effort-up (and (org-em 'effort-up 'effort-down ss)
6686 (org-cmp-effort a b)))
6687 (effort-down (if effort-up (- effort-up) nil))
6688 (category-up (and (or (org-em 'category-up 'category-down ss)
6689 (memq 'category-keep ss))
6690 (org-cmp-category a b)))
6691 (category-down (if category-up (- category-up) nil))
6692 (category-keep (if category-up +1 nil))
6693 (tag-up (and (org-em 'tag-up 'tag-down ss)
6694 (org-cmp-tag a b)))
6695 (tag-down (if tag-up (- tag-up) nil))
6696 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6697 (org-cmp-todo-state a b)))
6698 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6699 (habit-up (and (org-em 'habit-up 'habit-down ss)
6700 (org-cmp-habit-p a b)))
6701 (habit-down (if habit-up (- habit-up) nil))
6702 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6703 (org-cmp-alpha a b)))
6704 (alpha-down (if alpha-up (- alpha-up) nil))
6705 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6706 user-defined-up user-defined-down)
6707 (if (and need-user-cmp org-agenda-cmp-user-defined
6708 (functionp org-agenda-cmp-user-defined))
6709 (setq user-defined-up
6710 (funcall org-agenda-cmp-user-defined a b)
6711 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6712 (cdr (assoc
6713 (eval (cons 'or org-agenda-sorting-strategy-selected))
6714 '((-1 . t) (1 . nil) (nil . nil))))))
6716 ;;; Agenda restriction lock
6718 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6719 "Overlay to mark the headline to which agenda commands are restricted.")
6720 (overlay-put org-agenda-restriction-lock-overlay
6721 'face 'org-agenda-restriction-lock)
6722 (overlay-put org-agenda-restriction-lock-overlay
6723 'help-echo "Agendas are currently limited to this subtree.")
6724 (org-detach-overlay org-agenda-restriction-lock-overlay)
6726 (defun org-agenda-set-restriction-lock (&optional type)
6727 "Set restriction lock for agenda, to current subtree or file.
6728 Restriction will be the file if TYPE is `file', or if type is the
6729 universal prefix '(4), or if the cursor is before the first headline
6730 in the file. Otherwise, restriction will be to the current subtree."
6731 (interactive "P")
6732 (and (equal type '(4)) (setq type 'file))
6733 (setq type (cond
6734 (type type)
6735 ((org-at-heading-p) 'subtree)
6736 ((condition-case nil (org-back-to-heading t) (error nil))
6737 'subtree)
6738 (t 'file)))
6739 (if (eq type 'subtree)
6740 (progn
6741 (setq org-agenda-restrict t)
6742 (setq org-agenda-overriding-restriction 'subtree)
6743 (put 'org-agenda-files 'org-restrict
6744 (list (buffer-file-name (buffer-base-buffer))))
6745 (org-back-to-heading t)
6746 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6747 (move-marker org-agenda-restrict-begin (point))
6748 (move-marker org-agenda-restrict-end
6749 (save-excursion (org-end-of-subtree t)))
6750 (message "Locking agenda restriction to subtree"))
6751 (put 'org-agenda-files 'org-restrict
6752 (list (buffer-file-name (buffer-base-buffer))))
6753 (setq org-agenda-restrict nil)
6754 (setq org-agenda-overriding-restriction 'file)
6755 (move-marker org-agenda-restrict-begin nil)
6756 (move-marker org-agenda-restrict-end nil)
6757 (message "Locking agenda restriction to file"))
6758 (setq current-prefix-arg nil)
6759 (org-agenda-maybe-redo))
6761 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6762 "Remove the agenda restriction lock."
6763 (interactive "P")
6764 (org-detach-overlay org-agenda-restriction-lock-overlay)
6765 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6766 (setq org-agenda-overriding-restriction nil)
6767 (setq org-agenda-restrict nil)
6768 (put 'org-agenda-files 'org-restrict nil)
6769 (move-marker org-agenda-restrict-begin nil)
6770 (move-marker org-agenda-restrict-end nil)
6771 (setq current-prefix-arg nil)
6772 (message "Agenda restriction lock removed")
6773 (or noupdate (org-agenda-maybe-redo)))
6775 (defun org-agenda-maybe-redo ()
6776 "If there is any window showing the agenda view, update it."
6777 (let ((w (get-buffer-window org-agenda-buffer-name t))
6778 (w0 (selected-window)))
6779 (when w
6780 (select-window w)
6781 (org-agenda-redo)
6782 (select-window w0)
6783 (if org-agenda-overriding-restriction
6784 (message "Agenda view shifted to new %s restriction"
6785 org-agenda-overriding-restriction)
6786 (message "Agenda restriction lock removed")))))
6788 ;;; Agenda commands
6790 (defun org-agenda-check-type (error &rest types)
6791 "Check if agenda buffer is of allowed type.
6792 If ERROR is non-nil, throw an error, otherwise just return nil."
6793 (if (not org-agenda-type)
6794 (error "No Org agenda currently displayed")
6795 (if (memq org-agenda-type types)
6797 (if error
6798 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6799 nil))))
6801 (defun org-agenda-Quit (&optional arg)
6802 "Exit agenda by removing the window or the buffer."
6803 (interactive)
6804 (if org-agenda-columns-active
6805 (org-columns-quit)
6806 (let ((buf (current-buffer)))
6807 (if (eq org-agenda-window-setup 'other-frame)
6808 (progn
6809 (org-agenda-reset-markers)
6810 (kill-buffer buf)
6811 (org-columns-remove-overlays)
6812 (setq org-agenda-archives-mode nil)
6813 (delete-frame))
6814 (and (not (eq org-agenda-window-setup 'current-window))
6815 (not (one-window-p))
6816 (delete-window))
6817 (org-agenda-reset-markers)
6818 (kill-buffer buf)
6819 (org-columns-remove-overlays)
6820 (setq org-agenda-archives-mode nil)))
6821 ;; Maybe restore the pre-agenda window configuration.
6822 (and org-agenda-restore-windows-after-quit
6823 (not (eq org-agenda-window-setup 'other-frame))
6824 org-agenda-pre-window-conf
6825 (set-window-configuration org-agenda-pre-window-conf)
6826 (setq org-agenda-pre-window-conf nil))))
6828 (defun org-agenda-quit ()
6829 "Exit agenda by killing agenda buffer or burying it when
6830 `org-agenda-sticky' is non-NIL"
6831 (interactive)
6832 (if (and (eq org-indirect-buffer-display 'other-window)
6833 org-last-indirect-buffer)
6834 (delete-window (get-buffer-window org-last-indirect-buffer)))
6835 (if org-agenda-columns-active
6836 (org-columns-quit)
6837 (if org-agenda-sticky
6838 (let ((buf (current-buffer)))
6839 (if (eq org-agenda-window-setup 'other-frame)
6840 (progn
6841 (delete-frame))
6842 (and (not (eq org-agenda-window-setup 'current-window))
6843 (not (one-window-p))
6844 (delete-window)))
6845 (with-current-buffer buf
6846 (bury-buffer)
6847 ;; Maybe restore the pre-agenda window configuration.
6848 (and org-agenda-restore-windows-after-quit
6849 (not (eq org-agenda-window-setup 'other-frame))
6850 org-agenda-pre-window-conf
6851 (set-window-configuration org-agenda-pre-window-conf)
6852 (setq org-agenda-pre-window-conf nil))))
6853 (org-agenda-Quit))))
6855 (defun org-agenda-exit ()
6856 "Exit agenda by removing the window or the buffer.
6857 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6858 Org-mode buffers visited directly by the user will not be touched."
6859 (interactive)
6860 (org-release-buffers org-agenda-new-buffers)
6861 (setq org-agenda-new-buffers nil)
6862 (org-agenda-Quit))
6864 (defun org-agenda-kill-all-agenda-buffers ()
6865 "Kill all buffers in `org-agenda-mode'.
6866 This is used when toggling sticky agendas. You can also explicitly invoke it
6867 with `C-c a C-k'."
6868 (interactive)
6869 (let (blist)
6870 (dolist (buf (buffer-list))
6871 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6872 (push buf blist)))
6873 (mapc 'kill-buffer blist)))
6875 (defun org-agenda-execute (arg)
6876 "Execute another agenda command, keeping same window.
6877 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6878 in the agenda."
6879 (interactive "P")
6880 (let ((org-agenda-window-setup 'current-window))
6881 (org-agenda arg)))
6883 (defun org-agenda-redo (&optional all)
6884 "Rebuild possibly ALL agenda view(s) in the current buffer."
6885 (interactive "P")
6886 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6887 (cpa (unless (eq all t) current-prefix-arg))
6888 (org-agenda-doing-sticky-redo org-agenda-sticky)
6889 (org-agenda-sticky nil)
6890 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6891 org-agenda-buffer-name))
6892 (org-agenda-keep-modes t)
6893 (tag-filter org-agenda-tag-filter)
6894 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6895 (top-cat-filter org-agenda-top-category-filter)
6896 (cat-filter org-agenda-category-filter)
6897 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6898 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6899 (cols org-agenda-columns-active)
6900 (line (org-current-line))
6901 (window-line (- line (org-current-line (window-start))))
6902 (lprops (get 'org-agenda-redo-command 'org-lprops))
6903 (redo-cmd (get-text-property p 'org-redo-cmd))
6904 (last-args (get-text-property p 'org-last-args))
6905 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6906 (org-agenda-overriding-cmd-arguments
6907 (unless (eq all t)
6908 (cond ((listp last-args)
6909 (cons (or cpa (car last-args)) (cdr last-args)))
6910 ((stringp last-args)
6911 last-args))))
6912 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6913 (put 'org-agenda-tag-filter :preset-filter nil)
6914 (put 'org-agenda-category-filter :preset-filter nil)
6915 (and cols (org-columns-quit))
6916 (message "Rebuilding agenda buffer...")
6917 (if series-redo-cmd
6918 (eval series-redo-cmd)
6919 (org-let lprops '(eval redo-cmd)))
6920 (setq org-agenda-undo-list nil
6921 org-agenda-pending-undo-list nil)
6922 (message "Rebuilding agenda buffer...done")
6923 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6924 (put 'org-agenda-category-filter :preset-filter cat-preset)
6925 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6926 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6927 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6928 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6929 (org-goto-line line)
6930 (recenter window-line)))
6932 (defvar org-global-tags-completion-table nil)
6933 (defvar org-agenda-filter-form nil)
6934 (defvar org-agenda-filtered-by-category nil)
6936 (defun org-agenda-filter-by-category (strip)
6937 "Keep only those lines in the agenda buffer that have a specific category.
6938 The category is that of the current line."
6939 (interactive "P")
6940 (if (and org-agenda-filtered-by-category
6941 org-agenda-category-filter)
6942 (org-agenda-filter-show-all-cat)
6943 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6944 (if cat (org-agenda-filter-apply
6945 (list (concat (if strip "-" "+") cat)) 'category)
6946 (error "No category at point")))))
6948 (defun org-find-top-category (&optional pos)
6949 (save-excursion
6950 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6951 (if pos (goto-char pos))
6952 ;; Skip up to the topmost parent
6953 (while (ignore-errors (outline-up-heading 1) t))
6954 (ignore-errors
6955 (nth 4 (org-heading-components))))))
6957 (defvar org-agenda-filtered-by-top-category nil)
6959 (defun org-agenda-filter-by-top-category (strip)
6960 "Keep only those lines in the agenda buffer that have a specific category.
6961 The category is that of the current line."
6962 (interactive "P")
6963 (if org-agenda-filtered-by-top-category
6964 (progn
6965 (setq org-agenda-filtered-by-top-category nil
6966 org-agenda-top-category-filter nil)
6967 (org-agenda-filter-show-all-cat))
6968 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6969 (if cat (org-agenda-filter-top-category-apply cat strip)
6970 (error "No top-level category at point")))))
6972 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6973 "Keep only those lines in the agenda buffer that have a specific tag.
6974 The tag is selected with its fast selection letter, as configured.
6975 With prefix argument STRIP, remove all lines that do have the tag.
6976 A lisp caller can specify CHAR. NARROW means that the new tag should be
6977 used to narrow the search - the interactive user can also press `-' or `+'
6978 to switch to narrowing."
6979 (interactive "P")
6980 (let* ((alist org-tag-alist-for-agenda)
6981 (tag-chars (mapconcat
6982 (lambda (x) (if (and (not (symbolp (car x)))
6983 (cdr x))
6984 (char-to-string (cdr x))
6985 ""))
6986 alist ""))
6987 (efforts (org-split-string
6988 (or (cdr (assoc (concat org-effort-property "_ALL")
6989 org-global-properties))
6990 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6991 "")))
6992 (effort-op org-agenda-filter-effort-default-operator)
6993 (effort-prompt "")
6994 (inhibit-read-only t)
6995 (current org-agenda-tag-filter)
6996 maybe-refresh a n tag)
6997 (unless char
6998 (message
6999 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7000 (if narrow "Narrow" "Filter") tag-chars
7001 (if org-agenda-auto-exclude-function "[RET], " ""))
7002 (setq char (read-char-exclusive)))
7003 (when (member char '(?+ ?-))
7004 ;; Narrowing down
7005 (cond ((equal char ?-) (setq strip t narrow t))
7006 ((equal char ?+) (setq strip nil narrow t)))
7007 (message
7008 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7009 (setq char (read-char-exclusive)))
7010 (when (member char '(?< ?> ?= ??))
7011 ;; An effort operator
7012 (setq effort-op (char-to-string char))
7013 (setq alist nil) ; to make sure it will be interpreted as effort.
7014 (unless (equal char ??)
7015 (loop for i from 0 to 9 do
7016 (setq effort-prompt
7017 (concat
7018 effort-prompt " ["
7019 (if (= i 9) "0" (int-to-string (1+ i)))
7020 "]" (nth i efforts))))
7021 (message "Effort%s: %s " effort-op effort-prompt)
7022 (setq char (read-char-exclusive))
7023 (when (or (< char ?0) (> char ?9))
7024 (error "Need 1-9,0 to select effort"))))
7025 (when (equal char ?\t)
7026 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7027 (org-set-local 'org-global-tags-completion-table
7028 (org-global-tags-completion-table)))
7029 (let ((completion-ignore-case t))
7030 (setq tag (org-icompleting-read
7031 "Tag: " org-global-tags-completion-table))))
7032 (cond
7033 ((equal char ?\r)
7034 (org-agenda-filter-show-all-tag)
7035 (when org-agenda-auto-exclude-function
7036 (setq org-agenda-tag-filter '())
7037 (dolist (tag (org-agenda-get-represented-tags))
7038 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7039 (if modifier
7040 (push modifier org-agenda-tag-filter))))
7041 (if (not (null org-agenda-tag-filter))
7042 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7043 (setq maybe-refresh t))
7044 ((equal char ?/)
7045 (org-agenda-filter-show-all-tag)
7046 (when (get 'org-agenda-tag-filter :preset-filter)
7047 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7048 (setq maybe-refresh t))
7049 ((equal char ?. )
7050 (setq org-agenda-tag-filter
7051 (mapcar (lambda(tag) (concat "+" tag))
7052 (org-get-at-bol 'tags)))
7053 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7054 (setq maybe-refresh t))
7055 ((or (equal char ?\ )
7056 (setq a (rassoc char alist))
7057 (and (>= char ?0) (<= char ?9)
7058 (setq n (if (= char ?0) 9 (- char ?0 1))
7059 tag (concat effort-op (nth n efforts))
7060 a (cons tag nil)))
7061 (and (= char ??)
7062 (setq tag "?eff")
7063 a (cons tag nil))
7064 (and tag (setq a (cons tag nil))))
7065 (org-agenda-filter-show-all-tag)
7066 (setq tag (car a))
7067 (setq org-agenda-tag-filter
7068 (cons (concat (if strip "-" "+") tag)
7069 (if narrow current nil)))
7070 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7071 (setq maybe-refresh t))
7072 (t (error "Invalid tag selection character %c" char)))
7073 (when (and maybe-refresh
7074 (eq org-agenda-clockreport-mode 'with-filter))
7075 (org-agenda-redo))))
7077 (defun org-agenda-get-represented-tags ()
7078 "Get a list of all tags currently represented in the agenda."
7079 (let (p tags)
7080 (save-excursion
7081 (goto-char (point-min))
7082 (while (setq p (next-single-property-change (point) 'tags))
7083 (goto-char p)
7084 (mapc (lambda (x) (add-to-list 'tags x))
7085 (get-text-property (point) 'tags))))
7086 tags))
7088 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7089 "Refine the current filter. See `org-agenda-filter-by-tag'."
7090 (interactive "P")
7091 (org-agenda-filter-by-tag strip char 'refine))
7093 (defun org-agenda-filter-make-matcher ()
7094 "Create the form that tests a line for agenda filter."
7095 (let (f f1)
7096 ;; first compute the tag-filter matcher
7097 (dolist (x (delete-dups
7098 (append (get 'org-agenda-tag-filter
7099 :preset-filter) org-agenda-tag-filter)))
7100 (if (member x '("-" "+"))
7101 (setq f1 (if (equal x "-") 'tags '(not tags)))
7102 (if (string-match "[<=>?]" x)
7103 (setq f1 (org-agenda-filter-effort-form x))
7104 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7105 (if (equal (string-to-char x) ?-)
7106 (setq f1 (list 'not f1))))
7107 (push f1 f))
7108 ;; then compute the category-filter matcher
7109 (dolist (x (delete-dups
7110 (append (get 'org-agenda-category-filter
7111 :preset-filter) org-agenda-category-filter)))
7112 (if (equal "-" (substring x 0 1))
7113 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7114 (setq f1 (list 'equal (substring x 1) 'cat)))
7115 (push f1 f))
7116 (cons 'and (nreverse f))))
7118 (defun org-agenda-filter-effort-form (e)
7119 "Return the form to compare the effort of the current line with what E says.
7120 E looks like \"+<2:25\"."
7121 (let (op)
7122 (setq e (substring e 1))
7123 (setq op (string-to-char e) e (substring e 1))
7124 (setq op (cond ((equal op ?<) '<=)
7125 ((equal op ?>) '>=)
7126 ((equal op ??) op)
7127 (t '=)))
7128 (list 'org-agenda-compare-effort (list 'quote op)
7129 (org-duration-string-to-minutes e))))
7131 (defun org-agenda-compare-effort (op value)
7132 "Compare the effort of the current line with VALUE, using OP.
7133 If the line does not have an effort defined, return nil."
7134 (let ((eff (org-get-at-bol 'effort-minutes)))
7135 (if (equal op ??)
7136 (not eff)
7137 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7138 value))))
7140 (defun org-agenda-filter-apply (filter type)
7141 "Set FILTER as the new agenda filter and apply it."
7142 (let (tags cat)
7143 (if (eq type 'tag)
7144 (setq org-agenda-tag-filter filter)
7145 (setq org-agenda-category-filter filter))
7146 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7147 (if (and (eq type 'category)
7148 (not (equal (substring (car filter) 0 1) "-")))
7149 ;; Only set `org-agenda-filtered-by-category' to t
7150 ;; when a unique category is used as the filter
7151 (setq org-agenda-filtered-by-category t))
7152 (org-agenda-set-mode-name)
7153 (save-excursion
7154 (goto-char (point-min))
7155 (while (not (eobp))
7156 (if (org-get-at-bol 'org-marker)
7157 (progn
7158 (setq tags (org-get-at-bol 'tags) ; used in eval
7159 cat (get-text-property (point) 'org-category))
7160 (if (not (eval org-agenda-filter-form))
7161 (org-agenda-filter-hide-line type))
7162 (beginning-of-line 2))
7163 (beginning-of-line 2))))
7164 (if (get-char-property (point) 'invisible)
7165 (ignore-errors (org-agenda-previous-line)))))
7167 (defun org-agenda-filter-top-category-apply (category &optional negative)
7168 "Set FILTER as the new agenda filter and apply it."
7169 (org-agenda-set-mode-name)
7170 (save-excursion
7171 (goto-char (point-min))
7172 (while (not (eobp))
7173 (let* ((pos (org-get-at-bol 'org-hd-marker))
7174 (topcat (and pos (org-find-top-category pos))))
7175 (if (and topcat (funcall (if negative 'identity 'not)
7176 (string= category topcat)))
7177 (org-agenda-filter-hide-line 'category)))
7178 (beginning-of-line 2)))
7179 (if (get-char-property (point) 'invisible)
7180 (org-agenda-previous-line))
7181 (setq org-agenda-top-category-filter category
7182 org-agenda-filtered-by-top-category t))
7184 (defun org-agenda-filter-hide-line (type)
7185 (let (ov)
7186 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7187 (point-at-eol)))
7188 (overlay-put ov 'invisible t)
7189 (overlay-put ov 'type type)
7190 (if (eq type 'tag)
7191 (push ov org-agenda-tag-filter-overlays)
7192 (push ov org-agenda-cat-filter-overlays))))
7194 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7195 (setq pos (or pos (point)))
7196 (save-excursion
7197 (dolist (ov (overlays-at pos))
7198 (when (and (overlay-get ov 'invisible)
7199 (eq (overlay-get ov 'type) 'tag))
7200 (goto-char pos)
7201 (if (< (overlay-start ov) (point-at-eol))
7202 (move-overlay ov (point-at-eol)
7203 (overlay-end ov)))))))
7205 (defun org-agenda-filter-show-all-tag nil
7206 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7207 (setq org-agenda-tag-filter-overlays nil
7208 org-agenda-tag-filter nil
7209 org-agenda-filter-form nil)
7210 (org-agenda-set-mode-name))
7212 (defun org-agenda-filter-show-all-cat nil
7213 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7214 (setq org-agenda-cat-filter-overlays nil
7215 org-agenda-filtered-by-category nil
7216 org-agenda-category-filter nil
7217 org-agenda-filter-form nil)
7218 (org-agenda-set-mode-name))
7220 (defun org-agenda-manipulate-query-add ()
7221 "Manipulate the query by adding a search term with positive selection.
7222 Positive selection means the term must be matched for selection of an entry."
7223 (interactive)
7224 (org-agenda-manipulate-query ?\[))
7225 (defun org-agenda-manipulate-query-subtract ()
7226 "Manipulate the query by adding a search term with negative selection.
7227 Negative selection means term must not be matched for selection of an entry."
7228 (interactive)
7229 (org-agenda-manipulate-query ?\]))
7230 (defun org-agenda-manipulate-query-add-re ()
7231 "Manipulate the query by adding a search regexp with positive selection.
7232 Positive selection means the regexp must match for selection of an entry."
7233 (interactive)
7234 (org-agenda-manipulate-query ?\{))
7235 (defun org-agenda-manipulate-query-subtract-re ()
7236 "Manipulate the query by adding a search regexp with negative selection.
7237 Negative selection means regexp must not match for selection of an entry."
7238 (interactive)
7239 (org-agenda-manipulate-query ?\}))
7240 (defun org-agenda-manipulate-query (char)
7241 (cond
7242 ((memq org-agenda-type '(timeline agenda))
7243 (let ((org-agenda-include-inactive-timestamps t))
7244 (org-agenda-redo))
7245 (message "Display now includes inactive timestamps as well"))
7246 ((eq org-agenda-type 'search)
7247 (org-add-to-string
7248 'org-agenda-query-string
7249 (if org-agenda-last-search-view-search-was-boolean
7250 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7251 (?\{ . " +{}") (?\} . " -{}"))))
7252 " "))
7253 (setq org-agenda-redo-command
7254 (list 'org-search-view
7255 (car (get-text-property (min (1- (point-max)) (point))
7256 'org-last-args))
7257 org-agenda-query-string
7258 (+ (length org-agenda-query-string)
7259 (if (member char '(?\{ ?\})) 0 1))))
7260 (set-register org-agenda-query-register org-agenda-query-string)
7261 (let ((org-agenda-overriding-arguments
7262 (cdr org-agenda-redo-command)))
7263 (org-agenda-redo)))
7264 (t (error "Cannot manipulate query for %s-type agenda buffers"
7265 org-agenda-type))))
7267 (defun org-add-to-string (var string)
7268 (set var (concat (symbol-value var) string)))
7270 (defun org-agenda-goto-date (span)
7271 "Jump to DATE in agenda."
7272 (interactive "P")
7273 (let* ((org-read-date-prefer-future
7274 (eval org-agenda-jump-prefer-future))
7275 (date (org-read-date))
7276 (org-agenda-sticky-orig org-agenda-sticky)
7277 (org-agenda-buffer-tmp-name (buffer-name))
7278 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7279 (0-arg (or current-prefix-arg (car args)))
7280 (2-arg (nth 2 args))
7281 (newcmd (list 'org-agenda-list 0-arg date
7282 (org-agenda-span-to-ndays 2-arg)))
7283 (newargs (cdr newcmd))
7284 (inhibit-read-only t)
7285 org-agenda-sticky)
7286 (if (not (org-agenda-check-type t 'agenda))
7287 (error "Not available in non-agenda blocks")
7288 (add-text-properties (point-min) (point-max)
7289 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7290 (org-agenda-redo)
7291 (setq org-agenda-sticky org-agenda-sticky-orig
7292 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7294 (defun org-agenda-goto-today ()
7295 "Go to today."
7296 (interactive)
7297 (org-agenda-check-type t 'timeline 'agenda)
7298 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7299 (curspan (nth 2 args))
7300 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7301 (cond
7302 (tdpos (goto-char tdpos))
7303 ((eq org-agenda-type 'agenda)
7304 (let* ((sd (org-agenda-compute-starting-span
7305 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7306 (org-agenda-overriding-arguments args))
7307 (setf (nth 1 org-agenda-overriding-arguments) sd)
7308 (org-agenda-redo)
7309 (org-agenda-find-same-or-today-or-agenda)))
7310 (t (error "Cannot find today")))))
7312 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7313 (goto-char
7314 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7315 (text-property-any (point-min) (point-max) 'org-today t)
7316 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7317 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7318 (org-agenda-goto-block-beginning))
7319 (point-min))))
7321 (defun org-agenda-goto-block-beginning ()
7322 "Go the agenda block beginning."
7323 (interactive)
7324 (if (not (derived-mode-p 'org-agenda-mode))
7325 (error "Cannot execute this command outside of org-agenda-mode buffers")
7326 (let (dest)
7327 (save-excursion
7328 (unless (looking-at "\\'")
7329 (forward-char))
7330 (let* ((prop 'org-agenda-structural-header)
7331 (p (previous-single-property-change (point) prop))
7332 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7333 (1- (point))) prop)))
7334 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7335 (if (not dest)
7336 (error "Cannot find the beginning of the blog")
7337 (goto-char dest)
7338 (move-beginning-of-line 1)))))
7340 (defun org-agenda-later (arg)
7341 "Go forward in time by the current span.
7342 With prefix ARG, go forward that many times the current span."
7343 (interactive "p")
7344 (org-agenda-check-type t 'agenda)
7345 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7346 (span (or (nth 2 args) org-agenda-current-span))
7347 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7348 (greg (calendar-gregorian-from-absolute sd))
7349 (cnt (org-get-at-bol 'org-day-cnt))
7350 greg2)
7351 (cond
7352 ((numberp span)
7353 (setq sd (+ (* span arg) sd)))
7354 ((eq span 'day)
7355 (setq sd (+ arg sd)))
7356 ((eq span 'week)
7357 (setq sd (+ (* 7 arg) sd)))
7358 ((eq span 'month)
7359 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7360 sd (calendar-absolute-from-gregorian greg2))
7361 (setcar greg2 (1+ (car greg2))))
7362 ((eq span 'year)
7363 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7364 sd (calendar-absolute-from-gregorian greg2))
7365 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7367 (setq sd (+ (* span arg) sd))))
7368 (let ((org-agenda-overriding-cmd
7369 ;; `cmd' may have been set by `org-agenda-run-series' which
7370 ;; uses `org-agenda-overriding-cmd' to decide whether
7371 ;; overriding is allowed for `cmd'
7372 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7373 (org-agenda-overriding-arguments
7374 (list (car args) sd span)))
7375 (org-agenda-redo)
7376 (org-agenda-find-same-or-today-or-agenda cnt))))
7378 (defun org-agenda-earlier (arg)
7379 "Go backward in time by the current span.
7380 With prefix ARG, go backward that many times the current span."
7381 (interactive "p")
7382 (org-agenda-later (- arg)))
7384 (defun org-agenda-view-mode-dispatch ()
7385 "Call one of the view mode commands."
7386 (interactive)
7387 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7388 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7389 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7390 (let ((a (read-char-exclusive)))
7391 (case a
7392 (?\ (call-interactively 'org-agenda-reset-view))
7393 (?d (call-interactively 'org-agenda-day-view))
7394 (?w (call-interactively 'org-agenda-week-view))
7395 (?m (call-interactively 'org-agenda-month-view))
7396 (?y (call-interactively 'org-agenda-year-view))
7397 (?l (call-interactively 'org-agenda-log-mode))
7398 (?L (org-agenda-log-mode '(4)))
7399 (?c (org-agenda-log-mode 'clockcheck))
7400 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7401 (?a (call-interactively 'org-agenda-archives-mode))
7402 (?A (org-agenda-archives-mode 'files))
7403 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7404 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7405 (?G (call-interactively 'org-agenda-toggle-time-grid))
7406 (?D (call-interactively 'org-agenda-toggle-diary))
7407 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7408 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7409 (org-agenda-check-type t 'timeline 'agenda)
7410 (org-agenda-redo))
7411 (message "Display now includes inactive timestamps as well"))
7412 (?q (message "Abort"))
7413 (otherwise (error "Invalid key" )))))
7415 (defun org-agenda-reset-view ()
7416 "Switch to default view for agenda."
7417 (interactive)
7418 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7419 (defun org-agenda-day-view (&optional day-of-year)
7420 "Switch to daily view for agenda.
7421 With argument DAY-OF-YEAR, switch to that day of the year."
7422 (interactive "P")
7423 (org-agenda-change-time-span 'day day-of-year))
7424 (defun org-agenda-week-view (&optional iso-week)
7425 "Switch to daily view for agenda.
7426 With argument ISO-WEEK, switch to the corresponding ISO week.
7427 If ISO-WEEK has more then 2 digits, only the last two encode the
7428 week. Any digits before this encode a year. So 200712 means
7429 week 12 of year 2007. Years in the range 1938-2037 can also be
7430 written as 2-digit years."
7431 (interactive "P")
7432 (org-agenda-change-time-span 'week iso-week))
7433 (defun org-agenda-month-view (&optional month)
7434 "Switch to monthly view for agenda.
7435 With argument MONTH, switch to that month."
7436 (interactive "P")
7437 (org-agenda-change-time-span 'month month))
7438 (defun org-agenda-year-view (&optional year)
7439 "Switch to yearly view for agenda.
7440 With argument YEAR, switch to that year.
7441 If MONTH has more then 2 digits, only the last two encode the
7442 month. Any digits before this encode a year. So 200712 means
7443 December year 2007. Years in the range 1938-2037 can also be
7444 written as 2-digit years."
7445 (interactive "P")
7446 (when year
7447 (setq year (org-small-year-to-year year)))
7448 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7449 (org-agenda-change-time-span 'year year)
7450 (error "Abort")))
7452 (defun org-agenda-change-time-span (span &optional n)
7453 "Change the agenda view to SPAN.
7454 SPAN may be `day', `week', `month', `year'."
7455 (org-agenda-check-type t 'agenda)
7456 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7457 (curspan (nth 2 args)))
7458 (if (and (not n) (equal curspan span))
7459 (error "Viewing span is already \"%s\"" span))
7460 (let* ((sd (or (org-get-at-bol 'day)
7461 (nth 1 args)
7462 org-starting-day))
7463 (sd (org-agenda-compute-starting-span sd span n))
7464 (org-agenda-overriding-cmd
7465 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7466 (org-agenda-overriding-arguments
7467 (list (car args) sd span)))
7468 (org-agenda-redo)
7469 (org-agenda-find-same-or-today-or-agenda))
7470 (org-agenda-set-mode-name)
7471 (message "Switched to %s view" span)))
7473 (defun org-agenda-compute-starting-span (sd span &optional n)
7474 "Compute starting date for agenda.
7475 SPAN may be `day', `week', `month', `year'. The return value
7476 is a cons cell with the starting date and the number of days,
7477 so that the date SD will be in that range."
7478 (let* ((greg (calendar-gregorian-from-absolute sd))
7479 (dg (nth 1 greg))
7480 (mg (car greg))
7481 (yg (nth 2 greg)))
7482 (cond
7483 ((eq span 'day)
7484 (when n
7485 (setq sd (+ (calendar-absolute-from-gregorian
7486 (list mg 1 yg))
7487 n -1))))
7488 ((eq span 'week)
7489 (let* ((nt (calendar-day-of-week
7490 (calendar-gregorian-from-absolute sd)))
7491 (d (if org-agenda-start-on-weekday
7492 (- nt org-agenda-start-on-weekday)
7495 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7496 (when n
7497 (require 'cal-iso)
7498 (when (> n 99)
7499 (setq y1 (org-small-year-to-year (/ n 100))
7500 n (mod n 100)))
7501 (setq sd
7502 (calendar-absolute-from-iso
7503 (list n 1
7504 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7505 ((eq span 'month)
7506 (let (y1)
7507 (when (and n (> n 99))
7508 (setq y1 (org-small-year-to-year (/ n 100))
7509 n (mod n 100)))
7510 (setq sd (calendar-absolute-from-gregorian
7511 (list (or n mg) 1 (or y1 yg))))))
7512 ((eq span 'year)
7513 (setq sd (calendar-absolute-from-gregorian
7514 (list 1 1 (or n yg))))))
7515 sd))
7517 (defun org-agenda-next-date-line (&optional arg)
7518 "Jump to the next line indicating a date in agenda buffer."
7519 (interactive "p")
7520 (org-agenda-check-type t 'agenda 'timeline)
7521 (beginning-of-line 1)
7522 ;; This does not work if user makes date format that starts with a blank
7523 (if (looking-at "^\\S-") (forward-char 1))
7524 (if (not (re-search-forward "^\\S-" nil t arg))
7525 (progn
7526 (backward-char 1)
7527 (error "No next date after this line in this buffer")))
7528 (goto-char (match-beginning 0)))
7530 (defun org-agenda-previous-date-line (&optional arg)
7531 "Jump to the previous line indicating a date in agenda buffer."
7532 (interactive "p")
7533 (org-agenda-check-type t 'agenda 'timeline)
7534 (beginning-of-line 1)
7535 (if (not (re-search-backward "^\\S-" nil t arg))
7536 (error "No previous date before this line in this buffer")))
7538 ;; Initialize the highlight
7539 (defvar org-hl (make-overlay 1 1))
7540 (overlay-put org-hl 'face 'highlight)
7542 (defun org-highlight (begin end &optional buffer)
7543 "Highlight a region with overlay."
7544 (move-overlay org-hl begin end (or buffer (current-buffer))))
7546 (defun org-unhighlight ()
7547 "Detach overlay INDEX."
7548 (org-detach-overlay org-hl))
7550 (defun org-unhighlight-once ()
7551 "Remove the highlight from its position, and this function from the hook."
7552 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7553 (org-unhighlight))
7555 (defvar org-agenda-pre-follow-window-conf nil)
7556 (defun org-agenda-follow-mode ()
7557 "Toggle follow mode in an agenda buffer."
7558 (interactive)
7559 (unless org-agenda-follow-mode
7560 (setq org-agenda-pre-follow-window-conf
7561 (current-window-configuration)))
7562 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7563 (unless org-agenda-follow-mode
7564 (set-window-configuration org-agenda-pre-follow-window-conf))
7565 (org-agenda-set-mode-name)
7566 (org-agenda-do-context-action)
7567 (message "Follow mode is %s"
7568 (if org-agenda-follow-mode "on" "off")))
7570 (defun org-agenda-entry-text-mode (&optional arg)
7571 "Toggle entry text mode in an agenda buffer."
7572 (interactive "P")
7573 (setq org-agenda-entry-text-mode (or (integerp arg)
7574 (not org-agenda-entry-text-mode)))
7575 (org-agenda-entry-text-hide)
7576 (and org-agenda-entry-text-mode
7577 (let ((org-agenda-entry-text-maxlines
7578 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7579 (org-agenda-entry-text-show)))
7580 (org-agenda-set-mode-name)
7581 (message "Entry text mode is %s. Maximum number of lines is %d"
7582 (if org-agenda-entry-text-mode "on" "off")
7583 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7585 (defun org-agenda-clockreport-mode (&optional with-filter)
7586 "Toggle clocktable mode in an agenda buffer.
7587 With prefix arg WITH-FILTER, make the clocktable respect the current
7588 agenda filter."
7589 (interactive "P")
7590 (org-agenda-check-type t 'agenda)
7591 (if with-filter
7592 (setq org-agenda-clockreport-mode 'with-filter)
7593 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7594 (org-agenda-set-mode-name)
7595 (org-agenda-redo)
7596 (message "Clocktable mode is %s"
7597 (if org-agenda-clockreport-mode "on" "off")))
7599 (defun org-agenda-log-mode (&optional special)
7600 "Toggle log mode in an agenda buffer.
7601 With argument SPECIAL, show all possible log items, not only the ones
7602 configured in `org-agenda-log-mode-items'.
7603 With a double `C-u' prefix arg, show *only* log items, nothing else."
7604 (interactive "P")
7605 (org-agenda-check-type t 'agenda 'timeline)
7606 (setq org-agenda-show-log
7607 (cond
7608 ((equal special '(16)) 'only)
7609 ((eq special 'clockcheck)
7610 (if (eq org-agenda-show-log 'clockcheck)
7611 nil 'clockcheck))
7612 (special '(closed clock state))
7613 (t (not org-agenda-show-log))))
7614 (org-agenda-set-mode-name)
7615 (org-agenda-redo)
7616 (message "Log mode is %s"
7617 (if org-agenda-show-log "on" "off")))
7619 (defun org-agenda-archives-mode (&optional with-files)
7620 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7621 When called with a prefix argument, include all archive files as well."
7622 (interactive "P")
7623 (setq org-agenda-archives-mode
7624 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7625 (org-agenda-set-mode-name)
7626 (org-agenda-redo)
7627 (message
7628 "%s"
7629 (cond
7630 ((eq org-agenda-archives-mode nil)
7631 "No archives are included")
7632 ((eq org-agenda-archives-mode 'trees)
7633 (format "Trees with :%s: tag are included" org-archive-tag))
7634 ((eq org-agenda-archives-mode t)
7635 (format "Trees with :%s: tag and all active archive files are included"
7636 org-archive-tag)))))
7638 (defun org-agenda-toggle-diary ()
7639 "Toggle diary inclusion in an agenda buffer."
7640 (interactive)
7641 (org-agenda-check-type t 'agenda)
7642 (setq org-agenda-include-diary (not org-agenda-include-diary))
7643 (org-agenda-redo)
7644 (org-agenda-set-mode-name)
7645 (message "Diary inclusion turned %s"
7646 (if org-agenda-include-diary "on" "off")))
7648 (defun org-agenda-toggle-deadlines ()
7649 "Toggle inclusion of entries with a deadline in an agenda buffer."
7650 (interactive)
7651 (org-agenda-check-type t 'agenda)
7652 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7653 (org-agenda-redo)
7654 (org-agenda-set-mode-name)
7655 (message "Deadlines inclusion turned %s"
7656 (if org-agenda-include-deadlines "on" "off")))
7658 (defun org-agenda-toggle-time-grid ()
7659 "Toggle time grid in an agenda buffer."
7660 (interactive)
7661 (org-agenda-check-type t 'agenda)
7662 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7663 (org-agenda-redo)
7664 (org-agenda-set-mode-name)
7665 (message "Time-grid turned %s"
7666 (if org-agenda-use-time-grid "on" "off")))
7668 (defun org-agenda-set-mode-name ()
7669 "Set the mode name to indicate all the small mode settings."
7670 (setq mode-name
7671 (list "Org-Agenda"
7672 (if (get 'org-agenda-files 'org-restrict) " []" "")
7674 '(:eval (org-agenda-span-name org-agenda-current-span))
7675 (if org-agenda-follow-mode " Follow" "")
7676 (if org-agenda-entry-text-mode " ETxt" "")
7677 (if org-agenda-include-diary " Diary" "")
7678 (if org-agenda-include-deadlines " Ddl" "")
7679 (if org-agenda-use-time-grid " Grid" "")
7680 (if (and (boundp 'org-habit-show-habits)
7681 org-habit-show-habits) " Habit" "")
7682 (cond
7683 ((consp org-agenda-show-log) " LogAll")
7684 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7685 (org-agenda-show-log " Log")
7686 (t ""))
7687 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7688 :preset-filter))
7689 '(:eval (org-propertize
7690 (concat " <"
7691 (mapconcat
7692 'identity
7693 (append
7694 (get 'org-agenda-category-filter :preset-filter)
7695 org-agenda-category-filter)
7697 ">")
7698 'face 'org-agenda-filter-category
7699 'help-echo "Category used in filtering"))
7701 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7702 :preset-filter))
7703 '(:eval (org-propertize
7704 (concat " {"
7705 (mapconcat
7706 'identity
7707 (append
7708 (get 'org-agenda-tag-filter :preset-filter)
7709 org-agenda-tag-filter)
7711 "}")
7712 'face 'org-agenda-filter-tags
7713 'help-echo "Tags used in filtering"))
7715 (if org-agenda-archives-mode
7716 (if (eq org-agenda-archives-mode t)
7717 " Archives"
7718 (format " :%s:" org-archive-tag))
7720 (if org-agenda-clockreport-mode
7721 (if (eq org-agenda-clockreport-mode 'with-filter)
7722 " Clock{}" " Clock")
7723 "")))
7724 (force-mode-line-update))
7726 (define-obsolete-function-alias
7727 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7729 (defun org-agenda-update-agenda-type ()
7730 "Update the agenda type after each command."
7731 (setq org-agenda-type
7732 (or (get-text-property (point) 'org-agenda-type)
7733 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7735 (defun org-agenda-next-line ()
7736 "Move cursor to the next line, and show if follow mode is active."
7737 (interactive)
7738 (call-interactively 'next-line)
7739 (org-agenda-do-context-action))
7741 (defun org-agenda-previous-line ()
7742 "Move cursor to the previous line, and show if follow-mode is active."
7743 (interactive)
7744 (call-interactively 'previous-line)
7745 (org-agenda-do-context-action))
7747 (defun org-agenda-next-item (n)
7748 "Move cursor to next agenda item."
7749 (interactive "p")
7750 (let ((col (current-column)))
7751 (dotimes (c n)
7752 (when (next-single-property-change (point-at-eol) 'org-marker)
7753 (move-end-of-line 1)
7754 (goto-char (next-single-property-change (point) 'org-marker))))
7755 (org-move-to-column col))
7756 (org-agenda-do-context-action))
7758 (defun org-agenda-previous-item (n)
7759 "Move cursor to next agenda item."
7760 (interactive "p")
7761 (dotimes (c n)
7762 (let ((col (current-column))
7763 (goto (save-excursion
7764 (move-end-of-line 0)
7765 (previous-single-property-change (point) 'org-marker))))
7766 (if goto (goto-char goto))
7767 (org-move-to-column col)))
7768 (org-agenda-do-context-action))
7770 (defun org-agenda-do-context-action ()
7771 "Show outline path and, maybe, follow mode window."
7772 (let ((m (org-get-at-bol 'org-marker)))
7773 (when (and (markerp m) (marker-buffer m))
7774 (and org-agenda-follow-mode
7775 (if org-agenda-follow-indirect
7776 (org-agenda-tree-to-indirect-buffer nil)
7777 (org-agenda-show)))
7778 (and org-agenda-show-outline-path
7779 (org-with-point-at m (org-display-outline-path t))))))
7781 (defun org-agenda-show-tags ()
7782 "Show the tags applicable to the current item."
7783 (interactive)
7784 (let* ((tags (org-get-at-bol 'tags)))
7785 (if tags
7786 (message "Tags are :%s:"
7787 (org-no-properties (mapconcat 'identity tags ":")))
7788 (message "No tags associated with this line"))))
7790 (defun org-agenda-goto (&optional highlight)
7791 "Go to the Org-mode file which contains the item at point."
7792 (interactive)
7793 (let* ((marker (or (org-get-at-bol 'org-marker)
7794 (org-agenda-error)))
7795 (buffer (marker-buffer marker))
7796 (pos (marker-position marker)))
7797 (switch-to-buffer-other-window buffer)
7798 (widen)
7799 (push-mark)
7800 (goto-char pos)
7801 (when (derived-mode-p 'org-mode)
7802 (org-show-context 'agenda)
7803 (save-excursion
7804 (and (outline-next-heading)
7805 (org-flag-heading nil)))) ; show the next heading
7806 (when (outline-invisible-p)
7807 (show-entry)) ; display invisible text
7808 (recenter (/ (window-height) 2))
7809 (run-hooks 'org-agenda-after-show-hook)
7810 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7812 (defvar org-agenda-after-show-hook nil
7813 "Normal hook run after an item has been shown from the agenda.
7814 Point is in the buffer where the item originated.")
7816 (defun org-agenda-kill ()
7817 "Kill the entry or subtree belonging to the current agenda entry."
7818 (interactive)
7819 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7820 (let* ((bufname-orig (buffer-name))
7821 (marker (or (org-get-at-bol 'org-marker)
7822 (org-agenda-error)))
7823 (buffer (marker-buffer marker))
7824 (pos (marker-position marker))
7825 (type (org-get-at-bol 'type))
7826 dbeg dend (n 0) conf)
7827 (org-with-remote-undo buffer
7828 (with-current-buffer buffer
7829 (save-excursion
7830 (goto-char pos)
7831 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7832 (setq dbeg (progn (org-back-to-heading t) (point))
7833 dend (org-end-of-subtree t t))
7834 (setq dbeg (point-at-bol)
7835 dend (min (point-max) (1+ (point-at-eol)))))
7836 (goto-char dbeg)
7837 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7838 (setq conf (or (eq t org-agenda-confirm-kill)
7839 (and (numberp org-agenda-confirm-kill)
7840 (> n org-agenda-confirm-kill))))
7841 (and conf
7842 (not (y-or-n-p
7843 (format "Delete entry with %d lines in buffer \"%s\"? "
7844 n (buffer-name buffer))))
7845 (error "Abort"))
7846 (let ((org-agenda-buffer-name bufname-orig))
7847 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7848 (with-current-buffer buffer (delete-region dbeg dend))
7849 (message "Agenda item and source killed"))))
7851 (defvar org-archive-default-command) ; defined in org-archive.el
7852 (defun org-agenda-archive-default ()
7853 "Archive the entry or subtree belonging to the current agenda entry."
7854 (interactive)
7855 (require 'org-archive)
7856 (org-agenda-archive-with org-archive-default-command))
7858 (defun org-agenda-archive-default-with-confirmation ()
7859 "Archive the entry or subtree belonging to the current agenda entry."
7860 (interactive)
7861 (require 'org-archive)
7862 (org-agenda-archive-with org-archive-default-command 'confirm))
7864 (defun org-agenda-archive ()
7865 "Archive the entry or subtree belonging to the current agenda entry."
7866 (interactive)
7867 (org-agenda-archive-with 'org-archive-subtree))
7869 (defun org-agenda-archive-to-archive-sibling ()
7870 "Move the entry to the archive sibling."
7871 (interactive)
7872 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7874 (defun org-agenda-archive-with (cmd &optional confirm)
7875 "Move the entry to the archive sibling."
7876 (interactive)
7877 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7878 (let* ((bufname-orig (buffer-name))
7879 (marker (or (org-get-at-bol 'org-marker)
7880 (org-agenda-error)))
7881 (buffer (marker-buffer marker))
7882 (pos (marker-position marker)))
7883 (org-with-remote-undo buffer
7884 (with-current-buffer buffer
7885 (if (derived-mode-p 'org-mode)
7886 (if (and confirm
7887 (not (y-or-n-p "Archive this subtree or entry? ")))
7888 (error "Abort")
7889 (save-excursion
7890 (goto-char pos)
7891 (let ((org-agenda-buffer-name bufname-orig))
7892 (org-remove-subtree-entries-from-agenda))
7893 (org-back-to-heading t)
7894 (funcall cmd)))
7895 (error "Archiving works only in Org-mode files"))))))
7897 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7898 "Remove all lines in the agenda that correspond to a given subtree.
7899 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7900 If this information is not given, the function uses the tree at point."
7901 (let ((buf (or buf (current-buffer))) m p)
7902 (save-excursion
7903 (unless (and beg end)
7904 (org-back-to-heading t)
7905 (setq beg (point))
7906 (org-end-of-subtree t)
7907 (setq end (point)))
7908 (set-buffer (get-buffer org-agenda-buffer-name))
7909 (save-excursion
7910 (goto-char (point-max))
7911 (beginning-of-line 1)
7912 (while (not (bobp))
7913 (when (and (setq m (org-get-at-bol 'org-marker))
7914 (equal buf (marker-buffer m))
7915 (setq p (marker-position m))
7916 (>= p beg)
7917 (< p end))
7918 (let ((inhibit-read-only t))
7919 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7920 (beginning-of-line 0))))))
7922 (defun org-agenda-refile (&optional goto rfloc no-update)
7923 "Refile the item at point."
7924 (interactive "P")
7925 (if (equal goto '(16))
7926 (org-refile-goto-last-stored)
7927 (let* ((buffer-orig (buffer-name))
7928 (marker (or (org-get-at-bol 'org-hd-marker)
7929 (org-agenda-error)))
7930 (buffer (marker-buffer marker))
7931 (pos (marker-position marker))
7932 (rfloc (or rfloc
7933 (org-refile-get-location
7934 (if goto "Goto" "Refile to") buffer
7935 org-refile-allow-creating-parent-nodes))))
7936 (with-current-buffer buffer
7937 (save-excursion
7938 (save-restriction
7939 (widen)
7940 (goto-char marker)
7941 (let ((org-agenda-buffer-name buffer-orig))
7942 (org-remove-subtree-entries-from-agenda))
7943 (org-refile goto buffer rfloc)))))
7944 (unless no-update (org-agenda-redo))))
7946 (defun org-agenda-open-link (&optional arg)
7947 "Follow the link in the current line, if any.
7948 This looks for a link in the displayed line in the agenda. It also looks
7949 at the text of the entry itself."
7950 (interactive "P")
7951 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7952 (org-get-at-bol 'org-marker)))
7953 (buffer (and marker (marker-buffer marker)))
7954 (prefix (buffer-substring
7955 (point-at-bol) (point-at-eol))))
7956 (cond
7957 (buffer
7958 (with-current-buffer buffer
7959 (save-excursion
7960 (save-restriction
7961 (widen)
7962 (goto-char marker)
7963 (org-offer-links-in-entry arg prefix)))))
7964 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7965 (save-excursion
7966 (beginning-of-line 1)
7967 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7968 (org-open-link-from-string (match-string 1)))
7969 (t (error "No link to open here")))))
7971 (defun org-agenda-copy-local-variable (var)
7972 "Get a variable from a referenced buffer and install it here."
7973 (let ((m (org-get-at-bol 'org-marker)))
7974 (when (and m (buffer-live-p (marker-buffer m)))
7975 (org-set-local var (with-current-buffer (marker-buffer m)
7976 (symbol-value var))))))
7978 (defun org-agenda-switch-to (&optional delete-other-windows)
7979 "Go to the Org-mode file which contains the item at point."
7980 (interactive)
7981 (if (and org-return-follows-link
7982 (not (org-get-at-bol 'org-marker))
7983 (org-in-regexp org-bracket-link-regexp))
7984 (org-open-link-from-string (match-string 0))
7985 (let* ((marker (or (org-get-at-bol 'org-marker)
7986 (org-agenda-error)))
7987 (buffer (marker-buffer marker))
7988 (pos (marker-position marker)))
7989 (org-pop-to-buffer-same-window buffer)
7990 (and delete-other-windows (delete-other-windows))
7991 (widen)
7992 (goto-char pos)
7993 (when (derived-mode-p 'org-mode)
7994 (org-show-context 'agenda)
7995 (save-excursion
7996 (and (outline-next-heading)
7997 (org-flag-heading nil))) ; show the next heading
7998 (when (outline-invisible-p)
7999 (show-entry)) ; display invisible text
8000 (run-hooks 'org-agenda-after-show-hook)))))
8002 (defun org-agenda-goto-mouse (ev)
8003 "Go to the Org-mode file which contains the item at the mouse click."
8004 (interactive "e")
8005 (mouse-set-point ev)
8006 (org-agenda-goto))
8008 (defun org-agenda-show (&optional full-entry)
8009 "Display the Org-mode file which contains the item at point.
8010 With prefix argument FULL-ENTRY, make the entire entry visible
8011 if it was hidden in the outline."
8012 (interactive "P")
8013 (let ((win (selected-window)))
8014 (if full-entry
8015 (let ((org-show-entry-below t))
8016 (org-agenda-goto t))
8017 (org-agenda-goto t))
8018 (select-window win)))
8020 (defvar org-agenda-show-window nil)
8021 (defun org-agenda-show-and-scroll-up (&optional arg)
8022 "Display the Org-mode file which contains the item at point.
8023 When called repeatedly, scroll the window that is displaying the buffer.
8024 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8025 `show-subtree' to display the item, so that drawers and logbooks stay
8026 folded."
8027 (interactive "P")
8028 (let ((win (selected-window)))
8029 (if (and (window-live-p org-agenda-show-window)
8030 (eq this-command last-command))
8031 (progn
8032 (select-window org-agenda-show-window)
8033 (ignore-errors (scroll-up)))
8034 (org-agenda-goto t)
8035 (if arg (org-show-entry) (show-subtree))
8036 (setq org-agenda-show-window (selected-window)))
8037 (select-window win)))
8039 (defun org-agenda-show-scroll-down ()
8040 "Scroll down the window showing the agenda."
8041 (interactive)
8042 (let ((win (selected-window)))
8043 (when (window-live-p org-agenda-show-window)
8044 (select-window org-agenda-show-window)
8045 (ignore-errors (scroll-down))
8046 (select-window win))))
8048 (defun org-agenda-show-1 (&optional more)
8049 "Display the Org-mode file which contains the item at point.
8050 The prefix arg selects the amount of information to display:
8052 0 hide the subtree
8053 1 just show the entry according to defaults.
8054 2 show the children view
8055 3 show the subtree view
8056 4 show the entire subtree and any LOGBOOK drawers
8057 5 show the entire subtree and any drawers
8058 With prefix argument FULL-ENTRY, make the entire entry visible
8059 if it was hidden in the outline."
8060 (interactive "p")
8061 (let ((win (selected-window)))
8062 (org-agenda-goto t)
8063 (org-recenter-heading 1)
8064 (cond
8065 ((= more 0)
8066 (hide-subtree)
8067 (save-excursion
8068 (org-back-to-heading)
8069 (run-hook-with-args 'org-cycle-hook 'folded))
8070 (message "Remote: FOLDED"))
8071 ((and (org-called-interactively-p 'any) (= more 1))
8072 (message "Remote: show with default settings"))
8073 ((= more 2)
8074 (show-entry)
8075 (show-children)
8076 (save-excursion
8077 (org-back-to-heading)
8078 (run-hook-with-args 'org-cycle-hook 'children))
8079 (message "Remote: CHILDREN"))
8080 ((= more 3)
8081 (show-subtree)
8082 (save-excursion
8083 (org-back-to-heading)
8084 (run-hook-with-args 'org-cycle-hook 'subtree))
8085 (message "Remote: SUBTREE"))
8086 ((= more 4)
8087 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8088 (org-drawer-regexp
8089 (concat "^[ \t]*:\\("
8090 (mapconcat 'regexp-quote org-drawers "\\|")
8091 "\\):[ \t]*$")))
8092 (show-subtree)
8093 (save-excursion
8094 (org-back-to-heading)
8095 (org-cycle-hide-drawers 'subtree)))
8096 (message "Remote: SUBTREE AND LOGBOOK"))
8097 ((> more 4)
8098 (show-subtree)
8099 (message "Remote: SUBTREE AND ALL DRAWERS")))
8100 (select-window win)))
8102 (defun org-recenter-heading (n)
8103 (save-excursion
8104 (org-back-to-heading)
8105 (recenter n)))
8107 (defvar org-agenda-cycle-counter nil)
8108 (defun org-agenda-cycle-show (&optional n)
8109 "Show the current entry in another window, with default settings.
8110 Default settings are taken from `org-show-hierarchy-above' and siblings.
8111 When use repeatedly in immediate succession, the remote entry will cycle
8112 through visibility
8114 children -> subtree -> folded
8116 When called with a numeric prefix arg, that arg will be passed through to
8117 `org-agenda-show-1'. For the interpretation of that argument, see the
8118 docstring of `org-agenda-show-1'."
8119 (interactive "P")
8120 (if (integerp n)
8121 (setq org-agenda-cycle-counter n)
8122 (if (not (eq last-command this-command))
8123 (setq org-agenda-cycle-counter 1)
8124 (if (equal org-agenda-cycle-counter 0)
8125 (setq org-agenda-cycle-counter 2)
8126 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8127 (if (> org-agenda-cycle-counter 3)
8128 (setq org-agenda-cycle-counter 0)))))
8129 (org-agenda-show-1 org-agenda-cycle-counter))
8131 (defun org-agenda-recenter (arg)
8132 "Display the Org-mode file which contains the item at point and recenter."
8133 (interactive "P")
8134 (let ((win (selected-window)))
8135 (org-agenda-goto t)
8136 (recenter arg)
8137 (select-window win)))
8139 (defun org-agenda-show-mouse (ev)
8140 "Display the Org-mode file which contains the item at the mouse click."
8141 (interactive "e")
8142 (mouse-set-point ev)
8143 (org-agenda-show))
8145 (defun org-agenda-check-no-diary ()
8146 "Check if the entry is a diary link and abort if yes."
8147 (if (org-get-at-bol 'org-agenda-diary-link)
8148 (org-agenda-error)))
8150 (defun org-agenda-error ()
8151 (error "Command not allowed in this line"))
8153 (defun org-agenda-tree-to-indirect-buffer (arg)
8154 "Show the subtree corresponding to the current entry in an indirect buffer.
8155 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8157 With a numerical prefix ARG, go up to this level and then take that tree.
8158 With a negative numeric ARG, go up by this number of levels.
8159 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8160 use the dedicated frame)."
8161 (interactive "P")
8162 (if current-prefix-arg
8163 (org-agenda-do-tree-to-indirect-buffer arg)
8164 (let ((agenda-buffer (buffer-name))
8165 (agenda-window (selected-window))
8166 (indirect-window
8167 (and org-last-indirect-buffer
8168 (get-buffer-window org-last-indirect-buffer))))
8169 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8170 (unless (or (eq org-indirect-buffer-display 'new-frame)
8171 (eq org-indirect-buffer-display 'dedicated-frame))
8172 (unwind-protect
8173 (unless (and indirect-window (window-live-p indirect-window))
8174 (setq indirect-window (split-window agenda-window)))
8175 (and indirect-window (select-window indirect-window))
8176 (switch-to-buffer org-last-indirect-buffer :norecord)
8177 (fit-window-to-buffer indirect-window)))
8178 (select-window (get-buffer-window agenda-buffer)))))
8180 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8181 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8182 (org-agenda-check-no-diary)
8183 (let* ((marker (or (org-get-at-bol 'org-marker)
8184 (org-agenda-error)))
8185 (buffer (marker-buffer marker))
8186 (pos (marker-position marker)))
8187 (with-current-buffer buffer
8188 (save-excursion
8189 (goto-char pos)
8190 (funcall 'org-tree-to-indirect-buffer arg)))))
8192 (defvar org-last-heading-marker (make-marker)
8193 "Marker pointing to the headline that last changed its TODO state
8194 by a remote command from the agenda.")
8196 (defun org-agenda-todo-nextset ()
8197 "Switch TODO entry to next sequence."
8198 (interactive)
8199 (org-agenda-todo 'nextset))
8201 (defun org-agenda-todo-previousset ()
8202 "Switch TODO entry to previous sequence."
8203 (interactive)
8204 (org-agenda-todo 'previousset))
8206 (defun org-agenda-todo (&optional arg)
8207 "Cycle TODO state of line at point, also in Org-mode file.
8208 This changes the line at point, all other lines in the agenda referring to
8209 the same tree node, and the headline of the tree node in the Org-mode file."
8210 (interactive "P")
8211 (org-agenda-check-no-diary)
8212 (let* ((col (current-column))
8213 (marker (or (org-get-at-bol 'org-marker)
8214 (org-agenda-error)))
8215 (buffer (marker-buffer marker))
8216 (pos (marker-position marker))
8217 (hdmarker (org-get-at-bol 'org-hd-marker))
8218 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8219 (inhibit-read-only t)
8220 org-agenda-headline-snapshot-before-repeat newhead just-one)
8221 (org-with-remote-undo buffer
8222 (with-current-buffer buffer
8223 (widen)
8224 (goto-char pos)
8225 (org-show-context 'agenda)
8226 (save-excursion
8227 (and (outline-next-heading)
8228 (org-flag-heading nil))) ; show the next heading
8229 (let ((current-prefix-arg arg))
8230 (call-interactively 'org-todo))
8231 (and (bolp) (forward-char 1))
8232 (setq newhead (org-get-heading))
8233 (when (and (org-bound-and-true-p
8234 org-agenda-headline-snapshot-before-repeat)
8235 (not (equal org-agenda-headline-snapshot-before-repeat
8236 newhead))
8237 todayp)
8238 (setq newhead org-agenda-headline-snapshot-before-repeat
8239 just-one t))
8240 (save-excursion
8241 (org-back-to-heading)
8242 (move-marker org-last-heading-marker (point))))
8243 (beginning-of-line 1)
8244 (save-excursion
8245 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8246 (org-move-to-column col))))
8248 (defun org-agenda-add-note (&optional arg)
8249 "Add a time-stamped note to the entry at point."
8250 (interactive "P")
8251 (org-agenda-check-no-diary)
8252 (let* ((marker (or (org-get-at-bol 'org-marker)
8253 (org-agenda-error)))
8254 (buffer (marker-buffer marker))
8255 (pos (marker-position marker))
8256 (hdmarker (org-get-at-bol 'org-hd-marker))
8257 (inhibit-read-only t))
8258 (with-current-buffer buffer
8259 (widen)
8260 (goto-char pos)
8261 (org-show-context 'agenda)
8262 (save-excursion
8263 (and (outline-next-heading)
8264 (org-flag-heading nil))) ; show the next heading
8265 (org-add-note))))
8267 (defun org-agenda-change-all-lines (newhead hdmarker
8268 &optional fixface just-this)
8269 "Change all lines in the agenda buffer which match HDMARKER.
8270 The new content of the line will be NEWHEAD (as modified by
8271 `org-agenda-format-item'). HDMARKER is checked with
8272 `equal' against all `org-hd-marker' text properties in the file.
8273 If FIXFACE is non-nil, the face of each item is modified according to
8274 the new TODO state.
8275 If JUST-THIS is non-nil, change just the current line, not all.
8276 If FORCE-TAGS is non nil, the car of it returns the new tags."
8277 (let* ((inhibit-read-only t)
8278 (line (org-current-line))
8279 (org-agenda-buffer (current-buffer))
8280 (thetags (with-current-buffer (marker-buffer hdmarker)
8281 (save-excursion (save-restriction (widen)
8282 (goto-char hdmarker)
8283 (org-get-tags-at)))))
8284 props m pl undone-face done-face finish new dotime level cat tags)
8285 (save-excursion
8286 (goto-char (point-max))
8287 (beginning-of-line 1)
8288 (while (not finish)
8289 (setq finish (bobp))
8290 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8291 (or (not just-this) (= (org-current-line) line))
8292 (equal m hdmarker))
8293 (setq props (text-properties-at (point))
8294 dotime (org-get-at-bol 'dotime)
8295 cat (org-get-at-bol 'org-category)
8296 level (org-get-at-bol 'level)
8297 tags thetags
8299 (let ((org-prefix-format-compiled
8300 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8301 org-prefix-format-compiled))
8302 (extra (org-get-at-bol 'extra)))
8303 (with-current-buffer (marker-buffer hdmarker)
8304 (save-excursion
8305 (save-restriction
8306 (widen)
8307 (org-agenda-format-item extra newhead level cat tags dotime)))))
8308 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8309 undone-face (org-get-at-bol 'undone-face)
8310 done-face (org-get-at-bol 'done-face))
8311 (beginning-of-line 1)
8312 (cond
8313 ((equal new "")
8314 (and (looking-at ".*\n?") (replace-match "")))
8315 ((looking-at ".*")
8316 (replace-match new t t)
8317 (beginning-of-line 1)
8318 (add-text-properties (point-at-bol) (point-at-eol) props)
8319 (when fixface
8320 (add-text-properties
8321 (point-at-bol) (point-at-eol)
8322 (list 'face
8323 (if org-last-todo-state-is-todo
8324 undone-face done-face))))
8325 (org-agenda-highlight-todo 'line)
8326 (beginning-of-line 1))
8327 (t (error "Line update did not work")))
8328 (save-restriction
8329 (narrow-to-region (point-at-bol) (point-at-eol))
8330 (org-agenda-finalize)))
8331 (beginning-of-line 0)))))
8333 (defun org-agenda-align-tags (&optional line)
8334 "Align all tags in agenda items to `org-agenda-tags-column'."
8335 (let ((inhibit-read-only t) l c)
8336 (save-excursion
8337 (goto-char (if line (point-at-bol) (point-min)))
8338 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8339 (if line (point-at-eol) nil) t)
8340 (add-text-properties
8341 (match-beginning 2) (match-end 2)
8342 (list 'face (delq nil (let ((prop (get-text-property
8343 (match-beginning 2) 'face)))
8344 (or (listp prop) (setq prop (list prop)))
8345 (if (memq 'org-tag prop)
8346 prop
8347 (cons 'org-tag prop))))))
8348 (setq l (- (match-end 2) (match-beginning 2))
8349 c (if (< org-agenda-tags-column 0)
8350 (- (abs org-agenda-tags-column) l)
8351 org-agenda-tags-column))
8352 (delete-region (match-beginning 1) (match-end 1))
8353 (goto-char (match-beginning 1))
8354 (insert (org-add-props
8355 (make-string (max 1 (- c (current-column))) ?\ )
8356 (plist-put (copy-sequence (text-properties-at (point)))
8357 'face nil))))
8358 (goto-char (point-min))
8359 (org-font-lock-add-tag-faces (point-max)))))
8361 (defun org-agenda-priority-up ()
8362 "Increase the priority of line at point, also in Org-mode file."
8363 (interactive)
8364 (org-agenda-priority 'up))
8366 (defun org-agenda-priority-down ()
8367 "Decrease the priority of line at point, also in Org-mode file."
8368 (interactive)
8369 (org-agenda-priority 'down))
8371 (defun org-agenda-priority (&optional force-direction show)
8372 "Set the priority of line at point, also in Org-mode file.
8373 This changes the line at point, all other lines in the agenda referring to
8374 the same tree node, and the headline of the tree node in the Org-mode file."
8375 (interactive "P")
8376 (if (equal force-direction '(4)) (setq show t))
8377 (unless org-enable-priority-commands
8378 (error "Priority commands are disabled"))
8379 (org-agenda-check-no-diary)
8380 (let* ((marker (or (org-get-at-bol 'org-marker)
8381 (org-agenda-error)))
8382 (hdmarker (org-get-at-bol 'org-hd-marker))
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 (org-show-context 'agenda)
8392 (save-excursion
8393 (and (outline-next-heading)
8394 (org-flag-heading nil))) ; show the next heading
8395 (funcall 'org-priority force-direction show)
8396 (end-of-line 1)
8397 (setq newhead (org-get-heading)))
8398 (org-agenda-change-all-lines newhead hdmarker)
8399 (beginning-of-line 1))))
8401 ;; FIXME: should fix the tags property of the agenda line.
8402 (defun org-agenda-set-tags (&optional tag onoff)
8403 "Set tags for the current headline."
8404 (interactive)
8405 (org-agenda-check-no-diary)
8406 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8407 (call-interactively 'org-change-tag-in-region)
8408 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8409 (org-agenda-error)))
8410 (buffer (marker-buffer hdmarker))
8411 (pos (marker-position hdmarker))
8412 (inhibit-read-only t)
8413 newhead)
8414 (org-with-remote-undo buffer
8415 (with-current-buffer buffer
8416 (widen)
8417 (goto-char pos)
8418 (save-excursion
8419 (org-show-context 'agenda))
8420 (save-excursion
8421 (and (outline-next-heading)
8422 (org-flag-heading nil))) ; show the next heading
8423 (goto-char pos)
8424 (if tag
8425 (org-toggle-tag tag onoff)
8426 (call-interactively 'org-set-tags))
8427 (end-of-line 1)
8428 (setq newhead (org-get-heading)))
8429 (org-agenda-change-all-lines newhead hdmarker)
8430 (beginning-of-line 1)))))
8432 (defun org-agenda-set-property ()
8433 "Set a property for the current headline."
8434 (interactive)
8435 (org-agenda-check-no-diary)
8436 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8437 (org-agenda-error)))
8438 (buffer (marker-buffer hdmarker))
8439 (pos (marker-position hdmarker))
8440 (inhibit-read-only t)
8441 newhead)
8442 (org-with-remote-undo buffer
8443 (with-current-buffer buffer
8444 (widen)
8445 (goto-char pos)
8446 (save-excursion
8447 (org-show-context 'agenda))
8448 (save-excursion
8449 (and (outline-next-heading)
8450 (org-flag-heading nil))) ; show the next heading
8451 (goto-char pos)
8452 (call-interactively 'org-set-property)))))
8454 (defun org-agenda-set-effort ()
8455 "Set the effort property for the current headline."
8456 (interactive)
8457 (org-agenda-check-no-diary)
8458 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8459 (org-agenda-error)))
8460 (buffer (marker-buffer hdmarker))
8461 (pos (marker-position hdmarker))
8462 (inhibit-read-only t)
8463 newhead)
8464 (org-with-remote-undo buffer
8465 (with-current-buffer buffer
8466 (widen)
8467 (goto-char pos)
8468 (save-excursion
8469 (org-show-context 'agenda))
8470 (save-excursion
8471 (and (outline-next-heading)
8472 (org-flag-heading nil))) ; show the next heading
8473 (goto-char pos)
8474 (call-interactively 'org-set-effort)
8475 (end-of-line 1)
8476 (setq newhead (org-get-heading)))
8477 (org-agenda-change-all-lines newhead hdmarker))))
8479 (defun org-agenda-toggle-archive-tag ()
8480 "Toggle the archive tag for the current entry."
8481 (interactive)
8482 (org-agenda-check-no-diary)
8483 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8484 (org-agenda-error)))
8485 (buffer (marker-buffer hdmarker))
8486 (pos (marker-position hdmarker))
8487 (inhibit-read-only t)
8488 newhead)
8489 (org-with-remote-undo buffer
8490 (with-current-buffer buffer
8491 (widen)
8492 (goto-char pos)
8493 (org-show-context 'agenda)
8494 (save-excursion
8495 (and (outline-next-heading)
8496 (org-flag-heading nil))) ; show the next heading
8497 (call-interactively 'org-toggle-archive-tag)
8498 (end-of-line 1)
8499 (setq newhead (org-get-heading)))
8500 (org-agenda-change-all-lines newhead hdmarker)
8501 (beginning-of-line 1))))
8503 (defun org-agenda-do-date-later (arg)
8504 (interactive "P")
8505 (cond
8506 ((or (equal arg '(16))
8507 (memq last-command
8508 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8509 (setq this-command 'org-agenda-date-later-minutes)
8510 (org-agenda-date-later-minutes 1))
8511 ((or (equal arg '(4))
8512 (memq last-command
8513 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8514 (setq this-command 'org-agenda-date-later-hours)
8515 (org-agenda-date-later-hours 1))
8517 (org-agenda-date-later (prefix-numeric-value arg)))))
8519 (defun org-agenda-do-date-earlier (arg)
8520 (interactive "P")
8521 (cond
8522 ((or (equal arg '(16))
8523 (memq last-command
8524 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8525 (setq this-command 'org-agenda-date-earlier-minutes)
8526 (org-agenda-date-earlier-minutes 1))
8527 ((or (equal arg '(4))
8528 (memq last-command
8529 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8530 (setq this-command 'org-agenda-date-earlier-hours)
8531 (org-agenda-date-earlier-hours 1))
8533 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8535 (defun org-agenda-date-later (arg &optional what)
8536 "Change the date of this item to ARG day(s) later."
8537 (interactive "p")
8538 (org-agenda-check-type t 'agenda 'timeline)
8539 (org-agenda-check-no-diary)
8540 (let* ((marker (or (org-get-at-bol 'org-marker)
8541 (org-agenda-error)))
8542 (buffer (marker-buffer marker))
8543 (pos (marker-position marker))
8544 cdate today)
8545 (org-with-remote-undo buffer
8546 (with-current-buffer buffer
8547 (widen)
8548 (goto-char pos)
8549 (if (not (org-at-timestamp-p))
8550 (error "Cannot find time stamp"))
8551 (when (and org-agenda-move-date-from-past-immediately-to-today
8552 (equal arg 1)
8553 (or (not what) (eq what 'day))
8554 (not (save-match-data (org-at-date-range-p))))
8555 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8556 cdate (calendar-absolute-from-gregorian
8557 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8558 today (org-today))
8559 (if (> today cdate)
8560 ;; immediately shift to today
8561 (setq arg (- today cdate))))
8562 (org-timestamp-change arg (or what 'day))
8563 (when (and (org-at-date-range-p)
8564 (re-search-backward org-tr-regexp-both (point-at-bol)))
8565 (let ((end org-last-changed-timestamp))
8566 (org-timestamp-change arg (or what 'day))
8567 (setq org-last-changed-timestamp
8568 (concat org-last-changed-timestamp "--" end)))))
8569 (org-agenda-show-new-time marker org-last-changed-timestamp))
8570 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8572 (defun org-agenda-date-earlier (arg &optional what)
8573 "Change the date of this item to ARG day(s) earlier."
8574 (interactive "p")
8575 (org-agenda-date-later (- arg) what))
8577 (defun org-agenda-date-later-minutes (arg)
8578 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8579 (interactive "p")
8580 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8581 (org-agenda-date-later arg 'minute))
8583 (defun org-agenda-date-earlier-minutes (arg)
8584 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8585 (interactive "p")
8586 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8587 (org-agenda-date-earlier arg 'minute))
8589 (defun org-agenda-date-later-hours (arg)
8590 "Change the time of this item, in hour steps."
8591 (interactive "p")
8592 (org-agenda-date-later arg 'hour))
8594 (defun org-agenda-date-earlier-hours (arg)
8595 "Change the time of this item, in hour steps."
8596 (interactive "p")
8597 (org-agenda-date-earlier arg 'hour))
8599 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8600 "Show new date stamp via text properties."
8601 ;; We use text properties to make this undoable
8602 (let ((inhibit-read-only t)
8603 (buffer-invisibility-spec))
8604 (setq stamp (concat " " prefix " => " stamp))
8605 (save-excursion
8606 (goto-char (point-max))
8607 (while (not (bobp))
8608 (when (equal marker (org-get-at-bol 'org-marker))
8609 (org-move-to-column (- (window-width) (length stamp)) t)
8610 (org-agenda-fix-tags-filter-overlays-at (point))
8611 (if (featurep 'xemacs)
8612 ;; Use `duplicable' property to trigger undo recording
8613 (let ((ex (make-extent nil nil))
8614 (gl (make-glyph stamp)))
8615 (set-glyph-face gl 'secondary-selection)
8616 (set-extent-properties
8617 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8618 (insert-extent ex (1- (point)) (point-at-eol)))
8619 (add-text-properties
8620 (1- (point)) (point-at-eol)
8621 (list 'display (org-add-props stamp nil
8622 'face 'secondary-selection))))
8623 (beginning-of-line 1))
8624 (beginning-of-line 0)))))
8626 (defun org-agenda-date-prompt (arg)
8627 "Change the date of this item. Date is prompted for, with default today.
8628 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8629 be used to request time specification in the time stamp."
8630 (interactive "P")
8631 (org-agenda-check-type t 'agenda 'timeline)
8632 (org-agenda-check-no-diary)
8633 (let* ((marker (or (org-get-at-bol 'org-marker)
8634 (org-agenda-error)))
8635 (buffer (marker-buffer marker))
8636 (pos (marker-position marker)))
8637 (org-with-remote-undo buffer
8638 (with-current-buffer buffer
8639 (widen)
8640 (goto-char pos)
8641 (if (not (org-at-timestamp-p t))
8642 (error "Cannot find time stamp"))
8643 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8644 (org-agenda-show-new-time marker org-last-changed-timestamp))
8645 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8647 (defun org-agenda-schedule (arg &optional time)
8648 "Schedule the item at point.
8649 ARG is passed through to `org-schedule'."
8650 (interactive "P")
8651 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8652 (org-agenda-check-no-diary)
8653 (let* ((marker (or (org-get-at-bol 'org-marker)
8654 (org-agenda-error)))
8655 (type (marker-insertion-type marker))
8656 (buffer (marker-buffer marker))
8657 (pos (marker-position marker))
8658 (org-insert-labeled-timestamps-at-point nil)
8660 (set-marker-insertion-type marker t)
8661 (org-with-remote-undo buffer
8662 (with-current-buffer buffer
8663 (widen)
8664 (goto-char pos)
8665 (setq ts (org-schedule arg time)))
8666 (org-agenda-show-new-time marker ts "S"))
8667 (message "Item scheduled for %s" ts)))
8669 (defun org-agenda-deadline (arg &optional time)
8670 "Schedule the item at point.
8671 ARG is passed through to `org-deadline'."
8672 (interactive "P")
8673 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8674 (org-agenda-check-no-diary)
8675 (let* ((marker (or (org-get-at-bol 'org-marker)
8676 (org-agenda-error)))
8677 (buffer (marker-buffer marker))
8678 (pos (marker-position marker))
8679 (org-insert-labeled-timestamps-at-point nil)
8681 (org-with-remote-undo buffer
8682 (with-current-buffer buffer
8683 (widen)
8684 (goto-char pos)
8685 (setq ts (org-deadline arg time)))
8686 (org-agenda-show-new-time marker ts "D"))
8687 (message "Deadline for this item set to %s" ts)))
8689 (defun org-agenda-clock-in (&optional arg)
8690 "Start the clock on the currently selected item."
8691 (interactive "P")
8692 (org-agenda-check-no-diary)
8693 (if (equal arg '(4))
8694 (org-clock-in arg)
8695 (let* ((marker (or (org-get-at-bol 'org-marker)
8696 (org-agenda-error)))
8697 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8698 marker))
8699 (pos (marker-position marker))
8700 newhead)
8701 (org-with-remote-undo (marker-buffer marker)
8702 (with-current-buffer (marker-buffer marker)
8703 (widen)
8704 (goto-char pos)
8705 (org-show-context 'agenda)
8706 (org-show-entry)
8707 (org-cycle-hide-drawers 'children)
8708 (org-clock-in arg)
8709 (setq newhead (org-get-heading)))
8710 (org-agenda-change-all-lines newhead hdmarker)))))
8712 (defun org-agenda-clock-out ()
8713 "Stop the currently running clock."
8714 (interactive)
8715 (unless (marker-buffer org-clock-marker)
8716 (error "No running clock"))
8717 (let ((marker (make-marker)) newhead)
8718 (org-with-remote-undo (marker-buffer org-clock-marker)
8719 (with-current-buffer (marker-buffer org-clock-marker)
8720 (save-excursion
8721 (save-restriction
8722 (widen)
8723 (goto-char org-clock-marker)
8724 (org-back-to-heading t)
8725 (move-marker marker (point))
8726 (org-clock-out)
8727 (setq newhead (org-get-heading))))))
8728 (org-agenda-change-all-lines newhead marker)
8729 (move-marker marker nil)))
8731 (defun org-agenda-clock-cancel (&optional arg)
8732 "Cancel the currently running clock."
8733 (interactive "P")
8734 (unless (marker-buffer org-clock-marker)
8735 (error "No running clock"))
8736 (org-with-remote-undo (marker-buffer org-clock-marker)
8737 (org-clock-cancel)))
8739 (defun org-agenda-clock-goto ()
8740 "Jump to the currently clocked in task within the agenda.
8741 If the currently clocked in task is not listed in the agenda
8742 buffer, display it in another window."
8743 (interactive)
8744 (let (pos)
8745 (mapc (lambda (o)
8746 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8747 (setq pos (overlay-start o))))
8748 (overlays-in (point-min) (point-max)))
8749 (cond (pos (goto-char pos))
8750 ;; If the currently clocked entry is not in the agenda
8751 ;; buffer, we visit it in another window:
8752 (org-clock-current-task
8753 (org-switch-to-buffer-other-window (org-clock-goto)))
8754 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8756 (defun org-agenda-diary-entry-in-org-file ()
8757 "Make a diary entry in the file `org-agenda-diary-file'."
8758 (let (d1 d2 char (text "") dp1 dp2)
8759 (if (equal (buffer-name) "*Calendar*")
8760 (setq d1 (calendar-cursor-to-date t)
8761 d2 (car calendar-mark-ring))
8762 (setq dp1 (get-text-property (point-at-bol) 'day))
8763 (unless dp1 (error "No date defined in current line"))
8764 (setq d1 (calendar-gregorian-from-absolute dp1)
8765 d2 (and (ignore-errors (mark))
8766 (save-excursion
8767 (goto-char (mark))
8768 (setq dp2 (get-text-property (point-at-bol) 'day)))
8769 (calendar-gregorian-from-absolute dp2))))
8770 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8771 (setq char (read-char-exclusive))
8772 (cond
8773 ((equal char ?d)
8774 (setq text (read-string "Day entry: "))
8775 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8776 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8777 ((equal char ?a)
8778 (setq d1 (list (car d1) (nth 1 d1)
8779 (read-number (format "Reference year [%d]: " (nth 2 d1))
8780 (nth 2 d1))))
8781 (setq text (read-string "Anniversary (use %d to show years): "))
8782 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8783 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8784 ((equal char ?b)
8785 (setq text (read-string "Block entry: "))
8786 (unless (and d1 d2 (not (equal d1 d2)))
8787 (error "No block of days selected"))
8788 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8789 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8790 ((equal char ?j)
8791 (org-switch-to-buffer-other-window
8792 (find-file-noselect org-agenda-diary-file))
8793 (require 'org-datetree)
8794 (org-datetree-find-date-create d1)
8795 (org-reveal t))
8796 (t (error "Invalid selection character `%c'" char)))))
8798 (defcustom org-agenda-insert-diary-strategy 'date-tree
8799 "Where in `org-agenda-diary-file' should new entries be added?
8800 Valid values:
8802 date-tree in the date tree, as child of the date
8803 top-level as top-level entries at the end of the file."
8804 :group 'org-agenda
8805 :type '(choice
8806 (const :tag "in a date tree" date-tree)
8807 (const :tag "as top level at end of file" top-level)))
8809 (defcustom org-agenda-insert-diary-extract-time nil
8810 "Non-nil means extract any time specification from the diary entry."
8811 :group 'org-agenda
8812 :version "24.1"
8813 :type 'boolean)
8815 (defcustom org-agenda-bulk-mark-char ">"
8816 "A single-character string to be used as the bulk mark."
8817 :group 'org-agenda
8818 :version "24.1"
8819 :type 'string)
8821 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8822 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8823 If TEXT is not empty, it will become the headline of the new entry, and
8824 the resulting entry will not be shown. When TEXT is empty, switch to
8825 `org-agenda-diary-file' and let the user finish the entry there."
8826 (let ((cw (current-window-configuration)))
8827 (org-switch-to-buffer-other-window
8828 (find-file-noselect org-agenda-diary-file))
8829 (widen)
8830 (goto-char (point-min))
8831 (cond
8832 ((eq type 'anniversary)
8833 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8834 (progn
8835 (or (org-at-heading-p t)
8836 (progn
8837 (outline-next-heading)
8838 (insert "* Anniversaries\n\n")
8839 (beginning-of-line -1)))))
8840 (outline-next-heading)
8841 (org-back-over-empty-lines)
8842 (backward-char 1)
8843 (insert "\n")
8844 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8845 (nth 2 d1) (car d1) (nth 1 d1) text)))
8846 ((eq type 'day)
8847 (let ((org-prefix-has-time t)
8848 (org-agenda-time-leading-zero t)
8849 fmt time time2)
8850 (if org-agenda-insert-diary-extract-time
8851 ;; Use org-agenda-format-item to parse text for a time-range and
8852 ;; remove it. FIXME: This is a hack, we should refactor
8853 ;; that function to make time extraction available separately
8854 (setq fmt (org-agenda-format-item nil text nil nil nil t)
8855 time (get-text-property 0 'time fmt)
8856 time2 (if (> (length time) 0)
8857 ;; split-string removes trailing ...... if
8858 ;; no end time given. First space
8859 ;; separates time from date.
8860 (concat " " (car (split-string time "\\.")))
8861 nil)
8862 text (get-text-property 0 'txt fmt)))
8863 (if (eq org-agenda-insert-diary-strategy 'top-level)
8864 (org-agenda-insert-diary-as-top-level text)
8865 (require 'org-datetree)
8866 (org-datetree-find-date-create d1)
8867 (org-agenda-insert-diary-make-new-entry text))
8868 (org-insert-time-stamp (org-time-from-absolute
8869 (calendar-absolute-from-gregorian d1))
8870 nil nil nil nil time2))
8871 (end-of-line 0))
8872 ((eq type 'block)
8873 (if (> (calendar-absolute-from-gregorian d1)
8874 (calendar-absolute-from-gregorian d2))
8875 (setq d1 (prog1 d2 (setq d2 d1))))
8876 (if (eq org-agenda-insert-diary-strategy 'top-level)
8877 (org-agenda-insert-diary-as-top-level text)
8878 (require 'org-datetree)
8879 (org-datetree-find-date-create d1)
8880 (org-agenda-insert-diary-make-new-entry text))
8881 (org-insert-time-stamp (org-time-from-absolute
8882 (calendar-absolute-from-gregorian d1)))
8883 (insert "--")
8884 (org-insert-time-stamp (org-time-from-absolute
8885 (calendar-absolute-from-gregorian d2)))
8886 (end-of-line 0)))
8887 (if (string-match "\\S-" text)
8888 (progn
8889 (set-window-configuration cw)
8890 (message "%s entry added to %s"
8891 (capitalize (symbol-name type))
8892 (abbreviate-file-name org-agenda-diary-file)))
8893 (org-reveal t)
8894 (message "Please finish entry here"))))
8896 (defun org-agenda-insert-diary-as-top-level (text)
8897 "Make new entry as a top-level entry at the end of the file.
8898 Add TEXT as headline, and position the cursor in the second line so that
8899 a timestamp can be added there."
8900 (widen)
8901 (goto-char (point-max))
8902 (or (bolp) (insert "\n"))
8903 (insert "* " text "\n")
8904 (if org-adapt-indentation (org-indent-to-column 2)))
8906 (defun org-agenda-insert-diary-make-new-entry (text)
8907 "Make new entry as last child of current entry.
8908 Add TEXT as headline, and position the cursor in the second line so that
8909 a timestamp can be added there."
8910 (let ((org-show-following-heading t)
8911 (org-show-siblings t)
8912 (org-show-hierarchy-above t)
8913 (org-show-entry-below t)
8914 col)
8915 (outline-next-heading)
8916 (org-back-over-empty-lines)
8917 (or (looking-at "[ \t]*$")
8918 (progn (insert "\n") (backward-char 1)))
8919 (org-insert-heading nil t)
8920 (org-do-demote)
8921 (setq col (current-column))
8922 (insert text "\n")
8923 (if org-adapt-indentation (org-indent-to-column col))
8924 (let ((org-show-following-heading t)
8925 (org-show-siblings t)
8926 (org-show-hierarchy-above t)
8927 (org-show-entry-below t))
8928 (org-show-context))))
8930 (defun org-agenda-diary-entry ()
8931 "Make a diary entry, like the `i' command from the calendar.
8932 All the standard commands work: block, weekly etc.
8933 When `org-agenda-diary-file' points to a file,
8934 `org-agenda-diary-entry-in-org-file' is called instead to create
8935 entries in that Org-mode file."
8936 (interactive)
8937 (if (not (eq org-agenda-diary-file 'diary-file))
8938 (org-agenda-diary-entry-in-org-file)
8939 (require 'diary-lib)
8940 (let* ((char (progn
8941 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8942 (read-char-exclusive)))
8943 (cmd (cdr (assoc char
8944 '((?d . insert-diary-entry)
8945 (?w . insert-weekly-diary-entry)
8946 (?m . insert-monthly-diary-entry)
8947 (?y . insert-yearly-diary-entry)
8948 (?a . insert-anniversary-diary-entry)
8949 (?b . insert-block-diary-entry)
8950 (?c . insert-cyclic-diary-entry)))))
8951 (oldf (symbol-function 'calendar-cursor-to-date))
8952 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8953 (point (point))
8954 (mark (or (mark t) (point))))
8955 (unless cmd
8956 (error "No command associated with <%c>" char))
8957 (unless (and (get-text-property point 'day)
8958 (or (not (equal ?b char))
8959 (get-text-property mark 'day)))
8960 (error "Don't know which date to use for diary entry"))
8961 ;; We implement this by hacking the `calendar-cursor-to-date' function
8962 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8963 (let ((calendar-mark-ring
8964 (list (calendar-gregorian-from-absolute
8965 (or (get-text-property mark 'day)
8966 (get-text-property point 'day))))))
8967 (unwind-protect
8968 (progn
8969 (fset 'calendar-cursor-to-date
8970 (lambda (&optional error dummy)
8971 (calendar-gregorian-from-absolute
8972 (get-text-property point 'day))))
8973 (call-interactively cmd))
8974 (fset 'calendar-cursor-to-date oldf))))))
8976 (defun org-agenda-execute-calendar-command (cmd)
8977 "Execute a calendar command from the agenda with date from cursor."
8978 (org-agenda-check-type t 'agenda 'timeline)
8979 (require 'diary-lib)
8980 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
8981 (error "Don't know which date to use for the calendar command"))
8982 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8983 (point (point))
8984 (date (calendar-gregorian-from-absolute
8985 (get-text-property point 'day)))
8986 ;; the following 2 vars are needed in the calendar
8987 (displayed-month (car date))
8988 (displayed-year (nth 2 date)))
8989 (unwind-protect
8990 (progn
8991 (fset 'calendar-cursor-to-date
8992 (lambda (&optional error dummy)
8993 (calendar-gregorian-from-absolute
8994 (get-text-property point 'day))))
8995 (call-interactively cmd))
8996 (fset 'calendar-cursor-to-date oldf))))
8998 (defun org-agenda-phases-of-moon ()
8999 "Display the phases of the moon for the 3 months around the cursor date."
9000 (interactive)
9001 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9003 (defun org-agenda-holidays ()
9004 "Display the holidays for the 3 months around the cursor date."
9005 (interactive)
9006 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9008 (defvar calendar-longitude) ; defined in calendar.el
9009 (defvar calendar-latitude) ; defined in calendar.el
9010 (defvar calendar-location-name) ; defined in calendar.el
9012 (defun org-agenda-sunrise-sunset (arg)
9013 "Display sunrise and sunset for the cursor date.
9014 Latitude and longitude can be specified with the variables
9015 `calendar-latitude' and `calendar-longitude'. When called with prefix
9016 argument, latitude and longitude will be prompted for."
9017 (interactive "P")
9018 (require 'solar)
9019 (let ((calendar-longitude (if arg nil calendar-longitude))
9020 (calendar-latitude (if arg nil calendar-latitude))
9021 (calendar-location-name
9022 (if arg "the given coordinates" calendar-location-name)))
9023 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9025 (defun org-agenda-goto-calendar ()
9026 "Open the Emacs calendar with the date at the cursor."
9027 (interactive)
9028 (org-agenda-check-type t 'agenda 'timeline)
9029 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9030 (error "Don't know which date to open in calendar")))
9031 (date (calendar-gregorian-from-absolute day))
9032 (calendar-move-hook nil)
9033 (calendar-view-holidays-initially-flag nil)
9034 (calendar-view-diary-initially-flag nil))
9035 (calendar)
9036 (calendar-goto-date date)))
9038 ;;;###autoload
9039 (defun org-calendar-goto-agenda ()
9040 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9041 This is a command that has to be installed in `calendar-mode-map'."
9042 (interactive)
9043 (org-agenda-list nil (calendar-absolute-from-gregorian
9044 (calendar-cursor-to-date))
9045 nil))
9047 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9048 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9049 This is a command that has to be installed in `calendar-mode-map'.
9051 \(fn)" t nil)
9053 (defun org-agenda-convert-date ()
9054 (interactive)
9055 (org-agenda-check-type t 'agenda 'timeline)
9056 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9057 date s)
9058 (unless day
9059 (error "Don't know which date to convert"))
9060 (setq date (calendar-gregorian-from-absolute day))
9061 (setq s (concat
9062 "Gregorian: " (calendar-date-string date) "\n"
9063 "ISO: " (calendar-iso-date-string date) "\n"
9064 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9065 "Julian: " (calendar-julian-date-string date) "\n"
9066 "Astron. JD: " (calendar-astro-date-string date)
9067 " (Julian date number at noon UTC)\n"
9068 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9069 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9070 "French: " (calendar-french-date-string date) "\n"
9071 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9072 "Mayan: " (calendar-mayan-date-string date) "\n"
9073 "Coptic: " (calendar-coptic-date-string date) "\n"
9074 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9075 "Persian: " (calendar-persian-date-string date) "\n"
9076 "Chinese: " (calendar-chinese-date-string date) "\n"))
9077 (with-output-to-temp-buffer "*Dates*"
9078 (princ s))
9079 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9081 ;;; Bulk commands
9083 (defun org-agenda-bulk-marked-p ()
9084 (eq (get-char-property (point-at-bol) 'type)
9085 'org-marked-entry-overlay))
9087 (defun org-agenda-bulk-mark (&optional arg)
9088 "Mark the entry at point for future bulk action."
9089 (interactive "p")
9090 (dotimes (i (or arg 1))
9091 (unless (org-get-at-bol 'org-agenda-diary-link)
9092 (let* ((m (org-get-at-bol 'org-hd-marker))
9094 (unless (org-agenda-bulk-marked-p)
9095 (unless m (error "Nothing to mark at point"))
9096 (push m org-agenda-bulk-marked-entries)
9097 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9098 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9099 (org-get-todo-face "TODO")
9100 'evaporate)
9101 (overlay-put ov 'type 'org-marked-entry-overlay))
9102 (beginning-of-line 2)
9103 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9104 (beginning-of-line 2))
9105 (message "%d entries marked for bulk action"
9106 (length org-agenda-bulk-marked-entries))))))
9108 (defun org-agenda-bulk-mark-all ()
9109 "Mark all entries for future agenda bulk action."
9110 (interactive)
9111 (org-agenda-bulk-mark-regexp "."))
9113 (defun org-agenda-bulk-mark-regexp (regexp)
9114 "Mark entries matching REGEXP for future agenda bulk action."
9115 (interactive "sMark entries matching regexp: ")
9116 (let ((entries-marked 0))
9117 (save-excursion
9118 (goto-char (point-min))
9119 (goto-char (next-single-property-change (point) 'txt))
9120 (while (re-search-forward regexp nil t)
9121 (when (string-match regexp (get-text-property (point) 'txt))
9122 (setq entries-marked (1+ entries-marked))
9123 (call-interactively 'org-agenda-bulk-mark))))
9124 (if (not entries-marked)
9125 (message "No entry matching this regexp."))))
9127 (defun org-agenda-bulk-unmark (&optional arg)
9128 "Unmark the entry at point for future bulk action."
9129 (interactive "P")
9130 (if arg
9131 (org-agenda-bulk-unmark-all)
9132 (cond ((org-agenda-bulk-marked-p)
9133 (org-agenda-bulk-remove-overlays
9134 (point-at-bol) (+ 2 (point-at-bol)))
9135 (setq org-agenda-bulk-marked-entries
9136 (delete (org-get-at-bol 'org-hd-marker)
9137 org-agenda-bulk-marked-entries))
9138 (beginning-of-line 2)
9139 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9140 (beginning-of-line 2))
9141 (message "%d entries left marked for bulk action"
9142 (length org-agenda-bulk-marked-entries)))
9143 (t (message "No entry to unmark here")))))
9145 (defun org-agenda-bulk-toggle ()
9146 "Toggle marking the entry at point for bulk action."
9147 (interactive)
9148 (if (org-agenda-bulk-marked-p)
9149 (org-agenda-bulk-unmark)
9150 (org-agenda-bulk-mark)))
9152 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9153 "Remove the mark overlays between BEG and END in the agenda buffer.
9154 BEG and END default to the buffer limits.
9156 This only removes the overlays, it does not remove the markers
9157 from the list in `org-agenda-bulk-marked-entries'."
9158 (interactive)
9159 (mapc (lambda (ov)
9160 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9161 (delete-overlay ov)))
9162 (overlays-in (or beg (point-min)) (or end (point-max)))))
9164 (defun org-agenda-bulk-unmark-all ()
9165 "Remove all marks in the agenda buffer.
9166 This will remove the markers and the overlays."
9167 (interactive)
9168 (if (null org-agenda-bulk-marked-entries)
9169 (message "No entry to unmark")
9170 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9171 (setq org-agenda-bulk-marked-entries nil)
9172 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9174 (defcustom org-agenda-persistent-marks nil
9175 "Non-nil means marked items will stay marked after a bulk action.
9176 You can toggle this interactively by typing `p' when prompted for a
9177 bulk action."
9178 :group 'org-agenda
9179 :version "24.1"
9180 :type 'boolean)
9182 (defun org-agenda-bulk-action (&optional arg)
9183 "Execute an remote-editing action on all marked entries.
9184 The prefix arg is passed through to the command if possible."
9185 (interactive "P")
9186 ;; Make sure we have markers, and only valid ones
9187 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9188 (mapc
9189 (lambda (m)
9190 (unless (and (markerp m)
9191 (marker-buffer m)
9192 (buffer-live-p (marker-buffer m))
9193 (marker-position m))
9194 (error "Marker %s for bulk command is invalid" m)))
9195 org-agenda-bulk-marked-entries)
9197 ;; Prompt for the bulk command
9198 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9199 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9200 "[S]catter [f]unction "
9201 (when org-agenda-bulk-custom-functions
9202 (concat " Custom: ["
9203 (mapconcat (lambda(f) (char-to-string (car f)))
9204 org-agenda-bulk-custom-functions "")
9205 "]"))))
9206 (catch 'exit
9207 (let* ((action (read-char-exclusive))
9208 (org-log-refile (if org-log-refile 'time nil))
9209 (entries (reverse org-agenda-bulk-marked-entries))
9210 (org-overriding-default-time
9211 (if (get-text-property (point) 'org-agenda-date-header)
9212 (org-get-cursor-date)))
9213 redo-at-end
9214 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9215 (cond
9216 ((equal action ?p)
9217 (let ((org-agenda-persistent-marks
9218 (not org-agenda-persistent-marks)))
9219 (org-agenda-bulk-action)
9220 (throw 'exit nil)))
9222 ((equal action ?$)
9223 (setq cmd '(org-agenda-archive)))
9225 ((equal action ?A)
9226 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9228 ((member action '(?r ?w))
9229 (setq rfloc (org-refile-get-location
9230 "Refile to"
9231 (marker-buffer (car entries))
9232 org-refile-allow-creating-parent-nodes))
9233 (if (nth 3 rfloc)
9234 (setcar (nthcdr 3 rfloc)
9235 (move-marker (make-marker) (nth 3 rfloc)
9236 (or (get-file-buffer (nth 1 rfloc))
9237 (find-buffer-visiting (nth 1 rfloc))
9238 (error "This should not happen")))))
9240 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9241 redo-at-end t))
9243 ((equal action ?t)
9244 (setq state (org-icompleting-read
9245 "Todo state: "
9246 (with-current-buffer (marker-buffer (car entries))
9247 (mapcar 'list org-todo-keywords-1))))
9248 (setq cmd `(let ((org-inhibit-blocking t)
9249 (org-inhibit-logging 'note))
9250 (org-agenda-todo ,state))))
9252 ((memq action '(?- ?+))
9253 (setq tag (org-icompleting-read
9254 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9255 (with-current-buffer (marker-buffer (car entries))
9256 (delq nil
9257 (mapcar (lambda (x)
9258 (if (stringp (car x)) x)) org-tag-alist)))))
9259 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9261 ((memq action '(?s ?d))
9262 (let* ((time
9263 (unless arg
9264 (org-read-date
9265 nil nil nil
9266 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9267 org-overriding-default-time)))
9268 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9269 (setq cmd `(eval '(,c1 arg ,time)))))
9271 ((equal action ?S)
9272 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9273 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9274 (let ((days (read-number
9275 (format "Scatter tasks across how many %sdays: "
9276 (if arg "week" "")) 7)))
9277 (setq cmd
9278 `(let ((distance (1+ (random ,days))))
9279 (if arg
9280 (let ((dist distance)
9281 (day-of-week
9282 (calendar-day-of-week
9283 (calendar-gregorian-from-absolute (org-today)))))
9284 (dotimes (i (1+ dist))
9285 (while (member day-of-week org-agenda-weekend-days)
9286 (incf distance)
9287 (incf day-of-week)
9288 (if (= day-of-week 7)
9289 (setq day-of-week 0)))
9290 (incf day-of-week)
9291 (if (= day-of-week 7)
9292 (setq day-of-week 0)))))
9293 ;; silently fail when try to replan a sexp entry
9294 (condition-case nil
9295 (let* ((date (calendar-gregorian-from-absolute
9296 (+ (org-today) distance)))
9297 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9298 (nth 2 date))))
9299 (org-agenda-schedule nil time))
9300 (error nil)))))))
9302 ((assoc action org-agenda-bulk-custom-functions)
9303 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9304 redo-at-end t))
9306 ((equal action ?f)
9307 (setq cmd (list (intern
9308 (org-icompleting-read "Function: "
9309 obarray 'fboundp t nil nil)))))
9311 (t (error "Invalid bulk action")))
9313 ;; Sort the markers, to make sure that parents are handled before children
9314 (setq entries (sort entries
9315 (lambda (a b)
9316 (cond
9317 ((equal (marker-buffer a) (marker-buffer b))
9318 (< (marker-position a) (marker-position b)))
9320 (string< (buffer-name (marker-buffer a))
9321 (buffer-name (marker-buffer b))))))))
9323 ;; Now loop over all markers and apply cmd
9324 (while (setq e (pop entries))
9325 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9326 (if (not pos)
9327 (progn (message "Skipping removed entry at %s" e)
9328 (setq cntskip (1+ cntskip)))
9329 (goto-char pos)
9330 (let (org-loop-over-headlines-in-active-region)
9331 (eval cmd))
9332 (setq cnt (1+ cnt))))
9333 (when redo-at-end (org-agenda-redo))
9334 (unless org-agenda-persistent-marks
9335 (org-agenda-bulk-unmark-all))
9336 (message "Acted on %d entries%s%s"
9338 (if (= cntskip 0)
9340 (format ", skipped %d (disappeared before their turn)"
9341 cntskip))
9342 (if (not org-agenda-persistent-marks)
9343 "" " (kept marked)"))))))
9345 (defun org-agenda-capture ()
9346 "Call `org-capture' with the date at point."
9347 (interactive)
9348 (if (not (eq major-mode 'org-agenda-mode))
9349 (error "You cannot do this outside of agenda buffers")
9350 (let ((org-overriding-default-time
9351 (org-get-cursor-date)))
9352 (call-interactively 'org-capture))))
9354 ;;; Flagging notes
9356 (defun org-agenda-show-the-flagging-note ()
9357 "Display the flagging note in the other window.
9358 When called a second time in direct sequence, offer to remove the FLAGGING
9359 tag and (if present) the flagging note."
9360 (interactive)
9361 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9362 (win (selected-window))
9363 note heading newhead)
9364 (unless hdmarker
9365 (error "No linked entry at point"))
9366 (if (and (eq this-command last-command)
9367 (y-or-n-p "Unflag and remove any flagging note? "))
9368 (progn
9369 (org-agenda-remove-flag hdmarker)
9370 (let ((win (get-buffer-window "*Flagging Note*")))
9371 (and win (delete-window win)))
9372 (message "Entry unflagged"))
9373 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9374 (unless note
9375 (error "No flagging note"))
9376 (org-kill-new note)
9377 (org-switch-to-buffer-other-window "*Flagging Note*")
9378 (erase-buffer)
9379 (insert note)
9380 (goto-char (point-min))
9381 (while (re-search-forward "\\\\n" nil t)
9382 (replace-match "\n" t t))
9383 (goto-char (point-min))
9384 (select-window win)
9385 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9387 (defun org-agenda-remove-flag (marker)
9388 "Remove the FLAGGED tag and any flagging note in the entry."
9389 (let (newhead)
9390 (org-with-point-at marker
9391 (org-toggle-tag "FLAGGED" 'off)
9392 (org-entry-delete nil "THEFLAGGINGNOTE")
9393 (setq newhead (org-get-heading)))
9394 (org-agenda-change-all-lines newhead marker)
9395 (message "Entry unflagged")))
9397 (defun org-agenda-get-any-marker (&optional pos)
9398 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9399 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9401 ;;; Appointment reminders
9403 (defvar appt-time-msg-list) ; defined in appt.el
9405 ;;;###autoload
9406 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9407 "Activate appointments found in `org-agenda-files'.
9408 With a \\[universal-argument] prefix, refresh the list of
9409 appointments.
9411 If FILTER is t, interactively prompt the user for a regular
9412 expression, and filter out entries that don't match it.
9414 If FILTER is a string, use this string as a regular expression
9415 for filtering entries out.
9417 If FILTER is a function, filter out entries against which
9418 calling the function returns nil. This function takes one
9419 argument: an entry from `org-agenda-get-day-entries'.
9421 FILTER can also be an alist with the car of each cell being
9422 either 'headline or 'category. For example:
9424 '((headline \"IMPORTANT\")
9425 (category \"Work\"))
9427 will only add headlines containing IMPORTANT or headlines
9428 belonging to the \"Work\" category.
9430 ARGS are symbols indicating what kind of entries to consider.
9431 By default `org-agenda-to-appt' will use :deadline, :scheduled
9432 and :timestamp entries. See the docstring of `org-diary' for
9433 details and examples.
9435 If an entry as a APPT_WARNTIME property, its value will be used
9436 to override `appt-message-warning-time'."
9437 (interactive "P")
9438 (if refresh (setq appt-time-msg-list nil))
9439 (if (eq filter t)
9440 (setq filter (read-from-minibuffer "Regexp filter: ")))
9441 (let* ((cnt 0) ; count added events
9442 (scope (or args '(:deadline :scheduled :timestamp)))
9443 (org-agenda-new-buffers nil)
9444 (org-deadline-warning-days 0)
9445 ;; Do not use `org-today' here because appt only takes
9446 ;; time and without date as argument, so it may pass wrong
9447 ;; information otherwise
9448 (today (org-date-to-gregorian
9449 (time-to-days (current-time))))
9450 (org-agenda-restrict nil)
9451 (files (org-agenda-files 'unrestricted)) entries file
9452 (org-agenda-buffer nil))
9453 ;; Get all entries which may contain an appt
9454 (org-agenda-prepare-buffers files)
9455 (while (setq file (pop files))
9456 (setq entries
9457 (delq nil
9458 (append entries
9459 (apply 'org-agenda-get-day-entries
9460 file today scope)))))
9461 ;; Map thru entries and find if we should filter them out
9462 (mapc
9463 (lambda(x)
9464 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9465 (cat (get-text-property 1 'org-category x))
9466 (tod (get-text-property 1 'time-of-day x))
9467 (ok (or (null filter)
9468 (and (stringp filter) (string-match filter evt))
9469 (and (functionp filter) (funcall filter x))
9470 (and (listp filter)
9471 (let ((cat-filter (cadr (assoc 'category filter)))
9472 (evt-filter (cadr (assoc 'headline filter))))
9473 (or (and (stringp cat-filter)
9474 (string-match cat-filter cat))
9475 (and (stringp evt-filter)
9476 (string-match evt-filter evt)))))))
9477 (wrn (get-text-property 1 'warntime x)))
9478 ;; FIXME: Shall we remove text-properties for the appt text?
9479 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9480 (when (and ok tod)
9481 (setq tod (concat "00" (number-to-string tod))
9482 tod (when (string-match
9483 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9484 (concat (match-string 1 tod) ":"
9485 (match-string 2 tod))))
9486 (if (version< emacs-version "23.3")
9487 (appt-add tod evt)
9488 (appt-add tod evt wrn))
9489 (setq cnt (1+ cnt))))) entries)
9490 (org-release-buffers org-agenda-new-buffers)
9491 (if (eq cnt 0)
9492 (message "No event to add")
9493 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9495 (autoload 'org-agenda-to-appt "org-agenda" "\
9496 Activate appointments found in `org-agenda-files'.
9497 With a \\[universal-argument] prefix, refresh the list of
9498 appointments.
9500 If FILTER is t, interactively prompt the user for a regular
9501 expression, and filter out entries that don't match it.
9503 If FILTER is a string, use this string as a regular expression
9504 for filtering entries out.
9506 If FILTER is a function, filter out entries against which
9507 calling the function returns nil. This function takes one
9508 argument: an entry from `org-agenda-get-day-entries'.
9510 FILTER can also be an alist with the car of each cell being
9511 either 'headline or 'category. For example:
9513 '((headline \"IMPORTANT\")
9514 (category \"Work\"))
9516 will only add headlines containing IMPORTANT or headlines
9517 belonging to the \"Work\" category.
9519 ARGS are symbols indicating what kind of entries to consider.
9520 By default `org-agenda-to-appt' will use :deadline, :scheduled
9521 and :timestamp entries. See the docstring of `org-diary' for
9522 details and examples.
9524 If an entry as a APPT_WARNTIME property, its value will be used
9525 to override `appt-message-warning-time'.
9527 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9529 (defun org-agenda-todayp (date)
9530 "Does DATE mean today, when considering `org-extend-today-until'?"
9531 (let ((today (org-today))
9532 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9533 date)))
9534 (eq date today)))
9536 (defun org-agenda-todo-yesterday (&optional arg)
9537 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9538 (interactive "P")
9539 (let* ((hour (third (decode-time
9540 (org-current-time))))
9541 (org-extend-today-until (1+ hour)))
9542 (org-agenda-todo arg)))
9544 (provide 'org-agenda)
9546 ;;; org-agenda.el ends here