Merge branch 'maint-agenda-optimization' into maint
[org-mode.git] / lisp / org-agenda.el
blob1b2337cd142616f3e874c281ba1bb7e168d4616d
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags to not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-tags-todo-honor-ignore-options nil
744 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
745 The variables
746 `org-agenda-todo-ignore-with-date',
747 `org-agenda-todo-ignore-timestamp',
748 `org-agenda-todo-ignore-scheduled',
749 `org-agenda-todo-ignore-deadlines'
750 make the global TODO list skip entries that have time stamps of certain
751 kinds. If this option is set, the same options will also apply for the
752 tags-todo search, which is the general tags/property matcher
753 restricted to unfinished TODO entries only."
754 :group 'org-agenda-skip
755 :group 'org-agenda-todo-list
756 :group 'org-agenda-match-view
757 :type 'boolean)
759 (defcustom org-agenda-skip-scheduled-if-done nil
760 "Non-nil means don't show scheduled items in agenda when they are done.
761 This is relevant for the daily/weekly agenda, not for the TODO list. And
762 it applies only to the actual date of the scheduling. Warnings about
763 an item with a past scheduling dates are always turned off when the item
764 is DONE."
765 :group 'org-agenda-skip
766 :group 'org-agenda-daily/weekly
767 :type 'boolean)
769 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
770 "Non-nil means skip scheduling line if same entry shows because of deadline.
771 In the agenda of today, an entry can show up multiple times because
772 it is both scheduled and has a nearby deadline, and maybe a plain time
773 stamp as well.
774 When this variable is t, then only the deadline is shown and the fact that
775 the entry is scheduled today or was scheduled previously is not shown.
776 When this variable is nil, the entry will be shown several times. When
777 the variable is the symbol `not-today', then skip scheduled previously,
778 but not scheduled today."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type '(choice
782 (const :tag "Never" nil)
783 (const :tag "Always" t)
784 (const :tag "Not when scheduled today" not-today)))
786 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
787 "Non-nil means skip timestamp line if same entry shows because of deadline.
788 In the agenda of today, an entry can show up multiple times
789 because it has both a plain timestamp and has a nearby deadline.
790 When this variable is t, then only the deadline is shown and the
791 fact that the entry has a timestamp for or including today is not
792 shown. When this variable is nil, the entry will be shown
793 several times."
794 :group 'org-agenda-skip
795 :group 'org-agenda-daily/weekly
796 :version "24.1"
797 :type '(choice
798 (const :tag "Never" nil)
799 (const :tag "Always" t)))
801 (defcustom org-agenda-skip-deadline-if-done nil
802 "Non-nil means don't show deadlines when the corresponding item is done.
803 When nil, the deadline is still shown and should give you a happy feeling.
804 This is relevant for the daily/weekly agenda. And it applied only to the
805 actually date of the deadline. Warnings about approaching and past-due
806 deadlines are always turned off when the item is DONE."
807 :group 'org-agenda-skip
808 :group 'org-agenda-daily/weekly
809 :type 'boolean)
811 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
812 "Non-nil means skip deadline prewarning when entry is also scheduled.
813 This will apply on all days where a prewarning for the deadline would
814 be shown, but not at the day when the entry is actually due. On that day,
815 the deadline will be shown anyway.
816 This variable may be set to nil, t, or a number which will then give
817 the number of days before the actual deadline when the prewarnings
818 should resume.
819 This can be used in a workflow where the first showing of the deadline will
820 trigger you to schedule it, and then you don't want to be reminded of it
821 because you will take care of it on the day when scheduled."
822 :group 'org-agenda-skip
823 :group 'org-agenda-daily/weekly
824 :version "24.1"
825 :type '(choice
826 (const :tag "Always show prewarning" nil)
827 (const :tag "Remove prewarning if entry is scheduled" t)
828 (integer :tag "Restart prewarning N days before deadline")))
830 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
831 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
832 When non-nil, after the search for timestamps has matched once in an
833 entry, the rest of the entry will not be searched."
834 :group 'org-agenda-skip
835 :type 'boolean)
837 (defcustom org-agenda-skip-timestamp-if-done nil
838 "Non-nil means don't select item by timestamp or -range if it is DONE."
839 :group 'org-agenda-skip
840 :group 'org-agenda-daily/weekly
841 :type 'boolean)
843 (defcustom org-agenda-dim-blocked-tasks nil
844 "Non-nil means dim blocked tasks in the agenda display.
845 This causes some overhead during agenda construction, but if you
846 have turned on `org-enforce-todo-dependencies',
847 `org-enforce-todo-checkbox-dependencies', or any other blocking
848 mechanism, this will create useful feedback in the agenda.
850 Instead of t, this variable can also have the value `invisible'.
851 Then blocked tasks will be invisible and only become visible when
852 they become unblocked. An exemption to this behavior is when a task is
853 blocked because of unchecked checkboxes below it. Since checkboxes do
854 not show up in the agenda views, making this task invisible you remove any
855 trace from agenda views that there is something to do. Therefore, a task
856 that is blocked because of checkboxes will never be made invisible, it
857 will only be dimmed."
858 :group 'org-agenda-daily/weekly
859 :group 'org-agenda-todo-list
860 :version "24.3"
861 :type '(choice
862 (const :tag "Do not dim" nil)
863 (const :tag "Dim to a gray face" t)
864 (const :tag "Make invisible" invisible)))
866 (defcustom org-timeline-show-empty-dates 3
867 "Non-nil means `org-timeline' also shows dates without an entry.
868 When nil, only the days which actually have entries are shown.
869 When t, all days between the first and the last date are shown.
870 When an integer, show also empty dates, but if there is a gap of more than
871 N days, just insert a special line indicating the size of the gap."
872 :group 'org-agenda-skip
873 :type '(choice
874 (const :tag "None" nil)
875 (const :tag "All" t)
876 (integer :tag "at most")))
878 (defgroup org-agenda-startup nil
879 "Options concerning initial settings in the Agenda in Org Mode."
880 :tag "Org Agenda Startup"
881 :group 'org-agenda)
883 (defcustom org-agenda-menu-show-matcher t
884 "Non-nil means show the match string in the agenda dispatcher menu.
885 When nil, the matcher string is not shown, but is put into the help-echo
886 property so than moving the mouse over the command shows it.
887 Setting it to nil is good if matcher strings are very long and/or if
888 you want to use two-columns display (see `org-agenda-menu-two-columns')."
889 :group 'org-agenda
890 :version "24.1"
891 :type 'boolean)
893 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
895 (defcustom org-agenda-menu-two-columns nil
896 "Non-nil means, use two columns to show custom commands in the dispatcher.
897 If you use this, you probably want to set `org-agenda-menu-show-matcher'
898 to nil."
899 :group 'org-agenda
900 :version "24.1"
901 :type 'boolean)
903 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
904 (defcustom org-agenda-finalize-hook nil
905 "Hook run just before displaying an agenda buffer.
906 The buffer is still writable when the hook is called.
908 You can modify some of the buffer substrings but you should be
909 extra careful not to modify the text properties of the agenda
910 headlines as the agenda display heavily relies on them."
911 :group 'org-agenda-startup
912 :type 'hook)
914 (defcustom org-agenda-mouse-1-follows-link nil
915 "Non-nil means mouse-1 on a link will follow the link in the agenda.
916 A longer mouse click will still set point. Does not work on XEmacs.
917 Needs to be set before org.el is loaded."
918 :group 'org-agenda-startup
919 :type 'boolean)
921 (defcustom org-agenda-start-with-follow-mode nil
922 "The initial value of follow mode in a newly created agenda window."
923 :group 'org-agenda-startup
924 :type 'boolean)
926 (defcustom org-agenda-follow-indirect nil
927 "Non-nil means `org-agenda-follow-mode' displays only the
928 current item's tree, in an indirect buffer."
929 :group 'org-agenda
930 :version "24.1"
931 :type 'boolean)
933 (defcustom org-agenda-show-outline-path t
934 "Non-nil means show outline path in echo area after line motion."
935 :group 'org-agenda-startup
936 :type 'boolean)
938 (defcustom org-agenda-start-with-entry-text-mode nil
939 "The initial value of entry-text-mode in a newly created agenda window."
940 :group 'org-agenda-startup
941 :type 'boolean)
943 (defcustom org-agenda-entry-text-maxlines 5
944 "Number of text lines to be added when `E' is pressed in the agenda.
946 Note that this variable only used during agenda display. Add add entry text
947 when exporting the agenda, configure the variable
948 `org-agenda-add-entry-ext-maxlines'."
949 :group 'org-agenda
950 :type 'integer)
952 (defcustom org-agenda-entry-text-exclude-regexps nil
953 "List of regular expressions to clean up entry text.
954 The complete matches of all regular expressions in this list will be
955 removed from entry text before it is shown in the agenda."
956 :group 'org-agenda
957 :type '(repeat (regexp)))
959 (defvar org-agenda-entry-text-cleanup-hook nil
960 "Hook that is run after basic cleanup of entry text to be shown in agenda.
961 This cleanup is done in a temporary buffer, so the function may inspect and
962 change the entire buffer.
963 Some default stuff like drawers and scheduling/deadline dates will already
964 have been removed when this is called, as will any matches for regular
965 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
967 (defvar org-agenda-include-inactive-timestamps nil
968 "Non-nil means include inactive time stamps in agenda and timeline.
969 Dynamically scoped.")
971 (defgroup org-agenda-windows nil
972 "Options concerning the windows used by the Agenda in Org Mode."
973 :tag "Org Agenda Windows"
974 :group 'org-agenda)
976 (defcustom org-agenda-window-setup 'reorganize-frame
977 "How the agenda buffer should be displayed.
978 Possible values for this option are:
980 current-window Show agenda in the current window, keeping all other windows.
981 other-window Use `switch-to-buffer-other-window' to display agenda.
982 reorganize-frame Show only two windows on the current frame, the current
983 window and the agenda.
984 other-frame Use `switch-to-buffer-other-frame' to display agenda.
985 Also, when exiting the agenda, kill that frame.
986 See also the variable `org-agenda-restore-windows-after-quit'."
987 :group 'org-agenda-windows
988 :type '(choice
989 (const current-window)
990 (const other-frame)
991 (const other-window)
992 (const reorganize-frame)))
994 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
995 "The min and max height of the agenda window as a fraction of frame height.
996 The value of the variable is a cons cell with two numbers between 0 and 1.
997 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
998 :group 'org-agenda-windows
999 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1001 (defcustom org-agenda-restore-windows-after-quit nil
1002 "Non-nil means restore window configuration upon exiting agenda.
1003 Before the window configuration is changed for displaying the agenda,
1004 the current status is recorded. When the agenda is exited with
1005 `q' or `x' and this option is set, the old state is restored. If
1006 `org-agenda-window-setup' is `other-frame', the value of this
1007 option will be ignored."
1008 :group 'org-agenda-windows
1009 :type 'boolean)
1011 (defcustom org-agenda-ndays nil
1012 "Number of days to include in overview display.
1013 Should be 1 or 7.
1014 Obsolete, see `org-agenda-span'."
1015 :group 'org-agenda-daily/weekly
1016 :type 'integer)
1018 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1020 (defcustom org-agenda-span 'week
1021 "Number of days to include in overview display.
1022 Can be day, week, month, year, or any number of days.
1023 Custom commands can set this variable in the options section."
1024 :group 'org-agenda-daily/weekly
1025 :type '(choice (const :tag "Day" day)
1026 (const :tag "Week" week)
1027 (const :tag "Month" month)
1028 (const :tag "Year" year)
1029 (integer :tag "Custom")))
1031 (defcustom org-agenda-start-on-weekday 1
1032 "Non-nil means start the overview always on the specified weekday.
1033 0 denotes Sunday, 1 denotes Monday etc.
1034 When nil, always start on the current day.
1035 Custom commands can set this variable in the options section."
1036 :group 'org-agenda-daily/weekly
1037 :type '(choice (const :tag "Today" nil)
1038 (integer :tag "Weekday No.")))
1040 (defcustom org-agenda-show-all-dates t
1041 "Non-nil means `org-agenda' shows every day in the selected range.
1042 When nil, only the days which actually have entries are shown."
1043 :group 'org-agenda-daily/weekly
1044 :type 'boolean)
1046 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1047 "Format string for displaying dates in the agenda.
1048 Used by the daily/weekly agenda and by the timeline. This should be
1049 a format string understood by `format-time-string', or a function returning
1050 the formatted date as a string. The function must take a single argument,
1051 a calendar-style date list like (month day year)."
1052 :group 'org-agenda-daily/weekly
1053 :type '(choice
1054 (string :tag "Format string")
1055 (function :tag "Function")))
1057 (defun org-agenda-format-date-aligned (date)
1058 "Format a date string for display in the daily/weekly agenda, or timeline.
1059 This function makes sure that dates are aligned for easy reading."
1060 (require 'cal-iso)
1061 (let* ((dayname (calendar-day-name date))
1062 (day (cadr date))
1063 (day-of-week (calendar-day-of-week date))
1064 (month (car date))
1065 (monthname (calendar-month-name month))
1066 (year (nth 2 date))
1067 (iso-week (org-days-to-iso-week
1068 (calendar-absolute-from-gregorian date)))
1069 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1070 (1- year))
1071 ((and (= month 12) (<= iso-week 1))
1072 (1+ year))
1073 (t year)))
1074 (weekstring (if (= day-of-week 1)
1075 (format " W%02d" iso-week)
1076 "")))
1077 (format "%-10s %2d %s %4d%s"
1078 dayname day monthname year weekstring)))
1080 (defcustom org-agenda-time-leading-zero nil
1081 "Non-nil means use leading zero for military times in agenda.
1082 For example, 9:30am would become 09:30 rather than 9:30."
1083 :group 'org-agenda-daily/weekly
1084 :version "24.1"
1085 :type 'boolean)
1087 (defcustom org-agenda-timegrid-use-ampm nil
1088 "When set, show AM/PM style timestamps on the timegrid."
1089 :group 'org-agenda
1090 :version "24.1"
1091 :type 'boolean)
1093 (defun org-agenda-time-of-day-to-ampm (time)
1094 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1095 (let* ((hour-number (string-to-number (substring time 0 -3)))
1096 (minute (substring time -2))
1097 (ampm "am"))
1098 (cond
1099 ((equal hour-number 12)
1100 (setq ampm "pm"))
1101 ((> hour-number 12)
1102 (setq ampm "pm")
1103 (setq hour-number (- hour-number 12))))
1104 (concat
1105 (if org-agenda-time-leading-zero
1106 (format "%02d" hour-number)
1107 (format "%02s" (number-to-string hour-number)))
1108 ":" minute ampm)))
1110 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1111 "Conditionally convert TIME to AM/PM format
1112 based on `org-agenda-timegrid-use-ampm'"
1113 (if org-agenda-timegrid-use-ampm
1114 (org-agenda-time-of-day-to-ampm time)
1115 time))
1117 (defcustom org-agenda-weekend-days '(6 0)
1118 "Which days are weekend?
1119 These days get the special face `org-agenda-date-weekend' in the agenda
1120 and timeline buffers."
1121 :group 'org-agenda-daily/weekly
1122 :type '(set :greedy t
1123 (const :tag "Monday" 1)
1124 (const :tag "Tuesday" 2)
1125 (const :tag "Wednesday" 3)
1126 (const :tag "Thursday" 4)
1127 (const :tag "Friday" 5)
1128 (const :tag "Saturday" 6)
1129 (const :tag "Sunday" 0)))
1131 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1132 "Non-nil means jump to today when moving a past date forward in time.
1133 When using S-right in the agenda to move a a date forward, and the date
1134 stamp currently points to the past, the first key press will move it
1135 to today. WHen nil, just move one day forward even if the date stays
1136 in the past."
1137 :group 'org-agenda-daily/weekly
1138 :version "24.1"
1139 :type 'boolean)
1141 (defcustom org-agenda-include-diary nil
1142 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1143 Custom commands can set this variable in the options section."
1144 :group 'org-agenda-daily/weekly
1145 :type 'boolean)
1147 (defcustom org-agenda-include-deadlines t
1148 "If non-nil, include entries within their deadline warning period.
1149 Custom commands can set this variable in the options section."
1150 :group 'org-agenda-daily/weekly
1151 :version "24.1"
1152 :type 'boolean)
1154 (defcustom org-agenda-repeating-timestamp-show-all t
1155 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1156 When set to a list of strings, only show occurrences of repeating
1157 stamps for these TODO keywords. When nil, only one occurrence is
1158 shown, either today or the nearest into the future."
1159 :group 'org-agenda-daily/weekly
1160 :type '(choice
1161 (const :tag "Show repeating stamps" t)
1162 (repeat :tag "Show repeating stamps for these TODO keywords"
1163 (string :tag "TODO Keyword"))
1164 (const :tag "Don't show repeating stamps" nil)))
1166 (defcustom org-scheduled-past-days 10000
1167 "No. of days to continue listing scheduled items that are not marked DONE.
1168 When an item is scheduled on a date, it shows up in the agenda on this
1169 day and will be listed until it is marked done for the number of days
1170 given here."
1171 :group 'org-agenda-daily/weekly
1172 :type 'integer)
1174 (defcustom org-agenda-log-mode-items '(closed clock)
1175 "List of items that should be shown in agenda log mode.
1176 This list may contain the following symbols:
1178 closed Show entries that have been closed on that day.
1179 clock Show entries that have received clocked time on that day.
1180 state Show all logged state changes.
1181 Note that instead of changing this variable, you can also press `C-u l' in
1182 the agenda to display all available LOG items temporarily."
1183 :group 'org-agenda-daily/weekly
1184 :type '(set :greedy t (const closed) (const clock) (const state)))
1186 (defcustom org-agenda-clock-consistency-checks
1187 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1188 :gap-ok-around ("4:00")
1189 :default-face ((:background "DarkRed") (:foreground "white"))
1190 :overlap-face nil :gap-face nil :no-end-time-face nil
1191 :long-face nil :short-face nil)
1192 "This is a property list, with the following keys:
1194 :max-duration Mark clocking chunks that are longer than this time.
1195 This is a time string like \"HH:MM\", or the number
1196 of minutes as an integer.
1198 :min-duration Mark clocking chunks that are shorter that this.
1199 This is a time string like \"HH:MM\", or the number
1200 of minutes as an integer.
1202 :max-gap Mark gaps between clocking chunks that are longer than
1203 this duration. A number of minutes, or a string
1204 like \"HH:MM\".
1206 :gap-ok-around List of times during the day which are usually not working
1207 times. When a gap is detected, but the gap contains any
1208 of these times, the gap is *not* reported. For example,
1209 if this is (\"4:00\" \"13:00\") then gaps that contain
1210 4:00 in the morning (i.e. the night) and 13:00
1211 (i.e. a typical lunch time) do not cause a warning.
1212 You should have at least one time during the night in this
1213 list, or otherwise the first task each morning will trigger
1214 a warning because it follows a long gap.
1216 Furthermore, the following properties can be used to define faces for
1217 issue display.
1219 :default-face the default face, if the specific face is undefined
1220 :overlap-face face for overlapping clocks
1221 :gap-face face for gaps between clocks
1222 :no-end-time-face face for incomplete clocks
1223 :long-face face for clock intervals that are too long
1224 :short-face face for clock intervals that are too short"
1225 :group 'org-agenda-daily/weekly
1226 :group 'org-clock
1227 :version "24.1"
1228 :type 'plist)
1230 (defcustom org-agenda-log-mode-add-notes t
1231 "Non-nil means add first line of notes to log entries in agenda views.
1232 If a log item like a state change or a clock entry is associated with
1233 notes, the first line of these notes will be added to the entry in the
1234 agenda display."
1235 :group 'org-agenda-daily/weekly
1236 :type 'boolean)
1238 (defcustom org-agenda-start-with-log-mode nil
1239 "The initial value of log-mode in a newly created agenda window.
1240 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1241 explanations on the possible values."
1242 :group 'org-agenda-startup
1243 :group 'org-agenda-daily/weekly
1244 :type '(choice (const :tag "Don't show log items" nil)
1245 (const :tag "Show only log items" 'only)
1246 (const :tag "Show all possible log items" 'clockcheck)
1247 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1248 (choice (const :tag "Show closed log items" 'closed)
1249 (const :tag "Show clocked log items" 'clock)
1250 (const :tag "Show all logged state changes" 'state)))))
1252 (defcustom org-agenda-start-with-clockreport-mode nil
1253 "The initial value of clockreport-mode in a newly created agenda window."
1254 :group 'org-agenda-startup
1255 :group 'org-agenda-daily/weekly
1256 :type 'boolean)
1258 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1259 "Property list with parameters for the clocktable in clockreport mode.
1260 This is the display mode that shows a clock table in the daily/weekly
1261 agenda, the properties for this dynamic block can be set here.
1262 The usual clocktable parameters are allowed here, but you cannot set
1263 the properties :name, :tstart, :tend, :block, and :scope - these will
1264 be overwritten to make sure the content accurately reflects the
1265 current display in the agenda."
1266 :group 'org-agenda-daily/weekly
1267 :type 'plist)
1269 (defcustom org-agenda-search-view-always-boolean nil
1270 "Non-nil means the search string is interpreted as individual parts.
1272 The search string for search view can either be interpreted as a phrase,
1273 or as a list of snippets that define a boolean search for a number of
1274 strings.
1276 When this is non-nil, the string will be split on whitespace, and each
1277 snippet will be searched individually, and all must match in order to
1278 select an entry. A snippet is then a single string of non-white
1279 characters, or a string in double quotes, or a regexp in {} braces.
1280 If a snippet is preceded by \"-\", the snippet must *not* match.
1281 \"+\" is syntactic sugar for positive selection. Each snippet may
1282 be found as a full word or a partial word, but see the variable
1283 `org-agenda-search-view-force-full-words'.
1285 When this is nil, search will look for the entire search phrase as one,
1286 with each space character matching any amount of whitespace, including
1287 line breaks.
1289 Even when this is nil, you can still switch to Boolean search dynamically
1290 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1291 is a regexp marked with braces like \"{abc}\", this will also switch to
1292 boolean search."
1293 :group 'org-agenda-search-view
1294 :version "24.1"
1295 :type 'boolean)
1297 (if (fboundp 'defvaralias)
1298 (defvaralias 'org-agenda-search-view-search-words-only
1299 'org-agenda-search-view-always-boolean))
1301 (defcustom org-agenda-search-view-force-full-words nil
1302 "Non-nil means, search words must be matches as complete words.
1303 When nil, they may also match part of a word."
1304 :group 'org-agenda-search-view
1305 :version "24.1"
1306 :type 'boolean)
1308 (defgroup org-agenda-time-grid nil
1309 "Options concerning the time grid in the Org-mode Agenda."
1310 :tag "Org Agenda Time Grid"
1311 :group 'org-agenda)
1313 (defcustom org-agenda-search-headline-for-time t
1314 "Non-nil means search headline for a time-of-day.
1315 If the headline contains a time-of-day in one format or another, it will
1316 be used to sort the entry into the time sequence of items for a day.
1317 Some people have time stamps in the headline that refer to the creation
1318 time or so, and then this produces an unwanted side effect. If this is
1319 the case for your, use this variable to turn off searching the headline
1320 for a time."
1321 :group 'org-agenda-time-grid
1322 :type 'boolean)
1324 (defcustom org-agenda-use-time-grid t
1325 "Non-nil means show a time grid in the agenda schedule.
1326 A time grid is a set of lines for specific times (like every two hours between
1327 8:00 and 20:00). The items scheduled for a day at specific times are
1328 sorted in between these lines.
1329 For details about when the grid will be shown, and what it will look like, see
1330 the variable `org-agenda-time-grid'."
1331 :group 'org-agenda-time-grid
1332 :type 'boolean)
1334 (defcustom org-agenda-time-grid
1335 '((daily today require-timed)
1336 "----------------"
1337 (800 1000 1200 1400 1600 1800 2000))
1339 "The settings for time grid for agenda display.
1340 This is a list of three items. The first item is again a list. It contains
1341 symbols specifying conditions when the grid should be displayed:
1343 daily if the agenda shows a single day
1344 weekly if the agenda shows an entire week
1345 today show grid on current date, independent of daily/weekly display
1346 require-timed show grid only if at least one item has a time specification
1348 The second item is a string which will be placed behind the grid time.
1350 The third item is a list of integers, indicating the times that should have
1351 a grid line."
1352 :group 'org-agenda-time-grid
1353 :type
1354 '(list
1355 (set :greedy t :tag "Grid Display Options"
1356 (const :tag "Show grid in single day agenda display" daily)
1357 (const :tag "Show grid in weekly agenda display" weekly)
1358 (const :tag "Always show grid for today" today)
1359 (const :tag "Show grid only if any timed entries are present"
1360 require-timed)
1361 (const :tag "Skip grid times already present in an entry"
1362 remove-match))
1363 (string :tag "Grid String")
1364 (repeat :tag "Grid Times" (integer :tag "Time"))))
1366 (defcustom org-agenda-show-current-time-in-grid t
1367 "Non-nil means show the current time in the time grid."
1368 :group 'org-agenda-time-grid
1369 :version "24.1"
1370 :type 'boolean)
1372 (defcustom org-agenda-current-time-string
1373 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1374 "The string for the current time marker in the agenda."
1375 :group 'org-agenda-time-grid
1376 :version "24.1"
1377 :type 'string)
1379 (defgroup org-agenda-sorting nil
1380 "Options concerning sorting in the Org-mode Agenda."
1381 :tag "Org Agenda Sorting"
1382 :group 'org-agenda)
1384 (defcustom org-agenda-sorting-strategy
1385 '((agenda habit-down time-up priority-down category-keep)
1386 (todo priority-down category-keep)
1387 (tags priority-down category-keep)
1388 (search category-keep))
1389 "Sorting structure for the agenda items of a single day.
1390 This is a list of symbols which will be used in sequence to determine
1391 if an entry should be listed before another entry. The following
1392 symbols are recognized:
1394 time-up Put entries with time-of-day indications first, early first
1395 time-down Put entries with time-of-day indications first, late first
1396 category-keep Keep the default order of categories, corresponding to the
1397 sequence in `org-agenda-files'.
1398 category-up Sort alphabetically by category, A-Z.
1399 category-down Sort alphabetically by category, Z-A.
1400 tag-up Sort alphabetically by last tag, A-Z.
1401 tag-down Sort alphabetically by last tag, Z-A.
1402 priority-up Sort numerically by priority, high priority last.
1403 priority-down Sort numerically by priority, high priority first.
1404 todo-state-up Sort by todo state, tasks that are done last.
1405 todo-state-down Sort by todo state, tasks that are done first.
1406 effort-up Sort numerically by estimated effort, high effort last.
1407 effort-down Sort numerically by estimated effort, high effort first.
1408 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1409 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1410 habit-up Put entries that are habits first
1411 habit-down Put entries that are habits last
1412 alpha-up Sort headlines alphabetically
1413 alpha-down Sort headlines alphabetically, reversed
1415 The different possibilities will be tried in sequence, and testing stops
1416 if one comparison returns a \"not-equal\". For example, the default
1417 '(time-up category-keep priority-down)
1418 means: Pull out all entries having a specified time of day and sort them,
1419 in order to make a time schedule for the current day the first thing in the
1420 agenda listing for the day. Of the entries without a time indication, keep
1421 the grouped in categories, don't sort the categories, but keep them in
1422 the sequence given in `org-agenda-files'. Within each category sort by
1423 priority.
1425 Leaving out `category-keep' would mean that items will be sorted across
1426 categories by priority.
1428 Instead of a single list, this can also be a set of list for specific
1429 contents, with a context symbol in the car of the list, any of
1430 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1432 Custom commands can bind this variable in the options section."
1433 :group 'org-agenda-sorting
1434 :type `(choice
1435 (repeat :tag "General" ,org-sorting-choice)
1436 (list :tag "Individually"
1437 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1438 (repeat ,org-sorting-choice))
1439 (cons (const :tag "Strategy for TODO lists" todo)
1440 (repeat ,org-sorting-choice))
1441 (cons (const :tag "Strategy for Tags matches" tags)
1442 (repeat ,org-sorting-choice))
1443 (cons (const :tag "Strategy for search matches" search)
1444 (repeat ,org-sorting-choice)))))
1446 (defcustom org-agenda-cmp-user-defined nil
1447 "A function to define the comparison `user-defined'.
1448 This function must receive two arguments, agenda entry a and b.
1449 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1450 the user comparison, return nil.
1451 When this is defined, you can make `user-defined-up' and `user-defined-down'
1452 part of an agenda sorting strategy."
1453 :group 'org-agenda-sorting
1454 :type 'symbol)
1456 (defcustom org-sort-agenda-notime-is-late t
1457 "Non-nil means items without time are considered late.
1458 This is only relevant for sorting. When t, items which have no explicit
1459 time like 15:30 will be considered as 99:01, i.e. later than any items which
1460 do have a time. When nil, the default time is before 0:00. You can use this
1461 option to decide if the schedule for today should come before or after timeless
1462 agenda entries."
1463 :group 'org-agenda-sorting
1464 :type 'boolean)
1466 (defcustom org-sort-agenda-noeffort-is-high t
1467 "Non-nil means items without effort estimate are sorted as high effort.
1468 This also applies when filtering an agenda view with respect to the
1469 < or > effort operator. Then, tasks with no effort defined will be treated
1470 as tasks with high effort.
1471 When nil, such items are sorted as 0 minutes effort."
1472 :group 'org-agenda-sorting
1473 :type 'boolean)
1475 (defgroup org-agenda-line-format nil
1476 "Options concerning the entry prefix in the Org-mode agenda display."
1477 :tag "Org Agenda Line Format"
1478 :group 'org-agenda)
1480 (defcustom org-agenda-prefix-format
1481 '((agenda . " %i %-12:c%?-12t% s")
1482 (timeline . " % s")
1483 (todo . " %i %-12:c")
1484 (tags . " %i %-12:c")
1485 (search . " %i %-12:c"))
1486 "Format specifications for the prefix of items in the agenda views.
1487 An alist with five entries, each for the different agenda types. The
1488 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1489 The values are format strings.
1491 This format works similar to a printf format, with the following meaning:
1493 %c the category of the item, \"Diary\" for entries from the diary,
1494 or as given by the CATEGORY keyword or derived from the file name
1495 %e the effort required by the item
1496 %i the icon category of the item, see `org-agenda-category-icon-alist'
1497 %T the last tag of the item (ignore inherited tags, which come first)
1498 %t the HH:MM time-of-day specification if one applies to the entry
1499 %s Scheduling/Deadline information, a short string
1500 %(expression) Eval EXPRESSION and replace the control string
1501 by the result
1503 All specifiers work basically like the standard `%s' of printf, but may
1504 contain two additional characters: a question mark just after the `%'
1505 and a whitespace/punctuation character just before the final letter.
1507 If the first character after `%' is a question mark, the entire field
1508 will only be included if the corresponding value applies to the current
1509 entry. This is useful for fields which should have fixed width when
1510 present, but zero width when absent. For example, \"%?-12t\" will
1511 result in a 12 character time field if a time of the day is specified,
1512 but will completely disappear in entries which do not contain a time.
1514 If there is punctuation or whitespace character just before the final
1515 format letter, this character will be appended to the field value if
1516 the value is not empty. For example, the format \"%-12:c\" leads to
1517 \"Diary: \" if the category is \"Diary\". If the category were be
1518 empty, no additional colon would be inserted.
1520 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1521 which means:
1523 - Indent the line with two space characters
1524 - Give the category a 12 chars wide field, padded with whitespace on
1525 the right (because of `-'). Append a colon if there is a category
1526 (because of `:').
1527 - If there is a time-of-day, put it into a 12 chars wide field. If no
1528 time, don't put in an empty field, just skip it (because of '?').
1529 - Finally, put the scheduling information.
1531 See also the variables `org-agenda-remove-times-when-in-prefix' and
1532 `org-agenda-remove-tags'.
1534 Custom commands can set this variable in the options section."
1535 :type '(choice
1536 (string :tag "General format")
1537 (list :greedy t :tag "View dependent"
1538 (cons (const agenda) (string :tag "Format"))
1539 (cons (const timeline) (string :tag "Format"))
1540 (cons (const todo) (string :tag "Format"))
1541 (cons (const tags) (string :tag "Format"))
1542 (cons (const search) (string :tag "Format"))))
1543 :group 'org-agenda-line-format)
1545 (defvar org-prefix-format-compiled nil
1546 "The compiled prefix format and associated variables.
1547 This is a list where first element is a list of variable bindings, and second
1548 element is the compiled format expression. See the variable
1549 `org-agenda-prefix-format'.")
1551 (defcustom org-agenda-todo-keyword-format "%-1s"
1552 "Format for the TODO keyword in agenda lines.
1553 Set this to something like \"%-12s\" if you want all TODO keywords
1554 to occupy a fixed space in the agenda display."
1555 :group 'org-agenda-line-format
1556 :type 'string)
1558 (defcustom org-agenda-diary-sexp-prefix nil
1559 "A regexp that matches part of a diary sexp entry
1560 which should be treated as scheduling/deadline information in
1561 `org-agenda'.
1563 For example, you can use this to extract the `diary-remind-message' from
1564 `diary-remind' entries."
1565 :group 'org-agenda-line-format
1566 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1568 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1569 "Text preceding timerange entries in the agenda view.
1570 This is a list with two strings. The first applies when the range
1571 is entirely on one day. The second applies if the range spans several days.
1572 The strings may have two \"%d\" format specifiers which will be filled
1573 with the sequence number of the days, and the total number of days in the
1574 range, respectively."
1575 :group 'org-agenda-line-format
1576 :type '(list
1577 (string :tag "Deadline today ")
1578 (choice :tag "Deadline relative"
1579 (string :tag "Format string")
1580 (function))))
1582 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1583 "Text preceding scheduled items in the agenda view.
1584 This is a list with two strings. The first applies when the item is
1585 scheduled on the current day. The second applies when it has been scheduled
1586 previously, it may contain a %d indicating that this is the nth time that
1587 this item is scheduled, due to automatic rescheduling of unfinished items
1588 for the following day. So this number is one larger than the number of days
1589 that passed since this item was scheduled first."
1590 :group 'org-agenda-line-format
1591 :type '(list
1592 (string :tag "Scheduled today ")
1593 (string :tag "Scheduled previously")))
1595 (defcustom org-agenda-inactive-leader "["
1596 "Text preceding item pulled into the agenda by inactive time stamps.
1597 These entries are added to the agenda when pressing \"[\"."
1598 :group 'org-agenda-line-format
1599 :version "24.1"
1600 :type '(list
1601 (string :tag "Scheduled today ")
1602 (string :tag "Scheduled previously")))
1604 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1605 "Text preceding deadline items in the agenda view.
1606 This is a list with two strings. The first applies when the item has its
1607 deadline on the current day. The second applies when it is in the past or
1608 in the future, it may contain %d to capture how many days away the deadline
1609 is (was)."
1610 :group 'org-agenda-line-format
1611 :type '(list
1612 (string :tag "Deadline today ")
1613 (choice :tag "Deadline relative"
1614 (string :tag "Format string")
1615 (function))))
1617 (defcustom org-agenda-remove-times-when-in-prefix t
1618 "Non-nil means remove duplicate time specifications in agenda items.
1619 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1620 time-of-day specification in a headline or diary entry is extracted and
1621 placed into the prefix. If this option is non-nil, the original specification
1622 \(a timestamp or -range, or just a plain time(range) specification like
1623 11:30-4pm) will be removed for agenda display. This makes the agenda less
1624 cluttered.
1625 The option can be t or nil. It may also be the symbol `beg', indicating
1626 that the time should only be removed when it is located at the beginning of
1627 the headline/diary entry."
1628 :group 'org-agenda-line-format
1629 :type '(choice
1630 (const :tag "Always" t)
1631 (const :tag "Never" nil)
1632 (const :tag "When at beginning of entry" beg)))
1634 (defcustom org-agenda-remove-timeranges-from-blocks nil
1635 "Non-nil means remove time ranges specifications in agenda
1636 items that span on several days."
1637 :group 'org-agenda-line-format
1638 :version "24.1"
1639 :type 'boolean)
1641 (defcustom org-agenda-default-appointment-duration nil
1642 "Default duration for appointments that only have a starting time.
1643 When nil, no duration is specified in such cases.
1644 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1645 :group 'org-agenda-line-format
1646 :type '(choice
1647 (integer :tag "Minutes")
1648 (const :tag "No default duration")))
1650 (defcustom org-agenda-show-inherited-tags t
1651 "Non-nil means show inherited tags in each agenda line."
1652 :group 'org-agenda-line-format
1653 :type 'boolean)
1655 (defcustom org-agenda-hide-tags-regexp nil
1656 "Regular expression used to filter away specific tags in agenda views.
1657 This means that these tags will be present, but not be shown in the agenda
1658 line. Secondary filtering will still work on the hidden tags.
1659 Nil means don't hide any tags."
1660 :group 'org-agenda-line-format
1661 :type '(choice
1662 (const :tag "Hide none" nil)
1663 (string :tag "Regexp ")))
1665 (defcustom org-agenda-remove-tags nil
1666 "Non-nil means remove the tags from the headline copy in the agenda.
1667 When this is the symbol `prefix', only remove tags when
1668 `org-agenda-prefix-format' contains a `%T' specifier."
1669 :group 'org-agenda-line-format
1670 :type '(choice
1671 (const :tag "Always" t)
1672 (const :tag "Never" nil)
1673 (const :tag "When prefix format contains %T" prefix)))
1675 (if (fboundp 'defvaralias)
1676 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1677 'org-agenda-remove-tags))
1679 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1680 "Shift tags in agenda items to this column.
1681 If this number is positive, it specifies the column. If it is negative,
1682 it means that the tags should be flushright to that column. For example,
1683 -80 works well for a normal 80 character screen."
1684 :group 'org-agenda-line-format
1685 :type 'integer)
1687 (if (fboundp 'defvaralias)
1688 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1690 (defcustom org-agenda-fontify-priorities 'cookies
1691 "Non-nil means highlight low and high priorities in agenda.
1692 When t, the highest priority entries are bold, lowest priority italic.
1693 However, settings in `org-priority-faces' will overrule these faces.
1694 When this variable is the symbol `cookies', only fontify the
1695 cookies, not the entire task.
1696 This may also be an association list of priority faces, whose
1697 keys are the character values of `org-highest-priority',
1698 `org-default-priority', and `org-lowest-priority' (the default values
1699 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1700 color as a string, or a list like `(:background \"Red\")'.
1701 If it is a color, the variable `org-faces-easy-properties'
1702 determines if it is a foreground or a background color."
1703 :group 'org-agenda-line-format
1704 :type '(choice
1705 (const :tag "Never" nil)
1706 (const :tag "Defaults" t)
1707 (const :tag "Cookies only" cookies)
1708 (repeat :tag "Specify"
1709 (list (character :tag "Priority" :value ?A)
1710 (choice :tag "Face "
1711 (string :tag "Color")
1712 (sexp :tag "Face"))))))
1714 (defcustom org-agenda-day-face-function nil
1715 "Function called to determine what face should be used to display a day.
1716 The only argument passed to that function is the day. It should
1717 returns a face, or nil if does not want to specify a face and let
1718 the normal rules apply."
1719 :group 'org-agenda-line-format
1720 :version "24.1"
1721 :type 'function)
1723 (defcustom org-agenda-category-icon-alist nil
1724 "Alist of category icon to be displayed in agenda views.
1726 Each entry should have the following format:
1728 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1730 Where CATEGORY-REGEXP is a regexp matching the categories where
1731 the icon should be displayed.
1732 FILE-OR-DATA either a file path or a string containing image data.
1734 The other fields can be omitted safely if not needed:
1735 TYPE indicates the image type.
1736 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1737 image data.
1738 PROPS are additional image attributes to assign to the image,
1739 like, e.g. `:ascent center'.
1741 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1743 If you want to set the display properties yourself, just put a
1744 list as second element:
1746 (CATEGORY-REGEXP (MY PROPERTY LIST))
1748 For example, to display a 16px horizontal space for Emacs
1749 category, you can use:
1751 (\"Emacs\" '(space . (:width (16))))"
1752 :group 'org-agenda-line-format
1753 :version "24.1"
1754 :type '(alist :key-type (string :tag "Regexp matching category")
1755 :value-type (choice (list :tag "Icon"
1756 (string :tag "File or data")
1757 (symbol :tag "Type")
1758 (boolean :tag "Data?")
1759 (repeat :tag "Extra image properties" :inline t symbol))
1760 (list :tag "Display properties" sexp))))
1762 (defgroup org-agenda-column-view nil
1763 "Options concerning column view in the agenda."
1764 :tag "Org Agenda Column View"
1765 :group 'org-agenda)
1767 (defcustom org-agenda-columns-show-summaries t
1768 "Non-nil means show summaries for columns displayed in the agenda view."
1769 :group 'org-agenda-column-view
1770 :type 'boolean)
1772 (defcustom org-agenda-columns-compute-summary-properties t
1773 "Non-nil means recompute all summary properties before column view.
1774 When column view in the agenda is listing properties that have a summary
1775 operator, it can go to all relevant buffers and recompute the summaries
1776 there. This can mean overhead for the agenda column view, but is necessary
1777 to have thing up to date.
1778 As a special case, a CLOCKSUM property also makes sure that the clock
1779 computations are current."
1780 :group 'org-agenda-column-view
1781 :type 'boolean)
1783 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1784 "Non-nil means the duration of an appointment will add to day effort.
1785 The property to which appointment durations will be added is the one given
1786 in the option `org-effort-property'. If an appointment does not have
1787 an end time, `org-agenda-default-appointment-duration' will be used. If that
1788 is not set, an appointment without end time will not contribute to the time
1789 estimate."
1790 :group 'org-agenda-column-view
1791 :type 'boolean)
1793 (defcustom org-agenda-auto-exclude-function nil
1794 "A function called with a tag to decide if it is filtered on '/ RET'.
1795 The sole argument to the function, which is called once for each
1796 possible tag, is a string giving the name of the tag. The
1797 function should return either nil if the tag should be included
1798 as normal, or \"-<TAG>\" to exclude the tag.
1799 Note that for the purpose of tag filtering, only the lower-case version of
1800 all tags will be considered, so that this function will only ever see
1801 the lower-case version of all tags."
1802 :group 'org-agenda
1803 :type 'function)
1805 (defcustom org-agenda-bulk-custom-functions nil
1806 "Alist of characters and custom functions for bulk actions.
1807 For example, this value makes those two functions available:
1809 '((?R set-category)
1810 (?C bulk-cut))
1812 With selected entries in an agenda buffer, `B R' will call
1813 the custom function `set-category' on the selected entries.
1814 Note that functions in this alist don't need to be quoted."
1815 :type 'alist
1816 :version "24.1"
1817 :group 'org-agenda)
1819 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1820 "Execute BODY with point at location given by `org-hd-marker' property.
1821 If STRING is non-nil, the text property will be fetched from position 0
1822 in that string. If STRING is nil, it will be fetched from the beginning
1823 of the current line."
1824 (org-with-gensyms (marker)
1825 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1826 'org-hd-marker ,string)))
1827 (with-current-buffer (marker-buffer ,marker)
1828 (save-excursion
1829 (goto-char ,marker)
1830 ,@body)))))
1831 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1833 (defun org-add-agenda-custom-command (entry)
1834 "Replace or add a command in `org-agenda-custom-commands'.
1835 This is mostly for hacking and trying a new command - once the command
1836 works you probably want to add it to `org-agenda-custom-commands' for good."
1837 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1838 (if ass
1839 (setcdr ass (cdr entry))
1840 (push entry org-agenda-custom-commands))))
1842 ;;; Define the org-agenda-mode
1844 (defvar org-agenda-mode-map (make-sparse-keymap)
1845 "Keymap for `org-agenda-mode'.")
1846 (if (fboundp 'defvaralias)
1847 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1849 (defvar org-agenda-menu) ; defined later in this file.
1850 (defvar org-agenda-restrict nil) ; defined later in this file.
1851 (defvar org-agenda-follow-mode nil)
1852 (defvar org-agenda-entry-text-mode nil)
1853 (defvar org-agenda-clockreport-mode nil)
1854 (defvar org-agenda-show-log nil)
1855 (defvar org-agenda-redo-command nil)
1856 (defvar org-agenda-query-string nil)
1857 (defvar org-agenda-mode-hook nil
1858 "Hook run after `org-agenda-mode' is turned on.
1859 The buffer is still writable when this hook is called.")
1860 (defvar org-agenda-type nil)
1861 (defvar org-agenda-force-single-file nil)
1862 (defvar org-agenda-bulk-marked-entries nil
1863 "List of markers that refer to marked entries in the agenda.")
1865 ;;; Multiple agenda buffers support
1867 (defcustom org-agenda-sticky nil
1868 "Non-nil means agenda q key will bury agenda buffers.
1869 Agenda commands will then show existing buffer instead of generating new ones.
1870 When nil, `q' will kill the single agenda buffer."
1871 :group 'org-agenda
1872 :version "24.3"
1873 :type 'boolean)
1876 ;;;###autoload
1877 (defun org-toggle-sticky-agenda (&optional arg)
1878 "Toggle `org-agenda-sticky'."
1879 (interactive "P")
1880 (let ((new-value (if arg
1881 (> (prefix-numeric-value arg) 0)
1882 (not org-agenda-sticky))))
1883 (if (equal new-value org-agenda-sticky)
1884 (and (org-called-interactively-p 'interactive)
1885 (message "Sticky agenda was already %s"
1886 (if org-agenda-sticky "enabled" "disabled")))
1887 (setq org-agenda-sticky new-value)
1888 (org-agenda-kill-all-agenda-buffers)
1889 (and (org-called-interactively-p 'interactive)
1890 (message "Sticky agenda was %s"
1891 (if org-agenda-sticky "enabled" "disabled"))))))
1893 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1894 Toggle `org-agenda-sticky'.
1896 \(fn &optional ARG)" t nil)
1898 (defvar org-agenda-buffer nil
1899 "Agenda buffer currently being generated.")
1901 (defvar org-agenda-last-prefix-arg nil)
1902 (defvar org-agenda-this-buffer-name nil)
1903 (defvar org-agenda-doing-sticky-redo nil)
1904 (defvar org-agenda-this-buffer-is-sticky nil)
1906 (defconst org-agenda-local-vars
1907 '(org-agenda-this-buffer-name
1908 org-agenda-undo-list
1909 org-agenda-pending-undo-list
1910 org-agenda-follow-mode
1911 org-agenda-entry-text-mode
1912 org-agenda-clockreport-mode
1913 org-agenda-show-log
1914 org-agenda-redo-command
1915 org-agenda-query-string
1916 org-agenda-type
1917 org-agenda-bulk-marked-entries
1918 org-agenda-undo-has-started-in
1919 org-agenda-info
1920 org-agenda-tag-filter-overlays
1921 org-agenda-cat-filter-overlays
1922 org-agenda-pre-window-conf
1923 org-agenda-columns-active
1924 org-agenda-tag-filter
1925 org-agenda-category-filter
1926 org-agenda-markers
1927 org-agenda-last-search-view-search-was-boolean
1928 org-agenda-filtered-by-category
1929 org-agenda-filter-form
1930 org-agenda-show-window
1931 org-agenda-cycle-counter
1932 org-agenda-last-prefix-arg)
1933 "Variables that must be local in agenda buffers to allow multiple buffers.")
1935 (defun org-agenda-mode ()
1936 "Mode for time-sorted view on action items in Org-mode files.
1938 The following commands are available:
1940 \\{org-agenda-mode-map}"
1941 (interactive)
1942 (cond (org-agenda-doing-sticky-redo
1943 ;; Refreshing sticky agenda-buffer
1945 ;; Preserve the value of `org-agenda-local-vars' variables,
1946 ;; while letting `kill-all-local-variables' kill the rest
1947 (let ((save (buffer-local-variables)))
1948 (kill-all-local-variables)
1949 (mapc 'make-local-variable org-agenda-local-vars)
1950 (dolist (elem save)
1951 (let ((var (car elem))
1952 (val (cdr elem)))
1953 (when (and val
1954 (member var org-agenda-local-vars))
1955 (set var val)))))
1956 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1957 (org-agenda-sticky
1958 ;; Creating a sticky Agenda buffer for the first time
1959 (kill-all-local-variables)
1960 (mapc 'make-local-variable org-agenda-local-vars)
1961 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1963 ;; Creating a non-sticky agenda buffer
1964 (kill-all-local-variables)
1965 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1966 (setq org-agenda-undo-list nil
1967 org-agenda-pending-undo-list nil
1968 org-agenda-bulk-marked-entries nil)
1969 (setq major-mode 'org-agenda-mode)
1970 ;; Keep global-font-lock-mode from turning on font-lock-mode
1971 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1972 (setq mode-name "Org-Agenda")
1973 (use-local-map org-agenda-mode-map)
1974 (easy-menu-add org-agenda-menu)
1975 (if org-startup-truncated (setq truncate-lines t))
1976 (org-set-local 'line-move-visual nil)
1977 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
1978 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1979 ;; Make sure properties are removed when copying text
1980 (make-local-variable 'filter-buffer-substring-functions)
1981 (add-hook 'filter-buffer-substring-functions
1982 (lambda (fun start end delete)
1983 (substring-no-properties (funcall fun start end delete))))
1984 (unless org-agenda-keep-modes
1985 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1986 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1987 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1988 org-agenda-show-log org-agenda-start-with-log-mode))
1990 (easy-menu-change
1991 '("Agenda") "Agenda Files"
1992 (append
1993 (list
1994 (vector
1995 (if (get 'org-agenda-files 'org-restrict)
1996 "Restricted to single file"
1997 "Edit File List")
1998 '(org-edit-agenda-file-list)
1999 (not (get 'org-agenda-files 'org-restrict)))
2000 "--")
2001 (mapcar 'org-file-menu-entry (org-agenda-files))))
2002 (org-agenda-set-mode-name)
2003 (apply
2004 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2005 (list 'org-agenda-mode-hook)))
2007 (substitute-key-definition 'undo 'org-agenda-undo
2008 org-agenda-mode-map global-map)
2009 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2010 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2011 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2012 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2013 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2014 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2015 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2016 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2017 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2018 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2019 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2020 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2021 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2022 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2023 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2024 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2025 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2026 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2027 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2028 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2029 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2030 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2031 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2032 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2033 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2034 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2035 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2036 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2037 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2038 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2039 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2040 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2041 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2042 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2043 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2044 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2045 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2046 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2047 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2048 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2049 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2050 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2051 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2052 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2053 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2054 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2056 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2057 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2058 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2059 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2060 (while l (org-defkey org-agenda-mode-map
2061 (int-to-string (pop l)) 'digit-argument)))
2063 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2064 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2065 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2066 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2067 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2068 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2069 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2070 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2071 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2072 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2073 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2074 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2075 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2076 'org-clock-modify-effort-estimate)
2077 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2078 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2079 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2080 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2081 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2082 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2083 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2084 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2085 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2086 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2087 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2088 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2089 (substitute-key-definition 'next-line 'org-agenda-next-line
2090 org-agenda-mode-map global-map)
2091 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2092 org-agenda-mode-map global-map)
2093 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2094 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2095 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2096 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2097 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2098 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2099 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2100 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2101 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2102 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2103 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2104 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2105 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2106 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2107 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2108 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2109 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2110 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2111 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2112 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2113 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2114 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2115 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2116 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2117 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2118 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2119 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2120 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2121 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2122 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2124 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2125 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2126 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2127 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2128 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2129 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2130 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2131 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2132 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2133 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2134 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2135 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2137 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2138 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2139 (when org-agenda-mouse-1-follows-link
2140 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2141 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2142 '("Agenda"
2143 ("Agenda Files")
2144 "--"
2145 ("Agenda Dates"
2146 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2147 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2148 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2149 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2150 "--"
2151 ("View"
2152 ["Day View" org-agenda-day-view
2153 :active (org-agenda-check-type nil 'agenda)
2154 :style radio :selected (eq org-agenda-current-span 'day)
2155 :keys "v d (or just d)"]
2156 ["Week View" org-agenda-week-view
2157 :active (org-agenda-check-type nil 'agenda)
2158 :style radio :selected (eq org-agenda-current-span 'week)
2159 :keys "v w (or just w)"]
2160 ["Month View" org-agenda-month-view
2161 :active (org-agenda-check-type nil 'agenda)
2162 :style radio :selected (eq org-agenda-current-span 'month)
2163 :keys "v m"]
2164 ["Year View" org-agenda-year-view
2165 :active (org-agenda-check-type nil 'agenda)
2166 :style radio :selected (eq org-agenda-current-span 'year)
2167 :keys "v y"]
2168 "--"
2169 ["Include Diary" org-agenda-toggle-diary
2170 :style toggle :selected org-agenda-include-diary
2171 :active (org-agenda-check-type nil 'agenda)]
2172 ["Include Deadlines" org-agenda-toggle-deadlines
2173 :style toggle :selected org-agenda-include-deadlines
2174 :active (org-agenda-check-type nil 'agenda)]
2175 ["Use Time Grid" org-agenda-toggle-time-grid
2176 :style toggle :selected org-agenda-use-time-grid
2177 :active (org-agenda-check-type nil 'agenda)]
2178 "--"
2179 ["Show clock report" org-agenda-clockreport-mode
2180 :style toggle :selected org-agenda-clockreport-mode
2181 :active (org-agenda-check-type nil 'agenda)]
2182 ["Show some entry text" org-agenda-entry-text-mode
2183 :style toggle :selected org-agenda-entry-text-mode
2184 :active t]
2185 "--"
2186 ["Show Logbook entries" org-agenda-log-mode
2187 :style toggle :selected org-agenda-show-log
2188 :active (org-agenda-check-type nil 'agenda 'timeline)
2189 :keys "v l (or just l)"]
2190 ["Include archived trees" org-agenda-archives-mode
2191 :style toggle :selected org-agenda-archives-mode :active t
2192 :keys "v a"]
2193 ["Include archive files" (org-agenda-archives-mode t)
2194 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2195 :keys "v A"]
2196 "--"
2197 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2198 ["Write view to file" org-agenda-write t]
2199 ["Rebuild buffer" org-agenda-redo t]
2200 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2201 "--"
2202 ["Show original entry" org-agenda-show t]
2203 ["Go To (other window)" org-agenda-goto t]
2204 ["Go To (this window)" org-agenda-switch-to t]
2205 ["Capture with cursor date" org-agenda-capture t]
2206 ["Follow Mode" org-agenda-follow-mode
2207 :style toggle :selected org-agenda-follow-mode :active t]
2208 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2209 "--"
2210 ("TODO"
2211 ["Cycle TODO" org-agenda-todo t]
2212 ["Next TODO set" org-agenda-todo-nextset t]
2213 ["Previous TODO set" org-agenda-todo-previousset t]
2214 ["Add note" org-agenda-add-note t])
2215 ("Archive/Refile/Delete"
2216 ["Archive default" org-agenda-archive-default t]
2217 ["Archive default" org-agenda-archive-default-with-confirmation t]
2218 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2219 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2220 ["Archive subtree" org-agenda-archive t]
2221 "--"
2222 ["Refile" org-agenda-refile t]
2223 "--"
2224 ["Delete subtree" org-agenda-kill t])
2225 ("Bulk action"
2226 ["Mark entry" org-agenda-bulk-mark t]
2227 ["Mark all" org-agenda-bulk-mark-all t]
2228 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2229 ["Unmark entry" org-agenda-bulk-unmark t]
2230 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2231 ["Act on all marked" org-agenda-bulk-action t]
2232 "--"
2233 ("Tags and Properties"
2234 ["Show all Tags" org-agenda-show-tags t]
2235 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2236 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2237 "--"
2238 ["Column View" org-columns t])
2239 ("Deadline/Schedule"
2240 ["Schedule" org-agenda-schedule t]
2241 ["Set Deadline" org-agenda-deadline t]
2242 "--"
2243 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2244 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2245 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2246 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2247 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2248 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2249 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2250 ("Clock and Effort"
2251 ["Clock in" org-agenda-clock-in t]
2252 ["Clock out" org-agenda-clock-out t]
2253 ["Clock cancel" org-agenda-clock-cancel t]
2254 ["Goto running clock" org-clock-goto t]
2255 "--"
2256 ["Set Effort" org-agenda-set-effort t]
2257 ["Change clocked effort" org-clock-modify-effort-estimate
2258 (org-clock-is-active)])
2259 ("Priority"
2260 ["Set Priority" org-agenda-priority t]
2261 ["Increase Priority" org-agenda-priority-up t]
2262 ["Decrease Priority" org-agenda-priority-down t]
2263 ["Show Priority" org-show-priority t])
2264 ("Calendar/Diary"
2265 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2266 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2267 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2268 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2269 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2270 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2271 "--"
2272 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2273 "--"
2274 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2275 "--"
2276 ("MobileOrg"
2277 ["Push Files and Views" org-mobile-push t]
2278 ["Get Captured and Flagged" org-mobile-pull t]
2279 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2280 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2281 "--"
2282 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2283 "--"
2284 ["Quit" org-agenda-quit t]
2285 ["Exit and Release Buffers" org-agenda-exit t]
2288 ;;; Agenda undo
2290 (defvar org-agenda-allow-remote-undo t
2291 "Non-nil means allow remote undo from the agenda buffer.")
2292 (defvar org-agenda-undo-has-started-in nil
2293 "Buffers that have already seen `undo-start' in the current undo sequence.")
2295 (defun org-agenda-undo ()
2296 "Undo a remote editing step in the agenda.
2297 This undoes changes both in the agenda buffer and in the remote buffer
2298 that have been changed along."
2299 (interactive)
2300 (or org-agenda-allow-remote-undo
2301 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2302 (if (not (eq this-command last-command))
2303 (setq org-agenda-undo-has-started-in nil
2304 org-agenda-pending-undo-list org-agenda-undo-list))
2305 (if (not org-agenda-pending-undo-list)
2306 (error "No further undo information"))
2307 (let* ((entry (pop org-agenda-pending-undo-list))
2308 buf line cmd rembuf)
2309 (setq cmd (pop entry) line (pop entry))
2310 (setq rembuf (nth 2 entry))
2311 (org-with-remote-undo rembuf
2312 (while (bufferp (setq buf (pop entry)))
2313 (if (pop entry)
2314 (with-current-buffer buf
2315 (let ((last-undo-buffer buf)
2316 (inhibit-read-only t))
2317 (unless (memq buf org-agenda-undo-has-started-in)
2318 (push buf org-agenda-undo-has-started-in)
2319 (make-local-variable 'pending-undo-list)
2320 (undo-start))
2321 (while (and pending-undo-list
2322 (listp pending-undo-list)
2323 (not (car pending-undo-list)))
2324 (pop pending-undo-list))
2325 (undo-more 1))))))
2326 (org-goto-line line)
2327 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2329 (defun org-verify-change-for-undo (l1 l2)
2330 "Verify that a real change occurred between the undo lists L1 and L2."
2331 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2332 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2333 (not (eq l1 l2)))
2335 ;;; Agenda dispatch
2337 (defvar org-agenda-restrict-begin (make-marker))
2338 (defvar org-agenda-restrict-end (make-marker))
2339 (defvar org-agenda-last-dispatch-buffer nil)
2340 (defvar org-agenda-overriding-restriction nil)
2342 (defcustom org-agenda-custom-commands-contexts nil
2343 "Alist of custom agenda keys and contextual rules.
2345 For example, if you have a custom agenda command \"p\" and you
2346 want this command to be accessible only from plain text files,
2347 use this:
2349 '((\"p\" (in-file . \"\\.txt\")))
2351 Here are the available contexts definitions:
2353 in-file: command displayed only in matching files
2354 in-mode: command displayed only in matching modes
2355 not-in-file: command not displayed in matching files
2356 not-in-mode: command not displayed in matching modes
2357 [function]: a custom function taking no argument
2359 If you define several checks, the agenda command will be
2360 accessible if there is at least one valid check.
2362 You can also bind a key to another agenda custom command
2363 depending on contextual rules.
2365 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2367 Here it means: in .txt files, use \"p\" as the key for the
2368 agenda command otherwise associated with \"q\". (The command
2369 originally associated with \"q\" is not displayed to avoid
2370 duplicates.)"
2371 :version "24.3"
2372 :group 'org-agenda-custom-commands
2373 :type '(repeat (list :tag "Rule"
2374 (string :tag " Agenda key")
2375 (string :tag "Replace by command")
2376 (repeat :tag "Available when"
2377 (choice
2378 (cons :tag "Condition"
2379 (choice
2380 (const :tag "In file" in-file)
2381 (const :tag "Not in file" not-in-file)
2382 (const :tag "In mode" in-mode)
2383 (const :tag "Not in mode" not-in-mode))
2384 (regexp))
2385 (function :tag "Custom function"))))))
2387 (defvar org-keys nil)
2388 (defvar org-match nil)
2389 ;;;###autoload
2390 (defun org-agenda (&optional arg org-keys restriction)
2391 "Dispatch agenda commands to collect entries to the agenda buffer.
2392 Prompts for a command to execute. Any prefix arg will be passed
2393 on to the selected command. The default selections are:
2395 a Call `org-agenda-list' to display the agenda for current day or week.
2396 t Call `org-todo-list' to display the global todo list.
2397 T Call `org-todo-list' to display the global todo list, select only
2398 entries with a specific TODO keyword (the user gets a prompt).
2399 m Call `org-tags-view' to display headlines with tags matching
2400 a condition (the user is prompted for the condition).
2401 M Like `m', but select only TODO entries, no ordinary headlines.
2402 L Create a timeline for the current buffer.
2403 e Export views to associated files.
2404 s Search entries for keywords.
2405 S Search entries for keywords, only with TODO keywords.
2406 / Multi occur across all agenda files and also files listed
2407 in `org-agenda-text-search-extra-files'.
2408 < Restrict agenda commands to buffer, subtree, or region.
2409 Press several times to get the desired effect.
2410 > Remove a previous restriction.
2411 # List \"stuck\" projects.
2412 ! Configure what \"stuck\" means.
2413 C Configure custom agenda commands.
2415 More commands can be added by configuring the variable
2416 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2417 searches can be pre-defined in this way.
2419 If the current buffer is in Org-mode and visiting a file, you can also
2420 first press `<' once to indicate that the agenda should be temporarily
2421 \(until the next use of \\[org-agenda]) restricted to the current file.
2422 Pressing `<' twice means to restrict to the current subtree or region
2423 \(if active)."
2424 (interactive "P")
2425 (catch 'exit
2426 (let* ((prefix-descriptions nil)
2427 (org-agenda-buffer-name org-agenda-buffer-name)
2428 (org-agenda-window-setup (if (equal (buffer-name)
2429 org-agenda-buffer-name)
2430 'current-window
2431 org-agenda-window-setup))
2432 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2433 (org-agenda-custom-commands
2434 ;; normalize different versions
2435 (delq nil
2436 (mapcar
2437 (lambda (x)
2438 (cond ((stringp (cdr x))
2439 (push x prefix-descriptions)
2440 nil)
2441 ((stringp (nth 1 x)) x)
2442 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2443 (t (cons (car x) (cons "" (cdr x))))))
2444 org-agenda-custom-commands)))
2445 (org-agenda-custom-commands
2446 (org-contextualize-keys
2447 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2448 (buf (current-buffer))
2449 (bfn (buffer-file-name (buffer-base-buffer)))
2450 entry key type org-match lprops ans)
2451 ;; Turn off restriction unless there is an overriding one,
2452 (unless org-agenda-overriding-restriction
2453 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2454 ;; There is a request to keep the file list in place
2455 (put 'org-agenda-files 'org-restrict nil))
2456 (setq org-agenda-restrict nil)
2457 (move-marker org-agenda-restrict-begin nil)
2458 (move-marker org-agenda-restrict-end nil))
2459 ;; Delete old local properties
2460 (put 'org-agenda-redo-command 'org-lprops nil)
2461 ;; Delete previously set last-arguments
2462 (put 'org-agenda-redo-command 'last-args nil)
2463 ;; Remember where this call originated
2464 (setq org-agenda-last-dispatch-buffer (current-buffer))
2465 (unless org-keys
2466 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2467 org-keys (car ans)
2468 restriction (cdr ans)))
2469 ;; If we have sticky agenda buffers, set a name for the buffer,
2470 ;; depending on the invoking keys. The user may still set this
2471 ;; as a command option, which will overwrite what we do here.
2472 (if org-agenda-sticky
2473 (setq org-agenda-buffer-name
2474 (format "*Org Agenda(%s)*" org-keys)))
2475 ;; Establish the restriction, if any
2476 (when (and (not org-agenda-overriding-restriction) restriction)
2477 (put 'org-agenda-files 'org-restrict (list bfn))
2478 (cond
2479 ((eq restriction 'region)
2480 (setq org-agenda-restrict t)
2481 (move-marker org-agenda-restrict-begin (region-beginning))
2482 (move-marker org-agenda-restrict-end (region-end)))
2483 ((eq restriction 'subtree)
2484 (save-excursion
2485 (setq org-agenda-restrict t)
2486 (org-back-to-heading t)
2487 (move-marker org-agenda-restrict-begin (point))
2488 (move-marker org-agenda-restrict-end
2489 (progn (org-end-of-subtree t)))))))
2491 ;; For example the todo list should not need it (but does...)
2492 (cond
2493 ((setq entry (assoc org-keys org-agenda-custom-commands))
2494 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2495 (progn
2496 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2497 lprops (nth 4 entry))
2498 (if org-agenda-sticky
2499 (setq org-agenda-buffer-name
2500 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2501 (format "*Org Agenda(%s)*" org-keys))))
2502 (put 'org-agenda-redo-command 'org-lprops lprops)
2503 (cond
2504 ((eq type 'agenda)
2505 (org-let lprops '(org-agenda-list current-prefix-arg)))
2506 ((eq type 'alltodo)
2507 (org-let lprops '(org-todo-list current-prefix-arg)))
2508 ((eq type 'search)
2509 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2510 ((eq type 'stuck)
2511 (org-let lprops '(org-agenda-list-stuck-projects
2512 current-prefix-arg)))
2513 ((eq type 'tags)
2514 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2515 ((eq type 'tags-todo)
2516 (org-let lprops '(org-tags-view '(4) org-match)))
2517 ((eq type 'todo)
2518 (org-let lprops '(org-todo-list org-match)))
2519 ((eq type 'tags-tree)
2520 (org-check-for-org-mode)
2521 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2522 ((eq type 'todo-tree)
2523 (org-check-for-org-mode)
2524 (org-let lprops
2525 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2526 (regexp-quote org-match) "\\>"))))
2527 ((eq type 'occur-tree)
2528 (org-check-for-org-mode)
2529 (org-let lprops '(org-occur org-match)))
2530 ((functionp type)
2531 (org-let lprops '(funcall type org-match)))
2532 ((fboundp type)
2533 (org-let lprops '(funcall type org-match)))
2534 (t (error "Invalid custom agenda command type %s" type))))
2535 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2536 ((equal org-keys "C")
2537 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2538 (customize-variable 'org-agenda-custom-commands))
2539 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2540 ((equal org-keys "s") (call-interactively 'org-search-view))
2541 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2542 ((equal org-keys "t") (call-interactively 'org-todo-list))
2543 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2544 ((equal org-keys "m") (call-interactively 'org-tags-view))
2545 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2546 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2547 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2548 (org-add-hook
2549 'post-command-hook
2550 (lambda ()
2551 (unless (current-message)
2552 (let* ((m (org-agenda-get-any-marker))
2553 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2554 (when note
2555 (message (concat
2556 "FLAGGING-NOTE ([?] for more info): "
2557 (org-add-props
2558 (replace-regexp-in-string
2559 "\\\\n" "//"
2560 (copy-sequence note))
2561 nil 'face 'org-warning)))))))
2562 t t))
2563 ((equal org-keys "L")
2564 (unless (derived-mode-p 'org-mode)
2565 (error "This is not an Org-mode file"))
2566 (unless restriction
2567 (put 'org-agenda-files 'org-restrict (list bfn))
2568 (org-call-with-arg 'org-timeline arg)))
2569 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2570 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2571 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2572 (t (error "Invalid agenda key"))))))
2574 (autoload 'org-agenda "org-agenda" "\
2575 Dispatch agenda commands to collect entries to the agenda buffer.
2576 Prompts for a command to execute. Any prefix arg will be passed
2577 on to the selected command. The default selections are:
2579 a Call `org-agenda-list' to display the agenda for current day or week.
2580 t Call `org-todo-list' to display the global todo list.
2581 T Call `org-todo-list' to display the global todo list, select only
2582 entries with a specific TODO keyword (the user gets a prompt).
2583 m Call `org-tags-view' to display headlines with tags matching
2584 a condition (the user is prompted for the condition).
2585 M Like `m', but select only TODO entries, no ordinary headlines.
2586 L Create a timeline for the current buffer.
2587 e Export views to associated files.
2588 s Search entries for keywords.
2589 S Search entries for keywords, only with TODO keywords.
2590 / Multi occur across all agenda files and also files listed
2591 in `org-agenda-text-search-extra-files'.
2592 < Restrict agenda commands to buffer, subtree, or region.
2593 Press several times to get the desired effect.
2594 > Remove a previous restriction.
2595 # List \"stuck\" projects.
2596 ! Configure what \"stuck\" means.
2597 C Configure custom agenda commands.
2599 More commands can be added by configuring the variable
2600 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2601 searches can be pre-defined in this way.
2603 If the current buffer is in Org-mode and visiting a file, you can also
2604 first press `<' once to indicate that the agenda should be temporarily
2605 \(until the next use of \\[org-agenda]) restricted to the current file.
2606 Pressing `<' twice means to restrict to the current subtree or region
2607 \(if active).
2609 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2611 (defun org-agenda-append-agenda ()
2612 "Append another agenda view to the current one.
2613 This function allows interactive building of block agendas.
2614 Agenda views are separated by `org-agenda-block-separator'."
2615 (interactive)
2616 (unless (derived-mode-p 'org-agenda-mode)
2617 (error "Can only append from within agenda buffer"))
2618 (let ((org-agenda-multi t))
2619 (org-agenda)
2620 (widen)
2621 (org-agenda-finalize)
2622 (org-agenda-fit-window-to-buffer)))
2624 (defun org-agenda-normalize-custom-commands (cmds)
2625 (delq nil
2626 (mapcar
2627 (lambda (x)
2628 (cond ((stringp (cdr x)) nil)
2629 ((stringp (nth 1 x)) x)
2630 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2631 (t (cons (car x) (cons "" (cdr x))))))
2632 cmds)))
2634 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2635 "The user interface for selecting an agenda command."
2636 (catch 'exit
2637 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2638 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2639 (region-p (org-region-active-p))
2640 (custom org-agenda-custom-commands)
2641 (selstring "")
2642 restriction second-time
2643 c entry key type match prefixes rmheader header-end custom1 desc
2644 line lines left right n n1)
2645 (save-window-excursion
2646 (delete-other-windows)
2647 (org-switch-to-buffer-other-window " *Agenda Commands*")
2648 (erase-buffer)
2649 (insert (eval-when-compile
2650 (let ((header
2651 "Press key for an agenda command: < Buffer, subtree/region restriction
2652 -------------------------------- > Remove restriction
2653 a Agenda for current week or day e Export agenda views
2654 t List of all TODO entries T Entries with special TODO kwd
2655 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2656 s Search for keywords S Like s, but only TODO entries
2657 L Timeline for current buffer # List stuck projects (!=configure)
2658 / Multi-occur C Configure custom agenda commands
2659 ? Find :FLAGGED: entries * Toggle sticky agenda views
2661 (start 0))
2662 (while (string-match
2663 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2664 header start)
2665 (setq start (match-end 0))
2666 (add-text-properties (match-beginning 2) (match-end 2)
2667 '(face bold) header))
2668 header)))
2669 (setq header-end (point-marker))
2670 (while t
2671 (setq custom1 custom)
2672 (when (eq rmheader t)
2673 (org-goto-line 1)
2674 (re-search-forward ":" nil t)
2675 (delete-region (match-end 0) (point-at-eol))
2676 (forward-char 1)
2677 (looking-at "-+")
2678 (delete-region (match-end 0) (point-at-eol))
2679 (move-marker header-end (match-end 0)))
2680 (goto-char header-end)
2681 (delete-region (point) (point-max))
2683 ;; Produce all the lines that describe custom commands and prefixes
2684 (setq lines nil)
2685 (while (setq entry (pop custom1))
2686 (setq key (car entry) desc (nth 1 entry)
2687 type (nth 2 entry)
2688 match (nth 3 entry))
2689 (if (> (length key) 1)
2690 (add-to-list 'prefixes (string-to-char key))
2691 (setq line
2692 (format
2693 "%-4s%-14s"
2694 (org-add-props (copy-sequence key)
2695 '(face bold))
2696 (cond
2697 ((string-match "\\S-" desc) desc)
2698 ((eq type 'agenda) "Agenda for current week or day")
2699 ((eq type 'alltodo) "List of all TODO entries")
2700 ((eq type 'search) "Word search")
2701 ((eq type 'stuck) "List of stuck projects")
2702 ((eq type 'todo) "TODO keyword")
2703 ((eq type 'tags) "Tags query")
2704 ((eq type 'tags-todo) "Tags (TODO)")
2705 ((eq type 'tags-tree) "Tags tree")
2706 ((eq type 'todo-tree) "TODO kwd tree")
2707 ((eq type 'occur-tree) "Occur tree")
2708 ((functionp type) (if (symbolp type)
2709 (symbol-name type)
2710 "Lambda expression"))
2711 (t "???"))))
2712 (if org-agenda-menu-show-matcher
2713 (setq line
2714 (concat line ": "
2715 (cond
2716 ((stringp match)
2717 (setq match (copy-sequence match))
2718 (org-add-props match nil 'face 'org-warning))
2719 ((listp type)
2720 (format "set of %d commands" (length type))))))
2721 (if (org-string-nw-p match)
2722 (add-text-properties
2723 0 (length line) (list 'help-echo
2724 (concat "Matcher: " match)) line)))
2725 (push line lines)))
2726 (setq lines (nreverse lines))
2727 (when prefixes
2728 (mapc (lambda (x)
2729 (push
2730 (format "%s %s"
2731 (org-add-props (char-to-string x)
2732 nil 'face 'bold)
2733 (or (cdr (assoc (concat selstring
2734 (char-to-string x))
2735 prefix-descriptions))
2736 "Prefix key"))
2737 lines))
2738 prefixes))
2740 ;; Check if we should display in two columns
2741 (if org-agenda-menu-two-columns
2742 (progn
2743 (setq n (length lines)
2744 n1 (+ (/ n 2) (mod n 2))
2745 right (nthcdr n1 lines)
2746 left (copy-sequence lines))
2747 (setcdr (nthcdr (1- n1) left) nil))
2748 (setq left lines right nil))
2749 (while left
2750 (insert "\n" (pop left))
2751 (when right
2752 (if (< (current-column) 40)
2753 (move-to-column 40 t)
2754 (insert " "))
2755 (insert (pop right))))
2757 ;; Make the window the right size
2758 (goto-char (point-min))
2759 (if second-time
2760 (if (not (pos-visible-in-window-p (point-max)))
2761 (org-fit-window-to-buffer))
2762 (setq second-time t)
2763 (org-fit-window-to-buffer))
2765 ;; Ask for selection
2766 (message "Press key for agenda command%s:"
2767 (if (or restrict-ok org-agenda-overriding-restriction)
2768 (if org-agenda-overriding-restriction
2769 " (restriction lock active)"
2770 (if restriction
2771 (format " (restricted to %s)" restriction)
2772 " (unrestricted)"))
2773 ""))
2774 (setq c (read-char-exclusive))
2775 (message "")
2776 (cond
2777 ((assoc (char-to-string c) custom)
2778 (setq selstring (concat selstring (char-to-string c)))
2779 (throw 'exit (cons selstring restriction)))
2780 ((memq c prefixes)
2781 (setq selstring (concat selstring (char-to-string c))
2782 prefixes nil
2783 rmheader (or rmheader t)
2784 custom (delq nil (mapcar
2785 (lambda (x)
2786 (if (or (= (length (car x)) 1)
2787 (/= (string-to-char (car x)) c))
2789 (cons (substring (car x) 1) (cdr x))))
2790 custom))))
2791 ((eq c ?*)
2792 (call-interactively 'org-toggle-sticky-agenda)
2793 (sit-for 2))
2794 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2795 (message "Restriction is only possible in Org-mode buffers")
2796 (ding) (sit-for 1))
2797 ((eq c ?1)
2798 (org-agenda-remove-restriction-lock 'noupdate)
2799 (setq restriction 'buffer))
2800 ((eq c ?0)
2801 (org-agenda-remove-restriction-lock 'noupdate)
2802 (setq restriction (if region-p 'region 'subtree)))
2803 ((eq c ?<)
2804 (org-agenda-remove-restriction-lock 'noupdate)
2805 (setq restriction
2806 (cond
2807 ((eq restriction 'buffer)
2808 (if region-p 'region 'subtree))
2809 ((memq restriction '(subtree region))
2810 nil)
2811 (t 'buffer))))
2812 ((eq c ?>)
2813 (org-agenda-remove-restriction-lock 'noupdate)
2814 (setq restriction nil))
2815 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2816 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2817 ((and (> (length selstring) 0) (eq c ?\d))
2818 (delete-window)
2819 (org-agenda-get-restriction-and-command prefix-descriptions))
2821 ((equal c ?q) (error "Abort"))
2822 (t (error "Invalid key %c" c))))))))
2824 (defun org-agenda-fit-window-to-buffer ()
2825 "Fit the window to the buffer size."
2826 (and (memq org-agenda-window-setup '(reorganize-frame))
2827 (fboundp 'fit-window-to-buffer)
2828 (org-fit-window-to-buffer
2830 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2831 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2833 (defvar org-cmd nil)
2834 (defvar org-agenda-overriding-cmd nil)
2835 (defvar org-agenda-overriding-arguments nil)
2836 (defvar org-agenda-overriding-cmd-arguments nil)
2837 (defun org-agenda-run-series (name series)
2838 (org-let (nth 1 series) '(org-agenda-prepare name))
2839 ;; We need to reset agenda markers here, because when constructing a
2840 ;; block agenda, the individual blocks do not do that.
2841 (org-agenda-reset-markers)
2842 (let* ((org-agenda-multi t)
2843 (redo (list 'org-agenda-run-series name (list 'quote series)))
2844 (cmds (car series))
2845 (gprops (nth 1 series))
2846 match ;; The byte compiler incorrectly complains about this. Keep it!
2847 org-cmd type lprops)
2848 (while (setq org-cmd (pop cmds))
2849 (setq type (car org-cmd)
2850 match (eval (nth 1 org-cmd))
2851 lprops (nth 2 org-cmd))
2852 (let ((org-agenda-overriding-arguments
2853 (if (eq org-agenda-overriding-cmd org-cmd)
2854 (or org-agenda-overriding-arguments
2855 org-agenda-overriding-cmd-arguments))))
2856 (cond
2857 ((eq type 'agenda)
2858 (org-let2 gprops lprops
2859 '(call-interactively 'org-agenda-list)))
2860 ((eq type 'alltodo)
2861 (org-let2 gprops lprops
2862 '(call-interactively 'org-todo-list)))
2863 ((eq type 'search)
2864 (org-let2 gprops lprops
2865 '(org-search-view current-prefix-arg match nil)))
2866 ((eq type 'stuck)
2867 (org-let2 gprops lprops
2868 '(call-interactively 'org-agenda-list-stuck-projects)))
2869 ((eq type 'tags)
2870 (org-let2 gprops lprops
2871 '(org-tags-view current-prefix-arg match)))
2872 ((eq type 'tags-todo)
2873 (org-let2 gprops lprops
2874 '(org-tags-view '(4) match)))
2875 ((eq type 'todo)
2876 (org-let2 gprops lprops
2877 '(org-todo-list match)))
2878 ((fboundp type)
2879 (org-let2 gprops lprops
2880 '(funcall type match)))
2881 (t (error "Invalid type in command series")))))
2882 (widen)
2883 (let ((inhibit-read-only t))
2884 (add-text-properties (point-min) (point-max)
2885 `(org-series t org-series-redo-cmd ,redo)))
2886 (setq org-agenda-redo-command redo)
2887 (goto-char (point-min)))
2888 (org-agenda-fit-window-to-buffer)
2889 (org-let (nth 1 series) '(org-agenda-finalize)))
2891 ;;;###autoload
2892 (defmacro org-batch-agenda (cmd-key &rest parameters)
2893 "Run an agenda command in batch mode and send the result to STDOUT.
2894 If CMD-KEY is a string of length 1, it is used as a key in
2895 `org-agenda-custom-commands' and triggers this command. If it is a
2896 longer string it is used as a tags/todo match string.
2897 Parameters are alternating variable names and values that will be bound
2898 before running the agenda command."
2899 (org-eval-in-environment (org-make-parameter-alist parameters)
2900 (if (> (length cmd-key) 2)
2901 (org-tags-view nil cmd-key)
2902 (org-agenda nil cmd-key)))
2903 (set-buffer org-agenda-buffer-name)
2904 (princ (buffer-string)))
2906 (autoload 'org-batch-agenda "org-agenda" "\
2907 Run an agenda command in batch mode and send the result to STDOUT.
2908 If CMD-KEY is a string of length 1, it is used as a key in
2909 `org-agenda-custom-commands' and triggers this command. If it is a
2910 longer string it is used as a tags/todo match string.
2911 Parameters are alternating variable names and values that will be bound
2912 before running the agenda command.
2914 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2915 (def-edebug-spec org-batch-agenda (form &rest sexp))
2917 (defvar org-agenda-info nil)
2919 ;;;###autoload
2920 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2921 "Run an agenda command in batch mode and send the result to STDOUT.
2922 If CMD-KEY is a string of length 1, it is used as a key in
2923 `org-agenda-custom-commands' and triggers this command. If it is a
2924 longer string it is used as a tags/todo match string.
2925 Parameters are alternating variable names and values that will be bound
2926 before running the agenda command.
2928 The output gives a line for each selected agenda item. Each
2929 item is a list of comma-separated values, like this:
2931 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2933 category The category of the item
2934 head The headline, without TODO kwd, TAGS and PRIORITY
2935 type The type of the agenda entry, can be
2936 todo selected in TODO match
2937 tagsmatch selected in tags match
2938 diary imported from diary
2939 deadline a deadline on given date
2940 scheduled scheduled on given date
2941 timestamp entry has timestamp on given date
2942 closed entry was closed on given date
2943 upcoming-deadline warning about deadline
2944 past-scheduled forwarded scheduled item
2945 block entry has date block including g. date
2946 todo The todo keyword, if any
2947 tags All tags including inherited ones, separated by colons
2948 date The relevant date, like 2007-2-14
2949 time The time, like 15:00-16:50
2950 extra Sting with extra planning info
2951 priority-l The priority letter if any was given
2952 priority-n The computed numerical priority
2953 agenda-day The day in the agenda where this is listed"
2954 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2955 (org-make-parameter-alist parameters))
2956 (if (> (length cmd-key) 2)
2957 (org-tags-view nil cmd-key)
2958 (org-agenda nil cmd-key)))
2959 (set-buffer org-agenda-buffer-name)
2960 (let* ((lines (org-split-string (buffer-string) "\n"))
2961 line)
2962 (while (setq line (pop lines))
2963 (catch 'next
2964 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2965 (setq org-agenda-info
2966 (org-fix-agenda-info (text-properties-at 0 line)))
2967 (princ
2968 (mapconcat 'org-agenda-export-csv-mapper
2969 '(org-category txt type todo tags date time extra
2970 priority-letter priority agenda-day)
2971 ","))
2972 (princ "\n")))))
2974 (autoload 'org-batch-agenda-csv "org-agenda" "\
2975 Run an agenda command in batch mode and send the result to STDOUT.
2976 If CMD-KEY is a string of length 1, it is used as a key in
2977 `org-agenda-custom-commands' and triggers this command. If it is a
2978 longer string it is used as a tags/todo match string.
2979 Parameters are alternating variable names and values that will be bound
2980 before running the agenda command.
2982 The output gives a line for each selected agenda item. Each
2983 item is a list of comma-separated values, like this:
2985 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2987 category The category of the item
2988 head The headline, without TODO kwd, TAGS and PRIORITY
2989 type The type of the agenda entry, can be
2990 todo selected in TODO match
2991 tagsmatch selected in tags match
2992 diary imported from diary
2993 deadline a deadline on given date
2994 scheduled scheduled on given date
2995 timestamp entry has timestamp on given date
2996 closed entry was closed on given date
2997 upcoming-deadline warning about deadline
2998 past-scheduled forwarded scheduled item
2999 block entry has date block including g. date
3000 todo The todo keyword, if any
3001 tags All tags including inherited ones, separated by colons
3002 date The relevant date, like 2007-2-14
3003 time The time, like 15:00-16:50
3004 extra Sting with extra planning info
3005 priority-l The priority letter if any was given
3006 priority-n The computed numerical priority
3007 agenda-day The day in the agenda where this is listed
3009 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3010 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3012 (defun org-fix-agenda-info (props)
3013 "Make sure all properties on an agenda item have a canonical form.
3014 This ensures the export commands can easily use it."
3015 (let (tmp re)
3016 (when (setq tmp (plist-get props 'tags))
3017 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3018 (when (setq tmp (plist-get props 'date))
3019 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3020 (let ((calendar-date-display-form '(year "-" month "-" day)))
3021 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3023 (setq tmp (calendar-date-string tmp)))
3024 (setq props (plist-put props 'date tmp)))
3025 (when (setq tmp (plist-get props 'day))
3026 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3027 (let ((calendar-date-display-form '(year "-" month "-" day)))
3028 (setq tmp (calendar-date-string tmp)))
3029 (setq props (plist-put props 'day tmp))
3030 (setq props (plist-put props 'agenda-day tmp)))
3031 (when (setq tmp (plist-get props 'txt))
3032 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3033 (plist-put props 'priority-letter (match-string 1 tmp))
3034 (setq tmp (replace-match "" t t tmp)))
3035 (when (and (setq re (plist-get props 'org-todo-regexp))
3036 (setq re (concat "\\`\\.*" re " ?"))
3037 (string-match re tmp))
3038 (plist-put props 'todo (match-string 1 tmp))
3039 (setq tmp (replace-match "" t t tmp)))
3040 (plist-put props 'txt tmp)))
3041 props)
3043 (defun org-agenda-export-csv-mapper (prop)
3044 (let ((res (plist-get org-agenda-info prop)))
3045 (setq res
3046 (cond
3047 ((not res) "")
3048 ((stringp res) res)
3049 (t (prin1-to-string res))))
3050 (while (string-match "," res)
3051 (setq res (replace-match ";" t t res)))
3052 (org-trim res)))
3054 ;;;###autoload
3055 (defun org-store-agenda-views (&rest parameters)
3056 (interactive)
3057 (eval (list 'org-batch-store-agenda-views)))
3059 (autoload 'org-store-agenda-views "org-agenda" "\
3062 \(fn &rest PARAMETERS)" t nil)
3064 ;;;###autoload
3065 (defmacro org-batch-store-agenda-views (&rest parameters)
3066 "Run all custom agenda commands that have a file argument."
3067 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3068 (pop-up-frames nil)
3069 (dir default-directory)
3070 (pars (org-make-parameter-alist parameters))
3071 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3072 (save-window-excursion
3073 (while cmds
3074 (setq cmd (pop cmds)
3075 thiscmdkey (car cmd)
3076 thiscmdcmd (cdr cmd)
3077 match (nth 2 thiscmdcmd)
3078 bufname (if org-agenda-sticky
3079 (or (and (stringp match)
3080 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3081 (format "*Org Agenda(%s)*" thiscmdkey))
3082 org-agenda-buffer-name)
3083 cmd-or-set (nth 2 cmd)
3084 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3085 files (nth (if (listp cmd-or-set) 4 5) cmd))
3086 (if (stringp files) (setq files (list files)))
3087 (when files
3088 (org-eval-in-environment (append org-agenda-exporter-settings
3089 opts pars)
3090 (org-agenda nil thiscmdkey))
3091 (set-buffer bufname)
3092 (while files
3093 (org-eval-in-environment (append org-agenda-exporter-settings
3094 opts pars)
3095 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3096 (and (get-buffer bufname)
3097 (kill-buffer bufname)))))))
3099 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3100 Run all custom agenda commands that have a file argument.
3102 \(fn &rest PARAMETERS)" nil t)
3103 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3105 (defvar org-agenda-current-span nil
3106 "The current span used in the agenda view.") ; local variable in the agenda buffer
3107 (defun org-agenda-mark-header-line (pos)
3108 "Mark the line at POS as an agenda structure header."
3109 (save-excursion
3110 (goto-char pos)
3111 (put-text-property (point-at-bol) (point-at-eol)
3112 'org-agenda-structural-header t)
3113 (when org-agenda-title-append
3114 (put-text-property (point-at-bol) (point-at-eol)
3115 'org-agenda-title-append org-agenda-title-append))))
3117 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3118 (defvar org-agenda-write-buffer-name "Agenda View")
3119 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3120 "Write the current buffer (an agenda view) as a file.
3121 Depending on the extension of the file name, plain text (.txt),
3122 HTML (.html or .htm) or Postscript (.ps) is produced.
3123 If the extension is .ics, run icalendar export over all files used
3124 to construct the agenda and limit the export to entries listed in the
3125 agenda now.
3126 With prefix argument OPEN, open the new file immediately.
3127 If NOSETTINGS is given, do not scope the settings of
3128 `org-agenda-exporter-settings' into the export commands. This is used when
3129 the settings have already been scoped and we do not wish to overrule other,
3130 higher priority settings.
3131 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3132 (interactive "FWrite agenda to file: \nP")
3133 (if (not (file-writable-p file))
3134 (error "Cannot write agenda to file %s" file))
3135 (org-let (if nosettings nil org-agenda-exporter-settings)
3136 '(save-excursion
3137 (save-window-excursion
3138 (org-agenda-mark-filtered-text)
3139 (let ((bs (copy-sequence (buffer-string))) beg)
3140 (org-agenda-unmark-filtered-text)
3141 (with-temp-buffer
3142 (rename-buffer org-agenda-write-buffer-name t)
3143 (set-buffer-modified-p nil)
3144 (insert bs)
3145 (org-agenda-remove-marked-text 'org-filtered)
3146 (while (setq beg (text-property-any (point-min) (point-max)
3147 'org-filtered t))
3148 (delete-region
3149 beg (or (next-single-property-change beg 'org-filtered)
3150 (point-max))))
3151 (run-hooks 'org-agenda-before-write-hook)
3152 (cond
3153 ((org-bound-and-true-p org-mobile-creating-agendas)
3154 (org-mobile-write-agenda-for-mobile file))
3155 ((string-match "\\.html?\\'" file)
3156 (require 'htmlize)
3157 (set-buffer (htmlize-buffer (current-buffer)))
3158 (when org-agenda-export-html-style
3159 ;; replace <style> section with org-agenda-export-html-style
3160 (goto-char (point-min))
3161 (kill-region (- (search-forward "<style") 6)
3162 (search-forward "</style>"))
3163 (insert org-agenda-export-html-style))
3164 (write-file file)
3165 (kill-buffer (current-buffer))
3166 (message "HTML written to %s" file))
3167 ((string-match "\\.ps\\'" file)
3168 (require 'ps-print)
3169 (ps-print-buffer-with-faces file)
3170 (message "Postscript written to %s" file))
3171 ((string-match "\\.pdf\\'" file)
3172 (require 'ps-print)
3173 (ps-print-buffer-with-faces
3174 (concat (file-name-sans-extension file) ".ps"))
3175 (call-process "ps2pdf" nil nil nil
3176 (expand-file-name
3177 (concat (file-name-sans-extension file) ".ps"))
3178 (expand-file-name file))
3179 (delete-file (concat (file-name-sans-extension file) ".ps"))
3180 (message "PDF written to %s" file))
3181 ((string-match "\\.ics\\'" file)
3182 (require 'org-icalendar)
3183 (let ((org-agenda-marker-table
3184 (org-create-marker-find-array
3185 (org-agenda-collect-markers)))
3186 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3187 (org-combined-agenda-icalendar-file file))
3188 (apply 'org-export-icalendar 'combine
3189 (org-agenda-files nil 'ifmode))))
3191 (let ((bs (buffer-string)))
3192 (find-file file)
3193 (erase-buffer)
3194 (insert bs)
3195 (save-buffer 0)
3196 (kill-buffer (current-buffer))
3197 (message "Plain text written to %s" file))))))))
3198 (set-buffer (or agenda-bufname
3199 (and (org-called-interactively-p 'any) (buffer-name))
3200 org-agenda-buffer-name)))
3201 (when open (org-open-file file)))
3203 (defvar org-agenda-tag-filter-overlays nil)
3204 (defvar org-agenda-cat-filter-overlays nil)
3206 (defun org-agenda-mark-filtered-text ()
3207 "Mark all text hidden by filtering with a text property."
3208 (let ((inhibit-read-only t))
3209 (mapc
3210 (lambda (o)
3211 (when (equal (overlay-buffer o) (current-buffer))
3212 (put-text-property
3213 (overlay-start o) (overlay-end o)
3214 'org-filtered t)))
3215 (append org-agenda-tag-filter-overlays
3216 org-agenda-cat-filter-overlays))))
3218 (defun org-agenda-unmark-filtered-text ()
3219 "Remove the filtering text property."
3220 (let ((inhibit-read-only t))
3221 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3223 (defun org-agenda-remove-marked-text (property &optional value)
3224 "Delete all text marked with VALUE of PROPERTY.
3225 VALUE defaults to t."
3226 (let (beg)
3227 (setq value (or value t))
3228 (while (setq beg (text-property-any (point-min) (point-max)
3229 property value))
3230 (delete-region
3231 beg (or (next-single-property-change beg 'org-filtered)
3232 (point-max))))))
3234 (defun org-agenda-add-entry-text ()
3235 "Add entry text to agenda lines.
3236 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3237 entry text following headings shown in the agenda.
3238 Drawers will be excluded, also the line with scheduling/deadline info."
3239 (when (and (> org-agenda-add-entry-text-maxlines 0)
3240 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3241 (let (m txt)
3242 (goto-char (point-min))
3243 (while (not (eobp))
3244 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3245 (beginning-of-line 2)
3246 (setq txt (org-agenda-get-some-entry-text
3247 m org-agenda-add-entry-text-maxlines " > "))
3248 (end-of-line 1)
3249 (if (string-match "\\S-" txt)
3250 (insert "\n" txt)
3251 (or (eobp) (forward-char 1))))))))
3253 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3254 &rest keep)
3255 "Extract entry text from MARKER, at most N-LINES lines.
3256 This will ignore drawers etc, just get the text.
3257 If INDENT is given, prefix every line with this string. If KEEP is
3258 given, it is a list of symbols, defining stuff that should not be
3259 removed from the entry content. Currently only `planning' is allowed here."
3260 (let (txt drawer-re kwd-time-re ind)
3261 (save-excursion
3262 (with-current-buffer (marker-buffer marker)
3263 (if (not (derived-mode-p 'org-mode))
3264 (setq txt "")
3265 (save-excursion
3266 (save-restriction
3267 (widen)
3268 (goto-char marker)
3269 (end-of-line 1)
3270 (setq txt (buffer-substring
3271 (min (1+ (point)) (point-max))
3272 (progn (outline-next-heading) (point)))
3273 drawer-re org-drawer-regexp
3274 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3275 ".*\n?"))
3276 (with-temp-buffer
3277 (insert txt)
3278 (when org-agenda-add-entry-text-descriptive-links
3279 (goto-char (point-min))
3280 (while (org-activate-bracket-links (point-max))
3281 (add-text-properties (match-beginning 0) (match-end 0)
3282 '(face org-link))))
3283 (goto-char (point-min))
3284 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3285 (set-text-properties (match-beginning 0) (match-end 0)
3286 nil))
3287 (goto-char (point-min))
3288 (while (re-search-forward drawer-re nil t)
3289 (delete-region
3290 (match-beginning 0)
3291 (progn (re-search-forward
3292 "^[ \t]*:END:.*\n?" nil 'move)
3293 (point))))
3294 (unless (member 'planning keep)
3295 (goto-char (point-min))
3296 (while (re-search-forward kwd-time-re nil t)
3297 (replace-match "")))
3298 (goto-char (point-min))
3299 (when org-agenda-entry-text-exclude-regexps
3300 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3301 (while (setq re (pop re-list))
3302 (goto-char (point-min))
3303 (while (re-search-forward re nil t)
3304 (replace-match "")))))
3305 (goto-char (point-max))
3306 (skip-chars-backward " \t\n")
3307 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3309 ;; find and remove min common indentation
3310 (goto-char (point-min))
3311 (untabify (point-min) (point-max))
3312 (setq ind (org-get-indentation))
3313 (while (not (eobp))
3314 (unless (looking-at "[ \t]*$")
3315 (setq ind (min ind (org-get-indentation))))
3316 (beginning-of-line 2))
3317 (goto-char (point-min))
3318 (while (not (eobp))
3319 (unless (looking-at "[ \t]*$")
3320 (move-to-column ind)
3321 (delete-region (point-at-bol) (point)))
3322 (beginning-of-line 2))
3324 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3326 (goto-char (point-min))
3327 (when indent
3328 (while (and (not (eobp)) (re-search-forward "^" nil t))
3329 (replace-match indent t t)))
3330 (goto-char (point-min))
3331 (while (looking-at "[ \t]*\n") (replace-match ""))
3332 (goto-char (point-max))
3333 (when (> (org-current-line)
3334 n-lines)
3335 (org-goto-line (1+ n-lines))
3336 (backward-char 1))
3337 (setq txt (buffer-substring (point-min) (point)))))))))
3338 txt))
3340 (defun org-agenda-collect-markers ()
3341 "Collect the markers pointing to entries in the agenda buffer."
3342 (let (m markers)
3343 (save-excursion
3344 (goto-char (point-min))
3345 (while (not (eobp))
3346 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3347 (org-get-at-bol 'org-marker)))
3348 (push m markers))
3349 (beginning-of-line 2)))
3350 (nreverse markers)))
3352 (defun org-create-marker-find-array (marker-list)
3353 "Create a alist of files names with all marker positions in that file."
3354 (let (f tbl m a p)
3355 (while (setq m (pop marker-list))
3356 (setq p (marker-position m)
3357 f (buffer-file-name (or (buffer-base-buffer
3358 (marker-buffer m))
3359 (marker-buffer m))))
3360 (if (setq a (assoc f tbl))
3361 (push (marker-position m) (cdr a))
3362 (push (list f p) tbl)))
3363 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3364 tbl)))
3366 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3367 (defun org-check-agenda-marker-table ()
3368 "Check of the current entry is on the marker list."
3369 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3371 (and (setq a (assoc file org-agenda-marker-table))
3372 (save-match-data
3373 (save-excursion
3374 (org-back-to-heading t)
3375 (member (point) (cdr a)))))))
3377 (defun org-check-for-org-mode ()
3378 "Make sure current buffer is in org-mode. Error if not."
3379 (or (derived-mode-p 'org-mode)
3380 (error "Cannot execute org-mode agenda command on buffer in %s"
3381 major-mode)))
3383 ;;; Agenda prepare and finalize
3385 (defvar org-agenda-multi nil) ; dynamically scoped
3386 (defvar org-agenda-pre-window-conf nil)
3387 (defvar org-agenda-columns-active nil)
3388 (defvar org-agenda-name nil)
3389 (defvar org-agenda-tag-filter nil)
3390 (defvar org-agenda-category-filter nil)
3391 (defvar org-agenda-top-category-filter nil)
3392 (defvar org-agenda-tag-filter-while-redo nil)
3393 (defvar org-agenda-tag-filter-preset nil
3394 "A preset of the tags filter used for secondary agenda filtering.
3395 This must be a list of strings, each string must be a single tag preceded
3396 by \"+\" or \"-\".
3397 This variable should not be set directly, but agenda custom commands can
3398 bind it in the options section. The preset filter is a global property of
3399 the entire agenda view. In a block agenda, it will not work reliably to
3400 define a filter for one of the individual blocks. You need to set it in
3401 the global options and expect it to be applied to the entire view.")
3403 (defvar org-agenda-category-filter-preset nil
3404 "A preset of the category filter used for secondary agenda filtering.
3405 This must be a list of strings, each string must be a single category
3406 preceded by \"+\" or \"-\".
3407 This variable should not be set directly, but agenda custom commands can
3408 bind it in the options section. The preset filter is a global property of
3409 the entire agenda view. In a block agenda, it will not work reliably to
3410 define a filter for one of the individual blocks. You need to set it in
3411 the global options and expect it to be applied to the entire view.")
3414 (defun org-agenda-use-sticky-p ()
3415 "Return non-nil if an agenda buffer named
3416 `org-agenda-buffer-name' exists and should be shown instead of
3417 generating a new one."
3418 (and
3419 ;; turned off by user
3420 org-agenda-sticky
3421 ;; For multi-agenda buffer already exists
3422 (not org-agenda-multi)
3423 ;; buffer found
3424 (get-buffer org-agenda-buffer-name)
3425 ;; C-u parameter is same as last call
3426 (with-current-buffer (get-buffer org-agenda-buffer-name)
3427 (and
3428 (equal current-prefix-arg
3429 org-agenda-last-prefix-arg)
3430 ;; In case user turned stickiness on, while having existing
3431 ;; Agenda buffer active, don't reuse that buffer, because it
3432 ;; does not have org variables local
3433 org-agenda-this-buffer-is-sticky))))
3435 (defun org-agenda-prepare-window (abuf)
3436 "Setup agenda buffer in the window."
3437 (let* ((awin (get-buffer-window abuf))
3438 wconf)
3439 (cond
3440 ((equal (current-buffer) abuf) nil)
3441 (awin (select-window awin))
3442 ((not (setq wconf (current-window-configuration))))
3443 ((equal org-agenda-window-setup 'current-window)
3444 (org-pop-to-buffer-same-window abuf))
3445 ((equal org-agenda-window-setup 'other-window)
3446 (org-switch-to-buffer-other-window abuf))
3447 ((equal org-agenda-window-setup 'other-frame)
3448 (switch-to-buffer-other-frame abuf))
3449 ((equal org-agenda-window-setup 'reorganize-frame)
3450 (delete-other-windows)
3451 (org-switch-to-buffer-other-window abuf)))
3452 ;; additional test in case agenda is invoked from within agenda
3453 ;; buffer via elisp link
3454 (unless (equal (current-buffer) abuf)
3455 (org-pop-to-buffer-same-window abuf))
3456 (setq org-agenda-pre-window-conf
3457 (or org-agenda-pre-window-conf wconf))))
3459 (defun org-agenda-prepare (&optional name)
3460 (if (org-agenda-use-sticky-p)
3461 (progn
3462 ;; Popup existing buffer
3463 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3464 (message "Sticky Agenda buffer, use `r' to refresh")
3465 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3466 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3467 (setq org-todo-keywords-for-agenda nil)
3468 (setq org-drawers-for-agenda nil)
3469 (unless org-agenda-persistent-filter
3470 (setq org-agenda-tag-filter nil
3471 org-agenda-category-filter nil))
3472 (put 'org-agenda-tag-filter :preset-filter
3473 org-agenda-tag-filter-preset)
3474 (put 'org-agenda-category-filter :preset-filter
3475 org-agenda-category-filter-preset)
3476 (if org-agenda-multi
3477 (progn
3478 (setq buffer-read-only nil)
3479 (goto-char (point-max))
3480 (unless (or (bobp) org-agenda-compact-blocks
3481 (not org-agenda-block-separator))
3482 (insert "\n"
3483 (if (stringp org-agenda-block-separator)
3484 org-agenda-block-separator
3485 (make-string (window-width) org-agenda-block-separator))
3486 "\n"))
3487 (narrow-to-region (point) (point-max)))
3488 (setq org-done-keywords-for-agenda nil)
3490 ;; Setting any org variables that are in org-agenda-local-vars
3491 ;; list need to be done after the prepare call
3492 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3493 (setq buffer-read-only nil)
3494 (org-agenda-reset-markers)
3495 (let ((inhibit-read-only t)) (erase-buffer))
3496 (org-agenda-mode)
3497 (setq org-agenda-buffer (current-buffer))
3498 (setq org-agenda-contributing-files nil)
3499 (setq org-agenda-columns-active nil)
3500 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3501 (setq org-todo-keywords-for-agenda
3502 (org-uniquify org-todo-keywords-for-agenda))
3503 (setq org-done-keywords-for-agenda
3504 (org-uniquify org-done-keywords-for-agenda))
3505 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3506 (setq org-agenda-last-prefix-arg current-prefix-arg)
3507 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3508 (and name (not org-agenda-name)
3509 (org-set-local 'org-agenda-name name)))
3510 (setq buffer-read-only nil)))
3512 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3513 (defun org-agenda-finalize ()
3514 "Finishing touch for the agenda buffer, called just before displaying it."
3515 (unless org-agenda-multi
3516 (save-excursion
3517 (let ((inhibit-read-only t))
3518 (goto-char (point-min))
3519 (save-excursion
3520 (while (org-activate-bracket-links (point-max))
3521 (add-text-properties (match-beginning 0) (match-end 0)
3522 '(face org-link))))
3523 (save-excursion
3524 (while (org-activate-plain-links (point-max))
3525 (add-text-properties (match-beginning 0) (match-end 0)
3526 '(face org-link))))
3527 (when (cadr (assoc 'org-prefix-has-tag
3528 (car org-prefix-format-compiled)))
3529 (org-agenda-align-tags))
3530 (unless org-agenda-with-colors
3531 (remove-text-properties (point-min) (point-max) '(face nil))))
3532 (if (and (boundp 'org-agenda-overriding-columns-format)
3533 org-agenda-overriding-columns-format)
3534 (org-set-local 'org-agenda-overriding-columns-format
3535 org-agenda-overriding-columns-format))
3536 (if (and (boundp 'org-agenda-view-columns-initially)
3537 org-agenda-view-columns-initially)
3538 (org-agenda-columns))
3539 (when org-agenda-fontify-priorities
3540 (org-agenda-fontify-priorities))
3541 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3542 (org-agenda-dim-blocked-tasks))
3543 ;; We need to widen when `org-agenda-finalize' is called from
3544 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3545 (when org-clock-current-task
3546 (save-restriction
3547 (widen)
3548 (org-agenda-mark-clocking-task)))
3549 (when org-agenda-entry-text-mode
3550 (org-agenda-entry-text-hide)
3551 (org-agenda-entry-text-show))
3552 (if (and (functionp 'org-habit-insert-consistency-graphs)
3553 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
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 (&optional invisible)
3619 (interactive "P")
3620 "Dim currently blocked TODO's in the agenda display."
3621 (message "Dim or hide blocked tasks...")
3622 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3623 (delete-overlay o)))
3624 (overlays-in (point-min) (point-max)))
3625 (save-excursion
3626 (let ((inhibit-read-only t)
3627 (org-depend-tag-blocked nil)
3628 (invis (or (not (null invisible))
3629 (eq org-agenda-dim-blocked-tasks 'invisible)))
3630 org-blocked-by-checkboxes
3631 invis1 b e p ov h l)
3632 (goto-char (point-min))
3633 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3634 (and pos (goto-char (1+ pos))))
3635 (setq org-blocked-by-checkboxes nil invis1 invis)
3636 (let ((marker (org-get-at-bol 'org-hd-marker)))
3637 (when (and marker
3638 (with-current-buffer (marker-buffer marker)
3639 (save-excursion (goto-char marker)
3640 (org-entry-blocked-p))))
3641 (if org-blocked-by-checkboxes (setq invis1 nil))
3642 (setq b (if invis1
3643 (max (point-min) (1- (point-at-bol)))
3644 (point-at-bol))
3645 e (point-at-eol)
3646 ov (make-overlay b e))
3647 (if invis1
3648 (overlay-put ov 'invisible t)
3649 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3650 (overlay-put ov 'org-type 'org-blocked-todo))))))
3651 (message "Dim or hide blocked tasks...done"))
3653 (defvar org-agenda-skip-function nil
3654 "Function to be called at each match during agenda construction.
3655 If this function returns nil, the current match should not be skipped.
3656 Otherwise, the function must return a position from where the search
3657 should be continued.
3658 This may also be a Lisp form, it will be evaluated.
3659 Never set this variable using `setq' or so, because then it will apply
3660 to all future agenda commands. If you do want a global skipping condition,
3661 use the option `org-agenda-skip-function-global' instead.
3662 The correct usage for `org-agenda-skip-function' is to bind it with
3663 `let' to scope it dynamically into the agenda-constructing command.
3664 A good way to set it is through options in `org-agenda-custom-commands'.")
3666 (defun org-agenda-skip ()
3667 "Throw to `:skip' in places that should be skipped.
3668 Also moves point to the end of the skipped region, so that search can
3669 continue from there."
3670 (let ((p (point-at-bol)) to)
3671 (when (org-in-src-block-p t) (throw :skip t))
3672 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3673 (get-text-property p :org-archived)
3674 (org-end-of-subtree t)
3675 (throw :skip t))
3676 (and org-agenda-skip-comment-trees
3677 (get-text-property p :org-comment)
3678 (org-end-of-subtree t)
3679 (throw :skip t))
3680 (if (equal (char-after p) ?#) (throw :skip t))
3681 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3682 (org-agenda-skip-eval org-agenda-skip-function)))
3683 (goto-char to)
3684 (throw :skip t))))
3686 (defun org-agenda-skip-eval (form)
3687 "If FORM is a function or a list, call (or eval) is and return result.
3688 `save-excursion' and `save-match-data' are wrapped around the call, so point
3689 and match data are returned to the previous state no matter what these
3690 functions do."
3691 (let (fp)
3692 (and form
3693 (or (setq fp (functionp form))
3694 (consp form))
3695 (save-excursion
3696 (save-match-data
3697 (if fp
3698 (funcall form)
3699 (eval form)))))))
3701 (defvar org-agenda-markers nil
3702 "List of all currently active markers created by `org-agenda'.")
3703 (defvar org-agenda-last-marker-time (org-float-time)
3704 "Creation time of the last agenda marker.")
3706 (defun org-agenda-new-marker (&optional pos)
3707 "Return a new agenda marker.
3708 Org-mode keeps a list of these markers and resets them when they are
3709 no longer in use."
3710 (let ((m (copy-marker (or pos (point)))))
3711 (setq org-agenda-last-marker-time (org-float-time))
3712 (if org-agenda-buffer
3713 (with-current-buffer org-agenda-buffer
3714 (push m org-agenda-markers))
3715 (push m org-agenda-markers))
3718 (defun org-agenda-reset-markers ()
3719 "Reset markers created by `org-agenda'."
3720 (while org-agenda-markers
3721 (move-marker (pop org-agenda-markers) nil)))
3723 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3724 "Save relative positions of markers in region.
3725 This check for agenda markers in all agenda buffers currently active."
3726 (dolist (buf (buffer-list))
3727 (with-current-buffer buf
3728 (when (eq major-mode 'org-agenda-mode)
3729 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3730 org-agenda-markers)))))
3732 ;;; Entry text mode
3734 (defun org-agenda-entry-text-show-here ()
3735 "Add some text from the entry as context to the current line."
3736 (let (m txt o)
3737 (setq m (org-get-at-bol 'org-hd-marker))
3738 (unless (marker-buffer m)
3739 (error "No marker points to an entry here"))
3740 (setq txt (concat "\n" (org-no-properties
3741 (org-agenda-get-some-entry-text
3742 m org-agenda-entry-text-maxlines " > "))))
3743 (when (string-match "\\S-" txt)
3744 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3745 (overlay-put o 'evaporate t)
3746 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3747 (overlay-put o 'after-string txt))))
3749 (defun org-agenda-entry-text-show ()
3750 "Add entry context for all agenda lines."
3751 (interactive)
3752 (save-excursion
3753 (goto-char (point-max))
3754 (beginning-of-line 1)
3755 (while (not (bobp))
3756 (when (org-get-at-bol 'org-hd-marker)
3757 (org-agenda-entry-text-show-here))
3758 (beginning-of-line 0))))
3760 (defun org-agenda-entry-text-hide ()
3761 "Remove any shown entry context."
3762 (delq nil
3763 (mapcar (lambda (o)
3764 (if (eq (overlay-get o 'org-overlay-type)
3765 'agenda-entry-content)
3766 (progn (delete-overlay o) t)))
3767 (overlays-in (point-min) (point-max)))))
3769 (defun org-agenda-get-day-face (date)
3770 "Return the face DATE should be displayed with."
3771 (or (and (functionp org-agenda-day-face-function)
3772 (funcall org-agenda-day-face-function date))
3773 (cond ((org-agenda-todayp date)
3774 'org-agenda-date-today)
3775 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3776 'org-agenda-date-weekend)
3777 (t 'org-agenda-date))))
3779 ;;; Agenda timeline
3781 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3783 (defun org-timeline (&optional dotodo)
3784 "Show a time-sorted view of the entries in the current org file.
3785 Only entries with a time stamp of today or later will be listed. With
3786 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3787 under the current date.
3788 If the buffer contains an active region, only check the region for
3789 dates."
3790 (interactive "P")
3791 (let* ((dopast t)
3792 (org-agenda-show-log-scoped org-agenda-show-log)
3793 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3794 (current-buffer))))
3795 (date (calendar-current-date))
3796 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3797 (end (if (org-region-active-p) (region-end) (point-max)))
3798 (day-numbers (org-get-all-dates
3799 beg end 'no-ranges
3800 t org-agenda-show-log-scoped ; always include today
3801 org-timeline-show-empty-dates))
3802 (org-deadline-warning-days 0)
3803 (org-agenda-only-exact-dates t)
3804 (today (org-today))
3805 (past t)
3806 args
3807 s e rtn d emptyp)
3808 (setq org-agenda-redo-command
3809 (list 'progn
3810 (list 'org-switch-to-buffer-other-window (current-buffer))
3811 (list 'org-timeline (list 'quote dotodo))))
3812 (if (not dopast)
3813 ;; Remove past dates from the list of dates.
3814 (setq day-numbers (delq nil (mapcar (lambda(x)
3815 (if (>= x today) x nil))
3816 day-numbers))))
3817 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3818 (org-compile-prefix-format 'timeline)
3819 (org-set-sorting-strategy 'timeline)
3820 (if org-agenda-show-log-scoped (push :closed args))
3821 (push :timestamp args)
3822 (push :deadline args)
3823 (push :scheduled args)
3824 (push :sexp args)
3825 (if dotodo (push :todo args))
3826 (insert "Timeline of file " entry "\n")
3827 (add-text-properties (point-min) (point)
3828 (list 'face 'org-agenda-structure))
3829 (org-agenda-mark-header-line (point-min))
3830 (while (setq d (pop day-numbers))
3831 (if (and (listp d) (eq (car d) :omitted))
3832 (progn
3833 (setq s (point))
3834 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3835 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3836 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3837 (if (and (>= d today)
3838 dopast
3839 past)
3840 (progn
3841 (setq past nil)
3842 (insert (make-string 79 ?-) "\n")))
3843 (setq date (calendar-gregorian-from-absolute d))
3844 (setq s (point))
3845 (setq rtn (and (not emptyp)
3846 (apply 'org-agenda-get-day-entries entry
3847 date args)))
3848 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3849 (progn
3850 (insert
3851 (if (stringp org-agenda-format-date)
3852 (format-time-string org-agenda-format-date
3853 (org-time-from-absolute date))
3854 (funcall org-agenda-format-date date))
3855 "\n")
3856 (put-text-property s (1- (point)) 'face
3857 (org-agenda-get-day-face date))
3858 (put-text-property s (1- (point)) 'org-date-line t)
3859 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3860 (if (equal d today)
3861 (put-text-property s (1- (point)) 'org-today t))
3862 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3863 (put-text-property s (1- (point)) 'day d)))))
3864 (goto-char (point-min))
3865 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3866 (point-min)))
3867 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3868 (org-agenda-finalize)
3869 (setq buffer-read-only t)))
3871 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3872 "Return a list of all relevant day numbers from BEG to END buffer positions.
3873 If NO-RANGES is non-nil, include only the start and end dates of a range,
3874 not every single day in the range. If FORCE-TODAY is non-nil, make
3875 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3876 inactive time stamps (those in square brackets) are included.
3877 When EMPTY is non-nil, also include days without any entries."
3878 (let ((re (concat
3879 (if pre-re pre-re "")
3880 (if inactive org-ts-regexp-both org-ts-regexp)))
3881 dates dates1 date day day1 day2 ts1 ts2 pos)
3882 (if force-today
3883 (setq dates (list (org-today))))
3884 (save-excursion
3885 (goto-char beg)
3886 (while (re-search-forward re end t)
3887 (setq day (time-to-days (org-time-string-to-time
3888 (substring (match-string 1) 0 10)
3889 (current-buffer) (match-beginning 0))))
3890 (or (memq day dates) (push day dates)))
3891 (unless no-ranges
3892 (goto-char beg)
3893 (while (re-search-forward org-tr-regexp end t)
3894 (setq pos (match-beginning 0))
3895 (setq ts1 (substring (match-string 1) 0 10)
3896 ts2 (substring (match-string 2) 0 10)
3897 day1 (time-to-days (org-time-string-to-time
3898 ts1 (current-buffer) pos))
3899 day2 (time-to-days (org-time-string-to-time
3900 ts2 (current-buffer) pos)))
3901 (while (< (setq day1 (1+ day1)) day2)
3902 (or (memq day1 dates) (push day1 dates)))))
3903 (setq dates (sort dates '<))
3904 (when empty
3905 (while (setq day (pop dates))
3906 (setq day2 (car dates))
3907 (push day dates1)
3908 (when (and day2 empty)
3909 (if (or (eq empty t)
3910 (and (numberp empty) (<= (- day2 day) empty)))
3911 (while (< (setq day (1+ day)) day2)
3912 (push (list day) dates1))
3913 (push (cons :omitted (- day2 day)) dates1))))
3914 (setq dates (nreverse dates1)))
3915 dates)))
3917 ;;; Agenda Daily/Weekly
3919 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3920 "Start day for the agenda view.
3921 Custom commands can set this variable in the options section.")
3922 (defvar org-starting-day nil) ; local variable in the agenda buffer
3923 (defvar org-arg-loc nil) ; local variable
3925 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3926 "List of types searched for when creating the daily/weekly agenda.
3927 This variable is a list of symbols that controls the types of
3928 items that appear in the daily/weekly agenda. Allowed symbols in this
3929 list are are
3931 :timestamp List items containing a date stamp or date range matching
3932 the selected date. This includes sexp entries in
3933 angular brackets.
3935 :sexp List entries resulting from plain diary-like sexps.
3937 :deadline List deadline due on that date. When the date is today,
3938 also list any deadlines past due, or due within
3939 `org-deadline-warning-days'. `:deadline' must appear before
3940 `:scheduled' if the setting of
3941 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3942 any effect.
3944 :scheduled List all items which are scheduled for the given date.
3945 The diary for *today* also contains items which were
3946 scheduled earlier and are not yet marked DONE.
3948 By default, all four types are turned on.
3950 Never set this variable globally using `setq', because then it
3951 will apply to all future agenda commands. Instead, bind it with
3952 `let' to scope it dynamically into the agenda-constructing
3953 command. A good way to set it is through options in
3954 `org-agenda-custom-commands'. For a more flexible (though
3955 somewhat less efficient) way of determining what is included in
3956 the daily/weekly agenda, see `org-agenda-skip-function'.")
3958 (defvar org-agenda-buffer-tmp-name nil)
3959 ;;;###autoload
3960 (defun org-agenda-list (&optional arg start-day span)
3961 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3962 The view will be for the current day or week, but from the overview buffer
3963 you will be able to go to other days/weeks.
3965 With a numeric prefix argument in an interactive call, the agenda will
3966 span ARG days. Lisp programs should instead specify SPAN to change
3967 the number of days. SPAN defaults to `org-agenda-span'.
3969 START-DAY defaults to TODAY, or to the most recent match for the weekday
3970 given in `org-agenda-start-on-weekday'."
3971 (interactive "P")
3972 (if org-agenda-overriding-arguments
3973 (setq arg (car org-agenda-overriding-arguments)
3974 start-day (nth 1 org-agenda-overriding-arguments)
3975 span (nth 2 org-agenda-overriding-arguments)))
3976 (if (and (integerp arg) (> arg 0))
3977 (setq span arg arg nil))
3978 (catch 'exit
3979 (setq org-agenda-buffer-name
3980 (or org-agenda-buffer-tmp-name
3981 (if org-agenda-sticky
3982 (cond ((and org-keys (stringp org-match))
3983 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3984 (org-keys
3985 (format "*Org Agenda(%s)*" org-keys))
3986 (t "*Org Agenda(a)*")))
3987 org-agenda-buffer-name))
3988 (org-agenda-prepare "Day/Week")
3989 (setq start-day (or start-day org-agenda-start-day))
3990 (if (stringp start-day)
3991 ;; Convert to an absolute day number
3992 (setq start-day (time-to-days (org-read-date nil t start-day))))
3993 (org-compile-prefix-format 'agenda)
3994 (org-set-sorting-strategy 'agenda)
3995 (let* ((span (org-agenda-ndays-to-span
3996 (or span org-agenda-ndays org-agenda-span)))
3997 (today (org-today))
3998 (sd (or start-day today))
3999 (ndays (org-agenda-span-to-ndays span sd))
4000 (org-agenda-start-on-weekday
4001 (if (eq ndays 7)
4002 org-agenda-start-on-weekday))
4003 (thefiles (org-agenda-files nil 'ifmode))
4004 (files thefiles)
4005 (start (if (or (null org-agenda-start-on-weekday)
4006 (< ndays 7))
4008 (let* ((nt (calendar-day-of-week
4009 (calendar-gregorian-from-absolute sd)))
4010 (n1 org-agenda-start-on-weekday)
4011 (d (- nt n1)))
4012 (- sd (+ (if (< d 0) 7 0) d)))))
4013 (day-numbers (list start))
4014 (day-cnt 0)
4015 (inhibit-redisplay (not debug-on-error))
4016 (org-agenda-show-log-scoped org-agenda-show-log)
4017 s e rtn rtnall file date d start-pos end-pos todayp
4018 clocktable-start clocktable-end filter)
4019 (setq org-agenda-redo-command
4020 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4021 (dotimes (n (1- ndays))
4022 (push (1+ (car day-numbers)) day-numbers))
4023 (setq day-numbers (nreverse day-numbers))
4024 (setq clocktable-start (car day-numbers)
4025 clocktable-end (1+ (or (org-last day-numbers) 0)))
4026 (org-set-local 'org-starting-day (car day-numbers))
4027 (org-set-local 'org-arg-loc arg)
4028 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4029 (unless org-agenda-compact-blocks
4030 (let* ((d1 (car day-numbers))
4031 (d2 (org-last day-numbers))
4032 (w1 (org-days-to-iso-week d1))
4033 (w2 (org-days-to-iso-week d2)))
4034 (setq s (point))
4035 (if org-agenda-overriding-header
4036 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4037 nil 'face 'org-agenda-structure) "\n")
4038 (insert (org-agenda-span-name span)
4039 "-agenda"
4040 (if (< (- d2 d1) 350)
4041 (if (= w1 w2)
4042 (format " (W%02d)" w1)
4043 (format " (W%02d-W%02d)" w1 w2))
4045 ":\n")))
4046 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4047 'org-date-line t))
4048 (org-agenda-mark-header-line s))
4049 (while (setq d (pop day-numbers))
4050 (setq date (calendar-gregorian-from-absolute d)
4051 s (point))
4052 (if (or (setq todayp (= d today))
4053 (and (not start-pos) (= d sd)))
4054 (setq start-pos (point))
4055 (if (and start-pos (not end-pos))
4056 (setq end-pos (point))))
4057 (setq files thefiles
4058 rtnall nil)
4059 (while (setq file (pop files))
4060 (catch 'nextfile
4061 (org-check-agenda-file file)
4062 (let ((org-agenda-entry-types org-agenda-entry-types))
4063 (unless org-agenda-include-deadlines
4064 (setq org-agenda-entry-types
4065 (delq :deadline org-agenda-entry-types)))
4066 (cond
4067 ((memq org-agenda-show-log-scoped '(only clockcheck))
4068 (setq rtn (org-agenda-get-day-entries
4069 file date :closed)))
4070 (org-agenda-show-log-scoped
4071 (setq rtn (apply 'org-agenda-get-day-entries
4072 file date
4073 (append '(:closed) org-agenda-entry-types))))
4075 (setq rtn (apply 'org-agenda-get-day-entries
4076 file date
4077 org-agenda-entry-types)))))
4078 (setq rtnall (append rtnall rtn)))) ;; all entries
4079 (if org-agenda-include-diary
4080 (let ((org-agenda-search-headline-for-time t))
4081 (require 'diary-lib)
4082 (setq rtn (org-get-entries-from-diary date))
4083 (setq rtnall (append rtnall rtn))))
4084 (if (or rtnall org-agenda-show-all-dates)
4085 (progn
4086 (setq day-cnt (1+ day-cnt))
4087 (insert
4088 (if (stringp org-agenda-format-date)
4089 (format-time-string org-agenda-format-date
4090 (org-time-from-absolute date))
4091 (funcall org-agenda-format-date date))
4092 "\n")
4093 (put-text-property s (1- (point)) 'face
4094 (org-agenda-get-day-face date))
4095 (put-text-property s (1- (point)) 'org-date-line t)
4096 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4097 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4098 (when todayp
4099 (put-text-property s (1- (point)) 'org-today t))
4100 (setq rtnall
4101 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4102 (if rtnall (insert ;; all entries
4103 (org-agenda-finalize-entries rtnall)
4104 "\n"))
4105 (put-text-property s (1- (point)) 'day d)
4106 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4107 (when (and org-agenda-clockreport-mode clocktable-start)
4108 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4109 ;; the above line is to ensure the restricted range!
4110 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4111 tbl)
4112 (setq p (org-plist-delete p :block))
4113 (setq p (plist-put p :tstart clocktable-start))
4114 (setq p (plist-put p :tend clocktable-end))
4115 (setq p (plist-put p :scope 'agenda))
4116 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4117 (setq filter (or org-agenda-tag-filter-while-redo
4118 (get 'org-agenda-tag-filter :preset-filter))))
4119 (setq p (plist-put p :tags (mapconcat (lambda (x)
4120 (if (string-match "[<>=]" x)
4123 filter ""))))
4124 (setq tbl (apply 'org-clock-get-clocktable p))
4125 (insert tbl)))
4126 (goto-char (point-min))
4127 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4128 (unless (and (pos-visible-in-window-p (point-min))
4129 (pos-visible-in-window-p (point-max)))
4130 (goto-char (1- (point-max)))
4131 (recenter -1)
4132 (if (not (pos-visible-in-window-p (or start-pos 1)))
4133 (progn
4134 (goto-char (or start-pos 1))
4135 (recenter 1))))
4136 (goto-char (or start-pos 1))
4137 (add-text-properties (point-min) (point-max)
4138 `(org-agenda-type agenda
4139 org-last-args (,arg ,start-day ,span)
4140 org-redo-cmd ,org-agenda-redo-command
4141 org-series-cmd ,org-cmd))
4142 (if (eq org-agenda-show-log-scoped 'clockcheck)
4143 (org-agenda-show-clocking-issues))
4144 (org-agenda-finalize)
4145 (setq buffer-read-only t)
4146 (message ""))))
4148 (autoload 'org-agenda-list "org-agenda" "\
4149 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4150 The view will be for the current day or week, but from the overview buffer
4151 you will be able to go to other days/weeks.
4153 With a numeric prefix argument in an interactive call, the agenda will
4154 span ARG days. Lisp programs should instead specify SPAN to change
4155 the number of days. SPAN defaults to `org-agenda-span'.
4157 START-DAY defaults to TODAY, or to the most recent match for the weekday
4158 given in `org-agenda-start-on-weekday'.
4160 \(fn &optional ARG START-DAY SPAN)" t nil)
4162 (defun org-agenda-ndays-to-span (n)
4163 "Return a span symbol for a span of N days, or N if none matches."
4164 (cond ((symbolp n) n)
4165 ((= n 1) 'day)
4166 ((= n 7) 'week)
4167 (t n)))
4169 (defun org-agenda-span-to-ndays (span &optional start-day)
4170 "Return ndays from SPAN, possibly starting at START-DAY."
4171 (cond ((numberp span) span)
4172 ((eq span 'day) 1)
4173 ((eq span 'week) 7)
4174 ((eq span 'month)
4175 (let ((date (calendar-gregorian-from-absolute start-day)))
4176 (calendar-last-day-of-month (car date) (caddr date))))
4177 ((eq span 'year)
4178 (let ((date (calendar-gregorian-from-absolute start-day)))
4179 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4181 (defun org-agenda-span-name (span)
4182 "Return a SPAN name."
4183 (if (null span)
4185 (if (symbolp span)
4186 (capitalize (symbol-name span))
4187 (format "%d days" span))))
4189 ;;; Agenda word search
4191 (defvar org-agenda-search-history nil)
4193 (defvar org-search-syntax-table nil
4194 "Special syntax table for org-mode search.
4195 In this table, we have single quotes not as word constituents, to
4196 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4198 (defvar org-mode-syntax-table) ; From org.el
4199 (defun org-search-syntax-table ()
4200 (unless org-search-syntax-table
4201 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4202 (modify-syntax-entry ?' "." org-search-syntax-table)
4203 (modify-syntax-entry ?` "." org-search-syntax-table))
4204 org-search-syntax-table)
4206 (defvar org-agenda-last-search-view-search-was-boolean nil)
4208 ;;;###autoload
4209 (defun org-search-view (&optional todo-only string edit-at)
4210 "Show all entries that contain a phrase or words or regular expressions.
4212 With optional prefix argument TODO-ONLY, only consider entries that are
4213 TODO entries. The argument STRING can be used to pass a default search
4214 string into this function. If EDIT-AT is non-nil, it means that the
4215 user should get a chance to edit this string, with cursor at position
4216 EDIT-AT.
4218 The search string can be viewed either as a phrase that should be found as
4219 is, or it can be broken into a number of snippets, each of which must match
4220 in a Boolean way to select an entry. The default depends on the variable
4221 `org-agenda-search-view-always-boolean'.
4222 Even if this is turned off (the default) you can always switch to
4223 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4225 The default is a direct search of the whole phrase, where each space in
4226 the search string can expand to an arbitrary amount of whitespace,
4227 including newlines.
4229 If using a Boolean search, the search string is split on whitespace and
4230 each snippet is searched separately, with logical AND to select an entry.
4231 Words prefixed with a minus must *not* occur in the entry. Words without
4232 a prefix or prefixed with a plus must occur in the entry. Matching is
4233 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4234 match whole words, not parts of a word) if
4235 `org-agenda-search-view-force-full-words' is set (default is nil).
4237 Boolean search snippets enclosed by curly braces are interpreted as
4238 regular expressions that must or (when preceded with \"-\") must not
4239 match in the entry. Snippets enclosed into double quotes will be taken
4240 as a whole, to include whitespace.
4242 - If the search string starts with an asterisk, search only in headlines.
4243 - If (possibly after the leading star) the search string starts with an
4244 exclamation mark, this also means to look at TODO entries only, an effect
4245 that can also be achieved with a prefix argument.
4246 - If (possibly after star and exclamation mark) the search string starts
4247 with a colon, this will mean that the (non-regexp) snippets of the
4248 Boolean search must match as full words.
4250 This command searches the agenda files, and in addition the files listed
4251 in `org-agenda-text-search-extra-files'."
4252 (interactive "P")
4253 (if org-agenda-overriding-arguments
4254 (setq todo-only (car org-agenda-overriding-arguments)
4255 string (nth 1 org-agenda-overriding-arguments)
4256 edit-at (nth 2 org-agenda-overriding-arguments)))
4257 (let* ((props (list 'face nil
4258 'done-face 'org-agenda-done
4259 'org-not-done-regexp org-not-done-regexp
4260 'org-todo-regexp org-todo-regexp
4261 'org-complex-heading-regexp org-complex-heading-regexp
4262 'mouse-face 'highlight
4263 'help-echo (format "mouse-2 or RET jump to location")))
4264 (full-words org-agenda-search-view-force-full-words)
4265 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4266 regexp rtn rtnall files file pos
4267 marker category category-pos tags c neg re boolean
4268 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4269 (unless (and (not edit-at)
4270 (stringp string)
4271 (string-match "\\S-" string))
4272 (setq string (read-string
4273 (if org-agenda-search-view-always-boolean
4274 "[+-]Word/{Regexp} ...: "
4275 "Phrase or [+-]Word/{Regexp} ...: ")
4276 (cond
4277 ((integerp edit-at) (cons string edit-at))
4278 (edit-at string))
4279 'org-agenda-search-history)))
4280 (catch 'exit
4281 (if org-agenda-sticky
4282 (setq org-agenda-buffer-name
4283 (if (stringp string)
4284 (format "*Org Agenda(%s:%s)*"
4285 (or org-keys (or (and todo-only "S") "s")) string)
4286 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4287 (org-agenda-prepare "SEARCH")
4288 (org-compile-prefix-format 'search)
4289 (org-set-sorting-strategy 'search)
4290 (setq org-agenda-redo-command
4291 (list 'org-search-view (if todo-only t nil)
4292 (list 'if 'current-prefix-arg nil string)))
4293 (setq org-agenda-query-string string)
4294 (if (equal (string-to-char string) ?*)
4295 (setq hdl-only t
4296 words (substring string 1))
4297 (setq words string))
4298 (when (equal (string-to-char words) ?!)
4299 (setq todo-only t
4300 words (substring words 1)))
4301 (when (equal (string-to-char words) ?:)
4302 (setq full-words t
4303 words (substring words 1)))
4304 (if (or org-agenda-search-view-always-boolean
4305 (member (string-to-char words) '(?- ?+ ?\{)))
4306 (setq boolean t))
4307 (setq words (org-split-string words))
4308 (let (www w)
4309 (while (setq w (pop words))
4310 (while (and (string-match "\\\\\\'" w) words)
4311 (setq w (concat (substring w 0 -1) " " (pop words))))
4312 (push w www))
4313 (setq words (nreverse www) www nil)
4314 (while (setq w (pop words))
4315 (when (and (string-match "\\`[-+]?{" w)
4316 (not (string-match "}\\'" w)))
4317 (while (and words (not (string-match "}\\'" (car words))))
4318 (setq w (concat w " " (pop words))))
4319 (setq w (concat w " " (pop words))))
4320 (push w www))
4321 (setq words (nreverse www)))
4322 (setq org-agenda-last-search-view-search-was-boolean boolean)
4323 (when boolean
4324 (let (wds w)
4325 (while (setq w (pop words))
4326 (if (or (equal (substring w 0 1) "\"")
4327 (and (> (length w) 1)
4328 (member (substring w 0 1) '("+" "-"))
4329 (equal (substring w 1 2) "\"")))
4330 (while (and words (not (equal (substring w -1) "\"")))
4331 (setq w (concat w " " (pop words)))))
4332 (and (string-match "\\`\\([-+]?\\)\"" w)
4333 (setq w (replace-match "\\1" nil nil w)))
4334 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4335 (push w wds))
4336 (setq words (nreverse wds))))
4337 (if boolean
4338 (mapc (lambda (w)
4339 (setq c (string-to-char w))
4340 (if (equal c ?-)
4341 (setq neg t w (substring w 1))
4342 (if (equal c ?+)
4343 (setq neg nil w (substring w 1))
4344 (setq neg nil)))
4345 (if (string-match "\\`{.*}\\'" w)
4346 (setq re (substring w 1 -1))
4347 (if full-words
4348 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4349 (setq re (regexp-quote (downcase w)))))
4350 (if neg (push re regexps-) (push re regexps+)))
4351 words)
4352 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4353 regexps+))
4354 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4355 (if (not regexps+)
4356 (setq regexp org-outline-regexp-bol)
4357 (setq regexp (pop regexps+))
4358 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4359 regexp))))
4360 (setq files (org-agenda-files nil 'ifmode))
4361 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4362 (pop org-agenda-text-search-extra-files)
4363 (setq files (org-add-archive-files files)))
4364 (setq files (append files org-agenda-text-search-extra-files)
4365 rtnall nil)
4366 (while (setq file (pop files))
4367 (setq ee nil)
4368 (catch 'nextfile
4369 (org-check-agenda-file file)
4370 (setq buffer (if (file-exists-p file)
4371 (org-get-agenda-file-buffer file)
4372 (error "No such file %s" file)))
4373 (if (not buffer)
4374 ;; If file does not exist, make sure an error message is sent
4375 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4376 file))))
4377 (with-current-buffer buffer
4378 (with-syntax-table (org-search-syntax-table)
4379 (unless (derived-mode-p 'org-mode)
4380 (error "Agenda file %s is not in `org-mode'" file))
4381 (let ((case-fold-search t))
4382 (save-excursion
4383 (save-restriction
4384 (if org-agenda-restrict
4385 (narrow-to-region org-agenda-restrict-begin
4386 org-agenda-restrict-end)
4387 (widen))
4388 (goto-char (point-min))
4389 (unless (or (org-at-heading-p)
4390 (outline-next-heading))
4391 (throw 'nextfile t))
4392 (goto-char (max (point-min) (1- (point))))
4393 (while (re-search-forward regexp nil t)
4394 (org-back-to-heading t)
4395 (skip-chars-forward "* ")
4396 (setq beg (point-at-bol)
4397 beg1 (point)
4398 end (progn (outline-next-heading) (point)))
4399 (catch :skip
4400 (goto-char beg)
4401 (org-agenda-skip)
4402 (setq str (buffer-substring-no-properties
4403 (point-at-bol)
4404 (if hdl-only (point-at-eol) end)))
4405 (mapc (lambda (wr) (when (string-match wr str)
4406 (goto-char (1- end))
4407 (throw :skip t)))
4408 regexps-)
4409 (mapc (lambda (wr) (unless (string-match wr str)
4410 (goto-char (1- end))
4411 (throw :skip t)))
4412 (if todo-only
4413 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4414 regexps+)
4415 regexps+))
4416 (goto-char beg)
4417 (setq marker (org-agenda-new-marker (point))
4418 category (org-get-category)
4419 category-pos (get-text-property (point) 'org-category-position)
4420 tags (org-get-tags-at (point))
4421 txt (org-agenda-format-item
4423 (buffer-substring-no-properties
4424 beg1 (point-at-eol))
4425 category tags t))
4426 (org-add-props txt props
4427 'org-marker marker 'org-hd-marker marker
4428 'org-todo-regexp org-todo-regexp
4429 'org-complex-heading-regexp org-complex-heading-regexp
4430 'priority 1000 'org-category category
4431 'org-category-position category-pos
4432 'type "search")
4433 (push txt ee)
4434 (goto-char (1- end))))))))))
4435 (setq rtn (nreverse ee))
4436 (setq rtnall (append rtnall rtn)))
4437 (if org-agenda-overriding-header
4438 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4439 nil 'face 'org-agenda-structure) "\n")
4440 (insert "Search words: ")
4441 (add-text-properties (point-min) (1- (point))
4442 (list 'face 'org-agenda-structure))
4443 (setq pos (point))
4444 (insert string "\n")
4445 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4446 (setq pos (point))
4447 (unless org-agenda-multi
4448 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4449 (add-text-properties pos (1- (point))
4450 (list 'face 'org-agenda-structure))))
4451 (org-agenda-mark-header-line (point-min))
4452 (when rtnall
4453 (insert (org-agenda-finalize-entries rtnall) "\n"))
4454 (goto-char (point-min))
4455 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4456 (add-text-properties (point-min) (point-max)
4457 `(org-agenda-type search
4458 org-last-args (,todo-only ,string ,edit-at)
4459 org-redo-cmd ,org-agenda-redo-command
4460 org-series-cmd ,org-cmd))
4461 (org-agenda-finalize)
4462 (setq buffer-read-only t))))
4464 (autoload 'org-search-view "org-agenda" "\
4465 Show all entries that contain a phrase or words or regular expressions.
4467 With optional prefix argument TODO-ONLY, only consider entries that are
4468 TODO entries. The argument STRING can be used to pass a default search
4469 string into this function. If EDIT-AT is non-nil, it means that the
4470 user should get a chance to edit this string, with cursor at position
4471 EDIT-AT.
4473 The search string can be viewed either as a phrase that should be found as
4474 is, or it can be broken into a number of snippets, each of which must match
4475 in a Boolean way to select an entry. The default depends on the variable
4476 `org-agenda-search-view-always-boolean'.
4477 Even if this is turned off (the default) you can always switch to
4478 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4480 The default is a direct search of the whole phrase, where each space in
4481 the search string can expand to an arbitrary amount of whitespace,
4482 including newlines.
4484 If using a Boolean search, the search string is split on whitespace and
4485 each snippet is searched separately, with logical AND to select an entry.
4486 Words prefixed with a minus must *not* occur in the entry. Words without
4487 a prefix or prefixed with a plus must occur in the entry. Matching is
4488 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4489 match whole words, not parts of a word) if
4490 `org-agenda-search-view-force-full-words' is set (default is nil).
4492 Boolean search snippets enclosed by curly braces are interpreted as
4493 regular expressions that must or (when preceded with \"-\") must not
4494 match in the entry. Snippets enclosed into double quotes will be taken
4495 as a whole, to include whitespace.
4497 - If the search string starts with an asterisk, search only in headlines.
4498 - If (possibly after the leading star) the search string starts with an
4499 exclamation mark, this also means to look at TODO entries only, an effect
4500 that can also be achieved with a prefix argument.
4501 - If (possibly after star and exclamation mark) the search string starts
4502 with a colon, this will mean that the (non-regexp) snippets of the
4503 Boolean search must match as full words.
4505 This command searches the agenda files, and in addition the files listed
4506 in `org-agenda-text-search-extra-files'.
4508 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4510 ;;; Agenda TODO list
4512 (defvar org-select-this-todo-keyword nil)
4513 (defvar org-last-arg nil)
4515 ;;;###autoload
4516 (defun org-todo-list (&optional arg)
4517 "Show all (not done) TODO entries from all agenda file in a single list.
4518 The prefix arg can be used to select a specific TODO keyword and limit
4519 the list to these. When using \\[universal-argument], you will be prompted
4520 for a keyword. A numeric prefix directly selects the Nth keyword in
4521 `org-todo-keywords-1'."
4522 (interactive "P")
4523 (if org-agenda-overriding-arguments
4524 (setq arg org-agenda-overriding-arguments))
4525 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4526 (let* ((today (org-today))
4527 (date (calendar-gregorian-from-absolute today))
4528 (kwds org-todo-keywords-for-agenda)
4529 (completion-ignore-case t)
4530 (org-select-this-todo-keyword
4531 (if (stringp arg) arg
4532 (and arg (integerp arg) (> arg 0)
4533 (nth (1- arg) kwds))))
4534 rtn rtnall files file pos)
4535 (when (equal arg '(4))
4536 (setq org-select-this-todo-keyword
4537 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4538 (mapcar 'list kwds) nil nil)))
4539 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4540 (catch 'exit
4541 (if org-agenda-sticky
4542 (setq org-agenda-buffer-name
4543 (if (stringp org-select-this-todo-keyword)
4544 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4545 org-select-this-todo-keyword)
4546 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4547 (org-agenda-prepare "TODO")
4548 (org-compile-prefix-format 'todo)
4549 (org-set-sorting-strategy 'todo)
4550 (setq org-agenda-redo-command
4551 `(org-todo-list (or (and (numberp current-prefix-arg)
4552 current-prefix-arg)
4553 ,org-select-this-todo-keyword
4554 current-prefix-arg ,arg)))
4555 (setq files (org-agenda-files nil 'ifmode)
4556 rtnall nil)
4557 (while (setq file (pop files))
4558 (catch 'nextfile
4559 (org-check-agenda-file file)
4560 (setq rtn (org-agenda-get-day-entries file date :todo))
4561 (setq rtnall (append rtnall rtn))))
4562 (if org-agenda-overriding-header
4563 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4564 nil 'face 'org-agenda-structure) "\n")
4565 (insert "Global list of TODO items of type: ")
4566 (add-text-properties (point-min) (1- (point))
4567 (list 'face 'org-agenda-structure
4568 'short-heading
4569 (concat "ToDo: "
4570 (or org-select-this-todo-keyword "ALL"))))
4571 (org-agenda-mark-header-line (point-min))
4572 (setq pos (point))
4573 (insert (or org-select-this-todo-keyword "ALL") "\n")
4574 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4575 (setq pos (point))
4576 (unless org-agenda-multi
4577 (insert "Available with `N r': (0)[ALL]")
4578 (let ((n 0) s)
4579 (mapc (lambda (x)
4580 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4581 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4582 (insert "\n "))
4583 (insert " " s))
4584 kwds))
4585 (insert "\n"))
4586 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4587 (org-agenda-mark-header-line (point-min))
4588 (when rtnall
4589 (insert (org-agenda-finalize-entries rtnall) "\n"))
4590 (goto-char (point-min))
4591 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4592 (add-text-properties (point-min) (point-max)
4593 `(org-agenda-type todo
4594 org-last-args ,arg
4595 org-redo-cmd ,org-agenda-redo-command
4596 org-series-cmd ,org-cmd))
4597 (org-agenda-finalize)
4598 (setq buffer-read-only t))))
4600 (autoload 'org-todo-list "org-agenda" "\
4601 Show all (not done) TODO entries from all agenda file in a single list.
4602 The prefix arg can be used to select a specific TODO keyword and limit
4603 the list to these. When using \\[universal-argument], you will be prompted
4604 for a keyword. A numeric prefix directly selects the Nth keyword in
4605 `org-todo-keywords-1'.
4607 \(fn &optional ARG)" t nil)
4609 ;;; Agenda tags match
4611 ;;;###autoload
4612 (defun org-tags-view (&optional todo-only match)
4613 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4614 The prefix arg TODO-ONLY limits the search to TODO entries."
4615 (interactive "P")
4616 (if org-agenda-overriding-arguments
4617 (setq todo-only (car org-agenda-overriding-arguments)
4618 match (nth 1 org-agenda-overriding-arguments)))
4619 (let* ((org-tags-match-list-sublevels
4620 org-tags-match-list-sublevels)
4621 (completion-ignore-case t)
4622 rtn rtnall files file pos matcher
4623 buffer)
4624 (when (and (stringp match) (not (string-match "\\S-" match)))
4625 (setq match nil))
4626 (setq matcher (org-make-tags-matcher match)
4627 match (car matcher) matcher (cdr matcher))
4628 (catch 'exit
4629 (if org-agenda-sticky
4630 (setq org-agenda-buffer-name
4631 (if (stringp match)
4632 (format "*Org Agenda(%s:%s)*"
4633 (or org-keys (or (and todo-only "M") "m")) match)
4634 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4635 (org-agenda-prepare (concat "TAGS " match))
4636 (org-compile-prefix-format 'tags)
4637 (org-set-sorting-strategy 'tags)
4638 (setq org-agenda-query-string match)
4639 (setq org-agenda-redo-command
4640 (list 'org-tags-view `(quote ,todo-only)
4641 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4642 (setq files (org-agenda-files nil 'ifmode)
4643 rtnall nil)
4644 (while (setq file (pop files))
4645 (catch 'nextfile
4646 (org-check-agenda-file file)
4647 (setq buffer (if (file-exists-p file)
4648 (org-get-agenda-file-buffer file)
4649 (error "No such file %s" file)))
4650 (if (not buffer)
4651 ;; If file does not exist, error message to agenda
4652 (setq rtn (list
4653 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4654 rtnall (append rtnall rtn))
4655 (with-current-buffer buffer
4656 (unless (derived-mode-p 'org-mode)
4657 (error "Agenda file %s is not in `org-mode'" file))
4658 (save-excursion
4659 (save-restriction
4660 (if org-agenda-restrict
4661 (narrow-to-region org-agenda-restrict-begin
4662 org-agenda-restrict-end)
4663 (widen))
4664 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4665 (setq rtnall (append rtnall rtn))))))))
4666 (if org-agenda-overriding-header
4667 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4668 nil 'face 'org-agenda-structure) "\n")
4669 (insert "Headlines with TAGS match: ")
4670 (add-text-properties (point-min) (1- (point))
4671 (list 'face 'org-agenda-structure
4672 'short-heading
4673 (concat "Match: " match)))
4674 (setq pos (point))
4675 (insert match "\n")
4676 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4677 (setq pos (point))
4678 (unless org-agenda-multi
4679 (insert "Press `C-u r' to search again with new search string\n"))
4680 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4681 (org-agenda-mark-header-line (point-min))
4682 (when rtnall
4683 (insert (org-agenda-finalize-entries rtnall) "\n"))
4684 (goto-char (point-min))
4685 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4686 (add-text-properties (point-min) (point-max)
4687 `(org-agenda-type tags
4688 org-last-args (,todo-only ,match)
4689 org-redo-cmd ,org-agenda-redo-command
4690 org-series-cmd ,org-cmd))
4691 (org-agenda-finalize)
4692 (setq buffer-read-only t))))
4694 (autoload 'org-tags-view "org-agenda" "\
4695 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4696 The prefix arg TODO-ONLY limits the search to TODO entries.
4698 \(fn &optional TODO-ONLY MATCH)" t nil)
4700 ;;; Agenda Finding stuck projects
4702 (defvar org-agenda-skip-regexp nil
4703 "Regular expression used in skipping subtrees for the agenda.
4704 This is basically a temporary global variable that can be set and then
4705 used by user-defined selections using `org-agenda-skip-function'.")
4707 (defvar org-agenda-overriding-header nil
4708 "When set during agenda, todo and tags searches it replaces the header.
4709 This variable should not be set directly, but custom commands can bind it
4710 in the options section.")
4712 (defun org-agenda-skip-entry-when-regexp-matches ()
4713 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4714 If yes, it returns the end position of this entry, causing agenda commands
4715 to skip the entry but continuing the search in the subtree. This is a
4716 function that can be put into `org-agenda-skip-function' for the duration
4717 of a command."
4718 (let ((end (save-excursion (org-end-of-subtree t)))
4719 skip)
4720 (save-excursion
4721 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4722 (and skip end)))
4724 (defun org-agenda-skip-subtree-when-regexp-matches ()
4725 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4726 If yes, it returns the end position of this tree, causing agenda commands
4727 to skip this subtree. This is a function that can be put into
4728 `org-agenda-skip-function' for the duration of a command."
4729 (let ((end (save-excursion (org-end-of-subtree t)))
4730 skip)
4731 (save-excursion
4732 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4733 (and skip end)))
4735 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4736 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4737 If yes, it returns the end position of the current entry (NOT the tree),
4738 causing agenda commands to skip the entry but continuing the search in
4739 the subtree. This is a function that can be put into
4740 `org-agenda-skip-function' for the duration of a command. An important
4741 use of this function is for the stuck project list."
4742 (let ((end (save-excursion (org-end-of-subtree t)))
4743 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4744 skip)
4745 (save-excursion
4746 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4747 (and skip entry-end)))
4749 (defun org-agenda-skip-entry-if (&rest conditions)
4750 "Skip entry if any of CONDITIONS is true.
4751 See `org-agenda-skip-if' for details."
4752 (org-agenda-skip-if nil conditions))
4754 (defun org-agenda-skip-subtree-if (&rest conditions)
4755 "Skip entry if any of CONDITIONS is true.
4756 See `org-agenda-skip-if' for details."
4757 (org-agenda-skip-if t conditions))
4759 (defun org-agenda-skip-if (subtree conditions)
4760 "Checks current entity for CONDITIONS.
4761 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4762 the entry (i.e. the text before the next heading) is checked.
4764 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4765 from different tests. Valid conditions are:
4767 scheduled Check if there is a scheduled cookie
4768 notscheduled Check if there is no scheduled cookie
4769 deadline Check if there is a deadline
4770 notdeadline Check if there is no deadline
4771 timestamp Check if there is a timestamp (also deadline or scheduled)
4772 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4773 regexp Check if regexp matches
4774 notregexp Check if regexp does not match.
4775 todo Check if TODO keyword matches
4776 nottodo Check if TODO keyword does not match
4778 The regexp is taken from the conditions list, it must come right after
4779 the `regexp' or `notregexp' element.
4781 `todo' and `nottodo' accept as an argument a list of todo
4782 keywords, which may include \"*\" to match any todo keyword.
4784 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4786 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4788 Instead of a list, a keyword class may be given. For example:
4790 (org-agenda-skip-entry-if 'nottodo 'done)
4792 would skip entries that haven't been marked with any of \"DONE\"
4793 keywords. Possible classes are: `todo', `done', `any'.
4795 If any of these conditions is met, this function returns the end point of
4796 the entity, causing the search to continue from there. This is a function
4797 that can be put into `org-agenda-skip-function' for the duration of a command."
4798 (let (beg end m)
4799 (org-back-to-heading t)
4800 (setq beg (point)
4801 end (if subtree
4802 (progn (org-end-of-subtree t) (point))
4803 (progn (outline-next-heading) (1- (point)))))
4804 (goto-char beg)
4805 (and
4807 (and (memq 'scheduled conditions)
4808 (re-search-forward org-scheduled-time-regexp end t))
4809 (and (memq 'notscheduled conditions)
4810 (not (re-search-forward org-scheduled-time-regexp end t)))
4811 (and (memq 'deadline conditions)
4812 (re-search-forward org-deadline-time-regexp end t))
4813 (and (memq 'notdeadline conditions)
4814 (not (re-search-forward org-deadline-time-regexp end t)))
4815 (and (memq 'timestamp conditions)
4816 (re-search-forward org-ts-regexp end t))
4817 (and (memq 'nottimestamp conditions)
4818 (not (re-search-forward org-ts-regexp end t)))
4819 (and (setq m (memq 'regexp conditions))
4820 (stringp (nth 1 m))
4821 (re-search-forward (nth 1 m) end t))
4822 (and (setq m (memq 'notregexp conditions))
4823 (stringp (nth 1 m))
4824 (not (re-search-forward (nth 1 m) end t)))
4825 (and (or
4826 (setq m (memq 'nottodo conditions))
4827 (setq m (memq 'todo-unblocked conditions))
4828 (setq m (memq 'nottodo-unblocked conditions))
4829 (setq m (memq 'todo conditions)))
4830 (org-agenda-skip-if-todo m end)))
4831 end)))
4833 (defun org-agenda-skip-if-todo (args end)
4834 "Helper function for `org-agenda-skip-if', do not use it directly.
4835 ARGS is a list with first element either `todo', `nottodo',
4836 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4837 a list of TODO keywords, or a state symbol `todo' or `done' or
4838 `any'."
4839 (let ((kw (car args))
4840 (arg (cadr args))
4841 todo-wds todo-re)
4842 (setq todo-wds
4843 (org-uniquify
4844 (cond
4845 ((listp arg) ;; list of keywords
4846 (if (member "*" arg)
4847 (mapcar 'substring-no-properties org-todo-keywords-1)
4848 arg))
4849 ((symbolp arg) ;; keyword class name
4850 (cond
4851 ((eq arg 'todo)
4852 (org-delete-all org-done-keywords
4853 (mapcar 'substring-no-properties
4854 org-todo-keywords-1)))
4855 ((eq arg 'done) org-done-keywords)
4856 ((eq arg 'any)
4857 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4858 (setq todo-re
4859 (concat "^\\*+[ \t]+\\<\\("
4860 (mapconcat 'identity todo-wds "\\|")
4861 "\\)\\>"))
4862 (cond
4863 ((eq kw 'todo) (re-search-forward todo-re end t))
4864 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4865 ((eq kw 'todo-unblocked)
4866 (catch 'unblocked
4867 (while (re-search-forward todo-re end t)
4868 (or (org-entry-blocked-p) (throw 'unblocked t)))
4869 nil))
4870 ((eq kw 'nottodo-unblocked)
4871 (catch 'unblocked
4872 (while (re-search-forward todo-re end t)
4873 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4877 ;;;###autoload
4878 (defun org-agenda-list-stuck-projects (&rest ignore)
4879 "Create agenda view for projects that are stuck.
4880 Stuck projects are project that have no next actions. For the definitions
4881 of what a project is and how to check if it stuck, customize the variable
4882 `org-stuck-projects'."
4883 (interactive)
4884 (let* ((org-agenda-skip-function
4885 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4886 ;; We could have used org-agenda-skip-if here.
4887 (org-agenda-overriding-header
4888 (or org-agenda-overriding-header "List of stuck projects: "))
4889 (matcher (nth 0 org-stuck-projects))
4890 (todo (nth 1 org-stuck-projects))
4891 (todo-wds (if (member "*" todo)
4892 (progn
4893 (org-agenda-prepare-buffers (org-agenda-files
4894 nil 'ifmode))
4895 (org-delete-all
4896 org-done-keywords-for-agenda
4897 (copy-sequence org-todo-keywords-for-agenda)))
4898 todo))
4899 (todo-re (concat "^\\*+[ \t]+\\("
4900 (mapconcat 'identity todo-wds "\\|")
4901 "\\)\\>"))
4902 (tags (nth 2 org-stuck-projects))
4903 (tags-re (if (member "*" tags)
4904 (concat org-outline-regexp-bol
4905 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4906 (if tags
4907 (concat org-outline-regexp-bol
4908 ".*:\\("
4909 (mapconcat 'identity tags "\\|")
4910 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4911 (gen-re (nth 3 org-stuck-projects))
4912 (re-list
4913 (delq nil
4914 (list
4915 (if todo todo-re)
4916 (if tags tags-re)
4917 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4918 gen-re)))))
4919 (setq org-agenda-skip-regexp
4920 (if re-list
4921 (mapconcat 'identity re-list "\\|")
4922 (error "No information how to identify unstuck projects")))
4923 (org-tags-view nil matcher)
4924 (with-current-buffer org-agenda-buffer-name
4925 (setq org-agenda-redo-command
4926 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4928 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4929 Create agenda view for projects that are stuck.
4930 Stuck projects are project that have no next actions. For the definitions
4931 of what a project is and how to check if it stuck, customize the variable
4932 `org-stuck-projects'.
4934 \(fn &rest IGNORE)" t nil)
4936 ;;; Diary integration
4938 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4939 (defvar diary-list-entries-hook)
4940 (defvar diary-time-regexp)
4941 (defun org-get-entries-from-diary (date)
4942 "Get the (Emacs Calendar) diary entries for DATE."
4943 (require 'diary-lib)
4944 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4945 (diary-display-hook '(fancy-diary-display))
4946 (diary-display-function 'fancy-diary-display)
4947 (pop-up-frames nil)
4948 (diary-list-entries-hook
4949 (cons 'org-diary-default-entry diary-list-entries-hook))
4950 (diary-file-name-prefix-function nil) ; turn this feature off
4951 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4952 entries
4953 (org-disable-agenda-to-diary t))
4954 (save-excursion
4955 (save-window-excursion
4956 (funcall (if (fboundp 'diary-list-entries)
4957 'diary-list-entries 'list-diary-entries)
4958 date 1)))
4959 (if (not (get-buffer diary-fancy-buffer))
4960 (setq entries nil)
4961 (with-current-buffer diary-fancy-buffer
4962 (setq buffer-read-only nil)
4963 (if (zerop (buffer-size))
4964 ;; No entries
4965 (setq entries nil)
4966 ;; Omit the date and other unnecessary stuff
4967 (org-agenda-cleanup-fancy-diary)
4968 ;; Add prefix to each line and extend the text properties
4969 (if (zerop (buffer-size))
4970 (setq entries nil)
4971 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4972 (setq entries
4973 (with-temp-buffer
4974 (insert entries) (goto-char (point-min))
4975 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4976 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4977 (replace-match (concat "; " (match-string 1)))))
4978 (buffer-string)))))
4979 (set-buffer-modified-p nil)
4980 (kill-buffer diary-fancy-buffer)))
4981 (when entries
4982 (setq entries (org-split-string entries "\n"))
4983 (setq entries
4984 (mapcar
4985 (lambda (x)
4986 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4987 ;; Extend the text properties to the beginning of the line
4988 (org-add-props x (text-properties-at (1- (length x)) x)
4989 'type "diary" 'date date 'face 'org-agenda-diary))
4990 entries)))))
4992 (defvar org-agenda-cleanup-fancy-diary-hook nil
4993 "Hook run when the fancy diary buffer is cleaned up.")
4995 (defun org-agenda-cleanup-fancy-diary ()
4996 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4997 This gets rid of the date, the underline under the date, and
4998 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4999 date. It also removes lines that contain only whitespace."
5000 (goto-char (point-min))
5001 (if (looking-at ".*?:[ \t]*")
5002 (progn
5003 (replace-match "")
5004 (re-search-forward "\n=+$" nil t)
5005 (replace-match "")
5006 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5007 (re-search-forward "\n=+$" nil t)
5008 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5009 (goto-char (point-min))
5010 (while (re-search-forward "^ +\n" nil t)
5011 (replace-match ""))
5012 (goto-char (point-min))
5013 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5014 (replace-match ""))
5015 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5017 ;; Make sure entries from the diary have the right text properties.
5018 (eval-after-load "diary-lib"
5019 '(if (boundp 'diary-modify-entry-list-string-function)
5020 ;; We can rely on the hook, nothing to do
5022 ;; Hook not available, must use advice to make this work
5023 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5024 "Make the position visible."
5025 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5026 (stringp string)
5027 buffer-file-name)
5028 (setq string (org-modify-diary-entry-string string))))))
5030 (defun org-modify-diary-entry-string (string)
5031 "Add text properties to string, allowing org-mode to act on it."
5032 (org-add-props string nil
5033 'mouse-face 'highlight
5034 'help-echo (if buffer-file-name
5035 (format "mouse-2 or RET jump to diary file %s"
5036 (abbreviate-file-name buffer-file-name))
5038 'org-agenda-diary-link t
5039 'org-marker (org-agenda-new-marker (point-at-bol))))
5041 (defun org-diary-default-entry ()
5042 "Add a dummy entry to the diary.
5043 Needed to avoid empty dates which mess up holiday display."
5044 ;; Catch the error if dealing with the new add-to-diary-alist
5045 (when org-disable-agenda-to-diary
5046 (condition-case nil
5047 (org-add-to-diary-list original-date "Org-mode dummy" "")
5048 (error
5049 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5051 (defun org-add-to-diary-list (&rest args)
5052 (if (fboundp 'diary-add-to-list)
5053 (apply 'diary-add-to-list args)
5054 (apply 'add-to-diary-list args)))
5056 (defvar org-diary-last-run-time nil)
5058 ;;;###autoload
5059 (defun org-diary (&rest args)
5060 "Return diary information from org files.
5061 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5062 It accesses org files and extracts information from those files to be
5063 listed in the diary. The function accepts arguments specifying what
5064 items should be listed. For a list of arguments allowed here, see the
5065 variable `org-agenda-entry-types'.
5067 The call in the diary file should look like this:
5069 &%%(org-diary) ~/path/to/some/orgfile.org
5071 Use a separate line for each org file to check. Or, if you omit the file name,
5072 all files listed in `org-agenda-files' will be checked automatically:
5074 &%%(org-diary)
5076 If you don't give any arguments (as in the example above), the default
5077 arguments (:deadline :scheduled :timestamp :sexp) are used.
5078 So the example above may also be written as
5080 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5082 The function expects the lisp variables `entry' and `date' to be provided
5083 by the caller, because this is how the calendar works. Don't use this
5084 function from a program - use `org-agenda-get-day-entries' instead."
5085 (when (> (- (org-float-time)
5086 org-agenda-last-marker-time)
5088 ;; I am not sure if this works with sticky agendas, because the marker
5089 ;; list is then no longer a global variable.
5090 (org-agenda-reset-markers))
5091 (org-compile-prefix-format 'agenda)
5092 (org-set-sorting-strategy 'agenda)
5093 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5094 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5095 (list entry)
5096 (org-agenda-files t)))
5097 (time (org-float-time))
5098 file rtn results)
5099 (when (or (not org-diary-last-run-time)
5100 (> (- time
5101 org-diary-last-run-time)
5103 (org-agenda-prepare-buffers files))
5104 (setq org-diary-last-run-time time)
5105 ;; If this is called during org-agenda, don't return any entries to
5106 ;; the calendar. Org Agenda will list these entries itself.
5107 (if org-disable-agenda-to-diary (setq files nil))
5108 (while (setq file (pop files))
5109 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5110 (setq results (append results rtn)))
5111 (if results
5112 (concat (org-agenda-finalize-entries results) "\n"))))
5114 (autoload 'org-diary "org-agenda" "\
5115 Return diary information from org files.
5116 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5117 It accesses org files and extracts information from those files to be
5118 listed in the diary. The function accepts arguments specifying what
5119 items should be listed. For a list of arguments allowed here, see the
5120 variable `org-agenda-entry-types'.
5122 The call in the diary file should look like this:
5124 &%%(org-diary) ~/path/to/some/orgfile.org
5126 Use a separate line for each org file to check. Or, if you omit the file name,
5127 all files listed in `org-agenda-files' will be checked automatically:
5129 &%%(org-diary)
5131 If you don't give any arguments (as in the example above), the default
5132 arguments (:deadline :scheduled :timestamp :sexp) are used.
5133 So the example above may also be written as
5135 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5137 The function expects the lisp variables `entry' and `date' to be provided
5138 by the caller, because this is how the calendar works. Don't use this
5139 function from a program - use `org-agenda-get-day-entries' instead.
5141 \(fn &rest ARGS)" nil nil)
5143 ;;; Agenda entry finders
5145 (defun org-agenda-get-day-entries (file date &rest args)
5146 "Does the work for `org-diary' and `org-agenda'.
5147 FILE is the path to a file to be checked for entries. DATE is date like
5148 the one returned by `calendar-current-date'. ARGS are symbols indicating
5149 which kind of entries should be extracted. For details about these, see
5150 the documentation of `org-diary'."
5151 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5152 (let* ((org-startup-folded nil)
5153 (org-startup-align-all-tables nil)
5154 (buffer (if (file-exists-p file)
5155 (org-get-agenda-file-buffer file)
5156 (error "No such file %s" file)))
5157 arg results rtn deadline-results)
5158 (if (not buffer)
5159 ;; If file does not exist, make sure an error message ends up in diary
5160 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5161 (with-current-buffer buffer
5162 (unless (derived-mode-p 'org-mode)
5163 (error "Agenda file %s is not in `org-mode'" file))
5164 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5165 (let ((case-fold-search nil))
5166 (save-excursion
5167 (save-restriction
5168 (if org-agenda-restrict
5169 (narrow-to-region org-agenda-restrict-begin
5170 org-agenda-restrict-end)
5171 (widen))
5172 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5173 (while (setq arg (pop args))
5174 (cond
5175 ((and (eq arg :todo)
5176 (equal date (calendar-gregorian-from-absolute
5177 (org-today))))
5178 (setq rtn (org-agenda-get-todos))
5179 (setq results (append results rtn)))
5180 ((eq arg :timestamp)
5181 (setq rtn (org-agenda-get-blocks))
5182 (setq results (append results rtn))
5183 (setq rtn (org-agenda-get-timestamps deadline-results))
5184 (setq results (append results rtn)))
5185 ((eq arg :sexp)
5186 (setq rtn (org-agenda-get-sexps))
5187 (setq results (append results rtn)))
5188 ((eq arg :scheduled)
5189 (setq rtn (org-agenda-get-scheduled deadline-results))
5190 (setq results (append results rtn)))
5191 ((eq arg :closed)
5192 (setq rtn (org-agenda-get-progress))
5193 (setq results (append results rtn)))
5194 ((eq arg :deadline)
5195 (setq rtn (org-agenda-get-deadlines))
5196 (setq deadline-results (copy-sequence rtn))
5197 (setq results (append results rtn))))))))
5198 results))))
5200 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5201 (defun org-agenda-get-todos ()
5202 "Return the TODO information for agenda display."
5203 (let* ((props (list 'face nil
5204 'done-face 'org-agenda-done
5205 'org-not-done-regexp org-not-done-regexp
5206 'org-todo-regexp org-todo-regexp
5207 'org-complex-heading-regexp org-complex-heading-regexp
5208 'mouse-face 'highlight
5209 'help-echo
5210 (format "mouse-2 or RET jump to org file %s"
5211 (abbreviate-file-name buffer-file-name))))
5212 (regexp (format org-heading-keyword-regexp-format
5213 (cond
5214 ((and org-select-this-todo-keyword
5215 (equal org-select-this-todo-keyword "*"))
5216 org-todo-regexp)
5217 (org-select-this-todo-keyword
5218 (concat "\\("
5219 (mapconcat 'identity
5220 (org-split-string
5221 org-select-this-todo-keyword
5222 "|")
5223 "\\|") "\\)"))
5224 (t org-not-done-regexp))))
5225 marker priority category category-pos tags todo-state
5226 ee txt beg end)
5227 (goto-char (point-min))
5228 (while (re-search-forward regexp nil t)
5229 (catch :skip
5230 (save-match-data
5231 (beginning-of-line)
5232 (org-agenda-skip)
5233 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5234 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5235 (goto-char (1+ beg))
5236 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5237 (throw :skip nil)))
5238 (goto-char (match-beginning 2))
5239 (setq marker (org-agenda-new-marker (match-beginning 0))
5240 category (org-get-category)
5241 category-pos (get-text-property (point) 'org-category-position)
5242 txt (org-trim
5243 (buffer-substring (match-beginning 2) (match-end 0)))
5244 tags (org-get-tags-at (point))
5245 txt (org-agenda-format-item "" txt category tags t)
5246 priority (1+ (org-get-priority txt))
5247 todo-state (org-get-todo-state))
5248 (org-add-props txt props
5249 'org-marker marker 'org-hd-marker marker
5250 'priority priority 'org-category category
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-days-to-time time)))
5265 (if (>= n 0)
5266 (>= days n)
5267 (<= days n))))
5269 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5270 (&optional end)
5271 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5272 (when (or org-agenda-todo-ignore-with-date
5273 org-agenda-todo-ignore-scheduled
5274 org-agenda-todo-ignore-deadlines
5275 org-agenda-todo-ignore-timestamp)
5276 (setq end (or end (save-excursion (outline-next-heading) (point))))
5277 (save-excursion
5278 (or (and org-agenda-todo-ignore-with-date
5279 (re-search-forward org-ts-regexp end t))
5280 (and org-agenda-todo-ignore-scheduled
5281 (re-search-forward org-scheduled-time-regexp end t)
5282 (cond
5283 ((eq org-agenda-todo-ignore-scheduled 'future)
5284 (> (org-days-to-time (match-string 1)) 0))
5285 ((eq org-agenda-todo-ignore-scheduled 'past)
5286 (<= (org-days-to-time (match-string 1)) 0))
5287 ((numberp org-agenda-todo-ignore-scheduled)
5288 (org-agenda-todo-custom-ignore-p
5289 (match-string 1) org-agenda-todo-ignore-scheduled))
5290 (t)))
5291 (and org-agenda-todo-ignore-deadlines
5292 (re-search-forward org-deadline-time-regexp end t)
5293 (cond
5294 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5295 ((eq org-agenda-todo-ignore-deadlines 'far)
5296 (not (org-deadline-close (match-string 1))))
5297 ((eq org-agenda-todo-ignore-deadlines 'future)
5298 (> (org-days-to-time (match-string 1)) 0))
5299 ((eq org-agenda-todo-ignore-deadlines 'past)
5300 (<= (org-days-to-time (match-string 1)) 0))
5301 ((numberp org-agenda-todo-ignore-deadlines)
5302 (org-agenda-todo-custom-ignore-p
5303 (match-string 1) org-agenda-todo-ignore-deadlines))
5304 (t (org-deadline-close (match-string 1)))))
5305 (and org-agenda-todo-ignore-timestamp
5306 (let ((buffer (current-buffer))
5307 (regexp
5308 (concat
5309 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5310 (start (point)))
5311 ;; Copy current buffer into a temporary one
5312 (with-temp-buffer
5313 (insert-buffer-substring buffer start end)
5314 (goto-char (point-min))
5315 ;; Delete SCHEDULED and DEADLINE items
5316 (while (re-search-forward regexp end t)
5317 (delete-region (match-beginning 0) (match-end 0)))
5318 (goto-char (point-min))
5319 ;; No search for timestamp left
5320 (when (re-search-forward org-ts-regexp nil t)
5321 (cond
5322 ((eq org-agenda-todo-ignore-timestamp 'future)
5323 (> (org-days-to-time (match-string 1)) 0))
5324 ((eq org-agenda-todo-ignore-timestamp 'past)
5325 (<= (org-days-to-time (match-string 1)) 0))
5326 ((numberp org-agenda-todo-ignore-timestamp)
5327 (org-agenda-todo-custom-ignore-p
5328 (match-string 1) org-agenda-todo-ignore-timestamp))
5329 (t))))))))))
5331 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5332 Do we have a reason to ignore this TODO entry because it has a time stamp?
5334 \(fn &optional END)" nil nil)
5336 (defconst org-agenda-no-heading-message
5337 "No heading for this item in buffer or region.")
5339 (defun org-agenda-get-timestamps (&optional deadline-results)
5340 "Return the date stamp information for agenda display."
5341 (let* ((props (list 'face 'org-agenda-calendar-event
5342 'org-not-done-regexp org-not-done-regexp
5343 'org-todo-regexp org-todo-regexp
5344 'org-complex-heading-regexp org-complex-heading-regexp
5345 'mouse-face 'highlight
5346 'help-echo
5347 (format "mouse-2 or RET jump to org file %s"
5348 (abbreviate-file-name buffer-file-name))))
5349 (d1 (calendar-absolute-from-gregorian date))
5351 (deadline-position-alist
5352 (mapcar (lambda (a) (and (setq mm (get-text-property
5353 0 'org-hd-marker a))
5354 (cons (marker-position mm) a)))
5355 deadline-results))
5356 (remove-re org-ts-regexp)
5357 (regexp
5358 (concat
5359 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5360 (regexp-quote
5361 (substring
5362 (format-time-string
5363 (car org-time-stamp-formats)
5364 (apply 'encode-time ; DATE bound by calendar
5365 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5366 1 11))
5367 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5368 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5369 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5370 donep tmp priority category category-pos ee txt timestr tags
5371 b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
5372 (goto-char (point-min))
5373 (while (setq end-of-match (re-search-forward regexp nil t))
5374 (setq b0 (match-beginning 0)
5375 b3 (match-beginning 3) e3 (match-end 3)
5376 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5377 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5378 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5379 (member todo-state
5380 org-agenda-repeating-timestamp-show-all)))
5381 (catch :skip
5382 (and (org-at-date-range-p) (throw :skip nil))
5383 (org-agenda-skip)
5384 (if (and (match-end 1)
5385 (not (= d1 (org-time-string-to-absolute
5386 (match-string 1) d1 nil show-all
5387 (current-buffer) b0))))
5388 (throw :skip nil))
5389 (if (and e3
5390 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5391 (throw :skip nil))
5392 (setq tmp (buffer-substring (max (point-min)
5393 (- b0 org-ds-keyword-length))
5395 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5396 inactivep (= (char-after b0) ?\[)
5397 deadlinep (string-match org-deadline-regexp tmp)
5398 scheduledp (string-match org-scheduled-regexp tmp)
5399 closedp (and org-agenda-include-inactive-timestamps
5400 (string-match org-closed-string tmp))
5401 clockp (and org-agenda-include-inactive-timestamps
5402 (or (string-match org-clock-string tmp)
5403 (string-match "]-+\\'" tmp)))
5404 warntime (org-entry-get (point) "APPT_WARNTIME")
5405 donep (member todo-state org-done-keywords))
5406 (if (or scheduledp deadlinep closedp clockp
5407 (and donep org-agenda-skip-timestamp-if-done))
5408 (throw :skip t))
5409 (if (string-match ">" timestr)
5410 ;; substring should only run to end of time stamp
5411 (setq timestr (substring timestr 0 (match-end 0))))
5412 (setq marker (org-agenda-new-marker b0)
5413 category (org-get-category b0)
5414 category-pos (get-text-property b0 'org-category-position))
5415 (save-excursion
5416 (if (not (re-search-backward org-outline-regexp-bol nil t))
5417 (setq txt org-agenda-no-heading-message)
5418 (goto-char (match-beginning 0))
5419 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5420 (assoc (point) deadline-position-alist))
5421 (throw :skip nil))
5422 (setq hdmarker (org-agenda-new-marker)
5423 tags (org-get-tags-at))
5424 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5425 (setq head (or (match-string 1) ""))
5426 (setq txt (org-agenda-format-item
5427 (if inactivep org-agenda-inactive-leader nil)
5428 head category tags timestr
5429 remove-re habitp)))
5430 (setq priority (org-get-priority txt))
5431 (org-add-props txt props
5432 'org-marker marker 'org-hd-marker hdmarker)
5433 (org-add-props txt nil 'priority priority
5434 'org-category category 'date date
5435 'org-category-position category-pos
5436 'todo-state todo-state
5437 'warntime warntime
5438 'type "timestamp")
5439 (push txt ee))
5440 (if org-agenda-skip-additional-timestamps-same-entry
5441 (outline-next-heading)
5442 (goto-char end-of-match))))
5443 (nreverse ee)))
5445 (defun org-agenda-get-sexps ()
5446 "Return the sexp information for agenda display."
5447 (require 'diary-lib)
5448 (let* ((props (list 'face 'org-agenda-calendar-sexp
5449 'mouse-face 'highlight
5450 'help-echo
5451 (format "mouse-2 or RET jump to org file %s"
5452 (abbreviate-file-name buffer-file-name))))
5453 (regexp "^&?%%(")
5454 marker category extra category-pos ee txt tags entry
5455 result beg b sexp sexp-entry todo-state warntime)
5456 (goto-char (point-min))
5457 (while (re-search-forward regexp nil t)
5458 (catch :skip
5459 (org-agenda-skip)
5460 (setq beg (match-beginning 0))
5461 (goto-char (1- (match-end 0)))
5462 (setq b (point))
5463 (forward-sexp 1)
5464 (setq sexp (buffer-substring b (point)))
5465 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5466 (org-trim (match-string 1))
5467 ""))
5468 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5469 (when result
5470 (setq marker (org-agenda-new-marker beg)
5471 category (org-get-category beg)
5472 category-pos (get-text-property beg 'org-category-position)
5473 tags (save-excursion (org-backward-heading-same-level 0)
5474 (org-get-tags-at))
5475 todo-state (org-get-todo-state)
5476 warntime (org-entry-get (point) "APPT_WARNTIME")
5477 extra nil)
5479 (dolist (r (if (stringp result)
5480 (list result)
5481 result)) ;; we expect a list here
5482 (when (and org-agenda-diary-sexp-prefix
5483 (string-match org-agenda-diary-sexp-prefix r))
5484 (setq extra (match-string 0 r)
5485 r (replace-match "" nil nil r)))
5486 (if (string-match "\\S-" r)
5487 (setq txt r)
5488 (setq txt "SEXP entry returned empty string"))
5490 (setq txt (org-agenda-format-item
5491 extra txt category tags 'time))
5492 (org-add-props txt props 'org-marker marker)
5493 (org-add-props txt nil
5494 'org-category category 'date date 'todo-state todo-state
5495 'org-category-position category-pos 'tags tags
5496 'type "sexp" 'warntime warntime)
5497 (push txt ee)))))
5498 (nreverse ee)))
5500 ;; Calendar sanity: define some functions that are independent of
5501 ;; `calendar-date-style'.
5502 ;; Normally I would like to use ISO format when calling the diary functions,
5503 ;; but to make sure we still have Emacs 22 compatibility we bind
5504 ;; also `european-calendar-style' and use european format
5505 (defun org-anniversary (year month day &optional mark)
5506 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5507 (org-no-warnings
5508 (let ((calendar-date-style 'european) (european-calendar-style t))
5509 (diary-anniversary day month year mark))))
5510 (defun org-cyclic (N year month day &optional mark)
5511 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5512 (org-no-warnings
5513 (let ((calendar-date-style 'european) (european-calendar-style t))
5514 (diary-cyclic N day month year mark))))
5515 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5516 "Like `diary-block', but with fixed (ISO) order of arguments."
5517 (org-no-warnings
5518 (let ((calendar-date-style 'european) (european-calendar-style t))
5519 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5520 (defun org-date (year month day &optional mark)
5521 "Like `diary-date', but with fixed (ISO) order of arguments."
5522 (org-no-warnings
5523 (let ((calendar-date-style 'european) (european-calendar-style t))
5524 (diary-date day month year mark))))
5525 (defalias 'org-float 'diary-float)
5527 ;; Define the` org-class' function
5528 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5529 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5530 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5531 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5532 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5533 `holidays', then any date that is known by the Emacs calendar to be a
5534 holiday will also be skipped."
5535 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5536 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5537 (d (calendar-absolute-from-gregorian date)))
5538 (and
5539 (<= date1 d)
5540 (<= d date2)
5541 (= (calendar-day-of-week date) dayname)
5542 (or (not skip-weeks)
5543 (progn
5544 (require 'cal-iso)
5545 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5546 (not (and (memq 'holidays skip-weeks)
5547 (calendar-check-holidays date)))
5548 entry)))
5550 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5551 "Like `org-class', but honor `calendar-date-style'.
5552 The order of the first 2 times 3 arguments depends on the variable
5553 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5554 So for American calendars, give this as MONTH DAY YEAR, for European as
5555 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5556 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5557 is any number of ISO weeks in the block period for which the item should
5558 be skipped.
5560 This function is here only for backward compatibility and it is deprecated,
5561 please use `org-class' instead."
5562 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5563 (date2 (org-order-calendar-date-args m2 d2 y2)))
5564 (org-class
5565 (nth 2 date1) (car date1) (nth 1 date1)
5566 (nth 2 date2) (car date2) (nth 1 date2)
5567 dayname skip-weeks)))
5568 (make-obsolete 'org-diary-class 'org-class "")
5570 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5571 (defalias 'org-get-closed 'org-agenda-get-progress)
5572 (defun org-agenda-get-progress ()
5573 "Return the logged TODO entries for agenda display."
5574 (let* ((props (list 'mouse-face 'highlight
5575 'org-not-done-regexp org-not-done-regexp
5576 'org-todo-regexp org-todo-regexp
5577 'org-complex-heading-regexp org-complex-heading-regexp
5578 'help-echo
5579 (format "mouse-2 or RET jump to org file %s"
5580 (abbreviate-file-name buffer-file-name))))
5581 (items (if (consp org-agenda-show-log-scoped)
5582 org-agenda-show-log-scoped
5583 (if (eq org-agenda-show-log-scoped 'clockcheck)
5584 '(clock)
5585 org-agenda-log-mode-items)))
5586 (parts
5587 (delq nil
5588 (list
5589 (if (memq 'closed items) (concat "\\<" org-closed-string))
5590 (if (memq 'clock items) (concat "\\<" org-clock-string))
5591 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5592 (parts-re (if parts (mapconcat 'identity parts "\\|")
5593 (error "`org-agenda-log-mode-items' is empty")))
5594 (regexp (concat
5595 "\\(" parts-re "\\)"
5596 " *\\["
5597 (regexp-quote
5598 (substring
5599 (format-time-string
5600 (car org-time-stamp-formats)
5601 (apply 'encode-time ; DATE bound by calendar
5602 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5603 1 11))))
5604 (org-agenda-search-headline-for-time nil)
5605 marker hdmarker priority category category-pos tags closedp
5606 statep clockp state ee txt extra timestr rest clocked)
5607 (goto-char (point-min))
5608 (while (re-search-forward regexp nil t)
5609 (catch :skip
5610 (org-agenda-skip)
5611 (setq marker (org-agenda-new-marker (match-beginning 0))
5612 closedp (equal (match-string 1) org-closed-string)
5613 statep (equal (string-to-char (match-string 1)) ?-)
5614 clockp (not (or closedp statep))
5615 state (and statep (match-string 2))
5616 category (org-get-category (match-beginning 0))
5617 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5618 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5619 (when (string-match "\\]" timestr)
5620 ;; substring should only run to end of time stamp
5621 (setq rest (substring timestr (match-end 0))
5622 timestr (substring timestr 0 (match-end 0)))
5623 (if (and (not closedp) (not statep)
5624 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5625 rest))
5626 (progn (setq timestr (concat (substring timestr 0 -1)
5627 "-" (match-string 1 rest) "]"))
5628 (setq clocked (match-string 2 rest)))
5629 (setq clocked "-")))
5630 (save-excursion
5631 (setq extra
5632 (cond
5633 ((not org-agenda-log-mode-add-notes) nil)
5634 (statep
5635 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5636 (match-string 1)))
5637 (clockp
5638 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5639 (match-string 1)))))
5640 (if (not (re-search-backward org-outline-regexp-bol nil t))
5641 (setq txt org-agenda-no-heading-message)
5642 (goto-char (match-beginning 0))
5643 (setq hdmarker (org-agenda-new-marker)
5644 tags (org-get-tags-at))
5645 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5646 (setq txt (match-string 1))
5647 (when extra
5648 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5649 (setq txt (concat (substring txt 0 (match-beginning 1))
5650 " - " extra " " (match-string 2 txt)))
5651 (setq txt (concat txt " - " extra))))
5652 (setq txt (org-agenda-format-item
5653 (cond
5654 (closedp "Closed: ")
5655 (statep (concat "State: (" state ")"))
5656 (t (concat "Clocked: (" clocked ")")))
5657 txt category tags timestr)))
5658 (setq priority 100000)
5659 (org-add-props txt props
5660 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5661 'priority priority 'org-category category
5662 'org-category-position category-pos
5663 'type "closed" 'date date
5664 'undone-face 'org-warning 'done-face 'org-agenda-done)
5665 (push txt ee))
5666 (goto-char (point-at-eol))))
5667 (nreverse ee)))
5669 (defun org-agenda-show-clocking-issues ()
5670 "Add overlays, showing issues with clocking.
5671 See also the user option `org-agenda-clock-consistency-checks'."
5672 (interactive)
5673 (let* ((pl org-agenda-clock-consistency-checks)
5674 (re (concat "^[ \t]*"
5675 org-clock-string
5676 "[ \t]+"
5677 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5678 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5679 (tlstart 0.)
5680 (tlend 0.)
5681 (maxtime (org-hh:mm-string-to-minutes
5682 (or (plist-get pl :max-duration) "24:00")))
5683 (mintime (org-hh:mm-string-to-minutes
5684 (or (plist-get pl :min-duration) 0)))
5685 (maxgap (org-hh:mm-string-to-minutes
5686 ;; default 30:00 means never complain
5687 (or (plist-get pl :max-gap) "30:00")))
5688 (gapok (mapcar 'org-hh:mm-string-to-minutes
5689 (plist-get pl :gap-ok-around)))
5690 (def-face (or (plist-get pl :default-face)
5691 '((:background "DarkRed") (:foreground "white"))))
5692 issue face m te ts dt ov)
5693 (goto-char (point-min))
5694 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5695 (setq issue nil face def-face)
5696 (catch 'next
5697 (setq m (org-get-at-bol 'org-marker)
5698 te nil ts nil)
5699 (unless (and m (markerp m))
5700 (setq issue "No valid clock line") (throw 'next t))
5701 (org-with-point-at m
5702 (save-excursion
5703 (goto-char (point-at-bol))
5704 (unless (looking-at re)
5705 (error "No valid Clock line")
5706 (throw 'next t))
5707 (unless (match-end 3)
5708 (setq issue "No end time"
5709 face (or (plist-get pl :no-end-time-face) face))
5710 (throw 'next t))
5711 (setq ts (match-string 1)
5712 te (match-string 3)
5713 ts (org-float-time
5714 (apply 'encode-time (org-parse-time-string ts)))
5715 te (org-float-time
5716 (apply 'encode-time (org-parse-time-string te)))
5717 dt (- te ts))))
5718 (cond
5719 ((> dt (* 60 maxtime))
5720 ;; a very long clocking chunk
5721 (setq issue (format "Clocking interval is very long: %s"
5722 (org-minutes-to-hh:mm-string
5723 (floor (/ (float dt) 60.))))
5724 face (or (plist-get pl :long-face) face)))
5725 ((< dt (* 60 mintime))
5726 ;; a very short clocking chunk
5727 (setq issue (format "Clocking interval is very short: %s"
5728 (org-minutes-to-hh:mm-string
5729 (floor (/ (float dt) 60.))))
5730 face (or (plist-get pl :short-face) face)))
5731 ((and (> tlend 0) (< ts tlend))
5732 ;; Two clock entries are overlapping
5733 (setq issue (format "Clocking overlap: %d minutes"
5734 (/ (- tlend ts) 60))
5735 face (or (plist-get pl :overlap-face) face)))
5736 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5737 ;; There is a gap, lets see if we need to report it
5738 (unless (org-agenda-check-clock-gap tlend ts gapok)
5739 (setq issue (format "Clocking gap: %d minutes"
5740 (/ (- ts tlend) 60))
5741 face (or (plist-get pl :gap-face) face))))
5742 (t nil)))
5743 (setq tlend (or te tlend) tlstart (or ts tlstart))
5744 (when issue
5745 ;; OK, there was some issue, add an overlay to show the issue
5746 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5747 (overlay-put ov 'before-string
5748 (concat
5749 (org-add-props
5750 (format "%-43s" (concat " " issue))
5752 'face face)
5753 "\n"))
5754 (overlay-put ov 'evaporate t)))))
5756 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5757 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5758 (catch 'exit
5759 (unless ok-list
5760 ;; there are no OK times for gaps...
5761 (throw 'exit nil))
5762 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5763 ;; This is more than 24 hours, so it is OK.
5764 ;; because we have at least one OK time, that must be in the
5765 ;; 24 hour interval.
5766 (throw 'exit t))
5767 ;; We have a shorter gap.
5768 ;; Now we have to get the minute of the day when these times are
5769 (let* ((t1dec (decode-time (seconds-to-time t1)))
5770 (t2dec (decode-time (seconds-to-time t2)))
5771 ;; compute the minute on the day
5772 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5773 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5774 (when (< min2 min1)
5775 ;; if min2 is smaller than min1, this means it is on the next day.
5776 ;; Wrap it to after midnight.
5777 (setq min2 (+ min2 1440)))
5778 ;; Now check if any of the OK times is in the gap
5779 (mapc (lambda (x)
5780 ;; Wrap the time to after midnight if necessary
5781 (if (< x min1) (setq x (+ x 1440)))
5782 ;; Check if in interval
5783 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5784 ok-list)
5785 ;; Nope, this gap is not OK
5786 nil)))
5788 (defun org-agenda-get-deadlines ()
5789 "Return the deadline information for agenda display."
5790 (let* ((props (list 'mouse-face 'highlight
5791 'org-not-done-regexp org-not-done-regexp
5792 'org-todo-regexp org-todo-regexp
5793 'org-complex-heading-regexp org-complex-heading-regexp
5794 'help-echo
5795 (format "mouse-2 or RET jump to org file %s"
5796 (abbreviate-file-name buffer-file-name))))
5797 (regexp org-deadline-time-regexp)
5798 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5799 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5800 d2 diff dfrac wdays pos pos1 category category-pos
5801 tags suppress-prewarning ee txt head face s todo-state
5802 show-all upcomingp donep timestr warntime)
5803 (goto-char (point-min))
5804 (while (re-search-forward regexp nil t)
5805 (setq suppress-prewarning nil)
5806 (catch :skip
5807 (org-agenda-skip)
5808 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5809 (save-match-data
5810 (string-match org-scheduled-time-regexp
5811 (buffer-substring (point-at-bol)
5812 (point-at-eol)))))
5813 (setq suppress-prewarning
5814 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5815 org-agenda-skip-deadline-prewarning-if-scheduled
5816 0)))
5817 (setq s (match-string 1)
5818 txt nil
5819 pos (1- (match-beginning 1))
5820 todo-state (save-match-data (org-get-todo-state))
5821 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5822 (member todo-state
5823 org-agenda-repeating-timestamp-show-all))
5824 d2 (org-time-string-to-absolute
5825 (match-string 1) d1 'past show-all
5826 (current-buffer) pos)
5827 diff (- d2 d1)
5828 wdays (if suppress-prewarning
5829 (let ((org-deadline-warning-days suppress-prewarning))
5830 (org-get-wdays s))
5831 (org-get-wdays s))
5832 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5833 upcomingp (and todayp (> diff 0)))
5834 ;; When to show a deadline in the calendar:
5835 ;; If the expiration is within wdays warning time.
5836 ;; Past-due deadlines are only shown on the current date
5837 (if (and (or (and (<= diff wdays)
5838 (and todayp (not org-agenda-only-exact-dates)))
5839 (= diff 0)))
5840 (save-excursion
5841 ;; (setq todo-state (org-get-todo-state))
5842 (setq donep (member todo-state org-done-keywords))
5843 (if (and donep
5844 (or org-agenda-skip-deadline-if-done
5845 (not (= diff 0))))
5846 (setq txt nil)
5847 (setq category (org-get-category)
5848 warntime (org-entry-get (point) "APPT_WARNTIME")
5849 category-pos (get-text-property (point) 'org-category-position))
5850 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5851 (setq txt org-agenda-no-heading-message)
5852 (goto-char (match-end 0))
5853 (setq pos1 (match-beginning 0))
5854 (setq tags (org-get-tags-at pos1))
5855 (setq head (buffer-substring-no-properties
5856 (point)
5857 (progn (skip-chars-forward "^\r\n")
5858 (point))))
5859 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5860 (setq timestr
5861 (concat (substring s (match-beginning 1)) " "))
5862 (setq timestr 'time))
5863 (setq txt (org-agenda-format-item
5864 (if (= diff 0)
5865 (car org-agenda-deadline-leaders)
5866 (if (functionp
5867 (nth 1 org-agenda-deadline-leaders))
5868 (funcall
5869 (nth 1 org-agenda-deadline-leaders)
5870 diff date)
5871 (format (nth 1 org-agenda-deadline-leaders)
5872 diff)))
5873 head category tags
5874 (if (not (= diff 0)) nil timestr)))))
5875 (when txt
5876 (setq face (org-agenda-deadline-face dfrac))
5877 (org-add-props txt props
5878 'org-marker (org-agenda-new-marker pos)
5879 'warntime warntime
5880 'org-hd-marker (org-agenda-new-marker pos1)
5881 'priority (+ (- diff)
5882 (org-get-priority txt))
5883 'org-category category
5884 'org-category-position category-pos
5885 'todo-state todo-state
5886 'type (if upcomingp "upcoming-deadline" "deadline")
5887 'date (if upcomingp date d2)
5888 'face (if donep 'org-agenda-done face)
5889 'undone-face face 'done-face 'org-agenda-done)
5890 (push txt ee))))))
5891 (nreverse ee)))
5893 (defun org-agenda-deadline-face (fraction)
5894 "Return the face to displaying a deadline item.
5895 FRACTION is what fraction of the head-warning time has passed."
5896 (let ((faces org-agenda-deadline-faces) f)
5897 (catch 'exit
5898 (while (setq f (pop faces))
5899 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5901 (defun org-agenda-get-scheduled (&optional deadline-results)
5902 "Return the scheduled information for agenda display."
5903 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5904 'org-todo-regexp org-todo-regexp
5905 'org-complex-heading-regexp org-complex-heading-regexp
5906 'done-face 'org-agenda-done
5907 'mouse-face 'highlight
5908 'help-echo
5909 (format "mouse-2 or RET jump to org file %s"
5910 (abbreviate-file-name buffer-file-name))))
5911 (regexp org-scheduled-time-regexp)
5912 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5913 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5915 (deadline-position-alist
5916 (mapcar (lambda (a) (and (setq mm (get-text-property
5917 0 'org-hd-marker a))
5918 (cons (marker-position mm) a)))
5919 deadline-results))
5920 d2 diff pos pos1 category category-pos tags donep
5921 ee txt head pastschedp todo-state face timestr s habitp show-all
5922 did-habit-check-p warntime)
5923 (goto-char (point-min))
5924 (while (re-search-forward regexp nil t)
5925 (catch :skip
5926 (org-agenda-skip)
5927 (setq s (match-string 1)
5928 txt nil
5929 pos (1- (match-beginning 1))
5930 todo-state (save-match-data (org-get-todo-state))
5931 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5932 (member todo-state
5933 org-agenda-repeating-timestamp-show-all))
5934 d2 (org-time-string-to-absolute
5935 (match-string 1) d1 'past show-all
5936 (current-buffer) pos)
5937 diff (- d2 d1)
5938 warntime (org-entry-get (point) "APPT_WARNTIME"))
5939 (setq pastschedp (and todayp (< diff 0)))
5940 (setq did-habit-check-p nil)
5941 ;; When to show a scheduled item in the calendar:
5942 ;; If it is on or past the date.
5943 (when (or (and (< diff 0)
5944 (< (abs diff) org-scheduled-past-days)
5945 (and todayp (not org-agenda-only-exact-dates)))
5946 (= diff 0)
5947 ;; org-is-habit-p uses org-entry-get, which is expansive
5948 ;; so we go extra mile to only call it once
5949 (and todayp
5950 (boundp 'org-habit-show-all-today)
5951 org-habit-show-all-today
5952 (setq did-habit-check-p t)
5953 (setq habitp (and (functionp 'org-is-habit-p)
5954 (org-is-habit-p)))))
5955 (save-excursion
5956 (setq donep (member todo-state org-done-keywords))
5957 (if (and donep
5958 (or org-agenda-skip-scheduled-if-done
5959 (not (= diff 0))
5960 (and (functionp 'org-is-habit-p)
5961 (org-is-habit-p))))
5962 (setq txt nil)
5963 (setq habitp (if did-habit-check-p habitp
5964 (and (functionp 'org-is-habit-p)
5965 (org-is-habit-p))))
5966 (setq category (org-get-category)
5967 category-pos (get-text-property (point) 'org-category-position))
5968 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5969 (setq txt org-agenda-no-heading-message)
5970 (goto-char (match-end 0))
5971 (setq pos1 (match-beginning 0))
5972 (if habitp
5973 (if (or (not org-habit-show-habits)
5974 (and (not todayp)
5975 (boundp 'org-habit-show-habits-only-for-today)
5976 org-habit-show-habits-only-for-today))
5977 (throw :skip nil))
5978 (if (and
5979 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5980 (and org-agenda-skip-scheduled-if-deadline-is-shown
5981 pastschedp))
5982 (setq mm (assoc pos1 deadline-position-alist)))
5983 (throw :skip nil)))
5984 (setq tags (org-get-tags-at))
5985 (setq head (buffer-substring-no-properties
5986 (point)
5987 (progn (skip-chars-forward "^\r\n") (point))))
5988 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5989 (setq timestr
5990 (concat (substring s (match-beginning 1)) " "))
5991 (setq timestr 'time))
5992 (setq txt (org-agenda-format-item
5993 (if (= diff 0)
5994 (car org-agenda-scheduled-leaders)
5995 (format (nth 1 org-agenda-scheduled-leaders)
5996 (- 1 diff)))
5997 head category tags
5998 (if (not (= diff 0)) nil timestr)
5999 nil habitp))))
6000 (when txt
6001 (setq face
6002 (cond
6003 ((and (not habitp) pastschedp)
6004 'org-scheduled-previously)
6005 (todayp 'org-scheduled-today)
6006 (t 'org-scheduled))
6007 habitp (and habitp (org-habit-parse-todo)))
6008 (org-add-props txt props
6009 'undone-face face
6010 'face (if donep 'org-agenda-done face)
6011 'org-marker (org-agenda-new-marker pos)
6012 'org-hd-marker (org-agenda-new-marker pos1)
6013 'type (if pastschedp "past-scheduled" "scheduled")
6014 'date (if pastschedp d2 date)
6015 'warntime warntime
6016 'priority (if habitp
6017 (org-habit-get-priority habitp)
6018 (+ 94 (- 5 diff) (org-get-priority txt)))
6019 'org-category category
6020 'category-position category-pos
6021 'org-habit-p habitp
6022 'todo-state todo-state)
6023 (push txt ee))))))
6024 (nreverse ee)))
6026 (defun org-agenda-get-blocks ()
6027 "Return the date-range information for agenda display."
6028 (let* ((props (list 'face nil
6029 'org-not-done-regexp org-not-done-regexp
6030 'org-todo-regexp org-todo-regexp
6031 'org-complex-heading-regexp org-complex-heading-regexp
6032 'mouse-face 'highlight
6033 'help-echo
6034 (format "mouse-2 or RET jump to org file %s"
6035 (abbreviate-file-name buffer-file-name))))
6036 (regexp org-tr-regexp)
6037 (d0 (calendar-absolute-from-gregorian date))
6038 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6039 todo-state tags pos head donep)
6040 (goto-char (point-min))
6041 (while (re-search-forward regexp nil t)
6042 (catch :skip
6043 (org-agenda-skip)
6044 (setq pos (point))
6045 (let ((start-time (match-string 1))
6046 (end-time (match-string 2)))
6047 (setq s1 (match-string 1)
6048 s2 (match-string 2)
6049 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6050 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6051 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6052 ;; Only allow days between the limits, because the normal
6053 ;; date stamps will catch the limits.
6054 (save-excursion
6055 (setq todo-state (org-get-todo-state))
6056 (setq donep (member todo-state org-done-keywords))
6057 (if (and donep org-agenda-skip-timestamp-if-done)
6058 (throw :skip t))
6059 (setq marker (org-agenda-new-marker (point)))
6060 (setq category (org-get-category)
6061 category-pos (get-text-property (point) 'org-category-position))
6062 (if (not (re-search-backward org-outline-regexp-bol nil t))
6063 (setq txt org-agenda-no-heading-message)
6064 (goto-char (match-beginning 0))
6065 (setq hdmarker (org-agenda-new-marker (point)))
6066 (setq tags (org-get-tags-at))
6067 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6068 (setq head (match-string 1))
6069 (let ((remove-re
6070 (if org-agenda-remove-timeranges-from-blocks
6071 (concat
6072 "<" (regexp-quote s1) ".*?>"
6073 "--"
6074 "<" (regexp-quote s2) ".*?>")
6075 nil)))
6076 (setq txt (org-agenda-format-item
6077 (format
6078 (nth (if (= d1 d2) 0 1)
6079 org-agenda-timerange-leaders)
6080 (1+ (- d0 d1)) (1+ (- d2 d1)))
6081 head category tags
6082 (cond ((and (= d1 d0) (= d2 d0))
6083 (concat "<" start-time ">--<" end-time ">"))
6084 ((= d1 d0)
6085 (concat "<" start-time ">"))
6086 ((= d2 d0)
6087 (concat "<" end-time ">")))
6088 remove-re))))
6089 (org-add-props txt props
6090 'org-marker marker 'org-hd-marker hdmarker
6091 'type "block" 'date date
6092 'todo-state todo-state
6093 'priority (org-get-priority txt) 'org-category category
6094 'org-category-position category-pos)
6095 (push txt ee))))
6096 (goto-char pos)))
6097 ;; Sort the entries by expiration date.
6098 (nreverse ee)))
6100 ;;; Agenda presentation and sorting
6102 (defvar org-prefix-has-time nil
6103 "A flag, set by `org-compile-prefix-format'.
6104 The flag is set if the currently compiled format contains a `%t'.")
6105 (defvar org-prefix-has-tag nil
6106 "A flag, set by `org-compile-prefix-format'.
6107 The flag is set if the currently compiled format contains a `%T'.")
6108 (defvar org-prefix-has-effort nil
6109 "A flag, set by `org-compile-prefix-format'.
6110 The flag is set if the currently compiled format contains a `%e'.")
6111 (defvar org-prefix-category-length nil
6112 "Used by `org-compile-prefix-format' to remember the category field width.")
6113 (defvar org-prefix-category-max-length nil
6114 "Used by `org-compile-prefix-format' to remember the category field width.")
6116 (defun org-agenda-get-category-icon (category)
6117 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6118 (dolist (entry org-agenda-category-icon-alist)
6119 (when (org-string-match-p (car entry) category)
6120 (if (listp (cadr entry))
6121 (return (cadr entry))
6122 (return (apply 'create-image (cdr entry)))))))
6124 (defun org-agenda-format-item (extra txt &optional category tags dotime
6125 remove-re habitp)
6126 "Format TXT to be inserted into the agenda buffer.
6127 In particular, it adds the prefix and corresponding text properties. EXTRA
6128 must be a string and replaces the `%s' specifier in the prefix format.
6129 CATEGORY (string, symbol or nil) may be used to overrule the default
6130 category taken from local variable or file name. It will replace the `%c'
6131 specifier in the format. DOTIME, when non-nil, indicates that a
6132 time-of-day should be extracted from TXT for sorting of this entry, and for
6133 the `%t' specifier in the format. When DOTIME is a string, this string is
6134 searched for a time before TXT is. TAGS can be the tags of the headline.
6135 Any match of REMOVE-RE will be removed from TXT."
6136 ;; We keep the org-prefix-* variable values along with a compiled
6137 ;; formatter, so that multiple agendas existing at the same time, do
6138 ;; not step on each other toes.
6140 ;; It was inconvenient to make these variables buffer local in
6141 ;; Agenda buffers, because this function expects to be called with
6142 ;; the buffer where item comes from being current, and not agenda
6143 ;; buffer
6144 (let* ((bindings (car org-prefix-format-compiled))
6145 (formatter (cadr org-prefix-format-compiled)))
6146 (loop for (var value) in bindings
6147 do (set var value))
6148 (save-match-data
6149 ;; Diary entries sometimes have extra whitespace at the beginning
6150 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
6152 ;; Fix the tags part in txt
6153 (setq txt (org-agenda-fix-displayed-tags
6154 txt tags
6155 org-agenda-show-inherited-tags
6156 org-agenda-hide-tags-regexp))
6157 (let* ((category (or category
6158 (if (stringp org-category)
6159 org-category
6160 (and org-category (symbol-name org-category)))
6161 (if buffer-file-name
6162 (file-name-sans-extension
6163 (file-name-nondirectory buffer-file-name))
6164 "")))
6165 (category-icon (org-agenda-get-category-icon category))
6166 (category-icon (if category-icon
6167 (propertize " " 'display category-icon)
6168 ""))
6169 ;; time, tag, effort are needed for the eval of the prefix format
6170 (tag (if tags (nth (1- (length tags)) tags) ""))
6171 time effort neffort
6172 (ts (if dotime (concat
6173 (if (stringp dotime) dotime "")
6174 (and org-agenda-search-headline-for-time txt))))
6175 (time-of-day (and dotime (org-get-time-of-day ts)))
6176 stamp plain s0 s1 s2 rtn srp l
6177 duration thecategory)
6178 (and (derived-mode-p 'org-mode) buffer-file-name
6179 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6180 (when (and dotime time-of-day)
6181 ;; Extract starting and ending time and move them to prefix
6182 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6183 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6184 (setq s0 (match-string 0 ts)
6185 srp (and stamp (match-end 3))
6186 s1 (match-string (if plain 1 2) ts)
6187 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6189 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6190 ;; them, we might want to remove them there to avoid duplication.
6191 ;; The user can turn this off with a variable.
6192 (if (and org-prefix-has-time
6193 org-agenda-remove-times-when-in-prefix (or stamp plain)
6194 (string-match (concat (regexp-quote s0) " *") txt)
6195 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6196 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6197 (= (match-beginning 0) 0)
6199 (setq txt (replace-match "" nil nil txt))))
6200 ;; Normalize the time(s) to 24 hour
6201 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6202 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6204 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6205 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6206 (setq s2
6207 (org-minutes-to-hh:mm-string
6208 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6210 ;; Compute the duration
6211 (when s2
6212 (setq duration (- (org-hh:mm-string-to-minutes s2)
6213 (org-hh:mm-string-to-minutes s1)))))
6215 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6216 txt)
6217 ;; Tags are in the string
6218 (if (or (eq org-agenda-remove-tags t)
6219 (and org-agenda-remove-tags
6220 org-prefix-has-tag))
6221 (setq txt (replace-match "" t t txt))
6222 (setq txt (replace-match
6223 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6224 (match-string 2 txt))
6225 t t txt))))
6226 (when (derived-mode-p 'org-mode)
6227 (setq effort
6228 (condition-case nil
6229 (org-get-effort
6230 (or (get-text-property 0 'org-hd-marker txt)
6231 (get-text-property 0 'org-marker txt)))
6232 (error nil)))
6233 (when effort
6234 (setq neffort (org-duration-string-to-minutes effort)
6235 effort (setq effort (concat "[" effort "]")))))
6236 ;; prevent erroring out with %e format when there is no effort
6237 (or effort (setq effort ""))
6239 (when remove-re
6240 (while (string-match remove-re txt)
6241 (setq txt (replace-match "" t t txt))))
6243 ;; Set org-heading property on `txt' to mark the start of the
6244 ;; heading.
6245 (add-text-properties 0 (length txt) '(org-heading t) txt)
6247 ;; Prepare the variables needed in the eval of the compiled format
6248 (setq time (cond (s2 (concat
6249 (org-agenda-time-of-day-to-ampm-maybe s1)
6250 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6251 (if org-agenda-timegrid-use-ampm " ")))
6252 (s1 (concat
6253 (org-agenda-time-of-day-to-ampm-maybe s1)
6254 (if org-agenda-timegrid-use-ampm
6255 "........ "
6256 "......")))
6257 (t ""))
6258 extra (or (and (not habitp) extra) "")
6259 category (if (symbolp category) (symbol-name category) category)
6260 thecategory (copy-sequence category))
6261 (if (string-match org-bracket-link-regexp category)
6262 (progn
6263 (setq l (if (match-end 3)
6264 (- (match-end 3) (match-beginning 3))
6265 (- (match-end 1) (match-beginning 1))))
6266 (when (< l (or org-prefix-category-length 0))
6267 (setq category (copy-sequence category))
6268 (org-add-props category nil
6269 'extra-space (make-string
6270 (- org-prefix-category-length l 1) ?\ ))))
6271 (if (and org-prefix-category-max-length
6272 (>= (length category) org-prefix-category-max-length))
6273 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6274 ;; Evaluate the compiled format
6275 (setq rtn (concat (eval formatter) txt))
6277 ;; And finally add the text properties
6278 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6279 (org-add-props rtn nil
6280 'org-category (if thecategory (downcase thecategory) category)
6281 'tags (mapcar 'org-downcase-keep-props tags)
6282 'org-highest-priority org-highest-priority
6283 'org-lowest-priority org-lowest-priority
6284 'time-of-day time-of-day
6285 'duration duration
6286 'effort effort
6287 'effort-minutes neffort
6288 'txt txt
6289 'time time
6290 'extra extra
6291 'format org-prefix-format-compiled
6292 'dotime dotime)))))
6294 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6295 "Remove tags string from TXT, and add a modified list of tags.
6296 The modified list may contain inherited tags, and tags matched by
6297 `org-agenda-hide-tags-regexp' will be removed."
6298 (when (or add-inherited hide-re)
6299 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6300 (setq txt (substring txt 0 (match-beginning 0))))
6301 (setq tags
6302 (delq nil
6303 (mapcar (lambda (tg)
6304 (if (or (and hide-re (string-match hide-re tg))
6305 (and (not add-inherited)
6306 (get-text-property 0 'inherited tg)))
6308 tg))
6309 tags)))
6310 (when tags
6311 (let ((have-i (get-text-property 0 'inherited (car tags)))
6313 (setq txt (concat txt " :"
6314 (mapconcat
6315 (lambda (x)
6316 (setq i (get-text-property 0 'inherited x))
6317 (if (and have-i (not i))
6318 (progn
6319 (setq have-i nil)
6320 (concat ":" x))
6322 tags ":")
6323 (if have-i "::" ":"))))))
6324 txt)
6326 (defun org-downcase-keep-props (s)
6327 (let ((props (text-properties-at 0 s)))
6328 (setq s (downcase s))
6329 (add-text-properties 0 (length s) props s)
6332 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6333 (defvar org-agenda-sorting-strategy-selected nil)
6335 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6336 (catch 'exit
6337 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6338 ((and todayp (member 'today (car org-agenda-time-grid))))
6339 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6340 ((member 'weekly (car org-agenda-time-grid)))
6341 (t (throw 'exit list)))
6342 (let* ((have (delq nil (mapcar
6343 (lambda (x) (get-text-property 1 'time-of-day x))
6344 list)))
6345 (string (nth 1 org-agenda-time-grid))
6346 (gridtimes (nth 2 org-agenda-time-grid))
6347 (req (car org-agenda-time-grid))
6348 (remove (member 'remove-match req))
6349 new time)
6350 (if (and (member 'require-timed req) (not have))
6351 ;; don't show empty grid
6352 (throw 'exit list))
6353 (while (setq time (pop gridtimes))
6354 (unless (and remove (member time have))
6355 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6356 (push (org-agenda-format-item
6357 nil string "" nil
6358 (concat (substring time 0 -2) ":" (substring time -2)))
6359 new)
6360 (put-text-property
6361 2 (length (car new)) 'face 'org-time-grid (car new))))
6362 (when (and todayp org-agenda-show-current-time-in-grid)
6363 (push (org-agenda-format-item
6365 org-agenda-current-time-string
6366 "" nil
6367 (format-time-string "%H:%M "))
6368 new)
6369 (put-text-property
6370 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6372 (if (member 'time-up org-agenda-sorting-strategy-selected)
6373 (append new list)
6374 (append list new)))))
6376 (defun org-compile-prefix-format (key)
6377 "Compile the prefix format into a Lisp form that can be evaluated.
6378 The resulting form and associated variable bindings is returned
6379 and stored in the variable `org-prefix-format-compiled'."
6380 (setq org-prefix-has-time nil org-prefix-has-tag nil
6381 org-prefix-category-length nil
6382 org-prefix-has-effort nil)
6383 (let ((s (cond
6384 ((stringp org-agenda-prefix-format)
6385 org-agenda-prefix-format)
6386 ((assq key org-agenda-prefix-format)
6387 (cdr (assq key org-agenda-prefix-format)))
6388 (t " %-12:c%?-12t% s")))
6389 (start 0)
6390 varform vars var e c f opt)
6391 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6392 s start)
6393 (setq var (or (cdr (assoc (match-string 4 s)
6394 '(("c" . category) ("t" . time) ("s" . extra)
6395 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6396 'eval)
6397 c (or (match-string 3 s) "")
6398 opt (match-beginning 1)
6399 start (1+ (match-beginning 0)))
6400 (if (equal var 'time) (setq org-prefix-has-time t))
6401 (if (equal var 'tag) (setq org-prefix-has-tag t))
6402 (if (equal var 'effort) (setq org-prefix-has-effort t))
6403 (setq f (concat "%" (match-string 2 s) "s"))
6404 (when (equal var 'category)
6405 (setq org-prefix-category-length
6406 (floor (abs (string-to-number (match-string 2 s)))))
6407 (setq org-prefix-category-max-length
6408 (let ((x (match-string 2 s)))
6409 (save-match-data
6410 (if (string-match "\\.[0-9]+" x)
6411 (string-to-number (substring (match-string 0 x) 1)))))))
6412 (if (eq var 'eval)
6413 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6414 (if opt
6415 (setq varform
6416 `(if (equal "" ,var)
6418 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6419 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6420 (setq s (replace-match "%s" t nil s))
6421 (push varform vars))
6422 (setq vars (nreverse vars))
6423 (with-current-buffer (or org-agenda-buffer (current-buffer))
6424 (setq org-prefix-format-compiled
6425 (list
6426 `((org-prefix-has-time ,org-prefix-has-time)
6427 (org-prefix-has-tag ,org-prefix-has-tag)
6428 (org-prefix-category-length ,org-prefix-category-length)
6429 (org-prefix-has-effort ,org-prefix-has-effort))
6430 `(format ,s ,@vars))))))
6432 (defun org-set-sorting-strategy (key)
6433 (if (symbolp (car org-agenda-sorting-strategy))
6434 ;; the old format
6435 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6436 (setq org-agenda-sorting-strategy-selected
6437 (or (cdr (assq key org-agenda-sorting-strategy))
6438 (cdr (assq 'agenda org-agenda-sorting-strategy))
6439 '(time-up category-keep priority-down)))))
6441 (defun org-get-time-of-day (s &optional string mod24)
6442 "Check string S for a time of day.
6443 If found, return it as a military time number between 0 and 2400.
6444 If not found, return nil.
6445 The optional STRING argument forces conversion into a 5 character wide string
6446 HH:MM."
6447 (save-match-data
6448 (when
6449 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6450 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6451 (let* ((h (string-to-number (match-string 1 s)))
6452 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6453 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6454 (am-p (equal ampm "am"))
6455 (h1 (cond ((not ampm) h)
6456 ((= h 12) (if am-p 0 12))
6457 (t (+ h (if am-p 0 12)))))
6458 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6459 (mod h1 24) h1))
6460 (t0 (+ (* 100 h2) m))
6461 (t1 (concat (if (>= h1 24) "+" " ")
6462 (if (and org-agenda-time-leading-zero
6463 (< t0 1000)) "0" "")
6464 (if (< t0 100) "0" "")
6465 (if (< t0 10) "0" "")
6466 (int-to-string t0))))
6467 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6469 (defvar org-agenda-before-sorting-filter-function nil
6470 "Function to be applied to agenda items prior to sorting.
6471 Prior to sorting also means just before they are inserted into the agenda.
6473 To aid sorting, you may revisit the original entries and add more text
6474 properties which will later be used by the sorting functions.
6476 The function should take a string argument, an agenda line.
6477 It has access to the text properties in that line, which contain among
6478 other things, the property `org-hd-marker' that points to the entry
6479 where the line comes from. Note that not all lines going into the agenda
6480 have this property, only most.
6482 The function should return the modified string. It is probably best
6483 to ONLY change text properties.
6485 You can also use this function as a filter, by returning nil for lines
6486 you don't want to have in the agenda at all. For this application, you
6487 could bind the variable in the options section of a custom command.")
6489 (defun org-agenda-finalize-entries (list &optional nosort)
6490 "Sort and concatenate the agenda items."
6491 (setq list (mapcar 'org-agenda-highlight-todo list))
6492 (if nosort
6493 list
6494 (when org-agenda-before-sorting-filter-function
6495 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6496 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6498 (defun org-agenda-highlight-todo (x)
6499 (let ((org-done-keywords org-done-keywords-for-agenda)
6500 (case-fold-search nil)
6502 (if (eq x 'line)
6503 (save-excursion
6504 (beginning-of-line 1)
6505 (setq re (org-get-at-bol 'org-todo-regexp))
6506 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6507 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6508 (add-text-properties (match-beginning 0) (match-end 1)
6509 (list 'face (org-get-todo-face 1)))
6510 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6511 (delete-region (match-beginning 1) (1- (match-end 0)))
6512 (goto-char (match-beginning 1))
6513 (insert (format org-agenda-todo-keyword-format s)))))
6514 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6515 (setq re (get-text-property 0 'org-todo-regexp x))
6516 (when (and re
6517 ;; Test `pl' because if there's no heading content,
6518 ;; there's no point matching to highlight. Note
6519 ;; that if we didn't test `pl' first, and there
6520 ;; happened to be no keyword from `org-todo-regexp'
6521 ;; on this heading line, then the `equal' comparison
6522 ;; afterwards would spuriously succeed in the case
6523 ;; where `pl' is nil -- causing an args-out-of-range
6524 ;; error when we try to add text properties to text
6525 ;; that isn't there.
6527 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6528 x pl) pl))
6529 (add-text-properties
6530 (or (match-end 1) (match-end 0)) (match-end 0)
6531 (list 'face (org-get-todo-face (match-string 2 x)))
6533 (when (match-end 1)
6534 (setq x (concat (substring x 0 (match-end 1))
6535 (format org-agenda-todo-keyword-format
6536 (match-string 2 x))
6537 (org-add-props " " (text-properties-at 0 x))
6538 (substring x (match-end 3)))))))
6539 x)))
6541 (defsubst org-cmp-priority (a b)
6542 "Compare the priorities of string A and B."
6543 (let ((pa (or (get-text-property 1 'priority a) 0))
6544 (pb (or (get-text-property 1 'priority b) 0)))
6545 (cond ((> pa pb) +1)
6546 ((< pa pb) -1))))
6548 (defsubst org-cmp-effort (a b)
6549 "Compare the effort values of string A and B."
6550 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6551 (ea (or (get-text-property 1 'effort-minutes a) def))
6552 (eb (or (get-text-property 1 'effort-minutes b) def)))
6553 (cond ((> ea eb) +1)
6554 ((< ea eb) -1))))
6556 (defsubst org-cmp-category (a b)
6557 "Compare the string values of categories of strings A and B."
6558 (let ((ca (or (get-text-property 1 'org-category a) ""))
6559 (cb (or (get-text-property 1 'org-category b) "")))
6560 (cond ((string-lessp ca cb) -1)
6561 ((string-lessp cb ca) +1))))
6563 (defsubst org-cmp-todo-state (a b)
6564 "Compare the todo states of strings A and B."
6565 (let* ((ma (or (get-text-property 1 'org-marker a)
6566 (get-text-property 1 'org-hd-marker a)))
6567 (mb (or (get-text-property 1 'org-marker b)
6568 (get-text-property 1 'org-hd-marker b)))
6569 (fa (and ma (marker-buffer ma)))
6570 (fb (and mb (marker-buffer mb)))
6571 (todo-kwds
6572 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6573 (and fb (with-current-buffer fb org-todo-keywords-1))))
6574 (ta (or (get-text-property 1 'todo-state a) ""))
6575 (tb (or (get-text-property 1 'todo-state b) ""))
6576 (la (- (length (member ta todo-kwds))))
6577 (lb (- (length (member tb todo-kwds))))
6578 (donepa (member ta org-done-keywords-for-agenda))
6579 (donepb (member tb org-done-keywords-for-agenda)))
6580 (cond ((and donepa (not donepb)) -1)
6581 ((and (not donepa) donepb) +1)
6582 ((< la lb) -1)
6583 ((< lb la) +1))))
6585 (defsubst org-cmp-alpha (a b)
6586 "Compare the headlines, alphabetically."
6587 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6588 (plb (text-property-any 0 (length b) 'org-heading t b))
6589 (ta (and pla (substring a pla)))
6590 (tb (and plb (substring b plb))))
6591 (when pla
6592 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6593 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6594 (setq ta (substring ta (match-end 0))))
6595 (setq ta (downcase ta)))
6596 (when plb
6597 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6598 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6599 (setq tb (substring tb (match-end 0))))
6600 (setq tb (downcase tb)))
6601 (cond ((not ta) +1)
6602 ((not tb) -1)
6603 ((string-lessp ta tb) -1)
6604 ((string-lessp tb ta) +1))))
6606 (defsubst org-cmp-tag (a b)
6607 "Compare the string values of the first tags of A and B."
6608 (let ((ta (car (last (get-text-property 1 'tags a))))
6609 (tb (car (last (get-text-property 1 'tags b)))))
6610 (cond ((not ta) +1)
6611 ((not tb) -1)
6612 ((string-lessp ta tb) -1)
6613 ((string-lessp tb ta) +1))))
6615 (defsubst org-cmp-time (a b)
6616 "Compare the time-of-day values of strings A and B."
6617 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6618 (ta (or (get-text-property 1 'time-of-day a) def))
6619 (tb (or (get-text-property 1 'time-of-day b) def)))
6620 (cond ((< ta tb) -1)
6621 ((< tb ta) +1))))
6623 (defsubst org-cmp-habit-p (a b)
6624 "Compare the todo states of strings A and B."
6625 (let ((ha (get-text-property 1 'org-habit-p a))
6626 (hb (get-text-property 1 'org-habit-p b)))
6627 (cond ((and ha (not hb)) -1)
6628 ((and (not ha) hb) +1))))
6630 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6632 (defun org-entries-lessp (a b)
6633 "Predicate for sorting agenda entries."
6634 ;; The following variables will be used when the form is evaluated.
6635 ;; So even though the compiler complains, keep them.
6636 (let* ((ss org-agenda-sorting-strategy-selected)
6637 (time-up (and (org-em 'time-up 'time-down ss)
6638 (org-cmp-time a b)))
6639 (time-down (if time-up (- time-up) nil))
6640 (priority-up (and (org-em 'priority-up 'priority-down ss)
6641 (org-cmp-priority a b)))
6642 (priority-down (if priority-up (- priority-up) nil))
6643 (effort-up (and (org-em 'effort-up 'effort-down ss)
6644 (org-cmp-effort a b)))
6645 (effort-down (if effort-up (- effort-up) nil))
6646 (category-up (and (or (org-em 'category-up 'category-down ss)
6647 (memq 'category-keep ss))
6648 (org-cmp-category a b)))
6649 (category-down (if category-up (- category-up) nil))
6650 (category-keep (if category-up +1 nil))
6651 (tag-up (and (org-em 'tag-up 'tag-down ss)
6652 (org-cmp-tag a b)))
6653 (tag-down (if tag-up (- tag-up) nil))
6654 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6655 (org-cmp-todo-state a b)))
6656 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6657 (habit-up (and (org-em 'habit-up 'habit-down ss)
6658 (org-cmp-habit-p a b)))
6659 (habit-down (if habit-up (- habit-up) nil))
6660 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6661 (org-cmp-alpha a b)))
6662 (alpha-down (if alpha-up (- alpha-up) nil))
6663 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6664 user-defined-up user-defined-down)
6665 (if (and need-user-cmp org-agenda-cmp-user-defined
6666 (functionp org-agenda-cmp-user-defined))
6667 (setq user-defined-up
6668 (funcall org-agenda-cmp-user-defined a b)
6669 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6670 (cdr (assoc
6671 (eval (cons 'or org-agenda-sorting-strategy-selected))
6672 '((-1 . t) (1 . nil) (nil . nil))))))
6674 ;;; Agenda restriction lock
6676 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6677 "Overlay to mark the headline to which agenda commands are restricted.")
6678 (overlay-put org-agenda-restriction-lock-overlay
6679 'face 'org-agenda-restriction-lock)
6680 (overlay-put org-agenda-restriction-lock-overlay
6681 'help-echo "Agendas are currently limited to this subtree.")
6682 (org-detach-overlay org-agenda-restriction-lock-overlay)
6684 (defun org-agenda-set-restriction-lock (&optional type)
6685 "Set restriction lock for agenda, to current subtree or file.
6686 Restriction will be the file if TYPE is `file', or if type is the
6687 universal prefix '(4), or if the cursor is before the first headline
6688 in the file. Otherwise, restriction will be to the current subtree."
6689 (interactive "P")
6690 (and (equal type '(4)) (setq type 'file))
6691 (setq type (cond
6692 (type type)
6693 ((org-at-heading-p) 'subtree)
6694 ((condition-case nil (org-back-to-heading t) (error nil))
6695 'subtree)
6696 (t 'file)))
6697 (if (eq type 'subtree)
6698 (progn
6699 (setq org-agenda-restrict t)
6700 (setq org-agenda-overriding-restriction 'subtree)
6701 (put 'org-agenda-files 'org-restrict
6702 (list (buffer-file-name (buffer-base-buffer))))
6703 (org-back-to-heading t)
6704 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6705 (move-marker org-agenda-restrict-begin (point))
6706 (move-marker org-agenda-restrict-end
6707 (save-excursion (org-end-of-subtree t)))
6708 (message "Locking agenda restriction to subtree"))
6709 (put 'org-agenda-files 'org-restrict
6710 (list (buffer-file-name (buffer-base-buffer))))
6711 (setq org-agenda-restrict nil)
6712 (setq org-agenda-overriding-restriction 'file)
6713 (move-marker org-agenda-restrict-begin nil)
6714 (move-marker org-agenda-restrict-end nil)
6715 (message "Locking agenda restriction to file"))
6716 (setq current-prefix-arg nil)
6717 (org-agenda-maybe-redo))
6719 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6720 "Remove the agenda restriction lock."
6721 (interactive "P")
6722 (org-detach-overlay org-agenda-restriction-lock-overlay)
6723 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6724 (setq org-agenda-overriding-restriction nil)
6725 (setq org-agenda-restrict nil)
6726 (put 'org-agenda-files 'org-restrict nil)
6727 (move-marker org-agenda-restrict-begin nil)
6728 (move-marker org-agenda-restrict-end nil)
6729 (setq current-prefix-arg nil)
6730 (message "Agenda restriction lock removed")
6731 (or noupdate (org-agenda-maybe-redo)))
6733 (defun org-agenda-maybe-redo ()
6734 "If there is any window showing the agenda view, update it."
6735 (let ((w (get-buffer-window org-agenda-buffer-name t))
6736 (w0 (selected-window)))
6737 (when w
6738 (select-window w)
6739 (org-agenda-redo)
6740 (select-window w0)
6741 (if org-agenda-overriding-restriction
6742 (message "Agenda view shifted to new %s restriction"
6743 org-agenda-overriding-restriction)
6744 (message "Agenda restriction lock removed")))))
6746 ;;; Agenda commands
6748 (defun org-agenda-check-type (error &rest types)
6749 "Check if agenda buffer is of allowed type.
6750 If ERROR is non-nil, throw an error, otherwise just return nil."
6751 (if (not org-agenda-type)
6752 (error "No Org agenda currently displayed")
6753 (if (memq org-agenda-type types)
6755 (if error
6756 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6757 nil))))
6759 (defun org-agenda-Quit (&optional arg)
6760 "Exit agenda by removing the window or the buffer."
6761 (interactive)
6762 (if org-agenda-columns-active
6763 (org-columns-quit)
6764 (let ((buf (current-buffer)))
6765 (if (eq org-agenda-window-setup 'other-frame)
6766 (progn
6767 (org-agenda-reset-markers)
6768 (kill-buffer buf)
6769 (org-columns-remove-overlays)
6770 (setq org-agenda-archives-mode nil)
6771 (delete-frame))
6772 (and (not (eq org-agenda-window-setup 'current-window))
6773 (not (one-window-p))
6774 (delete-window))
6775 (org-agenda-reset-markers)
6776 (kill-buffer buf)
6777 (org-columns-remove-overlays)
6778 (setq org-agenda-archives-mode nil)))
6779 ;; Maybe restore the pre-agenda window configuration.
6780 (and org-agenda-restore-windows-after-quit
6781 (not (eq org-agenda-window-setup 'other-frame))
6782 org-agenda-pre-window-conf
6783 (set-window-configuration org-agenda-pre-window-conf)
6784 (setq org-agenda-pre-window-conf nil))))
6786 (defun org-agenda-quit ()
6787 "Exit agenda by killing agenda buffer or burying it when
6788 `org-agenda-sticky' is non-NIL"
6789 (interactive)
6790 (if (and (eq org-indirect-buffer-display 'other-window)
6791 org-last-indirect-buffer)
6792 (delete-window (get-buffer-window org-last-indirect-buffer)))
6793 (if org-agenda-columns-active
6794 (org-columns-quit)
6795 (if org-agenda-sticky
6796 (let ((buf (current-buffer)))
6797 (if (eq org-agenda-window-setup 'other-frame)
6798 (progn
6799 (delete-frame))
6800 (and (not (eq org-agenda-window-setup 'current-window))
6801 (not (one-window-p))
6802 (delete-window)))
6803 (with-current-buffer buf
6804 (bury-buffer)
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))))
6811 (org-agenda-Quit))))
6813 (defun org-agenda-exit ()
6814 "Exit agenda by removing the window or the buffer.
6815 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6816 Org-mode buffers visited directly by the user will not be touched."
6817 (interactive)
6818 (org-release-buffers org-agenda-new-buffers)
6819 (setq org-agenda-new-buffers nil)
6820 (org-agenda-Quit))
6822 (defun org-agenda-kill-all-agenda-buffers ()
6823 "Kill all buffers in `org-agenda-mode'.
6824 This is used when toggling sticky agendas. You can also explicitly invoke it
6825 with `C-c a C-k'."
6826 (interactive)
6827 (let (blist)
6828 (dolist (buf (buffer-list))
6829 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6830 (push buf blist)))
6831 (mapc 'kill-buffer blist)))
6833 (defun org-agenda-execute (arg)
6834 "Execute another agenda command, keeping same window.
6835 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6836 in the agenda."
6837 (interactive "P")
6838 (let ((org-agenda-window-setup 'current-window))
6839 (org-agenda arg)))
6841 (defun org-agenda-redo (&optional all)
6842 "Rebuild possibly ALL agenda view(s) in the current buffer."
6843 (interactive "P")
6844 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6845 (cpa (unless (eq all t) current-prefix-arg))
6846 (org-agenda-doing-sticky-redo org-agenda-sticky)
6847 (org-agenda-sticky nil)
6848 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6849 org-agenda-buffer-name))
6850 (org-agenda-keep-modes t)
6851 (tag-filter org-agenda-tag-filter)
6852 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6853 (top-cat-filter org-agenda-top-category-filter)
6854 (cat-filter org-agenda-category-filter)
6855 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6856 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6857 (cols org-agenda-columns-active)
6858 (line (org-current-line))
6859 (window-line (- line (org-current-line (window-start))))
6860 (lprops (get 'org-agenda-redo-command 'org-lprops))
6861 (redo-cmd (get-text-property p 'org-redo-cmd))
6862 (last-args (get-text-property p 'org-last-args))
6863 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6864 (org-agenda-overriding-cmd-arguments
6865 (unless (eq all t)
6866 (cond ((listp last-args)
6867 (cons (or cpa (car last-args)) (cdr last-args)))
6868 ((stringp last-args)
6869 last-args))))
6870 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6871 (put 'org-agenda-tag-filter :preset-filter nil)
6872 (put 'org-agenda-category-filter :preset-filter nil)
6873 (and cols (org-columns-quit))
6874 (message "Rebuilding agenda buffer...")
6875 (if series-redo-cmd
6876 (eval series-redo-cmd)
6877 (org-let lprops '(eval redo-cmd)))
6878 (setq org-agenda-undo-list nil
6879 org-agenda-pending-undo-list nil)
6880 (message "Rebuilding agenda buffer...done")
6881 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6882 (put 'org-agenda-category-filter :preset-filter cat-preset)
6883 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6884 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6885 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6886 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6887 (org-goto-line line)
6888 (recenter window-line)))
6890 (defvar org-global-tags-completion-table nil)
6891 (defvar org-agenda-filter-form nil)
6892 (defvar org-agenda-filtered-by-category nil)
6894 (defun org-agenda-filter-by-category (strip)
6895 "Keep only those lines in the agenda buffer that have a specific category.
6896 The category is that of the current line."
6897 (interactive "P")
6898 (if (and org-agenda-filtered-by-category
6899 org-agenda-category-filter)
6900 (org-agenda-filter-show-all-cat)
6901 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6902 (if cat (org-agenda-filter-apply
6903 (list (concat (if strip "-" "+") cat)) 'category)
6904 (error "No category at point")))))
6906 (defun org-find-top-category (&optional pos)
6907 (save-excursion
6908 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6909 (if pos (goto-char pos))
6910 ;; Skip up to the topmost parent
6911 (while (ignore-errors (outline-up-heading 1) t))
6912 (ignore-errors
6913 (nth 4 (org-heading-components))))))
6915 (defvar org-agenda-filtered-by-top-category nil)
6917 (defun org-agenda-filter-by-top-category (strip)
6918 "Keep only those lines in the agenda buffer that have a specific category.
6919 The category is that of the current line."
6920 (interactive "P")
6921 (if org-agenda-filtered-by-top-category
6922 (progn
6923 (setq org-agenda-filtered-by-top-category nil
6924 org-agenda-top-category-filter nil)
6925 (org-agenda-filter-show-all-cat))
6926 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6927 (if cat (org-agenda-filter-top-category-apply cat strip)
6928 (error "No top-level category at point")))))
6930 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6931 "Keep only those lines in the agenda buffer that have a specific tag.
6932 The tag is selected with its fast selection letter, as configured.
6933 With prefix argument STRIP, remove all lines that do have the tag.
6934 A lisp caller can specify CHAR. NARROW means that the new tag should be
6935 used to narrow the search - the interactive user can also press `-' or `+'
6936 to switch to narrowing."
6937 (interactive "P")
6938 (let* ((alist org-tag-alist-for-agenda)
6939 (tag-chars (mapconcat
6940 (lambda (x) (if (and (not (symbolp (car x)))
6941 (cdr x))
6942 (char-to-string (cdr x))
6943 ""))
6944 alist ""))
6945 (efforts (org-split-string
6946 (or (cdr (assoc (concat org-effort-property "_ALL")
6947 org-global-properties))
6948 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6949 "")))
6950 (effort-op org-agenda-filter-effort-default-operator)
6951 (effort-prompt "")
6952 (inhibit-read-only t)
6953 (current org-agenda-tag-filter)
6954 maybe-refresh a n tag)
6955 (unless char
6956 (message
6957 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6958 (if narrow "Narrow" "Filter") tag-chars
6959 (if org-agenda-auto-exclude-function "[RET], " ""))
6960 (setq char (read-char-exclusive)))
6961 (when (member char '(?+ ?-))
6962 ;; Narrowing down
6963 (cond ((equal char ?-) (setq strip t narrow t))
6964 ((equal char ?+) (setq strip nil narrow t)))
6965 (message
6966 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6967 (setq char (read-char-exclusive)))
6968 (when (member char '(?< ?> ?= ??))
6969 ;; An effort operator
6970 (setq effort-op (char-to-string char))
6971 (setq alist nil) ; to make sure it will be interpreted as effort.
6972 (unless (equal char ??)
6973 (loop for i from 0 to 9 do
6974 (setq effort-prompt
6975 (concat
6976 effort-prompt " ["
6977 (if (= i 9) "0" (int-to-string (1+ i)))
6978 "]" (nth i efforts))))
6979 (message "Effort%s: %s " effort-op effort-prompt)
6980 (setq char (read-char-exclusive))
6981 (when (or (< char ?0) (> char ?9))
6982 (error "Need 1-9,0 to select effort"))))
6983 (when (equal char ?\t)
6984 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6985 (org-set-local 'org-global-tags-completion-table
6986 (org-global-tags-completion-table)))
6987 (let ((completion-ignore-case t))
6988 (setq tag (org-icompleting-read
6989 "Tag: " org-global-tags-completion-table))))
6990 (cond
6991 ((equal char ?\r)
6992 (org-agenda-filter-show-all-tag)
6993 (when org-agenda-auto-exclude-function
6994 (setq org-agenda-tag-filter '())
6995 (dolist (tag (org-agenda-get-represented-tags))
6996 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6997 (if modifier
6998 (push modifier org-agenda-tag-filter))))
6999 (if (not (null org-agenda-tag-filter))
7000 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7001 (setq maybe-refresh t))
7002 ((equal char ?/)
7003 (org-agenda-filter-show-all-tag)
7004 (when (get 'org-agenda-tag-filter :preset-filter)
7005 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7006 (setq maybe-refresh t))
7007 ((equal char ?. )
7008 (setq org-agenda-tag-filter
7009 (mapcar (lambda(tag) (concat "+" tag))
7010 (org-get-at-bol 'tags)))
7011 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7012 (setq maybe-refresh t))
7013 ((or (equal char ?\ )
7014 (setq a (rassoc char alist))
7015 (and (>= char ?0) (<= char ?9)
7016 (setq n (if (= char ?0) 9 (- char ?0 1))
7017 tag (concat effort-op (nth n efforts))
7018 a (cons tag nil)))
7019 (and (= char ??)
7020 (setq tag "?eff")
7021 a (cons tag nil))
7022 (and tag (setq a (cons tag nil))))
7023 (org-agenda-filter-show-all-tag)
7024 (setq tag (car a))
7025 (setq org-agenda-tag-filter
7026 (cons (concat (if strip "-" "+") tag)
7027 (if narrow current nil)))
7028 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7029 (setq maybe-refresh t))
7030 (t (error "Invalid tag selection character %c" char)))
7031 (when (and maybe-refresh
7032 (eq org-agenda-clockreport-mode 'with-filter))
7033 (org-agenda-redo))))
7035 (defun org-agenda-get-represented-tags ()
7036 "Get a list of all tags currently represented in the agenda."
7037 (let (p tags)
7038 (save-excursion
7039 (goto-char (point-min))
7040 (while (setq p (next-single-property-change (point) 'tags))
7041 (goto-char p)
7042 (mapc (lambda (x) (add-to-list 'tags x))
7043 (get-text-property (point) 'tags))))
7044 tags))
7046 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7047 "Refine the current filter. See `org-agenda-filter-by-tag'."
7048 (interactive "P")
7049 (org-agenda-filter-by-tag strip char 'refine))
7051 (defun org-agenda-filter-make-matcher ()
7052 "Create the form that tests a line for agenda filter."
7053 (let (f f1)
7054 ;; first compute the tag-filter matcher
7055 (dolist (x (delete-dups
7056 (append (get 'org-agenda-tag-filter
7057 :preset-filter) org-agenda-tag-filter)))
7058 (if (member x '("-" "+"))
7059 (setq f1 (if (equal x "-") 'tags '(not tags)))
7060 (if (string-match "[<=>?]" x)
7061 (setq f1 (org-agenda-filter-effort-form x))
7062 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7063 (if (equal (string-to-char x) ?-)
7064 (setq f1 (list 'not f1))))
7065 (push f1 f))
7066 ;; then compute the category-filter matcher
7067 (dolist (x (delete-dups
7068 (append (get 'org-agenda-category-filter
7069 :preset-filter) org-agenda-category-filter)))
7070 (if (equal "-" (substring x 0 1))
7071 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7072 (setq f1 (list 'equal (substring x 1) 'cat)))
7073 (push f1 f))
7074 (cons 'and (nreverse f))))
7076 (defun org-agenda-filter-effort-form (e)
7077 "Return the form to compare the effort of the current line with what E says.
7078 E looks like \"+<2:25\"."
7079 (let (op)
7080 (setq e (substring e 1))
7081 (setq op (string-to-char e) e (substring e 1))
7082 (setq op (cond ((equal op ?<) '<=)
7083 ((equal op ?>) '>=)
7084 ((equal op ??) op)
7085 (t '=)))
7086 (list 'org-agenda-compare-effort (list 'quote op)
7087 (org-duration-string-to-minutes e))))
7089 (defun org-agenda-compare-effort (op value)
7090 "Compare the effort of the current line with VALUE, using OP.
7091 If the line does not have an effort defined, return nil."
7092 (let ((eff (org-get-at-bol 'effort-minutes)))
7093 (if (equal op ??)
7094 (not eff)
7095 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7096 value))))
7098 (defun org-agenda-filter-apply (filter type)
7099 "Set FILTER as the new agenda filter and apply it."
7100 (let (tags cat)
7101 (if (eq type 'tag)
7102 (setq org-agenda-tag-filter filter)
7103 (setq org-agenda-category-filter filter))
7104 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7105 (if (and (eq type 'category)
7106 (not (equal (substring (car filter) 0 1) "-")))
7107 ;; Only set `org-agenda-filtered-by-category' to t
7108 ;; when a unique category is used as the filter
7109 (setq org-agenda-filtered-by-category t))
7110 (org-agenda-set-mode-name)
7111 (save-excursion
7112 (goto-char (point-min))
7113 (while (not (eobp))
7114 (if (org-get-at-bol 'org-marker)
7115 (progn
7116 (setq tags (org-get-at-bol 'tags) ; used in eval
7117 cat (get-text-property (point) 'org-category))
7118 (if (not (eval org-agenda-filter-form))
7119 (org-agenda-filter-hide-line type))
7120 (beginning-of-line 2))
7121 (beginning-of-line 2))))
7122 (if (get-char-property (point) 'invisible)
7123 (ignore-errors (org-agenda-previous-line)))))
7125 (defun org-agenda-filter-top-category-apply (category &optional negative)
7126 "Set FILTER as the new agenda filter and apply it."
7127 (org-agenda-set-mode-name)
7128 (save-excursion
7129 (goto-char (point-min))
7130 (while (not (eobp))
7131 (let* ((pos (org-get-at-bol 'org-hd-marker))
7132 (topcat (and pos (org-find-top-category pos))))
7133 (if (and topcat (funcall (if negative 'identity 'not)
7134 (string= category topcat)))
7135 (org-agenda-filter-hide-line 'category)))
7136 (beginning-of-line 2)))
7137 (if (get-char-property (point) 'invisible)
7138 (org-agenda-previous-line))
7139 (setq org-agenda-top-category-filter category
7140 org-agenda-filtered-by-top-category t))
7142 (defun org-agenda-filter-hide-line (type)
7143 (let (ov)
7144 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7145 (point-at-eol)))
7146 (overlay-put ov 'invisible t)
7147 (overlay-put ov 'type type)
7148 (if (eq type 'tag)
7149 (push ov org-agenda-tag-filter-overlays)
7150 (push ov org-agenda-cat-filter-overlays))))
7152 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7153 (setq pos (or pos (point)))
7154 (save-excursion
7155 (dolist (ov (overlays-at pos))
7156 (when (and (overlay-get ov 'invisible)
7157 (eq (overlay-get ov 'type) 'tag))
7158 (goto-char pos)
7159 (if (< (overlay-start ov) (point-at-eol))
7160 (move-overlay ov (point-at-eol)
7161 (overlay-end ov)))))))
7163 (defun org-agenda-filter-show-all-tag nil
7164 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7165 (setq org-agenda-tag-filter-overlays nil
7166 org-agenda-tag-filter nil
7167 org-agenda-filter-form nil)
7168 (org-agenda-set-mode-name))
7170 (defun org-agenda-filter-show-all-cat nil
7171 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7172 (setq org-agenda-cat-filter-overlays nil
7173 org-agenda-filtered-by-category nil
7174 org-agenda-category-filter nil
7175 org-agenda-filter-form nil)
7176 (org-agenda-set-mode-name))
7178 (defun org-agenda-manipulate-query-add ()
7179 "Manipulate the query by adding a search term with positive selection.
7180 Positive selection means the term must be matched for selection of an entry."
7181 (interactive)
7182 (org-agenda-manipulate-query ?\[))
7183 (defun org-agenda-manipulate-query-subtract ()
7184 "Manipulate the query by adding a search term with negative selection.
7185 Negative selection means term must not be matched for selection of an entry."
7186 (interactive)
7187 (org-agenda-manipulate-query ?\]))
7188 (defun org-agenda-manipulate-query-add-re ()
7189 "Manipulate the query by adding a search regexp with positive selection.
7190 Positive selection means the regexp must match for selection of an entry."
7191 (interactive)
7192 (org-agenda-manipulate-query ?\{))
7193 (defun org-agenda-manipulate-query-subtract-re ()
7194 "Manipulate the query by adding a search regexp with negative selection.
7195 Negative selection means regexp must not match for selection of an entry."
7196 (interactive)
7197 (org-agenda-manipulate-query ?\}))
7198 (defun org-agenda-manipulate-query (char)
7199 (cond
7200 ((memq org-agenda-type '(timeline agenda))
7201 (let ((org-agenda-include-inactive-timestamps t))
7202 (org-agenda-redo))
7203 (message "Display now includes inactive timestamps as well"))
7204 ((eq org-agenda-type 'search)
7205 (org-add-to-string
7206 'org-agenda-query-string
7207 (if org-agenda-last-search-view-search-was-boolean
7208 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7209 (?\{ . " +{}") (?\} . " -{}"))))
7210 " "))
7211 (setq org-agenda-redo-command
7212 (list 'org-search-view
7213 (car (get-text-property (min (1- (point-max)) (point))
7214 'org-last-args))
7215 org-agenda-query-string
7216 (+ (length org-agenda-query-string)
7217 (if (member char '(?\{ ?\})) 0 1))))
7218 (set-register org-agenda-query-register org-agenda-query-string)
7219 (let ((org-agenda-overriding-arguments
7220 (cdr org-agenda-redo-command)))
7221 (org-agenda-redo)))
7222 (t (error "Cannot manipulate query for %s-type agenda buffers"
7223 org-agenda-type))))
7225 (defun org-add-to-string (var string)
7226 (set var (concat (symbol-value var) string)))
7228 (defun org-agenda-goto-date (span)
7229 "Jump to DATE in agenda."
7230 (interactive "P")
7231 (let* ((org-read-date-prefer-future
7232 (eval org-agenda-jump-prefer-future))
7233 (date (org-read-date))
7234 (org-agenda-sticky-orig org-agenda-sticky)
7235 (org-agenda-buffer-tmp-name (buffer-name))
7236 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7237 (0-arg (or current-prefix-arg (car args)))
7238 (2-arg (nth 2 args))
7239 (newcmd (list 'org-agenda-list 0-arg date
7240 (org-agenda-span-to-ndays 2-arg)))
7241 (newargs (cdr newcmd))
7242 (inhibit-read-only t)
7243 org-agenda-sticky)
7244 (if (not (org-agenda-check-type t 'agenda))
7245 (error "Not available in non-agenda blocks")
7246 (add-text-properties (point-min) (point-max)
7247 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7248 (org-agenda-redo)
7249 (setq org-agenda-sticky org-agenda-sticky-orig
7250 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7252 (defun org-agenda-goto-today ()
7253 "Go to today."
7254 (interactive)
7255 (org-agenda-check-type t 'timeline 'agenda)
7256 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7257 (curspan (nth 2 args))
7258 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7259 (cond
7260 (tdpos (goto-char tdpos))
7261 ((eq org-agenda-type 'agenda)
7262 (let* ((sd (org-agenda-compute-starting-span
7263 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7264 (org-agenda-overriding-arguments args))
7265 (setf (nth 1 org-agenda-overriding-arguments) sd)
7266 (org-agenda-redo)
7267 (org-agenda-find-same-or-today-or-agenda)))
7268 (t (error "Cannot find today")))))
7270 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7271 (goto-char
7272 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7273 (text-property-any (point-min) (point-max) 'org-today t)
7274 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7275 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7276 (org-agenda-goto-block-beginning))
7277 (point-min))))
7279 (defun org-agenda-goto-block-beginning ()
7280 "Go the agenda block beginning."
7281 (interactive)
7282 (if (not (derived-mode-p 'org-agenda-mode))
7283 (error "Cannot execute this command outside of org-agenda-mode buffers")
7284 (let (dest)
7285 (save-excursion
7286 (unless (looking-at "\\'")
7287 (forward-char))
7288 (let* ((prop 'org-agenda-structural-header)
7289 (p (previous-single-property-change (point) prop))
7290 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7291 (1- (point))) prop)))
7292 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7293 (if (not dest)
7294 (error "Cannot find the beginning of the blog")
7295 (goto-char dest)
7296 (move-beginning-of-line 1)))))
7298 (defun org-agenda-later (arg)
7299 "Go forward in time by the current span.
7300 With prefix ARG, go forward that many times the current span."
7301 (interactive "p")
7302 (org-agenda-check-type t 'agenda)
7303 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7304 (span (or (nth 2 args) org-agenda-current-span))
7305 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7306 (greg (calendar-gregorian-from-absolute sd))
7307 (cnt (org-get-at-bol 'org-day-cnt))
7308 greg2)
7309 (cond
7310 ((numberp span)
7311 (setq sd (+ (* span arg) sd)))
7312 ((eq span 'day)
7313 (setq sd (+ arg sd)))
7314 ((eq span 'week)
7315 (setq sd (+ (* 7 arg) sd)))
7316 ((eq span 'month)
7317 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7318 sd (calendar-absolute-from-gregorian greg2))
7319 (setcar greg2 (1+ (car greg2))))
7320 ((eq span 'year)
7321 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7322 sd (calendar-absolute-from-gregorian greg2))
7323 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7325 (setq sd (+ (* span arg) sd))))
7326 (let ((org-agenda-overriding-cmd
7327 ;; `cmd' may have been set by `org-agenda-run-series' which
7328 ;; uses `org-agenda-overriding-cmd' to decide whether
7329 ;; overriding is allowed for `cmd'
7330 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7331 (org-agenda-overriding-arguments
7332 (list (car args) sd span)))
7333 (org-agenda-redo)
7334 (org-agenda-find-same-or-today-or-agenda cnt))))
7336 (defun org-agenda-earlier (arg)
7337 "Go backward in time by the current span.
7338 With prefix ARG, go backward that many times the current span."
7339 (interactive "p")
7340 (org-agenda-later (- arg)))
7342 (defun org-agenda-view-mode-dispatch ()
7343 "Call one of the view mode commands."
7344 (interactive)
7345 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7346 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7347 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7348 (let ((a (read-char-exclusive)))
7349 (case a
7350 (?\ (call-interactively 'org-agenda-reset-view))
7351 (?d (call-interactively 'org-agenda-day-view))
7352 (?w (call-interactively 'org-agenda-week-view))
7353 (?m (call-interactively 'org-agenda-month-view))
7354 (?y (call-interactively 'org-agenda-year-view))
7355 (?l (call-interactively 'org-agenda-log-mode))
7356 (?L (org-agenda-log-mode '(4)))
7357 (?c (org-agenda-log-mode 'clockcheck))
7358 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7359 (?a (call-interactively 'org-agenda-archives-mode))
7360 (?A (org-agenda-archives-mode 'files))
7361 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7362 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7363 (?G (call-interactively 'org-agenda-toggle-time-grid))
7364 (?D (call-interactively 'org-agenda-toggle-diary))
7365 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7366 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7367 (org-agenda-check-type t 'timeline 'agenda)
7368 (org-agenda-redo))
7369 (message "Display now includes inactive timestamps as well"))
7370 (?q (message "Abort"))
7371 (otherwise (error "Invalid key" )))))
7373 (defun org-agenda-reset-view ()
7374 "Switch to default view for agenda."
7375 (interactive)
7376 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7377 (defun org-agenda-day-view (&optional day-of-year)
7378 "Switch to daily view for agenda.
7379 With argument DAY-OF-YEAR, switch to that day of the year."
7380 (interactive "P")
7381 (org-agenda-change-time-span 'day day-of-year))
7382 (defun org-agenda-week-view (&optional iso-week)
7383 "Switch to daily view for agenda.
7384 With argument ISO-WEEK, switch to the corresponding ISO week.
7385 If ISO-WEEK has more then 2 digits, only the last two encode the
7386 week. Any digits before this encode a year. So 200712 means
7387 week 12 of year 2007. Years in the range 1938-2037 can also be
7388 written as 2-digit years."
7389 (interactive "P")
7390 (org-agenda-change-time-span 'week iso-week))
7391 (defun org-agenda-month-view (&optional month)
7392 "Switch to monthly view for agenda.
7393 With argument MONTH, switch to that month."
7394 (interactive "P")
7395 (org-agenda-change-time-span 'month month))
7396 (defun org-agenda-year-view (&optional year)
7397 "Switch to yearly view for agenda.
7398 With argument YEAR, switch to that year.
7399 If MONTH has more then 2 digits, only the last two encode the
7400 month. Any digits before this encode a year. So 200712 means
7401 December year 2007. Years in the range 1938-2037 can also be
7402 written as 2-digit years."
7403 (interactive "P")
7404 (when year
7405 (setq year (org-small-year-to-year year)))
7406 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7407 (org-agenda-change-time-span 'year year)
7408 (error "Abort")))
7410 (defun org-agenda-change-time-span (span &optional n)
7411 "Change the agenda view to SPAN.
7412 SPAN may be `day', `week', `month', `year'."
7413 (org-agenda-check-type t 'agenda)
7414 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7415 (curspan (nth 2 args)))
7416 (if (and (not n) (equal curspan span))
7417 (error "Viewing span is already \"%s\"" span))
7418 (let* ((sd (or (org-get-at-bol 'day)
7419 (nth 1 args)
7420 org-starting-day))
7421 (sd (org-agenda-compute-starting-span sd span n))
7422 (org-agenda-overriding-cmd
7423 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7424 (org-agenda-overriding-arguments
7425 (list (car args) sd span)))
7426 (org-agenda-redo)
7427 (org-agenda-find-same-or-today-or-agenda))
7428 (org-agenda-set-mode-name)
7429 (message "Switched to %s view" span)))
7431 (defun org-agenda-compute-starting-span (sd span &optional n)
7432 "Compute starting date for agenda.
7433 SPAN may be `day', `week', `month', `year'. The return value
7434 is a cons cell with the starting date and the number of days,
7435 so that the date SD will be in that range."
7436 (let* ((greg (calendar-gregorian-from-absolute sd))
7437 (dg (nth 1 greg))
7438 (mg (car greg))
7439 (yg (nth 2 greg)))
7440 (cond
7441 ((eq span 'day)
7442 (when n
7443 (setq sd (+ (calendar-absolute-from-gregorian
7444 (list mg 1 yg))
7445 n -1))))
7446 ((eq span 'week)
7447 (let* ((nt (calendar-day-of-week
7448 (calendar-gregorian-from-absolute sd)))
7449 (d (if org-agenda-start-on-weekday
7450 (- nt org-agenda-start-on-weekday)
7453 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7454 (when n
7455 (require 'cal-iso)
7456 (when (> n 99)
7457 (setq y1 (org-small-year-to-year (/ n 100))
7458 n (mod n 100)))
7459 (setq sd
7460 (calendar-absolute-from-iso
7461 (list n 1
7462 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7463 ((eq span 'month)
7464 (let (y1)
7465 (when (and n (> n 99))
7466 (setq y1 (org-small-year-to-year (/ n 100))
7467 n (mod n 100)))
7468 (setq sd (calendar-absolute-from-gregorian
7469 (list (or n mg) 1 (or y1 yg))))))
7470 ((eq span 'year)
7471 (setq sd (calendar-absolute-from-gregorian
7472 (list 1 1 (or n yg))))))
7473 sd))
7475 (defun org-agenda-next-date-line (&optional arg)
7476 "Jump to the next line indicating a date in agenda buffer."
7477 (interactive "p")
7478 (org-agenda-check-type t 'agenda 'timeline)
7479 (beginning-of-line 1)
7480 ;; This does not work if user makes date format that starts with a blank
7481 (if (looking-at "^\\S-") (forward-char 1))
7482 (if (not (re-search-forward "^\\S-" nil t arg))
7483 (progn
7484 (backward-char 1)
7485 (error "No next date after this line in this buffer")))
7486 (goto-char (match-beginning 0)))
7488 (defun org-agenda-previous-date-line (&optional arg)
7489 "Jump to the previous line indicating a date in agenda buffer."
7490 (interactive "p")
7491 (org-agenda-check-type t 'agenda 'timeline)
7492 (beginning-of-line 1)
7493 (if (not (re-search-backward "^\\S-" nil t arg))
7494 (error "No previous date before this line in this buffer")))
7496 ;; Initialize the highlight
7497 (defvar org-hl (make-overlay 1 1))
7498 (overlay-put org-hl 'face 'highlight)
7500 (defun org-highlight (begin end &optional buffer)
7501 "Highlight a region with overlay."
7502 (move-overlay org-hl begin end (or buffer (current-buffer))))
7504 (defun org-unhighlight ()
7505 "Detach overlay INDEX."
7506 (org-detach-overlay org-hl))
7508 (defun org-unhighlight-once ()
7509 "Remove the highlight from its position, and this function from the hook."
7510 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7511 (org-unhighlight))
7513 (defvar org-agenda-pre-follow-window-conf nil)
7514 (defun org-agenda-follow-mode ()
7515 "Toggle follow mode in an agenda buffer."
7516 (interactive)
7517 (unless org-agenda-follow-mode
7518 (setq org-agenda-pre-follow-window-conf
7519 (current-window-configuration)))
7520 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7521 (unless org-agenda-follow-mode
7522 (set-window-configuration org-agenda-pre-follow-window-conf))
7523 (org-agenda-set-mode-name)
7524 (org-agenda-do-context-action)
7525 (message "Follow mode is %s"
7526 (if org-agenda-follow-mode "on" "off")))
7528 (defun org-agenda-entry-text-mode (&optional arg)
7529 "Toggle entry text mode in an agenda buffer."
7530 (interactive "P")
7531 (setq org-agenda-entry-text-mode (or (integerp arg)
7532 (not org-agenda-entry-text-mode)))
7533 (org-agenda-entry-text-hide)
7534 (and org-agenda-entry-text-mode
7535 (let ((org-agenda-entry-text-maxlines
7536 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7537 (org-agenda-entry-text-show)))
7538 (org-agenda-set-mode-name)
7539 (message "Entry text mode is %s. Maximum number of lines is %d"
7540 (if org-agenda-entry-text-mode "on" "off")
7541 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7543 (defun org-agenda-clockreport-mode (&optional with-filter)
7544 "Toggle clocktable mode in an agenda buffer.
7545 With prefix arg WITH-FILTER, make the clocktable respect the current
7546 agenda filter."
7547 (interactive "P")
7548 (org-agenda-check-type t 'agenda)
7549 (if with-filter
7550 (setq org-agenda-clockreport-mode 'with-filter)
7551 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7552 (org-agenda-set-mode-name)
7553 (org-agenda-redo)
7554 (message "Clocktable mode is %s"
7555 (if org-agenda-clockreport-mode "on" "off")))
7557 (defun org-agenda-log-mode (&optional special)
7558 "Toggle log mode in an agenda buffer.
7559 With argument SPECIAL, show all possible log items, not only the ones
7560 configured in `org-agenda-log-mode-items'.
7561 With a double `C-u' prefix arg, show *only* log items, nothing else."
7562 (interactive "P")
7563 (org-agenda-check-type t 'agenda 'timeline)
7564 (setq org-agenda-show-log
7565 (cond
7566 ((equal special '(16)) 'only)
7567 ((eq special 'clockcheck)
7568 (if (eq org-agenda-show-log 'clockcheck)
7569 nil 'clockcheck))
7570 (special '(closed clock state))
7571 (t (not org-agenda-show-log))))
7572 (org-agenda-set-mode-name)
7573 (org-agenda-redo)
7574 (message "Log mode is %s"
7575 (if org-agenda-show-log "on" "off")))
7577 (defun org-agenda-archives-mode (&optional with-files)
7578 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7579 When called with a prefix argument, include all archive files as well."
7580 (interactive "P")
7581 (setq org-agenda-archives-mode
7582 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7583 (org-agenda-set-mode-name)
7584 (org-agenda-redo)
7585 (message
7586 "%s"
7587 (cond
7588 ((eq org-agenda-archives-mode nil)
7589 "No archives are included")
7590 ((eq org-agenda-archives-mode 'trees)
7591 (format "Trees with :%s: tag are included" org-archive-tag))
7592 ((eq org-agenda-archives-mode t)
7593 (format "Trees with :%s: tag and all active archive files are included"
7594 org-archive-tag)))))
7596 (defun org-agenda-toggle-diary ()
7597 "Toggle diary inclusion in an agenda buffer."
7598 (interactive)
7599 (org-agenda-check-type t 'agenda)
7600 (setq org-agenda-include-diary (not org-agenda-include-diary))
7601 (org-agenda-redo)
7602 (org-agenda-set-mode-name)
7603 (message "Diary inclusion turned %s"
7604 (if org-agenda-include-diary "on" "off")))
7606 (defun org-agenda-toggle-deadlines ()
7607 "Toggle inclusion of entries with a deadline in an agenda buffer."
7608 (interactive)
7609 (org-agenda-check-type t 'agenda)
7610 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7611 (org-agenda-redo)
7612 (org-agenda-set-mode-name)
7613 (message "Deadlines inclusion turned %s"
7614 (if org-agenda-include-deadlines "on" "off")))
7616 (defun org-agenda-toggle-time-grid ()
7617 "Toggle time grid in an agenda buffer."
7618 (interactive)
7619 (org-agenda-check-type t 'agenda)
7620 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7621 (org-agenda-redo)
7622 (org-agenda-set-mode-name)
7623 (message "Time-grid turned %s"
7624 (if org-agenda-use-time-grid "on" "off")))
7626 (defun org-agenda-set-mode-name ()
7627 "Set the mode name to indicate all the small mode settings."
7628 (setq mode-name
7629 (list "Org-Agenda"
7630 (if (get 'org-agenda-files 'org-restrict) " []" "")
7632 '(:eval (org-agenda-span-name org-agenda-current-span))
7633 (if org-agenda-follow-mode " Follow" "")
7634 (if org-agenda-entry-text-mode " ETxt" "")
7635 (if org-agenda-include-diary " Diary" "")
7636 (if org-agenda-include-deadlines " Ddl" "")
7637 (if org-agenda-use-time-grid " Grid" "")
7638 (if (and (boundp 'org-habit-show-habits)
7639 org-habit-show-habits) " Habit" "")
7640 (cond
7641 ((consp org-agenda-show-log) " LogAll")
7642 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7643 (org-agenda-show-log " Log")
7644 (t ""))
7645 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7646 :preset-filter))
7647 '(:eval (org-propertize
7648 (concat " <"
7649 (mapconcat
7650 'identity
7651 (append
7652 (get 'org-agenda-category-filter :preset-filter)
7653 org-agenda-category-filter)
7655 ">")
7656 'face 'org-agenda-filter-category
7657 'help-echo "Category used in filtering"))
7659 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7660 :preset-filter))
7661 '(:eval (org-propertize
7662 (concat " {"
7663 (mapconcat
7664 'identity
7665 (append
7666 (get 'org-agenda-tag-filter :preset-filter)
7667 org-agenda-tag-filter)
7669 "}")
7670 'face 'org-agenda-filter-tags
7671 'help-echo "Tags used in filtering"))
7673 (if org-agenda-archives-mode
7674 (if (eq org-agenda-archives-mode t)
7675 " Archives"
7676 (format " :%s:" org-archive-tag))
7678 (if org-agenda-clockreport-mode
7679 (if (eq org-agenda-clockreport-mode 'with-filter)
7680 " Clock{}" " Clock")
7681 "")))
7682 (force-mode-line-update))
7684 (define-obsolete-function-alias
7685 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7687 (defun org-agenda-update-agenda-type ()
7688 "Update the agenda type after each command."
7689 (setq org-agenda-type
7690 (or (get-text-property (point) 'org-agenda-type)
7691 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7693 (defun org-agenda-next-line ()
7694 "Move cursor to the next line, and show if follow mode is active."
7695 (interactive)
7696 (call-interactively 'next-line)
7697 (org-agenda-do-context-action))
7699 (defun org-agenda-previous-line ()
7700 "Move cursor to the previous line, and show if follow-mode is active."
7701 (interactive)
7702 (call-interactively 'previous-line)
7703 (org-agenda-do-context-action))
7705 (defun org-agenda-next-item (n)
7706 "Move cursor to next agenda item."
7707 (interactive "p")
7708 (let ((col (current-column)))
7709 (dotimes (c n)
7710 (when (next-single-property-change (point-at-eol) 'org-marker)
7711 (move-end-of-line 1)
7712 (goto-char (next-single-property-change (point) 'org-marker))))
7713 (org-move-to-column col))
7714 (org-agenda-do-context-action))
7716 (defun org-agenda-previous-item (n)
7717 "Move cursor to next agenda item."
7718 (interactive "p")
7719 (dotimes (c n)
7720 (let ((col (current-column))
7721 (goto (save-excursion
7722 (move-end-of-line 0)
7723 (previous-single-property-change (point) 'org-marker))))
7724 (if goto (goto-char goto))
7725 (org-move-to-column col)))
7726 (org-agenda-do-context-action))
7728 (defun org-agenda-do-context-action ()
7729 "Show outline path and, maybe, follow mode window."
7730 (let ((m (org-get-at-bol 'org-marker)))
7731 (when (and (markerp m) (marker-buffer m))
7732 (and org-agenda-follow-mode
7733 (if org-agenda-follow-indirect
7734 (org-agenda-tree-to-indirect-buffer nil)
7735 (org-agenda-show)))
7736 (and org-agenda-show-outline-path
7737 (org-with-point-at m (org-display-outline-path t))))))
7739 (defun org-agenda-show-tags ()
7740 "Show the tags applicable to the current item."
7741 (interactive)
7742 (let* ((tags (org-get-at-bol 'tags)))
7743 (if tags
7744 (message "Tags are :%s:"
7745 (org-no-properties (mapconcat 'identity tags ":")))
7746 (message "No tags associated with this line"))))
7748 (defun org-agenda-goto (&optional highlight)
7749 "Go to the Org-mode file which contains the item at point."
7750 (interactive)
7751 (let* ((marker (or (org-get-at-bol 'org-marker)
7752 (org-agenda-error)))
7753 (buffer (marker-buffer marker))
7754 (pos (marker-position marker)))
7755 (switch-to-buffer-other-window buffer)
7756 (widen)
7757 (push-mark)
7758 (goto-char pos)
7759 (when (derived-mode-p 'org-mode)
7760 (org-show-context 'agenda)
7761 (save-excursion
7762 (and (outline-next-heading)
7763 (org-flag-heading nil)))) ; show the next heading
7764 (when (outline-invisible-p)
7765 (show-entry)) ; display invisible text
7766 (recenter (/ (window-height) 2))
7767 (run-hooks 'org-agenda-after-show-hook)
7768 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7770 (defvar org-agenda-after-show-hook nil
7771 "Normal hook run after an item has been shown from the agenda.
7772 Point is in the buffer where the item originated.")
7774 (defun org-agenda-kill ()
7775 "Kill the entry or subtree belonging to the current agenda entry."
7776 (interactive)
7777 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7778 (let* ((bufname-orig (buffer-name))
7779 (marker (or (org-get-at-bol 'org-marker)
7780 (org-agenda-error)))
7781 (buffer (marker-buffer marker))
7782 (pos (marker-position marker))
7783 (type (org-get-at-bol 'type))
7784 dbeg dend (n 0) conf)
7785 (org-with-remote-undo buffer
7786 (with-current-buffer buffer
7787 (save-excursion
7788 (goto-char pos)
7789 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7790 (setq dbeg (progn (org-back-to-heading t) (point))
7791 dend (org-end-of-subtree t t))
7792 (setq dbeg (point-at-bol)
7793 dend (min (point-max) (1+ (point-at-eol)))))
7794 (goto-char dbeg)
7795 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7796 (setq conf (or (eq t org-agenda-confirm-kill)
7797 (and (numberp org-agenda-confirm-kill)
7798 (> n org-agenda-confirm-kill))))
7799 (and conf
7800 (not (y-or-n-p
7801 (format "Delete entry with %d lines in buffer \"%s\"? "
7802 n (buffer-name buffer))))
7803 (error "Abort"))
7804 (let ((org-agenda-buffer-name bufname-orig))
7805 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7806 (with-current-buffer buffer (delete-region dbeg dend))
7807 (message "Agenda item and source killed"))))
7809 (defvar org-archive-default-command) ; defined in org-archive.el
7810 (defun org-agenda-archive-default ()
7811 "Archive the entry or subtree belonging to the current agenda entry."
7812 (interactive)
7813 (require 'org-archive)
7814 (org-agenda-archive-with org-archive-default-command))
7816 (defun org-agenda-archive-default-with-confirmation ()
7817 "Archive the entry or subtree belonging to the current agenda entry."
7818 (interactive)
7819 (require 'org-archive)
7820 (org-agenda-archive-with org-archive-default-command 'confirm))
7822 (defun org-agenda-archive ()
7823 "Archive the entry or subtree belonging to the current agenda entry."
7824 (interactive)
7825 (org-agenda-archive-with 'org-archive-subtree))
7827 (defun org-agenda-archive-to-archive-sibling ()
7828 "Move the entry to the archive sibling."
7829 (interactive)
7830 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7832 (defun org-agenda-archive-with (cmd &optional confirm)
7833 "Move the entry to the archive sibling."
7834 (interactive)
7835 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7836 (let* ((bufname-orig (buffer-name))
7837 (marker (or (org-get-at-bol 'org-marker)
7838 (org-agenda-error)))
7839 (buffer (marker-buffer marker))
7840 (pos (marker-position marker)))
7841 (org-with-remote-undo buffer
7842 (with-current-buffer buffer
7843 (if (derived-mode-p 'org-mode)
7844 (if (and confirm
7845 (not (y-or-n-p "Archive this subtree or entry? ")))
7846 (error "Abort")
7847 (save-excursion
7848 (goto-char pos)
7849 (let ((org-agenda-buffer-name bufname-orig))
7850 (org-remove-subtree-entries-from-agenda))
7851 (org-back-to-heading t)
7852 (funcall cmd)))
7853 (error "Archiving works only in Org-mode files"))))))
7855 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7856 "Remove all lines in the agenda that correspond to a given subtree.
7857 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7858 If this information is not given, the function uses the tree at point."
7859 (let ((buf (or buf (current-buffer))) m p)
7860 (save-excursion
7861 (unless (and beg end)
7862 (org-back-to-heading t)
7863 (setq beg (point))
7864 (org-end-of-subtree t)
7865 (setq end (point)))
7866 (set-buffer (get-buffer org-agenda-buffer-name))
7867 (save-excursion
7868 (goto-char (point-max))
7869 (beginning-of-line 1)
7870 (while (not (bobp))
7871 (when (and (setq m (org-get-at-bol 'org-marker))
7872 (equal buf (marker-buffer m))
7873 (setq p (marker-position m))
7874 (>= p beg)
7875 (< p end))
7876 (let ((inhibit-read-only t))
7877 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7878 (beginning-of-line 0))))))
7880 (defun org-agenda-refile (&optional goto rfloc no-update)
7881 "Refile the item at point."
7882 (interactive "P")
7883 (if (equal goto '(16))
7884 (org-refile-goto-last-stored)
7885 (let* ((buffer-orig (buffer-name))
7886 (marker (or (org-get-at-bol 'org-hd-marker)
7887 (org-agenda-error)))
7888 (buffer (marker-buffer marker))
7889 (pos (marker-position marker))
7890 (rfloc (or rfloc
7891 (org-refile-get-location
7892 (if goto "Goto" "Refile to") buffer
7893 org-refile-allow-creating-parent-nodes))))
7894 (with-current-buffer buffer
7895 (save-excursion
7896 (save-restriction
7897 (widen)
7898 (goto-char marker)
7899 (let ((org-agenda-buffer-name buffer-orig))
7900 (org-remove-subtree-entries-from-agenda))
7901 (org-refile goto buffer rfloc)))))
7902 (unless no-update (org-agenda-redo))))
7904 (defun org-agenda-open-link (&optional arg)
7905 "Open the link(s) in the current entry, if any.
7906 This looks for a link in the displayed line in the agenda.
7907 It also looks at the text of the entry itself."
7908 (interactive "P")
7909 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7910 (org-get-at-bol 'org-marker)))
7911 (buffer (and marker (marker-buffer marker)))
7912 (prefix (buffer-substring
7913 (point-at-bol) (point-at-eol)))
7914 (lkall (org-offer-links-in-entry buffer marker arg prefix))
7915 (lk (car lkall))
7916 (lkend (cdr lkall))
7917 trg)
7918 (cond
7919 ((and buffer (stringp lk))
7920 (with-current-buffer buffer
7921 (setq trg (and (string-match org-bracket-link-regexp lk)
7922 (match-string 1 lk)))
7923 (if (or (not trg) (string-match org-any-link-re trg))
7924 (save-excursion
7925 (save-restriction
7926 (widen)
7927 (goto-char marker)
7928 (when (search-forward lk nil lkend)
7929 (goto-char (match-beginning 0))
7930 (org-open-at-point))))
7931 ;; This is an internal link, widen the buffer
7932 (switch-to-buffer-other-window buffer)
7933 (widen)
7934 (goto-char marker)
7935 (when (search-forward lk nil lkend)
7936 (goto-char (match-beginning 0))
7937 (org-open-at-point)))))
7938 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7939 (save-excursion
7940 (beginning-of-line 1)
7941 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7942 (org-open-link-from-string (match-string 1)))
7943 (t (message "No link to open here")))))
7945 (defun org-agenda-copy-local-variable (var)
7946 "Get a variable from a referenced buffer and install it here."
7947 (let ((m (org-get-at-bol 'org-marker)))
7948 (when (and m (buffer-live-p (marker-buffer m)))
7949 (org-set-local var (with-current-buffer (marker-buffer m)
7950 (symbol-value var))))))
7952 (defun org-agenda-switch-to (&optional delete-other-windows)
7953 "Go to the Org-mode file which contains the item at point."
7954 (interactive)
7955 (if (and org-return-follows-link
7956 (not (org-get-at-bol 'org-marker))
7957 (org-in-regexp org-bracket-link-regexp))
7958 (org-open-link-from-string (match-string 0))
7959 (let* ((marker (or (org-get-at-bol 'org-marker)
7960 (org-agenda-error)))
7961 (buffer (marker-buffer marker))
7962 (pos (marker-position marker)))
7963 (org-pop-to-buffer-same-window buffer)
7964 (and delete-other-windows (delete-other-windows))
7965 (widen)
7966 (goto-char pos)
7967 (when (derived-mode-p 'org-mode)
7968 (org-show-context 'agenda)
7969 (save-excursion
7970 (and (outline-next-heading)
7971 (org-flag-heading nil))) ; show the next heading
7972 (when (outline-invisible-p)
7973 (show-entry)) ; display invisible text
7974 (run-hooks 'org-agenda-after-show-hook)))))
7976 (defun org-agenda-goto-mouse (ev)
7977 "Go to the Org-mode file which contains the item at the mouse click."
7978 (interactive "e")
7979 (mouse-set-point ev)
7980 (org-agenda-goto))
7982 (defun org-agenda-show (&optional full-entry)
7983 "Display the Org-mode file which contains the item at point.
7984 With prefix argument FULL-ENTRY, make the entire entry visible
7985 if it was hidden in the outline."
7986 (interactive "P")
7987 (let ((win (selected-window)))
7988 (if full-entry
7989 (let ((org-show-entry-below t))
7990 (org-agenda-goto t))
7991 (org-agenda-goto t))
7992 (select-window win)))
7994 (defvar org-agenda-show-window nil)
7995 (defun org-agenda-show-and-scroll-up (&optional arg)
7996 "Display the Org-mode file which contains the item at point.
7997 When called repeatedly, scroll the window that is displaying the buffer.
7998 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7999 `show-subtree' to display the item, so that drawers and logbooks stay
8000 folded."
8001 (interactive "P")
8002 (let ((win (selected-window)))
8003 (if (and (window-live-p org-agenda-show-window)
8004 (eq this-command last-command))
8005 (progn
8006 (select-window org-agenda-show-window)
8007 (ignore-errors (scroll-up)))
8008 (org-agenda-goto t)
8009 (if arg (org-show-entry) (show-subtree))
8010 (setq org-agenda-show-window (selected-window)))
8011 (select-window win)))
8013 (defun org-agenda-show-scroll-down ()
8014 "Scroll down the window showing the agenda."
8015 (interactive)
8016 (let ((win (selected-window)))
8017 (when (window-live-p org-agenda-show-window)
8018 (select-window org-agenda-show-window)
8019 (ignore-errors (scroll-down))
8020 (select-window win))))
8022 (defun org-agenda-show-1 (&optional more)
8023 "Display the Org-mode file which contains the item at point.
8024 The prefix arg selects the amount of information to display:
8026 0 hide the subtree
8027 1 just show the entry according to defaults.
8028 2 show the children view
8029 3 show the subtree view
8030 4 show the entire subtree and any LOGBOOK drawers
8031 5 show the entire subtree and any drawers
8032 With prefix argument FULL-ENTRY, make the entire entry visible
8033 if it was hidden in the outline."
8034 (interactive "p")
8035 (let ((win (selected-window)))
8036 (org-agenda-goto t)
8037 (org-recenter-heading 1)
8038 (cond
8039 ((= more 0)
8040 (hide-subtree)
8041 (save-excursion
8042 (org-back-to-heading)
8043 (run-hook-with-args 'org-cycle-hook 'folded))
8044 (message "Remote: FOLDED"))
8045 ((and (org-called-interactively-p 'any) (= more 1))
8046 (message "Remote: show with default settings"))
8047 ((= more 2)
8048 (show-entry)
8049 (show-children)
8050 (save-excursion
8051 (org-back-to-heading)
8052 (run-hook-with-args 'org-cycle-hook 'children))
8053 (message "Remote: CHILDREN"))
8054 ((= more 3)
8055 (show-subtree)
8056 (save-excursion
8057 (org-back-to-heading)
8058 (run-hook-with-args 'org-cycle-hook 'subtree))
8059 (message "Remote: SUBTREE"))
8060 ((= more 4)
8061 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8062 (org-drawer-regexp
8063 (concat "^[ \t]*:\\("
8064 (mapconcat 'regexp-quote org-drawers "\\|")
8065 "\\):[ \t]*$")))
8066 (show-subtree)
8067 (save-excursion
8068 (org-back-to-heading)
8069 (org-cycle-hide-drawers 'subtree)))
8070 (message "Remote: SUBTREE AND LOGBOOK"))
8071 ((> more 4)
8072 (show-subtree)
8073 (message "Remote: SUBTREE AND ALL DRAWERS")))
8074 (select-window win)))
8076 (defun org-recenter-heading (n)
8077 (save-excursion
8078 (org-back-to-heading)
8079 (recenter n)))
8081 (defvar org-agenda-cycle-counter nil)
8082 (defun org-agenda-cycle-show (&optional n)
8083 "Show the current entry in another window, with default settings.
8084 Default settings are taken from `org-show-hierarchy-above' and siblings.
8085 When use repeatedly in immediate succession, the remote entry will cycle
8086 through visibility
8088 children -> subtree -> folded
8090 When called with a numeric prefix arg, that arg will be passed through to
8091 `org-agenda-show-1'. For the interpretation of that argument, see the
8092 docstring of `org-agenda-show-1'."
8093 (interactive "P")
8094 (if (integerp n)
8095 (setq org-agenda-cycle-counter n)
8096 (if (not (eq last-command this-command))
8097 (setq org-agenda-cycle-counter 1)
8098 (if (equal org-agenda-cycle-counter 0)
8099 (setq org-agenda-cycle-counter 2)
8100 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8101 (if (> org-agenda-cycle-counter 3)
8102 (setq org-agenda-cycle-counter 0)))))
8103 (org-agenda-show-1 org-agenda-cycle-counter))
8105 (defun org-agenda-recenter (arg)
8106 "Display the Org-mode file which contains the item at point and recenter."
8107 (interactive "P")
8108 (let ((win (selected-window)))
8109 (org-agenda-goto t)
8110 (recenter arg)
8111 (select-window win)))
8113 (defun org-agenda-show-mouse (ev)
8114 "Display the Org-mode file which contains the item at the mouse click."
8115 (interactive "e")
8116 (mouse-set-point ev)
8117 (org-agenda-show))
8119 (defun org-agenda-check-no-diary ()
8120 "Check if the entry is a diary link and abort if yes."
8121 (if (org-get-at-bol 'org-agenda-diary-link)
8122 (org-agenda-error)))
8124 (defun org-agenda-error ()
8125 (error "Command not allowed in this line"))
8127 (defun org-agenda-tree-to-indirect-buffer (arg)
8128 "Show the subtree corresponding to the current entry in an indirect buffer.
8129 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8131 With a numerical prefix ARG, go up to this level and then take that tree.
8132 With a negative numeric ARG, go up by this number of levels.
8133 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8134 use the dedicated frame)."
8135 (interactive "P")
8136 (if current-prefix-arg
8137 (org-agenda-do-tree-to-indirect-buffer arg)
8138 (let ((agenda-buffer (buffer-name))
8139 (agenda-window (selected-window))
8140 (indirect-window
8141 (and org-last-indirect-buffer
8142 (get-buffer-window org-last-indirect-buffer))))
8143 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8144 (unless (or (eq org-indirect-buffer-display 'new-frame)
8145 (eq org-indirect-buffer-display 'dedicated-frame))
8146 (unwind-protect
8147 (unless (and indirect-window (window-live-p indirect-window))
8148 (setq indirect-window (split-window agenda-window)))
8149 (and indirect-window (select-window indirect-window))
8150 (switch-to-buffer org-last-indirect-buffer :norecord)
8151 (fit-window-to-buffer indirect-window)))
8152 (select-window (get-buffer-window agenda-buffer)))))
8154 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8155 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8156 (org-agenda-check-no-diary)
8157 (let* ((marker (or (org-get-at-bol 'org-marker)
8158 (org-agenda-error)))
8159 (buffer (marker-buffer marker))
8160 (pos (marker-position marker)))
8161 (with-current-buffer buffer
8162 (save-excursion
8163 (goto-char pos)
8164 (funcall 'org-tree-to-indirect-buffer arg)))))
8166 (defvar org-last-heading-marker (make-marker)
8167 "Marker pointing to the headline that last changed its TODO state
8168 by a remote command from the agenda.")
8170 (defun org-agenda-todo-nextset ()
8171 "Switch TODO entry to next sequence."
8172 (interactive)
8173 (org-agenda-todo 'nextset))
8175 (defun org-agenda-todo-previousset ()
8176 "Switch TODO entry to previous sequence."
8177 (interactive)
8178 (org-agenda-todo 'previousset))
8180 (defun org-agenda-todo (&optional arg)
8181 "Cycle TODO state of line at point, also in Org-mode file.
8182 This changes the line at point, all other lines in the agenda referring to
8183 the same tree node, and the headline of the tree node in the Org-mode file."
8184 (interactive "P")
8185 (org-agenda-check-no-diary)
8186 (let* ((col (current-column))
8187 (marker (or (org-get-at-bol 'org-marker)
8188 (org-agenda-error)))
8189 (buffer (marker-buffer marker))
8190 (pos (marker-position marker))
8191 (hdmarker (org-get-at-bol 'org-hd-marker))
8192 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8193 (inhibit-read-only t)
8194 org-agenda-headline-snapshot-before-repeat newhead just-one)
8195 (org-with-remote-undo buffer
8196 (with-current-buffer buffer
8197 (widen)
8198 (goto-char pos)
8199 (org-show-context 'agenda)
8200 (save-excursion
8201 (and (outline-next-heading)
8202 (org-flag-heading nil))) ; show the next heading
8203 (let ((current-prefix-arg arg))
8204 (call-interactively 'org-todo))
8205 (and (bolp) (forward-char 1))
8206 (setq newhead (org-get-heading))
8207 (when (and (org-bound-and-true-p
8208 org-agenda-headline-snapshot-before-repeat)
8209 (not (equal org-agenda-headline-snapshot-before-repeat
8210 newhead))
8211 todayp)
8212 (setq newhead org-agenda-headline-snapshot-before-repeat
8213 just-one t))
8214 (save-excursion
8215 (org-back-to-heading)
8216 (move-marker org-last-heading-marker (point))))
8217 (beginning-of-line 1)
8218 (save-excursion
8219 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8220 (org-move-to-column col))))
8222 (defun org-agenda-add-note (&optional arg)
8223 "Add a time-stamped note to the entry at point."
8224 (interactive "P")
8225 (org-agenda-check-no-diary)
8226 (let* ((marker (or (org-get-at-bol 'org-marker)
8227 (org-agenda-error)))
8228 (buffer (marker-buffer marker))
8229 (pos (marker-position marker))
8230 (hdmarker (org-get-at-bol 'org-hd-marker))
8231 (inhibit-read-only t))
8232 (with-current-buffer buffer
8233 (widen)
8234 (goto-char pos)
8235 (org-show-context 'agenda)
8236 (save-excursion
8237 (and (outline-next-heading)
8238 (org-flag-heading nil))) ; show the next heading
8239 (org-add-note))))
8241 (defun org-agenda-change-all-lines (newhead hdmarker
8242 &optional fixface just-this)
8243 "Change all lines in the agenda buffer which match HDMARKER.
8244 The new content of the line will be NEWHEAD (as modified by
8245 `org-agenda-format-item'). HDMARKER is checked with
8246 `equal' against all `org-hd-marker' text properties in the file.
8247 If FIXFACE is non-nil, the face of each item is modified according to
8248 the new TODO state.
8249 If JUST-THIS is non-nil, change just the current line, not all.
8250 If FORCE-TAGS is non nil, the car of it returns the new tags."
8251 (let* ((inhibit-read-only t)
8252 (line (org-current-line))
8253 (org-agenda-buffer (current-buffer))
8254 (thetags (with-current-buffer (marker-buffer hdmarker)
8255 (save-excursion (save-restriction (widen)
8256 (goto-char hdmarker)
8257 (org-get-tags-at)))))
8258 props m pl undone-face done-face finish new dotime cat tags)
8259 (save-excursion
8260 (goto-char (point-max))
8261 (beginning-of-line 1)
8262 (while (not finish)
8263 (setq finish (bobp))
8264 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8265 (or (not just-this) (= (org-current-line) line))
8266 (equal m hdmarker))
8267 (setq props (text-properties-at (point))
8268 dotime (org-get-at-bol 'dotime)
8269 cat (org-get-at-bol 'org-category)
8270 tags thetags
8272 (let ((org-prefix-format-compiled
8273 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8274 org-prefix-format-compiled))
8275 (extra (org-get-at-bol 'extra)))
8276 (with-current-buffer (marker-buffer hdmarker)
8277 (save-excursion
8278 (save-restriction
8279 (widen)
8280 (org-agenda-format-item extra newhead cat tags dotime)))))
8281 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8282 undone-face (org-get-at-bol 'undone-face)
8283 done-face (org-get-at-bol 'done-face))
8284 (beginning-of-line 1)
8285 (cond
8286 ((equal new "")
8287 (and (looking-at ".*\n?") (replace-match "")))
8288 ((looking-at ".*")
8289 (replace-match new t t)
8290 (beginning-of-line 1)
8291 (add-text-properties (point-at-bol) (point-at-eol) props)
8292 (when fixface
8293 (add-text-properties
8294 (point-at-bol) (point-at-eol)
8295 (list 'face
8296 (if org-last-todo-state-is-todo
8297 undone-face done-face))))
8298 (org-agenda-highlight-todo 'line)
8299 (beginning-of-line 1))
8300 (t (error "Line update did not work")))
8301 (save-restriction
8302 (narrow-to-region (point-at-bol) (point-at-eol))
8303 (org-agenda-finalize)))
8304 (beginning-of-line 0)))))
8306 (defun org-agenda-align-tags (&optional line)
8307 "Align all tags in agenda items to `org-agenda-tags-column'."
8308 (let ((inhibit-read-only t) l c)
8309 (save-excursion
8310 (goto-char (if line (point-at-bol) (point-min)))
8311 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8312 (if line (point-at-eol) nil) t)
8313 (add-text-properties
8314 (match-beginning 2) (match-end 2)
8315 (list 'face (delq nil (let ((prop (get-text-property
8316 (match-beginning 2) 'face)))
8317 (or (listp prop) (setq prop (list prop)))
8318 (if (memq 'org-tag prop)
8319 prop
8320 (cons 'org-tag prop))))))
8321 (setq l (- (match-end 2) (match-beginning 2))
8322 c (if (< org-agenda-tags-column 0)
8323 (- (abs org-agenda-tags-column) l)
8324 org-agenda-tags-column))
8325 (delete-region (match-beginning 1) (match-end 1))
8326 (goto-char (match-beginning 1))
8327 (insert (org-add-props
8328 (make-string (max 1 (- c (current-column))) ?\ )
8329 (plist-put (copy-sequence (text-properties-at (point)))
8330 'face nil))))
8331 (goto-char (point-min))
8332 (org-font-lock-add-tag-faces (point-max)))))
8334 (defun org-agenda-priority-up ()
8335 "Increase the priority of line at point, also in Org-mode file."
8336 (interactive)
8337 (org-agenda-priority 'up))
8339 (defun org-agenda-priority-down ()
8340 "Decrease the priority of line at point, also in Org-mode file."
8341 (interactive)
8342 (org-agenda-priority 'down))
8344 (defun org-agenda-priority (&optional force-direction)
8345 "Set the priority of line at point, also in Org-mode file.
8346 This changes the line at point, all other lines in the agenda referring to
8347 the same tree node, and the headline of the tree node in the Org-mode file.
8348 Called with a universal prefix arg, show the priority instead of setting it."
8349 (interactive "P")
8350 (if (equal force-direction '(4))
8351 (org-show-priority)
8352 (unless org-enable-priority-commands
8353 (error "Priority commands are disabled"))
8354 (org-agenda-check-no-diary)
8355 (let* ((marker (or (org-get-at-bol 'org-marker)
8356 (org-agenda-error)))
8357 (hdmarker (org-get-at-bol 'org-hd-marker))
8358 (buffer (marker-buffer hdmarker))
8359 (pos (marker-position hdmarker))
8360 (inhibit-read-only t)
8361 newhead)
8362 (org-with-remote-undo buffer
8363 (with-current-buffer buffer
8364 (widen)
8365 (goto-char pos)
8366 (org-show-context 'agenda)
8367 (save-excursion
8368 (and (outline-next-heading)
8369 (org-flag-heading nil))) ; show the next heading
8370 (funcall 'org-priority force-direction)
8371 (end-of-line 1)
8372 (setq newhead (org-get-heading)))
8373 (org-agenda-change-all-lines newhead hdmarker)
8374 (beginning-of-line 1)))))
8376 ;; FIXME: should fix the tags property of the agenda line.
8377 (defun org-agenda-set-tags (&optional tag onoff)
8378 "Set tags for the current headline."
8379 (interactive)
8380 (org-agenda-check-no-diary)
8381 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8382 (call-interactively 'org-change-tag-in-region)
8383 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8384 (org-agenda-error)))
8385 (buffer (marker-buffer hdmarker))
8386 (pos (marker-position hdmarker))
8387 (inhibit-read-only t)
8388 newhead)
8389 (org-with-remote-undo buffer
8390 (with-current-buffer buffer
8391 (widen)
8392 (goto-char pos)
8393 (save-excursion
8394 (org-show-context 'agenda))
8395 (save-excursion
8396 (and (outline-next-heading)
8397 (org-flag-heading nil))) ; show the next heading
8398 (goto-char pos)
8399 (if tag
8400 (org-toggle-tag tag onoff)
8401 (call-interactively 'org-set-tags))
8402 (end-of-line 1)
8403 (setq newhead (org-get-heading)))
8404 (org-agenda-change-all-lines newhead hdmarker)
8405 (beginning-of-line 1)))))
8407 (defun org-agenda-set-property ()
8408 "Set a property for the current headline."
8409 (interactive)
8410 (org-agenda-check-no-diary)
8411 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8412 (org-agenda-error)))
8413 (buffer (marker-buffer hdmarker))
8414 (pos (marker-position hdmarker))
8415 (inhibit-read-only t)
8416 newhead)
8417 (org-with-remote-undo buffer
8418 (with-current-buffer buffer
8419 (widen)
8420 (goto-char pos)
8421 (save-excursion
8422 (org-show-context 'agenda))
8423 (save-excursion
8424 (and (outline-next-heading)
8425 (org-flag-heading nil))) ; show the next heading
8426 (goto-char pos)
8427 (call-interactively 'org-set-property)))))
8429 (defun org-agenda-set-effort ()
8430 "Set the effort property for the current headline."
8431 (interactive)
8432 (org-agenda-check-no-diary)
8433 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8434 (org-agenda-error)))
8435 (buffer (marker-buffer hdmarker))
8436 (pos (marker-position hdmarker))
8437 (inhibit-read-only t)
8438 newhead)
8439 (org-with-remote-undo buffer
8440 (with-current-buffer buffer
8441 (widen)
8442 (goto-char pos)
8443 (save-excursion
8444 (org-show-context 'agenda))
8445 (save-excursion
8446 (and (outline-next-heading)
8447 (org-flag-heading nil))) ; show the next heading
8448 (goto-char pos)
8449 (call-interactively 'org-set-effort)
8450 (end-of-line 1)
8451 (setq newhead (org-get-heading)))
8452 (org-agenda-change-all-lines newhead hdmarker))))
8454 (defun org-agenda-toggle-archive-tag ()
8455 "Toggle the archive tag for the current entry."
8456 (interactive)
8457 (org-agenda-check-no-diary)
8458 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8459 (org-agenda-error)))
8460 (buffer (marker-buffer hdmarker))
8461 (pos (marker-position hdmarker))
8462 (inhibit-read-only t)
8463 newhead)
8464 (org-with-remote-undo buffer
8465 (with-current-buffer buffer
8466 (widen)
8467 (goto-char pos)
8468 (org-show-context 'agenda)
8469 (save-excursion
8470 (and (outline-next-heading)
8471 (org-flag-heading nil))) ; show the next heading
8472 (call-interactively 'org-toggle-archive-tag)
8473 (end-of-line 1)
8474 (setq newhead (org-get-heading)))
8475 (org-agenda-change-all-lines newhead hdmarker)
8476 (beginning-of-line 1))))
8478 (defun org-agenda-do-date-later (arg)
8479 (interactive "P")
8480 (cond
8481 ((or (equal arg '(16))
8482 (memq last-command
8483 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8484 (setq this-command 'org-agenda-date-later-minutes)
8485 (org-agenda-date-later-minutes 1))
8486 ((or (equal arg '(4))
8487 (memq last-command
8488 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8489 (setq this-command 'org-agenda-date-later-hours)
8490 (org-agenda-date-later-hours 1))
8492 (org-agenda-date-later (prefix-numeric-value arg)))))
8494 (defun org-agenda-do-date-earlier (arg)
8495 (interactive "P")
8496 (cond
8497 ((or (equal arg '(16))
8498 (memq last-command
8499 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8500 (setq this-command 'org-agenda-date-earlier-minutes)
8501 (org-agenda-date-earlier-minutes 1))
8502 ((or (equal arg '(4))
8503 (memq last-command
8504 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8505 (setq this-command 'org-agenda-date-earlier-hours)
8506 (org-agenda-date-earlier-hours 1))
8508 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8510 (defun org-agenda-date-later (arg &optional what)
8511 "Change the date of this item to ARG day(s) later."
8512 (interactive "p")
8513 (org-agenda-check-type t 'agenda 'timeline)
8514 (org-agenda-check-no-diary)
8515 (let* ((marker (or (org-get-at-bol 'org-marker)
8516 (org-agenda-error)))
8517 (buffer (marker-buffer marker))
8518 (pos (marker-position marker))
8519 cdate today)
8520 (org-with-remote-undo buffer
8521 (with-current-buffer buffer
8522 (widen)
8523 (goto-char pos)
8524 (if (not (org-at-timestamp-p))
8525 (error "Cannot find time stamp"))
8526 (when (and org-agenda-move-date-from-past-immediately-to-today
8527 (equal arg 1)
8528 (or (not what) (eq what 'day))
8529 (not (save-match-data (org-at-date-range-p))))
8530 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8531 cdate (calendar-absolute-from-gregorian
8532 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8533 today (org-today))
8534 (if (> today cdate)
8535 ;; immediately shift to today
8536 (setq arg (- today cdate))))
8537 (org-timestamp-change arg (or what 'day))
8538 (when (and (org-at-date-range-p)
8539 (re-search-backward org-tr-regexp-both (point-at-bol)))
8540 (let ((end org-last-changed-timestamp))
8541 (org-timestamp-change arg (or what 'day))
8542 (setq org-last-changed-timestamp
8543 (concat org-last-changed-timestamp "--" end)))))
8544 (org-agenda-show-new-time marker org-last-changed-timestamp))
8545 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8547 (defun org-agenda-date-earlier (arg &optional what)
8548 "Change the date of this item to ARG day(s) earlier."
8549 (interactive "p")
8550 (org-agenda-date-later (- arg) what))
8552 (defun org-agenda-date-later-minutes (arg)
8553 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8554 (interactive "p")
8555 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8556 (org-agenda-date-later arg 'minute))
8558 (defun org-agenda-date-earlier-minutes (arg)
8559 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8560 (interactive "p")
8561 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8562 (org-agenda-date-earlier arg 'minute))
8564 (defun org-agenda-date-later-hours (arg)
8565 "Change the time of this item, in hour steps."
8566 (interactive "p")
8567 (org-agenda-date-later arg 'hour))
8569 (defun org-agenda-date-earlier-hours (arg)
8570 "Change the time of this item, in hour steps."
8571 (interactive "p")
8572 (org-agenda-date-earlier arg 'hour))
8574 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8575 "Show new date stamp via text properties."
8576 ;; We use text properties to make this undoable
8577 (let ((inhibit-read-only t)
8578 (buffer-invisibility-spec))
8579 (setq stamp (concat " " prefix " => " stamp))
8580 (save-excursion
8581 (goto-char (point-max))
8582 (while (not (bobp))
8583 (when (equal marker (org-get-at-bol 'org-marker))
8584 (org-move-to-column (- (window-width) (length stamp)) t)
8585 (org-agenda-fix-tags-filter-overlays-at (point))
8586 (if (featurep 'xemacs)
8587 ;; Use `duplicable' property to trigger undo recording
8588 (let ((ex (make-extent nil nil))
8589 (gl (make-glyph stamp)))
8590 (set-glyph-face gl 'secondary-selection)
8591 (set-extent-properties
8592 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8593 (insert-extent ex (1- (point)) (point-at-eol)))
8594 (add-text-properties
8595 (1- (point)) (point-at-eol)
8596 (list 'display (org-add-props stamp nil
8597 'face 'secondary-selection))))
8598 (beginning-of-line 1))
8599 (beginning-of-line 0)))))
8601 (defun org-agenda-date-prompt (arg)
8602 "Change the date of this item. Date is prompted for, with default today.
8603 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8604 be used to request time specification in the time stamp."
8605 (interactive "P")
8606 (org-agenda-check-type t 'agenda 'timeline)
8607 (org-agenda-check-no-diary)
8608 (let* ((marker (or (org-get-at-bol 'org-marker)
8609 (org-agenda-error)))
8610 (buffer (marker-buffer marker))
8611 (pos (marker-position marker)))
8612 (org-with-remote-undo buffer
8613 (with-current-buffer buffer
8614 (widen)
8615 (goto-char pos)
8616 (if (not (org-at-timestamp-p t))
8617 (error "Cannot find time stamp"))
8618 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8619 (org-agenda-show-new-time marker org-last-changed-timestamp))
8620 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8622 (defun org-agenda-schedule (arg &optional time)
8623 "Schedule the item at point.
8624 ARG is passed through to `org-schedule'."
8625 (interactive "P")
8626 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8627 (org-agenda-check-no-diary)
8628 (let* ((marker (or (org-get-at-bol 'org-marker)
8629 (org-agenda-error)))
8630 (type (marker-insertion-type marker))
8631 (buffer (marker-buffer marker))
8632 (pos (marker-position marker))
8633 (org-insert-labeled-timestamps-at-point nil)
8635 (set-marker-insertion-type marker t)
8636 (org-with-remote-undo buffer
8637 (with-current-buffer buffer
8638 (widen)
8639 (goto-char pos)
8640 (setq ts (org-schedule arg time)))
8641 (org-agenda-show-new-time marker ts "S"))
8642 (message "%s" ts)))
8644 (defun org-agenda-deadline (arg &optional time)
8645 "Schedule the item at point.
8646 ARG is passed through to `org-deadline'."
8647 (interactive "P")
8648 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8649 (org-agenda-check-no-diary)
8650 (let* ((marker (or (org-get-at-bol 'org-marker)
8651 (org-agenda-error)))
8652 (buffer (marker-buffer marker))
8653 (pos (marker-position marker))
8654 (org-insert-labeled-timestamps-at-point nil)
8656 (org-with-remote-undo buffer
8657 (with-current-buffer buffer
8658 (widen)
8659 (goto-char pos)
8660 (setq ts (org-deadline arg time)))
8661 (org-agenda-show-new-time marker ts "D"))
8662 (message "%s" ts)))
8664 (defun org-agenda-clock-in (&optional arg)
8665 "Start the clock on the currently selected item."
8666 (interactive "P")
8667 (org-agenda-check-no-diary)
8668 (if (equal arg '(4))
8669 (org-clock-in arg)
8670 (let* ((marker (or (org-get-at-bol 'org-marker)
8671 (org-agenda-error)))
8672 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8673 marker))
8674 (pos (marker-position marker))
8675 newhead)
8676 (org-with-remote-undo (marker-buffer marker)
8677 (with-current-buffer (marker-buffer marker)
8678 (widen)
8679 (goto-char pos)
8680 (org-show-context 'agenda)
8681 (org-show-entry)
8682 (org-cycle-hide-drawers 'children)
8683 (org-clock-in arg)
8684 (setq newhead (org-get-heading)))
8685 (org-agenda-change-all-lines newhead hdmarker)))))
8687 (defun org-agenda-clock-out ()
8688 "Stop the currently running clock."
8689 (interactive)
8690 (unless (marker-buffer org-clock-marker)
8691 (error "No running clock"))
8692 (let ((marker (make-marker)) newhead)
8693 (org-with-remote-undo (marker-buffer org-clock-marker)
8694 (with-current-buffer (marker-buffer org-clock-marker)
8695 (save-excursion
8696 (save-restriction
8697 (widen)
8698 (goto-char org-clock-marker)
8699 (org-back-to-heading t)
8700 (move-marker marker (point))
8701 (org-clock-out)
8702 (setq newhead (org-get-heading))))))
8703 (org-agenda-change-all-lines newhead marker)
8704 (move-marker marker nil)))
8706 (defun org-agenda-clock-cancel (&optional arg)
8707 "Cancel the currently running clock."
8708 (interactive "P")
8709 (unless (marker-buffer org-clock-marker)
8710 (error "No running clock"))
8711 (org-with-remote-undo (marker-buffer org-clock-marker)
8712 (org-clock-cancel)))
8714 (defun org-agenda-clock-goto ()
8715 "Jump to the currently clocked in task within the agenda.
8716 If the currently clocked in task is not listed in the agenda
8717 buffer, display it in another window."
8718 (interactive)
8719 (let (pos)
8720 (mapc (lambda (o)
8721 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8722 (setq pos (overlay-start o))))
8723 (overlays-in (point-min) (point-max)))
8724 (cond (pos (goto-char pos))
8725 ;; If the currently clocked entry is not in the agenda
8726 ;; buffer, we visit it in another window:
8727 (org-clock-current-task
8728 (org-switch-to-buffer-other-window (org-clock-goto)))
8729 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8731 (defun org-agenda-diary-entry-in-org-file ()
8732 "Make a diary entry in the file `org-agenda-diary-file'."
8733 (let (d1 d2 char (text "") dp1 dp2)
8734 (if (equal (buffer-name) "*Calendar*")
8735 (setq d1 (calendar-cursor-to-date t)
8736 d2 (car calendar-mark-ring))
8737 (setq dp1 (get-text-property (point-at-bol) 'day))
8738 (unless dp1 (error "No date defined in current line"))
8739 (setq d1 (calendar-gregorian-from-absolute dp1)
8740 d2 (and (ignore-errors (mark))
8741 (save-excursion
8742 (goto-char (mark))
8743 (setq dp2 (get-text-property (point-at-bol) 'day)))
8744 (calendar-gregorian-from-absolute dp2))))
8745 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8746 (setq char (read-char-exclusive))
8747 (cond
8748 ((equal char ?d)
8749 (setq text (read-string "Day entry: "))
8750 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8751 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8752 ((equal char ?a)
8753 (setq d1 (list (car d1) (nth 1 d1)
8754 (read-number (format "Reference year [%d]: " (nth 2 d1))
8755 (nth 2 d1))))
8756 (setq text (read-string "Anniversary (use %d to show years): "))
8757 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8758 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8759 ((equal char ?b)
8760 (setq text (read-string "Block entry: "))
8761 (unless (and d1 d2 (not (equal d1 d2)))
8762 (error "No block of days selected"))
8763 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8764 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8765 ((equal char ?j)
8766 (org-switch-to-buffer-other-window
8767 (find-file-noselect org-agenda-diary-file))
8768 (require 'org-datetree)
8769 (org-datetree-find-date-create d1)
8770 (org-reveal t))
8771 (t (error "Invalid selection character `%c'" char)))))
8773 (defcustom org-agenda-insert-diary-strategy 'date-tree
8774 "Where in `org-agenda-diary-file' should new entries be added?
8775 Valid values:
8777 date-tree in the date tree, as child of the date
8778 top-level as top-level entries at the end of the file."
8779 :group 'org-agenda
8780 :type '(choice
8781 (const :tag "in a date tree" date-tree)
8782 (const :tag "as top level at end of file" top-level)))
8784 (defcustom org-agenda-insert-diary-extract-time nil
8785 "Non-nil means extract any time specification from the diary entry."
8786 :group 'org-agenda
8787 :version "24.1"
8788 :type 'boolean)
8790 (defcustom org-agenda-bulk-mark-char ">"
8791 "A single-character string to be used as the bulk mark."
8792 :group 'org-agenda
8793 :version "24.1"
8794 :type 'string)
8796 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8797 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8798 If TEXT is not empty, it will become the headline of the new entry, and
8799 the resulting entry will not be shown. When TEXT is empty, switch to
8800 `org-agenda-diary-file' and let the user finish the entry there."
8801 (let ((cw (current-window-configuration)))
8802 (org-switch-to-buffer-other-window
8803 (find-file-noselect org-agenda-diary-file))
8804 (widen)
8805 (goto-char (point-min))
8806 (cond
8807 ((eq type 'anniversary)
8808 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8809 (progn
8810 (or (org-at-heading-p t)
8811 (progn
8812 (outline-next-heading)
8813 (insert "* Anniversaries\n\n")
8814 (beginning-of-line -1)))))
8815 (outline-next-heading)
8816 (org-back-over-empty-lines)
8817 (backward-char 1)
8818 (insert "\n")
8819 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8820 (nth 2 d1) (car d1) (nth 1 d1) text)))
8821 ((eq type 'day)
8822 (let ((org-prefix-has-time t)
8823 (org-agenda-time-leading-zero t)
8824 fmt time time2)
8825 (if org-agenda-insert-diary-extract-time
8826 ;; Use org-agenda-format-item to parse text for a time-range and
8827 ;; remove it. FIXME: This is a hack, we should refactor
8828 ;; that function to make time extraction available separately
8829 (setq fmt (org-agenda-format-item nil text nil nil t)
8830 time (get-text-property 0 'time fmt)
8831 time2 (if (> (length time) 0)
8832 ;; split-string removes trailing ...... if
8833 ;; no end time given. First space
8834 ;; separates time from date.
8835 (concat " " (car (split-string time "\\.")))
8836 nil)
8837 text (get-text-property 0 'txt fmt)))
8838 (if (eq org-agenda-insert-diary-strategy 'top-level)
8839 (org-agenda-insert-diary-as-top-level text)
8840 (require 'org-datetree)
8841 (org-datetree-find-date-create d1)
8842 (org-agenda-insert-diary-make-new-entry text))
8843 (org-insert-time-stamp (org-time-from-absolute
8844 (calendar-absolute-from-gregorian d1))
8845 nil nil nil nil time2))
8846 (end-of-line 0))
8847 ((eq type 'block)
8848 (if (> (calendar-absolute-from-gregorian d1)
8849 (calendar-absolute-from-gregorian d2))
8850 (setq d1 (prog1 d2 (setq d2 d1))))
8851 (if (eq org-agenda-insert-diary-strategy 'top-level)
8852 (org-agenda-insert-diary-as-top-level text)
8853 (require 'org-datetree)
8854 (org-datetree-find-date-create d1)
8855 (org-agenda-insert-diary-make-new-entry text))
8856 (org-insert-time-stamp (org-time-from-absolute
8857 (calendar-absolute-from-gregorian d1)))
8858 (insert "--")
8859 (org-insert-time-stamp (org-time-from-absolute
8860 (calendar-absolute-from-gregorian d2)))
8861 (end-of-line 0)))
8862 (if (string-match "\\S-" text)
8863 (progn
8864 (set-window-configuration cw)
8865 (message "%s entry added to %s"
8866 (capitalize (symbol-name type))
8867 (abbreviate-file-name org-agenda-diary-file)))
8868 (org-reveal t)
8869 (message "Please finish entry here"))))
8871 (defun org-agenda-insert-diary-as-top-level (text)
8872 "Make new entry as a top-level entry at the end of the file.
8873 Add TEXT as headline, and position the cursor in the second line so that
8874 a timestamp can be added there."
8875 (widen)
8876 (goto-char (point-max))
8877 (or (bolp) (insert "\n"))
8878 (insert "* " text "\n")
8879 (if org-adapt-indentation (org-indent-to-column 2)))
8881 (defun org-agenda-insert-diary-make-new-entry (text)
8882 "Make new entry as last child of current entry.
8883 Add TEXT as headline, and position the cursor in the second line so that
8884 a timestamp can be added there."
8885 (let ((org-show-following-heading t)
8886 (org-show-siblings t)
8887 (org-show-hierarchy-above t)
8888 (org-show-entry-below t)
8889 col)
8890 (outline-next-heading)
8891 (org-back-over-empty-lines)
8892 (or (looking-at "[ \t]*$")
8893 (progn (insert "\n") (backward-char 1)))
8894 (org-insert-heading nil t)
8895 (org-do-demote)
8896 (setq col (current-column))
8897 (insert text "\n")
8898 (if org-adapt-indentation (org-indent-to-column col))
8899 (let ((org-show-following-heading t)
8900 (org-show-siblings t)
8901 (org-show-hierarchy-above t)
8902 (org-show-entry-below t))
8903 (org-show-context))))
8905 (defun org-agenda-diary-entry ()
8906 "Make a diary entry, like the `i' command from the calendar.
8907 All the standard commands work: block, weekly etc.
8908 When `org-agenda-diary-file' points to a file,
8909 `org-agenda-diary-entry-in-org-file' is called instead to create
8910 entries in that Org-mode file."
8911 (interactive)
8912 (if (not (eq org-agenda-diary-file 'diary-file))
8913 (org-agenda-diary-entry-in-org-file)
8914 (require 'diary-lib)
8915 (let* ((char (progn
8916 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8917 (read-char-exclusive)))
8918 (cmd (cdr (assoc char
8919 '((?d . insert-diary-entry)
8920 (?w . insert-weekly-diary-entry)
8921 (?m . insert-monthly-diary-entry)
8922 (?y . insert-yearly-diary-entry)
8923 (?a . insert-anniversary-diary-entry)
8924 (?b . insert-block-diary-entry)
8925 (?c . insert-cyclic-diary-entry)))))
8926 (oldf (symbol-function 'calendar-cursor-to-date))
8927 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8928 (point (point))
8929 (mark (or (mark t) (point))))
8930 (unless cmd
8931 (error "No command associated with <%c>" char))
8932 (unless (and (get-text-property point 'day)
8933 (or (not (equal ?b char))
8934 (get-text-property mark 'day)))
8935 (error "Don't know which date to use for diary entry"))
8936 ;; We implement this by hacking the `calendar-cursor-to-date' function
8937 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8938 (let ((calendar-mark-ring
8939 (list (calendar-gregorian-from-absolute
8940 (or (get-text-property mark 'day)
8941 (get-text-property point 'day))))))
8942 (unwind-protect
8943 (progn
8944 (fset 'calendar-cursor-to-date
8945 (lambda (&optional error dummy)
8946 (calendar-gregorian-from-absolute
8947 (get-text-property point 'day))))
8948 (call-interactively cmd))
8949 (fset 'calendar-cursor-to-date oldf))))))
8951 (defun org-agenda-execute-calendar-command (cmd)
8952 "Execute a calendar command from the agenda with date from cursor."
8953 (org-agenda-check-type t 'agenda 'timeline)
8954 (require 'diary-lib)
8955 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
8956 (error "Don't know which date to use for the calendar command"))
8957 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8958 (point (point))
8959 (date (calendar-gregorian-from-absolute
8960 (get-text-property point 'day)))
8961 ;; the following 2 vars are needed in the calendar
8962 (displayed-month (car date))
8963 (displayed-year (nth 2 date)))
8964 (unwind-protect
8965 (progn
8966 (fset 'calendar-cursor-to-date
8967 (lambda (&optional error dummy)
8968 (calendar-gregorian-from-absolute
8969 (get-text-property point 'day))))
8970 (call-interactively cmd))
8971 (fset 'calendar-cursor-to-date oldf))))
8973 (defun org-agenda-phases-of-moon ()
8974 "Display the phases of the moon for the 3 months around the cursor date."
8975 (interactive)
8976 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8978 (defun org-agenda-holidays ()
8979 "Display the holidays for the 3 months around the cursor date."
8980 (interactive)
8981 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8983 (defvar calendar-longitude) ; defined in calendar.el
8984 (defvar calendar-latitude) ; defined in calendar.el
8985 (defvar calendar-location-name) ; defined in calendar.el
8987 (defun org-agenda-sunrise-sunset (arg)
8988 "Display sunrise and sunset for the cursor date.
8989 Latitude and longitude can be specified with the variables
8990 `calendar-latitude' and `calendar-longitude'. When called with prefix
8991 argument, latitude and longitude will be prompted for."
8992 (interactive "P")
8993 (require 'solar)
8994 (let ((calendar-longitude (if arg nil calendar-longitude))
8995 (calendar-latitude (if arg nil calendar-latitude))
8996 (calendar-location-name
8997 (if arg "the given coordinates" calendar-location-name)))
8998 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9000 (defun org-agenda-goto-calendar ()
9001 "Open the Emacs calendar with the date at the cursor."
9002 (interactive)
9003 (org-agenda-check-type t 'agenda 'timeline)
9004 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9005 (error "Don't know which date to open in calendar")))
9006 (date (calendar-gregorian-from-absolute day))
9007 (calendar-move-hook nil)
9008 (calendar-view-holidays-initially-flag nil)
9009 (calendar-view-diary-initially-flag nil))
9010 (calendar)
9011 (calendar-goto-date date)))
9013 ;;;###autoload
9014 (defun org-calendar-goto-agenda ()
9015 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9016 This is a command that has to be installed in `calendar-mode-map'."
9017 (interactive)
9018 (org-agenda-list nil (calendar-absolute-from-gregorian
9019 (calendar-cursor-to-date))
9020 nil))
9022 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9023 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9024 This is a command that has to be installed in `calendar-mode-map'.
9026 \(fn)" t nil)
9028 (defun org-agenda-convert-date ()
9029 (interactive)
9030 (org-agenda-check-type t 'agenda 'timeline)
9031 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9032 date s)
9033 (unless day
9034 (error "Don't know which date to convert"))
9035 (setq date (calendar-gregorian-from-absolute day))
9036 (setq s (concat
9037 "Gregorian: " (calendar-date-string date) "\n"
9038 "ISO: " (calendar-iso-date-string date) "\n"
9039 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9040 "Julian: " (calendar-julian-date-string date) "\n"
9041 "Astron. JD: " (calendar-astro-date-string date)
9042 " (Julian date number at noon UTC)\n"
9043 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9044 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9045 "French: " (calendar-french-date-string date) "\n"
9046 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9047 "Mayan: " (calendar-mayan-date-string date) "\n"
9048 "Coptic: " (calendar-coptic-date-string date) "\n"
9049 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9050 "Persian: " (calendar-persian-date-string date) "\n"
9051 "Chinese: " (calendar-chinese-date-string date) "\n"))
9052 (with-output-to-temp-buffer "*Dates*"
9053 (princ s))
9054 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9056 ;;; Bulk commands
9058 (defun org-agenda-bulk-marked-p ()
9059 (eq (get-char-property (point-at-bol) 'type)
9060 'org-marked-entry-overlay))
9062 (defun org-agenda-bulk-mark (&optional arg)
9063 "Mark the entry at point for future bulk action."
9064 (interactive "p")
9065 (dotimes (i (or arg 1))
9066 (unless (org-get-at-bol 'org-agenda-diary-link)
9067 (let* ((m (org-get-at-bol 'org-hd-marker))
9069 (unless (org-agenda-bulk-marked-p)
9070 (unless m (error "Nothing to mark at point"))
9071 (push m org-agenda-bulk-marked-entries)
9072 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9073 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9074 (org-get-todo-face "TODO")
9075 'evaporate)
9076 (overlay-put ov 'type 'org-marked-entry-overlay))
9077 (beginning-of-line 2)
9078 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9079 (beginning-of-line 2))
9080 (message "%d entries marked for bulk action"
9081 (length org-agenda-bulk-marked-entries))))))
9083 (defun org-agenda-bulk-mark-all ()
9084 "Mark all entries for future agenda bulk action."
9085 (interactive)
9086 (org-agenda-bulk-mark-regexp "."))
9088 (defun org-agenda-bulk-mark-regexp (regexp)
9089 "Mark entries matching REGEXP for future agenda bulk action."
9090 (interactive "sMark entries matching regexp: ")
9091 (let ((entries-marked 0))
9092 (save-excursion
9093 (goto-char (point-min))
9094 (goto-char (next-single-property-change (point) 'txt))
9095 (while (re-search-forward regexp nil t)
9096 (when (string-match regexp (get-text-property (point) 'txt))
9097 (setq entries-marked (1+ entries-marked))
9098 (call-interactively 'org-agenda-bulk-mark))))
9099 (if (not entries-marked)
9100 (message "No entry matching this regexp."))))
9102 (defun org-agenda-bulk-unmark (&optional arg)
9103 "Unmark the entry at point for future bulk action."
9104 (interactive "P")
9105 (if arg
9106 (org-agenda-bulk-unmark-all)
9107 (cond ((org-agenda-bulk-marked-p)
9108 (org-agenda-bulk-remove-overlays
9109 (point-at-bol) (+ 2 (point-at-bol)))
9110 (setq org-agenda-bulk-marked-entries
9111 (delete (org-get-at-bol 'org-hd-marker)
9112 org-agenda-bulk-marked-entries))
9113 (beginning-of-line 2)
9114 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9115 (beginning-of-line 2))
9116 (message "%d entries left marked for bulk action"
9117 (length org-agenda-bulk-marked-entries)))
9118 (t (message "No entry to unmark here")))))
9120 (defun org-agenda-bulk-toggle ()
9121 "Toggle marking the entry at point for bulk action."
9122 (interactive)
9123 (if (org-agenda-bulk-marked-p)
9124 (org-agenda-bulk-unmark)
9125 (org-agenda-bulk-mark)))
9127 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9128 "Remove the mark overlays between BEG and END in the agenda buffer.
9129 BEG and END default to the buffer limits.
9131 This only removes the overlays, it does not remove the markers
9132 from the list in `org-agenda-bulk-marked-entries'."
9133 (interactive)
9134 (mapc (lambda (ov)
9135 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9136 (delete-overlay ov)))
9137 (overlays-in (or beg (point-min)) (or end (point-max)))))
9139 (defun org-agenda-bulk-unmark-all ()
9140 "Remove all marks in the agenda buffer.
9141 This will remove the markers and the overlays."
9142 (interactive)
9143 (if (null org-agenda-bulk-marked-entries)
9144 (message "No entry to unmark")
9145 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9146 (setq org-agenda-bulk-marked-entries nil)
9147 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9149 (defcustom org-agenda-persistent-marks nil
9150 "Non-nil means marked items will stay marked after a bulk action.
9151 You can toggle this interactively by typing `p' when prompted for a
9152 bulk action."
9153 :group 'org-agenda
9154 :version "24.1"
9155 :type 'boolean)
9157 (defun org-agenda-bulk-action (&optional arg)
9158 "Execute an remote-editing action on all marked entries.
9159 The prefix arg is passed through to the command if possible."
9160 (interactive "P")
9161 ;; Make sure we have markers, and only valid ones
9162 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9163 (mapc
9164 (lambda (m)
9165 (unless (and (markerp m)
9166 (marker-buffer m)
9167 (buffer-live-p (marker-buffer m))
9168 (marker-position m))
9169 (error "Marker %s for bulk command is invalid" m)))
9170 org-agenda-bulk-marked-entries)
9172 ;; Prompt for the bulk command
9173 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9174 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9175 "[S]catter [f]unction "
9176 (when org-agenda-bulk-custom-functions
9177 (concat " Custom: ["
9178 (mapconcat (lambda(f) (char-to-string (car f)))
9179 org-agenda-bulk-custom-functions "")
9180 "]"))))
9181 (catch 'exit
9182 (let* ((action (read-char-exclusive))
9183 (org-log-refile (if org-log-refile 'time nil))
9184 (entries (reverse org-agenda-bulk-marked-entries))
9185 (org-overriding-default-time
9186 (if (get-text-property (point) 'org-agenda-date-header)
9187 (org-get-cursor-date)))
9188 redo-at-end
9189 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9190 (cond
9191 ((equal action ?p)
9192 (let ((org-agenda-persistent-marks
9193 (not org-agenda-persistent-marks)))
9194 (org-agenda-bulk-action)
9195 (throw 'exit nil)))
9197 ((equal action ?$)
9198 (setq cmd '(org-agenda-archive)))
9200 ((equal action ?A)
9201 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9203 ((member action '(?r ?w))
9204 (setq rfloc (org-refile-get-location
9205 "Refile to"
9206 (marker-buffer (car entries))
9207 org-refile-allow-creating-parent-nodes))
9208 (if (nth 3 rfloc)
9209 (setcar (nthcdr 3 rfloc)
9210 (move-marker (make-marker) (nth 3 rfloc)
9211 (or (get-file-buffer (nth 1 rfloc))
9212 (find-buffer-visiting (nth 1 rfloc))
9213 (error "This should not happen")))))
9215 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9216 redo-at-end t))
9218 ((equal action ?t)
9219 (setq state (org-icompleting-read
9220 "Todo state: "
9221 (with-current-buffer (marker-buffer (car entries))
9222 (mapcar 'list org-todo-keywords-1))))
9223 (setq cmd `(let ((org-inhibit-blocking t)
9224 (org-inhibit-logging 'note))
9225 (org-agenda-todo ,state))))
9227 ((memq action '(?- ?+))
9228 (setq tag (org-icompleting-read
9229 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9230 (with-current-buffer (marker-buffer (car entries))
9231 (delq nil
9232 (mapcar (lambda (x)
9233 (if (stringp (car x)) x)) org-tag-alist)))))
9234 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9236 ((memq action '(?s ?d))
9237 (let* ((time
9238 (unless arg
9239 (org-read-date
9240 nil nil nil
9241 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9242 org-overriding-default-time)))
9243 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9244 (setq cmd `(eval '(,c1 arg ,time)))))
9246 ((equal action ?S)
9247 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9248 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9249 (let ((days (read-number
9250 (format "Scatter tasks across how many %sdays: "
9251 (if arg "week" "")) 7)))
9252 (setq cmd
9253 `(let ((distance (1+ (random ,days))))
9254 (if arg
9255 (let ((dist distance)
9256 (day-of-week
9257 (calendar-day-of-week
9258 (calendar-gregorian-from-absolute (org-today)))))
9259 (dotimes (i (1+ dist))
9260 (while (member day-of-week org-agenda-weekend-days)
9261 (incf distance)
9262 (incf day-of-week)
9263 (if (= day-of-week 7)
9264 (setq day-of-week 0)))
9265 (incf day-of-week)
9266 (if (= day-of-week 7)
9267 (setq day-of-week 0)))))
9268 ;; silently fail when try to replan a sexp entry
9269 (condition-case nil
9270 (let* ((date (calendar-gregorian-from-absolute
9271 (+ (org-today) distance)))
9272 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9273 (nth 2 date))))
9274 (org-agenda-schedule nil time))
9275 (error nil)))))))
9277 ((assoc action org-agenda-bulk-custom-functions)
9278 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9279 redo-at-end t))
9281 ((equal action ?f)
9282 (setq cmd (list (intern
9283 (org-icompleting-read "Function: "
9284 obarray 'fboundp t nil nil)))))
9286 (t (error "Invalid bulk action")))
9288 ;; Sort the markers, to make sure that parents are handled before children
9289 (setq entries (sort entries
9290 (lambda (a b)
9291 (cond
9292 ((equal (marker-buffer a) (marker-buffer b))
9293 (< (marker-position a) (marker-position b)))
9295 (string< (buffer-name (marker-buffer a))
9296 (buffer-name (marker-buffer b))))))))
9298 ;; Now loop over all markers and apply cmd
9299 (while (setq e (pop entries))
9300 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9301 (if (not pos)
9302 (progn (message "Skipping removed entry at %s" e)
9303 (setq cntskip (1+ cntskip)))
9304 (goto-char pos)
9305 (let (org-loop-over-headlines-in-active-region)
9306 (eval cmd))
9307 (setq cnt (1+ cnt))))
9308 (when redo-at-end (org-agenda-redo))
9309 (unless org-agenda-persistent-marks
9310 (org-agenda-bulk-unmark-all))
9311 (message "Acted on %d entries%s%s"
9313 (if (= cntskip 0)
9315 (format ", skipped %d (disappeared before their turn)"
9316 cntskip))
9317 (if (not org-agenda-persistent-marks)
9318 "" " (kept marked)"))))))
9320 (defun org-agenda-capture ()
9321 "Call `org-capture' with the date at point."
9322 (interactive)
9323 (if (not (eq major-mode 'org-agenda-mode))
9324 (error "You cannot do this outside of agenda buffers")
9325 (let ((org-overriding-default-time
9326 (org-get-cursor-date)))
9327 (call-interactively 'org-capture))))
9329 ;;; Flagging notes
9331 (defun org-agenda-show-the-flagging-note ()
9332 "Display the flagging note in the other window.
9333 When called a second time in direct sequence, offer to remove the FLAGGING
9334 tag and (if present) the flagging note."
9335 (interactive)
9336 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9337 (win (selected-window))
9338 note heading newhead)
9339 (unless hdmarker
9340 (error "No linked entry at point"))
9341 (if (and (eq this-command last-command)
9342 (y-or-n-p "Unflag and remove any flagging note? "))
9343 (progn
9344 (org-agenda-remove-flag hdmarker)
9345 (let ((win (get-buffer-window "*Flagging Note*")))
9346 (and win (delete-window win)))
9347 (message "Entry unflagged"))
9348 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9349 (unless note
9350 (error "No flagging note"))
9351 (org-kill-new note)
9352 (org-switch-to-buffer-other-window "*Flagging Note*")
9353 (erase-buffer)
9354 (insert note)
9355 (goto-char (point-min))
9356 (while (re-search-forward "\\\\n" nil t)
9357 (replace-match "\n" t t))
9358 (goto-char (point-min))
9359 (select-window win)
9360 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9362 (defun org-agenda-remove-flag (marker)
9363 "Remove the FLAGGED tag and any flagging note in the entry."
9364 (let (newhead)
9365 (org-with-point-at marker
9366 (org-toggle-tag "FLAGGED" 'off)
9367 (org-entry-delete nil "THEFLAGGINGNOTE")
9368 (setq newhead (org-get-heading)))
9369 (org-agenda-change-all-lines newhead marker)
9370 (message "Entry unflagged")))
9372 (defun org-agenda-get-any-marker (&optional pos)
9373 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9374 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9376 ;;; Appointment reminders
9378 (defvar appt-time-msg-list) ; defined in appt.el
9380 ;;;###autoload
9381 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9382 "Activate appointments found in `org-agenda-files'.
9383 With a \\[universal-argument] prefix, refresh the list of
9384 appointments.
9386 If FILTER is t, interactively prompt the user for a regular
9387 expression, and filter out entries that don't match it.
9389 If FILTER is a string, use this string as a regular expression
9390 for filtering entries out.
9392 If FILTER is a function, filter out entries against which
9393 calling the function returns nil. This function takes one
9394 argument: an entry from `org-agenda-get-day-entries'.
9396 FILTER can also be an alist with the car of each cell being
9397 either 'headline or 'category. For example:
9399 '((headline \"IMPORTANT\")
9400 (category \"Work\"))
9402 will only add headlines containing IMPORTANT or headlines
9403 belonging to the \"Work\" category.
9405 ARGS are symbols indicating what kind of entries to consider.
9406 By default `org-agenda-to-appt' will use :deadline, :scheduled
9407 and :timestamp entries. See the docstring of `org-diary' for
9408 details and examples.
9410 If an entry as a APPT_WARNTIME property, its value will be used
9411 to override `appt-message-warning-time'."
9412 (interactive "P")
9413 (if refresh (setq appt-time-msg-list nil))
9414 (if (eq filter t)
9415 (setq filter (read-from-minibuffer "Regexp filter: ")))
9416 (let* ((cnt 0) ; count added events
9417 (scope (or args '(:deadline :scheduled :timestamp)))
9418 (org-agenda-new-buffers nil)
9419 (org-deadline-warning-days 0)
9420 ;; Do not use `org-today' here because appt only takes
9421 ;; time and without date as argument, so it may pass wrong
9422 ;; information otherwise
9423 (today (org-date-to-gregorian
9424 (time-to-days (current-time))))
9425 (org-agenda-restrict nil)
9426 (files (org-agenda-files 'unrestricted)) entries file
9427 (org-agenda-buffer nil))
9428 ;; Get all entries which may contain an appt
9429 (org-agenda-prepare-buffers files)
9430 (while (setq file (pop files))
9431 (setq entries
9432 (delq nil
9433 (append entries
9434 (apply 'org-agenda-get-day-entries
9435 file today scope)))))
9436 ;; Map thru entries and find if we should filter them out
9437 (mapc
9438 (lambda(x)
9439 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9440 (cat (get-text-property 1 'org-category x))
9441 (tod (get-text-property 1 'time-of-day x))
9442 (ok (or (null filter)
9443 (and (stringp filter) (string-match filter evt))
9444 (and (functionp filter) (funcall filter x))
9445 (and (listp filter)
9446 (let ((cat-filter (cadr (assoc 'category filter)))
9447 (evt-filter (cadr (assoc 'headline filter))))
9448 (or (and (stringp cat-filter)
9449 (string-match cat-filter cat))
9450 (and (stringp evt-filter)
9451 (string-match evt-filter evt)))))))
9452 (wrn (get-text-property 1 'warntime x)))
9453 ;; FIXME: Shall we remove text-properties for the appt text?
9454 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9455 (when (and ok tod)
9456 (setq tod (concat "00" (number-to-string tod))
9457 tod (when (string-match
9458 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9459 (concat (match-string 1 tod) ":"
9460 (match-string 2 tod))))
9461 (if (version< emacs-version "23.3")
9462 (appt-add tod evt)
9463 (appt-add tod evt wrn))
9464 (setq cnt (1+ cnt))))) entries)
9465 (org-release-buffers org-agenda-new-buffers)
9466 (if (eq cnt 0)
9467 (message "No event to add")
9468 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9470 (autoload 'org-agenda-to-appt "org-agenda" "\
9471 Activate appointments found in `org-agenda-files'.
9472 With a \\[universal-argument] prefix, refresh the list of
9473 appointments.
9475 If FILTER is t, interactively prompt the user for a regular
9476 expression, and filter out entries that don't match it.
9478 If FILTER is a string, use this string as a regular expression
9479 for filtering entries out.
9481 If FILTER is a function, filter out entries against which
9482 calling the function returns nil. This function takes one
9483 argument: an entry from `org-agenda-get-day-entries'.
9485 FILTER can also be an alist with the car of each cell being
9486 either 'headline or 'category. For example:
9488 '((headline \"IMPORTANT\")
9489 (category \"Work\"))
9491 will only add headlines containing IMPORTANT or headlines
9492 belonging to the \"Work\" category.
9494 ARGS are symbols indicating what kind of entries to consider.
9495 By default `org-agenda-to-appt' will use :deadline, :scheduled
9496 and :timestamp entries. See the docstring of `org-diary' for
9497 details and examples.
9499 If an entry as a APPT_WARNTIME property, its value will be used
9500 to override `appt-message-warning-time'.
9502 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9504 (defun org-agenda-todayp (date)
9505 "Does DATE mean today, when considering `org-extend-today-until'?"
9506 (let ((today (org-today))
9507 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9508 date)))
9509 (eq date today)))
9511 (defun org-agenda-todo-yesterday (&optional arg)
9512 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9513 (interactive "P")
9514 (let* ((hour (third (decode-time
9515 (org-current-time))))
9516 (org-extend-today-until (1+ hour)))
9517 (org-agenda-todo arg)))
9519 (provide 'org-agenda)
9521 ;;; org-agenda.el ends here