org-export: Fix menu leak when reloading Org
[org-mode.git] / lisp / org-agenda.el
blob7fc39d50763d884761063585b1a93a08e9de40e9
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, or a number which will then give
831 the number of days before the actual deadline when the prewarnings
832 should resume.
833 This can be used in a workflow where the first showing of the deadline will
834 trigger you to schedule it, and then you don't want to be reminded of it
835 because you will take care of it on the day when scheduled."
836 :group 'org-agenda-skip
837 :group 'org-agenda-daily/weekly
838 :version "24.1"
839 :type '(choice
840 (const :tag "Alwas show prewarning" nil)
841 (const :tag "Remove prewarning if entry is scheduled" t)
842 (integer :tag "Restart prewarning N days before deadline")))
844 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
845 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
846 When non-nil, after the search for timestamps has matched once in an
847 entry, the rest of the entry will not be searched."
848 :group 'org-agenda-skip
849 :type 'boolean)
851 (defcustom org-agenda-skip-timestamp-if-done nil
852 "Non-nil means don't select item by timestamp or -range if it is DONE."
853 :group 'org-agenda-skip
854 :group 'org-agenda-daily/weekly
855 :type 'boolean)
857 (defcustom org-agenda-dim-blocked-tasks t
858 "Non-nil means dim blocked tasks in the agenda display.
859 This causes some overhead during agenda construction, but if you
860 have turned on `org-enforce-todo-dependencies',
861 `org-enforce-todo-checkbox-dependencies', or any other blocking
862 mechanism, this will create useful feedback in the agenda.
864 Instead of t, this variable can also have the value `invisible'.
865 Then blocked tasks will be invisible and only become visible when
866 they become unblocked. An exemption to this behavior is when a task is
867 blocked because of unchecked checkboxes below it. Since checkboxes do
868 not show up in the agenda views, making this task invisible you remove any
869 trace from agenda views that there is something to do. Therefore, a task
870 that is blocked because of checkboxes will never be made invisible, it
871 will only be dimmed."
872 :group 'org-agenda-daily/weekly
873 :group 'org-agenda-todo-list
874 :type '(choice
875 (const :tag "Do not dim" nil)
876 (const :tag "Dim to a gray face" t)
877 (const :tag "Make invisible" invisible)))
879 (defcustom org-timeline-show-empty-dates 3
880 "Non-nil means `org-timeline' also shows dates without an entry.
881 When nil, only the days which actually have entries are shown.
882 When t, all days between the first and the last date are shown.
883 When an integer, show also empty dates, but if there is a gap of more than
884 N days, just insert a special line indicating the size of the gap."
885 :group 'org-agenda-skip
886 :type '(choice
887 (const :tag "None" nil)
888 (const :tag "All" t)
889 (integer :tag "at most")))
891 (defgroup org-agenda-startup nil
892 "Options concerning initial settings in the Agenda in Org Mode."
893 :tag "Org Agenda Startup"
894 :group 'org-agenda)
896 (defcustom org-agenda-menu-show-matcher t
897 "Non-nil means show the match string in the agenda dispatcher menu.
898 When nil, the matcher string is not shown, but is put into the help-echo
899 property so than moving the mouse over the command shows it.
900 Setting it to nil is good if matcher strings are very long and/or if
901 you want to use two-columns display (see `org-agenda-menu-two-columns')."
902 :group 'org-agenda
903 :version "24.1"
904 :type 'boolean)
906 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
908 (defcustom org-agenda-menu-two-columns nil
909 "Non-nil means, use two columns to show custom commands in the dispatcher.
910 If you use this, you probably want to set `org-agenda-menu-show-matcher'
911 to nil."
912 :group 'org-agenda
913 :version "24.1"
914 :type 'boolean)
916 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
917 (defcustom org-agenda-finalize-hook nil
918 "Hook run just before displaying an agenda buffer.
919 The buffer is still writable when the hook is called.
921 You can modify some of the buffer substrings but you should be
922 extra careful not to modify the text properties of the agenda
923 headlines as the agenda display heavily relies on them."
924 :group 'org-agenda-startup
925 :type 'hook)
927 (defcustom org-agenda-mouse-1-follows-link nil
928 "Non-nil means mouse-1 on a link will follow the link in the agenda.
929 A longer mouse click will still set point. Does not work on XEmacs.
930 Needs to be set before org.el is loaded."
931 :group 'org-agenda-startup
932 :type 'boolean)
934 (defcustom org-agenda-start-with-follow-mode nil
935 "The initial value of follow mode in a newly created agenda window."
936 :group 'org-agenda-startup
937 :type 'boolean)
939 (defcustom org-agenda-follow-indirect nil
940 "Non-nil means `org-agenda-follow-mode' displays only the
941 current item's tree, in an indirect buffer."
942 :group 'org-agenda
943 :version "24.1"
944 :type 'boolean)
946 (defcustom org-agenda-show-outline-path t
947 "Non-nil means show outline path in echo area after line motion."
948 :group 'org-agenda-startup
949 :type 'boolean)
951 (defcustom org-agenda-start-with-entry-text-mode nil
952 "The initial value of entry-text-mode in a newly created agenda window."
953 :group 'org-agenda-startup
954 :type 'boolean)
956 (defcustom org-agenda-entry-text-maxlines 5
957 "Number of text lines to be added when `E' is pressed in the agenda.
959 Note that this variable only used during agenda display. Add add entry text
960 when exporting the agenda, configure the variable
961 `org-agenda-add-entry-ext-maxlines'."
962 :group 'org-agenda
963 :type 'integer)
965 (defcustom org-agenda-entry-text-exclude-regexps nil
966 "List of regular expressions to clean up entry text.
967 The complete matches of all regular expressions in this list will be
968 removed from entry text before it is shown in the agenda."
969 :group 'org-agenda
970 :type '(repeat (regexp)))
972 (defvar org-agenda-entry-text-cleanup-hook nil
973 "Hook that is run after basic cleanup of entry text to be shown in agenda.
974 This cleanup is done in a temporary buffer, so the function may inspect and
975 change the entire buffer.
976 Some default stuff like drawers and scheduling/deadline dates will already
977 have been removed when this is called, as will any matches for regular
978 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
980 (defvar org-agenda-include-inactive-timestamps nil
981 "Non-nil means include inactive time stamps in agenda and timeline.
982 Dynamically scoped.")
984 (defgroup org-agenda-windows nil
985 "Options concerning the windows used by the Agenda in Org Mode."
986 :tag "Org Agenda Windows"
987 :group 'org-agenda)
989 (defcustom org-agenda-window-setup 'reorganize-frame
990 "How the agenda buffer should be displayed.
991 Possible values for this option are:
993 current-window Show agenda in the current window, keeping all other windows.
994 other-window Use `switch-to-buffer-other-window' to display agenda.
995 reorganize-frame Show only two windows on the current frame, the current
996 window and the agenda.
997 other-frame Use `switch-to-buffer-other-frame' to display agenda.
998 Also, when exiting the agenda, kill that frame.
999 See also the variable `org-agenda-restore-windows-after-quit'."
1000 :group 'org-agenda-windows
1001 :type '(choice
1002 (const current-window)
1003 (const other-frame)
1004 (const other-window)
1005 (const reorganize-frame)))
1007 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1008 "The min and max height of the agenda window as a fraction of frame height.
1009 The value of the variable is a cons cell with two numbers between 0 and 1.
1010 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1011 :group 'org-agenda-windows
1012 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1014 (defcustom org-agenda-restore-windows-after-quit nil
1015 "Non-nil means restore window configuration upon exiting agenda.
1016 Before the window configuration is changed for displaying the agenda,
1017 the current status is recorded. When the agenda is exited with
1018 `q' or `x' and this option is set, the old state is restored. If
1019 `org-agenda-window-setup' is `other-frame', the value of this
1020 option will be ignored."
1021 :group 'org-agenda-windows
1022 :type 'boolean)
1024 (defcustom org-agenda-ndays nil
1025 "Number of days to include in overview display.
1026 Should be 1 or 7.
1027 Obsolete, see `org-agenda-span'."
1028 :group 'org-agenda-daily/weekly
1029 :type 'integer)
1031 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1033 (defcustom org-agenda-span 'week
1034 "Number of days to include in overview display.
1035 Can be day, week, month, year, or any number of days.
1036 Custom commands can set this variable in the options section."
1037 :group 'org-agenda-daily/weekly
1038 :type '(choice (const :tag "Day" day)
1039 (const :tag "Week" week)
1040 (const :tag "Month" month)
1041 (const :tag "Year" year)
1042 (integer :tag "Custom")))
1044 (defcustom org-agenda-start-on-weekday 1
1045 "Non-nil means start the overview always on the specified weekday.
1046 0 denotes Sunday, 1 denotes Monday etc.
1047 When nil, always start on the current day.
1048 Custom commands can set this variable in the options section."
1049 :group 'org-agenda-daily/weekly
1050 :type '(choice (const :tag "Today" nil)
1051 (integer :tag "Weekday No.")))
1053 (defcustom org-agenda-show-all-dates t
1054 "Non-nil means `org-agenda' shows every day in the selected range.
1055 When nil, only the days which actually have entries are shown."
1056 :group 'org-agenda-daily/weekly
1057 :type 'boolean)
1059 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1060 "Format string for displaying dates in the agenda.
1061 Used by the daily/weekly agenda and by the timeline. This should be
1062 a format string understood by `format-time-string', or a function returning
1063 the formatted date as a string. The function must take a single argument,
1064 a calendar-style date list like (month day year)."
1065 :group 'org-agenda-daily/weekly
1066 :type '(choice
1067 (string :tag "Format string")
1068 (function :tag "Function")))
1070 (defun org-agenda-format-date-aligned (date)
1071 "Format a date string for display in the daily/weekly agenda, or timeline.
1072 This function makes sure that dates are aligned for easy reading."
1073 (require 'cal-iso)
1074 (let* ((dayname (calendar-day-name date))
1075 (day (cadr date))
1076 (day-of-week (calendar-day-of-week date))
1077 (month (car date))
1078 (monthname (calendar-month-name month))
1079 (year (nth 2 date))
1080 (iso-week (org-days-to-iso-week
1081 (calendar-absolute-from-gregorian date)))
1082 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1083 (1- year))
1084 ((and (= month 12) (<= iso-week 1))
1085 (1+ year))
1086 (t year)))
1087 (weekstring (if (= day-of-week 1)
1088 (format " W%02d" iso-week)
1089 "")))
1090 (format "%-10s %2d %s %4d%s"
1091 dayname day monthname year weekstring)))
1093 (defcustom org-agenda-time-leading-zero nil
1094 "Non-nil means use leading zero for military times in agenda.
1095 For example, 9:30am would become 09:30 rather than 9:30."
1096 :group 'org-agenda-daily/weekly
1097 :version "24.1"
1098 :type 'boolean)
1100 (defcustom org-agenda-timegrid-use-ampm nil
1101 "When set, show AM/PM style timestamps on the timegrid."
1102 :group 'org-agenda
1103 :version "24.1"
1104 :type 'boolean)
1106 (defun org-agenda-time-of-day-to-ampm (time)
1107 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1108 (let* ((hour-number (string-to-number (substring time 0 -3)))
1109 (minute (substring time -2))
1110 (ampm "am"))
1111 (cond
1112 ((equal hour-number 12)
1113 (setq ampm "pm"))
1114 ((> hour-number 12)
1115 (setq ampm "pm")
1116 (setq hour-number (- hour-number 12))))
1117 (concat
1118 (if org-agenda-time-leading-zero
1119 (format "%02d" hour-number)
1120 (format "%02s" (number-to-string hour-number)))
1121 ":" minute ampm)))
1123 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1124 "Conditionally convert TIME to AM/PM format
1125 based on `org-agenda-timegrid-use-ampm'"
1126 (if org-agenda-timegrid-use-ampm
1127 (org-agenda-time-of-day-to-ampm time)
1128 time))
1130 (defcustom org-agenda-weekend-days '(6 0)
1131 "Which days are weekend?
1132 These days get the special face `org-agenda-date-weekend' in the agenda
1133 and timeline buffers."
1134 :group 'org-agenda-daily/weekly
1135 :type '(set :greedy t
1136 (const :tag "Monday" 1)
1137 (const :tag "Tuesday" 2)
1138 (const :tag "Wednesday" 3)
1139 (const :tag "Thursday" 4)
1140 (const :tag "Friday" 5)
1141 (const :tag "Saturday" 6)
1142 (const :tag "Sunday" 0)))
1144 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1145 "Non-nil means jump to today when moving a past date forward in time.
1146 When using S-right in the agenda to move a a date forward, and the date
1147 stamp currently points to the past, the first key press will move it
1148 to today. WHen nil, just move one day forward even if the date stays
1149 in the past."
1150 :group 'org-agenda-daily/weekly
1151 :version "24.1"
1152 :type 'boolean)
1154 (defcustom org-agenda-include-diary nil
1155 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1156 Custom commands can set this variable in the options section."
1157 :group 'org-agenda-daily/weekly
1158 :type 'boolean)
1160 (defcustom org-agenda-include-deadlines t
1161 "If non-nil, include entries within their deadline warning period.
1162 Custom commands can set this variable in the options section."
1163 :group 'org-agenda-daily/weekly
1164 :version "24.1"
1165 :type 'boolean)
1167 (defcustom org-agenda-repeating-timestamp-show-all t
1168 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1169 When set to a list of strings, only show occurrences of repeating
1170 stamps for these TODO keywords. When nil, only one occurrence is
1171 shown, either today or the nearest into the future."
1172 :group 'org-agenda-daily/weekly
1173 :type '(choice
1174 (const :tag "Show repeating stamps" t)
1175 (repeat :tag "Show repeating stamps for these TODO keywords"
1176 (string :tag "TODO Keyword"))
1177 (const :tag "Don't show repeating stamps" nil)))
1179 (defcustom org-scheduled-past-days 10000
1180 "No. of days to continue listing scheduled items that are not marked DONE.
1181 When an item is scheduled on a date, it shows up in the agenda on this
1182 day and will be listed until it is marked done for the number of days
1183 given here."
1184 :group 'org-agenda-daily/weekly
1185 :type 'integer)
1187 (defcustom org-agenda-log-mode-items '(closed clock)
1188 "List of items that should be shown in agenda log mode.
1189 This list may contain the following symbols:
1191 closed Show entries that have been closed on that day.
1192 clock Show entries that have received clocked time on that day.
1193 state Show all logged state changes.
1194 Note that instead of changing this variable, you can also press `C-u l' in
1195 the agenda to display all available LOG items temporarily."
1196 :group 'org-agenda-daily/weekly
1197 :type '(set :greedy t (const closed) (const clock) (const state)))
1199 (defcustom org-agenda-clock-consistency-checks
1200 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1201 :gap-ok-around ("4:00")
1202 :default-face ((:background "DarkRed") (:foreground "white"))
1203 :overlap-face nil :gap-face nil :no-end-time-face nil
1204 :long-face nil :short-face nil)
1205 "This is a property list, with the following keys:
1207 :max-duration Mark clocking chunks that are longer than this time.
1208 This is a time string like \"HH:MM\", or the number
1209 of minutes as an integer.
1211 :min-duration Mark clocking chunks that are shorter that this.
1212 This is a time string like \"HH:MM\", or the number
1213 of minutes as an integer.
1215 :max-gap Mark gaps between clocking chunks that are longer than
1216 this duration. A number of minutes, or a string
1217 like \"HH:MM\".
1219 :gap-ok-around List of times during the day which are usually not working
1220 times. When a gap is detected, but the gap contains any
1221 of these times, the gap is *not* reported. For example,
1222 if this is (\"4:00\" \"13:00\") then gaps that contain
1223 4:00 in the morning (i.e. the night) and 13:00
1224 (i.e. a typical lunch time) do not cause a warning.
1225 You should have at least one time during the night in this
1226 list, or otherwise the first task each morning will trigger
1227 a warning because it follows a long gap.
1229 Furthermore, the following properties can be used to define faces for
1230 issue display.
1232 :default-face the default face, if the specific face is undefined
1233 :overlap-face face for overlapping clocks
1234 :gap-face face for gaps between clocks
1235 :no-end-time-face face for incomplete clocks
1236 :long-face face for clock intervals that are too long
1237 :short-face face for clock intervals that are too short"
1238 :group 'org-agenda-daily/weekly
1239 :group 'org-clock
1240 :version "24.1"
1241 :type 'plist)
1243 (defcustom org-agenda-log-mode-add-notes t
1244 "Non-nil means add first line of notes to log entries in agenda views.
1245 If a log item like a state change or a clock entry is associated with
1246 notes, the first line of these notes will be added to the entry in the
1247 agenda display."
1248 :group 'org-agenda-daily/weekly
1249 :type 'boolean)
1251 (defcustom org-agenda-start-with-log-mode nil
1252 "The initial value of log-mode in a newly created agenda window.
1253 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1254 explanations on the possible values."
1255 :group 'org-agenda-startup
1256 :group 'org-agenda-daily/weekly
1257 :type '(choice (const :tag "Don't show log items" nil)
1258 (const :tag "Show only log items" 'only)
1259 (const :tag "Show all possible log items" 'clockcheck)
1260 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1261 (choice (const :tag "Show closed log items" 'closed)
1262 (const :tag "Show clocked log items" 'clock)
1263 (const :tag "Show all logged state changes" 'state)))))
1265 (defcustom org-agenda-start-with-clockreport-mode nil
1266 "The initial value of clockreport-mode in a newly created agenda window."
1267 :group 'org-agenda-startup
1268 :group 'org-agenda-daily/weekly
1269 :type 'boolean)
1271 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1272 "Property list with parameters for the clocktable in clockreport mode.
1273 This is the display mode that shows a clock table in the daily/weekly
1274 agenda, the properties for this dynamic block can be set here.
1275 The usual clocktable parameters are allowed here, but you cannot set
1276 the properties :name, :tstart, :tend, :block, and :scope - these will
1277 be overwritten to make sure the content accurately reflects the
1278 current display in the agenda."
1279 :group 'org-agenda-daily/weekly
1280 :type 'plist)
1282 (defcustom org-agenda-search-view-always-boolean nil
1283 "Non-nil means the search string is interpreted as individual parts.
1285 The search string for search view can either be interpreted as a phrase,
1286 or as a list of snippets that define a boolean search for a number of
1287 strings.
1289 When this is non-nil, the string will be split on whitespace, and each
1290 snippet will be searched individually, and all must match in order to
1291 select an entry. A snippet is then a single string of non-white
1292 characters, or a string in double quotes, or a regexp in {} braces.
1293 If a snippet is preceded by \"-\", the snippet must *not* match.
1294 \"+\" is syntactic sugar for positive selection. Each snippet may
1295 be found as a full word or a partial word, but see the variable
1296 `org-agenda-search-view-force-full-words'.
1298 When this is nil, search will look for the entire search phrase as one,
1299 with each space character matching any amount of whitespace, including
1300 line breaks.
1302 Even when this is nil, you can still switch to Boolean search dynamically
1303 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1304 is a regexp marked with braces like \"{abc}\", this will also switch to
1305 boolean search."
1306 :group 'org-agenda-search-view
1307 :version "24.1"
1308 :type 'boolean)
1310 (if (fboundp 'defvaralias)
1311 (defvaralias 'org-agenda-search-view-search-words-only
1312 'org-agenda-search-view-always-boolean))
1314 (defcustom org-agenda-search-view-force-full-words nil
1315 "Non-nil means, search words must be matches as complete words.
1316 When nil, they may also match part of a word."
1317 :group 'org-agenda-search-view
1318 :version "24.1"
1319 :type 'boolean)
1321 (defgroup org-agenda-time-grid nil
1322 "Options concerning the time grid in the Org-mode Agenda."
1323 :tag "Org Agenda Time Grid"
1324 :group 'org-agenda)
1326 (defcustom org-agenda-search-headline-for-time t
1327 "Non-nil means search headline for a time-of-day.
1328 If the headline contains a time-of-day in one format or another, it will
1329 be used to sort the entry into the time sequence of items for a day.
1330 Some people have time stamps in the headline that refer to the creation
1331 time or so, and then this produces an unwanted side effect. If this is
1332 the case for your, use this variable to turn off searching the headline
1333 for a time."
1334 :group 'org-agenda-time-grid
1335 :type 'boolean)
1337 (defcustom org-agenda-use-time-grid t
1338 "Non-nil means show a time grid in the agenda schedule.
1339 A time grid is a set of lines for specific times (like every two hours between
1340 8:00 and 20:00). The items scheduled for a day at specific times are
1341 sorted in between these lines.
1342 For details about when the grid will be shown, and what it will look like, see
1343 the variable `org-agenda-time-grid'."
1344 :group 'org-agenda-time-grid
1345 :type 'boolean)
1347 (defcustom org-agenda-time-grid
1348 '((daily today require-timed)
1349 "----------------"
1350 (800 1000 1200 1400 1600 1800 2000))
1352 "The settings for time grid for agenda display.
1353 This is a list of three items. The first item is again a list. It contains
1354 symbols specifying conditions when the grid should be displayed:
1356 daily if the agenda shows a single day
1357 weekly if the agenda shows an entire week
1358 today show grid on current date, independent of daily/weekly display
1359 require-timed show grid only if at least one item has a time specification
1361 The second item is a string which will be placed behind the grid time.
1363 The third item is a list of integers, indicating the times that should have
1364 a grid line."
1365 :group 'org-agenda-time-grid
1366 :type
1367 '(list
1368 (set :greedy t :tag "Grid Display Options"
1369 (const :tag "Show grid in single day agenda display" daily)
1370 (const :tag "Show grid in weekly agenda display" weekly)
1371 (const :tag "Always show grid for today" today)
1372 (const :tag "Show grid only if any timed entries are present"
1373 require-timed)
1374 (const :tag "Skip grid times already present in an entry"
1375 remove-match))
1376 (string :tag "Grid String")
1377 (repeat :tag "Grid Times" (integer :tag "Time"))))
1379 (defcustom org-agenda-show-current-time-in-grid t
1380 "Non-nil means show the current time in the time grid."
1381 :group 'org-agenda-time-grid
1382 :version "24.1"
1383 :type 'boolean)
1385 (defcustom org-agenda-current-time-string
1386 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1387 "The string for the current time marker in the agenda."
1388 :group 'org-agenda-time-grid
1389 :version "24.1"
1390 :type 'string)
1392 (defgroup org-agenda-sorting nil
1393 "Options concerning sorting in the Org-mode Agenda."
1394 :tag "Org Agenda Sorting"
1395 :group 'org-agenda)
1397 (defcustom org-agenda-sorting-strategy
1398 '((agenda habit-down time-up priority-down category-keep)
1399 (todo priority-down category-keep)
1400 (tags priority-down category-keep)
1401 (search category-keep))
1402 "Sorting structure for the agenda items of a single day.
1403 This is a list of symbols which will be used in sequence to determine
1404 if an entry should be listed before another entry. The following
1405 symbols are recognized:
1407 time-up Put entries with time-of-day indications first, early first
1408 time-down Put entries with time-of-day indications first, late first
1409 category-keep Keep the default order of categories, corresponding to the
1410 sequence in `org-agenda-files'.
1411 category-up Sort alphabetically by category, A-Z.
1412 category-down Sort alphabetically by category, Z-A.
1413 tag-up Sort alphabetically by last tag, A-Z.
1414 tag-down Sort alphabetically by last tag, Z-A.
1415 priority-up Sort numerically by priority, high priority last.
1416 priority-down Sort numerically by priority, high priority first.
1417 todo-state-up Sort by todo state, tasks that are done last.
1418 todo-state-down Sort by todo state, tasks that are done first.
1419 effort-up Sort numerically by estimated effort, high effort last.
1420 effort-down Sort numerically by estimated effort, high effort first.
1421 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1422 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1423 habit-up Put entries that are habits first
1424 habit-down Put entries that are habits last
1425 alpha-up Sort headlines alphabetically
1426 alpha-down Sort headlines alphabetically, reversed
1428 The different possibilities will be tried in sequence, and testing stops
1429 if one comparison returns a \"not-equal\". For example, the default
1430 '(time-up category-keep priority-down)
1431 means: Pull out all entries having a specified time of day and sort them,
1432 in order to make a time schedule for the current day the first thing in the
1433 agenda listing for the day. Of the entries without a time indication, keep
1434 the grouped in categories, don't sort the categories, but keep them in
1435 the sequence given in `org-agenda-files'. Within each category sort by
1436 priority.
1438 Leaving out `category-keep' would mean that items will be sorted across
1439 categories by priority.
1441 Instead of a single list, this can also be a set of list for specific
1442 contents, with a context symbol in the car of the list, any of
1443 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1445 Custom commands can bind this variable in the options section."
1446 :group 'org-agenda-sorting
1447 :type `(choice
1448 (repeat :tag "General" ,org-sorting-choice)
1449 (list :tag "Individually"
1450 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1451 (repeat ,org-sorting-choice))
1452 (cons (const :tag "Strategy for TODO lists" todo)
1453 (repeat ,org-sorting-choice))
1454 (cons (const :tag "Strategy for Tags matches" tags)
1455 (repeat ,org-sorting-choice))
1456 (cons (const :tag "Strategy for search matches" search)
1457 (repeat ,org-sorting-choice)))))
1459 (defcustom org-agenda-cmp-user-defined nil
1460 "A function to define the comparison `user-defined'.
1461 This function must receive two arguments, agenda entry a and b.
1462 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1463 the user comparison, return nil.
1464 When this is defined, you can make `user-defined-up' and `user-defined-down'
1465 part of an agenda sorting strategy."
1466 :group 'org-agenda-sorting
1467 :type 'symbol)
1469 (defcustom org-sort-agenda-notime-is-late t
1470 "Non-nil means items without time are considered late.
1471 This is only relevant for sorting. When t, items which have no explicit
1472 time like 15:30 will be considered as 99:01, i.e. later than any items which
1473 do have a time. When nil, the default time is before 0:00. You can use this
1474 option to decide if the schedule for today should come before or after timeless
1475 agenda entries."
1476 :group 'org-agenda-sorting
1477 :type 'boolean)
1479 (defcustom org-sort-agenda-noeffort-is-high t
1480 "Non-nil means items without effort estimate are sorted as high effort.
1481 This also applies when filtering an agenda view with respect to the
1482 < or > effort operator. Then, tasks with no effort defined will be treated
1483 as tasks with high effort.
1484 When nil, such items are sorted as 0 minutes effort."
1485 :group 'org-agenda-sorting
1486 :type 'boolean)
1488 (defgroup org-agenda-line-format nil
1489 "Options concerning the entry prefix in the Org-mode agenda display."
1490 :tag "Org Agenda Line Format"
1491 :group 'org-agenda)
1493 (defcustom org-agenda-prefix-format
1494 '((agenda . " %i %-12:c%?-12t% s")
1495 (timeline . " % s")
1496 (todo . " %i %-12:c")
1497 (tags . " %i %-12:c")
1498 (search . " %i %-12:c"))
1499 "Format specifications for the prefix of items in the agenda views.
1500 An alist with five entries, each for the different agenda types. The
1501 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1502 The values are format strings.
1504 This format works similar to a printf format, with the following meaning:
1506 %c the category of the item, \"Diary\" for entries from the diary,
1507 or as given by the CATEGORY keyword or derived from the file name
1508 %e the effort required by the item
1509 %l the level of the item (insert X space(s) if item is of level X)
1510 %i the icon category of the item, see `org-agenda-category-icon-alist'
1511 %T the last tag of the item (ignore inherited tags, which come first)
1512 %t the HH:MM time-of-day specification if one applies to the entry
1513 %s Scheduling/Deadline information, a short string
1514 %(expression) Eval EXPRESSION and replace the control string
1515 by the result
1517 All specifiers work basically like the standard `%s' of printf, but may
1518 contain two additional characters: a question mark just after the `%'
1519 and a whitespace/punctuation character just before the final letter.
1521 If the first character after `%' is a question mark, the entire field
1522 will only be included if the corresponding value applies to the current
1523 entry. This is useful for fields which should have fixed width when
1524 present, but zero width when absent. For example, \"%?-12t\" will
1525 result in a 12 character time field if a time of the day is specified,
1526 but will completely disappear in entries which do not contain a time.
1528 If there is punctuation or whitespace character just before the final
1529 format letter, this character will be appended to the field value if
1530 the value is not empty. For example, the format \"%-12:c\" leads to
1531 \"Diary: \" if the category is \"Diary\". If the category were be
1532 empty, no additional colon would be inserted.
1534 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1535 which means:
1537 - Indent the line with two space characters
1538 - Give the category a 12 chars wide field, padded with whitespace on
1539 the right (because of `-'). Append a colon if there is a category
1540 (because of `:').
1541 - If there is a time-of-day, put it into a 12 chars wide field. If no
1542 time, don't put in an empty field, just skip it (because of '?').
1543 - Finally, put the scheduling information.
1545 See also the variables `org-agenda-remove-times-when-in-prefix' and
1546 `org-agenda-remove-tags'.
1548 Custom commands can set this variable in the options section."
1549 :type '(choice
1550 (string :tag "General format")
1551 (list :greedy t :tag "View dependent"
1552 (cons (const agenda) (string :tag "Format"))
1553 (cons (const timeline) (string :tag "Format"))
1554 (cons (const todo) (string :tag "Format"))
1555 (cons (const tags) (string :tag "Format"))
1556 (cons (const search) (string :tag "Format"))))
1557 :group 'org-agenda-line-format)
1559 (defvar org-prefix-format-compiled nil
1560 "The compiled prefix format and associated variables.
1561 This is a list where first element is a list of variable bindings, and second
1562 element is the compiled format expression. See the variable
1563 `org-agenda-prefix-format'.")
1565 (defcustom org-agenda-todo-keyword-format "%-1s"
1566 "Format for the TODO keyword in agenda lines.
1567 Set this to something like \"%-12s\" if you want all TODO keywords
1568 to occupy a fixed space in the agenda display."
1569 :group 'org-agenda-line-format
1570 :type 'string)
1572 (defcustom org-agenda-diary-sexp-prefix nil
1573 "A regexp that matches part of a diary sexp entry
1574 which should be treated as scheduling/deadline information in
1575 `org-agenda'.
1577 For example, you can use this to extract the `diary-remind-message' from
1578 `diary-remind' entries."
1579 :group 'org-agenda-line-format
1580 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1582 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1583 "Text preceding timerange entries in the agenda view.
1584 This is a list with two strings. The first applies when the range
1585 is entirely on one day. The second applies if the range spans several days.
1586 The strings may have two \"%d\" format specifiers which will be filled
1587 with the sequence number of the days, and the total number of days in the
1588 range, respectively."
1589 :group 'org-agenda-line-format
1590 :type '(list
1591 (string :tag "Deadline today ")
1592 (choice :tag "Deadline relative"
1593 (string :tag "Format string")
1594 (function))))
1596 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1597 "Text preceding scheduled items in the agenda view.
1598 This is a list with two strings. The first applies when the item is
1599 scheduled on the current day. The second applies when it has been scheduled
1600 previously, it may contain a %d indicating that this is the nth time that
1601 this item is scheduled, due to automatic rescheduling of unfinished items
1602 for the following day. So this number is one larger than the number of days
1603 that passed since this item was scheduled first."
1604 :group 'org-agenda-line-format
1605 :type '(list
1606 (string :tag "Scheduled today ")
1607 (string :tag "Scheduled previously")))
1609 (defcustom org-agenda-inactive-leader "["
1610 "Text preceding item pulled into the agenda by inactive time stamps.
1611 These entries are added to the agenda when pressing \"[\"."
1612 :group 'org-agenda-line-format
1613 :version "24.1"
1614 :type '(list
1615 (string :tag "Scheduled today ")
1616 (string :tag "Scheduled previously")))
1618 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1619 "Text preceding deadline items in the agenda view.
1620 This is a list with two strings. The first applies when the item has its
1621 deadline on the current day. The second applies when it is in the past or
1622 in the future, it may contain %d to capture how many days away the deadline
1623 is (was)."
1624 :group 'org-agenda-line-format
1625 :type '(list
1626 (string :tag "Deadline today ")
1627 (choice :tag "Deadline relative"
1628 (string :tag "Format string")
1629 (function))))
1631 (defcustom org-agenda-remove-times-when-in-prefix t
1632 "Non-nil means remove duplicate time specifications in agenda items.
1633 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1634 time-of-day specification in a headline or diary entry is extracted and
1635 placed into the prefix. If this option is non-nil, the original specification
1636 \(a timestamp or -range, or just a plain time(range) specification like
1637 11:30-4pm) will be removed for agenda display. This makes the agenda less
1638 cluttered.
1639 The option can be t or nil. It may also be the symbol `beg', indicating
1640 that the time should only be removed when it is located at the beginning of
1641 the headline/diary entry."
1642 :group 'org-agenda-line-format
1643 :type '(choice
1644 (const :tag "Always" t)
1645 (const :tag "Never" nil)
1646 (const :tag "When at beginning of entry" beg)))
1648 (defcustom org-agenda-remove-timeranges-from-blocks nil
1649 "Non-nil means remove time ranges specifications in agenda
1650 items that span on several days."
1651 :group 'org-agenda-line-format
1652 :version "24.1"
1653 :type 'boolean)
1655 (defcustom org-agenda-default-appointment-duration nil
1656 "Default duration for appointments that only have a starting time.
1657 When nil, no duration is specified in such cases.
1658 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1659 :group 'org-agenda-line-format
1660 :type '(choice
1661 (integer :tag "Minutes")
1662 (const :tag "No default duration")))
1664 (defcustom org-agenda-show-inherited-tags t
1665 "Non-nil means show inherited tags in each agenda line."
1666 :group 'org-agenda-line-format
1667 :type 'boolean)
1669 (defcustom org-agenda-hide-tags-regexp nil
1670 "Regular expression used to filter away specific tags in agenda views.
1671 This means that these tags will be present, but not be shown in the agenda
1672 line. Secondary filtering will still work on the hidden tags.
1673 Nil means don't hide any tags."
1674 :group 'org-agenda-line-format
1675 :type '(choice
1676 (const :tag "Hide none" nil)
1677 (string :tag "Regexp ")))
1679 (defcustom org-agenda-remove-tags nil
1680 "Non-nil means remove the tags from the headline copy in the agenda.
1681 When this is the symbol `prefix', only remove tags when
1682 `org-agenda-prefix-format' contains a `%T' specifier."
1683 :group 'org-agenda-line-format
1684 :type '(choice
1685 (const :tag "Always" t)
1686 (const :tag "Never" nil)
1687 (const :tag "When prefix format contains %T" prefix)))
1689 (if (fboundp 'defvaralias)
1690 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1691 'org-agenda-remove-tags))
1693 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1694 "Shift tags in agenda items to this column.
1695 If this number is positive, it specifies the column. If it is negative,
1696 it means that the tags should be flushright to that column. For example,
1697 -80 works well for a normal 80 character screen."
1698 :group 'org-agenda-line-format
1699 :type 'integer)
1701 (if (fboundp 'defvaralias)
1702 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1704 (defcustom org-agenda-fontify-priorities 'cookies
1705 "Non-nil means highlight low and high priorities in agenda.
1706 When t, the highest priority entries are bold, lowest priority italic.
1707 However, settings in `org-priority-faces' will overrule these faces.
1708 When this variable is the symbol `cookies', only fontify the
1709 cookies, not the entire task.
1710 This may also be an association list of priority faces, whose
1711 keys are the character values of `org-highest-priority',
1712 `org-default-priority', and `org-lowest-priority' (the default values
1713 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1714 color as a string, or a list like `(:background \"Red\")'.
1715 If it is a color, the variable `org-faces-easy-properties'
1716 determines if it is a foreground or a background color."
1717 :group 'org-agenda-line-format
1718 :type '(choice
1719 (const :tag "Never" nil)
1720 (const :tag "Defaults" t)
1721 (const :tag "Cookies only" cookies)
1722 (repeat :tag "Specify"
1723 (list (character :tag "Priority" :value ?A)
1724 (choice :tag "Face "
1725 (string :tag "Color")
1726 (sexp :tag "Face"))))))
1728 (defcustom org-agenda-day-face-function nil
1729 "Function called to determine what face should be used to display a day.
1730 The only argument passed to that function is the day. It should
1731 returns a face, or nil if does not want to specify a face and let
1732 the normal rules apply."
1733 :group 'org-agenda-line-format
1734 :version "24.1"
1735 :type 'function)
1737 (defcustom org-agenda-category-icon-alist nil
1738 "Alist of category icon to be displayed in agenda views.
1740 Each entry should have the following format:
1742 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1744 Where CATEGORY-REGEXP is a regexp matching the categories where
1745 the icon should be displayed.
1746 FILE-OR-DATA either a file path or a string containing image data.
1748 The other fields can be omitted safely if not needed:
1749 TYPE indicates the image type.
1750 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1751 image data.
1752 PROPS are additional image attributes to assign to the image,
1753 like, e.g. `:ascent center'.
1755 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1757 If you want to set the display properties yourself, just put a
1758 list as second element:
1760 (CATEGORY-REGEXP (MY PROPERTY LIST))
1762 For example, to display a 16px horizontal space for Emacs
1763 category, you can use:
1765 (\"Emacs\" '(space . (:width (16))))"
1766 :group 'org-agenda-line-format
1767 :version "24.1"
1768 :type '(alist :key-type (string :tag "Regexp matching category")
1769 :value-type (choice (list :tag "Icon"
1770 (string :tag "File or data")
1771 (symbol :tag "Type")
1772 (boolean :tag "Data?")
1773 (repeat :tag "Extra image properties" :inline t symbol))
1774 (list :tag "Display properties" sexp))))
1776 (defgroup org-agenda-column-view nil
1777 "Options concerning column view in the agenda."
1778 :tag "Org Agenda Column View"
1779 :group 'org-agenda)
1781 (defcustom org-agenda-columns-show-summaries t
1782 "Non-nil means show summaries for columns displayed in the agenda view."
1783 :group 'org-agenda-column-view
1784 :type 'boolean)
1786 (defcustom org-agenda-columns-compute-summary-properties t
1787 "Non-nil means recompute all summary properties before column view.
1788 When column view in the agenda is listing properties that have a summary
1789 operator, it can go to all relevant buffers and recompute the summaries
1790 there. This can mean overhead for the agenda column view, but is necessary
1791 to have thing up to date.
1792 As a special case, a CLOCKSUM property also makes sure that the clock
1793 computations are current."
1794 :group 'org-agenda-column-view
1795 :type 'boolean)
1797 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1798 "Non-nil means the duration of an appointment will add to day effort.
1799 The property to which appointment durations will be added is the one given
1800 in the option `org-effort-property'. If an appointment does not have
1801 an end time, `org-agenda-default-appointment-duration' will be used. If that
1802 is not set, an appointment without end time will not contribute to the time
1803 estimate."
1804 :group 'org-agenda-column-view
1805 :type 'boolean)
1807 (defcustom org-agenda-auto-exclude-function nil
1808 "A function called with a tag to decide if it is filtered on '/ RET'.
1809 The sole argument to the function, which is called once for each
1810 possible tag, is a string giving the name of the tag. The
1811 function should return either nil if the tag should be included
1812 as normal, or \"-<TAG>\" to exclude the tag.
1813 Note that for the purpose of tag filtering, only the lower-case version of
1814 all tags will be considered, so that this function will only ever see
1815 the lower-case version of all tags."
1816 :group 'org-agenda
1817 :type 'function)
1819 (defcustom org-agenda-bulk-custom-functions nil
1820 "Alist of characters and custom functions for bulk actions.
1821 For example, this value makes those two functions available:
1823 '((?R set-category)
1824 (?C bulk-cut))
1826 With selected entries in an agenda buffer, `B R' will call
1827 the custom function `set-category' on the selected entries.
1828 Note that functions in this alist don't need to be quoted."
1829 :type 'alist
1830 :version "24.1"
1831 :group 'org-agenda)
1833 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1834 "Execute BODY with point at location given by `org-hd-marker' property.
1835 If STRING is non-nil, the text property will be fetched from position 0
1836 in that string. If STRING is nil, it will be fetched from the beginning
1837 of the current line."
1838 (org-with-gensyms (marker)
1839 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1840 'org-hd-marker ,string)))
1841 (with-current-buffer (marker-buffer ,marker)
1842 (save-excursion
1843 (goto-char ,marker)
1844 ,@body)))))
1845 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1847 (defun org-add-agenda-custom-command (entry)
1848 "Replace or add a command in `org-agenda-custom-commands'.
1849 This is mostly for hacking and trying a new command - once the command
1850 works you probably want to add it to `org-agenda-custom-commands' for good."
1851 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1852 (if ass
1853 (setcdr ass (cdr entry))
1854 (push entry org-agenda-custom-commands))))
1856 ;;; Define the org-agenda-mode
1858 (defvar org-agenda-mode-map (make-sparse-keymap)
1859 "Keymap for `org-agenda-mode'.")
1860 (if (fboundp 'defvaralias)
1861 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1863 (defvar org-agenda-menu) ; defined later in this file.
1864 (defvar org-agenda-restrict nil) ; defined later in this file.
1865 (defvar org-agenda-follow-mode nil)
1866 (defvar org-agenda-entry-text-mode nil)
1867 (defvar org-agenda-clockreport-mode nil)
1868 (defvar org-agenda-show-log nil)
1869 (defvar org-agenda-redo-command nil)
1870 (defvar org-agenda-query-string nil)
1871 (defvar org-agenda-mode-hook nil
1872 "Hook run after `org-agenda-mode' is turned on.
1873 The buffer is still writable when this hook is called.")
1874 (defvar org-agenda-type nil)
1875 (defvar org-agenda-force-single-file nil)
1876 (defvar org-agenda-bulk-marked-entries nil
1877 "List of markers that refer to marked entries in the agenda.")
1879 ;;; Multiple agenda buffers support
1881 (defcustom org-agenda-sticky nil
1882 "Non-nil means agenda q key will bury agenda buffers.
1883 Agenda commands will then show existing buffer instead of generating new ones.
1884 When nil, `q' will kill the single agenda buffer."
1885 :group 'org-agenda
1886 :version "24.3"
1887 :type 'boolean)
1890 ;;;###autoload
1891 (defun org-toggle-sticky-agenda (&optional arg)
1892 "Toggle `org-agenda-sticky'."
1893 (interactive "P")
1894 (let ((new-value (if arg
1895 (> (prefix-numeric-value arg) 0)
1896 (not org-agenda-sticky))))
1897 (if (equal new-value org-agenda-sticky)
1898 (and (org-called-interactively-p 'interactive)
1899 (message "Sticky agenda was already %s"
1900 (if org-agenda-sticky "enabled" "disabled")))
1901 (setq org-agenda-sticky new-value)
1902 (org-agenda-kill-all-agenda-buffers)
1903 (and (org-called-interactively-p 'interactive)
1904 (message "Sticky agenda was %s"
1905 (if org-agenda-sticky "enabled" "disabled"))))))
1907 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1908 Toggle `org-agenda-sticky'.
1910 \(fn &optional ARG)" t nil)
1912 (defvar org-agenda-buffer nil
1913 "Agenda buffer currently being generated.")
1915 (defvar org-agenda-last-prefix-arg nil)
1916 (defvar org-agenda-this-buffer-name nil)
1917 (defvar org-agenda-doing-sticky-redo nil)
1918 (defvar org-agenda-this-buffer-is-sticky nil)
1920 (defconst org-agenda-local-vars
1921 '(org-agenda-this-buffer-name
1922 org-agenda-undo-list
1923 org-agenda-pending-undo-list
1924 org-agenda-follow-mode
1925 org-agenda-entry-text-mode
1926 org-agenda-clockreport-mode
1927 org-agenda-show-log
1928 org-agenda-redo-command
1929 org-agenda-query-string
1930 org-agenda-type
1931 org-agenda-bulk-marked-entries
1932 org-agenda-undo-has-started-in
1933 org-agenda-info
1934 org-agenda-tag-filter-overlays
1935 org-agenda-cat-filter-overlays
1936 org-agenda-pre-window-conf
1937 org-agenda-columns-active
1938 org-agenda-tag-filter
1939 org-agenda-category-filter
1940 org-agenda-markers
1941 org-agenda-last-search-view-search-was-boolean
1942 org-agenda-filtered-by-category
1943 org-agenda-filter-form
1944 org-agenda-show-window
1945 org-agenda-cycle-counter
1946 org-agenda-last-prefix-arg)
1947 "Variables that must be local in agenda buffers to allow multiple buffers.")
1949 (defun org-agenda-mode ()
1950 "Mode for time-sorted view on action items in Org-mode files.
1952 The following commands are available:
1954 \\{org-agenda-mode-map}"
1955 (interactive)
1956 (cond (org-agenda-doing-sticky-redo
1957 ;; Refreshing sticky agenda-buffer
1959 ;; Preserve the value of `org-agenda-local-vars' variables,
1960 ;; while letting `kill-all-local-variables' kill the rest
1961 (let ((save (buffer-local-variables)))
1962 (kill-all-local-variables)
1963 (mapc 'make-local-variable org-agenda-local-vars)
1964 (dolist (elem save)
1965 (let ((var (car elem))
1966 (val (cdr elem)))
1967 (when (and val
1968 (member var org-agenda-local-vars))
1969 (set var val)))))
1970 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1971 (org-agenda-sticky
1972 ;; Creating a sticky Agenda buffer for the first time
1973 (kill-all-local-variables)
1974 (mapc 'make-local-variable org-agenda-local-vars)
1975 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1977 ;; Creating a non-sticky agenda buffer
1978 (kill-all-local-variables)
1979 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1980 (setq org-agenda-undo-list nil
1981 org-agenda-pending-undo-list nil
1982 org-agenda-bulk-marked-entries nil)
1983 (setq major-mode 'org-agenda-mode)
1984 ;; Keep global-font-lock-mode from turning on font-lock-mode
1985 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1986 (setq mode-name "Org-Agenda")
1987 (use-local-map org-agenda-mode-map)
1988 (easy-menu-add org-agenda-menu)
1989 (if org-startup-truncated (setq truncate-lines t))
1990 (org-set-local 'line-move-visual nil)
1991 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
1992 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1993 ;; Make sure properties are removed when copying text
1994 (make-local-variable 'filter-buffer-substring-functions)
1995 (add-hook 'filter-buffer-substring-functions
1996 (lambda (fun start end delete)
1997 (substring-no-properties (funcall fun start end delete))))
1998 (unless org-agenda-keep-modes
1999 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2000 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2001 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2002 org-agenda-show-log org-agenda-start-with-log-mode))
2004 (easy-menu-change
2005 '("Agenda") "Agenda Files"
2006 (append
2007 (list
2008 (vector
2009 (if (get 'org-agenda-files 'org-restrict)
2010 "Restricted to single file"
2011 "Edit File List")
2012 '(org-edit-agenda-file-list)
2013 (not (get 'org-agenda-files 'org-restrict)))
2014 "--")
2015 (mapcar 'org-file-menu-entry (org-agenda-files))))
2016 (org-agenda-set-mode-name)
2017 (apply
2018 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2019 (list 'org-agenda-mode-hook)))
2021 (substitute-key-definition 'undo 'org-agenda-undo
2022 org-agenda-mode-map global-map)
2023 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2024 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2025 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2026 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2027 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2028 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2029 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2030 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2031 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2032 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2033 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2034 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2035 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2036 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2037 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2038 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2039 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2040 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2041 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2042 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2043 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2044 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2045 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2046 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2047 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2048 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2049 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2050 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2051 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2052 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2053 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2054 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2055 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2056 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2057 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2058 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2059 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2060 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2061 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2062 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2063 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2064 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2065 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2066 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2067 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2069 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2070 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2071 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2072 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2073 (while l (org-defkey org-agenda-mode-map
2074 (int-to-string (pop l)) 'digit-argument)))
2076 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2077 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2078 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2079 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2080 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2081 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2082 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2083 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2084 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2085 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2086 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2087 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2088 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2089 'org-clock-modify-effort-estimate)
2090 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2091 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2092 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2093 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2094 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2095 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2096 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2097 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2098 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2099 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2100 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2101 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2102 (substitute-key-definition 'next-line 'org-agenda-next-line
2103 org-agenda-mode-map global-map)
2104 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2105 org-agenda-mode-map global-map)
2106 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2107 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2108 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2109 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2110 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2111 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2112 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2113 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2114 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2115 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2116 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2117 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2118 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2119 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2120 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2121 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2122 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2123 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2124 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2125 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2126 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2127 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2128 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2129 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2130 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2131 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2132 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2133 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2134 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2135 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2137 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2138 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2139 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2140 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2141 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2142 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2143 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2144 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2145 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2146 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2147 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2148 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2150 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2151 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2152 (when org-agenda-mouse-1-follows-link
2153 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2154 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2155 '("Agenda"
2156 ("Agenda Files")
2157 "--"
2158 ("Agenda Dates"
2159 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2160 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2161 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2162 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2163 "--"
2164 ("View"
2165 ["Day View" org-agenda-day-view
2166 :active (org-agenda-check-type nil 'agenda)
2167 :style radio :selected (eq org-agenda-current-span 'day)
2168 :keys "v d (or just d)"]
2169 ["Week View" org-agenda-week-view
2170 :active (org-agenda-check-type nil 'agenda)
2171 :style radio :selected (eq org-agenda-current-span 'week)
2172 :keys "v w (or just w)"]
2173 ["Month View" org-agenda-month-view
2174 :active (org-agenda-check-type nil 'agenda)
2175 :style radio :selected (eq org-agenda-current-span 'month)
2176 :keys "v m"]
2177 ["Year View" org-agenda-year-view
2178 :active (org-agenda-check-type nil 'agenda)
2179 :style radio :selected (eq org-agenda-current-span 'year)
2180 :keys "v y"]
2181 "--"
2182 ["Include Diary" org-agenda-toggle-diary
2183 :style toggle :selected org-agenda-include-diary
2184 :active (org-agenda-check-type nil 'agenda)]
2185 ["Include Deadlines" org-agenda-toggle-deadlines
2186 :style toggle :selected org-agenda-include-deadlines
2187 :active (org-agenda-check-type nil 'agenda)]
2188 ["Use Time Grid" org-agenda-toggle-time-grid
2189 :style toggle :selected org-agenda-use-time-grid
2190 :active (org-agenda-check-type nil 'agenda)]
2191 "--"
2192 ["Show clock report" org-agenda-clockreport-mode
2193 :style toggle :selected org-agenda-clockreport-mode
2194 :active (org-agenda-check-type nil 'agenda)]
2195 ["Show some entry text" org-agenda-entry-text-mode
2196 :style toggle :selected org-agenda-entry-text-mode
2197 :active t]
2198 "--"
2199 ["Show Logbook entries" org-agenda-log-mode
2200 :style toggle :selected org-agenda-show-log
2201 :active (org-agenda-check-type nil 'agenda 'timeline)
2202 :keys "v l (or just l)"]
2203 ["Include archived trees" org-agenda-archives-mode
2204 :style toggle :selected org-agenda-archives-mode :active t
2205 :keys "v a"]
2206 ["Include archive files" (org-agenda-archives-mode t)
2207 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2208 :keys "v A"]
2209 "--"
2210 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2211 ["Write view to file" org-agenda-write t]
2212 ["Rebuild buffer" org-agenda-redo t]
2213 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2214 "--"
2215 ["Show original entry" org-agenda-show t]
2216 ["Go To (other window)" org-agenda-goto t]
2217 ["Go To (this window)" org-agenda-switch-to t]
2218 ["Capture with cursor date" org-agenda-capture t]
2219 ["Follow Mode" org-agenda-follow-mode
2220 :style toggle :selected org-agenda-follow-mode :active t]
2221 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2222 "--"
2223 ("TODO"
2224 ["Cycle TODO" org-agenda-todo t]
2225 ["Next TODO set" org-agenda-todo-nextset t]
2226 ["Previous TODO set" org-agenda-todo-previousset t]
2227 ["Add note" org-agenda-add-note t])
2228 ("Archive/Refile/Delete"
2229 ["Archive default" org-agenda-archive-default t]
2230 ["Archive default" org-agenda-archive-default-with-confirmation t]
2231 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2232 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2233 ["Archive subtree" org-agenda-archive t]
2234 "--"
2235 ["Refile" org-agenda-refile t]
2236 "--"
2237 ["Delete subtree" org-agenda-kill t])
2238 ("Bulk action"
2239 ["Mark entry" org-agenda-bulk-mark t]
2240 ["Mark all" org-agenda-bulk-mark-all t]
2241 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2242 ["Unmark entry" org-agenda-bulk-unmark t]
2243 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2244 ["Act on all marked" org-agenda-bulk-action t]
2245 "--"
2246 ("Tags and Properties"
2247 ["Show all Tags" org-agenda-show-tags t]
2248 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2249 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2250 "--"
2251 ["Column View" org-columns t])
2252 ("Deadline/Schedule"
2253 ["Schedule" org-agenda-schedule t]
2254 ["Set Deadline" org-agenda-deadline t]
2255 "--"
2256 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2257 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2258 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2259 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2260 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2261 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2262 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2263 ("Clock and Effort"
2264 ["Clock in" org-agenda-clock-in t]
2265 ["Clock out" org-agenda-clock-out t]
2266 ["Clock cancel" org-agenda-clock-cancel t]
2267 ["Goto running clock" org-clock-goto t]
2268 "--"
2269 ["Set Effort" org-agenda-set-effort t]
2270 ["Change clocked effort" org-clock-modify-effort-estimate
2271 (org-clock-is-active)])
2272 ("Priority"
2273 ["Set Priority" org-agenda-priority t]
2274 ["Increase Priority" org-agenda-priority-up t]
2275 ["Decrease Priority" org-agenda-priority-down t]
2276 ["Show Priority" org-show-priority t])
2277 ("Calendar/Diary"
2278 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2279 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2280 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2281 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2282 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2283 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2284 "--"
2285 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2286 "--"
2287 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2288 "--"
2289 ("MobileOrg"
2290 ["Push Files and Views" org-mobile-push t]
2291 ["Get Captured and Flagged" org-mobile-pull t]
2292 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2293 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2294 "--"
2295 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2296 "--"
2297 ["Quit" org-agenda-quit t]
2298 ["Exit and Release Buffers" org-agenda-exit t]
2301 ;;; Agenda undo
2303 (defvar org-agenda-allow-remote-undo t
2304 "Non-nil means allow remote undo from the agenda buffer.")
2305 (defvar org-agenda-undo-has-started-in nil
2306 "Buffers that have already seen `undo-start' in the current undo sequence.")
2308 (defun org-agenda-undo ()
2309 "Undo a remote editing step in the agenda.
2310 This undoes changes both in the agenda buffer and in the remote buffer
2311 that have been changed along."
2312 (interactive)
2313 (or org-agenda-allow-remote-undo
2314 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2315 (if (not (eq this-command last-command))
2316 (setq org-agenda-undo-has-started-in nil
2317 org-agenda-pending-undo-list org-agenda-undo-list))
2318 (if (not org-agenda-pending-undo-list)
2319 (error "No further undo information"))
2320 (let* ((entry (pop org-agenda-pending-undo-list))
2321 buf line cmd rembuf)
2322 (setq cmd (pop entry) line (pop entry))
2323 (setq rembuf (nth 2 entry))
2324 (org-with-remote-undo rembuf
2325 (while (bufferp (setq buf (pop entry)))
2326 (if (pop entry)
2327 (with-current-buffer buf
2328 (let ((last-undo-buffer buf)
2329 (inhibit-read-only t))
2330 (unless (memq buf org-agenda-undo-has-started-in)
2331 (push buf org-agenda-undo-has-started-in)
2332 (make-local-variable 'pending-undo-list)
2333 (undo-start))
2334 (while (and pending-undo-list
2335 (listp pending-undo-list)
2336 (not (car pending-undo-list)))
2337 (pop pending-undo-list))
2338 (undo-more 1))))))
2339 (org-goto-line line)
2340 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2342 (defun org-verify-change-for-undo (l1 l2)
2343 "Verify that a real change occurred between the undo lists L1 and L2."
2344 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2345 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2346 (not (eq l1 l2)))
2348 ;;; Agenda dispatch
2350 (defvar org-agenda-restrict-begin (make-marker))
2351 (defvar org-agenda-restrict-end (make-marker))
2352 (defvar org-agenda-last-dispatch-buffer nil)
2353 (defvar org-agenda-overriding-restriction nil)
2355 (defcustom org-agenda-custom-commands-contexts nil
2356 "Alist of custom agenda keys and contextual rules.
2358 For example, if you have a custom agenda command \"p\" and you
2359 want this command to be accessible only from plain text files,
2360 use this:
2362 '((\"p\" (in-file . \"\\.txt\")))
2364 Here are the available contexts definitions:
2366 in-file: command displayed only in matching files
2367 in-mode: command displayed only in matching modes
2368 not-in-file: command not displayed in matching files
2369 not-in-mode: command not displayed in matching modes
2370 [function]: a custom function taking no argument
2372 If you define several checks, the agenda command will be
2373 accessible if there is at least one valid check.
2375 You can also bind a key to another agenda custom command
2376 depending on contextual rules.
2378 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2380 Here it means: in .txt files, use \"p\" as the key for the
2381 agenda command otherwise associated with \"q\". (The command
2382 originally associated with \"q\" is not displayed to avoid
2383 duplicates.)"
2384 :version "24.3"
2385 :group 'org-agenda-custom-commands
2386 :type '(repeat (list :tag "Rule"
2387 (string :tag " Agenda key")
2388 (string :tag "Replace by command")
2389 (repeat :tag "Available when"
2390 (choice
2391 (cons :tag "Condition"
2392 (choice
2393 (const :tag "In file" in-file)
2394 (const :tag "Not in file" not-in-file)
2395 (const :tag "In mode" in-mode)
2396 (const :tag "Not in mode" not-in-mode))
2397 (regexp))
2398 (function :tag "Custom function"))))))
2400 (defvar org-keys nil)
2401 (defvar org-match nil)
2402 ;;;###autoload
2403 (defun org-agenda (&optional arg org-keys restriction)
2404 "Dispatch agenda commands to collect entries to the agenda buffer.
2405 Prompts for a command to execute. Any prefix arg will be passed
2406 on to the selected command. The default selections are:
2408 a Call `org-agenda-list' to display the agenda for current day or week.
2409 t Call `org-todo-list' to display the global todo list.
2410 T Call `org-todo-list' to display the global todo list, select only
2411 entries with a specific TODO keyword (the user gets a prompt).
2412 m Call `org-tags-view' to display headlines with tags matching
2413 a condition (the user is prompted for the condition).
2414 M Like `m', but select only TODO entries, no ordinary headlines.
2415 L Create a timeline for the current buffer.
2416 e Export views to associated files.
2417 s Search entries for keywords.
2418 S Search entries for keywords, only with TODO keywords.
2419 / Multi occur across all agenda files and also files listed
2420 in `org-agenda-text-search-extra-files'.
2421 < Restrict agenda commands to buffer, subtree, or region.
2422 Press several times to get the desired effect.
2423 > Remove a previous restriction.
2424 # List \"stuck\" projects.
2425 ! Configure what \"stuck\" means.
2426 C Configure custom agenda commands.
2428 More commands can be added by configuring the variable
2429 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2430 searches can be pre-defined in this way.
2432 If the current buffer is in Org-mode and visiting a file, you can also
2433 first press `<' once to indicate that the agenda should be temporarily
2434 \(until the next use of \\[org-agenda]) restricted to the current file.
2435 Pressing `<' twice means to restrict to the current subtree or region
2436 \(if active)."
2437 (interactive "P")
2438 (catch 'exit
2439 (let* ((prefix-descriptions nil)
2440 (org-agenda-buffer-name org-agenda-buffer-name)
2441 (org-agenda-window-setup (if (equal (buffer-name)
2442 org-agenda-buffer-name)
2443 'current-window
2444 org-agenda-window-setup))
2445 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2446 (org-agenda-custom-commands
2447 ;; normalize different versions
2448 (delq nil
2449 (mapcar
2450 (lambda (x)
2451 (cond ((stringp (cdr x))
2452 (push x prefix-descriptions)
2453 nil)
2454 ((stringp (nth 1 x)) x)
2455 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2456 (t (cons (car x) (cons "" (cdr x))))))
2457 org-agenda-custom-commands)))
2458 (org-agenda-custom-commands
2459 (org-contextualize-keys
2460 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2461 (buf (current-buffer))
2462 (bfn (buffer-file-name (buffer-base-buffer)))
2463 entry key type org-match lprops ans)
2464 ;; Turn off restriction unless there is an overriding one,
2465 (unless org-agenda-overriding-restriction
2466 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2467 ;; There is a request to keep the file list in place
2468 (put 'org-agenda-files 'org-restrict nil))
2469 (setq org-agenda-restrict nil)
2470 (move-marker org-agenda-restrict-begin nil)
2471 (move-marker org-agenda-restrict-end nil))
2472 ;; Delete old local properties
2473 (put 'org-agenda-redo-command 'org-lprops nil)
2474 ;; Delete previously set last-arguments
2475 (put 'org-agenda-redo-command 'last-args nil)
2476 ;; Remember where this call originated
2477 (setq org-agenda-last-dispatch-buffer (current-buffer))
2478 (unless org-keys
2479 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2480 org-keys (car ans)
2481 restriction (cdr ans)))
2482 ;; If we have sticky agenda buffers, set a name for the buffer,
2483 ;; depending on the invoking keys. The user may still set this
2484 ;; as a command option, which will overwrite what we do here.
2485 (if org-agenda-sticky
2486 (setq org-agenda-buffer-name
2487 (format "*Org Agenda(%s)*" org-keys)))
2488 ;; Establish the restriction, if any
2489 (when (and (not org-agenda-overriding-restriction) restriction)
2490 (put 'org-agenda-files 'org-restrict (list bfn))
2491 (cond
2492 ((eq restriction 'region)
2493 (setq org-agenda-restrict t)
2494 (move-marker org-agenda-restrict-begin (region-beginning))
2495 (move-marker org-agenda-restrict-end (region-end)))
2496 ((eq restriction 'subtree)
2497 (save-excursion
2498 (setq org-agenda-restrict t)
2499 (org-back-to-heading t)
2500 (move-marker org-agenda-restrict-begin (point))
2501 (move-marker org-agenda-restrict-end
2502 (progn (org-end-of-subtree t)))))))
2504 ;; For example the todo list should not need it (but does...)
2505 (cond
2506 ((setq entry (assoc org-keys org-agenda-custom-commands))
2507 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2508 (progn
2509 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2510 lprops (nth 4 entry))
2511 (if org-agenda-sticky
2512 (setq org-agenda-buffer-name
2513 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2514 (format "*Org Agenda(%s)*" org-keys))))
2515 (put 'org-agenda-redo-command 'org-lprops lprops)
2516 (cond
2517 ((eq type 'agenda)
2518 (org-let lprops '(org-agenda-list current-prefix-arg)))
2519 ((eq type 'alltodo)
2520 (org-let lprops '(org-todo-list current-prefix-arg)))
2521 ((eq type 'search)
2522 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2523 ((eq type 'stuck)
2524 (org-let lprops '(org-agenda-list-stuck-projects
2525 current-prefix-arg)))
2526 ((eq type 'tags)
2527 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2528 ((eq type 'tags-todo)
2529 (org-let lprops '(org-tags-view '(4) org-match)))
2530 ((eq type 'todo)
2531 (org-let lprops '(org-todo-list org-match)))
2532 ((eq type 'tags-tree)
2533 (org-check-for-org-mode)
2534 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2535 ((eq type 'todo-tree)
2536 (org-check-for-org-mode)
2537 (org-let lprops
2538 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2539 (regexp-quote org-match) "\\>"))))
2540 ((eq type 'occur-tree)
2541 (org-check-for-org-mode)
2542 (org-let lprops '(org-occur org-match)))
2543 ((functionp type)
2544 (org-let lprops '(funcall type org-match)))
2545 ((fboundp type)
2546 (org-let lprops '(funcall type org-match)))
2547 (t (error "Invalid custom agenda command type %s" type))))
2548 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2549 ((equal org-keys "C")
2550 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2551 (customize-variable 'org-agenda-custom-commands))
2552 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2553 ((equal org-keys "s") (call-interactively 'org-search-view))
2554 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2555 ((equal org-keys "t") (call-interactively 'org-todo-list))
2556 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2557 ((equal org-keys "m") (call-interactively 'org-tags-view))
2558 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2559 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2560 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2561 (org-add-hook
2562 'post-command-hook
2563 (lambda ()
2564 (unless (current-message)
2565 (let* ((m (org-agenda-get-any-marker))
2566 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2567 (when note
2568 (message (concat
2569 "FLAGGING-NOTE ([?] for more info): "
2570 (org-add-props
2571 (replace-regexp-in-string
2572 "\\\\n" "//"
2573 (copy-sequence note))
2574 nil 'face 'org-warning)))))))
2575 t t))
2576 ((equal org-keys "L")
2577 (unless (derived-mode-p 'org-mode)
2578 (error "This is not an Org-mode file"))
2579 (unless restriction
2580 (put 'org-agenda-files 'org-restrict (list bfn))
2581 (org-call-with-arg 'org-timeline arg)))
2582 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2583 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2584 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2585 (t (error "Invalid agenda key"))))))
2587 (autoload 'org-agenda "org-agenda" "\
2588 Dispatch agenda commands to collect entries to the agenda buffer.
2589 Prompts for a command to execute. Any prefix arg will be passed
2590 on to the selected command. The default selections are:
2592 a Call `org-agenda-list' to display the agenda for current day or week.
2593 t Call `org-todo-list' to display the global todo list.
2594 T Call `org-todo-list' to display the global todo list, select only
2595 entries with a specific TODO keyword (the user gets a prompt).
2596 m Call `org-tags-view' to display headlines with tags matching
2597 a condition (the user is prompted for the condition).
2598 M Like `m', but select only TODO entries, no ordinary headlines.
2599 L Create a timeline for the current buffer.
2600 e Export views to associated files.
2601 s Search entries for keywords.
2602 S Search entries for keywords, only with TODO keywords.
2603 / Multi occur across all agenda files and also files listed
2604 in `org-agenda-text-search-extra-files'.
2605 < Restrict agenda commands to buffer, subtree, or region.
2606 Press several times to get the desired effect.
2607 > Remove a previous restriction.
2608 # List \"stuck\" projects.
2609 ! Configure what \"stuck\" means.
2610 C Configure custom agenda commands.
2612 More commands can be added by configuring the variable
2613 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2614 searches can be pre-defined in this way.
2616 If the current buffer is in Org-mode and visiting a file, you can also
2617 first press `<' once to indicate that the agenda should be temporarily
2618 \(until the next use of \\[org-agenda]) restricted to the current file.
2619 Pressing `<' twice means to restrict to the current subtree or region
2620 \(if active).
2622 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2624 (defun org-agenda-append-agenda ()
2625 "Append another agenda view to the current one.
2626 This function allows interactive building of block agendas.
2627 Agenda views are separated by `org-agenda-block-separator'."
2628 (interactive)
2629 (unless (derived-mode-p 'org-agenda-mode)
2630 (error "Can only append from within agenda buffer"))
2631 (let ((org-agenda-multi t))
2632 (org-agenda)
2633 (widen)
2634 (org-agenda-finalize)
2635 (org-agenda-fit-window-to-buffer)))
2637 (defun org-agenda-normalize-custom-commands (cmds)
2638 (delq nil
2639 (mapcar
2640 (lambda (x)
2641 (cond ((stringp (cdr x)) nil)
2642 ((stringp (nth 1 x)) x)
2643 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2644 (t (cons (car x) (cons "" (cdr x))))))
2645 cmds)))
2647 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2648 "The user interface for selecting an agenda command."
2649 (catch 'exit
2650 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2651 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2652 (region-p (org-region-active-p))
2653 (custom org-agenda-custom-commands)
2654 (selstring "")
2655 restriction second-time
2656 c entry key type match prefixes rmheader header-end custom1 desc
2657 line lines left right n n1)
2658 (save-window-excursion
2659 (delete-other-windows)
2660 (org-switch-to-buffer-other-window " *Agenda Commands*")
2661 (erase-buffer)
2662 (insert (eval-when-compile
2663 (let ((header
2664 "Press key for an agenda command: < Buffer, subtree/region restriction
2665 -------------------------------- > Remove restriction
2666 a Agenda for current week or day e Export agenda views
2667 t List of all TODO entries T Entries with special TODO kwd
2668 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2669 s Search for keywords S Like s, but only TODO entries
2670 L Timeline for current buffer # List stuck projects (!=configure)
2671 / Multi-occur C Configure custom agenda commands
2672 ? Find :FLAGGED: entries * Toggle sticky agenda views
2674 (start 0))
2675 (while (string-match
2676 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2677 header start)
2678 (setq start (match-end 0))
2679 (add-text-properties (match-beginning 2) (match-end 2)
2680 '(face bold) header))
2681 header)))
2682 (setq header-end (move-marker (make-marker) (point)))
2683 (while t
2684 (setq custom1 custom)
2685 (when (eq rmheader t)
2686 (org-goto-line 1)
2687 (re-search-forward ":" nil t)
2688 (delete-region (match-end 0) (point-at-eol))
2689 (forward-char 1)
2690 (looking-at "-+")
2691 (delete-region (match-end 0) (point-at-eol))
2692 (move-marker header-end (match-end 0)))
2693 (goto-char header-end)
2694 (delete-region (point) (point-max))
2696 ;; Produce all the lines that describe custom commands and prefixes
2697 (setq lines nil)
2698 (while (setq entry (pop custom1))
2699 (setq key (car entry) desc (nth 1 entry)
2700 type (nth 2 entry)
2701 match (nth 3 entry))
2702 (if (> (length key) 1)
2703 (add-to-list 'prefixes (string-to-char key))
2704 (setq line
2705 (format
2706 "%-4s%-14s"
2707 (org-add-props (copy-sequence key)
2708 '(face bold))
2709 (cond
2710 ((string-match "\\S-" desc) desc)
2711 ((eq type 'agenda) "Agenda for current week or day")
2712 ((eq type 'alltodo) "List of all TODO entries")
2713 ((eq type 'search) "Word search")
2714 ((eq type 'stuck) "List of stuck projects")
2715 ((eq type 'todo) "TODO keyword")
2716 ((eq type 'tags) "Tags query")
2717 ((eq type 'tags-todo) "Tags (TODO)")
2718 ((eq type 'tags-tree) "Tags tree")
2719 ((eq type 'todo-tree) "TODO kwd tree")
2720 ((eq type 'occur-tree) "Occur tree")
2721 ((functionp type) (if (symbolp type)
2722 (symbol-name type)
2723 "Lambda expression"))
2724 (t "???"))))
2725 (if org-agenda-menu-show-matcher
2726 (setq line
2727 (concat line ": "
2728 (cond
2729 ((stringp match)
2730 (setq match (copy-sequence match))
2731 (org-add-props match nil 'face 'org-warning))
2732 ((listp type)
2733 (format "set of %d commands" (length type))))))
2734 (if (org-string-nw-p match)
2735 (add-text-properties
2736 0 (length line) (list 'help-echo
2737 (concat "Matcher: " match)) line)))
2738 (push line lines)))
2739 (setq lines (nreverse lines))
2740 (when prefixes
2741 (mapc (lambda (x)
2742 (push
2743 (format "%s %s"
2744 (org-add-props (char-to-string x)
2745 nil 'face 'bold)
2746 (or (cdr (assoc (concat selstring
2747 (char-to-string x))
2748 prefix-descriptions))
2749 "Prefix key"))
2750 lines))
2751 prefixes))
2753 ;; Check if we should display in two columns
2754 (if org-agenda-menu-two-columns
2755 (progn
2756 (setq n (length lines)
2757 n1 (+ (/ n 2) (mod n 2))
2758 right (nthcdr n1 lines)
2759 left (copy-sequence lines))
2760 (setcdr (nthcdr (1- n1) left) nil))
2761 (setq left lines right nil))
2762 (while left
2763 (insert "\n" (pop left))
2764 (when right
2765 (if (< (current-column) 40)
2766 (move-to-column 40 t)
2767 (insert " "))
2768 (insert (pop right))))
2770 ;; Make the window the right size
2771 (goto-char (point-min))
2772 (if second-time
2773 (if (not (pos-visible-in-window-p (point-max)))
2774 (org-fit-window-to-buffer))
2775 (setq second-time t)
2776 (org-fit-window-to-buffer))
2778 ;; Ask for selection
2779 (message "Press key for agenda command%s:"
2780 (if (or restrict-ok org-agenda-overriding-restriction)
2781 (if org-agenda-overriding-restriction
2782 " (restriction lock active)"
2783 (if restriction
2784 (format " (restricted to %s)" restriction)
2785 " (unrestricted)"))
2786 ""))
2787 (setq c (read-char-exclusive))
2788 (message "")
2789 (cond
2790 ((assoc (char-to-string c) custom)
2791 (setq selstring (concat selstring (char-to-string c)))
2792 (throw 'exit (cons selstring restriction)))
2793 ((memq c prefixes)
2794 (setq selstring (concat selstring (char-to-string c))
2795 prefixes nil
2796 rmheader (or rmheader t)
2797 custom (delq nil (mapcar
2798 (lambda (x)
2799 (if (or (= (length (car x)) 1)
2800 (/= (string-to-char (car x)) c))
2802 (cons (substring (car x) 1) (cdr x))))
2803 custom))))
2804 ((eq c ?*)
2805 (call-interactively 'org-toggle-sticky-agenda)
2806 (sit-for 2))
2807 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2808 (message "Restriction is only possible in Org-mode buffers")
2809 (ding) (sit-for 1))
2810 ((eq c ?1)
2811 (org-agenda-remove-restriction-lock 'noupdate)
2812 (setq restriction 'buffer))
2813 ((eq c ?0)
2814 (org-agenda-remove-restriction-lock 'noupdate)
2815 (setq restriction (if region-p 'region 'subtree)))
2816 ((eq c ?<)
2817 (org-agenda-remove-restriction-lock 'noupdate)
2818 (setq restriction
2819 (cond
2820 ((eq restriction 'buffer)
2821 (if region-p 'region 'subtree))
2822 ((memq restriction '(subtree region))
2823 nil)
2824 (t 'buffer))))
2825 ((eq c ?>)
2826 (org-agenda-remove-restriction-lock 'noupdate)
2827 (setq restriction nil))
2828 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2829 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2830 ((and (> (length selstring) 0) (eq c ?\d))
2831 (delete-window)
2832 (org-agenda-get-restriction-and-command prefix-descriptions))
2834 ((equal c ?q) (error "Abort"))
2835 (t (error "Invalid key %c" c))))))))
2837 (defun org-agenda-fit-window-to-buffer ()
2838 "Fit the window to the buffer size."
2839 (and (memq org-agenda-window-setup '(reorganize-frame))
2840 (fboundp 'fit-window-to-buffer)
2841 (org-fit-window-to-buffer
2843 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2844 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2846 (defvar org-cmd nil)
2847 (defvar org-agenda-overriding-cmd nil)
2848 (defvar org-agenda-overriding-arguments nil)
2849 (defvar org-agenda-overriding-cmd-arguments nil)
2850 (defun org-agenda-run-series (name series)
2851 (org-let (nth 1 series) '(org-agenda-prepare name))
2852 ;; We need to reset agenda markers here, because when constructing a
2853 ;; block agenda, the individual blocks do not do that.
2854 (org-agenda-reset-markers)
2855 (let* ((org-agenda-multi t)
2856 (redo (list 'org-agenda-run-series name (list 'quote series)))
2857 (cmds (car series))
2858 (gprops (nth 1 series))
2859 match ;; The byte compiler incorrectly complains about this. Keep it!
2860 org-cmd type lprops)
2861 (while (setq org-cmd (pop cmds))
2862 (setq type (car org-cmd)
2863 match (eval (nth 1 org-cmd))
2864 lprops (nth 2 org-cmd))
2865 (let ((org-agenda-overriding-arguments
2866 (if (eq org-agenda-overriding-cmd org-cmd)
2867 (or org-agenda-overriding-arguments
2868 org-agenda-overriding-cmd-arguments))))
2869 (cond
2870 ((eq type 'agenda)
2871 (org-let2 gprops lprops
2872 '(call-interactively 'org-agenda-list)))
2873 ((eq type 'alltodo)
2874 (org-let2 gprops lprops
2875 '(call-interactively 'org-todo-list)))
2876 ((eq type 'search)
2877 (org-let2 gprops lprops
2878 '(org-search-view current-prefix-arg match nil)))
2879 ((eq type 'stuck)
2880 (org-let2 gprops lprops
2881 '(call-interactively 'org-agenda-list-stuck-projects)))
2882 ((eq type 'tags)
2883 (org-let2 gprops lprops
2884 '(org-tags-view current-prefix-arg match)))
2885 ((eq type 'tags-todo)
2886 (org-let2 gprops lprops
2887 '(org-tags-view '(4) match)))
2888 ((eq type 'todo)
2889 (org-let2 gprops lprops
2890 '(org-todo-list match)))
2891 ((fboundp type)
2892 (org-let2 gprops lprops
2893 '(funcall type match)))
2894 (t (error "Invalid type in command series")))))
2895 (widen)
2896 (let ((inhibit-read-only t))
2897 (add-text-properties (point-min) (point-max)
2898 `(org-serie t org-serie-redo-cmd ,redo)))
2899 (setq org-agenda-redo-command redo)
2900 (goto-char (point-min)))
2901 (org-agenda-fit-window-to-buffer)
2902 (org-let (nth 1 series) '(org-agenda-finalize)))
2904 ;;;###autoload
2905 (defmacro org-batch-agenda (cmd-key &rest parameters)
2906 "Run an agenda command in batch mode and send the result to STDOUT.
2907 If CMD-KEY is a string of length 1, it is used as a key in
2908 `org-agenda-custom-commands' and triggers this command. If it is a
2909 longer string it is used as a tags/todo match string.
2910 Parameters are alternating variable names and values that will be bound
2911 before running the agenda command."
2912 (org-eval-in-environment (org-make-parameter-alist parameters)
2913 (if (> (length cmd-key) 2)
2914 (org-tags-view nil cmd-key)
2915 (org-agenda nil cmd-key)))
2916 (set-buffer org-agenda-buffer-name)
2917 (princ (buffer-string)))
2919 (autoload 'org-batch-agenda "org-agenda" "\
2920 Run an agenda command in batch mode and send the result to STDOUT.
2921 If CMD-KEY is a string of length 1, it is used as a key in
2922 `org-agenda-custom-commands' and triggers this command. If it is a
2923 longer string it is used as a tags/todo match string.
2924 Parameters are alternating variable names and values that will be bound
2925 before running the agenda command.
2927 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2928 (def-edebug-spec org-batch-agenda (form &rest sexp))
2930 (defvar org-agenda-info nil)
2932 ;;;###autoload
2933 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2934 "Run an agenda command in batch mode and send the result to STDOUT.
2935 If CMD-KEY is a string of length 1, it is used as a key in
2936 `org-agenda-custom-commands' and triggers this command. If it is a
2937 longer string it is used as a tags/todo match string.
2938 Parameters are alternating variable names and values that will be bound
2939 before running the agenda command.
2941 The output gives a line for each selected agenda item. Each
2942 item is a list of comma-separated values, like this:
2944 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2946 category The category of the item
2947 head The headline, without TODO kwd, TAGS and PRIORITY
2948 type The type of the agenda entry, can be
2949 todo selected in TODO match
2950 tagsmatch selected in tags match
2951 diary imported from diary
2952 deadline a deadline on given date
2953 scheduled scheduled on given date
2954 timestamp entry has timestamp on given date
2955 closed entry was closed on given date
2956 upcoming-deadline warning about deadline
2957 past-scheduled forwarded scheduled item
2958 block entry has date block including g. date
2959 todo The todo keyword, if any
2960 tags All tags including inherited ones, separated by colons
2961 date The relevant date, like 2007-2-14
2962 time The time, like 15:00-16:50
2963 extra Sting with extra planning info
2964 priority-l The priority letter if any was given
2965 priority-n The computed numerical priority
2966 agenda-day The day in the agenda where this is listed"
2967 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2968 (org-make-parameter-alist parameters))
2969 (if (> (length cmd-key) 2)
2970 (org-tags-view nil cmd-key)
2971 (org-agenda nil cmd-key)))
2972 (set-buffer org-agenda-buffer-name)
2973 (let* ((lines (org-split-string (buffer-string) "\n"))
2974 line)
2975 (while (setq line (pop lines))
2976 (catch 'next
2977 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2978 (setq org-agenda-info
2979 (org-fix-agenda-info (text-properties-at 0 line)))
2980 (princ
2981 (mapconcat 'org-agenda-export-csv-mapper
2982 '(org-category txt type todo tags date time extra
2983 priority-letter priority agenda-day)
2984 ","))
2985 (princ "\n")))))
2987 (autoload 'org-batch-agenda-csv "org-agenda" "\
2988 Run an agenda command in batch mode and send the result to STDOUT.
2989 If CMD-KEY is a string of length 1, it is used as a key in
2990 `org-agenda-custom-commands' and triggers this command. If it is a
2991 longer string it is used as a tags/todo match string.
2992 Parameters are alternating variable names and values that will be bound
2993 before running the agenda command.
2995 The output gives a line for each selected agenda item. Each
2996 item is a list of comma-separated values, like this:
2998 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3000 category The category of the item
3001 head The headline, without TODO kwd, TAGS and PRIORITY
3002 type The type of the agenda entry, can be
3003 todo selected in TODO match
3004 tagsmatch selected in tags match
3005 diary imported from diary
3006 deadline a deadline on given date
3007 scheduled scheduled on given date
3008 timestamp entry has timestamp on given date
3009 closed entry was closed on given date
3010 upcoming-deadline warning about deadline
3011 past-scheduled forwarded scheduled item
3012 block entry has date block including g. date
3013 todo The todo keyword, if any
3014 tags All tags including inherited ones, separated by colons
3015 date The relevant date, like 2007-2-14
3016 time The time, like 15:00-16:50
3017 extra Sting with extra planning info
3018 priority-l The priority letter if any was given
3019 priority-n The computed numerical priority
3020 agenda-day The day in the agenda where this is listed
3022 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3023 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3025 (defun org-fix-agenda-info (props)
3026 "Make sure all properties on an agenda item have a canonical form.
3027 This ensures the export commands can easily use it."
3028 (let (tmp re)
3029 (when (setq tmp (plist-get props 'tags))
3030 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3031 (when (setq tmp (plist-get props 'date))
3032 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3033 (let ((calendar-date-display-form '(year "-" month "-" day)))
3034 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3036 (setq tmp (calendar-date-string tmp)))
3037 (setq props (plist-put props 'date tmp)))
3038 (when (setq tmp (plist-get props 'day))
3039 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3040 (let ((calendar-date-display-form '(year "-" month "-" day)))
3041 (setq tmp (calendar-date-string tmp)))
3042 (setq props (plist-put props 'day tmp))
3043 (setq props (plist-put props 'agenda-day tmp)))
3044 (when (setq tmp (plist-get props 'txt))
3045 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3046 (plist-put props 'priority-letter (match-string 1 tmp))
3047 (setq tmp (replace-match "" t t tmp)))
3048 (when (and (setq re (plist-get props 'org-todo-regexp))
3049 (setq re (concat "\\`\\.*" re " ?"))
3050 (string-match re tmp))
3051 (plist-put props 'todo (match-string 1 tmp))
3052 (setq tmp (replace-match "" t t tmp)))
3053 (plist-put props 'txt tmp)))
3054 props)
3056 (defun org-agenda-export-csv-mapper (prop)
3057 (let ((res (plist-get org-agenda-info prop)))
3058 (setq res
3059 (cond
3060 ((not res) "")
3061 ((stringp res) res)
3062 (t (prin1-to-string res))))
3063 (while (string-match "," res)
3064 (setq res (replace-match ";" t t res)))
3065 (org-trim res)))
3067 ;;;###autoload
3068 (defun org-store-agenda-views (&rest parameters)
3069 (interactive)
3070 (eval (list 'org-batch-store-agenda-views)))
3072 (autoload 'org-store-agenda-views "org-agenda" "\
3075 \(fn &rest PARAMETERS)" t nil)
3077 ;;;###autoload
3078 (defmacro org-batch-store-agenda-views (&rest parameters)
3079 "Run all custom agenda commands that have a file argument."
3080 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3081 (pop-up-frames nil)
3082 (dir default-directory)
3083 (pars (org-make-parameter-alist parameters))
3084 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3085 (save-window-excursion
3086 (while cmds
3087 (setq cmd (pop cmds)
3088 thiscmdkey (car cmd)
3089 thiscmdcmd (cdr cmd)
3090 match (nth 2 thiscmdcmd)
3091 bufname (if org-agenda-sticky
3092 (or (and (stringp match)
3093 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3094 (format "*Org Agenda(%s)*" thiscmdkey))
3095 org-agenda-buffer-name)
3096 cmd-or-set (nth 2 cmd)
3097 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3098 files (nth (if (listp cmd-or-set) 4 5) cmd))
3099 (if (stringp files) (setq files (list files)))
3100 (when files
3101 (org-eval-in-environment (append org-agenda-exporter-settings
3102 opts pars)
3103 (org-agenda nil thiscmdkey))
3104 (set-buffer bufname)
3105 (while files
3106 (org-eval-in-environment (append org-agenda-exporter-settings
3107 opts pars)
3108 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3109 (and (get-buffer bufname)
3110 (kill-buffer bufname)))))))
3112 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3113 Run all custom agenda commands that have a file argument.
3115 \(fn &rest PARAMETERS)" nil t)
3116 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3118 (defvar org-agenda-current-span nil
3119 "The current span used in the agenda view.") ; local variable in the agenda buffer
3120 (defun org-agenda-mark-header-line (pos)
3121 "Mark the line at POS as an agenda structure header."
3122 (save-excursion
3123 (goto-char pos)
3124 (put-text-property (point-at-bol) (point-at-eol)
3125 'org-agenda-structural-header t)
3126 (when org-agenda-title-append
3127 (put-text-property (point-at-bol) (point-at-eol)
3128 'org-agenda-title-append org-agenda-title-append))))
3130 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3131 (defvar org-agenda-write-buffer-name "Agenda View")
3132 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3133 "Write the current buffer (an agenda view) as a file.
3134 Depending on the extension of the file name, plain text (.txt),
3135 HTML (.html or .htm) or Postscript (.ps) is produced.
3136 If the extension is .ics, run icalendar export over all files used
3137 to construct the agenda and limit the export to entries listed in the
3138 agenda now.
3139 With prefix argument OPEN, open the new file immediately.
3140 If NOSETTINGS is given, do not scope the settings of
3141 `org-agenda-exporter-settings' into the export commands. This is used when
3142 the settings have already been scoped and we do not wish to overrule other,
3143 higher priority settings.
3144 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3145 (interactive "FWrite agenda to file: \nP")
3146 (if (not (file-writable-p file))
3147 (error "Cannot write agenda to file %s" file))
3148 (org-let (if nosettings nil org-agenda-exporter-settings)
3149 '(save-excursion
3150 (save-window-excursion
3151 (org-agenda-mark-filtered-text)
3152 (let ((bs (copy-sequence (buffer-string))) beg)
3153 (org-agenda-unmark-filtered-text)
3154 (with-temp-buffer
3155 (rename-buffer org-agenda-write-buffer-name t)
3156 (set-buffer-modified-p nil)
3157 (insert bs)
3158 (org-agenda-remove-marked-text 'org-filtered)
3159 (while (setq beg (text-property-any (point-min) (point-max)
3160 'org-filtered t))
3161 (delete-region
3162 beg (or (next-single-property-change beg 'org-filtered)
3163 (point-max))))
3164 (run-hooks 'org-agenda-before-write-hook)
3165 (cond
3166 ((org-bound-and-true-p org-mobile-creating-agendas)
3167 (org-mobile-write-agenda-for-mobile file))
3168 ((string-match "\\.html?\\'" file)
3169 (require 'htmlize)
3170 (set-buffer (htmlize-buffer (current-buffer)))
3171 (when org-agenda-export-html-style
3172 ;; replace <style> section with org-agenda-export-html-style
3173 (goto-char (point-min))
3174 (kill-region (- (search-forward "<style") 6)
3175 (search-forward "</style>"))
3176 (insert org-agenda-export-html-style))
3177 (write-file file)
3178 (kill-buffer (current-buffer))
3179 (message "HTML written to %s" file))
3180 ((string-match "\\.ps\\'" file)
3181 (require 'ps-print)
3182 (ps-print-buffer-with-faces file)
3183 (message "Postscript written to %s" file))
3184 ((string-match "\\.pdf\\'" file)
3185 (require 'ps-print)
3186 (ps-print-buffer-with-faces
3187 (concat (file-name-sans-extension file) ".ps"))
3188 (call-process "ps2pdf" nil nil nil
3189 (expand-file-name
3190 (concat (file-name-sans-extension file) ".ps"))
3191 (expand-file-name file))
3192 (delete-file (concat (file-name-sans-extension file) ".ps"))
3193 (message "PDF written to %s" file))
3194 ((string-match "\\.ics\\'" file)
3195 (require 'org-icalendar)
3196 (let ((org-agenda-marker-table
3197 (org-create-marker-find-array
3198 (org-agenda-collect-markers)))
3199 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3200 (org-combined-agenda-icalendar-file file))
3201 (apply 'org-export-icalendar 'combine
3202 (org-agenda-files nil 'ifmode))))
3204 (let ((bs (buffer-string)))
3205 (find-file file)
3206 (erase-buffer)
3207 (insert bs)
3208 (save-buffer 0)
3209 (kill-buffer (current-buffer))
3210 (message "Plain text written to %s" file))))))))
3211 (set-buffer (or agenda-bufname
3212 (and (called-interactively-p 'any) (buffer-name))
3213 org-agenda-buffer-name)))
3214 (when open (org-open-file file)))
3216 (defvar org-agenda-tag-filter-overlays nil)
3217 (defvar org-agenda-cat-filter-overlays nil)
3219 (defun org-agenda-mark-filtered-text ()
3220 "Mark all text hidden by filtering with a text property."
3221 (let ((inhibit-read-only t))
3222 (mapc
3223 (lambda (o)
3224 (when (equal (overlay-buffer o) (current-buffer))
3225 (put-text-property
3226 (overlay-start o) (overlay-end o)
3227 'org-filtered t)))
3228 (append org-agenda-tag-filter-overlays
3229 org-agenda-cat-filter-overlays))))
3231 (defun org-agenda-unmark-filtered-text ()
3232 "Remove the filtering text property."
3233 (let ((inhibit-read-only t))
3234 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3236 (defun org-agenda-remove-marked-text (property &optional value)
3237 "Delete all text marked with VALUE of PROPERTY.
3238 VALUE defaults to t."
3239 (let (beg)
3240 (setq value (or value t))
3241 (while (setq beg (text-property-any (point-min) (point-max)
3242 property value))
3243 (delete-region
3244 beg (or (next-single-property-change beg 'org-filtered)
3245 (point-max))))))
3247 (defun org-agenda-add-entry-text ()
3248 "Add entry text to agenda lines.
3249 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3250 entry text following headings shown in the agenda.
3251 Drawers will be excluded, also the line with scheduling/deadline info."
3252 (when (and (> org-agenda-add-entry-text-maxlines 0)
3253 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3254 (let (m txt)
3255 (goto-char (point-min))
3256 (while (not (eobp))
3257 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3258 (beginning-of-line 2)
3259 (setq txt (org-agenda-get-some-entry-text
3260 m org-agenda-add-entry-text-maxlines " > "))
3261 (end-of-line 1)
3262 (if (string-match "\\S-" txt)
3263 (insert "\n" txt)
3264 (or (eobp) (forward-char 1))))))))
3266 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3267 &rest keep)
3268 "Extract entry text from MARKER, at most N-LINES lines.
3269 This will ignore drawers etc, just get the text.
3270 If INDENT is given, prefix every line with this string. If KEEP is
3271 given, it is a list of symbols, defining stuff that should not be
3272 removed from the entry content. Currently only `planning' is allowed here."
3273 (let (txt drawer-re kwd-time-re ind)
3274 (save-excursion
3275 (with-current-buffer (marker-buffer marker)
3276 (if (not (derived-mode-p 'org-mode))
3277 (setq txt "")
3278 (save-excursion
3279 (save-restriction
3280 (widen)
3281 (goto-char marker)
3282 (end-of-line 1)
3283 (setq txt (buffer-substring
3284 (min (1+ (point)) (point-max))
3285 (progn (outline-next-heading) (point)))
3286 drawer-re org-drawer-regexp
3287 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3288 ".*\n?"))
3289 (with-temp-buffer
3290 (insert txt)
3291 (when org-agenda-add-entry-text-descriptive-links
3292 (goto-char (point-min))
3293 (while (org-activate-bracket-links (point-max))
3294 (add-text-properties (match-beginning 0) (match-end 0)
3295 '(face org-link))))
3296 (goto-char (point-min))
3297 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3298 (set-text-properties (match-beginning 0) (match-end 0)
3299 nil))
3300 (goto-char (point-min))
3301 (while (re-search-forward drawer-re nil t)
3302 (delete-region
3303 (match-beginning 0)
3304 (progn (re-search-forward
3305 "^[ \t]*:END:.*\n?" nil 'move)
3306 (point))))
3307 (unless (member 'planning keep)
3308 (goto-char (point-min))
3309 (while (re-search-forward kwd-time-re nil t)
3310 (replace-match "")))
3311 (goto-char (point-min))
3312 (when org-agenda-entry-text-exclude-regexps
3313 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3314 (while (setq re (pop re-list))
3315 (goto-char (point-min))
3316 (while (re-search-forward re nil t)
3317 (replace-match "")))))
3318 (goto-char (point-max))
3319 (skip-chars-backward " \t\n")
3320 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3322 ;; find and remove min common indentation
3323 (goto-char (point-min))
3324 (untabify (point-min) (point-max))
3325 (setq ind (org-get-indentation))
3326 (while (not (eobp))
3327 (unless (looking-at "[ \t]*$")
3328 (setq ind (min ind (org-get-indentation))))
3329 (beginning-of-line 2))
3330 (goto-char (point-min))
3331 (while (not (eobp))
3332 (unless (looking-at "[ \t]*$")
3333 (move-to-column ind)
3334 (delete-region (point-at-bol) (point)))
3335 (beginning-of-line 2))
3337 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3339 (goto-char (point-min))
3340 (when indent
3341 (while (and (not (eobp)) (re-search-forward "^" nil t))
3342 (replace-match indent t t)))
3343 (goto-char (point-min))
3344 (while (looking-at "[ \t]*\n") (replace-match ""))
3345 (goto-char (point-max))
3346 (when (> (org-current-line)
3347 n-lines)
3348 (org-goto-line (1+ n-lines))
3349 (backward-char 1))
3350 (setq txt (buffer-substring (point-min) (point)))))))))
3351 txt))
3353 (defun org-agenda-collect-markers ()
3354 "Collect the markers pointing to entries in the agenda buffer."
3355 (let (m markers)
3356 (save-excursion
3357 (goto-char (point-min))
3358 (while (not (eobp))
3359 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3360 (org-get-at-bol 'org-marker)))
3361 (push m markers))
3362 (beginning-of-line 2)))
3363 (nreverse markers)))
3365 (defun org-create-marker-find-array (marker-list)
3366 "Create a alist of files names with all marker positions in that file."
3367 (let (f tbl m a p)
3368 (while (setq m (pop marker-list))
3369 (setq p (marker-position m)
3370 f (buffer-file-name (or (buffer-base-buffer
3371 (marker-buffer m))
3372 (marker-buffer m))))
3373 (if (setq a (assoc f tbl))
3374 (push (marker-position m) (cdr a))
3375 (push (list f p) tbl)))
3376 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3377 tbl)))
3379 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3380 (defun org-check-agenda-marker-table ()
3381 "Check of the current entry is on the marker list."
3382 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3384 (and (setq a (assoc file org-agenda-marker-table))
3385 (save-match-data
3386 (save-excursion
3387 (org-back-to-heading t)
3388 (member (point) (cdr a)))))))
3390 (defun org-check-for-org-mode ()
3391 "Make sure current buffer is in org-mode. Error if not."
3392 (or (derived-mode-p 'org-mode)
3393 (error "Cannot execute org-mode agenda command on buffer in %s"
3394 major-mode)))
3396 ;;; Agenda prepare and finalize
3398 (defvar org-agenda-multi nil) ; dynamically scoped
3399 (defvar org-agenda-pre-window-conf nil)
3400 (defvar org-agenda-columns-active nil)
3401 (defvar org-agenda-name nil)
3402 (defvar org-agenda-tag-filter nil)
3403 (defvar org-agenda-category-filter nil)
3404 (defvar org-agenda-top-category-filter nil)
3405 (defvar org-agenda-tag-filter-while-redo nil)
3406 (defvar org-agenda-tag-filter-preset nil
3407 "A preset of the tags filter used for secondary agenda filtering.
3408 This must be a list of strings, each string must be a single tag preceded
3409 by \"+\" or \"-\".
3410 This variable should not be set directly, but agenda custom commands can
3411 bind it in the options section. The preset filter is a global property of
3412 the entire agenda view. In a block agenda, it will not work reliably to
3413 define a filter for one of the individual blocks. You need to set it in
3414 the global options and expect it to be applied to the entire view.")
3416 (defvar org-agenda-category-filter-preset nil
3417 "A preset of the category filter used for secondary agenda filtering.
3418 This must be a list of strings, each string must be a single category
3419 preceded by \"+\" or \"-\".
3420 This variable should not be set directly, but agenda custom commands can
3421 bind it in the options section. The preset filter is a global property of
3422 the entire agenda view. In a block agenda, it will not work reliably to
3423 define a filter for one of the individual blocks. You need to set it in
3424 the global options and expect it to be applied to the entire view.")
3427 (defun org-agenda-use-sticky-p ()
3428 "Return non-nil if an agenda buffer named
3429 `org-agenda-buffer-name' exists and should be shown instead of
3430 generating a new one."
3431 (and
3432 ;; turned off by user
3433 org-agenda-sticky
3434 ;; For multi-agenda buffer already exists
3435 (not org-agenda-multi)
3436 ;; buffer found
3437 (get-buffer org-agenda-buffer-name)
3438 ;; C-u parameter is same as last call
3439 (with-current-buffer (get-buffer org-agenda-buffer-name)
3440 (and
3441 (equal current-prefix-arg
3442 org-agenda-last-prefix-arg)
3443 ;; In case user turned stickiness on, while having existing
3444 ;; Agenda buffer active, don't reuse that buffer, because it
3445 ;; does not have org variables local
3446 org-agenda-this-buffer-is-sticky))))
3448 (defun org-agenda-prepare-window (abuf)
3449 "Setup agenda buffer in the window."
3450 (let* ((awin (get-buffer-window abuf))
3451 wconf)
3452 (cond
3453 ((equal (current-buffer) abuf) nil)
3454 (awin (select-window awin))
3455 ((not (setq wconf (current-window-configuration))))
3456 ((equal org-agenda-window-setup 'current-window)
3457 (org-pop-to-buffer-same-window abuf))
3458 ((equal org-agenda-window-setup 'other-window)
3459 (org-switch-to-buffer-other-window abuf))
3460 ((equal org-agenda-window-setup 'other-frame)
3461 (switch-to-buffer-other-frame abuf))
3462 ((equal org-agenda-window-setup 'reorganize-frame)
3463 (delete-other-windows)
3464 (org-switch-to-buffer-other-window abuf)))
3465 ;; additional test in case agenda is invoked from within agenda
3466 ;; buffer via elisp link
3467 (unless (equal (current-buffer) abuf)
3468 (org-pop-to-buffer-same-window abuf))
3469 (setq org-agenda-pre-window-conf
3470 (or org-agenda-pre-window-conf wconf))))
3472 (defun org-agenda-prepare (&optional name)
3473 (if (org-agenda-use-sticky-p)
3474 (progn
3475 ;; Popup existing buffer
3476 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3477 (message "Sticky Agenda buffer, use `r' to refresh")
3478 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3479 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3480 (setq org-todo-keywords-for-agenda nil)
3481 (setq org-drawers-for-agenda nil)
3482 (unless org-agenda-persistent-filter
3483 (setq org-agenda-tag-filter nil
3484 org-agenda-category-filter nil))
3485 (put 'org-agenda-tag-filter :preset-filter
3486 org-agenda-tag-filter-preset)
3487 (put 'org-agenda-category-filter :preset-filter
3488 org-agenda-category-filter-preset)
3489 (if org-agenda-multi
3490 (progn
3491 (setq buffer-read-only nil)
3492 (goto-char (point-max))
3493 (unless (or (bobp) org-agenda-compact-blocks
3494 (not org-agenda-block-separator))
3495 (insert "\n"
3496 (if (stringp org-agenda-block-separator)
3497 org-agenda-block-separator
3498 (make-string (window-width) org-agenda-block-separator))
3499 "\n"))
3500 (narrow-to-region (point) (point-max)))
3501 (setq org-done-keywords-for-agenda nil)
3503 ;; Setting any org variables that are in org-agenda-local-vars
3504 ;; list need to be done after the prepare call
3505 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3506 (setq buffer-read-only nil)
3507 (org-agenda-reset-markers)
3508 (let ((inhibit-read-only t)) (erase-buffer))
3509 (org-agenda-mode)
3510 (setq org-agenda-buffer (current-buffer))
3511 (setq org-agenda-contributing-files nil)
3512 (setq org-agenda-columns-active nil)
3513 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3514 (setq org-todo-keywords-for-agenda
3515 (org-uniquify org-todo-keywords-for-agenda))
3516 (setq org-done-keywords-for-agenda
3517 (org-uniquify org-done-keywords-for-agenda))
3518 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3519 (setq org-agenda-last-prefix-arg current-prefix-arg)
3520 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3521 (and name (not org-agenda-name)
3522 (org-set-local 'org-agenda-name name)))
3523 (setq buffer-read-only nil)))
3525 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3526 (defun org-agenda-finalize ()
3527 "Finishing touch for the agenda buffer, called just before displaying it."
3528 (unless org-agenda-multi
3529 (save-excursion
3530 (let ((inhibit-read-only t))
3531 (goto-char (point-min))
3532 (while (org-activate-bracket-links (point-max))
3533 (add-text-properties (match-beginning 0) (match-end 0)
3534 '(face org-link)))
3535 (org-agenda-align-tags)
3536 (unless org-agenda-with-colors
3537 (remove-text-properties (point-min) (point-max) '(face nil))))
3538 (if (and (boundp 'org-agenda-overriding-columns-format)
3539 org-agenda-overriding-columns-format)
3540 (org-set-local 'org-agenda-overriding-columns-format
3541 org-agenda-overriding-columns-format))
3542 (if (and (boundp 'org-agenda-view-columns-initially)
3543 org-agenda-view-columns-initially)
3544 (org-agenda-columns))
3545 (when org-agenda-fontify-priorities
3546 (org-agenda-fontify-priorities))
3547 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3548 (org-agenda-dim-blocked-tasks))
3549 (org-agenda-mark-clocking-task)
3550 (when org-agenda-entry-text-mode
3551 (org-agenda-entry-text-hide)
3552 (org-agenda-entry-text-show))
3553 (if (functionp 'org-habit-insert-consistency-graphs)
3554 (org-habit-insert-consistency-graphs))
3555 (let ((inhibit-read-only t))
3556 (run-hooks 'org-agenda-finalize-hook))
3557 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3558 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3559 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3560 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3561 (org-agenda-filter-apply org-agenda-category-filter 'category))
3562 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3564 (defun org-agenda-mark-clocking-task ()
3565 "Mark the current clock entry in the agenda if it is present."
3566 (mapc (lambda (o)
3567 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3568 (delete-overlay o)))
3569 (overlays-in (point-min) (point-max)))
3570 (when (marker-buffer org-clock-hd-marker)
3571 (save-excursion
3572 (goto-char (point-min))
3573 (let (s ov)
3574 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3575 (goto-char s)
3576 (when (equal (org-get-at-bol 'org-hd-marker)
3577 org-clock-hd-marker)
3578 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3579 (overlay-put ov 'type 'org-agenda-clocking)
3580 (overlay-put ov 'face 'org-agenda-clocking)
3581 (overlay-put ov 'help-echo
3582 "The clock is running in this item")))))))
3584 (defun org-agenda-fontify-priorities ()
3585 "Make highest priority lines bold, and lowest italic."
3586 (interactive)
3587 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3588 (delete-overlay o)))
3589 (overlays-in (point-min) (point-max)))
3590 (save-excursion
3591 (let ((inhibit-read-only t)
3592 b e p ov h l)
3593 (goto-char (point-min))
3594 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3595 (setq h (or (get-char-property (point) 'org-highest-priority)
3596 org-highest-priority)
3597 l (or (get-char-property (point) 'org-lowest-priority)
3598 org-lowest-priority)
3599 p (string-to-char (match-string 1))
3600 b (match-beginning 0)
3601 e (if (eq org-agenda-fontify-priorities 'cookies)
3602 (match-end 0)
3603 (point-at-eol))
3604 ov (make-overlay b e))
3605 (overlay-put
3606 ov 'face
3607 (cond ((org-face-from-face-or-color
3608 'priority nil
3609 (cdr (assoc p org-priority-faces))))
3610 ((and (listp org-agenda-fontify-priorities)
3611 (org-face-from-face-or-color
3612 'priority nil
3613 (cdr (assoc p org-agenda-fontify-priorities)))))
3614 ((equal p l) 'italic)
3615 ((equal p h) 'bold)))
3616 (overlay-put ov 'org-type 'org-priority)))))
3618 (defun org-agenda-dim-blocked-tasks ()
3619 "Dim currently blocked TODO's in the agenda display."
3620 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3621 (delete-overlay o)))
3622 (overlays-in (point-min) (point-max)))
3623 (save-excursion
3624 (let ((inhibit-read-only t)
3625 (org-depend-tag-blocked nil)
3626 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3627 org-blocked-by-checkboxes
3628 invis1 b e p ov h l)
3629 (goto-char (point-min))
3630 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3631 (and pos (goto-char (1+ pos))))
3632 (setq org-blocked-by-checkboxes nil invis1 invis)
3633 (let ((marker (org-get-at-bol 'org-hd-marker)))
3634 (when (and marker
3635 (with-current-buffer (marker-buffer marker)
3636 (save-excursion (goto-char marker)
3637 (org-entry-blocked-p))))
3638 (if org-blocked-by-checkboxes (setq invis1 nil))
3639 (setq b (if invis1
3640 (max (point-min) (1- (point-at-bol)))
3641 (point-at-bol))
3642 e (point-at-eol)
3643 ov (make-overlay b e))
3644 (if invis1
3645 (overlay-put ov 'invisible t)
3646 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3647 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3649 (defvar org-agenda-skip-function nil
3650 "Function to be called at each match during agenda construction.
3651 If this function returns nil, the current match should not be skipped.
3652 Otherwise, the function must return a position from where the search
3653 should be continued.
3654 This may also be a Lisp form, it will be evaluated.
3655 Never set this variable using `setq' or so, because then it will apply
3656 to all future agenda commands. If you do want a global skipping condition,
3657 use the option `org-agenda-skip-function-global' instead.
3658 The correct usage for `org-agenda-skip-function' is to bind it with
3659 `let' to scope it dynamically into the agenda-constructing command.
3660 A good way to set it is through options in `org-agenda-custom-commands'.")
3662 (defun org-agenda-skip ()
3663 "Throw to `:skip' in places that should be skipped.
3664 Also moves point to the end of the skipped region, so that search can
3665 continue from there."
3666 (let ((p (point-at-bol)) to)
3667 (when (org-in-src-block-p) (throw :skip t))
3668 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3669 (get-text-property p :org-archived)
3670 (org-end-of-subtree t)
3671 (throw :skip t))
3672 (and org-agenda-skip-comment-trees
3673 (get-text-property p :org-comment)
3674 (org-end-of-subtree t)
3675 (throw :skip t))
3676 (if (equal (char-after p) ?#) (throw :skip t))
3677 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3678 (org-agenda-skip-eval org-agenda-skip-function)))
3679 (goto-char to)
3680 (throw :skip t))))
3682 (defun org-agenda-skip-eval (form)
3683 "If FORM is a function or a list, call (or eval) is and return result.
3684 `save-excursion' and `save-match-data' are wrapped around the call, so point
3685 and match data are returned to the previous state no matter what these
3686 functions do."
3687 (let (fp)
3688 (and form
3689 (or (setq fp (functionp form))
3690 (consp form))
3691 (save-excursion
3692 (save-match-data
3693 (if fp
3694 (funcall form)
3695 (eval form)))))))
3697 (defvar org-agenda-markers nil
3698 "List of all currently active markers created by `org-agenda'.")
3699 (defvar org-agenda-last-marker-time (org-float-time)
3700 "Creation time of the last agenda marker.")
3702 (defun org-agenda-new-marker (&optional pos)
3703 "Return a new agenda marker.
3704 Org-mode keeps a list of these markers and resets them when they are
3705 no longer in use."
3706 (let ((m (copy-marker (or pos (point)))))
3707 (setq org-agenda-last-marker-time (org-float-time))
3708 (if org-agenda-buffer
3709 (with-current-buffer org-agenda-buffer
3710 (push m org-agenda-markers))
3711 (push m org-agenda-markers))
3714 (defun org-agenda-reset-markers ()
3715 "Reset markers created by `org-agenda'."
3716 (while org-agenda-markers
3717 (move-marker (pop org-agenda-markers) nil)))
3719 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3720 "Save relative positions of markers in region.
3721 This check for agenda markers in all agenda buffers currently active."
3722 (dolist (buf (buffer-list))
3723 (with-current-buffer buf
3724 (when (eq major-mode 'org-agenda-mode)
3725 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3726 org-agenda-markers)))))
3728 ;;; Entry text mode
3730 (defun org-agenda-entry-text-show-here ()
3731 "Add some text from the entry as context to the current line."
3732 (let (m txt o)
3733 (setq m (org-get-at-bol 'org-hd-marker))
3734 (unless (marker-buffer m)
3735 (error "No marker points to an entry here"))
3736 (setq txt (concat "\n" (org-no-properties
3737 (org-agenda-get-some-entry-text
3738 m org-agenda-entry-text-maxlines " > "))))
3739 (when (string-match "\\S-" txt)
3740 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3741 (overlay-put o 'evaporate t)
3742 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3743 (overlay-put o 'after-string txt))))
3745 (defun org-agenda-entry-text-show ()
3746 "Add entry context for all agenda lines."
3747 (interactive)
3748 (save-excursion
3749 (goto-char (point-max))
3750 (beginning-of-line 1)
3751 (while (not (bobp))
3752 (when (org-get-at-bol 'org-hd-marker)
3753 (org-agenda-entry-text-show-here))
3754 (beginning-of-line 0))))
3756 (defun org-agenda-entry-text-hide ()
3757 "Remove any shown entry context."
3758 (delq nil
3759 (mapcar (lambda (o)
3760 (if (eq (overlay-get o 'org-overlay-type)
3761 'agenda-entry-content)
3762 (progn (delete-overlay o) t)))
3763 (overlays-in (point-min) (point-max)))))
3765 (defun org-agenda-get-day-face (date)
3766 "Return the face DATE should be displayed with."
3767 (or (and (functionp org-agenda-day-face-function)
3768 (funcall org-agenda-day-face-function date))
3769 (cond ((org-agenda-todayp date)
3770 'org-agenda-date-today)
3771 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3772 'org-agenda-date-weekend)
3773 (t 'org-agenda-date))))
3775 ;;; Agenda timeline
3777 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3779 (defun org-timeline (&optional dotodo)
3780 "Show a time-sorted view of the entries in the current org file.
3781 Only entries with a time stamp of today or later will be listed. With
3782 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3783 under the current date.
3784 If the buffer contains an active region, only check the region for
3785 dates."
3786 (interactive "P")
3787 (let* ((dopast t)
3788 (org-agenda-show-log-scoped org-agenda-show-log)
3789 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3790 (current-buffer))))
3791 (date (calendar-current-date))
3792 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3793 (end (if (org-region-active-p) (region-end) (point-max)))
3794 (day-numbers (org-get-all-dates
3795 beg end 'no-ranges
3796 t org-agenda-show-log-scoped ; always include today
3797 org-timeline-show-empty-dates))
3798 (org-deadline-warning-days 0)
3799 (org-agenda-only-exact-dates t)
3800 (today (org-today))
3801 (past t)
3802 args
3803 s e rtn d emptyp)
3804 (setq org-agenda-redo-command
3805 (list 'progn
3806 (list 'org-switch-to-buffer-other-window (current-buffer))
3807 (list 'org-timeline (list 'quote dotodo))))
3808 (if (not dopast)
3809 ;; Remove past dates from the list of dates.
3810 (setq day-numbers (delq nil (mapcar (lambda(x)
3811 (if (>= x today) x nil))
3812 day-numbers))))
3813 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3814 (org-compile-prefix-format 'timeline)
3815 (org-set-sorting-strategy 'timeline)
3816 (if org-agenda-show-log-scoped (push :closed args))
3817 (push :timestamp args)
3818 (push :deadline args)
3819 (push :scheduled args)
3820 (push :sexp args)
3821 (if dotodo (push :todo args))
3822 (insert "Timeline of file " entry "\n")
3823 (add-text-properties (point-min) (point)
3824 (list 'face 'org-agenda-structure))
3825 (org-agenda-mark-header-line (point-min))
3826 (while (setq d (pop day-numbers))
3827 (if (and (listp d) (eq (car d) :omitted))
3828 (progn
3829 (setq s (point))
3830 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3831 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3832 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3833 (if (and (>= d today)
3834 dopast
3835 past)
3836 (progn
3837 (setq past nil)
3838 (insert (make-string 79 ?-) "\n")))
3839 (setq date (calendar-gregorian-from-absolute d))
3840 (setq s (point))
3841 (setq rtn (and (not emptyp)
3842 (apply 'org-agenda-get-day-entries entry
3843 date args)))
3844 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3845 (progn
3846 (insert
3847 (if (stringp org-agenda-format-date)
3848 (format-time-string org-agenda-format-date
3849 (org-time-from-absolute date))
3850 (funcall org-agenda-format-date date))
3851 "\n")
3852 (put-text-property s (1- (point)) 'face
3853 (org-agenda-get-day-face date))
3854 (put-text-property s (1- (point)) 'org-date-line t)
3855 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3856 (if (equal d today)
3857 (put-text-property s (1- (point)) 'org-today t))
3858 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3859 (put-text-property s (1- (point)) 'day d)))))
3860 (goto-char (point-min))
3861 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3862 (point-min)))
3863 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3864 (org-agenda-finalize)
3865 (setq buffer-read-only t)))
3867 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3868 "Return a list of all relevant day numbers from BEG to END buffer positions.
3869 If NO-RANGES is non-nil, include only the start and end dates of a range,
3870 not every single day in the range. If FORCE-TODAY is non-nil, make
3871 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3872 inactive time stamps (those in square brackets) are included.
3873 When EMPTY is non-nil, also include days without any entries."
3874 (let ((re (concat
3875 (if pre-re pre-re "")
3876 (if inactive org-ts-regexp-both org-ts-regexp)))
3877 dates dates1 date day day1 day2 ts1 ts2 pos)
3878 (if force-today
3879 (setq dates (list (org-today))))
3880 (save-excursion
3881 (goto-char beg)
3882 (while (re-search-forward re end t)
3883 (setq day (time-to-days (org-time-string-to-time
3884 (substring (match-string 1) 0 10)
3885 (current-buffer) (match-beginning 0))))
3886 (or (memq day dates) (push day dates)))
3887 (unless no-ranges
3888 (goto-char beg)
3889 (while (re-search-forward org-tr-regexp end t)
3890 (setq pos (match-beginning 0))
3891 (setq ts1 (substring (match-string 1) 0 10)
3892 ts2 (substring (match-string 2) 0 10)
3893 day1 (time-to-days (org-time-string-to-time
3894 ts1 (current-buffer) pos))
3895 day2 (time-to-days (org-time-string-to-time
3896 ts2 (current-buffer) pos)))
3897 (while (< (setq day1 (1+ day1)) day2)
3898 (or (memq day1 dates) (push day1 dates)))))
3899 (setq dates (sort dates '<))
3900 (when empty
3901 (while (setq day (pop dates))
3902 (setq day2 (car dates))
3903 (push day dates1)
3904 (when (and day2 empty)
3905 (if (or (eq empty t)
3906 (and (numberp empty) (<= (- day2 day) empty)))
3907 (while (< (setq day (1+ day)) day2)
3908 (push (list day) dates1))
3909 (push (cons :omitted (- day2 day)) dates1))))
3910 (setq dates (nreverse dates1)))
3911 dates)))
3913 ;;; Agenda Daily/Weekly
3915 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3916 "Start day for the agenda view.
3917 Custom commands can set this variable in the options section.")
3918 (defvar org-starting-day nil) ; local variable in the agenda buffer
3919 (defvar org-arg-loc nil) ; local variable
3921 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3922 "List of types searched for when creating the daily/weekly agenda.
3923 This variable is a list of symbols that controls the types of
3924 items that appear in the daily/weekly agenda. Allowed symbols in this
3925 list are are
3927 :timestamp List items containing a date stamp or date range matching
3928 the selected date. This includes sexp entries in
3929 angular brackets.
3931 :sexp List entries resulting from plain diary-like sexps.
3933 :deadline List deadline due on that date. When the date is today,
3934 also list any deadlines past due, or due within
3935 `org-deadline-warning-days'. `:deadline' must appear before
3936 `:scheduled' if the setting of
3937 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3938 any effect.
3940 :scheduled List all items which are scheduled for the given date.
3941 The diary for *today* also contains items which were
3942 scheduled earlier and are not yet marked DONE.
3944 By default, all four types are turned on.
3946 Never set this variable globally using `setq', because then it
3947 will apply to all future agenda commands. Instead, bind it with
3948 `let' to scope it dynamically into the agenda-constructing
3949 command. A good way to set it is through options in
3950 `org-agenda-custom-commands'. For a more flexible (though
3951 somewhat less efficient) way of determining what is included in
3952 the daily/weekly agenda, see `org-agenda-skip-function'.")
3954 (defvar org-agenda-buffer-tmp-name nil)
3955 ;;;###autoload
3956 (defun org-agenda-list (&optional arg start-day span)
3957 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3958 The view will be for the current day or week, but from the overview buffer
3959 you will be able to go to other days/weeks.
3961 With a numeric prefix argument in an interactive call, the agenda will
3962 span ARG days. Lisp programs should instead specify SPAN to change
3963 the number of days. SPAN defaults to `org-agenda-span'.
3965 START-DAY defaults to TODAY, or to the most recent match for the weekday
3966 given in `org-agenda-start-on-weekday'."
3967 (interactive "P")
3968 (if org-agenda-overriding-arguments
3969 (setq arg (car org-agenda-overriding-arguments)
3970 start-day (nth 1 org-agenda-overriding-arguments)
3971 span (nth 2 org-agenda-overriding-arguments)))
3972 (if (and (integerp arg) (> arg 0))
3973 (setq span arg arg nil))
3974 (catch 'exit
3975 (setq org-agenda-buffer-name
3976 (or org-agenda-buffer-tmp-name
3977 (if org-agenda-sticky
3978 (cond ((and org-keys (stringp org-match))
3979 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3980 (org-keys
3981 (format "*Org Agenda(%s)*" org-keys))
3982 (t "*Org Agenda(a)*")))
3983 org-agenda-buffer-name))
3984 (org-agenda-prepare "Day/Week")
3985 (setq start-day (or start-day org-agenda-start-day))
3986 (if (stringp start-day)
3987 ;; Convert to an absolute day number
3988 (setq start-day (time-to-days (org-read-date nil t start-day))))
3989 (org-compile-prefix-format 'agenda)
3990 (org-set-sorting-strategy 'agenda)
3991 (let* ((span (org-agenda-ndays-to-span
3992 (or span org-agenda-ndays org-agenda-span)))
3993 (today (org-today))
3994 (sd (or start-day today))
3995 (ndays (org-agenda-span-to-ndays span sd))
3996 (org-agenda-start-on-weekday
3997 (if (eq ndays 7)
3998 org-agenda-start-on-weekday))
3999 (thefiles (org-agenda-files nil 'ifmode))
4000 (files thefiles)
4001 (start (if (or (null org-agenda-start-on-weekday)
4002 (< ndays 7))
4004 (let* ((nt (calendar-day-of-week
4005 (calendar-gregorian-from-absolute sd)))
4006 (n1 org-agenda-start-on-weekday)
4007 (d (- nt n1)))
4008 (- sd (+ (if (< d 0) 7 0) d)))))
4009 (day-numbers (list start))
4010 (day-cnt 0)
4011 (inhibit-redisplay (not debug-on-error))
4012 (org-agenda-show-log-scoped org-agenda-show-log)
4013 s e rtn rtnall file date d start-pos end-pos todayp
4014 clocktable-start clocktable-end filter)
4015 (setq org-agenda-redo-command
4016 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4017 (dotimes (n (1- ndays))
4018 (push (1+ (car day-numbers)) day-numbers))
4019 (setq day-numbers (nreverse day-numbers))
4020 (setq clocktable-start (car day-numbers)
4021 clocktable-end (1+ (or (org-last day-numbers) 0)))
4022 (org-set-local 'org-starting-day (car day-numbers))
4023 (org-set-local 'org-arg-loc arg)
4024 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4025 (unless org-agenda-compact-blocks
4026 (let* ((d1 (car day-numbers))
4027 (d2 (org-last day-numbers))
4028 (w1 (org-days-to-iso-week d1))
4029 (w2 (org-days-to-iso-week d2)))
4030 (setq s (point))
4031 (if org-agenda-overriding-header
4032 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4033 nil 'face 'org-agenda-structure) "\n")
4034 (insert (org-agenda-span-name span)
4035 "-agenda"
4036 (if (< (- d2 d1) 350)
4037 (if (= w1 w2)
4038 (format " (W%02d)" w1)
4039 (format " (W%02d-W%02d)" w1 w2))
4041 ":\n")))
4042 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4043 'org-date-line t))
4044 (org-agenda-mark-header-line s))
4045 (while (setq d (pop day-numbers))
4046 (setq date (calendar-gregorian-from-absolute d)
4047 s (point))
4048 (if (or (setq todayp (= d today))
4049 (and (not start-pos) (= d sd)))
4050 (setq start-pos (point))
4051 (if (and start-pos (not end-pos))
4052 (setq end-pos (point))))
4053 (setq files thefiles
4054 rtnall nil)
4055 (while (setq file (pop files))
4056 (catch 'nextfile
4057 (org-check-agenda-file file)
4058 (let ((org-agenda-entry-types org-agenda-entry-types))
4059 (unless org-agenda-include-deadlines
4060 (setq org-agenda-entry-types
4061 (delq :deadline org-agenda-entry-types)))
4062 (cond
4063 ((memq org-agenda-show-log-scoped '(only clockcheck))
4064 (setq rtn (org-agenda-get-day-entries
4065 file date :closed)))
4066 (org-agenda-show-log-scoped
4067 (setq rtn (apply 'org-agenda-get-day-entries
4068 file date
4069 (append '(:closed) org-agenda-entry-types))))
4071 (setq rtn (apply 'org-agenda-get-day-entries
4072 file date
4073 org-agenda-entry-types)))))
4074 (setq rtnall (append rtnall rtn)))) ;; all entries
4075 (if org-agenda-include-diary
4076 (let ((org-agenda-search-headline-for-time t))
4077 (require 'diary-lib)
4078 (setq rtn (org-get-entries-from-diary date))
4079 (setq rtnall (append rtnall rtn))))
4080 (if (or rtnall org-agenda-show-all-dates)
4081 (progn
4082 (setq day-cnt (1+ day-cnt))
4083 (insert
4084 (if (stringp org-agenda-format-date)
4085 (format-time-string org-agenda-format-date
4086 (org-time-from-absolute date))
4087 (funcall org-agenda-format-date date))
4088 "\n")
4089 (put-text-property s (1- (point)) 'face
4090 (org-agenda-get-day-face date))
4091 (put-text-property s (1- (point)) 'org-date-line t)
4092 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4093 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4094 (when todayp
4095 (put-text-property s (1- (point)) 'org-today t))
4096 (setq rtnall
4097 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4098 (if rtnall (insert ;; all entries
4099 (org-agenda-finalize-entries rtnall)
4100 "\n"))
4101 (put-text-property s (1- (point)) 'day d)
4102 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4103 (when (and org-agenda-clockreport-mode clocktable-start)
4104 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4105 ;; the above line is to ensure the restricted range!
4106 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4107 tbl)
4108 (setq p (org-plist-delete p :block))
4109 (setq p (plist-put p :tstart clocktable-start))
4110 (setq p (plist-put p :tend clocktable-end))
4111 (setq p (plist-put p :scope 'agenda))
4112 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4113 (setq filter (or org-agenda-tag-filter-while-redo
4114 (get 'org-agenda-tag-filter :preset-filter))))
4115 (setq p (plist-put p :tags (mapconcat (lambda (x)
4116 (if (string-match "[<>=]" x)
4119 filter ""))))
4120 (setq tbl (apply 'org-clock-get-clocktable p))
4121 (insert tbl)))
4122 (goto-char (point-min))
4123 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4124 (unless (and (pos-visible-in-window-p (point-min))
4125 (pos-visible-in-window-p (point-max)))
4126 (goto-char (1- (point-max)))
4127 (recenter -1)
4128 (if (not (pos-visible-in-window-p (or start-pos 1)))
4129 (progn
4130 (goto-char (or start-pos 1))
4131 (recenter 1))))
4132 (goto-char (or start-pos 1))
4133 (add-text-properties (point-min) (point-max)
4134 `(org-agenda-type agenda
4135 org-last-args (,arg ,start-day ,span)
4136 org-redo-cmd ,org-agenda-redo-command
4137 org-serie-cmd ,org-cmd))
4138 (if (eq org-agenda-show-log-scoped 'clockcheck)
4139 (org-agenda-show-clocking-issues))
4140 (org-agenda-finalize)
4141 (setq buffer-read-only t)
4142 (message ""))))
4144 (autoload 'org-agenda-list "org-agenda" "\
4145 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4146 The view will be for the current day or week, but from the overview buffer
4147 you will be able to go to other days/weeks.
4149 With a numeric prefix argument in an interactive call, the agenda will
4150 span ARG days. Lisp programs should instead specify SPAN to change
4151 the number of days. SPAN defaults to `org-agenda-span'.
4153 START-DAY defaults to TODAY, or to the most recent match for the weekday
4154 given in `org-agenda-start-on-weekday'.
4156 \(fn &optional ARG START-DAY SPAN)" t nil)
4158 (defun org-agenda-ndays-to-span (n)
4159 "Return a span symbol for a span of N days, or N if none matches."
4160 (cond ((symbolp n) n)
4161 ((= n 1) 'day)
4162 ((= n 7) 'week)
4163 (t n)))
4165 (defun org-agenda-span-to-ndays (span &optional start-day)
4166 "Return ndays from SPAN, possibly starting at START-DAY."
4167 (cond ((numberp span) span)
4168 ((eq span 'day) 1)
4169 ((eq span 'week) 7)
4170 ((eq span 'month)
4171 (let ((date (calendar-gregorian-from-absolute start-day)))
4172 (calendar-last-day-of-month (car date) (caddr date))))
4173 ((eq span 'year)
4174 (let ((date (calendar-gregorian-from-absolute start-day)))
4175 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4177 (defun org-agenda-span-name (span)
4178 "Return a SPAN name."
4179 (if (null span)
4181 (if (symbolp span)
4182 (capitalize (symbol-name span))
4183 (format "%d days" span))))
4185 ;;; Agenda word search
4187 (defvar org-agenda-search-history nil)
4189 (defvar org-search-syntax-table nil
4190 "Special syntax table for org-mode search.
4191 In this table, we have single quotes not as word constituents, to
4192 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4194 (defvar org-mode-syntax-table) ; From org.el
4195 (defun org-search-syntax-table ()
4196 (unless org-search-syntax-table
4197 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4198 (modify-syntax-entry ?' "." org-search-syntax-table)
4199 (modify-syntax-entry ?` "." org-search-syntax-table))
4200 org-search-syntax-table)
4202 (defvar org-agenda-last-search-view-search-was-boolean nil)
4204 ;;;###autoload
4205 (defun org-search-view (&optional todo-only string edit-at)
4206 "Show all entries that contain a phrase or words or regular expressions.
4208 With optional prefix argument TODO-ONLY, only consider entries that are
4209 TODO entries. The argument STRING can be used to pass a default search
4210 string into this function. If EDIT-AT is non-nil, it means that the
4211 user should get a chance to edit this string, with cursor at position
4212 EDIT-AT.
4214 The search string can be viewed either as a phrase that should be found as
4215 is, or it can be broken into a number of snippets, each of which must match
4216 in a Boolean way to select an entry. The default depends on the variable
4217 `org-agenda-search-view-always-boolean'.
4218 Even if this is turned off (the default) you can always switch to
4219 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4221 The default is a direct search of the whole phrase, where each space in
4222 the search string can expand to an arbitrary amount of whitespace,
4223 including newlines.
4225 If using a Boolean search, the search string is split on whitespace and
4226 each snippet is searched separately, with logical AND to select an entry.
4227 Words prefixed with a minus must *not* occur in the entry. Words without
4228 a prefix or prefixed with a plus must occur in the entry. Matching is
4229 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4230 match whole words, not parts of a word) if
4231 `org-agenda-search-view-force-full-words' is set (default is nil).
4233 Boolean search snippets enclosed by curly braces are interpreted as
4234 regular expressions that must or (when preceded with \"-\") must not
4235 match in the entry. Snippets enclosed into double quotes will be taken
4236 as a whole, to include whitespace.
4238 - If the search string starts with an asterisk, search only in headlines.
4239 - If (possibly after the leading star) the search string starts with an
4240 exclamation mark, this also means to look at TODO entries only, an effect
4241 that can also be achieved with a prefix argument.
4242 - If (possibly after star and exclamation mark) the search string starts
4243 with a colon, this will mean that the (non-regexp) snippets of the
4244 Boolean search must match as full words.
4246 This command searches the agenda files, and in addition the files listed
4247 in `org-agenda-text-search-extra-files'."
4248 (interactive "P")
4249 (if org-agenda-overriding-arguments
4250 (setq todo-only (car org-agenda-overriding-arguments)
4251 string (nth 1 org-agenda-overriding-arguments)
4252 edit-at (nth 2 org-agenda-overriding-arguments)))
4253 (let* ((props (list 'face nil
4254 'done-face 'org-agenda-done
4255 'org-not-done-regexp org-not-done-regexp
4256 'org-todo-regexp org-todo-regexp
4257 'org-complex-heading-regexp org-complex-heading-regexp
4258 'mouse-face 'highlight
4259 'help-echo (format "mouse-2 or RET jump to location")))
4260 (full-words org-agenda-search-view-force-full-words)
4261 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4262 regexp rtn rtnall files file pos
4263 marker category category-pos level tags c neg re boolean
4264 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4265 (unless (and (not edit-at)
4266 (stringp string)
4267 (string-match "\\S-" string))
4268 (setq string (read-string
4269 (if org-agenda-search-view-always-boolean
4270 "[+-]Word/{Regexp} ...: "
4271 "Phrase or [+-]Word/{Regexp} ...: ")
4272 (cond
4273 ((integerp edit-at) (cons string edit-at))
4274 (edit-at string))
4275 'org-agenda-search-history)))
4276 (catch 'exit
4277 (if org-agenda-sticky
4278 (setq org-agenda-buffer-name
4279 (if (stringp string)
4280 (format "*Org Agenda(%s:%s)*"
4281 (or org-keys (or (and todo-only "S") "s")) string)
4282 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4283 (org-agenda-prepare "SEARCH")
4284 (org-compile-prefix-format 'search)
4285 (org-set-sorting-strategy 'search)
4286 (setq org-agenda-redo-command
4287 (list 'org-search-view (if todo-only t nil)
4288 (list 'if 'current-prefix-arg nil string)))
4289 (setq org-agenda-query-string string)
4290 (if (equal (string-to-char string) ?*)
4291 (setq hdl-only t
4292 words (substring string 1))
4293 (setq words string))
4294 (when (equal (string-to-char words) ?!)
4295 (setq todo-only t
4296 words (substring words 1)))
4297 (when (equal (string-to-char words) ?:)
4298 (setq full-words t
4299 words (substring words 1)))
4300 (if (or org-agenda-search-view-always-boolean
4301 (member (string-to-char words) '(?- ?+ ?\{)))
4302 (setq boolean t))
4303 (setq words (org-split-string words))
4304 (let (www w)
4305 (while (setq w (pop words))
4306 (while (and (string-match "\\\\\\'" w) words)
4307 (setq w (concat (substring w 0 -1) " " (pop words))))
4308 (push w www))
4309 (setq words (nreverse www) www nil)
4310 (while (setq w (pop words))
4311 (when (and (string-match "\\`[-+]?{" w)
4312 (not (string-match "}\\'" w)))
4313 (while (and words (not (string-match "}\\'" (car words))))
4314 (setq w (concat w " " (pop words))))
4315 (setq w (concat w " " (pop words))))
4316 (push w www))
4317 (setq words (nreverse www)))
4318 (setq org-agenda-last-search-view-search-was-boolean boolean)
4319 (when boolean
4320 (let (wds w)
4321 (while (setq w (pop words))
4322 (if (or (equal (substring w 0 1) "\"")
4323 (and (> (length w) 1)
4324 (member (substring w 0 1) '("+" "-"))
4325 (equal (substring w 1 2) "\"")))
4326 (while (and words (not (equal (substring w -1) "\"")))
4327 (setq w (concat w " " (pop words)))))
4328 (and (string-match "\\`\\([-+]?\\)\"" w)
4329 (setq w (replace-match "\\1" nil nil w)))
4330 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4331 (push w wds))
4332 (setq words (nreverse wds))))
4333 (if boolean
4334 (mapc (lambda (w)
4335 (setq c (string-to-char w))
4336 (if (equal c ?-)
4337 (setq neg t w (substring w 1))
4338 (if (equal c ?+)
4339 (setq neg nil w (substring w 1))
4340 (setq neg nil)))
4341 (if (string-match "\\`{.*}\\'" w)
4342 (setq re (substring w 1 -1))
4343 (if full-words
4344 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4345 (setq re (regexp-quote (downcase w)))))
4346 (if neg (push re regexps-) (push re regexps+)))
4347 words)
4348 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4349 regexps+))
4350 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4351 (if (not regexps+)
4352 (setq regexp org-outline-regexp-bol)
4353 (setq regexp (pop regexps+))
4354 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4355 regexp))))
4356 (setq files (org-agenda-files nil 'ifmode))
4357 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4358 (pop org-agenda-text-search-extra-files)
4359 (setq files (org-add-archive-files files)))
4360 (setq files (append files org-agenda-text-search-extra-files)
4361 rtnall nil)
4362 (while (setq file (pop files))
4363 (setq ee nil)
4364 (catch 'nextfile
4365 (org-check-agenda-file file)
4366 (setq buffer (if (file-exists-p file)
4367 (org-get-agenda-file-buffer file)
4368 (error "No such file %s" file)))
4369 (if (not buffer)
4370 ;; If file does not exist, make sure an error message is sent
4371 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4372 file))))
4373 (with-current-buffer buffer
4374 (with-syntax-table (org-search-syntax-table)
4375 (unless (derived-mode-p 'org-mode)
4376 (error "Agenda file %s is not in `org-mode'" file))
4377 (let ((case-fold-search t))
4378 (save-excursion
4379 (save-restriction
4380 (if org-agenda-restrict
4381 (narrow-to-region org-agenda-restrict-begin
4382 org-agenda-restrict-end)
4383 (widen))
4384 (goto-char (point-min))
4385 (unless (or (org-at-heading-p)
4386 (outline-next-heading))
4387 (throw 'nextfile t))
4388 (goto-char (max (point-min) (1- (point))))
4389 (while (re-search-forward regexp nil t)
4390 (org-back-to-heading t)
4391 (skip-chars-forward "* ")
4392 (setq beg (point-at-bol)
4393 beg1 (point)
4394 end (progn (outline-next-heading) (point)))
4395 (catch :skip
4396 (goto-char beg)
4397 (org-agenda-skip)
4398 (setq str (buffer-substring-no-properties
4399 (point-at-bol)
4400 (if hdl-only (point-at-eol) end)))
4401 (mapc (lambda (wr) (when (string-match wr str)
4402 (goto-char (1- end))
4403 (throw :skip t)))
4404 regexps-)
4405 (mapc (lambda (wr) (unless (string-match wr str)
4406 (goto-char (1- end))
4407 (throw :skip t)))
4408 (if todo-only
4409 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4410 regexps+)
4411 regexps+))
4412 (goto-char beg)
4413 (setq marker (org-agenda-new-marker (point))
4414 category (org-get-category)
4415 level (make-string (org-reduced-level (org-outline-level)) ? )
4416 category-pos (get-text-property (point) 'org-category-position)
4417 tags (org-get-tags-at (point))
4418 txt (org-agenda-format-item
4420 (buffer-substring-no-properties
4421 beg1 (point-at-eol))
4422 level category tags t))
4423 (org-add-props txt props
4424 'org-marker marker 'org-hd-marker marker
4425 'org-todo-regexp org-todo-regexp
4426 'level level
4427 'org-complex-heading-regexp org-complex-heading-regexp
4428 'priority 1000 'org-category category
4429 'org-category-position category-pos
4430 'type "search")
4431 (push txt ee)
4432 (goto-char (1- end))))))))))
4433 (setq rtn (nreverse ee))
4434 (setq rtnall (append rtnall rtn)))
4435 (if org-agenda-overriding-header
4436 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4437 nil 'face 'org-agenda-structure) "\n")
4438 (insert "Search words: ")
4439 (add-text-properties (point-min) (1- (point))
4440 (list 'face 'org-agenda-structure))
4441 (setq pos (point))
4442 (insert string "\n")
4443 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4444 (setq pos (point))
4445 (unless org-agenda-multi
4446 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4447 (add-text-properties pos (1- (point))
4448 (list 'face 'org-agenda-structure))))
4449 (org-agenda-mark-header-line (point-min))
4450 (when rtnall
4451 (insert (org-agenda-finalize-entries rtnall) "\n"))
4452 (goto-char (point-min))
4453 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4454 (add-text-properties (point-min) (point-max)
4455 `(org-agenda-type search
4456 org-last-args (,todo-only ,string ,edit-at)
4457 org-redo-cmd ,org-agenda-redo-command
4458 org-serie-cmd ,org-cmd))
4459 (org-agenda-finalize)
4460 (setq buffer-read-only t))))
4462 (autoload 'org-search-view "org-agenda" "\
4463 Show all entries that contain a phrase or words or regular expressions.
4465 With optional prefix argument TODO-ONLY, only consider entries that are
4466 TODO entries. The argument STRING can be used to pass a default search
4467 string into this function. If EDIT-AT is non-nil, it means that the
4468 user should get a chance to edit this string, with cursor at position
4469 EDIT-AT.
4471 The search string can be viewed either as a phrase that should be found as
4472 is, or it can be broken into a number of snippets, each of which must match
4473 in a Boolean way to select an entry. The default depends on the variable
4474 `org-agenda-search-view-always-boolean'.
4475 Even if this is turned off (the default) you can always switch to
4476 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4478 The default is a direct search of the whole phrase, where each space in
4479 the search string can expand to an arbitrary amount of whitespace,
4480 including newlines.
4482 If using a Boolean search, the search string is split on whitespace and
4483 each snippet is searched separately, with logical AND to select an entry.
4484 Words prefixed with a minus must *not* occur in the entry. Words without
4485 a prefix or prefixed with a plus must occur in the entry. Matching is
4486 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4487 match whole words, not parts of a word) if
4488 `org-agenda-search-view-force-full-words' is set (default is nil).
4490 Boolean search snippets enclosed by curly braces are interpreted as
4491 regular expressions that must or (when preceded with \"-\") must not
4492 match in the entry. Snippets enclosed into double quotes will be taken
4493 as a whole, to include whitespace.
4495 - If the search string starts with an asterisk, search only in headlines.
4496 - If (possibly after the leading star) the search string starts with an
4497 exclamation mark, this also means to look at TODO entries only, an effect
4498 that can also be achieved with a prefix argument.
4499 - If (possibly after star and exclamation mark) the search string starts
4500 with a colon, this will mean that the (non-regexp) snippets of the
4501 Boolean search must match as full words.
4503 This command searches the agenda files, and in addition the files listed
4504 in `org-agenda-text-search-extra-files'.
4506 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4508 ;;; Agenda TODO list
4510 (defvar org-select-this-todo-keyword nil)
4511 (defvar org-last-arg nil)
4513 ;;;###autoload
4514 (defun org-todo-list (&optional arg)
4515 "Show all (not done) TODO entries from all agenda file in a single list.
4516 The prefix arg can be used to select a specific TODO keyword and limit
4517 the list to these. When using \\[universal-argument], you will be prompted
4518 for a keyword. A numeric prefix directly selects the Nth keyword in
4519 `org-todo-keywords-1'."
4520 (interactive "P")
4521 (if org-agenda-overriding-arguments
4522 (setq arg org-agenda-overriding-arguments))
4523 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4524 (let* ((today (org-today))
4525 (date (calendar-gregorian-from-absolute today))
4526 (kwds org-todo-keywords-for-agenda)
4527 (completion-ignore-case t)
4528 (org-select-this-todo-keyword
4529 (if (stringp arg) arg
4530 (and arg (integerp arg) (> arg 0)
4531 (nth (1- arg) kwds))))
4532 rtn rtnall files file pos)
4533 (when (equal arg '(4))
4534 (setq org-select-this-todo-keyword
4535 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4536 (mapcar 'list kwds) nil nil)))
4537 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4538 (catch 'exit
4539 (if org-agenda-sticky
4540 (setq org-agenda-buffer-name
4541 (if (stringp org-select-this-todo-keyword)
4542 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4543 org-select-this-todo-keyword)
4544 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4545 (org-agenda-prepare "TODO")
4546 (org-compile-prefix-format 'todo)
4547 (org-set-sorting-strategy 'todo)
4548 (setq org-agenda-redo-command
4549 `(org-todo-list (or (and (numberp current-prefix-arg)
4550 current-prefix-arg)
4551 ,org-select-this-todo-keyword
4552 current-prefix-arg ,arg)))
4553 (setq files (org-agenda-files nil 'ifmode)
4554 rtnall nil)
4555 (while (setq file (pop files))
4556 (catch 'nextfile
4557 (org-check-agenda-file file)
4558 (setq rtn (org-agenda-get-day-entries file date :todo))
4559 (setq rtnall (append rtnall rtn))))
4560 (if org-agenda-overriding-header
4561 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4562 nil 'face 'org-agenda-structure) "\n")
4563 (insert "Global list of TODO items of type: ")
4564 (add-text-properties (point-min) (1- (point))
4565 (list 'face 'org-agenda-structure
4566 'short-heading
4567 (concat "ToDo: "
4568 (or org-select-this-todo-keyword "ALL"))))
4569 (org-agenda-mark-header-line (point-min))
4570 (setq pos (point))
4571 (insert (or org-select-this-todo-keyword "ALL") "\n")
4572 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4573 (setq pos (point))
4574 (unless org-agenda-multi
4575 (insert "Available with `N r': (0)[ALL]")
4576 (let ((n 0) s)
4577 (mapc (lambda (x)
4578 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4579 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4580 (insert "\n "))
4581 (insert " " s))
4582 kwds))
4583 (insert "\n"))
4584 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4585 (org-agenda-mark-header-line (point-min))
4586 (when rtnall
4587 (insert (org-agenda-finalize-entries rtnall) "\n"))
4588 (goto-char (point-min))
4589 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4590 (add-text-properties (point-min) (point-max)
4591 `(org-agenda-type todo
4592 org-last-args ,arg
4593 org-redo-cmd ,org-agenda-redo-command
4594 org-serie-cmd ,org-cmd))
4595 (org-agenda-finalize)
4596 (setq buffer-read-only t))))
4598 (autoload 'org-todo-list "org-agenda" "\
4599 Show all (not done) TODO entries from all agenda file in a single list.
4600 The prefix arg can be used to select a specific TODO keyword and limit
4601 the list to these. When using \\[universal-argument], you will be prompted
4602 for a keyword. A numeric prefix directly selects the Nth keyword in
4603 `org-todo-keywords-1'.
4605 \(fn &optional ARG)" t nil)
4607 ;;; Agenda tags match
4609 ;;;###autoload
4610 (defun org-tags-view (&optional todo-only match)
4611 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4612 The prefix arg TODO-ONLY limits the search to TODO entries."
4613 (interactive "P")
4614 (if org-agenda-overriding-arguments
4615 (setq todo-only (car org-agenda-overriding-arguments)
4616 match (nth 1 org-agenda-overriding-arguments)))
4617 (let* ((org-tags-match-list-sublevels
4618 org-tags-match-list-sublevels)
4619 (completion-ignore-case t)
4620 rtn rtnall files file pos matcher
4621 buffer)
4622 (when (and (stringp match) (not (string-match "\\S-" match)))
4623 (setq match nil))
4624 (setq matcher (org-make-tags-matcher match)
4625 match (car matcher) matcher (cdr matcher))
4626 (catch 'exit
4627 (if org-agenda-sticky
4628 (setq org-agenda-buffer-name
4629 (if (stringp match)
4630 (format "*Org Agenda(%s:%s)*"
4631 (or org-keys (or (and todo-only "M") "m")) match)
4632 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4633 (org-agenda-prepare (concat "TAGS " match))
4634 (org-compile-prefix-format 'tags)
4635 (org-set-sorting-strategy 'tags)
4636 (setq org-agenda-query-string match)
4637 (setq org-agenda-redo-command
4638 (list 'org-tags-view `(quote ,todo-only)
4639 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4640 (setq files (org-agenda-files nil 'ifmode)
4641 rtnall nil)
4642 (while (setq file (pop files))
4643 (catch 'nextfile
4644 (org-check-agenda-file file)
4645 (setq buffer (if (file-exists-p file)
4646 (org-get-agenda-file-buffer file)
4647 (error "No such file %s" file)))
4648 (if (not buffer)
4649 ;; If file does not exist, error message to agenda
4650 (setq rtn (list
4651 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4652 rtnall (append rtnall rtn))
4653 (with-current-buffer buffer
4654 (unless (derived-mode-p 'org-mode)
4655 (error "Agenda file %s is not in `org-mode'" file))
4656 (save-excursion
4657 (save-restriction
4658 (if org-agenda-restrict
4659 (narrow-to-region org-agenda-restrict-begin
4660 org-agenda-restrict-end)
4661 (widen))
4662 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4663 (setq rtnall (append rtnall rtn))))))))
4664 (if org-agenda-overriding-header
4665 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4666 nil 'face 'org-agenda-structure) "\n")
4667 (insert "Headlines with TAGS match: ")
4668 (add-text-properties (point-min) (1- (point))
4669 (list 'face 'org-agenda-structure
4670 'short-heading
4671 (concat "Match: " match)))
4672 (setq pos (point))
4673 (insert match "\n")
4674 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4675 (setq pos (point))
4676 (unless org-agenda-multi
4677 (insert "Press `C-u r' to search again with new search string\n"))
4678 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4679 (org-agenda-mark-header-line (point-min))
4680 (when rtnall
4681 (insert (org-agenda-finalize-entries rtnall) "\n"))
4682 (goto-char (point-min))
4683 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4684 (add-text-properties (point-min) (point-max)
4685 `(org-agenda-type tags
4686 org-last-args (,todo-only ,match)
4687 org-redo-cmd ,org-agenda-redo-command
4688 org-serie-cmd ,org-cmd))
4689 (org-agenda-finalize)
4690 (setq buffer-read-only t))))
4692 (autoload 'org-tags-view "org-agenda" "\
4693 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4694 The prefix arg TODO-ONLY limits the search to TODO entries.
4696 \(fn &optional TODO-ONLY MATCH)" t nil)
4698 ;;; Agenda Finding stuck projects
4700 (defvar org-agenda-skip-regexp nil
4701 "Regular expression used in skipping subtrees for the agenda.
4702 This is basically a temporary global variable that can be set and then
4703 used by user-defined selections using `org-agenda-skip-function'.")
4705 (defvar org-agenda-overriding-header nil
4706 "When set during agenda, todo and tags searches it replaces the header.
4707 This variable should not be set directly, but custom commands can bind it
4708 in the options section.")
4710 (defun org-agenda-skip-entry-when-regexp-matches ()
4711 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4712 If yes, it returns the end position of this entry, causing agenda commands
4713 to skip the entry but continuing the search in the subtree. This is a
4714 function that can be put into `org-agenda-skip-function' for the duration
4715 of a command."
4716 (let ((end (save-excursion (org-end-of-subtree t)))
4717 skip)
4718 (save-excursion
4719 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4720 (and skip end)))
4722 (defun org-agenda-skip-subtree-when-regexp-matches ()
4723 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4724 If yes, it returns the end position of this tree, causing agenda commands
4725 to skip this subtree. This is a function that can be put into
4726 `org-agenda-skip-function' for the duration of a command."
4727 (let ((end (save-excursion (org-end-of-subtree t)))
4728 skip)
4729 (save-excursion
4730 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4731 (and skip end)))
4733 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4734 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4735 If yes, it returns the end position of the current entry (NOT the tree),
4736 causing agenda commands to skip the entry but continuing the search in
4737 the subtree. This is a function that can be put into
4738 `org-agenda-skip-function' for the duration of a command. An important
4739 use of this function is for the stuck project list."
4740 (let ((end (save-excursion (org-end-of-subtree t)))
4741 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4742 skip)
4743 (save-excursion
4744 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4745 (and skip entry-end)))
4747 (defun org-agenda-skip-entry-if (&rest conditions)
4748 "Skip entry if any of CONDITIONS is true.
4749 See `org-agenda-skip-if' for details."
4750 (org-agenda-skip-if nil conditions))
4752 (defun org-agenda-skip-subtree-if (&rest conditions)
4753 "Skip entry if any of CONDITIONS is true.
4754 See `org-agenda-skip-if' for details."
4755 (org-agenda-skip-if t conditions))
4757 (defun org-agenda-skip-if (subtree conditions)
4758 "Checks current entity for CONDITIONS.
4759 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4760 the entry (i.e. the text before the next heading) is checked.
4762 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4763 from different tests. Valid conditions are:
4765 scheduled Check if there is a scheduled cookie
4766 notscheduled Check if there is no scheduled cookie
4767 deadline Check if there is a deadline
4768 notdeadline Check if there is no deadline
4769 timestamp Check if there is a timestamp (also deadline or scheduled)
4770 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4771 regexp Check if regexp matches
4772 notregexp Check if regexp does not match.
4773 todo Check if TODO keyword matches
4774 nottodo Check if TODO keyword does not match
4776 The regexp is taken from the conditions list, it must come right after
4777 the `regexp' or `notregexp' element.
4779 `todo' and `nottodo' accept as an argument a list of todo
4780 keywords, which may include \"*\" to match any todo keyword.
4782 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4784 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4786 Instead of a list, a keyword class may be given. For example:
4788 (org-agenda-skip-entry-if 'nottodo 'done)
4790 would skip entries that haven't been marked with any of \"DONE\"
4791 keywords. Possible classes are: `todo', `done', `any'.
4793 If any of these conditions is met, this function returns the end point of
4794 the entity, causing the search to continue from there. This is a function
4795 that can be put into `org-agenda-skip-function' for the duration of a command."
4796 (let (beg end m)
4797 (org-back-to-heading t)
4798 (setq beg (point)
4799 end (if subtree
4800 (progn (org-end-of-subtree t) (point))
4801 (progn (outline-next-heading) (1- (point)))))
4802 (goto-char beg)
4803 (and
4805 (and (memq 'scheduled conditions)
4806 (re-search-forward org-scheduled-time-regexp end t))
4807 (and (memq 'notscheduled conditions)
4808 (not (re-search-forward org-scheduled-time-regexp end t)))
4809 (and (memq 'deadline conditions)
4810 (re-search-forward org-deadline-time-regexp end t))
4811 (and (memq 'notdeadline conditions)
4812 (not (re-search-forward org-deadline-time-regexp end t)))
4813 (and (memq 'timestamp conditions)
4814 (re-search-forward org-ts-regexp end t))
4815 (and (memq 'nottimestamp conditions)
4816 (not (re-search-forward org-ts-regexp end t)))
4817 (and (setq m (memq 'regexp conditions))
4818 (stringp (nth 1 m))
4819 (re-search-forward (nth 1 m) end t))
4820 (and (setq m (memq 'notregexp conditions))
4821 (stringp (nth 1 m))
4822 (not (re-search-forward (nth 1 m) end t)))
4823 (and (or
4824 (setq m (memq 'nottodo conditions))
4825 (setq m (memq 'todo-unblocked conditions))
4826 (setq m (memq 'nottodo-unblocked conditions))
4827 (setq m (memq 'todo conditions)))
4828 (org-agenda-skip-if-todo m end)))
4829 end)))
4831 (defun org-agenda-skip-if-todo (args end)
4832 "Helper function for `org-agenda-skip-if', do not use it directly.
4833 ARGS is a list with first element either `todo', `nottodo',
4834 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4835 a list of TODO keywords, or a state symbol `todo' or `done' or
4836 `any'."
4837 (let ((kw (car args))
4838 (arg (cadr args))
4839 todo-wds todo-re)
4840 (setq todo-wds
4841 (org-uniquify
4842 (cond
4843 ((listp arg) ;; list of keywords
4844 (if (member "*" arg)
4845 (mapcar 'substring-no-properties org-todo-keywords-1)
4846 arg))
4847 ((symbolp arg) ;; keyword class name
4848 (cond
4849 ((eq arg 'todo)
4850 (org-delete-all org-done-keywords
4851 (mapcar 'substring-no-properties
4852 org-todo-keywords-1)))
4853 ((eq arg 'done) org-done-keywords)
4854 ((eq arg 'any)
4855 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4856 (setq todo-re
4857 (concat "^\\*+[ \t]+\\<\\("
4858 (mapconcat 'identity todo-wds "\\|")
4859 "\\)\\>"))
4860 (cond
4861 ((eq kw 'todo) (re-search-forward todo-re end t))
4862 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4863 ((eq kw 'todo-unblocked)
4864 (catch 'unblocked
4865 (while (re-search-forward todo-re end t)
4866 (or (org-entry-blocked-p) (throw 'unblocked t)))
4867 nil))
4868 ((eq kw 'nottodo-unblocked)
4869 (catch 'unblocked
4870 (while (re-search-forward todo-re end t)
4871 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4875 ;;;###autoload
4876 (defun org-agenda-list-stuck-projects (&rest ignore)
4877 "Create agenda view for projects that are stuck.
4878 Stuck projects are project that have no next actions. For the definitions
4879 of what a project is and how to check if it stuck, customize the variable
4880 `org-stuck-projects'."
4881 (interactive)
4882 (let* ((org-agenda-skip-function
4883 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4884 ;; We could have used org-agenda-skip-if here.
4885 (org-agenda-overriding-header
4886 (or org-agenda-overriding-header "List of stuck projects: "))
4887 (matcher (nth 0 org-stuck-projects))
4888 (todo (nth 1 org-stuck-projects))
4889 (todo-wds (if (member "*" todo)
4890 (progn
4891 (org-agenda-prepare-buffers (org-agenda-files
4892 nil 'ifmode))
4893 (org-delete-all
4894 org-done-keywords-for-agenda
4895 (copy-sequence org-todo-keywords-for-agenda)))
4896 todo))
4897 (todo-re (concat "^\\*+[ \t]+\\("
4898 (mapconcat 'identity todo-wds "\\|")
4899 "\\)\\>"))
4900 (tags (nth 2 org-stuck-projects))
4901 (tags-re (if (member "*" tags)
4902 (concat org-outline-regexp-bol
4903 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4904 (if tags
4905 (concat org-outline-regexp-bol
4906 ".*:\\("
4907 (mapconcat 'identity tags "\\|")
4908 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4909 (gen-re (nth 3 org-stuck-projects))
4910 (re-list
4911 (delq nil
4912 (list
4913 (if todo todo-re)
4914 (if tags tags-re)
4915 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4916 gen-re)))))
4917 (setq org-agenda-skip-regexp
4918 (if re-list
4919 (mapconcat 'identity re-list "\\|")
4920 (error "No information how to identify unstuck projects")))
4921 (org-tags-view nil matcher)
4922 (with-current-buffer org-agenda-buffer-name
4923 (setq org-agenda-redo-command
4924 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4926 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4927 Create agenda view for projects that are stuck.
4928 Stuck projects are project that have no next actions. For the definitions
4929 of what a project is and how to check if it stuck, customize the variable
4930 `org-stuck-projects'.
4932 \(fn &rest IGNORE)" t nil)
4934 ;;; Diary integration
4936 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4937 (defvar diary-list-entries-hook)
4938 (defvar diary-time-regexp)
4939 (defun org-get-entries-from-diary (date)
4940 "Get the (Emacs Calendar) diary entries for DATE."
4941 (require 'diary-lib)
4942 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4943 (diary-display-hook '(fancy-diary-display))
4944 (diary-display-function 'fancy-diary-display)
4945 (pop-up-frames nil)
4946 (diary-list-entries-hook
4947 (cons 'org-diary-default-entry diary-list-entries-hook))
4948 (diary-file-name-prefix-function nil) ; turn this feature off
4949 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4950 entries
4951 (org-disable-agenda-to-diary t))
4952 (save-excursion
4953 (save-window-excursion
4954 (funcall (if (fboundp 'diary-list-entries)
4955 'diary-list-entries 'list-diary-entries)
4956 date 1)))
4957 (if (not (get-buffer diary-fancy-buffer))
4958 (setq entries nil)
4959 (with-current-buffer diary-fancy-buffer
4960 (setq buffer-read-only nil)
4961 (if (zerop (buffer-size))
4962 ;; No entries
4963 (setq entries nil)
4964 ;; Omit the date and other unnecessary stuff
4965 (org-agenda-cleanup-fancy-diary)
4966 ;; Add prefix to each line and extend the text properties
4967 (if (zerop (buffer-size))
4968 (setq entries nil)
4969 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4970 (setq entries
4971 (with-temp-buffer
4972 (insert entries) (goto-char (point-min))
4973 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4974 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4975 (replace-match (concat "; " (match-string 1)))))
4976 (buffer-string)))))
4977 (set-buffer-modified-p nil)
4978 (kill-buffer diary-fancy-buffer)))
4979 (when entries
4980 (setq entries (org-split-string entries "\n"))
4981 (setq entries
4982 (mapcar
4983 (lambda (x)
4984 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
4985 ;; Extend the text properties to the beginning of the line
4986 (org-add-props x (text-properties-at (1- (length x)) x)
4987 'type "diary" 'date date 'face 'org-agenda-diary))
4988 entries)))))
4990 (defvar org-agenda-cleanup-fancy-diary-hook nil
4991 "Hook run when the fancy diary buffer is cleaned up.")
4993 (defun org-agenda-cleanup-fancy-diary ()
4994 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4995 This gets rid of the date, the underline under the date, and
4996 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4997 date. It also removes lines that contain only whitespace."
4998 (goto-char (point-min))
4999 (if (looking-at ".*?:[ \t]*")
5000 (progn
5001 (replace-match "")
5002 (re-search-forward "\n=+$" nil t)
5003 (replace-match "")
5004 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5005 (re-search-forward "\n=+$" nil t)
5006 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5007 (goto-char (point-min))
5008 (while (re-search-forward "^ +\n" nil t)
5009 (replace-match ""))
5010 (goto-char (point-min))
5011 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5012 (replace-match ""))
5013 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5015 ;; Make sure entries from the diary have the right text properties.
5016 (eval-after-load "diary-lib"
5017 '(if (boundp 'diary-modify-entry-list-string-function)
5018 ;; We can rely on the hook, nothing to do
5020 ;; Hook not available, must use advice to make this work
5021 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5022 "Make the position visible."
5023 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5024 (stringp string)
5025 buffer-file-name)
5026 (setq string (org-modify-diary-entry-string string))))))
5028 (defun org-modify-diary-entry-string (string)
5029 "Add text properties to string, allowing org-mode to act on it."
5030 (org-add-props string nil
5031 'mouse-face 'highlight
5032 'help-echo (if buffer-file-name
5033 (format "mouse-2 or RET jump to diary file %s"
5034 (abbreviate-file-name buffer-file-name))
5036 'org-agenda-diary-link t
5037 'org-marker (org-agenda-new-marker (point-at-bol))))
5039 (defun org-diary-default-entry ()
5040 "Add a dummy entry to the diary.
5041 Needed to avoid empty dates which mess up holiday display."
5042 ;; Catch the error if dealing with the new add-to-diary-alist
5043 (when org-disable-agenda-to-diary
5044 (condition-case nil
5045 (org-add-to-diary-list original-date "Org-mode dummy" "")
5046 (error
5047 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5049 (defun org-add-to-diary-list (&rest args)
5050 (if (fboundp 'diary-add-to-list)
5051 (apply 'diary-add-to-list args)
5052 (apply 'add-to-diary-list args)))
5054 (defvar org-diary-last-run-time nil)
5056 ;;;###autoload
5057 (defun org-diary (&rest args)
5058 "Return diary information from org files.
5059 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5060 It accesses org files and extracts information from those files to be
5061 listed in the diary. The function accepts arguments specifying what
5062 items should be listed. For a list of arguments allowed here, see the
5063 variable `org-agenda-entry-types'.
5065 The call in the diary file should look like this:
5067 &%%(org-diary) ~/path/to/some/orgfile.org
5069 Use a separate line for each org file to check. Or, if you omit the file name,
5070 all files listed in `org-agenda-files' will be checked automatically:
5072 &%%(org-diary)
5074 If you don't give any arguments (as in the example above), the default
5075 arguments (:deadline :scheduled :timestamp :sexp) are used.
5076 So the example above may also be written as
5078 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5080 The function expects the lisp variables `entry' and `date' to be provided
5081 by the caller, because this is how the calendar works. Don't use this
5082 function from a program - use `org-agenda-get-day-entries' instead."
5083 (when (> (- (org-float-time)
5084 org-agenda-last-marker-time)
5086 ;; I am not sure if this works with sticky agendas, because the marker
5087 ;; list is then no longer a global variable.
5088 (org-agenda-reset-markers))
5089 (org-compile-prefix-format 'agenda)
5090 (org-set-sorting-strategy 'agenda)
5091 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5092 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5093 (list entry)
5094 (org-agenda-files t)))
5095 (time (org-float-time))
5096 file rtn results)
5097 (when (or (not org-diary-last-run-time)
5098 (> (- time
5099 org-diary-last-run-time)
5101 (org-agenda-prepare-buffers files))
5102 (setq org-diary-last-run-time time)
5103 ;; If this is called during org-agenda, don't return any entries to
5104 ;; the calendar. Org Agenda will list these entries itself.
5105 (if org-disable-agenda-to-diary (setq files nil))
5106 (while (setq file (pop files))
5107 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5108 (setq results (append results rtn)))
5109 (if results
5110 (concat (org-agenda-finalize-entries results) "\n"))))
5112 (autoload 'org-diary "org-agenda" "\
5113 Return diary information from org files.
5114 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5115 It accesses org files and extracts information from those files to be
5116 listed in the diary. The function accepts arguments specifying what
5117 items should be listed. For a list of arguments allowed here, see the
5118 variable `org-agenda-entry-types'.
5120 The call in the diary file should look like this:
5122 &%%(org-diary) ~/path/to/some/orgfile.org
5124 Use a separate line for each org file to check. Or, if you omit the file name,
5125 all files listed in `org-agenda-files' will be checked automatically:
5127 &%%(org-diary)
5129 If you don't give any arguments (as in the example above), the default
5130 arguments (:deadline :scheduled :timestamp :sexp) are used.
5131 So the example above may also be written as
5133 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5135 The function expects the lisp variables `entry' and `date' to be provided
5136 by the caller, because this is how the calendar works. Don't use this
5137 function from a program - use `org-agenda-get-day-entries' instead.
5139 \(fn &rest ARGS)" nil nil)
5141 ;;; Agenda entry finders
5143 (defun org-agenda-get-day-entries (file date &rest args)
5144 "Does the work for `org-diary' and `org-agenda'.
5145 FILE is the path to a file to be checked for entries. DATE is date like
5146 the one returned by `calendar-current-date'. ARGS are symbols indicating
5147 which kind of entries should be extracted. For details about these, see
5148 the documentation of `org-diary'."
5149 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5150 (let* ((org-startup-folded nil)
5151 (org-startup-align-all-tables nil)
5152 (buffer (if (file-exists-p file)
5153 (org-get-agenda-file-buffer file)
5154 (error "No such file %s" file)))
5155 arg results rtn deadline-results)
5156 (if (not buffer)
5157 ;; If file does not exist, make sure an error message ends up in diary
5158 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5159 (with-current-buffer buffer
5160 (unless (derived-mode-p 'org-mode)
5161 (error "Agenda file %s is not in `org-mode'" file))
5162 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5163 (let ((case-fold-search nil))
5164 (save-excursion
5165 (save-restriction
5166 (if org-agenda-restrict
5167 (narrow-to-region org-agenda-restrict-begin
5168 org-agenda-restrict-end)
5169 (widen))
5170 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5171 (while (setq arg (pop args))
5172 (cond
5173 ((and (eq arg :todo)
5174 (equal date (calendar-gregorian-from-absolute
5175 (org-today))))
5176 (setq rtn (org-agenda-get-todos))
5177 (setq results (append results rtn)))
5178 ((eq arg :timestamp)
5179 (setq rtn (org-agenda-get-blocks))
5180 (setq results (append results rtn))
5181 (setq rtn (org-agenda-get-timestamps deadline-results))
5182 (setq results (append results rtn)))
5183 ((eq arg :sexp)
5184 (setq rtn (org-agenda-get-sexps))
5185 (setq results (append results rtn)))
5186 ((eq arg :scheduled)
5187 (setq rtn (org-agenda-get-scheduled deadline-results))
5188 (setq results (append results rtn)))
5189 ((eq arg :closed)
5190 (setq rtn (org-agenda-get-progress))
5191 (setq results (append results rtn)))
5192 ((eq arg :deadline)
5193 (setq rtn (org-agenda-get-deadlines))
5194 (setq deadline-results (copy-sequence rtn))
5195 (setq results (append results rtn))))))))
5196 results))))
5198 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5199 (defun org-agenda-get-todos ()
5200 "Return the TODO information for agenda display."
5201 (let* ((props (list 'face nil
5202 'done-face 'org-agenda-done
5203 'org-not-done-regexp org-not-done-regexp
5204 'org-todo-regexp org-todo-regexp
5205 'org-complex-heading-regexp org-complex-heading-regexp
5206 'mouse-face 'highlight
5207 'help-echo
5208 (format "mouse-2 or RET jump to org file %s"
5209 (abbreviate-file-name buffer-file-name))))
5210 (regexp (format org-heading-keyword-regexp-format
5211 (cond
5212 ((and org-select-this-todo-keyword
5213 (equal org-select-this-todo-keyword "*"))
5214 org-todo-regexp)
5215 (org-select-this-todo-keyword
5216 (concat "\\("
5217 (mapconcat 'identity
5218 (org-split-string
5219 org-select-this-todo-keyword
5220 "|")
5221 "\\|") "\\)"))
5222 (t org-not-done-regexp))))
5223 marker priority category category-pos level tags todo-state
5224 ee txt beg end)
5225 (goto-char (point-min))
5226 (while (re-search-forward regexp nil t)
5227 (catch :skip
5228 (save-match-data
5229 (beginning-of-line)
5230 (org-agenda-skip)
5231 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5232 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5233 (goto-char (1+ beg))
5234 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5235 (throw :skip nil)))
5236 (goto-char (match-beginning 2))
5237 (setq marker (org-agenda-new-marker (match-beginning 0))
5238 category (org-get-category)
5239 category-pos (get-text-property (point) 'org-category-position)
5240 txt (org-trim
5241 (buffer-substring (match-beginning 2) (match-end 0)))
5242 tags (org-get-tags-at (point))
5243 level (make-string (org-reduced-level (org-outline-level)) ? )
5244 txt (org-agenda-format-item "" txt level category tags t)
5245 priority (1+ (org-get-priority txt))
5246 todo-state (org-get-todo-state))
5247 (org-add-props txt props
5248 'org-marker marker 'org-hd-marker marker
5249 'priority priority 'org-category category
5250 'level level
5251 'org-category-position category-pos
5252 'type "todo" 'todo-state todo-state)
5253 (push txt ee)
5254 (if org-agenda-todo-list-sublevels
5255 (goto-char (match-end 2))
5256 (org-end-of-subtree 'invisible))))
5257 (nreverse ee)))
5259 (defun org-agenda-todo-custom-ignore-p (time n)
5260 "Check whether timestamp is farther away than n number of days.
5261 This function is invoked if `org-agenda-todo-ignore-deadlines',
5262 `org-agenda-todo-ignore-scheduled' or
5263 `org-agenda-todo-ignore-timestamp' is set to an integer."
5264 (let ((days (org-time-stamp-to-now
5265 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5266 (if (>= n 0)
5267 (>= days n)
5268 (<= days n))))
5270 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5271 (&optional end)
5272 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5273 (when (or org-agenda-todo-ignore-with-date
5274 org-agenda-todo-ignore-scheduled
5275 org-agenda-todo-ignore-deadlines
5276 org-agenda-todo-ignore-timestamp)
5277 (setq end (or end (save-excursion (outline-next-heading) (point))))
5278 (save-excursion
5279 (or (and org-agenda-todo-ignore-with-date
5280 (re-search-forward org-ts-regexp end t))
5281 (and org-agenda-todo-ignore-scheduled
5282 (re-search-forward org-scheduled-time-regexp end t)
5283 (cond
5284 ((eq org-agenda-todo-ignore-scheduled 'future)
5285 (> (org-time-stamp-to-now
5286 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5287 ((eq org-agenda-todo-ignore-scheduled 'past)
5288 (<= (org-time-stamp-to-now
5289 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5290 ((numberp org-agenda-todo-ignore-scheduled)
5291 (org-agenda-todo-custom-ignore-p
5292 (match-string 1) org-agenda-todo-ignore-scheduled))
5293 (t)))
5294 (and org-agenda-todo-ignore-deadlines
5295 (re-search-forward org-deadline-time-regexp end t)
5296 (cond
5297 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5298 ((eq org-agenda-todo-ignore-deadlines 'far)
5299 (not (org-deadline-close (match-string 1))))
5300 ((eq org-agenda-todo-ignore-deadlines 'future)
5301 (> (org-time-stamp-to-now
5302 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5303 ((eq org-agenda-todo-ignore-deadlines 'past)
5304 (<= (org-time-stamp-to-now
5305 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5306 ((numberp org-agenda-todo-ignore-deadlines)
5307 (org-agenda-todo-custom-ignore-p
5308 (match-string 1) org-agenda-todo-ignore-deadlines))
5309 (t (org-deadline-close (match-string 1)))))
5310 (and org-agenda-todo-ignore-timestamp
5311 (let ((buffer (current-buffer))
5312 (regexp
5313 (concat
5314 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5315 (start (point)))
5316 ;; Copy current buffer into a temporary one
5317 (with-temp-buffer
5318 (insert-buffer-substring buffer start end)
5319 (goto-char (point-min))
5320 ;; Delete SCHEDULED and DEADLINE items
5321 (while (re-search-forward regexp end t)
5322 (delete-region (match-beginning 0) (match-end 0)))
5323 (goto-char (point-min))
5324 ;; No search for timestamp left
5325 (when (re-search-forward org-ts-regexp nil t)
5326 (cond
5327 ((eq org-agenda-todo-ignore-timestamp 'future)
5328 (> (org-time-stamp-to-now
5329 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5330 ((eq org-agenda-todo-ignore-timestamp 'past)
5331 (<= (org-time-stamp-to-now
5332 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5333 ((numberp org-agenda-todo-ignore-timestamp)
5334 (org-agenda-todo-custom-ignore-p
5335 (match-string 1) org-agenda-todo-ignore-timestamp))
5336 (t))))))))))
5338 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5339 Do we have a reason to ignore this TODO entry because it has a time stamp?
5341 \(fn &optional END)" nil nil)
5343 (defconst org-agenda-no-heading-message
5344 "No heading for this item in buffer or region.")
5346 (defun org-agenda-get-timestamps (&optional deadline-results)
5347 "Return the date stamp information for agenda display."
5348 (let* ((props (list 'face 'org-agenda-calendar-event
5349 'org-not-done-regexp org-not-done-regexp
5350 'org-todo-regexp org-todo-regexp
5351 'org-complex-heading-regexp org-complex-heading-regexp
5352 'mouse-face 'highlight
5353 'help-echo
5354 (format "mouse-2 or RET jump to org file %s"
5355 (abbreviate-file-name buffer-file-name))))
5356 (d1 (calendar-absolute-from-gregorian date))
5358 (deadline-position-alist
5359 (mapcar (lambda (a) (and (setq mm (get-text-property
5360 0 'org-hd-marker a))
5361 (cons (marker-position mm) a)))
5362 deadline-results))
5363 (remove-re org-ts-regexp)
5364 (regexp
5365 (concat
5366 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5367 (regexp-quote
5368 (substring
5369 (format-time-string
5370 (car org-time-stamp-formats)
5371 (apply 'encode-time ; DATE bound by calendar
5372 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5373 1 11))
5374 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5375 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5376 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5377 donep tmp priority category category-pos level ee txt timestr tags
5378 b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
5379 (goto-char (point-min))
5380 (while (setq end-of-match (re-search-forward regexp nil t))
5381 (setq b0 (match-beginning 0)
5382 b3 (match-beginning 3) e3 (match-end 3)
5383 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5384 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5385 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5386 (member todo-state
5387 org-agenda-repeating-timestamp-show-all)))
5388 (catch :skip
5389 (and (org-at-date-range-p) (throw :skip nil))
5390 (org-agenda-skip)
5391 (if (and (match-end 1)
5392 (not (= d1 (org-time-string-to-absolute
5393 (match-string 1) d1 nil show-all
5394 (current-buffer) b0))))
5395 (throw :skip nil))
5396 (if (and e3
5397 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5398 (throw :skip nil))
5399 (setq tmp (buffer-substring (max (point-min)
5400 (- b0 org-ds-keyword-length))
5402 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5403 inactivep (= (char-after b0) ?\[)
5404 deadlinep (string-match org-deadline-regexp tmp)
5405 scheduledp (string-match org-scheduled-regexp tmp)
5406 closedp (and org-agenda-include-inactive-timestamps
5407 (string-match org-closed-string tmp))
5408 clockp (and org-agenda-include-inactive-timestamps
5409 (or (string-match org-clock-string tmp)
5410 (string-match "]-+\\'" tmp)))
5411 warntime (org-entry-get (point) "APPT_WARNTIME")
5412 donep (member todo-state org-done-keywords))
5413 (if (or scheduledp deadlinep closedp clockp
5414 (and donep org-agenda-skip-timestamp-if-done))
5415 (throw :skip t))
5416 (if (string-match ">" timestr)
5417 ;; substring should only run to end of time stamp
5418 (setq timestr (substring timestr 0 (match-end 0))))
5419 (setq marker (org-agenda-new-marker b0)
5420 category (org-get-category b0)
5421 category-pos (get-text-property b0 'org-category-position))
5422 (save-excursion
5423 (if (not (re-search-backward org-outline-regexp-bol nil t))
5424 (setq txt org-agenda-no-heading-message)
5425 (goto-char (match-beginning 0))
5426 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5427 (assoc (point) deadline-position-alist))
5428 (throw :skip nil))
5429 (setq hdmarker (org-agenda-new-marker)
5430 tags (org-get-tags-at)
5431 level (make-string (org-reduced-level (org-outline-level)) ? ))
5432 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5433 (setq head (or (match-string 1) ""))
5434 (setq txt (org-agenda-format-item
5435 (if inactivep org-agenda-inactive-leader nil)
5436 head level category tags timestr
5437 remove-re habitp)))
5438 (setq priority (org-get-priority txt))
5439 (org-add-props txt props 'priority priority
5440 'org-marker marker 'org-hd-marker hdmarker
5441 'org-category category 'date date
5442 'level level
5443 'org-category-position category-pos
5444 'todo-state todo-state
5445 'warntime warntime
5446 'type "timestamp")
5447 (push txt ee))
5448 (if org-agenda-skip-additional-timestamps-same-entry
5449 (outline-next-heading)
5450 (goto-char end-of-match))))
5451 (nreverse ee)))
5453 (defun org-agenda-get-sexps ()
5454 "Return the sexp information for agenda display."
5455 (require 'diary-lib)
5456 (let* ((props (list 'face 'org-agenda-calendar-sexp
5457 'mouse-face 'highlight
5458 'help-echo
5459 (format "mouse-2 or RET jump to org file %s"
5460 (abbreviate-file-name buffer-file-name))))
5461 (regexp "^&?%%(")
5462 marker category extra category-pos level ee txt tags entry
5463 result beg b sexp sexp-entry todo-state warntime)
5464 (goto-char (point-min))
5465 (while (re-search-forward regexp nil t)
5466 (catch :skip
5467 (org-agenda-skip)
5468 (setq beg (match-beginning 0))
5469 (goto-char (1- (match-end 0)))
5470 (setq b (point))
5471 (forward-sexp 1)
5472 (setq sexp (buffer-substring b (point)))
5473 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5474 (org-trim (match-string 1))
5475 ""))
5476 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5477 (when result
5478 (setq marker (org-agenda-new-marker beg)
5479 level (make-string (org-reduced-level (org-outline-level)) ? )
5480 category (org-get-category beg)
5481 category-pos (get-text-property beg 'org-category-position)
5482 tags (save-excursion (org-backward-heading-same-level 0)
5483 (org-get-tags-at))
5484 todo-state (org-get-todo-state)
5485 warntime (org-entry-get (point) "APPT_WARNTIME"))
5487 (dolist (r (if (stringp result)
5488 (list result)
5489 result)) ;; we expect a list here
5490 (when (and org-agenda-diary-sexp-prefix
5491 (string-match org-agenda-diary-sexp-prefix r))
5492 (setq extra (match-string 0 r)
5493 r (replace-match "" nil nil r)))
5494 (if (string-match "\\S-" r)
5495 (setq txt r)
5496 (setq txt "SEXP entry returned empty string"))
5497 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5498 (org-add-props txt props 'org-marker marker
5499 'org-category category 'date date 'todo-state todo-state
5500 'org-category-position category-pos 'tags tags
5501 'level level
5502 'type "sexp" 'warntime warntime)
5503 (push txt ee)))))
5504 (nreverse ee)))
5506 ;; Calendar sanity: define some functions that are independent of
5507 ;; `calendar-date-style'.
5508 ;; Normally I would like to use ISO format when calling the diary functions,
5509 ;; but to make sure we still have Emacs 22 compatibility we bind
5510 ;; also `european-calendar-style' and use european format
5511 (defun org-anniversary (year month day &optional mark)
5512 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5513 (org-no-warnings
5514 (let ((calendar-date-style 'european) (european-calendar-style t))
5515 (diary-anniversary day month year mark))))
5516 (defun org-cyclic (N year month day &optional mark)
5517 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5518 (org-no-warnings
5519 (let ((calendar-date-style 'european) (european-calendar-style t))
5520 (diary-cyclic N day month year mark))))
5521 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5522 "Like `diary-block', but with fixed (ISO) order of arguments."
5523 (org-no-warnings
5524 (let ((calendar-date-style 'european) (european-calendar-style t))
5525 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5526 (defun org-date (year month day &optional mark)
5527 "Like `diary-date', but with fixed (ISO) order of arguments."
5528 (org-no-warnings
5529 (let ((calendar-date-style 'european) (european-calendar-style t))
5530 (diary-date day month year mark))))
5531 (defalias 'org-float 'diary-float)
5533 ;; Define the` org-class' function
5534 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5535 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5536 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5537 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5538 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5539 `holidays', then any date that is known by the Emacs calendar to be a
5540 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5541 then those holidays will be skipped."
5542 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5543 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5544 (d (calendar-absolute-from-gregorian date))
5545 (h (when skip-weeks (calendar-check-holidays date))))
5546 (and
5547 (<= date1 d)
5548 (<= d date2)
5549 (= (calendar-day-of-week date) dayname)
5550 (or (not skip-weeks)
5551 (progn
5552 (require 'cal-iso)
5553 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5554 (not (or (and h (memq 'holidays skip-weeks))
5555 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5556 entry)))
5558 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5559 "Like `org-class', but honor `calendar-date-style'.
5560 The order of the first 2 times 3 arguments depends on the variable
5561 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5562 So for American calendars, give this as MONTH DAY YEAR, for European as
5563 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5564 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5565 is any number of ISO weeks in the block period for which the item should
5566 be skipped.
5568 This function is here only for backward compatibility and it is deprecated,
5569 please use `org-class' instead."
5570 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5571 (date2 (org-order-calendar-date-args m2 d2 y2)))
5572 (org-class
5573 (nth 2 date1) (car date1) (nth 1 date1)
5574 (nth 2 date2) (car date2) (nth 1 date2)
5575 dayname skip-weeks)))
5576 (make-obsolete 'org-diary-class 'org-class "")
5578 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5579 (defalias 'org-get-closed 'org-agenda-get-progress)
5580 (defun org-agenda-get-progress ()
5581 "Return the logged TODO entries for agenda display."
5582 (let* ((props (list 'mouse-face 'highlight
5583 'org-not-done-regexp org-not-done-regexp
5584 'org-todo-regexp org-todo-regexp
5585 'org-complex-heading-regexp org-complex-heading-regexp
5586 'help-echo
5587 (format "mouse-2 or RET jump to org file %s"
5588 (abbreviate-file-name buffer-file-name))))
5589 (items (if (consp org-agenda-show-log-scoped)
5590 org-agenda-show-log-scoped
5591 (if (eq org-agenda-show-log-scoped 'clockcheck)
5592 '(clock)
5593 org-agenda-log-mode-items)))
5594 (parts
5595 (delq nil
5596 (list
5597 (if (memq 'closed items) (concat "\\<" org-closed-string))
5598 (if (memq 'clock items) (concat "\\<" org-clock-string))
5599 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5600 (parts-re (if parts (mapconcat 'identity parts "\\|")
5601 (error "`org-agenda-log-mode-items' is empty")))
5602 (regexp (concat
5603 "\\(" parts-re "\\)"
5604 " *\\["
5605 (regexp-quote
5606 (substring
5607 (format-time-string
5608 (car org-time-stamp-formats)
5609 (apply 'encode-time ; DATE bound by calendar
5610 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5611 1 11))))
5612 (org-agenda-search-headline-for-time nil)
5613 marker hdmarker priority category category-pos level tags closedp
5614 statep clockp state ee txt extra timestr rest clocked)
5615 (goto-char (point-min))
5616 (while (re-search-forward regexp nil t)
5617 (catch :skip
5618 (org-agenda-skip)
5619 (setq marker (org-agenda-new-marker (match-beginning 0))
5620 closedp (equal (match-string 1) org-closed-string)
5621 statep (equal (string-to-char (match-string 1)) ?-)
5622 clockp (not (or closedp statep))
5623 state (and statep (match-string 2))
5624 category (org-get-category (match-beginning 0))
5625 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5626 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5627 (when (string-match "\\]" timestr)
5628 ;; substring should only run to end of time stamp
5629 (setq rest (substring timestr (match-end 0))
5630 timestr (substring timestr 0 (match-end 0)))
5631 (if (and (not closedp) (not statep)
5632 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5633 rest))
5634 (progn (setq timestr (concat (substring timestr 0 -1)
5635 "-" (match-string 1 rest) "]"))
5636 (setq clocked (match-string 2 rest)))
5637 (setq clocked "-")))
5638 (save-excursion
5639 (setq extra
5640 (cond
5641 ((not org-agenda-log-mode-add-notes) nil)
5642 (statep
5643 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5644 (match-string 1)))
5645 (clockp
5646 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5647 (match-string 1)))))
5648 (if (not (re-search-backward org-outline-regexp-bol nil t))
5649 (setq txt org-agenda-no-heading-message)
5650 (goto-char (match-beginning 0))
5651 (setq hdmarker (org-agenda-new-marker)
5652 tags (org-get-tags-at)
5653 level (make-string (org-reduced-level (org-outline-level)) ? ))
5654 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5655 (setq txt (match-string 1))
5656 (when extra
5657 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5658 (setq txt (concat (substring txt 0 (match-beginning 1))
5659 " - " extra " " (match-string 2 txt)))
5660 (setq txt (concat txt " - " extra))))
5661 (setq txt (org-agenda-format-item
5662 (cond
5663 (closedp "Closed: ")
5664 (statep (concat "State: (" state ")"))
5665 (t (concat "Clocked: (" clocked ")")))
5666 txt level category tags timestr)))
5667 (setq priority 100000)
5668 (org-add-props txt props
5669 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5670 'priority priority 'org-category category
5671 'org-category-position category-pos
5672 'level level
5673 'type "closed" 'date date
5674 'undone-face 'org-warning 'done-face 'org-agenda-done)
5675 (push txt ee))
5676 (goto-char (point-at-eol))))
5677 (nreverse ee)))
5679 (defun org-agenda-show-clocking-issues ()
5680 "Add overlays, showing issues with clocking.
5681 See also the user option `org-agenda-clock-consistency-checks'."
5682 (interactive)
5683 (let* ((pl org-agenda-clock-consistency-checks)
5684 (re (concat "^[ \t]*"
5685 org-clock-string
5686 "[ \t]+"
5687 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5688 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5689 (tlstart 0.)
5690 (tlend 0.)
5691 (maxtime (org-hh:mm-string-to-minutes
5692 (or (plist-get pl :max-duration) "24:00")))
5693 (mintime (org-hh:mm-string-to-minutes
5694 (or (plist-get pl :min-duration) 0)))
5695 (maxgap (org-hh:mm-string-to-minutes
5696 ;; default 30:00 means never complain
5697 (or (plist-get pl :max-gap) "30:00")))
5698 (gapok (mapcar 'org-hh:mm-string-to-minutes
5699 (plist-get pl :gap-ok-around)))
5700 (def-face (or (plist-get pl :default-face)
5701 '((:background "DarkRed") (:foreground "white"))))
5702 issue face m te ts dt ov)
5703 (goto-char (point-min))
5704 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5705 (setq issue nil face def-face)
5706 (catch 'next
5707 (setq m (org-get-at-bol 'org-marker)
5708 te nil ts nil)
5709 (unless (and m (markerp m))
5710 (setq issue "No valid clock line") (throw 'next t))
5711 (org-with-point-at m
5712 (save-excursion
5713 (goto-char (point-at-bol))
5714 (unless (looking-at re)
5715 (error "No valid Clock line")
5716 (throw 'next t))
5717 (unless (match-end 3)
5718 (setq issue "No end time"
5719 face (or (plist-get pl :no-end-time-face) face))
5720 (throw 'next t))
5721 (setq ts (match-string 1)
5722 te (match-string 3)
5723 ts (org-float-time
5724 (apply 'encode-time (org-parse-time-string ts)))
5725 te (org-float-time
5726 (apply 'encode-time (org-parse-time-string te)))
5727 dt (- te ts))))
5728 (cond
5729 ((> dt (* 60 maxtime))
5730 ;; a very long clocking chunk
5731 (setq issue (format "Clocking interval is very long: %s"
5732 (org-minutes-to-hh:mm-string
5733 (floor (/ (float dt) 60.))))
5734 face (or (plist-get pl :long-face) face)))
5735 ((< dt (* 60 mintime))
5736 ;; a very short clocking chunk
5737 (setq issue (format "Clocking interval is very short: %s"
5738 (org-minutes-to-hh:mm-string
5739 (floor (/ (float dt) 60.))))
5740 face (or (plist-get pl :short-face) face)))
5741 ((and (> tlend 0) (< ts tlend))
5742 ;; Two clock entries are overlapping
5743 (setq issue (format "Clocking overlap: %d minutes"
5744 (/ (- tlend ts) 60))
5745 face (or (plist-get pl :overlap-face) face)))
5746 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5747 ;; There is a gap, lets see if we need to report it
5748 (unless (org-agenda-check-clock-gap tlend ts gapok)
5749 (setq issue (format "Clocking gap: %d minutes"
5750 (/ (- ts tlend) 60))
5751 face (or (plist-get pl :gap-face) face))))
5752 (t nil)))
5753 (setq tlend (or te tlend) tlstart (or ts tlstart))
5754 (when issue
5755 ;; OK, there was some issue, add an overlay to show the issue
5756 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5757 (overlay-put ov 'before-string
5758 (concat
5759 (org-add-props
5760 (format "%-43s" (concat " " issue))
5762 'face face)
5763 "\n"))
5764 (overlay-put ov 'evaporate t)))))
5766 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5767 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5768 (catch 'exit
5769 (unless ok-list
5770 ;; there are no OK times for gaps...
5771 (throw 'exit nil))
5772 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5773 ;; This is more than 24 hours, so it is OK.
5774 ;; because we have at least one OK time, that must be in the
5775 ;; 24 hour interval.
5776 (throw 'exit t))
5777 ;; We have a shorter gap.
5778 ;; Now we have to get the minute of the day when these times are
5779 (let* ((t1dec (decode-time (seconds-to-time t1)))
5780 (t2dec (decode-time (seconds-to-time t2)))
5781 ;; compute the minute on the day
5782 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5783 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5784 (when (< min2 min1)
5785 ;; if min2 is smaller than min1, this means it is on the next day.
5786 ;; Wrap it to after midnight.
5787 (setq min2 (+ min2 1440)))
5788 ;; Now check if any of the OK times is in the gap
5789 (mapc (lambda (x)
5790 ;; Wrap the time to after midnight if necessary
5791 (if (< x min1) (setq x (+ x 1440)))
5792 ;; Check if in interval
5793 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5794 ok-list)
5795 ;; Nope, this gap is not OK
5796 nil)))
5798 (defun org-agenda-get-deadlines ()
5799 "Return the deadline information for agenda display."
5800 (let* ((props (list 'mouse-face 'highlight
5801 'org-not-done-regexp org-not-done-regexp
5802 'org-todo-regexp org-todo-regexp
5803 'org-complex-heading-regexp org-complex-heading-regexp
5804 'help-echo
5805 (format "mouse-2 or RET jump to org file %s"
5806 (abbreviate-file-name buffer-file-name))))
5807 (regexp org-deadline-time-regexp)
5808 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5809 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5810 d2 diff dfrac wdays pos pos1 category category-pos level
5811 tags suppress-prewarning ee txt head face s todo-state
5812 show-all upcomingp donep timestr warntime)
5813 (goto-char (point-min))
5814 (while (re-search-forward regexp nil t)
5815 (setq suppress-prewarning nil)
5816 (catch :skip
5817 (org-agenda-skip)
5818 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5819 (save-match-data
5820 (string-match org-scheduled-time-regexp
5821 (buffer-substring (point-at-bol)
5822 (point-at-eol)))))
5823 (setq suppress-prewarning
5824 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5825 org-agenda-skip-deadline-prewarning-if-scheduled
5826 0)))
5827 (setq s (match-string 1)
5828 txt nil
5829 pos (1- (match-beginning 1))
5830 todo-state (save-match-data (org-get-todo-state))
5831 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5832 (member todo-state
5833 org-agenda-repeating-timestamp-show-all))
5834 d2 (org-time-string-to-absolute
5835 (match-string 1) d1 'past show-all
5836 (current-buffer) pos)
5837 diff (- d2 d1)
5838 wdays (if suppress-prewarning
5839 (let ((org-deadline-warning-days suppress-prewarning))
5840 (org-get-wdays s))
5841 (org-get-wdays s))
5842 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5843 upcomingp (and todayp (> diff 0)))
5844 ;; When to show a deadline in the calendar:
5845 ;; If the expiration is within wdays warning time.
5846 ;; Past-due deadlines are only shown on the current date
5847 (if (and (or (and (<= diff wdays)
5848 (and todayp (not org-agenda-only-exact-dates)))
5849 (= diff 0)))
5850 (save-excursion
5851 ;; (setq todo-state (org-get-todo-state))
5852 (setq donep (member todo-state org-done-keywords))
5853 (if (and donep
5854 (or org-agenda-skip-deadline-if-done
5855 (not (= diff 0))))
5856 (setq txt nil)
5857 (setq category (org-get-category)
5858 warntime (org-entry-get (point) "APPT_WARNTIME")
5859 category-pos (get-text-property (point) 'org-category-position))
5860 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5861 (setq txt org-agenda-no-heading-message)
5862 (goto-char (match-end 0))
5863 (setq pos1 (match-beginning 0))
5864 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5865 (setq tags (org-get-tags-at pos1))
5866 (setq head (buffer-substring-no-properties
5867 (point)
5868 (progn (skip-chars-forward "^\r\n")
5869 (point))))
5870 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5871 (setq timestr
5872 (concat (substring s (match-beginning 1)) " "))
5873 (setq timestr 'time))
5874 (setq txt (org-agenda-format-item
5875 (if (= diff 0)
5876 (car org-agenda-deadline-leaders)
5877 (if (functionp
5878 (nth 1 org-agenda-deadline-leaders))
5879 (funcall
5880 (nth 1 org-agenda-deadline-leaders)
5881 diff date)
5882 (format (nth 1 org-agenda-deadline-leaders)
5883 diff)))
5884 head level category tags
5885 (if (not (= diff 0)) nil timestr)))))
5886 (when txt
5887 (setq face (org-agenda-deadline-face dfrac))
5888 (org-add-props txt props
5889 'org-marker (org-agenda-new-marker pos)
5890 'warntime warntime
5891 'level level
5892 'org-hd-marker (org-agenda-new-marker pos1)
5893 'priority (+ (- diff)
5894 (org-get-priority txt))
5895 'org-category category
5896 'org-category-position category-pos
5897 'todo-state todo-state
5898 'type (if upcomingp "upcoming-deadline" "deadline")
5899 'date (if upcomingp date d2)
5900 'face (if donep 'org-agenda-done face)
5901 'undone-face face 'done-face 'org-agenda-done)
5902 (push txt ee))))))
5903 (nreverse ee)))
5905 (defun org-agenda-deadline-face (fraction)
5906 "Return the face to displaying a deadline item.
5907 FRACTION is what fraction of the head-warning time has passed."
5908 (let ((faces org-agenda-deadline-faces) f)
5909 (catch 'exit
5910 (while (setq f (pop faces))
5911 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5913 (defun org-agenda-get-scheduled (&optional deadline-results)
5914 "Return the scheduled information for agenda display."
5915 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5916 'org-todo-regexp org-todo-regexp
5917 'org-complex-heading-regexp org-complex-heading-regexp
5918 'done-face 'org-agenda-done
5919 'mouse-face 'highlight
5920 'help-echo
5921 (format "mouse-2 or RET jump to org file %s"
5922 (abbreviate-file-name buffer-file-name))))
5923 (regexp org-scheduled-time-regexp)
5924 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5925 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5927 (deadline-position-alist
5928 (mapcar (lambda (a) (and (setq mm (get-text-property
5929 0 'org-hd-marker a))
5930 (cons (marker-position mm) a)))
5931 deadline-results))
5932 d2 diff pos pos1 category category-pos level tags donep
5933 ee txt head pastschedp todo-state face timestr s habitp show-all
5934 did-habit-check-p warntime)
5935 (goto-char (point-min))
5936 (while (re-search-forward regexp nil t)
5937 (catch :skip
5938 (org-agenda-skip)
5939 (setq s (match-string 1)
5940 txt nil
5941 pos (1- (match-beginning 1))
5942 todo-state (save-match-data (org-get-todo-state))
5943 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5944 (member todo-state
5945 org-agenda-repeating-timestamp-show-all))
5946 d2 (org-time-string-to-absolute
5947 (match-string 1) d1 'past show-all
5948 (current-buffer) pos)
5949 diff (- d2 d1)
5950 warntime (org-entry-get (point) "APPT_WARNTIME"))
5951 (setq pastschedp (and todayp (< diff 0)))
5952 (setq did-habit-check-p nil)
5953 ;; When to show a scheduled item in the calendar:
5954 ;; If it is on or past the date.
5955 (when (or (and (< diff 0)
5956 (< (abs diff) org-scheduled-past-days)
5957 (and todayp (not org-agenda-only-exact-dates)))
5958 (= diff 0)
5959 ;; org-is-habit-p uses org-entry-get, which is expansive
5960 ;; so we go extra mile to only call it once
5961 (and todayp
5962 (boundp 'org-habit-show-all-today)
5963 org-habit-show-all-today
5964 (setq did-habit-check-p t)
5965 (setq habitp (and (functionp 'org-is-habit-p)
5966 (org-is-habit-p)))))
5967 (save-excursion
5968 (setq donep (member todo-state org-done-keywords))
5969 (if (and donep
5970 (or org-agenda-skip-scheduled-if-done
5971 (not (= diff 0))
5972 (and (functionp 'org-is-habit-p)
5973 (org-is-habit-p))))
5974 (setq txt nil)
5975 (setq habitp (if did-habit-check-p habitp
5976 (and (functionp 'org-is-habit-p)
5977 (org-is-habit-p))))
5978 (setq category (org-get-category)
5979 category-pos (get-text-property (point) 'org-category-position))
5980 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5981 (setq txt org-agenda-no-heading-message)
5982 (goto-char (match-end 0))
5983 (setq pos1 (match-beginning 0))
5984 (if habitp
5985 (if (or (not org-habit-show-habits)
5986 (and (not todayp)
5987 (boundp 'org-habit-show-habits-only-for-today)
5988 org-habit-show-habits-only-for-today))
5989 (throw :skip nil))
5990 (if (and
5991 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5992 (and org-agenda-skip-scheduled-if-deadline-is-shown
5993 pastschedp))
5994 (setq mm (assoc pos1 deadline-position-alist)))
5995 (throw :skip nil)))
5996 (setq tags (org-get-tags-at))
5997 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5998 (setq head (buffer-substring-no-properties
5999 (point)
6000 (progn (skip-chars-forward "^\r\n") (point))))
6001 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6002 (setq timestr
6003 (concat (substring s (match-beginning 1)) " "))
6004 (setq timestr 'time))
6005 (setq txt (org-agenda-format-item
6006 (if (= diff 0)
6007 (car org-agenda-scheduled-leaders)
6008 (format (nth 1 org-agenda-scheduled-leaders)
6009 (- 1 diff)))
6010 head level category tags
6011 (if (not (= diff 0)) nil timestr)
6012 nil habitp))))
6013 (when txt
6014 (setq face
6015 (cond
6016 ((and (not habitp) pastschedp)
6017 'org-scheduled-previously)
6018 (todayp 'org-scheduled-today)
6019 (t 'org-scheduled))
6020 habitp (and habitp (org-habit-parse-todo)))
6021 (org-add-props txt props
6022 'undone-face face
6023 'face (if donep 'org-agenda-done face)
6024 'org-marker (org-agenda-new-marker pos)
6025 'org-hd-marker (org-agenda-new-marker pos1)
6026 'type (if pastschedp "past-scheduled" "scheduled")
6027 'date (if pastschedp d2 date)
6028 'warntime warntime
6029 'level level
6030 'priority (if habitp
6031 (org-habit-get-priority habitp)
6032 (+ 94 (- 5 diff) (org-get-priority txt)))
6033 'org-category category
6034 'category-position category-pos
6035 'org-habit-p habitp
6036 'todo-state todo-state)
6037 (push txt ee))))))
6038 (nreverse ee)))
6040 (defun org-agenda-get-blocks ()
6041 "Return the date-range information for agenda display."
6042 (let* ((props (list 'face nil
6043 'org-not-done-regexp org-not-done-regexp
6044 'org-todo-regexp org-todo-regexp
6045 'org-complex-heading-regexp org-complex-heading-regexp
6046 'mouse-face 'highlight
6047 'help-echo
6048 (format "mouse-2 or RET jump to org file %s"
6049 (abbreviate-file-name buffer-file-name))))
6050 (regexp org-tr-regexp)
6051 (d0 (calendar-absolute-from-gregorian date))
6052 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6053 level todo-state tags pos head donep)
6054 (goto-char (point-min))
6055 (while (re-search-forward regexp nil t)
6056 (catch :skip
6057 (org-agenda-skip)
6058 (setq pos (point))
6059 (let ((start-time (match-string 1))
6060 (end-time (match-string 2)))
6061 (setq s1 (match-string 1)
6062 s2 (match-string 2)
6063 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6064 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6065 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6066 ;; Only allow days between the limits, because the normal
6067 ;; date stamps will catch the limits.
6068 (save-excursion
6069 (setq todo-state (org-get-todo-state))
6070 (setq donep (member todo-state org-done-keywords))
6071 (if (and donep org-agenda-skip-timestamp-if-done)
6072 (throw :skip t))
6073 (setq marker (org-agenda-new-marker (point)))
6074 (setq category (org-get-category)
6075 category-pos (get-text-property (point) 'org-category-position))
6076 (if (not (re-search-backward org-outline-regexp-bol nil t))
6077 (setq txt org-agenda-no-heading-message)
6078 (goto-char (match-beginning 0))
6079 (setq hdmarker (org-agenda-new-marker (point)))
6080 (setq tags (org-get-tags-at))
6081 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6082 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6083 (setq head (match-string 1))
6084 (let ((remove-re
6085 (if org-agenda-remove-timeranges-from-blocks
6086 (concat
6087 "<" (regexp-quote s1) ".*?>"
6088 "--"
6089 "<" (regexp-quote s2) ".*?>")
6090 nil)))
6091 (setq txt (org-agenda-format-item
6092 (format
6093 (nth (if (= d1 d2) 0 1)
6094 org-agenda-timerange-leaders)
6095 (1+ (- d0 d1)) (1+ (- d2 d1)))
6096 head level category tags
6097 (cond ((and (= d1 d0) (= d2 d0))
6098 (concat "<" start-time ">--<" end-time ">"))
6099 ((= d1 d0)
6100 (concat "<" start-time ">"))
6101 ((= d2 d0)
6102 (concat "<" end-time ">")))
6103 remove-re))))
6104 (org-add-props txt props
6105 'org-marker marker 'org-hd-marker hdmarker
6106 'type "block" 'date date
6107 'level level
6108 'todo-state todo-state
6109 'priority (org-get-priority txt) 'org-category category
6110 'org-category-position category-pos)
6111 (push txt ee))))
6112 (goto-char pos)))
6113 ;; Sort the entries by expiration date.
6114 (nreverse ee)))
6116 ;;; Agenda presentation and sorting
6118 (defvar org-prefix-has-time nil
6119 "A flag, set by `org-compile-prefix-format'.
6120 The flag is set if the currently compiled format contains a `%t'.")
6121 (defvar org-prefix-has-tag nil
6122 "A flag, set by `org-compile-prefix-format'.
6123 The flag is set if the currently compiled format contains a `%T'.")
6124 (defvar org-prefix-has-effort nil
6125 "A flag, set by `org-compile-prefix-format'.
6126 The flag is set if the currently compiled format contains a `%e'.")
6127 (defvar org-prefix-category-length nil
6128 "Used by `org-compile-prefix-format' to remember the category field width.")
6129 (defvar org-prefix-category-max-length nil
6130 "Used by `org-compile-prefix-format' to remember the category field width.")
6132 (defun org-agenda-get-category-icon (category)
6133 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6134 (dolist (entry org-agenda-category-icon-alist)
6135 (when (org-string-match-p (car entry) category)
6136 (if (listp (cadr entry))
6137 (return (cadr entry))
6138 (return (apply 'create-image (cdr entry)))))))
6140 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6141 remove-re habitp)
6142 "Format TXT to be inserted into the agenda buffer.
6143 In particular, add the prefix and corresponding text properties.
6145 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6146 LEVEL may be a string to replace the `%l' specifier.
6147 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6148 category taken from local variable or file name. It will replace the `%c'
6149 specifier in the format.
6150 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6151 TXT for sorting of this entry, and for the `%t' specifier in the format.
6152 When DOTIME is a string, this string is searched for a time before TXT is.
6153 TAGS can be the tags of the headline.
6154 Any match of REMOVE-RE will be removed from TXT."
6155 ;; We keep the org-prefix-* variable values along with a compiled
6156 ;; formatter, so that multiple agendas existing at the same time do
6157 ;; not step on each other toes.
6159 ;; It was inconvenient to make these variables buffer local in
6160 ;; Agenda buffers, because this function expects to be called with
6161 ;; the buffer where item comes from being current, and not agenda
6162 ;; buffer
6163 (let* ((bindings (car org-prefix-format-compiled))
6164 (formatter (cadr org-prefix-format-compiled)))
6165 (loop for (var value) in bindings
6166 do (set var value))
6167 (save-match-data
6168 ;; Diary entries sometimes have extra whitespace at the beginning
6169 (setq txt (org-trim txt))
6171 ;; Fix the tags part in txt
6172 (setq txt (org-agenda-fix-displayed-tags
6173 txt tags
6174 org-agenda-show-inherited-tags
6175 org-agenda-hide-tags-regexp))
6177 (let* ((category (or category
6178 (if (stringp org-category)
6179 org-category
6180 (and org-category (symbol-name org-category)))
6181 (if buffer-file-name
6182 (file-name-sans-extension
6183 (file-name-nondirectory buffer-file-name))
6184 "")))
6185 (category-icon (org-agenda-get-category-icon category))
6186 (category-icon (if category-icon
6187 (propertize " " 'display category-icon)
6188 ""))
6189 ;; time, tag, effort are needed for the eval of the prefix format
6190 (tag (if tags (nth (1- (length tags)) tags) ""))
6191 time effort neffort
6192 (ts (if dotime (concat
6193 (if (stringp dotime) dotime "")
6194 (and org-agenda-search-headline-for-time txt))))
6195 (time-of-day (and dotime (org-get-time-of-day ts)))
6196 stamp plain s0 s1 s2 rtn srp l
6197 duration thecategory)
6198 (and (derived-mode-p 'org-mode) buffer-file-name
6199 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6200 (when (and dotime time-of-day)
6201 ;; Extract starting and ending time and move them to prefix
6202 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6203 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6204 (setq s0 (match-string 0 ts)
6205 srp (and stamp (match-end 3))
6206 s1 (match-string (if plain 1 2) ts)
6207 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6209 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6210 ;; them, we might want to remove them there to avoid duplication.
6211 ;; The user can turn this off with a variable.
6212 (if (and org-prefix-has-time
6213 org-agenda-remove-times-when-in-prefix (or stamp plain)
6214 (string-match (concat (regexp-quote s0) " *") txt)
6215 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6216 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6217 (= (match-beginning 0) 0)
6219 (setq txt (replace-match "" nil nil txt))))
6220 ;; Normalize the time(s) to 24 hour
6221 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6222 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6224 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6225 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6226 (setq s2
6227 (org-minutes-to-hh:mm-string
6228 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6230 ;; Compute the duration
6231 (when s2
6232 (setq duration (- (org-hh:mm-string-to-minutes s2)
6233 (org-hh:mm-string-to-minutes s1)))))
6235 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6236 txt)
6237 ;; Tags are in the string
6238 (if (or (eq org-agenda-remove-tags t)
6239 (and org-agenda-remove-tags
6240 org-prefix-has-tag))
6241 (setq txt (replace-match "" t t txt))
6242 (setq txt (replace-match
6243 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6244 (match-string 2 txt))
6245 t t txt))))
6246 (when (derived-mode-p 'org-mode)
6247 (setq effort
6248 (condition-case nil
6249 (org-get-effort
6250 (or (get-text-property 0 'org-hd-marker txt)
6251 (get-text-property 0 'org-marker txt)))
6252 (error nil)))
6253 (when effort
6254 (setq neffort (org-duration-string-to-minutes effort)
6255 effort (setq effort (concat "[" effort "]")))))
6256 ;; prevent erroring out with %e format when there is no effort
6257 (or effort (setq effort ""))
6259 (when remove-re
6260 (while (string-match remove-re txt)
6261 (setq txt (replace-match "" t t txt))))
6263 ;; Set org-heading property on `txt' to mark the start of the
6264 ;; heading.
6265 (add-text-properties 0 (length txt) '(org-heading t) txt)
6267 ;; Prepare the variables needed in the eval of the compiled format
6268 (setq time (cond (s2 (concat
6269 (org-agenda-time-of-day-to-ampm-maybe s1)
6270 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6271 (if org-agenda-timegrid-use-ampm " ")))
6272 (s1 (concat
6273 (org-agenda-time-of-day-to-ampm-maybe s1)
6274 (if org-agenda-timegrid-use-ampm
6275 "........ "
6276 "......")))
6277 (t ""))
6278 extra (or (and (not habitp) extra) "")
6279 category (if (symbolp category) (symbol-name category) category)
6280 thecategory (copy-sequence category)
6281 level (or level ""))
6282 (if (string-match org-bracket-link-regexp category)
6283 (progn
6284 (setq l (if (match-end 3)
6285 (- (match-end 3) (match-beginning 3))
6286 (- (match-end 1) (match-beginning 1))))
6287 (when (< l (or org-prefix-category-length 0))
6288 (setq category (copy-sequence category))
6289 (org-add-props category nil
6290 'extra-space (make-string
6291 (- org-prefix-category-length l 1) ?\ ))))
6292 (if (and org-prefix-category-max-length
6293 (>= (length category) org-prefix-category-max-length))
6294 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6295 ;; Evaluate the compiled format
6296 (setq rtn (concat (eval formatter) txt))
6298 ;; And finally add the text properties
6299 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6300 (org-add-props rtn nil
6301 'org-category (if thecategory (downcase thecategory) category)
6302 'tags (mapcar 'org-downcase-keep-props tags)
6303 'org-highest-priority org-highest-priority
6304 'org-lowest-priority org-lowest-priority
6305 'time-of-day time-of-day
6306 'duration duration
6307 'effort effort
6308 'effort-minutes neffort
6309 'txt txt
6310 'level level
6311 'time time
6312 'extra extra
6313 'format org-prefix-format-compiled
6314 'dotime dotime)))))
6316 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6317 "Remove tags string from TXT, and add a modified list of tags.
6318 The modified list may contain inherited tags, and tags matched by
6319 `org-agenda-hide-tags-regexp' will be removed."
6320 (when (or add-inherited hide-re)
6321 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6322 (setq txt (substring txt 0 (match-beginning 0))))
6323 (setq tags
6324 (delq nil
6325 (mapcar (lambda (tg)
6326 (if (or (and hide-re (string-match hide-re tg))
6327 (and (not add-inherited)
6328 (get-text-property 0 'inherited tg)))
6330 tg))
6331 tags)))
6332 (when tags
6333 (let ((have-i (get-text-property 0 'inherited (car tags)))
6335 (setq txt (concat txt " :"
6336 (mapconcat
6337 (lambda (x)
6338 (setq i (get-text-property 0 'inherited x))
6339 (if (and have-i (not i))
6340 (progn
6341 (setq have-i nil)
6342 (concat ":" x))
6344 tags ":")
6345 (if have-i "::" ":"))))))
6346 txt)
6348 (defun org-downcase-keep-props (s)
6349 (let ((props (text-properties-at 0 s)))
6350 (setq s (downcase s))
6351 (add-text-properties 0 (length s) props s)
6354 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6355 (defvar org-agenda-sorting-strategy-selected nil)
6357 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6358 "Add a time-grid for agenda items which need it.
6360 LIST is the list of agenda items formatted by `org-agenda-list'.
6361 NDAYS is the span of the current agenda view.
6362 TODAYP is `t' when the current agenda view is on today."
6363 (catch 'exit
6364 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6365 ((and todayp (member 'today (car org-agenda-time-grid))))
6366 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6367 ((member 'weekly (car org-agenda-time-grid)))
6368 (t (throw 'exit list)))
6369 (let* ((have (delq nil (mapcar
6370 (lambda (x) (get-text-property 1 'time-of-day x))
6371 list)))
6372 (string (nth 1 org-agenda-time-grid))
6373 (gridtimes (nth 2 org-agenda-time-grid))
6374 (req (car org-agenda-time-grid))
6375 (remove (member 'remove-match req))
6376 new time)
6377 (if (and (member 'require-timed req) (not have))
6378 ;; don't show empty grid
6379 (throw 'exit list))
6380 (while (setq time (pop gridtimes))
6381 (unless (and remove (member time have))
6382 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6383 (push (org-agenda-format-item
6384 nil string nil "" nil
6385 (concat (substring time 0 -2) ":" (substring time -2)))
6386 new)
6387 (put-text-property
6388 2 (length (car new)) 'face 'org-time-grid (car new))))
6389 (when (and todayp org-agenda-show-current-time-in-grid)
6390 (push (org-agenda-format-item
6391 nil org-agenda-current-time-string nil "" nil
6392 (format-time-string "%H:%M "))
6393 new)
6394 (put-text-property
6395 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6397 (if (member 'time-up org-agenda-sorting-strategy-selected)
6398 (append new list)
6399 (append list new)))))
6401 (defun org-compile-prefix-format (key)
6402 "Compile the prefix format into a Lisp form that can be evaluated.
6403 The resulting form and associated variable bindings is returned
6404 and stored in the variable `org-prefix-format-compiled'."
6405 (setq org-prefix-has-time nil
6406 org-prefix-has-tag nil
6407 org-prefix-category-length nil
6408 org-prefix-has-effort nil)
6409 (let ((s (cond
6410 ((stringp org-agenda-prefix-format)
6411 org-agenda-prefix-format)
6412 ((assq key org-agenda-prefix-format)
6413 (cdr (assq key org-agenda-prefix-format)))
6414 (t " %-12:c%?-12t% s")))
6415 (start 0)
6416 varform vars var e c f opt)
6417 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
6418 s start)
6419 (setq var (or (cdr (assoc (match-string 4 s)
6420 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6421 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6422 'eval)
6423 c (or (match-string 3 s) "")
6424 opt (match-beginning 1)
6425 start (1+ (match-beginning 0)))
6426 (if (equal var 'time) (setq org-prefix-has-time t))
6427 (if (equal var 'tag) (setq org-prefix-has-tag t))
6428 (if (equal var 'effort) (setq org-prefix-has-effort t))
6429 (setq f (concat "%" (match-string 2 s) "s"))
6430 (when (equal var 'category)
6431 (setq org-prefix-category-length
6432 (floor (abs (string-to-number (match-string 2 s)))))
6433 (setq org-prefix-category-max-length
6434 (let ((x (match-string 2 s)))
6435 (save-match-data
6436 (if (string-match "\\.[0-9]+" x)
6437 (string-to-number (substring (match-string 0 x) 1)))))))
6438 (if (eq var 'eval)
6439 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6440 (if opt
6441 (setq varform
6442 `(if (equal "" ,var)
6444 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6445 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6446 (setq s (replace-match "%s" t nil s))
6447 (push varform vars))
6448 (setq vars (nreverse vars))
6449 (with-current-buffer (or org-agenda-buffer (current-buffer))
6450 (setq org-prefix-format-compiled
6451 (list
6452 `((org-prefix-has-time ,org-prefix-has-time)
6453 (org-prefix-has-tag ,org-prefix-has-tag)
6454 (org-prefix-category-length ,org-prefix-category-length)
6455 (org-prefix-has-effort ,org-prefix-has-effort))
6456 `(format ,s ,@vars))))))
6458 (defun org-set-sorting-strategy (key)
6459 (if (symbolp (car org-agenda-sorting-strategy))
6460 ;; the old format
6461 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6462 (setq org-agenda-sorting-strategy-selected
6463 (or (cdr (assq key org-agenda-sorting-strategy))
6464 (cdr (assq 'agenda org-agenda-sorting-strategy))
6465 '(time-up category-keep priority-down)))))
6467 (defun org-get-time-of-day (s &optional string mod24)
6468 "Check string S for a time of day.
6469 If found, return it as a military time number between 0 and 2400.
6470 If not found, return nil.
6471 The optional STRING argument forces conversion into a 5 character wide string
6472 HH:MM."
6473 (save-match-data
6474 (when
6475 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6476 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6477 (let* ((h (string-to-number (match-string 1 s)))
6478 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6479 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6480 (am-p (equal ampm "am"))
6481 (h1 (cond ((not ampm) h)
6482 ((= h 12) (if am-p 0 12))
6483 (t (+ h (if am-p 0 12)))))
6484 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6485 (mod h1 24) h1))
6486 (t0 (+ (* 100 h2) m))
6487 (t1 (concat (if (>= h1 24) "+" " ")
6488 (if (and org-agenda-time-leading-zero
6489 (< t0 1000)) "0" "")
6490 (if (< t0 100) "0" "")
6491 (if (< t0 10) "0" "")
6492 (int-to-string t0))))
6493 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6495 (defvar org-agenda-before-sorting-filter-function nil
6496 "Function to be applied to agenda items prior to sorting.
6497 Prior to sorting also means just before they are inserted into the agenda.
6499 To aid sorting, you may revisit the original entries and add more text
6500 properties which will later be used by the sorting functions.
6502 The function should take a string argument, an agenda line.
6503 It has access to the text properties in that line, which contain among
6504 other things, the property `org-hd-marker' that points to the entry
6505 where the line comes from. Note that not all lines going into the agenda
6506 have this property, only most.
6508 The function should return the modified string. It is probably best
6509 to ONLY change text properties.
6511 You can also use this function as a filter, by returning nil for lines
6512 you don't want to have in the agenda at all. For this application, you
6513 could bind the variable in the options section of a custom command.")
6515 (defun org-agenda-finalize-entries (list &optional nosort)
6516 "Sort and concatenate the agenda items."
6517 (setq list (mapcar 'org-agenda-highlight-todo list))
6518 (if nosort
6519 list
6520 (when org-agenda-before-sorting-filter-function
6521 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6522 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6524 (defun org-agenda-highlight-todo (x)
6525 (let ((org-done-keywords org-done-keywords-for-agenda)
6526 (case-fold-search nil)
6528 (if (eq x 'line)
6529 (save-excursion
6530 (beginning-of-line 1)
6531 (setq re (org-get-at-bol 'org-todo-regexp))
6532 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6533 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6534 (add-text-properties (match-beginning 0) (match-end 1)
6535 (list 'face (org-get-todo-face 1)))
6536 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6537 (delete-region (match-beginning 1) (1- (match-end 0)))
6538 (goto-char (match-beginning 1))
6539 (insert (format org-agenda-todo-keyword-format s)))))
6540 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6541 (setq re (get-text-property 0 'org-todo-regexp x))
6542 (when (and re
6543 ;; Test `pl' because if there's no heading content,
6544 ;; there's no point matching to highlight. Note
6545 ;; that if we didn't test `pl' first, and there
6546 ;; happened to be no keyword from `org-todo-regexp'
6547 ;; on this heading line, then the `equal' comparison
6548 ;; afterwards would spuriously succeed in the case
6549 ;; where `pl' is nil -- causing an args-out-of-range
6550 ;; error when we try to add text properties to text
6551 ;; that isn't there.
6553 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6554 x pl) pl))
6555 (add-text-properties
6556 (or (match-end 1) (match-end 0)) (match-end 0)
6557 (list 'face (org-get-todo-face (match-string 2 x)))
6559 (when (match-end 1)
6560 (setq x (concat (substring x 0 (match-end 1))
6561 (format org-agenda-todo-keyword-format
6562 (match-string 2 x))
6563 (org-add-props " " (text-properties-at 0 x))
6564 (substring x (match-end 3)))))))
6565 x)))
6567 (defsubst org-cmp-priority (a b)
6568 "Compare the priorities of string A and B."
6569 (let ((pa (or (get-text-property 1 'priority a) 0))
6570 (pb (or (get-text-property 1 'priority b) 0)))
6571 (cond ((> pa pb) +1)
6572 ((< pa pb) -1))))
6574 (defsubst org-cmp-effort (a b)
6575 "Compare the effort values of string A and B."
6576 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6577 (ea (or (get-text-property 1 'effort-minutes a) def))
6578 (eb (or (get-text-property 1 'effort-minutes b) def)))
6579 (cond ((> ea eb) +1)
6580 ((< ea eb) -1))))
6582 (defsubst org-cmp-category (a b)
6583 "Compare the string values of categories of strings A and B."
6584 (let ((ca (or (get-text-property 1 'org-category a) ""))
6585 (cb (or (get-text-property 1 'org-category b) "")))
6586 (cond ((string-lessp ca cb) -1)
6587 ((string-lessp cb ca) +1))))
6589 (defsubst org-cmp-todo-state (a b)
6590 "Compare the todo states of strings A and B."
6591 (let* ((ma (or (get-text-property 1 'org-marker a)
6592 (get-text-property 1 'org-hd-marker a)))
6593 (mb (or (get-text-property 1 'org-marker b)
6594 (get-text-property 1 'org-hd-marker b)))
6595 (fa (and ma (marker-buffer ma)))
6596 (fb (and mb (marker-buffer mb)))
6597 (todo-kwds
6598 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6599 (and fb (with-current-buffer fb org-todo-keywords-1))))
6600 (ta (or (get-text-property 1 'todo-state a) ""))
6601 (tb (or (get-text-property 1 'todo-state b) ""))
6602 (la (- (length (member ta todo-kwds))))
6603 (lb (- (length (member tb todo-kwds))))
6604 (donepa (member ta org-done-keywords-for-agenda))
6605 (donepb (member tb org-done-keywords-for-agenda)))
6606 (cond ((and donepa (not donepb)) -1)
6607 ((and (not donepa) donepb) +1)
6608 ((< la lb) -1)
6609 ((< lb la) +1))))
6611 (defsubst org-cmp-alpha (a b)
6612 "Compare the headlines, alphabetically."
6613 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6614 (plb (text-property-any 0 (length b) 'org-heading t b))
6615 (ta (and pla (substring a pla)))
6616 (tb (and plb (substring b plb))))
6617 (when pla
6618 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6619 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6620 (setq ta (substring ta (match-end 0))))
6621 (setq ta (downcase ta)))
6622 (when plb
6623 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6624 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6625 (setq tb (substring tb (match-end 0))))
6626 (setq tb (downcase tb)))
6627 (cond ((not ta) +1)
6628 ((not tb) -1)
6629 ((string-lessp ta tb) -1)
6630 ((string-lessp tb ta) +1))))
6632 (defsubst org-cmp-tag (a b)
6633 "Compare the string values of the first tags of A and B."
6634 (let ((ta (car (last (get-text-property 1 'tags a))))
6635 (tb (car (last (get-text-property 1 'tags b)))))
6636 (cond ((not ta) +1)
6637 ((not tb) -1)
6638 ((string-lessp ta tb) -1)
6639 ((string-lessp tb ta) +1))))
6641 (defsubst org-cmp-time (a b)
6642 "Compare the time-of-day values of strings A and B."
6643 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6644 (ta (or (get-text-property 1 'time-of-day a) def))
6645 (tb (or (get-text-property 1 'time-of-day b) def)))
6646 (cond ((< ta tb) -1)
6647 ((< tb ta) +1))))
6649 (defsubst org-cmp-habit-p (a b)
6650 "Compare the todo states of strings A and B."
6651 (let ((ha (get-text-property 1 'org-habit-p a))
6652 (hb (get-text-property 1 'org-habit-p b)))
6653 (cond ((and ha (not hb)) -1)
6654 ((and (not ha) hb) +1))))
6656 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6658 (defun org-entries-lessp (a b)
6659 "Predicate for sorting agenda entries."
6660 ;; The following variables will be used when the form is evaluated.
6661 ;; So even though the compiler complains, keep them.
6662 (let* ((ss org-agenda-sorting-strategy-selected)
6663 (time-up (and (org-em 'time-up 'time-down ss)
6664 (org-cmp-time a b)))
6665 (time-down (if time-up (- time-up) nil))
6666 (priority-up (and (org-em 'priority-up 'priority-down ss)
6667 (org-cmp-priority a b)))
6668 (priority-down (if priority-up (- priority-up) nil))
6669 (effort-up (and (org-em 'effort-up 'effort-down ss)
6670 (org-cmp-effort a b)))
6671 (effort-down (if effort-up (- effort-up) nil))
6672 (category-up (and (or (org-em 'category-up 'category-down ss)
6673 (memq 'category-keep ss))
6674 (org-cmp-category a b)))
6675 (category-down (if category-up (- category-up) nil))
6676 (category-keep (if category-up +1 nil))
6677 (tag-up (and (org-em 'tag-up 'tag-down ss)
6678 (org-cmp-tag a b)))
6679 (tag-down (if tag-up (- tag-up) nil))
6680 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6681 (org-cmp-todo-state a b)))
6682 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6683 (habit-up (and (org-em 'habit-up 'habit-down ss)
6684 (org-cmp-habit-p a b)))
6685 (habit-down (if habit-up (- habit-up) nil))
6686 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6687 (org-cmp-alpha a b)))
6688 (alpha-down (if alpha-up (- alpha-up) nil))
6689 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6690 user-defined-up user-defined-down)
6691 (if (and need-user-cmp org-agenda-cmp-user-defined
6692 (functionp org-agenda-cmp-user-defined))
6693 (setq user-defined-up
6694 (funcall org-agenda-cmp-user-defined a b)
6695 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6696 (cdr (assoc
6697 (eval (cons 'or org-agenda-sorting-strategy-selected))
6698 '((-1 . t) (1 . nil) (nil . nil))))))
6700 ;;; Agenda restriction lock
6702 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6703 "Overlay to mark the headline to which agenda commands are restricted.")
6704 (overlay-put org-agenda-restriction-lock-overlay
6705 'face 'org-agenda-restriction-lock)
6706 (overlay-put org-agenda-restriction-lock-overlay
6707 'help-echo "Agendas are currently limited to this subtree.")
6708 (org-detach-overlay org-agenda-restriction-lock-overlay)
6710 (defun org-agenda-set-restriction-lock (&optional type)
6711 "Set restriction lock for agenda, to current subtree or file.
6712 Restriction will be the file if TYPE is `file', or if type is the
6713 universal prefix '(4), or if the cursor is before the first headline
6714 in the file. Otherwise, restriction will be to the current subtree."
6715 (interactive "P")
6716 (and (equal type '(4)) (setq type 'file))
6717 (setq type (cond
6718 (type type)
6719 ((org-at-heading-p) 'subtree)
6720 ((condition-case nil (org-back-to-heading t) (error nil))
6721 'subtree)
6722 (t 'file)))
6723 (if (eq type 'subtree)
6724 (progn
6725 (setq org-agenda-restrict t)
6726 (setq org-agenda-overriding-restriction 'subtree)
6727 (put 'org-agenda-files 'org-restrict
6728 (list (buffer-file-name (buffer-base-buffer))))
6729 (org-back-to-heading t)
6730 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6731 (move-marker org-agenda-restrict-begin (point))
6732 (move-marker org-agenda-restrict-end
6733 (save-excursion (org-end-of-subtree t)))
6734 (message "Locking agenda restriction to subtree"))
6735 (put 'org-agenda-files 'org-restrict
6736 (list (buffer-file-name (buffer-base-buffer))))
6737 (setq org-agenda-restrict nil)
6738 (setq org-agenda-overriding-restriction 'file)
6739 (move-marker org-agenda-restrict-begin nil)
6740 (move-marker org-agenda-restrict-end nil)
6741 (message "Locking agenda restriction to file"))
6742 (setq current-prefix-arg nil)
6743 (org-agenda-maybe-redo))
6745 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6746 "Remove the agenda restriction lock."
6747 (interactive "P")
6748 (org-detach-overlay org-agenda-restriction-lock-overlay)
6749 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6750 (setq org-agenda-overriding-restriction nil)
6751 (setq org-agenda-restrict nil)
6752 (put 'org-agenda-files 'org-restrict nil)
6753 (move-marker org-agenda-restrict-begin nil)
6754 (move-marker org-agenda-restrict-end nil)
6755 (setq current-prefix-arg nil)
6756 (message "Agenda restriction lock removed")
6757 (or noupdate (org-agenda-maybe-redo)))
6759 (defun org-agenda-maybe-redo ()
6760 "If there is any window showing the agenda view, update it."
6761 (let ((w (get-buffer-window org-agenda-buffer-name t))
6762 (w0 (selected-window)))
6763 (when w
6764 (select-window w)
6765 (org-agenda-redo)
6766 (select-window w0)
6767 (if org-agenda-overriding-restriction
6768 (message "Agenda view shifted to new %s restriction"
6769 org-agenda-overriding-restriction)
6770 (message "Agenda restriction lock removed")))))
6772 ;;; Agenda commands
6774 (defun org-agenda-check-type (error &rest types)
6775 "Check if agenda buffer is of allowed type.
6776 If ERROR is non-nil, throw an error, otherwise just return nil."
6777 (if (not org-agenda-type)
6778 (error "No Org agenda currently displayed")
6779 (if (memq org-agenda-type types)
6781 (if error
6782 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6783 nil))))
6785 (defun org-agenda-Quit (&optional arg)
6786 "Exit agenda by removing the window or the buffer."
6787 (interactive)
6788 (if org-agenda-columns-active
6789 (org-columns-quit)
6790 (let ((buf (current-buffer)))
6791 (if (eq org-agenda-window-setup 'other-frame)
6792 (progn
6793 (org-agenda-reset-markers)
6794 (kill-buffer buf)
6795 (org-columns-remove-overlays)
6796 (setq org-agenda-archives-mode nil)
6797 (delete-frame))
6798 (and (not (eq org-agenda-window-setup 'current-window))
6799 (not (one-window-p))
6800 (delete-window))
6801 (org-agenda-reset-markers)
6802 (kill-buffer buf)
6803 (org-columns-remove-overlays)
6804 (setq org-agenda-archives-mode nil)))
6805 ;; Maybe restore the pre-agenda window configuration.
6806 (and org-agenda-restore-windows-after-quit
6807 (not (eq org-agenda-window-setup 'other-frame))
6808 org-agenda-pre-window-conf
6809 (set-window-configuration org-agenda-pre-window-conf)
6810 (setq org-agenda-pre-window-conf nil))))
6812 (defun org-agenda-quit ()
6813 "Exit agenda by killing agenda buffer or burying it when
6814 `org-agenda-sticky' is non-NIL"
6815 (interactive)
6816 (if (and (eq org-indirect-buffer-display 'other-window)
6817 org-last-indirect-buffer)
6818 (delete-window (get-buffer-window org-last-indirect-buffer)))
6819 (if org-agenda-columns-active
6820 (org-columns-quit)
6821 (if org-agenda-sticky
6822 (let ((buf (current-buffer)))
6823 (if (eq org-agenda-window-setup 'other-frame)
6824 (progn
6825 (delete-frame))
6826 (and (not (eq org-agenda-window-setup 'current-window))
6827 (not (one-window-p))
6828 (delete-window)))
6829 (with-current-buffer buf
6830 (bury-buffer)
6831 ;; Maybe restore the pre-agenda window configuration.
6832 (and org-agenda-restore-windows-after-quit
6833 (not (eq org-agenda-window-setup 'other-frame))
6834 org-agenda-pre-window-conf
6835 (set-window-configuration org-agenda-pre-window-conf)
6836 (setq org-agenda-pre-window-conf nil))))
6837 (org-agenda-Quit))))
6839 (defun org-agenda-exit ()
6840 "Exit agenda by removing the window or the buffer.
6841 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6842 Org-mode buffers visited directly by the user will not be touched."
6843 (interactive)
6844 (org-release-buffers org-agenda-new-buffers)
6845 (setq org-agenda-new-buffers nil)
6846 (org-agenda-Quit))
6848 (defun org-agenda-kill-all-agenda-buffers ()
6849 "Kill all buffers in `org-agena-mode'.
6850 This is used when toggling sticky agendas. You can also explicitly invoke it
6851 with `C-c a C-k'."
6852 (interactive)
6853 (let (blist)
6854 (dolist (buf (buffer-list))
6855 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6856 (push buf blist)))
6857 (mapc 'kill-buffer blist)))
6859 (defun org-agenda-execute (arg)
6860 "Execute another agenda command, keeping same window.
6861 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6862 in the agenda."
6863 (interactive "P")
6864 (let ((org-agenda-window-setup 'current-window))
6865 (org-agenda arg)))
6867 (defun org-agenda-redo (&optional all)
6868 "Rebuild possibly ALL agenda view(s) in the current buffer."
6869 (interactive "P")
6870 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6871 (cpa (unless (eq all t) current-prefix-arg))
6872 (org-agenda-doing-sticky-redo org-agenda-sticky)
6873 (org-agenda-sticky nil)
6874 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6875 org-agenda-buffer-name))
6876 (org-agenda-keep-modes t)
6877 (tag-filter org-agenda-tag-filter)
6878 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6879 (top-cat-filter org-agenda-top-category-filter)
6880 (cat-filter org-agenda-category-filter)
6881 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6882 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6883 (cols org-agenda-columns-active)
6884 (line (org-current-line))
6885 (window-line (- line (org-current-line (window-start))))
6886 (lprops (get 'org-agenda-redo-command 'org-lprops))
6887 (redo-cmd (get-text-property p 'org-redo-cmd))
6888 (last-args (get-text-property p 'org-last-args))
6889 (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
6890 (org-agenda-overriding-cmd-arguments
6891 (unless (eq all t)
6892 (cond ((listp last-args)
6893 (cons (or cpa (car last-args)) (cdr last-args)))
6894 ((stringp last-args)
6895 last-args))))
6896 (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
6897 (put 'org-agenda-tag-filter :preset-filter nil)
6898 (put 'org-agenda-category-filter :preset-filter nil)
6899 (and cols (org-columns-quit))
6900 (message "Rebuilding agenda buffer...")
6901 (if serie-redo-cmd
6902 (eval serie-redo-cmd)
6903 (org-let lprops '(eval redo-cmd)))
6904 (setq org-agenda-undo-list nil
6905 org-agenda-pending-undo-list nil)
6906 (message "Rebuilding agenda buffer...done")
6907 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6908 (put 'org-agenda-category-filter :preset-filter cat-preset)
6909 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6910 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6911 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6912 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6913 (org-goto-line line)
6914 (recenter window-line)))
6916 (defvar org-global-tags-completion-table nil)
6917 (defvar org-agenda-filter-form nil)
6918 (defvar org-agenda-filtered-by-category nil)
6920 (defun org-agenda-filter-by-category (strip)
6921 "Keep only those lines in the agenda buffer that have a specific category.
6922 The category is that of the current line."
6923 (interactive "P")
6924 (if (and org-agenda-filtered-by-category
6925 org-agenda-category-filter)
6926 (org-agenda-filter-show-all-cat)
6927 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6928 (if cat (org-agenda-filter-apply
6929 (list (concat (if strip "-" "+") cat)) 'category)
6930 (error "No category at point")))))
6932 (defun org-find-top-category (&optional pos)
6933 (save-excursion
6934 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6935 (if pos (goto-char pos))
6936 ;; Skip up to the topmost parent
6937 (while (ignore-errors (outline-up-heading 1) t))
6938 (ignore-errors
6939 (nth 4 (org-heading-components))))))
6941 (defvar org-agenda-filtered-by-top-category nil)
6943 (defun org-agenda-filter-by-top-category (strip)
6944 "Keep only those lines in the agenda buffer that have a specific category.
6945 The category is that of the current line."
6946 (interactive "P")
6947 (if org-agenda-filtered-by-top-category
6948 (progn
6949 (setq org-agenda-filtered-by-top-category nil
6950 org-agenda-top-category-filter nil)
6951 (org-agenda-filter-show-all-cat))
6952 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6953 (if cat (org-agenda-filter-top-category-apply cat strip)
6954 (error "No top-level category at point")))))
6956 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6957 "Keep only those lines in the agenda buffer that have a specific tag.
6958 The tag is selected with its fast selection letter, as configured.
6959 With prefix argument STRIP, remove all lines that do have the tag.
6960 A lisp caller can specify CHAR. NARROW means that the new tag should be
6961 used to narrow the search - the interactive user can also press `-' or `+'
6962 to switch to narrowing."
6963 (interactive "P")
6964 (let* ((alist org-tag-alist-for-agenda)
6965 (tag-chars (mapconcat
6966 (lambda (x) (if (and (not (symbolp (car x)))
6967 (cdr x))
6968 (char-to-string (cdr x))
6969 ""))
6970 alist ""))
6971 (efforts (org-split-string
6972 (or (cdr (assoc (concat org-effort-property "_ALL")
6973 org-global-properties))
6974 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6975 "")))
6976 (effort-op org-agenda-filter-effort-default-operator)
6977 (effort-prompt "")
6978 (inhibit-read-only t)
6979 (current org-agenda-tag-filter)
6980 maybe-refresh a n tag)
6981 (unless char
6982 (message
6983 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6984 (if narrow "Narrow" "Filter") tag-chars
6985 (if org-agenda-auto-exclude-function "[RET], " ""))
6986 (setq char (read-char-exclusive)))
6987 (when (member char '(?+ ?-))
6988 ;; Narrowing down
6989 (cond ((equal char ?-) (setq strip t narrow t))
6990 ((equal char ?+) (setq strip nil narrow t)))
6991 (message
6992 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6993 (setq char (read-char-exclusive)))
6994 (when (member char '(?< ?> ?= ??))
6995 ;; An effort operator
6996 (setq effort-op (char-to-string char))
6997 (setq alist nil) ; to make sure it will be interpreted as effort.
6998 (unless (equal char ??)
6999 (loop for i from 0 to 9 do
7000 (setq effort-prompt
7001 (concat
7002 effort-prompt " ["
7003 (if (= i 9) "0" (int-to-string (1+ i)))
7004 "]" (nth i efforts))))
7005 (message "Effort%s: %s " effort-op effort-prompt)
7006 (setq char (read-char-exclusive))
7007 (when (or (< char ?0) (> char ?9))
7008 (error "Need 1-9,0 to select effort"))))
7009 (when (equal char ?\t)
7010 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7011 (org-set-local 'org-global-tags-completion-table
7012 (org-global-tags-completion-table)))
7013 (let ((completion-ignore-case t))
7014 (setq tag (org-icompleting-read
7015 "Tag: " org-global-tags-completion-table))))
7016 (cond
7017 ((equal char ?\r)
7018 (org-agenda-filter-show-all-tag)
7019 (when org-agenda-auto-exclude-function
7020 (setq org-agenda-tag-filter '())
7021 (dolist (tag (org-agenda-get-represented-tags))
7022 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7023 (if modifier
7024 (push modifier org-agenda-tag-filter))))
7025 (if (not (null org-agenda-tag-filter))
7026 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7027 (setq maybe-refresh t))
7028 ((equal char ?/)
7029 (org-agenda-filter-show-all-tag)
7030 (when (get 'org-agenda-tag-filter :preset-filter)
7031 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7032 (setq maybe-refresh t))
7033 ((equal char ?. )
7034 (setq org-agenda-tag-filter
7035 (mapcar (lambda(tag) (concat "+" tag))
7036 (org-get-at-bol 'tags)))
7037 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7038 (setq maybe-refresh t))
7039 ((or (equal char ?\ )
7040 (setq a (rassoc char alist))
7041 (and (>= char ?0) (<= char ?9)
7042 (setq n (if (= char ?0) 9 (- char ?0 1))
7043 tag (concat effort-op (nth n efforts))
7044 a (cons tag nil)))
7045 (and (= char ??)
7046 (setq tag "?eff")
7047 a (cons tag nil))
7048 (and tag (setq a (cons tag nil))))
7049 (org-agenda-filter-show-all-tag)
7050 (setq tag (car a))
7051 (setq org-agenda-tag-filter
7052 (cons (concat (if strip "-" "+") tag)
7053 (if narrow current nil)))
7054 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7055 (setq maybe-refresh t))
7056 (t (error "Invalid tag selection character %c" char)))
7057 (when (and maybe-refresh
7058 (eq org-agenda-clockreport-mode 'with-filter))
7059 (org-agenda-redo))))
7061 (defun org-agenda-get-represented-tags ()
7062 "Get a list of all tags currently represented in the agenda."
7063 (let (p tags)
7064 (save-excursion
7065 (goto-char (point-min))
7066 (while (setq p (next-single-property-change (point) 'tags))
7067 (goto-char p)
7068 (mapc (lambda (x) (add-to-list 'tags x))
7069 (get-text-property (point) 'tags))))
7070 tags))
7072 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7073 "Refine the current filter. See `org-agenda-filter-by-tag'."
7074 (interactive "P")
7075 (org-agenda-filter-by-tag strip char 'refine))
7077 (defun org-agenda-filter-make-matcher ()
7078 "Create the form that tests a line for agenda filter."
7079 (let (f f1)
7080 ;; first compute the tag-filter matcher
7081 (dolist (x (delete-dups
7082 (append (get 'org-agenda-tag-filter
7083 :preset-filter) org-agenda-tag-filter)))
7084 (if (member x '("-" "+"))
7085 (setq f1 (if (equal x "-") 'tags '(not tags)))
7086 (if (string-match "[<=>?]" x)
7087 (setq f1 (org-agenda-filter-effort-form x))
7088 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7089 (if (equal (string-to-char x) ?-)
7090 (setq f1 (list 'not f1))))
7091 (push f1 f))
7092 ;; then compute the category-filter matcher
7093 (dolist (x (delete-dups
7094 (append (get 'org-agenda-category-filter
7095 :preset-filter) org-agenda-category-filter)))
7096 (if (equal "-" (substring x 0 1))
7097 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7098 (setq f1 (list 'equal (substring x 1) 'cat)))
7099 (push f1 f))
7100 (cons 'and (nreverse f))))
7102 (defun org-agenda-filter-effort-form (e)
7103 "Return the form to compare the effort of the current line with what E says.
7104 E looks like \"+<2:25\"."
7105 (let (op)
7106 (setq e (substring e 1))
7107 (setq op (string-to-char e) e (substring e 1))
7108 (setq op (cond ((equal op ?<) '<=)
7109 ((equal op ?>) '>=)
7110 ((equal op ??) op)
7111 (t '=)))
7112 (list 'org-agenda-compare-effort (list 'quote op)
7113 (org-duration-string-to-minutes e))))
7115 (defun org-agenda-compare-effort (op value)
7116 "Compare the effort of the current line with VALUE, using OP.
7117 If the line does not have an effort defined, return nil."
7118 (let ((eff (org-get-at-bol 'effort-minutes)))
7119 (if (equal op ??)
7120 (not eff)
7121 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7122 value))))
7124 (defun org-agenda-filter-apply (filter type)
7125 "Set FILTER as the new agenda filter and apply it."
7126 (let (tags cat)
7127 (if (eq type 'tag)
7128 (setq org-agenda-tag-filter filter)
7129 (setq org-agenda-category-filter filter))
7130 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7131 (if (and (eq type 'category)
7132 (not (equal (substring (car filter) 0 1) "-")))
7133 ;; Only set `org-agenda-filtered-by-category' to t
7134 ;; when a unique category is used as the filter
7135 (setq org-agenda-filtered-by-category t))
7136 (org-agenda-set-mode-name)
7137 (save-excursion
7138 (goto-char (point-min))
7139 (while (not (eobp))
7140 (if (org-get-at-bol 'org-marker)
7141 (progn
7142 (setq tags (org-get-at-bol 'tags) ; used in eval
7143 cat (get-text-property (point) 'org-category))
7144 (if (not (eval org-agenda-filter-form))
7145 (org-agenda-filter-hide-line type))
7146 (beginning-of-line 2))
7147 (beginning-of-line 2))))
7148 (if (get-char-property (point) 'invisible)
7149 (ignore-errors (org-agenda-previous-line)))))
7151 (defun org-agenda-filter-top-category-apply (category &optional negative)
7152 "Set FILTER as the new agenda filter and apply it."
7153 (org-agenda-set-mode-name)
7154 (save-excursion
7155 (goto-char (point-min))
7156 (while (not (eobp))
7157 (let* ((pos (org-get-at-bol 'org-hd-marker))
7158 (topcat (and pos (org-find-top-category pos))))
7159 (if (and topcat (funcall (if negative 'identity 'not)
7160 (string= category topcat)))
7161 (org-agenda-filter-hide-line 'category)))
7162 (beginning-of-line 2)))
7163 (if (get-char-property (point) 'invisible)
7164 (org-agenda-previous-line))
7165 (setq org-agenda-top-category-filter category
7166 org-agenda-filtered-by-top-category t))
7168 (defun org-agenda-filter-hide-line (type)
7169 (let (ov)
7170 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7171 (point-at-eol)))
7172 (overlay-put ov 'invisible t)
7173 (overlay-put ov 'type type)
7174 (if (eq type 'tag)
7175 (push ov org-agenda-tag-filter-overlays)
7176 (push ov org-agenda-cat-filter-overlays))))
7178 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7179 (setq pos (or pos (point)))
7180 (save-excursion
7181 (dolist (ov (overlays-at pos))
7182 (when (and (overlay-get ov 'invisible)
7183 (eq (overlay-get ov 'type) 'tag))
7184 (goto-char pos)
7185 (if (< (overlay-start ov) (point-at-eol))
7186 (move-overlay ov (point-at-eol)
7187 (overlay-end ov)))))))
7189 (defun org-agenda-filter-show-all-tag nil
7190 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7191 (setq org-agenda-tag-filter-overlays nil
7192 org-agenda-tag-filter nil
7193 org-agenda-filter-form nil)
7194 (org-agenda-set-mode-name))
7196 (defun org-agenda-filter-show-all-cat nil
7197 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7198 (setq org-agenda-cat-filter-overlays nil
7199 org-agenda-filtered-by-category nil
7200 org-agenda-category-filter nil
7201 org-agenda-filter-form nil)
7202 (org-agenda-set-mode-name))
7204 (defun org-agenda-manipulate-query-add ()
7205 "Manipulate the query by adding a search term with positive selection.
7206 Positive selection means the term must be matched for selection of an entry."
7207 (interactive)
7208 (org-agenda-manipulate-query ?\[))
7209 (defun org-agenda-manipulate-query-subtract ()
7210 "Manipulate the query by adding a search term with negative selection.
7211 Negative selection means term must not be matched for selection of an entry."
7212 (interactive)
7213 (org-agenda-manipulate-query ?\]))
7214 (defun org-agenda-manipulate-query-add-re ()
7215 "Manipulate the query by adding a search regexp with positive selection.
7216 Positive selection means the regexp must match for selection of an entry."
7217 (interactive)
7218 (org-agenda-manipulate-query ?\{))
7219 (defun org-agenda-manipulate-query-subtract-re ()
7220 "Manipulate the query by adding a search regexp with negative selection.
7221 Negative selection means regexp must not match for selection of an entry."
7222 (interactive)
7223 (org-agenda-manipulate-query ?\}))
7224 (defun org-agenda-manipulate-query (char)
7225 (cond
7226 ((memq org-agenda-type '(timeline agenda))
7227 (let ((org-agenda-include-inactive-timestamps t))
7228 (org-agenda-redo))
7229 (message "Display now includes inactive timestamps as well"))
7230 ((eq org-agenda-type 'search)
7231 (org-add-to-string
7232 'org-agenda-query-string
7233 (if org-agenda-last-search-view-search-was-boolean
7234 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7235 (?\{ . " +{}") (?\} . " -{}"))))
7236 " "))
7237 (setq org-agenda-redo-command
7238 (list 'org-search-view
7239 (car (get-text-property (min (1- (point-max)) (point))
7240 'org-last-args))
7241 org-agenda-query-string
7242 (+ (length org-agenda-query-string)
7243 (if (member char '(?\{ ?\})) 0 1))))
7244 (set-register org-agenda-query-register org-agenda-query-string)
7245 (let ((org-agenda-overriding-arguments
7246 (cdr org-agenda-redo-command)))
7247 (org-agenda-redo)))
7248 (t (error "Cannot manipulate query for %s-type agenda buffers"
7249 org-agenda-type))))
7251 (defun org-add-to-string (var string)
7252 (set var (concat (symbol-value var) string)))
7254 (defun org-agenda-goto-date (span)
7255 "Jump to DATE in agenda."
7256 (interactive "P")
7257 (let* ((org-read-date-prefer-future
7258 (eval org-agenda-jump-prefer-future))
7259 (date (org-read-date))
7260 (org-agenda-sticky-orig org-agenda-sticky)
7261 (org-agenda-buffer-tmp-name (buffer-name))
7262 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7263 (0-arg (or current-prefix-arg (car args)))
7264 (2-arg (nth 2 args))
7265 (newcmd (list 'org-agenda-list 0-arg date
7266 (org-agenda-span-to-ndays 2-arg)))
7267 (newargs (cdr newcmd))
7268 (inhibit-read-only t)
7269 org-agenda-sticky)
7270 (if (not (org-agenda-check-type t 'agenda))
7271 (error "Not available in non-agenda blocks")
7272 (add-text-properties (point-min) (point-max)
7273 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7274 (org-agenda-redo)
7275 (setq org-agenda-sticky org-agenda-sticky-orig
7276 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7278 (defun org-agenda-goto-today ()
7279 "Go to today."
7280 (interactive)
7281 (org-agenda-check-type t 'timeline 'agenda)
7282 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7283 (curspan (nth 2 args))
7284 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7285 (cond
7286 (tdpos (goto-char tdpos))
7287 ((eq org-agenda-type 'agenda)
7288 (let* ((sd (org-agenda-compute-starting-span
7289 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7290 (org-agenda-overriding-arguments args))
7291 (setf (nth 1 org-agenda-overriding-arguments) sd)
7292 (org-agenda-redo)
7293 (org-agenda-find-same-or-today-or-agenda)))
7294 (t (error "Cannot find today")))))
7296 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7297 (goto-char
7298 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7299 (text-property-any (point-min) (point-max) 'org-today t)
7300 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7301 (and (get-text-property (min (1- (point-max)) (point)) 'org-serie)
7302 (org-agenda-goto-block-beginning))
7303 (point-min))))
7305 (defun org-agenda-goto-block-beginning ()
7306 "Go the agenda block beginning."
7307 (interactive)
7308 (if (not (derived-mode-p 'org-agenda-mode))
7309 (error "Cannot execute this command outside of org-agenda-mode buffers")
7310 (let (dest)
7311 (save-excursion
7312 (unless (looking-at "\\'")
7313 (forward-char))
7314 (let* ((prop 'org-agenda-structural-header)
7315 (p (previous-single-property-change (point) prop))
7316 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7317 (1- (point))) prop)))
7318 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7319 (if (not dest)
7320 (error "Cannot find the beginning of the blog")
7321 (goto-char dest)
7322 (move-beginning-of-line 1)))))
7324 (defun org-agenda-later (arg)
7325 "Go forward in time by thee current span.
7326 With prefix ARG, go forward that many times the current span."
7327 (interactive "p")
7328 (org-agenda-check-type t 'agenda)
7329 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7330 (span (or (nth 2 args) org-agenda-current-span))
7331 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7332 (greg (calendar-gregorian-from-absolute sd))
7333 (cnt (org-get-at-bol 'org-day-cnt))
7334 greg2)
7335 (cond
7336 ((numberp span)
7337 (setq sd (+ span sd)))
7338 ((eq span 'day)
7339 (setq sd (+ arg sd)))
7340 ((eq span 'week)
7341 (setq sd (+ (* 7 arg) sd)))
7342 ((eq span 'month)
7343 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7344 sd (calendar-absolute-from-gregorian greg2))
7345 (setcar greg2 (1+ (car greg2))))
7346 ((eq span 'year)
7347 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7348 sd (calendar-absolute-from-gregorian greg2))
7349 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7351 (setq sd (+ (* span arg) sd))))
7352 (let ((org-agenda-overriding-cmd
7353 ;; `cmd' may have been set by `org-agenda-run-series' which
7354 ;; uses `org-agenda-overriding-cmd' to decide whether
7355 ;; overriding is allowed for `cmd'
7356 (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
7357 (org-agenda-overriding-arguments
7358 (list (car args) sd span)))
7359 (org-agenda-redo)
7360 (org-agenda-find-same-or-today-or-agenda cnt))))
7362 (defun org-agenda-earlier (arg)
7363 "Go backward in time by the current span.
7364 With prefix ARG, go backward that many times the current span."
7365 (interactive "p")
7366 (org-agenda-later (- arg)))
7368 (defun org-agenda-view-mode-dispatch ()
7369 "Call one of the view mode commands."
7370 (interactive)
7371 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7372 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7373 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7374 (let ((a (read-char-exclusive)))
7375 (case a
7376 (?\ (call-interactively 'org-agenda-reset-view))
7377 (?d (call-interactively 'org-agenda-day-view))
7378 (?w (call-interactively 'org-agenda-week-view))
7379 (?m (call-interactively 'org-agenda-month-view))
7380 (?y (call-interactively 'org-agenda-year-view))
7381 (?l (call-interactively 'org-agenda-log-mode))
7382 (?L (org-agenda-log-mode '(4)))
7383 (?c (org-agenda-log-mode 'clockcheck))
7384 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7385 (?a (call-interactively 'org-agenda-archives-mode))
7386 (?A (org-agenda-archives-mode 'files))
7387 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7388 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7389 (?G (call-interactively 'org-agenda-toggle-time-grid))
7390 (?D (call-interactively 'org-agenda-toggle-diary))
7391 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7392 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7393 (org-agenda-check-type t 'timeline 'agenda)
7394 (org-agenda-redo))
7395 (message "Display now includes inactive timestamps as well"))
7396 (?q (message "Abort"))
7397 (otherwise (error "Invalid key" )))))
7399 (defun org-agenda-reset-view ()
7400 "Switch to default view for agenda."
7401 (interactive)
7402 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7403 (defun org-agenda-day-view (&optional day-of-year)
7404 "Switch to daily view for agenda.
7405 With argument DAY-OF-YEAR, switch to that day of the year."
7406 (interactive "P")
7407 (org-agenda-change-time-span 'day day-of-year))
7408 (defun org-agenda-week-view (&optional iso-week)
7409 "Switch to daily view for agenda.
7410 With argument ISO-WEEK, switch to the corresponding ISO week.
7411 If ISO-WEEK has more then 2 digits, only the last two encode the
7412 week. Any digits before this encode a year. So 200712 means
7413 week 12 of year 2007. Years in the range 1938-2037 can also be
7414 written as 2-digit years."
7415 (interactive "P")
7416 (org-agenda-change-time-span 'week iso-week))
7417 (defun org-agenda-month-view (&optional month)
7418 "Switch to monthly view for agenda.
7419 With argument MONTH, switch to that month."
7420 (interactive "P")
7421 (org-agenda-change-time-span 'month month))
7422 (defun org-agenda-year-view (&optional year)
7423 "Switch to yearly view for agenda.
7424 With argument YEAR, switch to that year.
7425 If MONTH has more then 2 digits, only the last two encode the
7426 month. Any digits before this encode a year. So 200712 means
7427 December year 2007. Years in the range 1938-2037 can also be
7428 written as 2-digit years."
7429 (interactive "P")
7430 (when year
7431 (setq year (org-small-year-to-year year)))
7432 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7433 (org-agenda-change-time-span 'year year)
7434 (error "Abort")))
7436 (defun org-agenda-change-time-span (span &optional n)
7437 "Change the agenda view to SPAN.
7438 SPAN may be `day', `week', `month', `year'."
7439 (org-agenda-check-type t 'agenda)
7440 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7441 (curspan (nth 2 args)))
7442 (if (and (not n) (equal curspan span))
7443 (error "Viewing span is already \"%s\"" span))
7444 (let* ((sd (or (org-get-at-bol 'day)
7445 (nth 1 args)
7446 org-starting-day))
7447 (sd (org-agenda-compute-starting-span sd span n))
7448 (org-agenda-overriding-cmd
7449 (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
7450 (org-agenda-overriding-arguments
7451 (list (car args) sd span)))
7452 (org-agenda-redo)
7453 (org-agenda-find-same-or-today-or-agenda))
7454 (org-agenda-set-mode-name)
7455 (message "Switched to %s view" span)))
7457 (defun org-agenda-compute-starting-span (sd span &optional n)
7458 "Compute starting date for agenda.
7459 SPAN may be `day', `week', `month', `year'. The return value
7460 is a cons cell with the starting date and the number of days,
7461 so that the date SD will be in that range."
7462 (let* ((greg (calendar-gregorian-from-absolute sd))
7463 (dg (nth 1 greg))
7464 (mg (car greg))
7465 (yg (nth 2 greg)))
7466 (cond
7467 ((eq span 'day)
7468 (when n
7469 (setq sd (+ (calendar-absolute-from-gregorian
7470 (list mg 1 yg))
7471 n -1))))
7472 ((eq span 'week)
7473 (let* ((nt (calendar-day-of-week
7474 (calendar-gregorian-from-absolute sd)))
7475 (d (if org-agenda-start-on-weekday
7476 (- nt org-agenda-start-on-weekday)
7479 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7480 (when n
7481 (require 'cal-iso)
7482 (when (> n 99)
7483 (setq y1 (org-small-year-to-year (/ n 100))
7484 n (mod n 100)))
7485 (setq sd
7486 (calendar-absolute-from-iso
7487 (list n 1
7488 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7489 ((eq span 'month)
7490 (let (y1)
7491 (when (and n (> n 99))
7492 (setq y1 (org-small-year-to-year (/ n 100))
7493 n (mod n 100)))
7494 (setq sd (calendar-absolute-from-gregorian
7495 (list (or n mg) 1 (or y1 yg))))))
7496 ((eq span 'year)
7497 (setq sd (calendar-absolute-from-gregorian
7498 (list 1 1 (or n yg))))))
7499 sd))
7501 (defun org-agenda-next-date-line (&optional arg)
7502 "Jump to the next line indicating a date in agenda buffer."
7503 (interactive "p")
7504 (org-agenda-check-type t 'agenda 'timeline)
7505 (beginning-of-line 1)
7506 ;; This does not work if user makes date format that starts with a blank
7507 (if (looking-at "^\\S-") (forward-char 1))
7508 (if (not (re-search-forward "^\\S-" nil t arg))
7509 (progn
7510 (backward-char 1)
7511 (error "No next date after this line in this buffer")))
7512 (goto-char (match-beginning 0)))
7514 (defun org-agenda-previous-date-line (&optional arg)
7515 "Jump to the previous line indicating a date in agenda buffer."
7516 (interactive "p")
7517 (org-agenda-check-type t 'agenda 'timeline)
7518 (beginning-of-line 1)
7519 (if (not (re-search-backward "^\\S-" nil t arg))
7520 (error "No previous date before this line in this buffer")))
7522 ;; Initialize the highlight
7523 (defvar org-hl (make-overlay 1 1))
7524 (overlay-put org-hl 'face 'highlight)
7526 (defun org-highlight (begin end &optional buffer)
7527 "Highlight a region with overlay."
7528 (move-overlay org-hl begin end (or buffer (current-buffer))))
7530 (defun org-unhighlight ()
7531 "Detach overlay INDEX."
7532 (org-detach-overlay org-hl))
7534 (defun org-unhighlight-once ()
7535 "Remove the highlight from its position, and this function from the hook."
7536 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7537 (org-unhighlight))
7539 (defvar org-agenda-pre-follow-window-conf nil)
7540 (defun org-agenda-follow-mode ()
7541 "Toggle follow mode in an agenda buffer."
7542 (interactive)
7543 (unless org-agenda-follow-mode
7544 (setq org-agenda-pre-follow-window-conf
7545 (current-window-configuration)))
7546 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7547 (unless org-agenda-follow-mode
7548 (set-window-configuration org-agenda-pre-follow-window-conf))
7549 (org-agenda-set-mode-name)
7550 (org-agenda-do-context-action)
7551 (message "Follow mode is %s"
7552 (if org-agenda-follow-mode "on" "off")))
7554 (defun org-agenda-entry-text-mode (&optional arg)
7555 "Toggle entry text mode in an agenda buffer."
7556 (interactive "P")
7557 (setq org-agenda-entry-text-mode (or (integerp arg)
7558 (not org-agenda-entry-text-mode)))
7559 (org-agenda-entry-text-hide)
7560 (and org-agenda-entry-text-mode
7561 (let ((org-agenda-entry-text-maxlines
7562 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7563 (org-agenda-entry-text-show)))
7564 (org-agenda-set-mode-name)
7565 (message "Entry text mode is %s. Maximum number of lines is %d"
7566 (if org-agenda-entry-text-mode "on" "off")
7567 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7569 (defun org-agenda-clockreport-mode (&optional with-filter)
7570 "Toggle clocktable mode in an agenda buffer.
7571 With prefix arg WITH-FILTER, make the clocktable respect the current
7572 agenda filter."
7573 (interactive "P")
7574 (org-agenda-check-type t 'agenda)
7575 (if with-filter
7576 (setq org-agenda-clockreport-mode 'with-filter)
7577 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7578 (org-agenda-set-mode-name)
7579 (org-agenda-redo)
7580 (message "Clocktable mode is %s"
7581 (if org-agenda-clockreport-mode "on" "off")))
7583 (defun org-agenda-log-mode (&optional special)
7584 "Toggle log mode in an agenda buffer.
7585 With argument SPECIAL, show all possible log items, not only the ones
7586 configured in `org-agenda-log-mode-items'.
7587 With a double `C-u' prefix arg, show *only* log items, nothing else."
7588 (interactive "P")
7589 (org-agenda-check-type t 'agenda 'timeline)
7590 (setq org-agenda-show-log
7591 (cond
7592 ((equal special '(16)) 'only)
7593 ((eq special 'clockcheck)
7594 (if (eq org-agenda-show-log 'clockcheck)
7595 nil 'clockcheck))
7596 (special '(closed clock state))
7597 (t (not org-agenda-show-log))))
7598 (org-agenda-set-mode-name)
7599 (org-agenda-redo)
7600 (message "Log mode is %s"
7601 (if org-agenda-show-log "on" "off")))
7603 (defun org-agenda-archives-mode (&optional with-files)
7604 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7605 When called with a prefix argument, include all archive files as well."
7606 (interactive "P")
7607 (setq org-agenda-archives-mode
7608 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7609 (org-agenda-set-mode-name)
7610 (org-agenda-redo)
7611 (message
7612 "%s"
7613 (cond
7614 ((eq org-agenda-archives-mode nil)
7615 "No archives are included")
7616 ((eq org-agenda-archives-mode 'trees)
7617 (format "Trees with :%s: tag are included" org-archive-tag))
7618 ((eq org-agenda-archives-mode t)
7619 (format "Trees with :%s: tag and all active archive files are included"
7620 org-archive-tag)))))
7622 (defun org-agenda-toggle-diary ()
7623 "Toggle diary inclusion in an agenda buffer."
7624 (interactive)
7625 (org-agenda-check-type t 'agenda)
7626 (setq org-agenda-include-diary (not org-agenda-include-diary))
7627 (org-agenda-redo)
7628 (org-agenda-set-mode-name)
7629 (message "Diary inclusion turned %s"
7630 (if org-agenda-include-diary "on" "off")))
7632 (defun org-agenda-toggle-deadlines ()
7633 "Toggle inclusion of entries with a deadline in an agenda buffer."
7634 (interactive)
7635 (org-agenda-check-type t 'agenda)
7636 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7637 (org-agenda-redo)
7638 (org-agenda-set-mode-name)
7639 (message "Deadlines inclusion turned %s"
7640 (if org-agenda-include-deadlines "on" "off")))
7642 (defun org-agenda-toggle-time-grid ()
7643 "Toggle time grid in an agenda buffer."
7644 (interactive)
7645 (org-agenda-check-type t 'agenda)
7646 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7647 (org-agenda-redo)
7648 (org-agenda-set-mode-name)
7649 (message "Time-grid turned %s"
7650 (if org-agenda-use-time-grid "on" "off")))
7652 (defun org-agenda-set-mode-name ()
7653 "Set the mode name to indicate all the small mode settings."
7654 (setq mode-name
7655 (list "Org-Agenda"
7656 (if (get 'org-agenda-files 'org-restrict) " []" "")
7658 '(:eval (org-agenda-span-name org-agenda-current-span))
7659 (if org-agenda-follow-mode " Follow" "")
7660 (if org-agenda-entry-text-mode " ETxt" "")
7661 (if org-agenda-include-diary " Diary" "")
7662 (if org-agenda-include-deadlines " Ddl" "")
7663 (if org-agenda-use-time-grid " Grid" "")
7664 (if (and (boundp 'org-habit-show-habits)
7665 org-habit-show-habits) " Habit" "")
7666 (cond
7667 ((consp org-agenda-show-log) " LogAll")
7668 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7669 (org-agenda-show-log " Log")
7670 (t ""))
7671 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7672 :preset-filter))
7673 '(:eval (org-propertize
7674 (concat " <"
7675 (mapconcat
7676 'identity
7677 (append
7678 (get 'org-agenda-category-filter :preset-filter)
7679 org-agenda-category-filter)
7681 ">")
7682 'face 'org-agenda-filter-category
7683 'help-echo "Category used in filtering"))
7685 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7686 :preset-filter))
7687 '(:eval (org-propertize
7688 (concat " {"
7689 (mapconcat
7690 'identity
7691 (append
7692 (get 'org-agenda-tag-filter :preset-filter)
7693 org-agenda-tag-filter)
7695 "}")
7696 'face 'org-agenda-filter-tags
7697 'help-echo "Tags used in filtering"))
7699 (if org-agenda-archives-mode
7700 (if (eq org-agenda-archives-mode t)
7701 " Archives"
7702 (format " :%s:" org-archive-tag))
7704 (if org-agenda-clockreport-mode
7705 (if (eq org-agenda-clockreport-mode 'with-filter)
7706 " Clock{}" " Clock")
7707 "")))
7708 (force-mode-line-update))
7710 (define-obsolete-function-alias
7711 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7713 (defun org-agenda-update-agenda-type ()
7714 "Update the agenda type after each command."
7715 (setq org-agenda-type
7716 (or (get-text-property (point) 'org-agenda-type)
7717 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7719 (defun org-agenda-next-line ()
7720 "Move cursor to the next line, and show if follow mode is active."
7721 (interactive)
7722 (call-interactively 'next-line)
7723 (org-agenda-do-context-action))
7725 (defun org-agenda-previous-line ()
7726 "Move cursor to the previous line, and show if follow-mode is active."
7727 (interactive)
7728 (call-interactively 'previous-line)
7729 (org-agenda-do-context-action))
7731 (defun org-agenda-next-item (n)
7732 "Move cursor to next agenda item."
7733 (interactive "p")
7734 (let ((col (current-column)))
7735 (dotimes (c n)
7736 (when (next-single-property-change (point-at-eol) 'org-marker)
7737 (move-end-of-line 1)
7738 (goto-char (next-single-property-change (point) 'org-marker))))
7739 (org-move-to-column col))
7740 (org-agenda-do-context-action))
7742 (defun org-agenda-previous-item (n)
7743 "Move cursor to next agenda item."
7744 (interactive "p")
7745 (dotimes (c n)
7746 (let ((col (current-column))
7747 (goto (save-excursion
7748 (move-end-of-line 0)
7749 (previous-single-property-change (point) 'org-marker))))
7750 (if goto (goto-char goto))
7751 (org-move-to-column col)))
7752 (org-agenda-do-context-action))
7754 (defun org-agenda-do-context-action ()
7755 "Show outline path and, maybe, follow mode window."
7756 (let ((m (org-get-at-bol 'org-marker)))
7757 (when (and (markerp m) (marker-buffer m))
7758 (and org-agenda-follow-mode
7759 (if org-agenda-follow-indirect
7760 (org-agenda-tree-to-indirect-buffer nil)
7761 (org-agenda-show)))
7762 (and org-agenda-show-outline-path
7763 (org-with-point-at m (org-display-outline-path t))))))
7765 (defun org-agenda-show-tags ()
7766 "Show the tags applicable to the current item."
7767 (interactive)
7768 (let* ((tags (org-get-at-bol 'tags)))
7769 (if tags
7770 (message "Tags are :%s:"
7771 (org-no-properties (mapconcat 'identity tags ":")))
7772 (message "No tags associated with this line"))))
7774 (defun org-agenda-goto (&optional highlight)
7775 "Go to the Org-mode file which contains the item at point."
7776 (interactive)
7777 (let* ((marker (or (org-get-at-bol 'org-marker)
7778 (org-agenda-error)))
7779 (buffer (marker-buffer marker))
7780 (pos (marker-position marker)))
7781 (switch-to-buffer-other-window buffer)
7782 (widen)
7783 (push-mark)
7784 (goto-char pos)
7785 (when (derived-mode-p 'org-mode)
7786 (org-show-context 'agenda)
7787 (save-excursion
7788 (and (outline-next-heading)
7789 (org-flag-heading nil)))) ; show the next heading
7790 (when (outline-invisible-p)
7791 (show-entry)) ; display invisible text
7792 (recenter (/ (window-height) 2))
7793 (run-hooks 'org-agenda-after-show-hook)
7794 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7796 (defvar org-agenda-after-show-hook nil
7797 "Normal hook run after an item has been shown from the agenda.
7798 Point is in the buffer where the item originated.")
7800 (defun org-agenda-kill ()
7801 "Kill the entry or subtree belonging to the current agenda entry."
7802 (interactive)
7803 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7804 (let* ((bufname-orig (buffer-name))
7805 (marker (or (org-get-at-bol 'org-marker)
7806 (org-agenda-error)))
7807 (buffer (marker-buffer marker))
7808 (pos (marker-position marker))
7809 (type (org-get-at-bol 'type))
7810 dbeg dend (n 0) conf)
7811 (org-with-remote-undo buffer
7812 (with-current-buffer buffer
7813 (save-excursion
7814 (goto-char pos)
7815 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7816 (setq dbeg (progn (org-back-to-heading t) (point))
7817 dend (org-end-of-subtree t t))
7818 (setq dbeg (point-at-bol)
7819 dend (min (point-max) (1+ (point-at-eol)))))
7820 (goto-char dbeg)
7821 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7822 (setq conf (or (eq t org-agenda-confirm-kill)
7823 (and (numberp org-agenda-confirm-kill)
7824 (> n org-agenda-confirm-kill))))
7825 (and conf
7826 (not (y-or-n-p
7827 (format "Delete entry with %d lines in buffer \"%s\"? "
7828 n (buffer-name buffer))))
7829 (error "Abort"))
7830 (let ((org-agenda-buffer-name bufname-orig))
7831 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7832 (with-current-buffer buffer (delete-region dbeg dend))
7833 (message "Agenda item and source killed"))))
7835 (defvar org-archive-default-command) ; defined in org-archive.el
7836 (defun org-agenda-archive-default ()
7837 "Archive the entry or subtree belonging to the current agenda entry."
7838 (interactive)
7839 (require 'org-archive)
7840 (org-agenda-archive-with org-archive-default-command))
7842 (defun org-agenda-archive-default-with-confirmation ()
7843 "Archive the entry or subtree belonging to the current agenda entry."
7844 (interactive)
7845 (require 'org-archive)
7846 (org-agenda-archive-with org-archive-default-command 'confirm))
7848 (defun org-agenda-archive ()
7849 "Archive the entry or subtree belonging to the current agenda entry."
7850 (interactive)
7851 (org-agenda-archive-with 'org-archive-subtree))
7853 (defun org-agenda-archive-to-archive-sibling ()
7854 "Move the entry to the archive sibling."
7855 (interactive)
7856 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7858 (defun org-agenda-archive-with (cmd &optional confirm)
7859 "Move the entry to the archive sibling."
7860 (interactive)
7861 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7862 (let* ((bufname-orig (buffer-name))
7863 (marker (or (org-get-at-bol 'org-marker)
7864 (org-agenda-error)))
7865 (buffer (marker-buffer marker))
7866 (pos (marker-position marker)))
7867 (org-with-remote-undo buffer
7868 (with-current-buffer buffer
7869 (if (derived-mode-p 'org-mode)
7870 (if (and confirm
7871 (not (y-or-n-p "Archive this subtree or entry? ")))
7872 (error "Abort")
7873 (save-excursion
7874 (goto-char pos)
7875 (let ((org-agenda-buffer-name bufname-orig))
7876 (org-remove-subtree-entries-from-agenda))
7877 (org-back-to-heading t)
7878 (funcall cmd)))
7879 (error "Archiving works only in Org-mode files"))))))
7881 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7882 "Remove all lines in the agenda that correspond to a given subtree.
7883 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7884 If this information is not given, the function uses the tree at point."
7885 (let ((buf (or buf (current-buffer))) m p)
7886 (save-excursion
7887 (unless (and beg end)
7888 (org-back-to-heading t)
7889 (setq beg (point))
7890 (org-end-of-subtree t)
7891 (setq end (point)))
7892 (set-buffer (get-buffer org-agenda-buffer-name))
7893 (save-excursion
7894 (goto-char (point-max))
7895 (beginning-of-line 1)
7896 (while (not (bobp))
7897 (when (and (setq m (org-get-at-bol 'org-marker))
7898 (equal buf (marker-buffer m))
7899 (setq p (marker-position m))
7900 (>= p beg)
7901 (< p end))
7902 (let ((inhibit-read-only t))
7903 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7904 (beginning-of-line 0))))))
7906 (defun org-agenda-refile (&optional goto rfloc no-update)
7907 "Refile the item at point."
7908 (interactive "P")
7909 (if (equal goto '(16))
7910 (org-refile-goto-last-stored)
7911 (let* ((buffer-orig (buffer-name))
7912 (marker (or (org-get-at-bol 'org-hd-marker)
7913 (org-agenda-error)))
7914 (buffer (marker-buffer marker))
7915 (pos (marker-position marker))
7916 (rfloc (or rfloc
7917 (org-refile-get-location
7918 (if goto "Goto" "Refile to") buffer
7919 org-refile-allow-creating-parent-nodes))))
7920 (with-current-buffer buffer
7921 (save-excursion
7922 (save-restriction
7923 (widen)
7924 (goto-char marker)
7925 (let ((org-agenda-buffer-name buffer-orig))
7926 (org-remove-subtree-entries-from-agenda))
7927 (org-refile goto buffer rfloc)))))
7928 (unless no-update (org-agenda-redo))))
7930 (defun org-agenda-open-link (&optional arg)
7931 "Follow the link in the current line, if any.
7932 This looks for a link in the displayed line in the agenda. It also looks
7933 at the text of the entry itself."
7934 (interactive "P")
7935 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7936 (org-get-at-bol 'org-marker)))
7937 (buffer (and marker (marker-buffer marker)))
7938 (prefix (buffer-substring
7939 (point-at-bol) (point-at-eol))))
7940 (cond
7941 (buffer
7942 (with-current-buffer buffer
7943 (save-excursion
7944 (save-restriction
7945 (widen)
7946 (goto-char marker)
7947 (org-offer-links-in-entry arg prefix)))))
7948 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7949 (save-excursion
7950 (beginning-of-line 1)
7951 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7952 (org-open-link-from-string (match-string 1)))
7953 (t (error "No link to open here")))))
7955 (defun org-agenda-copy-local-variable (var)
7956 "Get a variable from a referenced buffer and install it here."
7957 (let ((m (org-get-at-bol 'org-marker)))
7958 (when (and m (buffer-live-p (marker-buffer m)))
7959 (org-set-local var (with-current-buffer (marker-buffer m)
7960 (symbol-value var))))))
7962 (defun org-agenda-switch-to (&optional delete-other-windows)
7963 "Go to the Org-mode file which contains the item at point."
7964 (interactive)
7965 (if (and org-return-follows-link
7966 (not (org-get-at-bol 'org-marker))
7967 (org-in-regexp org-bracket-link-regexp))
7968 (org-open-link-from-string (match-string 0))
7969 (let* ((marker (or (org-get-at-bol 'org-marker)
7970 (org-agenda-error)))
7971 (buffer (marker-buffer marker))
7972 (pos (marker-position marker)))
7973 (org-pop-to-buffer-same-window buffer)
7974 (and delete-other-windows (delete-other-windows))
7975 (widen)
7976 (goto-char pos)
7977 (when (derived-mode-p 'org-mode)
7978 (org-show-context 'agenda)
7979 (save-excursion
7980 (and (outline-next-heading)
7981 (org-flag-heading nil))) ; show the next heading
7982 (when (outline-invisible-p)
7983 (show-entry)) ; display invisible text
7984 (run-hooks 'org-agenda-after-show-hook)))))
7986 (defun org-agenda-goto-mouse (ev)
7987 "Go to the Org-mode file which contains the item at the mouse click."
7988 (interactive "e")
7989 (mouse-set-point ev)
7990 (org-agenda-goto))
7992 (defun org-agenda-show (&optional full-entry)
7993 "Display the Org-mode file which contains the item at point.
7994 With prefix argument FULL-ENTRY, make the entire entry visible
7995 if it was hidden in the outline."
7996 (interactive "P")
7997 (let ((win (selected-window)))
7998 (if full-entry
7999 (let ((org-show-entry-below t))
8000 (org-agenda-goto t))
8001 (org-agenda-goto t))
8002 (select-window win)))
8004 (defvar org-agenda-show-window nil)
8005 (defun org-agenda-show-and-scroll-up (&optional arg)
8006 "Display the Org-mode file which contains the item at point.
8007 When called repeatedly, scroll the window that is displaying the buffer.
8008 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8009 `show-subtree' to display the item, so that drawers and logbooks stay
8010 folded."
8011 (interactive "P")
8012 (let ((win (selected-window)))
8013 (if (and (window-live-p org-agenda-show-window)
8014 (eq this-command last-command))
8015 (progn
8016 (select-window org-agenda-show-window)
8017 (ignore-errors (scroll-up)))
8018 (org-agenda-goto t)
8019 (if arg (org-show-entry) (show-subtree))
8020 (setq org-agenda-show-window (selected-window)))
8021 (select-window win)))
8023 (defun org-agenda-show-scroll-down ()
8024 "Scroll down the window showing the agenda."
8025 (interactive)
8026 (let ((win (selected-window)))
8027 (when (window-live-p org-agenda-show-window)
8028 (select-window org-agenda-show-window)
8029 (ignore-errors (scroll-down))
8030 (select-window win))))
8032 (defun org-agenda-show-1 (&optional more)
8033 "Display the Org-mode file which contains the item at point.
8034 The prefix arg selects the amount of information to display:
8036 0 hide the subtree
8037 1 just show the entry according to defaults.
8038 2 show the children view
8039 3 show the subtree view
8040 4 show the entire subtree and any LOGBOOK drawers
8041 5 show the entire subtree and any drawers
8042 With prefix argument FULL-ENTRY, make the entire entry visible
8043 if it was hidden in the outline."
8044 (interactive "p")
8045 (let ((win (selected-window)))
8046 (org-agenda-goto t)
8047 (org-recenter-heading 1)
8048 (cond
8049 ((= more 0)
8050 (hide-subtree)
8051 (save-excursion
8052 (org-back-to-heading)
8053 (run-hook-with-args 'org-cycle-hook 'folded))
8054 (message "Remote: FOLDED"))
8055 ((and (org-called-interactively-p 'any) (= more 1))
8056 (message "Remote: show with default settings"))
8057 ((= more 2)
8058 (show-entry)
8059 (show-children)
8060 (save-excursion
8061 (org-back-to-heading)
8062 (run-hook-with-args 'org-cycle-hook 'children))
8063 (message "Remote: CHILDREN"))
8064 ((= more 3)
8065 (show-subtree)
8066 (save-excursion
8067 (org-back-to-heading)
8068 (run-hook-with-args 'org-cycle-hook 'subtree))
8069 (message "Remote: SUBTREE"))
8070 ((= more 4)
8071 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8072 (org-drawer-regexp
8073 (concat "^[ \t]*:\\("
8074 (mapconcat 'regexp-quote org-drawers "\\|")
8075 "\\):[ \t]*$")))
8076 (show-subtree)
8077 (save-excursion
8078 (org-back-to-heading)
8079 (org-cycle-hide-drawers 'subtree)))
8080 (message "Remote: SUBTREE AND LOGBOOK"))
8081 ((> more 4)
8082 (show-subtree)
8083 (message "Remote: SUBTREE AND ALL DRAWERS")))
8084 (select-window win)))
8086 (defun org-recenter-heading (n)
8087 (save-excursion
8088 (org-back-to-heading)
8089 (recenter n)))
8091 (defvar org-agenda-cycle-counter nil)
8092 (defun org-agenda-cycle-show (&optional n)
8093 "Show the current entry in another window, with default settings.
8094 Default settings are taken from `org-show-hierarchy-above' and siblings.
8095 When use repeatedly in immediate succession, the remote entry will cycle
8096 through visibility
8098 children -> subtree -> folded
8100 When called with a numeric prefix arg, that arg will be passed through to
8101 `org-agenda-show-1'. For the interpretation of that argument, see the
8102 docstring of `org-agenda-show-1'."
8103 (interactive "P")
8104 (if (integerp n)
8105 (setq org-agenda-cycle-counter n)
8106 (if (not (eq last-command this-command))
8107 (setq org-agenda-cycle-counter 1)
8108 (if (equal org-agenda-cycle-counter 0)
8109 (setq org-agenda-cycle-counter 2)
8110 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8111 (if (> org-agenda-cycle-counter 3)
8112 (setq org-agenda-cycle-counter 0)))))
8113 (org-agenda-show-1 org-agenda-cycle-counter))
8115 (defun org-agenda-recenter (arg)
8116 "Display the Org-mode file which contains the item at point and recenter."
8117 (interactive "P")
8118 (let ((win (selected-window)))
8119 (org-agenda-goto t)
8120 (recenter arg)
8121 (select-window win)))
8123 (defun org-agenda-show-mouse (ev)
8124 "Display the Org-mode file which contains the item at the mouse click."
8125 (interactive "e")
8126 (mouse-set-point ev)
8127 (org-agenda-show))
8129 (defun org-agenda-check-no-diary ()
8130 "Check if the entry is a diary link and abort if yes."
8131 (if (org-get-at-bol 'org-agenda-diary-link)
8132 (org-agenda-error)))
8134 (defun org-agenda-error ()
8135 (error "Command not allowed in this line"))
8137 (defun org-agenda-tree-to-indirect-buffer (arg)
8138 "Show the subtree corresponding to the current entry in an indirect buffer.
8139 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8141 With a numerical prefix ARG, go up to this level and then take that tree.
8142 With a negative numeric ARG, go up by this number of levels.
8143 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8144 use the dedicated frame)."
8145 (interactive "P")
8146 (if current-prefix-arg
8147 (org-agenda-do-tree-to-indirect-buffer arg)
8148 (let ((agenda-buffer (buffer-name))
8149 (agenda-window (selected-window))
8150 (indirect-window
8151 (and org-last-indirect-buffer
8152 (get-buffer-window org-last-indirect-buffer))))
8153 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8154 (unless (or (eq org-indirect-buffer-display 'new-frame)
8155 (eq org-indirect-buffer-display 'dedicated-frame))
8156 (unwind-protect
8157 (unless (and indirect-window (window-live-p indirect-window))
8158 (setq indirect-window (split-window agenda-window)))
8159 (and indirect-window (select-window indirect-window))
8160 (switch-to-buffer org-last-indirect-buffer :norecord)
8161 (fit-window-to-buffer indirect-window)))
8162 (select-window (get-buffer-window agenda-buffer)))))
8164 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8165 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8166 (org-agenda-check-no-diary)
8167 (let* ((marker (or (org-get-at-bol 'org-marker)
8168 (org-agenda-error)))
8169 (buffer (marker-buffer marker))
8170 (pos (marker-position marker)))
8171 (with-current-buffer buffer
8172 (save-excursion
8173 (goto-char pos)
8174 (funcall 'org-tree-to-indirect-buffer arg)))))
8176 (defvar org-last-heading-marker (make-marker)
8177 "Marker pointing to the headline that last changed its TODO state
8178 by a remote command from the agenda.")
8180 (defun org-agenda-todo-nextset ()
8181 "Switch TODO entry to next sequence."
8182 (interactive)
8183 (org-agenda-todo 'nextset))
8185 (defun org-agenda-todo-previousset ()
8186 "Switch TODO entry to previous sequence."
8187 (interactive)
8188 (org-agenda-todo 'previousset))
8190 (defun org-agenda-todo (&optional arg)
8191 "Cycle TODO state of line at point, also in Org-mode file.
8192 This changes the line at point, all other lines in the agenda referring to
8193 the same tree node, and the headline of the tree node in the Org-mode file."
8194 (interactive "P")
8195 (org-agenda-check-no-diary)
8196 (let* ((col (current-column))
8197 (marker (or (org-get-at-bol 'org-marker)
8198 (org-agenda-error)))
8199 (buffer (marker-buffer marker))
8200 (pos (marker-position marker))
8201 (hdmarker (org-get-at-bol 'org-hd-marker))
8202 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8203 (inhibit-read-only t)
8204 org-agenda-headline-snapshot-before-repeat newhead just-one)
8205 (org-with-remote-undo buffer
8206 (with-current-buffer buffer
8207 (widen)
8208 (goto-char pos)
8209 (org-show-context 'agenda)
8210 (save-excursion
8211 (and (outline-next-heading)
8212 (org-flag-heading nil))) ; show the next heading
8213 (let ((current-prefix-arg arg))
8214 (call-interactively 'org-todo))
8215 (and (bolp) (forward-char 1))
8216 (setq newhead (org-get-heading))
8217 (when (and (org-bound-and-true-p
8218 org-agenda-headline-snapshot-before-repeat)
8219 (not (equal org-agenda-headline-snapshot-before-repeat
8220 newhead))
8221 todayp)
8222 (setq newhead org-agenda-headline-snapshot-before-repeat
8223 just-one t))
8224 (save-excursion
8225 (org-back-to-heading)
8226 (move-marker org-last-heading-marker (point))))
8227 (beginning-of-line 1)
8228 (save-excursion
8229 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8230 (org-move-to-column col))))
8232 (defun org-agenda-add-note (&optional arg)
8233 "Add a time-stamped note to the entry at point."
8234 (interactive "P")
8235 (org-agenda-check-no-diary)
8236 (let* ((marker (or (org-get-at-bol 'org-marker)
8237 (org-agenda-error)))
8238 (buffer (marker-buffer marker))
8239 (pos (marker-position marker))
8240 (hdmarker (org-get-at-bol 'org-hd-marker))
8241 (inhibit-read-only t))
8242 (with-current-buffer buffer
8243 (widen)
8244 (goto-char pos)
8245 (org-show-context 'agenda)
8246 (save-excursion
8247 (and (outline-next-heading)
8248 (org-flag-heading nil))) ; show the next heading
8249 (org-add-note))))
8251 (defun org-agenda-change-all-lines (newhead hdmarker
8252 &optional fixface just-this)
8253 "Change all lines in the agenda buffer which match HDMARKER.
8254 The new content of the line will be NEWHEAD (as modified by
8255 `org-agenda-format-item'). HDMARKER is checked with
8256 `equal' against all `org-hd-marker' text properties in the file.
8257 If FIXFACE is non-nil, the face of each item is modified according to
8258 the new TODO state.
8259 If JUST-THIS is non-nil, change just the current line, not all.
8260 If FORCE-TAGS is non nil, the car of it returns the new tags."
8261 (let* ((inhibit-read-only t)
8262 (line (org-current-line))
8263 (org-agenda-buffer (current-buffer))
8264 (thetags (with-current-buffer (marker-buffer hdmarker)
8265 (save-excursion (save-restriction (widen)
8266 (goto-char hdmarker)
8267 (org-get-tags-at)))))
8268 props m pl undone-face done-face finish new dotime level cat tags)
8269 (save-excursion
8270 (goto-char (point-max))
8271 (beginning-of-line 1)
8272 (while (not finish)
8273 (setq finish (bobp))
8274 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8275 (or (not just-this) (= (org-current-line) line))
8276 (equal m hdmarker))
8277 (setq props (text-properties-at (point))
8278 dotime (org-get-at-bol 'dotime)
8279 cat (org-get-at-bol 'org-category)
8280 level (org-get-at-bol 'level)
8281 tags thetags
8283 (let ((org-prefix-format-compiled
8284 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8285 org-prefix-format-compiled))
8286 (extra (org-get-at-bol 'extra)))
8287 (with-current-buffer (marker-buffer hdmarker)
8288 (save-excursion
8289 (save-restriction
8290 (widen)
8291 (org-agenda-format-item extra newhead level cat tags dotime)))))
8292 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8293 undone-face (org-get-at-bol 'undone-face)
8294 done-face (org-get-at-bol 'done-face))
8295 (beginning-of-line 1)
8296 (cond
8297 ((equal new "")
8298 (and (looking-at ".*\n?") (replace-match "")))
8299 ((looking-at ".*")
8300 (replace-match new t t)
8301 (beginning-of-line 1)
8302 (add-text-properties (point-at-bol) (point-at-eol) props)
8303 (when fixface
8304 (add-text-properties
8305 (point-at-bol) (point-at-eol)
8306 (list 'face
8307 (if org-last-todo-state-is-todo
8308 undone-face done-face))))
8309 (org-agenda-highlight-todo 'line)
8310 (beginning-of-line 1))
8311 (t (error "Line update did not work")))
8312 (save-restriction
8313 (narrow-to-region (point-at-bol) (point-at-eol))
8314 (org-agenda-finalize)))
8315 (beginning-of-line 0)))))
8317 (defun org-agenda-align-tags (&optional line)
8318 "Align all tags in agenda items to `org-agenda-tags-column'."
8319 (let ((inhibit-read-only t) l c)
8320 (save-excursion
8321 (goto-char (if line (point-at-bol) (point-min)))
8322 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8323 (if line (point-at-eol) nil) t)
8324 (add-text-properties
8325 (match-beginning 2) (match-end 2)
8326 (list 'face (delq nil (let ((prop (get-text-property
8327 (match-beginning 2) 'face)))
8328 (or (listp prop) (setq prop (list prop)))
8329 (if (memq 'org-tag prop)
8330 prop
8331 (cons 'org-tag prop))))))
8332 (setq l (- (match-end 2) (match-beginning 2))
8333 c (if (< org-agenda-tags-column 0)
8334 (- (abs org-agenda-tags-column) l)
8335 org-agenda-tags-column))
8336 (delete-region (match-beginning 1) (match-end 1))
8337 (goto-char (match-beginning 1))
8338 (insert (org-add-props
8339 (make-string (max 1 (- c (current-column))) ?\ )
8340 (plist-put (copy-sequence (text-properties-at (point)))
8341 'face nil))))
8342 (goto-char (point-min))
8343 (org-font-lock-add-tag-faces (point-max)))))
8345 (defun org-agenda-priority-up ()
8346 "Increase the priority of line at point, also in Org-mode file."
8347 (interactive)
8348 (org-agenda-priority 'up))
8350 (defun org-agenda-priority-down ()
8351 "Decrease the priority of line at point, also in Org-mode file."
8352 (interactive)
8353 (org-agenda-priority 'down))
8355 (defun org-agenda-priority (&optional force-direction show)
8356 "Set the priority of line at point, also in Org-mode file.
8357 This changes the line at point, all other lines in the agenda referring to
8358 the same tree node, and the headline of the tree node in the Org-mode file."
8359 (interactive "P")
8360 (if (equal force-direction '(4)) (setq show t))
8361 (unless org-enable-priority-commands
8362 (error "Priority commands are disabled"))
8363 (org-agenda-check-no-diary)
8364 (let* ((marker (or (org-get-at-bol 'org-marker)
8365 (org-agenda-error)))
8366 (hdmarker (org-get-at-bol 'org-hd-marker))
8367 (buffer (marker-buffer hdmarker))
8368 (pos (marker-position hdmarker))
8369 (inhibit-read-only t)
8370 newhead)
8371 (org-with-remote-undo buffer
8372 (with-current-buffer buffer
8373 (widen)
8374 (goto-char pos)
8375 (org-show-context 'agenda)
8376 (save-excursion
8377 (and (outline-next-heading)
8378 (org-flag-heading nil))) ; show the next heading
8379 (funcall 'org-priority force-direction show)
8380 (end-of-line 1)
8381 (setq newhead (org-get-heading)))
8382 (org-agenda-change-all-lines newhead hdmarker)
8383 (beginning-of-line 1))))
8385 ;; FIXME: should fix the tags property of the agenda line.
8386 (defun org-agenda-set-tags (&optional tag onoff)
8387 "Set tags for the current headline."
8388 (interactive)
8389 (org-agenda-check-no-diary)
8390 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8391 (call-interactively 'org-change-tag-in-region)
8392 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8393 (org-agenda-error)))
8394 (buffer (marker-buffer hdmarker))
8395 (pos (marker-position hdmarker))
8396 (inhibit-read-only t)
8397 newhead)
8398 (org-with-remote-undo buffer
8399 (with-current-buffer buffer
8400 (widen)
8401 (goto-char pos)
8402 (save-excursion
8403 (org-show-context 'agenda))
8404 (save-excursion
8405 (and (outline-next-heading)
8406 (org-flag-heading nil))) ; show the next heading
8407 (goto-char pos)
8408 (if tag
8409 (org-toggle-tag tag onoff)
8410 (call-interactively 'org-set-tags))
8411 (end-of-line 1)
8412 (setq newhead (org-get-heading)))
8413 (org-agenda-change-all-lines newhead hdmarker)
8414 (beginning-of-line 1)))))
8416 (defun org-agenda-set-property ()
8417 "Set a property for the current headline."
8418 (interactive)
8419 (org-agenda-check-no-diary)
8420 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8421 (org-agenda-error)))
8422 (buffer (marker-buffer hdmarker))
8423 (pos (marker-position hdmarker))
8424 (inhibit-read-only t)
8425 newhead)
8426 (org-with-remote-undo buffer
8427 (with-current-buffer buffer
8428 (widen)
8429 (goto-char pos)
8430 (save-excursion
8431 (org-show-context 'agenda))
8432 (save-excursion
8433 (and (outline-next-heading)
8434 (org-flag-heading nil))) ; show the next heading
8435 (goto-char pos)
8436 (call-interactively 'org-set-property)))))
8438 (defun org-agenda-set-effort ()
8439 "Set the effort property for the current headline."
8440 (interactive)
8441 (org-agenda-check-no-diary)
8442 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8443 (org-agenda-error)))
8444 (buffer (marker-buffer hdmarker))
8445 (pos (marker-position hdmarker))
8446 (inhibit-read-only t)
8447 newhead)
8448 (org-with-remote-undo buffer
8449 (with-current-buffer buffer
8450 (widen)
8451 (goto-char pos)
8452 (save-excursion
8453 (org-show-context 'agenda))
8454 (save-excursion
8455 (and (outline-next-heading)
8456 (org-flag-heading nil))) ; show the next heading
8457 (goto-char pos)
8458 (call-interactively 'org-set-effort)
8459 (end-of-line 1)
8460 (setq newhead (org-get-heading)))
8461 (org-agenda-change-all-lines newhead hdmarker))))
8463 (defun org-agenda-toggle-archive-tag ()
8464 "Toggle the archive tag for the current entry."
8465 (interactive)
8466 (org-agenda-check-no-diary)
8467 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8468 (org-agenda-error)))
8469 (buffer (marker-buffer hdmarker))
8470 (pos (marker-position hdmarker))
8471 (inhibit-read-only t)
8472 newhead)
8473 (org-with-remote-undo buffer
8474 (with-current-buffer buffer
8475 (widen)
8476 (goto-char pos)
8477 (org-show-context 'agenda)
8478 (save-excursion
8479 (and (outline-next-heading)
8480 (org-flag-heading nil))) ; show the next heading
8481 (call-interactively 'org-toggle-archive-tag)
8482 (end-of-line 1)
8483 (setq newhead (org-get-heading)))
8484 (org-agenda-change-all-lines newhead hdmarker)
8485 (beginning-of-line 1))))
8487 (defun org-agenda-do-date-later (arg)
8488 (interactive "P")
8489 (cond
8490 ((or (equal arg '(16))
8491 (memq last-command
8492 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8493 (setq this-command 'org-agenda-date-later-minutes)
8494 (org-agenda-date-later-minutes 1))
8495 ((or (equal arg '(4))
8496 (memq last-command
8497 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8498 (setq this-command 'org-agenda-date-later-hours)
8499 (org-agenda-date-later-hours 1))
8501 (org-agenda-date-later (prefix-numeric-value arg)))))
8503 (defun org-agenda-do-date-earlier (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-earlier-minutes)
8510 (org-agenda-date-earlier-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-earlier-hours)
8515 (org-agenda-date-earlier-hours 1))
8517 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8519 (defun org-agenda-date-later (arg &optional what)
8520 "Change the date of this item to ARG day(s) later."
8521 (interactive "p")
8522 (org-agenda-check-type t 'agenda 'timeline)
8523 (org-agenda-check-no-diary)
8524 (let* ((marker (or (org-get-at-bol 'org-marker)
8525 (org-agenda-error)))
8526 (buffer (marker-buffer marker))
8527 (pos (marker-position marker))
8528 cdate today)
8529 (org-with-remote-undo buffer
8530 (with-current-buffer buffer
8531 (widen)
8532 (goto-char pos)
8533 (if (not (org-at-timestamp-p))
8534 (error "Cannot find time stamp"))
8535 (when (and org-agenda-move-date-from-past-immediately-to-today
8536 (equal arg 1)
8537 (or (not what) (eq what 'day))
8538 (not (save-match-data (org-at-date-range-p))))
8539 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8540 cdate (calendar-absolute-from-gregorian
8541 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8542 today (org-today))
8543 (if (> today cdate)
8544 ;; immediately shift to today
8545 (setq arg (- today cdate))))
8546 (org-timestamp-change arg (or what 'day))
8547 (when (and (org-at-date-range-p)
8548 (re-search-backward org-tr-regexp-both (point-at-bol)))
8549 (let ((end org-last-changed-timestamp))
8550 (org-timestamp-change arg (or what 'day))
8551 (setq org-last-changed-timestamp
8552 (concat org-last-changed-timestamp "--" end)))))
8553 (org-agenda-show-new-time marker org-last-changed-timestamp))
8554 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8556 (defun org-agenda-date-earlier (arg &optional what)
8557 "Change the date of this item to ARG day(s) earlier."
8558 (interactive "p")
8559 (org-agenda-date-later (- arg) what))
8561 (defun org-agenda-date-later-minutes (arg)
8562 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8563 (interactive "p")
8564 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8565 (org-agenda-date-later arg 'minute))
8567 (defun org-agenda-date-earlier-minutes (arg)
8568 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8569 (interactive "p")
8570 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8571 (org-agenda-date-earlier arg 'minute))
8573 (defun org-agenda-date-later-hours (arg)
8574 "Change the time of this item, in hour steps."
8575 (interactive "p")
8576 (org-agenda-date-later arg 'hour))
8578 (defun org-agenda-date-earlier-hours (arg)
8579 "Change the time of this item, in hour steps."
8580 (interactive "p")
8581 (org-agenda-date-earlier arg 'hour))
8583 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8584 "Show new date stamp via text properties."
8585 ;; We use text properties to make this undoable
8586 (let ((inhibit-read-only t)
8587 (buffer-invisibility-spec))
8588 (setq stamp (concat " " prefix " => " stamp))
8589 (save-excursion
8590 (goto-char (point-max))
8591 (while (not (bobp))
8592 (when (equal marker (org-get-at-bol 'org-marker))
8593 (org-move-to-column (- (window-width) (length stamp)) t)
8594 (org-agenda-fix-tags-filter-overlays-at (point))
8595 (if (featurep 'xemacs)
8596 ;; Use `duplicable' property to trigger undo recording
8597 (let ((ex (make-extent nil nil))
8598 (gl (make-glyph stamp)))
8599 (set-glyph-face gl 'secondary-selection)
8600 (set-extent-properties
8601 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8602 (insert-extent ex (1- (point)) (point-at-eol)))
8603 (add-text-properties
8604 (1- (point)) (point-at-eol)
8605 (list 'display (org-add-props stamp nil
8606 'face 'secondary-selection))))
8607 (beginning-of-line 1))
8608 (beginning-of-line 0)))))
8610 (defun org-agenda-date-prompt (arg)
8611 "Change the date of this item. Date is prompted for, with default today.
8612 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8613 be used to request time specification in the time stamp."
8614 (interactive "P")
8615 (org-agenda-check-type t 'agenda 'timeline)
8616 (org-agenda-check-no-diary)
8617 (let* ((marker (or (org-get-at-bol 'org-marker)
8618 (org-agenda-error)))
8619 (buffer (marker-buffer marker))
8620 (pos (marker-position marker)))
8621 (org-with-remote-undo buffer
8622 (with-current-buffer buffer
8623 (widen)
8624 (goto-char pos)
8625 (if (not (org-at-timestamp-p t))
8626 (error "Cannot find time stamp"))
8627 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8628 (org-agenda-show-new-time marker org-last-changed-timestamp))
8629 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8631 (defun org-agenda-schedule (arg &optional time)
8632 "Schedule the item at point.
8633 ARG is passed through to `org-schedule'."
8634 (interactive "P")
8635 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8636 (org-agenda-check-no-diary)
8637 (let* ((marker (or (org-get-at-bol 'org-marker)
8638 (org-agenda-error)))
8639 (type (marker-insertion-type marker))
8640 (buffer (marker-buffer marker))
8641 (pos (marker-position marker))
8642 (org-insert-labeled-timestamps-at-point nil)
8644 (set-marker-insertion-type marker t)
8645 (org-with-remote-undo buffer
8646 (with-current-buffer buffer
8647 (widen)
8648 (goto-char pos)
8649 (setq ts (org-schedule arg time)))
8650 (org-agenda-show-new-time marker ts "S"))
8651 (message "Item scheduled for %s" ts)))
8653 (defun org-agenda-deadline (arg &optional time)
8654 "Schedule the item at point.
8655 ARG is passed through to `org-deadline'."
8656 (interactive "P")
8657 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8658 (org-agenda-check-no-diary)
8659 (let* ((marker (or (org-get-at-bol 'org-marker)
8660 (org-agenda-error)))
8661 (buffer (marker-buffer marker))
8662 (pos (marker-position marker))
8663 (org-insert-labeled-timestamps-at-point nil)
8665 (org-with-remote-undo buffer
8666 (with-current-buffer buffer
8667 (widen)
8668 (goto-char pos)
8669 (setq ts (org-deadline arg time)))
8670 (org-agenda-show-new-time marker ts "D"))
8671 (message "Deadline for this item set to %s" ts)))
8673 (defun org-agenda-clock-in (&optional arg)
8674 "Start the clock on the currently selected item."
8675 (interactive "P")
8676 (org-agenda-check-no-diary)
8677 (if (equal arg '(4))
8678 (org-clock-in arg)
8679 (let* ((marker (or (org-get-at-bol 'org-marker)
8680 (org-agenda-error)))
8681 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8682 marker))
8683 (pos (marker-position marker))
8684 newhead)
8685 (org-with-remote-undo (marker-buffer marker)
8686 (with-current-buffer (marker-buffer marker)
8687 (widen)
8688 (goto-char pos)
8689 (org-show-context 'agenda)
8690 (org-show-entry)
8691 (org-cycle-hide-drawers 'children)
8692 (org-clock-in arg)
8693 (setq newhead (org-get-heading)))
8694 (org-agenda-change-all-lines newhead hdmarker)))))
8696 (defun org-agenda-clock-out ()
8697 "Stop the currently running clock."
8698 (interactive)
8699 (unless (marker-buffer org-clock-marker)
8700 (error "No running clock"))
8701 (let ((marker (make-marker)) newhead)
8702 (org-with-remote-undo (marker-buffer org-clock-marker)
8703 (with-current-buffer (marker-buffer org-clock-marker)
8704 (save-excursion
8705 (save-restriction
8706 (widen)
8707 (goto-char org-clock-marker)
8708 (org-back-to-heading t)
8709 (move-marker marker (point))
8710 (org-clock-out)
8711 (setq newhead (org-get-heading))))))
8712 (org-agenda-change-all-lines newhead marker)
8713 (move-marker marker nil)))
8715 (defun org-agenda-clock-cancel (&optional arg)
8716 "Cancel the currently running clock."
8717 (interactive "P")
8718 (unless (marker-buffer org-clock-marker)
8719 (error "No running clock"))
8720 (org-with-remote-undo (marker-buffer org-clock-marker)
8721 (org-clock-cancel)))
8723 (defun org-agenda-clock-goto ()
8724 "Jump to the currently clocked in task within the agenda.
8725 If the currently clocked in task is not listed in the agenda
8726 buffer, display it in another window."
8727 (interactive)
8728 (let (pos)
8729 (mapc (lambda (o)
8730 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8731 (setq pos (overlay-start o))))
8732 (overlays-in (point-min) (point-max)))
8733 (cond (pos (goto-char pos))
8734 ;; If the currently clocked entry is not in the agenda
8735 ;; buffer, we visit it in another window:
8736 (org-clock-current-task
8737 (org-switch-to-buffer-other-window (org-clock-goto)))
8738 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8740 (defun org-agenda-diary-entry-in-org-file ()
8741 "Make a diary entry in the file `org-agenda-diary-file'."
8742 (let (d1 d2 char (text "") dp1 dp2)
8743 (if (equal (buffer-name) "*Calendar*")
8744 (setq d1 (calendar-cursor-to-date t)
8745 d2 (car calendar-mark-ring))
8746 (setq dp1 (get-text-property (point-at-bol) 'day))
8747 (unless dp1 (error "No date defined in current line"))
8748 (setq d1 (calendar-gregorian-from-absolute dp1)
8749 d2 (and (ignore-errors (mark))
8750 (save-excursion
8751 (goto-char (mark))
8752 (setq dp2 (get-text-property (point-at-bol) 'day)))
8753 (calendar-gregorian-from-absolute dp2))))
8754 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8755 (setq char (read-char-exclusive))
8756 (cond
8757 ((equal char ?d)
8758 (setq text (read-string "Day entry: "))
8759 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8760 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8761 ((equal char ?a)
8762 (setq d1 (list (car d1) (nth 1 d1)
8763 (read-number (format "Reference year [%d]: " (nth 2 d1))
8764 (nth 2 d1))))
8765 (setq text (read-string "Anniversary (use %d to show years): "))
8766 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8767 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8768 ((equal char ?b)
8769 (setq text (read-string "Block entry: "))
8770 (unless (and d1 d2 (not (equal d1 d2)))
8771 (error "No block of days selected"))
8772 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8773 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8774 ((equal char ?j)
8775 (org-switch-to-buffer-other-window
8776 (find-file-noselect org-agenda-diary-file))
8777 (require 'org-datetree)
8778 (org-datetree-find-date-create d1)
8779 (org-reveal t))
8780 (t (error "Invalid selection character `%c'" char)))))
8782 (defcustom org-agenda-insert-diary-strategy 'date-tree
8783 "Where in `org-agenda-diary-file' should new entries be added?
8784 Valid values:
8786 date-tree in the date tree, as child of the date
8787 top-level as top-level entries at the end of the file."
8788 :group 'org-agenda
8789 :type '(choice
8790 (const :tag "in a date tree" date-tree)
8791 (const :tag "as top level at end of file" top-level)))
8793 (defcustom org-agenda-insert-diary-extract-time nil
8794 "Non-nil means extract any time specification from the diary entry."
8795 :group 'org-agenda
8796 :version "24.1"
8797 :type 'boolean)
8799 (defcustom org-agenda-bulk-mark-char ">"
8800 "A single-character string to be used as the bulk mark."
8801 :group 'org-agenda
8802 :version "24.1"
8803 :type 'string)
8805 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8806 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8807 If TEXT is not empty, it will become the headline of the new entry, and
8808 the resulting entry will not be shown. When TEXT is empty, switch to
8809 `org-agenda-diary-file' and let the user finish the entry there."
8810 (let ((cw (current-window-configuration)))
8811 (org-switch-to-buffer-other-window
8812 (find-file-noselect org-agenda-diary-file))
8813 (widen)
8814 (goto-char (point-min))
8815 (cond
8816 ((eq type 'anniversary)
8817 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8818 (progn
8819 (or (org-at-heading-p t)
8820 (progn
8821 (outline-next-heading)
8822 (insert "* Anniversaries\n\n")
8823 (beginning-of-line -1)))))
8824 (outline-next-heading)
8825 (org-back-over-empty-lines)
8826 (backward-char 1)
8827 (insert "\n")
8828 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8829 (nth 2 d1) (car d1) (nth 1 d1) text)))
8830 ((eq type 'day)
8831 (let ((org-prefix-has-time t)
8832 (org-agenda-time-leading-zero t)
8833 fmt time time2)
8834 (if org-agenda-insert-diary-extract-time
8835 ;; Use org-agenda-format-item to parse text for a time-range and
8836 ;; remove it. FIXME: This is a hack, we should refactor
8837 ;; that function to make time extraction available separately
8838 (setq fmt (org-agenda-format-item nil text nil nil nil t)
8839 time (get-text-property 0 'time fmt)
8840 time2 (if (> (length time) 0)
8841 ;; split-string removes trailing ...... if
8842 ;; no end time given. First space
8843 ;; separates time from date.
8844 (concat " " (car (split-string time "\\.")))
8845 nil)
8846 text (get-text-property 0 'txt fmt)))
8847 (if (eq org-agenda-insert-diary-strategy 'top-level)
8848 (org-agenda-insert-diary-as-top-level text)
8849 (require 'org-datetree)
8850 (org-datetree-find-date-create d1)
8851 (org-agenda-insert-diary-make-new-entry text))
8852 (org-insert-time-stamp (org-time-from-absolute
8853 (calendar-absolute-from-gregorian d1))
8854 nil nil nil nil time2))
8855 (end-of-line 0))
8856 ((eq type 'block)
8857 (if (> (calendar-absolute-from-gregorian d1)
8858 (calendar-absolute-from-gregorian d2))
8859 (setq d1 (prog1 d2 (setq d2 d1))))
8860 (if (eq org-agenda-insert-diary-strategy 'top-level)
8861 (org-agenda-insert-diary-as-top-level text)
8862 (require 'org-datetree)
8863 (org-datetree-find-date-create d1)
8864 (org-agenda-insert-diary-make-new-entry text))
8865 (org-insert-time-stamp (org-time-from-absolute
8866 (calendar-absolute-from-gregorian d1)))
8867 (insert "--")
8868 (org-insert-time-stamp (org-time-from-absolute
8869 (calendar-absolute-from-gregorian d2)))
8870 (end-of-line 0)))
8871 (if (string-match "\\S-" text)
8872 (progn
8873 (set-window-configuration cw)
8874 (message "%s entry added to %s"
8875 (capitalize (symbol-name type))
8876 (abbreviate-file-name org-agenda-diary-file)))
8877 (org-reveal t)
8878 (message "Please finish entry here"))))
8880 (defun org-agenda-insert-diary-as-top-level (text)
8881 "Make new entry as a top-level entry at the end of the file.
8882 Add TEXT as headline, and position the cursor in the second line so that
8883 a timestamp can be added there."
8884 (widen)
8885 (goto-char (point-max))
8886 (or (bolp) (insert "\n"))
8887 (insert "* " text "\n")
8888 (if org-adapt-indentation (org-indent-to-column 2)))
8890 (defun org-agenda-insert-diary-make-new-entry (text)
8891 "Make new entry as last child of current entry.
8892 Add TEXT as headline, and position the cursor in the second line so that
8893 a timestamp can be added there."
8894 (let ((org-show-following-heading t)
8895 (org-show-siblings t)
8896 (org-show-hierarchy-above t)
8897 (org-show-entry-below t)
8898 col)
8899 (outline-next-heading)
8900 (org-back-over-empty-lines)
8901 (or (looking-at "[ \t]*$")
8902 (progn (insert "\n") (backward-char 1)))
8903 (org-insert-heading nil t)
8904 (org-do-demote)
8905 (setq col (current-column))
8906 (insert text "\n")
8907 (if org-adapt-indentation (org-indent-to-column col))
8908 (let ((org-show-following-heading t)
8909 (org-show-siblings t)
8910 (org-show-hierarchy-above t)
8911 (org-show-entry-below t))
8912 (org-show-context))))
8914 (defun org-agenda-diary-entry ()
8915 "Make a diary entry, like the `i' command from the calendar.
8916 All the standard commands work: block, weekly etc.
8917 When `org-agenda-diary-file' points to a file,
8918 `org-agenda-diary-entry-in-org-file' is called instead to create
8919 entries in that Org-mode file."
8920 (interactive)
8921 (if (not (eq org-agenda-diary-file 'diary-file))
8922 (org-agenda-diary-entry-in-org-file)
8923 (require 'diary-lib)
8924 (let* ((char (progn
8925 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8926 (read-char-exclusive)))
8927 (cmd (cdr (assoc char
8928 '((?d . insert-diary-entry)
8929 (?w . insert-weekly-diary-entry)
8930 (?m . insert-monthly-diary-entry)
8931 (?y . insert-yearly-diary-entry)
8932 (?a . insert-anniversary-diary-entry)
8933 (?b . insert-block-diary-entry)
8934 (?c . insert-cyclic-diary-entry)))))
8935 (oldf (symbol-function 'calendar-cursor-to-date))
8936 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8937 (point (point))
8938 (mark (or (mark t) (point))))
8939 (unless cmd
8940 (error "No command associated with <%c>" char))
8941 (unless (and (get-text-property point 'day)
8942 (or (not (equal ?b char))
8943 (get-text-property mark 'day)))
8944 (error "Don't know which date to use for diary entry"))
8945 ;; We implement this by hacking the `calendar-cursor-to-date' function
8946 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8947 (let ((calendar-mark-ring
8948 (list (calendar-gregorian-from-absolute
8949 (or (get-text-property mark 'day)
8950 (get-text-property point 'day))))))
8951 (unwind-protect
8952 (progn
8953 (fset 'calendar-cursor-to-date
8954 (lambda (&optional error dummy)
8955 (calendar-gregorian-from-absolute
8956 (get-text-property point 'day))))
8957 (call-interactively cmd))
8958 (fset 'calendar-cursor-to-date oldf))))))
8960 (defun org-agenda-execute-calendar-command (cmd)
8961 "Execute a calendar command from the agenda with date from cursor."
8962 (org-agenda-check-type t 'agenda 'timeline)
8963 (require 'diary-lib)
8964 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
8965 (error "Don't know which date to use for the calendar command"))
8966 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8967 (point (point))
8968 (date (calendar-gregorian-from-absolute
8969 (get-text-property point 'day)))
8970 ;; the following 2 vars are needed in the calendar
8971 (displayed-month (car date))
8972 (displayed-year (nth 2 date)))
8973 (unwind-protect
8974 (progn
8975 (fset 'calendar-cursor-to-date
8976 (lambda (&optional error dummy)
8977 (calendar-gregorian-from-absolute
8978 (get-text-property point 'day))))
8979 (call-interactively cmd))
8980 (fset 'calendar-cursor-to-date oldf))))
8982 (defun org-agenda-phases-of-moon ()
8983 "Display the phases of the moon for the 3 months around the cursor date."
8984 (interactive)
8985 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8987 (defun org-agenda-holidays ()
8988 "Display the holidays for the 3 months around the cursor date."
8989 (interactive)
8990 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8992 (defvar calendar-longitude) ; defined in calendar.el
8993 (defvar calendar-latitude) ; defined in calendar.el
8994 (defvar calendar-location-name) ; defined in calendar.el
8996 (defun org-agenda-sunrise-sunset (arg)
8997 "Display sunrise and sunset for the cursor date.
8998 Latitude and longitude can be specified with the variables
8999 `calendar-latitude' and `calendar-longitude'. When called with prefix
9000 argument, latitude and longitude will be prompted for."
9001 (interactive "P")
9002 (require 'solar)
9003 (let ((calendar-longitude (if arg nil calendar-longitude))
9004 (calendar-latitude (if arg nil calendar-latitude))
9005 (calendar-location-name
9006 (if arg "the given coordinates" calendar-location-name)))
9007 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9009 (defun org-agenda-goto-calendar ()
9010 "Open the Emacs calendar with the date at the cursor."
9011 (interactive)
9012 (org-agenda-check-type t 'agenda 'timeline)
9013 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9014 (error "Don't know which date to open in calendar")))
9015 (date (calendar-gregorian-from-absolute day))
9016 (calendar-move-hook nil)
9017 (calendar-view-holidays-initially-flag nil)
9018 (calendar-view-diary-initially-flag nil))
9019 (calendar)
9020 (calendar-goto-date date)))
9022 ;;;###autoload
9023 (defun org-calendar-goto-agenda ()
9024 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9025 This is a command that has to be installed in `calendar-mode-map'."
9026 (interactive)
9027 (org-agenda-list nil (calendar-absolute-from-gregorian
9028 (calendar-cursor-to-date))
9029 nil))
9031 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9032 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9033 This is a command that has to be installed in `calendar-mode-map'.
9035 \(fn)" t nil)
9037 (defun org-agenda-convert-date ()
9038 (interactive)
9039 (org-agenda-check-type t 'agenda 'timeline)
9040 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9041 date s)
9042 (unless day
9043 (error "Don't know which date to convert"))
9044 (setq date (calendar-gregorian-from-absolute day))
9045 (setq s (concat
9046 "Gregorian: " (calendar-date-string date) "\n"
9047 "ISO: " (calendar-iso-date-string date) "\n"
9048 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9049 "Julian: " (calendar-julian-date-string date) "\n"
9050 "Astron. JD: " (calendar-astro-date-string date)
9051 " (Julian date number at noon UTC)\n"
9052 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9053 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9054 "French: " (calendar-french-date-string date) "\n"
9055 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9056 "Mayan: " (calendar-mayan-date-string date) "\n"
9057 "Coptic: " (calendar-coptic-date-string date) "\n"
9058 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9059 "Persian: " (calendar-persian-date-string date) "\n"
9060 "Chinese: " (calendar-chinese-date-string date) "\n"))
9061 (with-output-to-temp-buffer "*Dates*"
9062 (princ s))
9063 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9065 ;;; Bulk commands
9067 (defun org-agenda-bulk-marked-p ()
9068 (eq (get-char-property (point-at-bol) 'type)
9069 'org-marked-entry-overlay))
9071 (defun org-agenda-bulk-mark (&optional arg)
9072 "Mark the entry at point for future bulk action."
9073 (interactive "p")
9074 (dotimes (i (or arg 1))
9075 (unless (org-get-at-bol 'org-agenda-diary-link)
9076 (let* ((m (org-get-at-bol 'org-hd-marker))
9078 (unless (org-agenda-bulk-marked-p)
9079 (unless m (error "Nothing to mark at point"))
9080 (push m org-agenda-bulk-marked-entries)
9081 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9082 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9083 (org-get-todo-face "TODO")
9084 'evaporate)
9085 (overlay-put ov 'type 'org-marked-entry-overlay))
9086 (beginning-of-line 2)
9087 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9088 (beginning-of-line 2))
9089 (message "%d entries marked for bulk action"
9090 (length org-agenda-bulk-marked-entries))))))
9092 (defun org-agenda-bulk-mark-all ()
9093 "Mark all entries for future agenda bulk action."
9094 (interactive)
9095 (org-agenda-bulk-mark-regexp "."))
9097 (defun org-agenda-bulk-mark-regexp (regexp)
9098 "Mark entries matching REGEXP for future agenda bulk action."
9099 (interactive "sMark entries matching regexp: ")
9100 (let ((entries-marked 0))
9101 (save-excursion
9102 (goto-char (point-min))
9103 (goto-char (next-single-property-change (point) 'txt))
9104 (while (re-search-forward regexp nil t)
9105 (when (string-match regexp (get-text-property (point) 'txt))
9106 (setq entries-marked (1+ entries-marked))
9107 (call-interactively 'org-agenda-bulk-mark))))
9108 (if (not entries-marked)
9109 (message "No entry matching this regexp."))))
9111 (defun org-agenda-bulk-unmark (&optional arg)
9112 "Unmark the entry at point for future bulk action."
9113 (interactive "P")
9114 (if arg
9115 (org-agenda-bulk-unmark-all)
9116 (cond ((org-agenda-bulk-marked-p)
9117 (org-agenda-bulk-remove-overlays
9118 (point-at-bol) (+ 2 (point-at-bol)))
9119 (setq org-agenda-bulk-marked-entries
9120 (delete (org-get-at-bol 'org-hd-marker)
9121 org-agenda-bulk-marked-entries))
9122 (beginning-of-line 2)
9123 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9124 (beginning-of-line 2))
9125 (message "%d entries left marked for bulk action"
9126 (length org-agenda-bulk-marked-entries)))
9127 (t (message "No entry to unmark here")))))
9129 (defun org-agenda-bulk-toggle ()
9130 "Toggle marking the entry at point for bulk action."
9131 (interactive)
9132 (if (org-agenda-bulk-marked-p)
9133 (org-agenda-bulk-unmark)
9134 (org-agenda-bulk-mark)))
9136 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9137 "Remove the mark overlays between BEG and END in the agenda buffer.
9138 BEG and END default to the buffer limits.
9140 This only removes the overlays, it does not remove the markers
9141 from the list in `org-agenda-bulk-marked-entries'."
9142 (interactive)
9143 (mapc (lambda (ov)
9144 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9145 (delete-overlay ov)))
9146 (overlays-in (or beg (point-min)) (or end (point-max)))))
9148 (defun org-agenda-bulk-unmark-all ()
9149 "Remove all marks in the agenda buffer.
9150 This will remove the markers and the overlays."
9151 (interactive)
9152 (if (null org-agenda-bulk-marked-entries)
9153 (message "No entry to unmark")
9154 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9155 (setq org-agenda-bulk-marked-entries nil)
9156 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9158 (defcustom org-agenda-persistent-marks nil
9159 "Non-nil means marked items will stay marked after a bulk action.
9160 You can toggle this interactively by typing `p' when prompted for a
9161 bulk action."
9162 :group 'org-agenda
9163 :version "24.1"
9164 :type 'boolean)
9166 (defun org-agenda-bulk-action (&optional arg)
9167 "Execute an remote-editing action on all marked entries.
9168 The prefix arg is passed through to the command if possible."
9169 (interactive "P")
9170 ;; Make sure we have markers, and only valid ones
9171 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9172 (mapc
9173 (lambda (m)
9174 (unless (and (markerp m)
9175 (marker-buffer m)
9176 (buffer-live-p (marker-buffer m))
9177 (marker-position m))
9178 (error "Marker %s for bulk command is invalid" m)))
9179 org-agenda-bulk-marked-entries)
9181 ;; Prompt for the bulk command
9182 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9183 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9184 "[S]catter [f]unction "
9185 (when org-agenda-bulk-custom-functions
9186 (concat " Custom: ["
9187 (mapconcat (lambda(f) (char-to-string (car f)))
9188 org-agenda-bulk-custom-functions "")
9189 "]"))))
9190 (catch 'exit
9191 (let* ((action (read-char-exclusive))
9192 (org-log-refile (if org-log-refile 'time nil))
9193 (entries (reverse org-agenda-bulk-marked-entries))
9194 (org-overriding-default-time
9195 (if (get-text-property (point) 'org-agenda-date-header)
9196 (org-get-cursor-date)))
9197 redo-at-end
9198 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9199 (cond
9200 ((equal action ?p)
9201 (let ((org-agenda-persistent-marks
9202 (not org-agenda-persistent-marks)))
9203 (org-agenda-bulk-action)
9204 (throw 'exit nil)))
9206 ((equal action ?$)
9207 (setq cmd '(org-agenda-archive)))
9209 ((equal action ?A)
9210 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9212 ((member action '(?r ?w))
9213 (setq rfloc (org-refile-get-location
9214 "Refile to"
9215 (marker-buffer (car entries))
9216 org-refile-allow-creating-parent-nodes))
9217 (if (nth 3 rfloc)
9218 (setcar (nthcdr 3 rfloc)
9219 (move-marker (make-marker) (nth 3 rfloc)
9220 (or (get-file-buffer (nth 1 rfloc))
9221 (find-buffer-visiting (nth 1 rfloc))
9222 (error "This should not happen")))))
9224 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9225 redo-at-end t))
9227 ((equal action ?t)
9228 (setq state (org-icompleting-read
9229 "Todo state: "
9230 (with-current-buffer (marker-buffer (car entries))
9231 (mapcar 'list org-todo-keywords-1))))
9232 (setq cmd `(let ((org-inhibit-blocking t)
9233 (org-inhibit-logging 'note))
9234 (org-agenda-todo ,state))))
9236 ((memq action '(?- ?+))
9237 (setq tag (org-icompleting-read
9238 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9239 (with-current-buffer (marker-buffer (car entries))
9240 (delq nil
9241 (mapcar (lambda (x)
9242 (if (stringp (car x)) x)) org-tag-alist)))))
9243 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9245 ((memq action '(?s ?d))
9246 (let* ((time
9247 (unless arg
9248 (org-read-date
9249 nil nil nil
9250 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9251 org-overriding-default-time)))
9252 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9253 (setq cmd `(eval '(,c1 arg ,time)))))
9255 ((equal action ?S)
9256 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9257 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9258 (let ((days (read-number
9259 (format "Scatter tasks across how many %sdays: "
9260 (if arg "week" "")) 7)))
9261 (setq cmd
9262 `(let ((distance (1+ (random ,days))))
9263 (if arg
9264 (let ((dist distance)
9265 (day-of-week
9266 (calendar-day-of-week
9267 (calendar-gregorian-from-absolute (org-today)))))
9268 (dotimes (i (1+ dist))
9269 (while (member day-of-week org-agenda-weekend-days)
9270 (incf distance)
9271 (incf day-of-week)
9272 (if (= day-of-week 7)
9273 (setq day-of-week 0)))
9274 (incf day-of-week)
9275 (if (= day-of-week 7)
9276 (setq day-of-week 0)))))
9277 ;; silently fail when try to replan a sexp entry
9278 (condition-case nil
9279 (let* ((date (calendar-gregorian-from-absolute
9280 (+ (org-today) distance)))
9281 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9282 (nth 2 date))))
9283 (org-agenda-schedule nil time))
9284 (error nil)))))))
9286 ((assoc action org-agenda-bulk-custom-functions)
9287 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9288 redo-at-end t))
9290 ((equal action ?f)
9291 (setq cmd (list (intern
9292 (org-icompleting-read "Function: "
9293 obarray 'fboundp t nil nil)))))
9295 (t (error "Invalid bulk action")))
9297 ;; Sort the markers, to make sure that parents are handled before children
9298 (setq entries (sort entries
9299 (lambda (a b)
9300 (cond
9301 ((equal (marker-buffer a) (marker-buffer b))
9302 (< (marker-position a) (marker-position b)))
9304 (string< (buffer-name (marker-buffer a))
9305 (buffer-name (marker-buffer b))))))))
9307 ;; Now loop over all markers and apply cmd
9308 (while (setq e (pop entries))
9309 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9310 (if (not pos)
9311 (progn (message "Skipping removed entry at %s" e)
9312 (setq cntskip (1+ cntskip)))
9313 (goto-char pos)
9314 (let (org-loop-over-headlines-in-active-region)
9315 (eval cmd))
9316 (setq cnt (1+ cnt))))
9317 (when redo-at-end (org-agenda-redo))
9318 (unless org-agenda-persistent-marks
9319 (org-agenda-bulk-unmark-all))
9320 (message "Acted on %d entries%s%s"
9322 (if (= cntskip 0)
9324 (format ", skipped %d (disappeared before their turn)"
9325 cntskip))
9326 (if (not org-agenda-persistent-marks)
9327 "" " (kept marked)"))))))
9329 (defun org-agenda-capture ()
9330 "Call `org-capture' with the date at point."
9331 (interactive)
9332 (if (not (eq major-mode 'org-agenda-mode))
9333 (error "You cannot do this outside of agenda buffers")
9334 (let ((org-overriding-default-time
9335 (org-get-cursor-date)))
9336 (call-interactively 'org-capture))))
9338 ;;; Flagging notes
9340 (defun org-agenda-show-the-flagging-note ()
9341 "Display the flagging note in the other window.
9342 When called a second time in direct sequence, offer to remove the FLAGGING
9343 tag and (if present) the flagging note."
9344 (interactive)
9345 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9346 (win (selected-window))
9347 note heading newhead)
9348 (unless hdmarker
9349 (error "No linked entry at point"))
9350 (if (and (eq this-command last-command)
9351 (y-or-n-p "Unflag and remove any flagging note? "))
9352 (progn
9353 (org-agenda-remove-flag hdmarker)
9354 (let ((win (get-buffer-window "*Flagging Note*")))
9355 (and win (delete-window win)))
9356 (message "Entry unflagged"))
9357 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9358 (unless note
9359 (error "No flagging note"))
9360 (org-kill-new note)
9361 (org-switch-to-buffer-other-window "*Flagging Note*")
9362 (erase-buffer)
9363 (insert note)
9364 (goto-char (point-min))
9365 (while (re-search-forward "\\\\n" nil t)
9366 (replace-match "\n" t t))
9367 (goto-char (point-min))
9368 (select-window win)
9369 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9371 (defun org-agenda-remove-flag (marker)
9372 "Remove the FLAGGED tag and any flagging note in the entry."
9373 (let (newhead)
9374 (org-with-point-at marker
9375 (org-toggle-tag "FLAGGED" 'off)
9376 (org-entry-delete nil "THEFLAGGINGNOTE")
9377 (setq newhead (org-get-heading)))
9378 (org-agenda-change-all-lines newhead marker)
9379 (message "Entry unflagged")))
9381 (defun org-agenda-get-any-marker (&optional pos)
9382 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9383 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9385 ;;; Appointment reminders
9387 (defvar appt-time-msg-list) ; defined in appt.el
9389 ;;;###autoload
9390 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9391 "Activate appointments found in `org-agenda-files'.
9392 With a \\[universal-argument] prefix, refresh the list of
9393 appointments.
9395 If FILTER is t, interactively prompt the user for a regular
9396 expression, and filter out entries that don't match it.
9398 If FILTER is a string, use this string as a regular expression
9399 for filtering entries out.
9401 If FILTER is a function, filter out entries against which
9402 calling the function returns nil. This function takes one
9403 argument: an entry from `org-agenda-get-day-entries'.
9405 FILTER can also be an alist with the car of each cell being
9406 either 'headline or 'category. For example:
9408 '((headline \"IMPORTANT\")
9409 (category \"Work\"))
9411 will only add headlines containing IMPORTANT or headlines
9412 belonging to the \"Work\" category.
9414 ARGS are symbols indicating what kind of entries to consider.
9415 By default `org-agenda-to-appt' will use :deadline, :scheduled
9416 and :timestamp entries. See the docstring of `org-diary' for
9417 details and examples.
9419 If an entry as a APPT_WARNTIME property, its value will be used
9420 to override `appt-message-warning-time'."
9421 (interactive "P")
9422 (if refresh (setq appt-time-msg-list nil))
9423 (if (eq filter t)
9424 (setq filter (read-from-minibuffer "Regexp filter: ")))
9425 (let* ((cnt 0) ; count added events
9426 (scope (or args '(:deadline :scheduled :timestamp)))
9427 (org-agenda-new-buffers nil)
9428 (org-deadline-warning-days 0)
9429 ;; Do not use `org-today' here because appt only takes
9430 ;; time and without date as argument, so it may pass wrong
9431 ;; information otherwise
9432 (today (org-date-to-gregorian
9433 (time-to-days (current-time))))
9434 (org-agenda-restrict nil)
9435 (files (org-agenda-files 'unrestricted)) entries file
9436 (org-agenda-buffer nil))
9437 ;; Get all entries which may contain an appt
9438 (org-agenda-prepare-buffers files)
9439 (while (setq file (pop files))
9440 (setq entries
9441 (delq nil
9442 (append entries
9443 (apply 'org-agenda-get-day-entries
9444 file today scope)))))
9445 ;; Map thru entries and find if we should filter them out
9446 (mapc
9447 (lambda(x)
9448 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9449 (cat (get-text-property 1 'org-category x))
9450 (tod (get-text-property 1 'time-of-day x))
9451 (ok (or (null filter)
9452 (and (stringp filter) (string-match filter evt))
9453 (and (functionp filter) (funcall filter x))
9454 (and (listp filter)
9455 (let ((cat-filter (cadr (assoc 'category filter)))
9456 (evt-filter (cadr (assoc 'headline filter))))
9457 (or (and (stringp cat-filter)
9458 (string-match cat-filter cat))
9459 (and (stringp evt-filter)
9460 (string-match evt-filter evt)))))))
9461 (wrn (get-text-property 1 'warntime x)))
9462 ;; FIXME: Shall we remove text-properties for the appt text?
9463 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9464 (when (and ok tod)
9465 (setq tod (concat "00" (number-to-string tod))
9466 tod (when (string-match
9467 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9468 (concat (match-string 1 tod) ":"
9469 (match-string 2 tod))))
9470 (if (version< emacs-version "23.3")
9471 (appt-add tod evt)
9472 (appt-add tod evt wrn))
9473 (setq cnt (1+ cnt))))) entries)
9474 (org-release-buffers org-agenda-new-buffers)
9475 (if (eq cnt 0)
9476 (message "No event to add")
9477 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9479 (autoload 'org-agenda-to-appt "org-agenda" "\
9480 Activate appointments found in `org-agenda-files'.
9481 With a \\[universal-argument] prefix, refresh the list of
9482 appointments.
9484 If FILTER is t, interactively prompt the user for a regular
9485 expression, and filter out entries that don't match it.
9487 If FILTER is a string, use this string as a regular expression
9488 for filtering entries out.
9490 If FILTER is a function, filter out entries against which
9491 calling the function returns nil. This function takes one
9492 argument: an entry from `org-agenda-get-day-entries'.
9494 FILTER can also be an alist with the car of each cell being
9495 either 'headline or 'category. For example:
9497 '((headline \"IMPORTANT\")
9498 (category \"Work\"))
9500 will only add headlines containing IMPORTANT or headlines
9501 belonging to the \"Work\" category.
9503 ARGS are symbols indicating what kind of entries to consider.
9504 By default `org-agenda-to-appt' will use :deadline, :scheduled
9505 and :timestamp entries. See the docstring of `org-diary' for
9506 details and examples.
9508 If an entry as a APPT_WARNTIME property, its value will be used
9509 to override `appt-message-warning-time'.
9511 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9513 (defun org-agenda-todayp (date)
9514 "Does DATE mean today, when considering `org-extend-today-until'?"
9515 (let ((today (org-today))
9516 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9517 date)))
9518 (eq date today)))
9520 (defun org-agenda-todo-yesterday (&optional arg)
9521 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9522 (interactive "P")
9523 (let* ((hour (third (decode-time
9524 (org-current-time))))
9525 (org-extend-today-until (1+ hour)))
9526 (org-agenda-todo arg)))
9528 (provide 'org-agenda)
9530 ;;; org-agenda.el ends here