org-agenda.el (org-agenda-local-vars): Don't include `org-agenda-show-window'
[org-mode.git] / lisp / org-agenda.el
blobbf77ad5933dba301b4fc6de830be9a8bd94de74a
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 do 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.
1653 When this option is set to 'always, it take precedences over
1654 `org-agenda-use-tag-inheritance' and inherited tags are shown
1655 in every agenda.
1657 When this option is set to t (the default), inherited tags are
1658 shown when they are available, i.e. when the value of
1659 `org-agenda-use-tag-inheritance' has been taken into account.
1661 This can be set to a list of agenda types in which the agenda
1662 must display the inherited tags. Available types are 'todo,
1663 'agenda, 'search and 'timeline.
1665 When set to nil, never show inherited tags in agenda lines."
1666 :group 'org-agenda-line-format
1667 :group 'org-agenda
1668 :version "24.3"
1669 :type '(choice
1670 (const :tag "Show inherited tags when available" t)
1671 (const :tag "Always show inherited tags" 'always)
1672 (repeat :tag "Show inherited tags only in selected agenda types"
1673 (symbol :tag "Agenda type"))))
1675 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1676 "List of agenda view types where to use tag inheritance.
1678 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1679 controlled by `org-use-tag-inheritance'. In other agenda types,
1680 `org-use-tag-inheritance' is not used for the selection of the
1681 agenda entries. Still, you may want the agenda to be aware of
1682 the inherited tags anyway, e.g. for later tag filtering.
1684 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1686 This variable has no effect if `org-agenda-show-inherited-tags'
1687 is set to 'always. In that case, the agenda is aware of those
1688 tags.
1690 The default value sets tags in every agenda type. Setting this
1691 option to nil will speed up non-tags agenda view a lot."
1692 :group 'org-agenda
1693 :version "24.3"
1694 :type '(choice
1695 (const :tag "Use tag inheritance in all agenda types" t)
1696 (repeat :tag "Use tag inheritance in selected agenda types"
1697 (symbol :tag "Agenda type"))))
1699 (defcustom org-agenda-hide-tags-regexp nil
1700 "Regular expression used to filter away specific tags in agenda views.
1701 This means that these tags will be present, but not be shown in the agenda
1702 line. Secondary filtering will still work on the hidden tags.
1703 Nil means don't hide any tags."
1704 :group 'org-agenda-line-format
1705 :type '(choice
1706 (const :tag "Hide none" nil)
1707 (string :tag "Regexp ")))
1709 (defcustom org-agenda-remove-tags nil
1710 "Non-nil means remove the tags from the headline copy in the agenda.
1711 When this is the symbol `prefix', only remove tags when
1712 `org-agenda-prefix-format' contains a `%T' specifier."
1713 :group 'org-agenda-line-format
1714 :type '(choice
1715 (const :tag "Always" t)
1716 (const :tag "Never" nil)
1717 (const :tag "When prefix format contains %T" prefix)))
1719 (if (fboundp 'defvaralias)
1720 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1721 'org-agenda-remove-tags))
1723 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1724 "Shift tags in agenda items to this column.
1725 If this number is positive, it specifies the column. If it is negative,
1726 it means that the tags should be flushright to that column. For example,
1727 -80 works well for a normal 80 character screen."
1728 :group 'org-agenda-line-format
1729 :type 'integer)
1731 (if (fboundp 'defvaralias)
1732 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1734 (defcustom org-agenda-fontify-priorities 'cookies
1735 "Non-nil means highlight low and high priorities in agenda.
1736 When t, the highest priority entries are bold, lowest priority italic.
1737 However, settings in `org-priority-faces' will overrule these faces.
1738 When this variable is the symbol `cookies', only fontify the
1739 cookies, not the entire task.
1740 This may also be an association list of priority faces, whose
1741 keys are the character values of `org-highest-priority',
1742 `org-default-priority', and `org-lowest-priority' (the default values
1743 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1744 color as a string, or a list like `(:background \"Red\")'.
1745 If it is a color, the variable `org-faces-easy-properties'
1746 determines if it is a foreground or a background color."
1747 :group 'org-agenda-line-format
1748 :type '(choice
1749 (const :tag "Never" nil)
1750 (const :tag "Defaults" t)
1751 (const :tag "Cookies only" cookies)
1752 (repeat :tag "Specify"
1753 (list (character :tag "Priority" :value ?A)
1754 (choice :tag "Face "
1755 (string :tag "Color")
1756 (sexp :tag "Face"))))))
1758 (defcustom org-agenda-day-face-function nil
1759 "Function called to determine what face should be used to display a day.
1760 The only argument passed to that function is the day. It should
1761 returns a face, or nil if does not want to specify a face and let
1762 the normal rules apply."
1763 :group 'org-agenda-line-format
1764 :version "24.1"
1765 :type 'function)
1767 (defcustom org-agenda-category-icon-alist nil
1768 "Alist of category icon to be displayed in agenda views.
1770 Each entry should have the following format:
1772 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1774 Where CATEGORY-REGEXP is a regexp matching the categories where
1775 the icon should be displayed.
1776 FILE-OR-DATA either a file path or a string containing image data.
1778 The other fields can be omitted safely if not needed:
1779 TYPE indicates the image type.
1780 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1781 image data.
1782 PROPS are additional image attributes to assign to the image,
1783 like, e.g. `:ascent center'.
1785 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1787 If you want to set the display properties yourself, just put a
1788 list as second element:
1790 (CATEGORY-REGEXP (MY PROPERTY LIST))
1792 For example, to display a 16px horizontal space for Emacs
1793 category, you can use:
1795 (\"Emacs\" '(space . (:width (16))))"
1796 :group 'org-agenda-line-format
1797 :version "24.1"
1798 :type '(alist :key-type (string :tag "Regexp matching category")
1799 :value-type (choice (list :tag "Icon"
1800 (string :tag "File or data")
1801 (symbol :tag "Type")
1802 (boolean :tag "Data?")
1803 (repeat :tag "Extra image properties" :inline t symbol))
1804 (list :tag "Display properties" sexp))))
1806 (defgroup org-agenda-column-view nil
1807 "Options concerning column view in the agenda."
1808 :tag "Org Agenda Column View"
1809 :group 'org-agenda)
1811 (defcustom org-agenda-columns-show-summaries t
1812 "Non-nil means show summaries for columns displayed in the agenda view."
1813 :group 'org-agenda-column-view
1814 :type 'boolean)
1816 (defcustom org-agenda-columns-compute-summary-properties t
1817 "Non-nil means recompute all summary properties before column view.
1818 When column view in the agenda is listing properties that have a summary
1819 operator, it can go to all relevant buffers and recompute the summaries
1820 there. This can mean overhead for the agenda column view, but is necessary
1821 to have thing up to date.
1822 As a special case, a CLOCKSUM property also makes sure that the clock
1823 computations are current."
1824 :group 'org-agenda-column-view
1825 :type 'boolean)
1827 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1828 "Non-nil means the duration of an appointment will add to day effort.
1829 The property to which appointment durations will be added is the one given
1830 in the option `org-effort-property'. If an appointment does not have
1831 an end time, `org-agenda-default-appointment-duration' will be used. If that
1832 is not set, an appointment without end time will not contribute to the time
1833 estimate."
1834 :group 'org-agenda-column-view
1835 :type 'boolean)
1837 (defcustom org-agenda-auto-exclude-function nil
1838 "A function called with a tag to decide if it is filtered on '/ RET'.
1839 The sole argument to the function, which is called once for each
1840 possible tag, is a string giving the name of the tag. The
1841 function should return either nil if the tag should be included
1842 as normal, or \"-<TAG>\" to exclude the tag.
1843 Note that for the purpose of tag filtering, only the lower-case version of
1844 all tags will be considered, so that this function will only ever see
1845 the lower-case version of all tags."
1846 :group 'org-agenda
1847 :type 'function)
1849 (defcustom org-agenda-bulk-custom-functions nil
1850 "Alist of characters and custom functions for bulk actions.
1851 For example, this value makes those two functions available:
1853 '((?R set-category)
1854 (?C bulk-cut))
1856 With selected entries in an agenda buffer, `B R' will call
1857 the custom function `set-category' on the selected entries.
1858 Note that functions in this alist don't need to be quoted."
1859 :type 'alist
1860 :version "24.1"
1861 :group 'org-agenda)
1863 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1864 "Execute BODY with point at location given by `org-hd-marker' property.
1865 If STRING is non-nil, the text property will be fetched from position 0
1866 in that string. If STRING is nil, it will be fetched from the beginning
1867 of the current line."
1868 (org-with-gensyms (marker)
1869 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1870 'org-hd-marker ,string)))
1871 (with-current-buffer (marker-buffer ,marker)
1872 (save-excursion
1873 (goto-char ,marker)
1874 ,@body)))))
1875 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1877 (defun org-add-agenda-custom-command (entry)
1878 "Replace or add a command in `org-agenda-custom-commands'.
1879 This is mostly for hacking and trying a new command - once the command
1880 works you probably want to add it to `org-agenda-custom-commands' for good."
1881 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1882 (if ass
1883 (setcdr ass (cdr entry))
1884 (push entry org-agenda-custom-commands))))
1886 ;;; Define the org-agenda-mode
1888 (defvar org-agenda-mode-map (make-sparse-keymap)
1889 "Keymap for `org-agenda-mode'.")
1890 (if (fboundp 'defvaralias)
1891 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1893 (defvar org-agenda-menu) ; defined later in this file.
1894 (defvar org-agenda-restrict nil) ; defined later in this file.
1895 (defvar org-agenda-follow-mode nil)
1896 (defvar org-agenda-entry-text-mode nil)
1897 (defvar org-agenda-clockreport-mode nil)
1898 (defvar org-agenda-show-log nil)
1899 (defvar org-agenda-redo-command nil)
1900 (defvar org-agenda-query-string nil)
1901 (defvar org-agenda-mode-hook nil
1902 "Hook run after `org-agenda-mode' is turned on.
1903 The buffer is still writable when this hook is called.")
1904 (defvar org-agenda-type nil)
1905 (defvar org-agenda-force-single-file nil)
1906 (defvar org-agenda-bulk-marked-entries nil
1907 "List of markers that refer to marked entries in the agenda.")
1909 ;;; Multiple agenda buffers support
1911 (defcustom org-agenda-sticky nil
1912 "Non-nil means agenda q key will bury agenda buffers.
1913 Agenda commands will then show existing buffer instead of generating new ones.
1914 When nil, `q' will kill the single agenda buffer."
1915 :group 'org-agenda
1916 :version "24.3"
1917 :type 'boolean)
1920 ;;;###autoload
1921 (defun org-toggle-sticky-agenda (&optional arg)
1922 "Toggle `org-agenda-sticky'."
1923 (interactive "P")
1924 (let ((new-value (if arg
1925 (> (prefix-numeric-value arg) 0)
1926 (not org-agenda-sticky))))
1927 (if (equal new-value org-agenda-sticky)
1928 (and (org-called-interactively-p 'interactive)
1929 (message "Sticky agenda was already %s"
1930 (if org-agenda-sticky "enabled" "disabled")))
1931 (setq org-agenda-sticky new-value)
1932 (org-agenda-kill-all-agenda-buffers)
1933 (and (org-called-interactively-p 'interactive)
1934 (message "Sticky agenda was %s"
1935 (if org-agenda-sticky "enabled" "disabled"))))))
1937 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1938 Toggle `org-agenda-sticky'.
1940 \(fn &optional ARG)" t nil)
1942 (defvar org-agenda-buffer nil
1943 "Agenda buffer currently being generated.")
1945 (defvar org-agenda-last-prefix-arg nil)
1946 (defvar org-agenda-this-buffer-name nil)
1947 (defvar org-agenda-doing-sticky-redo nil)
1948 (defvar org-agenda-this-buffer-is-sticky nil)
1950 (defconst org-agenda-local-vars
1951 '(org-agenda-this-buffer-name
1952 org-agenda-undo-list
1953 org-agenda-pending-undo-list
1954 org-agenda-follow-mode
1955 org-agenda-entry-text-mode
1956 org-agenda-clockreport-mode
1957 org-agenda-show-log
1958 org-agenda-redo-command
1959 org-agenda-query-string
1960 org-agenda-type
1961 org-agenda-bulk-marked-entries
1962 org-agenda-undo-has-started-in
1963 org-agenda-info
1964 org-agenda-tag-filter-overlays
1965 org-agenda-cat-filter-overlays
1966 org-agenda-pre-window-conf
1967 org-agenda-columns-active
1968 org-agenda-tag-filter
1969 org-agenda-category-filter
1970 org-agenda-markers
1971 org-agenda-last-search-view-search-was-boolean
1972 org-agenda-filtered-by-category
1973 org-agenda-filter-form
1974 org-agenda-cycle-counter
1975 org-agenda-last-prefix-arg)
1976 "Variables that must be local in agenda buffers to allow multiple buffers.")
1978 (defun org-agenda-mode ()
1979 "Mode for time-sorted view on action items in Org-mode files.
1981 The following commands are available:
1983 \\{org-agenda-mode-map}"
1984 (interactive)
1985 (cond (org-agenda-doing-sticky-redo
1986 ;; Refreshing sticky agenda-buffer
1988 ;; Preserve the value of `org-agenda-local-vars' variables,
1989 ;; while letting `kill-all-local-variables' kill the rest
1990 (let ((save (buffer-local-variables)))
1991 (kill-all-local-variables)
1992 (mapc 'make-local-variable org-agenda-local-vars)
1993 (dolist (elem save)
1994 (let ((var (car elem))
1995 (val (cdr elem)))
1996 (when (and val
1997 (member var org-agenda-local-vars))
1998 (set var val)))))
1999 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2000 (org-agenda-sticky
2001 ;; Creating a sticky Agenda buffer for the first time
2002 (kill-all-local-variables)
2003 (mapc 'make-local-variable org-agenda-local-vars)
2004 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2006 ;; Creating a non-sticky agenda buffer
2007 (kill-all-local-variables)
2008 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
2009 (setq org-agenda-undo-list nil
2010 org-agenda-pending-undo-list nil
2011 org-agenda-bulk-marked-entries nil)
2012 (setq major-mode 'org-agenda-mode)
2013 ;; Keep global-font-lock-mode from turning on font-lock-mode
2014 (org-set-local 'font-lock-global-modes (list 'not major-mode))
2015 (setq mode-name "Org-Agenda")
2016 (use-local-map org-agenda-mode-map)
2017 (easy-menu-add org-agenda-menu)
2018 (if org-startup-truncated (setq truncate-lines t))
2019 (org-set-local 'line-move-visual nil)
2020 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2021 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2022 ;; Make sure properties are removed when copying text
2023 (make-local-variable 'filter-buffer-substring-functions)
2024 (add-hook 'filter-buffer-substring-functions
2025 (lambda (fun start end delete)
2026 (substring-no-properties (funcall fun start end delete))))
2027 (unless org-agenda-keep-modes
2028 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2029 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2030 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2031 org-agenda-show-log org-agenda-start-with-log-mode))
2033 (easy-menu-change
2034 '("Agenda") "Agenda Files"
2035 (append
2036 (list
2037 (vector
2038 (if (get 'org-agenda-files 'org-restrict)
2039 "Restricted to single file"
2040 "Edit File List")
2041 '(org-edit-agenda-file-list)
2042 (not (get 'org-agenda-files 'org-restrict)))
2043 "--")
2044 (mapcar 'org-file-menu-entry (org-agenda-files))))
2045 (org-agenda-set-mode-name)
2046 (apply
2047 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2048 (list 'org-agenda-mode-hook)))
2050 (substitute-key-definition 'undo 'org-agenda-undo
2051 org-agenda-mode-map global-map)
2052 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2053 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2054 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2055 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2056 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2057 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2058 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2059 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2060 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2061 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2062 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2063 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2064 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2065 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2066 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2067 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2068 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2069 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2070 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2071 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2072 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2073 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2074 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2075 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2076 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2077 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2078 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2079 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2080 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2081 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2082 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2083 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2084 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2085 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2086 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2087 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2088 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2089 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2090 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2091 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2092 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2093 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2094 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2095 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2096 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2097 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2099 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2100 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2101 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2102 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2103 (while l (org-defkey org-agenda-mode-map
2104 (int-to-string (pop l)) 'digit-argument)))
2106 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2107 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2108 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2109 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2110 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2111 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2112 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2113 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2114 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2115 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2116 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2117 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2118 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2119 'org-clock-modify-effort-estimate)
2120 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2121 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2122 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2123 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2124 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2125 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2126 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2127 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2128 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2129 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2130 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2131 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2132 (substitute-key-definition 'next-line 'org-agenda-next-line
2133 org-agenda-mode-map global-map)
2134 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2135 org-agenda-mode-map global-map)
2136 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2137 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2138 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2139 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2140 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2141 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2142 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2143 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2144 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2145 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2146 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2147 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2148 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2149 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2150 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2151 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2152 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2153 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2154 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2155 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2156 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2157 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2158 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2159 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2160 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2161 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2162 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2163 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2164 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2165 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2167 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2168 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2169 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2170 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2171 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2172 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2173 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2174 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2175 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2176 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2177 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2178 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2180 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2181 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2182 (when org-agenda-mouse-1-follows-link
2183 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2184 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2185 '("Agenda"
2186 ("Agenda Files")
2187 "--"
2188 ("Agenda Dates"
2189 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2190 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2191 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2192 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2193 "--"
2194 ("View"
2195 ["Day View" org-agenda-day-view
2196 :active (org-agenda-check-type nil 'agenda)
2197 :style radio :selected (eq org-agenda-current-span 'day)
2198 :keys "v d (or just d)"]
2199 ["Week View" org-agenda-week-view
2200 :active (org-agenda-check-type nil 'agenda)
2201 :style radio :selected (eq org-agenda-current-span 'week)
2202 :keys "v w (or just w)"]
2203 ["Month View" org-agenda-month-view
2204 :active (org-agenda-check-type nil 'agenda)
2205 :style radio :selected (eq org-agenda-current-span 'month)
2206 :keys "v m"]
2207 ["Year View" org-agenda-year-view
2208 :active (org-agenda-check-type nil 'agenda)
2209 :style radio :selected (eq org-agenda-current-span 'year)
2210 :keys "v y"]
2211 "--"
2212 ["Include Diary" org-agenda-toggle-diary
2213 :style toggle :selected org-agenda-include-diary
2214 :active (org-agenda-check-type nil 'agenda)]
2215 ["Include Deadlines" org-agenda-toggle-deadlines
2216 :style toggle :selected org-agenda-include-deadlines
2217 :active (org-agenda-check-type nil 'agenda)]
2218 ["Use Time Grid" org-agenda-toggle-time-grid
2219 :style toggle :selected org-agenda-use-time-grid
2220 :active (org-agenda-check-type nil 'agenda)]
2221 "--"
2222 ["Show clock report" org-agenda-clockreport-mode
2223 :style toggle :selected org-agenda-clockreport-mode
2224 :active (org-agenda-check-type nil 'agenda)]
2225 ["Show some entry text" org-agenda-entry-text-mode
2226 :style toggle :selected org-agenda-entry-text-mode
2227 :active t]
2228 "--"
2229 ["Show Logbook entries" org-agenda-log-mode
2230 :style toggle :selected org-agenda-show-log
2231 :active (org-agenda-check-type nil 'agenda 'timeline)
2232 :keys "v l (or just l)"]
2233 ["Include archived trees" org-agenda-archives-mode
2234 :style toggle :selected org-agenda-archives-mode :active t
2235 :keys "v a"]
2236 ["Include archive files" (org-agenda-archives-mode t)
2237 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2238 :keys "v A"]
2239 "--"
2240 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2241 ["Write view to file" org-agenda-write t]
2242 ["Rebuild buffer" org-agenda-redo t]
2243 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2244 "--"
2245 ["Show original entry" org-agenda-show t]
2246 ["Go To (other window)" org-agenda-goto t]
2247 ["Go To (this window)" org-agenda-switch-to t]
2248 ["Capture with cursor date" org-agenda-capture t]
2249 ["Follow Mode" org-agenda-follow-mode
2250 :style toggle :selected org-agenda-follow-mode :active t]
2251 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2252 "--"
2253 ("TODO"
2254 ["Cycle TODO" org-agenda-todo t]
2255 ["Next TODO set" org-agenda-todo-nextset t]
2256 ["Previous TODO set" org-agenda-todo-previousset t]
2257 ["Add note" org-agenda-add-note t])
2258 ("Archive/Refile/Delete"
2259 ["Archive default" org-agenda-archive-default t]
2260 ["Archive default" org-agenda-archive-default-with-confirmation t]
2261 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2262 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2263 ["Archive subtree" org-agenda-archive t]
2264 "--"
2265 ["Refile" org-agenda-refile t]
2266 "--"
2267 ["Delete subtree" org-agenda-kill t])
2268 ("Bulk action"
2269 ["Mark entry" org-agenda-bulk-mark t]
2270 ["Mark all" org-agenda-bulk-mark-all t]
2271 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2272 ["Unmark entry" org-agenda-bulk-unmark t]
2273 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2274 ["Act on all marked" org-agenda-bulk-action t]
2275 "--"
2276 ("Tags and Properties"
2277 ["Show all Tags" org-agenda-show-tags t]
2278 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2279 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2280 "--"
2281 ["Column View" org-columns t])
2282 ("Deadline/Schedule"
2283 ["Schedule" org-agenda-schedule t]
2284 ["Set Deadline" org-agenda-deadline t]
2285 "--"
2286 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2287 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2288 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2289 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2290 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2291 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2292 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2293 ("Clock and Effort"
2294 ["Clock in" org-agenda-clock-in t]
2295 ["Clock out" org-agenda-clock-out t]
2296 ["Clock cancel" org-agenda-clock-cancel t]
2297 ["Goto running clock" org-clock-goto t]
2298 "--"
2299 ["Set Effort" org-agenda-set-effort t]
2300 ["Change clocked effort" org-clock-modify-effort-estimate
2301 (org-clock-is-active)])
2302 ("Priority"
2303 ["Set Priority" org-agenda-priority t]
2304 ["Increase Priority" org-agenda-priority-up t]
2305 ["Decrease Priority" org-agenda-priority-down t]
2306 ["Show Priority" org-show-priority t])
2307 ("Calendar/Diary"
2308 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2309 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2310 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2311 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2312 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2313 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2314 "--"
2315 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2316 "--"
2317 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2318 "--"
2319 ("MobileOrg"
2320 ["Push Files and Views" org-mobile-push t]
2321 ["Get Captured and Flagged" org-mobile-pull t]
2322 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2323 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2324 "--"
2325 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2326 "--"
2327 ["Quit" org-agenda-quit t]
2328 ["Exit and Release Buffers" org-agenda-exit t]
2331 ;;; Agenda undo
2333 (defvar org-agenda-allow-remote-undo t
2334 "Non-nil means allow remote undo from the agenda buffer.")
2335 (defvar org-agenda-undo-has-started-in nil
2336 "Buffers that have already seen `undo-start' in the current undo sequence.")
2338 (defun org-agenda-undo ()
2339 "Undo a remote editing step in the agenda.
2340 This undoes changes both in the agenda buffer and in the remote buffer
2341 that have been changed along."
2342 (interactive)
2343 (or org-agenda-allow-remote-undo
2344 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2345 (if (not (eq this-command last-command))
2346 (setq org-agenda-undo-has-started-in nil
2347 org-agenda-pending-undo-list org-agenda-undo-list))
2348 (if (not org-agenda-pending-undo-list)
2349 (error "No further undo information"))
2350 (let* ((entry (pop org-agenda-pending-undo-list))
2351 buf line cmd rembuf)
2352 (setq cmd (pop entry) line (pop entry))
2353 (setq rembuf (nth 2 entry))
2354 (org-with-remote-undo rembuf
2355 (while (bufferp (setq buf (pop entry)))
2356 (if (pop entry)
2357 (with-current-buffer buf
2358 (let ((last-undo-buffer buf)
2359 (inhibit-read-only t))
2360 (unless (memq buf org-agenda-undo-has-started-in)
2361 (push buf org-agenda-undo-has-started-in)
2362 (make-local-variable 'pending-undo-list)
2363 (undo-start))
2364 (while (and pending-undo-list
2365 (listp pending-undo-list)
2366 (not (car pending-undo-list)))
2367 (pop pending-undo-list))
2368 (undo-more 1))))))
2369 (org-goto-line line)
2370 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2372 (defun org-verify-change-for-undo (l1 l2)
2373 "Verify that a real change occurred between the undo lists L1 and L2."
2374 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2375 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2376 (not (eq l1 l2)))
2378 ;;; Agenda dispatch
2380 (defvar org-agenda-restrict-begin (make-marker))
2381 (defvar org-agenda-restrict-end (make-marker))
2382 (defvar org-agenda-last-dispatch-buffer nil)
2383 (defvar org-agenda-overriding-restriction nil)
2385 (defcustom org-agenda-custom-commands-contexts nil
2386 "Alist of custom agenda keys and contextual rules.
2388 For example, if you have a custom agenda command \"p\" and you
2389 want this command to be accessible only from plain text files,
2390 use this:
2392 '((\"p\" ((in-file . \"\\.txt\"))))
2394 Here are the available contexts definitions:
2396 in-file: command displayed only in matching files
2397 in-mode: command displayed only in matching modes
2398 not-in-file: command not displayed in matching files
2399 not-in-mode: command not displayed in matching modes
2400 [function]: a custom function taking no argument
2402 If you define several checks, the agenda command will be
2403 accessible if there is at least one valid check.
2405 You can also bind a key to another agenda custom command
2406 depending on contextual rules.
2408 '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
2410 Here it means: in .txt files, use \"p\" as the key for the
2411 agenda command otherwise associated with \"q\". (The command
2412 originally associated with \"q\" is not displayed to avoid
2413 duplicates.)"
2414 :version "24.3"
2415 :group 'org-agenda-custom-commands
2416 :type '(repeat (list :tag "Rule"
2417 (string :tag " Agenda key")
2418 (string :tag "Replace by command")
2419 (repeat :tag "Available when"
2420 (choice
2421 (cons :tag "Condition"
2422 (choice
2423 (const :tag "In file" in-file)
2424 (const :tag "Not in file" not-in-file)
2425 (const :tag "In mode" in-mode)
2426 (const :tag "Not in mode" not-in-mode))
2427 (regexp))
2428 (function :tag "Custom function"))))))
2430 (defvar org-keys nil)
2431 (defvar org-match nil)
2432 ;;;###autoload
2433 (defun org-agenda (&optional arg org-keys restriction)
2434 "Dispatch agenda commands to collect entries to the agenda buffer.
2435 Prompts for a command to execute. Any prefix arg will be passed
2436 on to the selected command. The default selections are:
2438 a Call `org-agenda-list' to display the agenda for current day or week.
2439 t Call `org-todo-list' to display the global todo list.
2440 T Call `org-todo-list' to display the global todo list, select only
2441 entries with a specific TODO keyword (the user gets a prompt).
2442 m Call `org-tags-view' to display headlines with tags matching
2443 a condition (the user is prompted for the condition).
2444 M Like `m', but select only TODO entries, no ordinary headlines.
2445 L Create a timeline for the current buffer.
2446 e Export views to associated files.
2447 s Search entries for keywords.
2448 S Search entries for keywords, only with TODO keywords.
2449 / Multi occur across all agenda files and also files listed
2450 in `org-agenda-text-search-extra-files'.
2451 < Restrict agenda commands to buffer, subtree, or region.
2452 Press several times to get the desired effect.
2453 > Remove a previous restriction.
2454 # List \"stuck\" projects.
2455 ! Configure what \"stuck\" means.
2456 C Configure custom agenda commands.
2458 More commands can be added by configuring the variable
2459 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2460 searches can be pre-defined in this way.
2462 If the current buffer is in Org-mode and visiting a file, you can also
2463 first press `<' once to indicate that the agenda should be temporarily
2464 \(until the next use of \\[org-agenda]) restricted to the current file.
2465 Pressing `<' twice means to restrict to the current subtree or region
2466 \(if active)."
2467 (interactive "P")
2468 (catch 'exit
2469 (let* ((prefix-descriptions nil)
2470 (org-agenda-buffer-name org-agenda-buffer-name)
2471 (org-agenda-window-setup (if (equal (buffer-name)
2472 org-agenda-buffer-name)
2473 'current-window
2474 org-agenda-window-setup))
2475 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2476 (org-agenda-custom-commands
2477 ;; normalize different versions
2478 (delq nil
2479 (mapcar
2480 (lambda (x)
2481 (cond ((stringp (cdr x))
2482 (push x prefix-descriptions)
2483 nil)
2484 ((stringp (nth 1 x)) x)
2485 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2486 (t (cons (car x) (cons "" (cdr x))))))
2487 org-agenda-custom-commands)))
2488 (org-agenda-custom-commands
2489 (org-contextualize-keys
2490 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2491 (buf (current-buffer))
2492 (bfn (buffer-file-name (buffer-base-buffer)))
2493 entry key type org-match lprops ans)
2494 ;; Turn off restriction unless there is an overriding one,
2495 (unless org-agenda-overriding-restriction
2496 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2497 ;; There is a request to keep the file list in place
2498 (put 'org-agenda-files 'org-restrict nil))
2499 (setq org-agenda-restrict nil)
2500 (move-marker org-agenda-restrict-begin nil)
2501 (move-marker org-agenda-restrict-end nil))
2502 ;; Delete old local properties
2503 (put 'org-agenda-redo-command 'org-lprops nil)
2504 ;; Delete previously set last-arguments
2505 (put 'org-agenda-redo-command 'last-args nil)
2506 ;; Remember where this call originated
2507 (setq org-agenda-last-dispatch-buffer (current-buffer))
2508 (unless org-keys
2509 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2510 org-keys (car ans)
2511 restriction (cdr ans)))
2512 ;; If we have sticky agenda buffers, set a name for the buffer,
2513 ;; depending on the invoking keys. The user may still set this
2514 ;; as a command option, which will overwrite what we do here.
2515 (if org-agenda-sticky
2516 (setq org-agenda-buffer-name
2517 (format "*Org Agenda(%s)*" org-keys)))
2518 ;; Establish the restriction, if any
2519 (when (and (not org-agenda-overriding-restriction) restriction)
2520 (put 'org-agenda-files 'org-restrict (list bfn))
2521 (cond
2522 ((eq restriction 'region)
2523 (setq org-agenda-restrict t)
2524 (move-marker org-agenda-restrict-begin (region-beginning))
2525 (move-marker org-agenda-restrict-end (region-end)))
2526 ((eq restriction 'subtree)
2527 (save-excursion
2528 (setq org-agenda-restrict t)
2529 (org-back-to-heading t)
2530 (move-marker org-agenda-restrict-begin (point))
2531 (move-marker org-agenda-restrict-end
2532 (progn (org-end-of-subtree t)))))))
2534 ;; For example the todo list should not need it (but does...)
2535 (cond
2536 ((setq entry (assoc org-keys org-agenda-custom-commands))
2537 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2538 (progn
2539 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2540 lprops (nth 4 entry))
2541 (if org-agenda-sticky
2542 (setq org-agenda-buffer-name
2543 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2544 (format "*Org Agenda(%s)*" org-keys))))
2545 (put 'org-agenda-redo-command 'org-lprops lprops)
2546 (cond
2547 ((eq type 'agenda)
2548 (org-let lprops '(org-agenda-list current-prefix-arg)))
2549 ((eq type 'alltodo)
2550 (org-let lprops '(org-todo-list current-prefix-arg)))
2551 ((eq type 'search)
2552 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2553 ((eq type 'stuck)
2554 (org-let lprops '(org-agenda-list-stuck-projects
2555 current-prefix-arg)))
2556 ((eq type 'tags)
2557 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2558 ((eq type 'tags-todo)
2559 (org-let lprops '(org-tags-view '(4) org-match)))
2560 ((eq type 'todo)
2561 (org-let lprops '(org-todo-list org-match)))
2562 ((eq type 'tags-tree)
2563 (org-check-for-org-mode)
2564 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2565 ((eq type 'todo-tree)
2566 (org-check-for-org-mode)
2567 (org-let lprops
2568 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2569 (regexp-quote org-match) "\\>"))))
2570 ((eq type 'occur-tree)
2571 (org-check-for-org-mode)
2572 (org-let lprops '(org-occur org-match)))
2573 ((functionp type)
2574 (org-let lprops '(funcall type org-match)))
2575 ((fboundp type)
2576 (org-let lprops '(funcall type org-match)))
2577 (t (error "Invalid custom agenda command type %s" type))))
2578 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2579 ((equal org-keys "C")
2580 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2581 (customize-variable 'org-agenda-custom-commands))
2582 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2583 ((equal org-keys "s") (call-interactively 'org-search-view))
2584 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2585 ((equal org-keys "t") (call-interactively 'org-todo-list))
2586 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2587 ((equal org-keys "m") (call-interactively 'org-tags-view))
2588 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2589 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2590 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2591 (org-add-hook
2592 'post-command-hook
2593 (lambda ()
2594 (unless (current-message)
2595 (let* ((m (org-agenda-get-any-marker))
2596 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2597 (when note
2598 (message (concat
2599 "FLAGGING-NOTE ([?] for more info): "
2600 (org-add-props
2601 (replace-regexp-in-string
2602 "\\\\n" "//"
2603 (copy-sequence note))
2604 nil 'face 'org-warning)))))))
2605 t t))
2606 ((equal org-keys "L")
2607 (unless (derived-mode-p 'org-mode)
2608 (error "This is not an Org-mode file"))
2609 (unless restriction
2610 (put 'org-agenda-files 'org-restrict (list bfn))
2611 (org-call-with-arg 'org-timeline arg)))
2612 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2613 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2614 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2615 (t (error "Invalid agenda key"))))))
2617 (autoload 'org-agenda "org-agenda" "\
2618 Dispatch agenda commands to collect entries to the agenda buffer.
2619 Prompts for a command to execute. Any prefix arg will be passed
2620 on to the selected command. The default selections are:
2622 a Call `org-agenda-list' to display the agenda for current day or week.
2623 t Call `org-todo-list' to display the global todo list.
2624 T Call `org-todo-list' to display the global todo list, select only
2625 entries with a specific TODO keyword (the user gets a prompt).
2626 m Call `org-tags-view' to display headlines with tags matching
2627 a condition (the user is prompted for the condition).
2628 M Like `m', but select only TODO entries, no ordinary headlines.
2629 L Create a timeline for the current buffer.
2630 e Export views to associated files.
2631 s Search entries for keywords.
2632 S Search entries for keywords, only with TODO keywords.
2633 / Multi occur across all agenda files and also files listed
2634 in `org-agenda-text-search-extra-files'.
2635 < Restrict agenda commands to buffer, subtree, or region.
2636 Press several times to get the desired effect.
2637 > Remove a previous restriction.
2638 # List \"stuck\" projects.
2639 ! Configure what \"stuck\" means.
2640 C Configure custom agenda commands.
2642 More commands can be added by configuring the variable
2643 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2644 searches can be pre-defined in this way.
2646 If the current buffer is in Org-mode and visiting a file, you can also
2647 first press `<' once to indicate that the agenda should be temporarily
2648 \(until the next use of \\[org-agenda]) restricted to the current file.
2649 Pressing `<' twice means to restrict to the current subtree or region
2650 \(if active).
2652 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2654 (defun org-agenda-append-agenda ()
2655 "Append another agenda view to the current one.
2656 This function allows interactive building of block agendas.
2657 Agenda views are separated by `org-agenda-block-separator'."
2658 (interactive)
2659 (unless (derived-mode-p 'org-agenda-mode)
2660 (error "Can only append from within agenda buffer"))
2661 (let ((org-agenda-multi t))
2662 (org-agenda)
2663 (widen)
2664 (org-agenda-finalize)
2665 (org-agenda-fit-window-to-buffer)))
2667 (defun org-agenda-normalize-custom-commands (cmds)
2668 (delq nil
2669 (mapcar
2670 (lambda (x)
2671 (cond ((stringp (cdr x)) nil)
2672 ((stringp (nth 1 x)) x)
2673 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2674 (t (cons (car x) (cons "" (cdr x))))))
2675 cmds)))
2677 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2678 "The user interface for selecting an agenda command."
2679 (catch 'exit
2680 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2681 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2682 (region-p (org-region-active-p))
2683 (custom org-agenda-custom-commands)
2684 (selstring "")
2685 restriction second-time
2686 c entry key type match prefixes rmheader header-end custom1 desc
2687 line lines left right n n1)
2688 (save-window-excursion
2689 (delete-other-windows)
2690 (org-switch-to-buffer-other-window " *Agenda Commands*")
2691 (erase-buffer)
2692 (insert (eval-when-compile
2693 (let ((header
2694 "Press key for an agenda command: < Buffer, subtree/region restriction
2695 -------------------------------- > Remove restriction
2696 a Agenda for current week or day e Export agenda views
2697 t List of all TODO entries T Entries with special TODO kwd
2698 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2699 s Search for keywords S Like s, but only TODO entries
2700 L Timeline for current buffer # List stuck projects (!=configure)
2701 / Multi-occur C Configure custom agenda commands
2702 ? Find :FLAGGED: entries * Toggle sticky agenda views
2704 (start 0))
2705 (while (string-match
2706 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2707 header start)
2708 (setq start (match-end 0))
2709 (add-text-properties (match-beginning 2) (match-end 2)
2710 '(face bold) header))
2711 header)))
2712 (setq header-end (point-marker))
2713 (while t
2714 (setq custom1 custom)
2715 (when (eq rmheader t)
2716 (org-goto-line 1)
2717 (re-search-forward ":" nil t)
2718 (delete-region (match-end 0) (point-at-eol))
2719 (forward-char 1)
2720 (looking-at "-+")
2721 (delete-region (match-end 0) (point-at-eol))
2722 (move-marker header-end (match-end 0)))
2723 (goto-char header-end)
2724 (delete-region (point) (point-max))
2726 ;; Produce all the lines that describe custom commands and prefixes
2727 (setq lines nil)
2728 (while (setq entry (pop custom1))
2729 (setq key (car entry) desc (nth 1 entry)
2730 type (nth 2 entry)
2731 match (nth 3 entry))
2732 (if (> (length key) 1)
2733 (add-to-list 'prefixes (string-to-char key))
2734 (setq line
2735 (format
2736 "%-4s%-14s"
2737 (org-add-props (copy-sequence key)
2738 '(face bold))
2739 (cond
2740 ((string-match "\\S-" desc) desc)
2741 ((eq type 'agenda) "Agenda for current week or day")
2742 ((eq type 'alltodo) "List of all TODO entries")
2743 ((eq type 'search) "Word search")
2744 ((eq type 'stuck) "List of stuck projects")
2745 ((eq type 'todo) "TODO keyword")
2746 ((eq type 'tags) "Tags query")
2747 ((eq type 'tags-todo) "Tags (TODO)")
2748 ((eq type 'tags-tree) "Tags tree")
2749 ((eq type 'todo-tree) "TODO kwd tree")
2750 ((eq type 'occur-tree) "Occur tree")
2751 ((functionp type) (if (symbolp type)
2752 (symbol-name type)
2753 "Lambda expression"))
2754 (t "???"))))
2755 (if org-agenda-menu-show-matcher
2756 (setq line
2757 (concat line ": "
2758 (cond
2759 ((stringp match)
2760 (setq match (copy-sequence match))
2761 (org-add-props match nil 'face 'org-warning))
2762 ((listp type)
2763 (format "set of %d commands" (length type))))))
2764 (if (org-string-nw-p match)
2765 (add-text-properties
2766 0 (length line) (list 'help-echo
2767 (concat "Matcher: " match)) line)))
2768 (push line lines)))
2769 (setq lines (nreverse lines))
2770 (when prefixes
2771 (mapc (lambda (x)
2772 (push
2773 (format "%s %s"
2774 (org-add-props (char-to-string x)
2775 nil 'face 'bold)
2776 (or (cdr (assoc (concat selstring
2777 (char-to-string x))
2778 prefix-descriptions))
2779 "Prefix key"))
2780 lines))
2781 prefixes))
2783 ;; Check if we should display in two columns
2784 (if org-agenda-menu-two-columns
2785 (progn
2786 (setq n (length lines)
2787 n1 (+ (/ n 2) (mod n 2))
2788 right (nthcdr n1 lines)
2789 left (copy-sequence lines))
2790 (setcdr (nthcdr (1- n1) left) nil))
2791 (setq left lines right nil))
2792 (while left
2793 (insert "\n" (pop left))
2794 (when right
2795 (if (< (current-column) 40)
2796 (move-to-column 40 t)
2797 (insert " "))
2798 (insert (pop right))))
2800 ;; Make the window the right size
2801 (goto-char (point-min))
2802 (if second-time
2803 (if (not (pos-visible-in-window-p (point-max)))
2804 (org-fit-window-to-buffer))
2805 (setq second-time t)
2806 (org-fit-window-to-buffer))
2808 ;; Ask for selection
2809 (message "Press key for agenda command%s:"
2810 (if (or restrict-ok org-agenda-overriding-restriction)
2811 (if org-agenda-overriding-restriction
2812 " (restriction lock active)"
2813 (if restriction
2814 (format " (restricted to %s)" restriction)
2815 " (unrestricted)"))
2816 ""))
2817 (setq c (read-char-exclusive))
2818 (message "")
2819 (cond
2820 ((assoc (char-to-string c) custom)
2821 (setq selstring (concat selstring (char-to-string c)))
2822 (throw 'exit (cons selstring restriction)))
2823 ((memq c prefixes)
2824 (setq selstring (concat selstring (char-to-string c))
2825 prefixes nil
2826 rmheader (or rmheader t)
2827 custom (delq nil (mapcar
2828 (lambda (x)
2829 (if (or (= (length (car x)) 1)
2830 (/= (string-to-char (car x)) c))
2832 (cons (substring (car x) 1) (cdr x))))
2833 custom))))
2834 ((eq c ?*)
2835 (call-interactively 'org-toggle-sticky-agenda)
2836 (sit-for 2))
2837 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2838 (message "Restriction is only possible in Org-mode buffers")
2839 (ding) (sit-for 1))
2840 ((eq c ?1)
2841 (org-agenda-remove-restriction-lock 'noupdate)
2842 (setq restriction 'buffer))
2843 ((eq c ?0)
2844 (org-agenda-remove-restriction-lock 'noupdate)
2845 (setq restriction (if region-p 'region 'subtree)))
2846 ((eq c ?<)
2847 (org-agenda-remove-restriction-lock 'noupdate)
2848 (setq restriction
2849 (cond
2850 ((eq restriction 'buffer)
2851 (if region-p 'region 'subtree))
2852 ((memq restriction '(subtree region))
2853 nil)
2854 (t 'buffer))))
2855 ((eq c ?>)
2856 (org-agenda-remove-restriction-lock 'noupdate)
2857 (setq restriction nil))
2858 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2859 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2860 ((and (> (length selstring) 0) (eq c ?\d))
2861 (delete-window)
2862 (org-agenda-get-restriction-and-command prefix-descriptions))
2864 ((equal c ?q) (error "Abort"))
2865 (t (error "Invalid key %c" c))))))))
2867 (defun org-agenda-fit-window-to-buffer ()
2868 "Fit the window to the buffer size."
2869 (and (memq org-agenda-window-setup '(reorganize-frame))
2870 (fboundp 'fit-window-to-buffer)
2871 (org-fit-window-to-buffer
2873 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2874 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2876 (defvar org-cmd nil)
2877 (defvar org-agenda-overriding-cmd nil)
2878 (defvar org-agenda-overriding-arguments nil)
2879 (defvar org-agenda-overriding-cmd-arguments nil)
2880 (defun org-agenda-run-series (name series)
2881 (org-let (nth 1 series) '(org-agenda-prepare name))
2882 ;; We need to reset agenda markers here, because when constructing a
2883 ;; block agenda, the individual blocks do not do that.
2884 (org-agenda-reset-markers)
2885 (let* ((org-agenda-multi t)
2886 (redo (list 'org-agenda-run-series name (list 'quote series)))
2887 (cmds (car series))
2888 (gprops (nth 1 series))
2889 match ;; The byte compiler incorrectly complains about this. Keep it!
2890 org-cmd type lprops)
2891 (while (setq org-cmd (pop cmds))
2892 (setq type (car org-cmd)
2893 match (eval (nth 1 org-cmd))
2894 lprops (nth 2 org-cmd))
2895 (let ((org-agenda-overriding-arguments
2896 (if (eq org-agenda-overriding-cmd org-cmd)
2897 (or org-agenda-overriding-arguments
2898 org-agenda-overriding-cmd-arguments))))
2899 (cond
2900 ((eq type 'agenda)
2901 (org-let2 gprops lprops
2902 '(call-interactively 'org-agenda-list)))
2903 ((eq type 'alltodo)
2904 (org-let2 gprops lprops
2905 '(call-interactively 'org-todo-list)))
2906 ((eq type 'search)
2907 (org-let2 gprops lprops
2908 '(org-search-view current-prefix-arg match nil)))
2909 ((eq type 'stuck)
2910 (org-let2 gprops lprops
2911 '(call-interactively 'org-agenda-list-stuck-projects)))
2912 ((eq type 'tags)
2913 (org-let2 gprops lprops
2914 '(org-tags-view current-prefix-arg match)))
2915 ((eq type 'tags-todo)
2916 (org-let2 gprops lprops
2917 '(org-tags-view '(4) match)))
2918 ((eq type 'todo)
2919 (org-let2 gprops lprops
2920 '(org-todo-list match)))
2921 ((fboundp type)
2922 (org-let2 gprops lprops
2923 '(funcall type match)))
2924 (t (error "Invalid type in command series")))))
2925 (widen)
2926 (let ((inhibit-read-only t))
2927 (add-text-properties (point-min) (point-max)
2928 `(org-series t org-series-redo-cmd ,redo)))
2929 (setq org-agenda-redo-command redo)
2930 (goto-char (point-min)))
2931 (org-agenda-fit-window-to-buffer)
2932 (org-let (nth 1 series) '(org-agenda-finalize)))
2934 ;;;###autoload
2935 (defmacro org-batch-agenda (cmd-key &rest parameters)
2936 "Run an agenda command in batch mode and send the result to STDOUT.
2937 If CMD-KEY is a string of length 1, it is used as a key in
2938 `org-agenda-custom-commands' and triggers this command. If it is a
2939 longer string it is used as a tags/todo match string.
2940 Parameters are alternating variable names and values that will be bound
2941 before running the agenda command."
2942 (org-eval-in-environment (org-make-parameter-alist parameters)
2943 (if (> (length cmd-key) 2)
2944 (org-tags-view nil cmd-key)
2945 (org-agenda nil cmd-key)))
2946 (set-buffer org-agenda-buffer-name)
2947 (princ (buffer-string)))
2949 (autoload 'org-batch-agenda "org-agenda" "\
2950 Run an agenda command in batch mode and send the result to STDOUT.
2951 If CMD-KEY is a string of length 1, it is used as a key in
2952 `org-agenda-custom-commands' and triggers this command. If it is a
2953 longer string it is used as a tags/todo match string.
2954 Parameters are alternating variable names and values that will be bound
2955 before running the agenda command.
2957 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2958 (def-edebug-spec org-batch-agenda (form &rest sexp))
2960 (defvar org-agenda-info nil)
2962 ;;;###autoload
2963 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2964 "Run an agenda command in batch mode and send the result to STDOUT.
2965 If CMD-KEY is a string of length 1, it is used as a key in
2966 `org-agenda-custom-commands' and triggers this command. If it is a
2967 longer string it is used as a tags/todo match string.
2968 Parameters are alternating variable names and values that will be bound
2969 before running the agenda command.
2971 The output gives a line for each selected agenda item. Each
2972 item is a list of comma-separated values, like this:
2974 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2976 category The category of the item
2977 head The headline, without TODO kwd, TAGS and PRIORITY
2978 type The type of the agenda entry, can be
2979 todo selected in TODO match
2980 tagsmatch selected in tags match
2981 diary imported from diary
2982 deadline a deadline on given date
2983 scheduled scheduled on given date
2984 timestamp entry has timestamp on given date
2985 closed entry was closed on given date
2986 upcoming-deadline warning about deadline
2987 past-scheduled forwarded scheduled item
2988 block entry has date block including g. date
2989 todo The todo keyword, if any
2990 tags All tags including inherited ones, separated by colons
2991 date The relevant date, like 2007-2-14
2992 time The time, like 15:00-16:50
2993 extra Sting with extra planning info
2994 priority-l The priority letter if any was given
2995 priority-n The computed numerical priority
2996 agenda-day The day in the agenda where this is listed"
2997 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2998 (org-make-parameter-alist parameters))
2999 (if (> (length cmd-key) 2)
3000 (org-tags-view nil cmd-key)
3001 (org-agenda nil cmd-key)))
3002 (set-buffer org-agenda-buffer-name)
3003 (let* ((lines (org-split-string (buffer-string) "\n"))
3004 line)
3005 (while (setq line (pop lines))
3006 (catch 'next
3007 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3008 (setq org-agenda-info
3009 (org-fix-agenda-info (text-properties-at 0 line)))
3010 (princ
3011 (mapconcat 'org-agenda-export-csv-mapper
3012 '(org-category txt type todo tags date time extra
3013 priority-letter priority agenda-day)
3014 ","))
3015 (princ "\n")))))
3017 (autoload 'org-batch-agenda-csv "org-agenda" "\
3018 Run an agenda command in batch mode and send the result to STDOUT.
3019 If CMD-KEY is a string of length 1, it is used as a key in
3020 `org-agenda-custom-commands' and triggers this command. If it is a
3021 longer string it is used as a tags/todo match string.
3022 Parameters are alternating variable names and values that will be bound
3023 before running the agenda command.
3025 The output gives a line for each selected agenda item. Each
3026 item is a list of comma-separated values, like this:
3028 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3030 category The category of the item
3031 head The headline, without TODO kwd, TAGS and PRIORITY
3032 type The type of the agenda entry, can be
3033 todo selected in TODO match
3034 tagsmatch selected in tags match
3035 diary imported from diary
3036 deadline a deadline on given date
3037 scheduled scheduled on given date
3038 timestamp entry has timestamp on given date
3039 closed entry was closed on given date
3040 upcoming-deadline warning about deadline
3041 past-scheduled forwarded scheduled item
3042 block entry has date block including g. date
3043 todo The todo keyword, if any
3044 tags All tags including inherited ones, separated by colons
3045 date The relevant date, like 2007-2-14
3046 time The time, like 15:00-16:50
3047 extra Sting with extra planning info
3048 priority-l The priority letter if any was given
3049 priority-n The computed numerical priority
3050 agenda-day The day in the agenda where this is listed
3052 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3053 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3055 (defun org-fix-agenda-info (props)
3056 "Make sure all properties on an agenda item have a canonical form.
3057 This ensures the export commands can easily use it."
3058 (let (tmp re)
3059 (when (setq tmp (plist-get props 'tags))
3060 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3061 (when (setq tmp (plist-get props 'date))
3062 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3063 (let ((calendar-date-display-form '(year "-" month "-" day)))
3064 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3066 (setq tmp (calendar-date-string tmp)))
3067 (setq props (plist-put props 'date tmp)))
3068 (when (setq tmp (plist-get props 'day))
3069 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3070 (let ((calendar-date-display-form '(year "-" month "-" day)))
3071 (setq tmp (calendar-date-string tmp)))
3072 (setq props (plist-put props 'day tmp))
3073 (setq props (plist-put props 'agenda-day tmp)))
3074 (when (setq tmp (plist-get props 'txt))
3075 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3076 (plist-put props 'priority-letter (match-string 1 tmp))
3077 (setq tmp (replace-match "" t t tmp)))
3078 (when (and (setq re (plist-get props 'org-todo-regexp))
3079 (setq re (concat "\\`\\.*" re " ?"))
3080 (string-match re tmp))
3081 (plist-put props 'todo (match-string 1 tmp))
3082 (setq tmp (replace-match "" t t tmp)))
3083 (plist-put props 'txt tmp)))
3084 props)
3086 (defun org-agenda-export-csv-mapper (prop)
3087 (let ((res (plist-get org-agenda-info prop)))
3088 (setq res
3089 (cond
3090 ((not res) "")
3091 ((stringp res) res)
3092 (t (prin1-to-string res))))
3093 (while (string-match "," res)
3094 (setq res (replace-match ";" t t res)))
3095 (org-trim res)))
3097 ;;;###autoload
3098 (defun org-store-agenda-views (&rest parameters)
3099 (interactive)
3100 (eval (list 'org-batch-store-agenda-views)))
3102 (autoload 'org-store-agenda-views "org-agenda" "\
3105 \(fn &rest PARAMETERS)" t nil)
3107 ;;;###autoload
3108 (defmacro org-batch-store-agenda-views (&rest parameters)
3109 "Run all custom agenda commands that have a file argument."
3110 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3111 (pop-up-frames nil)
3112 (dir default-directory)
3113 (pars (org-make-parameter-alist parameters))
3114 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3115 (save-window-excursion
3116 (while cmds
3117 (setq cmd (pop cmds)
3118 thiscmdkey (car cmd)
3119 thiscmdcmd (cdr cmd)
3120 match (nth 2 thiscmdcmd)
3121 bufname (if org-agenda-sticky
3122 (or (and (stringp match)
3123 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3124 (format "*Org Agenda(%s)*" thiscmdkey))
3125 org-agenda-buffer-name)
3126 cmd-or-set (nth 2 cmd)
3127 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3128 files (nth (if (listp cmd-or-set) 4 5) cmd))
3129 (if (stringp files) (setq files (list files)))
3130 (when files
3131 (org-eval-in-environment (append org-agenda-exporter-settings
3132 opts pars)
3133 (org-agenda nil thiscmdkey))
3134 (set-buffer bufname)
3135 (while files
3136 (org-eval-in-environment (append org-agenda-exporter-settings
3137 opts pars)
3138 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3139 (and (get-buffer bufname)
3140 (kill-buffer bufname)))))))
3142 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3143 Run all custom agenda commands that have a file argument.
3145 \(fn &rest PARAMETERS)" nil t)
3146 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3148 (defvar org-agenda-current-span nil
3149 "The current span used in the agenda view.") ; local variable in the agenda buffer
3150 (defun org-agenda-mark-header-line (pos)
3151 "Mark the line at POS as an agenda structure header."
3152 (save-excursion
3153 (goto-char pos)
3154 (put-text-property (point-at-bol) (point-at-eol)
3155 'org-agenda-structural-header t)
3156 (when org-agenda-title-append
3157 (put-text-property (point-at-bol) (point-at-eol)
3158 'org-agenda-title-append org-agenda-title-append))))
3160 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3161 (defvar org-agenda-write-buffer-name "Agenda View")
3162 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3163 "Write the current buffer (an agenda view) as a file.
3164 Depending on the extension of the file name, plain text (.txt),
3165 HTML (.html or .htm) or Postscript (.ps) is produced.
3166 If the extension is .ics, run icalendar export over all files used
3167 to construct the agenda and limit the export to entries listed in the
3168 agenda now.
3169 With prefix argument OPEN, open the new file immediately.
3170 If NOSETTINGS is given, do not scope the settings of
3171 `org-agenda-exporter-settings' into the export commands. This is used when
3172 the settings have already been scoped and we do not wish to overrule other,
3173 higher priority settings.
3174 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3175 (interactive "FWrite agenda to file: \nP")
3176 (if (not (file-writable-p file))
3177 (error "Cannot write agenda to file %s" file))
3178 (org-let (if nosettings nil org-agenda-exporter-settings)
3179 '(save-excursion
3180 (save-window-excursion
3181 (org-agenda-mark-filtered-text)
3182 (let ((bs (copy-sequence (buffer-string))) beg)
3183 (org-agenda-unmark-filtered-text)
3184 (with-temp-buffer
3185 (rename-buffer org-agenda-write-buffer-name t)
3186 (set-buffer-modified-p nil)
3187 (insert bs)
3188 (org-agenda-remove-marked-text 'org-filtered)
3189 (while (setq beg (text-property-any (point-min) (point-max)
3190 'org-filtered t))
3191 (delete-region
3192 beg (or (next-single-property-change beg 'org-filtered)
3193 (point-max))))
3194 (run-hooks 'org-agenda-before-write-hook)
3195 (cond
3196 ((org-bound-and-true-p org-mobile-creating-agendas)
3197 (org-mobile-write-agenda-for-mobile file))
3198 ((string-match "\\.html?\\'" file)
3199 (require 'htmlize)
3200 (set-buffer (htmlize-buffer (current-buffer)))
3201 (when org-agenda-export-html-style
3202 ;; replace <style> section with org-agenda-export-html-style
3203 (goto-char (point-min))
3204 (kill-region (- (search-forward "<style") 6)
3205 (search-forward "</style>"))
3206 (insert org-agenda-export-html-style))
3207 (write-file file)
3208 (kill-buffer (current-buffer))
3209 (message "HTML written to %s" file))
3210 ((string-match "\\.ps\\'" file)
3211 (require 'ps-print)
3212 (ps-print-buffer-with-faces file)
3213 (message "Postscript written to %s" file))
3214 ((string-match "\\.pdf\\'" file)
3215 (require 'ps-print)
3216 (ps-print-buffer-with-faces
3217 (concat (file-name-sans-extension file) ".ps"))
3218 (call-process "ps2pdf" nil nil nil
3219 (expand-file-name
3220 (concat (file-name-sans-extension file) ".ps"))
3221 (expand-file-name file))
3222 (delete-file (concat (file-name-sans-extension file) ".ps"))
3223 (message "PDF written to %s" file))
3224 ((string-match "\\.ics\\'" file)
3225 (require 'org-icalendar)
3226 (let ((org-agenda-marker-table
3227 (org-create-marker-find-array
3228 (org-agenda-collect-markers)))
3229 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3230 (org-combined-agenda-icalendar-file file))
3231 (apply 'org-export-icalendar 'combine
3232 (org-agenda-files nil 'ifmode))))
3234 (let ((bs (buffer-string)))
3235 (find-file file)
3236 (erase-buffer)
3237 (insert bs)
3238 (save-buffer 0)
3239 (kill-buffer (current-buffer))
3240 (message "Plain text written to %s" file))))))))
3241 (set-buffer (or agenda-bufname
3242 (and (org-called-interactively-p 'any) (buffer-name))
3243 org-agenda-buffer-name)))
3244 (when open (org-open-file file)))
3246 (defvar org-agenda-tag-filter-overlays nil)
3247 (defvar org-agenda-cat-filter-overlays nil)
3249 (defun org-agenda-mark-filtered-text ()
3250 "Mark all text hidden by filtering with a text property."
3251 (let ((inhibit-read-only t))
3252 (mapc
3253 (lambda (o)
3254 (when (equal (overlay-buffer o) (current-buffer))
3255 (put-text-property
3256 (overlay-start o) (overlay-end o)
3257 'org-filtered t)))
3258 (append org-agenda-tag-filter-overlays
3259 org-agenda-cat-filter-overlays))))
3261 (defun org-agenda-unmark-filtered-text ()
3262 "Remove the filtering text property."
3263 (let ((inhibit-read-only t))
3264 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3266 (defun org-agenda-remove-marked-text (property &optional value)
3267 "Delete all text marked with VALUE of PROPERTY.
3268 VALUE defaults to t."
3269 (let (beg)
3270 (setq value (or value t))
3271 (while (setq beg (text-property-any (point-min) (point-max)
3272 property value))
3273 (delete-region
3274 beg (or (next-single-property-change beg 'org-filtered)
3275 (point-max))))))
3277 (defun org-agenda-add-entry-text ()
3278 "Add entry text to agenda lines.
3279 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3280 entry text following headings shown in the agenda.
3281 Drawers will be excluded, also the line with scheduling/deadline info."
3282 (when (and (> org-agenda-add-entry-text-maxlines 0)
3283 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3284 (let (m txt)
3285 (goto-char (point-min))
3286 (while (not (eobp))
3287 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3288 (beginning-of-line 2)
3289 (setq txt (org-agenda-get-some-entry-text
3290 m org-agenda-add-entry-text-maxlines " > "))
3291 (end-of-line 1)
3292 (if (string-match "\\S-" txt)
3293 (insert "\n" txt)
3294 (or (eobp) (forward-char 1))))))))
3296 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3297 &rest keep)
3298 "Extract entry text from MARKER, at most N-LINES lines.
3299 This will ignore drawers etc, just get the text.
3300 If INDENT is given, prefix every line with this string. If KEEP is
3301 given, it is a list of symbols, defining stuff that should not be
3302 removed from the entry content. Currently only `planning' is allowed here."
3303 (let (txt drawer-re kwd-time-re ind)
3304 (save-excursion
3305 (with-current-buffer (marker-buffer marker)
3306 (if (not (derived-mode-p 'org-mode))
3307 (setq txt "")
3308 (save-excursion
3309 (save-restriction
3310 (widen)
3311 (goto-char marker)
3312 (end-of-line 1)
3313 (setq txt (buffer-substring
3314 (min (1+ (point)) (point-max))
3315 (progn (outline-next-heading) (point)))
3316 drawer-re org-drawer-regexp
3317 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3318 ".*\n?"))
3319 (with-temp-buffer
3320 (insert txt)
3321 (when org-agenda-add-entry-text-descriptive-links
3322 (goto-char (point-min))
3323 (while (org-activate-bracket-links (point-max))
3324 (add-text-properties (match-beginning 0) (match-end 0)
3325 '(face org-link))))
3326 (goto-char (point-min))
3327 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3328 (set-text-properties (match-beginning 0) (match-end 0)
3329 nil))
3330 (goto-char (point-min))
3331 (while (re-search-forward drawer-re nil t)
3332 (delete-region
3333 (match-beginning 0)
3334 (progn (re-search-forward
3335 "^[ \t]*:END:.*\n?" nil 'move)
3336 (point))))
3337 (unless (member 'planning keep)
3338 (goto-char (point-min))
3339 (while (re-search-forward kwd-time-re nil t)
3340 (replace-match "")))
3341 (goto-char (point-min))
3342 (when org-agenda-entry-text-exclude-regexps
3343 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3344 (while (setq re (pop re-list))
3345 (goto-char (point-min))
3346 (while (re-search-forward re nil t)
3347 (replace-match "")))))
3348 (goto-char (point-max))
3349 (skip-chars-backward " \t\n")
3350 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3352 ;; find and remove min common indentation
3353 (goto-char (point-min))
3354 (untabify (point-min) (point-max))
3355 (setq ind (org-get-indentation))
3356 (while (not (eobp))
3357 (unless (looking-at "[ \t]*$")
3358 (setq ind (min ind (org-get-indentation))))
3359 (beginning-of-line 2))
3360 (goto-char (point-min))
3361 (while (not (eobp))
3362 (unless (looking-at "[ \t]*$")
3363 (move-to-column ind)
3364 (delete-region (point-at-bol) (point)))
3365 (beginning-of-line 2))
3367 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3369 (goto-char (point-min))
3370 (when indent
3371 (while (and (not (eobp)) (re-search-forward "^" nil t))
3372 (replace-match indent t t)))
3373 (goto-char (point-min))
3374 (while (looking-at "[ \t]*\n") (replace-match ""))
3375 (goto-char (point-max))
3376 (when (> (org-current-line)
3377 n-lines)
3378 (org-goto-line (1+ n-lines))
3379 (backward-char 1))
3380 (setq txt (buffer-substring (point-min) (point)))))))))
3381 txt))
3383 (defun org-agenda-collect-markers ()
3384 "Collect the markers pointing to entries in the agenda buffer."
3385 (let (m markers)
3386 (save-excursion
3387 (goto-char (point-min))
3388 (while (not (eobp))
3389 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3390 (org-get-at-bol 'org-marker)))
3391 (push m markers))
3392 (beginning-of-line 2)))
3393 (nreverse markers)))
3395 (defun org-create-marker-find-array (marker-list)
3396 "Create a alist of files names with all marker positions in that file."
3397 (let (f tbl m a p)
3398 (while (setq m (pop marker-list))
3399 (setq p (marker-position m)
3400 f (buffer-file-name (or (buffer-base-buffer
3401 (marker-buffer m))
3402 (marker-buffer m))))
3403 (if (setq a (assoc f tbl))
3404 (push (marker-position m) (cdr a))
3405 (push (list f p) tbl)))
3406 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3407 tbl)))
3409 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3410 (defun org-check-agenda-marker-table ()
3411 "Check of the current entry is on the marker list."
3412 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3414 (and (setq a (assoc file org-agenda-marker-table))
3415 (save-match-data
3416 (save-excursion
3417 (org-back-to-heading t)
3418 (member (point) (cdr a)))))))
3420 (defun org-check-for-org-mode ()
3421 "Make sure current buffer is in org-mode. Error if not."
3422 (or (derived-mode-p 'org-mode)
3423 (error "Cannot execute org-mode agenda command on buffer in %s"
3424 major-mode)))
3426 ;;; Agenda prepare and finalize
3428 (defvar org-agenda-multi nil) ; dynamically scoped
3429 (defvar org-agenda-pre-window-conf nil)
3430 (defvar org-agenda-columns-active nil)
3431 (defvar org-agenda-name nil)
3432 (defvar org-agenda-tag-filter nil)
3433 (defvar org-agenda-category-filter nil)
3434 (defvar org-agenda-top-category-filter nil)
3435 (defvar org-agenda-tag-filter-while-redo nil)
3436 (defvar org-agenda-tag-filter-preset nil
3437 "A preset of the tags filter used for secondary agenda filtering.
3438 This must be a list of strings, each string must be a single tag preceded
3439 by \"+\" or \"-\".
3440 This variable should not be set directly, but agenda custom commands can
3441 bind it in the options section. The preset filter is a global property of
3442 the entire agenda view. In a block agenda, it will not work reliably to
3443 define a filter for one of the individual blocks. You need to set it in
3444 the global options and expect it to be applied to the entire view.")
3446 (defvar org-agenda-category-filter-preset nil
3447 "A preset of the category filter used for secondary agenda filtering.
3448 This must be a list of strings, each string must be a single category
3449 preceded by \"+\" or \"-\".
3450 This variable should not be set directly, but agenda custom commands can
3451 bind it in the options section. The preset filter is a global property of
3452 the entire agenda view. In a block agenda, it will not work reliably to
3453 define a filter for one of the individual blocks. You need to set it in
3454 the global options and expect it to be applied to the entire view.")
3457 (defun org-agenda-use-sticky-p ()
3458 "Return non-nil if an agenda buffer named
3459 `org-agenda-buffer-name' exists and should be shown instead of
3460 generating a new one."
3461 (and
3462 ;; turned off by user
3463 org-agenda-sticky
3464 ;; For multi-agenda buffer already exists
3465 (not org-agenda-multi)
3466 ;; buffer found
3467 (get-buffer org-agenda-buffer-name)
3468 ;; C-u parameter is same as last call
3469 (with-current-buffer (get-buffer org-agenda-buffer-name)
3470 (and
3471 (equal current-prefix-arg
3472 org-agenda-last-prefix-arg)
3473 ;; In case user turned stickiness on, while having existing
3474 ;; Agenda buffer active, don't reuse that buffer, because it
3475 ;; does not have org variables local
3476 org-agenda-this-buffer-is-sticky))))
3478 (defun org-agenda-prepare-window (abuf)
3479 "Setup agenda buffer in the window."
3480 (let* ((awin (get-buffer-window abuf))
3481 wconf)
3482 (cond
3483 ((equal (current-buffer) abuf) nil)
3484 (awin (select-window awin))
3485 ((not (setq wconf (current-window-configuration))))
3486 ((equal org-agenda-window-setup 'current-window)
3487 (org-pop-to-buffer-same-window abuf))
3488 ((equal org-agenda-window-setup 'other-window)
3489 (org-switch-to-buffer-other-window abuf))
3490 ((equal org-agenda-window-setup 'other-frame)
3491 (switch-to-buffer-other-frame abuf))
3492 ((equal org-agenda-window-setup 'reorganize-frame)
3493 (delete-other-windows)
3494 (org-switch-to-buffer-other-window abuf)))
3495 ;; additional test in case agenda is invoked from within agenda
3496 ;; buffer via elisp link
3497 (unless (equal (current-buffer) abuf)
3498 (org-pop-to-buffer-same-window abuf))
3499 (setq org-agenda-pre-window-conf
3500 (or org-agenda-pre-window-conf wconf))))
3502 (defun org-agenda-prepare (&optional name)
3503 (if (org-agenda-use-sticky-p)
3504 (progn
3505 ;; Popup existing buffer
3506 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3507 (message "Sticky Agenda buffer, use `r' to refresh")
3508 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3509 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3510 (setq org-todo-keywords-for-agenda nil)
3511 (setq org-drawers-for-agenda nil)
3512 (unless org-agenda-persistent-filter
3513 (setq org-agenda-tag-filter nil
3514 org-agenda-category-filter nil))
3515 (put 'org-agenda-tag-filter :preset-filter
3516 org-agenda-tag-filter-preset)
3517 (put 'org-agenda-category-filter :preset-filter
3518 org-agenda-category-filter-preset)
3519 (if org-agenda-multi
3520 (progn
3521 (setq buffer-read-only nil)
3522 (goto-char (point-max))
3523 (unless (or (bobp) org-agenda-compact-blocks
3524 (not org-agenda-block-separator))
3525 (insert "\n"
3526 (if (stringp org-agenda-block-separator)
3527 org-agenda-block-separator
3528 (make-string (window-width) org-agenda-block-separator))
3529 "\n"))
3530 (narrow-to-region (point) (point-max)))
3531 (setq org-done-keywords-for-agenda nil)
3533 ;; Setting any org variables that are in org-agenda-local-vars
3534 ;; list need to be done after the prepare call
3535 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3536 (setq buffer-read-only nil)
3537 (org-agenda-reset-markers)
3538 (let ((inhibit-read-only t)) (erase-buffer))
3539 (org-agenda-mode)
3540 (setq org-agenda-buffer (current-buffer))
3541 (setq org-agenda-contributing-files nil)
3542 (setq org-agenda-columns-active nil)
3543 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3544 (setq org-todo-keywords-for-agenda
3545 (org-uniquify org-todo-keywords-for-agenda))
3546 (setq org-done-keywords-for-agenda
3547 (org-uniquify org-done-keywords-for-agenda))
3548 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3549 (setq org-agenda-last-prefix-arg current-prefix-arg)
3550 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3551 (and name (not org-agenda-name)
3552 (org-set-local 'org-agenda-name name)))
3553 (setq buffer-read-only nil)))
3555 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3556 (defun org-agenda-finalize ()
3557 "Finishing touch for the agenda buffer, called just before displaying it."
3558 (unless org-agenda-multi
3559 (save-excursion
3560 (let ((inhibit-read-only t))
3561 (goto-char (point-min))
3562 (save-excursion
3563 (while (org-activate-bracket-links (point-max))
3564 (add-text-properties (match-beginning 0) (match-end 0)
3565 '(face org-link))))
3566 (save-excursion
3567 (while (org-activate-plain-links (point-max))
3568 (add-text-properties (match-beginning 0) (match-end 0)
3569 '(face org-link))))
3570 (unless (eq org-agenda-remove-tags t)
3571 (org-agenda-align-tags))
3572 (unless org-agenda-with-colors
3573 (remove-text-properties (point-min) (point-max) '(face nil)))
3574 (if (and (boundp 'org-agenda-overriding-columns-format)
3575 org-agenda-overriding-columns-format)
3576 (org-set-local 'org-agenda-overriding-columns-format
3577 org-agenda-overriding-columns-format))
3578 (if (and (boundp 'org-agenda-view-columns-initially)
3579 org-agenda-view-columns-initially)
3580 (org-agenda-columns))
3581 (when org-agenda-fontify-priorities
3582 (org-agenda-fontify-priorities))
3583 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3584 (org-agenda-dim-blocked-tasks))
3585 ;; We need to widen when `org-agenda-finalize' is called from
3586 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3587 (when org-clock-current-task
3588 (save-restriction
3589 (widen)
3590 (org-agenda-mark-clocking-task)))
3591 (when org-agenda-entry-text-mode
3592 (org-agenda-entry-text-hide)
3593 (org-agenda-entry-text-show))
3594 (if (and (functionp 'org-habit-insert-consistency-graphs)
3595 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3596 (org-habit-insert-consistency-graphs))
3597 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3598 (unless (or (eq org-agenda-show-inherited-tags 'always)
3599 (and (listp org-agenda-show-inherited-tags)
3600 (memq org-agenda-type org-agenda-show-inherited-tags))
3601 (and (eq org-agenda-show-inherited-tags t)
3602 (or (eq org-agenda-use-tag-inheritance t)
3603 (and (listp org-agenda-use-tag-inheritance)
3604 (not (memq org-agenda-type
3605 org-agenda-use-tag-inheritance))))))
3606 (let (mrk)
3607 (save-excursion
3608 (goto-char (point-min))
3609 (while (equal (forward-line) 0)
3610 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3611 (get-text-property (point) 'org-hd-marker)))
3612 (put-text-property (point-at-bol) (point-at-eol)
3613 'tags (org-with-point-at mrk
3614 (delete-dups
3615 (mapcar 'downcase (org-get-tags-at))))))))))
3616 (run-hooks 'org-agenda-finalize-hook)
3617 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3618 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3619 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3620 (org-agenda-filter-apply org-agenda-category-filter 'category))
3621 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3623 (defun org-agenda-mark-clocking-task ()
3624 "Mark the current clock entry in the agenda if it is present."
3625 (mapc (lambda (o)
3626 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3627 (delete-overlay o)))
3628 (overlays-in (point-min) (point-max)))
3629 (when (marker-buffer org-clock-hd-marker)
3630 (save-excursion
3631 (goto-char (point-min))
3632 (let (s ov)
3633 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3634 (goto-char s)
3635 (when (equal (org-get-at-bol 'org-hd-marker)
3636 org-clock-hd-marker)
3637 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3638 (overlay-put ov 'type 'org-agenda-clocking)
3639 (overlay-put ov 'face 'org-agenda-clocking)
3640 (overlay-put ov 'help-echo
3641 "The clock is running in this item")))))))
3643 (defun org-agenda-fontify-priorities ()
3644 "Make highest priority lines bold, and lowest italic."
3645 (interactive)
3646 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3647 (delete-overlay o)))
3648 (overlays-in (point-min) (point-max)))
3649 (save-excursion
3650 (let ((inhibit-read-only t)
3651 b e p ov h l)
3652 (goto-char (point-min))
3653 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3654 (setq h (or (get-char-property (point) 'org-highest-priority)
3655 org-highest-priority)
3656 l (or (get-char-property (point) 'org-lowest-priority)
3657 org-lowest-priority)
3658 p (string-to-char (match-string 1))
3659 b (match-beginning 0)
3660 e (if (eq org-agenda-fontify-priorities 'cookies)
3661 (match-end 0)
3662 (point-at-eol))
3663 ov (make-overlay b e))
3664 (overlay-put
3665 ov 'face
3666 (cond ((org-face-from-face-or-color
3667 'priority nil
3668 (cdr (assoc p org-priority-faces))))
3669 ((and (listp org-agenda-fontify-priorities)
3670 (org-face-from-face-or-color
3671 'priority nil
3672 (cdr (assoc p org-agenda-fontify-priorities)))))
3673 ((equal p l) 'italic)
3674 ((equal p h) 'bold)))
3675 (overlay-put ov 'org-type 'org-priority)))))
3677 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3678 (interactive "P")
3679 "Dim currently blocked TODO's in the agenda display."
3680 (message "Dim or hide blocked tasks...")
3681 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3682 (delete-overlay o)))
3683 (overlays-in (point-min) (point-max)))
3684 (save-excursion
3685 (let ((inhibit-read-only t)
3686 (org-depend-tag-blocked nil)
3687 (invis (or (not (null invisible))
3688 (eq org-agenda-dim-blocked-tasks 'invisible)))
3689 org-blocked-by-checkboxes
3690 invis1 b e p ov h l)
3691 (goto-char (point-min))
3692 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3693 (and pos (goto-char (1+ pos))))
3694 (setq org-blocked-by-checkboxes nil invis1 invis)
3695 (let ((marker (org-get-at-bol 'org-hd-marker)))
3696 (when (and marker
3697 (with-current-buffer (marker-buffer marker)
3698 (save-excursion (goto-char marker)
3699 (org-entry-blocked-p))))
3700 (if org-blocked-by-checkboxes (setq invis1 nil))
3701 (setq b (if invis1
3702 (max (point-min) (1- (point-at-bol)))
3703 (point-at-bol))
3704 e (point-at-eol)
3705 ov (make-overlay b e))
3706 (if invis1
3707 (overlay-put ov 'invisible t)
3708 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3709 (overlay-put ov 'org-type 'org-blocked-todo))))))
3710 (message "Dim or hide blocked tasks...done"))
3712 (defvar org-agenda-skip-function nil
3713 "Function to be called at each match during agenda construction.
3714 If this function returns nil, the current match should not be skipped.
3715 Otherwise, the function must return a position from where the search
3716 should be continued.
3717 This may also be a Lisp form, it will be evaluated.
3718 Never set this variable using `setq' or so, because then it will apply
3719 to all future agenda commands. If you do want a global skipping condition,
3720 use the option `org-agenda-skip-function-global' instead.
3721 The correct usage for `org-agenda-skip-function' is to bind it with
3722 `let' to scope it dynamically into the agenda-constructing command.
3723 A good way to set it is through options in `org-agenda-custom-commands'.")
3725 (defun org-agenda-skip ()
3726 "Throw to `:skip' in places that should be skipped.
3727 Also moves point to the end of the skipped region, so that search can
3728 continue from there."
3729 (let ((p (point-at-bol)) to)
3730 (when (or
3731 (save-excursion (goto-char p) (looking-at comment-start-skip))
3732 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3733 (get-text-property p :org-archived)
3734 (org-end-of-subtree t))
3735 (and org-agenda-skip-comment-trees
3736 (get-text-property p :org-comment)
3737 (org-end-of-subtree t))
3738 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3739 (org-agenda-skip-eval org-agenda-skip-function)))
3740 (goto-char to))
3741 (org-in-src-block-p t))
3742 (throw :skip t))))
3744 (defun org-agenda-skip-eval (form)
3745 "If FORM is a function or a list, call (or eval) is and return result.
3746 `save-excursion' and `save-match-data' are wrapped around the call, so point
3747 and match data are returned to the previous state no matter what these
3748 functions do."
3749 (let (fp)
3750 (and form
3751 (or (setq fp (functionp form))
3752 (consp form))
3753 (save-excursion
3754 (save-match-data
3755 (if fp
3756 (funcall form)
3757 (eval form)))))))
3759 (defvar org-agenda-markers nil
3760 "List of all currently active markers created by `org-agenda'.")
3761 (defvar org-agenda-last-marker-time (org-float-time)
3762 "Creation time of the last agenda marker.")
3764 (defun org-agenda-new-marker (&optional pos)
3765 "Return a new agenda marker.
3766 Org-mode keeps a list of these markers and resets them when they are
3767 no longer in use."
3768 (let ((m (copy-marker (or pos (point)))))
3769 (setq org-agenda-last-marker-time (org-float-time))
3770 (if org-agenda-buffer
3771 (with-current-buffer org-agenda-buffer
3772 (push m org-agenda-markers))
3773 (push m org-agenda-markers))
3776 (defun org-agenda-reset-markers ()
3777 "Reset markers created by `org-agenda'."
3778 (while org-agenda-markers
3779 (move-marker (pop org-agenda-markers) nil)))
3781 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3782 "Save relative positions of markers in region.
3783 This check for agenda markers in all agenda buffers currently active."
3784 (dolist (buf (buffer-list))
3785 (with-current-buffer buf
3786 (when (eq major-mode 'org-agenda-mode)
3787 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3788 org-agenda-markers)))))
3790 ;;; Entry text mode
3792 (defun org-agenda-entry-text-show-here ()
3793 "Add some text from the entry as context to the current line."
3794 (let (m txt o)
3795 (setq m (org-get-at-bol 'org-hd-marker))
3796 (unless (marker-buffer m)
3797 (error "No marker points to an entry here"))
3798 (setq txt (concat "\n" (org-no-properties
3799 (org-agenda-get-some-entry-text
3800 m org-agenda-entry-text-maxlines " > "))))
3801 (when (string-match "\\S-" txt)
3802 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3803 (overlay-put o 'evaporate t)
3804 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3805 (overlay-put o 'after-string txt))))
3807 (defun org-agenda-entry-text-show ()
3808 "Add entry context for all agenda lines."
3809 (interactive)
3810 (save-excursion
3811 (goto-char (point-max))
3812 (beginning-of-line 1)
3813 (while (not (bobp))
3814 (when (org-get-at-bol 'org-hd-marker)
3815 (org-agenda-entry-text-show-here))
3816 (beginning-of-line 0))))
3818 (defun org-agenda-entry-text-hide ()
3819 "Remove any shown entry context."
3820 (delq nil
3821 (mapcar (lambda (o)
3822 (if (eq (overlay-get o 'org-overlay-type)
3823 'agenda-entry-content)
3824 (progn (delete-overlay o) t)))
3825 (overlays-in (point-min) (point-max)))))
3827 (defun org-agenda-get-day-face (date)
3828 "Return the face DATE should be displayed with."
3829 (or (and (functionp org-agenda-day-face-function)
3830 (funcall org-agenda-day-face-function date))
3831 (cond ((org-agenda-todayp date)
3832 'org-agenda-date-today)
3833 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3834 'org-agenda-date-weekend)
3835 (t 'org-agenda-date))))
3837 ;;; Agenda timeline
3839 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3841 (defun org-timeline (&optional dotodo)
3842 "Show a time-sorted view of the entries in the current org file.
3843 Only entries with a time stamp of today or later will be listed. With
3844 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3845 under the current date.
3846 If the buffer contains an active region, only check the region for
3847 dates."
3848 (interactive "P")
3849 (let* ((dopast t)
3850 (org-agenda-show-log-scoped org-agenda-show-log)
3851 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3852 (current-buffer))))
3853 (date (calendar-current-date))
3854 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3855 (end (if (org-region-active-p) (region-end) (point-max)))
3856 (day-numbers (org-get-all-dates
3857 beg end 'no-ranges
3858 t org-agenda-show-log-scoped ; always include today
3859 org-timeline-show-empty-dates))
3860 (org-deadline-warning-days 0)
3861 (org-agenda-only-exact-dates t)
3862 (today (org-today))
3863 (past t)
3864 args
3865 s e rtn d emptyp)
3866 (setq org-agenda-redo-command
3867 (list 'progn
3868 (list 'org-switch-to-buffer-other-window (current-buffer))
3869 (list 'org-timeline (list 'quote dotodo))))
3870 (if (not dopast)
3871 ;; Remove past dates from the list of dates.
3872 (setq day-numbers (delq nil (mapcar (lambda(x)
3873 (if (>= x today) x nil))
3874 day-numbers))))
3875 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3876 (org-compile-prefix-format 'timeline)
3877 (org-set-sorting-strategy 'timeline)
3878 (if org-agenda-show-log-scoped (push :closed args))
3879 (push :timestamp args)
3880 (push :deadline args)
3881 (push :scheduled args)
3882 (push :sexp args)
3883 (if dotodo (push :todo args))
3884 (insert "Timeline of file " entry "\n")
3885 (add-text-properties (point-min) (point)
3886 (list 'face 'org-agenda-structure))
3887 (org-agenda-mark-header-line (point-min))
3888 (while (setq d (pop day-numbers))
3889 (if (and (listp d) (eq (car d) :omitted))
3890 (progn
3891 (setq s (point))
3892 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3893 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3894 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3895 (if (and (>= d today)
3896 dopast
3897 past)
3898 (progn
3899 (setq past nil)
3900 (insert (make-string 79 ?-) "\n")))
3901 (setq date (calendar-gregorian-from-absolute d))
3902 (setq s (point))
3903 (setq rtn (and (not emptyp)
3904 (apply 'org-agenda-get-day-entries entry
3905 date args)))
3906 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3907 (progn
3908 (insert
3909 (if (stringp org-agenda-format-date)
3910 (format-time-string org-agenda-format-date
3911 (org-time-from-absolute date))
3912 (funcall org-agenda-format-date date))
3913 "\n")
3914 (put-text-property s (1- (point)) 'face
3915 (org-agenda-get-day-face date))
3916 (put-text-property s (1- (point)) 'org-date-line t)
3917 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3918 (if (equal d today)
3919 (put-text-property s (1- (point)) 'org-today t))
3920 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3921 (put-text-property s (1- (point)) 'day d)))))
3922 (goto-char (point-min))
3923 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3924 (point-min)))
3925 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3926 (org-agenda-finalize)
3927 (setq buffer-read-only t)))
3929 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3930 "Return a list of all relevant day numbers from BEG to END buffer positions.
3931 If NO-RANGES is non-nil, include only the start and end dates of a range,
3932 not every single day in the range. If FORCE-TODAY is non-nil, make
3933 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3934 inactive time stamps (those in square brackets) are included.
3935 When EMPTY is non-nil, also include days without any entries."
3936 (let ((re (concat
3937 (if pre-re pre-re "")
3938 (if inactive org-ts-regexp-both org-ts-regexp)))
3939 dates dates1 date day day1 day2 ts1 ts2 pos)
3940 (if force-today
3941 (setq dates (list (org-today))))
3942 (save-excursion
3943 (goto-char beg)
3944 (while (re-search-forward re end t)
3945 (setq day (time-to-days (org-time-string-to-time
3946 (substring (match-string 1) 0 10)
3947 (current-buffer) (match-beginning 0))))
3948 (or (memq day dates) (push day dates)))
3949 (unless no-ranges
3950 (goto-char beg)
3951 (while (re-search-forward org-tr-regexp end t)
3952 (setq pos (match-beginning 0))
3953 (setq ts1 (substring (match-string 1) 0 10)
3954 ts2 (substring (match-string 2) 0 10)
3955 day1 (time-to-days (org-time-string-to-time
3956 ts1 (current-buffer) pos))
3957 day2 (time-to-days (org-time-string-to-time
3958 ts2 (current-buffer) pos)))
3959 (while (< (setq day1 (1+ day1)) day2)
3960 (or (memq day1 dates) (push day1 dates)))))
3961 (setq dates (sort dates '<))
3962 (when empty
3963 (while (setq day (pop dates))
3964 (setq day2 (car dates))
3965 (push day dates1)
3966 (when (and day2 empty)
3967 (if (or (eq empty t)
3968 (and (numberp empty) (<= (- day2 day) empty)))
3969 (while (< (setq day (1+ day)) day2)
3970 (push (list day) dates1))
3971 (push (cons :omitted (- day2 day)) dates1))))
3972 (setq dates (nreverse dates1)))
3973 dates)))
3975 ;;; Agenda Daily/Weekly
3977 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3978 "Start day for the agenda view.
3979 Custom commands can set this variable in the options section.")
3980 (defvar org-starting-day nil) ; local variable in the agenda buffer
3981 (defvar org-arg-loc nil) ; local variable
3983 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3984 "List of types searched for when creating the daily/weekly agenda.
3985 This variable is a list of symbols that controls the types of
3986 items that appear in the daily/weekly agenda. Allowed symbols in this
3987 list are are
3989 :timestamp List items containing a date stamp or date range matching
3990 the selected date. This includes sexp entries in
3991 angular brackets.
3993 :sexp List entries resulting from plain diary-like sexps.
3995 :deadline List deadline due on that date. When the date is today,
3996 also list any deadlines past due, or due within
3997 `org-deadline-warning-days'. `:deadline' must appear before
3998 `:scheduled' if the setting of
3999 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
4000 any effect.
4002 :scheduled List all items which are scheduled for the given date.
4003 The diary for *today* also contains items which were
4004 scheduled earlier and are not yet marked DONE.
4006 By default, all four types are turned on.
4008 Never set this variable globally using `setq', because then it
4009 will apply to all future agenda commands. Instead, bind it with
4010 `let' to scope it dynamically into the agenda-constructing
4011 command. A good way to set it is through options in
4012 `org-agenda-custom-commands'. For a more flexible (though
4013 somewhat less efficient) way of determining what is included in
4014 the daily/weekly agenda, see `org-agenda-skip-function'.")
4016 (defvar org-agenda-buffer-tmp-name nil)
4017 ;;;###autoload
4018 (defun org-agenda-list (&optional arg start-day span)
4019 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4020 The view will be for the current day or week, but from the overview buffer
4021 you will be able to go to other days/weeks.
4023 With a numeric prefix argument in an interactive call, the agenda will
4024 span ARG days. Lisp programs should instead specify SPAN to change
4025 the number of days. SPAN defaults to `org-agenda-span'.
4027 START-DAY defaults to TODAY, or to the most recent match for the weekday
4028 given in `org-agenda-start-on-weekday'."
4029 (interactive "P")
4030 (if org-agenda-overriding-arguments
4031 (setq arg (car org-agenda-overriding-arguments)
4032 start-day (nth 1 org-agenda-overriding-arguments)
4033 span (nth 2 org-agenda-overriding-arguments)))
4034 (if (and (integerp arg) (> arg 0))
4035 (setq span arg arg nil))
4036 (catch 'exit
4037 (setq org-agenda-buffer-name
4038 (or org-agenda-buffer-tmp-name
4039 (if org-agenda-sticky
4040 (cond ((and org-keys (stringp org-match))
4041 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4042 (org-keys
4043 (format "*Org Agenda(%s)*" org-keys))
4044 (t "*Org Agenda(a)*")))
4045 org-agenda-buffer-name))
4046 (org-agenda-prepare "Day/Week")
4047 (setq start-day (or start-day org-agenda-start-day))
4048 (if (stringp start-day)
4049 ;; Convert to an absolute day number
4050 (setq start-day (time-to-days (org-read-date nil t start-day))))
4051 (org-compile-prefix-format 'agenda)
4052 (org-set-sorting-strategy 'agenda)
4053 (let* ((span (org-agenda-ndays-to-span
4054 (or span org-agenda-ndays org-agenda-span)))
4055 (today (org-today))
4056 (sd (or start-day today))
4057 (ndays (org-agenda-span-to-ndays span sd))
4058 (org-agenda-start-on-weekday
4059 (if (eq ndays 7)
4060 org-agenda-start-on-weekday))
4061 (thefiles (org-agenda-files nil 'ifmode))
4062 (files thefiles)
4063 (start (if (or (null org-agenda-start-on-weekday)
4064 (< ndays 7))
4066 (let* ((nt (calendar-day-of-week
4067 (calendar-gregorian-from-absolute sd)))
4068 (n1 org-agenda-start-on-weekday)
4069 (d (- nt n1)))
4070 (- sd (+ (if (< d 0) 7 0) d)))))
4071 (day-numbers (list start))
4072 (day-cnt 0)
4073 (inhibit-redisplay (not debug-on-error))
4074 (org-agenda-show-log-scoped org-agenda-show-log)
4075 s e rtn rtnall file date d start-pos end-pos todayp
4076 clocktable-start clocktable-end filter)
4077 (setq org-agenda-redo-command
4078 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4079 (dotimes (n (1- ndays))
4080 (push (1+ (car day-numbers)) day-numbers))
4081 (setq day-numbers (nreverse day-numbers))
4082 (setq clocktable-start (car day-numbers)
4083 clocktable-end (1+ (or (org-last day-numbers) 0)))
4084 (org-set-local 'org-starting-day (car day-numbers))
4085 (org-set-local 'org-arg-loc arg)
4086 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4087 (unless org-agenda-compact-blocks
4088 (let* ((d1 (car day-numbers))
4089 (d2 (org-last day-numbers))
4090 (w1 (org-days-to-iso-week d1))
4091 (w2 (org-days-to-iso-week d2)))
4092 (setq s (point))
4093 (if org-agenda-overriding-header
4094 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4095 nil 'face 'org-agenda-structure) "\n")
4096 (insert (org-agenda-span-name span)
4097 "-agenda"
4098 (if (< (- d2 d1) 350)
4099 (if (= w1 w2)
4100 (format " (W%02d)" w1)
4101 (format " (W%02d-W%02d)" w1 w2))
4103 ":\n")))
4104 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4105 'org-date-line t))
4106 (org-agenda-mark-header-line s))
4107 (while (setq d (pop day-numbers))
4108 (setq date (calendar-gregorian-from-absolute d)
4109 s (point))
4110 (if (or (setq todayp (= d today))
4111 (and (not start-pos) (= d sd)))
4112 (setq start-pos (point))
4113 (if (and start-pos (not end-pos))
4114 (setq end-pos (point))))
4115 (setq files thefiles
4116 rtnall nil)
4117 (while (setq file (pop files))
4118 (catch 'nextfile
4119 (org-check-agenda-file file)
4120 (let ((org-agenda-entry-types org-agenda-entry-types))
4121 (unless org-agenda-include-deadlines
4122 (setq org-agenda-entry-types
4123 (delq :deadline org-agenda-entry-types)))
4124 (cond
4125 ((memq org-agenda-show-log-scoped '(only clockcheck))
4126 (setq rtn (org-agenda-get-day-entries
4127 file date :closed)))
4128 (org-agenda-show-log-scoped
4129 (setq rtn (apply 'org-agenda-get-day-entries
4130 file date
4131 (append '(:closed) org-agenda-entry-types))))
4133 (setq rtn (apply 'org-agenda-get-day-entries
4134 file date
4135 org-agenda-entry-types)))))
4136 (setq rtnall (append rtnall rtn)))) ;; all entries
4137 (if org-agenda-include-diary
4138 (let ((org-agenda-search-headline-for-time t))
4139 (require 'diary-lib)
4140 (setq rtn (org-get-entries-from-diary date))
4141 (setq rtnall (append rtnall rtn))))
4142 (if (or rtnall org-agenda-show-all-dates)
4143 (progn
4144 (setq day-cnt (1+ day-cnt))
4145 (insert
4146 (if (stringp org-agenda-format-date)
4147 (format-time-string org-agenda-format-date
4148 (org-time-from-absolute date))
4149 (funcall org-agenda-format-date date))
4150 "\n")
4151 (put-text-property s (1- (point)) 'face
4152 (org-agenda-get-day-face date))
4153 (put-text-property s (1- (point)) 'org-date-line t)
4154 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4155 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4156 (when todayp
4157 (put-text-property s (1- (point)) 'org-today t))
4158 (setq rtnall
4159 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4160 (if rtnall (insert ;; all entries
4161 (org-agenda-finalize-entries rtnall)
4162 "\n"))
4163 (put-text-property s (1- (point)) 'day d)
4164 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4165 (when (and org-agenda-clockreport-mode clocktable-start)
4166 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4167 ;; the above line is to ensure the restricted range!
4168 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4169 tbl)
4170 (setq p (org-plist-delete p :block))
4171 (setq p (plist-put p :tstart clocktable-start))
4172 (setq p (plist-put p :tend clocktable-end))
4173 (setq p (plist-put p :scope 'agenda))
4174 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4175 (setq filter (or org-agenda-tag-filter-while-redo
4176 (get 'org-agenda-tag-filter :preset-filter))))
4177 (setq p (plist-put p :tags (mapconcat (lambda (x)
4178 (if (string-match "[<>=]" x)
4181 filter ""))))
4182 (setq tbl (apply 'org-clock-get-clocktable p))
4183 (insert tbl)))
4184 (goto-char (point-min))
4185 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4186 (unless (and (pos-visible-in-window-p (point-min))
4187 (pos-visible-in-window-p (point-max)))
4188 (goto-char (1- (point-max)))
4189 (recenter -1)
4190 (if (not (pos-visible-in-window-p (or start-pos 1)))
4191 (progn
4192 (goto-char (or start-pos 1))
4193 (recenter 1))))
4194 (goto-char (or start-pos 1))
4195 (add-text-properties (point-min) (point-max)
4196 `(org-agenda-type agenda
4197 org-last-args (,arg ,start-day ,span)
4198 org-redo-cmd ,org-agenda-redo-command
4199 org-series-cmd ,org-cmd))
4200 (if (eq org-agenda-show-log-scoped 'clockcheck)
4201 (org-agenda-show-clocking-issues))
4202 (org-agenda-finalize)
4203 (setq buffer-read-only t)
4204 (message ""))))
4206 (autoload 'org-agenda-list "org-agenda" "\
4207 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4208 The view will be for the current day or week, but from the overview buffer
4209 you will be able to go to other days/weeks.
4211 With a numeric prefix argument in an interactive call, the agenda will
4212 span ARG days. Lisp programs should instead specify SPAN to change
4213 the number of days. SPAN defaults to `org-agenda-span'.
4215 START-DAY defaults to TODAY, or to the most recent match for the weekday
4216 given in `org-agenda-start-on-weekday'.
4218 \(fn &optional ARG START-DAY SPAN)" t nil)
4220 (defun org-agenda-ndays-to-span (n)
4221 "Return a span symbol for a span of N days, or N if none matches."
4222 (cond ((symbolp n) n)
4223 ((= n 1) 'day)
4224 ((= n 7) 'week)
4225 (t n)))
4227 (defun org-agenda-span-to-ndays (span &optional start-day)
4228 "Return ndays from SPAN, possibly starting at START-DAY."
4229 (cond ((numberp span) span)
4230 ((eq span 'day) 1)
4231 ((eq span 'week) 7)
4232 ((eq span 'month)
4233 (let ((date (calendar-gregorian-from-absolute start-day)))
4234 (calendar-last-day-of-month (car date) (caddr date))))
4235 ((eq span 'year)
4236 (let ((date (calendar-gregorian-from-absolute start-day)))
4237 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4239 (defun org-agenda-span-name (span)
4240 "Return a SPAN name."
4241 (if (null span)
4243 (if (symbolp span)
4244 (capitalize (symbol-name span))
4245 (format "%d days" span))))
4247 ;;; Agenda word search
4249 (defvar org-agenda-search-history nil)
4251 (defvar org-search-syntax-table nil
4252 "Special syntax table for org-mode search.
4253 In this table, we have single quotes not as word constituents, to
4254 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4256 (defvar org-mode-syntax-table) ; From org.el
4257 (defun org-search-syntax-table ()
4258 (unless org-search-syntax-table
4259 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4260 (modify-syntax-entry ?' "." org-search-syntax-table)
4261 (modify-syntax-entry ?` "." org-search-syntax-table))
4262 org-search-syntax-table)
4264 (defvar org-agenda-last-search-view-search-was-boolean nil)
4266 ;;;###autoload
4267 (defun org-search-view (&optional todo-only string edit-at)
4268 "Show all entries that contain a phrase or words or regular expressions.
4270 With optional prefix argument TODO-ONLY, only consider entries that are
4271 TODO entries. The argument STRING can be used to pass a default search
4272 string into this function. If EDIT-AT is non-nil, it means that the
4273 user should get a chance to edit this string, with cursor at position
4274 EDIT-AT.
4276 The search string can be viewed either as a phrase that should be found as
4277 is, or it can be broken into a number of snippets, each of which must match
4278 in a Boolean way to select an entry. The default depends on the variable
4279 `org-agenda-search-view-always-boolean'.
4280 Even if this is turned off (the default) you can always switch to
4281 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4283 The default is a direct search of the whole phrase, where each space in
4284 the search string can expand to an arbitrary amount of whitespace,
4285 including newlines.
4287 If using a Boolean search, the search string is split on whitespace and
4288 each snippet is searched separately, with logical AND to select an entry.
4289 Words prefixed with a minus must *not* occur in the entry. Words without
4290 a prefix or prefixed with a plus must occur in the entry. Matching is
4291 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4292 match whole words, not parts of a word) if
4293 `org-agenda-search-view-force-full-words' is set (default is nil).
4295 Boolean search snippets enclosed by curly braces are interpreted as
4296 regular expressions that must or (when preceded with \"-\") must not
4297 match in the entry. Snippets enclosed into double quotes will be taken
4298 as a whole, to include whitespace.
4300 - If the search string starts with an asterisk, search only in headlines.
4301 - If (possibly after the leading star) the search string starts with an
4302 exclamation mark, this also means to look at TODO entries only, an effect
4303 that can also be achieved with a prefix argument.
4304 - If (possibly after star and exclamation mark) the search string starts
4305 with a colon, this will mean that the (non-regexp) snippets of the
4306 Boolean search must match as full words.
4308 This command searches the agenda files, and in addition the files listed
4309 in `org-agenda-text-search-extra-files'."
4310 (interactive "P")
4311 (if org-agenda-overriding-arguments
4312 (setq todo-only (car org-agenda-overriding-arguments)
4313 string (nth 1 org-agenda-overriding-arguments)
4314 edit-at (nth 2 org-agenda-overriding-arguments)))
4315 (let* ((props (list 'face nil
4316 'done-face 'org-agenda-done
4317 'org-not-done-regexp org-not-done-regexp
4318 'org-todo-regexp org-todo-regexp
4319 'org-complex-heading-regexp org-complex-heading-regexp
4320 'mouse-face 'highlight
4321 'help-echo (format "mouse-2 or RET jump to location")))
4322 (full-words org-agenda-search-view-force-full-words)
4323 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4324 regexp rtn rtnall files file pos inherited-tags
4325 marker category category-pos tags c neg re boolean
4326 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4327 (unless (and (not edit-at)
4328 (stringp string)
4329 (string-match "\\S-" string))
4330 (setq string (read-string
4331 (if org-agenda-search-view-always-boolean
4332 "[+-]Word/{Regexp} ...: "
4333 "Phrase or [+-]Word/{Regexp} ...: ")
4334 (cond
4335 ((integerp edit-at) (cons string edit-at))
4336 (edit-at string))
4337 'org-agenda-search-history)))
4338 (catch 'exit
4339 (if org-agenda-sticky
4340 (setq org-agenda-buffer-name
4341 (if (stringp string)
4342 (format "*Org Agenda(%s:%s)*"
4343 (or org-keys (or (and todo-only "S") "s")) string)
4344 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4345 (org-agenda-prepare "SEARCH")
4346 (org-compile-prefix-format 'search)
4347 (org-set-sorting-strategy 'search)
4348 (setq org-agenda-redo-command
4349 (list 'org-search-view (if todo-only t nil)
4350 (list 'if 'current-prefix-arg nil string)))
4351 (setq org-agenda-query-string string)
4352 (if (equal (string-to-char string) ?*)
4353 (setq hdl-only t
4354 words (substring string 1))
4355 (setq words string))
4356 (when (equal (string-to-char words) ?!)
4357 (setq todo-only t
4358 words (substring words 1)))
4359 (when (equal (string-to-char words) ?:)
4360 (setq full-words t
4361 words (substring words 1)))
4362 (if (or org-agenda-search-view-always-boolean
4363 (member (string-to-char words) '(?- ?+ ?\{)))
4364 (setq boolean t))
4365 (setq words (org-split-string words))
4366 (let (www w)
4367 (while (setq w (pop words))
4368 (while (and (string-match "\\\\\\'" w) words)
4369 (setq w (concat (substring w 0 -1) " " (pop words))))
4370 (push w www))
4371 (setq words (nreverse www) www nil)
4372 (while (setq w (pop words))
4373 (when (and (string-match "\\`[-+]?{" w)
4374 (not (string-match "}\\'" w)))
4375 (while (and words (not (string-match "}\\'" (car words))))
4376 (setq w (concat w " " (pop words))))
4377 (setq w (concat w " " (pop words))))
4378 (push w www))
4379 (setq words (nreverse www)))
4380 (setq org-agenda-last-search-view-search-was-boolean boolean)
4381 (when boolean
4382 (let (wds w)
4383 (while (setq w (pop words))
4384 (if (or (equal (substring w 0 1) "\"")
4385 (and (> (length w) 1)
4386 (member (substring w 0 1) '("+" "-"))
4387 (equal (substring w 1 2) "\"")))
4388 (while (and words (not (equal (substring w -1) "\"")))
4389 (setq w (concat w " " (pop words)))))
4390 (and (string-match "\\`\\([-+]?\\)\"" w)
4391 (setq w (replace-match "\\1" nil nil w)))
4392 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4393 (push w wds))
4394 (setq words (nreverse wds))))
4395 (if boolean
4396 (mapc (lambda (w)
4397 (setq c (string-to-char w))
4398 (if (equal c ?-)
4399 (setq neg t w (substring w 1))
4400 (if (equal c ?+)
4401 (setq neg nil w (substring w 1))
4402 (setq neg nil)))
4403 (if (string-match "\\`{.*}\\'" w)
4404 (setq re (substring w 1 -1))
4405 (if full-words
4406 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4407 (setq re (regexp-quote (downcase w)))))
4408 (if neg (push re regexps-) (push re regexps+)))
4409 words)
4410 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4411 regexps+))
4412 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4413 (if (not regexps+)
4414 (setq regexp org-outline-regexp-bol)
4415 (setq regexp (pop regexps+))
4416 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4417 regexp))))
4418 (setq files (org-agenda-files nil 'ifmode))
4419 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4420 (pop org-agenda-text-search-extra-files)
4421 (setq files (org-add-archive-files files)))
4422 (setq files (append files org-agenda-text-search-extra-files)
4423 rtnall nil)
4424 (while (setq file (pop files))
4425 (setq ee nil)
4426 (catch 'nextfile
4427 (org-check-agenda-file file)
4428 (setq buffer (if (file-exists-p file)
4429 (org-get-agenda-file-buffer file)
4430 (error "No such file %s" file)))
4431 (if (not buffer)
4432 ;; If file does not exist, make sure an error message is sent
4433 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4434 file))))
4435 (with-current-buffer buffer
4436 (with-syntax-table (org-search-syntax-table)
4437 (unless (derived-mode-p 'org-mode)
4438 (error "Agenda file %s is not in `org-mode'" file))
4439 (let ((case-fold-search t))
4440 (save-excursion
4441 (save-restriction
4442 (if org-agenda-restrict
4443 (narrow-to-region org-agenda-restrict-begin
4444 org-agenda-restrict-end)
4445 (widen))
4446 (goto-char (point-min))
4447 (unless (or (org-at-heading-p)
4448 (outline-next-heading))
4449 (throw 'nextfile t))
4450 (goto-char (max (point-min) (1- (point))))
4451 (while (re-search-forward regexp nil t)
4452 (org-back-to-heading t)
4453 (skip-chars-forward "* ")
4454 (setq beg (point-at-bol)
4455 beg1 (point)
4456 end (progn (outline-next-heading) (point)))
4457 (catch :skip
4458 (goto-char beg)
4459 (org-agenda-skip)
4460 (setq str (buffer-substring-no-properties
4461 (point-at-bol)
4462 (if hdl-only (point-at-eol) end)))
4463 (mapc (lambda (wr) (when (string-match wr str)
4464 (goto-char (1- end))
4465 (throw :skip t)))
4466 regexps-)
4467 (mapc (lambda (wr) (unless (string-match wr str)
4468 (goto-char (1- end))
4469 (throw :skip t)))
4470 (if todo-only
4471 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4472 regexps+)
4473 regexps+))
4474 (goto-char beg)
4475 (setq marker (org-agenda-new-marker (point))
4476 category (org-get-category)
4477 category-pos (get-text-property (point) 'org-category-position)
4478 inherited-tags
4479 (or (eq org-agenda-show-inherited-tags 'always)
4480 (and (listp org-agenda-show-inherited-tags)
4481 (memq 'todo org-agenda-show-inherited-tags))
4482 (and (eq org-agenda-show-inherited-tags t)
4483 (or (eq org-agenda-use-tag-inheritance t)
4484 (memq 'todo org-agenda-use-tag-inheritance))))
4485 tags (org-get-tags-at nil (not inherited-tags))
4486 txt (org-agenda-format-item
4488 (buffer-substring-no-properties
4489 beg1 (point-at-eol))
4490 category tags t))
4491 (org-add-props txt props
4492 'org-marker marker 'org-hd-marker marker
4493 'org-todo-regexp org-todo-regexp
4494 'org-complex-heading-regexp org-complex-heading-regexp
4495 'priority 1000 'org-category category
4496 'org-category-position category-pos
4497 'type "search")
4498 (push txt ee)
4499 (goto-char (1- end))))))))))
4500 (setq rtn (nreverse ee))
4501 (setq rtnall (append rtnall rtn)))
4502 (if org-agenda-overriding-header
4503 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4504 nil 'face 'org-agenda-structure) "\n")
4505 (insert "Search words: ")
4506 (add-text-properties (point-min) (1- (point))
4507 (list 'face 'org-agenda-structure))
4508 (setq pos (point))
4509 (insert string "\n")
4510 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4511 (setq pos (point))
4512 (unless org-agenda-multi
4513 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4514 (add-text-properties pos (1- (point))
4515 (list 'face 'org-agenda-structure))))
4516 (org-agenda-mark-header-line (point-min))
4517 (when rtnall
4518 (insert (org-agenda-finalize-entries rtnall) "\n"))
4519 (goto-char (point-min))
4520 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4521 (add-text-properties (point-min) (point-max)
4522 `(org-agenda-type search
4523 org-last-args (,todo-only ,string ,edit-at)
4524 org-redo-cmd ,org-agenda-redo-command
4525 org-series-cmd ,org-cmd))
4526 (org-agenda-finalize)
4527 (setq buffer-read-only t))))
4529 (autoload 'org-search-view "org-agenda" "\
4530 Show all entries that contain a phrase or words or regular expressions.
4532 With optional prefix argument TODO-ONLY, only consider entries that are
4533 TODO entries. The argument STRING can be used to pass a default search
4534 string into this function. If EDIT-AT is non-nil, it means that the
4535 user should get a chance to edit this string, with cursor at position
4536 EDIT-AT.
4538 The search string can be viewed either as a phrase that should be found as
4539 is, or it can be broken into a number of snippets, each of which must match
4540 in a Boolean way to select an entry. The default depends on the variable
4541 `org-agenda-search-view-always-boolean'.
4542 Even if this is turned off (the default) you can always switch to
4543 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4545 The default is a direct search of the whole phrase, where each space in
4546 the search string can expand to an arbitrary amount of whitespace,
4547 including newlines.
4549 If using a Boolean search, the search string is split on whitespace and
4550 each snippet is searched separately, with logical AND to select an entry.
4551 Words prefixed with a minus must *not* occur in the entry. Words without
4552 a prefix or prefixed with a plus must occur in the entry. Matching is
4553 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4554 match whole words, not parts of a word) if
4555 `org-agenda-search-view-force-full-words' is set (default is nil).
4557 Boolean search snippets enclosed by curly braces are interpreted as
4558 regular expressions that must or (when preceded with \"-\") must not
4559 match in the entry. Snippets enclosed into double quotes will be taken
4560 as a whole, to include whitespace.
4562 - If the search string starts with an asterisk, search only in headlines.
4563 - If (possibly after the leading star) the search string starts with an
4564 exclamation mark, this also means to look at TODO entries only, an effect
4565 that can also be achieved with a prefix argument.
4566 - If (possibly after star and exclamation mark) the search string starts
4567 with a colon, this will mean that the (non-regexp) snippets of the
4568 Boolean search must match as full words.
4570 This command searches the agenda files, and in addition the files listed
4571 in `org-agenda-text-search-extra-files'.
4573 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4575 ;;; Agenda TODO list
4577 (defvar org-select-this-todo-keyword nil)
4578 (defvar org-last-arg nil)
4580 ;;;###autoload
4581 (defun org-todo-list (&optional arg)
4582 "Show all (not done) TODO entries from all agenda file in a single list.
4583 The prefix arg can be used to select a specific TODO keyword and limit
4584 the list to these. When using \\[universal-argument], you will be prompted
4585 for a keyword. A numeric prefix directly selects the Nth keyword in
4586 `org-todo-keywords-1'."
4587 (interactive "P")
4588 (if org-agenda-overriding-arguments
4589 (setq arg org-agenda-overriding-arguments))
4590 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4591 (let* ((today (org-today))
4592 (date (calendar-gregorian-from-absolute today))
4593 (kwds org-todo-keywords-for-agenda)
4594 (completion-ignore-case t)
4595 (org-select-this-todo-keyword
4596 (if (stringp arg) arg
4597 (and arg (integerp arg) (> arg 0)
4598 (nth (1- arg) kwds))))
4599 rtn rtnall files file pos)
4600 (when (equal arg '(4))
4601 (setq org-select-this-todo-keyword
4602 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4603 (mapcar 'list kwds) nil nil)))
4604 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4605 (catch 'exit
4606 (if org-agenda-sticky
4607 (setq org-agenda-buffer-name
4608 (if (stringp org-select-this-todo-keyword)
4609 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4610 org-select-this-todo-keyword)
4611 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4612 (org-agenda-prepare "TODO")
4613 (org-compile-prefix-format 'todo)
4614 (org-set-sorting-strategy 'todo)
4615 (setq org-agenda-redo-command
4616 `(org-todo-list (or (and (numberp current-prefix-arg)
4617 current-prefix-arg)
4618 ,org-select-this-todo-keyword
4619 current-prefix-arg ,arg)))
4620 (setq files (org-agenda-files nil 'ifmode)
4621 rtnall nil)
4622 (while (setq file (pop files))
4623 (catch 'nextfile
4624 (org-check-agenda-file file)
4625 (setq rtn (org-agenda-get-day-entries file date :todo))
4626 (setq rtnall (append rtnall rtn))))
4627 (if org-agenda-overriding-header
4628 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4629 nil 'face 'org-agenda-structure) "\n")
4630 (insert "Global list of TODO items of type: ")
4631 (add-text-properties (point-min) (1- (point))
4632 (list 'face 'org-agenda-structure
4633 'short-heading
4634 (concat "ToDo: "
4635 (or org-select-this-todo-keyword "ALL"))))
4636 (org-agenda-mark-header-line (point-min))
4637 (setq pos (point))
4638 (insert (or org-select-this-todo-keyword "ALL") "\n")
4639 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4640 (setq pos (point))
4641 (unless org-agenda-multi
4642 (insert "Available with `N r': (0)[ALL]")
4643 (let ((n 0) s)
4644 (mapc (lambda (x)
4645 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4646 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4647 (insert "\n "))
4648 (insert " " s))
4649 kwds))
4650 (insert "\n"))
4651 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4652 (org-agenda-mark-header-line (point-min))
4653 (when rtnall
4654 (insert (org-agenda-finalize-entries rtnall) "\n"))
4655 (goto-char (point-min))
4656 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4657 (add-text-properties (point-min) (point-max)
4658 `(org-agenda-type todo
4659 org-last-args ,arg
4660 org-redo-cmd ,org-agenda-redo-command
4661 org-series-cmd ,org-cmd))
4662 (org-agenda-finalize)
4663 (setq buffer-read-only t))))
4665 (autoload 'org-todo-list "org-agenda" "\
4666 Show all (not done) TODO entries from all agenda file in a single list.
4667 The prefix arg can be used to select a specific TODO keyword and limit
4668 the list to these. When using \\[universal-argument], you will be prompted
4669 for a keyword. A numeric prefix directly selects the Nth keyword in
4670 `org-todo-keywords-1'.
4672 \(fn &optional ARG)" t nil)
4674 ;;; Agenda tags match
4676 ;;;###autoload
4677 (defun org-tags-view (&optional todo-only match)
4678 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4679 The prefix arg TODO-ONLY limits the search to TODO entries."
4680 (interactive "P")
4681 (if org-agenda-overriding-arguments
4682 (setq todo-only (car org-agenda-overriding-arguments)
4683 match (nth 1 org-agenda-overriding-arguments)))
4684 (let* ((org-tags-match-list-sublevels
4685 org-tags-match-list-sublevels)
4686 (completion-ignore-case t)
4687 rtn rtnall files file pos matcher
4688 buffer)
4689 (when (and (stringp match) (not (string-match "\\S-" match)))
4690 (setq match nil))
4691 (setq matcher (org-make-tags-matcher match)
4692 match (car matcher) matcher (cdr matcher))
4693 (catch 'exit
4694 (if org-agenda-sticky
4695 (setq org-agenda-buffer-name
4696 (if (stringp match)
4697 (format "*Org Agenda(%s:%s)*"
4698 (or org-keys (or (and todo-only "M") "m")) match)
4699 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4700 (org-agenda-prepare (concat "TAGS " match))
4701 (org-compile-prefix-format 'tags)
4702 (org-set-sorting-strategy 'tags)
4703 (setq org-agenda-query-string match)
4704 (setq org-agenda-redo-command
4705 (list 'org-tags-view `(quote ,todo-only)
4706 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4707 (setq files (org-agenda-files nil 'ifmode)
4708 rtnall nil)
4709 (while (setq file (pop files))
4710 (catch 'nextfile
4711 (org-check-agenda-file file)
4712 (setq buffer (if (file-exists-p file)
4713 (org-get-agenda-file-buffer file)
4714 (error "No such file %s" file)))
4715 (if (not buffer)
4716 ;; If file does not exist, error message to agenda
4717 (setq rtn (list
4718 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4719 rtnall (append rtnall rtn))
4720 (with-current-buffer buffer
4721 (unless (derived-mode-p 'org-mode)
4722 (error "Agenda file %s is not in `org-mode'" file))
4723 (save-excursion
4724 (save-restriction
4725 (if org-agenda-restrict
4726 (narrow-to-region org-agenda-restrict-begin
4727 org-agenda-restrict-end)
4728 (widen))
4729 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4730 (setq rtnall (append rtnall rtn))))))))
4731 (if org-agenda-overriding-header
4732 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4733 nil 'face 'org-agenda-structure) "\n")
4734 (insert "Headlines with TAGS match: ")
4735 (add-text-properties (point-min) (1- (point))
4736 (list 'face 'org-agenda-structure
4737 'short-heading
4738 (concat "Match: " match)))
4739 (setq pos (point))
4740 (insert match "\n")
4741 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4742 (setq pos (point))
4743 (unless org-agenda-multi
4744 (insert "Press `C-u r' to search again with new search string\n"))
4745 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4746 (org-agenda-mark-header-line (point-min))
4747 (when rtnall
4748 (insert (org-agenda-finalize-entries rtnall) "\n"))
4749 (goto-char (point-min))
4750 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4751 (add-text-properties (point-min) (point-max)
4752 `(org-agenda-type tags
4753 org-last-args (,todo-only ,match)
4754 org-redo-cmd ,org-agenda-redo-command
4755 org-series-cmd ,org-cmd))
4756 (org-agenda-finalize)
4757 (setq buffer-read-only t))))
4759 (autoload 'org-tags-view "org-agenda" "\
4760 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4761 The prefix arg TODO-ONLY limits the search to TODO entries.
4763 \(fn &optional TODO-ONLY MATCH)" t nil)
4765 ;;; Agenda Finding stuck projects
4767 (defvar org-agenda-skip-regexp nil
4768 "Regular expression used in skipping subtrees for the agenda.
4769 This is basically a temporary global variable that can be set and then
4770 used by user-defined selections using `org-agenda-skip-function'.")
4772 (defvar org-agenda-overriding-header nil
4773 "When set during agenda, todo and tags searches it replaces the header.
4774 This variable should not be set directly, but custom commands can bind it
4775 in the options section.")
4777 (defun org-agenda-skip-entry-when-regexp-matches ()
4778 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4779 If yes, it returns the end position of this entry, causing agenda commands
4780 to skip the entry but continuing the search in the subtree. This is a
4781 function that can be put into `org-agenda-skip-function' for the duration
4782 of a command."
4783 (let ((end (save-excursion (org-end-of-subtree t)))
4784 skip)
4785 (save-excursion
4786 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4787 (and skip end)))
4789 (defun org-agenda-skip-subtree-when-regexp-matches ()
4790 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4791 If yes, it returns the end position of this tree, causing agenda commands
4792 to skip this subtree. This is a function that can be put into
4793 `org-agenda-skip-function' for the duration of a command."
4794 (let ((end (save-excursion (org-end-of-subtree t)))
4795 skip)
4796 (save-excursion
4797 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4798 (and skip end)))
4800 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4801 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4802 If yes, it returns the end position of the current entry (NOT the tree),
4803 causing agenda commands to skip the entry but continuing the search in
4804 the subtree. This is a function that can be put into
4805 `org-agenda-skip-function' for the duration of a command. An important
4806 use of this function is for the stuck project list."
4807 (let ((end (save-excursion (org-end-of-subtree t)))
4808 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4809 skip)
4810 (save-excursion
4811 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4812 (and skip entry-end)))
4814 (defun org-agenda-skip-entry-if (&rest conditions)
4815 "Skip entry if any of CONDITIONS is true.
4816 See `org-agenda-skip-if' for details."
4817 (org-agenda-skip-if nil conditions))
4819 (defun org-agenda-skip-subtree-if (&rest conditions)
4820 "Skip entry if any of CONDITIONS is true.
4821 See `org-agenda-skip-if' for details."
4822 (org-agenda-skip-if t conditions))
4824 (defun org-agenda-skip-if (subtree conditions)
4825 "Checks current entity for CONDITIONS.
4826 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4827 the entry (i.e. the text before the next heading) is checked.
4829 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4830 from different tests. Valid conditions are:
4832 scheduled Check if there is a scheduled cookie
4833 notscheduled Check if there is no scheduled cookie
4834 deadline Check if there is a deadline
4835 notdeadline Check if there is no deadline
4836 timestamp Check if there is a timestamp (also deadline or scheduled)
4837 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4838 regexp Check if regexp matches
4839 notregexp Check if regexp does not match.
4840 todo Check if TODO keyword matches
4841 nottodo Check if TODO keyword does not match
4843 The regexp is taken from the conditions list, it must come right after
4844 the `regexp' or `notregexp' element.
4846 `todo' and `nottodo' accept as an argument a list of todo
4847 keywords, which may include \"*\" to match any todo keyword.
4849 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4851 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4853 Instead of a list, a keyword class may be given. For example:
4855 (org-agenda-skip-entry-if 'nottodo 'done)
4857 would skip entries that haven't been marked with any of \"DONE\"
4858 keywords. Possible classes are: `todo', `done', `any'.
4860 If any of these conditions is met, this function returns the end point of
4861 the entity, causing the search to continue from there. This is a function
4862 that can be put into `org-agenda-skip-function' for the duration of a command."
4863 (let (beg end m)
4864 (org-back-to-heading t)
4865 (setq beg (point)
4866 end (if subtree
4867 (progn (org-end-of-subtree t) (point))
4868 (progn (outline-next-heading) (1- (point)))))
4869 (goto-char beg)
4870 (and
4872 (and (memq 'scheduled conditions)
4873 (re-search-forward org-scheduled-time-regexp end t))
4874 (and (memq 'notscheduled conditions)
4875 (not (re-search-forward org-scheduled-time-regexp end t)))
4876 (and (memq 'deadline conditions)
4877 (re-search-forward org-deadline-time-regexp end t))
4878 (and (memq 'notdeadline conditions)
4879 (not (re-search-forward org-deadline-time-regexp end t)))
4880 (and (memq 'timestamp conditions)
4881 (re-search-forward org-ts-regexp end t))
4882 (and (memq 'nottimestamp conditions)
4883 (not (re-search-forward org-ts-regexp end t)))
4884 (and (setq m (memq 'regexp conditions))
4885 (stringp (nth 1 m))
4886 (re-search-forward (nth 1 m) end t))
4887 (and (setq m (memq 'notregexp conditions))
4888 (stringp (nth 1 m))
4889 (not (re-search-forward (nth 1 m) end t)))
4890 (and (or
4891 (setq m (memq 'nottodo conditions))
4892 (setq m (memq 'todo-unblocked conditions))
4893 (setq m (memq 'nottodo-unblocked conditions))
4894 (setq m (memq 'todo conditions)))
4895 (org-agenda-skip-if-todo m end)))
4896 end)))
4898 (defun org-agenda-skip-if-todo (args end)
4899 "Helper function for `org-agenda-skip-if', do not use it directly.
4900 ARGS is a list with first element either `todo', `nottodo',
4901 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4902 a list of TODO keywords, or a state symbol `todo' or `done' or
4903 `any'."
4904 (let ((kw (car args))
4905 (arg (cadr args))
4906 todo-wds todo-re)
4907 (setq todo-wds
4908 (org-uniquify
4909 (cond
4910 ((listp arg) ;; list of keywords
4911 (if (member "*" arg)
4912 (mapcar 'substring-no-properties org-todo-keywords-1)
4913 arg))
4914 ((symbolp arg) ;; keyword class name
4915 (cond
4916 ((eq arg 'todo)
4917 (org-delete-all org-done-keywords
4918 (mapcar 'substring-no-properties
4919 org-todo-keywords-1)))
4920 ((eq arg 'done) org-done-keywords)
4921 ((eq arg 'any)
4922 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4923 (setq todo-re
4924 (concat "^\\*+[ \t]+\\<\\("
4925 (mapconcat 'identity todo-wds "\\|")
4926 "\\)\\>"))
4927 (cond
4928 ((eq kw 'todo) (re-search-forward todo-re end t))
4929 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4930 ((eq kw 'todo-unblocked)
4931 (catch 'unblocked
4932 (while (re-search-forward todo-re end t)
4933 (or (org-entry-blocked-p) (throw 'unblocked t)))
4934 nil))
4935 ((eq kw 'nottodo-unblocked)
4936 (catch 'unblocked
4937 (while (re-search-forward todo-re end t)
4938 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4942 ;;;###autoload
4943 (defun org-agenda-list-stuck-projects (&rest ignore)
4944 "Create agenda view for projects that are stuck.
4945 Stuck projects are project that have no next actions. For the definitions
4946 of what a project is and how to check if it stuck, customize the variable
4947 `org-stuck-projects'."
4948 (interactive)
4949 (let* ((org-agenda-skip-function
4950 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4951 ;; We could have used org-agenda-skip-if here.
4952 (org-agenda-overriding-header
4953 (or org-agenda-overriding-header "List of stuck projects: "))
4954 (matcher (nth 0 org-stuck-projects))
4955 (todo (nth 1 org-stuck-projects))
4956 (todo-wds (if (member "*" todo)
4957 (progn
4958 (org-agenda-prepare-buffers (org-agenda-files
4959 nil 'ifmode))
4960 (org-delete-all
4961 org-done-keywords-for-agenda
4962 (copy-sequence org-todo-keywords-for-agenda)))
4963 todo))
4964 (todo-re (concat "^\\*+[ \t]+\\("
4965 (mapconcat 'identity todo-wds "\\|")
4966 "\\)\\>"))
4967 (tags (nth 2 org-stuck-projects))
4968 (tags-re (if (member "*" tags)
4969 (concat org-outline-regexp-bol
4970 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4971 (if tags
4972 (concat org-outline-regexp-bol
4973 ".*:\\("
4974 (mapconcat 'identity tags "\\|")
4975 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4976 (gen-re (nth 3 org-stuck-projects))
4977 (re-list
4978 (delq nil
4979 (list
4980 (if todo todo-re)
4981 (if tags tags-re)
4982 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4983 gen-re)))))
4984 (setq org-agenda-skip-regexp
4985 (if re-list
4986 (mapconcat 'identity re-list "\\|")
4987 (error "No information how to identify unstuck projects")))
4988 (org-tags-view nil matcher)
4989 (with-current-buffer org-agenda-buffer-name
4990 (setq org-agenda-redo-command
4991 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4993 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4994 Create agenda view for projects that are stuck.
4995 Stuck projects are project that have no next actions. For the definitions
4996 of what a project is and how to check if it stuck, customize the variable
4997 `org-stuck-projects'.
4999 \(fn &rest IGNORE)" t nil)
5001 ;;; Diary integration
5003 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5004 (defvar diary-list-entries-hook)
5005 (defvar diary-time-regexp)
5006 (defun org-get-entries-from-diary (date)
5007 "Get the (Emacs Calendar) diary entries for DATE."
5008 (require 'diary-lib)
5009 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5010 (diary-display-hook '(fancy-diary-display))
5011 (diary-display-function 'fancy-diary-display)
5012 (pop-up-frames nil)
5013 (diary-list-entries-hook
5014 (cons 'org-diary-default-entry diary-list-entries-hook))
5015 (diary-file-name-prefix nil) ; turn this feature off
5016 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5017 entries
5018 (org-disable-agenda-to-diary t))
5019 (save-excursion
5020 (save-window-excursion
5021 (funcall (if (fboundp 'diary-list-entries)
5022 'diary-list-entries 'list-diary-entries)
5023 date 1)))
5024 (if (not (get-buffer diary-fancy-buffer))
5025 (setq entries nil)
5026 (with-current-buffer diary-fancy-buffer
5027 (setq buffer-read-only nil)
5028 (if (zerop (buffer-size))
5029 ;; No entries
5030 (setq entries nil)
5031 ;; Omit the date and other unnecessary stuff
5032 (org-agenda-cleanup-fancy-diary)
5033 ;; Add prefix to each line and extend the text properties
5034 (if (zerop (buffer-size))
5035 (setq entries nil)
5036 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5037 (setq entries
5038 (with-temp-buffer
5039 (insert entries) (goto-char (point-min))
5040 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5041 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5042 (replace-match (concat "; " (match-string 1)))))
5043 (buffer-string)))))
5044 (set-buffer-modified-p nil)
5045 (kill-buffer diary-fancy-buffer)))
5046 (when entries
5047 (setq entries (org-split-string entries "\n"))
5048 (setq entries
5049 (mapcar
5050 (lambda (x)
5051 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
5052 ;; Extend the text properties to the beginning of the line
5053 (org-add-props x (text-properties-at (1- (length x)) x)
5054 'type "diary" 'date date 'face 'org-agenda-diary))
5055 entries)))))
5057 (defvar org-agenda-cleanup-fancy-diary-hook nil
5058 "Hook run when the fancy diary buffer is cleaned up.")
5060 (defun org-agenda-cleanup-fancy-diary ()
5061 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5062 This gets rid of the date, the underline under the date, and
5063 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5064 date. It also removes lines that contain only whitespace."
5065 (goto-char (point-min))
5066 (if (looking-at ".*?:[ \t]*")
5067 (progn
5068 (replace-match "")
5069 (re-search-forward "\n=+$" nil t)
5070 (replace-match "")
5071 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5072 (re-search-forward "\n=+$" nil t)
5073 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5074 (goto-char (point-min))
5075 (while (re-search-forward "^ +\n" nil t)
5076 (replace-match ""))
5077 (goto-char (point-min))
5078 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5079 (replace-match ""))
5080 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5082 ;; Make sure entries from the diary have the right text properties.
5083 (eval-after-load "diary-lib"
5084 '(if (boundp 'diary-modify-entry-list-string-function)
5085 ;; We can rely on the hook, nothing to do
5087 ;; Hook not available, must use advice to make this work
5088 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5089 "Make the position visible."
5090 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5091 (stringp string)
5092 buffer-file-name)
5093 (setq string (org-modify-diary-entry-string string))))))
5095 (defun org-modify-diary-entry-string (string)
5096 "Add text properties to string, allowing org-mode to act on it."
5097 (org-add-props string nil
5098 'mouse-face 'highlight
5099 'help-echo (if buffer-file-name
5100 (format "mouse-2 or RET jump to diary file %s"
5101 (abbreviate-file-name buffer-file-name))
5103 'org-agenda-diary-link t
5104 'org-marker (org-agenda-new-marker (point-at-bol))))
5106 (defun org-diary-default-entry ()
5107 "Add a dummy entry to the diary.
5108 Needed to avoid empty dates which mess up holiday display."
5109 ;; Catch the error if dealing with the new add-to-diary-alist
5110 (when org-disable-agenda-to-diary
5111 (condition-case nil
5112 (org-add-to-diary-list original-date "Org-mode dummy" "")
5113 (error
5114 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5116 (defun org-add-to-diary-list (&rest args)
5117 (if (fboundp 'diary-add-to-list)
5118 (apply 'diary-add-to-list args)
5119 (apply 'add-to-diary-list args)))
5121 (defvar org-diary-last-run-time nil)
5123 ;;;###autoload
5124 (defun org-diary (&rest args)
5125 "Return diary information from org files.
5126 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5127 It accesses org files and extracts information from those files to be
5128 listed in the diary. The function accepts arguments specifying what
5129 items should be listed. For a list of arguments allowed here, see the
5130 variable `org-agenda-entry-types'.
5132 The call in the diary file should look like this:
5134 &%%(org-diary) ~/path/to/some/orgfile.org
5136 Use a separate line for each org file to check. Or, if you omit the file name,
5137 all files listed in `org-agenda-files' will be checked automatically:
5139 &%%(org-diary)
5141 If you don't give any arguments (as in the example above), the default
5142 arguments (:deadline :scheduled :timestamp :sexp) are used.
5143 So the example above may also be written as
5145 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5147 The function expects the lisp variables `entry' and `date' to be provided
5148 by the caller, because this is how the calendar works. Don't use this
5149 function from a program - use `org-agenda-get-day-entries' instead."
5150 (when (> (- (org-float-time)
5151 org-agenda-last-marker-time)
5153 ;; I am not sure if this works with sticky agendas, because the marker
5154 ;; list is then no longer a global variable.
5155 (org-agenda-reset-markers))
5156 (org-compile-prefix-format 'agenda)
5157 (org-set-sorting-strategy 'agenda)
5158 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5159 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5160 (list entry)
5161 (org-agenda-files t)))
5162 (time (org-float-time))
5163 file rtn results)
5164 (when (or (not org-diary-last-run-time)
5165 (> (- time
5166 org-diary-last-run-time)
5168 (org-agenda-prepare-buffers files))
5169 (setq org-diary-last-run-time time)
5170 ;; If this is called during org-agenda, don't return any entries to
5171 ;; the calendar. Org Agenda will list these entries itself.
5172 (if org-disable-agenda-to-diary (setq files nil))
5173 (while (setq file (pop files))
5174 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5175 (setq results (append results rtn)))
5176 (if results
5177 (concat (org-agenda-finalize-entries results) "\n"))))
5179 (autoload 'org-diary "org-agenda" "\
5180 Return diary information from org files.
5181 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5182 It accesses org files and extracts information from those files to be
5183 listed in the diary. The function accepts arguments specifying what
5184 items should be listed. For a list of arguments allowed here, see the
5185 variable `org-agenda-entry-types'.
5187 The call in the diary file should look like this:
5189 &%%(org-diary) ~/path/to/some/orgfile.org
5191 Use a separate line for each org file to check. Or, if you omit the file name,
5192 all files listed in `org-agenda-files' will be checked automatically:
5194 &%%(org-diary)
5196 If you don't give any arguments (as in the example above), the default
5197 arguments (:deadline :scheduled :timestamp :sexp) are used.
5198 So the example above may also be written as
5200 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5202 The function expects the lisp variables `entry' and `date' to be provided
5203 by the caller, because this is how the calendar works. Don't use this
5204 function from a program - use `org-agenda-get-day-entries' instead.
5206 \(fn &rest ARGS)" nil nil)
5208 ;;; Agenda entry finders
5210 (defun org-agenda-get-day-entries (file date &rest args)
5211 "Does the work for `org-diary' and `org-agenda'.
5212 FILE is the path to a file to be checked for entries. DATE is date like
5213 the one returned by `calendar-current-date'. ARGS are symbols indicating
5214 which kind of entries should be extracted. For details about these, see
5215 the documentation of `org-diary'."
5216 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5217 (let* ((org-startup-folded nil)
5218 (org-startup-align-all-tables nil)
5219 (buffer (if (file-exists-p file)
5220 (org-get-agenda-file-buffer file)
5221 (error "No such file %s" file)))
5222 arg results rtn deadline-results)
5223 (if (not buffer)
5224 ;; If file does not exist, make sure an error message ends up in diary
5225 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5226 (with-current-buffer buffer
5227 (unless (derived-mode-p 'org-mode)
5228 (error "Agenda file %s is not in `org-mode'" file))
5229 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5230 (let ((case-fold-search nil))
5231 (save-excursion
5232 (save-restriction
5233 (if org-agenda-restrict
5234 (narrow-to-region org-agenda-restrict-begin
5235 org-agenda-restrict-end)
5236 (widen))
5237 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5238 (while (setq arg (pop args))
5239 (cond
5240 ((and (eq arg :todo)
5241 (equal date (calendar-gregorian-from-absolute
5242 (org-today))))
5243 (setq rtn (org-agenda-get-todos))
5244 (setq results (append results rtn)))
5245 ((eq arg :timestamp)
5246 (setq rtn (org-agenda-get-blocks))
5247 (setq results (append results rtn))
5248 (setq rtn (org-agenda-get-timestamps deadline-results))
5249 (setq results (append results rtn)))
5250 ((eq arg :sexp)
5251 (setq rtn (org-agenda-get-sexps))
5252 (setq results (append results rtn)))
5253 ((eq arg :scheduled)
5254 (setq rtn (org-agenda-get-scheduled deadline-results))
5255 (setq results (append results rtn)))
5256 ((eq arg :closed)
5257 (setq rtn (org-agenda-get-progress))
5258 (setq results (append results rtn)))
5259 ((eq arg :deadline)
5260 (setq rtn (org-agenda-get-deadlines))
5261 (setq deadline-results (copy-sequence rtn))
5262 (setq results (append results rtn))))))))
5263 results))))
5265 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5266 (defun org-agenda-get-todos ()
5267 "Return the TODO information for agenda display."
5268 (let* ((props (list 'face nil
5269 'done-face 'org-agenda-done
5270 'org-not-done-regexp org-not-done-regexp
5271 'org-todo-regexp org-todo-regexp
5272 'org-complex-heading-regexp org-complex-heading-regexp
5273 'mouse-face 'highlight
5274 'help-echo
5275 (format "mouse-2 or RET jump to org file %s"
5276 (abbreviate-file-name buffer-file-name))))
5277 (regexp (format org-heading-keyword-regexp-format
5278 (cond
5279 ((and org-select-this-todo-keyword
5280 (equal org-select-this-todo-keyword "*"))
5281 org-todo-regexp)
5282 (org-select-this-todo-keyword
5283 (concat "\\("
5284 (mapconcat 'identity
5285 (org-split-string
5286 org-select-this-todo-keyword
5287 "|")
5288 "\\|") "\\)"))
5289 (t org-not-done-regexp))))
5290 marker priority category category-pos tags todo-state
5291 ee txt beg end inherited-tags)
5292 (goto-char (point-min))
5293 (while (re-search-forward regexp nil t)
5294 (catch :skip
5295 (save-match-data
5296 (beginning-of-line)
5297 (org-agenda-skip)
5298 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5299 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5300 (goto-char (1+ beg))
5301 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5302 (throw :skip nil)))
5303 (goto-char (match-beginning 2))
5304 (setq marker (org-agenda-new-marker (match-beginning 0))
5305 category (org-get-category)
5306 category-pos (get-text-property (point) 'org-category-position)
5307 txt (org-trim
5308 (buffer-substring (match-beginning 2) (match-end 0)))
5309 inherited-tags
5310 (or (eq org-agenda-show-inherited-tags 'always)
5311 (and (listp org-agenda-show-inherited-tags)
5312 (memq 'todo org-agenda-show-inherited-tags))
5313 (and (eq org-agenda-show-inherited-tags t)
5314 (or (eq org-agenda-use-tag-inheritance t)
5315 (memq 'todo org-agenda-use-tag-inheritance))))
5316 tags (org-get-tags-at nil (not inherited-tags))
5317 txt (org-agenda-format-item "" txt category tags t)
5318 priority (1+ (org-get-priority txt))
5319 todo-state (org-get-todo-state))
5320 (org-add-props txt props
5321 'org-marker marker 'org-hd-marker marker
5322 'priority priority 'org-category category
5323 'org-category-position category-pos
5324 'type "todo" 'todo-state todo-state)
5325 (push txt ee)
5326 (if org-agenda-todo-list-sublevels
5327 (goto-char (match-end 2))
5328 (org-end-of-subtree 'invisible))))
5329 (nreverse ee)))
5331 (defun org-agenda-todo-custom-ignore-p (time n)
5332 "Check whether timestamp is farther away than n number of days.
5333 This function is invoked if `org-agenda-todo-ignore-deadlines',
5334 `org-agenda-todo-ignore-scheduled' or
5335 `org-agenda-todo-ignore-timestamp' is set to an integer."
5336 (let ((days (org-days-to-time time)))
5337 (if (>= n 0)
5338 (>= days n)
5339 (<= days n))))
5341 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5342 (&optional end)
5343 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5344 (when (or org-agenda-todo-ignore-with-date
5345 org-agenda-todo-ignore-scheduled
5346 org-agenda-todo-ignore-deadlines
5347 org-agenda-todo-ignore-timestamp)
5348 (setq end (or end (save-excursion (outline-next-heading) (point))))
5349 (save-excursion
5350 (or (and org-agenda-todo-ignore-with-date
5351 (re-search-forward org-ts-regexp end t))
5352 (and org-agenda-todo-ignore-scheduled
5353 (re-search-forward org-scheduled-time-regexp end t)
5354 (cond
5355 ((eq org-agenda-todo-ignore-scheduled 'future)
5356 (> (org-days-to-time (match-string 1)) 0))
5357 ((eq org-agenda-todo-ignore-scheduled 'past)
5358 (<= (org-days-to-time (match-string 1)) 0))
5359 ((numberp org-agenda-todo-ignore-scheduled)
5360 (org-agenda-todo-custom-ignore-p
5361 (match-string 1) org-agenda-todo-ignore-scheduled))
5362 (t)))
5363 (and org-agenda-todo-ignore-deadlines
5364 (re-search-forward org-deadline-time-regexp end t)
5365 (cond
5366 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5367 ((eq org-agenda-todo-ignore-deadlines 'far)
5368 (not (org-deadline-close (match-string 1))))
5369 ((eq org-agenda-todo-ignore-deadlines 'future)
5370 (> (org-days-to-time (match-string 1)) 0))
5371 ((eq org-agenda-todo-ignore-deadlines 'past)
5372 (<= (org-days-to-time (match-string 1)) 0))
5373 ((numberp org-agenda-todo-ignore-deadlines)
5374 (org-agenda-todo-custom-ignore-p
5375 (match-string 1) org-agenda-todo-ignore-deadlines))
5376 (t (org-deadline-close (match-string 1)))))
5377 (and org-agenda-todo-ignore-timestamp
5378 (let ((buffer (current-buffer))
5379 (regexp
5380 (concat
5381 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5382 (start (point)))
5383 ;; Copy current buffer into a temporary one
5384 (with-temp-buffer
5385 (insert-buffer-substring buffer start end)
5386 (goto-char (point-min))
5387 ;; Delete SCHEDULED and DEADLINE items
5388 (while (re-search-forward regexp end t)
5389 (delete-region (match-beginning 0) (match-end 0)))
5390 (goto-char (point-min))
5391 ;; No search for timestamp left
5392 (when (re-search-forward org-ts-regexp nil t)
5393 (cond
5394 ((eq org-agenda-todo-ignore-timestamp 'future)
5395 (> (org-days-to-time (match-string 1)) 0))
5396 ((eq org-agenda-todo-ignore-timestamp 'past)
5397 (<= (org-days-to-time (match-string 1)) 0))
5398 ((numberp org-agenda-todo-ignore-timestamp)
5399 (org-agenda-todo-custom-ignore-p
5400 (match-string 1) org-agenda-todo-ignore-timestamp))
5401 (t))))))))))
5403 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5404 Do we have a reason to ignore this TODO entry because it has a time stamp?
5406 \(fn &optional END)" nil nil)
5408 (defun org-agenda-get-timestamps (&optional deadline-results)
5409 "Return the date stamp information for agenda display."
5410 (let* ((props (list 'face 'org-agenda-calendar-event
5411 'org-not-done-regexp org-not-done-regexp
5412 'org-todo-regexp org-todo-regexp
5413 'org-complex-heading-regexp org-complex-heading-regexp
5414 'mouse-face 'highlight
5415 'help-echo
5416 (format "mouse-2 or RET jump to org file %s"
5417 (abbreviate-file-name buffer-file-name))))
5418 (d1 (calendar-absolute-from-gregorian date))
5420 (deadline-position-alist
5421 (mapcar (lambda (a) (and (setq mm (get-text-property
5422 0 'org-hd-marker a))
5423 (cons (marker-position mm) a)))
5424 deadline-results))
5425 (remove-re org-ts-regexp)
5426 (regexp
5427 (concat
5428 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5429 (regexp-quote
5430 (substring
5431 (format-time-string
5432 (car org-time-stamp-formats)
5433 (apply 'encode-time ; DATE bound by calendar
5434 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5435 1 11))
5436 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5437 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5438 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5439 donep tmp priority category category-pos ee txt timestr tags
5440 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5441 inherited-tags)
5442 (goto-char (point-min))
5443 (while (setq end-of-match (re-search-forward regexp nil t))
5444 (setq b0 (match-beginning 0)
5445 b3 (match-beginning 3) e3 (match-end 3)
5446 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5447 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5448 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5449 (member todo-state
5450 org-agenda-repeating-timestamp-show-all)))
5451 (catch :skip
5452 (and (org-at-date-range-p) (throw :skip nil))
5453 (org-agenda-skip)
5454 (if (and (match-end 1)
5455 (not (= d1 (org-time-string-to-absolute
5456 (match-string 1) d1 nil show-all
5457 (current-buffer) b0))))
5458 (throw :skip nil))
5459 (if (and e3
5460 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5461 (throw :skip nil))
5462 (setq tmp (buffer-substring (max (point-min)
5463 (- b0 org-ds-keyword-length))
5465 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5466 inactivep (= (char-after b0) ?\[)
5467 deadlinep (string-match org-deadline-regexp tmp)
5468 scheduledp (string-match org-scheduled-regexp tmp)
5469 closedp (and org-agenda-include-inactive-timestamps
5470 (string-match org-closed-string tmp))
5471 clockp (and org-agenda-include-inactive-timestamps
5472 (or (string-match org-clock-string tmp)
5473 (string-match "]-+\\'" tmp)))
5474 warntime (get-text-property (point) 'org-appt-warntime)
5475 donep (member todo-state org-done-keywords))
5476 (if (or scheduledp deadlinep closedp clockp
5477 (and donep org-agenda-skip-timestamp-if-done))
5478 (throw :skip t))
5479 (if (string-match ">" timestr)
5480 ;; substring should only run to end of time stamp
5481 (setq timestr (substring timestr 0 (match-end 0))))
5482 (setq marker (org-agenda-new-marker b0)
5483 category (org-get-category b0)
5484 category-pos (get-text-property b0 'org-category-position))
5485 (save-excursion
5486 (if (not (re-search-backward org-outline-regexp-bol nil t))
5487 (throw :skip nil)
5488 (goto-char (match-beginning 0))
5489 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5490 (assoc (point) deadline-position-alist))
5491 (throw :skip nil))
5492 (setq hdmarker (org-agenda-new-marker)
5493 inherited-tags
5494 (or (eq org-agenda-show-inherited-tags 'always)
5495 (and (listp org-agenda-show-inherited-tags)
5496 (memq 'agenda org-agenda-show-inherited-tags))
5497 (and (eq org-agenda-show-inherited-tags t)
5498 (or (eq org-agenda-use-tag-inheritance t)
5499 (memq 'agenda org-agenda-use-tag-inheritance))))
5500 tags (org-get-tags-at nil (not inherited-tags)))
5501 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5502 (setq head (or (match-string 1) ""))
5503 (setq txt (org-agenda-format-item
5504 (if inactivep org-agenda-inactive-leader nil)
5505 head category tags timestr
5506 remove-re habitp)))
5507 (setq priority (org-get-priority txt))
5508 (org-add-props txt props
5509 'org-marker marker 'org-hd-marker hdmarker)
5510 (org-add-props txt nil 'priority priority
5511 'org-category category 'date date
5512 'org-category-position category-pos
5513 'todo-state todo-state
5514 'warntime warntime
5515 'type "timestamp")
5516 (push txt ee))
5517 (if org-agenda-skip-additional-timestamps-same-entry
5518 (outline-next-heading)
5519 (goto-char end-of-match))))
5520 (nreverse ee)))
5522 (defun org-agenda-get-sexps ()
5523 "Return the sexp information for agenda display."
5524 (require 'diary-lib)
5525 (let* ((props (list 'face 'org-agenda-calendar-sexp
5526 'mouse-face 'highlight
5527 'help-echo
5528 (format "mouse-2 or RET jump to org file %s"
5529 (abbreviate-file-name buffer-file-name))))
5530 (regexp "^&?%%(")
5531 marker category extra category-pos ee txt tags entry
5532 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5533 (goto-char (point-min))
5534 (while (re-search-forward regexp nil t)
5535 (catch :skip
5536 (org-agenda-skip)
5537 (setq beg (match-beginning 0))
5538 (goto-char (1- (match-end 0)))
5539 (setq b (point))
5540 (forward-sexp 1)
5541 (setq sexp (buffer-substring b (point)))
5542 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5543 (org-trim (match-string 1))
5544 ""))
5545 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5546 (when result
5547 (setq marker (org-agenda-new-marker beg)
5548 category (org-get-category beg)
5549 category-pos (get-text-property beg 'org-category-position)
5550 inherited-tags
5551 (or (eq org-agenda-show-inherited-tags 'always)
5552 (and (listp org-agenda-show-inherited-tags)
5553 (memq 'agenda org-agenda-show-inherited-tags))
5554 (and (eq org-agenda-show-inherited-tags t)
5555 (or (eq org-agenda-use-tag-inheritance t)
5556 (memq 'agenda org-agenda-use-tag-inheritance))))
5557 tags (org-get-tags-at nil (not inherited-tags))
5558 todo-state (org-get-todo-state)
5559 warntime (get-text-property (point) 'org-appt-warntime)
5560 extra nil)
5562 (dolist (r (if (stringp result)
5563 (list result)
5564 result)) ;; we expect a list here
5565 (when (and org-agenda-diary-sexp-prefix
5566 (string-match org-agenda-diary-sexp-prefix r))
5567 (setq extra (match-string 0 r)
5568 r (replace-match "" nil nil r)))
5569 (if (string-match "\\S-" r)
5570 (setq txt r)
5571 (setq txt "SEXP entry returned empty string"))
5573 (setq txt (org-agenda-format-item
5574 extra txt category tags 'time))
5575 (org-add-props txt props 'org-marker marker)
5576 (org-add-props txt nil
5577 'org-category category 'date date 'todo-state todo-state
5578 'org-category-position category-pos 'tags tags
5579 'type "sexp" 'warntime warntime)
5580 (push txt ee)))))
5581 (nreverse ee)))
5583 ;; Calendar sanity: define some functions that are independent of
5584 ;; `calendar-date-style'.
5585 ;; Normally I would like to use ISO format when calling the diary functions,
5586 ;; but to make sure we still have Emacs 22 compatibility we bind
5587 ;; also `european-calendar-style' and use european format
5588 (defun org-anniversary (year month day &optional mark)
5589 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5590 (org-no-warnings
5591 (let ((calendar-date-style 'european) (european-calendar-style t))
5592 (diary-anniversary day month year mark))))
5593 (defun org-cyclic (N year month day &optional mark)
5594 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5595 (org-no-warnings
5596 (let ((calendar-date-style 'european) (european-calendar-style t))
5597 (diary-cyclic N day month year mark))))
5598 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5599 "Like `diary-block', but with fixed (ISO) order of arguments."
5600 (org-no-warnings
5601 (let ((calendar-date-style 'european) (european-calendar-style t))
5602 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5603 (defun org-date (year month day &optional mark)
5604 "Like `diary-date', but with fixed (ISO) order of arguments."
5605 (org-no-warnings
5606 (let ((calendar-date-style 'european) (european-calendar-style t))
5607 (diary-date day month year mark))))
5609 ;; Define the` org-class' function
5610 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5611 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5612 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5613 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5614 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5615 `holidays', then any date that is known by the Emacs calendar to be a
5616 holiday will also be skipped."
5617 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5618 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5619 (d (calendar-absolute-from-gregorian date)))
5620 (and
5621 (<= date1 d)
5622 (<= d date2)
5623 (= (calendar-day-of-week date) dayname)
5624 (or (not skip-weeks)
5625 (progn
5626 (require 'cal-iso)
5627 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5628 (not (and (memq 'holidays skip-weeks)
5629 (calendar-check-holidays date)))
5630 entry)))
5632 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5633 "Like `org-class', but honor `calendar-date-style'.
5634 The order of the first 2 times 3 arguments depends on the variable
5635 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5636 So for American calendars, give this as MONTH DAY YEAR, for European as
5637 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5638 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5639 is any number of ISO weeks in the block period for which the item should
5640 be skipped.
5642 This function is here only for backward compatibility and it is deprecated,
5643 please use `org-class' instead."
5644 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5645 (date2 (org-order-calendar-date-args m2 d2 y2)))
5646 (org-class
5647 (nth 2 date1) (car date1) (nth 1 date1)
5648 (nth 2 date2) (car date2) (nth 1 date2)
5649 dayname skip-weeks)))
5650 (make-obsolete 'org-diary-class 'org-class "")
5652 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5653 (defalias 'org-get-closed 'org-agenda-get-progress)
5654 (defun org-agenda-get-progress ()
5655 "Return the logged TODO entries for agenda display."
5656 (let* ((props (list 'mouse-face 'highlight
5657 'org-not-done-regexp org-not-done-regexp
5658 'org-todo-regexp org-todo-regexp
5659 'org-complex-heading-regexp org-complex-heading-regexp
5660 'help-echo
5661 (format "mouse-2 or RET jump to org file %s"
5662 (abbreviate-file-name buffer-file-name))))
5663 (items (if (consp org-agenda-show-log-scoped)
5664 org-agenda-show-log-scoped
5665 (if (eq org-agenda-show-log-scoped 'clockcheck)
5666 '(clock)
5667 org-agenda-log-mode-items)))
5668 (parts
5669 (delq nil
5670 (list
5671 (if (memq 'closed items) (concat "\\<" org-closed-string))
5672 (if (memq 'clock items) (concat "\\<" org-clock-string))
5673 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5674 (parts-re (if parts (mapconcat 'identity parts "\\|")
5675 (error "`org-agenda-log-mode-items' is empty")))
5676 (regexp (concat
5677 "\\(" parts-re "\\)"
5678 " *\\["
5679 (regexp-quote
5680 (substring
5681 (format-time-string
5682 (car org-time-stamp-formats)
5683 (apply 'encode-time ; DATE bound by calendar
5684 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5685 1 11))))
5686 (org-agenda-search-headline-for-time nil)
5687 marker hdmarker priority category category-pos tags closedp
5688 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5689 (goto-char (point-min))
5690 (while (re-search-forward regexp nil t)
5691 (catch :skip
5692 (org-agenda-skip)
5693 (setq marker (org-agenda-new-marker (match-beginning 0))
5694 closedp (equal (match-string 1) org-closed-string)
5695 statep (equal (string-to-char (match-string 1)) ?-)
5696 clockp (not (or closedp statep))
5697 state (and statep (match-string 2))
5698 category (org-get-category (match-beginning 0))
5699 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5700 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5701 (when (string-match "\\]" timestr)
5702 ;; substring should only run to end of time stamp
5703 (setq rest (substring timestr (match-end 0))
5704 timestr (substring timestr 0 (match-end 0)))
5705 (if (and (not closedp) (not statep)
5706 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5707 rest))
5708 (progn (setq timestr (concat (substring timestr 0 -1)
5709 "-" (match-string 1 rest) "]"))
5710 (setq clocked (match-string 2 rest)))
5711 (setq clocked "-")))
5712 (save-excursion
5713 (setq extra
5714 (cond
5715 ((not org-agenda-log-mode-add-notes) nil)
5716 (statep
5717 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5718 (match-string 1)))
5719 (clockp
5720 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5721 (match-string 1)))))
5722 (if (not (re-search-backward org-outline-regexp-bol nil t))
5723 (throw :skip nil)
5724 (goto-char (match-beginning 0))
5725 (setq hdmarker (org-agenda-new-marker)
5726 inherited-tags
5727 (or (eq org-agenda-show-inherited-tags 'always)
5728 (and (listp org-agenda-show-inherited-tags)
5729 (memq 'todo org-agenda-show-inherited-tags))
5730 (and (eq org-agenda-show-inherited-tags t)
5731 (or (eq org-agenda-use-tag-inheritance t)
5732 (memq 'todo org-agenda-use-tag-inheritance))))
5733 tags (org-get-tags-at nil (not inherited-tags)))
5734 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5735 (setq txt (match-string 1))
5736 (when extra
5737 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5738 (setq txt (concat (substring txt 0 (match-beginning 1))
5739 " - " extra " " (match-string 2 txt)))
5740 (setq txt (concat txt " - " extra))))
5741 (setq txt (org-agenda-format-item
5742 (cond
5743 (closedp "Closed: ")
5744 (statep (concat "State: (" state ")"))
5745 (t (concat "Clocked: (" clocked ")")))
5746 txt category tags timestr)))
5747 (setq priority 100000)
5748 (org-add-props txt props
5749 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5750 'priority priority 'org-category category
5751 'org-category-position category-pos
5752 'type "closed" 'date date
5753 'undone-face 'org-warning 'done-face 'org-agenda-done)
5754 (push txt ee))
5755 (goto-char (point-at-eol))))
5756 (nreverse ee)))
5758 (defun org-agenda-show-clocking-issues ()
5759 "Add overlays, showing issues with clocking.
5760 See also the user option `org-agenda-clock-consistency-checks'."
5761 (interactive)
5762 (let* ((pl org-agenda-clock-consistency-checks)
5763 (re (concat "^[ \t]*"
5764 org-clock-string
5765 "[ \t]+"
5766 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5767 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5768 (tlstart 0.)
5769 (tlend 0.)
5770 (maxtime (org-hh:mm-string-to-minutes
5771 (or (plist-get pl :max-duration) "24:00")))
5772 (mintime (org-hh:mm-string-to-minutes
5773 (or (plist-get pl :min-duration) 0)))
5774 (maxgap (org-hh:mm-string-to-minutes
5775 ;; default 30:00 means never complain
5776 (or (plist-get pl :max-gap) "30:00")))
5777 (gapok (mapcar 'org-hh:mm-string-to-minutes
5778 (plist-get pl :gap-ok-around)))
5779 (def-face (or (plist-get pl :default-face)
5780 '((:background "DarkRed") (:foreground "white"))))
5781 issue face m te ts dt ov)
5782 (goto-char (point-min))
5783 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5784 (setq issue nil face def-face)
5785 (catch 'next
5786 (setq m (org-get-at-bol 'org-marker)
5787 te nil ts nil)
5788 (unless (and m (markerp m))
5789 (setq issue "No valid clock line") (throw 'next t))
5790 (org-with-point-at m
5791 (save-excursion
5792 (goto-char (point-at-bol))
5793 (unless (looking-at re)
5794 (error "No valid Clock line")
5795 (throw 'next t))
5796 (unless (match-end 3)
5797 (setq issue "No end time"
5798 face (or (plist-get pl :no-end-time-face) face))
5799 (throw 'next t))
5800 (setq ts (match-string 1)
5801 te (match-string 3)
5802 ts (org-float-time
5803 (apply 'encode-time (org-parse-time-string ts)))
5804 te (org-float-time
5805 (apply 'encode-time (org-parse-time-string te)))
5806 dt (- te ts))))
5807 (cond
5808 ((> dt (* 60 maxtime))
5809 ;; a very long clocking chunk
5810 (setq issue (format "Clocking interval is very long: %s"
5811 (org-minutes-to-hh:mm-string
5812 (floor (/ (float dt) 60.))))
5813 face (or (plist-get pl :long-face) face)))
5814 ((< dt (* 60 mintime))
5815 ;; a very short clocking chunk
5816 (setq issue (format "Clocking interval is very short: %s"
5817 (org-minutes-to-hh:mm-string
5818 (floor (/ (float dt) 60.))))
5819 face (or (plist-get pl :short-face) face)))
5820 ((and (> tlend 0) (< ts tlend))
5821 ;; Two clock entries are overlapping
5822 (setq issue (format "Clocking overlap: %d minutes"
5823 (/ (- tlend ts) 60))
5824 face (or (plist-get pl :overlap-face) face)))
5825 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5826 ;; There is a gap, lets see if we need to report it
5827 (unless (org-agenda-check-clock-gap tlend ts gapok)
5828 (setq issue (format "Clocking gap: %d minutes"
5829 (/ (- ts tlend) 60))
5830 face (or (plist-get pl :gap-face) face))))
5831 (t nil)))
5832 (setq tlend (or te tlend) tlstart (or ts tlstart))
5833 (when issue
5834 ;; OK, there was some issue, add an overlay to show the issue
5835 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5836 (overlay-put ov 'before-string
5837 (concat
5838 (org-add-props
5839 (format "%-43s" (concat " " issue))
5841 'face face)
5842 "\n"))
5843 (overlay-put ov 'evaporate t)))))
5845 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5846 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5847 (catch 'exit
5848 (unless ok-list
5849 ;; there are no OK times for gaps...
5850 (throw 'exit nil))
5851 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5852 ;; This is more than 24 hours, so it is OK.
5853 ;; because we have at least one OK time, that must be in the
5854 ;; 24 hour interval.
5855 (throw 'exit t))
5856 ;; We have a shorter gap.
5857 ;; Now we have to get the minute of the day when these times are
5858 (let* ((t1dec (decode-time (seconds-to-time t1)))
5859 (t2dec (decode-time (seconds-to-time t2)))
5860 ;; compute the minute on the day
5861 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5862 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5863 (when (< min2 min1)
5864 ;; if min2 is smaller than min1, this means it is on the next day.
5865 ;; Wrap it to after midnight.
5866 (setq min2 (+ min2 1440)))
5867 ;; Now check if any of the OK times is in the gap
5868 (mapc (lambda (x)
5869 ;; Wrap the time to after midnight if necessary
5870 (if (< x min1) (setq x (+ x 1440)))
5871 ;; Check if in interval
5872 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5873 ok-list)
5874 ;; Nope, this gap is not OK
5875 nil)))
5877 (defun org-agenda-get-deadlines ()
5878 "Return the deadline information for agenda display."
5879 (let* ((props (list 'mouse-face 'highlight
5880 'org-not-done-regexp org-not-done-regexp
5881 'org-todo-regexp org-todo-regexp
5882 'org-complex-heading-regexp org-complex-heading-regexp
5883 'help-echo
5884 (format "mouse-2 or RET jump to org file %s"
5885 (abbreviate-file-name buffer-file-name))))
5886 (regexp org-deadline-time-regexp)
5887 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5888 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5889 d2 diff dfrac wdays pos pos1 category category-pos
5890 tags suppress-prewarning ee txt head face s todo-state
5891 show-all upcomingp donep timestr warntime inherited-tags)
5892 (goto-char (point-min))
5893 (while (re-search-forward regexp nil t)
5894 (setq suppress-prewarning nil)
5895 (catch :skip
5896 (org-agenda-skip)
5897 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5898 (save-match-data
5899 (string-match org-scheduled-time-regexp
5900 (buffer-substring (point-at-bol)
5901 (point-at-eol)))))
5902 (setq suppress-prewarning
5903 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5904 org-agenda-skip-deadline-prewarning-if-scheduled
5905 0)))
5906 (setq s (match-string 1)
5907 txt nil
5908 pos (1- (match-beginning 1))
5909 todo-state (save-match-data (org-get-todo-state))
5910 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5911 (member todo-state
5912 org-agenda-repeating-timestamp-show-all))
5913 d2 (org-time-string-to-absolute
5914 (match-string 1) d1 'past show-all
5915 (current-buffer) pos)
5916 diff (- d2 d1)
5917 wdays (if suppress-prewarning
5918 (let ((org-deadline-warning-days suppress-prewarning))
5919 (org-get-wdays s))
5920 (org-get-wdays s))
5921 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5922 upcomingp (and todayp (> diff 0)))
5923 ;; When to show a deadline in the calendar:
5924 ;; If the expiration is within wdays warning time.
5925 ;; Past-due deadlines are only shown on the current date
5926 (if (and (or (and (<= diff wdays)
5927 (and todayp (not org-agenda-only-exact-dates)))
5928 (= diff 0)))
5929 (save-excursion
5930 ;; (setq todo-state (org-get-todo-state))
5931 (setq donep (member todo-state org-done-keywords))
5932 (if (and donep
5933 (or org-agenda-skip-deadline-if-done
5934 (not (= diff 0))))
5935 (setq txt nil)
5936 (setq category (org-get-category)
5937 warntime (get-text-property (point) 'org-appt-warntime)
5938 category-pos (get-text-property (point) 'org-category-position))
5939 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5940 (throw :skip nil)
5941 (goto-char (match-end 0))
5942 (setq pos1 (match-beginning 0))
5943 (setq inherited-tags
5944 (or (eq org-agenda-show-inherited-tags 'always)
5945 (and (listp org-agenda-show-inherited-tags)
5946 (memq 'agenda org-agenda-show-inherited-tags))
5947 (and (eq org-agenda-show-inherited-tags t)
5948 (or (eq org-agenda-use-tag-inheritance t)
5949 (memq 'agenda org-agenda-use-tag-inheritance))))
5950 tags (org-get-tags-at pos1 (not inherited-tags)))
5951 (setq head (buffer-substring
5952 (point)
5953 (progn (skip-chars-forward "^\r\n")
5954 (point))))
5955 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5956 (setq timestr
5957 (concat (substring s (match-beginning 1)) " "))
5958 (setq timestr 'time))
5959 (setq txt (org-agenda-format-item
5960 (if (= diff 0)
5961 (car org-agenda-deadline-leaders)
5962 (if (functionp
5963 (nth 1 org-agenda-deadline-leaders))
5964 (funcall
5965 (nth 1 org-agenda-deadline-leaders)
5966 diff date)
5967 (format (nth 1 org-agenda-deadline-leaders)
5968 diff)))
5969 head category tags
5970 (if (not (= diff 0)) nil timestr)))))
5971 (when txt
5972 (setq face (org-agenda-deadline-face dfrac))
5973 (org-add-props txt props
5974 'org-marker (org-agenda-new-marker pos)
5975 'warntime warntime
5976 'org-hd-marker (org-agenda-new-marker pos1)
5977 'priority (+ (- diff)
5978 (org-get-priority txt))
5979 'org-category category
5980 'org-category-position category-pos
5981 'todo-state todo-state
5982 'type (if upcomingp "upcoming-deadline" "deadline")
5983 'date (if upcomingp date d2)
5984 'face (if donep 'org-agenda-done face)
5985 'undone-face face 'done-face 'org-agenda-done)
5986 (push txt ee))))))
5987 (nreverse ee)))
5989 (defun org-agenda-deadline-face (fraction)
5990 "Return the face to displaying a deadline item.
5991 FRACTION is what fraction of the head-warning time has passed."
5992 (let ((faces org-agenda-deadline-faces) f)
5993 (catch 'exit
5994 (while (setq f (pop faces))
5995 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5997 (defun org-agenda-get-scheduled (&optional deadline-results)
5998 "Return the scheduled information for agenda display."
5999 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6000 'org-todo-regexp org-todo-regexp
6001 'org-complex-heading-regexp org-complex-heading-regexp
6002 'done-face 'org-agenda-done
6003 'mouse-face 'highlight
6004 'help-echo
6005 (format "mouse-2 or RET jump to org file %s"
6006 (abbreviate-file-name buffer-file-name))))
6007 (regexp org-scheduled-time-regexp)
6008 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6009 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6011 (deadline-position-alist
6012 (mapcar (lambda (a) (and (setq mm (get-text-property
6013 0 'org-hd-marker a))
6014 (cons (marker-position mm) a)))
6015 deadline-results))
6016 d2 diff pos pos1 category category-pos tags donep
6017 ee txt head pastschedp todo-state face timestr s habitp show-all
6018 did-habit-check-p warntime inherited-tags)
6019 (goto-char (point-min))
6020 (while (re-search-forward regexp nil t)
6021 (catch :skip
6022 (org-agenda-skip)
6023 (setq s (match-string 1)
6024 txt nil
6025 pos (1- (match-beginning 1))
6026 todo-state (save-match-data (org-get-todo-state))
6027 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6028 (member todo-state
6029 org-agenda-repeating-timestamp-show-all))
6030 d2 (org-time-string-to-absolute
6031 (match-string 1) d1 'past show-all
6032 (current-buffer) pos)
6033 diff (- d2 d1)
6034 warntime (get-text-property (point) 'org-appt-warntime))
6035 (setq pastschedp (and todayp (< diff 0)))
6036 (setq did-habit-check-p nil)
6037 ;; When to show a scheduled item in the calendar:
6038 ;; If it is on or past the date.
6039 (when (or (and (< diff 0)
6040 (< (abs diff) org-scheduled-past-days)
6041 (and todayp (not org-agenda-only-exact-dates)))
6042 (= diff 0)
6043 ;; org-is-habit-p uses org-entry-get, which is expansive
6044 ;; so we go extra mile to only call it once
6045 (and todayp
6046 (boundp 'org-habit-show-all-today)
6047 org-habit-show-all-today
6048 (setq did-habit-check-p t)
6049 (setq habitp (and (functionp 'org-is-habit-p)
6050 (org-is-habit-p)))))
6051 (save-excursion
6052 (setq donep (member todo-state org-done-keywords))
6053 (if (and donep
6054 (or org-agenda-skip-scheduled-if-done
6055 (not (= diff 0))
6056 (and (functionp 'org-is-habit-p)
6057 (org-is-habit-p))))
6058 (setq txt nil)
6059 (setq habitp (if did-habit-check-p habitp
6060 (and (functionp 'org-is-habit-p)
6061 (org-is-habit-p))))
6062 (setq category (org-get-category)
6063 category-pos (get-text-property (point) 'org-category-position))
6064 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6065 (throw :skip nil)
6066 (goto-char (match-end 0))
6067 (setq pos1 (match-beginning 0))
6068 (if habitp
6069 (if (or (not org-habit-show-habits)
6070 (and (not todayp)
6071 (boundp 'org-habit-show-habits-only-for-today)
6072 org-habit-show-habits-only-for-today))
6073 (throw :skip nil))
6074 (if (and
6075 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6076 (and org-agenda-skip-scheduled-if-deadline-is-shown
6077 pastschedp))
6078 (setq mm (assoc pos1 deadline-position-alist)))
6079 (throw :skip nil)))
6080 (setq inherited-tags
6081 (or (eq org-agenda-show-inherited-tags 'always)
6082 (and (listp org-agenda-show-inherited-tags)
6083 (memq 'agenda org-agenda-show-inherited-tags))
6084 (and (eq org-agenda-show-inherited-tags t)
6085 (or (eq org-agenda-use-tag-inheritance t)
6086 (memq 'agenda org-agenda-use-tag-inheritance))))
6087 tags (org-get-tags-at nil (not inherited-tags)))
6088 (setq head (buffer-substring
6089 (point)
6090 (progn (skip-chars-forward "^\r\n") (point))))
6091 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6092 (setq timestr
6093 (concat (substring s (match-beginning 1)) " "))
6094 (setq timestr 'time))
6095 (setq txt (org-agenda-format-item
6096 (if (= diff 0)
6097 (car org-agenda-scheduled-leaders)
6098 (format (nth 1 org-agenda-scheduled-leaders)
6099 (- 1 diff)))
6100 head category tags
6101 (if (not (= diff 0)) nil timestr)
6102 nil habitp))))
6103 (when txt
6104 (setq face
6105 (cond
6106 ((and (not habitp) pastschedp)
6107 'org-scheduled-previously)
6108 (todayp 'org-scheduled-today)
6109 (t 'org-scheduled))
6110 habitp (and habitp (org-habit-parse-todo)))
6111 (org-add-props txt props
6112 'undone-face face
6113 'face (if donep 'org-agenda-done face)
6114 'org-marker (org-agenda-new-marker pos)
6115 'org-hd-marker (org-agenda-new-marker pos1)
6116 'type (if pastschedp "past-scheduled" "scheduled")
6117 'date (if pastschedp d2 date)
6118 'warntime warntime
6119 'priority (if habitp
6120 (org-habit-get-priority habitp)
6121 (+ 94 (- 5 diff) (org-get-priority txt)))
6122 'org-category category
6123 'category-position category-pos
6124 'org-habit-p habitp
6125 'todo-state todo-state)
6126 (push txt ee))))))
6127 (nreverse ee)))
6129 (defun org-agenda-get-blocks ()
6130 "Return the date-range information for agenda display."
6131 (let* ((props (list 'face nil
6132 'org-not-done-regexp org-not-done-regexp
6133 'org-todo-regexp org-todo-regexp
6134 'org-complex-heading-regexp org-complex-heading-regexp
6135 'mouse-face 'highlight
6136 'help-echo
6137 (format "mouse-2 or RET jump to org file %s"
6138 (abbreviate-file-name buffer-file-name))))
6139 (regexp org-tr-regexp)
6140 (d0 (calendar-absolute-from-gregorian date))
6141 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6142 todo-state tags pos head donep inherited-tags)
6143 (goto-char (point-min))
6144 (while (re-search-forward regexp nil t)
6145 (catch :skip
6146 (org-agenda-skip)
6147 (setq pos (point))
6148 (let ((start-time (match-string 1))
6149 (end-time (match-string 2)))
6150 (setq s1 (match-string 1)
6151 s2 (match-string 2)
6152 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6153 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6154 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6155 ;; Only allow days between the limits, because the normal
6156 ;; date stamps will catch the limits.
6157 (save-excursion
6158 (setq todo-state (org-get-todo-state))
6159 (setq donep (member todo-state org-done-keywords))
6160 (if (and donep org-agenda-skip-timestamp-if-done)
6161 (throw :skip t))
6162 (setq marker (org-agenda-new-marker (point)))
6163 (setq category (org-get-category)
6164 category-pos (get-text-property (point) 'org-category-position))
6165 (if (not (re-search-backward org-outline-regexp-bol nil t))
6166 (throw :skip nil)
6167 (goto-char (match-beginning 0))
6168 (setq hdmarker (org-agenda-new-marker (point))
6169 inherited-tags
6170 (or (eq org-agenda-show-inherited-tags 'always)
6171 (and (listp org-agenda-show-inherited-tags)
6172 (memq 'agenda org-agenda-show-inherited-tags))
6173 (and (eq org-agenda-show-inherited-tags t)
6174 (or (eq org-agenda-use-tag-inheritance t)
6175 (memq 'agenda org-agenda-use-tag-inheritance))))
6176 tags (org-get-tags-at nil (not inherited-tags)))
6177 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6178 (setq head (match-string 1))
6179 (let ((remove-re
6180 (if org-agenda-remove-timeranges-from-blocks
6181 (concat
6182 "<" (regexp-quote s1) ".*?>"
6183 "--"
6184 "<" (regexp-quote s2) ".*?>")
6185 nil)))
6186 (setq txt (org-agenda-format-item
6187 (format
6188 (nth (if (= d1 d2) 0 1)
6189 org-agenda-timerange-leaders)
6190 (1+ (- d0 d1)) (1+ (- d2 d1)))
6191 head category tags
6192 (cond ((and (= d1 d0) (= d2 d0))
6193 (concat "<" start-time ">--<" end-time ">"))
6194 ((= d1 d0)
6195 (concat "<" start-time ">"))
6196 ((= d2 d0)
6197 (concat "<" end-time ">")))
6198 remove-re))))
6199 (org-add-props txt props
6200 'org-marker marker 'org-hd-marker hdmarker
6201 'type "block" 'date date
6202 'todo-state todo-state
6203 'priority (org-get-priority txt) 'org-category category
6204 'org-category-position category-pos)
6205 (push txt ee))))
6206 (goto-char pos)))
6207 ;; Sort the entries by expiration date.
6208 (nreverse ee)))
6210 ;;; Agenda presentation and sorting
6212 (defvar org-prefix-has-time nil
6213 "A flag, set by `org-compile-prefix-format'.
6214 The flag is set if the currently compiled format contains a `%t'.")
6215 (defvar org-prefix-has-tag nil
6216 "A flag, set by `org-compile-prefix-format'.
6217 The flag is set if the currently compiled format contains a `%T'.")
6218 (defvar org-prefix-has-effort nil
6219 "A flag, set by `org-compile-prefix-format'.
6220 The flag is set if the currently compiled format contains a `%e'.")
6221 (defvar org-prefix-category-length nil
6222 "Used by `org-compile-prefix-format' to remember the category field width.")
6223 (defvar org-prefix-category-max-length nil
6224 "Used by `org-compile-prefix-format' to remember the category field width.")
6226 (defun org-agenda-get-category-icon (category)
6227 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6228 (dolist (entry org-agenda-category-icon-alist)
6229 (when (org-string-match-p (car entry) category)
6230 (if (listp (cadr entry))
6231 (return (cadr entry))
6232 (return (apply 'create-image (cdr entry)))))))
6234 (defun org-agenda-format-item (extra txt &optional category tags dotime
6235 remove-re habitp)
6236 "Format TXT to be inserted into the agenda buffer.
6237 In particular, it adds the prefix and corresponding text properties. EXTRA
6238 must be a string and replaces the `%s' specifier in the prefix format.
6239 CATEGORY (string, symbol or nil) may be used to overrule the default
6240 category taken from local variable or file name. It will replace the `%c'
6241 specifier in the format. DOTIME, when non-nil, indicates that a
6242 time-of-day should be extracted from TXT for sorting of this entry, and for
6243 the `%t' specifier in the format. When DOTIME is a string, this string is
6244 searched for a time before TXT is. TAGS can be the tags of the headline.
6245 Any match of REMOVE-RE will be removed from TXT."
6246 ;; We keep the org-prefix-* variable values along with a compiled
6247 ;; formatter, so that multiple agendas existing at the same time, do
6248 ;; not step on each other toes.
6250 ;; It was inconvenient to make these variables buffer local in
6251 ;; Agenda buffers, because this function expects to be called with
6252 ;; the buffer where item comes from being current, and not agenda
6253 ;; buffer
6254 (let* ((bindings (car org-prefix-format-compiled))
6255 (formatter (cadr org-prefix-format-compiled)))
6256 (loop for (var value) in bindings
6257 do (set var value))
6258 (save-match-data
6259 ;; Diary entries sometimes have extra whitespace at the beginning
6260 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
6262 ;; Fix the tags part in txt
6263 (setq txt (org-agenda-fix-displayed-tags
6264 txt tags
6265 org-agenda-show-inherited-tags
6266 org-agenda-hide-tags-regexp))
6267 (let* ((category (or category
6268 (if (stringp org-category)
6269 org-category
6270 (and org-category (symbol-name org-category)))
6271 (if buffer-file-name
6272 (file-name-sans-extension
6273 (file-name-nondirectory buffer-file-name))
6274 "")))
6275 (category-icon (org-agenda-get-category-icon category))
6276 (category-icon (if category-icon
6277 (propertize " " 'display category-icon)
6278 ""))
6279 ;; time, tag, effort are needed for the eval of the prefix format
6280 (tag (if tags (nth (1- (length tags)) tags) ""))
6281 time effort neffort
6282 (ts (if dotime (concat
6283 (if (stringp dotime) dotime "")
6284 (and org-agenda-search-headline-for-time txt))))
6285 (time-of-day (and dotime (org-get-time-of-day ts)))
6286 stamp plain s0 s1 s2 rtn srp l
6287 duration thecategory)
6288 (and (derived-mode-p 'org-mode) buffer-file-name
6289 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6290 (when (and dotime time-of-day)
6291 ;; Extract starting and ending time and move them to prefix
6292 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6293 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6294 (setq s0 (match-string 0 ts)
6295 srp (and stamp (match-end 3))
6296 s1 (match-string (if plain 1 2) ts)
6297 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6299 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6300 ;; them, we might want to remove them there to avoid duplication.
6301 ;; The user can turn this off with a variable.
6302 (if (and org-prefix-has-time
6303 org-agenda-remove-times-when-in-prefix (or stamp plain)
6304 (string-match (concat (regexp-quote s0) " *") txt)
6305 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6306 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6307 (= (match-beginning 0) 0)
6309 (setq txt (replace-match "" nil nil txt))))
6310 ;; Normalize the time(s) to 24 hour
6311 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6312 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6314 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6315 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6316 (setq s2
6317 (org-minutes-to-hh:mm-string
6318 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6320 ;; Compute the duration
6321 (when s2
6322 (setq duration (- (org-hh:mm-string-to-minutes s2)
6323 (org-hh:mm-string-to-minutes s1)))))
6325 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6326 txt)
6327 ;; Tags are in the string
6328 (if (or (eq org-agenda-remove-tags t)
6329 (and org-agenda-remove-tags
6330 org-prefix-has-tag))
6331 (setq txt (replace-match "" t t txt))
6332 (setq txt (replace-match
6333 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6334 (match-string 2 txt))
6335 t t txt))))
6336 (when (derived-mode-p 'org-mode)
6337 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6338 (when effort
6339 (setq neffort (org-duration-string-to-minutes effort)
6340 effort (setq effort (concat "[" effort "]")))))
6341 ;; prevent erroring out with %e format when there is no effort
6342 (or effort (setq effort ""))
6344 (when remove-re
6345 (while (string-match remove-re txt)
6346 (setq txt (replace-match "" t t txt))))
6348 ;; Set org-heading property on `txt' to mark the start of the
6349 ;; heading.
6350 (add-text-properties 0 (length txt) '(org-heading t) txt)
6352 ;; Prepare the variables needed in the eval of the compiled format
6353 (setq time (cond (s2 (concat
6354 (org-agenda-time-of-day-to-ampm-maybe s1)
6355 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6356 (if org-agenda-timegrid-use-ampm " ")))
6357 (s1 (concat
6358 (org-agenda-time-of-day-to-ampm-maybe s1)
6359 (if org-agenda-timegrid-use-ampm
6360 "........ "
6361 "......")))
6362 (t ""))
6363 extra (or (and (not habitp) extra) "")
6364 category (if (symbolp category) (symbol-name category) category)
6365 thecategory (copy-sequence category))
6366 (if (string-match org-bracket-link-regexp category)
6367 (progn
6368 (setq l (if (match-end 3)
6369 (- (match-end 3) (match-beginning 3))
6370 (- (match-end 1) (match-beginning 1))))
6371 (when (< l (or org-prefix-category-length 0))
6372 (setq category (copy-sequence category))
6373 (org-add-props category nil
6374 'extra-space (make-string
6375 (- org-prefix-category-length l 1) ?\ ))))
6376 (if (and org-prefix-category-max-length
6377 (>= (length category) org-prefix-category-max-length))
6378 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6379 ;; Evaluate the compiled format
6380 (setq rtn (concat (eval formatter) txt))
6382 ;; And finally add the text properties
6383 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6384 (org-add-props rtn nil
6385 'org-category (if thecategory (downcase thecategory) category)
6386 'tags (mapcar 'org-downcase-keep-props tags)
6387 'org-highest-priority org-highest-priority
6388 'org-lowest-priority org-lowest-priority
6389 'time-of-day time-of-day
6390 'duration duration
6391 'effort effort
6392 'effort-minutes neffort
6393 'txt txt
6394 'time time
6395 'extra extra
6396 'format org-prefix-format-compiled
6397 'dotime dotime)))))
6399 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6400 "Remove tags string from TXT, and add a modified list of tags.
6401 The modified list may contain inherited tags, and tags matched by
6402 `org-agenda-hide-tags-regexp' will be removed."
6403 (when (or add-inherited hide-re)
6404 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6405 (setq txt (substring txt 0 (match-beginning 0))))
6406 (setq tags
6407 (delq nil
6408 (mapcar (lambda (tg)
6409 (if (or (and hide-re (string-match hide-re tg))
6410 (and (not add-inherited)
6411 (get-text-property 0 'inherited tg)))
6413 tg))
6414 tags)))
6415 (when tags
6416 (let ((have-i (get-text-property 0 'inherited (car tags)))
6418 (setq txt (concat txt " :"
6419 (mapconcat
6420 (lambda (x)
6421 (setq i (get-text-property 0 'inherited x))
6422 (if (and have-i (not i))
6423 (progn
6424 (setq have-i nil)
6425 (concat ":" x))
6427 tags ":")
6428 (if have-i "::" ":"))))))
6429 txt)
6431 (defun org-downcase-keep-props (s)
6432 (let ((props (text-properties-at 0 s)))
6433 (setq s (downcase s))
6434 (add-text-properties 0 (length s) props s)
6437 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6438 (defvar org-agenda-sorting-strategy-selected nil)
6440 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6441 (catch 'exit
6442 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6443 ((and todayp (member 'today (car org-agenda-time-grid))))
6444 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6445 ((member 'weekly (car org-agenda-time-grid)))
6446 (t (throw 'exit list)))
6447 (let* ((have (delq nil (mapcar
6448 (lambda (x) (get-text-property 1 'time-of-day x))
6449 list)))
6450 (string (nth 1 org-agenda-time-grid))
6451 (gridtimes (nth 2 org-agenda-time-grid))
6452 (req (car org-agenda-time-grid))
6453 (remove (member 'remove-match req))
6454 new time)
6455 (if (and (member 'require-timed req) (not have))
6456 ;; don't show empty grid
6457 (throw 'exit list))
6458 (while (setq time (pop gridtimes))
6459 (unless (and remove (member time have))
6460 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6461 (push (org-agenda-format-item
6462 nil string "" nil
6463 (concat (substring time 0 -2) ":" (substring time -2)))
6464 new)
6465 (put-text-property
6466 2 (length (car new)) 'face 'org-time-grid (car new))))
6467 (when (and todayp org-agenda-show-current-time-in-grid)
6468 (push (org-agenda-format-item
6470 org-agenda-current-time-string
6471 "" nil
6472 (format-time-string "%H:%M "))
6473 new)
6474 (put-text-property
6475 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6477 (if (member 'time-up org-agenda-sorting-strategy-selected)
6478 (append new list)
6479 (append list new)))))
6481 (defun org-compile-prefix-format (key)
6482 "Compile the prefix format into a Lisp form that can be evaluated.
6483 The resulting form and associated variable bindings is returned
6484 and stored in the variable `org-prefix-format-compiled'."
6485 (setq org-prefix-has-time nil org-prefix-has-tag nil
6486 org-prefix-category-length nil
6487 org-prefix-has-effort nil)
6488 (let ((s (cond
6489 ((stringp org-agenda-prefix-format)
6490 org-agenda-prefix-format)
6491 ((assq key org-agenda-prefix-format)
6492 (cdr (assq key org-agenda-prefix-format)))
6493 (t " %-12:c%?-12t% s")))
6494 (start 0)
6495 varform vars var e c f opt)
6496 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6497 s start)
6498 (setq var (or (cdr (assoc (match-string 4 s)
6499 '(("c" . category) ("t" . time) ("s" . extra)
6500 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6501 'eval)
6502 c (or (match-string 3 s) "")
6503 opt (match-beginning 1)
6504 start (1+ (match-beginning 0)))
6505 (if (equal var 'time) (setq org-prefix-has-time t))
6506 (if (equal var 'tag) (setq org-prefix-has-tag t))
6507 (if (equal var 'effort) (setq org-prefix-has-effort t))
6508 (setq f (concat "%" (match-string 2 s) "s"))
6509 (when (equal var 'category)
6510 (setq org-prefix-category-length
6511 (floor (abs (string-to-number (match-string 2 s)))))
6512 (setq org-prefix-category-max-length
6513 (let ((x (match-string 2 s)))
6514 (save-match-data
6515 (if (string-match "\\.[0-9]+" x)
6516 (string-to-number (substring (match-string 0 x) 1)))))))
6517 (if (eq var 'eval)
6518 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6519 (if opt
6520 (setq varform
6521 `(if (equal "" ,var)
6523 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6524 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6525 (setq s (replace-match "%s" t nil s))
6526 (push varform vars))
6527 (setq vars (nreverse vars))
6528 (with-current-buffer (or org-agenda-buffer (current-buffer))
6529 (setq org-prefix-format-compiled
6530 (list
6531 `((org-prefix-has-time ,org-prefix-has-time)
6532 (org-prefix-has-tag ,org-prefix-has-tag)
6533 (org-prefix-category-length ,org-prefix-category-length)
6534 (org-prefix-has-effort ,org-prefix-has-effort))
6535 `(format ,s ,@vars))))))
6537 (defun org-set-sorting-strategy (key)
6538 (if (symbolp (car org-agenda-sorting-strategy))
6539 ;; the old format
6540 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6541 (setq org-agenda-sorting-strategy-selected
6542 (or (cdr (assq key org-agenda-sorting-strategy))
6543 (cdr (assq 'agenda org-agenda-sorting-strategy))
6544 '(time-up category-keep priority-down)))))
6546 (defun org-get-time-of-day (s &optional string mod24)
6547 "Check string S for a time of day.
6548 If found, return it as a military time number between 0 and 2400.
6549 If not found, return nil.
6550 The optional STRING argument forces conversion into a 5 character wide string
6551 HH:MM."
6552 (save-match-data
6553 (when
6554 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6555 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6556 (let* ((h (string-to-number (match-string 1 s)))
6557 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6558 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6559 (am-p (equal ampm "am"))
6560 (h1 (cond ((not ampm) h)
6561 ((= h 12) (if am-p 0 12))
6562 (t (+ h (if am-p 0 12)))))
6563 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6564 (mod h1 24) h1))
6565 (t0 (+ (* 100 h2) m))
6566 (t1 (concat (if (>= h1 24) "+" " ")
6567 (if (and org-agenda-time-leading-zero
6568 (< t0 1000)) "0" "")
6569 (if (< t0 100) "0" "")
6570 (if (< t0 10) "0" "")
6571 (int-to-string t0))))
6572 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6574 (defvar org-agenda-before-sorting-filter-function nil
6575 "Function to be applied to agenda items prior to sorting.
6576 Prior to sorting also means just before they are inserted into the agenda.
6578 To aid sorting, you may revisit the original entries and add more text
6579 properties which will later be used by the sorting functions.
6581 The function should take a string argument, an agenda line.
6582 It has access to the text properties in that line, which contain among
6583 other things, the property `org-hd-marker' that points to the entry
6584 where the line comes from. Note that not all lines going into the agenda
6585 have this property, only most.
6587 The function should return the modified string. It is probably best
6588 to ONLY change text properties.
6590 You can also use this function as a filter, by returning nil for lines
6591 you don't want to have in the agenda at all. For this application, you
6592 could bind the variable in the options section of a custom command.")
6594 (defun org-agenda-finalize-entries (list &optional nosort)
6595 "Sort and concatenate the agenda items."
6596 (setq list (mapcar 'org-agenda-highlight-todo list))
6597 (if nosort
6598 list
6599 (when org-agenda-before-sorting-filter-function
6600 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6601 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6603 (defun org-agenda-highlight-todo (x)
6604 (let ((org-done-keywords org-done-keywords-for-agenda)
6605 (case-fold-search nil)
6607 (if (eq x 'line)
6608 (save-excursion
6609 (beginning-of-line 1)
6610 (setq re (org-get-at-bol 'org-todo-regexp))
6611 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6612 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6613 (add-text-properties (match-beginning 0) (match-end 1)
6614 (list 'face (org-get-todo-face 1)))
6615 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6616 (delete-region (match-beginning 1) (1- (match-end 0)))
6617 (goto-char (match-beginning 1))
6618 (insert (format org-agenda-todo-keyword-format s)))))
6619 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6620 (setq re (get-text-property 0 'org-todo-regexp x))
6621 (when (and re
6622 ;; Test `pl' because if there's no heading content,
6623 ;; there's no point matching to highlight. Note
6624 ;; that if we didn't test `pl' first, and there
6625 ;; happened to be no keyword from `org-todo-regexp'
6626 ;; on this heading line, then the `equal' comparison
6627 ;; afterwards would spuriously succeed in the case
6628 ;; where `pl' is nil -- causing an args-out-of-range
6629 ;; error when we try to add text properties to text
6630 ;; that isn't there.
6632 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6633 x pl) pl))
6634 (add-text-properties
6635 (or (match-end 1) (match-end 0)) (match-end 0)
6636 (list 'face (org-get-todo-face (match-string 2 x)))
6638 (when (match-end 1)
6639 (setq x (concat (substring x 0 (match-end 1))
6640 (format org-agenda-todo-keyword-format
6641 (match-string 2 x))
6642 (org-add-props " " (text-properties-at 0 x))
6643 (substring x (match-end 3)))))))
6644 x)))
6646 (defsubst org-cmp-priority (a b)
6647 "Compare the priorities of string A and B."
6648 (let ((pa (or (get-text-property 1 'priority a) 0))
6649 (pb (or (get-text-property 1 'priority b) 0)))
6650 (cond ((> pa pb) +1)
6651 ((< pa pb) -1))))
6653 (defsubst org-cmp-effort (a b)
6654 "Compare the effort values of string A and B."
6655 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6656 (ea (or (get-text-property 1 'effort-minutes a) def))
6657 (eb (or (get-text-property 1 'effort-minutes b) def)))
6658 (cond ((> ea eb) +1)
6659 ((< ea eb) -1))))
6661 (defsubst org-cmp-category (a b)
6662 "Compare the string values of categories of strings A and B."
6663 (let ((ca (or (get-text-property 1 'org-category a) ""))
6664 (cb (or (get-text-property 1 'org-category b) "")))
6665 (cond ((string-lessp ca cb) -1)
6666 ((string-lessp cb ca) +1))))
6668 (defsubst org-cmp-todo-state (a b)
6669 "Compare the todo states of strings A and B."
6670 (let* ((ma (or (get-text-property 1 'org-marker a)
6671 (get-text-property 1 'org-hd-marker a)))
6672 (mb (or (get-text-property 1 'org-marker b)
6673 (get-text-property 1 'org-hd-marker b)))
6674 (fa (and ma (marker-buffer ma)))
6675 (fb (and mb (marker-buffer mb)))
6676 (todo-kwds
6677 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6678 (and fb (with-current-buffer fb org-todo-keywords-1))))
6679 (ta (or (get-text-property 1 'todo-state a) ""))
6680 (tb (or (get-text-property 1 'todo-state b) ""))
6681 (la (- (length (member ta todo-kwds))))
6682 (lb (- (length (member tb todo-kwds))))
6683 (donepa (member ta org-done-keywords-for-agenda))
6684 (donepb (member tb org-done-keywords-for-agenda)))
6685 (cond ((and donepa (not donepb)) -1)
6686 ((and (not donepa) donepb) +1)
6687 ((< la lb) -1)
6688 ((< lb la) +1))))
6690 (defsubst org-cmp-alpha (a b)
6691 "Compare the headlines, alphabetically."
6692 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6693 (plb (text-property-any 0 (length b) 'org-heading t b))
6694 (ta (and pla (substring a pla)))
6695 (tb (and plb (substring b plb))))
6696 (when pla
6697 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6698 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6699 (setq ta (substring ta (match-end 0))))
6700 (setq ta (downcase ta)))
6701 (when plb
6702 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6703 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6704 (setq tb (substring tb (match-end 0))))
6705 (setq tb (downcase tb)))
6706 (cond ((not ta) +1)
6707 ((not tb) -1)
6708 ((string-lessp ta tb) -1)
6709 ((string-lessp tb ta) +1))))
6711 (defsubst org-cmp-tag (a b)
6712 "Compare the string values of the first tags of A and B."
6713 (let ((ta (car (last (get-text-property 1 'tags a))))
6714 (tb (car (last (get-text-property 1 'tags b)))))
6715 (cond ((not ta) +1)
6716 ((not tb) -1)
6717 ((string-lessp ta tb) -1)
6718 ((string-lessp tb ta) +1))))
6720 (defsubst org-cmp-time (a b)
6721 "Compare the time-of-day values of strings A and B."
6722 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6723 (ta (or (get-text-property 1 'time-of-day a) def))
6724 (tb (or (get-text-property 1 'time-of-day b) def)))
6725 (cond ((< ta tb) -1)
6726 ((< tb ta) +1))))
6728 (defsubst org-cmp-habit-p (a b)
6729 "Compare the todo states of strings A and B."
6730 (let ((ha (get-text-property 1 'org-habit-p a))
6731 (hb (get-text-property 1 'org-habit-p b)))
6732 (cond ((and ha (not hb)) -1)
6733 ((and (not ha) hb) +1))))
6735 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6737 (defun org-entries-lessp (a b)
6738 "Predicate for sorting agenda entries."
6739 ;; The following variables will be used when the form is evaluated.
6740 ;; So even though the compiler complains, keep them.
6741 (let* ((ss org-agenda-sorting-strategy-selected)
6742 (time-up (and (org-em 'time-up 'time-down ss)
6743 (org-cmp-time a b)))
6744 (time-down (if time-up (- time-up) nil))
6745 (priority-up (and (org-em 'priority-up 'priority-down ss)
6746 (org-cmp-priority a b)))
6747 (priority-down (if priority-up (- priority-up) nil))
6748 (effort-up (and (org-em 'effort-up 'effort-down ss)
6749 (org-cmp-effort a b)))
6750 (effort-down (if effort-up (- effort-up) nil))
6751 (category-up (and (or (org-em 'category-up 'category-down ss)
6752 (memq 'category-keep ss))
6753 (org-cmp-category a b)))
6754 (category-down (if category-up (- category-up) nil))
6755 (category-keep (if category-up +1 nil))
6756 (tag-up (and (org-em 'tag-up 'tag-down ss)
6757 (org-cmp-tag a b)))
6758 (tag-down (if tag-up (- tag-up) nil))
6759 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6760 (org-cmp-todo-state a b)))
6761 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6762 (habit-up (and (org-em 'habit-up 'habit-down ss)
6763 (org-cmp-habit-p a b)))
6764 (habit-down (if habit-up (- habit-up) nil))
6765 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6766 (org-cmp-alpha a b)))
6767 (alpha-down (if alpha-up (- alpha-up) nil))
6768 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6769 user-defined-up user-defined-down)
6770 (if (and need-user-cmp org-agenda-cmp-user-defined
6771 (functionp org-agenda-cmp-user-defined))
6772 (setq user-defined-up
6773 (funcall org-agenda-cmp-user-defined a b)
6774 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6775 (cdr (assoc
6776 (eval (cons 'or org-agenda-sorting-strategy-selected))
6777 '((-1 . t) (1 . nil) (nil . nil))))))
6779 ;;; Agenda restriction lock
6781 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6782 "Overlay to mark the headline to which agenda commands are restricted.")
6783 (overlay-put org-agenda-restriction-lock-overlay
6784 'face 'org-agenda-restriction-lock)
6785 (overlay-put org-agenda-restriction-lock-overlay
6786 'help-echo "Agendas are currently limited to this subtree.")
6787 (org-detach-overlay org-agenda-restriction-lock-overlay)
6789 (defun org-agenda-set-restriction-lock (&optional type)
6790 "Set restriction lock for agenda, to current subtree or file.
6791 Restriction will be the file if TYPE is `file', or if type is the
6792 universal prefix '(4), or if the cursor is before the first headline
6793 in the file. Otherwise, restriction will be to the current subtree."
6794 (interactive "P")
6795 (and (equal type '(4)) (setq type 'file))
6796 (setq type (cond
6797 (type type)
6798 ((org-at-heading-p) 'subtree)
6799 ((condition-case nil (org-back-to-heading t) (error nil))
6800 'subtree)
6801 (t 'file)))
6802 (if (eq type 'subtree)
6803 (progn
6804 (setq org-agenda-restrict t)
6805 (setq org-agenda-overriding-restriction 'subtree)
6806 (put 'org-agenda-files 'org-restrict
6807 (list (buffer-file-name (buffer-base-buffer))))
6808 (org-back-to-heading t)
6809 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6810 (move-marker org-agenda-restrict-begin (point))
6811 (move-marker org-agenda-restrict-end
6812 (save-excursion (org-end-of-subtree t)))
6813 (message "Locking agenda restriction to subtree"))
6814 (put 'org-agenda-files 'org-restrict
6815 (list (buffer-file-name (buffer-base-buffer))))
6816 (setq org-agenda-restrict nil)
6817 (setq org-agenda-overriding-restriction 'file)
6818 (move-marker org-agenda-restrict-begin nil)
6819 (move-marker org-agenda-restrict-end nil)
6820 (message "Locking agenda restriction to file"))
6821 (setq current-prefix-arg nil)
6822 (org-agenda-maybe-redo))
6824 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6825 "Remove the agenda restriction lock."
6826 (interactive "P")
6827 (org-detach-overlay org-agenda-restriction-lock-overlay)
6828 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6829 (setq org-agenda-overriding-restriction nil)
6830 (setq org-agenda-restrict nil)
6831 (put 'org-agenda-files 'org-restrict nil)
6832 (move-marker org-agenda-restrict-begin nil)
6833 (move-marker org-agenda-restrict-end nil)
6834 (setq current-prefix-arg nil)
6835 (message "Agenda restriction lock removed")
6836 (or noupdate (org-agenda-maybe-redo)))
6838 (defun org-agenda-maybe-redo ()
6839 "If there is any window showing the agenda view, update it."
6840 (let ((w (get-buffer-window org-agenda-buffer-name t))
6841 (w0 (selected-window)))
6842 (when w
6843 (select-window w)
6844 (org-agenda-redo)
6845 (select-window w0)
6846 (if org-agenda-overriding-restriction
6847 (message "Agenda view shifted to new %s restriction"
6848 org-agenda-overriding-restriction)
6849 (message "Agenda restriction lock removed")))))
6851 ;;; Agenda commands
6853 (defun org-agenda-check-type (error &rest types)
6854 "Check if agenda buffer is of allowed type.
6855 If ERROR is non-nil, throw an error, otherwise just return nil.
6856 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
6857 (if (not org-agenda-type)
6858 (error "No Org agenda currently displayed")
6859 (if (memq org-agenda-type types)
6861 (if error
6862 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6863 nil))))
6865 (defun org-agenda-Quit (&optional arg)
6866 "Exit agenda by removing the window or the buffer."
6867 (interactive)
6868 (if org-agenda-columns-active
6869 (org-columns-quit)
6870 (let ((buf (current-buffer)))
6871 (if (eq org-agenda-window-setup 'other-frame)
6872 (progn
6873 (org-agenda-reset-markers)
6874 (kill-buffer buf)
6875 (org-columns-remove-overlays)
6876 (setq org-agenda-archives-mode nil)
6877 (delete-frame))
6878 (and (not (eq org-agenda-window-setup 'current-window))
6879 (not (one-window-p))
6880 (delete-window))
6881 (org-agenda-reset-markers)
6882 (kill-buffer buf)
6883 (org-columns-remove-overlays)
6884 (setq org-agenda-archives-mode nil)))
6885 ;; Maybe restore the pre-agenda window configuration.
6886 (and org-agenda-restore-windows-after-quit
6887 (not (eq org-agenda-window-setup 'other-frame))
6888 org-agenda-pre-window-conf
6889 (set-window-configuration org-agenda-pre-window-conf)
6890 (setq org-agenda-pre-window-conf nil))))
6892 (defun org-agenda-quit ()
6893 "Exit agenda by killing agenda buffer or burying it when
6894 `org-agenda-sticky' is non-NIL"
6895 (interactive)
6896 (if (and (eq org-indirect-buffer-display 'other-window)
6897 org-last-indirect-buffer)
6898 (let ((org-last-indirect-window
6899 (get-buffer-window org-last-indirect-buffer)))
6900 (if org-last-indirect-window
6901 (delete-window org-last-indirect-window))))
6902 (if org-agenda-columns-active
6903 (org-columns-quit)
6904 (if org-agenda-sticky
6905 (let ((buf (current-buffer)))
6906 (if (eq org-agenda-window-setup 'other-frame)
6907 (progn
6908 (delete-frame))
6909 (and (not (eq org-agenda-window-setup 'current-window))
6910 (not (one-window-p))
6911 (delete-window)))
6912 (with-current-buffer buf
6913 (bury-buffer)
6914 ;; Maybe restore the pre-agenda window configuration.
6915 (and org-agenda-restore-windows-after-quit
6916 (not (eq org-agenda-window-setup 'other-frame))
6917 org-agenda-pre-window-conf
6918 (set-window-configuration org-agenda-pre-window-conf)
6919 (setq org-agenda-pre-window-conf nil))))
6920 (org-agenda-Quit))))
6922 (defun org-agenda-exit ()
6923 "Exit agenda by removing the window or the buffer.
6924 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6925 Org-mode buffers visited directly by the user will not be touched."
6926 (interactive)
6927 (org-release-buffers org-agenda-new-buffers)
6928 (setq org-agenda-new-buffers nil)
6929 (org-agenda-Quit))
6931 (defun org-agenda-kill-all-agenda-buffers ()
6932 "Kill all buffers in `org-agenda-mode'.
6933 This is used when toggling sticky agendas. You can also explicitly invoke it
6934 with `C-c a C-k'."
6935 (interactive)
6936 (let (blist)
6937 (dolist (buf (buffer-list))
6938 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6939 (push buf blist)))
6940 (mapc 'kill-buffer blist)))
6942 (defun org-agenda-execute (arg)
6943 "Execute another agenda command, keeping same window.
6944 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6945 in the agenda."
6946 (interactive "P")
6947 (let ((org-agenda-window-setup 'current-window))
6948 (org-agenda arg)))
6950 (defun org-agenda-redo (&optional all)
6951 "Rebuild possibly ALL agenda view(s) in the current buffer."
6952 (interactive "P")
6953 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6954 (cpa (unless (eq all t) current-prefix-arg))
6955 (org-agenda-doing-sticky-redo org-agenda-sticky)
6956 (org-agenda-sticky nil)
6957 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6958 org-agenda-buffer-name))
6959 (org-agenda-keep-modes t)
6960 (tag-filter org-agenda-tag-filter)
6961 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6962 (top-cat-filter org-agenda-top-category-filter)
6963 (cat-filter org-agenda-category-filter)
6964 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6965 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6966 (cols org-agenda-columns-active)
6967 (line (org-current-line))
6968 (window-line (- line (org-current-line (window-start))))
6969 (lprops (get 'org-agenda-redo-command 'org-lprops))
6970 (redo-cmd (get-text-property p 'org-redo-cmd))
6971 (last-args (get-text-property p 'org-last-args))
6972 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6973 (org-agenda-overriding-cmd-arguments
6974 (unless (eq all t)
6975 (cond ((listp last-args)
6976 (cons (or cpa (car last-args)) (cdr last-args)))
6977 ((stringp last-args)
6978 last-args))))
6979 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6980 (put 'org-agenda-tag-filter :preset-filter nil)
6981 (put 'org-agenda-category-filter :preset-filter nil)
6982 (and cols (org-columns-quit))
6983 (message "Rebuilding agenda buffer...")
6984 (if series-redo-cmd
6985 (eval series-redo-cmd)
6986 (org-let lprops '(eval redo-cmd)))
6987 (setq org-agenda-undo-list nil
6988 org-agenda-pending-undo-list nil)
6989 (message "Rebuilding agenda buffer...done")
6990 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6991 (put 'org-agenda-category-filter :preset-filter cat-preset)
6992 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6993 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6994 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6995 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6996 (org-goto-line line)
6997 (recenter window-line)))
6999 (defvar org-global-tags-completion-table nil)
7000 (defvar org-agenda-filter-form nil)
7001 (defvar org-agenda-filtered-by-category nil)
7003 (defun org-agenda-filter-by-category (strip)
7004 "Keep only those lines in the agenda buffer that have a specific category.
7005 The category is that of the current line."
7006 (interactive "P")
7007 (if (and org-agenda-filtered-by-category
7008 org-agenda-category-filter)
7009 (org-agenda-filter-show-all-cat)
7010 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7011 (if cat (org-agenda-filter-apply
7012 (list (concat (if strip "-" "+") cat)) 'category)
7013 (error "No category at point")))))
7015 (defun org-find-top-category (&optional pos)
7016 (save-excursion
7017 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7018 (if pos (goto-char pos))
7019 ;; Skip up to the topmost parent
7020 (while (ignore-errors (outline-up-heading 1) t))
7021 (ignore-errors
7022 (nth 4 (org-heading-components))))))
7024 (defvar org-agenda-filtered-by-top-category nil)
7026 (defun org-agenda-filter-by-top-category (strip)
7027 "Keep only those lines in the agenda buffer that have a specific category.
7028 The category is that of the current line."
7029 (interactive "P")
7030 (if org-agenda-filtered-by-top-category
7031 (progn
7032 (setq org-agenda-filtered-by-top-category nil
7033 org-agenda-top-category-filter nil)
7034 (org-agenda-filter-show-all-cat))
7035 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7036 (if cat (org-agenda-filter-top-category-apply cat strip)
7037 (error "No top-level category at point")))))
7039 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7040 "Keep only those lines in the agenda buffer that have a specific tag.
7041 The tag is selected with its fast selection letter, as configured.
7042 With prefix argument STRIP, remove all lines that do have the tag.
7043 A lisp caller can specify CHAR. NARROW means that the new tag should be
7044 used to narrow the search - the interactive user can also press `-' or `+'
7045 to switch to narrowing."
7046 (interactive "P")
7047 (let* ((alist org-tag-alist-for-agenda)
7048 (tag-chars (mapconcat
7049 (lambda (x) (if (and (not (symbolp (car x)))
7050 (cdr x))
7051 (char-to-string (cdr x))
7052 ""))
7053 alist ""))
7054 (efforts (org-split-string
7055 (or (cdr (assoc (concat org-effort-property "_ALL")
7056 org-global-properties))
7057 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7058 "")))
7059 (effort-op org-agenda-filter-effort-default-operator)
7060 (effort-prompt "")
7061 (inhibit-read-only t)
7062 (current org-agenda-tag-filter)
7063 maybe-refresh a n tag)
7064 (unless char
7065 (message
7066 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7067 (if narrow "Narrow" "Filter") tag-chars
7068 (if org-agenda-auto-exclude-function "[RET], " ""))
7069 (setq char (read-char-exclusive)))
7070 (when (member char '(?+ ?-))
7071 ;; Narrowing down
7072 (cond ((equal char ?-) (setq strip t narrow t))
7073 ((equal char ?+) (setq strip nil narrow t)))
7074 (message
7075 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7076 (setq char (read-char-exclusive)))
7077 (when (member char '(?< ?> ?= ??))
7078 ;; An effort operator
7079 (setq effort-op (char-to-string char))
7080 (setq alist nil) ; to make sure it will be interpreted as effort.
7081 (unless (equal char ??)
7082 (loop for i from 0 to 9 do
7083 (setq effort-prompt
7084 (concat
7085 effort-prompt " ["
7086 (if (= i 9) "0" (int-to-string (1+ i)))
7087 "]" (nth i efforts))))
7088 (message "Effort%s: %s " effort-op effort-prompt)
7089 (setq char (read-char-exclusive))
7090 (when (or (< char ?0) (> char ?9))
7091 (error "Need 1-9,0 to select effort"))))
7092 (when (equal char ?\t)
7093 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7094 (org-set-local 'org-global-tags-completion-table
7095 (org-global-tags-completion-table)))
7096 (let ((completion-ignore-case t))
7097 (setq tag (org-icompleting-read
7098 "Tag: " org-global-tags-completion-table))))
7099 (cond
7100 ((equal char ?\r)
7101 (org-agenda-filter-show-all-tag)
7102 (when org-agenda-auto-exclude-function
7103 (setq org-agenda-tag-filter '())
7104 (dolist (tag (org-agenda-get-represented-tags))
7105 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7106 (if modifier
7107 (push modifier org-agenda-tag-filter))))
7108 (if (not (null org-agenda-tag-filter))
7109 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7110 (setq maybe-refresh t))
7111 ((equal char ?/)
7112 (org-agenda-filter-show-all-tag)
7113 (when (get 'org-agenda-tag-filter :preset-filter)
7114 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7115 (setq maybe-refresh t))
7116 ((equal char ?. )
7117 (setq org-agenda-tag-filter
7118 (mapcar (lambda(tag) (concat "+" tag))
7119 (org-get-at-bol 'tags)))
7120 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7121 (setq maybe-refresh t))
7122 ((or (equal char ?\ )
7123 (setq a (rassoc char alist))
7124 (and (>= char ?0) (<= char ?9)
7125 (setq n (if (= char ?0) 9 (- char ?0 1))
7126 tag (concat effort-op (nth n efforts))
7127 a (cons tag nil)))
7128 (and (= char ??)
7129 (setq tag "?eff")
7130 a (cons tag nil))
7131 (and tag (setq a (cons tag nil))))
7132 (org-agenda-filter-show-all-tag)
7133 (setq tag (car a))
7134 (setq org-agenda-tag-filter
7135 (cons (concat (if strip "-" "+") tag)
7136 (if narrow current nil)))
7137 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7138 (setq maybe-refresh t))
7139 (t (error "Invalid tag selection character %c" char)))
7140 (when (and maybe-refresh
7141 (eq org-agenda-clockreport-mode 'with-filter))
7142 (org-agenda-redo))))
7144 (defun org-agenda-get-represented-tags ()
7145 "Get a list of all tags currently represented in the agenda."
7146 (let (p tags)
7147 (save-excursion
7148 (goto-char (point-min))
7149 (while (setq p (next-single-property-change (point) 'tags))
7150 (goto-char p)
7151 (mapc (lambda (x) (add-to-list 'tags x))
7152 (get-text-property (point) 'tags))))
7153 tags))
7155 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7156 "Refine the current filter. See `org-agenda-filter-by-tag'."
7157 (interactive "P")
7158 (org-agenda-filter-by-tag strip char 'refine))
7160 (defun org-agenda-filter-make-matcher ()
7161 "Create the form that tests a line for agenda filter."
7162 (let (f f1)
7163 ;; first compute the tag-filter matcher
7164 (dolist (x (delete-dups
7165 (append (get 'org-agenda-tag-filter
7166 :preset-filter) org-agenda-tag-filter)))
7167 (if (member x '("-" "+"))
7168 (setq f1 (if (equal x "-") 'tags '(not tags)))
7169 (if (string-match "[<=>?]" x)
7170 (setq f1 (org-agenda-filter-effort-form x))
7171 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7172 (if (equal (string-to-char x) ?-)
7173 (setq f1 (list 'not f1))))
7174 (push f1 f))
7175 ;; then compute the category-filter matcher
7176 (dolist (x (delete-dups
7177 (append (get 'org-agenda-category-filter
7178 :preset-filter) org-agenda-category-filter)))
7179 (if (equal "-" (substring x 0 1))
7180 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7181 (setq f1 (list 'equal (substring x 1) 'cat)))
7182 (push f1 f))
7183 (cons 'and (nreverse f))))
7185 (defun org-agenda-filter-effort-form (e)
7186 "Return the form to compare the effort of the current line with what E says.
7187 E looks like \"+<2:25\"."
7188 (let (op)
7189 (setq e (substring e 1))
7190 (setq op (string-to-char e) e (substring e 1))
7191 (setq op (cond ((equal op ?<) '<=)
7192 ((equal op ?>) '>=)
7193 ((equal op ??) op)
7194 (t '=)))
7195 (list 'org-agenda-compare-effort (list 'quote op)
7196 (org-duration-string-to-minutes e))))
7198 (defun org-agenda-compare-effort (op value)
7199 "Compare the effort of the current line with VALUE, using OP.
7200 If the line does not have an effort defined, return nil."
7201 (let ((eff (org-get-at-bol 'effort-minutes)))
7202 (if (equal op ??)
7203 (not eff)
7204 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7205 value))))
7207 (defun org-agenda-filter-apply (filter type)
7208 "Set FILTER as the new agenda filter and apply it."
7209 (let (tags cat)
7210 (if (eq type 'tag)
7211 (setq org-agenda-tag-filter filter)
7212 (setq org-agenda-category-filter filter))
7213 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7214 (if (and (eq type 'category)
7215 (not (equal (substring (car filter) 0 1) "-")))
7216 ;; Only set `org-agenda-filtered-by-category' to t
7217 ;; when a unique category is used as the filter
7218 (setq org-agenda-filtered-by-category t))
7219 (org-agenda-set-mode-name)
7220 (save-excursion
7221 (goto-char (point-min))
7222 (while (not (eobp))
7223 (if (org-get-at-bol 'org-marker)
7224 (progn
7225 (setq tags (org-get-at-bol 'tags) ; used in eval
7226 cat (get-text-property (point) 'org-category))
7227 (if (not (eval org-agenda-filter-form))
7228 (org-agenda-filter-hide-line type))
7229 (beginning-of-line 2))
7230 (beginning-of-line 2))))
7231 (if (get-char-property (point) 'invisible)
7232 (ignore-errors (org-agenda-previous-line)))))
7234 (defun org-agenda-filter-top-category-apply (category &optional negative)
7235 "Set FILTER as the new agenda filter and apply it."
7236 (org-agenda-set-mode-name)
7237 (save-excursion
7238 (goto-char (point-min))
7239 (while (not (eobp))
7240 (let* ((pos (org-get-at-bol 'org-hd-marker))
7241 (topcat (and pos (org-find-top-category pos))))
7242 (if (and topcat (funcall (if negative 'identity 'not)
7243 (string= category topcat)))
7244 (org-agenda-filter-hide-line 'category)))
7245 (beginning-of-line 2)))
7246 (if (get-char-property (point) 'invisible)
7247 (org-agenda-previous-line))
7248 (setq org-agenda-top-category-filter category
7249 org-agenda-filtered-by-top-category t))
7251 (defun org-agenda-filter-hide-line (type)
7252 (let (ov)
7253 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7254 (point-at-eol)))
7255 (overlay-put ov 'invisible t)
7256 (overlay-put ov 'type type)
7257 (if (eq type 'tag)
7258 (push ov org-agenda-tag-filter-overlays)
7259 (push ov org-agenda-cat-filter-overlays))))
7261 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7262 (setq pos (or pos (point)))
7263 (save-excursion
7264 (dolist (ov (overlays-at pos))
7265 (when (and (overlay-get ov 'invisible)
7266 (eq (overlay-get ov 'type) 'tag))
7267 (goto-char pos)
7268 (if (< (overlay-start ov) (point-at-eol))
7269 (move-overlay ov (point-at-eol)
7270 (overlay-end ov)))))))
7272 (defun org-agenda-filter-show-all-tag nil
7273 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7274 (setq org-agenda-tag-filter-overlays nil
7275 org-agenda-tag-filter nil
7276 org-agenda-filter-form nil)
7277 (org-agenda-set-mode-name))
7279 (defun org-agenda-filter-show-all-cat nil
7280 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7281 (setq org-agenda-cat-filter-overlays nil
7282 org-agenda-filtered-by-category nil
7283 org-agenda-category-filter nil
7284 org-agenda-filter-form nil)
7285 (org-agenda-set-mode-name))
7287 (defun org-agenda-manipulate-query-add ()
7288 "Manipulate the query by adding a search term with positive selection.
7289 Positive selection means the term must be matched for selection of an entry."
7290 (interactive)
7291 (org-agenda-manipulate-query ?\[))
7292 (defun org-agenda-manipulate-query-subtract ()
7293 "Manipulate the query by adding a search term with negative selection.
7294 Negative selection means term must not be matched for selection of an entry."
7295 (interactive)
7296 (org-agenda-manipulate-query ?\]))
7297 (defun org-agenda-manipulate-query-add-re ()
7298 "Manipulate the query by adding a search regexp with positive selection.
7299 Positive selection means the regexp must match for selection of an entry."
7300 (interactive)
7301 (org-agenda-manipulate-query ?\{))
7302 (defun org-agenda-manipulate-query-subtract-re ()
7303 "Manipulate the query by adding a search regexp with negative selection.
7304 Negative selection means regexp must not match for selection of an entry."
7305 (interactive)
7306 (org-agenda-manipulate-query ?\}))
7307 (defun org-agenda-manipulate-query (char)
7308 (cond
7309 ((memq org-agenda-type '(timeline agenda))
7310 (let ((org-agenda-include-inactive-timestamps t))
7311 (org-agenda-redo))
7312 (message "Display now includes inactive timestamps as well"))
7313 ((eq org-agenda-type 'search)
7314 (org-add-to-string
7315 'org-agenda-query-string
7316 (if org-agenda-last-search-view-search-was-boolean
7317 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7318 (?\{ . " +{}") (?\} . " -{}"))))
7319 " "))
7320 (setq org-agenda-redo-command
7321 (list 'org-search-view
7322 (car (get-text-property (min (1- (point-max)) (point))
7323 'org-last-args))
7324 org-agenda-query-string
7325 (+ (length org-agenda-query-string)
7326 (if (member char '(?\{ ?\})) 0 1))))
7327 (set-register org-agenda-query-register org-agenda-query-string)
7328 (let ((org-agenda-overriding-arguments
7329 (cdr org-agenda-redo-command)))
7330 (org-agenda-redo)))
7331 (t (error "Cannot manipulate query for %s-type agenda buffers"
7332 org-agenda-type))))
7334 (defun org-add-to-string (var string)
7335 (set var (concat (symbol-value var) string)))
7337 (defun org-agenda-goto-date (span)
7338 "Jump to DATE in agenda."
7339 (interactive "P")
7340 (let* ((org-read-date-prefer-future
7341 (eval org-agenda-jump-prefer-future))
7342 (date (org-read-date))
7343 (org-agenda-sticky-orig org-agenda-sticky)
7344 (org-agenda-buffer-tmp-name (buffer-name))
7345 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7346 (0-arg (or current-prefix-arg (car args)))
7347 (2-arg (nth 2 args))
7348 (newcmd (list 'org-agenda-list 0-arg date
7349 (org-agenda-span-to-ndays 2-arg)))
7350 (newargs (cdr newcmd))
7351 (inhibit-read-only t)
7352 org-agenda-sticky)
7353 (if (not (org-agenda-check-type t 'agenda))
7354 (error "Not available in non-agenda blocks")
7355 (add-text-properties (point-min) (point-max)
7356 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7357 (org-agenda-redo)
7358 (setq org-agenda-sticky org-agenda-sticky-orig
7359 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7361 (defun org-agenda-goto-today ()
7362 "Go to today."
7363 (interactive)
7364 (org-agenda-check-type t 'timeline 'agenda)
7365 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7366 (curspan (nth 2 args))
7367 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7368 (cond
7369 (tdpos (goto-char tdpos))
7370 ((eq org-agenda-type 'agenda)
7371 (let* ((sd (org-agenda-compute-starting-span
7372 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7373 (org-agenda-overriding-arguments args))
7374 (setf (nth 1 org-agenda-overriding-arguments) sd)
7375 (org-agenda-redo)
7376 (org-agenda-find-same-or-today-or-agenda)))
7377 (t (error "Cannot find today")))))
7379 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7380 (goto-char
7381 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7382 (text-property-any (point-min) (point-max) 'org-today t)
7383 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7384 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7385 (org-agenda-goto-block-beginning))
7386 (point-min))))
7388 (defun org-agenda-goto-block-beginning ()
7389 "Go the agenda block beginning."
7390 (interactive)
7391 (if (not (derived-mode-p 'org-agenda-mode))
7392 (error "Cannot execute this command outside of org-agenda-mode buffers")
7393 (let (dest)
7394 (save-excursion
7395 (unless (looking-at "\\'")
7396 (forward-char))
7397 (let* ((prop 'org-agenda-structural-header)
7398 (p (previous-single-property-change (point) prop))
7399 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7400 (1- (point))) prop)))
7401 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7402 (if (not dest)
7403 (error "Cannot find the beginning of the blog")
7404 (goto-char dest)
7405 (move-beginning-of-line 1)))))
7407 (defun org-agenda-later (arg)
7408 "Go forward in time by the current span.
7409 With prefix ARG, go forward that many times the current span."
7410 (interactive "p")
7411 (org-agenda-check-type t 'agenda)
7412 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7413 (span (or (nth 2 args) org-agenda-current-span))
7414 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7415 (greg (calendar-gregorian-from-absolute sd))
7416 (cnt (org-get-at-bol 'org-day-cnt))
7417 greg2)
7418 (cond
7419 ((numberp span)
7420 (setq sd (+ (* span arg) sd)))
7421 ((eq span 'day)
7422 (setq sd (+ arg sd)))
7423 ((eq span 'week)
7424 (setq sd (+ (* 7 arg) sd)))
7425 ((eq span 'month)
7426 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7427 sd (calendar-absolute-from-gregorian greg2))
7428 (setcar greg2 (1+ (car greg2))))
7429 ((eq span 'year)
7430 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7431 sd (calendar-absolute-from-gregorian greg2))
7432 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7434 (setq sd (+ (* span arg) sd))))
7435 (let ((org-agenda-overriding-cmd
7436 ;; `cmd' may have been set by `org-agenda-run-series' which
7437 ;; uses `org-agenda-overriding-cmd' to decide whether
7438 ;; overriding is allowed for `cmd'
7439 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7440 (org-agenda-overriding-arguments
7441 (list (car args) sd span)))
7442 (org-agenda-redo)
7443 (org-agenda-find-same-or-today-or-agenda cnt))))
7445 (defun org-agenda-earlier (arg)
7446 "Go backward in time by the current span.
7447 With prefix ARG, go backward that many times the current span."
7448 (interactive "p")
7449 (org-agenda-later (- arg)))
7451 (defun org-agenda-view-mode-dispatch ()
7452 "Call one of the view mode commands."
7453 (interactive)
7454 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7455 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7456 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7457 (let ((a (read-char-exclusive)))
7458 (case a
7459 (?\ (call-interactively 'org-agenda-reset-view))
7460 (?d (call-interactively 'org-agenda-day-view))
7461 (?w (call-interactively 'org-agenda-week-view))
7462 (?m (call-interactively 'org-agenda-month-view))
7463 (?y (call-interactively 'org-agenda-year-view))
7464 (?l (call-interactively 'org-agenda-log-mode))
7465 (?L (org-agenda-log-mode '(4)))
7466 (?c (org-agenda-log-mode 'clockcheck))
7467 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7468 (?a (call-interactively 'org-agenda-archives-mode))
7469 (?A (org-agenda-archives-mode 'files))
7470 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7471 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7472 (?G (call-interactively 'org-agenda-toggle-time-grid))
7473 (?D (call-interactively 'org-agenda-toggle-diary))
7474 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7475 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7476 (org-agenda-check-type t 'timeline 'agenda)
7477 (org-agenda-redo))
7478 (message "Display now includes inactive timestamps as well"))
7479 (?q (message "Abort"))
7480 (otherwise (error "Invalid key" )))))
7482 (defun org-agenda-reset-view ()
7483 "Switch to default view for agenda."
7484 (interactive)
7485 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7486 (defun org-agenda-day-view (&optional day-of-year)
7487 "Switch to daily view for agenda.
7488 With argument DAY-OF-YEAR, switch to that day of the year."
7489 (interactive "P")
7490 (org-agenda-change-time-span 'day day-of-year))
7491 (defun org-agenda-week-view (&optional iso-week)
7492 "Switch to daily view for agenda.
7493 With argument ISO-WEEK, switch to the corresponding ISO week.
7494 If ISO-WEEK has more then 2 digits, only the last two encode the
7495 week. Any digits before this encode a year. So 200712 means
7496 week 12 of year 2007. Years in the range 1938-2037 can also be
7497 written as 2-digit years."
7498 (interactive "P")
7499 (org-agenda-change-time-span 'week iso-week))
7500 (defun org-agenda-month-view (&optional month)
7501 "Switch to monthly view for agenda.
7502 With argument MONTH, switch to that month."
7503 (interactive "P")
7504 (org-agenda-change-time-span 'month month))
7505 (defun org-agenda-year-view (&optional year)
7506 "Switch to yearly view for agenda.
7507 With argument YEAR, switch to that year.
7508 If MONTH has more then 2 digits, only the last two encode the
7509 month. Any digits before this encode a year. So 200712 means
7510 December year 2007. Years in the range 1938-2037 can also be
7511 written as 2-digit years."
7512 (interactive "P")
7513 (when year
7514 (setq year (org-small-year-to-year year)))
7515 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7516 (org-agenda-change-time-span 'year year)
7517 (error "Abort")))
7519 (defun org-agenda-change-time-span (span &optional n)
7520 "Change the agenda view to SPAN.
7521 SPAN may be `day', `week', `month', `year'."
7522 (org-agenda-check-type t 'agenda)
7523 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7524 (curspan (nth 2 args)))
7525 (if (and (not n) (equal curspan span))
7526 (error "Viewing span is already \"%s\"" span))
7527 (let* ((sd (or (org-get-at-bol 'day)
7528 (nth 1 args)
7529 org-starting-day))
7530 (sd (org-agenda-compute-starting-span sd span n))
7531 (org-agenda-overriding-cmd
7532 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7533 (org-agenda-overriding-arguments
7534 (list (car args) sd span)))
7535 (org-agenda-redo)
7536 (org-agenda-find-same-or-today-or-agenda))
7537 (org-agenda-set-mode-name)
7538 (message "Switched to %s view" span)))
7540 (defun org-agenda-compute-starting-span (sd span &optional n)
7541 "Compute starting date for agenda.
7542 SPAN may be `day', `week', `month', `year'. The return value
7543 is a cons cell with the starting date and the number of days,
7544 so that the date SD will be in that range."
7545 (let* ((greg (calendar-gregorian-from-absolute sd))
7546 (dg (nth 1 greg))
7547 (mg (car greg))
7548 (yg (nth 2 greg)))
7549 (cond
7550 ((eq span 'day)
7551 (when n
7552 (setq sd (+ (calendar-absolute-from-gregorian
7553 (list mg 1 yg))
7554 n -1))))
7555 ((eq span 'week)
7556 (let* ((nt (calendar-day-of-week
7557 (calendar-gregorian-from-absolute sd)))
7558 (d (if org-agenda-start-on-weekday
7559 (- nt org-agenda-start-on-weekday)
7562 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7563 (when n
7564 (require 'cal-iso)
7565 (when (> n 99)
7566 (setq y1 (org-small-year-to-year (/ n 100))
7567 n (mod n 100)))
7568 (setq sd
7569 (calendar-absolute-from-iso
7570 (list n 1
7571 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7572 ((eq span 'month)
7573 (let (y1)
7574 (when (and n (> n 99))
7575 (setq y1 (org-small-year-to-year (/ n 100))
7576 n (mod n 100)))
7577 (setq sd (calendar-absolute-from-gregorian
7578 (list (or n mg) 1 (or y1 yg))))))
7579 ((eq span 'year)
7580 (setq sd (calendar-absolute-from-gregorian
7581 (list 1 1 (or n yg))))))
7582 sd))
7584 (defun org-agenda-next-date-line (&optional arg)
7585 "Jump to the next line indicating a date in agenda buffer."
7586 (interactive "p")
7587 (org-agenda-check-type t 'agenda 'timeline)
7588 (beginning-of-line 1)
7589 ;; This does not work if user makes date format that starts with a blank
7590 (if (looking-at "^\\S-") (forward-char 1))
7591 (if (not (re-search-forward "^\\S-" nil t arg))
7592 (progn
7593 (backward-char 1)
7594 (error "No next date after this line in this buffer")))
7595 (goto-char (match-beginning 0)))
7597 (defun org-agenda-previous-date-line (&optional arg)
7598 "Jump to the previous line indicating a date in agenda buffer."
7599 (interactive "p")
7600 (org-agenda-check-type t 'agenda 'timeline)
7601 (beginning-of-line 1)
7602 (if (not (re-search-backward "^\\S-" nil t arg))
7603 (error "No previous date before this line in this buffer")))
7605 ;; Initialize the highlight
7606 (defvar org-hl (make-overlay 1 1))
7607 (overlay-put org-hl 'face 'highlight)
7609 (defun org-highlight (begin end &optional buffer)
7610 "Highlight a region with overlay."
7611 (move-overlay org-hl begin end (or buffer (current-buffer))))
7613 (defun org-unhighlight ()
7614 "Detach overlay INDEX."
7615 (org-detach-overlay org-hl))
7617 (defun org-unhighlight-once ()
7618 "Remove the highlight from its position, and this function from the hook."
7619 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7620 (org-unhighlight))
7622 (defvar org-agenda-pre-follow-window-conf nil)
7623 (defun org-agenda-follow-mode ()
7624 "Toggle follow mode in an agenda buffer."
7625 (interactive)
7626 (unless org-agenda-follow-mode
7627 (setq org-agenda-pre-follow-window-conf
7628 (current-window-configuration)))
7629 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7630 (unless org-agenda-follow-mode
7631 (set-window-configuration org-agenda-pre-follow-window-conf))
7632 (org-agenda-set-mode-name)
7633 (org-agenda-do-context-action)
7634 (message "Follow mode is %s"
7635 (if org-agenda-follow-mode "on" "off")))
7637 (defun org-agenda-entry-text-mode (&optional arg)
7638 "Toggle entry text mode in an agenda buffer."
7639 (interactive "P")
7640 (setq org-agenda-entry-text-mode (or (integerp arg)
7641 (not org-agenda-entry-text-mode)))
7642 (org-agenda-entry-text-hide)
7643 (and org-agenda-entry-text-mode
7644 (let ((org-agenda-entry-text-maxlines
7645 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7646 (org-agenda-entry-text-show)))
7647 (org-agenda-set-mode-name)
7648 (message "Entry text mode is %s. Maximum number of lines is %d"
7649 (if org-agenda-entry-text-mode "on" "off")
7650 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7652 (defun org-agenda-clockreport-mode (&optional with-filter)
7653 "Toggle clocktable mode in an agenda buffer.
7654 With prefix arg WITH-FILTER, make the clocktable respect the current
7655 agenda filter."
7656 (interactive "P")
7657 (org-agenda-check-type t 'agenda)
7658 (if with-filter
7659 (setq org-agenda-clockreport-mode 'with-filter)
7660 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7661 (org-agenda-set-mode-name)
7662 (org-agenda-redo)
7663 (message "Clocktable mode is %s"
7664 (if org-agenda-clockreport-mode "on" "off")))
7666 (defun org-agenda-log-mode (&optional special)
7667 "Toggle log mode in an agenda buffer.
7668 With argument SPECIAL, show all possible log items, not only the ones
7669 configured in `org-agenda-log-mode-items'.
7670 With a double `C-u' prefix arg, show *only* log items, nothing else."
7671 (interactive "P")
7672 (org-agenda-check-type t 'agenda 'timeline)
7673 (setq org-agenda-show-log
7674 (cond
7675 ((equal special '(16)) 'only)
7676 ((eq special 'clockcheck)
7677 (if (eq org-agenda-show-log 'clockcheck)
7678 nil 'clockcheck))
7679 (special '(closed clock state))
7680 (t (not org-agenda-show-log))))
7681 (org-agenda-set-mode-name)
7682 (org-agenda-redo)
7683 (message "Log mode is %s"
7684 (if org-agenda-show-log "on" "off")))
7686 (defun org-agenda-archives-mode (&optional with-files)
7687 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7688 When called with a prefix argument, include all archive files as well."
7689 (interactive "P")
7690 (setq org-agenda-archives-mode
7691 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7692 (org-agenda-set-mode-name)
7693 (org-agenda-redo)
7694 (message
7695 "%s"
7696 (cond
7697 ((eq org-agenda-archives-mode nil)
7698 "No archives are included")
7699 ((eq org-agenda-archives-mode 'trees)
7700 (format "Trees with :%s: tag are included" org-archive-tag))
7701 ((eq org-agenda-archives-mode t)
7702 (format "Trees with :%s: tag and all active archive files are included"
7703 org-archive-tag)))))
7705 (defun org-agenda-toggle-diary ()
7706 "Toggle diary inclusion in an agenda buffer."
7707 (interactive)
7708 (org-agenda-check-type t 'agenda)
7709 (setq org-agenda-include-diary (not org-agenda-include-diary))
7710 (org-agenda-redo)
7711 (org-agenda-set-mode-name)
7712 (message "Diary inclusion turned %s"
7713 (if org-agenda-include-diary "on" "off")))
7715 (defun org-agenda-toggle-deadlines ()
7716 "Toggle inclusion of entries with a deadline in an agenda buffer."
7717 (interactive)
7718 (org-agenda-check-type t 'agenda)
7719 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7720 (org-agenda-redo)
7721 (org-agenda-set-mode-name)
7722 (message "Deadlines inclusion turned %s"
7723 (if org-agenda-include-deadlines "on" "off")))
7725 (defun org-agenda-toggle-time-grid ()
7726 "Toggle time grid in an agenda buffer."
7727 (interactive)
7728 (org-agenda-check-type t 'agenda)
7729 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7730 (org-agenda-redo)
7731 (org-agenda-set-mode-name)
7732 (message "Time-grid turned %s"
7733 (if org-agenda-use-time-grid "on" "off")))
7735 (defun org-agenda-set-mode-name ()
7736 "Set the mode name to indicate all the small mode settings."
7737 (setq mode-name
7738 (list "Org-Agenda"
7739 (if (get 'org-agenda-files 'org-restrict) " []" "")
7741 '(:eval (org-agenda-span-name org-agenda-current-span))
7742 (if org-agenda-follow-mode " Follow" "")
7743 (if org-agenda-entry-text-mode " ETxt" "")
7744 (if org-agenda-include-diary " Diary" "")
7745 (if org-agenda-include-deadlines " Ddl" "")
7746 (if org-agenda-use-time-grid " Grid" "")
7747 (if (and (boundp 'org-habit-show-habits)
7748 org-habit-show-habits) " Habit" "")
7749 (cond
7750 ((consp org-agenda-show-log) " LogAll")
7751 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7752 (org-agenda-show-log " Log")
7753 (t ""))
7754 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7755 :preset-filter))
7756 '(:eval (org-propertize
7757 (concat " <"
7758 (mapconcat
7759 'identity
7760 (append
7761 (get 'org-agenda-category-filter :preset-filter)
7762 org-agenda-category-filter)
7764 ">")
7765 'face 'org-agenda-filter-category
7766 'help-echo "Category used in filtering"))
7768 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7769 :preset-filter))
7770 '(:eval (org-propertize
7771 (concat " {"
7772 (mapconcat
7773 'identity
7774 (append
7775 (get 'org-agenda-tag-filter :preset-filter)
7776 org-agenda-tag-filter)
7778 "}")
7779 'face 'org-agenda-filter-tags
7780 'help-echo "Tags used in filtering"))
7782 (if org-agenda-archives-mode
7783 (if (eq org-agenda-archives-mode t)
7784 " Archives"
7785 (format " :%s:" org-archive-tag))
7787 (if org-agenda-clockreport-mode
7788 (if (eq org-agenda-clockreport-mode 'with-filter)
7789 " Clock{}" " Clock")
7790 "")))
7791 (force-mode-line-update))
7793 (define-obsolete-function-alias
7794 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7796 (defun org-agenda-update-agenda-type ()
7797 "Update the agenda type after each command."
7798 (setq org-agenda-type
7799 (or (get-text-property (point) 'org-agenda-type)
7800 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7802 (defun org-agenda-next-line ()
7803 "Move cursor to the next line, and show if follow mode is active."
7804 (interactive)
7805 (call-interactively 'next-line)
7806 (org-agenda-do-context-action))
7808 (defun org-agenda-previous-line ()
7809 "Move cursor to the previous line, and show if follow-mode is active."
7810 (interactive)
7811 (call-interactively 'previous-line)
7812 (org-agenda-do-context-action))
7814 (defun org-agenda-next-item (n)
7815 "Move cursor to next agenda item."
7816 (interactive "p")
7817 (let ((col (current-column)))
7818 (dotimes (c n)
7819 (when (next-single-property-change (point-at-eol) 'org-marker)
7820 (move-end-of-line 1)
7821 (goto-char (next-single-property-change (point) 'org-marker))))
7822 (org-move-to-column col))
7823 (org-agenda-do-context-action))
7825 (defun org-agenda-previous-item (n)
7826 "Move cursor to next agenda item."
7827 (interactive "p")
7828 (dotimes (c n)
7829 (let ((col (current-column))
7830 (goto (save-excursion
7831 (move-end-of-line 0)
7832 (previous-single-property-change (point) 'org-marker))))
7833 (if goto (goto-char goto))
7834 (org-move-to-column col)))
7835 (org-agenda-do-context-action))
7837 (defun org-agenda-do-context-action ()
7838 "Show outline path and, maybe, follow mode window."
7839 (let ((m (org-get-at-bol 'org-marker)))
7840 (when (and (markerp m) (marker-buffer m))
7841 (and org-agenda-follow-mode
7842 (if org-agenda-follow-indirect
7843 (org-agenda-tree-to-indirect-buffer nil)
7844 (org-agenda-show)))
7845 (and org-agenda-show-outline-path
7846 (org-with-point-at m (org-display-outline-path t))))))
7848 (defun org-agenda-show-tags ()
7849 "Show the tags applicable to the current item."
7850 (interactive)
7851 (let* ((tags (org-get-at-bol 'tags)))
7852 (if tags
7853 (message "Tags are :%s:"
7854 (org-no-properties (mapconcat 'identity tags ":")))
7855 (message "No tags associated with this line"))))
7857 (defun org-agenda-goto (&optional highlight)
7858 "Go to the Org-mode file which contains the item at point."
7859 (interactive)
7860 (let* ((marker (or (org-get-at-bol 'org-marker)
7861 (org-agenda-error)))
7862 (buffer (marker-buffer marker))
7863 (pos (marker-position marker)))
7864 (switch-to-buffer-other-window buffer)
7865 (widen)
7866 (push-mark)
7867 (goto-char pos)
7868 (when (derived-mode-p 'org-mode)
7869 (org-show-context 'agenda)
7870 (save-excursion
7871 (and (outline-next-heading)
7872 (org-flag-heading nil)))) ; show the next heading
7873 (when (outline-invisible-p)
7874 (show-entry)) ; display invisible text
7875 (recenter (/ (window-height) 2))
7876 (run-hooks 'org-agenda-after-show-hook)
7877 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7879 (defvar org-agenda-after-show-hook nil
7880 "Normal hook run after an item has been shown from the agenda.
7881 Point is in the buffer where the item originated.")
7883 (defun org-agenda-kill ()
7884 "Kill the entry or subtree belonging to the current agenda entry."
7885 (interactive)
7886 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7887 (let* ((bufname-orig (buffer-name))
7888 (marker (or (org-get-at-bol 'org-marker)
7889 (org-agenda-error)))
7890 (buffer (marker-buffer marker))
7891 (pos (marker-position marker))
7892 (type (org-get-at-bol 'type))
7893 dbeg dend (n 0) conf)
7894 (org-with-remote-undo buffer
7895 (with-current-buffer buffer
7896 (save-excursion
7897 (goto-char pos)
7898 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7899 (setq dbeg (progn (org-back-to-heading t) (point))
7900 dend (org-end-of-subtree t t))
7901 (setq dbeg (point-at-bol)
7902 dend (min (point-max) (1+ (point-at-eol)))))
7903 (goto-char dbeg)
7904 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7905 (setq conf (or (eq t org-agenda-confirm-kill)
7906 (and (numberp org-agenda-confirm-kill)
7907 (> n org-agenda-confirm-kill))))
7908 (and conf
7909 (not (y-or-n-p
7910 (format "Delete entry with %d lines in buffer \"%s\"? "
7911 n (buffer-name buffer))))
7912 (error "Abort"))
7913 (let ((org-agenda-buffer-name bufname-orig))
7914 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7915 (with-current-buffer buffer (delete-region dbeg dend))
7916 (message "Agenda item and source killed"))))
7918 (defvar org-archive-default-command) ; defined in org-archive.el
7919 (defun org-agenda-archive-default ()
7920 "Archive the entry or subtree belonging to the current agenda entry."
7921 (interactive)
7922 (require 'org-archive)
7923 (org-agenda-archive-with org-archive-default-command))
7925 (defun org-agenda-archive-default-with-confirmation ()
7926 "Archive the entry or subtree belonging to the current agenda entry."
7927 (interactive)
7928 (require 'org-archive)
7929 (org-agenda-archive-with org-archive-default-command 'confirm))
7931 (defun org-agenda-archive ()
7932 "Archive the entry or subtree belonging to the current agenda entry."
7933 (interactive)
7934 (org-agenda-archive-with 'org-archive-subtree))
7936 (defun org-agenda-archive-to-archive-sibling ()
7937 "Move the entry to the archive sibling."
7938 (interactive)
7939 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7941 (defun org-agenda-archive-with (cmd &optional confirm)
7942 "Move the entry to the archive sibling."
7943 (interactive)
7944 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7945 (let* ((bufname-orig (buffer-name))
7946 (marker (or (org-get-at-bol 'org-marker)
7947 (org-agenda-error)))
7948 (buffer (marker-buffer marker))
7949 (pos (marker-position marker)))
7950 (org-with-remote-undo buffer
7951 (with-current-buffer buffer
7952 (if (derived-mode-p 'org-mode)
7953 (if (and confirm
7954 (not (y-or-n-p "Archive this subtree or entry? ")))
7955 (error "Abort")
7956 (save-excursion
7957 (goto-char pos)
7958 (let ((org-agenda-buffer-name bufname-orig))
7959 (org-remove-subtree-entries-from-agenda))
7960 (org-back-to-heading t)
7961 (funcall cmd)))
7962 (error "Archiving works only in Org-mode files"))))))
7964 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7965 "Remove all lines in the agenda that correspond to a given subtree.
7966 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7967 If this information is not given, the function uses the tree at point."
7968 (let ((buf (or buf (current-buffer))) m p)
7969 (save-excursion
7970 (unless (and beg end)
7971 (org-back-to-heading t)
7972 (setq beg (point))
7973 (org-end-of-subtree t)
7974 (setq end (point)))
7975 (set-buffer (get-buffer org-agenda-buffer-name))
7976 (save-excursion
7977 (goto-char (point-max))
7978 (beginning-of-line 1)
7979 (while (not (bobp))
7980 (when (and (setq m (org-get-at-bol 'org-marker))
7981 (equal buf (marker-buffer m))
7982 (setq p (marker-position m))
7983 (>= p beg)
7984 (< p end))
7985 (let ((inhibit-read-only t))
7986 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7987 (beginning-of-line 0))))))
7989 (defun org-agenda-refile (&optional goto rfloc no-update)
7990 "Refile the item at point."
7991 (interactive "P")
7992 (if (equal goto '(16))
7993 (org-refile-goto-last-stored)
7994 (let* ((buffer-orig (buffer-name))
7995 (marker (or (org-get-at-bol 'org-hd-marker)
7996 (org-agenda-error)))
7997 (buffer (marker-buffer marker))
7998 (pos (marker-position marker))
7999 (rfloc (or rfloc
8000 (org-refile-get-location
8001 (if goto "Goto" "Refile to") buffer
8002 org-refile-allow-creating-parent-nodes))))
8003 (with-current-buffer buffer
8004 (save-excursion
8005 (save-restriction
8006 (widen)
8007 (goto-char marker)
8008 (let ((org-agenda-buffer-name buffer-orig))
8009 (org-remove-subtree-entries-from-agenda))
8010 (org-refile goto buffer rfloc)))))
8011 (unless no-update (org-agenda-redo))))
8013 (defun org-agenda-open-link (&optional arg)
8014 "Open the link(s) in the current entry, if any.
8015 This looks for a link in the displayed line in the agenda.
8016 It also looks at the text of the entry itself."
8017 (interactive "P")
8018 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8019 (org-get-at-bol 'org-marker)))
8020 (buffer (and marker (marker-buffer marker)))
8021 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8022 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8023 (lk0 (car lkall))
8024 (lk (if (stringp lk0) (list lk0) lk0))
8025 (lkend (cdr lkall))
8026 trg)
8027 (cond
8028 ((and buffer lk)
8029 (mapcar (lambda(l)
8030 (with-current-buffer buffer
8031 (setq trg (and (string-match org-bracket-link-regexp l)
8032 (match-string 1 l)))
8033 (if (or (not trg) (string-match org-any-link-re trg))
8034 (save-excursion
8035 (save-restriction
8036 (widen)
8037 (goto-char marker)
8038 (when (search-forward l nil lkend)
8039 (goto-char (match-beginning 0))
8040 (org-open-at-point))))
8041 ;; This is an internal link, widen the buffer
8042 (switch-to-buffer-other-window buffer)
8043 (widen)
8044 (goto-char marker)
8045 (when (search-forward l nil lkend)
8046 (goto-char (match-beginning 0))
8047 (org-open-at-point)))))
8048 lk))
8049 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8050 (save-excursion
8051 (beginning-of-line 1)
8052 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8053 (org-open-link-from-string (match-string 1)))
8054 (t (message "No link to open here")))))
8056 (defun org-agenda-copy-local-variable (var)
8057 "Get a variable from a referenced buffer and install it here."
8058 (let ((m (org-get-at-bol 'org-marker)))
8059 (when (and m (buffer-live-p (marker-buffer m)))
8060 (org-set-local var (with-current-buffer (marker-buffer m)
8061 (symbol-value var))))))
8063 (defun org-agenda-switch-to (&optional delete-other-windows)
8064 "Go to the Org-mode file which contains the item at point."
8065 (interactive)
8066 (if (and org-return-follows-link
8067 (not (org-get-at-bol 'org-marker))
8068 (org-in-regexp org-bracket-link-regexp))
8069 (org-open-link-from-string (match-string 0))
8070 (let* ((marker (or (org-get-at-bol 'org-marker)
8071 (org-agenda-error)))
8072 (buffer (marker-buffer marker))
8073 (pos (marker-position marker)))
8074 (org-pop-to-buffer-same-window buffer)
8075 (and delete-other-windows (delete-other-windows))
8076 (widen)
8077 (goto-char pos)
8078 (when (derived-mode-p 'org-mode)
8079 (org-show-context 'agenda)
8080 (save-excursion
8081 (and (outline-next-heading)
8082 (org-flag-heading nil))) ; show the next heading
8083 (when (outline-invisible-p)
8084 (show-entry)) ; display invisible text
8085 (run-hooks 'org-agenda-after-show-hook)))))
8087 (defun org-agenda-goto-mouse (ev)
8088 "Go to the Org-mode file which contains the item at the mouse click."
8089 (interactive "e")
8090 (mouse-set-point ev)
8091 (org-agenda-goto))
8093 (defun org-agenda-show (&optional full-entry)
8094 "Display the Org-mode file which contains the item at point.
8095 With prefix argument FULL-ENTRY, make the entire entry visible
8096 if it was hidden in the outline."
8097 (interactive "P")
8098 (let ((win (selected-window)))
8099 (if full-entry
8100 (let ((org-show-entry-below t))
8101 (org-agenda-goto t))
8102 (org-agenda-goto t))
8103 (select-window win)))
8105 (defvar org-agenda-show-window nil)
8106 (defun org-agenda-show-and-scroll-up (&optional arg)
8107 "Display the Org-mode file which contains the item at point.
8108 When called repeatedly, scroll the window that is displaying the buffer.
8109 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8110 `show-subtree' to display the item, so that drawers and logbooks stay
8111 folded."
8112 (interactive "P")
8113 (let ((win (selected-window)))
8114 (if (and (window-live-p org-agenda-show-window)
8115 (eq this-command last-command))
8116 (progn
8117 (select-window org-agenda-show-window)
8118 (ignore-errors (scroll-up)))
8119 (org-agenda-goto t)
8120 (if arg (org-show-entry) (show-subtree))
8121 (setq org-agenda-show-window (selected-window)))
8122 (select-window win)))
8124 (defun org-agenda-show-scroll-down ()
8125 "Scroll down the window showing the agenda."
8126 (interactive)
8127 (let ((win (selected-window)))
8128 (when (window-live-p org-agenda-show-window)
8129 (select-window org-agenda-show-window)
8130 (ignore-errors (scroll-down))
8131 (select-window win))))
8133 (defun org-agenda-show-1 (&optional more)
8134 "Display the Org-mode file which contains the item at point.
8135 The prefix arg selects the amount of information to display:
8137 0 hide the subtree
8138 1 just show the entry according to defaults.
8139 2 show the children view
8140 3 show the subtree view
8141 4 show the entire subtree and any LOGBOOK drawers
8142 5 show the entire subtree and any drawers
8143 With prefix argument FULL-ENTRY, make the entire entry visible
8144 if it was hidden in the outline."
8145 (interactive "p")
8146 (let ((win (selected-window)))
8147 (org-agenda-goto t)
8148 (org-recenter-heading 1)
8149 (cond
8150 ((= more 0)
8151 (hide-subtree)
8152 (save-excursion
8153 (org-back-to-heading)
8154 (run-hook-with-args 'org-cycle-hook 'folded))
8155 (message "Remote: FOLDED"))
8156 ((and (org-called-interactively-p 'any) (= more 1))
8157 (message "Remote: show with default settings"))
8158 ((= more 2)
8159 (show-entry)
8160 (show-children)
8161 (save-excursion
8162 (org-back-to-heading)
8163 (run-hook-with-args 'org-cycle-hook 'children))
8164 (message "Remote: CHILDREN"))
8165 ((= more 3)
8166 (show-subtree)
8167 (save-excursion
8168 (org-back-to-heading)
8169 (run-hook-with-args 'org-cycle-hook 'subtree))
8170 (message "Remote: SUBTREE"))
8171 ((= more 4)
8172 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8173 (org-drawer-regexp
8174 (concat "^[ \t]*:\\("
8175 (mapconcat 'regexp-quote org-drawers "\\|")
8176 "\\):[ \t]*$")))
8177 (show-subtree)
8178 (save-excursion
8179 (org-back-to-heading)
8180 (org-cycle-hide-drawers 'subtree)))
8181 (message "Remote: SUBTREE AND LOGBOOK"))
8182 ((> more 4)
8183 (show-subtree)
8184 (message "Remote: SUBTREE AND ALL DRAWERS")))
8185 (select-window win)))
8187 (defun org-recenter-heading (n)
8188 (save-excursion
8189 (org-back-to-heading)
8190 (recenter n)))
8192 (defvar org-agenda-cycle-counter nil)
8193 (defun org-agenda-cycle-show (&optional n)
8194 "Show the current entry in another window, with default settings.
8195 Default settings are taken from `org-show-hierarchy-above' and siblings.
8196 When use repeatedly in immediate succession, the remote entry will cycle
8197 through visibility
8199 children -> subtree -> folded
8201 When called with a numeric prefix arg, that arg will be passed through to
8202 `org-agenda-show-1'. For the interpretation of that argument, see the
8203 docstring of `org-agenda-show-1'."
8204 (interactive "P")
8205 (if (integerp n)
8206 (setq org-agenda-cycle-counter n)
8207 (if (not (eq last-command this-command))
8208 (setq org-agenda-cycle-counter 1)
8209 (if (equal org-agenda-cycle-counter 0)
8210 (setq org-agenda-cycle-counter 2)
8211 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8212 (if (> org-agenda-cycle-counter 3)
8213 (setq org-agenda-cycle-counter 0)))))
8214 (org-agenda-show-1 org-agenda-cycle-counter))
8216 (defun org-agenda-recenter (arg)
8217 "Display the Org-mode file which contains the item at point and recenter."
8218 (interactive "P")
8219 (let ((win (selected-window)))
8220 (org-agenda-goto t)
8221 (recenter arg)
8222 (select-window win)))
8224 (defun org-agenda-show-mouse (ev)
8225 "Display the Org-mode file which contains the item at the mouse click."
8226 (interactive "e")
8227 (mouse-set-point ev)
8228 (org-agenda-show))
8230 (defun org-agenda-check-no-diary ()
8231 "Check if the entry is a diary link and abort if yes."
8232 (if (org-get-at-bol 'org-agenda-diary-link)
8233 (org-agenda-error)))
8235 (defun org-agenda-error ()
8236 (error "Command not allowed in this line"))
8238 (defun org-agenda-tree-to-indirect-buffer (arg)
8239 "Show the subtree corresponding to the current entry in an indirect buffer.
8240 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8242 With a numerical prefix ARG, go up to this level and then take that tree.
8243 With a negative numeric ARG, go up by this number of levels.
8244 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8245 use the dedicated frame)."
8246 (interactive "P")
8247 (if current-prefix-arg
8248 (org-agenda-do-tree-to-indirect-buffer arg)
8249 (let ((agenda-buffer (buffer-name))
8250 (agenda-window (selected-window))
8251 (indirect-window
8252 (and org-last-indirect-buffer
8253 (get-buffer-window org-last-indirect-buffer))))
8254 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8255 (unless (or (eq org-indirect-buffer-display 'new-frame)
8256 (eq org-indirect-buffer-display 'dedicated-frame))
8257 (unwind-protect
8258 (unless (and indirect-window (window-live-p indirect-window))
8259 (setq indirect-window (split-window agenda-window)))
8260 (and indirect-window (select-window indirect-window))
8261 (switch-to-buffer org-last-indirect-buffer :norecord)
8262 (fit-window-to-buffer indirect-window)))
8263 (select-window (get-buffer-window agenda-buffer)))))
8265 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8266 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8267 (org-agenda-check-no-diary)
8268 (let* ((marker (or (org-get-at-bol 'org-marker)
8269 (org-agenda-error)))
8270 (buffer (marker-buffer marker))
8271 (pos (marker-position marker)))
8272 (with-current-buffer buffer
8273 (save-excursion
8274 (goto-char pos)
8275 (funcall 'org-tree-to-indirect-buffer arg)))))
8277 (defvar org-last-heading-marker (make-marker)
8278 "Marker pointing to the headline that last changed its TODO state
8279 by a remote command from the agenda.")
8281 (defun org-agenda-todo-nextset ()
8282 "Switch TODO entry to next sequence."
8283 (interactive)
8284 (org-agenda-todo 'nextset))
8286 (defun org-agenda-todo-previousset ()
8287 "Switch TODO entry to previous sequence."
8288 (interactive)
8289 (org-agenda-todo 'previousset))
8291 (defun org-agenda-todo (&optional arg)
8292 "Cycle TODO state of line at point, also in Org-mode file.
8293 This changes the line at point, all other lines in the agenda referring to
8294 the same tree node, and the headline of the tree node in the Org-mode file."
8295 (interactive "P")
8296 (org-agenda-check-no-diary)
8297 (let* ((col (current-column))
8298 (marker (or (org-get-at-bol 'org-marker)
8299 (org-agenda-error)))
8300 (buffer (marker-buffer marker))
8301 (pos (marker-position marker))
8302 (hdmarker (org-get-at-bol 'org-hd-marker))
8303 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8304 (inhibit-read-only t)
8305 org-agenda-headline-snapshot-before-repeat newhead just-one)
8306 (org-with-remote-undo buffer
8307 (with-current-buffer buffer
8308 (widen)
8309 (goto-char pos)
8310 (org-show-context 'agenda)
8311 (save-excursion
8312 (and (outline-next-heading)
8313 (org-flag-heading nil))) ; show the next heading
8314 (let ((current-prefix-arg arg))
8315 (call-interactively 'org-todo))
8316 (and (bolp) (forward-char 1))
8317 (setq newhead (org-get-heading))
8318 (when (and (org-bound-and-true-p
8319 org-agenda-headline-snapshot-before-repeat)
8320 (not (equal org-agenda-headline-snapshot-before-repeat
8321 newhead))
8322 todayp)
8323 (setq newhead org-agenda-headline-snapshot-before-repeat
8324 just-one t))
8325 (save-excursion
8326 (org-back-to-heading)
8327 (move-marker org-last-heading-marker (point))))
8328 (beginning-of-line 1)
8329 (save-excursion
8330 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8331 (org-move-to-column col))))
8333 (defun org-agenda-add-note (&optional arg)
8334 "Add a time-stamped note to the entry at point."
8335 (interactive "P")
8336 (org-agenda-check-no-diary)
8337 (let* ((marker (or (org-get-at-bol 'org-marker)
8338 (org-agenda-error)))
8339 (buffer (marker-buffer marker))
8340 (pos (marker-position marker))
8341 (hdmarker (org-get-at-bol 'org-hd-marker))
8342 (inhibit-read-only t))
8343 (with-current-buffer buffer
8344 (widen)
8345 (goto-char pos)
8346 (org-show-context 'agenda)
8347 (save-excursion
8348 (and (outline-next-heading)
8349 (org-flag-heading nil))) ; show the next heading
8350 (org-add-note))))
8352 (defun org-agenda-change-all-lines (newhead hdmarker
8353 &optional fixface just-this)
8354 "Change all lines in the agenda buffer which match HDMARKER.
8355 The new content of the line will be NEWHEAD (as modified by
8356 `org-agenda-format-item'). HDMARKER is checked with
8357 `equal' against all `org-hd-marker' text properties in the file.
8358 If FIXFACE is non-nil, the face of each item is modified according to
8359 the new TODO state.
8360 If JUST-THIS is non-nil, change just the current line, not all.
8361 If FORCE-TAGS is non nil, the car of it returns the new tags."
8362 (let* ((inhibit-read-only t)
8363 (line (org-current-line))
8364 (org-agenda-buffer (current-buffer))
8365 (thetags (with-current-buffer (marker-buffer hdmarker)
8366 (save-excursion (save-restriction (widen)
8367 (goto-char hdmarker)
8368 (org-get-tags-at)))))
8369 props m pl undone-face done-face finish new dotime cat tags)
8370 (save-excursion
8371 (goto-char (point-max))
8372 (beginning-of-line 1)
8373 (while (not finish)
8374 (setq finish (bobp))
8375 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8376 (or (not just-this) (= (org-current-line) line))
8377 (equal m hdmarker))
8378 (setq props (text-properties-at (point))
8379 dotime (org-get-at-bol 'dotime)
8380 cat (org-get-at-bol 'org-category)
8381 tags thetags
8383 (let ((org-prefix-format-compiled
8384 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8385 org-prefix-format-compiled))
8386 (extra (org-get-at-bol 'extra)))
8387 (with-current-buffer (marker-buffer hdmarker)
8388 (save-excursion
8389 (save-restriction
8390 (widen)
8391 (org-agenda-format-item extra newhead cat tags dotime)))))
8392 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8393 undone-face (org-get-at-bol 'undone-face)
8394 done-face (org-get-at-bol 'done-face))
8395 (beginning-of-line 1)
8396 (cond
8397 ((equal new "")
8398 (and (looking-at ".*\n?") (replace-match "")))
8399 ((looking-at ".*")
8400 (replace-match new t t)
8401 (beginning-of-line 1)
8402 (add-text-properties (point-at-bol) (point-at-eol) props)
8403 (when fixface
8404 (add-text-properties
8405 (point-at-bol) (point-at-eol)
8406 (list 'face
8407 (if org-last-todo-state-is-todo
8408 undone-face done-face))))
8409 (org-agenda-highlight-todo 'line)
8410 (beginning-of-line 1))
8411 (t (error "Line update did not work")))
8412 (save-restriction
8413 (narrow-to-region (point-at-bol) (point-at-eol))
8414 (org-agenda-finalize)))
8415 (beginning-of-line 0)))))
8417 (defun org-agenda-align-tags (&optional line)
8418 "Align all tags in agenda items to `org-agenda-tags-column'."
8419 (let ((inhibit-read-only t) l c)
8420 (save-excursion
8421 (goto-char (if line (point-at-bol) (point-min)))
8422 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8423 (if line (point-at-eol) nil) t)
8424 (add-text-properties
8425 (match-beginning 2) (match-end 2)
8426 (list 'face (delq nil (let ((prop (get-text-property
8427 (match-beginning 2) 'face)))
8428 (or (listp prop) (setq prop (list prop)))
8429 (if (memq 'org-tag prop)
8430 prop
8431 (cons 'org-tag prop))))))
8432 (setq l (- (match-end 2) (match-beginning 2))
8433 c (if (< org-agenda-tags-column 0)
8434 (- (abs org-agenda-tags-column) l)
8435 org-agenda-tags-column))
8436 (delete-region (match-beginning 1) (match-end 1))
8437 (goto-char (match-beginning 1))
8438 (insert (org-add-props
8439 (make-string (max 1 (- c (current-column))) ?\ )
8440 (plist-put (copy-sequence (text-properties-at (point)))
8441 'face nil))))
8442 (goto-char (point-min))
8443 (org-font-lock-add-tag-faces (point-max)))))
8445 (defun org-agenda-priority-up ()
8446 "Increase the priority of line at point, also in Org-mode file."
8447 (interactive)
8448 (org-agenda-priority 'up))
8450 (defun org-agenda-priority-down ()
8451 "Decrease the priority of line at point, also in Org-mode file."
8452 (interactive)
8453 (org-agenda-priority 'down))
8455 (defun org-agenda-priority (&optional force-direction)
8456 "Set the priority of line at point, also in Org-mode file.
8457 This changes the line at point, all other lines in the agenda referring to
8458 the same tree node, and the headline of the tree node in the Org-mode file.
8459 Called with a universal prefix arg, show the priority instead of setting it."
8460 (interactive "P")
8461 (if (equal force-direction '(4))
8462 (org-show-priority)
8463 (unless org-enable-priority-commands
8464 (error "Priority commands are disabled"))
8465 (org-agenda-check-no-diary)
8466 (let* ((marker (or (org-get-at-bol 'org-marker)
8467 (org-agenda-error)))
8468 (hdmarker (org-get-at-bol 'org-hd-marker))
8469 (buffer (marker-buffer hdmarker))
8470 (pos (marker-position hdmarker))
8471 (inhibit-read-only t)
8472 newhead)
8473 (org-with-remote-undo buffer
8474 (with-current-buffer buffer
8475 (widen)
8476 (goto-char pos)
8477 (org-show-context 'agenda)
8478 (save-excursion
8479 (and (outline-next-heading)
8480 (org-flag-heading nil))) ; show the next heading
8481 (funcall 'org-priority force-direction)
8482 (end-of-line 1)
8483 (setq newhead (org-get-heading)))
8484 (org-agenda-change-all-lines newhead hdmarker)
8485 (beginning-of-line 1)))))
8487 ;; FIXME: should fix the tags property of the agenda line.
8488 (defun org-agenda-set-tags (&optional tag onoff)
8489 "Set tags for the current headline."
8490 (interactive)
8491 (org-agenda-check-no-diary)
8492 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8493 (call-interactively 'org-change-tag-in-region)
8494 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8495 (org-agenda-error)))
8496 (buffer (marker-buffer hdmarker))
8497 (pos (marker-position hdmarker))
8498 (inhibit-read-only t)
8499 newhead)
8500 (org-with-remote-undo buffer
8501 (with-current-buffer buffer
8502 (widen)
8503 (goto-char pos)
8504 (save-excursion
8505 (org-show-context 'agenda))
8506 (save-excursion
8507 (and (outline-next-heading)
8508 (org-flag-heading nil))) ; show the next heading
8509 (goto-char pos)
8510 (if tag
8511 (org-toggle-tag tag onoff)
8512 (call-interactively 'org-set-tags))
8513 (end-of-line 1)
8514 (setq newhead (org-get-heading)))
8515 (org-agenda-change-all-lines newhead hdmarker)
8516 (beginning-of-line 1)))))
8518 (defun org-agenda-set-property ()
8519 "Set a property for the current headline."
8520 (interactive)
8521 (org-agenda-check-no-diary)
8522 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8523 (org-agenda-error)))
8524 (buffer (marker-buffer hdmarker))
8525 (pos (marker-position hdmarker))
8526 (inhibit-read-only t)
8527 newhead)
8528 (org-with-remote-undo buffer
8529 (with-current-buffer buffer
8530 (widen)
8531 (goto-char pos)
8532 (save-excursion
8533 (org-show-context 'agenda))
8534 (save-excursion
8535 (and (outline-next-heading)
8536 (org-flag-heading nil))) ; show the next heading
8537 (goto-char pos)
8538 (call-interactively 'org-set-property)))))
8540 (defun org-agenda-set-effort ()
8541 "Set the effort property for the current headline."
8542 (interactive)
8543 (org-agenda-check-no-diary)
8544 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8545 (org-agenda-error)))
8546 (buffer (marker-buffer hdmarker))
8547 (pos (marker-position hdmarker))
8548 (inhibit-read-only t)
8549 newhead)
8550 (org-with-remote-undo buffer
8551 (with-current-buffer buffer
8552 (widen)
8553 (goto-char pos)
8554 (save-excursion
8555 (org-show-context 'agenda))
8556 (save-excursion
8557 (and (outline-next-heading)
8558 (org-flag-heading nil))) ; show the next heading
8559 (goto-char pos)
8560 (call-interactively 'org-set-effort)
8561 (end-of-line 1)
8562 (setq newhead (org-get-heading)))
8563 (org-agenda-change-all-lines newhead hdmarker))))
8565 (defun org-agenda-toggle-archive-tag ()
8566 "Toggle the archive tag for the current entry."
8567 (interactive)
8568 (org-agenda-check-no-diary)
8569 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8570 (org-agenda-error)))
8571 (buffer (marker-buffer hdmarker))
8572 (pos (marker-position hdmarker))
8573 (inhibit-read-only t)
8574 newhead)
8575 (org-with-remote-undo buffer
8576 (with-current-buffer buffer
8577 (widen)
8578 (goto-char pos)
8579 (org-show-context 'agenda)
8580 (save-excursion
8581 (and (outline-next-heading)
8582 (org-flag-heading nil))) ; show the next heading
8583 (call-interactively 'org-toggle-archive-tag)
8584 (end-of-line 1)
8585 (setq newhead (org-get-heading)))
8586 (org-agenda-change-all-lines newhead hdmarker)
8587 (beginning-of-line 1))))
8589 (defun org-agenda-do-date-later (arg)
8590 (interactive "P")
8591 (cond
8592 ((or (equal arg '(16))
8593 (memq last-command
8594 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8595 (setq this-command 'org-agenda-date-later-minutes)
8596 (org-agenda-date-later-minutes 1))
8597 ((or (equal arg '(4))
8598 (memq last-command
8599 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8600 (setq this-command 'org-agenda-date-later-hours)
8601 (org-agenda-date-later-hours 1))
8603 (org-agenda-date-later (prefix-numeric-value arg)))))
8605 (defun org-agenda-do-date-earlier (arg)
8606 (interactive "P")
8607 (cond
8608 ((or (equal arg '(16))
8609 (memq last-command
8610 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8611 (setq this-command 'org-agenda-date-earlier-minutes)
8612 (org-agenda-date-earlier-minutes 1))
8613 ((or (equal arg '(4))
8614 (memq last-command
8615 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8616 (setq this-command 'org-agenda-date-earlier-hours)
8617 (org-agenda-date-earlier-hours 1))
8619 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8621 (defun org-agenda-date-later (arg &optional what)
8622 "Change the date of this item to ARG day(s) later."
8623 (interactive "p")
8624 (org-agenda-check-type t 'agenda 'timeline)
8625 (org-agenda-check-no-diary)
8626 (let* ((marker (or (org-get-at-bol 'org-marker)
8627 (org-agenda-error)))
8628 (buffer (marker-buffer marker))
8629 (pos (marker-position marker))
8630 cdate today)
8631 (org-with-remote-undo buffer
8632 (with-current-buffer buffer
8633 (widen)
8634 (goto-char pos)
8635 (if (not (org-at-timestamp-p))
8636 (error "Cannot find time stamp"))
8637 (when (and org-agenda-move-date-from-past-immediately-to-today
8638 (equal arg 1)
8639 (or (not what) (eq what 'day))
8640 (not (save-match-data (org-at-date-range-p))))
8641 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8642 cdate (calendar-absolute-from-gregorian
8643 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8644 today (org-today))
8645 (if (> today cdate)
8646 ;; immediately shift to today
8647 (setq arg (- today cdate))))
8648 (org-timestamp-change arg (or what 'day))
8649 (when (and (org-at-date-range-p)
8650 (re-search-backward org-tr-regexp-both (point-at-bol)))
8651 (let ((end org-last-changed-timestamp))
8652 (org-timestamp-change arg (or what 'day))
8653 (setq org-last-changed-timestamp
8654 (concat org-last-changed-timestamp "--" end)))))
8655 (org-agenda-show-new-time marker org-last-changed-timestamp))
8656 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8658 (defun org-agenda-date-earlier (arg &optional what)
8659 "Change the date of this item to ARG day(s) earlier."
8660 (interactive "p")
8661 (org-agenda-date-later (- arg) what))
8663 (defun org-agenda-date-later-minutes (arg)
8664 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8665 (interactive "p")
8666 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8667 (org-agenda-date-later arg 'minute))
8669 (defun org-agenda-date-earlier-minutes (arg)
8670 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8671 (interactive "p")
8672 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8673 (org-agenda-date-earlier arg 'minute))
8675 (defun org-agenda-date-later-hours (arg)
8676 "Change the time of this item, in hour steps."
8677 (interactive "p")
8678 (org-agenda-date-later arg 'hour))
8680 (defun org-agenda-date-earlier-hours (arg)
8681 "Change the time of this item, in hour steps."
8682 (interactive "p")
8683 (org-agenda-date-earlier arg 'hour))
8685 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8686 "Show new date stamp via text properties."
8687 ;; We use text properties to make this undoable
8688 (let ((inhibit-read-only t))
8689 (setq stamp (concat prefix " => " stamp " "))
8690 (save-excursion
8691 (goto-char (point-max))
8692 (while (not (bobp))
8693 (when (equal marker (org-get-at-bol 'org-marker))
8694 (org-move-to-column (- (window-width) (length stamp)) t)
8695 (org-agenda-fix-tags-filter-overlays-at (point))
8696 (if (featurep 'xemacs)
8697 ;; Use `duplicable' property to trigger undo recording
8698 (let ((ex (make-extent nil nil))
8699 (gl (make-glyph stamp)))
8700 (set-glyph-face gl 'secondary-selection)
8701 (set-extent-properties
8702 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8703 (insert-extent ex (1- (point)) (point-at-eol)))
8704 (add-text-properties
8705 (1- (point)) (point-at-eol)
8706 (list 'display (org-add-props stamp nil
8707 'face 'secondary-selection))))
8708 (beginning-of-line 1))
8709 (beginning-of-line 0)))))
8711 (defun org-agenda-date-prompt (arg)
8712 "Change the date of this item. Date is prompted for, with default today.
8713 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8714 be used to request time specification in the time stamp."
8715 (interactive "P")
8716 (org-agenda-check-type t 'agenda 'timeline)
8717 (org-agenda-check-no-diary)
8718 (let* ((marker (or (org-get-at-bol 'org-marker)
8719 (org-agenda-error)))
8720 (buffer (marker-buffer marker))
8721 (pos (marker-position marker)))
8722 (org-with-remote-undo buffer
8723 (with-current-buffer buffer
8724 (widen)
8725 (goto-char pos)
8726 (if (not (org-at-timestamp-p t))
8727 (error "Cannot find time stamp"))
8728 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8729 (org-agenda-show-new-time marker org-last-changed-timestamp))
8730 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8732 (defun org-agenda-schedule (arg &optional time)
8733 "Schedule the item at point.
8734 ARG is passed through to `org-schedule'."
8735 (interactive "P")
8736 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8737 (org-agenda-check-no-diary)
8738 (let* ((marker (or (org-get-at-bol 'org-marker)
8739 (org-agenda-error)))
8740 (type (marker-insertion-type marker))
8741 (buffer (marker-buffer marker))
8742 (pos (marker-position marker))
8743 (org-insert-labeled-timestamps-at-point nil)
8745 (set-marker-insertion-type marker t)
8746 (org-with-remote-undo buffer
8747 (with-current-buffer buffer
8748 (widen)
8749 (goto-char pos)
8750 (setq ts (org-schedule arg time)))
8751 (org-agenda-show-new-time marker ts " S"))
8752 (message "%s" ts)))
8754 (defun org-agenda-deadline (arg &optional time)
8755 "Schedule the item at point.
8756 ARG is passed through to `org-deadline'."
8757 (interactive "P")
8758 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8759 (org-agenda-check-no-diary)
8760 (let* ((marker (or (org-get-at-bol 'org-marker)
8761 (org-agenda-error)))
8762 (buffer (marker-buffer marker))
8763 (pos (marker-position marker))
8764 (org-insert-labeled-timestamps-at-point nil)
8766 (org-with-remote-undo buffer
8767 (with-current-buffer buffer
8768 (widen)
8769 (goto-char pos)
8770 (setq ts (org-deadline arg time)))
8771 (org-agenda-show-new-time marker ts " D"))
8772 (message "%s" ts)))
8774 (defun org-agenda-clock-in (&optional arg)
8775 "Start the clock on the currently selected item."
8776 (interactive "P")
8777 (org-agenda-check-no-diary)
8778 (if (equal arg '(4))
8779 (org-clock-in arg)
8780 (let* ((marker (or (org-get-at-bol 'org-marker)
8781 (org-agenda-error)))
8782 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8783 marker))
8784 (pos (marker-position marker))
8785 newhead)
8786 (org-with-remote-undo (marker-buffer marker)
8787 (with-current-buffer (marker-buffer marker)
8788 (widen)
8789 (goto-char pos)
8790 (org-show-context 'agenda)
8791 (org-show-entry)
8792 (org-cycle-hide-drawers 'children)
8793 (org-clock-in arg)
8794 (setq newhead (org-get-heading)))
8795 (org-agenda-change-all-lines newhead hdmarker)))))
8797 (defun org-agenda-clock-out ()
8798 "Stop the currently running clock."
8799 (interactive)
8800 (unless (marker-buffer org-clock-marker)
8801 (error "No running clock"))
8802 (let ((marker (make-marker)) newhead)
8803 (org-with-remote-undo (marker-buffer org-clock-marker)
8804 (with-current-buffer (marker-buffer org-clock-marker)
8805 (save-excursion
8806 (save-restriction
8807 (widen)
8808 (goto-char org-clock-marker)
8809 (org-back-to-heading t)
8810 (move-marker marker (point))
8811 (org-clock-out)
8812 (setq newhead (org-get-heading))))))
8813 (org-agenda-change-all-lines newhead marker)
8814 (move-marker marker nil)))
8816 (defun org-agenda-clock-cancel (&optional arg)
8817 "Cancel the currently running clock."
8818 (interactive "P")
8819 (unless (marker-buffer org-clock-marker)
8820 (error "No running clock"))
8821 (org-with-remote-undo (marker-buffer org-clock-marker)
8822 (org-clock-cancel)))
8824 (defun org-agenda-clock-goto ()
8825 "Jump to the currently clocked in task within the agenda.
8826 If the currently clocked in task is not listed in the agenda
8827 buffer, display it in another window."
8828 (interactive)
8829 (let (pos)
8830 (mapc (lambda (o)
8831 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8832 (setq pos (overlay-start o))))
8833 (overlays-in (point-min) (point-max)))
8834 (cond (pos (goto-char pos))
8835 ;; If the currently clocked entry is not in the agenda
8836 ;; buffer, we visit it in another window:
8837 (org-clock-current-task
8838 (org-switch-to-buffer-other-window (org-clock-goto)))
8839 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8841 (defun org-agenda-diary-entry-in-org-file ()
8842 "Make a diary entry in the file `org-agenda-diary-file'."
8843 (let (d1 d2 char (text "") dp1 dp2)
8844 (if (equal (buffer-name) "*Calendar*")
8845 (setq d1 (calendar-cursor-to-date t)
8846 d2 (car calendar-mark-ring))
8847 (setq dp1 (get-text-property (point-at-bol) 'day))
8848 (unless dp1 (error "No date defined in current line"))
8849 (setq d1 (calendar-gregorian-from-absolute dp1)
8850 d2 (and (ignore-errors (mark))
8851 (save-excursion
8852 (goto-char (mark))
8853 (setq dp2 (get-text-property (point-at-bol) 'day)))
8854 (calendar-gregorian-from-absolute dp2))))
8855 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8856 (setq char (read-char-exclusive))
8857 (cond
8858 ((equal char ?d)
8859 (setq text (read-string "Day entry: "))
8860 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8861 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8862 ((equal char ?a)
8863 (setq d1 (list (car d1) (nth 1 d1)
8864 (read-number (format "Reference year [%d]: " (nth 2 d1))
8865 (nth 2 d1))))
8866 (setq text (read-string "Anniversary (use %d to show years): "))
8867 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8868 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8869 ((equal char ?b)
8870 (setq text (read-string "Block entry: "))
8871 (unless (and d1 d2 (not (equal d1 d2)))
8872 (error "No block of days selected"))
8873 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8874 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8875 ((equal char ?j)
8876 (org-switch-to-buffer-other-window
8877 (find-file-noselect org-agenda-diary-file))
8878 (require 'org-datetree)
8879 (org-datetree-find-date-create d1)
8880 (org-reveal t))
8881 (t (error "Invalid selection character `%c'" char)))))
8883 (defcustom org-agenda-insert-diary-strategy 'date-tree
8884 "Where in `org-agenda-diary-file' should new entries be added?
8885 Valid values:
8887 date-tree in the date tree, as child of the date
8888 top-level as top-level entries at the end of the file."
8889 :group 'org-agenda
8890 :type '(choice
8891 (const :tag "in a date tree" date-tree)
8892 (const :tag "as top level at end of file" top-level)))
8894 (defcustom org-agenda-insert-diary-extract-time nil
8895 "Non-nil means extract any time specification from the diary entry."
8896 :group 'org-agenda
8897 :version "24.1"
8898 :type 'boolean)
8900 (defcustom org-agenda-bulk-mark-char ">"
8901 "A single-character string to be used as the bulk mark."
8902 :group 'org-agenda
8903 :version "24.1"
8904 :type 'string)
8906 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8907 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8908 If TEXT is not empty, it will become the headline of the new entry, and
8909 the resulting entry will not be shown. When TEXT is empty, switch to
8910 `org-agenda-diary-file' and let the user finish the entry there."
8911 (let ((cw (current-window-configuration)))
8912 (org-switch-to-buffer-other-window
8913 (find-file-noselect org-agenda-diary-file))
8914 (widen)
8915 (goto-char (point-min))
8916 (cond
8917 ((eq type 'anniversary)
8918 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8919 (progn
8920 (or (org-at-heading-p t)
8921 (progn
8922 (outline-next-heading)
8923 (insert "* Anniversaries\n\n")
8924 (beginning-of-line -1)))))
8925 (outline-next-heading)
8926 (org-back-over-empty-lines)
8927 (backward-char 1)
8928 (insert "\n")
8929 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8930 (nth 2 d1) (car d1) (nth 1 d1) text)))
8931 ((eq type 'day)
8932 (let ((org-prefix-has-time t)
8933 (org-agenda-time-leading-zero t)
8934 fmt time time2)
8935 (if org-agenda-insert-diary-extract-time
8936 ;; Use org-agenda-format-item to parse text for a time-range and
8937 ;; remove it. FIXME: This is a hack, we should refactor
8938 ;; that function to make time extraction available separately
8939 (setq fmt (org-agenda-format-item nil text nil nil t)
8940 time (get-text-property 0 'time fmt)
8941 time2 (if (> (length time) 0)
8942 ;; split-string removes trailing ...... if
8943 ;; no end time given. First space
8944 ;; separates time from date.
8945 (concat " " (car (split-string time "\\.")))
8946 nil)
8947 text (get-text-property 0 'txt fmt)))
8948 (if (eq org-agenda-insert-diary-strategy 'top-level)
8949 (org-agenda-insert-diary-as-top-level text)
8950 (require 'org-datetree)
8951 (org-datetree-find-date-create d1)
8952 (org-agenda-insert-diary-make-new-entry text))
8953 (org-insert-time-stamp (org-time-from-absolute
8954 (calendar-absolute-from-gregorian d1))
8955 nil nil nil nil time2))
8956 (end-of-line 0))
8957 ((eq type 'block)
8958 (if (> (calendar-absolute-from-gregorian d1)
8959 (calendar-absolute-from-gregorian d2))
8960 (setq d1 (prog1 d2 (setq d2 d1))))
8961 (if (eq org-agenda-insert-diary-strategy 'top-level)
8962 (org-agenda-insert-diary-as-top-level text)
8963 (require 'org-datetree)
8964 (org-datetree-find-date-create d1)
8965 (org-agenda-insert-diary-make-new-entry text))
8966 (org-insert-time-stamp (org-time-from-absolute
8967 (calendar-absolute-from-gregorian d1)))
8968 (insert "--")
8969 (org-insert-time-stamp (org-time-from-absolute
8970 (calendar-absolute-from-gregorian d2)))
8971 (end-of-line 0)))
8972 (if (string-match "\\S-" text)
8973 (progn
8974 (set-window-configuration cw)
8975 (message "%s entry added to %s"
8976 (capitalize (symbol-name type))
8977 (abbreviate-file-name org-agenda-diary-file)))
8978 (org-reveal t)
8979 (message "Please finish entry here"))))
8981 (defun org-agenda-insert-diary-as-top-level (text)
8982 "Make new entry as a top-level entry at the end of the file.
8983 Add TEXT as headline, and position the cursor in the second line so that
8984 a timestamp can be added there."
8985 (widen)
8986 (goto-char (point-max))
8987 (or (bolp) (insert "\n"))
8988 (insert "* " text "\n")
8989 (if org-adapt-indentation (org-indent-to-column 2)))
8991 (defun org-agenda-insert-diary-make-new-entry (text)
8992 "Make new entry as last child of current entry.
8993 Add TEXT as headline, and position the cursor in the second line so that
8994 a timestamp can be added there."
8995 (let ((org-show-following-heading t)
8996 (org-show-siblings t)
8997 (org-show-hierarchy-above t)
8998 (org-show-entry-below t)
8999 col)
9000 (outline-next-heading)
9001 (org-back-over-empty-lines)
9002 (or (looking-at "[ \t]*$")
9003 (progn (insert "\n") (backward-char 1)))
9004 (org-insert-heading nil t)
9005 (org-do-demote)
9006 (setq col (current-column))
9007 (insert text "\n")
9008 (if org-adapt-indentation (org-indent-to-column col))
9009 (let ((org-show-following-heading t)
9010 (org-show-siblings t)
9011 (org-show-hierarchy-above t)
9012 (org-show-entry-below t))
9013 (org-show-context))))
9015 (defun org-agenda-diary-entry ()
9016 "Make a diary entry, like the `i' command from the calendar.
9017 All the standard commands work: block, weekly etc.
9018 When `org-agenda-diary-file' points to a file,
9019 `org-agenda-diary-entry-in-org-file' is called instead to create
9020 entries in that Org-mode file."
9021 (interactive)
9022 (if (not (eq org-agenda-diary-file 'diary-file))
9023 (org-agenda-diary-entry-in-org-file)
9024 (require 'diary-lib)
9025 (let* ((char (progn
9026 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9027 (read-char-exclusive)))
9028 (cmd (cdr (assoc char
9029 '((?d . insert-diary-entry)
9030 (?w . insert-weekly-diary-entry)
9031 (?m . insert-monthly-diary-entry)
9032 (?y . insert-yearly-diary-entry)
9033 (?a . insert-anniversary-diary-entry)
9034 (?b . insert-block-diary-entry)
9035 (?c . insert-cyclic-diary-entry)))))
9036 (oldf (symbol-function 'calendar-cursor-to-date))
9037 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9038 (point (point))
9039 (mark (or (mark t) (point))))
9040 (unless cmd
9041 (error "No command associated with <%c>" char))
9042 (unless (and (get-text-property point 'day)
9043 (or (not (equal ?b char))
9044 (get-text-property mark 'day)))
9045 (error "Don't know which date to use for diary entry"))
9046 ;; We implement this by hacking the `calendar-cursor-to-date' function
9047 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9048 (let ((calendar-mark-ring
9049 (list (calendar-gregorian-from-absolute
9050 (or (get-text-property mark 'day)
9051 (get-text-property point 'day))))))
9052 (unwind-protect
9053 (progn
9054 (fset 'calendar-cursor-to-date
9055 (lambda (&optional error dummy)
9056 (calendar-gregorian-from-absolute
9057 (get-text-property point 'day))))
9058 (call-interactively cmd))
9059 (fset 'calendar-cursor-to-date oldf))))))
9061 (defun org-agenda-execute-calendar-command (cmd)
9062 "Execute a calendar command from the agenda with date from cursor."
9063 (org-agenda-check-type t 'agenda 'timeline)
9064 (require 'diary-lib)
9065 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9066 (error "Don't know which date to use for the calendar command"))
9067 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9068 (point (point))
9069 (date (calendar-gregorian-from-absolute
9070 (get-text-property point 'day)))
9071 ;; the following 2 vars are needed in the calendar
9072 (displayed-month (car date))
9073 (displayed-year (nth 2 date)))
9074 (unwind-protect
9075 (progn
9076 (fset 'calendar-cursor-to-date
9077 (lambda (&optional error dummy)
9078 (calendar-gregorian-from-absolute
9079 (get-text-property point 'day))))
9080 (call-interactively cmd))
9081 (fset 'calendar-cursor-to-date oldf))))
9083 (defun org-agenda-phases-of-moon ()
9084 "Display the phases of the moon for the 3 months around the cursor date."
9085 (interactive)
9086 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9088 (defun org-agenda-holidays ()
9089 "Display the holidays for the 3 months around the cursor date."
9090 (interactive)
9091 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9093 (defvar calendar-longitude) ; defined in calendar.el
9094 (defvar calendar-latitude) ; defined in calendar.el
9095 (defvar calendar-location-name) ; defined in calendar.el
9097 (defun org-agenda-sunrise-sunset (arg)
9098 "Display sunrise and sunset for the cursor date.
9099 Latitude and longitude can be specified with the variables
9100 `calendar-latitude' and `calendar-longitude'. When called with prefix
9101 argument, latitude and longitude will be prompted for."
9102 (interactive "P")
9103 (require 'solar)
9104 (let ((calendar-longitude (if arg nil calendar-longitude))
9105 (calendar-latitude (if arg nil calendar-latitude))
9106 (calendar-location-name
9107 (if arg "the given coordinates" calendar-location-name)))
9108 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9110 (defun org-agenda-goto-calendar ()
9111 "Open the Emacs calendar with the date at the cursor."
9112 (interactive)
9113 (org-agenda-check-type t 'agenda 'timeline)
9114 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9115 (error "Don't know which date to open in calendar")))
9116 (date (calendar-gregorian-from-absolute day))
9117 (calendar-move-hook nil)
9118 (calendar-view-holidays-initially-flag nil)
9119 (calendar-view-diary-initially-flag nil))
9120 (calendar)
9121 (calendar-goto-date date)))
9123 ;;;###autoload
9124 (defun org-calendar-goto-agenda ()
9125 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9126 This is a command that has to be installed in `calendar-mode-map'."
9127 (interactive)
9128 (org-agenda-list nil (calendar-absolute-from-gregorian
9129 (calendar-cursor-to-date))
9130 nil))
9132 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9133 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9134 This is a command that has to be installed in `calendar-mode-map'.
9136 \(fn)" t nil)
9138 (defun org-agenda-convert-date ()
9139 (interactive)
9140 (org-agenda-check-type t 'agenda 'timeline)
9141 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9142 date s)
9143 (unless day
9144 (error "Don't know which date to convert"))
9145 (setq date (calendar-gregorian-from-absolute day))
9146 (setq s (concat
9147 "Gregorian: " (calendar-date-string date) "\n"
9148 "ISO: " (calendar-iso-date-string date) "\n"
9149 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9150 "Julian: " (calendar-julian-date-string date) "\n"
9151 "Astron. JD: " (calendar-astro-date-string date)
9152 " (Julian date number at noon UTC)\n"
9153 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9154 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9155 "French: " (calendar-french-date-string date) "\n"
9156 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9157 "Mayan: " (calendar-mayan-date-string date) "\n"
9158 "Coptic: " (calendar-coptic-date-string date) "\n"
9159 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9160 "Persian: " (calendar-persian-date-string date) "\n"
9161 "Chinese: " (calendar-chinese-date-string date) "\n"))
9162 (with-output-to-temp-buffer "*Dates*"
9163 (princ s))
9164 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9166 ;;; Bulk commands
9168 (defun org-agenda-bulk-marked-p ()
9169 (eq (get-char-property (point-at-bol) 'type)
9170 'org-marked-entry-overlay))
9172 (defun org-agenda-bulk-mark (&optional arg)
9173 "Mark the entry at point for future bulk action."
9174 (interactive "p")
9175 (dotimes (i (or arg 1))
9176 (unless (org-get-at-bol 'org-agenda-diary-link)
9177 (let* ((m (org-get-at-bol 'org-hd-marker))
9179 (unless (org-agenda-bulk-marked-p)
9180 (unless m (error "Nothing to mark at point"))
9181 (push m org-agenda-bulk-marked-entries)
9182 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9183 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9184 (org-get-todo-face "TODO")
9185 'evaporate)
9186 (overlay-put ov 'type 'org-marked-entry-overlay))
9187 (beginning-of-line 2)
9188 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9189 (beginning-of-line 2))
9190 (message "%d entries marked for bulk action"
9191 (length org-agenda-bulk-marked-entries))))))
9193 (defun org-agenda-bulk-mark-all ()
9194 "Mark all entries for future agenda bulk action."
9195 (interactive)
9196 (org-agenda-bulk-mark-regexp "."))
9198 (defun org-agenda-bulk-mark-regexp (regexp)
9199 "Mark entries matching REGEXP for future agenda bulk action."
9200 (interactive "sMark entries matching regexp: ")
9201 (let ((entries-marked 0))
9202 (save-excursion
9203 (goto-char (point-min))
9204 (goto-char (next-single-property-change (point) 'txt))
9205 (while (re-search-forward regexp nil t)
9206 (when (string-match regexp (get-text-property (point) 'txt))
9207 (setq entries-marked (1+ entries-marked))
9208 (call-interactively 'org-agenda-bulk-mark))))
9209 (if (not entries-marked)
9210 (message "No entry matching this regexp."))))
9212 (defun org-agenda-bulk-unmark (&optional arg)
9213 "Unmark the entry at point for future bulk action."
9214 (interactive "P")
9215 (if arg
9216 (org-agenda-bulk-unmark-all)
9217 (cond ((org-agenda-bulk-marked-p)
9218 (org-agenda-bulk-remove-overlays
9219 (point-at-bol) (+ 2 (point-at-bol)))
9220 (setq org-agenda-bulk-marked-entries
9221 (delete (org-get-at-bol 'org-hd-marker)
9222 org-agenda-bulk-marked-entries))
9223 (beginning-of-line 2)
9224 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9225 (beginning-of-line 2))
9226 (message "%d entries left marked for bulk action"
9227 (length org-agenda-bulk-marked-entries)))
9228 (t (message "No entry to unmark here")))))
9230 (defun org-agenda-bulk-toggle ()
9231 "Toggle marking the entry at point for bulk action."
9232 (interactive)
9233 (if (org-agenda-bulk-marked-p)
9234 (org-agenda-bulk-unmark)
9235 (org-agenda-bulk-mark)))
9237 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9238 "Remove the mark overlays between BEG and END in the agenda buffer.
9239 BEG and END default to the buffer limits.
9241 This only removes the overlays, it does not remove the markers
9242 from the list in `org-agenda-bulk-marked-entries'."
9243 (interactive)
9244 (mapc (lambda (ov)
9245 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9246 (delete-overlay ov)))
9247 (overlays-in (or beg (point-min)) (or end (point-max)))))
9249 (defun org-agenda-bulk-unmark-all ()
9250 "Remove all marks in the agenda buffer.
9251 This will remove the markers and the overlays."
9252 (interactive)
9253 (if (null org-agenda-bulk-marked-entries)
9254 (message "No entry to unmark")
9255 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9256 (setq org-agenda-bulk-marked-entries nil)
9257 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9259 (defcustom org-agenda-persistent-marks nil
9260 "Non-nil means marked items will stay marked after a bulk action.
9261 You can toggle this interactively by typing `p' when prompted for a
9262 bulk action."
9263 :group 'org-agenda
9264 :version "24.1"
9265 :type 'boolean)
9267 (defun org-agenda-bulk-action (&optional arg)
9268 "Execute an remote-editing action on all marked entries.
9269 The prefix arg is passed through to the command if possible."
9270 (interactive "P")
9271 ;; Make sure we have markers, and only valid ones
9272 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9273 (mapc
9274 (lambda (m)
9275 (unless (and (markerp m)
9276 (marker-buffer m)
9277 (buffer-live-p (marker-buffer m))
9278 (marker-position m))
9279 (error "Marker %s for bulk command is invalid" m)))
9280 org-agenda-bulk-marked-entries)
9282 ;; Prompt for the bulk command
9283 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9284 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9285 "[S]catter [f]unction "
9286 (when org-agenda-bulk-custom-functions
9287 (concat " Custom: ["
9288 (mapconcat (lambda(f) (char-to-string (car f)))
9289 org-agenda-bulk-custom-functions "")
9290 "]"))))
9291 (catch 'exit
9292 (let* ((action (read-char-exclusive))
9293 (org-log-refile (if org-log-refile 'time nil))
9294 (entries (reverse org-agenda-bulk-marked-entries))
9295 (org-overriding-default-time
9296 (if (get-text-property (point) 'org-agenda-date-header)
9297 (org-get-cursor-date)))
9298 redo-at-end
9299 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9300 (cond
9301 ((equal action ?p)
9302 (let ((org-agenda-persistent-marks
9303 (not org-agenda-persistent-marks)))
9304 (org-agenda-bulk-action)
9305 (throw 'exit nil)))
9307 ((equal action ?$)
9308 (setq cmd '(org-agenda-archive)))
9310 ((equal action ?A)
9311 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9313 ((member action '(?r ?w))
9314 (setq rfloc (org-refile-get-location
9315 "Refile to"
9316 (marker-buffer (car entries))
9317 org-refile-allow-creating-parent-nodes))
9318 (if (nth 3 rfloc)
9319 (setcar (nthcdr 3 rfloc)
9320 (move-marker (make-marker) (nth 3 rfloc)
9321 (or (get-file-buffer (nth 1 rfloc))
9322 (find-buffer-visiting (nth 1 rfloc))
9323 (error "This should not happen")))))
9325 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9326 redo-at-end t))
9328 ((equal action ?t)
9329 (setq state (org-icompleting-read
9330 "Todo state: "
9331 (with-current-buffer (marker-buffer (car entries))
9332 (mapcar 'list org-todo-keywords-1))))
9333 (setq cmd `(let ((org-inhibit-blocking t)
9334 (org-inhibit-logging 'note))
9335 (org-agenda-todo ,state))))
9337 ((memq action '(?- ?+))
9338 (setq tag (org-icompleting-read
9339 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9340 (with-current-buffer (marker-buffer (car entries))
9341 (delq nil
9342 (mapcar (lambda (x)
9343 (if (stringp (car x)) x)) org-tag-alist)))))
9344 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9346 ((memq action '(?s ?d))
9347 (let* ((time
9348 (unless arg
9349 (org-read-date
9350 nil nil nil
9351 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9352 org-overriding-default-time)))
9353 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9354 (setq cmd `(eval '(,c1 arg ,time)))))
9356 ((equal action ?S)
9357 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9358 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9359 (let ((days (read-number
9360 (format "Scatter tasks across how many %sdays: "
9361 (if arg "week" "")) 7)))
9362 (setq cmd
9363 `(let ((distance (1+ (random ,days))))
9364 (if arg
9365 (let ((dist distance)
9366 (day-of-week
9367 (calendar-day-of-week
9368 (calendar-gregorian-from-absolute (org-today)))))
9369 (dotimes (i (1+ dist))
9370 (while (member day-of-week org-agenda-weekend-days)
9371 (incf distance)
9372 (incf day-of-week)
9373 (if (= day-of-week 7)
9374 (setq day-of-week 0)))
9375 (incf day-of-week)
9376 (if (= day-of-week 7)
9377 (setq day-of-week 0)))))
9378 ;; silently fail when try to replan a sexp entry
9379 (condition-case nil
9380 (let* ((date (calendar-gregorian-from-absolute
9381 (+ (org-today) distance)))
9382 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9383 (nth 2 date))))
9384 (org-agenda-schedule nil time))
9385 (error nil)))))))
9387 ((assoc action org-agenda-bulk-custom-functions)
9388 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9389 redo-at-end t))
9391 ((equal action ?f)
9392 (setq cmd (list (intern
9393 (org-icompleting-read "Function: "
9394 obarray 'fboundp t nil nil)))))
9396 (t (error "Invalid bulk action")))
9398 ;; Sort the markers, to make sure that parents are handled before children
9399 (setq entries (sort entries
9400 (lambda (a b)
9401 (cond
9402 ((equal (marker-buffer a) (marker-buffer b))
9403 (< (marker-position a) (marker-position b)))
9405 (string< (buffer-name (marker-buffer a))
9406 (buffer-name (marker-buffer b))))))))
9408 ;; Now loop over all markers and apply cmd
9409 (while (setq e (pop entries))
9410 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9411 (if (not pos)
9412 (progn (message "Skipping removed entry at %s" e)
9413 (setq cntskip (1+ cntskip)))
9414 (goto-char pos)
9415 (let (org-loop-over-headlines-in-active-region)
9416 (eval cmd))
9417 (setq cnt (1+ cnt))))
9418 (when redo-at-end (org-agenda-redo))
9419 (unless org-agenda-persistent-marks
9420 (org-agenda-bulk-unmark-all))
9421 (message "Acted on %d entries%s%s"
9423 (if (= cntskip 0)
9425 (format ", skipped %d (disappeared before their turn)"
9426 cntskip))
9427 (if (not org-agenda-persistent-marks)
9428 "" " (kept marked)"))))))
9430 (defun org-agenda-capture ()
9431 "Call `org-capture' with the date at point."
9432 (interactive)
9433 (if (not (eq major-mode 'org-agenda-mode))
9434 (error "You cannot do this outside of agenda buffers")
9435 (let ((org-overriding-default-time
9436 (org-get-cursor-date)))
9437 (call-interactively 'org-capture))))
9439 ;;; Flagging notes
9441 (defun org-agenda-show-the-flagging-note ()
9442 "Display the flagging note in the other window.
9443 When called a second time in direct sequence, offer to remove the FLAGGING
9444 tag and (if present) the flagging note."
9445 (interactive)
9446 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9447 (win (selected-window))
9448 note heading newhead)
9449 (unless hdmarker
9450 (error "No linked entry at point"))
9451 (if (and (eq this-command last-command)
9452 (y-or-n-p "Unflag and remove any flagging note? "))
9453 (progn
9454 (org-agenda-remove-flag hdmarker)
9455 (let ((win (get-buffer-window "*Flagging Note*")))
9456 (and win (delete-window win)))
9457 (message "Entry unflagged"))
9458 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9459 (unless note
9460 (error "No flagging note"))
9461 (org-kill-new note)
9462 (org-switch-to-buffer-other-window "*Flagging Note*")
9463 (erase-buffer)
9464 (insert note)
9465 (goto-char (point-min))
9466 (while (re-search-forward "\\\\n" nil t)
9467 (replace-match "\n" t t))
9468 (goto-char (point-min))
9469 (select-window win)
9470 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9472 (defun org-agenda-remove-flag (marker)
9473 "Remove the FLAGGED tag and any flagging note in the entry."
9474 (let (newhead)
9475 (org-with-point-at marker
9476 (org-toggle-tag "FLAGGED" 'off)
9477 (org-entry-delete nil "THEFLAGGINGNOTE")
9478 (setq newhead (org-get-heading)))
9479 (org-agenda-change-all-lines newhead marker)
9480 (message "Entry unflagged")))
9482 (defun org-agenda-get-any-marker (&optional pos)
9483 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9484 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9486 ;;; Appointment reminders
9488 (defvar appt-time-msg-list) ; defined in appt.el
9490 ;;;###autoload
9491 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9492 "Activate appointments found in `org-agenda-files'.
9493 With a \\[universal-argument] prefix, refresh the list of
9494 appointments.
9496 If FILTER is t, interactively prompt the user for a regular
9497 expression, and filter out entries that don't match it.
9499 If FILTER is a string, use this string as a regular expression
9500 for filtering entries out.
9502 If FILTER is a function, filter out entries against which
9503 calling the function returns nil. This function takes one
9504 argument: an entry from `org-agenda-get-day-entries'.
9506 FILTER can also be an alist with the car of each cell being
9507 either 'headline or 'category. For example:
9509 '((headline \"IMPORTANT\")
9510 (category \"Work\"))
9512 will only add headlines containing IMPORTANT or headlines
9513 belonging to the \"Work\" category.
9515 ARGS are symbols indicating what kind of entries to consider.
9516 By default `org-agenda-to-appt' will use :deadline, :scheduled
9517 and :timestamp entries. See the docstring of `org-diary' for
9518 details and examples.
9520 If an entry as a APPT_WARNTIME property, its value will be used
9521 to override `appt-message-warning-time'."
9522 (interactive "P")
9523 (if refresh (setq appt-time-msg-list nil))
9524 (if (eq filter t)
9525 (setq filter (read-from-minibuffer "Regexp filter: ")))
9526 (let* ((cnt 0) ; count added events
9527 (scope (or args '(:deadline :scheduled :timestamp)))
9528 (org-agenda-new-buffers nil)
9529 (org-deadline-warning-days 0)
9530 ;; Do not use `org-today' here because appt only takes
9531 ;; time and without date as argument, so it may pass wrong
9532 ;; information otherwise
9533 (today (org-date-to-gregorian
9534 (time-to-days (current-time))))
9535 (org-agenda-restrict nil)
9536 (files (org-agenda-files 'unrestricted)) entries file
9537 (org-agenda-buffer nil))
9538 ;; Get all entries which may contain an appt
9539 (org-agenda-prepare-buffers files)
9540 (while (setq file (pop files))
9541 (setq entries
9542 (delq nil
9543 (append entries
9544 (apply 'org-agenda-get-day-entries
9545 file today scope)))))
9546 ;; Map thru entries and find if we should filter them out
9547 (mapc
9548 (lambda(x)
9549 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9550 (cat (get-text-property 1 'org-category x))
9551 (tod (get-text-property 1 'time-of-day x))
9552 (ok (or (null filter)
9553 (and (stringp filter) (string-match filter evt))
9554 (and (functionp filter) (funcall filter x))
9555 (and (listp filter)
9556 (let ((cat-filter (cadr (assoc 'category filter)))
9557 (evt-filter (cadr (assoc 'headline filter))))
9558 (or (and (stringp cat-filter)
9559 (string-match cat-filter cat))
9560 (and (stringp evt-filter)
9561 (string-match evt-filter evt)))))))
9562 (wrn (get-text-property 1 'warntime x)))
9563 ;; FIXME: Shall we remove text-properties for the appt text?
9564 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9565 (when (and ok tod)
9566 (setq tod (concat "00" (number-to-string tod))
9567 tod (when (string-match
9568 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9569 (concat (match-string 1 tod) ":"
9570 (match-string 2 tod))))
9571 (if (version< emacs-version "23.3")
9572 (appt-add tod evt)
9573 (appt-add tod evt wrn))
9574 (setq cnt (1+ cnt))))) entries)
9575 (org-release-buffers org-agenda-new-buffers)
9576 (if (eq cnt 0)
9577 (message "No event to add")
9578 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9580 (autoload 'org-agenda-to-appt "org-agenda" "\
9581 Activate appointments found in `org-agenda-files'.
9582 With a \\[universal-argument] prefix, refresh the list of
9583 appointments.
9585 If FILTER is t, interactively prompt the user for a regular
9586 expression, and filter out entries that don't match it.
9588 If FILTER is a string, use this string as a regular expression
9589 for filtering entries out.
9591 If FILTER is a function, filter out entries against which
9592 calling the function returns nil. This function takes one
9593 argument: an entry from `org-agenda-get-day-entries'.
9595 FILTER can also be an alist with the car of each cell being
9596 either 'headline or 'category. For example:
9598 '((headline \"IMPORTANT\")
9599 (category \"Work\"))
9601 will only add headlines containing IMPORTANT or headlines
9602 belonging to the \"Work\" category.
9604 ARGS are symbols indicating what kind of entries to consider.
9605 By default `org-agenda-to-appt' will use :deadline, :scheduled
9606 and :timestamp entries. See the docstring of `org-diary' for
9607 details and examples.
9609 If an entry as a APPT_WARNTIME property, its value will be used
9610 to override `appt-message-warning-time'.
9612 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9614 (defun org-agenda-todayp (date)
9615 "Does DATE mean today, when considering `org-extend-today-until'?"
9616 (let ((today (org-today))
9617 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9618 date)))
9619 (eq date today)))
9621 (defun org-agenda-todo-yesterday (&optional arg)
9622 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9623 (interactive "P")
9624 (let* ((hour (third (decode-time
9625 (org-current-time))))
9626 (org-extend-today-until (1+ hour)))
9627 (org-agenda-todo arg)))
9629 (provide 'org-agenda)
9631 ;;; org-agenda.el ends here