org-agenda.el (org-agenda-finalize): Inhibit readonly for the whole function
[org-mode.git] / lisp / org-agenda.el
blob2eb96c2510b2b92351a0b9a9f3919bacd5fc7bed
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags to not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-tags-todo-honor-ignore-options nil
744 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
745 The variables
746 `org-agenda-todo-ignore-with-date',
747 `org-agenda-todo-ignore-timestamp',
748 `org-agenda-todo-ignore-scheduled',
749 `org-agenda-todo-ignore-deadlines'
750 make the global TODO list skip entries that have time stamps of certain
751 kinds. If this option is set, the same options will also apply for the
752 tags-todo search, which is the general tags/property matcher
753 restricted to unfinished TODO entries only."
754 :group 'org-agenda-skip
755 :group 'org-agenda-todo-list
756 :group 'org-agenda-match-view
757 :type 'boolean)
759 (defcustom org-agenda-skip-scheduled-if-done nil
760 "Non-nil means don't show scheduled items in agenda when they are done.
761 This is relevant for the daily/weekly agenda, not for the TODO list. And
762 it applies only to the actual date of the scheduling. Warnings about
763 an item with a past scheduling dates are always turned off when the item
764 is DONE."
765 :group 'org-agenda-skip
766 :group 'org-agenda-daily/weekly
767 :type 'boolean)
769 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
770 "Non-nil means skip scheduling line if same entry shows because of deadline.
771 In the agenda of today, an entry can show up multiple times because
772 it is both scheduled and has a nearby deadline, and maybe a plain time
773 stamp as well.
774 When this variable is t, then only the deadline is shown and the fact that
775 the entry is scheduled today or was scheduled previously is not shown.
776 When this variable is nil, the entry will be shown several times. When
777 the variable is the symbol `not-today', then skip scheduled previously,
778 but not scheduled today."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type '(choice
782 (const :tag "Never" nil)
783 (const :tag "Always" t)
784 (const :tag "Not when scheduled today" not-today)))
786 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
787 "Non-nil means skip timestamp line if same entry shows because of deadline.
788 In the agenda of today, an entry can show up multiple times
789 because it has both a plain timestamp and has a nearby deadline.
790 When this variable is t, then only the deadline is shown and the
791 fact that the entry has a timestamp for or including today is not
792 shown. When this variable is nil, the entry will be shown
793 several times."
794 :group 'org-agenda-skip
795 :group 'org-agenda-daily/weekly
796 :version "24.1"
797 :type '(choice
798 (const :tag "Never" nil)
799 (const :tag "Always" t)))
801 (defcustom org-agenda-skip-deadline-if-done nil
802 "Non-nil means don't show deadlines when the corresponding item is done.
803 When nil, the deadline is still shown and should give you a happy feeling.
804 This is relevant for the daily/weekly agenda. And it applied only to the
805 actually date of the deadline. Warnings about approaching and past-due
806 deadlines are always turned off when the item is DONE."
807 :group 'org-agenda-skip
808 :group 'org-agenda-daily/weekly
809 :type 'boolean)
811 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
812 "Non-nil means skip deadline prewarning when entry is also scheduled.
813 This will apply on all days where a prewarning for the deadline would
814 be shown, but not at the day when the entry is actually due. On that day,
815 the deadline will be shown anyway.
816 This variable may be set to nil, t, or a number which will then give
817 the number of days before the actual deadline when the prewarnings
818 should resume.
819 This can be used in a workflow where the first showing of the deadline will
820 trigger you to schedule it, and then you don't want to be reminded of it
821 because you will take care of it on the day when scheduled."
822 :group 'org-agenda-skip
823 :group 'org-agenda-daily/weekly
824 :version "24.1"
825 :type '(choice
826 (const :tag "Always show prewarning" nil)
827 (const :tag "Remove prewarning if entry is scheduled" t)
828 (integer :tag "Restart prewarning N days before deadline")))
830 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
831 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
832 When non-nil, after the search for timestamps has matched once in an
833 entry, the rest of the entry will not be searched."
834 :group 'org-agenda-skip
835 :type 'boolean)
837 (defcustom org-agenda-skip-timestamp-if-done nil
838 "Non-nil means don't select item by timestamp or -range if it is DONE."
839 :group 'org-agenda-skip
840 :group 'org-agenda-daily/weekly
841 :type 'boolean)
843 (defcustom org-agenda-dim-blocked-tasks nil
844 "Non-nil means dim blocked tasks in the agenda display.
845 This causes some overhead during agenda construction, but if you
846 have turned on `org-enforce-todo-dependencies',
847 `org-enforce-todo-checkbox-dependencies', or any other blocking
848 mechanism, this will create useful feedback in the agenda.
850 Instead of t, this variable can also have the value `invisible'.
851 Then blocked tasks will be invisible and only become visible when
852 they become unblocked. An exemption to this behavior is when a task is
853 blocked because of unchecked checkboxes below it. Since checkboxes do
854 not show up in the agenda views, making this task invisible you remove any
855 trace from agenda views that there is something to do. Therefore, a task
856 that is blocked because of checkboxes will never be made invisible, it
857 will only be dimmed."
858 :group 'org-agenda-daily/weekly
859 :group 'org-agenda-todo-list
860 :version "24.3"
861 :type '(choice
862 (const :tag "Do not dim" nil)
863 (const :tag "Dim to a gray face" t)
864 (const :tag "Make invisible" invisible)))
866 (defcustom org-timeline-show-empty-dates 3
867 "Non-nil means `org-timeline' also shows dates without an entry.
868 When nil, only the days which actually have entries are shown.
869 When t, all days between the first and the last date are shown.
870 When an integer, show also empty dates, but if there is a gap of more than
871 N days, just insert a special line indicating the size of the gap."
872 :group 'org-agenda-skip
873 :type '(choice
874 (const :tag "None" nil)
875 (const :tag "All" t)
876 (integer :tag "at most")))
878 (defgroup org-agenda-startup nil
879 "Options concerning initial settings in the Agenda in Org Mode."
880 :tag "Org Agenda Startup"
881 :group 'org-agenda)
883 (defcustom org-agenda-menu-show-matcher t
884 "Non-nil means show the match string in the agenda dispatcher menu.
885 When nil, the matcher string is not shown, but is put into the help-echo
886 property so than moving the mouse over the command shows it.
887 Setting it to nil is good if matcher strings are very long and/or if
888 you want to use two-columns display (see `org-agenda-menu-two-columns')."
889 :group 'org-agenda
890 :version "24.1"
891 :type 'boolean)
893 (org-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 (org-define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
904 (defcustom org-agenda-finalize-hook nil
905 "Hook run just before displaying an agenda buffer.
906 The buffer is still writable when the hook is called.
908 You can modify some of the buffer substrings but you should be
909 extra careful not to modify the text properties of the agenda
910 headlines as the agenda display heavily relies on them."
911 :group 'org-agenda-startup
912 :type 'hook)
914 (defcustom org-agenda-mouse-1-follows-link nil
915 "Non-nil means mouse-1 on a link will follow the link in the agenda.
916 A longer mouse click will still set point. Does not work on XEmacs.
917 Needs to be set before org.el is loaded."
918 :group 'org-agenda-startup
919 :type 'boolean)
921 (defcustom org-agenda-start-with-follow-mode nil
922 "The initial value of follow mode in a newly created agenda window."
923 :group 'org-agenda-startup
924 :type 'boolean)
926 (defcustom org-agenda-follow-indirect nil
927 "Non-nil means `org-agenda-follow-mode' displays only the
928 current item's tree, in an indirect buffer."
929 :group 'org-agenda
930 :version "24.1"
931 :type 'boolean)
933 (defcustom org-agenda-show-outline-path t
934 "Non-nil means show outline path in echo area after line motion."
935 :group 'org-agenda-startup
936 :type 'boolean)
938 (defcustom org-agenda-start-with-entry-text-mode nil
939 "The initial value of entry-text-mode in a newly created agenda window."
940 :group 'org-agenda-startup
941 :type 'boolean)
943 (defcustom org-agenda-entry-text-maxlines 5
944 "Number of text lines to be added when `E' is pressed in the agenda.
946 Note that this variable only used during agenda display. Add add entry text
947 when exporting the agenda, configure the variable
948 `org-agenda-add-entry-ext-maxlines'."
949 :group 'org-agenda
950 :type 'integer)
952 (defcustom org-agenda-entry-text-exclude-regexps nil
953 "List of regular expressions to clean up entry text.
954 The complete matches of all regular expressions in this list will be
955 removed from entry text before it is shown in the agenda."
956 :group 'org-agenda
957 :type '(repeat (regexp)))
959 (defvar org-agenda-entry-text-cleanup-hook nil
960 "Hook that is run after basic cleanup of entry text to be shown in agenda.
961 This cleanup is done in a temporary buffer, so the function may inspect and
962 change the entire buffer.
963 Some default stuff like drawers and scheduling/deadline dates will already
964 have been removed when this is called, as will any matches for regular
965 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
967 (defvar org-agenda-include-inactive-timestamps nil
968 "Non-nil means include inactive time stamps in agenda and timeline.
969 Dynamically scoped.")
971 (defgroup org-agenda-windows nil
972 "Options concerning the windows used by the Agenda in Org Mode."
973 :tag "Org Agenda Windows"
974 :group 'org-agenda)
976 (defcustom org-agenda-window-setup 'reorganize-frame
977 "How the agenda buffer should be displayed.
978 Possible values for this option are:
980 current-window Show agenda in the current window, keeping all other windows.
981 other-window Use `switch-to-buffer-other-window' to display agenda.
982 reorganize-frame Show only two windows on the current frame, the current
983 window and the agenda.
984 other-frame Use `switch-to-buffer-other-frame' to display agenda.
985 Also, when exiting the agenda, kill that frame.
986 See also the variable `org-agenda-restore-windows-after-quit'."
987 :group 'org-agenda-windows
988 :type '(choice
989 (const current-window)
990 (const other-frame)
991 (const other-window)
992 (const reorganize-frame)))
994 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
995 "The min and max height of the agenda window as a fraction of frame height.
996 The value of the variable is a cons cell with two numbers between 0 and 1.
997 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
998 :group 'org-agenda-windows
999 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1001 (defcustom org-agenda-restore-windows-after-quit nil
1002 "Non-nil means restore window configuration upon exiting agenda.
1003 Before the window configuration is changed for displaying the agenda,
1004 the current status is recorded. When the agenda is exited with
1005 `q' or `x' and this option is set, the old state is restored. If
1006 `org-agenda-window-setup' is `other-frame', the value of this
1007 option will be ignored."
1008 :group 'org-agenda-windows
1009 :type 'boolean)
1011 (defcustom org-agenda-ndays nil
1012 "Number of days to include in overview display.
1013 Should be 1 or 7.
1014 Obsolete, see `org-agenda-span'."
1015 :group 'org-agenda-daily/weekly
1016 :type 'integer)
1018 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1020 (defcustom org-agenda-span 'week
1021 "Number of days to include in overview display.
1022 Can be day, week, month, year, or any number of days.
1023 Custom commands can set this variable in the options section."
1024 :group 'org-agenda-daily/weekly
1025 :type '(choice (const :tag "Day" day)
1026 (const :tag "Week" week)
1027 (const :tag "Month" month)
1028 (const :tag "Year" year)
1029 (integer :tag "Custom")))
1031 (defcustom org-agenda-start-on-weekday 1
1032 "Non-nil means start the overview always on the specified weekday.
1033 0 denotes Sunday, 1 denotes Monday etc.
1034 When nil, always start on the current day.
1035 Custom commands can set this variable in the options section."
1036 :group 'org-agenda-daily/weekly
1037 :type '(choice (const :tag "Today" nil)
1038 (integer :tag "Weekday No.")))
1040 (defcustom org-agenda-show-all-dates t
1041 "Non-nil means `org-agenda' shows every day in the selected range.
1042 When nil, only the days which actually have entries are shown."
1043 :group 'org-agenda-daily/weekly
1044 :type 'boolean)
1046 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1047 "Format string for displaying dates in the agenda.
1048 Used by the daily/weekly agenda and by the timeline. This should be
1049 a format string understood by `format-time-string', or a function returning
1050 the formatted date as a string. The function must take a single argument,
1051 a calendar-style date list like (month day year)."
1052 :group 'org-agenda-daily/weekly
1053 :type '(choice
1054 (string :tag "Format string")
1055 (function :tag "Function")))
1057 (defun org-agenda-format-date-aligned (date)
1058 "Format a date string for display in the daily/weekly agenda, or timeline.
1059 This function makes sure that dates are aligned for easy reading."
1060 (require 'cal-iso)
1061 (let* ((dayname (calendar-day-name date))
1062 (day (cadr date))
1063 (day-of-week (calendar-day-of-week date))
1064 (month (car date))
1065 (monthname (calendar-month-name month))
1066 (year (nth 2 date))
1067 (iso-week (org-days-to-iso-week
1068 (calendar-absolute-from-gregorian date)))
1069 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1070 (1- year))
1071 ((and (= month 12) (<= iso-week 1))
1072 (1+ year))
1073 (t year)))
1074 (weekstring (if (= day-of-week 1)
1075 (format " W%02d" iso-week)
1076 "")))
1077 (format "%-10s %2d %s %4d%s"
1078 dayname day monthname year weekstring)))
1080 (defcustom org-agenda-time-leading-zero nil
1081 "Non-nil means use leading zero for military times in agenda.
1082 For example, 9:30am would become 09:30 rather than 9:30."
1083 :group 'org-agenda-daily/weekly
1084 :version "24.1"
1085 :type 'boolean)
1087 (defcustom org-agenda-timegrid-use-ampm nil
1088 "When set, show AM/PM style timestamps on the timegrid."
1089 :group 'org-agenda
1090 :version "24.1"
1091 :type 'boolean)
1093 (defun org-agenda-time-of-day-to-ampm (time)
1094 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1095 (let* ((hour-number (string-to-number (substring time 0 -3)))
1096 (minute (substring time -2))
1097 (ampm "am"))
1098 (cond
1099 ((equal hour-number 12)
1100 (setq ampm "pm"))
1101 ((> hour-number 12)
1102 (setq ampm "pm")
1103 (setq hour-number (- hour-number 12))))
1104 (concat
1105 (if org-agenda-time-leading-zero
1106 (format "%02d" hour-number)
1107 (format "%02s" (number-to-string hour-number)))
1108 ":" minute ampm)))
1110 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1111 "Conditionally convert TIME to AM/PM format
1112 based on `org-agenda-timegrid-use-ampm'"
1113 (if org-agenda-timegrid-use-ampm
1114 (org-agenda-time-of-day-to-ampm time)
1115 time))
1117 (defcustom org-agenda-weekend-days '(6 0)
1118 "Which days are weekend?
1119 These days get the special face `org-agenda-date-weekend' in the agenda
1120 and timeline buffers."
1121 :group 'org-agenda-daily/weekly
1122 :type '(set :greedy t
1123 (const :tag "Monday" 1)
1124 (const :tag "Tuesday" 2)
1125 (const :tag "Wednesday" 3)
1126 (const :tag "Thursday" 4)
1127 (const :tag "Friday" 5)
1128 (const :tag "Saturday" 6)
1129 (const :tag "Sunday" 0)))
1131 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1132 "Non-nil means jump to today when moving a past date forward in time.
1133 When using S-right in the agenda to move a a date forward, and the date
1134 stamp currently points to the past, the first key press will move it
1135 to today. WHen nil, just move one day forward even if the date stays
1136 in the past."
1137 :group 'org-agenda-daily/weekly
1138 :version "24.1"
1139 :type 'boolean)
1141 (defcustom org-agenda-include-diary nil
1142 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1143 Custom commands can set this variable in the options section."
1144 :group 'org-agenda-daily/weekly
1145 :type 'boolean)
1147 (defcustom org-agenda-include-deadlines t
1148 "If non-nil, include entries within their deadline warning period.
1149 Custom commands can set this variable in the options section."
1150 :group 'org-agenda-daily/weekly
1151 :version "24.1"
1152 :type 'boolean)
1154 (defcustom org-agenda-repeating-timestamp-show-all t
1155 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1156 When set to a list of strings, only show occurrences of repeating
1157 stamps for these TODO keywords. When nil, only one occurrence is
1158 shown, either today or the nearest into the future."
1159 :group 'org-agenda-daily/weekly
1160 :type '(choice
1161 (const :tag "Show repeating stamps" t)
1162 (repeat :tag "Show repeating stamps for these TODO keywords"
1163 (string :tag "TODO Keyword"))
1164 (const :tag "Don't show repeating stamps" nil)))
1166 (defcustom org-scheduled-past-days 10000
1167 "No. of days to continue listing scheduled items that are not marked DONE.
1168 When an item is scheduled on a date, it shows up in the agenda on this
1169 day and will be listed until it is marked done for the number of days
1170 given here."
1171 :group 'org-agenda-daily/weekly
1172 :type 'integer)
1174 (defcustom org-agenda-log-mode-items '(closed clock)
1175 "List of items that should be shown in agenda log mode.
1176 This list may contain the following symbols:
1178 closed Show entries that have been closed on that day.
1179 clock Show entries that have received clocked time on that day.
1180 state Show all logged state changes.
1181 Note that instead of changing this variable, you can also press `C-u l' in
1182 the agenda to display all available LOG items temporarily."
1183 :group 'org-agenda-daily/weekly
1184 :type '(set :greedy t (const closed) (const clock) (const state)))
1186 (defcustom org-agenda-clock-consistency-checks
1187 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1188 :gap-ok-around ("4:00")
1189 :default-face ((:background "DarkRed") (:foreground "white"))
1190 :overlap-face nil :gap-face nil :no-end-time-face nil
1191 :long-face nil :short-face nil)
1192 "This is a property list, with the following keys:
1194 :max-duration Mark clocking chunks that are longer than this time.
1195 This is a time string like \"HH:MM\", or the number
1196 of minutes as an integer.
1198 :min-duration Mark clocking chunks that are shorter that this.
1199 This is a time string like \"HH:MM\", or the number
1200 of minutes as an integer.
1202 :max-gap Mark gaps between clocking chunks that are longer than
1203 this duration. A number of minutes, or a string
1204 like \"HH:MM\".
1206 :gap-ok-around List of times during the day which are usually not working
1207 times. When a gap is detected, but the gap contains any
1208 of these times, the gap is *not* reported. For example,
1209 if this is (\"4:00\" \"13:00\") then gaps that contain
1210 4:00 in the morning (i.e. the night) and 13:00
1211 (i.e. a typical lunch time) do not cause a warning.
1212 You should have at least one time during the night in this
1213 list, or otherwise the first task each morning will trigger
1214 a warning because it follows a long gap.
1216 Furthermore, the following properties can be used to define faces for
1217 issue display.
1219 :default-face the default face, if the specific face is undefined
1220 :overlap-face face for overlapping clocks
1221 :gap-face face for gaps between clocks
1222 :no-end-time-face face for incomplete clocks
1223 :long-face face for clock intervals that are too long
1224 :short-face face for clock intervals that are too short"
1225 :group 'org-agenda-daily/weekly
1226 :group 'org-clock
1227 :version "24.1"
1228 :type 'plist)
1230 (defcustom org-agenda-log-mode-add-notes t
1231 "Non-nil means add first line of notes to log entries in agenda views.
1232 If a log item like a state change or a clock entry is associated with
1233 notes, the first line of these notes will be added to the entry in the
1234 agenda display."
1235 :group 'org-agenda-daily/weekly
1236 :type 'boolean)
1238 (defcustom org-agenda-start-with-log-mode nil
1239 "The initial value of log-mode in a newly created agenda window.
1240 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1241 explanations on the possible values."
1242 :group 'org-agenda-startup
1243 :group 'org-agenda-daily/weekly
1244 :type '(choice (const :tag "Don't show log items" nil)
1245 (const :tag "Show only log items" 'only)
1246 (const :tag "Show all possible log items" 'clockcheck)
1247 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1248 (choice (const :tag "Show closed log items" 'closed)
1249 (const :tag "Show clocked log items" 'clock)
1250 (const :tag "Show all logged state changes" 'state)))))
1252 (defcustom org-agenda-start-with-clockreport-mode nil
1253 "The initial value of clockreport-mode in a newly created agenda window."
1254 :group 'org-agenda-startup
1255 :group 'org-agenda-daily/weekly
1256 :type 'boolean)
1258 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1259 "Property list with parameters for the clocktable in clockreport mode.
1260 This is the display mode that shows a clock table in the daily/weekly
1261 agenda, the properties for this dynamic block can be set here.
1262 The usual clocktable parameters are allowed here, but you cannot set
1263 the properties :name, :tstart, :tend, :block, and :scope - these will
1264 be overwritten to make sure the content accurately reflects the
1265 current display in the agenda."
1266 :group 'org-agenda-daily/weekly
1267 :type 'plist)
1269 (defcustom org-agenda-search-view-always-boolean nil
1270 "Non-nil means the search string is interpreted as individual parts.
1272 The search string for search view can either be interpreted as a phrase,
1273 or as a list of snippets that define a boolean search for a number of
1274 strings.
1276 When this is non-nil, the string will be split on whitespace, and each
1277 snippet will be searched individually, and all must match in order to
1278 select an entry. A snippet is then a single string of non-white
1279 characters, or a string in double quotes, or a regexp in {} braces.
1280 If a snippet is preceded by \"-\", the snippet must *not* match.
1281 \"+\" is syntactic sugar for positive selection. Each snippet may
1282 be found as a full word or a partial word, but see the variable
1283 `org-agenda-search-view-force-full-words'.
1285 When this is nil, search will look for the entire search phrase as one,
1286 with each space character matching any amount of whitespace, including
1287 line breaks.
1289 Even when this is nil, you can still switch to Boolean search dynamically
1290 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1291 is a regexp marked with braces like \"{abc}\", this will also switch to
1292 boolean search."
1293 :group 'org-agenda-search-view
1294 :version "24.1"
1295 :type 'boolean)
1297 (if (fboundp 'defvaralias)
1298 (defvaralias 'org-agenda-search-view-search-words-only
1299 'org-agenda-search-view-always-boolean))
1301 (defcustom org-agenda-search-view-force-full-words nil
1302 "Non-nil means, search words must be matches as complete words.
1303 When nil, they may also match part of a word."
1304 :group 'org-agenda-search-view
1305 :version "24.1"
1306 :type 'boolean)
1308 (defgroup org-agenda-time-grid nil
1309 "Options concerning the time grid in the Org-mode Agenda."
1310 :tag "Org Agenda Time Grid"
1311 :group 'org-agenda)
1313 (defcustom org-agenda-search-headline-for-time t
1314 "Non-nil means search headline for a time-of-day.
1315 If the headline contains a time-of-day in one format or another, it will
1316 be used to sort the entry into the time sequence of items for a day.
1317 Some people have time stamps in the headline that refer to the creation
1318 time or so, and then this produces an unwanted side effect. If this is
1319 the case for your, use this variable to turn off searching the headline
1320 for a time."
1321 :group 'org-agenda-time-grid
1322 :type 'boolean)
1324 (defcustom org-agenda-use-time-grid t
1325 "Non-nil means show a time grid in the agenda schedule.
1326 A time grid is a set of lines for specific times (like every two hours between
1327 8:00 and 20:00). The items scheduled for a day at specific times are
1328 sorted in between these lines.
1329 For details about when the grid will be shown, and what it will look like, see
1330 the variable `org-agenda-time-grid'."
1331 :group 'org-agenda-time-grid
1332 :type 'boolean)
1334 (defcustom org-agenda-time-grid
1335 '((daily today require-timed)
1336 "----------------"
1337 (800 1000 1200 1400 1600 1800 2000))
1339 "The settings for time grid for agenda display.
1340 This is a list of three items. The first item is again a list. It contains
1341 symbols specifying conditions when the grid should be displayed:
1343 daily if the agenda shows a single day
1344 weekly if the agenda shows an entire week
1345 today show grid on current date, independent of daily/weekly display
1346 require-timed show grid only if at least one item has a time specification
1348 The second item is a string which will be placed behind the grid time.
1350 The third item is a list of integers, indicating the times that should have
1351 a grid line."
1352 :group 'org-agenda-time-grid
1353 :type
1354 '(list
1355 (set :greedy t :tag "Grid Display Options"
1356 (const :tag "Show grid in single day agenda display" daily)
1357 (const :tag "Show grid in weekly agenda display" weekly)
1358 (const :tag "Always show grid for today" today)
1359 (const :tag "Show grid only if any timed entries are present"
1360 require-timed)
1361 (const :tag "Skip grid times already present in an entry"
1362 remove-match))
1363 (string :tag "Grid String")
1364 (repeat :tag "Grid Times" (integer :tag "Time"))))
1366 (defcustom org-agenda-show-current-time-in-grid t
1367 "Non-nil means show the current time in the time grid."
1368 :group 'org-agenda-time-grid
1369 :version "24.1"
1370 :type 'boolean)
1372 (defcustom org-agenda-current-time-string
1373 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1374 "The string for the current time marker in the agenda."
1375 :group 'org-agenda-time-grid
1376 :version "24.1"
1377 :type 'string)
1379 (defgroup org-agenda-sorting nil
1380 "Options concerning sorting in the Org-mode Agenda."
1381 :tag "Org Agenda Sorting"
1382 :group 'org-agenda)
1384 (defcustom org-agenda-sorting-strategy
1385 '((agenda habit-down time-up priority-down category-keep)
1386 (todo priority-down category-keep)
1387 (tags priority-down category-keep)
1388 (search category-keep))
1389 "Sorting structure for the agenda items of a single day.
1390 This is a list of symbols which will be used in sequence to determine
1391 if an entry should be listed before another entry. The following
1392 symbols are recognized:
1394 time-up Put entries with time-of-day indications first, early first
1395 time-down Put entries with time-of-day indications first, late first
1396 category-keep Keep the default order of categories, corresponding to the
1397 sequence in `org-agenda-files'.
1398 category-up Sort alphabetically by category, A-Z.
1399 category-down Sort alphabetically by category, Z-A.
1400 tag-up Sort alphabetically by last tag, A-Z.
1401 tag-down Sort alphabetically by last tag, Z-A.
1402 priority-up Sort numerically by priority, high priority last.
1403 priority-down Sort numerically by priority, high priority first.
1404 todo-state-up Sort by todo state, tasks that are done last.
1405 todo-state-down Sort by todo state, tasks that are done first.
1406 effort-up Sort numerically by estimated effort, high effort last.
1407 effort-down Sort numerically by estimated effort, high effort first.
1408 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1409 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1410 habit-up Put entries that are habits first
1411 habit-down Put entries that are habits last
1412 alpha-up Sort headlines alphabetically
1413 alpha-down Sort headlines alphabetically, reversed
1415 The different possibilities will be tried in sequence, and testing stops
1416 if one comparison returns a \"not-equal\". For example, the default
1417 '(time-up category-keep priority-down)
1418 means: Pull out all entries having a specified time of day and sort them,
1419 in order to make a time schedule for the current day the first thing in the
1420 agenda listing for the day. Of the entries without a time indication, keep
1421 the grouped in categories, don't sort the categories, but keep them in
1422 the sequence given in `org-agenda-files'. Within each category sort by
1423 priority.
1425 Leaving out `category-keep' would mean that items will be sorted across
1426 categories by priority.
1428 Instead of a single list, this can also be a set of list for specific
1429 contents, with a context symbol in the car of the list, any of
1430 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1432 Custom commands can bind this variable in the options section."
1433 :group 'org-agenda-sorting
1434 :type `(choice
1435 (repeat :tag "General" ,org-sorting-choice)
1436 (list :tag "Individually"
1437 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1438 (repeat ,org-sorting-choice))
1439 (cons (const :tag "Strategy for TODO lists" todo)
1440 (repeat ,org-sorting-choice))
1441 (cons (const :tag "Strategy for Tags matches" tags)
1442 (repeat ,org-sorting-choice))
1443 (cons (const :tag "Strategy for search matches" search)
1444 (repeat ,org-sorting-choice)))))
1446 (defcustom org-agenda-cmp-user-defined nil
1447 "A function to define the comparison `user-defined'.
1448 This function must receive two arguments, agenda entry a and b.
1449 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1450 the user comparison, return nil.
1451 When this is defined, you can make `user-defined-up' and `user-defined-down'
1452 part of an agenda sorting strategy."
1453 :group 'org-agenda-sorting
1454 :type 'symbol)
1456 (defcustom org-sort-agenda-notime-is-late t
1457 "Non-nil means items without time are considered late.
1458 This is only relevant for sorting. When t, items which have no explicit
1459 time like 15:30 will be considered as 99:01, i.e. later than any items which
1460 do have a time. When nil, the default time is before 0:00. You can use this
1461 option to decide if the schedule for today should come before or after timeless
1462 agenda entries."
1463 :group 'org-agenda-sorting
1464 :type 'boolean)
1466 (defcustom org-sort-agenda-noeffort-is-high t
1467 "Non-nil means items without effort estimate are sorted as high effort.
1468 This also applies when filtering an agenda view with respect to the
1469 < or > effort operator. Then, tasks with no effort defined will be treated
1470 as tasks with high effort.
1471 When nil, such items are sorted as 0 minutes effort."
1472 :group 'org-agenda-sorting
1473 :type 'boolean)
1475 (defgroup org-agenda-line-format nil
1476 "Options concerning the entry prefix in the Org-mode agenda display."
1477 :tag "Org Agenda Line Format"
1478 :group 'org-agenda)
1480 (defcustom org-agenda-prefix-format
1481 '((agenda . " %i %-12:c%?-12t% s")
1482 (timeline . " % s")
1483 (todo . " %i %-12:c")
1484 (tags . " %i %-12:c")
1485 (search . " %i %-12:c"))
1486 "Format specifications for the prefix of items in the agenda views.
1487 An alist with five entries, each for the different agenda types. The
1488 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1489 The values are format strings.
1491 This format works similar to a printf format, with the following meaning:
1493 %c the category of the item, \"Diary\" for entries from the diary,
1494 or as given by the CATEGORY keyword or derived from the file name
1495 %e the effort required by the item
1496 %i the icon category of the item, see `org-agenda-category-icon-alist'
1497 %T the last tag of the item (ignore inherited tags, which come first)
1498 %t the HH:MM time-of-day specification if one applies to the entry
1499 %s Scheduling/Deadline information, a short string
1500 %(expression) Eval EXPRESSION and replace the control string
1501 by the result
1503 All specifiers work basically like the standard `%s' of printf, but may
1504 contain two additional characters: a question mark just after the `%'
1505 and a whitespace/punctuation character just before the final letter.
1507 If the first character after `%' is a question mark, the entire field
1508 will only be included if the corresponding value applies to the current
1509 entry. This is useful for fields which should have fixed width when
1510 present, but zero width when absent. For example, \"%?-12t\" will
1511 result in a 12 character time field if a time of the day is specified,
1512 but will completely disappear in entries which do not contain a time.
1514 If there is punctuation or whitespace character just before the final
1515 format letter, this character will be appended to the field value if
1516 the value is not empty. For example, the format \"%-12:c\" leads to
1517 \"Diary: \" if the category is \"Diary\". If the category were be
1518 empty, no additional colon would be inserted.
1520 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1521 which means:
1523 - Indent the line with two space characters
1524 - Give the category a 12 chars wide field, padded with whitespace on
1525 the right (because of `-'). Append a colon if there is a category
1526 (because of `:').
1527 - If there is a time-of-day, put it into a 12 chars wide field. If no
1528 time, don't put in an empty field, just skip it (because of '?').
1529 - Finally, put the scheduling information.
1531 See also the variables `org-agenda-remove-times-when-in-prefix' and
1532 `org-agenda-remove-tags'.
1534 Custom commands can set this variable in the options section."
1535 :type '(choice
1536 (string :tag "General format")
1537 (list :greedy t :tag "View dependent"
1538 (cons (const agenda) (string :tag "Format"))
1539 (cons (const timeline) (string :tag "Format"))
1540 (cons (const todo) (string :tag "Format"))
1541 (cons (const tags) (string :tag "Format"))
1542 (cons (const search) (string :tag "Format"))))
1543 :group 'org-agenda-line-format)
1545 (defvar org-prefix-format-compiled nil
1546 "The compiled prefix format and associated variables.
1547 This is a list where first element is a list of variable bindings, and second
1548 element is the compiled format expression. See the variable
1549 `org-agenda-prefix-format'.")
1551 (defcustom org-agenda-todo-keyword-format "%-1s"
1552 "Format for the TODO keyword in agenda lines.
1553 Set this to something like \"%-12s\" if you want all TODO keywords
1554 to occupy a fixed space in the agenda display."
1555 :group 'org-agenda-line-format
1556 :type 'string)
1558 (defcustom org-agenda-diary-sexp-prefix nil
1559 "A regexp that matches part of a diary sexp entry
1560 which should be treated as scheduling/deadline information in
1561 `org-agenda'.
1563 For example, you can use this to extract the `diary-remind-message' from
1564 `diary-remind' entries."
1565 :group 'org-agenda-line-format
1566 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1568 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1569 "Text preceding timerange entries in the agenda view.
1570 This is a list with two strings. The first applies when the range
1571 is entirely on one day. The second applies if the range spans several days.
1572 The strings may have two \"%d\" format specifiers which will be filled
1573 with the sequence number of the days, and the total number of days in the
1574 range, respectively."
1575 :group 'org-agenda-line-format
1576 :type '(list
1577 (string :tag "Deadline today ")
1578 (choice :tag "Deadline relative"
1579 (string :tag "Format string")
1580 (function))))
1582 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1583 "Text preceding scheduled items in the agenda view.
1584 This is a list with two strings. The first applies when the item is
1585 scheduled on the current day. The second applies when it has been scheduled
1586 previously, it may contain a %d indicating that this is the nth time that
1587 this item is scheduled, due to automatic rescheduling of unfinished items
1588 for the following day. So this number is one larger than the number of days
1589 that passed since this item was scheduled first."
1590 :group 'org-agenda-line-format
1591 :type '(list
1592 (string :tag "Scheduled today ")
1593 (string :tag "Scheduled previously")))
1595 (defcustom org-agenda-inactive-leader "["
1596 "Text preceding item pulled into the agenda by inactive time stamps.
1597 These entries are added to the agenda when pressing \"[\"."
1598 :group 'org-agenda-line-format
1599 :version "24.1"
1600 :type '(list
1601 (string :tag "Scheduled today ")
1602 (string :tag "Scheduled previously")))
1604 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1605 "Text preceding deadline items in the agenda view.
1606 This is a list with two strings. The first applies when the item has its
1607 deadline on the current day. The second applies when it is in the past or
1608 in the future, it may contain %d to capture how many days away the deadline
1609 is (was)."
1610 :group 'org-agenda-line-format
1611 :type '(list
1612 (string :tag "Deadline today ")
1613 (choice :tag "Deadline relative"
1614 (string :tag "Format string")
1615 (function))))
1617 (defcustom org-agenda-remove-times-when-in-prefix t
1618 "Non-nil means remove duplicate time specifications in agenda items.
1619 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1620 time-of-day specification in a headline or diary entry is extracted and
1621 placed into the prefix. If this option is non-nil, the original specification
1622 \(a timestamp or -range, or just a plain time(range) specification like
1623 11:30-4pm) will be removed for agenda display. This makes the agenda less
1624 cluttered.
1625 The option can be t or nil. It may also be the symbol `beg', indicating
1626 that the time should only be removed when it is located at the beginning of
1627 the headline/diary entry."
1628 :group 'org-agenda-line-format
1629 :type '(choice
1630 (const :tag "Always" t)
1631 (const :tag "Never" nil)
1632 (const :tag "When at beginning of entry" beg)))
1634 (defcustom org-agenda-remove-timeranges-from-blocks nil
1635 "Non-nil means remove time ranges specifications in agenda
1636 items that span on several days."
1637 :group 'org-agenda-line-format
1638 :version "24.1"
1639 :type 'boolean)
1641 (defcustom org-agenda-default-appointment-duration nil
1642 "Default duration for appointments that only have a starting time.
1643 When nil, no duration is specified in such cases.
1644 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1645 :group 'org-agenda-line-format
1646 :type '(choice
1647 (integer :tag "Minutes")
1648 (const :tag "No default duration")))
1650 (defcustom org-agenda-show-inherited-tags t
1651 "Non-nil means show inherited tags in each agenda line."
1652 :group 'org-agenda-line-format
1653 :type 'boolean)
1655 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1656 "List of agenda view types where to use tag inheritance.
1658 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1659 controlled by `org-use-tag-inheritance'. In other agenda types,
1660 `org-use-tag-inheritance' is not used when selecting the agenda
1661 entries, but you may want the agenda to use the inherited tags
1662 anyway, e.g. for later tag filtering.
1664 The default value reset tags in every agenda type. Setting this
1665 option to nil will speed up non-tags agenda view a lot.
1667 Allowed value are 'todo, 'search, 'timeline and 'agenda."
1668 :version "24.3"
1669 :group 'org-agenda
1670 :type '(repeat (symbol :tag "Agenda type")))
1672 (defcustom org-agenda-hide-tags-regexp nil
1673 "Regular expression used to filter away specific tags in agenda views.
1674 This means that these tags will be present, but not be shown in the agenda
1675 line. Secondary filtering will still work on the hidden tags.
1676 Nil means don't hide any tags."
1677 :group 'org-agenda-line-format
1678 :type '(choice
1679 (const :tag "Hide none" nil)
1680 (string :tag "Regexp ")))
1682 (defcustom org-agenda-remove-tags nil
1683 "Non-nil means remove the tags from the headline copy in the agenda.
1684 When this is the symbol `prefix', only remove tags when
1685 `org-agenda-prefix-format' contains a `%T' specifier."
1686 :group 'org-agenda-line-format
1687 :type '(choice
1688 (const :tag "Always" t)
1689 (const :tag "Never" nil)
1690 (const :tag "When prefix format contains %T" prefix)))
1692 (if (fboundp 'defvaralias)
1693 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1694 'org-agenda-remove-tags))
1696 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1697 "Shift tags in agenda items to this column.
1698 If this number is positive, it specifies the column. If it is negative,
1699 it means that the tags should be flushright to that column. For example,
1700 -80 works well for a normal 80 character screen."
1701 :group 'org-agenda-line-format
1702 :type 'integer)
1704 (if (fboundp 'defvaralias)
1705 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1707 (defcustom org-agenda-fontify-priorities 'cookies
1708 "Non-nil means highlight low and high priorities in agenda.
1709 When t, the highest priority entries are bold, lowest priority italic.
1710 However, settings in `org-priority-faces' will overrule these faces.
1711 When this variable is the symbol `cookies', only fontify the
1712 cookies, not the entire task.
1713 This may also be an association list of priority faces, whose
1714 keys are the character values of `org-highest-priority',
1715 `org-default-priority', and `org-lowest-priority' (the default values
1716 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1717 color as a string, or a list like `(:background \"Red\")'.
1718 If it is a color, the variable `org-faces-easy-properties'
1719 determines if it is a foreground or a background color."
1720 :group 'org-agenda-line-format
1721 :type '(choice
1722 (const :tag "Never" nil)
1723 (const :tag "Defaults" t)
1724 (const :tag "Cookies only" cookies)
1725 (repeat :tag "Specify"
1726 (list (character :tag "Priority" :value ?A)
1727 (choice :tag "Face "
1728 (string :tag "Color")
1729 (sexp :tag "Face"))))))
1731 (defcustom org-agenda-day-face-function nil
1732 "Function called to determine what face should be used to display a day.
1733 The only argument passed to that function is the day. It should
1734 returns a face, or nil if does not want to specify a face and let
1735 the normal rules apply."
1736 :group 'org-agenda-line-format
1737 :version "24.1"
1738 :type 'function)
1740 (defcustom org-agenda-category-icon-alist nil
1741 "Alist of category icon to be displayed in agenda views.
1743 Each entry should have the following format:
1745 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1747 Where CATEGORY-REGEXP is a regexp matching the categories where
1748 the icon should be displayed.
1749 FILE-OR-DATA either a file path or a string containing image data.
1751 The other fields can be omitted safely if not needed:
1752 TYPE indicates the image type.
1753 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1754 image data.
1755 PROPS are additional image attributes to assign to the image,
1756 like, e.g. `:ascent center'.
1758 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1760 If you want to set the display properties yourself, just put a
1761 list as second element:
1763 (CATEGORY-REGEXP (MY PROPERTY LIST))
1765 For example, to display a 16px horizontal space for Emacs
1766 category, you can use:
1768 (\"Emacs\" '(space . (:width (16))))"
1769 :group 'org-agenda-line-format
1770 :version "24.1"
1771 :type '(alist :key-type (string :tag "Regexp matching category")
1772 :value-type (choice (list :tag "Icon"
1773 (string :tag "File or data")
1774 (symbol :tag "Type")
1775 (boolean :tag "Data?")
1776 (repeat :tag "Extra image properties" :inline t symbol))
1777 (list :tag "Display properties" sexp))))
1779 (defgroup org-agenda-column-view nil
1780 "Options concerning column view in the agenda."
1781 :tag "Org Agenda Column View"
1782 :group 'org-agenda)
1784 (defcustom org-agenda-columns-show-summaries t
1785 "Non-nil means show summaries for columns displayed in the agenda view."
1786 :group 'org-agenda-column-view
1787 :type 'boolean)
1789 (defcustom org-agenda-columns-compute-summary-properties t
1790 "Non-nil means recompute all summary properties before column view.
1791 When column view in the agenda is listing properties that have a summary
1792 operator, it can go to all relevant buffers and recompute the summaries
1793 there. This can mean overhead for the agenda column view, but is necessary
1794 to have thing up to date.
1795 As a special case, a CLOCKSUM property also makes sure that the clock
1796 computations are current."
1797 :group 'org-agenda-column-view
1798 :type 'boolean)
1800 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1801 "Non-nil means the duration of an appointment will add to day effort.
1802 The property to which appointment durations will be added is the one given
1803 in the option `org-effort-property'. If an appointment does not have
1804 an end time, `org-agenda-default-appointment-duration' will be used. If that
1805 is not set, an appointment without end time will not contribute to the time
1806 estimate."
1807 :group 'org-agenda-column-view
1808 :type 'boolean)
1810 (defcustom org-agenda-auto-exclude-function nil
1811 "A function called with a tag to decide if it is filtered on '/ RET'.
1812 The sole argument to the function, which is called once for each
1813 possible tag, is a string giving the name of the tag. The
1814 function should return either nil if the tag should be included
1815 as normal, or \"-<TAG>\" to exclude the tag.
1816 Note that for the purpose of tag filtering, only the lower-case version of
1817 all tags will be considered, so that this function will only ever see
1818 the lower-case version of all tags."
1819 :group 'org-agenda
1820 :type 'function)
1822 (defcustom org-agenda-bulk-custom-functions nil
1823 "Alist of characters and custom functions for bulk actions.
1824 For example, this value makes those two functions available:
1826 '((?R set-category)
1827 (?C bulk-cut))
1829 With selected entries in an agenda buffer, `B R' will call
1830 the custom function `set-category' on the selected entries.
1831 Note that functions in this alist don't need to be quoted."
1832 :type 'alist
1833 :version "24.1"
1834 :group 'org-agenda)
1836 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1837 "Execute BODY with point at location given by `org-hd-marker' property.
1838 If STRING is non-nil, the text property will be fetched from position 0
1839 in that string. If STRING is nil, it will be fetched from the beginning
1840 of the current line."
1841 (org-with-gensyms (marker)
1842 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1843 'org-hd-marker ,string)))
1844 (with-current-buffer (marker-buffer ,marker)
1845 (save-excursion
1846 (goto-char ,marker)
1847 ,@body)))))
1848 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1850 (defun org-add-agenda-custom-command (entry)
1851 "Replace or add a command in `org-agenda-custom-commands'.
1852 This is mostly for hacking and trying a new command - once the command
1853 works you probably want to add it to `org-agenda-custom-commands' for good."
1854 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1855 (if ass
1856 (setcdr ass (cdr entry))
1857 (push entry org-agenda-custom-commands))))
1859 ;;; Define the org-agenda-mode
1861 (defvar org-agenda-mode-map (make-sparse-keymap)
1862 "Keymap for `org-agenda-mode'.")
1863 (if (fboundp 'defvaralias)
1864 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1866 (defvar org-agenda-menu) ; defined later in this file.
1867 (defvar org-agenda-restrict nil) ; defined later in this file.
1868 (defvar org-agenda-follow-mode nil)
1869 (defvar org-agenda-entry-text-mode nil)
1870 (defvar org-agenda-clockreport-mode nil)
1871 (defvar org-agenda-show-log nil)
1872 (defvar org-agenda-redo-command nil)
1873 (defvar org-agenda-query-string nil)
1874 (defvar org-agenda-mode-hook nil
1875 "Hook run after `org-agenda-mode' is turned on.
1876 The buffer is still writable when this hook is called.")
1877 (defvar org-agenda-type nil)
1878 (defvar org-agenda-force-single-file nil)
1879 (defvar org-agenda-bulk-marked-entries nil
1880 "List of markers that refer to marked entries in the agenda.")
1882 ;;; Multiple agenda buffers support
1884 (defcustom org-agenda-sticky nil
1885 "Non-nil means agenda q key will bury agenda buffers.
1886 Agenda commands will then show existing buffer instead of generating new ones.
1887 When nil, `q' will kill the single agenda buffer."
1888 :group 'org-agenda
1889 :version "24.3"
1890 :type 'boolean)
1893 ;;;###autoload
1894 (defun org-toggle-sticky-agenda (&optional arg)
1895 "Toggle `org-agenda-sticky'."
1896 (interactive "P")
1897 (let ((new-value (if arg
1898 (> (prefix-numeric-value arg) 0)
1899 (not org-agenda-sticky))))
1900 (if (equal new-value org-agenda-sticky)
1901 (and (org-called-interactively-p 'interactive)
1902 (message "Sticky agenda was already %s"
1903 (if org-agenda-sticky "enabled" "disabled")))
1904 (setq org-agenda-sticky new-value)
1905 (org-agenda-kill-all-agenda-buffers)
1906 (and (org-called-interactively-p 'interactive)
1907 (message "Sticky agenda was %s"
1908 (if org-agenda-sticky "enabled" "disabled"))))))
1910 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1911 Toggle `org-agenda-sticky'.
1913 \(fn &optional ARG)" t nil)
1915 (defvar org-agenda-buffer nil
1916 "Agenda buffer currently being generated.")
1918 (defvar org-agenda-last-prefix-arg nil)
1919 (defvar org-agenda-this-buffer-name nil)
1920 (defvar org-agenda-doing-sticky-redo nil)
1921 (defvar org-agenda-this-buffer-is-sticky nil)
1923 (defconst org-agenda-local-vars
1924 '(org-agenda-this-buffer-name
1925 org-agenda-undo-list
1926 org-agenda-pending-undo-list
1927 org-agenda-follow-mode
1928 org-agenda-entry-text-mode
1929 org-agenda-clockreport-mode
1930 org-agenda-show-log
1931 org-agenda-redo-command
1932 org-agenda-query-string
1933 org-agenda-type
1934 org-agenda-bulk-marked-entries
1935 org-agenda-undo-has-started-in
1936 org-agenda-info
1937 org-agenda-tag-filter-overlays
1938 org-agenda-cat-filter-overlays
1939 org-agenda-pre-window-conf
1940 org-agenda-columns-active
1941 org-agenda-tag-filter
1942 org-agenda-category-filter
1943 org-agenda-markers
1944 org-agenda-last-search-view-search-was-boolean
1945 org-agenda-filtered-by-category
1946 org-agenda-filter-form
1947 org-agenda-show-window
1948 org-agenda-cycle-counter
1949 org-agenda-last-prefix-arg)
1950 "Variables that must be local in agenda buffers to allow multiple buffers.")
1952 (defun org-agenda-mode ()
1953 "Mode for time-sorted view on action items in Org-mode files.
1955 The following commands are available:
1957 \\{org-agenda-mode-map}"
1958 (interactive)
1959 (cond (org-agenda-doing-sticky-redo
1960 ;; Refreshing sticky agenda-buffer
1962 ;; Preserve the value of `org-agenda-local-vars' variables,
1963 ;; while letting `kill-all-local-variables' kill the rest
1964 (let ((save (buffer-local-variables)))
1965 (kill-all-local-variables)
1966 (mapc 'make-local-variable org-agenda-local-vars)
1967 (dolist (elem save)
1968 (let ((var (car elem))
1969 (val (cdr elem)))
1970 (when (and val
1971 (member var org-agenda-local-vars))
1972 (set var val)))))
1973 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1974 (org-agenda-sticky
1975 ;; Creating a sticky Agenda buffer for the first time
1976 (kill-all-local-variables)
1977 (mapc 'make-local-variable org-agenda-local-vars)
1978 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1980 ;; Creating a non-sticky agenda buffer
1981 (kill-all-local-variables)
1982 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1983 (setq org-agenda-undo-list nil
1984 org-agenda-pending-undo-list nil
1985 org-agenda-bulk-marked-entries nil)
1986 (setq major-mode 'org-agenda-mode)
1987 ;; Keep global-font-lock-mode from turning on font-lock-mode
1988 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1989 (setq mode-name "Org-Agenda")
1990 (use-local-map org-agenda-mode-map)
1991 (easy-menu-add org-agenda-menu)
1992 (if org-startup-truncated (setq truncate-lines t))
1993 (org-set-local 'line-move-visual nil)
1994 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
1995 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1996 ;; Make sure properties are removed when copying text
1997 (make-local-variable 'filter-buffer-substring-functions)
1998 (add-hook 'filter-buffer-substring-functions
1999 (lambda (fun start end delete)
2000 (substring-no-properties (funcall fun start end delete))))
2001 (unless org-agenda-keep-modes
2002 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2003 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2004 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2005 org-agenda-show-log org-agenda-start-with-log-mode))
2007 (easy-menu-change
2008 '("Agenda") "Agenda Files"
2009 (append
2010 (list
2011 (vector
2012 (if (get 'org-agenda-files 'org-restrict)
2013 "Restricted to single file"
2014 "Edit File List")
2015 '(org-edit-agenda-file-list)
2016 (not (get 'org-agenda-files 'org-restrict)))
2017 "--")
2018 (mapcar 'org-file-menu-entry (org-agenda-files))))
2019 (org-agenda-set-mode-name)
2020 (apply
2021 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2022 (list 'org-agenda-mode-hook)))
2024 (substitute-key-definition 'undo 'org-agenda-undo
2025 org-agenda-mode-map global-map)
2026 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2027 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2028 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2029 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2030 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2031 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2032 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2033 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2034 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2035 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2036 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2037 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2038 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2039 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2040 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2041 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2042 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2043 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2044 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2045 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2046 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2047 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2048 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2049 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2050 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2051 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2052 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2053 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2054 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2055 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2056 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2057 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2058 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2059 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2060 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2061 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2062 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2063 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2064 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2065 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2066 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2067 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2068 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2069 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2070 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2071 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2073 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2074 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2075 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2076 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2077 (while l (org-defkey org-agenda-mode-map
2078 (int-to-string (pop l)) 'digit-argument)))
2080 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2081 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2082 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2083 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2084 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2085 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2086 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2087 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2088 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2089 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2090 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2091 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2092 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2093 'org-clock-modify-effort-estimate)
2094 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2095 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2096 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2097 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2098 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2099 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2100 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2101 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2102 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2103 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2104 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2105 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2106 (substitute-key-definition 'next-line 'org-agenda-next-line
2107 org-agenda-mode-map global-map)
2108 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2109 org-agenda-mode-map global-map)
2110 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2111 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2112 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2113 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2114 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2115 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2116 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2117 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2118 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2119 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2120 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2121 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2122 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2123 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2124 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2125 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2126 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2127 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2128 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2129 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2130 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2131 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2132 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2133 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2134 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2135 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2136 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2137 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2138 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2139 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2141 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2142 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2143 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2144 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2145 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2146 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2147 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2148 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2149 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2150 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2151 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2152 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2154 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2155 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2156 (when org-agenda-mouse-1-follows-link
2157 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2158 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2159 '("Agenda"
2160 ("Agenda Files")
2161 "--"
2162 ("Agenda Dates"
2163 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2164 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2165 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2166 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2167 "--"
2168 ("View"
2169 ["Day View" org-agenda-day-view
2170 :active (org-agenda-check-type nil 'agenda)
2171 :style radio :selected (eq org-agenda-current-span 'day)
2172 :keys "v d (or just d)"]
2173 ["Week View" org-agenda-week-view
2174 :active (org-agenda-check-type nil 'agenda)
2175 :style radio :selected (eq org-agenda-current-span 'week)
2176 :keys "v w (or just w)"]
2177 ["Month View" org-agenda-month-view
2178 :active (org-agenda-check-type nil 'agenda)
2179 :style radio :selected (eq org-agenda-current-span 'month)
2180 :keys "v m"]
2181 ["Year View" org-agenda-year-view
2182 :active (org-agenda-check-type nil 'agenda)
2183 :style radio :selected (eq org-agenda-current-span 'year)
2184 :keys "v y"]
2185 "--"
2186 ["Include Diary" org-agenda-toggle-diary
2187 :style toggle :selected org-agenda-include-diary
2188 :active (org-agenda-check-type nil 'agenda)]
2189 ["Include Deadlines" org-agenda-toggle-deadlines
2190 :style toggle :selected org-agenda-include-deadlines
2191 :active (org-agenda-check-type nil 'agenda)]
2192 ["Use Time Grid" org-agenda-toggle-time-grid
2193 :style toggle :selected org-agenda-use-time-grid
2194 :active (org-agenda-check-type nil 'agenda)]
2195 "--"
2196 ["Show clock report" org-agenda-clockreport-mode
2197 :style toggle :selected org-agenda-clockreport-mode
2198 :active (org-agenda-check-type nil 'agenda)]
2199 ["Show some entry text" org-agenda-entry-text-mode
2200 :style toggle :selected org-agenda-entry-text-mode
2201 :active t]
2202 "--"
2203 ["Show Logbook entries" org-agenda-log-mode
2204 :style toggle :selected org-agenda-show-log
2205 :active (org-agenda-check-type nil 'agenda 'timeline)
2206 :keys "v l (or just l)"]
2207 ["Include archived trees" org-agenda-archives-mode
2208 :style toggle :selected org-agenda-archives-mode :active t
2209 :keys "v a"]
2210 ["Include archive files" (org-agenda-archives-mode t)
2211 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2212 :keys "v A"]
2213 "--"
2214 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2215 ["Write view to file" org-agenda-write t]
2216 ["Rebuild buffer" org-agenda-redo t]
2217 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2218 "--"
2219 ["Show original entry" org-agenda-show t]
2220 ["Go To (other window)" org-agenda-goto t]
2221 ["Go To (this window)" org-agenda-switch-to t]
2222 ["Capture with cursor date" org-agenda-capture t]
2223 ["Follow Mode" org-agenda-follow-mode
2224 :style toggle :selected org-agenda-follow-mode :active t]
2225 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2226 "--"
2227 ("TODO"
2228 ["Cycle TODO" org-agenda-todo t]
2229 ["Next TODO set" org-agenda-todo-nextset t]
2230 ["Previous TODO set" org-agenda-todo-previousset t]
2231 ["Add note" org-agenda-add-note t])
2232 ("Archive/Refile/Delete"
2233 ["Archive default" org-agenda-archive-default t]
2234 ["Archive default" org-agenda-archive-default-with-confirmation t]
2235 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2236 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2237 ["Archive subtree" org-agenda-archive t]
2238 "--"
2239 ["Refile" org-agenda-refile t]
2240 "--"
2241 ["Delete subtree" org-agenda-kill t])
2242 ("Bulk action"
2243 ["Mark entry" org-agenda-bulk-mark t]
2244 ["Mark all" org-agenda-bulk-mark-all t]
2245 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2246 ["Unmark entry" org-agenda-bulk-unmark t]
2247 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2248 ["Act on all marked" org-agenda-bulk-action t]
2249 "--"
2250 ("Tags and Properties"
2251 ["Show all Tags" org-agenda-show-tags t]
2252 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2253 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2254 "--"
2255 ["Column View" org-columns t])
2256 ("Deadline/Schedule"
2257 ["Schedule" org-agenda-schedule t]
2258 ["Set Deadline" org-agenda-deadline t]
2259 "--"
2260 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2261 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2262 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2263 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2264 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2265 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2266 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2267 ("Clock and Effort"
2268 ["Clock in" org-agenda-clock-in t]
2269 ["Clock out" org-agenda-clock-out t]
2270 ["Clock cancel" org-agenda-clock-cancel t]
2271 ["Goto running clock" org-clock-goto t]
2272 "--"
2273 ["Set Effort" org-agenda-set-effort t]
2274 ["Change clocked effort" org-clock-modify-effort-estimate
2275 (org-clock-is-active)])
2276 ("Priority"
2277 ["Set Priority" org-agenda-priority t]
2278 ["Increase Priority" org-agenda-priority-up t]
2279 ["Decrease Priority" org-agenda-priority-down t]
2280 ["Show Priority" org-show-priority t])
2281 ("Calendar/Diary"
2282 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2283 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2284 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2285 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2286 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2287 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2288 "--"
2289 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2290 "--"
2291 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2292 "--"
2293 ("MobileOrg"
2294 ["Push Files and Views" org-mobile-push t]
2295 ["Get Captured and Flagged" org-mobile-pull t]
2296 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2297 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2298 "--"
2299 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2300 "--"
2301 ["Quit" org-agenda-quit t]
2302 ["Exit and Release Buffers" org-agenda-exit t]
2305 ;;; Agenda undo
2307 (defvar org-agenda-allow-remote-undo t
2308 "Non-nil means allow remote undo from the agenda buffer.")
2309 (defvar org-agenda-undo-has-started-in nil
2310 "Buffers that have already seen `undo-start' in the current undo sequence.")
2312 (defun org-agenda-undo ()
2313 "Undo a remote editing step in the agenda.
2314 This undoes changes both in the agenda buffer and in the remote buffer
2315 that have been changed along."
2316 (interactive)
2317 (or org-agenda-allow-remote-undo
2318 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2319 (if (not (eq this-command last-command))
2320 (setq org-agenda-undo-has-started-in nil
2321 org-agenda-pending-undo-list org-agenda-undo-list))
2322 (if (not org-agenda-pending-undo-list)
2323 (error "No further undo information"))
2324 (let* ((entry (pop org-agenda-pending-undo-list))
2325 buf line cmd rembuf)
2326 (setq cmd (pop entry) line (pop entry))
2327 (setq rembuf (nth 2 entry))
2328 (org-with-remote-undo rembuf
2329 (while (bufferp (setq buf (pop entry)))
2330 (if (pop entry)
2331 (with-current-buffer buf
2332 (let ((last-undo-buffer buf)
2333 (inhibit-read-only t))
2334 (unless (memq buf org-agenda-undo-has-started-in)
2335 (push buf org-agenda-undo-has-started-in)
2336 (make-local-variable 'pending-undo-list)
2337 (undo-start))
2338 (while (and pending-undo-list
2339 (listp pending-undo-list)
2340 (not (car pending-undo-list)))
2341 (pop pending-undo-list))
2342 (undo-more 1))))))
2343 (org-goto-line line)
2344 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2346 (defun org-verify-change-for-undo (l1 l2)
2347 "Verify that a real change occurred between the undo lists L1 and L2."
2348 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2349 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2350 (not (eq l1 l2)))
2352 ;;; Agenda dispatch
2354 (defvar org-agenda-restrict-begin (make-marker))
2355 (defvar org-agenda-restrict-end (make-marker))
2356 (defvar org-agenda-last-dispatch-buffer nil)
2357 (defvar org-agenda-overriding-restriction nil)
2359 (defcustom org-agenda-custom-commands-contexts nil
2360 "Alist of custom agenda keys and contextual rules.
2362 For example, if you have a custom agenda command \"p\" and you
2363 want this command to be accessible only from plain text files,
2364 use this:
2366 '((\"p\" (in-file . \"\\.txt\")))
2368 Here are the available contexts definitions:
2370 in-file: command displayed only in matching files
2371 in-mode: command displayed only in matching modes
2372 not-in-file: command not displayed in matching files
2373 not-in-mode: command not displayed in matching modes
2374 [function]: a custom function taking no argument
2376 If you define several checks, the agenda command will be
2377 accessible if there is at least one valid check.
2379 You can also bind a key to another agenda custom command
2380 depending on contextual rules.
2382 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2384 Here it means: in .txt files, use \"p\" as the key for the
2385 agenda command otherwise associated with \"q\". (The command
2386 originally associated with \"q\" is not displayed to avoid
2387 duplicates.)"
2388 :version "24.3"
2389 :group 'org-agenda-custom-commands
2390 :type '(repeat (list :tag "Rule"
2391 (string :tag " Agenda key")
2392 (string :tag "Replace by command")
2393 (repeat :tag "Available when"
2394 (choice
2395 (cons :tag "Condition"
2396 (choice
2397 (const :tag "In file" in-file)
2398 (const :tag "Not in file" not-in-file)
2399 (const :tag "In mode" in-mode)
2400 (const :tag "Not in mode" not-in-mode))
2401 (regexp))
2402 (function :tag "Custom function"))))))
2404 (defvar org-keys nil)
2405 (defvar org-match nil)
2406 ;;;###autoload
2407 (defun org-agenda (&optional arg org-keys restriction)
2408 "Dispatch agenda commands to collect entries to the agenda buffer.
2409 Prompts for a command to execute. Any prefix arg will be passed
2410 on to the selected command. The default selections are:
2412 a Call `org-agenda-list' to display the agenda for current day or week.
2413 t Call `org-todo-list' to display the global todo list.
2414 T Call `org-todo-list' to display the global todo list, select only
2415 entries with a specific TODO keyword (the user gets a prompt).
2416 m Call `org-tags-view' to display headlines with tags matching
2417 a condition (the user is prompted for the condition).
2418 M Like `m', but select only TODO entries, no ordinary headlines.
2419 L Create a timeline for the current buffer.
2420 e Export views to associated files.
2421 s Search entries for keywords.
2422 S Search entries for keywords, only with TODO keywords.
2423 / Multi occur across all agenda files and also files listed
2424 in `org-agenda-text-search-extra-files'.
2425 < Restrict agenda commands to buffer, subtree, or region.
2426 Press several times to get the desired effect.
2427 > Remove a previous restriction.
2428 # List \"stuck\" projects.
2429 ! Configure what \"stuck\" means.
2430 C Configure custom agenda commands.
2432 More commands can be added by configuring the variable
2433 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2434 searches can be pre-defined in this way.
2436 If the current buffer is in Org-mode and visiting a file, you can also
2437 first press `<' once to indicate that the agenda should be temporarily
2438 \(until the next use of \\[org-agenda]) restricted to the current file.
2439 Pressing `<' twice means to restrict to the current subtree or region
2440 \(if active)."
2441 (interactive "P")
2442 (catch 'exit
2443 (let* ((prefix-descriptions nil)
2444 (org-agenda-buffer-name org-agenda-buffer-name)
2445 (org-agenda-window-setup (if (equal (buffer-name)
2446 org-agenda-buffer-name)
2447 'current-window
2448 org-agenda-window-setup))
2449 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2450 (org-agenda-custom-commands
2451 ;; normalize different versions
2452 (delq nil
2453 (mapcar
2454 (lambda (x)
2455 (cond ((stringp (cdr x))
2456 (push x prefix-descriptions)
2457 nil)
2458 ((stringp (nth 1 x)) x)
2459 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2460 (t (cons (car x) (cons "" (cdr x))))))
2461 org-agenda-custom-commands)))
2462 (org-agenda-custom-commands
2463 (org-contextualize-keys
2464 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2465 (buf (current-buffer))
2466 (bfn (buffer-file-name (buffer-base-buffer)))
2467 entry key type org-match lprops ans)
2468 ;; Turn off restriction unless there is an overriding one,
2469 (unless org-agenda-overriding-restriction
2470 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2471 ;; There is a request to keep the file list in place
2472 (put 'org-agenda-files 'org-restrict nil))
2473 (setq org-agenda-restrict nil)
2474 (move-marker org-agenda-restrict-begin nil)
2475 (move-marker org-agenda-restrict-end nil))
2476 ;; Delete old local properties
2477 (put 'org-agenda-redo-command 'org-lprops nil)
2478 ;; Delete previously set last-arguments
2479 (put 'org-agenda-redo-command 'last-args nil)
2480 ;; Remember where this call originated
2481 (setq org-agenda-last-dispatch-buffer (current-buffer))
2482 (unless org-keys
2483 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2484 org-keys (car ans)
2485 restriction (cdr ans)))
2486 ;; If we have sticky agenda buffers, set a name for the buffer,
2487 ;; depending on the invoking keys. The user may still set this
2488 ;; as a command option, which will overwrite what we do here.
2489 (if org-agenda-sticky
2490 (setq org-agenda-buffer-name
2491 (format "*Org Agenda(%s)*" org-keys)))
2492 ;; Establish the restriction, if any
2493 (when (and (not org-agenda-overriding-restriction) restriction)
2494 (put 'org-agenda-files 'org-restrict (list bfn))
2495 (cond
2496 ((eq restriction 'region)
2497 (setq org-agenda-restrict t)
2498 (move-marker org-agenda-restrict-begin (region-beginning))
2499 (move-marker org-agenda-restrict-end (region-end)))
2500 ((eq restriction 'subtree)
2501 (save-excursion
2502 (setq org-agenda-restrict t)
2503 (org-back-to-heading t)
2504 (move-marker org-agenda-restrict-begin (point))
2505 (move-marker org-agenda-restrict-end
2506 (progn (org-end-of-subtree t)))))))
2508 ;; For example the todo list should not need it (but does...)
2509 (cond
2510 ((setq entry (assoc org-keys org-agenda-custom-commands))
2511 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2512 (progn
2513 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2514 lprops (nth 4 entry))
2515 (if org-agenda-sticky
2516 (setq org-agenda-buffer-name
2517 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2518 (format "*Org Agenda(%s)*" org-keys))))
2519 (put 'org-agenda-redo-command 'org-lprops lprops)
2520 (cond
2521 ((eq type 'agenda)
2522 (org-let lprops '(org-agenda-list current-prefix-arg)))
2523 ((eq type 'alltodo)
2524 (org-let lprops '(org-todo-list current-prefix-arg)))
2525 ((eq type 'search)
2526 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2527 ((eq type 'stuck)
2528 (org-let lprops '(org-agenda-list-stuck-projects
2529 current-prefix-arg)))
2530 ((eq type 'tags)
2531 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2532 ((eq type 'tags-todo)
2533 (org-let lprops '(org-tags-view '(4) org-match)))
2534 ((eq type 'todo)
2535 (org-let lprops '(org-todo-list org-match)))
2536 ((eq type 'tags-tree)
2537 (org-check-for-org-mode)
2538 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2539 ((eq type 'todo-tree)
2540 (org-check-for-org-mode)
2541 (org-let lprops
2542 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2543 (regexp-quote org-match) "\\>"))))
2544 ((eq type 'occur-tree)
2545 (org-check-for-org-mode)
2546 (org-let lprops '(org-occur org-match)))
2547 ((functionp type)
2548 (org-let lprops '(funcall type org-match)))
2549 ((fboundp type)
2550 (org-let lprops '(funcall type org-match)))
2551 (t (error "Invalid custom agenda command type %s" type))))
2552 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2553 ((equal org-keys "C")
2554 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2555 (customize-variable 'org-agenda-custom-commands))
2556 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2557 ((equal org-keys "s") (call-interactively 'org-search-view))
2558 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2559 ((equal org-keys "t") (call-interactively 'org-todo-list))
2560 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2561 ((equal org-keys "m") (call-interactively 'org-tags-view))
2562 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2563 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2564 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2565 (org-add-hook
2566 'post-command-hook
2567 (lambda ()
2568 (unless (current-message)
2569 (let* ((m (org-agenda-get-any-marker))
2570 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2571 (when note
2572 (message (concat
2573 "FLAGGING-NOTE ([?] for more info): "
2574 (org-add-props
2575 (replace-regexp-in-string
2576 "\\\\n" "//"
2577 (copy-sequence note))
2578 nil 'face 'org-warning)))))))
2579 t t))
2580 ((equal org-keys "L")
2581 (unless (derived-mode-p 'org-mode)
2582 (error "This is not an Org-mode file"))
2583 (unless restriction
2584 (put 'org-agenda-files 'org-restrict (list bfn))
2585 (org-call-with-arg 'org-timeline arg)))
2586 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2587 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2588 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2589 (t (error "Invalid agenda key"))))))
2591 (autoload 'org-agenda "org-agenda" "\
2592 Dispatch agenda commands to collect entries to the agenda buffer.
2593 Prompts for a command to execute. Any prefix arg will be passed
2594 on to the selected command. The default selections are:
2596 a Call `org-agenda-list' to display the agenda for current day or week.
2597 t Call `org-todo-list' to display the global todo list.
2598 T Call `org-todo-list' to display the global todo list, select only
2599 entries with a specific TODO keyword (the user gets a prompt).
2600 m Call `org-tags-view' to display headlines with tags matching
2601 a condition (the user is prompted for the condition).
2602 M Like `m', but select only TODO entries, no ordinary headlines.
2603 L Create a timeline for the current buffer.
2604 e Export views to associated files.
2605 s Search entries for keywords.
2606 S Search entries for keywords, only with TODO keywords.
2607 / Multi occur across all agenda files and also files listed
2608 in `org-agenda-text-search-extra-files'.
2609 < Restrict agenda commands to buffer, subtree, or region.
2610 Press several times to get the desired effect.
2611 > Remove a previous restriction.
2612 # List \"stuck\" projects.
2613 ! Configure what \"stuck\" means.
2614 C Configure custom agenda commands.
2616 More commands can be added by configuring the variable
2617 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2618 searches can be pre-defined in this way.
2620 If the current buffer is in Org-mode and visiting a file, you can also
2621 first press `<' once to indicate that the agenda should be temporarily
2622 \(until the next use of \\[org-agenda]) restricted to the current file.
2623 Pressing `<' twice means to restrict to the current subtree or region
2624 \(if active).
2626 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2628 (defun org-agenda-append-agenda ()
2629 "Append another agenda view to the current one.
2630 This function allows interactive building of block agendas.
2631 Agenda views are separated by `org-agenda-block-separator'."
2632 (interactive)
2633 (unless (derived-mode-p 'org-agenda-mode)
2634 (error "Can only append from within agenda buffer"))
2635 (let ((org-agenda-multi t))
2636 (org-agenda)
2637 (widen)
2638 (org-agenda-finalize)
2639 (org-agenda-fit-window-to-buffer)))
2641 (defun org-agenda-normalize-custom-commands (cmds)
2642 (delq nil
2643 (mapcar
2644 (lambda (x)
2645 (cond ((stringp (cdr x)) nil)
2646 ((stringp (nth 1 x)) x)
2647 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2648 (t (cons (car x) (cons "" (cdr x))))))
2649 cmds)))
2651 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2652 "The user interface for selecting an agenda command."
2653 (catch 'exit
2654 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2655 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2656 (region-p (org-region-active-p))
2657 (custom org-agenda-custom-commands)
2658 (selstring "")
2659 restriction second-time
2660 c entry key type match prefixes rmheader header-end custom1 desc
2661 line lines left right n n1)
2662 (save-window-excursion
2663 (delete-other-windows)
2664 (org-switch-to-buffer-other-window " *Agenda Commands*")
2665 (erase-buffer)
2666 (insert (eval-when-compile
2667 (let ((header
2668 "Press key for an agenda command: < Buffer, subtree/region restriction
2669 -------------------------------- > Remove restriction
2670 a Agenda for current week or day e Export agenda views
2671 t List of all TODO entries T Entries with special TODO kwd
2672 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2673 s Search for keywords S Like s, but only TODO entries
2674 L Timeline for current buffer # List stuck projects (!=configure)
2675 / Multi-occur C Configure custom agenda commands
2676 ? Find :FLAGGED: entries * Toggle sticky agenda views
2678 (start 0))
2679 (while (string-match
2680 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2681 header start)
2682 (setq start (match-end 0))
2683 (add-text-properties (match-beginning 2) (match-end 2)
2684 '(face bold) header))
2685 header)))
2686 (setq header-end (point-marker))
2687 (while t
2688 (setq custom1 custom)
2689 (when (eq rmheader t)
2690 (org-goto-line 1)
2691 (re-search-forward ":" nil t)
2692 (delete-region (match-end 0) (point-at-eol))
2693 (forward-char 1)
2694 (looking-at "-+")
2695 (delete-region (match-end 0) (point-at-eol))
2696 (move-marker header-end (match-end 0)))
2697 (goto-char header-end)
2698 (delete-region (point) (point-max))
2700 ;; Produce all the lines that describe custom commands and prefixes
2701 (setq lines nil)
2702 (while (setq entry (pop custom1))
2703 (setq key (car entry) desc (nth 1 entry)
2704 type (nth 2 entry)
2705 match (nth 3 entry))
2706 (if (> (length key) 1)
2707 (add-to-list 'prefixes (string-to-char key))
2708 (setq line
2709 (format
2710 "%-4s%-14s"
2711 (org-add-props (copy-sequence key)
2712 '(face bold))
2713 (cond
2714 ((string-match "\\S-" desc) desc)
2715 ((eq type 'agenda) "Agenda for current week or day")
2716 ((eq type 'alltodo) "List of all TODO entries")
2717 ((eq type 'search) "Word search")
2718 ((eq type 'stuck) "List of stuck projects")
2719 ((eq type 'todo) "TODO keyword")
2720 ((eq type 'tags) "Tags query")
2721 ((eq type 'tags-todo) "Tags (TODO)")
2722 ((eq type 'tags-tree) "Tags tree")
2723 ((eq type 'todo-tree) "TODO kwd tree")
2724 ((eq type 'occur-tree) "Occur tree")
2725 ((functionp type) (if (symbolp type)
2726 (symbol-name type)
2727 "Lambda expression"))
2728 (t "???"))))
2729 (if org-agenda-menu-show-matcher
2730 (setq line
2731 (concat line ": "
2732 (cond
2733 ((stringp match)
2734 (setq match (copy-sequence match))
2735 (org-add-props match nil 'face 'org-warning))
2736 ((listp type)
2737 (format "set of %d commands" (length type))))))
2738 (if (org-string-nw-p match)
2739 (add-text-properties
2740 0 (length line) (list 'help-echo
2741 (concat "Matcher: " match)) line)))
2742 (push line lines)))
2743 (setq lines (nreverse lines))
2744 (when prefixes
2745 (mapc (lambda (x)
2746 (push
2747 (format "%s %s"
2748 (org-add-props (char-to-string x)
2749 nil 'face 'bold)
2750 (or (cdr (assoc (concat selstring
2751 (char-to-string x))
2752 prefix-descriptions))
2753 "Prefix key"))
2754 lines))
2755 prefixes))
2757 ;; Check if we should display in two columns
2758 (if org-agenda-menu-two-columns
2759 (progn
2760 (setq n (length lines)
2761 n1 (+ (/ n 2) (mod n 2))
2762 right (nthcdr n1 lines)
2763 left (copy-sequence lines))
2764 (setcdr (nthcdr (1- n1) left) nil))
2765 (setq left lines right nil))
2766 (while left
2767 (insert "\n" (pop left))
2768 (when right
2769 (if (< (current-column) 40)
2770 (move-to-column 40 t)
2771 (insert " "))
2772 (insert (pop right))))
2774 ;; Make the window the right size
2775 (goto-char (point-min))
2776 (if second-time
2777 (if (not (pos-visible-in-window-p (point-max)))
2778 (org-fit-window-to-buffer))
2779 (setq second-time t)
2780 (org-fit-window-to-buffer))
2782 ;; Ask for selection
2783 (message "Press key for agenda command%s:"
2784 (if (or restrict-ok org-agenda-overriding-restriction)
2785 (if org-agenda-overriding-restriction
2786 " (restriction lock active)"
2787 (if restriction
2788 (format " (restricted to %s)" restriction)
2789 " (unrestricted)"))
2790 ""))
2791 (setq c (read-char-exclusive))
2792 (message "")
2793 (cond
2794 ((assoc (char-to-string c) custom)
2795 (setq selstring (concat selstring (char-to-string c)))
2796 (throw 'exit (cons selstring restriction)))
2797 ((memq c prefixes)
2798 (setq selstring (concat selstring (char-to-string c))
2799 prefixes nil
2800 rmheader (or rmheader t)
2801 custom (delq nil (mapcar
2802 (lambda (x)
2803 (if (or (= (length (car x)) 1)
2804 (/= (string-to-char (car x)) c))
2806 (cons (substring (car x) 1) (cdr x))))
2807 custom))))
2808 ((eq c ?*)
2809 (call-interactively 'org-toggle-sticky-agenda)
2810 (sit-for 2))
2811 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2812 (message "Restriction is only possible in Org-mode buffers")
2813 (ding) (sit-for 1))
2814 ((eq c ?1)
2815 (org-agenda-remove-restriction-lock 'noupdate)
2816 (setq restriction 'buffer))
2817 ((eq c ?0)
2818 (org-agenda-remove-restriction-lock 'noupdate)
2819 (setq restriction (if region-p 'region 'subtree)))
2820 ((eq c ?<)
2821 (org-agenda-remove-restriction-lock 'noupdate)
2822 (setq restriction
2823 (cond
2824 ((eq restriction 'buffer)
2825 (if region-p 'region 'subtree))
2826 ((memq restriction '(subtree region))
2827 nil)
2828 (t 'buffer))))
2829 ((eq c ?>)
2830 (org-agenda-remove-restriction-lock 'noupdate)
2831 (setq restriction nil))
2832 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2833 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2834 ((and (> (length selstring) 0) (eq c ?\d))
2835 (delete-window)
2836 (org-agenda-get-restriction-and-command prefix-descriptions))
2838 ((equal c ?q) (error "Abort"))
2839 (t (error "Invalid key %c" c))))))))
2841 (defun org-agenda-fit-window-to-buffer ()
2842 "Fit the window to the buffer size."
2843 (and (memq org-agenda-window-setup '(reorganize-frame))
2844 (fboundp 'fit-window-to-buffer)
2845 (org-fit-window-to-buffer
2847 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2848 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2850 (defvar org-cmd nil)
2851 (defvar org-agenda-overriding-cmd nil)
2852 (defvar org-agenda-overriding-arguments nil)
2853 (defvar org-agenda-overriding-cmd-arguments nil)
2854 (defun org-agenda-run-series (name series)
2855 (org-let (nth 1 series) '(org-agenda-prepare name))
2856 ;; We need to reset agenda markers here, because when constructing a
2857 ;; block agenda, the individual blocks do not do that.
2858 (org-agenda-reset-markers)
2859 (let* ((org-agenda-multi t)
2860 (redo (list 'org-agenda-run-series name (list 'quote series)))
2861 (cmds (car series))
2862 (gprops (nth 1 series))
2863 match ;; The byte compiler incorrectly complains about this. Keep it!
2864 org-cmd type lprops)
2865 (while (setq org-cmd (pop cmds))
2866 (setq type (car org-cmd)
2867 match (eval (nth 1 org-cmd))
2868 lprops (nth 2 org-cmd))
2869 (let ((org-agenda-overriding-arguments
2870 (if (eq org-agenda-overriding-cmd org-cmd)
2871 (or org-agenda-overriding-arguments
2872 org-agenda-overriding-cmd-arguments))))
2873 (cond
2874 ((eq type 'agenda)
2875 (org-let2 gprops lprops
2876 '(call-interactively 'org-agenda-list)))
2877 ((eq type 'alltodo)
2878 (org-let2 gprops lprops
2879 '(call-interactively 'org-todo-list)))
2880 ((eq type 'search)
2881 (org-let2 gprops lprops
2882 '(org-search-view current-prefix-arg match nil)))
2883 ((eq type 'stuck)
2884 (org-let2 gprops lprops
2885 '(call-interactively 'org-agenda-list-stuck-projects)))
2886 ((eq type 'tags)
2887 (org-let2 gprops lprops
2888 '(org-tags-view current-prefix-arg match)))
2889 ((eq type 'tags-todo)
2890 (org-let2 gprops lprops
2891 '(org-tags-view '(4) match)))
2892 ((eq type 'todo)
2893 (org-let2 gprops lprops
2894 '(org-todo-list match)))
2895 ((fboundp type)
2896 (org-let2 gprops lprops
2897 '(funcall type match)))
2898 (t (error "Invalid type in command series")))))
2899 (widen)
2900 (let ((inhibit-read-only t))
2901 (add-text-properties (point-min) (point-max)
2902 `(org-series t org-series-redo-cmd ,redo)))
2903 (setq org-agenda-redo-command redo)
2904 (goto-char (point-min)))
2905 (org-agenda-fit-window-to-buffer)
2906 (org-let (nth 1 series) '(org-agenda-finalize)))
2908 ;;;###autoload
2909 (defmacro org-batch-agenda (cmd-key &rest parameters)
2910 "Run an agenda command in batch mode and send the result to STDOUT.
2911 If CMD-KEY is a string of length 1, it is used as a key in
2912 `org-agenda-custom-commands' and triggers this command. If it is a
2913 longer string it is used as a tags/todo match string.
2914 Parameters are alternating variable names and values that will be bound
2915 before running the agenda command."
2916 (org-eval-in-environment (org-make-parameter-alist parameters)
2917 (if (> (length cmd-key) 2)
2918 (org-tags-view nil cmd-key)
2919 (org-agenda nil cmd-key)))
2920 (set-buffer org-agenda-buffer-name)
2921 (princ (buffer-string)))
2923 (autoload 'org-batch-agenda "org-agenda" "\
2924 Run an agenda command in batch mode and send the result to STDOUT.
2925 If CMD-KEY is a string of length 1, it is used as a key in
2926 `org-agenda-custom-commands' and triggers this command. If it is a
2927 longer string it is used as a tags/todo match string.
2928 Parameters are alternating variable names and values that will be bound
2929 before running the agenda command.
2931 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2932 (def-edebug-spec org-batch-agenda (form &rest sexp))
2934 (defvar org-agenda-info nil)
2936 ;;;###autoload
2937 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2938 "Run an agenda command in batch mode and send the result to STDOUT.
2939 If CMD-KEY is a string of length 1, it is used as a key in
2940 `org-agenda-custom-commands' and triggers this command. If it is a
2941 longer string it is used as a tags/todo match string.
2942 Parameters are alternating variable names and values that will be bound
2943 before running the agenda command.
2945 The output gives a line for each selected agenda item. Each
2946 item is a list of comma-separated values, like this:
2948 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2950 category The category of the item
2951 head The headline, without TODO kwd, TAGS and PRIORITY
2952 type The type of the agenda entry, can be
2953 todo selected in TODO match
2954 tagsmatch selected in tags match
2955 diary imported from diary
2956 deadline a deadline on given date
2957 scheduled scheduled on given date
2958 timestamp entry has timestamp on given date
2959 closed entry was closed on given date
2960 upcoming-deadline warning about deadline
2961 past-scheduled forwarded scheduled item
2962 block entry has date block including g. date
2963 todo The todo keyword, if any
2964 tags All tags including inherited ones, separated by colons
2965 date The relevant date, like 2007-2-14
2966 time The time, like 15:00-16:50
2967 extra Sting with extra planning info
2968 priority-l The priority letter if any was given
2969 priority-n The computed numerical priority
2970 agenda-day The day in the agenda where this is listed"
2971 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2972 (org-make-parameter-alist parameters))
2973 (if (> (length cmd-key) 2)
2974 (org-tags-view nil cmd-key)
2975 (org-agenda nil cmd-key)))
2976 (set-buffer org-agenda-buffer-name)
2977 (let* ((lines (org-split-string (buffer-string) "\n"))
2978 line)
2979 (while (setq line (pop lines))
2980 (catch 'next
2981 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2982 (setq org-agenda-info
2983 (org-fix-agenda-info (text-properties-at 0 line)))
2984 (princ
2985 (mapconcat 'org-agenda-export-csv-mapper
2986 '(org-category txt type todo tags date time extra
2987 priority-letter priority agenda-day)
2988 ","))
2989 (princ "\n")))))
2991 (autoload 'org-batch-agenda-csv "org-agenda" "\
2992 Run an agenda command in batch mode and send the result to STDOUT.
2993 If CMD-KEY is a string of length 1, it is used as a key in
2994 `org-agenda-custom-commands' and triggers this command. If it is a
2995 longer string it is used as a tags/todo match string.
2996 Parameters are alternating variable names and values that will be bound
2997 before running the agenda command.
2999 The output gives a line for each selected agenda item. Each
3000 item is a list of comma-separated values, like this:
3002 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3004 category The category of the item
3005 head The headline, without TODO kwd, TAGS and PRIORITY
3006 type The type of the agenda entry, can be
3007 todo selected in TODO match
3008 tagsmatch selected in tags match
3009 diary imported from diary
3010 deadline a deadline on given date
3011 scheduled scheduled on given date
3012 timestamp entry has timestamp on given date
3013 closed entry was closed on given date
3014 upcoming-deadline warning about deadline
3015 past-scheduled forwarded scheduled item
3016 block entry has date block including g. date
3017 todo The todo keyword, if any
3018 tags All tags including inherited ones, separated by colons
3019 date The relevant date, like 2007-2-14
3020 time The time, like 15:00-16:50
3021 extra Sting with extra planning info
3022 priority-l The priority letter if any was given
3023 priority-n The computed numerical priority
3024 agenda-day The day in the agenda where this is listed
3026 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3027 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3029 (defun org-fix-agenda-info (props)
3030 "Make sure all properties on an agenda item have a canonical form.
3031 This ensures the export commands can easily use it."
3032 (let (tmp re)
3033 (when (setq tmp (plist-get props 'tags))
3034 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3035 (when (setq tmp (plist-get props 'date))
3036 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3037 (let ((calendar-date-display-form '(year "-" month "-" day)))
3038 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3040 (setq tmp (calendar-date-string tmp)))
3041 (setq props (plist-put props 'date tmp)))
3042 (when (setq tmp (plist-get props 'day))
3043 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3044 (let ((calendar-date-display-form '(year "-" month "-" day)))
3045 (setq tmp (calendar-date-string tmp)))
3046 (setq props (plist-put props 'day tmp))
3047 (setq props (plist-put props 'agenda-day tmp)))
3048 (when (setq tmp (plist-get props 'txt))
3049 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3050 (plist-put props 'priority-letter (match-string 1 tmp))
3051 (setq tmp (replace-match "" t t tmp)))
3052 (when (and (setq re (plist-get props 'org-todo-regexp))
3053 (setq re (concat "\\`\\.*" re " ?"))
3054 (string-match re tmp))
3055 (plist-put props 'todo (match-string 1 tmp))
3056 (setq tmp (replace-match "" t t tmp)))
3057 (plist-put props 'txt tmp)))
3058 props)
3060 (defun org-agenda-export-csv-mapper (prop)
3061 (let ((res (plist-get org-agenda-info prop)))
3062 (setq res
3063 (cond
3064 ((not res) "")
3065 ((stringp res) res)
3066 (t (prin1-to-string res))))
3067 (while (string-match "," res)
3068 (setq res (replace-match ";" t t res)))
3069 (org-trim res)))
3071 ;;;###autoload
3072 (defun org-store-agenda-views (&rest parameters)
3073 (interactive)
3074 (eval (list 'org-batch-store-agenda-views)))
3076 (autoload 'org-store-agenda-views "org-agenda" "\
3079 \(fn &rest PARAMETERS)" t nil)
3081 ;;;###autoload
3082 (defmacro org-batch-store-agenda-views (&rest parameters)
3083 "Run all custom agenda commands that have a file argument."
3084 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3085 (pop-up-frames nil)
3086 (dir default-directory)
3087 (pars (org-make-parameter-alist parameters))
3088 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3089 (save-window-excursion
3090 (while cmds
3091 (setq cmd (pop cmds)
3092 thiscmdkey (car cmd)
3093 thiscmdcmd (cdr cmd)
3094 match (nth 2 thiscmdcmd)
3095 bufname (if org-agenda-sticky
3096 (or (and (stringp match)
3097 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3098 (format "*Org Agenda(%s)*" thiscmdkey))
3099 org-agenda-buffer-name)
3100 cmd-or-set (nth 2 cmd)
3101 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3102 files (nth (if (listp cmd-or-set) 4 5) cmd))
3103 (if (stringp files) (setq files (list files)))
3104 (when files
3105 (org-eval-in-environment (append org-agenda-exporter-settings
3106 opts pars)
3107 (org-agenda nil thiscmdkey))
3108 (set-buffer bufname)
3109 (while files
3110 (org-eval-in-environment (append org-agenda-exporter-settings
3111 opts pars)
3112 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3113 (and (get-buffer bufname)
3114 (kill-buffer bufname)))))))
3116 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3117 Run all custom agenda commands that have a file argument.
3119 \(fn &rest PARAMETERS)" nil t)
3120 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3122 (defvar org-agenda-current-span nil
3123 "The current span used in the agenda view.") ; local variable in the agenda buffer
3124 (defun org-agenda-mark-header-line (pos)
3125 "Mark the line at POS as an agenda structure header."
3126 (save-excursion
3127 (goto-char pos)
3128 (put-text-property (point-at-bol) (point-at-eol)
3129 'org-agenda-structural-header t)
3130 (when org-agenda-title-append
3131 (put-text-property (point-at-bol) (point-at-eol)
3132 'org-agenda-title-append org-agenda-title-append))))
3134 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3135 (defvar org-agenda-write-buffer-name "Agenda View")
3136 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3137 "Write the current buffer (an agenda view) as a file.
3138 Depending on the extension of the file name, plain text (.txt),
3139 HTML (.html or .htm) or Postscript (.ps) is produced.
3140 If the extension is .ics, run icalendar export over all files used
3141 to construct the agenda and limit the export to entries listed in the
3142 agenda now.
3143 With prefix argument OPEN, open the new file immediately.
3144 If NOSETTINGS is given, do not scope the settings of
3145 `org-agenda-exporter-settings' into the export commands. This is used when
3146 the settings have already been scoped and we do not wish to overrule other,
3147 higher priority settings.
3148 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3149 (interactive "FWrite agenda to file: \nP")
3150 (if (not (file-writable-p file))
3151 (error "Cannot write agenda to file %s" file))
3152 (org-let (if nosettings nil org-agenda-exporter-settings)
3153 '(save-excursion
3154 (save-window-excursion
3155 (org-agenda-mark-filtered-text)
3156 (let ((bs (copy-sequence (buffer-string))) beg)
3157 (org-agenda-unmark-filtered-text)
3158 (with-temp-buffer
3159 (rename-buffer org-agenda-write-buffer-name t)
3160 (set-buffer-modified-p nil)
3161 (insert bs)
3162 (org-agenda-remove-marked-text 'org-filtered)
3163 (while (setq beg (text-property-any (point-min) (point-max)
3164 'org-filtered t))
3165 (delete-region
3166 beg (or (next-single-property-change beg 'org-filtered)
3167 (point-max))))
3168 (run-hooks 'org-agenda-before-write-hook)
3169 (cond
3170 ((org-bound-and-true-p org-mobile-creating-agendas)
3171 (org-mobile-write-agenda-for-mobile file))
3172 ((string-match "\\.html?\\'" file)
3173 (require 'htmlize)
3174 (set-buffer (htmlize-buffer (current-buffer)))
3175 (when org-agenda-export-html-style
3176 ;; replace <style> section with org-agenda-export-html-style
3177 (goto-char (point-min))
3178 (kill-region (- (search-forward "<style") 6)
3179 (search-forward "</style>"))
3180 (insert org-agenda-export-html-style))
3181 (write-file file)
3182 (kill-buffer (current-buffer))
3183 (message "HTML written to %s" file))
3184 ((string-match "\\.ps\\'" file)
3185 (require 'ps-print)
3186 (ps-print-buffer-with-faces file)
3187 (message "Postscript written to %s" file))
3188 ((string-match "\\.pdf\\'" file)
3189 (require 'ps-print)
3190 (ps-print-buffer-with-faces
3191 (concat (file-name-sans-extension file) ".ps"))
3192 (call-process "ps2pdf" nil nil nil
3193 (expand-file-name
3194 (concat (file-name-sans-extension file) ".ps"))
3195 (expand-file-name file))
3196 (delete-file (concat (file-name-sans-extension file) ".ps"))
3197 (message "PDF written to %s" file))
3198 ((string-match "\\.ics\\'" file)
3199 (require 'org-icalendar)
3200 (let ((org-agenda-marker-table
3201 (org-create-marker-find-array
3202 (org-agenda-collect-markers)))
3203 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3204 (org-combined-agenda-icalendar-file file))
3205 (apply 'org-export-icalendar 'combine
3206 (org-agenda-files nil 'ifmode))))
3208 (let ((bs (buffer-string)))
3209 (find-file file)
3210 (erase-buffer)
3211 (insert bs)
3212 (save-buffer 0)
3213 (kill-buffer (current-buffer))
3214 (message "Plain text written to %s" file))))))))
3215 (set-buffer (or agenda-bufname
3216 (and (org-called-interactively-p 'any) (buffer-name))
3217 org-agenda-buffer-name)))
3218 (when open (org-open-file file)))
3220 (defvar org-agenda-tag-filter-overlays nil)
3221 (defvar org-agenda-cat-filter-overlays nil)
3223 (defun org-agenda-mark-filtered-text ()
3224 "Mark all text hidden by filtering with a text property."
3225 (let ((inhibit-read-only t))
3226 (mapc
3227 (lambda (o)
3228 (when (equal (overlay-buffer o) (current-buffer))
3229 (put-text-property
3230 (overlay-start o) (overlay-end o)
3231 'org-filtered t)))
3232 (append org-agenda-tag-filter-overlays
3233 org-agenda-cat-filter-overlays))))
3235 (defun org-agenda-unmark-filtered-text ()
3236 "Remove the filtering text property."
3237 (let ((inhibit-read-only t))
3238 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3240 (defun org-agenda-remove-marked-text (property &optional value)
3241 "Delete all text marked with VALUE of PROPERTY.
3242 VALUE defaults to t."
3243 (let (beg)
3244 (setq value (or value t))
3245 (while (setq beg (text-property-any (point-min) (point-max)
3246 property value))
3247 (delete-region
3248 beg (or (next-single-property-change beg 'org-filtered)
3249 (point-max))))))
3251 (defun org-agenda-add-entry-text ()
3252 "Add entry text to agenda lines.
3253 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3254 entry text following headings shown in the agenda.
3255 Drawers will be excluded, also the line with scheduling/deadline info."
3256 (when (and (> org-agenda-add-entry-text-maxlines 0)
3257 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3258 (let (m txt)
3259 (goto-char (point-min))
3260 (while (not (eobp))
3261 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3262 (beginning-of-line 2)
3263 (setq txt (org-agenda-get-some-entry-text
3264 m org-agenda-add-entry-text-maxlines " > "))
3265 (end-of-line 1)
3266 (if (string-match "\\S-" txt)
3267 (insert "\n" txt)
3268 (or (eobp) (forward-char 1))))))))
3270 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3271 &rest keep)
3272 "Extract entry text from MARKER, at most N-LINES lines.
3273 This will ignore drawers etc, just get the text.
3274 If INDENT is given, prefix every line with this string. If KEEP is
3275 given, it is a list of symbols, defining stuff that should not be
3276 removed from the entry content. Currently only `planning' is allowed here."
3277 (let (txt drawer-re kwd-time-re ind)
3278 (save-excursion
3279 (with-current-buffer (marker-buffer marker)
3280 (if (not (derived-mode-p 'org-mode))
3281 (setq txt "")
3282 (save-excursion
3283 (save-restriction
3284 (widen)
3285 (goto-char marker)
3286 (end-of-line 1)
3287 (setq txt (buffer-substring
3288 (min (1+ (point)) (point-max))
3289 (progn (outline-next-heading) (point)))
3290 drawer-re org-drawer-regexp
3291 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3292 ".*\n?"))
3293 (with-temp-buffer
3294 (insert txt)
3295 (when org-agenda-add-entry-text-descriptive-links
3296 (goto-char (point-min))
3297 (while (org-activate-bracket-links (point-max))
3298 (add-text-properties (match-beginning 0) (match-end 0)
3299 '(face org-link))))
3300 (goto-char (point-min))
3301 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3302 (set-text-properties (match-beginning 0) (match-end 0)
3303 nil))
3304 (goto-char (point-min))
3305 (while (re-search-forward drawer-re nil t)
3306 (delete-region
3307 (match-beginning 0)
3308 (progn (re-search-forward
3309 "^[ \t]*:END:.*\n?" nil 'move)
3310 (point))))
3311 (unless (member 'planning keep)
3312 (goto-char (point-min))
3313 (while (re-search-forward kwd-time-re nil t)
3314 (replace-match "")))
3315 (goto-char (point-min))
3316 (when org-agenda-entry-text-exclude-regexps
3317 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3318 (while (setq re (pop re-list))
3319 (goto-char (point-min))
3320 (while (re-search-forward re nil t)
3321 (replace-match "")))))
3322 (goto-char (point-max))
3323 (skip-chars-backward " \t\n")
3324 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3326 ;; find and remove min common indentation
3327 (goto-char (point-min))
3328 (untabify (point-min) (point-max))
3329 (setq ind (org-get-indentation))
3330 (while (not (eobp))
3331 (unless (looking-at "[ \t]*$")
3332 (setq ind (min ind (org-get-indentation))))
3333 (beginning-of-line 2))
3334 (goto-char (point-min))
3335 (while (not (eobp))
3336 (unless (looking-at "[ \t]*$")
3337 (move-to-column ind)
3338 (delete-region (point-at-bol) (point)))
3339 (beginning-of-line 2))
3341 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3343 (goto-char (point-min))
3344 (when indent
3345 (while (and (not (eobp)) (re-search-forward "^" nil t))
3346 (replace-match indent t t)))
3347 (goto-char (point-min))
3348 (while (looking-at "[ \t]*\n") (replace-match ""))
3349 (goto-char (point-max))
3350 (when (> (org-current-line)
3351 n-lines)
3352 (org-goto-line (1+ n-lines))
3353 (backward-char 1))
3354 (setq txt (buffer-substring (point-min) (point)))))))))
3355 txt))
3357 (defun org-agenda-collect-markers ()
3358 "Collect the markers pointing to entries in the agenda buffer."
3359 (let (m markers)
3360 (save-excursion
3361 (goto-char (point-min))
3362 (while (not (eobp))
3363 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3364 (org-get-at-bol 'org-marker)))
3365 (push m markers))
3366 (beginning-of-line 2)))
3367 (nreverse markers)))
3369 (defun org-create-marker-find-array (marker-list)
3370 "Create a alist of files names with all marker positions in that file."
3371 (let (f tbl m a p)
3372 (while (setq m (pop marker-list))
3373 (setq p (marker-position m)
3374 f (buffer-file-name (or (buffer-base-buffer
3375 (marker-buffer m))
3376 (marker-buffer m))))
3377 (if (setq a (assoc f tbl))
3378 (push (marker-position m) (cdr a))
3379 (push (list f p) tbl)))
3380 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3381 tbl)))
3383 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3384 (defun org-check-agenda-marker-table ()
3385 "Check of the current entry is on the marker list."
3386 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3388 (and (setq a (assoc file org-agenda-marker-table))
3389 (save-match-data
3390 (save-excursion
3391 (org-back-to-heading t)
3392 (member (point) (cdr a)))))))
3394 (defun org-check-for-org-mode ()
3395 "Make sure current buffer is in org-mode. Error if not."
3396 (or (derived-mode-p 'org-mode)
3397 (error "Cannot execute org-mode agenda command on buffer in %s"
3398 major-mode)))
3400 ;;; Agenda prepare and finalize
3402 (defvar org-agenda-multi nil) ; dynamically scoped
3403 (defvar org-agenda-pre-window-conf nil)
3404 (defvar org-agenda-columns-active nil)
3405 (defvar org-agenda-name nil)
3406 (defvar org-agenda-tag-filter nil)
3407 (defvar org-agenda-category-filter nil)
3408 (defvar org-agenda-top-category-filter nil)
3409 (defvar org-agenda-tag-filter-while-redo nil)
3410 (defvar org-agenda-tag-filter-preset nil
3411 "A preset of the tags filter used for secondary agenda filtering.
3412 This must be a list of strings, each string must be a single tag preceded
3413 by \"+\" or \"-\".
3414 This variable should not be set directly, but agenda custom commands can
3415 bind it in the options section. The preset filter is a global property of
3416 the entire agenda view. In a block agenda, it will not work reliably to
3417 define a filter for one of the individual blocks. You need to set it in
3418 the global options and expect it to be applied to the entire view.")
3420 (defvar org-agenda-category-filter-preset nil
3421 "A preset of the category filter used for secondary agenda filtering.
3422 This must be a list of strings, each string must be a single category
3423 preceded by \"+\" or \"-\".
3424 This variable should not be set directly, but agenda custom commands can
3425 bind it in the options section. The preset filter is a global property of
3426 the entire agenda view. In a block agenda, it will not work reliably to
3427 define a filter for one of the individual blocks. You need to set it in
3428 the global options and expect it to be applied to the entire view.")
3431 (defun org-agenda-use-sticky-p ()
3432 "Return non-nil if an agenda buffer named
3433 `org-agenda-buffer-name' exists and should be shown instead of
3434 generating a new one."
3435 (and
3436 ;; turned off by user
3437 org-agenda-sticky
3438 ;; For multi-agenda buffer already exists
3439 (not org-agenda-multi)
3440 ;; buffer found
3441 (get-buffer org-agenda-buffer-name)
3442 ;; C-u parameter is same as last call
3443 (with-current-buffer (get-buffer org-agenda-buffer-name)
3444 (and
3445 (equal current-prefix-arg
3446 org-agenda-last-prefix-arg)
3447 ;; In case user turned stickiness on, while having existing
3448 ;; Agenda buffer active, don't reuse that buffer, because it
3449 ;; does not have org variables local
3450 org-agenda-this-buffer-is-sticky))))
3452 (defun org-agenda-prepare-window (abuf)
3453 "Setup agenda buffer in the window."
3454 (let* ((awin (get-buffer-window abuf))
3455 wconf)
3456 (cond
3457 ((equal (current-buffer) abuf) nil)
3458 (awin (select-window awin))
3459 ((not (setq wconf (current-window-configuration))))
3460 ((equal org-agenda-window-setup 'current-window)
3461 (org-pop-to-buffer-same-window abuf))
3462 ((equal org-agenda-window-setup 'other-window)
3463 (org-switch-to-buffer-other-window abuf))
3464 ((equal org-agenda-window-setup 'other-frame)
3465 (switch-to-buffer-other-frame abuf))
3466 ((equal org-agenda-window-setup 'reorganize-frame)
3467 (delete-other-windows)
3468 (org-switch-to-buffer-other-window abuf)))
3469 ;; additional test in case agenda is invoked from within agenda
3470 ;; buffer via elisp link
3471 (unless (equal (current-buffer) abuf)
3472 (org-pop-to-buffer-same-window abuf))
3473 (setq org-agenda-pre-window-conf
3474 (or org-agenda-pre-window-conf wconf))))
3476 (defun org-agenda-prepare (&optional name)
3477 (if (org-agenda-use-sticky-p)
3478 (progn
3479 ;; Popup existing buffer
3480 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3481 (message "Sticky Agenda buffer, use `r' to refresh")
3482 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3483 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3484 (setq org-todo-keywords-for-agenda nil)
3485 (setq org-drawers-for-agenda nil)
3486 (unless org-agenda-persistent-filter
3487 (setq org-agenda-tag-filter nil
3488 org-agenda-category-filter nil))
3489 (put 'org-agenda-tag-filter :preset-filter
3490 org-agenda-tag-filter-preset)
3491 (put 'org-agenda-category-filter :preset-filter
3492 org-agenda-category-filter-preset)
3493 (if org-agenda-multi
3494 (progn
3495 (setq buffer-read-only nil)
3496 (goto-char (point-max))
3497 (unless (or (bobp) org-agenda-compact-blocks
3498 (not org-agenda-block-separator))
3499 (insert "\n"
3500 (if (stringp org-agenda-block-separator)
3501 org-agenda-block-separator
3502 (make-string (window-width) org-agenda-block-separator))
3503 "\n"))
3504 (narrow-to-region (point) (point-max)))
3505 (setq org-done-keywords-for-agenda nil)
3507 ;; Setting any org variables that are in org-agenda-local-vars
3508 ;; list need to be done after the prepare call
3509 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3510 (setq buffer-read-only nil)
3511 (org-agenda-reset-markers)
3512 (let ((inhibit-read-only t)) (erase-buffer))
3513 (org-agenda-mode)
3514 (setq org-agenda-buffer (current-buffer))
3515 (setq org-agenda-contributing-files nil)
3516 (setq org-agenda-columns-active nil)
3517 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3518 (setq org-todo-keywords-for-agenda
3519 (org-uniquify org-todo-keywords-for-agenda))
3520 (setq org-done-keywords-for-agenda
3521 (org-uniquify org-done-keywords-for-agenda))
3522 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3523 (setq org-agenda-last-prefix-arg current-prefix-arg)
3524 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3525 (and name (not org-agenda-name)
3526 (org-set-local 'org-agenda-name name)))
3527 (setq buffer-read-only nil)))
3529 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3530 (defun org-agenda-finalize ()
3531 "Finishing touch for the agenda buffer, called just before displaying it."
3532 (unless org-agenda-multi
3533 (save-excursion
3534 (let ((inhibit-read-only t))
3535 (goto-char (point-min))
3536 (save-excursion
3537 (while (org-activate-bracket-links (point-max))
3538 (add-text-properties (match-beginning 0) (match-end 0)
3539 '(face org-link))))
3540 (save-excursion
3541 (while (org-activate-plain-links (point-max))
3542 (add-text-properties (match-beginning 0) (match-end 0)
3543 '(face org-link))))
3544 (unless (eq org-agenda-remove-tags t)
3545 (org-agenda-align-tags))
3546 (unless org-agenda-with-colors
3547 (remove-text-properties (point-min) (point-max) '(face nil)))
3548 (if (and (boundp 'org-agenda-overriding-columns-format)
3549 org-agenda-overriding-columns-format)
3550 (org-set-local 'org-agenda-overriding-columns-format
3551 org-agenda-overriding-columns-format))
3552 (if (and (boundp 'org-agenda-view-columns-initially)
3553 org-agenda-view-columns-initially)
3554 (org-agenda-columns))
3555 (when org-agenda-fontify-priorities
3556 (org-agenda-fontify-priorities))
3557 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3558 (org-agenda-dim-blocked-tasks))
3559 ;; We need to widen when `org-agenda-finalize' is called from
3560 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3561 (when org-clock-current-task
3562 (save-restriction
3563 (widen)
3564 (org-agenda-mark-clocking-task)))
3565 (when org-agenda-entry-text-mode
3566 (org-agenda-entry-text-hide)
3567 (org-agenda-entry-text-show))
3568 (if (and (functionp 'org-habit-insert-consistency-graphs)
3569 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3570 (org-habit-insert-consistency-graphs))
3571 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3572 (when (delq nil (mapcar (lambda (tp) (org-agenda-check-type nil tp))
3573 org-agenda-use-tag-inheritance))
3574 (let (mrk)
3575 (save-excursion
3576 (goto-char (point-min))
3577 (while (equal (forward-line) 0)
3578 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3579 (get-text-property (point) 'org-hd-marker)))
3580 (put-text-property (point-at-bol) (point-at-eol)
3581 'tags (org-with-point-at mrk
3582 (delete-dups
3583 (mapcar 'downcase (org-get-tags-at))))))))))
3584 (run-hooks 'org-agenda-finalize-hook)
3585 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3586 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3587 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3588 (org-agenda-filter-apply org-agenda-category-filter 'category))
3589 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3591 (defun org-agenda-mark-clocking-task ()
3592 "Mark the current clock entry in the agenda if it is present."
3593 (mapc (lambda (o)
3594 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3595 (delete-overlay o)))
3596 (overlays-in (point-min) (point-max)))
3597 (when (marker-buffer org-clock-hd-marker)
3598 (save-excursion
3599 (goto-char (point-min))
3600 (let (s ov)
3601 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3602 (goto-char s)
3603 (when (equal (org-get-at-bol 'org-hd-marker)
3604 org-clock-hd-marker)
3605 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3606 (overlay-put ov 'type 'org-agenda-clocking)
3607 (overlay-put ov 'face 'org-agenda-clocking)
3608 (overlay-put ov 'help-echo
3609 "The clock is running in this item")))))))
3611 (defun org-agenda-fontify-priorities ()
3612 "Make highest priority lines bold, and lowest italic."
3613 (interactive)
3614 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3615 (delete-overlay o)))
3616 (overlays-in (point-min) (point-max)))
3617 (save-excursion
3618 (let ((inhibit-read-only t)
3619 b e p ov h l)
3620 (goto-char (point-min))
3621 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3622 (setq h (or (get-char-property (point) 'org-highest-priority)
3623 org-highest-priority)
3624 l (or (get-char-property (point) 'org-lowest-priority)
3625 org-lowest-priority)
3626 p (string-to-char (match-string 1))
3627 b (match-beginning 0)
3628 e (if (eq org-agenda-fontify-priorities 'cookies)
3629 (match-end 0)
3630 (point-at-eol))
3631 ov (make-overlay b e))
3632 (overlay-put
3633 ov 'face
3634 (cond ((org-face-from-face-or-color
3635 'priority nil
3636 (cdr (assoc p org-priority-faces))))
3637 ((and (listp org-agenda-fontify-priorities)
3638 (org-face-from-face-or-color
3639 'priority nil
3640 (cdr (assoc p org-agenda-fontify-priorities)))))
3641 ((equal p l) 'italic)
3642 ((equal p h) 'bold)))
3643 (overlay-put ov 'org-type 'org-priority)))))
3645 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3646 (interactive "P")
3647 "Dim currently blocked TODO's in the agenda display."
3648 (message "Dim or hide blocked tasks...")
3649 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3650 (delete-overlay o)))
3651 (overlays-in (point-min) (point-max)))
3652 (save-excursion
3653 (let ((inhibit-read-only t)
3654 (org-depend-tag-blocked nil)
3655 (invis (or (not (null invisible))
3656 (eq org-agenda-dim-blocked-tasks 'invisible)))
3657 org-blocked-by-checkboxes
3658 invis1 b e p ov h l)
3659 (goto-char (point-min))
3660 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3661 (and pos (goto-char (1+ pos))))
3662 (setq org-blocked-by-checkboxes nil invis1 invis)
3663 (let ((marker (org-get-at-bol 'org-hd-marker)))
3664 (when (and marker
3665 (with-current-buffer (marker-buffer marker)
3666 (save-excursion (goto-char marker)
3667 (org-entry-blocked-p))))
3668 (if org-blocked-by-checkboxes (setq invis1 nil))
3669 (setq b (if invis1
3670 (max (point-min) (1- (point-at-bol)))
3671 (point-at-bol))
3672 e (point-at-eol)
3673 ov (make-overlay b e))
3674 (if invis1
3675 (overlay-put ov 'invisible t)
3676 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3677 (overlay-put ov 'org-type 'org-blocked-todo))))))
3678 (message "Dim or hide blocked tasks...done"))
3680 (defvar org-agenda-skip-function nil
3681 "Function to be called at each match during agenda construction.
3682 If this function returns nil, the current match should not be skipped.
3683 Otherwise, the function must return a position from where the search
3684 should be continued.
3685 This may also be a Lisp form, it will be evaluated.
3686 Never set this variable using `setq' or so, because then it will apply
3687 to all future agenda commands. If you do want a global skipping condition,
3688 use the option `org-agenda-skip-function-global' instead.
3689 The correct usage for `org-agenda-skip-function' is to bind it with
3690 `let' to scope it dynamically into the agenda-constructing command.
3691 A good way to set it is through options in `org-agenda-custom-commands'.")
3693 (defun org-agenda-skip ()
3694 "Throw to `:skip' in places that should be skipped.
3695 Also moves point to the end of the skipped region, so that search can
3696 continue from there."
3697 (let ((p (point-at-bol)) to)
3698 (when (org-in-src-block-p t) (throw :skip t))
3699 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3700 (get-text-property p :org-archived)
3701 (org-end-of-subtree t)
3702 (throw :skip t))
3703 (and org-agenda-skip-comment-trees
3704 (get-text-property p :org-comment)
3705 (org-end-of-subtree t)
3706 (throw :skip t))
3707 (if (equal (char-after p) ?#) (throw :skip t))
3708 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3709 (org-agenda-skip-eval org-agenda-skip-function)))
3710 (goto-char to)
3711 (throw :skip t))))
3713 (defun org-agenda-skip-eval (form)
3714 "If FORM is a function or a list, call (or eval) is and return result.
3715 `save-excursion' and `save-match-data' are wrapped around the call, so point
3716 and match data are returned to the previous state no matter what these
3717 functions do."
3718 (let (fp)
3719 (and form
3720 (or (setq fp (functionp form))
3721 (consp form))
3722 (save-excursion
3723 (save-match-data
3724 (if fp
3725 (funcall form)
3726 (eval form)))))))
3728 (defvar org-agenda-markers nil
3729 "List of all currently active markers created by `org-agenda'.")
3730 (defvar org-agenda-last-marker-time (org-float-time)
3731 "Creation time of the last agenda marker.")
3733 (defun org-agenda-new-marker (&optional pos)
3734 "Return a new agenda marker.
3735 Org-mode keeps a list of these markers and resets them when they are
3736 no longer in use."
3737 (let ((m (copy-marker (or pos (point)))))
3738 (setq org-agenda-last-marker-time (org-float-time))
3739 (if org-agenda-buffer
3740 (with-current-buffer org-agenda-buffer
3741 (push m org-agenda-markers))
3742 (push m org-agenda-markers))
3745 (defun org-agenda-reset-markers ()
3746 "Reset markers created by `org-agenda'."
3747 (while org-agenda-markers
3748 (move-marker (pop org-agenda-markers) nil)))
3750 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3751 "Save relative positions of markers in region.
3752 This check for agenda markers in all agenda buffers currently active."
3753 (dolist (buf (buffer-list))
3754 (with-current-buffer buf
3755 (when (eq major-mode 'org-agenda-mode)
3756 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3757 org-agenda-markers)))))
3759 ;;; Entry text mode
3761 (defun org-agenda-entry-text-show-here ()
3762 "Add some text from the entry as context to the current line."
3763 (let (m txt o)
3764 (setq m (org-get-at-bol 'org-hd-marker))
3765 (unless (marker-buffer m)
3766 (error "No marker points to an entry here"))
3767 (setq txt (concat "\n" (org-no-properties
3768 (org-agenda-get-some-entry-text
3769 m org-agenda-entry-text-maxlines " > "))))
3770 (when (string-match "\\S-" txt)
3771 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3772 (overlay-put o 'evaporate t)
3773 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3774 (overlay-put o 'after-string txt))))
3776 (defun org-agenda-entry-text-show ()
3777 "Add entry context for all agenda lines."
3778 (interactive)
3779 (save-excursion
3780 (goto-char (point-max))
3781 (beginning-of-line 1)
3782 (while (not (bobp))
3783 (when (org-get-at-bol 'org-hd-marker)
3784 (org-agenda-entry-text-show-here))
3785 (beginning-of-line 0))))
3787 (defun org-agenda-entry-text-hide ()
3788 "Remove any shown entry context."
3789 (delq nil
3790 (mapcar (lambda (o)
3791 (if (eq (overlay-get o 'org-overlay-type)
3792 'agenda-entry-content)
3793 (progn (delete-overlay o) t)))
3794 (overlays-in (point-min) (point-max)))))
3796 (defun org-agenda-get-day-face (date)
3797 "Return the face DATE should be displayed with."
3798 (or (and (functionp org-agenda-day-face-function)
3799 (funcall org-agenda-day-face-function date))
3800 (cond ((org-agenda-todayp date)
3801 'org-agenda-date-today)
3802 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3803 'org-agenda-date-weekend)
3804 (t 'org-agenda-date))))
3806 ;;; Agenda timeline
3808 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3810 (defun org-timeline (&optional dotodo)
3811 "Show a time-sorted view of the entries in the current org file.
3812 Only entries with a time stamp of today or later will be listed. With
3813 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3814 under the current date.
3815 If the buffer contains an active region, only check the region for
3816 dates."
3817 (interactive "P")
3818 (let* ((dopast t)
3819 (org-agenda-show-log-scoped org-agenda-show-log)
3820 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3821 (current-buffer))))
3822 (date (calendar-current-date))
3823 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3824 (end (if (org-region-active-p) (region-end) (point-max)))
3825 (day-numbers (org-get-all-dates
3826 beg end 'no-ranges
3827 t org-agenda-show-log-scoped ; always include today
3828 org-timeline-show-empty-dates))
3829 (org-deadline-warning-days 0)
3830 (org-agenda-only-exact-dates t)
3831 (today (org-today))
3832 (past t)
3833 args
3834 s e rtn d emptyp)
3835 (setq org-agenda-redo-command
3836 (list 'progn
3837 (list 'org-switch-to-buffer-other-window (current-buffer))
3838 (list 'org-timeline (list 'quote dotodo))))
3839 (if (not dopast)
3840 ;; Remove past dates from the list of dates.
3841 (setq day-numbers (delq nil (mapcar (lambda(x)
3842 (if (>= x today) x nil))
3843 day-numbers))))
3844 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3845 (org-compile-prefix-format 'timeline)
3846 (org-set-sorting-strategy 'timeline)
3847 (if org-agenda-show-log-scoped (push :closed args))
3848 (push :timestamp args)
3849 (push :deadline args)
3850 (push :scheduled args)
3851 (push :sexp args)
3852 (if dotodo (push :todo args))
3853 (insert "Timeline of file " entry "\n")
3854 (add-text-properties (point-min) (point)
3855 (list 'face 'org-agenda-structure))
3856 (org-agenda-mark-header-line (point-min))
3857 (while (setq d (pop day-numbers))
3858 (if (and (listp d) (eq (car d) :omitted))
3859 (progn
3860 (setq s (point))
3861 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3862 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3863 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3864 (if (and (>= d today)
3865 dopast
3866 past)
3867 (progn
3868 (setq past nil)
3869 (insert (make-string 79 ?-) "\n")))
3870 (setq date (calendar-gregorian-from-absolute d))
3871 (setq s (point))
3872 (setq rtn (and (not emptyp)
3873 (apply 'org-agenda-get-day-entries entry
3874 date args)))
3875 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3876 (progn
3877 (insert
3878 (if (stringp org-agenda-format-date)
3879 (format-time-string org-agenda-format-date
3880 (org-time-from-absolute date))
3881 (funcall org-agenda-format-date date))
3882 "\n")
3883 (put-text-property s (1- (point)) 'face
3884 (org-agenda-get-day-face date))
3885 (put-text-property s (1- (point)) 'org-date-line t)
3886 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3887 (if (equal d today)
3888 (put-text-property s (1- (point)) 'org-today t))
3889 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3890 (put-text-property s (1- (point)) 'day d)))))
3891 (goto-char (point-min))
3892 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3893 (point-min)))
3894 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3895 (org-agenda-finalize)
3896 (setq buffer-read-only t)))
3898 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3899 "Return a list of all relevant day numbers from BEG to END buffer positions.
3900 If NO-RANGES is non-nil, include only the start and end dates of a range,
3901 not every single day in the range. If FORCE-TODAY is non-nil, make
3902 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3903 inactive time stamps (those in square brackets) are included.
3904 When EMPTY is non-nil, also include days without any entries."
3905 (let ((re (concat
3906 (if pre-re pre-re "")
3907 (if inactive org-ts-regexp-both org-ts-regexp)))
3908 dates dates1 date day day1 day2 ts1 ts2 pos)
3909 (if force-today
3910 (setq dates (list (org-today))))
3911 (save-excursion
3912 (goto-char beg)
3913 (while (re-search-forward re end t)
3914 (setq day (time-to-days (org-time-string-to-time
3915 (substring (match-string 1) 0 10)
3916 (current-buffer) (match-beginning 0))))
3917 (or (memq day dates) (push day dates)))
3918 (unless no-ranges
3919 (goto-char beg)
3920 (while (re-search-forward org-tr-regexp end t)
3921 (setq pos (match-beginning 0))
3922 (setq ts1 (substring (match-string 1) 0 10)
3923 ts2 (substring (match-string 2) 0 10)
3924 day1 (time-to-days (org-time-string-to-time
3925 ts1 (current-buffer) pos))
3926 day2 (time-to-days (org-time-string-to-time
3927 ts2 (current-buffer) pos)))
3928 (while (< (setq day1 (1+ day1)) day2)
3929 (or (memq day1 dates) (push day1 dates)))))
3930 (setq dates (sort dates '<))
3931 (when empty
3932 (while (setq day (pop dates))
3933 (setq day2 (car dates))
3934 (push day dates1)
3935 (when (and day2 empty)
3936 (if (or (eq empty t)
3937 (and (numberp empty) (<= (- day2 day) empty)))
3938 (while (< (setq day (1+ day)) day2)
3939 (push (list day) dates1))
3940 (push (cons :omitted (- day2 day)) dates1))))
3941 (setq dates (nreverse dates1)))
3942 dates)))
3944 ;;; Agenda Daily/Weekly
3946 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3947 "Start day for the agenda view.
3948 Custom commands can set this variable in the options section.")
3949 (defvar org-starting-day nil) ; local variable in the agenda buffer
3950 (defvar org-arg-loc nil) ; local variable
3952 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3953 "List of types searched for when creating the daily/weekly agenda.
3954 This variable is a list of symbols that controls the types of
3955 items that appear in the daily/weekly agenda. Allowed symbols in this
3956 list are are
3958 :timestamp List items containing a date stamp or date range matching
3959 the selected date. This includes sexp entries in
3960 angular brackets.
3962 :sexp List entries resulting from plain diary-like sexps.
3964 :deadline List deadline due on that date. When the date is today,
3965 also list any deadlines past due, or due within
3966 `org-deadline-warning-days'. `:deadline' must appear before
3967 `:scheduled' if the setting of
3968 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3969 any effect.
3971 :scheduled List all items which are scheduled for the given date.
3972 The diary for *today* also contains items which were
3973 scheduled earlier and are not yet marked DONE.
3975 By default, all four types are turned on.
3977 Never set this variable globally using `setq', because then it
3978 will apply to all future agenda commands. Instead, bind it with
3979 `let' to scope it dynamically into the agenda-constructing
3980 command. A good way to set it is through options in
3981 `org-agenda-custom-commands'. For a more flexible (though
3982 somewhat less efficient) way of determining what is included in
3983 the daily/weekly agenda, see `org-agenda-skip-function'.")
3985 (defvar org-agenda-buffer-tmp-name nil)
3986 ;;;###autoload
3987 (defun org-agenda-list (&optional arg start-day span)
3988 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3989 The view will be for the current day or week, but from the overview buffer
3990 you will be able to go to other days/weeks.
3992 With a numeric prefix argument in an interactive call, the agenda will
3993 span ARG days. Lisp programs should instead specify SPAN to change
3994 the number of days. SPAN defaults to `org-agenda-span'.
3996 START-DAY defaults to TODAY, or to the most recent match for the weekday
3997 given in `org-agenda-start-on-weekday'."
3998 (interactive "P")
3999 (if org-agenda-overriding-arguments
4000 (setq arg (car org-agenda-overriding-arguments)
4001 start-day (nth 1 org-agenda-overriding-arguments)
4002 span (nth 2 org-agenda-overriding-arguments)))
4003 (if (and (integerp arg) (> arg 0))
4004 (setq span arg arg nil))
4005 (catch 'exit
4006 (setq org-agenda-buffer-name
4007 (or org-agenda-buffer-tmp-name
4008 (if org-agenda-sticky
4009 (cond ((and org-keys (stringp org-match))
4010 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4011 (org-keys
4012 (format "*Org Agenda(%s)*" org-keys))
4013 (t "*Org Agenda(a)*")))
4014 org-agenda-buffer-name))
4015 (org-agenda-prepare "Day/Week")
4016 (setq start-day (or start-day org-agenda-start-day))
4017 (if (stringp start-day)
4018 ;; Convert to an absolute day number
4019 (setq start-day (time-to-days (org-read-date nil t start-day))))
4020 (org-compile-prefix-format 'agenda)
4021 (org-set-sorting-strategy 'agenda)
4022 (let* ((span (org-agenda-ndays-to-span
4023 (or span org-agenda-ndays org-agenda-span)))
4024 (today (org-today))
4025 (sd (or start-day today))
4026 (ndays (org-agenda-span-to-ndays span sd))
4027 (org-agenda-start-on-weekday
4028 (if (eq ndays 7)
4029 org-agenda-start-on-weekday))
4030 (thefiles (org-agenda-files nil 'ifmode))
4031 (files thefiles)
4032 (start (if (or (null org-agenda-start-on-weekday)
4033 (< ndays 7))
4035 (let* ((nt (calendar-day-of-week
4036 (calendar-gregorian-from-absolute sd)))
4037 (n1 org-agenda-start-on-weekday)
4038 (d (- nt n1)))
4039 (- sd (+ (if (< d 0) 7 0) d)))))
4040 (day-numbers (list start))
4041 (day-cnt 0)
4042 (inhibit-redisplay (not debug-on-error))
4043 (org-agenda-show-log-scoped org-agenda-show-log)
4044 s e rtn rtnall file date d start-pos end-pos todayp
4045 clocktable-start clocktable-end filter)
4046 (setq org-agenda-redo-command
4047 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4048 (dotimes (n (1- ndays))
4049 (push (1+ (car day-numbers)) day-numbers))
4050 (setq day-numbers (nreverse day-numbers))
4051 (setq clocktable-start (car day-numbers)
4052 clocktable-end (1+ (or (org-last day-numbers) 0)))
4053 (org-set-local 'org-starting-day (car day-numbers))
4054 (org-set-local 'org-arg-loc arg)
4055 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4056 (unless org-agenda-compact-blocks
4057 (let* ((d1 (car day-numbers))
4058 (d2 (org-last day-numbers))
4059 (w1 (org-days-to-iso-week d1))
4060 (w2 (org-days-to-iso-week d2)))
4061 (setq s (point))
4062 (if org-agenda-overriding-header
4063 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4064 nil 'face 'org-agenda-structure) "\n")
4065 (insert (org-agenda-span-name span)
4066 "-agenda"
4067 (if (< (- d2 d1) 350)
4068 (if (= w1 w2)
4069 (format " (W%02d)" w1)
4070 (format " (W%02d-W%02d)" w1 w2))
4072 ":\n")))
4073 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4074 'org-date-line t))
4075 (org-agenda-mark-header-line s))
4076 (while (setq d (pop day-numbers))
4077 (setq date (calendar-gregorian-from-absolute d)
4078 s (point))
4079 (if (or (setq todayp (= d today))
4080 (and (not start-pos) (= d sd)))
4081 (setq start-pos (point))
4082 (if (and start-pos (not end-pos))
4083 (setq end-pos (point))))
4084 (setq files thefiles
4085 rtnall nil)
4086 (while (setq file (pop files))
4087 (catch 'nextfile
4088 (org-check-agenda-file file)
4089 (let ((org-agenda-entry-types org-agenda-entry-types))
4090 (unless org-agenda-include-deadlines
4091 (setq org-agenda-entry-types
4092 (delq :deadline org-agenda-entry-types)))
4093 (cond
4094 ((memq org-agenda-show-log-scoped '(only clockcheck))
4095 (setq rtn (org-agenda-get-day-entries
4096 file date :closed)))
4097 (org-agenda-show-log-scoped
4098 (setq rtn (apply 'org-agenda-get-day-entries
4099 file date
4100 (append '(:closed) org-agenda-entry-types))))
4102 (setq rtn (apply 'org-agenda-get-day-entries
4103 file date
4104 org-agenda-entry-types)))))
4105 (setq rtnall (append rtnall rtn)))) ;; all entries
4106 (if org-agenda-include-diary
4107 (let ((org-agenda-search-headline-for-time t))
4108 (require 'diary-lib)
4109 (setq rtn (org-get-entries-from-diary date))
4110 (setq rtnall (append rtnall rtn))))
4111 (if (or rtnall org-agenda-show-all-dates)
4112 (progn
4113 (setq day-cnt (1+ day-cnt))
4114 (insert
4115 (if (stringp org-agenda-format-date)
4116 (format-time-string org-agenda-format-date
4117 (org-time-from-absolute date))
4118 (funcall org-agenda-format-date date))
4119 "\n")
4120 (put-text-property s (1- (point)) 'face
4121 (org-agenda-get-day-face date))
4122 (put-text-property s (1- (point)) 'org-date-line t)
4123 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4124 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4125 (when todayp
4126 (put-text-property s (1- (point)) 'org-today t))
4127 (setq rtnall
4128 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4129 (if rtnall (insert ;; all entries
4130 (org-agenda-finalize-entries rtnall)
4131 "\n"))
4132 (put-text-property s (1- (point)) 'day d)
4133 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4134 (when (and org-agenda-clockreport-mode clocktable-start)
4135 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4136 ;; the above line is to ensure the restricted range!
4137 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4138 tbl)
4139 (setq p (org-plist-delete p :block))
4140 (setq p (plist-put p :tstart clocktable-start))
4141 (setq p (plist-put p :tend clocktable-end))
4142 (setq p (plist-put p :scope 'agenda))
4143 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4144 (setq filter (or org-agenda-tag-filter-while-redo
4145 (get 'org-agenda-tag-filter :preset-filter))))
4146 (setq p (plist-put p :tags (mapconcat (lambda (x)
4147 (if (string-match "[<>=]" x)
4150 filter ""))))
4151 (setq tbl (apply 'org-clock-get-clocktable p))
4152 (insert tbl)))
4153 (goto-char (point-min))
4154 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4155 (unless (and (pos-visible-in-window-p (point-min))
4156 (pos-visible-in-window-p (point-max)))
4157 (goto-char (1- (point-max)))
4158 (recenter -1)
4159 (if (not (pos-visible-in-window-p (or start-pos 1)))
4160 (progn
4161 (goto-char (or start-pos 1))
4162 (recenter 1))))
4163 (goto-char (or start-pos 1))
4164 (add-text-properties (point-min) (point-max)
4165 `(org-agenda-type agenda
4166 org-last-args (,arg ,start-day ,span)
4167 org-redo-cmd ,org-agenda-redo-command
4168 org-series-cmd ,org-cmd))
4169 (if (eq org-agenda-show-log-scoped 'clockcheck)
4170 (org-agenda-show-clocking-issues))
4171 (org-agenda-finalize)
4172 (setq buffer-read-only t)
4173 (message ""))))
4175 (autoload 'org-agenda-list "org-agenda" "\
4176 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4177 The view will be for the current day or week, but from the overview buffer
4178 you will be able to go to other days/weeks.
4180 With a numeric prefix argument in an interactive call, the agenda will
4181 span ARG days. Lisp programs should instead specify SPAN to change
4182 the number of days. SPAN defaults to `org-agenda-span'.
4184 START-DAY defaults to TODAY, or to the most recent match for the weekday
4185 given in `org-agenda-start-on-weekday'.
4187 \(fn &optional ARG START-DAY SPAN)" t nil)
4189 (defun org-agenda-ndays-to-span (n)
4190 "Return a span symbol for a span of N days, or N if none matches."
4191 (cond ((symbolp n) n)
4192 ((= n 1) 'day)
4193 ((= n 7) 'week)
4194 (t n)))
4196 (defun org-agenda-span-to-ndays (span &optional start-day)
4197 "Return ndays from SPAN, possibly starting at START-DAY."
4198 (cond ((numberp span) span)
4199 ((eq span 'day) 1)
4200 ((eq span 'week) 7)
4201 ((eq span 'month)
4202 (let ((date (calendar-gregorian-from-absolute start-day)))
4203 (calendar-last-day-of-month (car date) (caddr date))))
4204 ((eq span 'year)
4205 (let ((date (calendar-gregorian-from-absolute start-day)))
4206 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4208 (defun org-agenda-span-name (span)
4209 "Return a SPAN name."
4210 (if (null span)
4212 (if (symbolp span)
4213 (capitalize (symbol-name span))
4214 (format "%d days" span))))
4216 ;;; Agenda word search
4218 (defvar org-agenda-search-history nil)
4220 (defvar org-search-syntax-table nil
4221 "Special syntax table for org-mode search.
4222 In this table, we have single quotes not as word constituents, to
4223 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4225 (defvar org-mode-syntax-table) ; From org.el
4226 (defun org-search-syntax-table ()
4227 (unless org-search-syntax-table
4228 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4229 (modify-syntax-entry ?' "." org-search-syntax-table)
4230 (modify-syntax-entry ?` "." org-search-syntax-table))
4231 org-search-syntax-table)
4233 (defvar org-agenda-last-search-view-search-was-boolean nil)
4235 ;;;###autoload
4236 (defun org-search-view (&optional todo-only string edit-at)
4237 "Show all entries that contain a phrase or words or regular expressions.
4239 With optional prefix argument TODO-ONLY, only consider entries that are
4240 TODO entries. The argument STRING can be used to pass a default search
4241 string into this function. If EDIT-AT is non-nil, it means that the
4242 user should get a chance to edit this string, with cursor at position
4243 EDIT-AT.
4245 The search string can be viewed either as a phrase that should be found as
4246 is, or it can be broken into a number of snippets, each of which must match
4247 in a Boolean way to select an entry. The default depends on the variable
4248 `org-agenda-search-view-always-boolean'.
4249 Even if this is turned off (the default) you can always switch to
4250 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4252 The default is a direct search of the whole phrase, where each space in
4253 the search string can expand to an arbitrary amount of whitespace,
4254 including newlines.
4256 If using a Boolean search, the search string is split on whitespace and
4257 each snippet is searched separately, with logical AND to select an entry.
4258 Words prefixed with a minus must *not* occur in the entry. Words without
4259 a prefix or prefixed with a plus must occur in the entry. Matching is
4260 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4261 match whole words, not parts of a word) if
4262 `org-agenda-search-view-force-full-words' is set (default is nil).
4264 Boolean search snippets enclosed by curly braces are interpreted as
4265 regular expressions that must or (when preceded with \"-\") must not
4266 match in the entry. Snippets enclosed into double quotes will be taken
4267 as a whole, to include whitespace.
4269 - If the search string starts with an asterisk, search only in headlines.
4270 - If (possibly after the leading star) the search string starts with an
4271 exclamation mark, this also means to look at TODO entries only, an effect
4272 that can also be achieved with a prefix argument.
4273 - If (possibly after star and exclamation mark) the search string starts
4274 with a colon, this will mean that the (non-regexp) snippets of the
4275 Boolean search must match as full words.
4277 This command searches the agenda files, and in addition the files listed
4278 in `org-agenda-text-search-extra-files'."
4279 (interactive "P")
4280 (if org-agenda-overriding-arguments
4281 (setq todo-only (car org-agenda-overriding-arguments)
4282 string (nth 1 org-agenda-overriding-arguments)
4283 edit-at (nth 2 org-agenda-overriding-arguments)))
4284 (let* ((props (list 'face nil
4285 'done-face 'org-agenda-done
4286 'org-not-done-regexp org-not-done-regexp
4287 'org-todo-regexp org-todo-regexp
4288 'org-complex-heading-regexp org-complex-heading-regexp
4289 'mouse-face 'highlight
4290 'help-echo (format "mouse-2 or RET jump to location")))
4291 (full-words org-agenda-search-view-force-full-words)
4292 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4293 regexp rtn rtnall files file pos
4294 marker category category-pos tags c neg re boolean
4295 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4296 (unless (and (not edit-at)
4297 (stringp string)
4298 (string-match "\\S-" string))
4299 (setq string (read-string
4300 (if org-agenda-search-view-always-boolean
4301 "[+-]Word/{Regexp} ...: "
4302 "Phrase or [+-]Word/{Regexp} ...: ")
4303 (cond
4304 ((integerp edit-at) (cons string edit-at))
4305 (edit-at string))
4306 'org-agenda-search-history)))
4307 (catch 'exit
4308 (if org-agenda-sticky
4309 (setq org-agenda-buffer-name
4310 (if (stringp string)
4311 (format "*Org Agenda(%s:%s)*"
4312 (or org-keys (or (and todo-only "S") "s")) string)
4313 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4314 (org-agenda-prepare "SEARCH")
4315 (org-compile-prefix-format 'search)
4316 (org-set-sorting-strategy 'search)
4317 (setq org-agenda-redo-command
4318 (list 'org-search-view (if todo-only t nil)
4319 (list 'if 'current-prefix-arg nil string)))
4320 (setq org-agenda-query-string string)
4321 (if (equal (string-to-char string) ?*)
4322 (setq hdl-only t
4323 words (substring string 1))
4324 (setq words string))
4325 (when (equal (string-to-char words) ?!)
4326 (setq todo-only t
4327 words (substring words 1)))
4328 (when (equal (string-to-char words) ?:)
4329 (setq full-words t
4330 words (substring words 1)))
4331 (if (or org-agenda-search-view-always-boolean
4332 (member (string-to-char words) '(?- ?+ ?\{)))
4333 (setq boolean t))
4334 (setq words (org-split-string words))
4335 (let (www w)
4336 (while (setq w (pop words))
4337 (while (and (string-match "\\\\\\'" w) words)
4338 (setq w (concat (substring w 0 -1) " " (pop words))))
4339 (push w www))
4340 (setq words (nreverse www) www nil)
4341 (while (setq w (pop words))
4342 (when (and (string-match "\\`[-+]?{" w)
4343 (not (string-match "}\\'" w)))
4344 (while (and words (not (string-match "}\\'" (car words))))
4345 (setq w (concat w " " (pop words))))
4346 (setq w (concat w " " (pop words))))
4347 (push w www))
4348 (setq words (nreverse www)))
4349 (setq org-agenda-last-search-view-search-was-boolean boolean)
4350 (when boolean
4351 (let (wds w)
4352 (while (setq w (pop words))
4353 (if (or (equal (substring w 0 1) "\"")
4354 (and (> (length w) 1)
4355 (member (substring w 0 1) '("+" "-"))
4356 (equal (substring w 1 2) "\"")))
4357 (while (and words (not (equal (substring w -1) "\"")))
4358 (setq w (concat w " " (pop words)))))
4359 (and (string-match "\\`\\([-+]?\\)\"" w)
4360 (setq w (replace-match "\\1" nil nil w)))
4361 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4362 (push w wds))
4363 (setq words (nreverse wds))))
4364 (if boolean
4365 (mapc (lambda (w)
4366 (setq c (string-to-char w))
4367 (if (equal c ?-)
4368 (setq neg t w (substring w 1))
4369 (if (equal c ?+)
4370 (setq neg nil w (substring w 1))
4371 (setq neg nil)))
4372 (if (string-match "\\`{.*}\\'" w)
4373 (setq re (substring w 1 -1))
4374 (if full-words
4375 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4376 (setq re (regexp-quote (downcase w)))))
4377 (if neg (push re regexps-) (push re regexps+)))
4378 words)
4379 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4380 regexps+))
4381 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4382 (if (not regexps+)
4383 (setq regexp org-outline-regexp-bol)
4384 (setq regexp (pop regexps+))
4385 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4386 regexp))))
4387 (setq files (org-agenda-files nil 'ifmode))
4388 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4389 (pop org-agenda-text-search-extra-files)
4390 (setq files (org-add-archive-files files)))
4391 (setq files (append files org-agenda-text-search-extra-files)
4392 rtnall nil)
4393 (while (setq file (pop files))
4394 (setq ee nil)
4395 (catch 'nextfile
4396 (org-check-agenda-file file)
4397 (setq buffer (if (file-exists-p file)
4398 (org-get-agenda-file-buffer file)
4399 (error "No such file %s" file)))
4400 (if (not buffer)
4401 ;; If file does not exist, make sure an error message is sent
4402 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4403 file))))
4404 (with-current-buffer buffer
4405 (with-syntax-table (org-search-syntax-table)
4406 (unless (derived-mode-p 'org-mode)
4407 (error "Agenda file %s is not in `org-mode'" file))
4408 (let ((case-fold-search t))
4409 (save-excursion
4410 (save-restriction
4411 (if org-agenda-restrict
4412 (narrow-to-region org-agenda-restrict-begin
4413 org-agenda-restrict-end)
4414 (widen))
4415 (goto-char (point-min))
4416 (unless (or (org-at-heading-p)
4417 (outline-next-heading))
4418 (throw 'nextfile t))
4419 (goto-char (max (point-min) (1- (point))))
4420 (while (re-search-forward regexp nil t)
4421 (org-back-to-heading t)
4422 (skip-chars-forward "* ")
4423 (setq beg (point-at-bol)
4424 beg1 (point)
4425 end (progn (outline-next-heading) (point)))
4426 (catch :skip
4427 (goto-char beg)
4428 (org-agenda-skip)
4429 (setq str (buffer-substring-no-properties
4430 (point-at-bol)
4431 (if hdl-only (point-at-eol) end)))
4432 (mapc (lambda (wr) (when (string-match wr str)
4433 (goto-char (1- end))
4434 (throw :skip t)))
4435 regexps-)
4436 (mapc (lambda (wr) (unless (string-match wr str)
4437 (goto-char (1- end))
4438 (throw :skip t)))
4439 (if todo-only
4440 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4441 regexps+)
4442 regexps+))
4443 (goto-char beg)
4444 (setq marker (org-agenda-new-marker (point))
4445 category (org-get-category)
4446 category-pos (get-text-property (point) 'org-category-position)
4447 tags (org-get-tags-at nil t)
4448 txt (org-agenda-format-item
4450 (buffer-substring-no-properties
4451 beg1 (point-at-eol))
4452 category tags t))
4453 (org-add-props txt props
4454 'org-marker marker 'org-hd-marker marker
4455 'org-todo-regexp org-todo-regexp
4456 'org-complex-heading-regexp org-complex-heading-regexp
4457 'priority 1000 'org-category category
4458 'org-category-position category-pos
4459 'type "search")
4460 (push txt ee)
4461 (goto-char (1- end))))))))))
4462 (setq rtn (nreverse ee))
4463 (setq rtnall (append rtnall rtn)))
4464 (if org-agenda-overriding-header
4465 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4466 nil 'face 'org-agenda-structure) "\n")
4467 (insert "Search words: ")
4468 (add-text-properties (point-min) (1- (point))
4469 (list 'face 'org-agenda-structure))
4470 (setq pos (point))
4471 (insert string "\n")
4472 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4473 (setq pos (point))
4474 (unless org-agenda-multi
4475 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4476 (add-text-properties pos (1- (point))
4477 (list 'face 'org-agenda-structure))))
4478 (org-agenda-mark-header-line (point-min))
4479 (when rtnall
4480 (insert (org-agenda-finalize-entries rtnall) "\n"))
4481 (goto-char (point-min))
4482 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4483 (add-text-properties (point-min) (point-max)
4484 `(org-agenda-type search
4485 org-last-args (,todo-only ,string ,edit-at)
4486 org-redo-cmd ,org-agenda-redo-command
4487 org-series-cmd ,org-cmd))
4488 (org-agenda-finalize)
4489 (setq buffer-read-only t))))
4491 (autoload 'org-search-view "org-agenda" "\
4492 Show all entries that contain a phrase or words or regular expressions.
4494 With optional prefix argument TODO-ONLY, only consider entries that are
4495 TODO entries. The argument STRING can be used to pass a default search
4496 string into this function. If EDIT-AT is non-nil, it means that the
4497 user should get a chance to edit this string, with cursor at position
4498 EDIT-AT.
4500 The search string can be viewed either as a phrase that should be found as
4501 is, or it can be broken into a number of snippets, each of which must match
4502 in a Boolean way to select an entry. The default depends on the variable
4503 `org-agenda-search-view-always-boolean'.
4504 Even if this is turned off (the default) you can always switch to
4505 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4507 The default is a direct search of the whole phrase, where each space in
4508 the search string can expand to an arbitrary amount of whitespace,
4509 including newlines.
4511 If using a Boolean search, the search string is split on whitespace and
4512 each snippet is searched separately, with logical AND to select an entry.
4513 Words prefixed with a minus must *not* occur in the entry. Words without
4514 a prefix or prefixed with a plus must occur in the entry. Matching is
4515 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4516 match whole words, not parts of a word) if
4517 `org-agenda-search-view-force-full-words' is set (default is nil).
4519 Boolean search snippets enclosed by curly braces are interpreted as
4520 regular expressions that must or (when preceded with \"-\") must not
4521 match in the entry. Snippets enclosed into double quotes will be taken
4522 as a whole, to include whitespace.
4524 - If the search string starts with an asterisk, search only in headlines.
4525 - If (possibly after the leading star) the search string starts with an
4526 exclamation mark, this also means to look at TODO entries only, an effect
4527 that can also be achieved with a prefix argument.
4528 - If (possibly after star and exclamation mark) the search string starts
4529 with a colon, this will mean that the (non-regexp) snippets of the
4530 Boolean search must match as full words.
4532 This command searches the agenda files, and in addition the files listed
4533 in `org-agenda-text-search-extra-files'.
4535 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4537 ;;; Agenda TODO list
4539 (defvar org-select-this-todo-keyword nil)
4540 (defvar org-last-arg nil)
4542 ;;;###autoload
4543 (defun org-todo-list (&optional arg)
4544 "Show all (not done) TODO entries from all agenda file in a single list.
4545 The prefix arg can be used to select a specific TODO keyword and limit
4546 the list to these. When using \\[universal-argument], you will be prompted
4547 for a keyword. A numeric prefix directly selects the Nth keyword in
4548 `org-todo-keywords-1'."
4549 (interactive "P")
4550 (if org-agenda-overriding-arguments
4551 (setq arg org-agenda-overriding-arguments))
4552 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4553 (let* ((today (org-today))
4554 (date (calendar-gregorian-from-absolute today))
4555 (kwds org-todo-keywords-for-agenda)
4556 (completion-ignore-case t)
4557 (org-select-this-todo-keyword
4558 (if (stringp arg) arg
4559 (and arg (integerp arg) (> arg 0)
4560 (nth (1- arg) kwds))))
4561 rtn rtnall files file pos)
4562 (when (equal arg '(4))
4563 (setq org-select-this-todo-keyword
4564 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4565 (mapcar 'list kwds) nil nil)))
4566 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4567 (catch 'exit
4568 (if org-agenda-sticky
4569 (setq org-agenda-buffer-name
4570 (if (stringp org-select-this-todo-keyword)
4571 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4572 org-select-this-todo-keyword)
4573 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4574 (org-agenda-prepare "TODO")
4575 (org-compile-prefix-format 'todo)
4576 (org-set-sorting-strategy 'todo)
4577 (setq org-agenda-redo-command
4578 `(org-todo-list (or (and (numberp current-prefix-arg)
4579 current-prefix-arg)
4580 ,org-select-this-todo-keyword
4581 current-prefix-arg ,arg)))
4582 (setq files (org-agenda-files nil 'ifmode)
4583 rtnall nil)
4584 (while (setq file (pop files))
4585 (catch 'nextfile
4586 (org-check-agenda-file file)
4587 (setq rtn (org-agenda-get-day-entries file date :todo))
4588 (setq rtnall (append rtnall rtn))))
4589 (if org-agenda-overriding-header
4590 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4591 nil 'face 'org-agenda-structure) "\n")
4592 (insert "Global list of TODO items of type: ")
4593 (add-text-properties (point-min) (1- (point))
4594 (list 'face 'org-agenda-structure
4595 'short-heading
4596 (concat "ToDo: "
4597 (or org-select-this-todo-keyword "ALL"))))
4598 (org-agenda-mark-header-line (point-min))
4599 (setq pos (point))
4600 (insert (or org-select-this-todo-keyword "ALL") "\n")
4601 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4602 (setq pos (point))
4603 (unless org-agenda-multi
4604 (insert "Available with `N r': (0)[ALL]")
4605 (let ((n 0) s)
4606 (mapc (lambda (x)
4607 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4608 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4609 (insert "\n "))
4610 (insert " " s))
4611 kwds))
4612 (insert "\n"))
4613 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4614 (org-agenda-mark-header-line (point-min))
4615 (when rtnall
4616 (insert (org-agenda-finalize-entries rtnall) "\n"))
4617 (goto-char (point-min))
4618 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4619 (add-text-properties (point-min) (point-max)
4620 `(org-agenda-type todo
4621 org-last-args ,arg
4622 org-redo-cmd ,org-agenda-redo-command
4623 org-series-cmd ,org-cmd))
4624 (org-agenda-finalize)
4625 (setq buffer-read-only t))))
4627 (autoload 'org-todo-list "org-agenda" "\
4628 Show all (not done) TODO entries from all agenda file in a single list.
4629 The prefix arg can be used to select a specific TODO keyword and limit
4630 the list to these. When using \\[universal-argument], you will be prompted
4631 for a keyword. A numeric prefix directly selects the Nth keyword in
4632 `org-todo-keywords-1'.
4634 \(fn &optional ARG)" t nil)
4636 ;;; Agenda tags match
4638 ;;;###autoload
4639 (defun org-tags-view (&optional todo-only match)
4640 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4641 The prefix arg TODO-ONLY limits the search to TODO entries."
4642 (interactive "P")
4643 (if org-agenda-overriding-arguments
4644 (setq todo-only (car org-agenda-overriding-arguments)
4645 match (nth 1 org-agenda-overriding-arguments)))
4646 (let* ((org-tags-match-list-sublevels
4647 org-tags-match-list-sublevels)
4648 (completion-ignore-case t)
4649 rtn rtnall files file pos matcher
4650 buffer)
4651 (when (and (stringp match) (not (string-match "\\S-" match)))
4652 (setq match nil))
4653 (setq matcher (org-make-tags-matcher match)
4654 match (car matcher) matcher (cdr matcher))
4655 (catch 'exit
4656 (if org-agenda-sticky
4657 (setq org-agenda-buffer-name
4658 (if (stringp match)
4659 (format "*Org Agenda(%s:%s)*"
4660 (or org-keys (or (and todo-only "M") "m")) match)
4661 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4662 (org-agenda-prepare (concat "TAGS " match))
4663 (org-compile-prefix-format 'tags)
4664 (org-set-sorting-strategy 'tags)
4665 (setq org-agenda-query-string match)
4666 (setq org-agenda-redo-command
4667 (list 'org-tags-view `(quote ,todo-only)
4668 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4669 (setq files (org-agenda-files nil 'ifmode)
4670 rtnall nil)
4671 (while (setq file (pop files))
4672 (catch 'nextfile
4673 (org-check-agenda-file file)
4674 (setq buffer (if (file-exists-p file)
4675 (org-get-agenda-file-buffer file)
4676 (error "No such file %s" file)))
4677 (if (not buffer)
4678 ;; If file does not exist, error message to agenda
4679 (setq rtn (list
4680 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4681 rtnall (append rtnall rtn))
4682 (with-current-buffer buffer
4683 (unless (derived-mode-p 'org-mode)
4684 (error "Agenda file %s is not in `org-mode'" file))
4685 (save-excursion
4686 (save-restriction
4687 (if org-agenda-restrict
4688 (narrow-to-region org-agenda-restrict-begin
4689 org-agenda-restrict-end)
4690 (widen))
4691 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4692 (setq rtnall (append rtnall rtn))))))))
4693 (if org-agenda-overriding-header
4694 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4695 nil 'face 'org-agenda-structure) "\n")
4696 (insert "Headlines with TAGS match: ")
4697 (add-text-properties (point-min) (1- (point))
4698 (list 'face 'org-agenda-structure
4699 'short-heading
4700 (concat "Match: " match)))
4701 (setq pos (point))
4702 (insert match "\n")
4703 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4704 (setq pos (point))
4705 (unless org-agenda-multi
4706 (insert "Press `C-u r' to search again with new search string\n"))
4707 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4708 (org-agenda-mark-header-line (point-min))
4709 (when rtnall
4710 (insert (org-agenda-finalize-entries rtnall) "\n"))
4711 (goto-char (point-min))
4712 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4713 (add-text-properties (point-min) (point-max)
4714 `(org-agenda-type tags
4715 org-last-args (,todo-only ,match)
4716 org-redo-cmd ,org-agenda-redo-command
4717 org-series-cmd ,org-cmd))
4718 (org-agenda-finalize)
4719 (setq buffer-read-only t))))
4721 (autoload 'org-tags-view "org-agenda" "\
4722 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4723 The prefix arg TODO-ONLY limits the search to TODO entries.
4725 \(fn &optional TODO-ONLY MATCH)" t nil)
4727 ;;; Agenda Finding stuck projects
4729 (defvar org-agenda-skip-regexp nil
4730 "Regular expression used in skipping subtrees for the agenda.
4731 This is basically a temporary global variable that can be set and then
4732 used by user-defined selections using `org-agenda-skip-function'.")
4734 (defvar org-agenda-overriding-header nil
4735 "When set during agenda, todo and tags searches it replaces the header.
4736 This variable should not be set directly, but custom commands can bind it
4737 in the options section.")
4739 (defun org-agenda-skip-entry-when-regexp-matches ()
4740 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4741 If yes, it returns the end position of this entry, causing agenda commands
4742 to skip the entry but continuing the search in the subtree. This is a
4743 function that can be put into `org-agenda-skip-function' for the duration
4744 of a command."
4745 (let ((end (save-excursion (org-end-of-subtree t)))
4746 skip)
4747 (save-excursion
4748 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4749 (and skip end)))
4751 (defun org-agenda-skip-subtree-when-regexp-matches ()
4752 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4753 If yes, it returns the end position of this tree, causing agenda commands
4754 to skip this subtree. This is a function that can be put into
4755 `org-agenda-skip-function' for the duration of a command."
4756 (let ((end (save-excursion (org-end-of-subtree t)))
4757 skip)
4758 (save-excursion
4759 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4760 (and skip end)))
4762 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4763 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4764 If yes, it returns the end position of the current entry (NOT the tree),
4765 causing agenda commands to skip the entry but continuing the search in
4766 the subtree. This is a function that can be put into
4767 `org-agenda-skip-function' for the duration of a command. An important
4768 use of this function is for the stuck project list."
4769 (let ((end (save-excursion (org-end-of-subtree t)))
4770 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4771 skip)
4772 (save-excursion
4773 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4774 (and skip entry-end)))
4776 (defun org-agenda-skip-entry-if (&rest conditions)
4777 "Skip entry if any of CONDITIONS is true.
4778 See `org-agenda-skip-if' for details."
4779 (org-agenda-skip-if nil conditions))
4781 (defun org-agenda-skip-subtree-if (&rest conditions)
4782 "Skip entry if any of CONDITIONS is true.
4783 See `org-agenda-skip-if' for details."
4784 (org-agenda-skip-if t conditions))
4786 (defun org-agenda-skip-if (subtree conditions)
4787 "Checks current entity for CONDITIONS.
4788 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4789 the entry (i.e. the text before the next heading) is checked.
4791 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4792 from different tests. Valid conditions are:
4794 scheduled Check if there is a scheduled cookie
4795 notscheduled Check if there is no scheduled cookie
4796 deadline Check if there is a deadline
4797 notdeadline Check if there is no deadline
4798 timestamp Check if there is a timestamp (also deadline or scheduled)
4799 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4800 regexp Check if regexp matches
4801 notregexp Check if regexp does not match.
4802 todo Check if TODO keyword matches
4803 nottodo Check if TODO keyword does not match
4805 The regexp is taken from the conditions list, it must come right after
4806 the `regexp' or `notregexp' element.
4808 `todo' and `nottodo' accept as an argument a list of todo
4809 keywords, which may include \"*\" to match any todo keyword.
4811 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4813 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4815 Instead of a list, a keyword class may be given. For example:
4817 (org-agenda-skip-entry-if 'nottodo 'done)
4819 would skip entries that haven't been marked with any of \"DONE\"
4820 keywords. Possible classes are: `todo', `done', `any'.
4822 If any of these conditions is met, this function returns the end point of
4823 the entity, causing the search to continue from there. This is a function
4824 that can be put into `org-agenda-skip-function' for the duration of a command."
4825 (let (beg end m)
4826 (org-back-to-heading t)
4827 (setq beg (point)
4828 end (if subtree
4829 (progn (org-end-of-subtree t) (point))
4830 (progn (outline-next-heading) (1- (point)))))
4831 (goto-char beg)
4832 (and
4834 (and (memq 'scheduled conditions)
4835 (re-search-forward org-scheduled-time-regexp end t))
4836 (and (memq 'notscheduled conditions)
4837 (not (re-search-forward org-scheduled-time-regexp end t)))
4838 (and (memq 'deadline conditions)
4839 (re-search-forward org-deadline-time-regexp end t))
4840 (and (memq 'notdeadline conditions)
4841 (not (re-search-forward org-deadline-time-regexp end t)))
4842 (and (memq 'timestamp conditions)
4843 (re-search-forward org-ts-regexp end t))
4844 (and (memq 'nottimestamp conditions)
4845 (not (re-search-forward org-ts-regexp end t)))
4846 (and (setq m (memq 'regexp conditions))
4847 (stringp (nth 1 m))
4848 (re-search-forward (nth 1 m) end t))
4849 (and (setq m (memq 'notregexp conditions))
4850 (stringp (nth 1 m))
4851 (not (re-search-forward (nth 1 m) end t)))
4852 (and (or
4853 (setq m (memq 'nottodo conditions))
4854 (setq m (memq 'todo-unblocked conditions))
4855 (setq m (memq 'nottodo-unblocked conditions))
4856 (setq m (memq 'todo conditions)))
4857 (org-agenda-skip-if-todo m end)))
4858 end)))
4860 (defun org-agenda-skip-if-todo (args end)
4861 "Helper function for `org-agenda-skip-if', do not use it directly.
4862 ARGS is a list with first element either `todo', `nottodo',
4863 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4864 a list of TODO keywords, or a state symbol `todo' or `done' or
4865 `any'."
4866 (let ((kw (car args))
4867 (arg (cadr args))
4868 todo-wds todo-re)
4869 (setq todo-wds
4870 (org-uniquify
4871 (cond
4872 ((listp arg) ;; list of keywords
4873 (if (member "*" arg)
4874 (mapcar 'substring-no-properties org-todo-keywords-1)
4875 arg))
4876 ((symbolp arg) ;; keyword class name
4877 (cond
4878 ((eq arg 'todo)
4879 (org-delete-all org-done-keywords
4880 (mapcar 'substring-no-properties
4881 org-todo-keywords-1)))
4882 ((eq arg 'done) org-done-keywords)
4883 ((eq arg 'any)
4884 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4885 (setq todo-re
4886 (concat "^\\*+[ \t]+\\<\\("
4887 (mapconcat 'identity todo-wds "\\|")
4888 "\\)\\>"))
4889 (cond
4890 ((eq kw 'todo) (re-search-forward todo-re end t))
4891 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4892 ((eq kw 'todo-unblocked)
4893 (catch 'unblocked
4894 (while (re-search-forward todo-re end t)
4895 (or (org-entry-blocked-p) (throw 'unblocked t)))
4896 nil))
4897 ((eq kw 'nottodo-unblocked)
4898 (catch 'unblocked
4899 (while (re-search-forward todo-re end t)
4900 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4904 ;;;###autoload
4905 (defun org-agenda-list-stuck-projects (&rest ignore)
4906 "Create agenda view for projects that are stuck.
4907 Stuck projects are project that have no next actions. For the definitions
4908 of what a project is and how to check if it stuck, customize the variable
4909 `org-stuck-projects'."
4910 (interactive)
4911 (let* ((org-agenda-skip-function
4912 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4913 ;; We could have used org-agenda-skip-if here.
4914 (org-agenda-overriding-header
4915 (or org-agenda-overriding-header "List of stuck projects: "))
4916 (matcher (nth 0 org-stuck-projects))
4917 (todo (nth 1 org-stuck-projects))
4918 (todo-wds (if (member "*" todo)
4919 (progn
4920 (org-agenda-prepare-buffers (org-agenda-files
4921 nil 'ifmode))
4922 (org-delete-all
4923 org-done-keywords-for-agenda
4924 (copy-sequence org-todo-keywords-for-agenda)))
4925 todo))
4926 (todo-re (concat "^\\*+[ \t]+\\("
4927 (mapconcat 'identity todo-wds "\\|")
4928 "\\)\\>"))
4929 (tags (nth 2 org-stuck-projects))
4930 (tags-re (if (member "*" tags)
4931 (concat org-outline-regexp-bol
4932 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4933 (if tags
4934 (concat org-outline-regexp-bol
4935 ".*:\\("
4936 (mapconcat 'identity tags "\\|")
4937 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4938 (gen-re (nth 3 org-stuck-projects))
4939 (re-list
4940 (delq nil
4941 (list
4942 (if todo todo-re)
4943 (if tags tags-re)
4944 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4945 gen-re)))))
4946 (setq org-agenda-skip-regexp
4947 (if re-list
4948 (mapconcat 'identity re-list "\\|")
4949 (error "No information how to identify unstuck projects")))
4950 (org-tags-view nil matcher)
4951 (with-current-buffer org-agenda-buffer-name
4952 (setq org-agenda-redo-command
4953 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4955 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4956 Create agenda view for projects that are stuck.
4957 Stuck projects are project that have no next actions. For the definitions
4958 of what a project is and how to check if it stuck, customize the variable
4959 `org-stuck-projects'.
4961 \(fn &rest IGNORE)" t nil)
4963 ;;; Diary integration
4965 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4966 (defvar diary-list-entries-hook)
4967 (defvar diary-time-regexp)
4968 (defun org-get-entries-from-diary (date)
4969 "Get the (Emacs Calendar) diary entries for DATE."
4970 (require 'diary-lib)
4971 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4972 (diary-display-hook '(fancy-diary-display))
4973 (diary-display-function 'fancy-diary-display)
4974 (pop-up-frames nil)
4975 (diary-list-entries-hook
4976 (cons 'org-diary-default-entry diary-list-entries-hook))
4977 (diary-file-name-prefix-function nil) ; turn this feature off
4978 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4979 entries
4980 (org-disable-agenda-to-diary t))
4981 (save-excursion
4982 (save-window-excursion
4983 (funcall (if (fboundp 'diary-list-entries)
4984 'diary-list-entries 'list-diary-entries)
4985 date 1)))
4986 (if (not (get-buffer diary-fancy-buffer))
4987 (setq entries nil)
4988 (with-current-buffer diary-fancy-buffer
4989 (setq buffer-read-only nil)
4990 (if (zerop (buffer-size))
4991 ;; No entries
4992 (setq entries nil)
4993 ;; Omit the date and other unnecessary stuff
4994 (org-agenda-cleanup-fancy-diary)
4995 ;; Add prefix to each line and extend the text properties
4996 (if (zerop (buffer-size))
4997 (setq entries nil)
4998 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4999 (setq entries
5000 (with-temp-buffer
5001 (insert entries) (goto-char (point-min))
5002 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5003 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5004 (replace-match (concat "; " (match-string 1)))))
5005 (buffer-string)))))
5006 (set-buffer-modified-p nil)
5007 (kill-buffer diary-fancy-buffer)))
5008 (when entries
5009 (setq entries (org-split-string entries "\n"))
5010 (setq entries
5011 (mapcar
5012 (lambda (x)
5013 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
5014 ;; Extend the text properties to the beginning of the line
5015 (org-add-props x (text-properties-at (1- (length x)) x)
5016 'type "diary" 'date date 'face 'org-agenda-diary))
5017 entries)))))
5019 (defvar org-agenda-cleanup-fancy-diary-hook nil
5020 "Hook run when the fancy diary buffer is cleaned up.")
5022 (defun org-agenda-cleanup-fancy-diary ()
5023 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5024 This gets rid of the date, the underline under the date, and
5025 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5026 date. It also removes lines that contain only whitespace."
5027 (goto-char (point-min))
5028 (if (looking-at ".*?:[ \t]*")
5029 (progn
5030 (replace-match "")
5031 (re-search-forward "\n=+$" nil t)
5032 (replace-match "")
5033 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5034 (re-search-forward "\n=+$" nil t)
5035 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5036 (goto-char (point-min))
5037 (while (re-search-forward "^ +\n" nil t)
5038 (replace-match ""))
5039 (goto-char (point-min))
5040 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5041 (replace-match ""))
5042 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5044 ;; Make sure entries from the diary have the right text properties.
5045 (eval-after-load "diary-lib"
5046 '(if (boundp 'diary-modify-entry-list-string-function)
5047 ;; We can rely on the hook, nothing to do
5049 ;; Hook not available, must use advice to make this work
5050 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5051 "Make the position visible."
5052 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5053 (stringp string)
5054 buffer-file-name)
5055 (setq string (org-modify-diary-entry-string string))))))
5057 (defun org-modify-diary-entry-string (string)
5058 "Add text properties to string, allowing org-mode to act on it."
5059 (org-add-props string nil
5060 'mouse-face 'highlight
5061 'help-echo (if buffer-file-name
5062 (format "mouse-2 or RET jump to diary file %s"
5063 (abbreviate-file-name buffer-file-name))
5065 'org-agenda-diary-link t
5066 'org-marker (org-agenda-new-marker (point-at-bol))))
5068 (defun org-diary-default-entry ()
5069 "Add a dummy entry to the diary.
5070 Needed to avoid empty dates which mess up holiday display."
5071 ;; Catch the error if dealing with the new add-to-diary-alist
5072 (when org-disable-agenda-to-diary
5073 (condition-case nil
5074 (org-add-to-diary-list original-date "Org-mode dummy" "")
5075 (error
5076 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5078 (defun org-add-to-diary-list (&rest args)
5079 (if (fboundp 'diary-add-to-list)
5080 (apply 'diary-add-to-list args)
5081 (apply 'add-to-diary-list args)))
5083 (defvar org-diary-last-run-time nil)
5085 ;;;###autoload
5086 (defun org-diary (&rest args)
5087 "Return diary information from org files.
5088 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5089 It accesses org files and extracts information from those files to be
5090 listed in the diary. The function accepts arguments specifying what
5091 items should be listed. For a list of arguments allowed here, see the
5092 variable `org-agenda-entry-types'.
5094 The call in the diary file should look like this:
5096 &%%(org-diary) ~/path/to/some/orgfile.org
5098 Use a separate line for each org file to check. Or, if you omit the file name,
5099 all files listed in `org-agenda-files' will be checked automatically:
5101 &%%(org-diary)
5103 If you don't give any arguments (as in the example above), the default
5104 arguments (:deadline :scheduled :timestamp :sexp) are used.
5105 So the example above may also be written as
5107 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5109 The function expects the lisp variables `entry' and `date' to be provided
5110 by the caller, because this is how the calendar works. Don't use this
5111 function from a program - use `org-agenda-get-day-entries' instead."
5112 (when (> (- (org-float-time)
5113 org-agenda-last-marker-time)
5115 ;; I am not sure if this works with sticky agendas, because the marker
5116 ;; list is then no longer a global variable.
5117 (org-agenda-reset-markers))
5118 (org-compile-prefix-format 'agenda)
5119 (org-set-sorting-strategy 'agenda)
5120 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5121 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5122 (list entry)
5123 (org-agenda-files t)))
5124 (time (org-float-time))
5125 file rtn results)
5126 (when (or (not org-diary-last-run-time)
5127 (> (- time
5128 org-diary-last-run-time)
5130 (org-agenda-prepare-buffers files))
5131 (setq org-diary-last-run-time time)
5132 ;; If this is called during org-agenda, don't return any entries to
5133 ;; the calendar. Org Agenda will list these entries itself.
5134 (if org-disable-agenda-to-diary (setq files nil))
5135 (while (setq file (pop files))
5136 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5137 (setq results (append results rtn)))
5138 (if results
5139 (concat (org-agenda-finalize-entries results) "\n"))))
5141 (autoload 'org-diary "org-agenda" "\
5142 Return diary information from org files.
5143 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5144 It accesses org files and extracts information from those files to be
5145 listed in the diary. The function accepts arguments specifying what
5146 items should be listed. For a list of arguments allowed here, see the
5147 variable `org-agenda-entry-types'.
5149 The call in the diary file should look like this:
5151 &%%(org-diary) ~/path/to/some/orgfile.org
5153 Use a separate line for each org file to check. Or, if you omit the file name,
5154 all files listed in `org-agenda-files' will be checked automatically:
5156 &%%(org-diary)
5158 If you don't give any arguments (as in the example above), the default
5159 arguments (:deadline :scheduled :timestamp :sexp) are used.
5160 So the example above may also be written as
5162 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5164 The function expects the lisp variables `entry' and `date' to be provided
5165 by the caller, because this is how the calendar works. Don't use this
5166 function from a program - use `org-agenda-get-day-entries' instead.
5168 \(fn &rest ARGS)" nil nil)
5170 ;;; Agenda entry finders
5172 (defun org-agenda-get-day-entries (file date &rest args)
5173 "Does the work for `org-diary' and `org-agenda'.
5174 FILE is the path to a file to be checked for entries. DATE is date like
5175 the one returned by `calendar-current-date'. ARGS are symbols indicating
5176 which kind of entries should be extracted. For details about these, see
5177 the documentation of `org-diary'."
5178 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5179 (let* ((org-startup-folded nil)
5180 (org-startup-align-all-tables nil)
5181 (buffer (if (file-exists-p file)
5182 (org-get-agenda-file-buffer file)
5183 (error "No such file %s" file)))
5184 arg results rtn deadline-results)
5185 (if (not buffer)
5186 ;; If file does not exist, make sure an error message ends up in diary
5187 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5188 (with-current-buffer buffer
5189 (unless (derived-mode-p 'org-mode)
5190 (error "Agenda file %s is not in `org-mode'" file))
5191 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5192 (let ((case-fold-search nil))
5193 (save-excursion
5194 (save-restriction
5195 (if org-agenda-restrict
5196 (narrow-to-region org-agenda-restrict-begin
5197 org-agenda-restrict-end)
5198 (widen))
5199 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5200 (while (setq arg (pop args))
5201 (cond
5202 ((and (eq arg :todo)
5203 (equal date (calendar-gregorian-from-absolute
5204 (org-today))))
5205 (setq rtn (org-agenda-get-todos))
5206 (setq results (append results rtn)))
5207 ((eq arg :timestamp)
5208 (setq rtn (org-agenda-get-blocks))
5209 (setq results (append results rtn))
5210 (setq rtn (org-agenda-get-timestamps deadline-results))
5211 (setq results (append results rtn)))
5212 ((eq arg :sexp)
5213 (setq rtn (org-agenda-get-sexps))
5214 (setq results (append results rtn)))
5215 ((eq arg :scheduled)
5216 (setq rtn (org-agenda-get-scheduled deadline-results))
5217 (setq results (append results rtn)))
5218 ((eq arg :closed)
5219 (setq rtn (org-agenda-get-progress))
5220 (setq results (append results rtn)))
5221 ((eq arg :deadline)
5222 (setq rtn (org-agenda-get-deadlines))
5223 (setq deadline-results (copy-sequence rtn))
5224 (setq results (append results rtn))))))))
5225 results))))
5227 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5228 (defun org-agenda-get-todos ()
5229 "Return the TODO information for agenda display."
5230 (let* ((props (list 'face nil
5231 'done-face 'org-agenda-done
5232 'org-not-done-regexp org-not-done-regexp
5233 'org-todo-regexp org-todo-regexp
5234 'org-complex-heading-regexp org-complex-heading-regexp
5235 'mouse-face 'highlight
5236 'help-echo
5237 (format "mouse-2 or RET jump to org file %s"
5238 (abbreviate-file-name buffer-file-name))))
5239 (regexp (format org-heading-keyword-regexp-format
5240 (cond
5241 ((and org-select-this-todo-keyword
5242 (equal org-select-this-todo-keyword "*"))
5243 org-todo-regexp)
5244 (org-select-this-todo-keyword
5245 (concat "\\("
5246 (mapconcat 'identity
5247 (org-split-string
5248 org-select-this-todo-keyword
5249 "|")
5250 "\\|") "\\)"))
5251 (t org-not-done-regexp))))
5252 marker priority category category-pos tags todo-state
5253 ee txt beg end)
5254 (goto-char (point-min))
5255 (while (re-search-forward regexp nil t)
5256 (catch :skip
5257 (save-match-data
5258 (beginning-of-line)
5259 (org-agenda-skip)
5260 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5261 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5262 (goto-char (1+ beg))
5263 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5264 (throw :skip nil)))
5265 (goto-char (match-beginning 2))
5266 (setq marker (org-agenda-new-marker (match-beginning 0))
5267 category (org-get-category)
5268 category-pos (get-text-property (point) 'org-category-position)
5269 txt (org-trim
5270 (buffer-substring (match-beginning 2) (match-end 0)))
5271 tags (org-get-tags-at nil t)
5272 txt (org-agenda-format-item "" txt category tags t)
5273 priority (1+ (org-get-priority txt))
5274 todo-state (org-get-todo-state))
5275 (org-add-props txt props
5276 'org-marker marker 'org-hd-marker marker
5277 'priority priority 'org-category category
5278 'org-category-position category-pos
5279 'type "todo" 'todo-state todo-state)
5280 (push txt ee)
5281 (if org-agenda-todo-list-sublevels
5282 (goto-char (match-end 2))
5283 (org-end-of-subtree 'invisible))))
5284 (nreverse ee)))
5286 (defun org-agenda-todo-custom-ignore-p (time n)
5287 "Check whether timestamp is farther away than n number of days.
5288 This function is invoked if `org-agenda-todo-ignore-deadlines',
5289 `org-agenda-todo-ignore-scheduled' or
5290 `org-agenda-todo-ignore-timestamp' is set to an integer."
5291 (let ((days (org-days-to-time time)))
5292 (if (>= n 0)
5293 (>= days n)
5294 (<= days n))))
5296 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5297 (&optional end)
5298 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5299 (when (or org-agenda-todo-ignore-with-date
5300 org-agenda-todo-ignore-scheduled
5301 org-agenda-todo-ignore-deadlines
5302 org-agenda-todo-ignore-timestamp)
5303 (setq end (or end (save-excursion (outline-next-heading) (point))))
5304 (save-excursion
5305 (or (and org-agenda-todo-ignore-with-date
5306 (re-search-forward org-ts-regexp end t))
5307 (and org-agenda-todo-ignore-scheduled
5308 (re-search-forward org-scheduled-time-regexp end t)
5309 (cond
5310 ((eq org-agenda-todo-ignore-scheduled 'future)
5311 (> (org-days-to-time (match-string 1)) 0))
5312 ((eq org-agenda-todo-ignore-scheduled 'past)
5313 (<= (org-days-to-time (match-string 1)) 0))
5314 ((numberp org-agenda-todo-ignore-scheduled)
5315 (org-agenda-todo-custom-ignore-p
5316 (match-string 1) org-agenda-todo-ignore-scheduled))
5317 (t)))
5318 (and org-agenda-todo-ignore-deadlines
5319 (re-search-forward org-deadline-time-regexp end t)
5320 (cond
5321 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5322 ((eq org-agenda-todo-ignore-deadlines 'far)
5323 (not (org-deadline-close (match-string 1))))
5324 ((eq org-agenda-todo-ignore-deadlines 'future)
5325 (> (org-days-to-time (match-string 1)) 0))
5326 ((eq org-agenda-todo-ignore-deadlines 'past)
5327 (<= (org-days-to-time (match-string 1)) 0))
5328 ((numberp org-agenda-todo-ignore-deadlines)
5329 (org-agenda-todo-custom-ignore-p
5330 (match-string 1) org-agenda-todo-ignore-deadlines))
5331 (t (org-deadline-close (match-string 1)))))
5332 (and org-agenda-todo-ignore-timestamp
5333 (let ((buffer (current-buffer))
5334 (regexp
5335 (concat
5336 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5337 (start (point)))
5338 ;; Copy current buffer into a temporary one
5339 (with-temp-buffer
5340 (insert-buffer-substring buffer start end)
5341 (goto-char (point-min))
5342 ;; Delete SCHEDULED and DEADLINE items
5343 (while (re-search-forward regexp end t)
5344 (delete-region (match-beginning 0) (match-end 0)))
5345 (goto-char (point-min))
5346 ;; No search for timestamp left
5347 (when (re-search-forward org-ts-regexp nil t)
5348 (cond
5349 ((eq org-agenda-todo-ignore-timestamp 'future)
5350 (> (org-days-to-time (match-string 1)) 0))
5351 ((eq org-agenda-todo-ignore-timestamp 'past)
5352 (<= (org-days-to-time (match-string 1)) 0))
5353 ((numberp org-agenda-todo-ignore-timestamp)
5354 (org-agenda-todo-custom-ignore-p
5355 (match-string 1) org-agenda-todo-ignore-timestamp))
5356 (t))))))))))
5358 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5359 Do we have a reason to ignore this TODO entry because it has a time stamp?
5361 \(fn &optional END)" nil nil)
5363 (defconst org-agenda-no-heading-message
5364 "No heading for this item in buffer or region.")
5366 (defun org-agenda-get-timestamps (&optional deadline-results)
5367 "Return the date stamp information for agenda display."
5368 (let* ((props (list 'face 'org-agenda-calendar-event
5369 'org-not-done-regexp org-not-done-regexp
5370 'org-todo-regexp org-todo-regexp
5371 'org-complex-heading-regexp org-complex-heading-regexp
5372 'mouse-face 'highlight
5373 'help-echo
5374 (format "mouse-2 or RET jump to org file %s"
5375 (abbreviate-file-name buffer-file-name))))
5376 (d1 (calendar-absolute-from-gregorian date))
5378 (deadline-position-alist
5379 (mapcar (lambda (a) (and (setq mm (get-text-property
5380 0 'org-hd-marker a))
5381 (cons (marker-position mm) a)))
5382 deadline-results))
5383 (remove-re org-ts-regexp)
5384 (regexp
5385 (concat
5386 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5387 (regexp-quote
5388 (substring
5389 (format-time-string
5390 (car org-time-stamp-formats)
5391 (apply 'encode-time ; DATE bound by calendar
5392 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5393 1 11))
5394 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5395 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5396 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5397 donep tmp priority category category-pos ee txt timestr tags
5398 b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
5399 (goto-char (point-min))
5400 (while (setq end-of-match (re-search-forward regexp nil t))
5401 (setq b0 (match-beginning 0)
5402 b3 (match-beginning 3) e3 (match-end 3)
5403 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5404 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5405 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5406 (member todo-state
5407 org-agenda-repeating-timestamp-show-all)))
5408 (catch :skip
5409 (and (org-at-date-range-p) (throw :skip nil))
5410 (org-agenda-skip)
5411 (if (and (match-end 1)
5412 (not (= d1 (org-time-string-to-absolute
5413 (match-string 1) d1 nil show-all
5414 (current-buffer) b0))))
5415 (throw :skip nil))
5416 (if (and e3
5417 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5418 (throw :skip nil))
5419 (setq tmp (buffer-substring (max (point-min)
5420 (- b0 org-ds-keyword-length))
5422 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5423 inactivep (= (char-after b0) ?\[)
5424 deadlinep (string-match org-deadline-regexp tmp)
5425 scheduledp (string-match org-scheduled-regexp tmp)
5426 closedp (and org-agenda-include-inactive-timestamps
5427 (string-match org-closed-string tmp))
5428 clockp (and org-agenda-include-inactive-timestamps
5429 (or (string-match org-clock-string tmp)
5430 (string-match "]-+\\'" tmp)))
5431 warntime (get-text-property (point) 'org-appt-warntime)
5432 donep (member todo-state org-done-keywords))
5433 (if (or scheduledp deadlinep closedp clockp
5434 (and donep org-agenda-skip-timestamp-if-done))
5435 (throw :skip t))
5436 (if (string-match ">" timestr)
5437 ;; substring should only run to end of time stamp
5438 (setq timestr (substring timestr 0 (match-end 0))))
5439 (setq marker (org-agenda-new-marker b0)
5440 category (org-get-category b0)
5441 category-pos (get-text-property b0 'org-category-position))
5442 (save-excursion
5443 (if (not (re-search-backward org-outline-regexp-bol nil t))
5444 (setq txt org-agenda-no-heading-message)
5445 (goto-char (match-beginning 0))
5446 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5447 (assoc (point) deadline-position-alist))
5448 (throw :skip nil))
5449 (setq hdmarker (org-agenda-new-marker)
5450 tags (org-get-tags-at nil t))
5451 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5452 (setq head (or (match-string 1) ""))
5453 (setq txt (org-agenda-format-item
5454 (if inactivep org-agenda-inactive-leader nil)
5455 head category tags timestr
5456 remove-re habitp)))
5457 (setq priority (org-get-priority txt))
5458 (org-add-props txt props
5459 'org-marker marker 'org-hd-marker hdmarker)
5460 (org-add-props txt nil 'priority priority
5461 'org-category category 'date date
5462 'org-category-position category-pos
5463 'todo-state todo-state
5464 'warntime warntime
5465 'type "timestamp")
5466 (push txt ee))
5467 (if org-agenda-skip-additional-timestamps-same-entry
5468 (outline-next-heading)
5469 (goto-char end-of-match))))
5470 (nreverse ee)))
5472 (defun org-agenda-get-sexps ()
5473 "Return the sexp information for agenda display."
5474 (require 'diary-lib)
5475 (let* ((props (list 'face 'org-agenda-calendar-sexp
5476 'mouse-face 'highlight
5477 'help-echo
5478 (format "mouse-2 or RET jump to org file %s"
5479 (abbreviate-file-name buffer-file-name))))
5480 (regexp "^&?%%(")
5481 marker category extra category-pos ee txt tags entry
5482 result beg b sexp sexp-entry todo-state warntime)
5483 (goto-char (point-min))
5484 (while (re-search-forward regexp nil t)
5485 (catch :skip
5486 (org-agenda-skip)
5487 (setq beg (match-beginning 0))
5488 (goto-char (1- (match-end 0)))
5489 (setq b (point))
5490 (forward-sexp 1)
5491 (setq sexp (buffer-substring b (point)))
5492 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5493 (org-trim (match-string 1))
5494 ""))
5495 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5496 (when result
5497 (setq marker (org-agenda-new-marker beg)
5498 category (org-get-category beg)
5499 category-pos (get-text-property beg 'org-category-position)
5500 tags (save-excursion (org-back-to-heading t) (org-get-tags-at nil t))
5501 todo-state (org-get-todo-state)
5502 warntime (get-text-property (point) 'org-appt-warntime)
5503 extra nil)
5505 (dolist (r (if (stringp result)
5506 (list result)
5507 result)) ;; we expect a list here
5508 (when (and org-agenda-diary-sexp-prefix
5509 (string-match org-agenda-diary-sexp-prefix r))
5510 (setq extra (match-string 0 r)
5511 r (replace-match "" nil nil r)))
5512 (if (string-match "\\S-" r)
5513 (setq txt r)
5514 (setq txt "SEXP entry returned empty string"))
5516 (setq txt (org-agenda-format-item
5517 extra txt category tags 'time))
5518 (org-add-props txt props 'org-marker marker)
5519 (org-add-props txt nil
5520 'org-category category 'date date 'todo-state todo-state
5521 'org-category-position category-pos 'tags tags
5522 'type "sexp" 'warntime warntime)
5523 (push txt ee)))))
5524 (nreverse ee)))
5526 ;; Calendar sanity: define some functions that are independent of
5527 ;; `calendar-date-style'.
5528 ;; Normally I would like to use ISO format when calling the diary functions,
5529 ;; but to make sure we still have Emacs 22 compatibility we bind
5530 ;; also `european-calendar-style' and use european format
5531 (defun org-anniversary (year month day &optional mark)
5532 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5533 (org-no-warnings
5534 (let ((calendar-date-style 'european) (european-calendar-style t))
5535 (diary-anniversary day month year mark))))
5536 (defun org-cyclic (N year month day &optional mark)
5537 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5538 (org-no-warnings
5539 (let ((calendar-date-style 'european) (european-calendar-style t))
5540 (diary-cyclic N day month year mark))))
5541 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5542 "Like `diary-block', but with fixed (ISO) order of arguments."
5543 (org-no-warnings
5544 (let ((calendar-date-style 'european) (european-calendar-style t))
5545 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5546 (defun org-date (year month day &optional mark)
5547 "Like `diary-date', but with fixed (ISO) order of arguments."
5548 (org-no-warnings
5549 (let ((calendar-date-style 'european) (european-calendar-style t))
5550 (diary-date day month year mark))))
5552 ;; Define the` org-class' function
5553 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5554 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5555 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5556 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5557 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5558 `holidays', then any date that is known by the Emacs calendar to be a
5559 holiday will also be skipped."
5560 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5561 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5562 (d (calendar-absolute-from-gregorian date)))
5563 (and
5564 (<= date1 d)
5565 (<= d date2)
5566 (= (calendar-day-of-week date) dayname)
5567 (or (not skip-weeks)
5568 (progn
5569 (require 'cal-iso)
5570 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5571 (not (and (memq 'holidays skip-weeks)
5572 (calendar-check-holidays date)))
5573 entry)))
5575 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5576 "Like `org-class', but honor `calendar-date-style'.
5577 The order of the first 2 times 3 arguments depends on the variable
5578 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5579 So for American calendars, give this as MONTH DAY YEAR, for European as
5580 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5581 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5582 is any number of ISO weeks in the block period for which the item should
5583 be skipped.
5585 This function is here only for backward compatibility and it is deprecated,
5586 please use `org-class' instead."
5587 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5588 (date2 (org-order-calendar-date-args m2 d2 y2)))
5589 (org-class
5590 (nth 2 date1) (car date1) (nth 1 date1)
5591 (nth 2 date2) (car date2) (nth 1 date2)
5592 dayname skip-weeks)))
5593 (make-obsolete 'org-diary-class 'org-class "")
5595 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5596 (defalias 'org-get-closed 'org-agenda-get-progress)
5597 (defun org-agenda-get-progress ()
5598 "Return the logged TODO entries for agenda display."
5599 (let* ((props (list 'mouse-face 'highlight
5600 'org-not-done-regexp org-not-done-regexp
5601 'org-todo-regexp org-todo-regexp
5602 'org-complex-heading-regexp org-complex-heading-regexp
5603 'help-echo
5604 (format "mouse-2 or RET jump to org file %s"
5605 (abbreviate-file-name buffer-file-name))))
5606 (items (if (consp org-agenda-show-log-scoped)
5607 org-agenda-show-log-scoped
5608 (if (eq org-agenda-show-log-scoped 'clockcheck)
5609 '(clock)
5610 org-agenda-log-mode-items)))
5611 (parts
5612 (delq nil
5613 (list
5614 (if (memq 'closed items) (concat "\\<" org-closed-string))
5615 (if (memq 'clock items) (concat "\\<" org-clock-string))
5616 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5617 (parts-re (if parts (mapconcat 'identity parts "\\|")
5618 (error "`org-agenda-log-mode-items' is empty")))
5619 (regexp (concat
5620 "\\(" parts-re "\\)"
5621 " *\\["
5622 (regexp-quote
5623 (substring
5624 (format-time-string
5625 (car org-time-stamp-formats)
5626 (apply 'encode-time ; DATE bound by calendar
5627 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5628 1 11))))
5629 (org-agenda-search-headline-for-time nil)
5630 marker hdmarker priority category category-pos tags closedp
5631 statep clockp state ee txt extra timestr rest clocked)
5632 (goto-char (point-min))
5633 (while (re-search-forward regexp nil t)
5634 (catch :skip
5635 (org-agenda-skip)
5636 (setq marker (org-agenda-new-marker (match-beginning 0))
5637 closedp (equal (match-string 1) org-closed-string)
5638 statep (equal (string-to-char (match-string 1)) ?-)
5639 clockp (not (or closedp statep))
5640 state (and statep (match-string 2))
5641 category (org-get-category (match-beginning 0))
5642 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5643 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5644 (when (string-match "\\]" timestr)
5645 ;; substring should only run to end of time stamp
5646 (setq rest (substring timestr (match-end 0))
5647 timestr (substring timestr 0 (match-end 0)))
5648 (if (and (not closedp) (not statep)
5649 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5650 rest))
5651 (progn (setq timestr (concat (substring timestr 0 -1)
5652 "-" (match-string 1 rest) "]"))
5653 (setq clocked (match-string 2 rest)))
5654 (setq clocked "-")))
5655 (save-excursion
5656 (setq extra
5657 (cond
5658 ((not org-agenda-log-mode-add-notes) nil)
5659 (statep
5660 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5661 (match-string 1)))
5662 (clockp
5663 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5664 (match-string 1)))))
5665 (if (not (re-search-backward org-outline-regexp-bol nil t))
5666 (setq txt org-agenda-no-heading-message)
5667 (goto-char (match-beginning 0))
5668 (setq hdmarker (org-agenda-new-marker)
5669 tags (org-get-tags-at nil t))
5670 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5671 (setq txt (match-string 1))
5672 (when extra
5673 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5674 (setq txt (concat (substring txt 0 (match-beginning 1))
5675 " - " extra " " (match-string 2 txt)))
5676 (setq txt (concat txt " - " extra))))
5677 (setq txt (org-agenda-format-item
5678 (cond
5679 (closedp "Closed: ")
5680 (statep (concat "State: (" state ")"))
5681 (t (concat "Clocked: (" clocked ")")))
5682 txt category tags timestr)))
5683 (setq priority 100000)
5684 (org-add-props txt props
5685 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5686 'priority priority 'org-category category
5687 'org-category-position category-pos
5688 'type "closed" 'date date
5689 'undone-face 'org-warning 'done-face 'org-agenda-done)
5690 (push txt ee))
5691 (goto-char (point-at-eol))))
5692 (nreverse ee)))
5694 (defun org-agenda-show-clocking-issues ()
5695 "Add overlays, showing issues with clocking.
5696 See also the user option `org-agenda-clock-consistency-checks'."
5697 (interactive)
5698 (let* ((pl org-agenda-clock-consistency-checks)
5699 (re (concat "^[ \t]*"
5700 org-clock-string
5701 "[ \t]+"
5702 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5703 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5704 (tlstart 0.)
5705 (tlend 0.)
5706 (maxtime (org-hh:mm-string-to-minutes
5707 (or (plist-get pl :max-duration) "24:00")))
5708 (mintime (org-hh:mm-string-to-minutes
5709 (or (plist-get pl :min-duration) 0)))
5710 (maxgap (org-hh:mm-string-to-minutes
5711 ;; default 30:00 means never complain
5712 (or (plist-get pl :max-gap) "30:00")))
5713 (gapok (mapcar 'org-hh:mm-string-to-minutes
5714 (plist-get pl :gap-ok-around)))
5715 (def-face (or (plist-get pl :default-face)
5716 '((:background "DarkRed") (:foreground "white"))))
5717 issue face m te ts dt ov)
5718 (goto-char (point-min))
5719 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5720 (setq issue nil face def-face)
5721 (catch 'next
5722 (setq m (org-get-at-bol 'org-marker)
5723 te nil ts nil)
5724 (unless (and m (markerp m))
5725 (setq issue "No valid clock line") (throw 'next t))
5726 (org-with-point-at m
5727 (save-excursion
5728 (goto-char (point-at-bol))
5729 (unless (looking-at re)
5730 (error "No valid Clock line")
5731 (throw 'next t))
5732 (unless (match-end 3)
5733 (setq issue "No end time"
5734 face (or (plist-get pl :no-end-time-face) face))
5735 (throw 'next t))
5736 (setq ts (match-string 1)
5737 te (match-string 3)
5738 ts (org-float-time
5739 (apply 'encode-time (org-parse-time-string ts)))
5740 te (org-float-time
5741 (apply 'encode-time (org-parse-time-string te)))
5742 dt (- te ts))))
5743 (cond
5744 ((> dt (* 60 maxtime))
5745 ;; a very long clocking chunk
5746 (setq issue (format "Clocking interval is very long: %s"
5747 (org-minutes-to-hh:mm-string
5748 (floor (/ (float dt) 60.))))
5749 face (or (plist-get pl :long-face) face)))
5750 ((< dt (* 60 mintime))
5751 ;; a very short clocking chunk
5752 (setq issue (format "Clocking interval is very short: %s"
5753 (org-minutes-to-hh:mm-string
5754 (floor (/ (float dt) 60.))))
5755 face (or (plist-get pl :short-face) face)))
5756 ((and (> tlend 0) (< ts tlend))
5757 ;; Two clock entries are overlapping
5758 (setq issue (format "Clocking overlap: %d minutes"
5759 (/ (- tlend ts) 60))
5760 face (or (plist-get pl :overlap-face) face)))
5761 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5762 ;; There is a gap, lets see if we need to report it
5763 (unless (org-agenda-check-clock-gap tlend ts gapok)
5764 (setq issue (format "Clocking gap: %d minutes"
5765 (/ (- ts tlend) 60))
5766 face (or (plist-get pl :gap-face) face))))
5767 (t nil)))
5768 (setq tlend (or te tlend) tlstart (or ts tlstart))
5769 (when issue
5770 ;; OK, there was some issue, add an overlay to show the issue
5771 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5772 (overlay-put ov 'before-string
5773 (concat
5774 (org-add-props
5775 (format "%-43s" (concat " " issue))
5777 'face face)
5778 "\n"))
5779 (overlay-put ov 'evaporate t)))))
5781 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5782 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5783 (catch 'exit
5784 (unless ok-list
5785 ;; there are no OK times for gaps...
5786 (throw 'exit nil))
5787 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5788 ;; This is more than 24 hours, so it is OK.
5789 ;; because we have at least one OK time, that must be in the
5790 ;; 24 hour interval.
5791 (throw 'exit t))
5792 ;; We have a shorter gap.
5793 ;; Now we have to get the minute of the day when these times are
5794 (let* ((t1dec (decode-time (seconds-to-time t1)))
5795 (t2dec (decode-time (seconds-to-time t2)))
5796 ;; compute the minute on the day
5797 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5798 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5799 (when (< min2 min1)
5800 ;; if min2 is smaller than min1, this means it is on the next day.
5801 ;; Wrap it to after midnight.
5802 (setq min2 (+ min2 1440)))
5803 ;; Now check if any of the OK times is in the gap
5804 (mapc (lambda (x)
5805 ;; Wrap the time to after midnight if necessary
5806 (if (< x min1) (setq x (+ x 1440)))
5807 ;; Check if in interval
5808 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5809 ok-list)
5810 ;; Nope, this gap is not OK
5811 nil)))
5813 (defun org-agenda-get-deadlines ()
5814 "Return the deadline information for agenda display."
5815 (let* ((props (list 'mouse-face 'highlight
5816 'org-not-done-regexp org-not-done-regexp
5817 'org-todo-regexp org-todo-regexp
5818 'org-complex-heading-regexp org-complex-heading-regexp
5819 'help-echo
5820 (format "mouse-2 or RET jump to org file %s"
5821 (abbreviate-file-name buffer-file-name))))
5822 (regexp org-deadline-time-regexp)
5823 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5824 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5825 d2 diff dfrac wdays pos pos1 category category-pos
5826 tags suppress-prewarning ee txt head face s todo-state
5827 show-all upcomingp donep timestr warntime)
5828 (goto-char (point-min))
5829 (while (re-search-forward regexp nil t)
5830 (setq suppress-prewarning nil)
5831 (catch :skip
5832 (org-agenda-skip)
5833 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5834 (save-match-data
5835 (string-match org-scheduled-time-regexp
5836 (buffer-substring (point-at-bol)
5837 (point-at-eol)))))
5838 (setq suppress-prewarning
5839 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5840 org-agenda-skip-deadline-prewarning-if-scheduled
5841 0)))
5842 (setq s (match-string 1)
5843 txt nil
5844 pos (1- (match-beginning 1))
5845 todo-state (save-match-data (org-get-todo-state))
5846 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5847 (member todo-state
5848 org-agenda-repeating-timestamp-show-all))
5849 d2 (org-time-string-to-absolute
5850 (match-string 1) d1 'past show-all
5851 (current-buffer) pos)
5852 diff (- d2 d1)
5853 wdays (if suppress-prewarning
5854 (let ((org-deadline-warning-days suppress-prewarning))
5855 (org-get-wdays s))
5856 (org-get-wdays s))
5857 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5858 upcomingp (and todayp (> diff 0)))
5859 ;; When to show a deadline in the calendar:
5860 ;; If the expiration is within wdays warning time.
5861 ;; Past-due deadlines are only shown on the current date
5862 (if (and (or (and (<= diff wdays)
5863 (and todayp (not org-agenda-only-exact-dates)))
5864 (= diff 0)))
5865 (save-excursion
5866 ;; (setq todo-state (org-get-todo-state))
5867 (setq donep (member todo-state org-done-keywords))
5868 (if (and donep
5869 (or org-agenda-skip-deadline-if-done
5870 (not (= diff 0))))
5871 (setq txt nil)
5872 (setq category (org-get-category)
5873 warntime (get-text-property (point) 'org-appt-warntime)
5874 category-pos (get-text-property (point) 'org-category-position))
5875 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5876 (setq txt org-agenda-no-heading-message)
5877 (goto-char (match-end 0))
5878 (setq pos1 (match-beginning 0))
5879 (setq tags (org-get-tags-at pos1 t))
5880 (setq head (buffer-substring-no-properties
5881 (point)
5882 (progn (skip-chars-forward "^\r\n")
5883 (point))))
5884 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5885 (setq timestr
5886 (concat (substring s (match-beginning 1)) " "))
5887 (setq timestr 'time))
5888 (setq txt (org-agenda-format-item
5889 (if (= diff 0)
5890 (car org-agenda-deadline-leaders)
5891 (if (functionp
5892 (nth 1 org-agenda-deadline-leaders))
5893 (funcall
5894 (nth 1 org-agenda-deadline-leaders)
5895 diff date)
5896 (format (nth 1 org-agenda-deadline-leaders)
5897 diff)))
5898 head category tags
5899 (if (not (= diff 0)) nil timestr)))))
5900 (when txt
5901 (setq face (org-agenda-deadline-face dfrac))
5902 (org-add-props txt props
5903 'org-marker (org-agenda-new-marker pos)
5904 'warntime warntime
5905 'org-hd-marker (org-agenda-new-marker pos1)
5906 'priority (+ (- diff)
5907 (org-get-priority txt))
5908 'org-category category
5909 'org-category-position category-pos
5910 'todo-state todo-state
5911 'type (if upcomingp "upcoming-deadline" "deadline")
5912 'date (if upcomingp date d2)
5913 'face (if donep 'org-agenda-done face)
5914 'undone-face face 'done-face 'org-agenda-done)
5915 (push txt ee))))))
5916 (nreverse ee)))
5918 (defun org-agenda-deadline-face (fraction)
5919 "Return the face to displaying a deadline item.
5920 FRACTION is what fraction of the head-warning time has passed."
5921 (let ((faces org-agenda-deadline-faces) f)
5922 (catch 'exit
5923 (while (setq f (pop faces))
5924 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5926 (defun org-agenda-get-scheduled (&optional deadline-results)
5927 "Return the scheduled information for agenda display."
5928 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5929 'org-todo-regexp org-todo-regexp
5930 'org-complex-heading-regexp org-complex-heading-regexp
5931 'done-face 'org-agenda-done
5932 'mouse-face 'highlight
5933 'help-echo
5934 (format "mouse-2 or RET jump to org file %s"
5935 (abbreviate-file-name buffer-file-name))))
5936 (regexp org-scheduled-time-regexp)
5937 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5938 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5940 (deadline-position-alist
5941 (mapcar (lambda (a) (and (setq mm (get-text-property
5942 0 'org-hd-marker a))
5943 (cons (marker-position mm) a)))
5944 deadline-results))
5945 d2 diff pos pos1 category category-pos tags donep
5946 ee txt head pastschedp todo-state face timestr s habitp show-all
5947 did-habit-check-p warntime)
5948 (goto-char (point-min))
5949 (while (re-search-forward regexp nil t)
5950 (catch :skip
5951 (org-agenda-skip)
5952 (setq s (match-string 1)
5953 txt nil
5954 pos (1- (match-beginning 1))
5955 todo-state (save-match-data (org-get-todo-state))
5956 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5957 (member todo-state
5958 org-agenda-repeating-timestamp-show-all))
5959 d2 (org-time-string-to-absolute
5960 (match-string 1) d1 'past show-all
5961 (current-buffer) pos)
5962 diff (- d2 d1)
5963 warntime (get-text-property (point) 'org-appt-warntime))
5964 (setq pastschedp (and todayp (< diff 0)))
5965 (setq did-habit-check-p nil)
5966 ;; When to show a scheduled item in the calendar:
5967 ;; If it is on or past the date.
5968 (when (or (and (< diff 0)
5969 (< (abs diff) org-scheduled-past-days)
5970 (and todayp (not org-agenda-only-exact-dates)))
5971 (= diff 0)
5972 ;; org-is-habit-p uses org-entry-get, which is expansive
5973 ;; so we go extra mile to only call it once
5974 (and todayp
5975 (boundp 'org-habit-show-all-today)
5976 org-habit-show-all-today
5977 (setq did-habit-check-p t)
5978 (setq habitp (and (functionp 'org-is-habit-p)
5979 (org-is-habit-p)))))
5980 (save-excursion
5981 (setq donep (member todo-state org-done-keywords))
5982 (if (and donep
5983 (or org-agenda-skip-scheduled-if-done
5984 (not (= diff 0))
5985 (and (functionp 'org-is-habit-p)
5986 (org-is-habit-p))))
5987 (setq txt nil)
5988 (setq habitp (if did-habit-check-p habitp
5989 (and (functionp 'org-is-habit-p)
5990 (org-is-habit-p))))
5991 (setq category (org-get-category)
5992 category-pos (get-text-property (point) 'org-category-position))
5993 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5994 (setq txt org-agenda-no-heading-message)
5995 (goto-char (match-end 0))
5996 (setq pos1 (match-beginning 0))
5997 (if habitp
5998 (if (or (not org-habit-show-habits)
5999 (and (not todayp)
6000 (boundp 'org-habit-show-habits-only-for-today)
6001 org-habit-show-habits-only-for-today))
6002 (throw :skip nil))
6003 (if (and
6004 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6005 (and org-agenda-skip-scheduled-if-deadline-is-shown
6006 pastschedp))
6007 (setq mm (assoc pos1 deadline-position-alist)))
6008 (throw :skip nil)))
6009 (setq tags (org-get-tags-at nil t))
6010 (setq head (buffer-substring-no-properties
6011 (point)
6012 (progn (skip-chars-forward "^\r\n") (point))))
6013 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6014 (setq timestr
6015 (concat (substring s (match-beginning 1)) " "))
6016 (setq timestr 'time))
6017 (setq txt (org-agenda-format-item
6018 (if (= diff 0)
6019 (car org-agenda-scheduled-leaders)
6020 (format (nth 1 org-agenda-scheduled-leaders)
6021 (- 1 diff)))
6022 head category tags
6023 (if (not (= diff 0)) nil timestr)
6024 nil habitp))))
6025 (when txt
6026 (setq face
6027 (cond
6028 ((and (not habitp) pastschedp)
6029 'org-scheduled-previously)
6030 (todayp 'org-scheduled-today)
6031 (t 'org-scheduled))
6032 habitp (and habitp (org-habit-parse-todo)))
6033 (org-add-props txt props
6034 'undone-face face
6035 'face (if donep 'org-agenda-done face)
6036 'org-marker (org-agenda-new-marker pos)
6037 'org-hd-marker (org-agenda-new-marker pos1)
6038 'type (if pastschedp "past-scheduled" "scheduled")
6039 'date (if pastschedp d2 date)
6040 'warntime warntime
6041 'priority (if habitp
6042 (org-habit-get-priority habitp)
6043 (+ 94 (- 5 diff) (org-get-priority txt)))
6044 'org-category category
6045 'category-position category-pos
6046 'org-habit-p habitp
6047 'todo-state todo-state)
6048 (push txt ee))))))
6049 (nreverse ee)))
6051 (defun org-agenda-get-blocks ()
6052 "Return the date-range information for agenda display."
6053 (let* ((props (list 'face nil
6054 'org-not-done-regexp org-not-done-regexp
6055 'org-todo-regexp org-todo-regexp
6056 'org-complex-heading-regexp org-complex-heading-regexp
6057 'mouse-face 'highlight
6058 'help-echo
6059 (format "mouse-2 or RET jump to org file %s"
6060 (abbreviate-file-name buffer-file-name))))
6061 (regexp org-tr-regexp)
6062 (d0 (calendar-absolute-from-gregorian date))
6063 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6064 todo-state tags pos head donep)
6065 (goto-char (point-min))
6066 (while (re-search-forward regexp nil t)
6067 (catch :skip
6068 (org-agenda-skip)
6069 (setq pos (point))
6070 (let ((start-time (match-string 1))
6071 (end-time (match-string 2)))
6072 (setq s1 (match-string 1)
6073 s2 (match-string 2)
6074 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6075 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6076 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6077 ;; Only allow days between the limits, because the normal
6078 ;; date stamps will catch the limits.
6079 (save-excursion
6080 (setq todo-state (org-get-todo-state))
6081 (setq donep (member todo-state org-done-keywords))
6082 (if (and donep org-agenda-skip-timestamp-if-done)
6083 (throw :skip t))
6084 (setq marker (org-agenda-new-marker (point)))
6085 (setq category (org-get-category)
6086 category-pos (get-text-property (point) 'org-category-position))
6087 (if (not (re-search-backward org-outline-regexp-bol nil t))
6088 (setq txt org-agenda-no-heading-message)
6089 (goto-char (match-beginning 0))
6090 (setq hdmarker (org-agenda-new-marker (point)))
6091 (setq tags (org-get-tags-at nil t))
6092 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6093 (setq head (match-string 1))
6094 (let ((remove-re
6095 (if org-agenda-remove-timeranges-from-blocks
6096 (concat
6097 "<" (regexp-quote s1) ".*?>"
6098 "--"
6099 "<" (regexp-quote s2) ".*?>")
6100 nil)))
6101 (setq txt (org-agenda-format-item
6102 (format
6103 (nth (if (= d1 d2) 0 1)
6104 org-agenda-timerange-leaders)
6105 (1+ (- d0 d1)) (1+ (- d2 d1)))
6106 head category tags
6107 (cond ((and (= d1 d0) (= d2 d0))
6108 (concat "<" start-time ">--<" end-time ">"))
6109 ((= d1 d0)
6110 (concat "<" start-time ">"))
6111 ((= d2 d0)
6112 (concat "<" end-time ">")))
6113 remove-re))))
6114 (org-add-props txt props
6115 'org-marker marker 'org-hd-marker hdmarker
6116 'type "block" 'date date
6117 'todo-state todo-state
6118 'priority (org-get-priority txt) 'org-category category
6119 'org-category-position category-pos)
6120 (push txt ee))))
6121 (goto-char pos)))
6122 ;; Sort the entries by expiration date.
6123 (nreverse ee)))
6125 ;;; Agenda presentation and sorting
6127 (defvar org-prefix-has-time nil
6128 "A flag, set by `org-compile-prefix-format'.
6129 The flag is set if the currently compiled format contains a `%t'.")
6130 (defvar org-prefix-has-tag nil
6131 "A flag, set by `org-compile-prefix-format'.
6132 The flag is set if the currently compiled format contains a `%T'.")
6133 (defvar org-prefix-has-effort nil
6134 "A flag, set by `org-compile-prefix-format'.
6135 The flag is set if the currently compiled format contains a `%e'.")
6136 (defvar org-prefix-category-length nil
6137 "Used by `org-compile-prefix-format' to remember the category field width.")
6138 (defvar org-prefix-category-max-length nil
6139 "Used by `org-compile-prefix-format' to remember the category field width.")
6141 (defun org-agenda-get-category-icon (category)
6142 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6143 (dolist (entry org-agenda-category-icon-alist)
6144 (when (org-string-match-p (car entry) category)
6145 (if (listp (cadr entry))
6146 (return (cadr entry))
6147 (return (apply 'create-image (cdr entry)))))))
6149 (defun org-agenda-format-item (extra txt &optional category tags dotime
6150 remove-re habitp)
6151 "Format TXT to be inserted into the agenda buffer.
6152 In particular, it adds the prefix and corresponding text properties. EXTRA
6153 must be a string and replaces the `%s' specifier in the prefix format.
6154 CATEGORY (string, symbol or nil) may be used to overrule the default
6155 category taken from local variable or file name. It will replace the `%c'
6156 specifier in the format. DOTIME, when non-nil, indicates that a
6157 time-of-day should be extracted from TXT for sorting of this entry, and for
6158 the `%t' specifier in the format. When DOTIME is a string, this string is
6159 searched for a time before TXT is. TAGS can be the tags of the headline.
6160 Any match of REMOVE-RE will be removed from TXT."
6161 ;; We keep the org-prefix-* variable values along with a compiled
6162 ;; formatter, so that multiple agendas existing at the same time, do
6163 ;; not step on each other toes.
6165 ;; It was inconvenient to make these variables buffer local in
6166 ;; Agenda buffers, because this function expects to be called with
6167 ;; the buffer where item comes from being current, and not agenda
6168 ;; buffer
6169 (let* ((bindings (car org-prefix-format-compiled))
6170 (formatter (cadr org-prefix-format-compiled)))
6171 (loop for (var value) in bindings
6172 do (set var value))
6173 (save-match-data
6174 ;; Diary entries sometimes have extra whitespace at the beginning
6175 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
6177 ;; Fix the tags part in txt
6178 (setq txt (org-agenda-fix-displayed-tags
6179 txt tags
6180 org-agenda-show-inherited-tags
6181 org-agenda-hide-tags-regexp))
6182 (let* ((category (or category
6183 (if (stringp org-category)
6184 org-category
6185 (and org-category (symbol-name org-category)))
6186 (if buffer-file-name
6187 (file-name-sans-extension
6188 (file-name-nondirectory buffer-file-name))
6189 "")))
6190 (category-icon (org-agenda-get-category-icon category))
6191 (category-icon (if category-icon
6192 (propertize " " 'display category-icon)
6193 ""))
6194 ;; time, tag, effort are needed for the eval of the prefix format
6195 (tag (if tags (nth (1- (length tags)) tags) ""))
6196 time effort neffort
6197 (ts (if dotime (concat
6198 (if (stringp dotime) dotime "")
6199 (and org-agenda-search-headline-for-time txt))))
6200 (time-of-day (and dotime (org-get-time-of-day ts)))
6201 stamp plain s0 s1 s2 rtn srp l
6202 duration thecategory)
6203 (and (derived-mode-p 'org-mode) buffer-file-name
6204 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6205 (when (and dotime time-of-day)
6206 ;; Extract starting and ending time and move them to prefix
6207 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6208 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6209 (setq s0 (match-string 0 ts)
6210 srp (and stamp (match-end 3))
6211 s1 (match-string (if plain 1 2) ts)
6212 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6214 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6215 ;; them, we might want to remove them there to avoid duplication.
6216 ;; The user can turn this off with a variable.
6217 (if (and org-prefix-has-time
6218 org-agenda-remove-times-when-in-prefix (or stamp plain)
6219 (string-match (concat (regexp-quote s0) " *") txt)
6220 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6221 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6222 (= (match-beginning 0) 0)
6224 (setq txt (replace-match "" nil nil txt))))
6225 ;; Normalize the time(s) to 24 hour
6226 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6227 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6229 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6230 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6231 (setq s2
6232 (org-minutes-to-hh:mm-string
6233 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6235 ;; Compute the duration
6236 (when s2
6237 (setq duration (- (org-hh:mm-string-to-minutes s2)
6238 (org-hh:mm-string-to-minutes s1)))))
6240 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6241 txt)
6242 ;; Tags are in the string
6243 (if (or (eq org-agenda-remove-tags t)
6244 (and org-agenda-remove-tags
6245 org-prefix-has-tag))
6246 (setq txt (replace-match "" t t txt))
6247 (setq txt (replace-match
6248 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6249 (match-string 2 txt))
6250 t t txt))))
6251 (when (derived-mode-p 'org-mode)
6252 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6253 (when effort
6254 (setq neffort (org-duration-string-to-minutes effort)
6255 effort (setq effort (concat "[" effort "]")))))
6256 ;; prevent erroring out with %e format when there is no effort
6257 (or effort (setq effort ""))
6259 (when remove-re
6260 (while (string-match remove-re txt)
6261 (setq txt (replace-match "" t t txt))))
6263 ;; Set org-heading property on `txt' to mark the start of the
6264 ;; heading.
6265 (add-text-properties 0 (length txt) '(org-heading t) txt)
6267 ;; Prepare the variables needed in the eval of the compiled format
6268 (setq time (cond (s2 (concat
6269 (org-agenda-time-of-day-to-ampm-maybe s1)
6270 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6271 (if org-agenda-timegrid-use-ampm " ")))
6272 (s1 (concat
6273 (org-agenda-time-of-day-to-ampm-maybe s1)
6274 (if org-agenda-timegrid-use-ampm
6275 "........ "
6276 "......")))
6277 (t ""))
6278 extra (or (and (not habitp) extra) "")
6279 category (if (symbolp category) (symbol-name category) category)
6280 thecategory (copy-sequence category))
6281 (if (string-match org-bracket-link-regexp category)
6282 (progn
6283 (setq l (if (match-end 3)
6284 (- (match-end 3) (match-beginning 3))
6285 (- (match-end 1) (match-beginning 1))))
6286 (when (< l (or org-prefix-category-length 0))
6287 (setq category (copy-sequence category))
6288 (org-add-props category nil
6289 'extra-space (make-string
6290 (- org-prefix-category-length l 1) ?\ ))))
6291 (if (and org-prefix-category-max-length
6292 (>= (length category) org-prefix-category-max-length))
6293 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6294 ;; Evaluate the compiled format
6295 (setq rtn (concat (eval formatter) txt))
6297 ;; And finally add the text properties
6298 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6299 (org-add-props rtn nil
6300 'org-category (if thecategory (downcase thecategory) category)
6301 'tags (mapcar 'org-downcase-keep-props tags)
6302 'org-highest-priority org-highest-priority
6303 'org-lowest-priority org-lowest-priority
6304 'time-of-day time-of-day
6305 'duration duration
6306 'effort effort
6307 'effort-minutes neffort
6308 'txt txt
6309 'time time
6310 'extra extra
6311 'format org-prefix-format-compiled
6312 'dotime dotime)))))
6314 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6315 "Remove tags string from TXT, and add a modified list of tags.
6316 The modified list may contain inherited tags, and tags matched by
6317 `org-agenda-hide-tags-regexp' will be removed."
6318 (when (or add-inherited hide-re)
6319 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6320 (setq txt (substring txt 0 (match-beginning 0))))
6321 (setq tags
6322 (delq nil
6323 (mapcar (lambda (tg)
6324 (if (or (and hide-re (string-match hide-re tg))
6325 (and (not add-inherited)
6326 (get-text-property 0 'inherited tg)))
6328 tg))
6329 tags)))
6330 (when tags
6331 (let ((have-i (get-text-property 0 'inherited (car tags)))
6333 (setq txt (concat txt " :"
6334 (mapconcat
6335 (lambda (x)
6336 (setq i (get-text-property 0 'inherited x))
6337 (if (and have-i (not i))
6338 (progn
6339 (setq have-i nil)
6340 (concat ":" x))
6342 tags ":")
6343 (if have-i "::" ":"))))))
6344 txt)
6346 (defun org-downcase-keep-props (s)
6347 (let ((props (text-properties-at 0 s)))
6348 (setq s (downcase s))
6349 (add-text-properties 0 (length s) props s)
6352 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6353 (defvar org-agenda-sorting-strategy-selected nil)
6355 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6356 (catch 'exit
6357 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6358 ((and todayp (member 'today (car org-agenda-time-grid))))
6359 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6360 ((member 'weekly (car org-agenda-time-grid)))
6361 (t (throw 'exit list)))
6362 (let* ((have (delq nil (mapcar
6363 (lambda (x) (get-text-property 1 'time-of-day x))
6364 list)))
6365 (string (nth 1 org-agenda-time-grid))
6366 (gridtimes (nth 2 org-agenda-time-grid))
6367 (req (car org-agenda-time-grid))
6368 (remove (member 'remove-match req))
6369 new time)
6370 (if (and (member 'require-timed req) (not have))
6371 ;; don't show empty grid
6372 (throw 'exit list))
6373 (while (setq time (pop gridtimes))
6374 (unless (and remove (member time have))
6375 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6376 (push (org-agenda-format-item
6377 nil string "" nil
6378 (concat (substring time 0 -2) ":" (substring time -2)))
6379 new)
6380 (put-text-property
6381 2 (length (car new)) 'face 'org-time-grid (car new))))
6382 (when (and todayp org-agenda-show-current-time-in-grid)
6383 (push (org-agenda-format-item
6385 org-agenda-current-time-string
6386 "" nil
6387 (format-time-string "%H:%M "))
6388 new)
6389 (put-text-property
6390 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6392 (if (member 'time-up org-agenda-sorting-strategy-selected)
6393 (append new list)
6394 (append list new)))))
6396 (defun org-compile-prefix-format (key)
6397 "Compile the prefix format into a Lisp form that can be evaluated.
6398 The resulting form and associated variable bindings is returned
6399 and stored in the variable `org-prefix-format-compiled'."
6400 (setq org-prefix-has-time nil org-prefix-has-tag nil
6401 org-prefix-category-length nil
6402 org-prefix-has-effort nil)
6403 (let ((s (cond
6404 ((stringp org-agenda-prefix-format)
6405 org-agenda-prefix-format)
6406 ((assq key org-agenda-prefix-format)
6407 (cdr (assq key org-agenda-prefix-format)))
6408 (t " %-12:c%?-12t% s")))
6409 (start 0)
6410 varform vars var e c f opt)
6411 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6412 s start)
6413 (setq var (or (cdr (assoc (match-string 4 s)
6414 '(("c" . category) ("t" . time) ("s" . extra)
6415 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6416 'eval)
6417 c (or (match-string 3 s) "")
6418 opt (match-beginning 1)
6419 start (1+ (match-beginning 0)))
6420 (if (equal var 'time) (setq org-prefix-has-time t))
6421 (if (equal var 'tag) (setq org-prefix-has-tag t))
6422 (if (equal var 'effort) (setq org-prefix-has-effort t))
6423 (setq f (concat "%" (match-string 2 s) "s"))
6424 (when (equal var 'category)
6425 (setq org-prefix-category-length
6426 (floor (abs (string-to-number (match-string 2 s)))))
6427 (setq org-prefix-category-max-length
6428 (let ((x (match-string 2 s)))
6429 (save-match-data
6430 (if (string-match "\\.[0-9]+" x)
6431 (string-to-number (substring (match-string 0 x) 1)))))))
6432 (if (eq var 'eval)
6433 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6434 (if opt
6435 (setq varform
6436 `(if (equal "" ,var)
6438 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6439 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6440 (setq s (replace-match "%s" t nil s))
6441 (push varform vars))
6442 (setq vars (nreverse vars))
6443 (with-current-buffer (or org-agenda-buffer (current-buffer))
6444 (setq org-prefix-format-compiled
6445 (list
6446 `((org-prefix-has-time ,org-prefix-has-time)
6447 (org-prefix-has-tag ,org-prefix-has-tag)
6448 (org-prefix-category-length ,org-prefix-category-length)
6449 (org-prefix-has-effort ,org-prefix-has-effort))
6450 `(format ,s ,@vars))))))
6452 (defun org-set-sorting-strategy (key)
6453 (if (symbolp (car org-agenda-sorting-strategy))
6454 ;; the old format
6455 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6456 (setq org-agenda-sorting-strategy-selected
6457 (or (cdr (assq key org-agenda-sorting-strategy))
6458 (cdr (assq 'agenda org-agenda-sorting-strategy))
6459 '(time-up category-keep priority-down)))))
6461 (defun org-get-time-of-day (s &optional string mod24)
6462 "Check string S for a time of day.
6463 If found, return it as a military time number between 0 and 2400.
6464 If not found, return nil.
6465 The optional STRING argument forces conversion into a 5 character wide string
6466 HH:MM."
6467 (save-match-data
6468 (when
6469 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6470 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6471 (let* ((h (string-to-number (match-string 1 s)))
6472 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6473 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6474 (am-p (equal ampm "am"))
6475 (h1 (cond ((not ampm) h)
6476 ((= h 12) (if am-p 0 12))
6477 (t (+ h (if am-p 0 12)))))
6478 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6479 (mod h1 24) h1))
6480 (t0 (+ (* 100 h2) m))
6481 (t1 (concat (if (>= h1 24) "+" " ")
6482 (if (and org-agenda-time-leading-zero
6483 (< t0 1000)) "0" "")
6484 (if (< t0 100) "0" "")
6485 (if (< t0 10) "0" "")
6486 (int-to-string t0))))
6487 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6489 (defvar org-agenda-before-sorting-filter-function nil
6490 "Function to be applied to agenda items prior to sorting.
6491 Prior to sorting also means just before they are inserted into the agenda.
6493 To aid sorting, you may revisit the original entries and add more text
6494 properties which will later be used by the sorting functions.
6496 The function should take a string argument, an agenda line.
6497 It has access to the text properties in that line, which contain among
6498 other things, the property `org-hd-marker' that points to the entry
6499 where the line comes from. Note that not all lines going into the agenda
6500 have this property, only most.
6502 The function should return the modified string. It is probably best
6503 to ONLY change text properties.
6505 You can also use this function as a filter, by returning nil for lines
6506 you don't want to have in the agenda at all. For this application, you
6507 could bind the variable in the options section of a custom command.")
6509 (defun org-agenda-finalize-entries (list &optional nosort)
6510 "Sort and concatenate the agenda items."
6511 (setq list (mapcar 'org-agenda-highlight-todo list))
6512 (if nosort
6513 list
6514 (when org-agenda-before-sorting-filter-function
6515 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6516 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6518 (defun org-agenda-highlight-todo (x)
6519 (let ((org-done-keywords org-done-keywords-for-agenda)
6520 (case-fold-search nil)
6522 (if (eq x 'line)
6523 (save-excursion
6524 (beginning-of-line 1)
6525 (setq re (org-get-at-bol 'org-todo-regexp))
6526 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6527 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6528 (add-text-properties (match-beginning 0) (match-end 1)
6529 (list 'face (org-get-todo-face 1)))
6530 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6531 (delete-region (match-beginning 1) (1- (match-end 0)))
6532 (goto-char (match-beginning 1))
6533 (insert (format org-agenda-todo-keyword-format s)))))
6534 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6535 (setq re (get-text-property 0 'org-todo-regexp x))
6536 (when (and re
6537 ;; Test `pl' because if there's no heading content,
6538 ;; there's no point matching to highlight. Note
6539 ;; that if we didn't test `pl' first, and there
6540 ;; happened to be no keyword from `org-todo-regexp'
6541 ;; on this heading line, then the `equal' comparison
6542 ;; afterwards would spuriously succeed in the case
6543 ;; where `pl' is nil -- causing an args-out-of-range
6544 ;; error when we try to add text properties to text
6545 ;; that isn't there.
6547 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6548 x pl) pl))
6549 (add-text-properties
6550 (or (match-end 1) (match-end 0)) (match-end 0)
6551 (list 'face (org-get-todo-face (match-string 2 x)))
6553 (when (match-end 1)
6554 (setq x (concat (substring x 0 (match-end 1))
6555 (format org-agenda-todo-keyword-format
6556 (match-string 2 x))
6557 (org-add-props " " (text-properties-at 0 x))
6558 (substring x (match-end 3)))))))
6559 x)))
6561 (defsubst org-cmp-priority (a b)
6562 "Compare the priorities of string A and B."
6563 (let ((pa (or (get-text-property 1 'priority a) 0))
6564 (pb (or (get-text-property 1 'priority b) 0)))
6565 (cond ((> pa pb) +1)
6566 ((< pa pb) -1))))
6568 (defsubst org-cmp-effort (a b)
6569 "Compare the effort values of string A and B."
6570 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6571 (ea (or (get-text-property 1 'effort-minutes a) def))
6572 (eb (or (get-text-property 1 'effort-minutes b) def)))
6573 (cond ((> ea eb) +1)
6574 ((< ea eb) -1))))
6576 (defsubst org-cmp-category (a b)
6577 "Compare the string values of categories of strings A and B."
6578 (let ((ca (or (get-text-property 1 'org-category a) ""))
6579 (cb (or (get-text-property 1 'org-category b) "")))
6580 (cond ((string-lessp ca cb) -1)
6581 ((string-lessp cb ca) +1))))
6583 (defsubst org-cmp-todo-state (a b)
6584 "Compare the todo states of strings A and B."
6585 (let* ((ma (or (get-text-property 1 'org-marker a)
6586 (get-text-property 1 'org-hd-marker a)))
6587 (mb (or (get-text-property 1 'org-marker b)
6588 (get-text-property 1 'org-hd-marker b)))
6589 (fa (and ma (marker-buffer ma)))
6590 (fb (and mb (marker-buffer mb)))
6591 (todo-kwds
6592 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6593 (and fb (with-current-buffer fb org-todo-keywords-1))))
6594 (ta (or (get-text-property 1 'todo-state a) ""))
6595 (tb (or (get-text-property 1 'todo-state b) ""))
6596 (la (- (length (member ta todo-kwds))))
6597 (lb (- (length (member tb todo-kwds))))
6598 (donepa (member ta org-done-keywords-for-agenda))
6599 (donepb (member tb org-done-keywords-for-agenda)))
6600 (cond ((and donepa (not donepb)) -1)
6601 ((and (not donepa) donepb) +1)
6602 ((< la lb) -1)
6603 ((< lb la) +1))))
6605 (defsubst org-cmp-alpha (a b)
6606 "Compare the headlines, alphabetically."
6607 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6608 (plb (text-property-any 0 (length b) 'org-heading t b))
6609 (ta (and pla (substring a pla)))
6610 (tb (and plb (substring b plb))))
6611 (when pla
6612 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6613 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6614 (setq ta (substring ta (match-end 0))))
6615 (setq ta (downcase ta)))
6616 (when plb
6617 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6618 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6619 (setq tb (substring tb (match-end 0))))
6620 (setq tb (downcase tb)))
6621 (cond ((not ta) +1)
6622 ((not tb) -1)
6623 ((string-lessp ta tb) -1)
6624 ((string-lessp tb ta) +1))))
6626 (defsubst org-cmp-tag (a b)
6627 "Compare the string values of the first tags of A and B."
6628 (let ((ta (car (last (get-text-property 1 'tags a))))
6629 (tb (car (last (get-text-property 1 'tags b)))))
6630 (cond ((not ta) +1)
6631 ((not tb) -1)
6632 ((string-lessp ta tb) -1)
6633 ((string-lessp tb ta) +1))))
6635 (defsubst org-cmp-time (a b)
6636 "Compare the time-of-day values of strings A and B."
6637 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6638 (ta (or (get-text-property 1 'time-of-day a) def))
6639 (tb (or (get-text-property 1 'time-of-day b) def)))
6640 (cond ((< ta tb) -1)
6641 ((< tb ta) +1))))
6643 (defsubst org-cmp-habit-p (a b)
6644 "Compare the todo states of strings A and B."
6645 (let ((ha (get-text-property 1 'org-habit-p a))
6646 (hb (get-text-property 1 'org-habit-p b)))
6647 (cond ((and ha (not hb)) -1)
6648 ((and (not ha) hb) +1))))
6650 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6652 (defun org-entries-lessp (a b)
6653 "Predicate for sorting agenda entries."
6654 ;; The following variables will be used when the form is evaluated.
6655 ;; So even though the compiler complains, keep them.
6656 (let* ((ss org-agenda-sorting-strategy-selected)
6657 (time-up (and (org-em 'time-up 'time-down ss)
6658 (org-cmp-time a b)))
6659 (time-down (if time-up (- time-up) nil))
6660 (priority-up (and (org-em 'priority-up 'priority-down ss)
6661 (org-cmp-priority a b)))
6662 (priority-down (if priority-up (- priority-up) nil))
6663 (effort-up (and (org-em 'effort-up 'effort-down ss)
6664 (org-cmp-effort a b)))
6665 (effort-down (if effort-up (- effort-up) nil))
6666 (category-up (and (or (org-em 'category-up 'category-down ss)
6667 (memq 'category-keep ss))
6668 (org-cmp-category a b)))
6669 (category-down (if category-up (- category-up) nil))
6670 (category-keep (if category-up +1 nil))
6671 (tag-up (and (org-em 'tag-up 'tag-down ss)
6672 (org-cmp-tag a b)))
6673 (tag-down (if tag-up (- tag-up) nil))
6674 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6675 (org-cmp-todo-state a b)))
6676 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6677 (habit-up (and (org-em 'habit-up 'habit-down ss)
6678 (org-cmp-habit-p a b)))
6679 (habit-down (if habit-up (- habit-up) nil))
6680 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6681 (org-cmp-alpha a b)))
6682 (alpha-down (if alpha-up (- alpha-up) nil))
6683 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6684 user-defined-up user-defined-down)
6685 (if (and need-user-cmp org-agenda-cmp-user-defined
6686 (functionp org-agenda-cmp-user-defined))
6687 (setq user-defined-up
6688 (funcall org-agenda-cmp-user-defined a b)
6689 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6690 (cdr (assoc
6691 (eval (cons 'or org-agenda-sorting-strategy-selected))
6692 '((-1 . t) (1 . nil) (nil . nil))))))
6694 ;;; Agenda restriction lock
6696 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6697 "Overlay to mark the headline to which agenda commands are restricted.")
6698 (overlay-put org-agenda-restriction-lock-overlay
6699 'face 'org-agenda-restriction-lock)
6700 (overlay-put org-agenda-restriction-lock-overlay
6701 'help-echo "Agendas are currently limited to this subtree.")
6702 (org-detach-overlay org-agenda-restriction-lock-overlay)
6704 (defun org-agenda-set-restriction-lock (&optional type)
6705 "Set restriction lock for agenda, to current subtree or file.
6706 Restriction will be the file if TYPE is `file', or if type is the
6707 universal prefix '(4), or if the cursor is before the first headline
6708 in the file. Otherwise, restriction will be to the current subtree."
6709 (interactive "P")
6710 (and (equal type '(4)) (setq type 'file))
6711 (setq type (cond
6712 (type type)
6713 ((org-at-heading-p) 'subtree)
6714 ((condition-case nil (org-back-to-heading t) (error nil))
6715 'subtree)
6716 (t 'file)))
6717 (if (eq type 'subtree)
6718 (progn
6719 (setq org-agenda-restrict t)
6720 (setq org-agenda-overriding-restriction 'subtree)
6721 (put 'org-agenda-files 'org-restrict
6722 (list (buffer-file-name (buffer-base-buffer))))
6723 (org-back-to-heading t)
6724 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6725 (move-marker org-agenda-restrict-begin (point))
6726 (move-marker org-agenda-restrict-end
6727 (save-excursion (org-end-of-subtree t)))
6728 (message "Locking agenda restriction to subtree"))
6729 (put 'org-agenda-files 'org-restrict
6730 (list (buffer-file-name (buffer-base-buffer))))
6731 (setq org-agenda-restrict nil)
6732 (setq org-agenda-overriding-restriction 'file)
6733 (move-marker org-agenda-restrict-begin nil)
6734 (move-marker org-agenda-restrict-end nil)
6735 (message "Locking agenda restriction to file"))
6736 (setq current-prefix-arg nil)
6737 (org-agenda-maybe-redo))
6739 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6740 "Remove the agenda restriction lock."
6741 (interactive "P")
6742 (org-detach-overlay org-agenda-restriction-lock-overlay)
6743 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6744 (setq org-agenda-overriding-restriction nil)
6745 (setq org-agenda-restrict nil)
6746 (put 'org-agenda-files 'org-restrict nil)
6747 (move-marker org-agenda-restrict-begin nil)
6748 (move-marker org-agenda-restrict-end nil)
6749 (setq current-prefix-arg nil)
6750 (message "Agenda restriction lock removed")
6751 (or noupdate (org-agenda-maybe-redo)))
6753 (defun org-agenda-maybe-redo ()
6754 "If there is any window showing the agenda view, update it."
6755 (let ((w (get-buffer-window org-agenda-buffer-name t))
6756 (w0 (selected-window)))
6757 (when w
6758 (select-window w)
6759 (org-agenda-redo)
6760 (select-window w0)
6761 (if org-agenda-overriding-restriction
6762 (message "Agenda view shifted to new %s restriction"
6763 org-agenda-overriding-restriction)
6764 (message "Agenda restriction lock removed")))))
6766 ;;; Agenda commands
6768 (defun org-agenda-check-type (error &rest types)
6769 "Check if agenda buffer is of allowed type.
6770 If ERROR is non-nil, throw an error, otherwise just return nil.
6771 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
6772 (if (not org-agenda-type)
6773 (error "No Org agenda currently displayed")
6774 (if (memq org-agenda-type types)
6776 (if error
6777 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6778 nil))))
6780 (defun org-agenda-Quit (&optional arg)
6781 "Exit agenda by removing the window or the buffer."
6782 (interactive)
6783 (if org-agenda-columns-active
6784 (org-columns-quit)
6785 (let ((buf (current-buffer)))
6786 (if (eq org-agenda-window-setup 'other-frame)
6787 (progn
6788 (org-agenda-reset-markers)
6789 (kill-buffer buf)
6790 (org-columns-remove-overlays)
6791 (setq org-agenda-archives-mode nil)
6792 (delete-frame))
6793 (and (not (eq org-agenda-window-setup 'current-window))
6794 (not (one-window-p))
6795 (delete-window))
6796 (org-agenda-reset-markers)
6797 (kill-buffer buf)
6798 (org-columns-remove-overlays)
6799 (setq org-agenda-archives-mode nil)))
6800 ;; Maybe restore the pre-agenda window configuration.
6801 (and org-agenda-restore-windows-after-quit
6802 (not (eq org-agenda-window-setup 'other-frame))
6803 org-agenda-pre-window-conf
6804 (set-window-configuration org-agenda-pre-window-conf)
6805 (setq org-agenda-pre-window-conf nil))))
6807 (defun org-agenda-quit ()
6808 "Exit agenda by killing agenda buffer or burying it when
6809 `org-agenda-sticky' is non-NIL"
6810 (interactive)
6811 (if (and (eq org-indirect-buffer-display 'other-window)
6812 org-last-indirect-buffer)
6813 (delete-window (get-buffer-window org-last-indirect-buffer)))
6814 (if org-agenda-columns-active
6815 (org-columns-quit)
6816 (if org-agenda-sticky
6817 (let ((buf (current-buffer)))
6818 (if (eq org-agenda-window-setup 'other-frame)
6819 (progn
6820 (delete-frame))
6821 (and (not (eq org-agenda-window-setup 'current-window))
6822 (not (one-window-p))
6823 (delete-window)))
6824 (with-current-buffer buf
6825 (bury-buffer)
6826 ;; Maybe restore the pre-agenda window configuration.
6827 (and org-agenda-restore-windows-after-quit
6828 (not (eq org-agenda-window-setup 'other-frame))
6829 org-agenda-pre-window-conf
6830 (set-window-configuration org-agenda-pre-window-conf)
6831 (setq org-agenda-pre-window-conf nil))))
6832 (org-agenda-Quit))))
6834 (defun org-agenda-exit ()
6835 "Exit agenda by removing the window or the buffer.
6836 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6837 Org-mode buffers visited directly by the user will not be touched."
6838 (interactive)
6839 (org-release-buffers org-agenda-new-buffers)
6840 (setq org-agenda-new-buffers nil)
6841 (org-agenda-Quit))
6843 (defun org-agenda-kill-all-agenda-buffers ()
6844 "Kill all buffers in `org-agenda-mode'.
6845 This is used when toggling sticky agendas. You can also explicitly invoke it
6846 with `C-c a C-k'."
6847 (interactive)
6848 (let (blist)
6849 (dolist (buf (buffer-list))
6850 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6851 (push buf blist)))
6852 (mapc 'kill-buffer blist)))
6854 (defun org-agenda-execute (arg)
6855 "Execute another agenda command, keeping same window.
6856 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6857 in the agenda."
6858 (interactive "P")
6859 (let ((org-agenda-window-setup 'current-window))
6860 (org-agenda arg)))
6862 (defun org-agenda-redo (&optional all)
6863 "Rebuild possibly ALL agenda view(s) in the current buffer."
6864 (interactive "P")
6865 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6866 (cpa (unless (eq all t) current-prefix-arg))
6867 (org-agenda-doing-sticky-redo org-agenda-sticky)
6868 (org-agenda-sticky nil)
6869 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6870 org-agenda-buffer-name))
6871 (org-agenda-keep-modes t)
6872 (tag-filter org-agenda-tag-filter)
6873 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6874 (top-cat-filter org-agenda-top-category-filter)
6875 (cat-filter org-agenda-category-filter)
6876 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6877 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6878 (cols org-agenda-columns-active)
6879 (line (org-current-line))
6880 (window-line (- line (org-current-line (window-start))))
6881 (lprops (get 'org-agenda-redo-command 'org-lprops))
6882 (redo-cmd (get-text-property p 'org-redo-cmd))
6883 (last-args (get-text-property p 'org-last-args))
6884 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6885 (org-agenda-overriding-cmd-arguments
6886 (unless (eq all t)
6887 (cond ((listp last-args)
6888 (cons (or cpa (car last-args)) (cdr last-args)))
6889 ((stringp last-args)
6890 last-args))))
6891 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6892 (put 'org-agenda-tag-filter :preset-filter nil)
6893 (put 'org-agenda-category-filter :preset-filter nil)
6894 (and cols (org-columns-quit))
6895 (message "Rebuilding agenda buffer...")
6896 (if series-redo-cmd
6897 (eval series-redo-cmd)
6898 (org-let lprops '(eval redo-cmd)))
6899 (setq org-agenda-undo-list nil
6900 org-agenda-pending-undo-list nil)
6901 (message "Rebuilding agenda buffer...done")
6902 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6903 (put 'org-agenda-category-filter :preset-filter cat-preset)
6904 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6905 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6906 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6907 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6908 (org-goto-line line)
6909 (recenter window-line)))
6911 (defvar org-global-tags-completion-table nil)
6912 (defvar org-agenda-filter-form nil)
6913 (defvar org-agenda-filtered-by-category nil)
6915 (defun org-agenda-filter-by-category (strip)
6916 "Keep only those lines in the agenda buffer that have a specific category.
6917 The category is that of the current line."
6918 (interactive "P")
6919 (if (and org-agenda-filtered-by-category
6920 org-agenda-category-filter)
6921 (org-agenda-filter-show-all-cat)
6922 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6923 (if cat (org-agenda-filter-apply
6924 (list (concat (if strip "-" "+") cat)) 'category)
6925 (error "No category at point")))))
6927 (defun org-find-top-category (&optional pos)
6928 (save-excursion
6929 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6930 (if pos (goto-char pos))
6931 ;; Skip up to the topmost parent
6932 (while (ignore-errors (outline-up-heading 1) t))
6933 (ignore-errors
6934 (nth 4 (org-heading-components))))))
6936 (defvar org-agenda-filtered-by-top-category nil)
6938 (defun org-agenda-filter-by-top-category (strip)
6939 "Keep only those lines in the agenda buffer that have a specific category.
6940 The category is that of the current line."
6941 (interactive "P")
6942 (if org-agenda-filtered-by-top-category
6943 (progn
6944 (setq org-agenda-filtered-by-top-category nil
6945 org-agenda-top-category-filter nil)
6946 (org-agenda-filter-show-all-cat))
6947 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6948 (if cat (org-agenda-filter-top-category-apply cat strip)
6949 (error "No top-level category at point")))))
6951 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6952 "Keep only those lines in the agenda buffer that have a specific tag.
6953 The tag is selected with its fast selection letter, as configured.
6954 With prefix argument STRIP, remove all lines that do have the tag.
6955 A lisp caller can specify CHAR. NARROW means that the new tag should be
6956 used to narrow the search - the interactive user can also press `-' or `+'
6957 to switch to narrowing."
6958 (interactive "P")
6959 (let* ((alist org-tag-alist-for-agenda)
6960 (tag-chars (mapconcat
6961 (lambda (x) (if (and (not (symbolp (car x)))
6962 (cdr x))
6963 (char-to-string (cdr x))
6964 ""))
6965 alist ""))
6966 (efforts (org-split-string
6967 (or (cdr (assoc (concat org-effort-property "_ALL")
6968 org-global-properties))
6969 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6970 "")))
6971 (effort-op org-agenda-filter-effort-default-operator)
6972 (effort-prompt "")
6973 (inhibit-read-only t)
6974 (current org-agenda-tag-filter)
6975 maybe-refresh a n tag)
6976 (unless char
6977 (message
6978 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6979 (if narrow "Narrow" "Filter") tag-chars
6980 (if org-agenda-auto-exclude-function "[RET], " ""))
6981 (setq char (read-char-exclusive)))
6982 (when (member char '(?+ ?-))
6983 ;; Narrowing down
6984 (cond ((equal char ?-) (setq strip t narrow t))
6985 ((equal char ?+) (setq strip nil narrow t)))
6986 (message
6987 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6988 (setq char (read-char-exclusive)))
6989 (when (member char '(?< ?> ?= ??))
6990 ;; An effort operator
6991 (setq effort-op (char-to-string char))
6992 (setq alist nil) ; to make sure it will be interpreted as effort.
6993 (unless (equal char ??)
6994 (loop for i from 0 to 9 do
6995 (setq effort-prompt
6996 (concat
6997 effort-prompt " ["
6998 (if (= i 9) "0" (int-to-string (1+ i)))
6999 "]" (nth i efforts))))
7000 (message "Effort%s: %s " effort-op effort-prompt)
7001 (setq char (read-char-exclusive))
7002 (when (or (< char ?0) (> char ?9))
7003 (error "Need 1-9,0 to select effort"))))
7004 (when (equal char ?\t)
7005 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7006 (org-set-local 'org-global-tags-completion-table
7007 (org-global-tags-completion-table)))
7008 (let ((completion-ignore-case t))
7009 (setq tag (org-icompleting-read
7010 "Tag: " org-global-tags-completion-table))))
7011 (cond
7012 ((equal char ?\r)
7013 (org-agenda-filter-show-all-tag)
7014 (when org-agenda-auto-exclude-function
7015 (setq org-agenda-tag-filter '())
7016 (dolist (tag (org-agenda-get-represented-tags))
7017 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7018 (if modifier
7019 (push modifier org-agenda-tag-filter))))
7020 (if (not (null org-agenda-tag-filter))
7021 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7022 (setq maybe-refresh t))
7023 ((equal char ?/)
7024 (org-agenda-filter-show-all-tag)
7025 (when (get 'org-agenda-tag-filter :preset-filter)
7026 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7027 (setq maybe-refresh t))
7028 ((equal char ?. )
7029 (setq org-agenda-tag-filter
7030 (mapcar (lambda(tag) (concat "+" tag))
7031 (org-get-at-bol 'tags)))
7032 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7033 (setq maybe-refresh t))
7034 ((or (equal char ?\ )
7035 (setq a (rassoc char alist))
7036 (and (>= char ?0) (<= char ?9)
7037 (setq n (if (= char ?0) 9 (- char ?0 1))
7038 tag (concat effort-op (nth n efforts))
7039 a (cons tag nil)))
7040 (and (= char ??)
7041 (setq tag "?eff")
7042 a (cons tag nil))
7043 (and tag (setq a (cons tag nil))))
7044 (org-agenda-filter-show-all-tag)
7045 (setq tag (car a))
7046 (setq org-agenda-tag-filter
7047 (cons (concat (if strip "-" "+") tag)
7048 (if narrow current nil)))
7049 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7050 (setq maybe-refresh t))
7051 (t (error "Invalid tag selection character %c" char)))
7052 (when (and maybe-refresh
7053 (eq org-agenda-clockreport-mode 'with-filter))
7054 (org-agenda-redo))))
7056 (defun org-agenda-get-represented-tags ()
7057 "Get a list of all tags currently represented in the agenda."
7058 (let (p tags)
7059 (save-excursion
7060 (goto-char (point-min))
7061 (while (setq p (next-single-property-change (point) 'tags))
7062 (goto-char p)
7063 (mapc (lambda (x) (add-to-list 'tags x))
7064 (get-text-property (point) 'tags))))
7065 tags))
7067 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7068 "Refine the current filter. See `org-agenda-filter-by-tag'."
7069 (interactive "P")
7070 (org-agenda-filter-by-tag strip char 'refine))
7072 (defun org-agenda-filter-make-matcher ()
7073 "Create the form that tests a line for agenda filter."
7074 (let (f f1)
7075 ;; first compute the tag-filter matcher
7076 (dolist (x (delete-dups
7077 (append (get 'org-agenda-tag-filter
7078 :preset-filter) org-agenda-tag-filter)))
7079 (if (member x '("-" "+"))
7080 (setq f1 (if (equal x "-") 'tags '(not tags)))
7081 (if (string-match "[<=>?]" x)
7082 (setq f1 (org-agenda-filter-effort-form x))
7083 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7084 (if (equal (string-to-char x) ?-)
7085 (setq f1 (list 'not f1))))
7086 (push f1 f))
7087 ;; then compute the category-filter matcher
7088 (dolist (x (delete-dups
7089 (append (get 'org-agenda-category-filter
7090 :preset-filter) org-agenda-category-filter)))
7091 (if (equal "-" (substring x 0 1))
7092 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7093 (setq f1 (list 'equal (substring x 1) 'cat)))
7094 (push f1 f))
7095 (cons 'and (nreverse f))))
7097 (defun org-agenda-filter-effort-form (e)
7098 "Return the form to compare the effort of the current line with what E says.
7099 E looks like \"+<2:25\"."
7100 (let (op)
7101 (setq e (substring e 1))
7102 (setq op (string-to-char e) e (substring e 1))
7103 (setq op (cond ((equal op ?<) '<=)
7104 ((equal op ?>) '>=)
7105 ((equal op ??) op)
7106 (t '=)))
7107 (list 'org-agenda-compare-effort (list 'quote op)
7108 (org-duration-string-to-minutes e))))
7110 (defun org-agenda-compare-effort (op value)
7111 "Compare the effort of the current line with VALUE, using OP.
7112 If the line does not have an effort defined, return nil."
7113 (let ((eff (org-get-at-bol 'effort-minutes)))
7114 (if (equal op ??)
7115 (not eff)
7116 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7117 value))))
7119 (defun org-agenda-filter-apply (filter type)
7120 "Set FILTER as the new agenda filter and apply it."
7121 (let (tags cat)
7122 (if (eq type 'tag)
7123 (setq org-agenda-tag-filter filter)
7124 (setq org-agenda-category-filter filter))
7125 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7126 (if (and (eq type 'category)
7127 (not (equal (substring (car filter) 0 1) "-")))
7128 ;; Only set `org-agenda-filtered-by-category' to t
7129 ;; when a unique category is used as the filter
7130 (setq org-agenda-filtered-by-category t))
7131 (org-agenda-set-mode-name)
7132 (save-excursion
7133 (goto-char (point-min))
7134 (while (not (eobp))
7135 (if (org-get-at-bol 'org-marker)
7136 (progn
7137 (setq tags (org-get-at-bol 'tags) ; used in eval
7138 cat (get-text-property (point) 'org-category))
7139 (if (not (eval org-agenda-filter-form))
7140 (org-agenda-filter-hide-line type))
7141 (beginning-of-line 2))
7142 (beginning-of-line 2))))
7143 (if (get-char-property (point) 'invisible)
7144 (ignore-errors (org-agenda-previous-line)))))
7146 (defun org-agenda-filter-top-category-apply (category &optional negative)
7147 "Set FILTER as the new agenda filter and apply it."
7148 (org-agenda-set-mode-name)
7149 (save-excursion
7150 (goto-char (point-min))
7151 (while (not (eobp))
7152 (let* ((pos (org-get-at-bol 'org-hd-marker))
7153 (topcat (and pos (org-find-top-category pos))))
7154 (if (and topcat (funcall (if negative 'identity 'not)
7155 (string= category topcat)))
7156 (org-agenda-filter-hide-line 'category)))
7157 (beginning-of-line 2)))
7158 (if (get-char-property (point) 'invisible)
7159 (org-agenda-previous-line))
7160 (setq org-agenda-top-category-filter category
7161 org-agenda-filtered-by-top-category t))
7163 (defun org-agenda-filter-hide-line (type)
7164 (let (ov)
7165 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7166 (point-at-eol)))
7167 (overlay-put ov 'invisible t)
7168 (overlay-put ov 'type type)
7169 (if (eq type 'tag)
7170 (push ov org-agenda-tag-filter-overlays)
7171 (push ov org-agenda-cat-filter-overlays))))
7173 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7174 (setq pos (or pos (point)))
7175 (save-excursion
7176 (dolist (ov (overlays-at pos))
7177 (when (and (overlay-get ov 'invisible)
7178 (eq (overlay-get ov 'type) 'tag))
7179 (goto-char pos)
7180 (if (< (overlay-start ov) (point-at-eol))
7181 (move-overlay ov (point-at-eol)
7182 (overlay-end ov)))))))
7184 (defun org-agenda-filter-show-all-tag nil
7185 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7186 (setq org-agenda-tag-filter-overlays nil
7187 org-agenda-tag-filter nil
7188 org-agenda-filter-form nil)
7189 (org-agenda-set-mode-name))
7191 (defun org-agenda-filter-show-all-cat nil
7192 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7193 (setq org-agenda-cat-filter-overlays nil
7194 org-agenda-filtered-by-category nil
7195 org-agenda-category-filter nil
7196 org-agenda-filter-form nil)
7197 (org-agenda-set-mode-name))
7199 (defun org-agenda-manipulate-query-add ()
7200 "Manipulate the query by adding a search term with positive selection.
7201 Positive selection means the term must be matched for selection of an entry."
7202 (interactive)
7203 (org-agenda-manipulate-query ?\[))
7204 (defun org-agenda-manipulate-query-subtract ()
7205 "Manipulate the query by adding a search term with negative selection.
7206 Negative selection means term must not be matched for selection of an entry."
7207 (interactive)
7208 (org-agenda-manipulate-query ?\]))
7209 (defun org-agenda-manipulate-query-add-re ()
7210 "Manipulate the query by adding a search regexp with positive selection.
7211 Positive selection means the regexp must match for selection of an entry."
7212 (interactive)
7213 (org-agenda-manipulate-query ?\{))
7214 (defun org-agenda-manipulate-query-subtract-re ()
7215 "Manipulate the query by adding a search regexp with negative selection.
7216 Negative selection means regexp must not match for selection of an entry."
7217 (interactive)
7218 (org-agenda-manipulate-query ?\}))
7219 (defun org-agenda-manipulate-query (char)
7220 (cond
7221 ((memq org-agenda-type '(timeline agenda))
7222 (let ((org-agenda-include-inactive-timestamps t))
7223 (org-agenda-redo))
7224 (message "Display now includes inactive timestamps as well"))
7225 ((eq org-agenda-type 'search)
7226 (org-add-to-string
7227 'org-agenda-query-string
7228 (if org-agenda-last-search-view-search-was-boolean
7229 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7230 (?\{ . " +{}") (?\} . " -{}"))))
7231 " "))
7232 (setq org-agenda-redo-command
7233 (list 'org-search-view
7234 (car (get-text-property (min (1- (point-max)) (point))
7235 'org-last-args))
7236 org-agenda-query-string
7237 (+ (length org-agenda-query-string)
7238 (if (member char '(?\{ ?\})) 0 1))))
7239 (set-register org-agenda-query-register org-agenda-query-string)
7240 (let ((org-agenda-overriding-arguments
7241 (cdr org-agenda-redo-command)))
7242 (org-agenda-redo)))
7243 (t (error "Cannot manipulate query for %s-type agenda buffers"
7244 org-agenda-type))))
7246 (defun org-add-to-string (var string)
7247 (set var (concat (symbol-value var) string)))
7249 (defun org-agenda-goto-date (span)
7250 "Jump to DATE in agenda."
7251 (interactive "P")
7252 (let* ((org-read-date-prefer-future
7253 (eval org-agenda-jump-prefer-future))
7254 (date (org-read-date))
7255 (org-agenda-sticky-orig org-agenda-sticky)
7256 (org-agenda-buffer-tmp-name (buffer-name))
7257 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7258 (0-arg (or current-prefix-arg (car args)))
7259 (2-arg (nth 2 args))
7260 (newcmd (list 'org-agenda-list 0-arg date
7261 (org-agenda-span-to-ndays 2-arg)))
7262 (newargs (cdr newcmd))
7263 (inhibit-read-only t)
7264 org-agenda-sticky)
7265 (if (not (org-agenda-check-type t 'agenda))
7266 (error "Not available in non-agenda blocks")
7267 (add-text-properties (point-min) (point-max)
7268 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7269 (org-agenda-redo)
7270 (setq org-agenda-sticky org-agenda-sticky-orig
7271 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7273 (defun org-agenda-goto-today ()
7274 "Go to today."
7275 (interactive)
7276 (org-agenda-check-type t 'timeline 'agenda)
7277 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7278 (curspan (nth 2 args))
7279 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7280 (cond
7281 (tdpos (goto-char tdpos))
7282 ((eq org-agenda-type 'agenda)
7283 (let* ((sd (org-agenda-compute-starting-span
7284 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7285 (org-agenda-overriding-arguments args))
7286 (setf (nth 1 org-agenda-overriding-arguments) sd)
7287 (org-agenda-redo)
7288 (org-agenda-find-same-or-today-or-agenda)))
7289 (t (error "Cannot find today")))))
7291 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7292 (goto-char
7293 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7294 (text-property-any (point-min) (point-max) 'org-today t)
7295 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7296 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7297 (org-agenda-goto-block-beginning))
7298 (point-min))))
7300 (defun org-agenda-goto-block-beginning ()
7301 "Go the agenda block beginning."
7302 (interactive)
7303 (if (not (derived-mode-p 'org-agenda-mode))
7304 (error "Cannot execute this command outside of org-agenda-mode buffers")
7305 (let (dest)
7306 (save-excursion
7307 (unless (looking-at "\\'")
7308 (forward-char))
7309 (let* ((prop 'org-agenda-structural-header)
7310 (p (previous-single-property-change (point) prop))
7311 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7312 (1- (point))) prop)))
7313 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7314 (if (not dest)
7315 (error "Cannot find the beginning of the blog")
7316 (goto-char dest)
7317 (move-beginning-of-line 1)))))
7319 (defun org-agenda-later (arg)
7320 "Go forward in time by the current span.
7321 With prefix ARG, go forward that many times the current span."
7322 (interactive "p")
7323 (org-agenda-check-type t 'agenda)
7324 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7325 (span (or (nth 2 args) org-agenda-current-span))
7326 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7327 (greg (calendar-gregorian-from-absolute sd))
7328 (cnt (org-get-at-bol 'org-day-cnt))
7329 greg2)
7330 (cond
7331 ((numberp span)
7332 (setq sd (+ (* span arg) sd)))
7333 ((eq span 'day)
7334 (setq sd (+ arg sd)))
7335 ((eq span 'week)
7336 (setq sd (+ (* 7 arg) sd)))
7337 ((eq span 'month)
7338 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7339 sd (calendar-absolute-from-gregorian greg2))
7340 (setcar greg2 (1+ (car greg2))))
7341 ((eq span 'year)
7342 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7343 sd (calendar-absolute-from-gregorian greg2))
7344 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7346 (setq sd (+ (* span arg) sd))))
7347 (let ((org-agenda-overriding-cmd
7348 ;; `cmd' may have been set by `org-agenda-run-series' which
7349 ;; uses `org-agenda-overriding-cmd' to decide whether
7350 ;; overriding is allowed for `cmd'
7351 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7352 (org-agenda-overriding-arguments
7353 (list (car args) sd span)))
7354 (org-agenda-redo)
7355 (org-agenda-find-same-or-today-or-agenda cnt))))
7357 (defun org-agenda-earlier (arg)
7358 "Go backward in time by the current span.
7359 With prefix ARG, go backward that many times the current span."
7360 (interactive "p")
7361 (org-agenda-later (- arg)))
7363 (defun org-agenda-view-mode-dispatch ()
7364 "Call one of the view mode commands."
7365 (interactive)
7366 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7367 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7368 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7369 (let ((a (read-char-exclusive)))
7370 (case a
7371 (?\ (call-interactively 'org-agenda-reset-view))
7372 (?d (call-interactively 'org-agenda-day-view))
7373 (?w (call-interactively 'org-agenda-week-view))
7374 (?m (call-interactively 'org-agenda-month-view))
7375 (?y (call-interactively 'org-agenda-year-view))
7376 (?l (call-interactively 'org-agenda-log-mode))
7377 (?L (org-agenda-log-mode '(4)))
7378 (?c (org-agenda-log-mode 'clockcheck))
7379 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7380 (?a (call-interactively 'org-agenda-archives-mode))
7381 (?A (org-agenda-archives-mode 'files))
7382 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7383 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7384 (?G (call-interactively 'org-agenda-toggle-time-grid))
7385 (?D (call-interactively 'org-agenda-toggle-diary))
7386 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7387 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7388 (org-agenda-check-type t 'timeline 'agenda)
7389 (org-agenda-redo))
7390 (message "Display now includes inactive timestamps as well"))
7391 (?q (message "Abort"))
7392 (otherwise (error "Invalid key" )))))
7394 (defun org-agenda-reset-view ()
7395 "Switch to default view for agenda."
7396 (interactive)
7397 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7398 (defun org-agenda-day-view (&optional day-of-year)
7399 "Switch to daily view for agenda.
7400 With argument DAY-OF-YEAR, switch to that day of the year."
7401 (interactive "P")
7402 (org-agenda-change-time-span 'day day-of-year))
7403 (defun org-agenda-week-view (&optional iso-week)
7404 "Switch to daily view for agenda.
7405 With argument ISO-WEEK, switch to the corresponding ISO week.
7406 If ISO-WEEK has more then 2 digits, only the last two encode the
7407 week. Any digits before this encode a year. So 200712 means
7408 week 12 of year 2007. Years in the range 1938-2037 can also be
7409 written as 2-digit years."
7410 (interactive "P")
7411 (org-agenda-change-time-span 'week iso-week))
7412 (defun org-agenda-month-view (&optional month)
7413 "Switch to monthly view for agenda.
7414 With argument MONTH, switch to that month."
7415 (interactive "P")
7416 (org-agenda-change-time-span 'month month))
7417 (defun org-agenda-year-view (&optional year)
7418 "Switch to yearly view for agenda.
7419 With argument YEAR, switch to that year.
7420 If MONTH has more then 2 digits, only the last two encode the
7421 month. Any digits before this encode a year. So 200712 means
7422 December year 2007. Years in the range 1938-2037 can also be
7423 written as 2-digit years."
7424 (interactive "P")
7425 (when year
7426 (setq year (org-small-year-to-year year)))
7427 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7428 (org-agenda-change-time-span 'year year)
7429 (error "Abort")))
7431 (defun org-agenda-change-time-span (span &optional n)
7432 "Change the agenda view to SPAN.
7433 SPAN may be `day', `week', `month', `year'."
7434 (org-agenda-check-type t 'agenda)
7435 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7436 (curspan (nth 2 args)))
7437 (if (and (not n) (equal curspan span))
7438 (error "Viewing span is already \"%s\"" span))
7439 (let* ((sd (or (org-get-at-bol 'day)
7440 (nth 1 args)
7441 org-starting-day))
7442 (sd (org-agenda-compute-starting-span sd span n))
7443 (org-agenda-overriding-cmd
7444 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7445 (org-agenda-overriding-arguments
7446 (list (car args) sd span)))
7447 (org-agenda-redo)
7448 (org-agenda-find-same-or-today-or-agenda))
7449 (org-agenda-set-mode-name)
7450 (message "Switched to %s view" span)))
7452 (defun org-agenda-compute-starting-span (sd span &optional n)
7453 "Compute starting date for agenda.
7454 SPAN may be `day', `week', `month', `year'. The return value
7455 is a cons cell with the starting date and the number of days,
7456 so that the date SD will be in that range."
7457 (let* ((greg (calendar-gregorian-from-absolute sd))
7458 (dg (nth 1 greg))
7459 (mg (car greg))
7460 (yg (nth 2 greg)))
7461 (cond
7462 ((eq span 'day)
7463 (when n
7464 (setq sd (+ (calendar-absolute-from-gregorian
7465 (list mg 1 yg))
7466 n -1))))
7467 ((eq span 'week)
7468 (let* ((nt (calendar-day-of-week
7469 (calendar-gregorian-from-absolute sd)))
7470 (d (if org-agenda-start-on-weekday
7471 (- nt org-agenda-start-on-weekday)
7474 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7475 (when n
7476 (require 'cal-iso)
7477 (when (> n 99)
7478 (setq y1 (org-small-year-to-year (/ n 100))
7479 n (mod n 100)))
7480 (setq sd
7481 (calendar-absolute-from-iso
7482 (list n 1
7483 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7484 ((eq span 'month)
7485 (let (y1)
7486 (when (and n (> n 99))
7487 (setq y1 (org-small-year-to-year (/ n 100))
7488 n (mod n 100)))
7489 (setq sd (calendar-absolute-from-gregorian
7490 (list (or n mg) 1 (or y1 yg))))))
7491 ((eq span 'year)
7492 (setq sd (calendar-absolute-from-gregorian
7493 (list 1 1 (or n yg))))))
7494 sd))
7496 (defun org-agenda-next-date-line (&optional arg)
7497 "Jump to the next line indicating a date in agenda buffer."
7498 (interactive "p")
7499 (org-agenda-check-type t 'agenda 'timeline)
7500 (beginning-of-line 1)
7501 ;; This does not work if user makes date format that starts with a blank
7502 (if (looking-at "^\\S-") (forward-char 1))
7503 (if (not (re-search-forward "^\\S-" nil t arg))
7504 (progn
7505 (backward-char 1)
7506 (error "No next date after this line in this buffer")))
7507 (goto-char (match-beginning 0)))
7509 (defun org-agenda-previous-date-line (&optional arg)
7510 "Jump to the previous line indicating a date in agenda buffer."
7511 (interactive "p")
7512 (org-agenda-check-type t 'agenda 'timeline)
7513 (beginning-of-line 1)
7514 (if (not (re-search-backward "^\\S-" nil t arg))
7515 (error "No previous date before this line in this buffer")))
7517 ;; Initialize the highlight
7518 (defvar org-hl (make-overlay 1 1))
7519 (overlay-put org-hl 'face 'highlight)
7521 (defun org-highlight (begin end &optional buffer)
7522 "Highlight a region with overlay."
7523 (move-overlay org-hl begin end (or buffer (current-buffer))))
7525 (defun org-unhighlight ()
7526 "Detach overlay INDEX."
7527 (org-detach-overlay org-hl))
7529 (defun org-unhighlight-once ()
7530 "Remove the highlight from its position, and this function from the hook."
7531 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7532 (org-unhighlight))
7534 (defvar org-agenda-pre-follow-window-conf nil)
7535 (defun org-agenda-follow-mode ()
7536 "Toggle follow mode in an agenda buffer."
7537 (interactive)
7538 (unless org-agenda-follow-mode
7539 (setq org-agenda-pre-follow-window-conf
7540 (current-window-configuration)))
7541 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7542 (unless org-agenda-follow-mode
7543 (set-window-configuration org-agenda-pre-follow-window-conf))
7544 (org-agenda-set-mode-name)
7545 (org-agenda-do-context-action)
7546 (message "Follow mode is %s"
7547 (if org-agenda-follow-mode "on" "off")))
7549 (defun org-agenda-entry-text-mode (&optional arg)
7550 "Toggle entry text mode in an agenda buffer."
7551 (interactive "P")
7552 (setq org-agenda-entry-text-mode (or (integerp arg)
7553 (not org-agenda-entry-text-mode)))
7554 (org-agenda-entry-text-hide)
7555 (and org-agenda-entry-text-mode
7556 (let ((org-agenda-entry-text-maxlines
7557 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7558 (org-agenda-entry-text-show)))
7559 (org-agenda-set-mode-name)
7560 (message "Entry text mode is %s. Maximum number of lines is %d"
7561 (if org-agenda-entry-text-mode "on" "off")
7562 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7564 (defun org-agenda-clockreport-mode (&optional with-filter)
7565 "Toggle clocktable mode in an agenda buffer.
7566 With prefix arg WITH-FILTER, make the clocktable respect the current
7567 agenda filter."
7568 (interactive "P")
7569 (org-agenda-check-type t 'agenda)
7570 (if with-filter
7571 (setq org-agenda-clockreport-mode 'with-filter)
7572 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7573 (org-agenda-set-mode-name)
7574 (org-agenda-redo)
7575 (message "Clocktable mode is %s"
7576 (if org-agenda-clockreport-mode "on" "off")))
7578 (defun org-agenda-log-mode (&optional special)
7579 "Toggle log mode in an agenda buffer.
7580 With argument SPECIAL, show all possible log items, not only the ones
7581 configured in `org-agenda-log-mode-items'.
7582 With a double `C-u' prefix arg, show *only* log items, nothing else."
7583 (interactive "P")
7584 (org-agenda-check-type t 'agenda 'timeline)
7585 (setq org-agenda-show-log
7586 (cond
7587 ((equal special '(16)) 'only)
7588 ((eq special 'clockcheck)
7589 (if (eq org-agenda-show-log 'clockcheck)
7590 nil 'clockcheck))
7591 (special '(closed clock state))
7592 (t (not org-agenda-show-log))))
7593 (org-agenda-set-mode-name)
7594 (org-agenda-redo)
7595 (message "Log mode is %s"
7596 (if org-agenda-show-log "on" "off")))
7598 (defun org-agenda-archives-mode (&optional with-files)
7599 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7600 When called with a prefix argument, include all archive files as well."
7601 (interactive "P")
7602 (setq org-agenda-archives-mode
7603 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7604 (org-agenda-set-mode-name)
7605 (org-agenda-redo)
7606 (message
7607 "%s"
7608 (cond
7609 ((eq org-agenda-archives-mode nil)
7610 "No archives are included")
7611 ((eq org-agenda-archives-mode 'trees)
7612 (format "Trees with :%s: tag are included" org-archive-tag))
7613 ((eq org-agenda-archives-mode t)
7614 (format "Trees with :%s: tag and all active archive files are included"
7615 org-archive-tag)))))
7617 (defun org-agenda-toggle-diary ()
7618 "Toggle diary inclusion in an agenda buffer."
7619 (interactive)
7620 (org-agenda-check-type t 'agenda)
7621 (setq org-agenda-include-diary (not org-agenda-include-diary))
7622 (org-agenda-redo)
7623 (org-agenda-set-mode-name)
7624 (message "Diary inclusion turned %s"
7625 (if org-agenda-include-diary "on" "off")))
7627 (defun org-agenda-toggle-deadlines ()
7628 "Toggle inclusion of entries with a deadline in an agenda buffer."
7629 (interactive)
7630 (org-agenda-check-type t 'agenda)
7631 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7632 (org-agenda-redo)
7633 (org-agenda-set-mode-name)
7634 (message "Deadlines inclusion turned %s"
7635 (if org-agenda-include-deadlines "on" "off")))
7637 (defun org-agenda-toggle-time-grid ()
7638 "Toggle time grid in an agenda buffer."
7639 (interactive)
7640 (org-agenda-check-type t 'agenda)
7641 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7642 (org-agenda-redo)
7643 (org-agenda-set-mode-name)
7644 (message "Time-grid turned %s"
7645 (if org-agenda-use-time-grid "on" "off")))
7647 (defun org-agenda-set-mode-name ()
7648 "Set the mode name to indicate all the small mode settings."
7649 (setq mode-name
7650 (list "Org-Agenda"
7651 (if (get 'org-agenda-files 'org-restrict) " []" "")
7653 '(:eval (org-agenda-span-name org-agenda-current-span))
7654 (if org-agenda-follow-mode " Follow" "")
7655 (if org-agenda-entry-text-mode " ETxt" "")
7656 (if org-agenda-include-diary " Diary" "")
7657 (if org-agenda-include-deadlines " Ddl" "")
7658 (if org-agenda-use-time-grid " Grid" "")
7659 (if (and (boundp 'org-habit-show-habits)
7660 org-habit-show-habits) " Habit" "")
7661 (cond
7662 ((consp org-agenda-show-log) " LogAll")
7663 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7664 (org-agenda-show-log " Log")
7665 (t ""))
7666 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7667 :preset-filter))
7668 '(:eval (org-propertize
7669 (concat " <"
7670 (mapconcat
7671 'identity
7672 (append
7673 (get 'org-agenda-category-filter :preset-filter)
7674 org-agenda-category-filter)
7676 ">")
7677 'face 'org-agenda-filter-category
7678 'help-echo "Category used in filtering"))
7680 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7681 :preset-filter))
7682 '(:eval (org-propertize
7683 (concat " {"
7684 (mapconcat
7685 'identity
7686 (append
7687 (get 'org-agenda-tag-filter :preset-filter)
7688 org-agenda-tag-filter)
7690 "}")
7691 'face 'org-agenda-filter-tags
7692 'help-echo "Tags used in filtering"))
7694 (if org-agenda-archives-mode
7695 (if (eq org-agenda-archives-mode t)
7696 " Archives"
7697 (format " :%s:" org-archive-tag))
7699 (if org-agenda-clockreport-mode
7700 (if (eq org-agenda-clockreport-mode 'with-filter)
7701 " Clock{}" " Clock")
7702 "")))
7703 (force-mode-line-update))
7705 (org-define-obsolete-function-alias
7706 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7708 (defun org-agenda-update-agenda-type ()
7709 "Update the agenda type after each command."
7710 (setq org-agenda-type
7711 (or (get-text-property (point) 'org-agenda-type)
7712 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7714 (defun org-agenda-next-line ()
7715 "Move cursor to the next line, and show if follow mode is active."
7716 (interactive)
7717 (call-interactively 'next-line)
7718 (org-agenda-do-context-action))
7720 (defun org-agenda-previous-line ()
7721 "Move cursor to the previous line, and show if follow-mode is active."
7722 (interactive)
7723 (call-interactively 'previous-line)
7724 (org-agenda-do-context-action))
7726 (defun org-agenda-next-item (n)
7727 "Move cursor to next agenda item."
7728 (interactive "p")
7729 (let ((col (current-column)))
7730 (dotimes (c n)
7731 (when (next-single-property-change (point-at-eol) 'org-marker)
7732 (move-end-of-line 1)
7733 (goto-char (next-single-property-change (point) 'org-marker))))
7734 (org-move-to-column col))
7735 (org-agenda-do-context-action))
7737 (defun org-agenda-previous-item (n)
7738 "Move cursor to next agenda item."
7739 (interactive "p")
7740 (dotimes (c n)
7741 (let ((col (current-column))
7742 (goto (save-excursion
7743 (move-end-of-line 0)
7744 (previous-single-property-change (point) 'org-marker))))
7745 (if goto (goto-char goto))
7746 (org-move-to-column col)))
7747 (org-agenda-do-context-action))
7749 (defun org-agenda-do-context-action ()
7750 "Show outline path and, maybe, follow mode window."
7751 (let ((m (org-get-at-bol 'org-marker)))
7752 (when (and (markerp m) (marker-buffer m))
7753 (and org-agenda-follow-mode
7754 (if org-agenda-follow-indirect
7755 (org-agenda-tree-to-indirect-buffer nil)
7756 (org-agenda-show)))
7757 (and org-agenda-show-outline-path
7758 (org-with-point-at m (org-display-outline-path t))))))
7760 (defun org-agenda-show-tags ()
7761 "Show the tags applicable to the current item."
7762 (interactive)
7763 (let* ((tags (org-get-at-bol 'tags)))
7764 (if tags
7765 (message "Tags are :%s:"
7766 (org-no-properties (mapconcat 'identity tags ":")))
7767 (message "No tags associated with this line"))))
7769 (defun org-agenda-goto (&optional highlight)
7770 "Go to the Org-mode file which contains the item at point."
7771 (interactive)
7772 (let* ((marker (or (org-get-at-bol 'org-marker)
7773 (org-agenda-error)))
7774 (buffer (marker-buffer marker))
7775 (pos (marker-position marker)))
7776 (switch-to-buffer-other-window buffer)
7777 (widen)
7778 (push-mark)
7779 (goto-char pos)
7780 (when (derived-mode-p 'org-mode)
7781 (org-show-context 'agenda)
7782 (save-excursion
7783 (and (outline-next-heading)
7784 (org-flag-heading nil)))) ; show the next heading
7785 (when (outline-invisible-p)
7786 (show-entry)) ; display invisible text
7787 (recenter (/ (window-height) 2))
7788 (run-hooks 'org-agenda-after-show-hook)
7789 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7791 (defvar org-agenda-after-show-hook nil
7792 "Normal hook run after an item has been shown from the agenda.
7793 Point is in the buffer where the item originated.")
7795 (defun org-agenda-kill ()
7796 "Kill the entry or subtree belonging to the current agenda entry."
7797 (interactive)
7798 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7799 (let* ((bufname-orig (buffer-name))
7800 (marker (or (org-get-at-bol 'org-marker)
7801 (org-agenda-error)))
7802 (buffer (marker-buffer marker))
7803 (pos (marker-position marker))
7804 (type (org-get-at-bol 'type))
7805 dbeg dend (n 0) conf)
7806 (org-with-remote-undo buffer
7807 (with-current-buffer buffer
7808 (save-excursion
7809 (goto-char pos)
7810 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7811 (setq dbeg (progn (org-back-to-heading t) (point))
7812 dend (org-end-of-subtree t t))
7813 (setq dbeg (point-at-bol)
7814 dend (min (point-max) (1+ (point-at-eol)))))
7815 (goto-char dbeg)
7816 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7817 (setq conf (or (eq t org-agenda-confirm-kill)
7818 (and (numberp org-agenda-confirm-kill)
7819 (> n org-agenda-confirm-kill))))
7820 (and conf
7821 (not (y-or-n-p
7822 (format "Delete entry with %d lines in buffer \"%s\"? "
7823 n (buffer-name buffer))))
7824 (error "Abort"))
7825 (let ((org-agenda-buffer-name bufname-orig))
7826 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7827 (with-current-buffer buffer (delete-region dbeg dend))
7828 (message "Agenda item and source killed"))))
7830 (defvar org-archive-default-command) ; defined in org-archive.el
7831 (defun org-agenda-archive-default ()
7832 "Archive the entry or subtree belonging to the current agenda entry."
7833 (interactive)
7834 (require 'org-archive)
7835 (org-agenda-archive-with org-archive-default-command))
7837 (defun org-agenda-archive-default-with-confirmation ()
7838 "Archive the entry or subtree belonging to the current agenda entry."
7839 (interactive)
7840 (require 'org-archive)
7841 (org-agenda-archive-with org-archive-default-command 'confirm))
7843 (defun org-agenda-archive ()
7844 "Archive the entry or subtree belonging to the current agenda entry."
7845 (interactive)
7846 (org-agenda-archive-with 'org-archive-subtree))
7848 (defun org-agenda-archive-to-archive-sibling ()
7849 "Move the entry to the archive sibling."
7850 (interactive)
7851 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7853 (defun org-agenda-archive-with (cmd &optional confirm)
7854 "Move the entry to the archive sibling."
7855 (interactive)
7856 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7857 (let* ((bufname-orig (buffer-name))
7858 (marker (or (org-get-at-bol 'org-marker)
7859 (org-agenda-error)))
7860 (buffer (marker-buffer marker))
7861 (pos (marker-position marker)))
7862 (org-with-remote-undo buffer
7863 (with-current-buffer buffer
7864 (if (derived-mode-p 'org-mode)
7865 (if (and confirm
7866 (not (y-or-n-p "Archive this subtree or entry? ")))
7867 (error "Abort")
7868 (save-excursion
7869 (goto-char pos)
7870 (let ((org-agenda-buffer-name bufname-orig))
7871 (org-remove-subtree-entries-from-agenda))
7872 (org-back-to-heading t)
7873 (funcall cmd)))
7874 (error "Archiving works only in Org-mode files"))))))
7876 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7877 "Remove all lines in the agenda that correspond to a given subtree.
7878 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7879 If this information is not given, the function uses the tree at point."
7880 (let ((buf (or buf (current-buffer))) m p)
7881 (save-excursion
7882 (unless (and beg end)
7883 (org-back-to-heading t)
7884 (setq beg (point))
7885 (org-end-of-subtree t)
7886 (setq end (point)))
7887 (set-buffer (get-buffer org-agenda-buffer-name))
7888 (save-excursion
7889 (goto-char (point-max))
7890 (beginning-of-line 1)
7891 (while (not (bobp))
7892 (when (and (setq m (org-get-at-bol 'org-marker))
7893 (equal buf (marker-buffer m))
7894 (setq p (marker-position m))
7895 (>= p beg)
7896 (< p end))
7897 (let ((inhibit-read-only t))
7898 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7899 (beginning-of-line 0))))))
7901 (defun org-agenda-refile (&optional goto rfloc no-update)
7902 "Refile the item at point."
7903 (interactive "P")
7904 (if (equal goto '(16))
7905 (org-refile-goto-last-stored)
7906 (let* ((buffer-orig (buffer-name))
7907 (marker (or (org-get-at-bol 'org-hd-marker)
7908 (org-agenda-error)))
7909 (buffer (marker-buffer marker))
7910 (pos (marker-position marker))
7911 (rfloc (or rfloc
7912 (org-refile-get-location
7913 (if goto "Goto" "Refile to") buffer
7914 org-refile-allow-creating-parent-nodes))))
7915 (with-current-buffer buffer
7916 (save-excursion
7917 (save-restriction
7918 (widen)
7919 (goto-char marker)
7920 (let ((org-agenda-buffer-name buffer-orig))
7921 (org-remove-subtree-entries-from-agenda))
7922 (org-refile goto buffer rfloc)))))
7923 (unless no-update (org-agenda-redo))))
7925 (defun org-agenda-open-link (&optional arg)
7926 "Open the link(s) in the current entry, if any.
7927 This looks for a link in the displayed line in the agenda.
7928 It also looks at the text of the entry itself."
7929 (interactive "P")
7930 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7931 (org-get-at-bol 'org-marker)))
7932 (buffer (and marker (marker-buffer marker)))
7933 (prefix (buffer-substring
7934 (point-at-bol) (point-at-eol)))
7935 (lkall (org-offer-links-in-entry buffer marker arg prefix))
7936 (lk (car lkall))
7937 (lkend (cdr lkall))
7938 trg)
7939 (cond
7940 ((and buffer (stringp lk))
7941 (with-current-buffer buffer
7942 (setq trg (and (string-match org-bracket-link-regexp lk)
7943 (match-string 1 lk)))
7944 (if (or (not trg) (string-match org-any-link-re trg))
7945 (save-excursion
7946 (save-restriction
7947 (widen)
7948 (goto-char marker)
7949 (when (search-forward lk nil lkend)
7950 (goto-char (match-beginning 0))
7951 (org-open-at-point))))
7952 ;; This is an internal link, widen the buffer
7953 (switch-to-buffer-other-window buffer)
7954 (widen)
7955 (goto-char marker)
7956 (when (search-forward lk nil lkend)
7957 (goto-char (match-beginning 0))
7958 (org-open-at-point)))))
7959 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7960 (save-excursion
7961 (beginning-of-line 1)
7962 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7963 (org-open-link-from-string (match-string 1)))
7964 (t (message "No link to open here")))))
7966 (defun org-agenda-copy-local-variable (var)
7967 "Get a variable from a referenced buffer and install it here."
7968 (let ((m (org-get-at-bol 'org-marker)))
7969 (when (and m (buffer-live-p (marker-buffer m)))
7970 (org-set-local var (with-current-buffer (marker-buffer m)
7971 (symbol-value var))))))
7973 (defun org-agenda-switch-to (&optional delete-other-windows)
7974 "Go to the Org-mode file which contains the item at point."
7975 (interactive)
7976 (if (and org-return-follows-link
7977 (not (org-get-at-bol 'org-marker))
7978 (org-in-regexp org-bracket-link-regexp))
7979 (org-open-link-from-string (match-string 0))
7980 (let* ((marker (or (org-get-at-bol 'org-marker)
7981 (org-agenda-error)))
7982 (buffer (marker-buffer marker))
7983 (pos (marker-position marker)))
7984 (org-pop-to-buffer-same-window buffer)
7985 (and delete-other-windows (delete-other-windows))
7986 (widen)
7987 (goto-char pos)
7988 (when (derived-mode-p 'org-mode)
7989 (org-show-context 'agenda)
7990 (save-excursion
7991 (and (outline-next-heading)
7992 (org-flag-heading nil))) ; show the next heading
7993 (when (outline-invisible-p)
7994 (show-entry)) ; display invisible text
7995 (run-hooks 'org-agenda-after-show-hook)))))
7997 (defun org-agenda-goto-mouse (ev)
7998 "Go to the Org-mode file which contains the item at the mouse click."
7999 (interactive "e")
8000 (mouse-set-point ev)
8001 (org-agenda-goto))
8003 (defun org-agenda-show (&optional full-entry)
8004 "Display the Org-mode file which contains the item at point.
8005 With prefix argument FULL-ENTRY, make the entire entry visible
8006 if it was hidden in the outline."
8007 (interactive "P")
8008 (let ((win (selected-window)))
8009 (if full-entry
8010 (let ((org-show-entry-below t))
8011 (org-agenda-goto t))
8012 (org-agenda-goto t))
8013 (select-window win)))
8015 (defvar org-agenda-show-window nil)
8016 (defun org-agenda-show-and-scroll-up (&optional arg)
8017 "Display the Org-mode file which contains the item at point.
8018 When called repeatedly, scroll the window that is displaying the buffer.
8019 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8020 `show-subtree' to display the item, so that drawers and logbooks stay
8021 folded."
8022 (interactive "P")
8023 (let ((win (selected-window)))
8024 (if (and (window-live-p org-agenda-show-window)
8025 (eq this-command last-command))
8026 (progn
8027 (select-window org-agenda-show-window)
8028 (ignore-errors (scroll-up)))
8029 (org-agenda-goto t)
8030 (if arg (org-show-entry) (show-subtree))
8031 (setq org-agenda-show-window (selected-window)))
8032 (select-window win)))
8034 (defun org-agenda-show-scroll-down ()
8035 "Scroll down the window showing the agenda."
8036 (interactive)
8037 (let ((win (selected-window)))
8038 (when (window-live-p org-agenda-show-window)
8039 (select-window org-agenda-show-window)
8040 (ignore-errors (scroll-down))
8041 (select-window win))))
8043 (defun org-agenda-show-1 (&optional more)
8044 "Display the Org-mode file which contains the item at point.
8045 The prefix arg selects the amount of information to display:
8047 0 hide the subtree
8048 1 just show the entry according to defaults.
8049 2 show the children view
8050 3 show the subtree view
8051 4 show the entire subtree and any LOGBOOK drawers
8052 5 show the entire subtree and any drawers
8053 With prefix argument FULL-ENTRY, make the entire entry visible
8054 if it was hidden in the outline."
8055 (interactive "p")
8056 (let ((win (selected-window)))
8057 (org-agenda-goto t)
8058 (org-recenter-heading 1)
8059 (cond
8060 ((= more 0)
8061 (hide-subtree)
8062 (save-excursion
8063 (org-back-to-heading)
8064 (run-hook-with-args 'org-cycle-hook 'folded))
8065 (message "Remote: FOLDED"))
8066 ((and (org-called-interactively-p 'any) (= more 1))
8067 (message "Remote: show with default settings"))
8068 ((= more 2)
8069 (show-entry)
8070 (show-children)
8071 (save-excursion
8072 (org-back-to-heading)
8073 (run-hook-with-args 'org-cycle-hook 'children))
8074 (message "Remote: CHILDREN"))
8075 ((= more 3)
8076 (show-subtree)
8077 (save-excursion
8078 (org-back-to-heading)
8079 (run-hook-with-args 'org-cycle-hook 'subtree))
8080 (message "Remote: SUBTREE"))
8081 ((= more 4)
8082 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8083 (org-drawer-regexp
8084 (concat "^[ \t]*:\\("
8085 (mapconcat 'regexp-quote org-drawers "\\|")
8086 "\\):[ \t]*$")))
8087 (show-subtree)
8088 (save-excursion
8089 (org-back-to-heading)
8090 (org-cycle-hide-drawers 'subtree)))
8091 (message "Remote: SUBTREE AND LOGBOOK"))
8092 ((> more 4)
8093 (show-subtree)
8094 (message "Remote: SUBTREE AND ALL DRAWERS")))
8095 (select-window win)))
8097 (defun org-recenter-heading (n)
8098 (save-excursion
8099 (org-back-to-heading)
8100 (recenter n)))
8102 (defvar org-agenda-cycle-counter nil)
8103 (defun org-agenda-cycle-show (&optional n)
8104 "Show the current entry in another window, with default settings.
8105 Default settings are taken from `org-show-hierarchy-above' and siblings.
8106 When use repeatedly in immediate succession, the remote entry will cycle
8107 through visibility
8109 children -> subtree -> folded
8111 When called with a numeric prefix arg, that arg will be passed through to
8112 `org-agenda-show-1'. For the interpretation of that argument, see the
8113 docstring of `org-agenda-show-1'."
8114 (interactive "P")
8115 (if (integerp n)
8116 (setq org-agenda-cycle-counter n)
8117 (if (not (eq last-command this-command))
8118 (setq org-agenda-cycle-counter 1)
8119 (if (equal org-agenda-cycle-counter 0)
8120 (setq org-agenda-cycle-counter 2)
8121 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8122 (if (> org-agenda-cycle-counter 3)
8123 (setq org-agenda-cycle-counter 0)))))
8124 (org-agenda-show-1 org-agenda-cycle-counter))
8126 (defun org-agenda-recenter (arg)
8127 "Display the Org-mode file which contains the item at point and recenter."
8128 (interactive "P")
8129 (let ((win (selected-window)))
8130 (org-agenda-goto t)
8131 (recenter arg)
8132 (select-window win)))
8134 (defun org-agenda-show-mouse (ev)
8135 "Display the Org-mode file which contains the item at the mouse click."
8136 (interactive "e")
8137 (mouse-set-point ev)
8138 (org-agenda-show))
8140 (defun org-agenda-check-no-diary ()
8141 "Check if the entry is a diary link and abort if yes."
8142 (if (org-get-at-bol 'org-agenda-diary-link)
8143 (org-agenda-error)))
8145 (defun org-agenda-error ()
8146 (error "Command not allowed in this line"))
8148 (defun org-agenda-tree-to-indirect-buffer (arg)
8149 "Show the subtree corresponding to the current entry in an indirect buffer.
8150 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8152 With a numerical prefix ARG, go up to this level and then take that tree.
8153 With a negative numeric ARG, go up by this number of levels.
8154 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8155 use the dedicated frame)."
8156 (interactive "P")
8157 (if current-prefix-arg
8158 (org-agenda-do-tree-to-indirect-buffer arg)
8159 (let ((agenda-buffer (buffer-name))
8160 (agenda-window (selected-window))
8161 (indirect-window
8162 (and org-last-indirect-buffer
8163 (get-buffer-window org-last-indirect-buffer))))
8164 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8165 (unless (or (eq org-indirect-buffer-display 'new-frame)
8166 (eq org-indirect-buffer-display 'dedicated-frame))
8167 (unwind-protect
8168 (unless (and indirect-window (window-live-p indirect-window))
8169 (setq indirect-window (split-window agenda-window)))
8170 (and indirect-window (select-window indirect-window))
8171 (switch-to-buffer org-last-indirect-buffer :norecord)
8172 (fit-window-to-buffer indirect-window)))
8173 (select-window (get-buffer-window agenda-buffer)))))
8175 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8176 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8177 (org-agenda-check-no-diary)
8178 (let* ((marker (or (org-get-at-bol 'org-marker)
8179 (org-agenda-error)))
8180 (buffer (marker-buffer marker))
8181 (pos (marker-position marker)))
8182 (with-current-buffer buffer
8183 (save-excursion
8184 (goto-char pos)
8185 (funcall 'org-tree-to-indirect-buffer arg)))))
8187 (defvar org-last-heading-marker (make-marker)
8188 "Marker pointing to the headline that last changed its TODO state
8189 by a remote command from the agenda.")
8191 (defun org-agenda-todo-nextset ()
8192 "Switch TODO entry to next sequence."
8193 (interactive)
8194 (org-agenda-todo 'nextset))
8196 (defun org-agenda-todo-previousset ()
8197 "Switch TODO entry to previous sequence."
8198 (interactive)
8199 (org-agenda-todo 'previousset))
8201 (defun org-agenda-todo (&optional arg)
8202 "Cycle TODO state of line at point, also in Org-mode file.
8203 This changes the line at point, all other lines in the agenda referring to
8204 the same tree node, and the headline of the tree node in the Org-mode file."
8205 (interactive "P")
8206 (org-agenda-check-no-diary)
8207 (let* ((col (current-column))
8208 (marker (or (org-get-at-bol 'org-marker)
8209 (org-agenda-error)))
8210 (buffer (marker-buffer marker))
8211 (pos (marker-position marker))
8212 (hdmarker (org-get-at-bol 'org-hd-marker))
8213 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8214 (inhibit-read-only t)
8215 org-agenda-headline-snapshot-before-repeat newhead just-one)
8216 (org-with-remote-undo buffer
8217 (with-current-buffer buffer
8218 (widen)
8219 (goto-char pos)
8220 (org-show-context 'agenda)
8221 (save-excursion
8222 (and (outline-next-heading)
8223 (org-flag-heading nil))) ; show the next heading
8224 (let ((current-prefix-arg arg))
8225 (call-interactively 'org-todo))
8226 (and (bolp) (forward-char 1))
8227 (setq newhead (org-get-heading))
8228 (when (and (org-bound-and-true-p
8229 org-agenda-headline-snapshot-before-repeat)
8230 (not (equal org-agenda-headline-snapshot-before-repeat
8231 newhead))
8232 todayp)
8233 (setq newhead org-agenda-headline-snapshot-before-repeat
8234 just-one t))
8235 (save-excursion
8236 (org-back-to-heading)
8237 (move-marker org-last-heading-marker (point))))
8238 (beginning-of-line 1)
8239 (save-excursion
8240 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8241 (org-move-to-column col))))
8243 (defun org-agenda-add-note (&optional arg)
8244 "Add a time-stamped note to the entry at point."
8245 (interactive "P")
8246 (org-agenda-check-no-diary)
8247 (let* ((marker (or (org-get-at-bol 'org-marker)
8248 (org-agenda-error)))
8249 (buffer (marker-buffer marker))
8250 (pos (marker-position marker))
8251 (hdmarker (org-get-at-bol 'org-hd-marker))
8252 (inhibit-read-only t))
8253 (with-current-buffer buffer
8254 (widen)
8255 (goto-char pos)
8256 (org-show-context 'agenda)
8257 (save-excursion
8258 (and (outline-next-heading)
8259 (org-flag-heading nil))) ; show the next heading
8260 (org-add-note))))
8262 (defun org-agenda-change-all-lines (newhead hdmarker
8263 &optional fixface just-this)
8264 "Change all lines in the agenda buffer which match HDMARKER.
8265 The new content of the line will be NEWHEAD (as modified by
8266 `org-agenda-format-item'). HDMARKER is checked with
8267 `equal' against all `org-hd-marker' text properties in the file.
8268 If FIXFACE is non-nil, the face of each item is modified according to
8269 the new TODO state.
8270 If JUST-THIS is non-nil, change just the current line, not all.
8271 If FORCE-TAGS is non nil, the car of it returns the new tags."
8272 (let* ((inhibit-read-only t)
8273 (line (org-current-line))
8274 (org-agenda-buffer (current-buffer))
8275 (thetags (with-current-buffer (marker-buffer hdmarker)
8276 (save-excursion (save-restriction (widen)
8277 (goto-char hdmarker)
8278 (org-get-tags-at)))))
8279 props m pl undone-face done-face finish new dotime cat tags)
8280 (save-excursion
8281 (goto-char (point-max))
8282 (beginning-of-line 1)
8283 (while (not finish)
8284 (setq finish (bobp))
8285 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8286 (or (not just-this) (= (org-current-line) line))
8287 (equal m hdmarker))
8288 (setq props (text-properties-at (point))
8289 dotime (org-get-at-bol 'dotime)
8290 cat (org-get-at-bol 'org-category)
8291 tags thetags
8293 (let ((org-prefix-format-compiled
8294 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8295 org-prefix-format-compiled))
8296 (extra (org-get-at-bol 'extra)))
8297 (with-current-buffer (marker-buffer hdmarker)
8298 (save-excursion
8299 (save-restriction
8300 (widen)
8301 (org-agenda-format-item extra newhead cat tags dotime)))))
8302 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8303 undone-face (org-get-at-bol 'undone-face)
8304 done-face (org-get-at-bol 'done-face))
8305 (beginning-of-line 1)
8306 (cond
8307 ((equal new "")
8308 (and (looking-at ".*\n?") (replace-match "")))
8309 ((looking-at ".*")
8310 (replace-match new t t)
8311 (beginning-of-line 1)
8312 (add-text-properties (point-at-bol) (point-at-eol) props)
8313 (when fixface
8314 (add-text-properties
8315 (point-at-bol) (point-at-eol)
8316 (list 'face
8317 (if org-last-todo-state-is-todo
8318 undone-face done-face))))
8319 (org-agenda-highlight-todo 'line)
8320 (beginning-of-line 1))
8321 (t (error "Line update did not work")))
8322 (save-restriction
8323 (narrow-to-region (point-at-bol) (point-at-eol))
8324 (org-agenda-finalize)))
8325 (beginning-of-line 0)))))
8327 (defun org-agenda-align-tags (&optional line)
8328 "Align all tags in agenda items to `org-agenda-tags-column'."
8329 (let ((inhibit-read-only t) l c)
8330 (save-excursion
8331 (goto-char (if line (point-at-bol) (point-min)))
8332 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8333 (if line (point-at-eol) nil) t)
8334 (add-text-properties
8335 (match-beginning 2) (match-end 2)
8336 (list 'face (delq nil (let ((prop (get-text-property
8337 (match-beginning 2) 'face)))
8338 (or (listp prop) (setq prop (list prop)))
8339 (if (memq 'org-tag prop)
8340 prop
8341 (cons 'org-tag prop))))))
8342 (setq l (- (match-end 2) (match-beginning 2))
8343 c (if (< org-agenda-tags-column 0)
8344 (- (abs org-agenda-tags-column) l)
8345 org-agenda-tags-column))
8346 (delete-region (match-beginning 1) (match-end 1))
8347 (goto-char (match-beginning 1))
8348 (insert (org-add-props
8349 (make-string (max 1 (- c (current-column))) ?\ )
8350 (plist-put (copy-sequence (text-properties-at (point)))
8351 'face nil))))
8352 (goto-char (point-min))
8353 (org-font-lock-add-tag-faces (point-max)))))
8355 (defun org-agenda-priority-up ()
8356 "Increase the priority of line at point, also in Org-mode file."
8357 (interactive)
8358 (org-agenda-priority 'up))
8360 (defun org-agenda-priority-down ()
8361 "Decrease the priority of line at point, also in Org-mode file."
8362 (interactive)
8363 (org-agenda-priority 'down))
8365 (defun org-agenda-priority (&optional force-direction)
8366 "Set the priority of line at point, also in Org-mode file.
8367 This changes the line at point, all other lines in the agenda referring to
8368 the same tree node, and the headline of the tree node in the Org-mode file.
8369 Called with a universal prefix arg, show the priority instead of setting it."
8370 (interactive "P")
8371 (if (equal force-direction '(4))
8372 (org-show-priority)
8373 (unless org-enable-priority-commands
8374 (error "Priority commands are disabled"))
8375 (org-agenda-check-no-diary)
8376 (let* ((marker (or (org-get-at-bol 'org-marker)
8377 (org-agenda-error)))
8378 (hdmarker (org-get-at-bol 'org-hd-marker))
8379 (buffer (marker-buffer hdmarker))
8380 (pos (marker-position hdmarker))
8381 (inhibit-read-only t)
8382 newhead)
8383 (org-with-remote-undo buffer
8384 (with-current-buffer buffer
8385 (widen)
8386 (goto-char pos)
8387 (org-show-context 'agenda)
8388 (save-excursion
8389 (and (outline-next-heading)
8390 (org-flag-heading nil))) ; show the next heading
8391 (funcall 'org-priority force-direction)
8392 (end-of-line 1)
8393 (setq newhead (org-get-heading)))
8394 (org-agenda-change-all-lines newhead hdmarker)
8395 (beginning-of-line 1)))))
8397 ;; FIXME: should fix the tags property of the agenda line.
8398 (defun org-agenda-set-tags (&optional tag onoff)
8399 "Set tags for the current headline."
8400 (interactive)
8401 (org-agenda-check-no-diary)
8402 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8403 (call-interactively 'org-change-tag-in-region)
8404 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8405 (org-agenda-error)))
8406 (buffer (marker-buffer hdmarker))
8407 (pos (marker-position hdmarker))
8408 (inhibit-read-only t)
8409 newhead)
8410 (org-with-remote-undo buffer
8411 (with-current-buffer buffer
8412 (widen)
8413 (goto-char pos)
8414 (save-excursion
8415 (org-show-context 'agenda))
8416 (save-excursion
8417 (and (outline-next-heading)
8418 (org-flag-heading nil))) ; show the next heading
8419 (goto-char pos)
8420 (if tag
8421 (org-toggle-tag tag onoff)
8422 (call-interactively 'org-set-tags))
8423 (end-of-line 1)
8424 (setq newhead (org-get-heading)))
8425 (org-agenda-change-all-lines newhead hdmarker)
8426 (beginning-of-line 1)))))
8428 (defun org-agenda-set-property ()
8429 "Set a property for the current headline."
8430 (interactive)
8431 (org-agenda-check-no-diary)
8432 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8433 (org-agenda-error)))
8434 (buffer (marker-buffer hdmarker))
8435 (pos (marker-position hdmarker))
8436 (inhibit-read-only t)
8437 newhead)
8438 (org-with-remote-undo buffer
8439 (with-current-buffer buffer
8440 (widen)
8441 (goto-char pos)
8442 (save-excursion
8443 (org-show-context 'agenda))
8444 (save-excursion
8445 (and (outline-next-heading)
8446 (org-flag-heading nil))) ; show the next heading
8447 (goto-char pos)
8448 (call-interactively 'org-set-property)))))
8450 (defun org-agenda-set-effort ()
8451 "Set the effort property for the current headline."
8452 (interactive)
8453 (org-agenda-check-no-diary)
8454 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8455 (org-agenda-error)))
8456 (buffer (marker-buffer hdmarker))
8457 (pos (marker-position hdmarker))
8458 (inhibit-read-only t)
8459 newhead)
8460 (org-with-remote-undo buffer
8461 (with-current-buffer buffer
8462 (widen)
8463 (goto-char pos)
8464 (save-excursion
8465 (org-show-context 'agenda))
8466 (save-excursion
8467 (and (outline-next-heading)
8468 (org-flag-heading nil))) ; show the next heading
8469 (goto-char pos)
8470 (call-interactively 'org-set-effort)
8471 (end-of-line 1)
8472 (setq newhead (org-get-heading)))
8473 (org-agenda-change-all-lines newhead hdmarker))))
8475 (defun org-agenda-toggle-archive-tag ()
8476 "Toggle the archive tag for the current entry."
8477 (interactive)
8478 (org-agenda-check-no-diary)
8479 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8480 (org-agenda-error)))
8481 (buffer (marker-buffer hdmarker))
8482 (pos (marker-position hdmarker))
8483 (inhibit-read-only t)
8484 newhead)
8485 (org-with-remote-undo buffer
8486 (with-current-buffer buffer
8487 (widen)
8488 (goto-char pos)
8489 (org-show-context 'agenda)
8490 (save-excursion
8491 (and (outline-next-heading)
8492 (org-flag-heading nil))) ; show the next heading
8493 (call-interactively 'org-toggle-archive-tag)
8494 (end-of-line 1)
8495 (setq newhead (org-get-heading)))
8496 (org-agenda-change-all-lines newhead hdmarker)
8497 (beginning-of-line 1))))
8499 (defun org-agenda-do-date-later (arg)
8500 (interactive "P")
8501 (cond
8502 ((or (equal arg '(16))
8503 (memq last-command
8504 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8505 (setq this-command 'org-agenda-date-later-minutes)
8506 (org-agenda-date-later-minutes 1))
8507 ((or (equal arg '(4))
8508 (memq last-command
8509 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8510 (setq this-command 'org-agenda-date-later-hours)
8511 (org-agenda-date-later-hours 1))
8513 (org-agenda-date-later (prefix-numeric-value arg)))))
8515 (defun org-agenda-do-date-earlier (arg)
8516 (interactive "P")
8517 (cond
8518 ((or (equal arg '(16))
8519 (memq last-command
8520 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8521 (setq this-command 'org-agenda-date-earlier-minutes)
8522 (org-agenda-date-earlier-minutes 1))
8523 ((or (equal arg '(4))
8524 (memq last-command
8525 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8526 (setq this-command 'org-agenda-date-earlier-hours)
8527 (org-agenda-date-earlier-hours 1))
8529 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8531 (defun org-agenda-date-later (arg &optional what)
8532 "Change the date of this item to ARG day(s) later."
8533 (interactive "p")
8534 (org-agenda-check-type t 'agenda 'timeline)
8535 (org-agenda-check-no-diary)
8536 (let* ((marker (or (org-get-at-bol 'org-marker)
8537 (org-agenda-error)))
8538 (buffer (marker-buffer marker))
8539 (pos (marker-position marker))
8540 cdate today)
8541 (org-with-remote-undo buffer
8542 (with-current-buffer buffer
8543 (widen)
8544 (goto-char pos)
8545 (if (not (org-at-timestamp-p))
8546 (error "Cannot find time stamp"))
8547 (when (and org-agenda-move-date-from-past-immediately-to-today
8548 (equal arg 1)
8549 (or (not what) (eq what 'day))
8550 (not (save-match-data (org-at-date-range-p))))
8551 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8552 cdate (calendar-absolute-from-gregorian
8553 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8554 today (org-today))
8555 (if (> today cdate)
8556 ;; immediately shift to today
8557 (setq arg (- today cdate))))
8558 (org-timestamp-change arg (or what 'day))
8559 (when (and (org-at-date-range-p)
8560 (re-search-backward org-tr-regexp-both (point-at-bol)))
8561 (let ((end org-last-changed-timestamp))
8562 (org-timestamp-change arg (or what 'day))
8563 (setq org-last-changed-timestamp
8564 (concat org-last-changed-timestamp "--" end)))))
8565 (org-agenda-show-new-time marker org-last-changed-timestamp))
8566 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8568 (defun org-agenda-date-earlier (arg &optional what)
8569 "Change the date of this item to ARG day(s) earlier."
8570 (interactive "p")
8571 (org-agenda-date-later (- arg) what))
8573 (defun org-agenda-date-later-minutes (arg)
8574 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8575 (interactive "p")
8576 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8577 (org-agenda-date-later arg 'minute))
8579 (defun org-agenda-date-earlier-minutes (arg)
8580 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8581 (interactive "p")
8582 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8583 (org-agenda-date-earlier arg 'minute))
8585 (defun org-agenda-date-later-hours (arg)
8586 "Change the time of this item, in hour steps."
8587 (interactive "p")
8588 (org-agenda-date-later arg 'hour))
8590 (defun org-agenda-date-earlier-hours (arg)
8591 "Change the time of this item, in hour steps."
8592 (interactive "p")
8593 (org-agenda-date-earlier arg 'hour))
8595 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8596 "Show new date stamp via text properties."
8597 ;; We use text properties to make this undoable
8598 (let ((inhibit-read-only t)
8599 (buffer-invisibility-spec))
8600 (setq stamp (concat " " prefix " => " stamp))
8601 (save-excursion
8602 (goto-char (point-max))
8603 (while (not (bobp))
8604 (when (equal marker (org-get-at-bol 'org-marker))
8605 (org-move-to-column (- (window-width) (length stamp)) t)
8606 (org-agenda-fix-tags-filter-overlays-at (point))
8607 (if (featurep 'xemacs)
8608 ;; Use `duplicable' property to trigger undo recording
8609 (let ((ex (make-extent nil nil))
8610 (gl (make-glyph stamp)))
8611 (set-glyph-face gl 'secondary-selection)
8612 (set-extent-properties
8613 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8614 (insert-extent ex (1- (point)) (point-at-eol)))
8615 (add-text-properties
8616 (1- (point)) (point-at-eol)
8617 (list 'display (org-add-props stamp nil
8618 'face 'secondary-selection))))
8619 (beginning-of-line 1))
8620 (beginning-of-line 0)))))
8622 (defun org-agenda-date-prompt (arg)
8623 "Change the date of this item. Date is prompted for, with default today.
8624 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8625 be used to request time specification in the time stamp."
8626 (interactive "P")
8627 (org-agenda-check-type t 'agenda 'timeline)
8628 (org-agenda-check-no-diary)
8629 (let* ((marker (or (org-get-at-bol 'org-marker)
8630 (org-agenda-error)))
8631 (buffer (marker-buffer marker))
8632 (pos (marker-position marker)))
8633 (org-with-remote-undo buffer
8634 (with-current-buffer buffer
8635 (widen)
8636 (goto-char pos)
8637 (if (not (org-at-timestamp-p t))
8638 (error "Cannot find time stamp"))
8639 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8640 (org-agenda-show-new-time marker org-last-changed-timestamp))
8641 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8643 (defun org-agenda-schedule (arg &optional time)
8644 "Schedule the item at point.
8645 ARG is passed through to `org-schedule'."
8646 (interactive "P")
8647 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8648 (org-agenda-check-no-diary)
8649 (let* ((marker (or (org-get-at-bol 'org-marker)
8650 (org-agenda-error)))
8651 (type (marker-insertion-type marker))
8652 (buffer (marker-buffer marker))
8653 (pos (marker-position marker))
8654 (org-insert-labeled-timestamps-at-point nil)
8656 (set-marker-insertion-type marker t)
8657 (org-with-remote-undo buffer
8658 (with-current-buffer buffer
8659 (widen)
8660 (goto-char pos)
8661 (setq ts (org-schedule arg time)))
8662 (org-agenda-show-new-time marker ts "S"))
8663 (message "%s" ts)))
8665 (defun org-agenda-deadline (arg &optional time)
8666 "Schedule the item at point.
8667 ARG is passed through to `org-deadline'."
8668 (interactive "P")
8669 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8670 (org-agenda-check-no-diary)
8671 (let* ((marker (or (org-get-at-bol 'org-marker)
8672 (org-agenda-error)))
8673 (buffer (marker-buffer marker))
8674 (pos (marker-position marker))
8675 (org-insert-labeled-timestamps-at-point nil)
8677 (org-with-remote-undo buffer
8678 (with-current-buffer buffer
8679 (widen)
8680 (goto-char pos)
8681 (setq ts (org-deadline arg time)))
8682 (org-agenda-show-new-time marker ts "D"))
8683 (message "%s" ts)))
8685 (defun org-agenda-clock-in (&optional arg)
8686 "Start the clock on the currently selected item."
8687 (interactive "P")
8688 (org-agenda-check-no-diary)
8689 (if (equal arg '(4))
8690 (org-clock-in arg)
8691 (let* ((marker (or (org-get-at-bol 'org-marker)
8692 (org-agenda-error)))
8693 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8694 marker))
8695 (pos (marker-position marker))
8696 newhead)
8697 (org-with-remote-undo (marker-buffer marker)
8698 (with-current-buffer (marker-buffer marker)
8699 (widen)
8700 (goto-char pos)
8701 (org-show-context 'agenda)
8702 (org-show-entry)
8703 (org-cycle-hide-drawers 'children)
8704 (org-clock-in arg)
8705 (setq newhead (org-get-heading)))
8706 (org-agenda-change-all-lines newhead hdmarker)))))
8708 (defun org-agenda-clock-out ()
8709 "Stop the currently running clock."
8710 (interactive)
8711 (unless (marker-buffer org-clock-marker)
8712 (error "No running clock"))
8713 (let ((marker (make-marker)) newhead)
8714 (org-with-remote-undo (marker-buffer org-clock-marker)
8715 (with-current-buffer (marker-buffer org-clock-marker)
8716 (save-excursion
8717 (save-restriction
8718 (widen)
8719 (goto-char org-clock-marker)
8720 (org-back-to-heading t)
8721 (move-marker marker (point))
8722 (org-clock-out)
8723 (setq newhead (org-get-heading))))))
8724 (org-agenda-change-all-lines newhead marker)
8725 (move-marker marker nil)))
8727 (defun org-agenda-clock-cancel (&optional arg)
8728 "Cancel the currently running clock."
8729 (interactive "P")
8730 (unless (marker-buffer org-clock-marker)
8731 (error "No running clock"))
8732 (org-with-remote-undo (marker-buffer org-clock-marker)
8733 (org-clock-cancel)))
8735 (defun org-agenda-clock-goto ()
8736 "Jump to the currently clocked in task within the agenda.
8737 If the currently clocked in task is not listed in the agenda
8738 buffer, display it in another window."
8739 (interactive)
8740 (let (pos)
8741 (mapc (lambda (o)
8742 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8743 (setq pos (overlay-start o))))
8744 (overlays-in (point-min) (point-max)))
8745 (cond (pos (goto-char pos))
8746 ;; If the currently clocked entry is not in the agenda
8747 ;; buffer, we visit it in another window:
8748 (org-clock-current-task
8749 (org-switch-to-buffer-other-window (org-clock-goto)))
8750 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8752 (defun org-agenda-diary-entry-in-org-file ()
8753 "Make a diary entry in the file `org-agenda-diary-file'."
8754 (let (d1 d2 char (text "") dp1 dp2)
8755 (if (equal (buffer-name) "*Calendar*")
8756 (setq d1 (calendar-cursor-to-date t)
8757 d2 (car calendar-mark-ring))
8758 (setq dp1 (get-text-property (point-at-bol) 'day))
8759 (unless dp1 (error "No date defined in current line"))
8760 (setq d1 (calendar-gregorian-from-absolute dp1)
8761 d2 (and (ignore-errors (mark))
8762 (save-excursion
8763 (goto-char (mark))
8764 (setq dp2 (get-text-property (point-at-bol) 'day)))
8765 (calendar-gregorian-from-absolute dp2))))
8766 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8767 (setq char (read-char-exclusive))
8768 (cond
8769 ((equal char ?d)
8770 (setq text (read-string "Day entry: "))
8771 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8772 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8773 ((equal char ?a)
8774 (setq d1 (list (car d1) (nth 1 d1)
8775 (read-number (format "Reference year [%d]: " (nth 2 d1))
8776 (nth 2 d1))))
8777 (setq text (read-string "Anniversary (use %d to show years): "))
8778 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8779 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8780 ((equal char ?b)
8781 (setq text (read-string "Block entry: "))
8782 (unless (and d1 d2 (not (equal d1 d2)))
8783 (error "No block of days selected"))
8784 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8785 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8786 ((equal char ?j)
8787 (org-switch-to-buffer-other-window
8788 (find-file-noselect org-agenda-diary-file))
8789 (require 'org-datetree)
8790 (org-datetree-find-date-create d1)
8791 (org-reveal t))
8792 (t (error "Invalid selection character `%c'" char)))))
8794 (defcustom org-agenda-insert-diary-strategy 'date-tree
8795 "Where in `org-agenda-diary-file' should new entries be added?
8796 Valid values:
8798 date-tree in the date tree, as child of the date
8799 top-level as top-level entries at the end of the file."
8800 :group 'org-agenda
8801 :type '(choice
8802 (const :tag "in a date tree" date-tree)
8803 (const :tag "as top level at end of file" top-level)))
8805 (defcustom org-agenda-insert-diary-extract-time nil
8806 "Non-nil means extract any time specification from the diary entry."
8807 :group 'org-agenda
8808 :version "24.1"
8809 :type 'boolean)
8811 (defcustom org-agenda-bulk-mark-char ">"
8812 "A single-character string to be used as the bulk mark."
8813 :group 'org-agenda
8814 :version "24.1"
8815 :type 'string)
8817 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8818 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8819 If TEXT is not empty, it will become the headline of the new entry, and
8820 the resulting entry will not be shown. When TEXT is empty, switch to
8821 `org-agenda-diary-file' and let the user finish the entry there."
8822 (let ((cw (current-window-configuration)))
8823 (org-switch-to-buffer-other-window
8824 (find-file-noselect org-agenda-diary-file))
8825 (widen)
8826 (goto-char (point-min))
8827 (cond
8828 ((eq type 'anniversary)
8829 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8830 (progn
8831 (or (org-at-heading-p t)
8832 (progn
8833 (outline-next-heading)
8834 (insert "* Anniversaries\n\n")
8835 (beginning-of-line -1)))))
8836 (outline-next-heading)
8837 (org-back-over-empty-lines)
8838 (backward-char 1)
8839 (insert "\n")
8840 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8841 (nth 2 d1) (car d1) (nth 1 d1) text)))
8842 ((eq type 'day)
8843 (let ((org-prefix-has-time t)
8844 (org-agenda-time-leading-zero t)
8845 fmt time time2)
8846 (if org-agenda-insert-diary-extract-time
8847 ;; Use org-agenda-format-item to parse text for a time-range and
8848 ;; remove it. FIXME: This is a hack, we should refactor
8849 ;; that function to make time extraction available separately
8850 (setq fmt (org-agenda-format-item nil text nil nil t)
8851 time (get-text-property 0 'time fmt)
8852 time2 (if (> (length time) 0)
8853 ;; split-string removes trailing ...... if
8854 ;; no end time given. First space
8855 ;; separates time from date.
8856 (concat " " (car (split-string time "\\.")))
8857 nil)
8858 text (get-text-property 0 'txt fmt)))
8859 (if (eq org-agenda-insert-diary-strategy 'top-level)
8860 (org-agenda-insert-diary-as-top-level text)
8861 (require 'org-datetree)
8862 (org-datetree-find-date-create d1)
8863 (org-agenda-insert-diary-make-new-entry text))
8864 (org-insert-time-stamp (org-time-from-absolute
8865 (calendar-absolute-from-gregorian d1))
8866 nil nil nil nil time2))
8867 (end-of-line 0))
8868 ((eq type 'block)
8869 (if (> (calendar-absolute-from-gregorian d1)
8870 (calendar-absolute-from-gregorian d2))
8871 (setq d1 (prog1 d2 (setq d2 d1))))
8872 (if (eq org-agenda-insert-diary-strategy 'top-level)
8873 (org-agenda-insert-diary-as-top-level text)
8874 (require 'org-datetree)
8875 (org-datetree-find-date-create d1)
8876 (org-agenda-insert-diary-make-new-entry text))
8877 (org-insert-time-stamp (org-time-from-absolute
8878 (calendar-absolute-from-gregorian d1)))
8879 (insert "--")
8880 (org-insert-time-stamp (org-time-from-absolute
8881 (calendar-absolute-from-gregorian d2)))
8882 (end-of-line 0)))
8883 (if (string-match "\\S-" text)
8884 (progn
8885 (set-window-configuration cw)
8886 (message "%s entry added to %s"
8887 (capitalize (symbol-name type))
8888 (abbreviate-file-name org-agenda-diary-file)))
8889 (org-reveal t)
8890 (message "Please finish entry here"))))
8892 (defun org-agenda-insert-diary-as-top-level (text)
8893 "Make new entry as a top-level entry at the end of the file.
8894 Add TEXT as headline, and position the cursor in the second line so that
8895 a timestamp can be added there."
8896 (widen)
8897 (goto-char (point-max))
8898 (or (bolp) (insert "\n"))
8899 (insert "* " text "\n")
8900 (if org-adapt-indentation (org-indent-to-column 2)))
8902 (defun org-agenda-insert-diary-make-new-entry (text)
8903 "Make new entry as last child of current entry.
8904 Add TEXT as headline, and position the cursor in the second line so that
8905 a timestamp can be added there."
8906 (let ((org-show-following-heading t)
8907 (org-show-siblings t)
8908 (org-show-hierarchy-above t)
8909 (org-show-entry-below t)
8910 col)
8911 (outline-next-heading)
8912 (org-back-over-empty-lines)
8913 (or (looking-at "[ \t]*$")
8914 (progn (insert "\n") (backward-char 1)))
8915 (org-insert-heading nil t)
8916 (org-do-demote)
8917 (setq col (current-column))
8918 (insert text "\n")
8919 (if org-adapt-indentation (org-indent-to-column col))
8920 (let ((org-show-following-heading t)
8921 (org-show-siblings t)
8922 (org-show-hierarchy-above t)
8923 (org-show-entry-below t))
8924 (org-show-context))))
8926 (defun org-agenda-diary-entry ()
8927 "Make a diary entry, like the `i' command from the calendar.
8928 All the standard commands work: block, weekly etc.
8929 When `org-agenda-diary-file' points to a file,
8930 `org-agenda-diary-entry-in-org-file' is called instead to create
8931 entries in that Org-mode file."
8932 (interactive)
8933 (if (not (eq org-agenda-diary-file 'diary-file))
8934 (org-agenda-diary-entry-in-org-file)
8935 (require 'diary-lib)
8936 (let* ((char (progn
8937 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8938 (read-char-exclusive)))
8939 (cmd (cdr (assoc char
8940 '((?d . insert-diary-entry)
8941 (?w . insert-weekly-diary-entry)
8942 (?m . insert-monthly-diary-entry)
8943 (?y . insert-yearly-diary-entry)
8944 (?a . insert-anniversary-diary-entry)
8945 (?b . insert-block-diary-entry)
8946 (?c . insert-cyclic-diary-entry)))))
8947 (oldf (symbol-function 'calendar-cursor-to-date))
8948 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8949 (point (point))
8950 (mark (or (mark t) (point))))
8951 (unless cmd
8952 (error "No command associated with <%c>" char))
8953 (unless (and (get-text-property point 'day)
8954 (or (not (equal ?b char))
8955 (get-text-property mark 'day)))
8956 (error "Don't know which date to use for diary entry"))
8957 ;; We implement this by hacking the `calendar-cursor-to-date' function
8958 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8959 (let ((calendar-mark-ring
8960 (list (calendar-gregorian-from-absolute
8961 (or (get-text-property mark 'day)
8962 (get-text-property point 'day))))))
8963 (unwind-protect
8964 (progn
8965 (fset 'calendar-cursor-to-date
8966 (lambda (&optional error dummy)
8967 (calendar-gregorian-from-absolute
8968 (get-text-property point 'day))))
8969 (call-interactively cmd))
8970 (fset 'calendar-cursor-to-date oldf))))))
8972 (defun org-agenda-execute-calendar-command (cmd)
8973 "Execute a calendar command from the agenda with date from cursor."
8974 (org-agenda-check-type t 'agenda 'timeline)
8975 (require 'diary-lib)
8976 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
8977 (error "Don't know which date to use for the calendar command"))
8978 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8979 (point (point))
8980 (date (calendar-gregorian-from-absolute
8981 (get-text-property point 'day)))
8982 ;; the following 2 vars are needed in the calendar
8983 (displayed-month (car date))
8984 (displayed-year (nth 2 date)))
8985 (unwind-protect
8986 (progn
8987 (fset 'calendar-cursor-to-date
8988 (lambda (&optional error dummy)
8989 (calendar-gregorian-from-absolute
8990 (get-text-property point 'day))))
8991 (call-interactively cmd))
8992 (fset 'calendar-cursor-to-date oldf))))
8994 (defun org-agenda-phases-of-moon ()
8995 "Display the phases of the moon for the 3 months around the cursor date."
8996 (interactive)
8997 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8999 (defun org-agenda-holidays ()
9000 "Display the holidays for the 3 months around the cursor date."
9001 (interactive)
9002 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9004 (defvar calendar-longitude) ; defined in calendar.el
9005 (defvar calendar-latitude) ; defined in calendar.el
9006 (defvar calendar-location-name) ; defined in calendar.el
9008 (defun org-agenda-sunrise-sunset (arg)
9009 "Display sunrise and sunset for the cursor date.
9010 Latitude and longitude can be specified with the variables
9011 `calendar-latitude' and `calendar-longitude'. When called with prefix
9012 argument, latitude and longitude will be prompted for."
9013 (interactive "P")
9014 (require 'solar)
9015 (let ((calendar-longitude (if arg nil calendar-longitude))
9016 (calendar-latitude (if arg nil calendar-latitude))
9017 (calendar-location-name
9018 (if arg "the given coordinates" calendar-location-name)))
9019 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9021 (defun org-agenda-goto-calendar ()
9022 "Open the Emacs calendar with the date at the cursor."
9023 (interactive)
9024 (org-agenda-check-type t 'agenda 'timeline)
9025 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9026 (error "Don't know which date to open in calendar")))
9027 (date (calendar-gregorian-from-absolute day))
9028 (calendar-move-hook nil)
9029 (calendar-view-holidays-initially-flag nil)
9030 (calendar-view-diary-initially-flag nil))
9031 (calendar)
9032 (calendar-goto-date date)))
9034 ;;;###autoload
9035 (defun org-calendar-goto-agenda ()
9036 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9037 This is a command that has to be installed in `calendar-mode-map'."
9038 (interactive)
9039 (org-agenda-list nil (calendar-absolute-from-gregorian
9040 (calendar-cursor-to-date))
9041 nil))
9043 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9044 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9045 This is a command that has to be installed in `calendar-mode-map'.
9047 \(fn)" t nil)
9049 (defun org-agenda-convert-date ()
9050 (interactive)
9051 (org-agenda-check-type t 'agenda 'timeline)
9052 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9053 date s)
9054 (unless day
9055 (error "Don't know which date to convert"))
9056 (setq date (calendar-gregorian-from-absolute day))
9057 (setq s (concat
9058 "Gregorian: " (calendar-date-string date) "\n"
9059 "ISO: " (calendar-iso-date-string date) "\n"
9060 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9061 "Julian: " (calendar-julian-date-string date) "\n"
9062 "Astron. JD: " (calendar-astro-date-string date)
9063 " (Julian date number at noon UTC)\n"
9064 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9065 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9066 "French: " (calendar-french-date-string date) "\n"
9067 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9068 "Mayan: " (calendar-mayan-date-string date) "\n"
9069 "Coptic: " (calendar-coptic-date-string date) "\n"
9070 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9071 "Persian: " (calendar-persian-date-string date) "\n"
9072 "Chinese: " (calendar-chinese-date-string date) "\n"))
9073 (with-output-to-temp-buffer "*Dates*"
9074 (princ s))
9075 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9077 ;;; Bulk commands
9079 (defun org-agenda-bulk-marked-p ()
9080 (eq (get-char-property (point-at-bol) 'type)
9081 'org-marked-entry-overlay))
9083 (defun org-agenda-bulk-mark (&optional arg)
9084 "Mark the entry at point for future bulk action."
9085 (interactive "p")
9086 (dotimes (i (or arg 1))
9087 (unless (org-get-at-bol 'org-agenda-diary-link)
9088 (let* ((m (org-get-at-bol 'org-hd-marker))
9090 (unless (org-agenda-bulk-marked-p)
9091 (unless m (error "Nothing to mark at point"))
9092 (push m org-agenda-bulk-marked-entries)
9093 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9094 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9095 (org-get-todo-face "TODO")
9096 'evaporate)
9097 (overlay-put ov 'type 'org-marked-entry-overlay))
9098 (beginning-of-line 2)
9099 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9100 (beginning-of-line 2))
9101 (message "%d entries marked for bulk action"
9102 (length org-agenda-bulk-marked-entries))))))
9104 (defun org-agenda-bulk-mark-all ()
9105 "Mark all entries for future agenda bulk action."
9106 (interactive)
9107 (org-agenda-bulk-mark-regexp "."))
9109 (defun org-agenda-bulk-mark-regexp (regexp)
9110 "Mark entries matching REGEXP for future agenda bulk action."
9111 (interactive "sMark entries matching regexp: ")
9112 (let ((entries-marked 0))
9113 (save-excursion
9114 (goto-char (point-min))
9115 (goto-char (next-single-property-change (point) 'txt))
9116 (while (re-search-forward regexp nil t)
9117 (when (string-match regexp (get-text-property (point) 'txt))
9118 (setq entries-marked (1+ entries-marked))
9119 (call-interactively 'org-agenda-bulk-mark))))
9120 (if (not entries-marked)
9121 (message "No entry matching this regexp."))))
9123 (defun org-agenda-bulk-unmark (&optional arg)
9124 "Unmark the entry at point for future bulk action."
9125 (interactive "P")
9126 (if arg
9127 (org-agenda-bulk-unmark-all)
9128 (cond ((org-agenda-bulk-marked-p)
9129 (org-agenda-bulk-remove-overlays
9130 (point-at-bol) (+ 2 (point-at-bol)))
9131 (setq org-agenda-bulk-marked-entries
9132 (delete (org-get-at-bol 'org-hd-marker)
9133 org-agenda-bulk-marked-entries))
9134 (beginning-of-line 2)
9135 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9136 (beginning-of-line 2))
9137 (message "%d entries left marked for bulk action"
9138 (length org-agenda-bulk-marked-entries)))
9139 (t (message "No entry to unmark here")))))
9141 (defun org-agenda-bulk-toggle ()
9142 "Toggle marking the entry at point for bulk action."
9143 (interactive)
9144 (if (org-agenda-bulk-marked-p)
9145 (org-agenda-bulk-unmark)
9146 (org-agenda-bulk-mark)))
9148 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9149 "Remove the mark overlays between BEG and END in the agenda buffer.
9150 BEG and END default to the buffer limits.
9152 This only removes the overlays, it does not remove the markers
9153 from the list in `org-agenda-bulk-marked-entries'."
9154 (interactive)
9155 (mapc (lambda (ov)
9156 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9157 (delete-overlay ov)))
9158 (overlays-in (or beg (point-min)) (or end (point-max)))))
9160 (defun org-agenda-bulk-unmark-all ()
9161 "Remove all marks in the agenda buffer.
9162 This will remove the markers and the overlays."
9163 (interactive)
9164 (if (null org-agenda-bulk-marked-entries)
9165 (message "No entry to unmark")
9166 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9167 (setq org-agenda-bulk-marked-entries nil)
9168 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9170 (defcustom org-agenda-persistent-marks nil
9171 "Non-nil means marked items will stay marked after a bulk action.
9172 You can toggle this interactively by typing `p' when prompted for a
9173 bulk action."
9174 :group 'org-agenda
9175 :version "24.1"
9176 :type 'boolean)
9178 (defun org-agenda-bulk-action (&optional arg)
9179 "Execute an remote-editing action on all marked entries.
9180 The prefix arg is passed through to the command if possible."
9181 (interactive "P")
9182 ;; Make sure we have markers, and only valid ones
9183 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9184 (mapc
9185 (lambda (m)
9186 (unless (and (markerp m)
9187 (marker-buffer m)
9188 (buffer-live-p (marker-buffer m))
9189 (marker-position m))
9190 (error "Marker %s for bulk command is invalid" m)))
9191 org-agenda-bulk-marked-entries)
9193 ;; Prompt for the bulk command
9194 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9195 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9196 "[S]catter [f]unction "
9197 (when org-agenda-bulk-custom-functions
9198 (concat " Custom: ["
9199 (mapconcat (lambda(f) (char-to-string (car f)))
9200 org-agenda-bulk-custom-functions "")
9201 "]"))))
9202 (catch 'exit
9203 (let* ((action (read-char-exclusive))
9204 (org-log-refile (if org-log-refile 'time nil))
9205 (entries (reverse org-agenda-bulk-marked-entries))
9206 (org-overriding-default-time
9207 (if (get-text-property (point) 'org-agenda-date-header)
9208 (org-get-cursor-date)))
9209 redo-at-end
9210 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9211 (cond
9212 ((equal action ?p)
9213 (let ((org-agenda-persistent-marks
9214 (not org-agenda-persistent-marks)))
9215 (org-agenda-bulk-action)
9216 (throw 'exit nil)))
9218 ((equal action ?$)
9219 (setq cmd '(org-agenda-archive)))
9221 ((equal action ?A)
9222 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9224 ((member action '(?r ?w))
9225 (setq rfloc (org-refile-get-location
9226 "Refile to"
9227 (marker-buffer (car entries))
9228 org-refile-allow-creating-parent-nodes))
9229 (if (nth 3 rfloc)
9230 (setcar (nthcdr 3 rfloc)
9231 (move-marker (make-marker) (nth 3 rfloc)
9232 (or (get-file-buffer (nth 1 rfloc))
9233 (find-buffer-visiting (nth 1 rfloc))
9234 (error "This should not happen")))))
9236 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9237 redo-at-end t))
9239 ((equal action ?t)
9240 (setq state (org-icompleting-read
9241 "Todo state: "
9242 (with-current-buffer (marker-buffer (car entries))
9243 (mapcar 'list org-todo-keywords-1))))
9244 (setq cmd `(let ((org-inhibit-blocking t)
9245 (org-inhibit-logging 'note))
9246 (org-agenda-todo ,state))))
9248 ((memq action '(?- ?+))
9249 (setq tag (org-icompleting-read
9250 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9251 (with-current-buffer (marker-buffer (car entries))
9252 (delq nil
9253 (mapcar (lambda (x)
9254 (if (stringp (car x)) x)) org-tag-alist)))))
9255 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9257 ((memq action '(?s ?d))
9258 (let* ((time
9259 (unless arg
9260 (org-read-date
9261 nil nil nil
9262 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9263 org-overriding-default-time)))
9264 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9265 (setq cmd `(eval '(,c1 arg ,time)))))
9267 ((equal action ?S)
9268 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9269 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9270 (let ((days (read-number
9271 (format "Scatter tasks across how many %sdays: "
9272 (if arg "week" "")) 7)))
9273 (setq cmd
9274 `(let ((distance (1+ (random ,days))))
9275 (if arg
9276 (let ((dist distance)
9277 (day-of-week
9278 (calendar-day-of-week
9279 (calendar-gregorian-from-absolute (org-today)))))
9280 (dotimes (i (1+ dist))
9281 (while (member day-of-week org-agenda-weekend-days)
9282 (incf distance)
9283 (incf day-of-week)
9284 (if (= day-of-week 7)
9285 (setq day-of-week 0)))
9286 (incf day-of-week)
9287 (if (= day-of-week 7)
9288 (setq day-of-week 0)))))
9289 ;; silently fail when try to replan a sexp entry
9290 (condition-case nil
9291 (let* ((date (calendar-gregorian-from-absolute
9292 (+ (org-today) distance)))
9293 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9294 (nth 2 date))))
9295 (org-agenda-schedule nil time))
9296 (error nil)))))))
9298 ((assoc action org-agenda-bulk-custom-functions)
9299 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9300 redo-at-end t))
9302 ((equal action ?f)
9303 (setq cmd (list (intern
9304 (org-icompleting-read "Function: "
9305 obarray 'fboundp t nil nil)))))
9307 (t (error "Invalid bulk action")))
9309 ;; Sort the markers, to make sure that parents are handled before children
9310 (setq entries (sort entries
9311 (lambda (a b)
9312 (cond
9313 ((equal (marker-buffer a) (marker-buffer b))
9314 (< (marker-position a) (marker-position b)))
9316 (string< (buffer-name (marker-buffer a))
9317 (buffer-name (marker-buffer b))))))))
9319 ;; Now loop over all markers and apply cmd
9320 (while (setq e (pop entries))
9321 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9322 (if (not pos)
9323 (progn (message "Skipping removed entry at %s" e)
9324 (setq cntskip (1+ cntskip)))
9325 (goto-char pos)
9326 (let (org-loop-over-headlines-in-active-region)
9327 (eval cmd))
9328 (setq cnt (1+ cnt))))
9329 (when redo-at-end (org-agenda-redo))
9330 (unless org-agenda-persistent-marks
9331 (org-agenda-bulk-unmark-all))
9332 (message "Acted on %d entries%s%s"
9334 (if (= cntskip 0)
9336 (format ", skipped %d (disappeared before their turn)"
9337 cntskip))
9338 (if (not org-agenda-persistent-marks)
9339 "" " (kept marked)"))))))
9341 (defun org-agenda-capture ()
9342 "Call `org-capture' with the date at point."
9343 (interactive)
9344 (if (not (eq major-mode 'org-agenda-mode))
9345 (error "You cannot do this outside of agenda buffers")
9346 (let ((org-overriding-default-time
9347 (org-get-cursor-date)))
9348 (call-interactively 'org-capture))))
9350 ;;; Flagging notes
9352 (defun org-agenda-show-the-flagging-note ()
9353 "Display the flagging note in the other window.
9354 When called a second time in direct sequence, offer to remove the FLAGGING
9355 tag and (if present) the flagging note."
9356 (interactive)
9357 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9358 (win (selected-window))
9359 note heading newhead)
9360 (unless hdmarker
9361 (error "No linked entry at point"))
9362 (if (and (eq this-command last-command)
9363 (y-or-n-p "Unflag and remove any flagging note? "))
9364 (progn
9365 (org-agenda-remove-flag hdmarker)
9366 (let ((win (get-buffer-window "*Flagging Note*")))
9367 (and win (delete-window win)))
9368 (message "Entry unflagged"))
9369 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9370 (unless note
9371 (error "No flagging note"))
9372 (org-kill-new note)
9373 (org-switch-to-buffer-other-window "*Flagging Note*")
9374 (erase-buffer)
9375 (insert note)
9376 (goto-char (point-min))
9377 (while (re-search-forward "\\\\n" nil t)
9378 (replace-match "\n" t t))
9379 (goto-char (point-min))
9380 (select-window win)
9381 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9383 (defun org-agenda-remove-flag (marker)
9384 "Remove the FLAGGED tag and any flagging note in the entry."
9385 (let (newhead)
9386 (org-with-point-at marker
9387 (org-toggle-tag "FLAGGED" 'off)
9388 (org-entry-delete nil "THEFLAGGINGNOTE")
9389 (setq newhead (org-get-heading)))
9390 (org-agenda-change-all-lines newhead marker)
9391 (message "Entry unflagged")))
9393 (defun org-agenda-get-any-marker (&optional pos)
9394 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9395 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9397 ;;; Appointment reminders
9399 (defvar appt-time-msg-list) ; defined in appt.el
9401 ;;;###autoload
9402 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9403 "Activate appointments found in `org-agenda-files'.
9404 With a \\[universal-argument] prefix, refresh the list of
9405 appointments.
9407 If FILTER is t, interactively prompt the user for a regular
9408 expression, and filter out entries that don't match it.
9410 If FILTER is a string, use this string as a regular expression
9411 for filtering entries out.
9413 If FILTER is a function, filter out entries against which
9414 calling the function returns nil. This function takes one
9415 argument: an entry from `org-agenda-get-day-entries'.
9417 FILTER can also be an alist with the car of each cell being
9418 either 'headline or 'category. For example:
9420 '((headline \"IMPORTANT\")
9421 (category \"Work\"))
9423 will only add headlines containing IMPORTANT or headlines
9424 belonging to the \"Work\" category.
9426 ARGS are symbols indicating what kind of entries to consider.
9427 By default `org-agenda-to-appt' will use :deadline, :scheduled
9428 and :timestamp entries. See the docstring of `org-diary' for
9429 details and examples.
9431 If an entry as a APPT_WARNTIME property, its value will be used
9432 to override `appt-message-warning-time'."
9433 (interactive "P")
9434 (if refresh (setq appt-time-msg-list nil))
9435 (if (eq filter t)
9436 (setq filter (read-from-minibuffer "Regexp filter: ")))
9437 (let* ((cnt 0) ; count added events
9438 (scope (or args '(:deadline :scheduled :timestamp)))
9439 (org-agenda-new-buffers nil)
9440 (org-deadline-warning-days 0)
9441 ;; Do not use `org-today' here because appt only takes
9442 ;; time and without date as argument, so it may pass wrong
9443 ;; information otherwise
9444 (today (org-date-to-gregorian
9445 (time-to-days (current-time))))
9446 (org-agenda-restrict nil)
9447 (files (org-agenda-files 'unrestricted)) entries file
9448 (org-agenda-buffer nil))
9449 ;; Get all entries which may contain an appt
9450 (org-agenda-prepare-buffers files)
9451 (while (setq file (pop files))
9452 (setq entries
9453 (delq nil
9454 (append entries
9455 (apply 'org-agenda-get-day-entries
9456 file today scope)))))
9457 ;; Map thru entries and find if we should filter them out
9458 (mapc
9459 (lambda(x)
9460 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9461 (cat (get-text-property 1 'org-category x))
9462 (tod (get-text-property 1 'time-of-day x))
9463 (ok (or (null filter)
9464 (and (stringp filter) (string-match filter evt))
9465 (and (functionp filter) (funcall filter x))
9466 (and (listp filter)
9467 (let ((cat-filter (cadr (assoc 'category filter)))
9468 (evt-filter (cadr (assoc 'headline filter))))
9469 (or (and (stringp cat-filter)
9470 (string-match cat-filter cat))
9471 (and (stringp evt-filter)
9472 (string-match evt-filter evt)))))))
9473 (wrn (get-text-property 1 'warntime x)))
9474 ;; FIXME: Shall we remove text-properties for the appt text?
9475 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9476 (when (and ok tod)
9477 (setq tod (concat "00" (number-to-string tod))
9478 tod (when (string-match
9479 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9480 (concat (match-string 1 tod) ":"
9481 (match-string 2 tod))))
9482 (if (version< emacs-version "23.3")
9483 (appt-add tod evt)
9484 (appt-add tod evt wrn))
9485 (setq cnt (1+ cnt))))) entries)
9486 (org-release-buffers org-agenda-new-buffers)
9487 (if (eq cnt 0)
9488 (message "No event to add")
9489 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9491 (autoload 'org-agenda-to-appt "org-agenda" "\
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'.
9523 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9525 (defun org-agenda-todayp (date)
9526 "Does DATE mean today, when considering `org-extend-today-until'?"
9527 (let ((today (org-today))
9528 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9529 date)))
9530 (eq date today)))
9532 (defun org-agenda-todo-yesterday (&optional arg)
9533 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9534 (interactive "P")
9535 (let* ((hour (third (decode-time
9536 (org-current-time))))
9537 (org-extend-today-until (1+ hour)))
9538 (org-agenda-todo arg)))
9540 (provide 'org-agenda)
9542 ;;; org-agenda.el ends here