Merge branch 'master' into max-sticky-agenda
[org-mode.git] / lisp / org-agenda.el
blobb906cdfee2ae57faea121092d6de25b2361b9e5a
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (eval-when-compile
50 (require 'cl))
52 (declare-function diary-add-to-list "diary-lib"
53 (date string specifier &optional marker globcolor literal))
54 (declare-function calendar-absolute-from-iso "cal-iso" (date))
55 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
56 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
57 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
58 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
59 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-french-date-string "cal-french" (&optional date))
61 (declare-function calendar-goto-date "cal-move" (date))
62 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
63 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
64 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
65 (declare-function calendar-iso-from-absolute "cal-iso" (date))
66 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
67 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
68 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
69 (declare-function calendar-check-holidays "holidays" (date))
71 (declare-function org-datetree-find-date-create "org-datetree"
72 (date &optional keep-restriction))
73 (declare-function org-columns-quit "org-colview" ())
74 (declare-function diary-date-display-form "diary-lib" (&optional type))
75 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
76 (declare-function org-habit-insert-consistency-graphs
77 "org-habit" (&optional line))
78 (declare-function org-is-habit-p "org-habit" (&optional pom))
79 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
80 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
81 (declare-function org-pop-to-buffer-same-window "org-compat"
82 (&optional buffer-or-name norecord label))
84 (defvar calendar-mode-map)
85 (defvar org-clock-current-task) ; defined in org-clock.el
86 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
87 (defvar org-habit-show-habits)
88 (defvar org-habit-show-habits-only-for-today)
90 ;; Defined somewhere in this file, but used before definition.
91 (defvar org-agenda-buffer-name)
92 (defvar org-agenda-overriding-header)
93 (defvar org-agenda-title-append nil)
94 (defvar entry)
95 (defvar date)
96 (defvar org-agenda-undo-list)
97 (defvar org-agenda-pending-undo-list)
98 (defvar original-date) ; dynamically scoped, calendar.el does scope this
100 (defcustom org-agenda-confirm-kill 1
101 "When set, remote killing from the agenda buffer needs confirmation.
102 When t, a confirmation is always needed. When a number N, confirmation is
103 only needed when the text to be killed contains more than N non-white lines."
104 :group 'org-agenda
105 :type '(choice
106 (const :tag "Never" nil)
107 (const :tag "Always" t)
108 (integer :tag "When more than N lines")))
110 (defcustom org-agenda-compact-blocks nil
111 "Non-nil means make the block agenda more compact.
112 This is done globally by leaving out lines like the agenda span
113 name and week number or the separator lines."
114 :group 'org-agenda
115 :type 'boolean)
117 (defcustom org-agenda-block-separator ?=
118 "The separator between blocks in the agenda.
119 If this is a string, it will be used as the separator, with a newline added.
120 If it is a character, it will be repeated to fill the window width.
121 If nil the separator is disabled. In `org-agenda-custom-commands' this
122 addresses the separator between the current and the previous block."
123 :group 'org-agenda
124 :type '(choice
125 (const :tag "Disabled" nil)
126 (character)
127 (string)))
129 (defgroup org-agenda-export nil
130 "Options concerning exporting agenda views in Org-mode."
131 :tag "Org Agenda Export"
132 :group 'org-agenda)
134 (defcustom org-agenda-with-colors t
135 "Non-nil means use colors in agenda views."
136 :group 'org-agenda-export
137 :type 'boolean)
139 (defcustom org-agenda-exporter-settings nil
140 "Alist of variable/value pairs that should be active during agenda export.
141 This is a good place to set options for ps-print and for htmlize.
142 Note that the way this is implemented, the values will be evaluated
143 before assigned to the variables. So make sure to quote values you do
144 *not* want evaluated, for example
146 (setq org-agenda-exporter-settings
147 '((ps-print-color-p 'black-white)))"
148 :group 'org-agenda-export
149 :type '(repeat
150 (list
151 (variable)
152 (sexp :tag "Value"))))
154 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
155 "Hook run in temporary buffer before writing it to an export file.
156 A useful function is `org-agenda-add-entry-text'."
157 :group 'org-agenda-export
158 :type 'hook
159 :options '(org-agenda-add-entry-text))
161 (defcustom org-agenda-add-entry-text-maxlines 0
162 "Maximum number of entry text lines to be added to agenda.
163 This is only relevant when `org-agenda-add-entry-text' is part of
164 `org-agenda-before-write-hook', which it is by default.
165 When this is 0, nothing will happen. When it is greater than 0, it
166 specifies the maximum number of lines that will be added for each entry
167 that is listed in the agenda view.
169 Note that this variable is not used during display, only when exporting
170 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
171 and `org-agenda-entry-text-maxlines'."
172 :group 'org-agenda
173 :type 'integer)
175 (defcustom org-agenda-add-entry-text-descriptive-links t
176 "Non-nil means export org-links as descriptive links in agenda added text.
177 This variable applies to the text added to the agenda when
178 `org-agenda-add-entry-text-maxlines' is larger than 0.
179 When this variable nil, the URL will (also) be shown."
180 :group 'org-agenda
181 :type 'boolean)
183 (defcustom org-agenda-export-html-style ""
184 "The style specification for exported HTML Agenda files.
185 If this variable contains a string, it will replace the default <style>
186 section as produced by `htmlize'.
187 Since there are different ways of setting style information, this variable
188 needs to contain the full HTML structure to provide a style, including the
189 surrounding HTML tags. The style specifications should include definitions
190 the fonts used by the agenda, here is an example:
192 <style type=\"text/css\">
193 p { font-weight: normal; color: gray; }
194 .org-agenda-structure {
195 font-size: 110%;
196 color: #003399;
197 font-weight: 600;
199 .org-todo {
200 color: #cc6666;
201 font-weight: bold;
203 .org-agenda-done {
204 color: #339933;
206 .org-done {
207 color: #339933;
209 .title { text-align: center; }
210 .todo, .deadline { color: red; }
211 .done { color: green; }
212 </style>
214 or, if you want to keep the style in a file,
216 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
218 As the value of this option simply gets inserted into the HTML <head> header,
219 you can \"misuse\" it to also add other text to the header. However,
220 <style>...</style> is required, if not present the variable will be ignored."
221 :group 'org-agenda-export
222 :group 'org-export-html
223 :type 'string)
225 (defcustom org-agenda-persistent-filter nil
226 "When set, keep filters from one agenda view to the next."
227 :group 'org-agenda
228 :type 'boolean)
230 (defgroup org-agenda-custom-commands nil
231 "Options concerning agenda views in Org-mode."
232 :tag "Org Agenda Custom Commands"
233 :group 'org-agenda)
235 (defconst org-sorting-choice
236 '(choice
237 (const time-up) (const time-down)
238 (const category-keep) (const category-up) (const category-down)
239 (const tag-down) (const tag-up)
240 (const priority-up) (const priority-down)
241 (const todo-state-up) (const todo-state-down)
242 (const effort-up) (const effort-down)
243 (const habit-up) (const habit-down)
244 (const alpha-up) (const alpha-down)
245 (const user-defined-up) (const user-defined-down))
246 "Sorting choices.")
248 ;; Keep custom values for `org-agenda-filter-preset' compatible with
249 ;; the new variable `org-agenda-tag-filter-preset'.
250 (if (fboundp 'defvaralias)
251 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
252 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
254 (defconst org-agenda-custom-commands-local-options
255 `(repeat :tag "Local settings for this command. Remember to quote values"
256 (choice :tag "Setting"
257 (list :tag "Heading for this block"
258 (const org-agenda-overriding-header)
259 (string :tag "Headline"))
260 (list :tag "Files to be searched"
261 (const org-agenda-files)
262 (list
263 (const :format "" quote)
264 (repeat (file))))
265 (list :tag "Sorting strategy"
266 (const org-agenda-sorting-strategy)
267 (list
268 (const :format "" quote)
269 (repeat
270 ,org-sorting-choice)))
271 (list :tag "Prefix format"
272 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
273 (string))
274 (list :tag "Number of days in agenda"
275 (const org-agenda-span)
276 (choice (const :tag "Day" 'day)
277 (const :tag "Week" 'week)
278 (const :tag "Month" 'month)
279 (const :tag "Year" 'year)
280 (integer :tag "Custom")))
281 (list :tag "Fixed starting date"
282 (const org-agenda-start-day)
283 (string :value "2007-11-01"))
284 (list :tag "Start on day of week"
285 (const org-agenda-start-on-weekday)
286 (choice :value 1
287 (const :tag "Today" nil)
288 (integer :tag "Weekday No.")))
289 (list :tag "Include data from diary"
290 (const org-agenda-include-diary)
291 (boolean))
292 (list :tag "Deadline Warning days"
293 (const org-deadline-warning-days)
294 (integer :value 1))
295 (list :tag "Category filter preset"
296 (const org-agenda-category-filter-preset)
297 (list
298 (const :format "" quote)
299 (repeat
300 (string :tag "+category or -category"))))
301 (list :tag "Tags filter preset"
302 (const org-agenda-tag-filter-preset)
303 (list
304 (const :format "" quote)
305 (repeat
306 (string :tag "+tag or -tag"))))
307 (list :tag "Set daily/weekly entry types"
308 (const org-agenda-entry-types)
309 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
310 (const :deadline)
311 (const :scheduled)
312 (const :timestamp)
313 (const :sexp)))
314 (list :tag "Standard skipping condition"
315 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
316 (const org-agenda-skip-function)
317 (list
318 (const :format "" quote)
319 (list
320 (choice
321 :tag "Skipping range"
322 (const :tag "Skip entry" org-agenda-skip-entry-if)
323 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
324 (repeat :inline t :tag "Conditions for skipping"
325 (choice
326 :tag "Condition type"
327 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
328 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
329 (list :tag "TODO state is" :inline t
330 (const 'todo)
331 (choice
332 (const :tag "any not-done state" 'todo)
333 (const :tag "any done state" 'done)
334 (const :tag "any state" 'any)
335 (list :tag "Keyword list"
336 (const :format "" quote)
337 (repeat (string :tag "Keyword")))))
338 (list :tag "TODO state is not" :inline t
339 (const 'nottodo)
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 (const :tag "scheduled" 'scheduled)
348 (const :tag "not scheduled" 'notscheduled)
349 (const :tag "deadline" 'deadline)
350 (const :tag "no deadline" 'notdeadline)
351 (const :tag "timestamp" 'timestamp)
352 (const :tag "no timestamp" 'nottimestamp))))))
353 (list :tag "Non-standard skipping condition"
354 :value (org-agenda-skip-function)
355 (const org-agenda-skip-function)
356 (sexp :tag "Function or form (quoted!)"))
357 (list :tag "Any variable"
358 (variable :tag "Variable")
359 (sexp :tag "Value (sexp)"))))
360 "Selection of examples for agenda command settings.
361 This will be spliced into the custom type of
362 `org-agenda-custom-commands'.")
365 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
366 ((agenda "") (alltodo))))
367 "Custom commands for the agenda.
368 These commands will be offered on the splash screen displayed by the
369 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
371 (key desc type match settings files)
373 key The key (one or more characters as a string) to be associated
374 with the command.
375 desc A description of the command, when omitted or nil, a default
376 description is built using MATCH.
377 type The command type, any of the following symbols:
378 agenda The daily/weekly agenda.
379 todo Entries with a specific TODO keyword, in all agenda files.
380 search Entries containing search words entry or headline.
381 tags Tags/Property/TODO match in all agenda files.
382 tags-todo Tags/P/T match in all agenda files, TODO entries only.
383 todo-tree Sparse tree of specific TODO keyword in *current* file.
384 tags-tree Sparse tree with all tags matches in *current* file.
385 occur-tree Occur sparse tree for *current* file.
386 ... A user-defined function.
387 match What to search for:
388 - a single keyword for TODO keyword searches
389 - a tags match expression for tags searches
390 - a word search expression for text searches.
391 - a regular expression for occur searches
392 For all other commands, this should be the empty string.
393 settings A list of option settings, similar to that in a let form, so like
394 this: ((opt1 val1) (opt2 val2) ...). The values will be
395 evaluated at the moment of execution, so quote them when needed.
396 files A list of files file to write the produced agenda buffer to
397 with the command `org-store-agenda-views'.
398 If a file name ends in \".html\", an HTML version of the buffer
399 is written out. If it ends in \".ps\", a postscript version is
400 produced. Otherwise, only the plain text is written to the file.
402 You can also define a set of commands, to create a composite agenda buffer.
403 In this case, an entry looks like this:
405 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
407 where
409 desc A description string to be displayed in the dispatcher menu.
410 cmd An agenda command, similar to the above. However, tree commands
411 are no allowed, but instead you can get agenda and global todo list.
412 So valid commands for a set are:
413 (agenda \"\" settings)
414 (alltodo \"\" settings)
415 (stuck \"\" settings)
416 (todo \"match\" settings files)
417 (search \"match\" settings files)
418 (tags \"match\" settings files)
419 (tags-todo \"match\" settings files)
421 Each command can carry a list of options, and another set of options can be
422 given for the whole set of commands. Individual command options take
423 precedence over the general options.
425 When using several characters as key to a command, the first characters
426 are prefix commands. For the dispatcher to display useful information, you
427 should provide a description for the prefix, like
429 (setq org-agenda-custom-commands
430 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
431 (\"hl\" tags \"+HOME+Lisa\")
432 (\"hp\" tags \"+HOME+Peter\")
433 (\"hk\" tags \"+HOME+Kim\")))"
434 :group 'org-agenda-custom-commands
435 :type `(repeat
436 (choice :value ("x" "Describe command here" tags "" nil)
437 (list :tag "Single command"
438 (string :tag "Access Key(s) ")
439 (option (string :tag "Description"))
440 (choice
441 (const :tag "Agenda" agenda)
442 (const :tag "TODO list" alltodo)
443 (const :tag "Search words" search)
444 (const :tag "Stuck projects" stuck)
445 (const :tag "Tags/Property match (all agenda files)" tags)
446 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
447 (const :tag "TODO keyword search (all agenda files)" todo)
448 (const :tag "Tags sparse tree (current buffer)" tags-tree)
449 (const :tag "TODO keyword tree (current buffer)" todo-tree)
450 (const :tag "Occur tree (current buffer)" occur-tree)
451 (sexp :tag "Other, user-defined function"))
452 (string :tag "Match (only for some commands)")
453 ,org-agenda-custom-commands-local-options
454 (option (repeat :tag "Export" (file :tag "Export to"))))
455 (list :tag "Command series, all agenda files"
456 (string :tag "Access Key(s)")
457 (string :tag "Description ")
458 (repeat :tag "Component"
459 (choice
460 (list :tag "Agenda"
461 (const :format "" agenda)
462 (const :tag "" :format "" "")
463 ,org-agenda-custom-commands-local-options)
464 (list :tag "TODO list (all keywords)"
465 (const :format "" alltodo)
466 (const :tag "" :format "" "")
467 ,org-agenda-custom-commands-local-options)
468 (list :tag "Search words"
469 (const :format "" search)
470 (string :tag "Match")
471 ,org-agenda-custom-commands-local-options)
472 (list :tag "Stuck projects"
473 (const :format "" stuck)
474 (const :tag "" :format "" "")
475 ,org-agenda-custom-commands-local-options)
476 (list :tag "Tags search"
477 (const :format "" tags)
478 (string :tag "Match")
479 ,org-agenda-custom-commands-local-options)
480 (list :tag "Tags search, TODO entries only"
481 (const :format "" tags-todo)
482 (string :tag "Match")
483 ,org-agenda-custom-commands-local-options)
484 (list :tag "TODO keyword search"
485 (const :format "" todo)
486 (string :tag "Match")
487 ,org-agenda-custom-commands-local-options)
488 (list :tag "Other, user-defined function"
489 (symbol :tag "function")
490 (string :tag "Match")
491 ,org-agenda-custom-commands-local-options)))
493 (repeat :tag "Settings for entire command set"
494 (list (variable :tag "Any variable")
495 (sexp :tag "Value")))
496 (option (repeat :tag "Export" (file :tag "Export to"))))
497 (cons :tag "Prefix key documentation"
498 (string :tag "Access Key(s)")
499 (string :tag "Description ")))))
501 (defcustom org-agenda-query-register ?o
502 "The register holding the current query string.
503 The purpose of this is that if you construct a query string interactively,
504 you can then use it to define a custom command."
505 :group 'org-agenda-custom-commands
506 :type 'character)
508 (defcustom org-stuck-projects
509 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
510 "How to identify stuck projects.
511 This is a list of four items:
512 1. A tags/todo/property matcher string that is used to identify a project.
513 See the manual for a description of tag and property searches.
514 The entire tree below a headline matched by this is considered one project.
515 2. A list of TODO keywords identifying non-stuck projects.
516 If the project subtree contains any headline with one of these todo
517 keywords, the project is considered to be not stuck. If you specify
518 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
519 3. A list of tags identifying non-stuck projects.
520 If the project subtree contains any headline with one of these tags,
521 the project is considered to be not stuck. If you specify \"*\" as
522 a tag, any tag will mark the project unstuck. Note that this is about
523 the explicit presence of a tag somewhere in the subtree, inherited
524 tags to not count here. If inherited tags make a project not stuck,
525 use \"-TAG\" in the tags part of the matcher under (1.) above.
526 4. An arbitrary regular expression matching non-stuck projects.
528 If the project turns out to be not stuck, search continues also in the
529 subtree to see if any of the subtasks have project status.
531 See also the variable `org-tags-match-list-sublevels' which applies
532 to projects matched by this search as well.
534 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
535 or `C-c a #' to produce the list."
536 :group 'org-agenda-custom-commands
537 :type '(list
538 (string :tag "Tags/TODO match to identify a project")
539 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
540 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
541 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
543 (defcustom org-agenda-filter-effort-default-operator "<"
544 "The default operator for effort estimate filtering.
545 If you select an effort estimate limit without first pressing an operator,
546 this one will be used."
547 :group 'org-agenda-custom-commands
548 :type '(choice (const :tag "less or equal" "<")
549 (const :tag "greater or equal"">")
550 (const :tag "equal" "=")))
552 (defgroup org-agenda-skip nil
553 "Options concerning skipping parts of agenda files."
554 :tag "Org Agenda Skip"
555 :group 'org-agenda)
557 (defcustom org-agenda-skip-function-global nil
558 "Function to be called at each match during agenda construction.
559 If this function returns nil, the current match should not be skipped.
560 If the function decided to skip an agenda match, is must return the
561 buffer position from which the search should be continued.
562 This may also be a Lisp form, which will be evaluated.
564 This variable will be applied to every agenda match, including
565 tags/property searches and TODO lists. So try to make the test function
566 do its checking as efficiently as possible. To implement a skipping
567 condition just for specific agenda commands, use the variable
568 `org-agenda-skip-function' which can be set in the options section
569 of custom agenda commands."
570 :group 'org-agenda-skip
571 :type 'sexp)
573 (defgroup org-agenda-daily/weekly nil
574 "Options concerning the daily/weekly agenda."
575 :tag "Org Agenda Daily/Weekly"
576 :group 'org-agenda)
577 (defgroup org-agenda-todo-list nil
578 "Options concerning the global todo list agenda view."
579 :tag "Org Agenda Todo List"
580 :group 'org-agenda)
581 (defgroup org-agenda-match-view nil
582 "Options concerning the general tags/property/todo match agenda view."
583 :tag "Org Agenda Match View"
584 :group 'org-agenda)
585 (defgroup org-agenda-search-view nil
586 "Options concerning the general tags/property/todo match agenda view."
587 :tag "Org Agenda Match View"
588 :group 'org-agenda)
590 (defvar org-agenda-archives-mode nil
591 "Non-nil means the agenda will include archived items.
592 If this is the symbol `trees', trees in the selected agenda scope
593 that are marked with the ARCHIVE tag will be included anyway. When this is
594 t, also all archive files associated with the current selection of agenda
595 files will be included.")
597 (defcustom org-agenda-skip-comment-trees t
598 "Non-nil means skip trees that start with the COMMENT keyword.
599 When nil, these trees are also scanned by agenda commands."
600 :group 'org-agenda-skip
601 :type 'boolean)
603 (defcustom org-agenda-todo-list-sublevels t
604 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
605 When nil, the sublevels of a TODO entry are not checked, resulting in
606 potentially much shorter TODO lists."
607 :group 'org-agenda-skip
608 :group 'org-agenda-todo-list
609 :type 'boolean)
611 (defcustom org-agenda-todo-ignore-with-date nil
612 "Non-nil means don't show entries with a date in the global todo list.
613 You can use this if you prefer to mark mere appointments with a TODO keyword,
614 but don't want them to show up in the TODO list.
615 When this is set, it also covers deadlines and scheduled items, the settings
616 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
617 will be ignored.
618 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
619 :group 'org-agenda-skip
620 :group 'org-agenda-todo-list
621 :type 'boolean)
623 (defcustom org-agenda-todo-ignore-timestamp nil
624 "Non-nil means don't show entries with a timestamp.
625 This applies when creating the global todo list.
626 Valid values are:
628 past Don't show entries for today or in the past.
630 future Don't show entries with a timestamp in the future.
631 The idea behind this is that if it has a future
632 timestamp, you don't want to think about it until the
633 date.
635 all Don't show any entries with a timestamp in the global todo list.
636 The idea behind this is that by setting a timestamp, you
637 have already \"taken care\" of this item.
639 This variable can also have an integer as a value. If positive (N),
640 todos with a timestamp N or more days in the future will be ignored. If
641 negative (-N), todos with a timestamp N or more days in the past will be
642 ignored. If 0, todos with a timestamp either today or in the future will
643 be ignored. For example, a value of -1 will exclude todos with a
644 timestamp in the past (yesterday or earlier), while a value of 7 will
645 exclude todos with a timestamp a week or more in the future.
647 See also `org-agenda-todo-ignore-with-date'.
648 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
649 to make his option also apply to the tags-todo list."
650 :group 'org-agenda-skip
651 :group 'org-agenda-todo-list
652 :version "24.1"
653 :type '(choice
654 (const :tag "Ignore future timestamp todos" future)
655 (const :tag "Ignore past or present timestamp todos" past)
656 (const :tag "Ignore all timestamp todos" all)
657 (const :tag "Show timestamp todos" nil)
658 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
660 (defcustom org-agenda-todo-ignore-scheduled nil
661 "Non-nil means, ignore some scheduled TODO items when making TODO list.
662 This applies when creating the global todo list.
663 Valid values are:
665 past Don't show entries scheduled today or in the past.
667 future Don't show entries scheduled in the future.
668 The idea behind this is that by scheduling it, you don't want to
669 think about it until the scheduled date.
671 all Don't show any scheduled entries in the global todo list.
672 The idea behind this is that by scheduling it, you have already
673 \"taken care\" of this item.
675 t Same as `all', for backward compatibility.
677 This variable can also have an integer as a value. See
678 `org-agenda-todo-ignore-timestamp' for more details.
680 See also `org-agenda-todo-ignore-with-date'.
681 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
682 to make his option also apply to the tags-todo list."
683 :group 'org-agenda-skip
684 :group 'org-agenda-todo-list
685 :type '(choice
686 (const :tag "Ignore future-scheduled todos" future)
687 (const :tag "Ignore past- or present-scheduled todos" past)
688 (const :tag "Ignore all scheduled todos" all)
689 (const :tag "Ignore all scheduled todos (compatibility)" t)
690 (const :tag "Show scheduled todos" nil)
691 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
693 (defcustom org-agenda-todo-ignore-deadlines nil
694 "Non-nil means ignore some deadlined TODO items when making TODO list.
695 There are different motivations for using different values, please think
696 carefully when configuring this variable.
698 This applies when creating the global todo list.
699 Valid values are:
701 near Don't show near deadline entries. A deadline is near when it is
702 closer than `org-deadline-warning-days' days. The idea behind this
703 is that such items will appear in the agenda anyway.
705 far Don't show TODO entries where a deadline has been defined, but
706 the deadline is not near. This is useful if you don't want to
707 use the todo list to figure out what to do now.
709 past Don't show entries with a deadline timestamp for today or in the past.
711 future Don't show entries with a deadline timestamp in the future, not even
712 when they become `near' ones. Use it with caution.
714 all Ignore all TODO entries that do have a deadline.
716 t Same as `near', for backward compatibility.
718 This variable can also have an integer as a value. See
719 `org-agenda-todo-ignore-timestamp' for more details.
721 See also `org-agenda-todo-ignore-with-date'.
722 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
723 to make his option also apply to the tags-todo list."
724 :group 'org-agenda-skip
725 :group 'org-agenda-todo-list
726 :type '(choice
727 (const :tag "Ignore near deadlines" near)
728 (const :tag "Ignore near deadlines (compatibility)" t)
729 (const :tag "Ignore far deadlines" far)
730 (const :tag "Ignore all TODOs with a deadlines" all)
731 (const :tag "Show all TODOs, even if they have a deadline" nil)
732 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
734 (defcustom org-agenda-tags-todo-honor-ignore-options nil
735 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
736 The variables
737 `org-agenda-todo-ignore-with-date',
738 `org-agenda-todo-ignore-timestamp',
739 `org-agenda-todo-ignore-scheduled',
740 `org-agenda-todo-ignore-deadlines'
741 make the global TODO list skip entries that have time stamps of certain
742 kinds. If this option is set, the same options will also apply for the
743 tags-todo search, which is the general tags/property matcher
744 restricted to unfinished TODO entries only."
745 :group 'org-agenda-skip
746 :group 'org-agenda-todo-list
747 :group 'org-agenda-match-view
748 :type 'boolean)
750 (defcustom org-agenda-skip-scheduled-if-done nil
751 "Non-nil means don't show scheduled items in agenda when they are done.
752 This is relevant for the daily/weekly agenda, not for the TODO list. And
753 it applies only to the actual date of the scheduling. Warnings about
754 an item with a past scheduling dates are always turned off when the item
755 is DONE."
756 :group 'org-agenda-skip
757 :group 'org-agenda-daily/weekly
758 :type 'boolean)
760 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
761 "Non-nil means skip scheduling line if same entry shows because of deadline.
762 In the agenda of today, an entry can show up multiple times because
763 it is both scheduled and has a nearby deadline, and maybe a plain time
764 stamp as well.
765 When this variable is t, then only the deadline is shown and the fact that
766 the entry is scheduled today or was scheduled previously is not shown.
767 When this variable is nil, the entry will be shown several times. When
768 the variable is the symbol `not-today', then skip scheduled previously,
769 but not scheduled today."
770 :group 'org-agenda-skip
771 :group 'org-agenda-daily/weekly
772 :type '(choice
773 (const :tag "Never" nil)
774 (const :tag "Always" t)
775 (const :tag "Not when scheduled today" not-today)))
777 (defcustom org-agenda-skip-deadline-if-done nil
778 "Non-nil means don't show deadlines when the corresponding item is done.
779 When nil, the deadline is still shown and should give you a happy feeling.
780 This is relevant for the daily/weekly agenda. And it applied only to the
781 actually date of the deadline. Warnings about approaching and past-due
782 deadlines are always turned off when the item is DONE."
783 :group 'org-agenda-skip
784 :group 'org-agenda-daily/weekly
785 :type 'boolean)
787 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
788 "Non-nil means skip deadline prewarning when entry is also scheduled.
789 This will apply on all days where a prewarning for the deadline would
790 be shown, but not at the day when the entry is actually due. On that day,
791 the deadline will be shown anyway.
792 This variable may be set to nil, t, or a number which will then give
793 the number of days before the actual deadline when the prewarnings
794 should resume.
795 This can be used in a workflow where the first showing of the deadline will
796 trigger you to schedule it, and then you don't want to be reminded of it
797 because you will take care of it on the day when scheduled."
798 :group 'org-agenda-skip
799 :group 'org-agenda-daily/weekly
800 :version "24.1"
801 :type '(choice
802 (const :tag "Alwas show prewarning" nil)
803 (const :tag "Remove prewarning if entry is scheduled" t)
804 (integer :tag "Restart prewarning N days before deadline")))
806 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
807 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
808 When non-nil, after the search for timestamps has matched once in an
809 entry, the rest of the entry will not be searched."
810 :group 'org-agenda-skip
811 :type 'boolean)
813 (defcustom org-agenda-skip-timestamp-if-done nil
814 "Non-nil means don't select item by timestamp or -range if it is DONE."
815 :group 'org-agenda-skip
816 :group 'org-agenda-daily/weekly
817 :type 'boolean)
819 (defcustom org-agenda-dim-blocked-tasks t
820 "Non-nil means dim blocked tasks in the agenda display.
821 This causes some overhead during agenda construction, but if you
822 have turned on `org-enforce-todo-dependencies',
823 `org-enforce-todo-checkbox-dependencies', or any other blocking
824 mechanism, this will create useful feedback in the agenda.
826 Instead of t, this variable can also have the value `invisible'.
827 Then blocked tasks will be invisible and only become visible when
828 they become unblocked. An exemption to this behavior is when a task is
829 blocked because of unchecked checkboxes below it. Since checkboxes do
830 not show up in the agenda views, making this task invisible you remove any
831 trace from agenda views that there is something to do. Therefore, a task
832 that is blocked because of checkboxes will never be made invisible, it
833 will only be dimmed."
834 :group 'org-agenda-daily/weekly
835 :group 'org-agenda-todo-list
836 :type '(choice
837 (const :tag "Do not dim" nil)
838 (const :tag "Dim to a gray face" t)
839 (const :tag "Make invisible" invisible)))
841 (defcustom org-timeline-show-empty-dates 3
842 "Non-nil means `org-timeline' also shows dates without an entry.
843 When nil, only the days which actually have entries are shown.
844 When t, all days between the first and the last date are shown.
845 When an integer, show also empty dates, but if there is a gap of more than
846 N days, just insert a special line indicating the size of the gap."
847 :group 'org-agenda-skip
848 :type '(choice
849 (const :tag "None" nil)
850 (const :tag "All" t)
851 (integer :tag "at most")))
853 (defgroup org-agenda-startup nil
854 "Options concerning initial settings in the Agenda in Org Mode."
855 :tag "Org Agenda Startup"
856 :group 'org-agenda)
858 (defcustom org-agenda-menu-show-matcher t
859 "Non-nil means show the match string in the agenda dispatcher menu.
860 When nil, the matcher string is not shown, but is put into the help-echo
861 property so than moving the mouse over the command shows it.
862 Setting it to nil is good if matcher strings are very long and/or if
863 you want to use two-column display (see `org-agenda-menu-two-column')."
864 :group 'org-agenda
865 :version "24.1"
866 :type 'boolean)
868 (defcustom org-agenda-menu-two-column nil
869 "Non-nil means, use two columns to show custom commands in the dispatcher.
870 If you use this, you probably want to set `org-agenda-menu-show-matcher'
871 to nil."
872 :group 'org-agenda
873 :version "24.1"
874 :type 'boolean)
876 (defcustom org-finalize-agenda-hook nil
877 "Hook run just before displaying an agenda buffer."
878 :group 'org-agenda-startup
879 :type 'hook)
881 (defcustom org-agenda-mouse-1-follows-link nil
882 "Non-nil means mouse-1 on a link will follow the link in the agenda.
883 A longer mouse click will still set point. Does not work on XEmacs.
884 Needs to be set before org.el is loaded."
885 :group 'org-agenda-startup
886 :type 'boolean)
888 (defcustom org-agenda-start-with-follow-mode nil
889 "The initial value of follow mode in a newly created agenda window."
890 :group 'org-agenda-startup
891 :type 'boolean)
893 (defcustom org-agenda-follow-indirect nil
894 "Non-nil means `org-agenda-follow-mode' displays only the
895 current item's tree, in an indirect buffer."
896 :group 'org-agenda
897 :version "24.1"
898 :type 'boolean)
900 (defcustom org-agenda-show-outline-path t
901 "Non-nil means show outline path in echo area after line motion."
902 :group 'org-agenda-startup
903 :type 'boolean)
905 (defcustom org-agenda-start-with-entry-text-mode nil
906 "The initial value of entry-text-mode in a newly created agenda window."
907 :group 'org-agenda-startup
908 :type 'boolean)
910 (defcustom org-agenda-entry-text-maxlines 5
911 "Number of text lines to be added when `E' is pressed in the agenda.
913 Note that this variable only used during agenda display. Add add entry text
914 when exporting the agenda, configure the variable
915 `org-agenda-add-entry-ext-maxlines'."
916 :group 'org-agenda
917 :type 'integer)
919 (defcustom org-agenda-entry-text-exclude-regexps nil
920 "List of regular expressions to clean up entry text.
921 The complete matches of all regular expressions in this list will be
922 removed from entry text before it is shown in the agenda."
923 :group 'org-agenda
924 :type '(repeat (regexp)))
926 (defvar org-agenda-entry-text-cleanup-hook nil
927 "Hook that is run after basic cleanup of entry text to be shown in agenda.
928 This cleanup is done in a temporary buffer, so the function may inspect and
929 change the entire buffer.
930 Some default stuff like drawers and scheduling/deadline dates will already
931 have been removed when this is called, as will any matches for regular
932 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
934 (defvar org-agenda-include-inactive-timestamps nil
935 "Non-nil means include inactive time stamps in agenda and timeline.")
937 (defgroup org-agenda-windows nil
938 "Options concerning the windows used by the Agenda in Org Mode."
939 :tag "Org Agenda Windows"
940 :group 'org-agenda)
942 (defcustom org-agenda-window-setup 'reorganize-frame
943 "How the agenda buffer should be displayed.
944 Possible values for this option are:
946 current-window Show agenda in the current window, keeping all other windows.
947 other-window Use `switch-to-buffer-other-window' to display agenda.
948 reorganize-frame Show only two windows on the current frame, the current
949 window and the agenda.
950 other-frame Use `switch-to-buffer-other-frame' to display agenda.
951 Also, when exiting the agenda, kill that frame.
952 See also the variable `org-agenda-restore-windows-after-quit'."
953 :group 'org-agenda-windows
954 :type '(choice
955 (const current-window)
956 (const other-frame)
957 (const other-window)
958 (const reorganize-frame)))
960 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
961 "The min and max height of the agenda window as a fraction of frame height.
962 The value of the variable is a cons cell with two numbers between 0 and 1.
963 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
964 :group 'org-agenda-windows
965 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
967 (defcustom org-agenda-restore-windows-after-quit nil
968 "Non-nil means restore window configuration upon exiting agenda.
969 Before the window configuration is changed for displaying the agenda,
970 the current status is recorded. When the agenda is exited with
971 `q' or `x' and this option is set, the old state is restored. If
972 `org-agenda-window-setup' is `other-frame', the value of this
973 option will be ignored."
974 :group 'org-agenda-windows
975 :type 'boolean)
977 (defcustom org-agenda-ndays nil
978 "Number of days to include in overview display.
979 Should be 1 or 7.
980 Obsolete, see `org-agenda-span'."
981 :group 'org-agenda-daily/weekly
982 :type 'integer)
984 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
986 (defcustom org-agenda-span 'week
987 "Number of days to include in overview display.
988 Can be day, week, month, year, or any number of days.
989 Custom commands can set this variable in the options section."
990 :group 'org-agenda-daily/weekly
991 :type '(choice (const :tag "Day" day)
992 (const :tag "Week" week)
993 (const :tag "Month" month)
994 (const :tag "Year" year)
995 (integer :tag "Custom")))
997 (defcustom org-agenda-start-on-weekday 1
998 "Non-nil means start the overview always on the specified weekday.
999 0 denotes Sunday, 1 denotes Monday etc.
1000 When nil, always start on the current day.
1001 Custom commands can set this variable in the options section."
1002 :group 'org-agenda-daily/weekly
1003 :type '(choice (const :tag "Today" nil)
1004 (integer :tag "Weekday No.")))
1006 (defcustom org-agenda-show-all-dates t
1007 "Non-nil means `org-agenda' shows every day in the selected range.
1008 When nil, only the days which actually have entries are shown."
1009 :group 'org-agenda-daily/weekly
1010 :type 'boolean)
1012 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1013 "Format string for displaying dates in the agenda.
1014 Used by the daily/weekly agenda and by the timeline. This should be
1015 a format string understood by `format-time-string', or a function returning
1016 the formatted date as a string. The function must take a single argument,
1017 a calendar-style date list like (month day year)."
1018 :group 'org-agenda-daily/weekly
1019 :type '(choice
1020 (string :tag "Format string")
1021 (function :tag "Function")))
1023 (defun org-agenda-format-date-aligned (date)
1024 "Format a date string for display in the daily/weekly agenda, or timeline.
1025 This function makes sure that dates are aligned for easy reading."
1026 (require 'cal-iso)
1027 (let* ((dayname (calendar-day-name date))
1028 (day (cadr date))
1029 (day-of-week (calendar-day-of-week date))
1030 (month (car date))
1031 (monthname (calendar-month-name month))
1032 (year (nth 2 date))
1033 (iso-week (org-days-to-iso-week
1034 (calendar-absolute-from-gregorian date)))
1035 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1036 (1- year))
1037 ((and (= month 12) (<= iso-week 1))
1038 (1+ year))
1039 (t year)))
1040 (weekstring (if (= day-of-week 1)
1041 (format " W%02d" iso-week)
1042 "")))
1043 (format "%-10s %2d %s %4d%s"
1044 dayname day monthname year weekstring)))
1046 (defcustom org-agenda-time-leading-zero nil
1047 "Non-nil means use leading zero for military times in agenda.
1048 For example, 9:30am would become 09:30 rather than 9:30."
1049 :group 'org-agenda-daily/weekly
1050 :version "24.1"
1051 :type 'boolean)
1053 (defcustom org-agenda-timegrid-use-ampm nil
1054 "When set, show AM/PM style timestamps on the timegrid."
1055 :group 'org-agenda
1056 :version "24.1"
1057 :type 'boolean)
1059 (defun org-agenda-time-of-day-to-ampm (time)
1060 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1061 (let* ((hour-number (string-to-number (substring time 0 -3)))
1062 (minute (substring time -2))
1063 (ampm "am"))
1064 (cond
1065 ((equal hour-number 12)
1066 (setq ampm "pm"))
1067 ((> hour-number 12)
1068 (setq ampm "pm")
1069 (setq hour-number (- hour-number 12))))
1070 (concat
1071 (if org-agenda-time-leading-zero
1072 (format "%02d" hour-number)
1073 (format "%02s" (number-to-string hour-number)))
1074 ":" minute ampm)))
1076 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1077 "Conditionally convert TIME to AM/PM format
1078 based on `org-agenda-timegrid-use-ampm'"
1079 (if org-agenda-timegrid-use-ampm
1080 (org-agenda-time-of-day-to-ampm time)
1081 time))
1083 (defcustom org-agenda-weekend-days '(6 0)
1084 "Which days are weekend?
1085 These days get the special face `org-agenda-date-weekend' in the agenda
1086 and timeline buffers."
1087 :group 'org-agenda-daily/weekly
1088 :type '(set :greedy t
1089 (const :tag "Monday" 1)
1090 (const :tag "Tuesday" 2)
1091 (const :tag "Wednesday" 3)
1092 (const :tag "Thursday" 4)
1093 (const :tag "Friday" 5)
1094 (const :tag "Saturday" 6)
1095 (const :tag "Sunday" 0)))
1097 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1098 "Non-nil means jump to today when moving a past date forward in time.
1099 When using S-right in the agenda to move a a date forward, and the date
1100 stamp currently points to the past, the first key press will move it
1101 to today. WHen nil, just move one day forward even if the date stays
1102 in the past."
1103 :group 'org-agenda-daily/weekly
1104 :version "24.1"
1105 :type 'boolean)
1107 (defcustom org-agenda-include-diary nil
1108 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1109 Custom commands can set this variable in the options section."
1110 :group 'org-agenda-daily/weekly
1111 :type 'boolean)
1113 (defcustom org-agenda-include-deadlines t
1114 "If non-nil, include entries within their deadline warning period.
1115 Custom commands can set this variable in the options section."
1116 :group 'org-agenda-daily/weekly
1117 :version "24.1"
1118 :type 'boolean)
1120 (defcustom org-agenda-repeating-timestamp-show-all t
1121 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1122 When set to a list of strings, only show occurrences of repeating
1123 stamps for these TODO keywords. When nil, only one occurrence is
1124 shown, either today or the nearest into the future."
1125 :group 'org-agenda-daily/weekly
1126 :type '(choice
1127 (const :tag "Show repeating stamps" t)
1128 (repeat :tag "Show repeating stamps for these TODO keywords"
1129 (string :tag "TODO Keyword"))
1130 (const :tag "Don't show repeating stamps" nil)))
1132 (defcustom org-scheduled-past-days 10000
1133 "No. of days to continue listing scheduled items that are not marked DONE.
1134 When an item is scheduled on a date, it shows up in the agenda on this
1135 day and will be listed until it is marked done for the number of days
1136 given here."
1137 :group 'org-agenda-daily/weekly
1138 :type 'integer)
1140 (defcustom org-agenda-log-mode-items '(closed clock)
1141 "List of items that should be shown in agenda log mode.
1142 This list may contain the following symbols:
1144 closed Show entries that have been closed on that day.
1145 clock Show entries that have received clocked time on that day.
1146 state Show all logged state changes.
1147 Note that instead of changing this variable, you can also press `C-u l' in
1148 the agenda to display all available LOG items temporarily."
1149 :group 'org-agenda-daily/weekly
1150 :type '(set :greedy t (const closed) (const clock) (const state)))
1152 (defcustom org-agenda-clock-consistency-checks
1153 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1154 :gap-ok-around ("4:00")
1155 :default-face ((:background "DarkRed") (:foreground "white"))
1156 :overlap-face nil :gap-face nil :no-end-time-face nil
1157 :long-face nil :short-face nil)
1158 "This is a property list, with the following keys:
1160 :max-duration Mark clocking chunks that are longer than this time.
1161 This is a time string like \"HH:MM\", or the number
1162 of minutes as an integer.
1164 :min-duration Mark clocking chunks that are shorter that this.
1165 This is a time string like \"HH:MM\", or the number
1166 of minutes as an integer.
1168 :max-gap Mark gaps between clocking chunks that are longer than
1169 this duration. A number of minutes, or a string
1170 like \"HH:MM\".
1172 :gap-ok-around List of times during the day which are usually not working
1173 times. When a gap is detected, but the gap contains any
1174 of these times, the gap is *not* reported. For example,
1175 if this is (\"4:00\" \"13:00\") then gaps that contain
1176 4:00 in the morning (i.e. the night) and 13:00
1177 (i.e. a typical lunch time) do not cause a warning.
1178 You should have at least one time during the night in this
1179 list, or otherwise the first task each morning will trigger
1180 a warning because it follows a long gap.
1182 Furthermore, the following properties can be used to define faces for
1183 issue display.
1185 :default-face the default face, if the specific face is undefined
1186 :overlap-face face for overlapping clocks
1187 :gap-face face for gaps between clocks
1188 :no-end-time-face face for incomplete clocks
1189 :long-face face for clock intervals that are too long
1190 :short-face face for clock intervals that are too short"
1191 :group 'org-agenda-daily/weekly
1192 :group 'org-clock
1193 :version "24.1"
1194 :type 'plist)
1196 (defcustom org-agenda-log-mode-add-notes t
1197 "Non-nil means add first line of notes to log entries in agenda views.
1198 If a log item like a state change or a clock entry is associated with
1199 notes, the first line of these notes will be added to the entry in the
1200 agenda display."
1201 :group 'org-agenda-daily/weekly
1202 :type 'boolean)
1204 (defcustom org-agenda-start-with-log-mode nil
1205 "The initial value of log-mode in a newly created agenda window."
1206 :group 'org-agenda-startup
1207 :group 'org-agenda-daily/weekly
1208 :type 'boolean)
1210 (defcustom org-agenda-start-with-clockreport-mode nil
1211 "The initial value of clockreport-mode in a newly created agenda window."
1212 :group 'org-agenda-startup
1213 :group 'org-agenda-daily/weekly
1214 :type 'boolean)
1216 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1217 "Property list with parameters for the clocktable in clockreport mode.
1218 This is the display mode that shows a clock table in the daily/weekly
1219 agenda, the properties for this dynamic block can be set here.
1220 The usual clocktable parameters are allowed here, but you cannot set
1221 the properties :name, :tstart, :tend, :block, and :scope - these will
1222 be overwritten to make sure the content accurately reflects the
1223 current display in the agenda."
1224 :group 'org-agenda-daily/weekly
1225 :type 'plist)
1227 (defcustom org-agenda-search-view-always-boolean nil
1228 "Non-nil means the search string is interpreted as individual parts.
1230 The search string for search view can either be interpreted as a phrase,
1231 or as a list of snippets that define a boolean search for a number of
1232 strings.
1234 When this is non-nil, the string will be split on whitespace, and each
1235 snippet will be searched individually, and all must match in order to
1236 select an entry. A snippet is then a single string of non-white
1237 characters, or a string in double quotes, or a regexp in {} braces.
1238 If a snippet is preceded by \"-\", the snippet must *not* match.
1239 \"+\" is syntactic sugar for positive selection. Each snippet may
1240 be found as a full word or a partial word, but see the variable
1241 `org-agenda-search-view-force-full-words'.
1243 When this is nil, search will look for the entire search phrase as one,
1244 with each space character matching any amount of whitespace, including
1245 line breaks.
1247 Even when this is nil, you can still switch to Boolean search dynamically
1248 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1249 is a regexp marked with braces like \"{abc}\", this will also switch to
1250 boolean search."
1251 :group 'org-agenda-search-view
1252 :version "24.1"
1253 :type 'boolean)
1255 (if (fboundp 'defvaralias)
1256 (defvaralias 'org-agenda-search-view-search-words-only
1257 'org-agenda-search-view-always-boolean))
1259 (defcustom org-agenda-search-view-force-full-words nil
1260 "Non-nil means, search words must be matches as complete words.
1261 When nil, they may also match part of a word."
1262 :group 'org-agenda-search-view
1263 :version "24.1"
1264 :type 'boolean)
1266 (defgroup org-agenda-time-grid nil
1267 "Options concerning the time grid in the Org-mode Agenda."
1268 :tag "Org Agenda Time Grid"
1269 :group 'org-agenda)
1271 (defcustom org-agenda-search-headline-for-time t
1272 "Non-nil means search headline for a time-of-day.
1273 If the headline contains a time-of-day in one format or another, it will
1274 be used to sort the entry into the time sequence of items for a day.
1275 Some people have time stamps in the headline that refer to the creation
1276 time or so, and then this produces an unwanted side effect. If this is
1277 the case for your, use this variable to turn off searching the headline
1278 for a time."
1279 :group 'org-agenda-time-grid
1280 :type 'boolean)
1282 (defcustom org-agenda-use-time-grid t
1283 "Non-nil means show a time grid in the agenda schedule.
1284 A time grid is a set of lines for specific times (like every two hours between
1285 8:00 and 20:00). The items scheduled for a day at specific times are
1286 sorted in between these lines.
1287 For details about when the grid will be shown, and what it will look like, see
1288 the variable `org-agenda-time-grid'."
1289 :group 'org-agenda-time-grid
1290 :type 'boolean)
1292 (defcustom org-agenda-time-grid
1293 '((daily today require-timed)
1294 "----------------"
1295 (800 1000 1200 1400 1600 1800 2000))
1297 "The settings for time grid for agenda display.
1298 This is a list of three items. The first item is again a list. It contains
1299 symbols specifying conditions when the grid should be displayed:
1301 daily if the agenda shows a single day
1302 weekly if the agenda shows an entire week
1303 today show grid on current date, independent of daily/weekly display
1304 require-timed show grid only if at least one item has a time specification
1306 The second item is a string which will be placed behind the grid time.
1308 The third item is a list of integers, indicating the times that should have
1309 a grid line."
1310 :group 'org-agenda-time-grid
1311 :type
1312 '(list
1313 (set :greedy t :tag "Grid Display Options"
1314 (const :tag "Show grid in single day agenda display" daily)
1315 (const :tag "Show grid in weekly agenda display" weekly)
1316 (const :tag "Always show grid for today" today)
1317 (const :tag "Show grid only if any timed entries are present"
1318 require-timed)
1319 (const :tag "Skip grid times already present in an entry"
1320 remove-match))
1321 (string :tag "Grid String")
1322 (repeat :tag "Grid Times" (integer :tag "Time"))))
1324 (defcustom org-agenda-show-current-time-in-grid t
1325 "Non-nil means show the current time in the time grid."
1326 :group 'org-agenda-time-grid
1327 :version "24.1"
1328 :type 'boolean)
1330 (defcustom org-agenda-current-time-string
1331 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1332 "The string for the current time marker in the agenda."
1333 :group 'org-agenda-time-grid
1334 :version "24.1"
1335 :type 'string)
1337 (defgroup org-agenda-sorting nil
1338 "Options concerning sorting in the Org-mode Agenda."
1339 :tag "Org Agenda Sorting"
1340 :group 'org-agenda)
1342 (defcustom org-agenda-sorting-strategy
1343 '((agenda habit-down time-up priority-down category-keep)
1344 (todo priority-down category-keep)
1345 (tags priority-down category-keep)
1346 (search category-keep))
1347 "Sorting structure for the agenda items of a single day.
1348 This is a list of symbols which will be used in sequence to determine
1349 if an entry should be listed before another entry. The following
1350 symbols are recognized:
1352 time-up Put entries with time-of-day indications first, early first
1353 time-down Put entries with time-of-day indications first, late first
1354 category-keep Keep the default order of categories, corresponding to the
1355 sequence in `org-agenda-files'.
1356 category-up Sort alphabetically by category, A-Z.
1357 category-down Sort alphabetically by category, Z-A.
1358 tag-up Sort alphabetically by last tag, A-Z.
1359 tag-down Sort alphabetically by last tag, Z-A.
1360 priority-up Sort numerically by priority, high priority last.
1361 priority-down Sort numerically by priority, high priority first.
1362 todo-state-up Sort by todo state, tasks that are done last.
1363 todo-state-down Sort by todo state, tasks that are done first.
1364 effort-up Sort numerically by estimated effort, high effort last.
1365 effort-down Sort numerically by estimated effort, high effort first.
1366 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1367 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1368 habit-up Put entries that are habits first
1369 habit-down Put entries that are habits last
1370 alpha-up Sort headlines alphabetically
1371 alpha-down Sort headlines alphabetically, reversed
1373 The different possibilities will be tried in sequence, and testing stops
1374 if one comparison returns a \"not-equal\". For example, the default
1375 '(time-up category-keep priority-down)
1376 means: Pull out all entries having a specified time of day and sort them,
1377 in order to make a time schedule for the current day the first thing in the
1378 agenda listing for the day. Of the entries without a time indication, keep
1379 the grouped in categories, don't sort the categories, but keep them in
1380 the sequence given in `org-agenda-files'. Within each category sort by
1381 priority.
1383 Leaving out `category-keep' would mean that items will be sorted across
1384 categories by priority.
1386 Instead of a single list, this can also be a set of list for specific
1387 contents, with a context symbol in the car of the list, any of
1388 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1390 Custom commands can bind this variable in the options section."
1391 :group 'org-agenda-sorting
1392 :type `(choice
1393 (repeat :tag "General" ,org-sorting-choice)
1394 (list :tag "Individually"
1395 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1396 (repeat ,org-sorting-choice))
1397 (cons (const :tag "Strategy for TODO lists" todo)
1398 (repeat ,org-sorting-choice))
1399 (cons (const :tag "Strategy for Tags matches" tags)
1400 (repeat ,org-sorting-choice))
1401 (cons (const :tag "Strategy for search matches" search)
1402 (repeat ,org-sorting-choice)))))
1404 (defcustom org-agenda-cmp-user-defined nil
1405 "A function to define the comparison `user-defined'.
1406 This function must receive two arguments, agenda entry a and b.
1407 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1408 the user comparison, return nil.
1409 When this is defined, you can make `user-defined-up' and `user-defined-down'
1410 part of an agenda sorting strategy."
1411 :group 'org-agenda-sorting
1412 :type 'symbol)
1414 (defcustom org-sort-agenda-notime-is-late t
1415 "Non-nil means items without time are considered late.
1416 This is only relevant for sorting. When t, items which have no explicit
1417 time like 15:30 will be considered as 99:01, i.e. later than any items which
1418 do have a time. When nil, the default time is before 0:00. You can use this
1419 option to decide if the schedule for today should come before or after timeless
1420 agenda entries."
1421 :group 'org-agenda-sorting
1422 :type 'boolean)
1424 (defcustom org-sort-agenda-noeffort-is-high t
1425 "Non-nil means items without effort estimate are sorted as high effort.
1426 This also applies when filtering an agenda view with respect to the
1427 < or > effort operator. Then, tasks with no effort defined will be treated
1428 as tasks with high effort.
1429 When nil, such items are sorted as 0 minutes effort."
1430 :group 'org-agenda-sorting
1431 :type 'boolean)
1433 (defgroup org-agenda-line-format nil
1434 "Options concerning the entry prefix in the Org-mode agenda display."
1435 :tag "Org Agenda Line Format"
1436 :group 'org-agenda)
1438 (defcustom org-agenda-prefix-format
1439 '((agenda . " %i %-12:c%?-12t% s")
1440 (timeline . " % s")
1441 (todo . " %i %-12:c")
1442 (tags . " %i %-12:c")
1443 (search . " %i %-12:c"))
1444 "Format specifications for the prefix of items in the agenda views.
1445 An alist with five entries, each for the different agenda types. The
1446 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1447 The values are format strings.
1449 This format works similar to a printf format, with the following meaning:
1451 %c the category of the item, \"Diary\" for entries from the diary,
1452 or as given by the CATEGORY keyword or derived from the file name
1453 %e the effort required by the item
1454 %i the icon category of the item, see `org-agenda-category-icon-alist'
1455 %T the last tag of the item (ignore inherited tags, which come first)
1456 %t the HH:MM time-of-day specification if one applies to the entry
1457 %s Scheduling/Deadline information, a short string
1458 %(expression) Eval EXPRESSION and replace the control string
1459 by the result
1461 All specifiers work basically like the standard `%s' of printf, but may
1462 contain two additional characters: a question mark just after the `%'
1463 and a whitespace/punctuation character just before the final letter.
1465 If the first character after `%' is a question mark, the entire field
1466 will only be included if the corresponding value applies to the current
1467 entry. This is useful for fields which should have fixed width when
1468 present, but zero width when absent. For example, \"%?-12t\" will
1469 result in a 12 character time field if a time of the day is specified,
1470 but will completely disappear in entries which do not contain a time.
1472 If there is punctuation or whitespace character just before the final
1473 format letter, this character will be appended to the field value if
1474 the value is not empty. For example, the format \"%-12:c\" leads to
1475 \"Diary: \" if the category is \"Diary\". If the category were be
1476 empty, no additional colon would be inserted.
1478 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1479 which means:
1481 - Indent the line with two space characters
1482 - Give the category a 12 chars wide field, padded with whitespace on
1483 the right (because of `-'). Append a colon if there is a category
1484 (because of `:').
1485 - If there is a time-of-day, put it into a 12 chars wide field. If no
1486 time, don't put in an empty field, just skip it (because of '?').
1487 - Finally, put the scheduling information.
1489 See also the variables `org-agenda-remove-times-when-in-prefix' and
1490 `org-agenda-remove-tags'.
1492 Custom commands can set this variable in the options section."
1493 :type '(choice
1494 (string :tag "General format")
1495 (list :greedy t :tag "View dependent"
1496 (cons (const agenda) (string :tag "Format"))
1497 (cons (const timeline) (string :tag "Format"))
1498 (cons (const todo) (string :tag "Format"))
1499 (cons (const tags) (string :tag "Format"))
1500 (cons (const search) (string :tag "Format"))))
1501 :group 'org-agenda-line-format)
1503 (defvar org-prefix-format-compiled nil
1504 "The compiled prefix format and associated variables.
1505 This is a list where first element is a list of variable bindings, and second
1506 element is the compiled format expression. See the variable
1507 `org-agenda-prefix-format'.")
1509 (defcustom org-agenda-todo-keyword-format "%-1s"
1510 "Format for the TODO keyword in agenda lines.
1511 Set this to something like \"%-12s\" if you want all TODO keywords
1512 to occupy a fixed space in the agenda display."
1513 :group 'org-agenda-line-format
1514 :type 'string)
1516 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1517 "Text preceding timerange entries in the agenda view.
1518 This is a list with two strings. The first applies when the range
1519 is entirely on one day. The second applies if the range spans several days.
1520 The strings may have two \"%d\" format specifiers which will be filled
1521 with the sequence number of the days, and the total number of days in the
1522 range, respectively."
1523 :group 'org-agenda-line-format
1524 :type '(list
1525 (string :tag "Deadline today ")
1526 (choice :tag "Deadline relative"
1527 (string :tag "Format string")
1528 (function))))
1530 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1531 "Text preceding scheduled items in the agenda view.
1532 This is a list with two strings. The first applies when the item is
1533 scheduled on the current day. The second applies when it has been scheduled
1534 previously, it may contain a %d indicating that this is the nth time that
1535 this item is scheduled, due to automatic rescheduling of unfinished items
1536 for the following day. So this number is one larger than the number of days
1537 that passed since this item was scheduled first."
1538 :group 'org-agenda-line-format
1539 :type '(list
1540 (string :tag "Scheduled today ")
1541 (string :tag "Scheduled previously")))
1543 (defcustom org-agenda-inactive-leader "["
1544 "Text preceding item pulled into the agenda by inactive time stamps.
1545 These entries are added to the agenda when pressing \"[\"."
1546 :group 'org-agenda-line-format
1547 :version "24.1"
1548 :type '(list
1549 (string :tag "Scheduled today ")
1550 (string :tag "Scheduled previously")))
1552 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1553 "Text preceding deadline items in the agenda view.
1554 This is a list with two strings. The first applies when the item has its
1555 deadline on the current day. The second applies when it is in the past or
1556 in the future, it may contain %d to capture how many days away the deadline
1557 is (was)."
1558 :group 'org-agenda-line-format
1559 :type '(list
1560 (string :tag "Deadline today ")
1561 (choice :tag "Deadline relative"
1562 (string :tag "Format string")
1563 (function))))
1565 (defcustom org-agenda-remove-times-when-in-prefix t
1566 "Non-nil means remove duplicate time specifications in agenda items.
1567 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1568 time-of-day specification in a headline or diary entry is extracted and
1569 placed into the prefix. If this option is non-nil, the original specification
1570 \(a timestamp or -range, or just a plain time(range) specification like
1571 11:30-4pm) will be removed for agenda display. This makes the agenda less
1572 cluttered.
1573 The option can be t or nil. It may also be the symbol `beg', indicating
1574 that the time should only be removed when it is located at the beginning of
1575 the headline/diary entry."
1576 :group 'org-agenda-line-format
1577 :type '(choice
1578 (const :tag "Always" t)
1579 (const :tag "Never" nil)
1580 (const :tag "When at beginning of entry" beg)))
1582 (defcustom org-agenda-remove-timeranges-from-blocks nil
1583 "Non-nil means remove time ranges specifications in agenda
1584 items that span on several days."
1585 :group 'org-agenda-line-format
1586 :version "24.1"
1587 :type 'boolean)
1589 (defcustom org-agenda-default-appointment-duration nil
1590 "Default duration for appointments that only have a starting time.
1591 When nil, no duration is specified in such cases.
1592 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1593 :group 'org-agenda-line-format
1594 :type '(choice
1595 (integer :tag "Minutes")
1596 (const :tag "No default duration")))
1598 (defcustom org-agenda-show-inherited-tags t
1599 "Non-nil means show inherited tags in each agenda line."
1600 :group 'org-agenda-line-format
1601 :type 'boolean)
1603 (defcustom org-agenda-hide-tags-regexp nil
1604 "Regular expression used to filter away specific tags in agenda views.
1605 This means that these tags will be present, but not be shown in the agenda
1606 line. Secondary filtering will still work on the hidden tags.
1607 Nil means don't hide any tags."
1608 :group 'org-agenda-line-format
1609 :type '(choice
1610 (const :tag "Hide none" nil)
1611 (string :tag "Regexp ")))
1613 (defcustom org-agenda-remove-tags nil
1614 "Non-nil means remove the tags from the headline copy in the agenda.
1615 When this is the symbol `prefix', only remove tags when
1616 `org-agenda-prefix-format' contains a `%T' specifier."
1617 :group 'org-agenda-line-format
1618 :type '(choice
1619 (const :tag "Always" t)
1620 (const :tag "Never" nil)
1621 (const :tag "When prefix format contains %T" prefix)))
1623 (if (fboundp 'defvaralias)
1624 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1625 'org-agenda-remove-tags))
1627 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1628 "Shift tags in agenda items to this column.
1629 If this number is positive, it specifies the column. If it is negative,
1630 it means that the tags should be flushright to that column. For example,
1631 -80 works well for a normal 80 character screen."
1632 :group 'org-agenda-line-format
1633 :type 'integer)
1635 (if (fboundp 'defvaralias)
1636 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1638 (defcustom org-agenda-fontify-priorities 'cookies
1639 "Non-nil means highlight low and high priorities in agenda.
1640 When t, the highest priority entries are bold, lowest priority italic.
1641 However, settings in `org-priority-faces' will overrule these faces.
1642 When this variable is the symbol `cookies', only fontify the
1643 cookies, not the entire task.
1644 This may also be an association list of priority faces, whose
1645 keys are the character values of `org-highest-priority',
1646 `org-default-priority', and `org-lowest-priority' (the default values
1647 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1648 color as a string, or a list like `(:background \"Red\")'.
1649 If it is a color, the variable `org-faces-easy-properties'
1650 determines if it is a foreground or a background color."
1651 :group 'org-agenda-line-format
1652 :type '(choice
1653 (const :tag "Never" nil)
1654 (const :tag "Defaults" t)
1655 (const :tag "Cookies only" cookies)
1656 (repeat :tag "Specify"
1657 (list (character :tag "Priority" :value ?A)
1658 (choice :tag "Face "
1659 (string :tag "Color")
1660 (sexp :tag "Face"))))))
1662 (defcustom org-agenda-day-face-function nil
1663 "Function called to determine what face should be used to display a day.
1664 The only argument passed to that function is the day. It should
1665 returns a face, or nil if does not want to specify a face and let
1666 the normal rules apply."
1667 :group 'org-agenda-line-format
1668 :version "24.1"
1669 :type 'function)
1671 (defcustom org-agenda-category-icon-alist nil
1672 "Alist of category icon to be displayed in agenda views.
1674 Each entry should have the following format:
1676 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1678 Where CATEGORY-REGEXP is a regexp matching the categories where
1679 the icon should be displayed.
1680 FILE-OR-DATA either a file path or a string containing image data.
1682 The other fields can be omitted safely if not needed:
1683 TYPE indicates the image type.
1684 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1685 image data.
1686 PROPS are additional image attributes to assign to the image,
1687 like, e.g. `:ascent center'.
1689 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1691 If you want to set the display properties yourself, just put a
1692 list as second element:
1694 (CATEGORY-REGEXP (MY PROPERTY LIST))
1696 For example, to display a 16px horizontal space for Emacs
1697 category, you can use:
1699 (\"Emacs\" '(space . (:width (16))))"
1700 :group 'org-agenda-line-format
1701 :version "24.1"
1702 :type '(alist :key-type (string :tag "Regexp matching category")
1703 :value-type (choice (list :tag "Icon"
1704 (string :tag "File or data")
1705 (symbol :tag "Type")
1706 (boolean :tag "Data?")
1707 (repeat :tag "Extra image properties" :inline t symbol))
1708 (list :tag "Display properties" sexp))))
1710 (defgroup org-agenda-column-view nil
1711 "Options concerning column view in the agenda."
1712 :tag "Org Agenda Column View"
1713 :group 'org-agenda)
1715 (defcustom org-agenda-columns-show-summaries t
1716 "Non-nil means show summaries for columns displayed in the agenda view."
1717 :group 'org-agenda-column-view
1718 :type 'boolean)
1720 (defcustom org-agenda-columns-compute-summary-properties t
1721 "Non-nil means recompute all summary properties before column view.
1722 When column view in the agenda is listing properties that have a summary
1723 operator, it can go to all relevant buffers and recompute the summaries
1724 there. This can mean overhead for the agenda column view, but is necessary
1725 to have thing up to date.
1726 As a special case, a CLOCKSUM property also makes sure that the clock
1727 computations are current."
1728 :group 'org-agenda-column-view
1729 :type 'boolean)
1731 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1732 "Non-nil means the duration of an appointment will add to day effort.
1733 The property to which appointment durations will be added is the one given
1734 in the option `org-effort-property'. If an appointment does not have
1735 an end time, `org-agenda-default-appointment-duration' will be used. If that
1736 is not set, an appointment without end time will not contribute to the time
1737 estimate."
1738 :group 'org-agenda-column-view
1739 :type 'boolean)
1741 (defcustom org-agenda-auto-exclude-function nil
1742 "A function called with a tag to decide if it is filtered on '/ RET'.
1743 The sole argument to the function, which is called once for each
1744 possible tag, is a string giving the name of the tag. The
1745 function should return either nil if the tag should be included
1746 as normal, or \"-<TAG>\" to exclude the tag.
1747 Note that for the purpose of tag filtering, only the lower-case version of
1748 all tags will be considered, so that this function will only ever see
1749 the lower-case version of all tags."
1750 :group 'org-agenda
1751 :type 'function)
1753 (defcustom org-agenda-bulk-custom-functions nil
1754 "Alist of characters and custom functions for bulk actions.
1755 For example, this value makes those two functions available:
1757 '((?R set-category)
1758 (?C bulk-cut))
1760 With selected entries in an agenda buffer, `B R' will call
1761 the custom function `set-category' on the selected entries.
1762 Note that functions in this alist don't need to be quoted."
1763 :type 'alist
1764 :version "24.1"
1765 :group 'org-agenda)
1767 (eval-when-compile
1768 (require 'cl))
1769 (require 'org)
1771 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1772 "Execute BODY with point at location given by `org-hd-marker' property.
1773 If STRING is non-nil, the text property will be fetched from position 0
1774 in that string. If STRING is nil, it will be fetched from the beginning
1775 of the current line."
1776 (org-with-gensyms (marker)
1777 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1778 'org-hd-marker ,string)))
1779 (with-current-buffer (marker-buffer ,marker)
1780 (save-excursion
1781 (goto-char ,marker)
1782 ,@body)))))
1783 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1785 (defun org-add-agenda-custom-command (entry)
1786 "Replace or add a command in `org-agenda-custom-commands'.
1787 This is mostly for hacking and trying a new command - once the command
1788 works you probably want to add it to `org-agenda-custom-commands' for good."
1789 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1790 (if ass
1791 (setcdr ass (cdr entry))
1792 (push entry org-agenda-custom-commands))))
1794 ;;; Define the org-agenda-mode
1796 (defvar org-agenda-mode-map (make-sparse-keymap)
1797 "Keymap for `org-agenda-mode'.")
1798 (if (fboundp 'defvaralias)
1799 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1801 (defvar org-agenda-menu) ; defined later in this file.
1802 (defvar org-agenda-restrict) ; defined later in this file.
1803 (defvar org-agenda-follow-mode nil)
1804 (defvar org-agenda-entry-text-mode nil)
1805 (defvar org-agenda-clockreport-mode nil)
1806 (defvar org-agenda-show-log nil)
1807 (defvar org-agenda-redo-command nil)
1808 (defvar org-agenda-query-string nil)
1809 (defvar org-agenda-mode-hook nil
1810 "Hook for `org-agenda-mode', run after the mode is turned on.")
1811 (defvar org-agenda-type nil)
1812 (defvar org-agenda-force-single-file nil)
1813 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1816 ;;; Multiple agenda buffers support
1818 (defcustom org-agenda-sticky nil
1819 "Non-nil means agenda q key will bury agenda buffers.
1820 Agenda commands will then show existing buffer instead of generating new ones.
1821 When nil, `q' will kill the single agenda buffer."
1822 :group 'org-agenda
1823 :type 'boolean)
1825 (defvar org-agenda-buffer nil
1826 "Agenda buffer currently being generated.")
1828 (defun org-toggle-sticky-agenda (&optional arg)
1829 "Toggle `org-agenda-sticky'."
1830 (interactive)
1831 (setq org-agenda-sticky (or arg (not org-agenda-sticky)))
1832 (message "Sticky agenda was %s" (if org-agenda-sticky "enabled" "disabled")))
1834 (defvar org-agenda-last-prefix-arg nil)
1835 (defvar org-agenda-this-buffer-name nil)
1836 (defvar org-agenda-doing-sticky-redo nil)
1837 (defvar org-agenda-this-buffer-is-sticky nil)
1839 ;; below list is generating by grepping org-agenda.el for defvar
1840 (defconst org-agenda-local-vars
1841 '(;; calendar-mode-map
1842 ; org-clock-current-task
1843 ; org-mobile-force-id-on-agenda-items
1844 ; org-habit-show-habits
1845 ; org-habit-show-habits-only-for-today
1846 org-agenda-this-buffer-name
1847 ; org-agenda-overriding-header
1848 ; org-agenda-title-append
1849 org-agenda-undo-list
1850 org-agenda-pending-undo-list
1851 org-agenda-archives-mode
1852 ; org-agenda-entry-text-cleanup-hook
1853 ; org-agenda-include-inactive-timestamps ?????????????
1854 ; org-prefix-format-compiled ???????????
1855 ; org-agenda-mode-map
1856 ; org-agenda-menu
1857 org-agenda-follow-mode
1858 org-agenda-entry-text-mode
1859 org-agenda-clockreport-mode
1860 org-agenda-show-log
1861 org-agenda-redo-command
1862 org-agenda-query-string
1863 ; org-agenda-mode-hook
1864 org-agenda-type
1865 org-agenda-force-single-file
1866 org-agenda-bulk-marked-entries
1867 ; org-agenda-allow-remote-undo
1868 org-agenda-undo-has-started-in
1869 org-agenda-restrict
1870 org-agenda-restrict-begin
1871 org-agenda-restrict-end
1872 ; org-agenda-last-dispatch-buffer
1873 ;; org-agenda-overriding-restriction
1874 ;; org-agenda-overriding-arguments
1875 org-agenda-last-arguments
1876 org-agenda-info
1877 ; org-mobile-creating-agendas
1878 org-agenda-tag-filter-overlays
1879 org-agenda-cat-filter-overlays
1880 ; org-agenda-marker-table
1881 org-pre-agenda-window-conf
1882 org-agenda-columns-active
1883 org-agenda-name
1884 org-agenda-tag-filter
1885 org-agenda-category-filter
1886 org-agenda-tag-filter-while-redo
1887 org-agenda-tag-filter-preset
1888 org-agenda-category-filter-preset
1889 ; org-agenda-skip-function
1890 org-agenda-markers
1891 ; org-agenda-last-marker-time
1892 ; org-agenda-only-exact-dates
1893 ; org-agenda-start-day
1894 org-starting-day ; not necessary to include, but no harm
1895 org-agenda-current-span ; not necessary to include, but no harm
1896 org-arg-loc ; not necessary to include, but no harm
1897 ; org-agenda-entry-types
1898 ; org-agenda-search-history
1899 ; org-todo-only
1900 ; org-search-syntax-table
1901 org-agenda-last-search-view-search-was-boolean
1902 org-last-arg ; not necessary to include, but no harm
1903 ; org-agenda-skip-regexp
1904 ; org-agenda-overriding-header
1905 ; org-disable-agenda-to-diary
1906 ; diary-list-entries-hook
1907 ; diary-time-regexp
1908 ; org-agenda-cleanup-fancy-diary-hook
1909 ; org-diary-last-run-time
1910 ; org-heading-keyword-regexp-format
1911 ; org-agenda-sorting-strategy
1912 ; org-agenda-sorting-strategy-selected
1913 ; org-agenda-before-sorting-filter-function
1914 ; org-agenda-restriction-lock-overlay
1915 ; org-global-tags-completion-table
1916 org-agenda-filtered-by-category
1917 org-agenda-filter-form
1918 ; org-hl
1919 ; org-agenda-after-show-hook
1920 ; org-archive-default-command
1921 org-agenda-show-window ; not sure if needed, but probably OK
1922 org-agenda-cycle-counter ; not sure if needed, but probably OK
1923 ; org-last-heading-marker
1924 ;; calendar-longitude
1925 ;; calendar-latitude
1926 ;; calendar-location-name
1927 org-agenda-bulk-marked-entries
1928 ; appt-time-msg-list
1929 org-agenda-last-prefix-arg
1933 (defun org-agenda-mode ()
1934 "Mode for time-sorted view on action items in Org-mode files.
1936 The following commands are available:
1938 \\{org-agenda-mode-map}"
1939 (interactive)
1940 (cond (org-agenda-doing-sticky-redo
1941 ;; Refreshing sticky agenda-buffer
1943 ;; Preserve the value of `org-agenda-local-vars' variables,
1944 ;; while letting `kill-all-local-variables' kill the rest
1945 (let ((save (buffer-local-variables)))
1946 (kill-all-local-variables)
1947 (mapc 'make-local-variable org-agenda-local-vars)
1948 (dolist (elem save)
1949 (let ((var (car elem))
1950 (val (cdr elem)))
1951 (when (and val
1952 (member var org-agenda-local-vars))
1953 (set var val)))))
1954 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1955 (org-agenda-sticky
1956 ;; Creating a sticky Agenda buffer for the first time
1957 (kill-all-local-variables)
1958 (mapc 'make-local-variable org-agenda-local-vars)
1959 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1961 ;; Creating a non-sticky agenda buffer
1962 (kill-all-local-variables)
1963 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1964 (setq org-agenda-undo-list nil
1965 org-agenda-pending-undo-list nil
1966 org-agenda-bulk-marked-entries nil)
1967 (setq major-mode 'org-agenda-mode)
1968 ;; Keep global-font-lock-mode from turning on font-lock-mode
1969 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1970 (setq mode-name "Org-Agenda")
1971 (use-local-map org-agenda-mode-map)
1972 (easy-menu-add org-agenda-menu)
1973 (if org-startup-truncated (setq truncate-lines t))
1974 (org-set-local 'line-move-visual nil)
1975 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1976 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1977 ;; Make sure properties are removed when copying text
1978 (when (boundp 'buffer-substring-filters)
1979 (org-set-local 'buffer-substring-filters
1980 (cons (lambda (x)
1981 (set-text-properties 0 (length x) nil x) x)
1982 buffer-substring-filters)))
1983 (unless org-agenda-keep-modes
1984 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1985 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1986 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1987 org-agenda-show-log org-agenda-start-with-log-mode))
1989 (easy-menu-change
1990 '("Agenda") "Agenda Files"
1991 (append
1992 (list
1993 (vector
1994 (if (get 'org-agenda-files 'org-restrict)
1995 "Restricted to single file"
1996 "Edit File List")
1997 '(org-edit-agenda-file-list)
1998 (not (get 'org-agenda-files 'org-restrict)))
1999 "--")
2000 (mapcar 'org-file-menu-entry (org-agenda-files))))
2001 (org-agenda-set-mode-name)
2002 (apply
2003 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2004 (list 'org-agenda-mode-hook)))
2006 (substitute-key-definition 'undo 'org-agenda-undo
2007 org-agenda-mode-map global-map)
2008 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2009 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2010 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2011 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2012 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2013 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2014 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2015 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2016 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
2017 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2018 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2019 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2020 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2021 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2022 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2023 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2024 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2025 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2026 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2027 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2028 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2029 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2030 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2031 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2032 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2033 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2034 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2035 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2036 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2037 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2038 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2039 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2040 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2041 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2042 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2043 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2044 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2045 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2046 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2047 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
2048 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
2049 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2050 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2051 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2052 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2054 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2055 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2056 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2057 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2058 (while l (org-defkey org-agenda-mode-map
2059 (int-to-string (pop l)) 'digit-argument)))
2061 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2062 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2063 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2064 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2065 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2066 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2067 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2068 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2069 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2070 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
2071 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2072 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2073 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2074 'org-clock-modify-effort-estimate)
2075 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2076 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2077 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2078 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2079 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2080 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2081 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2082 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
2083 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2084 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2085 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2086 (substitute-key-definition 'next-line 'org-agenda-next-line
2087 org-agenda-mode-map global-map)
2088 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2089 org-agenda-mode-map global-map)
2090 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2091 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2092 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2093 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2094 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2095 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2096 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2097 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2098 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2099 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2100 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2101 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2102 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2103 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2104 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2105 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2106 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2107 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2108 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2109 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2110 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2111 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2112 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2113 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2114 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2115 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2116 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2117 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2118 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2119 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2121 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2122 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2123 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2124 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2125 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2126 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2127 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2128 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2129 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2130 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2131 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2133 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2134 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2135 (when org-agenda-mouse-1-follows-link
2136 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2137 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2138 '("Agenda"
2139 ("Agenda Files")
2140 "--"
2141 ("Agenda Dates"
2142 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2143 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2144 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2145 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2146 "--"
2147 ("View"
2148 ["Day View" org-agenda-day-view
2149 :active (org-agenda-check-type nil 'agenda)
2150 :style radio :selected (eq org-agenda-current-span 'day)
2151 :keys "v d (or just d)"]
2152 ["Week View" org-agenda-week-view
2153 :active (org-agenda-check-type nil 'agenda)
2154 :style radio :selected (eq org-agenda-current-span 'week)
2155 :keys "v w (or just w)"]
2156 ["Month View" org-agenda-month-view
2157 :active (org-agenda-check-type nil 'agenda)
2158 :style radio :selected (eq org-agenda-current-span 'month)
2159 :keys "v m"]
2160 ["Year View" org-agenda-year-view
2161 :active (org-agenda-check-type nil 'agenda)
2162 :style radio :selected (eq org-agenda-current-span 'year)
2163 :keys "v y"]
2164 "--"
2165 ["Include Diary" org-agenda-toggle-diary
2166 :style toggle :selected org-agenda-include-diary
2167 :active (org-agenda-check-type nil 'agenda)]
2168 ["Include Deadlines" org-agenda-toggle-deadlines
2169 :style toggle :selected org-agenda-include-deadlines
2170 :active (org-agenda-check-type nil 'agenda)]
2171 ["Use Time Grid" org-agenda-toggle-time-grid
2172 :style toggle :selected org-agenda-use-time-grid
2173 :active (org-agenda-check-type nil 'agenda)]
2174 "--"
2175 ["Show clock report" org-agenda-clockreport-mode
2176 :style toggle :selected org-agenda-clockreport-mode
2177 :active (org-agenda-check-type nil 'agenda)]
2178 ["Show some entry text" org-agenda-entry-text-mode
2179 :style toggle :selected org-agenda-entry-text-mode
2180 :active t]
2181 "--"
2182 ["Show Logbook entries" org-agenda-log-mode
2183 :style toggle :selected org-agenda-show-log
2184 :active (org-agenda-check-type nil 'agenda 'timeline)
2185 :keys "v l (or just l)"]
2186 ["Include archived trees" org-agenda-archives-mode
2187 :style toggle :selected org-agenda-archives-mode :active t
2188 :keys "v a"]
2189 ["Include archive files" (org-agenda-archives-mode t)
2190 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2191 :keys "v A"]
2192 "--"
2193 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2194 ["Write view to file" org-agenda-write t]
2195 ["Rebuild buffer" org-agenda-redo t]
2196 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2197 "--"
2198 ["Show original entry" org-agenda-show t]
2199 ["Go To (other window)" org-agenda-goto t]
2200 ["Go To (this window)" org-agenda-switch-to t]
2201 ["Follow Mode" org-agenda-follow-mode
2202 :style toggle :selected org-agenda-follow-mode :active t]
2203 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2204 "--"
2205 ("TODO"
2206 ["Cycle TODO" org-agenda-todo t]
2207 ["Next TODO set" org-agenda-todo-nextset t]
2208 ["Previous TODO set" org-agenda-todo-previousset t]
2209 ["Add note" org-agenda-add-note t])
2210 ("Archive/Refile/Delete"
2211 ["Archive default" org-agenda-archive-default t]
2212 ["Archive default" org-agenda-archive-default-with-confirmation t]
2213 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2214 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2215 ["Archive subtree" org-agenda-archive t]
2216 "--"
2217 ["Refile" org-agenda-refile t]
2218 "--"
2219 ["Delete subtree" org-agenda-kill t])
2220 ("Bulk action"
2221 ["Mark entry" org-agenda-bulk-mark t]
2222 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2223 ["Unmark entry" org-agenda-bulk-unmark t]
2224 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
2225 ["Act on all marked" org-agenda-bulk-action t]
2226 "--"
2227 ("Tags and Properties"
2228 ["Show all Tags" org-agenda-show-tags t]
2229 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2230 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2231 "--"
2232 ["Column View" org-columns t])
2233 ("Deadline/Schedule"
2234 ["Schedule" org-agenda-schedule t]
2235 ["Set Deadline" org-agenda-deadline t]
2236 "--"
2237 ["Mark item" org-agenda-action :active t :keys "k m"]
2238 ["Show mark item" org-agenda-action :active t :keys "k v"]
2239 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2240 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2241 "--"
2242 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2243 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2244 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2245 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2246 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2247 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2248 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2249 ("Clock and Effort"
2250 ["Clock in" org-agenda-clock-in t]
2251 ["Clock out" org-agenda-clock-out t]
2252 ["Clock cancel" org-agenda-clock-cancel t]
2253 ["Goto running clock" org-clock-goto t]
2254 "--"
2255 ["Set Effort" org-agenda-set-effort t]
2256 ["Change clocked effort" org-clock-modify-effort-estimate
2257 (org-clock-is-active)])
2258 ("Priority"
2259 ["Set Priority" org-agenda-priority t]
2260 ["Increase Priority" org-agenda-priority-up t]
2261 ["Decrease Priority" org-agenda-priority-down t]
2262 ["Show Priority" org-agenda-show-priority t])
2263 ("Calendar/Diary"
2264 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2265 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2266 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2267 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2268 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2269 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2270 "--"
2271 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2272 "--"
2273 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2274 "--"
2275 ("MobileOrg"
2276 ["Push Files and Views" org-mobile-push t]
2277 ["Get Captured and Flagged" org-mobile-pull t]
2278 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2279 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2280 "--"
2281 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2282 "--"
2283 ["Quit" org-agenda-quit t]
2284 ["Exit and Release Buffers" org-agenda-exit t]
2287 ;;; Agenda undo
2289 (defvar org-agenda-allow-remote-undo t
2290 "Non-nil means allow remote undo from the agenda buffer.")
2291 (defvar org-agenda-undo-list nil
2292 "List of undoable operations in the agenda since last refresh.")
2293 (defvar org-agenda-undo-has-started-in nil
2294 "Buffers that have already seen `undo-start' in the current undo sequence.")
2295 (defvar org-agenda-pending-undo-list nil
2296 "In a series of undo commands, this is the list of remaining undo items.")
2298 (defun org-agenda-undo ()
2299 "Undo a remote editing step in the agenda.
2300 This undoes changes both in the agenda buffer and in the remote buffer
2301 that have been changed along."
2302 (interactive)
2303 (or org-agenda-allow-remote-undo
2304 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2305 (if (not (eq this-command last-command))
2306 (setq org-agenda-undo-has-started-in nil
2307 org-agenda-pending-undo-list org-agenda-undo-list))
2308 (if (not org-agenda-pending-undo-list)
2309 (error "No further undo information"))
2310 (let* ((entry (pop org-agenda-pending-undo-list))
2311 buf line cmd rembuf)
2312 (setq cmd (pop entry) line (pop entry))
2313 (setq rembuf (nth 2 entry))
2314 (org-with-remote-undo rembuf
2315 (while (bufferp (setq buf (pop entry)))
2316 (if (pop entry)
2317 (with-current-buffer buf
2318 (let ((last-undo-buffer buf)
2319 (inhibit-read-only t))
2320 (unless (memq buf org-agenda-undo-has-started-in)
2321 (push buf org-agenda-undo-has-started-in)
2322 (make-local-variable 'pending-undo-list)
2323 (undo-start))
2324 (while (and pending-undo-list
2325 (listp pending-undo-list)
2326 (not (car pending-undo-list)))
2327 (pop pending-undo-list))
2328 (undo-more 1))))))
2329 (org-goto-line line)
2330 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2332 (defun org-verify-change-for-undo (l1 l2)
2333 "Verify that a real change occurred between the undo lists L1 and L2."
2334 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2335 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2336 (not (eq l1 l2)))
2338 ;;; Agenda dispatch
2340 (defvar org-agenda-restrict nil)
2341 (defvar org-agenda-restrict-begin (make-marker))
2342 (defvar org-agenda-restrict-end (make-marker))
2343 (defvar org-agenda-last-dispatch-buffer nil)
2344 (defvar org-agenda-overriding-restriction nil)
2346 ;;;###autoload
2347 (defun org-agenda (&optional arg keys restriction)
2348 "Dispatch agenda commands to collect entries to the agenda buffer.
2349 Prompts for a command to execute. Any prefix arg will be passed
2350 on to the selected command. The default selections are:
2352 a Call `org-agenda-list' to display the agenda for current day or week.
2353 t Call `org-todo-list' to display the global todo list.
2354 T Call `org-todo-list' to display the global todo list, select only
2355 entries with a specific TODO keyword (the user gets a prompt).
2356 m Call `org-tags-view' to display headlines with tags matching
2357 a condition (the user is prompted for the condition).
2358 M Like `m', but select only TODO entries, no ordinary headlines.
2359 L Create a timeline for the current buffer.
2360 e Export views to associated files.
2361 s Search entries for keywords.
2362 / Multi occur across all agenda files and also files listed
2363 in `org-agenda-text-search-extra-files'.
2364 < Restrict agenda commands to buffer, subtree, or region.
2365 Press several times to get the desired effect.
2366 > Remove a previous restriction.
2367 # List \"stuck\" projects.
2368 ! Configure what \"stuck\" means.
2369 C Configure custom agenda commands.
2371 More commands can be added by configuring the variable
2372 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2373 searches can be pre-defined in this way.
2375 If the current buffer is in Org-mode and visiting a file, you can also
2376 first press `<' once to indicate that the agenda should be temporarily
2377 \(until the next use of \\[org-agenda]) restricted to the current file.
2378 Pressing `<' twice means to restrict to the current subtree or region
2379 \(if active)."
2380 (interactive "P")
2381 (catch 'exit
2382 (let* ((prefix-descriptions nil)
2383 (org-agenda-buffer-name org-agenda-buffer-name)
2384 (org-agenda-window-setup (if (equal (buffer-name)
2385 org-agenda-buffer-name)
2386 'current-window
2387 org-agenda-window-setup))
2388 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2389 (org-agenda-custom-commands
2390 ;; normalize different versions
2391 (delq nil
2392 (mapcar
2393 (lambda (x)
2394 (cond ((stringp (cdr x))
2395 (push x prefix-descriptions)
2396 nil)
2397 ((stringp (nth 1 x)) x)
2398 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2399 (t (cons (car x) (cons "" (cdr x))))))
2400 org-agenda-custom-commands)))
2401 (buf (current-buffer))
2402 (bfn (buffer-file-name (buffer-base-buffer)))
2403 entry key type match lprops ans)
2404 ;; Turn off restriction unless there is an overriding one,
2405 (unless org-agenda-overriding-restriction
2406 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2407 ;; There is a request to keep the file list in place
2408 (put 'org-agenda-files 'org-restrict nil))
2409 (setq org-agenda-restrict nil)
2410 (move-marker org-agenda-restrict-begin nil)
2411 (move-marker org-agenda-restrict-end nil))
2412 ;; Delete old local properties
2413 (put 'org-agenda-redo-command 'org-lprops nil)
2414 ;; Delete previously set last-arguments
2415 (put 'org-agenda-redo-command 'last-args nil)
2416 ;; Remember where this call originated
2417 (setq org-agenda-last-dispatch-buffer (current-buffer))
2418 (unless keys
2419 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2420 keys (car ans)
2421 restriction (cdr ans)))
2422 ;; If we have sticky agenda buffers, set a name for the buffer,
2423 ;; depending on the invoking keys. The user may still set this
2424 ;; as a command option, which will overwrite what we do here.
2425 (if org-agenda-sticky
2426 (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
2427 ;; Establish the restriction, if any
2428 (when (and (not org-agenda-overriding-restriction) restriction)
2429 (put 'org-agenda-files 'org-restrict (list bfn))
2430 (cond
2431 ((eq restriction 'region)
2432 (setq org-agenda-restrict t)
2433 (move-marker org-agenda-restrict-begin (region-beginning))
2434 (move-marker org-agenda-restrict-end (region-end)))
2435 ((eq restriction 'subtree)
2436 (save-excursion
2437 (setq org-agenda-restrict t)
2438 (org-back-to-heading t)
2439 (move-marker org-agenda-restrict-begin (point))
2440 (move-marker org-agenda-restrict-end
2441 (progn (org-end-of-subtree t)))))))
2443 ;; For example the todo list should not need it (but does...)
2444 (cond
2445 ((setq entry (assoc keys org-agenda-custom-commands))
2446 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2447 (progn
2448 (setq type (nth 2 entry) match (eval (nth 3 entry))
2449 lprops (nth 4 entry))
2450 (put 'org-agenda-redo-command 'org-lprops lprops)
2451 (cond
2452 ((eq type 'agenda)
2453 (org-let lprops '(org-agenda-list current-prefix-arg)))
2454 ((eq type 'alltodo)
2455 (org-let lprops '(org-todo-list current-prefix-arg)))
2456 ((eq type 'search)
2457 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2458 ((eq type 'stuck)
2459 (org-let lprops '(org-agenda-list-stuck-projects
2460 current-prefix-arg)))
2461 ((eq type 'tags)
2462 (org-let lprops '(org-tags-view current-prefix-arg match)))
2463 ((eq type 'tags-todo)
2464 (org-let lprops '(org-tags-view '(4) match)))
2465 ((eq type 'todo)
2466 (org-let lprops '(org-todo-list match)))
2467 ((eq type 'tags-tree)
2468 (org-check-for-org-mode)
2469 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2470 ((eq type 'todo-tree)
2471 (org-check-for-org-mode)
2472 (org-let lprops
2473 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2474 (regexp-quote match) "\\>"))))
2475 ((eq type 'occur-tree)
2476 (org-check-for-org-mode)
2477 (org-let lprops '(org-occur match)))
2478 ((functionp type)
2479 (org-let lprops '(funcall type match)))
2480 ((fboundp type)
2481 (org-let lprops '(funcall type match)))
2482 (t (error "Invalid custom agenda command type %s" type))))
2483 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2484 ((equal keys "C")
2485 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2486 (customize-variable 'org-agenda-custom-commands))
2487 ((equal keys "a") (call-interactively 'org-agenda-list))
2488 ((equal keys "s") (call-interactively 'org-search-view))
2489 ((equal keys "t") (call-interactively 'org-todo-list))
2490 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2491 ((equal keys "m") (call-interactively 'org-tags-view))
2492 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2493 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2494 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2495 (org-add-hook
2496 'post-command-hook
2497 (lambda ()
2498 (unless (current-message)
2499 (let* ((m (org-agenda-get-any-marker))
2500 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2501 (when note
2502 (message (concat
2503 "FLAGGING-NOTE ([?] for more info): "
2504 (org-add-props
2505 (replace-regexp-in-string
2506 "\\\\n" "//"
2507 (copy-sequence note))
2508 nil 'face 'org-warning)))))))
2509 t t))
2510 ((equal keys "L")
2511 (unless (eq major-mode 'org-mode)
2512 (error "This is not an Org-mode file"))
2513 (unless restriction
2514 (put 'org-agenda-files 'org-restrict (list bfn))
2515 (org-call-with-arg 'org-timeline arg)))
2516 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2517 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2518 ((equal keys "!") (customize-variable 'org-stuck-projects))
2519 (t (error "Invalid agenda key"))))))
2521 (defun org-agenda-append-agenda ()
2522 "Append another agenda view to the current one.
2523 This function allows interactive building of block agendas.
2524 Agenda views are separated by `org-agenda-block-separator'."
2525 (interactive)
2526 (unless (string= (buffer-name) org-agenda-buffer-name)
2527 (error "Can only append from within agenda buffer"))
2528 (let ((org-agenda-multi t))
2529 (org-agenda)
2530 (widen)))
2532 (defun org-agenda-normalize-custom-commands (cmds)
2533 (delq nil
2534 (mapcar
2535 (lambda (x)
2536 (cond ((stringp (cdr x)) nil)
2537 ((stringp (nth 1 x)) x)
2538 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2539 (t (cons (car x) (cons "" (cdr x))))))
2540 cmds)))
2542 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2543 "The user interface for selecting an agenda command."
2544 (catch 'exit
2545 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2546 (restrict-ok (and bfn (eq major-mode 'org-mode)))
2547 (region-p (org-region-active-p))
2548 (custom org-agenda-custom-commands)
2549 (selstring "")
2550 restriction second-time
2551 c entry key type match prefixes rmheader header-end custom1 desc
2552 line lines left right n n1)
2553 (save-window-excursion
2554 (delete-other-windows)
2555 (org-switch-to-buffer-other-window " *Agenda Commands*")
2556 (erase-buffer)
2557 (insert (eval-when-compile
2558 (let ((header
2560 Press key for an agenda command: < Buffer, subtree/region restriction
2561 -------------------------------- > Remove restriction
2562 a Agenda for current week or day e Export agenda views
2563 t List of all TODO entries T Entries with special TODO kwd
2564 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2565 L Timeline for current buffer # List stuck projects (!=configure)
2566 s Search for keywords C Configure custom agenda commands
2567 / Multi-occur ? Find :FLAGGED: entries
2569 (start 0))
2570 (while (string-match
2571 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2572 header start)
2573 (setq start (match-end 0))
2574 (add-text-properties (match-beginning 2) (match-end 2)
2575 '(face bold) header))
2576 header)))
2577 (setq header-end (move-marker (make-marker) (point)))
2578 (while t
2579 (setq custom1 custom)
2580 (when (eq rmheader t)
2581 (org-goto-line 1)
2582 (re-search-forward ":" nil t)
2583 (delete-region (match-end 0) (point-at-eol))
2584 (forward-char 1)
2585 (looking-at "-+")
2586 (delete-region (match-end 0) (point-at-eol))
2587 (move-marker header-end (match-end 0)))
2588 (goto-char header-end)
2589 (delete-region (point) (point-max))
2591 ;; Produce all the lines that describe custom commands and prefixes
2592 (setq lines nil)
2593 (while (setq entry (pop custom1))
2594 (setq key (car entry) desc (nth 1 entry)
2595 type (nth 2 entry)
2596 match (nth 3 entry))
2597 (if (> (length key) 1)
2598 (add-to-list 'prefixes (string-to-char key))
2599 (setq line
2600 (format
2601 "%-4s%-14s"
2602 (org-add-props (copy-sequence key)
2603 '(face bold))
2604 (cond
2605 ((string-match "\\S-" desc) desc)
2606 ((eq type 'agenda) "Agenda for current week or day")
2607 ((eq type 'alltodo) "List of all TODO entries")
2608 ((eq type 'search) "Word search")
2609 ((eq type 'stuck) "List of stuck projects")
2610 ((eq type 'todo) "TODO keyword")
2611 ((eq type 'tags) "Tags query")
2612 ((eq type 'tags-todo) "Tags (TODO)")
2613 ((eq type 'tags-tree) "Tags tree")
2614 ((eq type 'todo-tree) "TODO kwd tree")
2615 ((eq type 'occur-tree) "Occur tree")
2616 ((functionp type) (if (symbolp type)
2617 (symbol-name type)
2618 "Lambda expression"))
2619 (t "???"))))
2620 (if org-agenda-menu-show-matcher
2621 (setq line
2622 (concat line ": "
2623 (cond
2624 ((stringp match)
2625 (setq match (copy-sequence match))
2626 (org-add-props match nil 'face 'org-warning))
2627 (match
2628 (format "set of %d commands" (length match)))
2629 (t ""))))
2630 (if (org-string-nw-p match)
2631 (add-text-properties
2632 0 (length line) (list 'help-echo
2633 (concat "Matcher: "match)) line)))
2634 (push line lines)))
2635 (setq lines (nreverse lines))
2636 (when prefixes
2637 (mapc (lambda (x)
2638 (push
2639 (format "%s %s"
2640 (org-add-props (char-to-string x)
2641 nil 'face 'bold)
2642 (or (cdr (assoc (concat selstring
2643 (char-to-string x))
2644 prefix-descriptions))
2645 "Prefix key"))
2646 lines))
2647 prefixes))
2649 ;; Check if we should display in two columns
2650 (if org-agenda-menu-two-column
2651 (progn
2652 (setq n (length lines)
2653 n1 (+ (/ n 2) (mod n 2))
2654 right (nthcdr n1 lines)
2655 left (copy-sequence lines))
2656 (setcdr (nthcdr (1- n1) left) nil))
2657 (setq left lines right nil))
2658 (while left
2659 (insert "\n" (pop left))
2660 (when right
2661 (if (< (current-column) 40)
2662 (move-to-column 40 t)
2663 (insert " "))
2664 (insert (pop right))))
2666 ;; Make the window the right size
2667 (goto-char (point-min))
2668 (if second-time
2669 (if (not (pos-visible-in-window-p (point-max)))
2670 (org-fit-window-to-buffer))
2671 (setq second-time t)
2672 (org-fit-window-to-buffer))
2674 ;; Ask for selection
2675 (message "Press key for agenda command%s:"
2676 (if (or restrict-ok org-agenda-overriding-restriction)
2677 (if org-agenda-overriding-restriction
2678 " (restriction lock active)"
2679 (if restriction
2680 (format " (restricted to %s)" restriction)
2681 " (unrestricted)"))
2682 ""))
2683 (setq c (read-char-exclusive))
2684 (message "")
2685 (cond
2686 ((assoc (char-to-string c) custom)
2687 (setq selstring (concat selstring (char-to-string c)))
2688 (throw 'exit (cons selstring restriction)))
2689 ((memq c prefixes)
2690 (setq selstring (concat selstring (char-to-string c))
2691 prefixes nil
2692 rmheader (or rmheader t)
2693 custom (delq nil (mapcar
2694 (lambda (x)
2695 (if (or (= (length (car x)) 1)
2696 (/= (string-to-char (car x)) c))
2698 (cons (substring (car x) 1) (cdr x))))
2699 custom))))
2700 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2701 (message "Restriction is only possible in Org-mode buffers")
2702 (ding) (sit-for 1))
2703 ((eq c ?1)
2704 (org-agenda-remove-restriction-lock 'noupdate)
2705 (setq restriction 'buffer))
2706 ((eq c ?0)
2707 (org-agenda-remove-restriction-lock 'noupdate)
2708 (setq restriction (if region-p 'region 'subtree)))
2709 ((eq c ?<)
2710 (org-agenda-remove-restriction-lock 'noupdate)
2711 (setq restriction
2712 (cond
2713 ((eq restriction 'buffer)
2714 (if region-p 'region 'subtree))
2715 ((memq restriction '(subtree region))
2716 nil)
2717 (t 'buffer))))
2718 ((eq c ?>)
2719 (org-agenda-remove-restriction-lock 'noupdate)
2720 (setq restriction nil))
2721 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2722 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2723 ((and (> (length selstring) 0) (eq c ?\d))
2724 (delete-window)
2725 (org-agenda-get-restriction-and-command prefix-descriptions))
2727 ((equal c ?q) (error "Abort"))
2728 (t (error "Invalid key %c" c))))))))
2730 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2731 (defvar org-agenda-last-arguments nil
2732 "The arguments of the previous call to `org-agenda'.")
2733 (defun org-agenda-run-series (name series)
2734 (org-let (nth 1 series) '(org-prepare-agenda name))
2735 (let* ((org-agenda-multi t)
2736 (redo (list 'org-agenda-run-series name (list 'quote series)))
2737 (org-agenda-overriding-arguments
2738 (or org-agenda-overriding-arguments
2739 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2740 (get 'org-agenda-redo-command 'last-args))))
2741 (cmds (car series))
2742 (gprops (nth 1 series))
2743 match ;; The byte compiler incorrectly complains about this. Keep it!
2744 cmd type lprops)
2745 (while (setq cmd (pop cmds))
2746 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2747 (cond
2748 ((eq type 'agenda)
2749 (org-let2 gprops lprops
2750 '(call-interactively 'org-agenda-list)))
2751 ((eq type 'alltodo)
2752 (org-let2 gprops lprops
2753 '(call-interactively 'org-todo-list)))
2754 ((eq type 'search)
2755 (org-let2 gprops lprops
2756 '(org-search-view current-prefix-arg match nil)))
2757 ((eq type 'stuck)
2758 (org-let2 gprops lprops
2759 '(call-interactively 'org-agenda-list-stuck-projects)))
2760 ((eq type 'tags)
2761 (org-let2 gprops lprops
2762 '(org-tags-view current-prefix-arg match)))
2763 ((eq type 'tags-todo)
2764 (org-let2 gprops lprops
2765 '(org-tags-view '(4) match)))
2766 ((eq type 'todo)
2767 (org-let2 gprops lprops
2768 '(org-todo-list match)))
2769 ((fboundp type)
2770 (org-let2 gprops lprops
2771 '(funcall type match)))
2772 (t (error "Invalid type in command series"))))
2773 (widen)
2774 (setq org-agenda-redo-command redo)
2775 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2776 (goto-char (point-min)))
2777 (org-fit-agenda-window)
2778 (org-let (nth 1 series) '(org-finalize-agenda)))
2780 ;;;###autoload
2781 (defmacro org-batch-agenda (cmd-key &rest parameters)
2782 "Run an agenda command in batch mode and send the result to STDOUT.
2783 If CMD-KEY is a string of length 1, it is used as a key in
2784 `org-agenda-custom-commands' and triggers this command. If it is a
2785 longer string it is used as a tags/todo match string.
2786 Parameters are alternating variable names and values that will be bound
2787 before running the agenda command."
2788 (org-eval-in-environment (org-make-parameter-alist parameters)
2789 (if (> (length cmd-key) 2)
2790 (org-tags-view nil cmd-key)
2791 (org-agenda nil cmd-key)))
2792 (set-buffer org-agenda-buffer-name)
2793 (princ (buffer-string)))
2794 (def-edebug-spec org-batch-agenda (form &rest sexp))
2796 (defvar org-agenda-info nil)
2798 ;;;###autoload
2799 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2800 "Run an agenda command in batch mode and send the result to STDOUT.
2801 If CMD-KEY is a string of length 1, it is used as a key in
2802 `org-agenda-custom-commands' and triggers this command. If it is a
2803 longer string it is used as a tags/todo match string.
2804 Parameters are alternating variable names and values that will be bound
2805 before running the agenda command.
2807 The output gives a line for each selected agenda item. Each
2808 item is a list of comma-separated values, like this:
2810 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2812 category The category of the item
2813 head The headline, without TODO kwd, TAGS and PRIORITY
2814 type The type of the agenda entry, can be
2815 todo selected in TODO match
2816 tagsmatch selected in tags match
2817 diary imported from diary
2818 deadline a deadline on given date
2819 scheduled scheduled on given date
2820 timestamp entry has timestamp on given date
2821 closed entry was closed on given date
2822 upcoming-deadline warning about deadline
2823 past-scheduled forwarded scheduled item
2824 block entry has date block including g. date
2825 todo The todo keyword, if any
2826 tags All tags including inherited ones, separated by colons
2827 date The relevant date, like 2007-2-14
2828 time The time, like 15:00-16:50
2829 extra Sting with extra planning info
2830 priority-l The priority letter if any was given
2831 priority-n The computed numerical priority
2832 agenda-day The day in the agenda where this is listed"
2833 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2834 (org-make-parameter-alist parameters))
2835 (if (> (length cmd-key) 2)
2836 (org-tags-view nil cmd-key)
2837 (org-agenda nil cmd-key)))
2838 (set-buffer org-agenda-buffer-name)
2839 (let* ((lines (org-split-string (buffer-string) "\n"))
2840 line)
2841 (while (setq line (pop lines))
2842 (catch 'next
2843 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2844 (setq org-agenda-info
2845 (org-fix-agenda-info (text-properties-at 0 line)))
2846 (princ
2847 (mapconcat 'org-agenda-export-csv-mapper
2848 '(org-category txt type todo tags date time extra
2849 priority-letter priority agenda-day)
2850 ","))
2851 (princ "\n")))))
2852 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2854 (defun org-fix-agenda-info (props)
2855 "Make sure all properties on an agenda item have a canonical form.
2856 This ensures the export commands can easily use it."
2857 (let (tmp re)
2858 (when (setq tmp (plist-get props 'tags))
2859 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2860 (when (setq tmp (plist-get props 'date))
2861 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2862 (let ((calendar-date-display-form '(year "-" month "-" day)))
2863 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2865 (setq tmp (calendar-date-string tmp)))
2866 (setq props (plist-put props 'date tmp)))
2867 (when (setq tmp (plist-get props 'day))
2868 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2869 (let ((calendar-date-display-form '(year "-" month "-" day)))
2870 (setq tmp (calendar-date-string tmp)))
2871 (setq props (plist-put props 'day tmp))
2872 (setq props (plist-put props 'agenda-day tmp)))
2873 (when (setq tmp (plist-get props 'txt))
2874 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2875 (plist-put props 'priority-letter (match-string 1 tmp))
2876 (setq tmp (replace-match "" t t tmp)))
2877 (when (and (setq re (plist-get props 'org-todo-regexp))
2878 (setq re (concat "\\`\\.*" re " ?"))
2879 (string-match re tmp))
2880 (plist-put props 'todo (match-string 1 tmp))
2881 (setq tmp (replace-match "" t t tmp)))
2882 (plist-put props 'txt tmp)))
2883 props)
2885 (defun org-agenda-export-csv-mapper (prop)
2886 (let ((res (plist-get org-agenda-info prop)))
2887 (setq res
2888 (cond
2889 ((not res) "")
2890 ((stringp res) res)
2891 (t (prin1-to-string res))))
2892 (while (string-match "," res)
2893 (setq res (replace-match ";" t t res))) ;
2894 (org-trim res)))
2897 ;;;###autoload
2898 (defun org-store-agenda-views (&rest parameters)
2899 (interactive)
2900 (eval (list 'org-batch-store-agenda-views)))
2902 ;;;###autoload
2903 (defmacro org-batch-store-agenda-views (&rest parameters)
2904 "Run all custom agenda commands that have a file argument."
2905 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2906 (pop-up-frames nil)
2907 (dir default-directory)
2908 (pars (org-make-parameter-alist parameters))
2909 cmd thiscmdkey files opts cmd-or-set)
2910 (save-window-excursion
2911 (while cmds
2912 (setq cmd (pop cmds)
2913 thiscmdkey (car cmd)
2914 cmd-or-set (nth 2 cmd)
2915 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2916 files (nth (if (listp cmd-or-set) 4 5) cmd))
2917 (if (stringp files) (setq files (list files)))
2918 (when files
2919 (org-eval-in-environment (append org-agenda-exporter-settings
2920 opts pars)
2921 (org-agenda nil thiscmdkey))
2922 (set-buffer org-agenda-buffer-name)
2923 (while files
2924 (org-eval-in-environment (append org-agenda-exporter-settings
2925 opts pars)
2926 (org-agenda-write (expand-file-name (pop files) dir) nil t)))
2927 (and (get-buffer org-agenda-buffer-name)
2928 (kill-buffer org-agenda-buffer-name)))))))
2929 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2931 (defun org-agenda-mark-header-line (pos)
2932 "Mark the line at POS as an agenda structure header."
2933 (save-excursion
2934 (goto-char pos)
2935 (put-text-property (point-at-bol) (point-at-eol)
2936 'org-agenda-structural-header t)
2937 (when org-agenda-title-append
2938 (put-text-property (point-at-bol) (point-at-eol)
2939 'org-agenda-title-append org-agenda-title-append))))
2941 (defvar org-mobile-creating-agendas)
2942 (defvar org-agenda-write-buffer-name "Agenda View")
2943 (defun org-agenda-write (file &optional open nosettings)
2944 "Write the current buffer (an agenda view) as a file.
2945 Depending on the extension of the file name, plain text (.txt),
2946 HTML (.html or .htm) or Postscript (.ps) is produced.
2947 If the extension is .ics, run icalendar export over all files used
2948 to construct the agenda and limit the export to entries listed in the
2949 agenda now.
2950 With prefix argument OPEN, open the new file immediately.
2951 If NOSETTINGS is given, do not scope the settings of
2952 `org-agenda-exporter-settings' into the export commands. This is used when
2953 the settings have already been scoped and we do not wish to overrule other,
2954 higher priority settings."
2955 (interactive "FWrite agenda to file: \nP")
2956 (if (not (file-writable-p file))
2957 (error "Cannot write agenda to file %s" file))
2958 (org-let (if nosettings nil org-agenda-exporter-settings)
2959 '(save-excursion
2960 (save-window-excursion
2961 (org-agenda-mark-filtered-text)
2962 (let ((bs (copy-sequence (buffer-string))) beg)
2963 (org-agenda-unmark-filtered-text)
2964 (with-temp-buffer
2965 (rename-buffer org-agenda-write-buffer-name t)
2966 (set-buffer-modified-p nil)
2967 (insert bs)
2968 (org-agenda-remove-marked-text 'org-filtered)
2969 (while (setq beg (text-property-any (point-min) (point-max)
2970 'org-filtered t))
2971 (delete-region
2972 beg (or (next-single-property-change beg 'org-filtered)
2973 (point-max))))
2974 (run-hooks 'org-agenda-before-write-hook)
2975 (cond
2976 ((org-bound-and-true-p org-mobile-creating-agendas)
2977 (org-mobile-write-agenda-for-mobile file))
2978 ((string-match "\\.html?\\'" file)
2979 (require 'htmlize)
2980 (set-buffer (htmlize-buffer (current-buffer)))
2982 (when (and org-agenda-export-html-style
2983 (string-match "<style>" org-agenda-export-html-style))
2984 ;; replace <style> section with org-agenda-export-html-style
2985 (goto-char (point-min))
2986 (kill-region (- (search-forward "<style") 6)
2987 (search-forward "</style>"))
2988 (insert org-agenda-export-html-style))
2989 (write-file file)
2990 (kill-buffer (current-buffer))
2991 (message "HTML written to %s" file))
2992 ((string-match "\\.ps\\'" file)
2993 (require 'ps-print)
2994 (ps-print-buffer-with-faces file)
2995 (message "Postscript written to %s" file))
2996 ((string-match "\\.pdf\\'" file)
2997 (require 'ps-print)
2998 (ps-print-buffer-with-faces
2999 (concat (file-name-sans-extension file) ".ps"))
3000 (call-process "ps2pdf" nil nil nil
3001 (expand-file-name
3002 (concat (file-name-sans-extension file) ".ps"))
3003 (expand-file-name file))
3004 (delete-file (concat (file-name-sans-extension file) ".ps"))
3005 (message "PDF written to %s" file))
3006 ((string-match "\\.ics\\'" file)
3007 (require 'org-icalendar)
3008 (let ((org-agenda-marker-table
3009 (org-create-marker-find-array
3010 (org-agenda-collect-markers)))
3011 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3012 (org-combined-agenda-icalendar-file file))
3013 (apply 'org-export-icalendar 'combine
3014 (org-agenda-files nil 'ifmode))))
3016 (let ((bs (buffer-string)))
3017 (find-file file)
3018 (erase-buffer)
3019 (insert bs)
3020 (save-buffer 0)
3021 (kill-buffer (current-buffer))
3022 (message "Plain text written to %s" file))))))))
3023 (set-buffer org-agenda-buffer-name))
3024 (when open (org-open-file file)))
3026 (defvar org-agenda-tag-filter-overlays nil)
3027 (defvar org-agenda-cat-filter-overlays nil)
3029 (defun org-agenda-mark-filtered-text ()
3030 "Mark all text hidden by filtering with a text property."
3031 (let ((inhibit-read-only t))
3032 (mapc
3033 (lambda (o)
3034 (when (equal (overlay-buffer o) (current-buffer))
3035 (put-text-property
3036 (overlay-start o) (overlay-end o)
3037 'org-filtered t)))
3038 (append org-agenda-tag-filter-overlays
3039 org-agenda-cat-filter-overlays))))
3041 (defun org-agenda-unmark-filtered-text ()
3042 "Remove the filtering text property."
3043 (let ((inhibit-read-only t))
3044 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3046 (defun org-agenda-remove-marked-text (property &optional value)
3047 "Delete all text marked with VALUE of PROPERTY.
3048 VALUE defaults to t."
3049 (let (beg)
3050 (setq value (or value t))
3051 (while (setq beg (text-property-any (point-min) (point-max)
3052 property value))
3053 (delete-region
3054 beg (or (next-single-property-change beg 'org-filtered)
3055 (point-max))))))
3057 (defun org-agenda-add-entry-text ()
3058 "Add entry text to agenda lines.
3059 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3060 entry text following headings shown in the agenda.
3061 Drawers will be excluded, also the line with scheduling/deadline info."
3062 (when (and (> org-agenda-add-entry-text-maxlines 0)
3063 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3064 (let (m txt)
3065 (goto-char (point-min))
3066 (while (not (eobp))
3067 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3068 (beginning-of-line 2)
3069 (setq txt (org-agenda-get-some-entry-text
3070 m org-agenda-add-entry-text-maxlines " > "))
3071 (end-of-line 1)
3072 (if (string-match "\\S-" txt)
3073 (insert "\n" txt)
3074 (or (eobp) (forward-char 1))))))))
3076 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3077 &rest keep)
3078 "Extract entry text from MARKER, at most N-LINES lines.
3079 This will ignore drawers etc, just get the text.
3080 If INDENT is given, prefix every line with this string. If KEEP is
3081 given, it is a list of symbols, defining stuff that should not be
3082 removed from the entry content. Currently only `planning' is allowed here."
3083 (let (txt drawer-re kwd-time-re ind)
3084 (save-excursion
3085 (with-current-buffer (marker-buffer marker)
3086 (if (not (eq major-mode 'org-mode))
3087 (setq txt "")
3088 (save-excursion
3089 (save-restriction
3090 (widen)
3091 (goto-char marker)
3092 (end-of-line 1)
3093 (setq txt (buffer-substring
3094 (min (1+ (point)) (point-max))
3095 (progn (outline-next-heading) (point)))
3096 drawer-re org-drawer-regexp
3097 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3098 ".*\n?"))
3099 (with-temp-buffer
3100 (insert txt)
3101 (when org-agenda-add-entry-text-descriptive-links
3102 (goto-char (point-min))
3103 (while (org-activate-bracket-links (point-max))
3104 (add-text-properties (match-beginning 0) (match-end 0)
3105 '(face org-link))))
3106 (goto-char (point-min))
3107 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3108 (set-text-properties (match-beginning 0) (match-end 0)
3109 nil))
3110 (goto-char (point-min))
3111 (while (re-search-forward drawer-re nil t)
3112 (delete-region
3113 (match-beginning 0)
3114 (progn (re-search-forward
3115 "^[ \t]*:END:.*\n?" nil 'move)
3116 (point))))
3117 (unless (member 'planning keep)
3118 (goto-char (point-min))
3119 (while (re-search-forward kwd-time-re nil t)
3120 (replace-match "")))
3121 (goto-char (point-min))
3122 (when org-agenda-entry-text-exclude-regexps
3123 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3124 (while (setq re (pop re-list))
3125 (goto-char (point-min))
3126 (while (re-search-forward re nil t)
3127 (replace-match "")))))
3128 (goto-char (point-max))
3129 (skip-chars-backward " \t\n")
3130 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3132 ;; find and remove min common indentation
3133 (goto-char (point-min))
3134 (untabify (point-min) (point-max))
3135 (setq ind (org-get-indentation))
3136 (while (not (eobp))
3137 (unless (looking-at "[ \t]*$")
3138 (setq ind (min ind (org-get-indentation))))
3139 (beginning-of-line 2))
3140 (goto-char (point-min))
3141 (while (not (eobp))
3142 (unless (looking-at "[ \t]*$")
3143 (move-to-column ind)
3144 (delete-region (point-at-bol) (point)))
3145 (beginning-of-line 2))
3147 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3149 (goto-char (point-min))
3150 (when indent
3151 (while (and (not (eobp)) (re-search-forward "^" nil t))
3152 (replace-match indent t t)))
3153 (goto-char (point-min))
3154 (while (looking-at "[ \t]*\n") (replace-match ""))
3155 (goto-char (point-max))
3156 (when (> (org-current-line)
3157 n-lines)
3158 (org-goto-line (1+ n-lines))
3159 (backward-char 1))
3160 (setq txt (buffer-substring (point-min) (point)))))))))
3161 txt))
3163 (defun org-agenda-collect-markers ()
3164 "Collect the markers pointing to entries in the agenda buffer."
3165 (let (m markers)
3166 (save-excursion
3167 (goto-char (point-min))
3168 (while (not (eobp))
3169 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3170 (org-get-at-bol 'org-marker)))
3171 (push m markers))
3172 (beginning-of-line 2)))
3173 (nreverse markers)))
3175 (defun org-create-marker-find-array (marker-list)
3176 "Create a alist of files names with all marker positions in that file."
3177 (let (f tbl m a p)
3178 (while (setq m (pop marker-list))
3179 (setq p (marker-position m)
3180 f (buffer-file-name (or (buffer-base-buffer
3181 (marker-buffer m))
3182 (marker-buffer m))))
3183 (if (setq a (assoc f tbl))
3184 (push (marker-position m) (cdr a))
3185 (push (list f p) tbl)))
3186 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3187 tbl)))
3189 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3190 (defun org-check-agenda-marker-table ()
3191 "Check of the current entry is on the marker list."
3192 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3194 (and (setq a (assoc file org-agenda-marker-table))
3195 (save-match-data
3196 (save-excursion
3197 (org-back-to-heading t)
3198 (member (point) (cdr a)))))))
3200 (defun org-check-for-org-mode ()
3201 "Make sure current buffer is in org-mode. Error if not."
3202 (or (eq major-mode 'org-mode)
3203 (error "Cannot execute org-mode agenda command on buffer in %s"
3204 major-mode)))
3206 (defun org-fit-agenda-window ()
3207 "Fit the window to the buffer size."
3208 (and (memq org-agenda-window-setup '(reorganize-frame))
3209 (fboundp 'fit-window-to-buffer)
3210 (org-fit-window-to-buffer
3212 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3213 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3215 ;;; Agenda prepare and finalize
3217 (defvar org-agenda-multi nil) ; dynamically scoped
3218 (defvar org-agenda-buffer-name "*Org Agenda*")
3219 (defvar org-pre-agenda-window-conf nil)
3220 (defvar org-agenda-columns-active nil)
3221 (defvar org-agenda-name nil)
3222 (defvar org-agenda-tag-filter nil)
3223 (defvar org-agenda-category-filter nil)
3224 (defvar org-agenda-tag-filter-while-redo nil)
3225 (defvar org-agenda-tag-filter-preset nil
3226 "A preset of the tags filter used for secondary agenda filtering.
3227 This must be a list of strings, each string must be a single tag preceded
3228 by \"+\" or \"-\".
3229 This variable should not be set directly, but agenda custom commands can
3230 bind it in the options section. The preset filter is a global property of
3231 the entire agenda view. In a block agenda, it will not work reliably to
3232 define a filter for one of the individual blocks. You need to set it in
3233 the global options and expect it to be applied to the entire view.")
3235 (defvar org-agenda-category-filter-preset nil
3236 "A preset of the category filter used for secondary agenda filtering.
3237 This must be a list of strings, each string must be a single category
3238 preceded by \"+\" or \"-\".
3239 This variable should not be set directly, but agenda custom commands can
3240 bind it in the options section. The preset filter is a global property of
3241 the entire agenda view. In a block agenda, it will not work reliably to
3242 define a filter for one of the individual blocks. You need to set it in
3243 the global options and expect it to be applied to the entire view.")
3246 (defun org-agenda-use-sticky-p ()
3247 "Return non-NIL if existing agenda buffer named
3248 `org-agenda-buffer-name' exists, and should be shown instead of
3249 generating a new one"
3250 (and
3251 ;; turned off by user
3252 org-agenda-sticky
3253 ;; For multi-agenda buffer already exists
3254 (not org-agenda-multi)
3255 ;; buffer found
3256 (get-buffer org-agenda-buffer-name)
3257 ;; C-u parameter is same as last call
3258 (with-current-buffer (get-buffer org-agenda-buffer-name)
3259 (and
3260 (equal current-prefix-arg
3261 org-agenda-last-prefix-arg)
3262 ;; In case user turned stickiness on, while having existing
3263 ;; Agenda buffer active, don't reuse that buffer, because it
3264 ;; does not have org variables local
3265 org-agenda-this-buffer-is-sticky))))
3267 (defun org-prepare-agenda-window (abuf)
3268 "Setup agenda buffer in the window"
3269 (let* ((awin (get-buffer-window abuf)))
3270 (cond
3271 ((equal (current-buffer) abuf) nil)
3272 (awin (select-window awin))
3273 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
3274 ((equal org-agenda-window-setup 'current-window)
3275 (org-pop-to-buffer-same-window abuf))
3276 ((equal org-agenda-window-setup 'other-window)
3277 (org-switch-to-buffer-other-window abuf))
3278 ((equal org-agenda-window-setup 'other-frame)
3279 (switch-to-buffer-other-frame abuf))
3280 ((equal org-agenda-window-setup 'reorganize-frame)
3281 (delete-other-windows)
3282 (org-switch-to-buffer-other-window abuf)))
3283 ;; additional test in case agenda is invoked from within agenda
3284 ;; buffer via elisp link
3285 (unless (equal (current-buffer) abuf)
3286 (org-pop-to-buffer-same-window abuf))))
3288 (defun org-prepare-agenda (&optional name)
3289 (if (org-agenda-use-sticky-p)
3290 (progn
3291 ;; Popup existing buffer
3292 (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
3293 (message
3294 "Sticky Agenda buffer, use `r' to refresh")
3295 (throw 'exit nil))
3296 (setq org-todo-keywords-for-agenda nil)
3297 (setq org-done-keywords-for-agenda nil)
3298 (setq org-drawers-for-agenda nil)
3299 (unless org-agenda-persistent-filter
3300 (setq org-agenda-tag-filter nil
3301 org-agenda-category-filter nil))
3302 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3303 (put 'org-agenda-category-filter :preset-filter org-agenda-category-filter-preset)
3304 (if org-agenda-multi
3305 (progn
3306 (setq buffer-read-only nil)
3307 (goto-char (point-max))
3308 (unless (or (bobp) org-agenda-compact-blocks
3309 (not org-agenda-block-separator))
3310 (insert "\n"
3311 (if (stringp org-agenda-block-separator)
3312 org-agenda-block-separator
3313 (make-string (window-width) org-agenda-block-separator))
3314 "\n"))
3315 (narrow-to-region (point) (point-max)))
3317 ;; any org variables need to be set after being in agenda buffer
3318 ;; since they are now buffer local
3319 (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
3320 (setq buffer-read-only nil)
3321 (let ((inhibit-read-only t)) (erase-buffer))
3322 (org-agenda-mode)
3323 (setq org-agenda-buffer (current-buffer))
3324 (org-agenda-reset-markers)
3325 (setq org-agenda-contributing-files nil)
3326 (setq org-agenda-columns-active nil)
3327 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3328 (setq org-todo-keywords-for-agenda
3329 (org-uniquify org-todo-keywords-for-agenda))
3330 (setq org-done-keywords-for-agenda
3331 (org-uniquify org-done-keywords-for-agenda))
3332 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3333 (setq org-agenda-last-prefix-arg current-prefix-arg)
3334 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3335 (and name (not org-agenda-name)
3336 (org-set-local 'org-agenda-name name)))
3337 (setq buffer-read-only nil)))
3339 (defun org-finalize-agenda ()
3340 "Finishing touch for the agenda buffer, called just before displaying it."
3341 (unless org-agenda-multi
3342 (save-excursion
3343 (let ((inhibit-read-only t))
3344 (goto-char (point-min))
3345 (while (org-activate-bracket-links (point-max))
3346 (add-text-properties (match-beginning 0) (match-end 0)
3347 '(face org-link)))
3348 (org-agenda-align-tags)
3349 (unless org-agenda-with-colors
3350 (remove-text-properties (point-min) (point-max) '(face nil))))
3351 (if (and (boundp 'org-agenda-overriding-columns-format)
3352 org-agenda-overriding-columns-format)
3353 (org-set-local 'org-agenda-overriding-columns-format
3354 org-agenda-overriding-columns-format))
3355 (if (and (boundp 'org-agenda-view-columns-initially)
3356 org-agenda-view-columns-initially)
3357 (org-agenda-columns))
3358 (when org-agenda-fontify-priorities
3359 (org-agenda-fontify-priorities))
3360 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3361 (org-agenda-dim-blocked-tasks))
3362 (org-agenda-mark-clocking-task)
3363 (when org-agenda-entry-text-mode
3364 (org-agenda-entry-text-hide)
3365 (org-agenda-entry-text-show))
3366 (if (functionp 'org-habit-insert-consistency-graphs)
3367 (org-habit-insert-consistency-graphs))
3368 (run-hooks 'org-finalize-agenda-hook)
3369 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3370 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3371 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3372 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3373 (org-agenda-filter-apply org-agenda-category-filter 'category))
3376 (defun org-agenda-mark-clocking-task ()
3377 "Mark the current clock entry in the agenda if it is present."
3378 (mapc (lambda (o)
3379 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3380 (delete-overlay o)))
3381 (overlays-in (point-min) (point-max)))
3382 (when (marker-buffer org-clock-hd-marker)
3383 (save-excursion
3384 (goto-char (point-min))
3385 (let (s ov)
3386 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3387 (goto-char s)
3388 (when (equal (org-get-at-bol 'org-hd-marker)
3389 org-clock-hd-marker)
3390 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3391 (overlay-put ov 'type 'org-agenda-clocking)
3392 (overlay-put ov 'face 'org-agenda-clocking)
3393 (overlay-put ov 'help-echo
3394 "The clock is running in this item")))))))
3396 (defun org-agenda-fontify-priorities ()
3397 "Make highest priority lines bold, and lowest italic."
3398 (interactive)
3399 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3400 (delete-overlay o)))
3401 (overlays-in (point-min) (point-max)))
3402 (save-excursion
3403 (let ((inhibit-read-only t)
3404 b e p ov h l)
3405 (goto-char (point-min))
3406 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3407 (setq h (or (get-char-property (point) 'org-highest-priority)
3408 org-highest-priority)
3409 l (or (get-char-property (point) 'org-lowest-priority)
3410 org-lowest-priority)
3411 p (string-to-char (match-string 1))
3412 b (match-beginning 0)
3413 e (if (eq org-agenda-fontify-priorities 'cookies)
3414 (match-end 0)
3415 (point-at-eol))
3416 ov (make-overlay b e))
3417 (overlay-put
3418 ov 'face
3419 (cond ((org-face-from-face-or-color
3420 'priority nil
3421 (cdr (assoc p org-priority-faces))))
3422 ((and (listp org-agenda-fontify-priorities)
3423 (org-face-from-face-or-color
3424 'priority nil
3425 (cdr (assoc p org-agenda-fontify-priorities)))))
3426 ((equal p l) 'italic)
3427 ((equal p h) 'bold)))
3428 (overlay-put ov 'org-type 'org-priority)))))
3430 (defun org-agenda-dim-blocked-tasks ()
3431 "Dim currently blocked TODO's in the agenda display."
3432 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3433 (delete-overlay o)))
3434 (overlays-in (point-min) (point-max)))
3435 (save-excursion
3436 (let ((inhibit-read-only t)
3437 (org-depend-tag-blocked nil)
3438 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3439 org-blocked-by-checkboxes
3440 invis1 b e p ov h l)
3441 (goto-char (point-min))
3442 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3443 (and pos (goto-char (1+ pos))))
3444 (setq org-blocked-by-checkboxes nil invis1 invis)
3445 (let ((marker (org-get-at-bol 'org-hd-marker)))
3446 (when (and marker
3447 (with-current-buffer (marker-buffer marker)
3448 (save-excursion (goto-char marker)
3449 (org-entry-blocked-p))))
3450 (if org-blocked-by-checkboxes (setq invis1 nil))
3451 (setq b (if invis1
3452 (max (point-min) (1- (point-at-bol)))
3453 (point-at-bol))
3454 e (point-at-eol)
3455 ov (make-overlay b e))
3456 (if invis1
3457 (overlay-put ov 'invisible t)
3458 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3459 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3461 (defvar org-agenda-skip-function nil
3462 "Function to be called at each match during agenda construction.
3463 If this function returns nil, the current match should not be skipped.
3464 Otherwise, the function must return a position from where the search
3465 should be continued.
3466 This may also be a Lisp form, it will be evaluated.
3467 Never set this variable using `setq' or so, because then it will apply
3468 to all future agenda commands. If you do want a global skipping condition,
3469 use the option `org-agenda-skip-function-global' instead.
3470 The correct usage for `org-agenda-skip-function' is to bind it with
3471 `let' to scope it dynamically into the agenda-constructing command.
3472 A good way to set it is through options in `org-agenda-custom-commands'.")
3474 (defun org-agenda-skip ()
3475 "Throw to `:skip' in places that should be skipped.
3476 Also moves point to the end of the skipped region, so that search can
3477 continue from there."
3478 (let ((p (point-at-bol)) to)
3479 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3480 (get-text-property p :org-archived)
3481 (org-end-of-subtree t)
3482 (throw :skip t))
3483 (and org-agenda-skip-comment-trees
3484 (get-text-property p :org-comment)
3485 (org-end-of-subtree t)
3486 (throw :skip t))
3487 (if (equal (char-after p) ?#) (throw :skip t))
3488 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3489 (org-agenda-skip-eval org-agenda-skip-function)))
3490 (goto-char to)
3491 (throw :skip t))))
3493 (defun org-agenda-skip-eval (form)
3494 "If FORM is a function or a list, call (or eval) is and return result.
3495 `save-excursion' and `save-match-data' are wrapped around the call, so point
3496 and match data are returned to the previous state no matter what these
3497 functions do."
3498 (let (fp)
3499 (and form
3500 (or (setq fp (functionp form))
3501 (consp form))
3502 (save-excursion
3503 (save-match-data
3504 (if fp
3505 (funcall form)
3506 (eval form)))))))
3508 (defvar org-agenda-markers nil
3509 "List of all currently active markers created by `org-agenda'.")
3510 (defvar org-agenda-last-marker-time (org-float-time)
3511 "Creation time of the last agenda marker.")
3513 (defun org-agenda-new-marker (&optional pos)
3514 "Return a new agenda marker.
3515 Org-mode keeps a list of these markers and resets them when they are
3516 no longer in use."
3517 (let ((m (copy-marker (or pos (point)))))
3518 (setq org-agenda-last-marker-time (org-float-time))
3519 (with-current-buffer org-agenda-buffer
3520 (push m org-agenda-markers))
3523 (defun org-agenda-reset-markers ()
3524 "Reset markers created by `org-agenda'."
3525 (while org-agenda-markers
3526 (move-marker (pop org-agenda-markers) nil)))
3528 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3529 "Save relative positions of markers in region."
3530 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3531 org-agenda-markers))
3533 ;;; Entry text mode
3535 (defun org-agenda-entry-text-show-here ()
3536 "Add some text from the entry as context to the current line."
3537 (let (m txt o)
3538 (setq m (org-get-at-bol 'org-hd-marker))
3539 (unless (marker-buffer m)
3540 (error "No marker points to an entry here"))
3541 (setq txt (concat "\n" (org-no-properties
3542 (org-agenda-get-some-entry-text
3543 m org-agenda-entry-text-maxlines " > "))))
3544 (when (string-match "\\S-" txt)
3545 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3546 (overlay-put o 'evaporate t)
3547 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3548 (overlay-put o 'after-string txt))))
3550 (defun org-agenda-entry-text-show ()
3551 "Add entry context for all agenda lines."
3552 (interactive)
3553 (save-excursion
3554 (goto-char (point-max))
3555 (beginning-of-line 1)
3556 (while (not (bobp))
3557 (when (org-get-at-bol 'org-hd-marker)
3558 (org-agenda-entry-text-show-here))
3559 (beginning-of-line 0))))
3561 (defun org-agenda-entry-text-hide ()
3562 "Remove any shown entry context."
3563 (delq nil
3564 (mapcar (lambda (o)
3565 (if (eq (overlay-get o 'org-overlay-type)
3566 'agenda-entry-content)
3567 (progn (delete-overlay o) t)))
3568 (overlays-in (point-min) (point-max)))))
3570 (defun org-agenda-get-day-face (date)
3571 "Return the face DATE should be displayed with."
3572 (or (and (functionp org-agenda-day-face-function)
3573 (funcall org-agenda-day-face-function date))
3574 (cond ((org-agenda-todayp date)
3575 'org-agenda-date-today)
3576 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3577 'org-agenda-date-weekend)
3578 (t 'org-agenda-date))))
3580 ;;; Agenda timeline
3582 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3584 (defun org-timeline (&optional dotodo)
3585 "Show a time-sorted view of the entries in the current org file.
3586 Only entries with a time stamp of today or later will be listed. With
3587 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3588 under the current date.
3589 If the buffer contains an active region, only check the region for
3590 dates."
3591 (interactive "P")
3592 (let* ((dopast t)
3593 (doclosed org-agenda-show-log)
3594 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3595 (current-buffer))))
3596 (date (calendar-current-date))
3597 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3598 (end (if (org-region-active-p) (region-end) (point-max)))
3599 (day-numbers (org-get-all-dates beg end 'no-ranges
3600 t doclosed ; always include today
3601 org-timeline-show-empty-dates))
3602 (org-deadline-warning-days 0)
3603 (org-agenda-only-exact-dates t)
3604 (today (org-today))
3605 (past t)
3606 args
3607 s e rtn d emptyp)
3608 (setq org-agenda-redo-command
3609 (list 'progn
3610 (list 'org-switch-to-buffer-other-window (current-buffer))
3611 (list 'org-timeline (list 'quote dotodo))))
3612 (if (not dopast)
3613 ;; Remove past dates from the list of dates.
3614 (setq day-numbers (delq nil (mapcar (lambda(x)
3615 (if (>= x today) x nil))
3616 day-numbers))))
3617 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3618 (org-compile-prefix-format 'timeline)
3619 (org-set-sorting-strategy 'timeline)
3620 (if doclosed (push :closed args))
3621 (push :timestamp args)
3622 (push :deadline args)
3623 (push :scheduled args)
3624 (push :sexp args)
3625 (if dotodo (push :todo args))
3626 (insert "Timeline of file " entry "\n")
3627 (add-text-properties (point-min) (point)
3628 (list 'face 'org-agenda-structure))
3629 (org-agenda-mark-header-line (point-min))
3630 (while (setq d (pop day-numbers))
3631 (if (and (listp d) (eq (car d) :omitted))
3632 (progn
3633 (setq s (point))
3634 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3635 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3636 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3637 (if (and (>= d today)
3638 dopast
3639 past)
3640 (progn
3641 (setq past nil)
3642 (insert (make-string 79 ?-) "\n")))
3643 (setq date (calendar-gregorian-from-absolute d))
3644 (setq s (point))
3645 (setq rtn (and (not emptyp)
3646 (apply 'org-agenda-get-day-entries entry
3647 date args)))
3648 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3649 (progn
3650 (insert
3651 (if (stringp org-agenda-format-date)
3652 (format-time-string org-agenda-format-date
3653 (org-time-from-absolute date))
3654 (funcall org-agenda-format-date date))
3655 "\n")
3656 (put-text-property s (1- (point)) 'face
3657 (org-agenda-get-day-face date))
3658 (put-text-property s (1- (point)) 'org-date-line t)
3659 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3660 (if (equal d today)
3661 (put-text-property s (1- (point)) 'org-today t))
3662 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3663 (put-text-property s (1- (point)) 'day d)))))
3664 (goto-char (point-min))
3665 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3666 (point-min)))
3667 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3668 (org-finalize-agenda)
3669 (setq buffer-read-only t)))
3671 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3672 "Return a list of all relevant day numbers from BEG to END buffer positions.
3673 If NO-RANGES is non-nil, include only the start and end dates of a range,
3674 not every single day in the range. If FORCE-TODAY is non-nil, make
3675 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3676 inactive time stamps (those in square brackets) are included.
3677 When EMPTY is non-nil, also include days without any entries."
3678 (let ((re (concat
3679 (if pre-re pre-re "")
3680 (if inactive org-ts-regexp-both org-ts-regexp)))
3681 dates dates1 date day day1 day2 ts1 ts2 pos)
3682 (if force-today
3683 (setq dates (list (org-today))))
3684 (save-excursion
3685 (goto-char beg)
3686 (while (re-search-forward re end t)
3687 (setq day (time-to-days (org-time-string-to-time
3688 (substring (match-string 1) 0 10)
3689 (current-buffer) (match-beginning 0))))
3690 (or (memq day dates) (push day dates)))
3691 (unless no-ranges
3692 (goto-char beg)
3693 (while (re-search-forward org-tr-regexp end t)
3694 (setq pos (match-beginning 0))
3695 (setq ts1 (substring (match-string 1) 0 10)
3696 ts2 (substring (match-string 2) 0 10)
3697 day1 (time-to-days (org-time-string-to-time
3698 ts1 (current-buffer) pos))
3699 day2 (time-to-days (org-time-string-to-time
3700 ts2 (current-buffer) pos)))
3701 (while (< (setq day1 (1+ day1)) day2)
3702 (or (memq day1 dates) (push day1 dates)))))
3703 (setq dates (sort dates '<))
3704 (when empty
3705 (while (setq day (pop dates))
3706 (setq day2 (car dates))
3707 (push day dates1)
3708 (when (and day2 empty)
3709 (if (or (eq empty t)
3710 (and (numberp empty) (<= (- day2 day) empty)))
3711 (while (< (setq day (1+ day)) day2)
3712 (push (list day) dates1))
3713 (push (cons :omitted (- day2 day)) dates1))))
3714 (setq dates (nreverse dates1)))
3715 dates)))
3717 ;;; Agenda Daily/Weekly
3719 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3720 "Start day for the agenda view.
3721 Custom commands can set this variable in the options section.")
3722 (defvar org-starting-day nil) ; local variable in the agenda buffer
3723 (defvar org-agenda-current-span nil
3724 "The current span used in the agenda view.") ; local variable in the agenda buffer
3725 (defvar org-arg-loc nil) ; local variable
3727 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3728 "List of types searched for when creating the daily/weekly agenda.
3729 This variable is a list of symbols that controls the types of
3730 items that appear in the daily/weekly agenda. Allowed symbols in this
3731 list are are
3733 :timestamp List items containing a date stamp or date range matching
3734 the selected date. This includes sexp entries in
3735 angular brackets.
3737 :sexp List entries resulting from plain diary-like sexps.
3739 :deadline List deadline due on that date. When the date is today,
3740 also list any deadlines past due, or due within
3741 `org-deadline-warning-days'. `:deadline' must appear before
3742 `:scheduled' if the setting of
3743 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3744 any effect.
3746 :scheduled List all items which are scheduled for the given date.
3747 The diary for *today* also contains items which were
3748 scheduled earlier and are not yet marked DONE.
3750 By default, all four types are turned on.
3752 Never set this variable globally using `setq', because then it
3753 will apply to all future agenda commands. Instead, bind it with
3754 `let' to scope it dynamically into the agenda-constructing
3755 command. A good way to set it is through options in
3756 `org-agenda-custom-commands'. For a more flexible (though
3757 somewhat less efficient) way of determining what is included in
3758 the daily/weekly agenda, see `org-agenda-skip-function'.")
3760 ;;;###autoload
3761 (defun org-agenda-list (&optional arg start-day span)
3762 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3763 The view will be for the current day or week, but from the overview buffer
3764 you will be able to go to other days/weeks.
3766 With a numeric prefix argument in an interactive call, the agenda will
3767 span ARG days. Lisp programs should instead specify SPAN to change
3768 the number of days. SPAN defaults to `org-agenda-span'.
3770 START-DAY defaults to TODAY, or to the most recent match for the weekday
3771 given in `org-agenda-start-on-weekday'."
3772 (interactive "P")
3773 (if (and (integerp arg) (> arg 0))
3774 (setq span arg arg nil))
3775 (org-prepare-agenda "Day/Week")
3776 (setq start-day (or start-day org-agenda-start-day))
3777 (if org-agenda-overriding-arguments
3778 (setq arg (car org-agenda-overriding-arguments)
3779 start-day (nth 1 org-agenda-overriding-arguments)
3780 span (nth 2 org-agenda-overriding-arguments)))
3781 (if (stringp start-day)
3782 ;; Convert to an absolute day number
3783 (setq start-day (time-to-days (org-read-date nil t start-day))))
3784 (setq org-agenda-last-arguments (list arg start-day span))
3785 (org-compile-prefix-format 'agenda)
3786 (org-set-sorting-strategy 'agenda)
3787 (let* ((span (org-agenda-ndays-to-span
3788 (or span org-agenda-ndays org-agenda-span)))
3789 (today (org-today))
3790 (sd (or start-day today))
3791 (ndays (org-agenda-span-to-ndays span sd))
3792 (org-agenda-start-on-weekday
3793 (if (eq ndays 7)
3794 org-agenda-start-on-weekday))
3795 (thefiles (org-agenda-files nil 'ifmode))
3796 (files thefiles)
3797 (start (if (or (null org-agenda-start-on-weekday)
3798 (< ndays 7))
3800 (let* ((nt (calendar-day-of-week
3801 (calendar-gregorian-from-absolute sd)))
3802 (n1 org-agenda-start-on-weekday)
3803 (d (- nt n1)))
3804 (- sd (+ (if (< d 0) 7 0) d)))))
3805 (day-numbers (list start))
3806 (day-cnt 0)
3807 (inhibit-redisplay (not debug-on-error))
3808 s e rtn rtnall file date d start-pos end-pos todayp
3809 clocktable-start clocktable-end filter)
3810 (setq org-agenda-redo-command
3811 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3812 (dotimes (n (1- ndays))
3813 (push (1+ (car day-numbers)) day-numbers))
3814 (setq day-numbers (nreverse day-numbers))
3815 (setq clocktable-start (car day-numbers)
3816 clocktable-end (1+ (or (org-last day-numbers) 0)))
3817 (org-set-local 'org-starting-day (car day-numbers))
3818 (org-set-local 'org-arg-loc arg)
3819 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3820 (unless org-agenda-compact-blocks
3821 (let* ((d1 (car day-numbers))
3822 (d2 (org-last day-numbers))
3823 (w1 (org-days-to-iso-week d1))
3824 (w2 (org-days-to-iso-week d2)))
3825 (setq s (point))
3826 (if org-agenda-overriding-header
3827 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3828 nil 'face 'org-agenda-structure) "\n")
3829 (insert (org-agenda-span-name span)
3830 "-agenda"
3831 (if (< (- d2 d1) 350)
3832 (if (= w1 w2)
3833 (format " (W%02d)" w1)
3834 (format " (W%02d-W%02d)" w1 w2))
3836 ":\n")))
3837 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3838 'org-date-line t))
3839 (org-agenda-mark-header-line s))
3840 (while (setq d (pop day-numbers))
3841 (setq date (calendar-gregorian-from-absolute d)
3842 s (point))
3843 (if (or (setq todayp (= d today))
3844 (and (not start-pos) (= d sd)))
3845 (setq start-pos (point))
3846 (if (and start-pos (not end-pos))
3847 (setq end-pos (point))))
3848 (setq files thefiles
3849 rtnall nil)
3850 (while (setq file (pop files))
3851 (catch 'nextfile
3852 (org-check-agenda-file file)
3853 (let ((org-agenda-entry-types org-agenda-entry-types))
3854 (unless org-agenda-include-deadlines
3855 (setq org-agenda-entry-types
3856 (delq :deadline org-agenda-entry-types)))
3857 (cond
3858 ((memq org-agenda-show-log '(only clockcheck))
3859 (setq rtn (org-agenda-get-day-entries
3860 file date :closed)))
3861 (org-agenda-show-log
3862 (setq rtn (apply 'org-agenda-get-day-entries
3863 file date
3864 (append '(:closed) org-agenda-entry-types))))
3866 (setq rtn (apply 'org-agenda-get-day-entries
3867 file date
3868 org-agenda-entry-types)))))
3869 (setq rtnall (append rtnall rtn)))) ;; all entries
3870 (if org-agenda-include-diary
3871 (let ((org-agenda-search-headline-for-time t))
3872 (require 'diary-lib)
3873 (setq rtn (org-get-entries-from-diary date))
3874 (setq rtnall (append rtnall rtn))))
3875 (if (or rtnall org-agenda-show-all-dates)
3876 (progn
3877 (setq day-cnt (1+ day-cnt))
3878 (insert
3879 (if (stringp org-agenda-format-date)
3880 (format-time-string org-agenda-format-date
3881 (org-time-from-absolute date))
3882 (funcall org-agenda-format-date date))
3883 "\n")
3884 (put-text-property s (1- (point)) 'face
3885 (org-agenda-get-day-face date))
3886 (put-text-property s (1- (point)) 'org-date-line t)
3887 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3888 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3889 (when todayp
3890 (put-text-property s (1- (point)) 'org-today t))
3891 (if rtnall (insert ;; all entries
3892 (org-finalize-agenda-entries
3893 (org-agenda-add-time-grid-maybe
3894 rtnall ndays todayp))
3895 "\n"))
3896 (put-text-property s (1- (point)) 'day d)
3897 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3898 (when (and org-agenda-clockreport-mode clocktable-start)
3899 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3900 ;; the above line is to ensure the restricted range!
3901 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3902 tbl)
3903 (setq p (org-plist-delete p :block))
3904 (setq p (plist-put p :tstart clocktable-start))
3905 (setq p (plist-put p :tend clocktable-end))
3906 (setq p (plist-put p :scope 'agenda))
3907 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3908 (setq filter (or org-agenda-tag-filter-while-redo
3909 (get 'org-agenda-tag-filter :preset-filter))))
3910 (setq p (plist-put p :tags (mapconcat (lambda (x)
3911 (if (string-match "[<>=]" x)
3914 filter ""))))
3915 (setq tbl (apply 'org-get-clocktable p))
3916 (insert tbl)))
3917 (goto-char (point-min))
3918 (or org-agenda-multi (org-fit-agenda-window))
3919 (unless (and (pos-visible-in-window-p (point-min))
3920 (pos-visible-in-window-p (point-max)))
3921 (goto-char (1- (point-max)))
3922 (recenter -1)
3923 (if (not (pos-visible-in-window-p (or start-pos 1)))
3924 (progn
3925 (goto-char (or start-pos 1))
3926 (recenter 1))))
3927 (goto-char (or start-pos 1))
3928 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3929 (if (eq org-agenda-show-log 'clockcheck)
3930 (org-agenda-show-clocking-issues))
3931 (org-finalize-agenda)
3932 (setq buffer-read-only t)
3933 (message "")))
3935 (defun org-agenda-ndays-to-span (n)
3936 "Return a span symbol for a span of N days, or N if none matches."
3937 (cond ((symbolp n) n)
3938 ((= n 1) 'day)
3939 ((= n 7) 'week)
3940 (t n)))
3942 (defun org-agenda-span-to-ndays (span start-day)
3943 "Return ndays from SPAN starting at START-DAY."
3944 (cond ((numberp span) span)
3945 ((eq span 'day) 1)
3946 ((eq span 'week) 7)
3947 ((eq span 'month)
3948 (let ((date (calendar-gregorian-from-absolute start-day)))
3949 (calendar-last-day-of-month (car date) (caddr date))))
3950 ((eq span 'year)
3951 (let ((date (calendar-gregorian-from-absolute start-day)))
3952 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3954 (defun org-agenda-span-name (span)
3955 "Return a SPAN name."
3956 (if (null span)
3958 (if (symbolp span)
3959 (capitalize (symbol-name span))
3960 (format "%d days" span))))
3962 ;;; Agenda word search
3964 (defvar org-agenda-search-history nil)
3965 (defvar org-todo-only nil)
3967 (defvar org-search-syntax-table nil
3968 "Special syntax table for org-mode search.
3969 In this table, we have single quotes not as word constituents, to
3970 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3972 (defun org-search-syntax-table ()
3973 (unless org-search-syntax-table
3974 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3975 (modify-syntax-entry ?' "." org-search-syntax-table)
3976 (modify-syntax-entry ?` "." org-search-syntax-table))
3977 org-search-syntax-table)
3979 (defvar org-agenda-last-search-view-search-was-boolean nil)
3981 ;;;###autoload
3982 (defun org-search-view (&optional todo-only string edit-at)
3983 "Show all entries that contain a phrase or words or regular expressions.
3985 With optional prefix argument TODO-ONLY, only consider entries that are
3986 TODO entries. The argument STRING can be used to pass a default search
3987 string into this function. If EDIT-AT is non-nil, it means that the
3988 user should get a chance to edit this string, with cursor at position
3989 EDIT-AT.
3991 The search string can be viewed either as a phrase that should be found as
3992 is, or it can be broken into a number of snippets, each of which must match
3993 in a Boolean way to select an entry. The default depends on the variable
3994 `org-agenda-search-view-always-boolean'.
3995 Even if this is turned off (the default) you can always switch to
3996 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3998 The default is a direct search of the whole phrase, where each space in
3999 the search string can expand to an arbitrary amount of whitespace,
4000 including newlines.
4002 If using a Boolean search, the search string is split on whitespace and
4003 each snippet is searched separately, with logical AND to select an entry.
4004 Words prefixed with a minus must *not* occur in the entry. Words without
4005 a prefix or prefixed with a plus must occur in the entry. Matching is
4006 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4007 match whole words, not parts of a word) if
4008 `org-agenda-search-view-force-full-words' is set (default is nil).
4010 Boolean search snippets enclosed by curly braces are interpreted as
4011 regular expressions that must or (when preceded with \"-\") must not
4012 match in the entry. Snippets enclosed into double quotes will be taken
4013 as a whole, to include whitespace.
4015 - If the search string starts with an asterisk, search only in headlines.
4016 - If (possibly after the leading star) the search string starts with an
4017 exclamation mark, this also means to look at TODO entries only, an effect
4018 that can also be achieved with a prefix argument.
4019 - If (possibly after star and exclamation mark) the search string starts
4020 with a colon, this will mean that the (non-regexp) snippets of the
4021 Boolean search must match as full words.
4023 This command searches the agenda files, and in addition the files listed
4024 in `org-agenda-text-search-extra-files'."
4025 (interactive "P")
4026 (org-prepare-agenda "SEARCH")
4027 (org-compile-prefix-format 'search)
4028 (org-set-sorting-strategy 'search)
4029 (let* ((props (list 'face nil
4030 'done-face 'org-agenda-done
4031 'org-not-done-regexp org-not-done-regexp
4032 'org-todo-regexp org-todo-regexp
4033 'org-complex-heading-regexp org-complex-heading-regexp
4034 'mouse-face 'highlight
4035 'help-echo (format "mouse-2 or RET jump to location")))
4036 (full-words org-agenda-search-view-force-full-words)
4037 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4038 regexp rtn rtnall files file pos
4039 marker category org-category-pos tags c neg re boolean
4040 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4041 (unless (and (not edit-at)
4042 (stringp string)
4043 (string-match "\\S-" string))
4044 (setq string (read-string
4045 (if org-agenda-search-view-always-boolean
4046 "[+-]Word/{Regexp} ...: "
4047 "Phrase, or [+-]Word/{Regexp} ...: ")
4048 (cond
4049 ((integerp edit-at) (cons string edit-at))
4050 (edit-at string))
4051 'org-agenda-search-history)))
4052 (org-set-local 'org-todo-only todo-only)
4053 (setq org-agenda-redo-command
4054 (list 'org-search-view (if todo-only t nil) string
4055 '(if current-prefix-arg 1 nil)))
4056 (setq org-agenda-query-string string)
4058 (if (equal (string-to-char string) ?*)
4059 (setq hdl-only t
4060 words (substring string 1))
4061 (setq words string))
4062 (when (equal (string-to-char words) ?!)
4063 (setq todo-only t
4064 words (substring words 1)))
4065 (when (equal (string-to-char words) ?:)
4066 (setq full-words t
4067 words (substring words 1)))
4068 (if (or org-agenda-search-view-always-boolean
4069 (member (string-to-char words) '(?- ?+ ?\{)))
4070 (setq boolean t))
4071 (setq words (org-split-string words))
4072 (let (www w)
4073 (while (setq w (pop words))
4074 (while (and (string-match "\\\\\\'" w) words)
4075 (setq w (concat (substring w 0 -1) " " (pop words))))
4076 (push w www))
4077 (setq words (nreverse www) www nil)
4078 (while (setq w (pop words))
4079 (when (and (string-match "\\`[-+]?{" w)
4080 (not (string-match "}\\'" w)))
4081 (while (and words (not (string-match "}\\'" (car words))))
4082 (setq w (concat w " " (pop words))))
4083 (setq w (concat w " " (pop words))))
4084 (push w www))
4085 (setq words (nreverse www)))
4086 (setq org-agenda-last-search-view-search-was-boolean boolean)
4087 (when boolean
4088 (let (wds w)
4089 (while (setq w (pop words))
4090 (if (or (equal (substring w 0 1) "\"")
4091 (and (> (length w) 1)
4092 (member (substring w 0 1) '("+" "-"))
4093 (equal (substring w 1 2) "\"")))
4094 (while (and words (not (equal (substring w -1) "\"")))
4095 (setq w (concat w " " (pop words)))))
4096 (and (string-match "\\`\\([-+]?\\)\"" w)
4097 (setq w (replace-match "\\1" nil nil w)))
4098 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4099 (push w wds))
4100 (setq words (nreverse wds))))
4101 (if boolean
4102 (mapc (lambda (w)
4103 (setq c (string-to-char w))
4104 (if (equal c ?-)
4105 (setq neg t w (substring w 1))
4106 (if (equal c ?+)
4107 (setq neg nil w (substring w 1))
4108 (setq neg nil)))
4109 (if (string-match "\\`{.*}\\'" w)
4110 (setq re (substring w 1 -1))
4111 (if full-words
4112 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4113 (setq re (regexp-quote (downcase w)))))
4114 (if neg (push re regexps-) (push re regexps+)))
4115 words)
4116 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4117 regexps+))
4118 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4119 (if (not regexps+)
4120 (setq regexp org-outline-regexp-bol)
4121 (setq regexp (pop regexps+))
4122 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4123 regexp))))
4124 (setq files (org-agenda-files nil 'ifmode))
4125 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4126 (pop org-agenda-text-search-extra-files)
4127 (setq files (org-add-archive-files files)))
4128 (setq files (append files org-agenda-text-search-extra-files)
4129 rtnall nil)
4130 (while (setq file (pop files))
4131 (setq ee nil)
4132 (catch 'nextfile
4133 (org-check-agenda-file file)
4134 (setq buffer (if (file-exists-p file)
4135 (org-get-agenda-file-buffer file)
4136 (error "No such file %s" file)))
4137 (if (not buffer)
4138 ;; If file does not exist, make sure an error message is sent
4139 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4140 file))))
4141 (with-current-buffer buffer
4142 (with-syntax-table (org-search-syntax-table)
4143 (unless (eq major-mode 'org-mode)
4144 (error "Agenda file %s is not in `org-mode'" file))
4145 (let ((case-fold-search t))
4146 (save-excursion
4147 (save-restriction
4148 (if org-agenda-restrict
4149 (narrow-to-region org-agenda-restrict-begin
4150 org-agenda-restrict-end)
4151 (widen))
4152 (goto-char (point-min))
4153 (unless (or (org-at-heading-p)
4154 (outline-next-heading))
4155 (throw 'nextfile t))
4156 (goto-char (max (point-min) (1- (point))))
4157 (while (re-search-forward regexp nil t)
4158 (org-back-to-heading t)
4159 (skip-chars-forward "* ")
4160 (setq beg (point-at-bol)
4161 beg1 (point)
4162 end (progn (outline-next-heading) (point)))
4163 (catch :skip
4164 (goto-char beg)
4165 (org-agenda-skip)
4166 (setq str (buffer-substring-no-properties
4167 (point-at-bol)
4168 (if hdl-only (point-at-eol) end)))
4169 (mapc (lambda (wr) (when (string-match wr str)
4170 (goto-char (1- end))
4171 (throw :skip t)))
4172 regexps-)
4173 (mapc (lambda (wr) (unless (string-match wr str)
4174 (goto-char (1- end))
4175 (throw :skip t)))
4176 (if todo-only
4177 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4178 regexps+)
4179 regexps+))
4180 (goto-char beg)
4181 (setq marker (org-agenda-new-marker (point))
4182 category (org-get-category)
4183 org-category-pos (get-text-property (point) 'org-category-position)
4184 tags (org-get-tags-at (point))
4185 txt (org-agenda-format-item
4187 (buffer-substring-no-properties
4188 beg1 (point-at-eol))
4189 category tags))
4190 (org-add-props txt props
4191 'org-marker marker 'org-hd-marker marker
4192 'org-todo-regexp org-todo-regexp
4193 'org-complex-heading-regexp org-complex-heading-regexp
4194 'priority 1000 'org-category category
4195 'org-category-position org-category-pos
4196 'type "search")
4197 (push txt ee)
4198 (goto-char (1- end))))))))))
4199 (setq rtn (nreverse ee))
4200 (setq rtnall (append rtnall rtn)))
4201 (if org-agenda-overriding-header
4202 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4203 nil 'face 'org-agenda-structure) "\n")
4204 (insert "Search words: ")
4205 (add-text-properties (point-min) (1- (point))
4206 (list 'face 'org-agenda-structure))
4207 (setq pos (point))
4208 (insert string "\n")
4209 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4210 (setq pos (point))
4211 (unless org-agenda-multi
4212 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4213 (add-text-properties pos (1- (point))
4214 (list 'face 'org-agenda-structure))))
4215 (org-agenda-mark-header-line (point-min))
4216 (when rtnall
4217 (insert (org-finalize-agenda-entries rtnall) "\n"))
4218 (goto-char (point-min))
4219 (or org-agenda-multi (org-fit-agenda-window))
4220 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4221 (org-finalize-agenda)
4222 (setq buffer-read-only t)))
4224 ;;; Agenda TODO list
4226 (defvar org-select-this-todo-keyword nil)
4227 (defvar org-last-arg nil)
4229 ;;;###autoload
4230 (defun org-todo-list (arg)
4231 "Show all (not done) TODO entries from all agenda file in a single list.
4232 The prefix arg can be used to select a specific TODO keyword and limit
4233 the list to these. When using \\[universal-argument], you will be prompted
4234 for a keyword. A numeric prefix directly selects the Nth keyword in
4235 `org-todo-keywords-1'."
4236 (interactive "P")
4237 (org-prepare-agenda "TODO")
4238 (org-compile-prefix-format 'todo)
4239 (org-set-sorting-strategy 'todo)
4240 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4241 (let* ((today (org-today))
4242 (date (calendar-gregorian-from-absolute today))
4243 (kwds org-todo-keywords-for-agenda)
4244 (completion-ignore-case t)
4245 (org-select-this-todo-keyword
4246 (if (stringp arg) arg
4247 (and arg (integerp arg) (> arg 0)
4248 (nth (1- arg) kwds))))
4249 rtn rtnall files file pos)
4250 (when (equal arg '(4))
4251 (setq org-select-this-todo-keyword
4252 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4253 (mapcar 'list kwds) nil nil)))
4254 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4255 (org-set-local 'org-last-arg arg)
4256 (setq org-agenda-redo-command
4257 '(org-todo-list (or current-prefix-arg org-last-arg)))
4258 (setq files (org-agenda-files nil 'ifmode)
4259 rtnall nil)
4260 (while (setq file (pop files))
4261 (catch 'nextfile
4262 (org-check-agenda-file file)
4263 (setq rtn (org-agenda-get-day-entries file date :todo))
4264 (setq rtnall (append rtnall rtn))))
4265 (if org-agenda-overriding-header
4266 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4267 nil 'face 'org-agenda-structure) "\n")
4268 (insert "Global list of TODO items of type: ")
4269 (add-text-properties (point-min) (1- (point))
4270 (list 'face 'org-agenda-structure
4271 'short-heading
4272 (concat "ToDo: "
4273 (or org-select-this-todo-keyword "ALL"))))
4274 (org-agenda-mark-header-line (point-min))
4275 (setq pos (point))
4276 (insert (or org-select-this-todo-keyword "ALL") "\n")
4277 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4278 (setq pos (point))
4279 (unless org-agenda-multi
4280 (insert "Available with `N r': (0)ALL")
4281 (let ((n 0) s)
4282 (mapc (lambda (x)
4283 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4284 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4285 (insert "\n "))
4286 (insert " " s))
4287 kwds))
4288 (insert "\n"))
4289 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4290 (org-agenda-mark-header-line (point-min))
4291 (when rtnall
4292 (insert (org-finalize-agenda-entries rtnall) "\n"))
4293 (goto-char (point-min))
4294 (or org-agenda-multi (org-fit-agenda-window))
4295 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4296 (org-finalize-agenda)
4297 (setq buffer-read-only t)))
4299 ;;; Agenda tags match
4301 ;;;###autoload
4302 (defun org-tags-view (&optional todo-only match)
4303 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4304 The prefix arg TODO-ONLY limits the search to TODO entries."
4305 (interactive "P")
4306 (let* ((org-tags-match-list-sublevels
4307 org-tags-match-list-sublevels)
4308 (completion-ignore-case t)
4309 rtn rtnall files file pos matcher
4310 buffer)
4311 (when (and (stringp match) (not (string-match "\\S-" match)))
4312 (setq match nil))
4313 (setq matcher (org-make-tags-matcher match)
4314 match (car matcher) matcher (cdr matcher))
4315 (org-prepare-agenda (concat "TAGS " match))
4316 (org-compile-prefix-format 'tags)
4317 (org-set-sorting-strategy 'tags)
4318 (setq org-agenda-query-string match)
4319 (setq org-agenda-redo-command
4320 (list 'org-tags-view (list 'quote todo-only)
4321 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4322 (setq files (org-agenda-files nil 'ifmode)
4323 rtnall nil)
4324 (while (setq file (pop files))
4325 (catch 'nextfile
4326 (org-check-agenda-file file)
4327 (setq buffer (if (file-exists-p file)
4328 (org-get-agenda-file-buffer file)
4329 (error "No such file %s" file)))
4330 (if (not buffer)
4331 ;; If file does not exist, error message to agenda
4332 (setq rtn (list
4333 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4334 rtnall (append rtnall rtn))
4335 (with-current-buffer buffer
4336 (unless (eq major-mode 'org-mode)
4337 (error "Agenda file %s is not in `org-mode'" file))
4338 (save-excursion
4339 (save-restriction
4340 (if org-agenda-restrict
4341 (narrow-to-region org-agenda-restrict-begin
4342 org-agenda-restrict-end)
4343 (widen))
4344 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4345 (setq rtnall (append rtnall rtn))))))))
4346 (if org-agenda-overriding-header
4347 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4348 nil 'face 'org-agenda-structure) "\n")
4349 (insert "Headlines with TAGS match: ")
4350 (add-text-properties (point-min) (1- (point))
4351 (list 'face 'org-agenda-structure
4352 'short-heading
4353 (concat "Match: " match)))
4354 (setq pos (point))
4355 (insert match "\n")
4356 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4357 (setq pos (point))
4358 (unless org-agenda-multi
4359 (insert "Press `C-u r' to search again with new search string\n"))
4360 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4361 (org-agenda-mark-header-line (point-min))
4362 (when rtnall
4363 (insert (org-finalize-agenda-entries rtnall) "\n"))
4364 (goto-char (point-min))
4365 (or org-agenda-multi (org-fit-agenda-window))
4366 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4367 (org-finalize-agenda)
4368 (setq buffer-read-only t)))
4370 ;;; Agenda Finding stuck projects
4372 (defvar org-agenda-skip-regexp nil
4373 "Regular expression used in skipping subtrees for the agenda.
4374 This is basically a temporary global variable that can be set and then
4375 used by user-defined selections using `org-agenda-skip-function'.")
4377 (defvar org-agenda-overriding-header nil
4378 "When set during agenda, todo and tags searches it replaces the header.
4379 This variable should not be set directly, but custom commands can bind it
4380 in the options section.")
4382 (defun org-agenda-skip-entry-when-regexp-matches ()
4383 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4384 If yes, it returns the end position of this entry, causing agenda commands
4385 to skip the entry but continuing the search in the subtree. This is a
4386 function that can be put into `org-agenda-skip-function' for the duration
4387 of a command."
4388 (let ((end (save-excursion (org-end-of-subtree t)))
4389 skip)
4390 (save-excursion
4391 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4392 (and skip end)))
4394 (defun org-agenda-skip-subtree-when-regexp-matches ()
4395 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4396 If yes, it returns the end position of this tree, causing agenda commands
4397 to skip this subtree. This is a function that can be put into
4398 `org-agenda-skip-function' for the duration of a command."
4399 (let ((end (save-excursion (org-end-of-subtree t)))
4400 skip)
4401 (save-excursion
4402 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4403 (and skip end)))
4405 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4406 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4407 If yes, it returns the end position of the current entry (NOT the tree),
4408 causing agenda commands to skip the entry but continuing the search in
4409 the subtree. This is a function that can be put into
4410 `org-agenda-skip-function' for the duration of a command. An important
4411 use of this function is for the stuck project list."
4412 (let ((end (save-excursion (org-end-of-subtree t)))
4413 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4414 skip)
4415 (save-excursion
4416 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4417 (and skip entry-end)))
4419 (defun org-agenda-skip-entry-if (&rest conditions)
4420 "Skip entry if any of CONDITIONS is true.
4421 See `org-agenda-skip-if' for details."
4422 (org-agenda-skip-if nil conditions))
4424 (defun org-agenda-skip-subtree-if (&rest conditions)
4425 "Skip entry if any of CONDITIONS is true.
4426 See `org-agenda-skip-if' for details."
4427 (org-agenda-skip-if t conditions))
4429 (defun org-agenda-skip-if (subtree conditions)
4430 "Checks current entity for CONDITIONS.
4431 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4432 the entry, i.e. the text before the next heading is checked.
4434 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4435 from different tests. Valid conditions are:
4437 scheduled Check if there is a scheduled cookie
4438 notscheduled Check if there is no scheduled cookie
4439 deadline Check if there is a deadline
4440 notdeadline Check if there is no deadline
4441 timestamp Check if there is a timestamp (also deadline or scheduled)
4442 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4443 regexp Check if regexp matches
4444 notregexp Check if regexp does not match.
4445 todo Check if TODO keyword matches
4446 nottodo Check if TODO keyword does not match
4448 The regexp is taken from the conditions list, it must come right after
4449 the `regexp' or `notregexp' element.
4451 `todo' and `nottodo' accept as an argument a list of todo
4452 keywords, which may include \"*\" to match any todo keyword.
4454 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4456 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4458 Instead of a list a keyword class may be given
4460 (org-agenda-skip-entry-if 'nottodo 'done)
4462 would skip entries that haven't been marked with any of \"DONE\"
4463 keywords. Possible classes are: `todo', `done', `any'.
4465 If any of these conditions is met, this function returns the end point of
4466 the entity, causing the search to continue from there. This is a function
4467 that can be put into `org-agenda-skip-function' for the duration of a command."
4468 (let (beg end m)
4469 (org-back-to-heading t)
4470 (setq beg (point)
4471 end (if subtree
4472 (progn (org-end-of-subtree t) (point))
4473 (progn (outline-next-heading) (1- (point)))))
4474 (goto-char beg)
4475 (and
4477 (and (memq 'scheduled conditions)
4478 (re-search-forward org-scheduled-time-regexp end t))
4479 (and (memq 'notscheduled conditions)
4480 (not (re-search-forward org-scheduled-time-regexp end t)))
4481 (and (memq 'deadline conditions)
4482 (re-search-forward org-deadline-time-regexp end t))
4483 (and (memq 'notdeadline conditions)
4484 (not (re-search-forward org-deadline-time-regexp end t)))
4485 (and (memq 'timestamp conditions)
4486 (re-search-forward org-ts-regexp end t))
4487 (and (memq 'nottimestamp conditions)
4488 (not (re-search-forward org-ts-regexp end t)))
4489 (and (setq m (memq 'regexp conditions))
4490 (stringp (nth 1 m))
4491 (re-search-forward (nth 1 m) end t))
4492 (and (setq m (memq 'notregexp conditions))
4493 (stringp (nth 1 m))
4494 (not (re-search-forward (nth 1 m) end t)))
4495 (and (or
4496 (setq m (memq 'todo conditions))
4497 (setq m (memq 'nottodo conditions)))
4498 (org-agenda-skip-if-todo m end)))
4499 end)))
4501 (defun org-agenda-skip-if-todo (args end)
4502 "Helper function for `org-agenda-skip-if', do not use it directly.
4503 ARGS is a list with first element either `todo' or `nottodo'.
4504 The remainder is either a list of TODO keywords, or a state symbol
4505 `todo' or `done' or `any'."
4506 (let ((kw (car args))
4507 (arg (cadr args))
4508 todo-wds todo-re)
4509 (setq todo-wds
4510 (org-uniquify
4511 (cond
4512 ((listp arg) ;; list of keywords
4513 (if (member "*" arg)
4514 (mapcar 'substring-no-properties org-todo-keywords-1)
4515 arg))
4516 ((symbolp arg) ;; keyword class name
4517 (cond
4518 ((eq arg 'todo)
4519 (org-delete-all org-done-keywords
4520 (mapcar 'substring-no-properties
4521 org-todo-keywords-1)))
4522 ((eq arg 'done) org-done-keywords)
4523 ((eq arg 'any)
4524 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4525 (setq todo-re
4526 (concat "^\\*+[ \t]+\\<\\("
4527 (mapconcat 'identity todo-wds "\\|")
4528 "\\)\\>"))
4529 (if (eq kw 'todo)
4530 (re-search-forward todo-re end t)
4531 (not (re-search-forward todo-re end t)))))
4533 ;;;###autoload
4534 (defun org-agenda-list-stuck-projects (&rest ignore)
4535 "Create agenda view for projects that are stuck.
4536 Stuck projects are project that have no next actions. For the definitions
4537 of what a project is and how to check if it stuck, customize the variable
4538 `org-stuck-projects'."
4539 (interactive)
4540 (let* ((org-agenda-skip-function
4541 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4542 ;; We could have used org-agenda-skip-if here.
4543 (org-agenda-overriding-header
4544 (or org-agenda-overriding-header "List of stuck projects: "))
4545 (matcher (nth 0 org-stuck-projects))
4546 (todo (nth 1 org-stuck-projects))
4547 (todo-wds (if (member "*" todo)
4548 (progn
4549 (org-prepare-agenda-buffers (org-agenda-files
4550 nil 'ifmode))
4551 (org-delete-all
4552 org-done-keywords-for-agenda
4553 (copy-sequence org-todo-keywords-for-agenda)))
4554 todo))
4555 (todo-re (concat "^\\*+[ \t]+\\("
4556 (mapconcat 'identity todo-wds "\\|")
4557 "\\)\\>"))
4558 (tags (nth 2 org-stuck-projects))
4559 (tags-re (if (member "*" tags)
4560 (concat org-outline-regexp-bol
4561 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4562 (if tags
4563 (concat org-outline-regexp-bol
4564 ".*:\\("
4565 (mapconcat 'identity tags "\\|")
4566 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4567 (gen-re (nth 3 org-stuck-projects))
4568 (re-list
4569 (delq nil
4570 (list
4571 (if todo todo-re)
4572 (if tags tags-re)
4573 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4574 gen-re)))))
4575 (setq org-agenda-skip-regexp
4576 (if re-list
4577 (mapconcat 'identity re-list "\\|")
4578 (error "No information how to identify unstuck projects")))
4579 (org-tags-view nil matcher)
4580 (with-current-buffer org-agenda-buffer-name
4581 (setq org-agenda-redo-command
4582 '(org-agenda-list-stuck-projects
4583 (or current-prefix-arg org-last-arg))))))
4585 ;;; Diary integration
4587 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4588 (defvar diary-list-entries-hook)
4589 (defvar diary-time-regexp)
4590 (defun org-get-entries-from-diary (date)
4591 "Get the (Emacs Calendar) diary entries for DATE."
4592 (require 'diary-lib)
4593 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4594 (diary-display-hook '(fancy-diary-display))
4595 (diary-display-function 'fancy-diary-display)
4596 (pop-up-frames nil)
4597 (diary-list-entries-hook
4598 (cons 'org-diary-default-entry diary-list-entries-hook))
4599 (diary-file-name-prefix-function nil) ; turn this feature off
4600 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4601 entries
4602 (org-disable-agenda-to-diary t))
4603 (save-excursion
4604 (save-window-excursion
4605 (funcall (if (fboundp 'diary-list-entries)
4606 'diary-list-entries 'list-diary-entries)
4607 date 1)))
4608 (if (not (get-buffer diary-fancy-buffer))
4609 (setq entries nil)
4610 (with-current-buffer diary-fancy-buffer
4611 (setq buffer-read-only nil)
4612 (if (zerop (buffer-size))
4613 ;; No entries
4614 (setq entries nil)
4615 ;; Omit the date and other unnecessary stuff
4616 (org-agenda-cleanup-fancy-diary)
4617 ;; Add prefix to each line and extend the text properties
4618 (if (zerop (buffer-size))
4619 (setq entries nil)
4620 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4621 (setq entries
4622 (with-temp-buffer
4623 (insert entries) (goto-char (point-min))
4624 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4625 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4626 (replace-match (concat "; " (match-string 1)))))
4627 (buffer-string)))))
4628 (set-buffer-modified-p nil)
4629 (kill-buffer diary-fancy-buffer)))
4630 (when entries
4631 (setq entries (org-split-string entries "\n"))
4632 (setq entries
4633 (mapcar
4634 (lambda (x)
4635 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4636 ;; Extend the text properties to the beginning of the line
4637 (org-add-props x (text-properties-at (1- (length x)) x)
4638 'type "diary" 'date date 'face 'org-agenda-diary))
4639 entries)))))
4641 (defvar org-agenda-cleanup-fancy-diary-hook nil
4642 "Hook run when the fancy diary buffer is cleaned up.")
4644 (defun org-agenda-cleanup-fancy-diary ()
4645 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4646 This gets rid of the date, the underline under the date, and
4647 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4648 date. It also removes lines that contain only whitespace."
4649 (goto-char (point-min))
4650 (if (looking-at ".*?:[ \t]*")
4651 (progn
4652 (replace-match "")
4653 (re-search-forward "\n=+$" nil t)
4654 (replace-match "")
4655 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4656 (re-search-forward "\n=+$" nil t)
4657 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4658 (goto-char (point-min))
4659 (while (re-search-forward "^ +\n" nil t)
4660 (replace-match ""))
4661 (goto-char (point-min))
4662 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4663 (replace-match ""))
4664 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4666 ;; Make sure entries from the diary have the right text properties.
4667 (eval-after-load "diary-lib"
4668 '(if (boundp 'diary-modify-entry-list-string-function)
4669 ;; We can rely on the hook, nothing to do
4671 ;; Hook not available, must use advice to make this work
4672 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4673 "Make the position visible."
4674 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4675 (stringp string)
4676 buffer-file-name)
4677 (setq string (org-modify-diary-entry-string string))))))
4679 (defun org-modify-diary-entry-string (string)
4680 "Add text properties to string, allowing org-mode to act on it."
4681 (org-add-props string nil
4682 'mouse-face 'highlight
4683 'help-echo (if buffer-file-name
4684 (format "mouse-2 or RET jump to diary file %s"
4685 (abbreviate-file-name buffer-file-name))
4687 'org-agenda-diary-link t
4688 'org-marker (org-agenda-new-marker (point-at-bol))))
4690 (defun org-diary-default-entry ()
4691 "Add a dummy entry to the diary.
4692 Needed to avoid empty dates which mess up holiday display."
4693 ;; Catch the error if dealing with the new add-to-diary-alist
4694 (when org-disable-agenda-to-diary
4695 (condition-case nil
4696 (org-add-to-diary-list original-date "Org-mode dummy" "")
4697 (error
4698 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4700 (defun org-add-to-diary-list (&rest args)
4701 (if (fboundp 'diary-add-to-list)
4702 (apply 'diary-add-to-list args)
4703 (apply 'add-to-diary-list args)))
4705 (defvar org-diary-last-run-time nil)
4707 ;;;###autoload
4708 (defun org-diary (&rest args)
4709 "Return diary information from org-files.
4710 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4711 It accesses org files and extracts information from those files to be
4712 listed in the diary. The function accepts arguments specifying what
4713 items should be listed. For a list of arguments allowed here, see the
4714 variable `org-agenda-entry-types'.
4716 The call in the diary file should look like this:
4718 &%%(org-diary) ~/path/to/some/orgfile.org
4720 Use a separate line for each org file to check. Or, if you omit the file name,
4721 all files listed in `org-agenda-files' will be checked automatically:
4723 &%%(org-diary)
4725 If you don't give any arguments (as in the example above), the default
4726 arguments (:deadline :scheduled :timestamp :sexp) are used.
4727 So the example above may also be written as
4729 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4731 The function expects the lisp variables `entry' and `date' to be provided
4732 by the caller, because this is how the calendar works. Don't use this
4733 function from a program - use `org-agenda-get-day-entries' instead."
4734 (when (> (- (org-float-time)
4735 org-agenda-last-marker-time)
4737 (org-agenda-reset-markers))
4738 (org-compile-prefix-format 'agenda)
4739 (org-set-sorting-strategy 'agenda)
4740 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4741 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4742 (list entry)
4743 (org-agenda-files t)))
4744 (time (org-float-time))
4745 file rtn results)
4746 (when (or (not org-diary-last-run-time)
4747 (> (- time
4748 org-diary-last-run-time)
4750 (org-prepare-agenda-buffers files))
4751 (setq org-diary-last-run-time time)
4752 ;; If this is called during org-agenda, don't return any entries to
4753 ;; the calendar. Org Agenda will list these entries itself.
4754 (if org-disable-agenda-to-diary (setq files nil))
4755 (while (setq file (pop files))
4756 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4757 (setq results (append results rtn)))
4758 (if results
4759 (concat (org-finalize-agenda-entries results) "\n"))))
4761 ;;; Agenda entry finders
4763 (defun org-agenda-get-day-entries (file date &rest args)
4764 "Does the work for `org-diary' and `org-agenda'.
4765 FILE is the path to a file to be checked for entries. DATE is date like
4766 the one returned by `calendar-current-date'. ARGS are symbols indicating
4767 which kind of entries should be extracted. For details about these, see
4768 the documentation of `org-diary'."
4769 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4770 (let* ((org-startup-folded nil)
4771 (org-startup-align-all-tables nil)
4772 (buffer (if (file-exists-p file)
4773 (org-get-agenda-file-buffer file)
4774 (error "No such file %s" file)))
4775 arg results rtn deadline-results)
4776 (if (not buffer)
4777 ;; If file does not exist, make sure an error message ends up in diary
4778 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4779 (with-current-buffer buffer
4780 (unless (eq major-mode 'org-mode)
4781 (error "Agenda file %s is not in `org-mode'" file))
4782 (let ((case-fold-search nil))
4783 (save-excursion
4784 (save-restriction
4785 (if org-agenda-restrict
4786 (narrow-to-region org-agenda-restrict-begin
4787 org-agenda-restrict-end)
4788 (widen))
4789 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4790 (while (setq arg (pop args))
4791 (cond
4792 ((and (eq arg :todo)
4793 (equal date (calendar-gregorian-from-absolute
4794 (org-today))))
4795 (setq rtn (org-agenda-get-todos))
4796 (setq results (append results rtn)))
4797 ((eq arg :timestamp)
4798 (setq rtn (org-agenda-get-blocks))
4799 (setq results (append results rtn))
4800 (setq rtn (org-agenda-get-timestamps))
4801 (setq results (append results rtn)))
4802 ((eq arg :sexp)
4803 (setq rtn (org-agenda-get-sexps))
4804 (setq results (append results rtn)))
4805 ((eq arg :scheduled)
4806 (setq rtn (org-agenda-get-scheduled deadline-results))
4807 (setq results (append results rtn)))
4808 ((eq arg :closed)
4809 (setq rtn (org-agenda-get-progress))
4810 (setq results (append results rtn)))
4811 ((eq arg :deadline)
4812 (setq rtn (org-agenda-get-deadlines))
4813 (setq deadline-results (copy-sequence rtn))
4814 (setq results (append results rtn))))))))
4815 results))))
4817 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4818 (defun org-agenda-get-todos ()
4819 "Return the TODO information for agenda display."
4820 (let* ((props (list 'face nil
4821 'done-face 'org-agenda-done
4822 'org-not-done-regexp org-not-done-regexp
4823 'org-todo-regexp org-todo-regexp
4824 'org-complex-heading-regexp org-complex-heading-regexp
4825 'mouse-face 'highlight
4826 'help-echo
4827 (format "mouse-2 or RET jump to org file %s"
4828 (abbreviate-file-name buffer-file-name))))
4829 (regexp (format org-heading-keyword-regexp-format
4830 (cond
4831 ((and org-select-this-todo-keyword
4832 (equal org-select-this-todo-keyword "*"))
4833 org-todo-regexp)
4834 (org-select-this-todo-keyword
4835 (concat "\\("
4836 (mapconcat 'identity
4837 (org-split-string
4838 org-select-this-todo-keyword
4839 "|")
4840 "\\|") "\\)"))
4841 (t org-not-done-regexp))))
4842 marker priority category org-category-pos tags todo-state
4843 ee txt beg end)
4844 (goto-char (point-min))
4845 (while (re-search-forward regexp nil t)
4846 (catch :skip
4847 (save-match-data
4848 (beginning-of-line)
4849 (org-agenda-skip)
4850 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4851 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4852 (goto-char (1+ beg))
4853 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4854 (throw :skip nil)))
4855 (goto-char (match-beginning 2))
4856 (setq marker (org-agenda-new-marker (match-beginning 0))
4857 category (org-get-category)
4858 org-category-pos (get-text-property (point) 'org-category-position)
4859 txt (org-trim
4860 (buffer-substring (match-beginning 2) (match-end 0)))
4861 tags (org-get-tags-at (point))
4862 txt (org-agenda-format-item "" txt category tags)
4863 priority (1+ (org-get-priority txt))
4864 todo-state (org-get-todo-state))
4865 (org-add-props txt props
4866 'org-marker marker 'org-hd-marker marker
4867 'priority priority 'org-category category
4868 'org-category-position org-category-pos
4869 'type "todo" 'todo-state todo-state)
4870 (push txt ee)
4871 (if org-agenda-todo-list-sublevels
4872 (goto-char (match-end 2))
4873 (org-end-of-subtree 'invisible))))
4874 (nreverse ee)))
4876 (defun org-agenda-todo-custom-ignore-p (time n)
4877 "Check whether timestamp is farther away then n number of days.
4878 This function is invoked if `org-agenda-todo-ignore-deadlines',
4879 `org-agenda-todo-ignore-scheduled' or
4880 `org-agenda-todo-ignore-timestamp' is set to an integer."
4881 (let ((days (org-days-to-time time)))
4882 (if (>= n 0)
4883 (>= days n)
4884 (<= days n))))
4886 ;;;###autoload
4887 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4888 (&optional end)
4889 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4890 (when (or org-agenda-todo-ignore-with-date
4891 org-agenda-todo-ignore-scheduled
4892 org-agenda-todo-ignore-deadlines
4893 org-agenda-todo-ignore-timestamp)
4894 (setq end (or end (save-excursion (outline-next-heading) (point))))
4895 (save-excursion
4896 (or (and org-agenda-todo-ignore-with-date
4897 (re-search-forward org-ts-regexp end t))
4898 (and org-agenda-todo-ignore-scheduled
4899 (re-search-forward org-scheduled-time-regexp end t)
4900 (cond
4901 ((eq org-agenda-todo-ignore-scheduled 'future)
4902 (> (org-days-to-time (match-string 1)) 0))
4903 ((eq org-agenda-todo-ignore-scheduled 'past)
4904 (<= (org-days-to-time (match-string 1)) 0))
4905 ((numberp org-agenda-todo-ignore-scheduled)
4906 (org-agenda-todo-custom-ignore-p
4907 (match-string 1) org-agenda-todo-ignore-scheduled))
4908 (t)))
4909 (and org-agenda-todo-ignore-deadlines
4910 (re-search-forward org-deadline-time-regexp end t)
4911 (cond
4912 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4913 ((eq org-agenda-todo-ignore-deadlines 'far)
4914 (not (org-deadline-close (match-string 1))))
4915 ((eq org-agenda-todo-ignore-deadlines 'future)
4916 (> (org-days-to-time (match-string 1)) 0))
4917 ((eq org-agenda-todo-ignore-deadlines 'past)
4918 (<= (org-days-to-time (match-string 1)) 0))
4919 ((numberp org-agenda-todo-ignore-deadlines)
4920 (org-agenda-todo-custom-ignore-p
4921 (match-string 1) org-agenda-todo-ignore-deadlines))
4922 (t (org-deadline-close (match-string 1)))))
4923 (and org-agenda-todo-ignore-timestamp
4924 (let ((buffer (current-buffer))
4925 (regexp
4926 (concat
4927 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4928 (start (point)))
4929 ;; Copy current buffer into a temporary one
4930 (with-temp-buffer
4931 (insert-buffer-substring buffer start end)
4932 (goto-char (point-min))
4933 ;; Delete SCHEDULED and DEADLINE items
4934 (while (re-search-forward regexp end t)
4935 (delete-region (match-beginning 0) (match-end 0)))
4936 (goto-char (point-min))
4937 ;; No search for timestamp left
4938 (when (re-search-forward org-ts-regexp nil t)
4939 (cond
4940 ((eq org-agenda-todo-ignore-timestamp 'future)
4941 (> (org-days-to-time (match-string 1)) 0))
4942 ((eq org-agenda-todo-ignore-timestamp 'past)
4943 (<= (org-days-to-time (match-string 1)) 0))
4944 ((numberp org-agenda-todo-ignore-timestamp)
4945 (org-agenda-todo-custom-ignore-p
4946 (match-string 1) org-agenda-todo-ignore-timestamp))
4947 (t))))))))))
4949 (defconst org-agenda-no-heading-message
4950 "No heading for this item in buffer or region.")
4952 (defun org-agenda-get-timestamps ()
4953 "Return the date stamp information for agenda display."
4954 (let* ((props (list 'face 'org-agenda-calendar-event
4955 'org-not-done-regexp org-not-done-regexp
4956 'org-todo-regexp org-todo-regexp
4957 'org-complex-heading-regexp org-complex-heading-regexp
4958 'mouse-face 'highlight
4959 'help-echo
4960 (format "mouse-2 or RET jump to org file %s"
4961 (abbreviate-file-name buffer-file-name))))
4962 (d1 (calendar-absolute-from-gregorian date))
4963 (remove-re
4964 (concat
4965 (regexp-quote
4966 (format-time-string
4967 "<%Y-%m-%d"
4968 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4969 ".*?>"))
4970 (regexp
4971 (concat
4972 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4973 (regexp-quote
4974 (substring
4975 (format-time-string
4976 (car org-time-stamp-formats)
4977 (apply 'encode-time ; DATE bound by calendar
4978 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4979 1 11))
4980 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4981 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4982 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4983 donep tmp priority category org-category-pos ee txt timestr tags
4984 b0 b3 e3 head todo-state end-of-match show-all)
4985 (goto-char (point-min))
4986 (while (setq end-of-match (re-search-forward regexp nil t))
4987 (setq b0 (match-beginning 0)
4988 b3 (match-beginning 3) e3 (match-end 3)
4989 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4990 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4991 (member todo-state
4992 org-agenda-repeating-timestamp-show-all)))
4993 (catch :skip
4994 (and (org-at-date-range-p) (throw :skip nil))
4995 (org-agenda-skip)
4996 (if (and (match-end 1)
4997 (not (= d1 (org-time-string-to-absolute
4998 (match-string 1) d1 nil show-all
4999 (current-buffer) b0))))
5000 (throw :skip nil))
5001 (if (and e3
5002 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5003 (throw :skip nil))
5004 (setq tmp (buffer-substring (max (point-min)
5005 (- b0 org-ds-keyword-length))
5007 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5008 inactivep (= (char-after b0) ?\[)
5009 deadlinep (string-match org-deadline-regexp tmp)
5010 scheduledp (string-match org-scheduled-regexp tmp)
5011 closedp (and org-agenda-include-inactive-timestamps
5012 (string-match org-closed-string tmp))
5013 clockp (and org-agenda-include-inactive-timestamps
5014 (or (string-match org-clock-string tmp)
5015 (string-match "]-+\\'" tmp)))
5016 donep (member todo-state org-done-keywords))
5017 (if (or scheduledp deadlinep closedp clockp
5018 (and donep org-agenda-skip-timestamp-if-done))
5019 (throw :skip t))
5020 (if (string-match ">" timestr)
5021 ;; substring should only run to end of time stamp
5022 (setq timestr (substring timestr 0 (match-end 0))))
5023 (setq marker (org-agenda-new-marker b0)
5024 category (org-get-category b0)
5025 org-category-pos (get-text-property b0 'org-category-position))
5026 (save-excursion
5027 (if (not (re-search-backward org-outline-regexp-bol nil t))
5028 (setq txt org-agenda-no-heading-message)
5029 (goto-char (match-beginning 0))
5030 (setq hdmarker (org-agenda-new-marker)
5031 tags (org-get-tags-at))
5032 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5033 (setq head (or (match-string 1) ""))
5034 (setq txt (org-agenda-format-item
5035 (if inactivep org-agenda-inactive-leader nil)
5036 head category tags timestr
5037 remove-re)))
5038 (setq priority (org-get-priority txt))
5039 (org-add-props txt props
5040 'org-marker marker 'org-hd-marker hdmarker)
5041 (org-add-props txt nil 'priority priority
5042 'org-category category 'date date
5043 'org-category-position org-category-pos
5044 'todo-state todo-state
5045 'type "timestamp")
5046 (push txt ee))
5047 (if org-agenda-skip-additional-timestamps-same-entry
5048 (outline-next-heading)
5049 (goto-char end-of-match))))
5050 (nreverse ee)))
5052 (defun org-agenda-get-sexps ()
5053 "Return the sexp information for agenda display."
5054 (require 'diary-lib)
5055 (let* ((props (list 'face 'org-agenda-calendar-sexp
5056 'mouse-face 'highlight
5057 'help-echo
5058 (format "mouse-2 or RET jump to org file %s"
5059 (abbreviate-file-name buffer-file-name))))
5060 (regexp "^&?%%(")
5061 marker category org-category-pos ee txt tags entry
5062 result beg b sexp sexp-entry todo-state)
5063 (goto-char (point-min))
5064 (while (re-search-forward regexp nil t)
5065 (catch :skip
5066 (org-agenda-skip)
5067 (setq beg (match-beginning 0))
5068 (goto-char (1- (match-end 0)))
5069 (setq b (point))
5070 (forward-sexp 1)
5071 (setq sexp (buffer-substring b (point)))
5072 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5073 (org-trim (match-string 1))
5074 ""))
5075 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5076 (when result
5077 (setq marker (org-agenda-new-marker beg)
5078 category (org-get-category beg)
5079 org-category-pos (get-text-property beg 'org-category-position)
5080 todo-state (org-get-todo-state))
5082 (dolist (r (if (stringp result)
5083 (list result)
5084 result)) ;; we expect a list here
5085 (if (string-match "\\S-" r)
5086 (setq txt r)
5087 (setq txt "SEXP entry returned empty string"))
5089 (setq txt (org-agenda-format-item
5090 "" txt category tags 'time))
5091 (org-add-props txt props 'org-marker marker)
5092 (org-add-props txt nil
5093 'org-category category 'date date 'todo-state todo-state
5094 'org-category-position org-category-pos
5095 'type "sexp")
5096 (push txt ee)))))
5097 (nreverse ee)))
5099 ;; Calendar sanity: define some functions that are independent of
5100 ;; `calendar-date-style'.
5101 ;; Normally I would like to use ISO format when calling the diary functions,
5102 ;; but to make sure we still have Emacs 22 compatibility we bind
5103 ;; also `european-calendar-style' and use european format
5104 (defun org-anniversary (year month day &optional mark)
5105 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5106 (org-no-warnings
5107 (let ((calendar-date-style 'european) (european-calendar-style t))
5108 (diary-anniversary day month year mark))))
5109 (defun org-cyclic (N year month day &optional mark)
5110 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5111 (org-no-warnings
5112 (let ((calendar-date-style 'european) (european-calendar-style t))
5113 (diary-cyclic N day month year mark))))
5114 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5115 "Like `diary-block', but with fixed (ISO) order of arguments."
5116 (org-no-warnings
5117 (let ((calendar-date-style 'european) (european-calendar-style t))
5118 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5119 (defun org-date (year month day &optional mark)
5120 "Like `diary-date', but with fixed (ISO) order of arguments."
5121 (org-no-warnings
5122 (let ((calendar-date-style 'european) (european-calendar-style t))
5123 (diary-date day month year mark))))
5124 (defalias 'org-float 'diary-float)
5126 ;; Define the` org-class' function
5127 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5128 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5129 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5130 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5131 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5132 `holidays', then any date that is known by the Emacs calendar to be a
5133 holiday will also be skipped."
5134 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5135 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5136 (d (calendar-absolute-from-gregorian date)))
5137 (and
5138 (<= date1 d)
5139 (<= d date2)
5140 (= (calendar-day-of-week date) dayname)
5141 (or (not skip-weeks)
5142 (progn
5143 (require 'cal-iso)
5144 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5145 (not (and (memq 'holidays skip-weeks)
5146 (calendar-check-holidays date)))
5147 entry)))
5149 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5150 "Like `org-class', but honor `calendar-date-style'.
5151 The order of the first 2 times 3 arguments depends on the variable
5152 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5153 So for American calendars, give this as MONTH DAY YEAR, for European as
5154 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5155 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5156 is any number of ISO weeks in the block period for which the item should
5157 be skipped.
5159 This function is here only for backward compatibility and it is deprecated,
5160 please use `org-class' instead."
5161 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5162 (date2 (org-order-calendar-date-args m2 d2 y2)))
5163 (org-class
5164 (nth 2 date1) (car date1) (nth 1 date1)
5165 (nth 2 date2) (car date2) (nth 1 date2)
5166 dayname skip-weeks)))
5167 (make-obsolete 'org-diary-class 'org-class "")
5169 (defalias 'org-get-closed 'org-agenda-get-progress)
5170 (defun org-agenda-get-progress ()
5171 "Return the logged TODO entries for agenda display."
5172 (let* ((props (list 'mouse-face 'highlight
5173 'org-not-done-regexp org-not-done-regexp
5174 'org-todo-regexp org-todo-regexp
5175 'org-complex-heading-regexp org-complex-heading-regexp
5176 'help-echo
5177 (format "mouse-2 or RET jump to org file %s"
5178 (abbreviate-file-name buffer-file-name))))
5179 (items (if (consp org-agenda-show-log)
5180 org-agenda-show-log
5181 (if (eq org-agenda-show-log 'clockcheck)
5182 '(clock)
5183 org-agenda-log-mode-items)))
5184 (parts
5185 (delq nil
5186 (list
5187 (if (memq 'closed items) (concat "\\<" org-closed-string))
5188 (if (memq 'clock items) (concat "\\<" org-clock-string))
5189 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5190 (parts-re (if parts (mapconcat 'identity parts "\\|")
5191 (error "`org-agenda-log-mode-items' is empty")))
5192 (regexp (concat
5193 "\\(" parts-re "\\)"
5194 " *\\["
5195 (regexp-quote
5196 (substring
5197 (format-time-string
5198 (car org-time-stamp-formats)
5199 (apply 'encode-time ; DATE bound by calendar
5200 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5201 1 11))))
5202 (org-agenda-search-headline-for-time nil)
5203 marker hdmarker priority category org-category-pos tags closedp
5204 statep clockp state ee txt extra timestr rest clocked)
5205 (goto-char (point-min))
5206 (while (re-search-forward regexp nil t)
5207 (catch :skip
5208 (org-agenda-skip)
5209 (setq marker (org-agenda-new-marker (match-beginning 0))
5210 closedp (equal (match-string 1) org-closed-string)
5211 statep (equal (string-to-char (match-string 1)) ?-)
5212 clockp (not (or closedp statep))
5213 state (and statep (match-string 2))
5214 category (org-get-category (match-beginning 0))
5215 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5216 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5217 (when (string-match "\\]" timestr)
5218 ;; substring should only run to end of time stamp
5219 (setq rest (substring timestr (match-end 0))
5220 timestr (substring timestr 0 (match-end 0)))
5221 (if (and (not closedp) (not statep)
5222 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5223 rest))
5224 (progn (setq timestr (concat (substring timestr 0 -1)
5225 "-" (match-string 1 rest) "]"))
5226 (setq clocked (match-string 2 rest)))
5227 (setq clocked "-")))
5228 (save-excursion
5229 (setq extra
5230 (cond
5231 ((not org-agenda-log-mode-add-notes) nil)
5232 (statep
5233 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5234 (match-string 1)))
5235 (clockp
5236 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5237 (match-string 1)))))
5238 (if (not (re-search-backward org-outline-regexp-bol nil t))
5239 (setq txt org-agenda-no-heading-message)
5240 (goto-char (match-beginning 0))
5241 (setq hdmarker (org-agenda-new-marker)
5242 tags (org-get-tags-at))
5243 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5244 (setq txt (match-string 1))
5245 (when extra
5246 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5247 (setq txt (concat (substring txt 0 (match-beginning 1))
5248 " - " extra " " (match-string 2 txt)))
5249 (setq txt (concat txt " - " extra))))
5250 (setq txt (org-agenda-format-item
5251 (cond
5252 (closedp "Closed: ")
5253 (statep (concat "State: (" state ")"))
5254 (t (concat "Clocked: (" clocked ")")))
5255 txt category tags timestr)))
5256 (setq priority 100000)
5257 (org-add-props txt props
5258 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5259 'priority priority 'org-category category
5260 'org-category-position org-category-pos
5261 'type "closed" 'date date
5262 'undone-face 'org-warning 'done-face 'org-agenda-done)
5263 (push txt ee))
5264 (goto-char (point-at-eol))))
5265 (nreverse ee)))
5267 (defun org-agenda-show-clocking-issues ()
5268 "Add overlays, showing issues with clocking.
5269 See also the user option `org-agenda-clock-consistency-checks'."
5270 (interactive)
5271 (let* ((pl org-agenda-clock-consistency-checks)
5272 (re (concat "^[ \t]*"
5273 org-clock-string
5274 "[ \t]+"
5275 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5276 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5277 (tlstart 0.)
5278 (tlend 0.)
5279 (maxtime (org-hh:mm-string-to-minutes
5280 (or (plist-get pl :max-duration) "24:00")))
5281 (mintime (org-hh:mm-string-to-minutes
5282 (or (plist-get pl :min-duration) 0)))
5283 (maxgap (org-hh:mm-string-to-minutes
5284 ;; default 30:00 means never complain
5285 (or (plist-get pl :max-gap) "30:00")))
5286 (gapok (mapcar 'org-hh:mm-string-to-minutes
5287 (plist-get pl :gap-ok-around)))
5288 (def-face (or (plist-get pl :default-face)
5289 '((:background "DarkRed") (:foreground "white"))))
5290 issue face m te ts dt ov)
5291 (goto-char (point-min))
5292 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5293 (setq issue nil face def-face)
5294 (catch 'next
5295 (setq m (org-get-at-bol 'org-marker)
5296 te nil ts nil)
5297 (unless (and m (markerp m))
5298 (setq issue "No valid clock line") (throw 'next t))
5299 (org-with-point-at m
5300 (save-excursion
5301 (goto-char (point-at-bol))
5302 (unless (looking-at re)
5303 (error "No valid Clock line")
5304 (throw 'next t))
5305 (unless (match-end 3)
5306 (setq issue "No end time"
5307 face (or (plist-get pl :no-end-time-face) face))
5308 (throw 'next t))
5309 (setq ts (match-string 1)
5310 te (match-string 3)
5311 ts (org-float-time
5312 (apply 'encode-time (org-parse-time-string ts)))
5313 te (org-float-time
5314 (apply 'encode-time (org-parse-time-string te)))
5315 dt (- te ts))))
5316 (cond
5317 ((> dt (* 60 maxtime))
5318 ;; a very long clocking chunk
5319 (setq issue (format "Clocking interval is very long: %s"
5320 (org-minutes-to-hh:mm-string
5321 (floor (/ (float dt) 60.))))
5322 face (or (plist-get pl :long-face) face)))
5323 ((< dt (* 60 mintime))
5324 ;; a very short clocking chunk
5325 (setq issue (format "Clocking interval is very short: %s"
5326 (org-minutes-to-hh:mm-string
5327 (floor (/ (float dt) 60.))))
5328 face (or (plist-get pl :short-face) face)))
5329 ((and (> tlend 0) (< ts tlend))
5330 ;; Two clock entries are overlapping
5331 (setq issue (format "Clocking overlap: %d minutes"
5332 (/ (- tlend ts) 60))
5333 face (or (plist-get pl :overlap-face) face)))
5334 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5335 ;; There is a gap, lets see if we need to report it
5336 (unless (org-agenda-check-clock-gap tlend ts gapok)
5337 (setq issue (format "Clocking gap: %d minutes"
5338 (/ (- ts tlend) 60))
5339 face (or (plist-get pl :gap-face) face))))
5340 (t nil)))
5341 (setq tlend (or te tlend) tlstart (or ts tlstart))
5342 (when issue
5343 ;; OK, there was some issue, add an overlay to show the issue
5344 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5345 (overlay-put ov 'before-string
5346 (concat
5347 (org-add-props
5348 (format "%-43s" (concat " " issue))
5350 'face face)
5351 "\n"))
5352 (overlay-put ov 'evaporate t)))))
5354 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5355 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5356 (catch 'exit
5357 (unless ok-list
5358 ;; there are no OK times for gaps...
5359 (throw 'exit nil))
5360 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5361 ;; This is more than 24 hours, so it is OK.
5362 ;; because we have at least one OK time, that must be in the
5363 ;; 24 hour interval.
5364 (throw 'exit t))
5365 ;; We have a shorter gap.
5366 ;; Now we have to get the minute of the day when these times are
5367 (let* ((t1dec (decode-time (seconds-to-time t1)))
5368 (t2dec (decode-time (seconds-to-time t2)))
5369 ;; compute the minute on the day
5370 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5371 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5372 (when (< min2 min1)
5373 ;; if min2 is smaller than min1, this means it is on the next day.
5374 ;; Wrap it to after midnight.
5375 (setq min2 (+ min2 1440)))
5376 ;; Now check if any of the OK times is in the gap
5377 (mapc (lambda (x)
5378 ;; Wrap the time to after midnight if necessary
5379 (if (< x min1) (setq x (+ x 1440)))
5380 ;; Check if in interval
5381 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5382 ok-list)
5383 ;; Nope, this gap is not OK
5384 nil)))
5386 (defun org-agenda-get-deadlines ()
5387 "Return the deadline information for agenda display."
5388 (let* ((props (list 'mouse-face 'highlight
5389 'org-not-done-regexp org-not-done-regexp
5390 'org-todo-regexp org-todo-regexp
5391 'org-complex-heading-regexp org-complex-heading-regexp
5392 'help-echo
5393 (format "mouse-2 or RET jump to org file %s"
5394 (abbreviate-file-name buffer-file-name))))
5395 (regexp org-deadline-time-regexp)
5396 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5397 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5398 d2 diff dfrac wdays pos pos1 category org-category-pos
5399 tags suppress-prewarning ee txt head face s todo-state
5400 show-all upcomingp donep timestr)
5401 (goto-char (point-min))
5402 (while (re-search-forward regexp nil t)
5403 (setq suppress-prewarning nil)
5404 (catch :skip
5405 (org-agenda-skip)
5406 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5407 (save-match-data
5408 (string-match org-scheduled-time-regexp
5409 (buffer-substring (point-at-bol)
5410 (point-at-eol)))))
5411 (setq suppress-prewarning
5412 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5413 org-agenda-skip-deadline-prewarning-if-scheduled
5414 0)))
5415 (setq s (match-string 1)
5416 txt nil
5417 pos (1- (match-beginning 1))
5418 todo-state (save-match-data (org-get-todo-state))
5419 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5420 (member todo-state
5421 org-agenda-repeating-timestamp-show-all))
5422 d2 (org-time-string-to-absolute
5423 (match-string 1) d1 'past show-all
5424 (current-buffer) pos)
5425 diff (- d2 d1)
5426 wdays (if suppress-prewarning
5427 (let ((org-deadline-warning-days suppress-prewarning))
5428 (org-get-wdays s))
5429 (org-get-wdays s))
5430 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5431 upcomingp (and todayp (> diff 0)))
5432 ;; When to show a deadline in the calendar:
5433 ;; If the expiration is within wdays warning time.
5434 ;; Past-due deadlines are only shown on the current date
5435 (if (and (or (and (<= diff wdays)
5436 (and todayp (not org-agenda-only-exact-dates)))
5437 (= diff 0)))
5438 (save-excursion
5439 ;; (setq todo-state (org-get-todo-state))
5440 (setq donep (member todo-state org-done-keywords))
5441 (if (and donep
5442 (or org-agenda-skip-deadline-if-done
5443 (not (= diff 0))))
5444 (setq txt nil)
5445 (setq category (org-get-category)
5446 org-category-pos (get-text-property (point) 'org-category-position))
5447 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5448 (setq txt org-agenda-no-heading-message)
5449 (goto-char (match-end 0))
5450 (setq pos1 (match-beginning 0))
5451 (setq tags (org-get-tags-at pos1))
5452 (setq head (buffer-substring-no-properties
5453 (point)
5454 (progn (skip-chars-forward "^\r\n")
5455 (point))))
5456 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5457 (setq timestr
5458 (concat (substring s (match-beginning 1)) " "))
5459 (setq timestr 'time))
5460 (setq txt (org-agenda-format-item
5461 (if (= diff 0)
5462 (car org-agenda-deadline-leaders)
5463 (if (functionp
5464 (nth 1 org-agenda-deadline-leaders))
5465 (funcall
5466 (nth 1 org-agenda-deadline-leaders)
5467 diff date)
5468 (format (nth 1 org-agenda-deadline-leaders)
5469 diff)))
5470 head category tags
5471 (if (not (= diff 0)) nil timestr)))))
5472 (when txt
5473 (setq face (org-agenda-deadline-face dfrac))
5474 (org-add-props txt props
5475 'org-marker (org-agenda-new-marker pos)
5476 'org-hd-marker (org-agenda-new-marker pos1)
5477 'priority (+ (- diff)
5478 (org-get-priority txt))
5479 'org-category category
5480 'org-category-position org-category-pos
5481 'todo-state todo-state
5482 'type (if upcomingp "upcoming-deadline" "deadline")
5483 'date (if upcomingp date d2)
5484 'face (if donep 'org-agenda-done face)
5485 'undone-face face 'done-face 'org-agenda-done)
5486 (push txt ee))))))
5487 (nreverse ee)))
5489 (defun org-agenda-deadline-face (fraction)
5490 "Return the face to displaying a deadline item.
5491 FRACTION is what fraction of the head-warning time has passed."
5492 (let ((faces org-agenda-deadline-faces) f)
5493 (catch 'exit
5494 (while (setq f (pop faces))
5495 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5497 (defun org-agenda-get-scheduled (&optional deadline-results)
5498 "Return the scheduled information for agenda display."
5499 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5500 'org-todo-regexp org-todo-regexp
5501 'org-complex-heading-regexp org-complex-heading-regexp
5502 'done-face 'org-agenda-done
5503 'mouse-face 'highlight
5504 'help-echo
5505 (format "mouse-2 or RET jump to org file %s"
5506 (abbreviate-file-name buffer-file-name))))
5507 (regexp org-scheduled-time-regexp)
5508 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5509 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5511 (deadline-position-alist
5512 (mapcar (lambda (a) (and (setq mm (get-text-property
5513 0 'org-hd-marker a))
5514 (cons (marker-position mm) a)))
5515 deadline-results))
5516 d2 diff pos pos1 category org-category-pos tags donep
5517 ee txt head pastschedp todo-state face timestr s habitp show-all)
5518 (goto-char (point-min))
5519 (while (re-search-forward regexp nil t)
5520 (catch :skip
5521 (org-agenda-skip)
5522 (setq s (match-string 1)
5523 txt nil
5524 pos (1- (match-beginning 1))
5525 todo-state (save-match-data (org-get-todo-state))
5526 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5527 (member todo-state
5528 org-agenda-repeating-timestamp-show-all))
5529 d2 (org-time-string-to-absolute
5530 (match-string 1) d1 'past show-all
5531 (current-buffer) pos)
5532 diff (- d2 d1))
5533 (setq pastschedp (and todayp (< diff 0)))
5534 ;; When to show a scheduled item in the calendar:
5535 ;; If it is on or past the date.
5536 (when (or (and (< diff 0)
5537 (< (abs diff) org-scheduled-past-days)
5538 (and todayp (not org-agenda-only-exact-dates)))
5539 (= diff 0))
5540 (save-excursion
5541 (setq donep (member todo-state org-done-keywords))
5542 (if (and donep
5543 (or org-agenda-skip-scheduled-if-done
5544 (not (= diff 0))
5545 (and (functionp 'org-is-habit-p)
5546 (org-is-habit-p))))
5547 (setq txt nil)
5548 (setq habitp (and (functionp 'org-is-habit-p)
5549 (org-is-habit-p)))
5550 (setq category (org-get-category)
5551 org-category-pos (get-text-property (point) 'org-category-position))
5552 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5553 (setq txt org-agenda-no-heading-message)
5554 (goto-char (match-end 0))
5555 (setq pos1 (match-beginning 0))
5556 (if habitp
5557 (if (or (not org-habit-show-habits)
5558 (and (not todayp)
5559 org-habit-show-habits-only-for-today))
5560 (throw :skip nil))
5561 (if (and
5562 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5563 (and org-agenda-skip-scheduled-if-deadline-is-shown
5564 pastschedp))
5565 (setq mm (assoc pos1 deadline-position-alist)))
5566 (throw :skip nil)))
5567 (setq tags (org-get-tags-at))
5568 (setq head (buffer-substring-no-properties
5569 (point)
5570 (progn (skip-chars-forward "^\r\n") (point))))
5571 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5572 (setq timestr
5573 (concat (substring s (match-beginning 1)) " "))
5574 (setq timestr 'time))
5575 (setq txt (org-agenda-format-item
5576 (if (= diff 0)
5577 (car org-agenda-scheduled-leaders)
5578 (format (nth 1 org-agenda-scheduled-leaders)
5579 (- 1 diff)))
5580 head category tags
5581 (if (not (= diff 0)) nil timestr)
5582 nil habitp))))
5583 (when txt
5584 (setq face
5585 (cond
5586 ((and (not habitp) pastschedp)
5587 'org-scheduled-previously)
5588 (todayp 'org-scheduled-today)
5589 (t 'org-scheduled))
5590 habitp (and habitp (org-habit-parse-todo)))
5591 (org-add-props txt props
5592 'undone-face face
5593 'face (if donep 'org-agenda-done face)
5594 'org-marker (org-agenda-new-marker pos)
5595 'org-hd-marker (org-agenda-new-marker pos1)
5596 'type (if pastschedp "past-scheduled" "scheduled")
5597 'date (if pastschedp d2 date)
5598 'priority (if habitp
5599 (org-habit-get-priority habitp)
5600 (+ 94 (- 5 diff) (org-get-priority txt)))
5601 'org-category category
5602 'org-category-position org-category-pos
5603 'org-habit-p habitp
5604 'todo-state todo-state)
5605 (push txt ee))))))
5606 (nreverse ee)))
5608 (defun org-agenda-get-blocks ()
5609 "Return the date-range information for agenda display."
5610 (let* ((props (list 'face nil
5611 'org-not-done-regexp org-not-done-regexp
5612 'org-todo-regexp org-todo-regexp
5613 'org-complex-heading-regexp org-complex-heading-regexp
5614 'mouse-face 'highlight
5615 'help-echo
5616 (format "mouse-2 or RET jump to org file %s"
5617 (abbreviate-file-name buffer-file-name))))
5618 (regexp org-tr-regexp)
5619 (d0 (calendar-absolute-from-gregorian date))
5620 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5621 todo-state tags pos head donep)
5622 (goto-char (point-min))
5623 (while (re-search-forward regexp nil t)
5624 (catch :skip
5625 (org-agenda-skip)
5626 (setq pos (point))
5627 (let ((start-time (match-string 1))
5628 (end-time (match-string 2)))
5629 (setq s1 (match-string 1)
5630 s2 (match-string 2)
5631 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5632 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5633 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5634 ;; Only allow days between the limits, because the normal
5635 ;; date stamps will catch the limits.
5636 (save-excursion
5637 (setq todo-state (org-get-todo-state))
5638 (setq donep (member todo-state org-done-keywords))
5639 (if (and donep org-agenda-skip-timestamp-if-done)
5640 (throw :skip t))
5641 (setq marker (org-agenda-new-marker (point)))
5642 (setq category (org-get-category)
5643 org-category-pos (get-text-property (point) 'org-category-position))
5644 (if (not (re-search-backward org-outline-regexp-bol nil t))
5645 (setq txt org-agenda-no-heading-message)
5646 (goto-char (match-beginning 0))
5647 (setq hdmarker (org-agenda-new-marker (point)))
5648 (setq tags (org-get-tags-at))
5649 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5650 (setq head (match-string 1))
5651 (let ((remove-re
5652 (if org-agenda-remove-timeranges-from-blocks
5653 (concat
5654 "<" (regexp-quote s1) ".*?>"
5655 "--"
5656 "<" (regexp-quote s2) ".*?>")
5657 nil)))
5658 (setq txt (org-agenda-format-item
5659 (format
5660 (nth (if (= d1 d2) 0 1)
5661 org-agenda-timerange-leaders)
5662 (1+ (- d0 d1)) (1+ (- d2 d1)))
5663 head category tags
5664 (cond ((and (= d1 d0) (= d2 d0))
5665 (concat "<" start-time ">--<" end-time ">"))
5666 ((= d1 d0)
5667 (concat "<" start-time ">"))
5668 ((= d2 d0)
5669 (concat "<" end-time ">"))
5670 (t nil))
5671 remove-re))))
5672 (org-add-props txt props
5673 'org-marker marker 'org-hd-marker hdmarker
5674 'type "block" 'date date
5675 'todo-state todo-state
5676 'priority (org-get-priority txt) 'org-category category
5677 'org-category-position org-category-pos)
5678 (push txt ee))))
5679 (goto-char pos)))
5680 ;; Sort the entries by expiration date.
5681 (nreverse ee)))
5683 ;;; Agenda presentation and sorting
5685 (defvar org-prefix-has-time nil
5686 "A flag, set by `org-compile-prefix-format'.
5687 The flag is set if the currently compiled format contains a `%t'.")
5688 (defvar org-prefix-has-tag nil
5689 "A flag, set by `org-compile-prefix-format'.
5690 The flag is set if the currently compiled format contains a `%T'.")
5691 (defvar org-prefix-has-effort nil
5692 "A flag, set by `org-compile-prefix-format'.
5693 The flag is set if the currently compiled format contains a `%e'.")
5694 (defvar org-prefix-category-length nil
5695 "Used by `org-compile-prefix-format' to remember the category field width.")
5696 (defvar org-prefix-category-max-length nil
5697 "Used by `org-compile-prefix-format' to remember the category field width.")
5699 (defun org-agenda-get-category-icon (category)
5700 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5701 (dolist (entry org-agenda-category-icon-alist)
5702 (when (org-string-match-p (car entry) category)
5703 (if (listp (cadr entry))
5704 (return (cadr entry))
5705 (return (apply 'create-image (cdr entry)))))))
5707 (defun org-agenda-format-item (extra txt &optional category tags dotime
5708 remove-re habitp)
5709 "Format TXT to be inserted into the agenda buffer.
5710 In particular, it adds the prefix and corresponding text properties. EXTRA
5711 must be a string and replaces the `%s' specifier in the prefix format.
5712 CATEGORY (string, symbol or nil) may be used to overrule the default
5713 category taken from local variable or file name. It will replace the `%c'
5714 specifier in the format. DOTIME, when non-nil, indicates that a
5715 time-of-day should be extracted from TXT for sorting of this entry, and for
5716 the `%t' specifier in the format. When DOTIME is a string, this string is
5717 searched for a time before TXT is. TAGS can be the tags of the headline.
5718 Any match of REMOVE-RE will be removed from TXT."
5719 ;; We keep the org-prefix-* variable values along with a compiled
5720 ;; formatter, so that multiple agendas existing at the same time, do
5721 ;; not step on each other toes.
5723 ;; It was inconvenient to make these variables buffer local in
5724 ;; Agenda buffers, because this function expects to be called with
5725 ;; the buffer where item comes from being current, and not agenda
5726 ;; buffer
5727 (let* ((org-prefix-format-compiled
5728 (with-current-buffer org-agenda-buffer
5729 org-prefix-format-compiled))
5730 (bindings (car org-prefix-format-compiled))
5731 (formatter (cadr org-prefix-format-compiled)))
5732 (loop for (var value) in bindings
5733 do (set var value))
5734 (save-match-data
5735 ;; Diary entries sometimes have extra whitespace at the beginning
5736 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5738 ;; Fix the tags part in txt
5739 (setq txt (org-agenda-fix-displayed-tags
5740 txt tags
5741 org-agenda-show-inherited-tags
5742 org-agenda-hide-tags-regexp))
5743 (let* ((category (or category
5744 (if (stringp org-category)
5745 org-category
5746 (and org-category (symbol-name org-category)))
5747 (if buffer-file-name
5748 (file-name-sans-extension
5749 (file-name-nondirectory buffer-file-name))
5750 "")))
5751 (category-icon (org-agenda-get-category-icon category))
5752 (category-icon (if category-icon
5753 (propertize " " 'display category-icon)
5754 ""))
5755 ;; time, tag, effort are needed for the eval of the prefix format
5756 (tag (if tags (nth (1- (length tags)) tags) ""))
5757 time effort neffort
5758 (ts (if dotime (concat
5759 (if (stringp dotime) dotime "")
5760 (and org-agenda-search-headline-for-time txt))))
5761 (time-of-day (and dotime (org-get-time-of-day ts)))
5762 stamp plain s0 s1 s2 rtn srp l
5763 duration thecategory)
5764 (and (eq major-mode 'org-mode) buffer-file-name
5765 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5766 (when (and dotime time-of-day)
5767 ;; Extract starting and ending time and move them to prefix
5768 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5769 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5770 (setq s0 (match-string 0 ts)
5771 srp (and stamp (match-end 3))
5772 s1 (match-string (if plain 1 2) ts)
5773 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5775 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5776 ;; them, we might want to remove them there to avoid duplication.
5777 ;; The user can turn this off with a variable.
5778 (if (and org-prefix-has-time
5779 org-agenda-remove-times-when-in-prefix (or stamp plain)
5780 (string-match (concat (regexp-quote s0) " *") txt)
5781 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5782 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5783 (= (match-beginning 0) 0)
5785 (setq txt (replace-match "" nil nil txt))))
5786 ;; Normalize the time(s) to 24 hour
5787 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5788 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5790 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5791 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5792 (setq s2
5793 (org-minutes-to-hh:mm-string
5794 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5796 ;; Compute the duration
5797 (when s2
5798 (setq duration (- (org-hh:mm-string-to-minutes s2)
5799 (org-hh:mm-string-to-minutes s1)))))
5801 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5802 txt)
5803 ;; Tags are in the string
5804 (if (or (eq org-agenda-remove-tags t)
5805 (and org-agenda-remove-tags
5806 org-prefix-has-tag))
5807 (setq txt (replace-match "" t t txt))
5808 (setq txt (replace-match
5809 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5810 (match-string 2 txt))
5811 t t txt))))
5812 (when (eq major-mode 'org-mode)
5813 (setq effort
5814 (condition-case nil
5815 (org-get-effort
5816 (or (get-text-property 0 'org-hd-marker txt)
5817 (get-text-property 0 'org-marker txt)))
5818 (error nil)))
5819 (when effort
5820 (setq neffort (org-duration-string-to-minutes effort)
5821 effort (setq effort (concat "[" effort "]")))))
5822 ;; prevent erroring out with %e format when there is no effort
5823 (or effort (setq effort ""))
5825 (when remove-re
5826 (while (string-match remove-re txt)
5827 (setq txt (replace-match "" t t txt))))
5829 ;; Set org-heading property on `txt' to mark the start of the
5830 ;; heading.
5831 (add-text-properties 0 (length txt) '(org-heading t) txt)
5833 ;; Prepare the variables needed in the eval of the compiled format
5834 (setq time (cond (s2 (concat
5835 (org-agenda-time-of-day-to-ampm-maybe s1)
5836 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5837 (if org-agenda-timegrid-use-ampm " ")))
5838 (s1 (concat
5839 (org-agenda-time-of-day-to-ampm-maybe s1)
5840 (if org-agenda-timegrid-use-ampm
5841 "........ "
5842 "......")))
5843 (t ""))
5844 extra (or (and (not habitp) extra) "")
5845 category (if (symbolp category) (symbol-name category) category)
5846 thecategory (copy-sequence category))
5847 (if (string-match org-bracket-link-regexp category)
5848 (progn
5849 (setq l (if (match-end 3)
5850 (- (match-end 3) (match-beginning 3))
5851 (- (match-end 1) (match-beginning 1))))
5852 (when (< l (or org-prefix-category-length 0))
5853 (setq category (copy-sequence category))
5854 (org-add-props category nil
5855 'extra-space (make-string
5856 (- org-prefix-category-length l 1) ?\ ))))
5857 (if (and org-prefix-category-max-length
5858 (>= (length category) org-prefix-category-max-length))
5859 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5860 ;; Evaluate the compiled format
5861 (setq rtn (concat (eval formatter) txt))
5863 ;; And finally add the text properties
5864 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5865 (org-add-props rtn nil
5866 'org-category (if thecategory (downcase thecategory) category)
5867 'tags (mapcar 'org-downcase-keep-props tags)
5868 'org-highest-priority org-highest-priority
5869 'org-lowest-priority org-lowest-priority
5870 'time-of-day time-of-day
5871 'duration duration
5872 'effort effort
5873 'effort-minutes neffort
5874 'txt txt
5875 'time time
5876 'extra extra
5877 'format org-prefix-format-compiled
5878 'dotime dotime)))))
5880 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5881 "Remove tags string from TXT, and add a modified list of tags.
5882 The modified list may contain inherited tags, and tags matched by
5883 `org-agenda-hide-tags-regexp' will be removed."
5884 (when (or add-inherited hide-re)
5885 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5886 (setq txt (substring txt 0 (match-beginning 0))))
5887 (setq tags
5888 (delq nil
5889 (mapcar (lambda (tg)
5890 (if (or (and hide-re (string-match hide-re tg))
5891 (and (not add-inherited)
5892 (get-text-property 0 'inherited tg)))
5894 tg))
5895 tags)))
5896 (when tags
5897 (let ((have-i (get-text-property 0 'inherited (car tags)))
5899 (setq txt (concat txt " :"
5900 (mapconcat
5901 (lambda (x)
5902 (setq i (get-text-property 0 'inherited x))
5903 (if (and have-i (not i))
5904 (progn
5905 (setq have-i nil)
5906 (concat ":" x))
5908 tags ":")
5909 (if have-i "::" ":"))))))
5910 txt)
5912 (defun org-downcase-keep-props (s)
5913 (let ((props (text-properties-at 0 s)))
5914 (setq s (downcase s))
5915 (add-text-properties 0 (length s) props s)
5918 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5919 (defvar org-agenda-sorting-strategy-selected nil)
5921 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5922 (catch 'exit
5923 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5924 ((and todayp (member 'today (car org-agenda-time-grid))))
5925 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5926 ((member 'weekly (car org-agenda-time-grid)))
5927 (t (throw 'exit list)))
5928 (let* ((have (delq nil (mapcar
5929 (lambda (x) (get-text-property 1 'time-of-day x))
5930 list)))
5931 (string (nth 1 org-agenda-time-grid))
5932 (gridtimes (nth 2 org-agenda-time-grid))
5933 (req (car org-agenda-time-grid))
5934 (remove (member 'remove-match req))
5935 new time)
5936 (if (and (member 'require-timed req) (not have))
5937 ;; don't show empty grid
5938 (throw 'exit list))
5939 (while (setq time (pop gridtimes))
5940 (unless (and remove (member time have))
5941 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5942 (push (org-agenda-format-item
5943 nil string "" nil
5944 (concat (substring time 0 -2) ":" (substring time -2)))
5945 new)
5946 (put-text-property
5947 2 (length (car new)) 'face 'org-time-grid (car new))))
5948 (when (and todayp org-agenda-show-current-time-in-grid)
5949 (push (org-agenda-format-item
5951 org-agenda-current-time-string
5952 "" nil
5953 (format-time-string "%H:%M "))
5954 new)
5955 (put-text-property
5956 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5958 (if (member 'time-up org-agenda-sorting-strategy-selected)
5959 (append new list)
5960 (append list new)))))
5962 (defun org-compile-prefix-format (key)
5963 "Compile the prefix format into a Lisp form that can be evaluated.
5964 The resulting form and associated variable bindings is returned
5965 and stored in the variable `org-prefix-format-compiled'."
5966 (setq org-prefix-has-time nil org-prefix-has-tag nil
5967 org-prefix-category-length nil
5968 org-prefix-has-effort nil)
5969 (let ((s (cond
5970 ((stringp org-agenda-prefix-format)
5971 org-agenda-prefix-format)
5972 ((assq key org-agenda-prefix-format)
5973 (cdr (assq key org-agenda-prefix-format)))
5974 (t " %-12:c%?-12t% s")))
5975 (start 0)
5976 varform vars var e c f opt)
5977 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5978 s start)
5979 (setq var (or (cdr (assoc (match-string 4 s)
5980 '(("c" . category) ("t" . time) ("s" . extra)
5981 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5982 'eval)
5983 c (or (match-string 3 s) "")
5984 opt (match-beginning 1)
5985 start (1+ (match-beginning 0)))
5986 (if (equal var 'time) (setq org-prefix-has-time t))
5987 (if (equal var 'tag) (setq org-prefix-has-tag t))
5988 (if (equal var 'effort) (setq org-prefix-has-effort t))
5989 (setq f (concat "%" (match-string 2 s) "s"))
5990 (when (equal var 'category)
5991 (setq org-prefix-category-length
5992 (floor (abs (string-to-number (match-string 2 s)))))
5993 (setq org-prefix-category-max-length
5994 (let ((x (match-string 2 s)))
5995 (save-match-data
5996 (if (string-match "\\.[0-9]+" x)
5997 (string-to-number (substring (match-string 0 x) 1)))))))
5998 (if (eq var 'eval)
5999 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6000 (if opt
6001 (setq varform
6002 `(if (equal "" ,var)
6004 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6005 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6006 (setq s (replace-match "%s" t nil s))
6007 (push varform vars))
6008 (setq vars (nreverse vars))
6009 (with-current-buffer org-agenda-buffer
6010 (setq org-prefix-format-compiled
6011 (list
6012 `((org-prefix-has-time ,org-prefix-has-time)
6013 (org-prefix-has-tag ,org-prefix-has-tag)
6014 (org-prefix-category-length ,org-prefix-category-length)
6015 (org-prefix-has-effort ,org-prefix-has-effort))
6016 `(format ,s ,@vars))))))
6018 (defun org-set-sorting-strategy (key)
6019 (if (symbolp (car org-agenda-sorting-strategy))
6020 ;; the old format
6021 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6022 (setq org-agenda-sorting-strategy-selected
6023 (or (cdr (assq key org-agenda-sorting-strategy))
6024 (cdr (assq 'agenda org-agenda-sorting-strategy))
6025 '(time-up category-keep priority-down)))))
6027 (defun org-get-time-of-day (s &optional string mod24)
6028 "Check string S for a time of day.
6029 If found, return it as a military time number between 0 and 2400.
6030 If not found, return nil.
6031 The optional STRING argument forces conversion into a 5 character wide string
6032 HH:MM."
6033 (save-match-data
6034 (when
6035 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6036 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6037 (let* ((h (string-to-number (match-string 1 s)))
6038 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6039 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6040 (am-p (equal ampm "am"))
6041 (h1 (cond ((not ampm) h)
6042 ((= h 12) (if am-p 0 12))
6043 (t (+ h (if am-p 0 12)))))
6044 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6045 (mod h1 24) h1))
6046 (t0 (+ (* 100 h2) m))
6047 (t1 (concat (if (>= h1 24) "+" " ")
6048 (if (and org-agenda-time-leading-zero
6049 (< t0 1000)) "0" "")
6050 (if (< t0 100) "0" "")
6051 (if (< t0 10) "0" "")
6052 (int-to-string t0))))
6053 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6055 (defvar org-agenda-before-sorting-filter-function nil
6056 "Function to be applied to agenda items prior to sorting.
6057 Prior to sorting also means just before they are inserted into the agenda.
6059 To aid sorting, you may revisit the original entries and add more text
6060 properties which will later be used by the sorting functions.
6062 The function should take a string argument, an agenda line.
6063 It has access to the text properties in that line, which contain among
6064 other things, the property `org-hd-marker' that points to the entry
6065 where the line comes from. Note that not all lines going into the agenda
6066 have this property, only most.
6068 The function should return the modified string. It is probably best
6069 to ONLY change text properties.
6071 You can also use this function as a filter, by returning nil for lines
6072 you don't want to have in the agenda at all. For this application, you
6073 could bind the variable in the options section of a custom command.")
6075 (defun org-finalize-agenda-entries (list &optional nosort)
6076 "Sort and concatenate the agenda items."
6077 (setq list (mapcar 'org-agenda-highlight-todo list))
6078 (if nosort
6079 list
6080 (when org-agenda-before-sorting-filter-function
6081 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6082 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6084 (defun org-agenda-highlight-todo (x)
6085 (let ((org-done-keywords org-done-keywords-for-agenda)
6086 (case-fold-search nil)
6088 (if (eq x 'line)
6089 (save-excursion
6090 (beginning-of-line 1)
6091 (setq re (org-get-at-bol 'org-todo-regexp))
6092 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6093 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6094 (add-text-properties (match-beginning 0) (match-end 1)
6095 (list 'face (org-get-todo-face 1)))
6096 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6097 (delete-region (match-beginning 1) (1- (match-end 0)))
6098 (goto-char (match-beginning 1))
6099 (insert (format org-agenda-todo-keyword-format s)))))
6100 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6101 (setq re (get-text-property 0 'org-todo-regexp x))
6102 (when (and re
6103 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6104 x (or pl 0)) pl))
6105 (add-text-properties
6106 (or (match-end 1) (match-end 0)) (match-end 0)
6107 (list 'face (org-get-todo-face (match-string 2 x)))
6109 (when (match-end 1)
6110 (setq x (concat (substring x 0 (match-end 1))
6111 (format org-agenda-todo-keyword-format
6112 (match-string 2 x))
6113 (org-add-props " " (text-properties-at 0 x))
6114 (substring x (match-end 3)))))))
6115 x)))
6117 (defsubst org-cmp-priority (a b)
6118 "Compare the priorities of string A and B."
6119 (let ((pa (or (get-text-property 1 'priority a) 0))
6120 (pb (or (get-text-property 1 'priority b) 0)))
6121 (cond ((> pa pb) +1)
6122 ((< pa pb) -1)
6123 (t nil))))
6125 (defsubst org-cmp-effort (a b)
6126 "Compare the effort values of string A and B."
6127 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6128 (ea (or (get-text-property 1 'effort-minutes a) def))
6129 (eb (or (get-text-property 1 'effort-minutes b) def)))
6130 (cond ((> ea eb) +1)
6131 ((< ea eb) -1)
6132 (t nil))))
6134 (defsubst org-cmp-category (a b)
6135 "Compare the string values of categories of strings A and B."
6136 (let ((ca (or (get-text-property 1 'org-category a) ""))
6137 (cb (or (get-text-property 1 'org-category b) "")))
6138 (cond ((string-lessp ca cb) -1)
6139 ((string-lessp cb ca) +1)
6140 (t nil))))
6142 (defsubst org-cmp-todo-state (a b)
6143 "Compare the todo states of strings A and B."
6144 (let* ((ma (or (get-text-property 1 'org-marker a)
6145 (get-text-property 1 'org-hd-marker a)))
6146 (mb (or (get-text-property 1 'org-marker b)
6147 (get-text-property 1 'org-hd-marker b)))
6148 (fa (and ma (marker-buffer ma)))
6149 (fb (and mb (marker-buffer mb)))
6150 (todo-kwds
6151 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6152 (and fb (with-current-buffer fb org-todo-keywords-1))))
6153 (ta (or (get-text-property 1 'todo-state a) ""))
6154 (tb (or (get-text-property 1 'todo-state b) ""))
6155 (la (- (length (member ta todo-kwds))))
6156 (lb (- (length (member tb todo-kwds))))
6157 (donepa (member ta org-done-keywords-for-agenda))
6158 (donepb (member tb org-done-keywords-for-agenda)))
6159 (cond ((and donepa (not donepb)) -1)
6160 ((and (not donepa) donepb) +1)
6161 ((< la lb) -1)
6162 ((< lb la) +1)
6163 (t nil))))
6165 (defsubst org-cmp-alpha (a b)
6166 "Compare the headlines, alphabetically."
6167 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6168 (plb (text-property-any 0 (length b) 'org-heading t b))
6169 (ta (and pla (substring a pla)))
6170 (tb (and plb (substring b plb))))
6171 (when pla
6172 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6173 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6174 (setq ta (substring ta (match-end 0))))
6175 (setq ta (downcase ta)))
6176 (when plb
6177 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6178 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6179 (setq tb (substring tb (match-end 0))))
6180 (setq tb (downcase tb)))
6181 (cond ((not ta) +1)
6182 ((not tb) -1)
6183 ((string-lessp ta tb) -1)
6184 ((string-lessp tb ta) +1)
6185 (t nil))))
6187 (defsubst org-cmp-tag (a b)
6188 "Compare the string values of the first tags of A and B."
6189 (let ((ta (car (last (get-text-property 1 'tags a))))
6190 (tb (car (last (get-text-property 1 'tags b)))))
6191 (cond ((not ta) +1)
6192 ((not tb) -1)
6193 ((string-lessp ta tb) -1)
6194 ((string-lessp tb ta) +1)
6195 (t nil))))
6197 (defsubst org-cmp-time (a b)
6198 "Compare the time-of-day values of strings A and B."
6199 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6200 (ta (or (get-text-property 1 'time-of-day a) def))
6201 (tb (or (get-text-property 1 'time-of-day b) def)))
6202 (cond ((< ta tb) -1)
6203 ((< tb ta) +1)
6204 (t nil))))
6206 (defsubst org-cmp-habit-p (a b)
6207 "Compare the todo states of strings A and B."
6208 (let ((ha (get-text-property 1 'org-habit-p a))
6209 (hb (get-text-property 1 'org-habit-p b)))
6210 (cond ((and ha (not hb)) -1)
6211 ((and (not ha) hb) +1)
6212 (t nil))))
6214 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6216 (defun org-entries-lessp (a b)
6217 "Predicate for sorting agenda entries."
6218 ;; The following variables will be used when the form is evaluated.
6219 ;; So even though the compiler complains, keep them.
6220 (let* ((ss org-agenda-sorting-strategy-selected)
6221 (time-up (and (org-em 'time-up 'time-down ss)
6222 (org-cmp-time a b)))
6223 (time-down (if time-up (- time-up) nil))
6224 (priority-up (and (org-em 'priority-up 'priority-down ss)
6225 (org-cmp-priority a b)))
6226 (priority-down (if priority-up (- priority-up) nil))
6227 (effort-up (and (org-em 'effort-up 'effort-down ss)
6228 (org-cmp-effort a b)))
6229 (effort-down (if effort-up (- effort-up) nil))
6230 (category-up (and (or (org-em 'category-up 'category-down ss)
6231 (memq 'category-keep ss))
6232 (org-cmp-category a b)))
6233 (category-down (if category-up (- category-up) nil))
6234 (category-keep (if category-up +1 nil))
6235 (tag-up (and (org-em 'tag-up 'tag-down ss)
6236 (org-cmp-tag a b)))
6237 (tag-down (if tag-up (- tag-up) nil))
6238 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6239 (org-cmp-todo-state a b)))
6240 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6241 (habit-up (and (org-em 'habit-up 'habit-down ss)
6242 (org-cmp-habit-p a b)))
6243 (habit-down (if habit-up (- habit-up) nil))
6244 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6245 (org-cmp-alpha a b)))
6246 (alpha-down (if alpha-up (- alpha-up) nil))
6247 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6248 user-defined-up user-defined-down)
6249 (if (and need-user-cmp org-agenda-cmp-user-defined
6250 (functionp org-agenda-cmp-user-defined))
6251 (setq user-defined-up
6252 (funcall org-agenda-cmp-user-defined a b)
6253 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6254 (cdr (assoc
6255 (eval (cons 'or org-agenda-sorting-strategy-selected))
6256 '((-1 . t) (1 . nil) (nil . nil))))))
6258 ;;; Agenda restriction lock
6260 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6261 "Overlay to mark the headline to which agenda commands are restricted.")
6262 (overlay-put org-agenda-restriction-lock-overlay
6263 'face 'org-agenda-restriction-lock)
6264 (overlay-put org-agenda-restriction-lock-overlay
6265 'help-echo "Agendas are currently limited to this subtree.")
6266 (org-detach-overlay org-agenda-restriction-lock-overlay)
6268 (defun org-agenda-set-restriction-lock (&optional type)
6269 "Set restriction lock for agenda, to current subtree or file.
6270 Restriction will be the file if TYPE is `file', or if type is the
6271 universal prefix '(4), or if the cursor is before the first headline
6272 in the file. Otherwise, restriction will be to the current subtree."
6273 (interactive "P")
6274 (and (equal type '(4)) (setq type 'file))
6275 (setq type (cond
6276 (type type)
6277 ((org-at-heading-p) 'subtree)
6278 ((condition-case nil (org-back-to-heading t) (error nil))
6279 'subtree)
6280 (t 'file)))
6281 (if (eq type 'subtree)
6282 (progn
6283 (setq org-agenda-restrict t)
6284 (setq org-agenda-overriding-restriction 'subtree)
6285 (put 'org-agenda-files 'org-restrict
6286 (list (buffer-file-name (buffer-base-buffer))))
6287 (org-back-to-heading t)
6288 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6289 (move-marker org-agenda-restrict-begin (point))
6290 (move-marker org-agenda-restrict-end
6291 (save-excursion (org-end-of-subtree t)))
6292 (message "Locking agenda restriction to subtree"))
6293 (put 'org-agenda-files 'org-restrict
6294 (list (buffer-file-name (buffer-base-buffer))))
6295 (setq org-agenda-restrict nil)
6296 (setq org-agenda-overriding-restriction 'file)
6297 (move-marker org-agenda-restrict-begin nil)
6298 (move-marker org-agenda-restrict-end nil)
6299 (message "Locking agenda restriction to file"))
6300 (setq current-prefix-arg nil)
6301 (org-agenda-maybe-redo))
6303 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6304 "Remove the agenda restriction lock."
6305 (interactive "P")
6306 (org-detach-overlay org-agenda-restriction-lock-overlay)
6307 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6308 (setq org-agenda-overriding-restriction nil)
6309 (setq org-agenda-restrict nil)
6310 (put 'org-agenda-files 'org-restrict nil)
6311 (move-marker org-agenda-restrict-begin nil)
6312 (move-marker org-agenda-restrict-end nil)
6313 (setq current-prefix-arg nil)
6314 (message "Agenda restriction lock removed")
6315 (or noupdate (org-agenda-maybe-redo)))
6317 (defun org-agenda-maybe-redo ()
6318 "If there is any window showing the agenda view, update it."
6319 (let ((w (get-buffer-window org-agenda-buffer-name t))
6320 (w0 (selected-window)))
6321 (when w
6322 (select-window w)
6323 (org-agenda-redo)
6324 (select-window w0)
6325 (if org-agenda-overriding-restriction
6326 (message "Agenda view shifted to new %s restriction"
6327 org-agenda-overriding-restriction)
6328 (message "Agenda restriction lock removed")))))
6330 ;;; Agenda commands
6332 (defun org-agenda-check-type (error &rest types)
6333 "Check if agenda buffer is of allowed type.
6334 If ERROR is non-nil, throw an error, otherwise just return nil."
6335 (if (memq org-agenda-type types)
6337 (if error
6338 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6339 nil)))
6342 (defun org-agenda-Quit (&optional arg)
6343 "Exit agenda by removing the window or the buffer"
6344 (interactive)
6345 (if org-agenda-columns-active
6346 (org-columns-quit)
6347 (let ((buf (current-buffer)))
6348 (if (eq org-agenda-window-setup 'other-frame)
6349 (progn
6350 (kill-buffer buf)
6351 (org-agenda-reset-markers)
6352 (org-columns-remove-overlays)
6353 (setq org-agenda-archives-mode nil)
6354 (delete-frame))
6355 (and (not (eq org-agenda-window-setup 'current-window))
6356 (not (one-window-p))
6357 (delete-window))
6358 (kill-buffer buf)
6359 (org-agenda-reset-markers)
6360 (org-columns-remove-overlays)
6361 (setq org-agenda-archives-mode nil)))
6362 ;; Maybe restore the pre-agenda window configuration.
6363 (and org-agenda-restore-windows-after-quit
6364 (not (eq org-agenda-window-setup 'other-frame))
6365 org-pre-agenda-window-conf
6366 (set-window-configuration org-pre-agenda-window-conf))))
6368 (defun org-agenda-quit ()
6369 "Exit agenda by killing agenda buffer or burying it when
6370 `org-agenda-sticky' is non-NIL"
6371 (interactive)
6372 (if org-agenda-columns-active
6373 (org-columns-quit)
6374 (if org-agenda-sticky
6375 (let ((buf (current-buffer)))
6376 (if (eq org-agenda-window-setup 'other-frame)
6377 (progn
6378 (delete-frame))
6379 (and (not (eq org-agenda-window-setup 'current-window))
6380 (not (one-window-p))
6381 (delete-window)))
6382 (with-current-buffer buf
6383 (bury-buffer)))
6384 (org-agenda-Quit))))
6386 (defun org-agenda-exit ()
6387 "Exit agenda by removing the window or the buffer.
6388 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6389 Org-mode buffers visited directly by the user will not be touched."
6390 (interactive)
6391 (org-release-buffers org-agenda-new-buffers)
6392 (setq org-agenda-new-buffers nil)
6393 (org-agenda-Quit))
6395 (defun org-agenda-execute (arg)
6396 "Execute another agenda command, keeping same window.
6397 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6398 in the agenda."
6399 (interactive "P")
6400 (let ((org-agenda-window-setup 'current-window))
6401 (org-agenda arg)))
6403 (defun org-agenda-redo ()
6404 "Rebuild Agenda.
6405 When this is the global TODO list, a prefix argument will be interpreted."
6406 (interactive)
6407 (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
6408 (org-agenda-sticky nil)
6409 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6410 org-agenda-buffer-name))
6411 (org-agenda-keep-modes t)
6412 (tag-filter org-agenda-tag-filter)
6413 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6414 (cat-filter org-agenda-category-filter)
6415 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6416 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6417 (cols org-agenda-columns-active)
6418 (line (org-current-line))
6419 (window-line (- line (org-current-line (window-start))))
6420 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6421 (put 'org-agenda-tag-filter :preset-filter nil)
6422 (put 'org-agenda-category-filter :preset-filter nil)
6423 (and cols (org-columns-quit))
6424 (message "Rebuilding agenda buffer...")
6425 (org-let lprops '(eval org-agenda-redo-command))
6426 (setq org-agenda-undo-list nil
6427 org-agenda-pending-undo-list nil)
6428 (message "Rebuilding agenda buffer...done")
6429 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6430 (put 'org-agenda-category-filter :preset-filter cat-preset)
6431 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6432 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6433 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6434 (org-goto-line line)
6435 (recenter window-line)))
6437 (defvar org-global-tags-completion-table nil)
6438 (defvar org-agenda-filtered-by-category nil)
6439 (defvar org-agenda-filter-form nil)
6441 (defun org-agenda-filter-by-category (strip)
6442 "Keep only those lines in the agenda buffer that have a specific category.
6443 The category is that of the current line."
6444 (interactive "P")
6445 (if org-agenda-filtered-by-category
6446 (org-agenda-filter-show-all-cat)
6447 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6448 (if cat (org-agenda-filter-apply
6449 (list (concat (if strip "-" "+") cat)) 'category)
6450 (error "No category at point")))))
6452 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6453 "Keep only those lines in the agenda buffer that have a specific tag.
6454 The tag is selected with its fast selection letter, as configured.
6455 With prefix argument STRIP, remove all lines that do have the tag.
6456 A lisp caller can specify CHAR. NARROW means that the new tag should be
6457 used to narrow the search - the interactive user can also press `-' or `+'
6458 to switch to narrowing."
6459 (interactive "P")
6460 (let* ((alist org-tag-alist-for-agenda)
6461 (tag-chars (mapconcat
6462 (lambda (x) (if (and (not (symbolp (car x)))
6463 (cdr x))
6464 (char-to-string (cdr x))
6465 ""))
6466 alist ""))
6467 (efforts (org-split-string
6468 (or (cdr (assoc (concat org-effort-property "_ALL")
6469 org-global-properties))
6470 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6471 "")))
6472 (effort-op org-agenda-filter-effort-default-operator)
6473 (effort-prompt "")
6474 (inhibit-read-only t)
6475 (current org-agenda-tag-filter)
6476 maybe-refresh a n tag)
6477 (unless char
6478 (message
6479 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6480 (if narrow "Narrow" "Filter") tag-chars
6481 (if org-agenda-auto-exclude-function "[RET], " ""))
6482 (setq char (read-char-exclusive)))
6483 (when (member char '(?+ ?-))
6484 ;; Narrowing down
6485 (cond ((equal char ?-) (setq strip t narrow t))
6486 ((equal char ?+) (setq strip nil narrow t)))
6487 (message
6488 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6489 (setq char (read-char-exclusive)))
6490 (when (member char '(?< ?> ?= ??))
6491 ;; An effort operator
6492 (setq effort-op (char-to-string char))
6493 (setq alist nil) ; to make sure it will be interpreted as effort.
6494 (unless (equal char ??)
6495 (loop for i from 0 to 9 do
6496 (setq effort-prompt
6497 (concat
6498 effort-prompt " ["
6499 (if (= i 9) "0" (int-to-string (1+ i)))
6500 "]" (nth i efforts))))
6501 (message "Effort%s: %s " effort-op effort-prompt)
6502 (setq char (read-char-exclusive))
6503 (when (or (< char ?0) (> char ?9))
6504 (error "Need 1-9,0 to select effort"))))
6505 (when (equal char ?\t)
6506 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6507 (org-set-local 'org-global-tags-completion-table
6508 (org-global-tags-completion-table)))
6509 (let ((completion-ignore-case t))
6510 (setq tag (org-icompleting-read
6511 "Tag: " org-global-tags-completion-table))))
6512 (cond
6513 ((equal char ?\r)
6514 (org-agenda-filter-show-all-tag)
6515 (when org-agenda-auto-exclude-function
6516 (setq org-agenda-tag-filter '())
6517 (dolist (tag (org-agenda-get-represented-tags))
6518 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6519 (if modifier
6520 (push modifier org-agenda-tag-filter))))
6521 (if (not (null org-agenda-tag-filter))
6522 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6523 (setq maybe-refresh t))
6524 ((equal char ?/)
6525 (org-agenda-filter-show-all-tag)
6526 (when (get 'org-agenda-tag-filter :preset-filter)
6527 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6528 (setq maybe-refresh t))
6529 ((equal char ?. )
6530 (setq org-agenda-tag-filter
6531 (mapcar (lambda(tag) (concat "+" tag))
6532 (org-get-at-bol 'tags)))
6533 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6534 (setq maybe-refresh t))
6535 ((or (equal char ?\ )
6536 (setq a (rassoc char alist))
6537 (and (>= char ?0) (<= char ?9)
6538 (setq n (if (= char ?0) 9 (- char ?0 1))
6539 tag (concat effort-op (nth n efforts))
6540 a (cons tag nil)))
6541 (and (= char ??)
6542 (setq tag "?eff")
6543 a (cons tag nil))
6544 (and tag (setq a (cons tag nil))))
6545 (org-agenda-filter-show-all-tag)
6546 (setq tag (car a))
6547 (setq org-agenda-tag-filter
6548 (cons (concat (if strip "-" "+") tag)
6549 (if narrow current nil)))
6550 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6551 (setq maybe-refresh t))
6552 (t (error "Invalid tag selection character %c" char)))
6553 (when (and maybe-refresh
6554 (eq org-agenda-clockreport-mode 'with-filter))
6555 (org-agenda-redo))))
6557 (defun org-agenda-get-represented-tags ()
6558 "Get a list of all tags currently represented in the agenda."
6559 (let (p tags)
6560 (save-excursion
6561 (goto-char (point-min))
6562 (while (setq p (next-single-property-change (point) 'tags))
6563 (goto-char p)
6564 (mapc (lambda (x) (add-to-list 'tags x))
6565 (get-text-property (point) 'tags))))
6566 tags))
6568 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6569 "Refine the current filter. See `org-agenda-filter-by-tag'."
6570 (interactive "P")
6571 (org-agenda-filter-by-tag strip char 'refine))
6573 (defun org-agenda-filter-make-matcher ()
6574 "Create the form that tests a line for agenda filter."
6575 (let (f f1)
6576 ;; first compute the tag-filter matcher
6577 (dolist (x (delete-dups
6578 (append (get 'org-agenda-tag-filter
6579 :preset-filter) org-agenda-tag-filter)))
6580 (if (member x '("-" "+"))
6581 (setq f1 (if (equal x "-") 'tags '(not tags)))
6582 (if (string-match "[<=>?]" x)
6583 (setq f1 (org-agenda-filter-effort-form x))
6584 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6585 (if (equal (string-to-char x) ?-)
6586 (setq f1 (list 'not f1))))
6587 (push f1 f))
6588 ;; then compute the category-filter matcher
6589 (dolist (x (delete-dups
6590 (append (get 'org-agenda-category-filter
6591 :preset-filter) org-agenda-category-filter)))
6592 (setq f1 (list 'equal (substring x 1) 'cat))
6593 (push f1 f))
6594 (cons 'and (nreverse f))))
6596 (defun org-agenda-filter-effort-form (e)
6597 "Return the form to compare the effort of the current line with what E says.
6598 E looks like \"+<2:25\"."
6599 (let (op)
6600 (setq e (substring e 1))
6601 (setq op (string-to-char e) e (substring e 1))
6602 (setq op (cond ((equal op ?<) '<=)
6603 ((equal op ?>) '>=)
6604 ((equal op ??) op)
6605 (t '=)))
6606 (list 'org-agenda-compare-effort (list 'quote op)
6607 (org-duration-string-to-minutes e))))
6609 (defun org-agenda-compare-effort (op value)
6610 "Compare the effort of the current line with VALUE, using OP.
6611 If the line does not have an effort defined, return nil."
6612 (let ((eff (org-get-at-bol 'effort-minutes)))
6613 (if (equal op ??)
6614 (not eff)
6615 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6616 value))))
6618 (defun org-agenda-filter-apply (filter type)
6619 "Set FILTER as the new agenda filter and apply it."
6620 (let (tags cat)
6621 (if (eq type 'tag)
6622 (setq org-agenda-tag-filter filter)
6623 (setq org-agenda-category-filter filter
6624 org-agenda-filtered-by-category t))
6625 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6626 (org-agenda-set-mode-name)
6627 (save-excursion
6628 (goto-char (point-min))
6629 (while (not (eobp))
6630 (if (org-get-at-bol 'org-marker)
6631 (progn
6632 (setq tags (org-get-at-bol 'tags) ; used in eval
6633 cat (get-text-property (point) 'org-category))
6634 (if (not (eval org-agenda-filter-form))
6635 (org-agenda-filter-hide-line type))
6636 (beginning-of-line 2))
6637 (beginning-of-line 2))))
6638 (if (get-char-property (point) 'invisible)
6639 (org-agenda-previous-line))))
6641 (defun org-agenda-filter-hide-line (type)
6642 (let (ov)
6643 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6644 (point-at-eol)))
6645 (overlay-put ov 'invisible t)
6646 (overlay-put ov 'type type)
6647 (if (eq type 'tag)
6648 (push ov org-agenda-tag-filter-overlays)
6649 (push ov org-agenda-cat-filter-overlays))))
6651 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6652 (setq pos (or pos (point)))
6653 (save-excursion
6654 (dolist (ov (overlays-at pos))
6655 (when (and (overlay-get ov 'invisible)
6656 (eq (overlay-get ov 'type) 'tag))
6657 (goto-char pos)
6658 (if (< (overlay-start ov) (point-at-eol))
6659 (move-overlay ov (point-at-eol)
6660 (overlay-end ov)))))))
6662 (defun org-agenda-filter-show-all-tag nil
6663 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6664 (setq org-agenda-tag-filter-overlays nil
6665 org-agenda-tag-filter nil
6666 org-agenda-filter-form nil)
6667 (org-agenda-set-mode-name))
6669 (defun org-agenda-filter-show-all-cat nil
6670 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6671 (setq org-agenda-cat-filter-overlays nil
6672 org-agenda-filtered-by-category nil
6673 org-agenda-category-filter nil
6674 org-agenda-filter-form nil)
6675 (org-agenda-set-mode-name))
6677 (defun org-agenda-manipulate-query-add ()
6678 "Manipulate the query by adding a search term with positive selection.
6679 Positive selection means the term must be matched for selection of an entry."
6680 (interactive)
6681 (org-agenda-manipulate-query ?\[))
6682 (defun org-agenda-manipulate-query-subtract ()
6683 "Manipulate the query by adding a search term with negative selection.
6684 Negative selection means term must not be matched for selection of an entry."
6685 (interactive)
6686 (org-agenda-manipulate-query ?\]))
6687 (defun org-agenda-manipulate-query-add-re ()
6688 "Manipulate the query by adding a search regexp with positive selection.
6689 Positive selection means the regexp must match for selection of an entry."
6690 (interactive)
6691 (org-agenda-manipulate-query ?\{))
6692 (defun org-agenda-manipulate-query-subtract-re ()
6693 "Manipulate the query by adding a search regexp with negative selection.
6694 Negative selection means regexp must not match for selection of an entry."
6695 (interactive)
6696 (org-agenda-manipulate-query ?\}))
6697 (defun org-agenda-manipulate-query (char)
6698 (cond
6699 ((memq org-agenda-type '(timeline agenda))
6700 (let ((org-agenda-include-inactive-timestamps t))
6701 (org-agenda-redo))
6702 (message "Display now includes inactive timestamps as well"))
6703 ((eq org-agenda-type 'search)
6704 (org-add-to-string
6705 'org-agenda-query-string
6706 (if org-agenda-last-search-view-search-was-boolean
6707 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6708 (?\{ . " +{}") (?\} . " -{}"))))
6709 " "))
6710 (setq org-agenda-redo-command
6711 (list 'org-search-view
6712 org-todo-only
6713 org-agenda-query-string
6714 (+ (length org-agenda-query-string)
6715 (if (member char '(?\{ ?\})) 0 1))))
6716 (set-register org-agenda-query-register org-agenda-query-string)
6717 (org-agenda-redo))
6718 (t (error "Cannot manipulate query for %s-type agenda buffers"
6719 org-agenda-type))))
6721 (defun org-add-to-string (var string)
6722 (set var (concat (symbol-value var) string)))
6724 (defun org-agenda-goto-date (date)
6725 "Jump to DATE in agenda."
6726 (interactive (list (let ((org-read-date-prefer-future
6727 (eval org-agenda-jump-prefer-future)))
6728 (org-read-date))))
6729 (org-agenda-list nil date))
6731 (defun org-agenda-goto-today ()
6732 "Go to today."
6733 (interactive)
6734 (org-agenda-check-type t 'timeline 'agenda)
6735 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6736 (cond
6737 (tdpos (goto-char tdpos))
6738 ((eq org-agenda-type 'agenda)
6739 (let* ((sd (org-agenda-compute-starting-span
6740 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6741 (org-agenda-overriding-arguments org-agenda-last-arguments))
6742 (setf (nth 1 org-agenda-overriding-arguments) sd)
6743 (org-agenda-redo)
6744 (org-agenda-find-same-or-today-or-agenda)))
6745 (t (error "Cannot find today")))))
6747 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6748 (goto-char
6749 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6750 (text-property-any (point-min) (point-max) 'org-today t)
6751 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6752 (point-min))))
6754 (defun org-agenda-later (arg)
6755 "Go forward in time by thee current span.
6756 With prefix ARG, go forward that many times the current span."
6757 (interactive "p")
6758 (org-agenda-check-type t 'agenda)
6759 (let* ((span org-agenda-current-span)
6760 (sd org-starting-day)
6761 (greg (calendar-gregorian-from-absolute sd))
6762 (cnt (org-get-at-bol 'org-day-cnt))
6763 greg2)
6764 (cond
6765 ((eq span 'day)
6766 (setq sd (+ arg sd)))
6767 ((eq span 'week)
6768 (setq sd (+ (* 7 arg) sd)))
6769 ((eq span 'month)
6770 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6771 sd (calendar-absolute-from-gregorian greg2))
6772 (setcar greg2 (1+ (car greg2))))
6773 ((eq span 'year)
6774 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6775 sd (calendar-absolute-from-gregorian greg2))
6776 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6778 (setq sd (+ (* span arg) sd))))
6779 (let ((org-agenda-overriding-arguments
6780 (list (car org-agenda-last-arguments) sd span t)))
6781 (org-agenda-redo)
6782 (org-agenda-find-same-or-today-or-agenda cnt))))
6784 (defun org-agenda-earlier (arg)
6785 "Go backward in time by the current span.
6786 With prefix ARG, go backward that many times the current span."
6787 (interactive "p")
6788 (org-agenda-later (- arg)))
6790 (defun org-agenda-view-mode-dispatch ()
6791 "Call one of the view mode commands."
6792 (interactive)
6793 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6794 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6795 [a]rch-trees [A]rch-files clock[R]eport include[D]iary
6796 [E]ntryText")
6797 (let ((a (read-char-exclusive)))
6798 (case a
6799 (?\ (call-interactively 'org-agenda-reset-view))
6800 (?d (call-interactively 'org-agenda-day-view))
6801 (?w (call-interactively 'org-agenda-week-view))
6802 (?m (call-interactively 'org-agenda-month-view))
6803 (?y (call-interactively 'org-agenda-year-view))
6804 (?l (call-interactively 'org-agenda-log-mode))
6805 (?L (org-agenda-log-mode '(4)))
6806 (?c (org-agenda-log-mode 'clockcheck))
6807 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6808 (?a (call-interactively 'org-agenda-archives-mode))
6809 (?A (org-agenda-archives-mode 'files))
6810 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6811 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6812 (?G (call-interactively 'org-agenda-toggle-time-grid))
6813 (?D (call-interactively 'org-agenda-toggle-diary))
6814 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6815 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6816 (org-agenda-check-type t 'timeline 'agenda)
6817 (org-agenda-redo))
6818 (message "Display now includes inactive timestamps as well"))
6819 (?q (message "Abort"))
6820 (otherwise (error "Invalid key" )))))
6822 (defun org-agenda-reset-view ()
6823 "Switch to default view for agenda."
6824 (interactive)
6825 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6826 (defun org-agenda-day-view (&optional day-of-year)
6827 "Switch to daily view for agenda.
6828 With argument DAY-OF-YEAR, switch to that day of the year."
6829 (interactive "P")
6830 (org-agenda-change-time-span 'day day-of-year))
6831 (defun org-agenda-week-view (&optional iso-week)
6832 "Switch to daily view for agenda.
6833 With argument ISO-WEEK, switch to the corresponding ISO week.
6834 If ISO-WEEK has more then 2 digits, only the last two encode the
6835 week. Any digits before this encode a year. So 200712 means
6836 week 12 of year 2007. Years in the range 1938-2037 can also be
6837 written as 2-digit years."
6838 (interactive "P")
6839 (org-agenda-change-time-span 'week iso-week))
6840 (defun org-agenda-month-view (&optional month)
6841 "Switch to monthly view for agenda.
6842 With argument MONTH, switch to that month."
6843 (interactive "P")
6844 (org-agenda-change-time-span 'month month))
6845 (defun org-agenda-year-view (&optional year)
6846 "Switch to yearly view for agenda.
6847 With argument YEAR, switch to that year.
6848 If MONTH has more then 2 digits, only the last two encode the
6849 month. Any digits before this encode a year. So 200712 means
6850 December year 2007. Years in the range 1938-2037 can also be
6851 written as 2-digit years."
6852 (interactive "P")
6853 (when year
6854 (setq year (org-small-year-to-year year)))
6855 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6856 (org-agenda-change-time-span 'year year)
6857 (error "Abort")))
6859 (defun org-agenda-change-time-span (span &optional n)
6860 "Change the agenda view to SPAN.
6861 SPAN may be `day', `week', `month', `year'."
6862 (org-agenda-check-type t 'agenda)
6863 (if (and (not n) (equal org-agenda-current-span span))
6864 (error "Viewing span is already \"%s\"" span))
6865 (let* ((sd (or (org-get-at-bol 'day)
6866 org-starting-day))
6867 (sd (org-agenda-compute-starting-span sd span n))
6868 (org-agenda-overriding-arguments
6869 (or org-agenda-overriding-arguments
6870 (list (car org-agenda-last-arguments) sd span t))))
6871 (org-agenda-redo)
6872 (org-agenda-find-same-or-today-or-agenda))
6873 (org-agenda-set-mode-name)
6874 (message "Switched to %s view" span))
6876 (defun org-agenda-compute-starting-span (sd span &optional n)
6877 "Compute starting date for agenda.
6878 SPAN may be `day', `week', `month', `year'. The return value
6879 is a cons cell with the starting date and the number of days,
6880 so that the date SD will be in that range."
6881 (let* ((greg (calendar-gregorian-from-absolute sd))
6882 (dg (nth 1 greg))
6883 (mg (car greg))
6884 (yg (nth 2 greg)))
6885 (cond
6886 ((eq span 'day)
6887 (when n
6888 (setq sd (+ (calendar-absolute-from-gregorian
6889 (list mg 1 yg))
6890 n -1))))
6891 ((eq span 'week)
6892 (let* ((nt (calendar-day-of-week
6893 (calendar-gregorian-from-absolute sd)))
6894 (d (if org-agenda-start-on-weekday
6895 (- nt org-agenda-start-on-weekday)
6898 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6899 (when n
6900 (require 'cal-iso)
6901 (when (> n 99)
6902 (setq y1 (org-small-year-to-year (/ n 100))
6903 n (mod n 100)))
6904 (setq sd
6905 (calendar-absolute-from-iso
6906 (list n 1
6907 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6908 ((eq span 'month)
6909 (let (y1)
6910 (when (and n (> n 99))
6911 (setq y1 (org-small-year-to-year (/ n 100))
6912 n (mod n 100)))
6913 (setq sd (calendar-absolute-from-gregorian
6914 (list (or n mg) 1 (or y1 yg))))))
6915 ((eq span 'year)
6916 (setq sd (calendar-absolute-from-gregorian
6917 (list 1 1 (or n yg))))))
6918 sd))
6920 (defun org-agenda-next-date-line (&optional arg)
6921 "Jump to the next line indicating a date in agenda buffer."
6922 (interactive "p")
6923 (org-agenda-check-type t 'agenda 'timeline)
6924 (beginning-of-line 1)
6925 ;; This does not work if user makes date format that starts with a blank
6926 (if (looking-at "^\\S-") (forward-char 1))
6927 (if (not (re-search-forward "^\\S-" nil t arg))
6928 (progn
6929 (backward-char 1)
6930 (error "No next date after this line in this buffer")))
6931 (goto-char (match-beginning 0)))
6933 (defun org-agenda-previous-date-line (&optional arg)
6934 "Jump to the previous line indicating a date in agenda buffer."
6935 (interactive "p")
6936 (org-agenda-check-type t 'agenda 'timeline)
6937 (beginning-of-line 1)
6938 (if (not (re-search-backward "^\\S-" nil t arg))
6939 (error "No previous date before this line in this buffer")))
6941 ;; Initialize the highlight
6942 (defvar org-hl (make-overlay 1 1))
6943 (overlay-put org-hl 'face 'highlight)
6945 (defun org-highlight (begin end &optional buffer)
6946 "Highlight a region with overlay."
6947 (move-overlay org-hl begin end (or buffer (current-buffer))))
6949 (defun org-unhighlight ()
6950 "Detach overlay INDEX."
6951 (org-detach-overlay org-hl))
6953 ;; FIXME this is currently not used.
6954 (defun org-highlight-until-next-command (beg end &optional buffer)
6955 "Move the highlight overlay to BEG/END, remove it before the next command."
6956 (org-highlight beg end buffer)
6957 (add-hook 'pre-command-hook 'org-unhighlight-once))
6958 (defun org-unhighlight-once ()
6959 "Remove the highlight from its position, and this function from the hook."
6960 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6961 (org-unhighlight))
6963 (defun org-agenda-follow-mode ()
6964 "Toggle follow mode in an agenda buffer."
6965 (interactive)
6966 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6967 (org-agenda-set-mode-name)
6968 (org-agenda-do-context-action)
6969 (message "Follow mode is %s"
6970 (if org-agenda-follow-mode "on" "off")))
6972 (defun org-agenda-entry-text-mode (&optional arg)
6973 "Toggle entry text mode in an agenda buffer."
6974 (interactive "P")
6975 (setq org-agenda-entry-text-mode (or (integerp arg)
6976 (not org-agenda-entry-text-mode)))
6977 (org-agenda-entry-text-hide)
6978 (and org-agenda-entry-text-mode
6979 (let ((org-agenda-entry-text-maxlines
6980 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6981 (org-agenda-entry-text-show)))
6982 (org-agenda-set-mode-name)
6983 (message "Entry text mode is %s. Maximum number of lines is %d"
6984 (if org-agenda-entry-text-mode "on" "off")
6985 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6987 (defun org-agenda-clockreport-mode (&optional with-filter)
6988 "Toggle clocktable mode in an agenda buffer.
6989 With prefix arg WITH-FILTER, make the clocktable respect the current
6990 agenda filter."
6991 (interactive "P")
6992 (org-agenda-check-type t 'agenda)
6993 (if with-filter
6994 (setq org-agenda-clockreport-mode 'with-filter)
6995 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6996 (org-agenda-set-mode-name)
6997 (org-agenda-redo)
6998 (message "Clocktable mode is %s"
6999 (if org-agenda-clockreport-mode "on" "off")))
7001 (defun org-agenda-log-mode (&optional special)
7002 "Toggle log mode in an agenda buffer.
7003 With argument SPECIAL, show all possible log items, not only the ones
7004 configured in `org-agenda-log-mode-items'.
7005 With a double `C-u' prefix arg, show *only* log items, nothing else."
7006 (interactive "P")
7007 (org-agenda-check-type t 'agenda 'timeline)
7008 (setq org-agenda-show-log
7009 (cond
7010 ((equal special '(16)) 'only)
7011 ((eq special 'clockcheck)
7012 (if (eq org-agenda-show-log 'clockcheck)
7013 nil 'clockcheck))
7014 (special '(closed clock state))
7015 (t (not org-agenda-show-log))))
7016 (org-agenda-set-mode-name)
7017 (org-agenda-redo)
7018 (message "Log mode is %s"
7019 (if org-agenda-show-log "on" "off")))
7021 (defun org-agenda-archives-mode (&optional with-files)
7022 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7023 When called with a prefix argument, include all archive files as well."
7024 (interactive "P")
7025 (setq org-agenda-archives-mode
7026 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7027 (org-agenda-set-mode-name)
7028 (org-agenda-redo)
7029 (message
7030 "%s"
7031 (cond
7032 ((eq org-agenda-archives-mode nil)
7033 "No archives are included")
7034 ((eq org-agenda-archives-mode 'trees)
7035 (format "Trees with :%s: tag are included" org-archive-tag))
7036 ((eq org-agenda-archives-mode t)
7037 (format "Trees with :%s: tag and all active archive files are included"
7038 org-archive-tag)))))
7040 (defun org-agenda-toggle-diary ()
7041 "Toggle diary inclusion in an agenda buffer."
7042 (interactive)
7043 (org-agenda-check-type t 'agenda)
7044 (setq org-agenda-include-diary (not org-agenda-include-diary))
7045 (org-agenda-redo)
7046 (org-agenda-set-mode-name)
7047 (message "Diary inclusion turned %s"
7048 (if org-agenda-include-diary "on" "off")))
7050 (defun org-agenda-toggle-deadlines ()
7051 "Toggle inclusion of entries with a deadline in an agenda buffer."
7052 (interactive)
7053 (org-agenda-check-type t 'agenda)
7054 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7055 (org-agenda-redo)
7056 (org-agenda-set-mode-name)
7057 (message "Deadlines inclusion turned %s"
7058 (if org-agenda-include-deadlines "on" "off")))
7060 (defun org-agenda-toggle-time-grid ()
7061 "Toggle time grid in an agenda buffer."
7062 (interactive)
7063 (org-agenda-check-type t 'agenda)
7064 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7065 (org-agenda-redo)
7066 (org-agenda-set-mode-name)
7067 (message "Time-grid turned %s"
7068 (if org-agenda-use-time-grid "on" "off")))
7070 (defun org-agenda-set-mode-name ()
7071 "Set the mode name to indicate all the small mode settings."
7072 (setq mode-name
7073 (list "Org-Agenda"
7074 (if (get 'org-agenda-files 'org-restrict) " []" "")
7076 '(:eval (org-agenda-span-name org-agenda-current-span))
7077 (if org-agenda-follow-mode " Follow" "")
7078 (if org-agenda-entry-text-mode " ETxt" "")
7079 (if org-agenda-include-diary " Diary" "")
7080 (if org-agenda-include-deadlines " Ddl" "")
7081 (if org-agenda-use-time-grid " Grid" "")
7082 (if (and (boundp 'org-habit-show-habits)
7083 org-habit-show-habits) " Habit" "")
7084 (cond
7085 ((consp org-agenda-show-log) " LogAll")
7086 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7087 (org-agenda-show-log " Log")
7088 (t ""))
7089 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7090 :preset-filter))
7091 '(:eval (org-propertize
7092 (concat " <"
7093 (mapconcat
7094 'identity
7095 (append
7096 (get 'org-agenda-category-filter :preset-filter)
7097 org-agenda-category-filter)
7099 ">")
7100 'face 'org-agenda-filter-category
7101 'help-echo "Category used in filtering"))
7103 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7104 :preset-filter))
7105 '(:eval (org-propertize
7106 (concat " {"
7107 (mapconcat
7108 'identity
7109 (append
7110 (get 'org-agenda-tag-filter :preset-filter)
7111 org-agenda-tag-filter)
7113 "}")
7114 'face 'org-agenda-filter-tags
7115 'help-echo "Tags used in filtering"))
7117 (if org-agenda-archives-mode
7118 (if (eq org-agenda-archives-mode t)
7119 " Archives"
7120 (format " :%s:" org-archive-tag))
7122 (if org-agenda-clockreport-mode
7123 (if (eq org-agenda-clockreport-mode 'with-filter)
7124 " Clock{}" " Clock")
7125 "")))
7126 (force-mode-line-update))
7128 (defun org-agenda-post-command-hook ()
7129 (setq org-agenda-type
7130 (or (get-text-property (point) 'org-agenda-type)
7131 (get-text-property (max (point-min) (1- (point)))
7132 'org-agenda-type))))
7134 (defun org-agenda-next-line ()
7135 "Move cursor to the next line, and show if follow mode is active."
7136 (interactive)
7137 (call-interactively 'next-line)
7138 (org-agenda-do-context-action))
7140 (defun org-agenda-previous-line ()
7141 "Move cursor to the previous line, and show if follow-mode is active."
7142 (interactive)
7143 (call-interactively 'previous-line)
7144 (org-agenda-do-context-action))
7146 (defun org-agenda-do-context-action ()
7147 "Show outline path and, maybe, follow mode window."
7148 (let ((m (org-get-at-bol 'org-marker)))
7149 (when (and (markerp m) (marker-buffer m))
7150 (and org-agenda-follow-mode
7151 (if org-agenda-follow-indirect
7152 (org-agenda-tree-to-indirect-buffer)
7153 (org-agenda-show)))
7154 (and org-agenda-show-outline-path
7155 (org-with-point-at m (org-display-outline-path t))))))
7157 (defun org-agenda-show-priority ()
7158 "Show the priority of the current item.
7159 This priority is composed of the main priority given with the [#A] cookies,
7160 and by additional input from the age of a schedules or deadline entry."
7161 (interactive)
7162 (let* ((pri (org-get-at-bol 'priority)))
7163 (message "Priority is %d" (if pri pri -1000))))
7165 (defun org-agenda-show-tags ()
7166 "Show the tags applicable to the current item."
7167 (interactive)
7168 (let* ((tags (org-get-at-bol 'tags)))
7169 (if tags
7170 (message "Tags are :%s:"
7171 (org-no-properties (mapconcat 'identity tags ":")))
7172 (message "No tags associated with this line"))))
7174 (defun org-agenda-goto (&optional highlight)
7175 "Go to the Org-mode file which contains the item at point."
7176 (interactive)
7177 (let* ((marker (or (org-get-at-bol 'org-marker)
7178 (org-agenda-error)))
7179 (buffer (marker-buffer marker))
7180 (pos (marker-position marker)))
7181 (switch-to-buffer-other-window buffer)
7182 (widen)
7183 (push-mark)
7184 (goto-char pos)
7185 (when (eq major-mode 'org-mode)
7186 (org-show-context 'agenda)
7187 (save-excursion
7188 (and (outline-next-heading)
7189 (org-flag-heading nil)))) ; show the next heading
7190 (when (outline-invisible-p)
7191 (show-entry)) ; display invisible text
7192 (recenter (/ (window-height) 2))
7193 (run-hooks 'org-agenda-after-show-hook)
7194 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7196 (defvar org-agenda-after-show-hook nil
7197 "Normal hook run after an item has been shown from the agenda.
7198 Point is in the buffer where the item originated.")
7200 (defun org-agenda-kill ()
7201 "Kill the entry or subtree belonging to the current agenda entry."
7202 (interactive)
7203 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7204 (let* ((marker (or (org-get-at-bol 'org-marker)
7205 (org-agenda-error)))
7206 (buffer (marker-buffer marker))
7207 (pos (marker-position marker))
7208 (type (org-get-at-bol 'type))
7209 dbeg dend (n 0) conf)
7210 (org-with-remote-undo buffer
7211 (with-current-buffer buffer
7212 (save-excursion
7213 (goto-char pos)
7214 (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
7215 (setq dbeg (progn (org-back-to-heading t) (point))
7216 dend (org-end-of-subtree t t))
7217 (setq dbeg (point-at-bol)
7218 dend (min (point-max) (1+ (point-at-eol)))))
7219 (goto-char dbeg)
7220 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7221 (setq conf (or (eq t org-agenda-confirm-kill)
7222 (and (numberp org-agenda-confirm-kill)
7223 (> n org-agenda-confirm-kill))))
7224 (and conf
7225 (not (y-or-n-p
7226 (format "Delete entry with %d lines in buffer \"%s\"? "
7227 n (buffer-name buffer))))
7228 (error "Abort"))
7229 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
7230 (with-current-buffer buffer (delete-region dbeg dend))
7231 (message "Agenda item and source killed"))))
7233 (defvar org-archive-default-command)
7234 (defun org-agenda-archive-default ()
7235 "Archive the entry or subtree belonging to the current agenda entry."
7236 (interactive)
7237 (require 'org-archive)
7238 (org-agenda-archive-with org-archive-default-command))
7240 (defun org-agenda-archive-default-with-confirmation ()
7241 "Archive the entry or subtree belonging to the current agenda entry."
7242 (interactive)
7243 (require 'org-archive)
7244 (org-agenda-archive-with org-archive-default-command 'confirm))
7246 (defun org-agenda-archive ()
7247 "Archive the entry or subtree belonging to the current agenda entry."
7248 (interactive)
7249 (org-agenda-archive-with 'org-archive-subtree))
7251 (defun org-agenda-archive-to-archive-sibling ()
7252 "Move the entry to the archive sibling."
7253 (interactive)
7254 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7256 (defun org-agenda-archive-with (cmd &optional confirm)
7257 "Move the entry to the archive sibling."
7258 (interactive)
7259 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7260 (let* ((marker (or (org-get-at-bol 'org-marker)
7261 (org-agenda-error)))
7262 (buffer (marker-buffer marker))
7263 (pos (marker-position marker)))
7264 (org-with-remote-undo buffer
7265 (with-current-buffer buffer
7266 (if (eq major-mode 'org-mode)
7267 (if (and confirm
7268 (not (y-or-n-p "Archive this subtree or entry? ")))
7269 (error "Abort")
7270 (save-excursion
7271 (goto-char pos)
7272 (org-remove-subtree-entries-from-agenda)
7273 (org-back-to-heading t)
7274 (funcall cmd)))
7275 (error "Archiving works only in Org-mode files"))))))
7277 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7278 "Remove all lines in the agenda that correspond to a given subtree.
7279 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7280 If this information is not given, the function uses the tree at point."
7281 (let ((buf (or buf (current-buffer))) m p)
7282 (save-excursion
7283 (unless (and beg end)
7284 (org-back-to-heading t)
7285 (setq beg (point))
7286 (org-end-of-subtree t)
7287 (setq end (point)))
7288 (set-buffer (get-buffer org-agenda-buffer-name))
7289 (save-excursion
7290 (goto-char (point-max))
7291 (beginning-of-line 1)
7292 (while (not (bobp))
7293 (when (and (setq m (org-get-at-bol 'org-marker))
7294 (equal buf (marker-buffer m))
7295 (setq p (marker-position m))
7296 (>= p beg)
7297 (< p end))
7298 (let ((inhibit-read-only t))
7299 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7300 (beginning-of-line 0))))))
7302 (defun org-agenda-refile (&optional goto rfloc no-update)
7303 "Refile the item at point."
7304 (interactive "P")
7305 (if (equal goto '(16))
7306 (org-refile-goto-last-stored)
7307 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7308 (org-agenda-error)))
7309 (buffer (marker-buffer marker))
7310 (pos (marker-position marker))
7311 (rfloc (or rfloc
7312 (org-refile-get-location
7313 (if goto "Goto" "Refile to") buffer
7314 org-refile-allow-creating-parent-nodes))))
7315 (with-current-buffer buffer
7316 (save-excursion
7317 (save-restriction
7318 (widen)
7319 (goto-char marker)
7320 (org-remove-subtree-entries-from-agenda)
7321 (org-refile goto buffer rfloc)))))
7322 (unless no-update (org-agenda-redo))))
7324 (defun org-agenda-open-link (&optional arg)
7325 "Follow the link in the current line, if any.
7326 This looks for a link in the displayed line in the agenda. It also looks
7327 at the text of the entry itself."
7328 (interactive "P")
7329 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7330 (org-get-at-bol 'org-marker)))
7331 (buffer (and marker (marker-buffer marker)))
7332 (prefix (buffer-substring
7333 (point-at-bol) (point-at-eol))))
7334 (cond
7335 (buffer
7336 (with-current-buffer buffer
7337 (save-excursion
7338 (save-restriction
7339 (widen)
7340 (goto-char marker)
7341 (org-offer-links-in-entry arg prefix)))))
7342 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7343 (save-excursion
7344 (beginning-of-line 1)
7345 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7346 (org-open-link-from-string (match-string 1)))
7347 (t (error "No link to open here")))))
7349 (defun org-agenda-copy-local-variable (var)
7350 "Get a variable from a referenced buffer and install it here."
7351 (let ((m (org-get-at-bol 'org-marker)))
7352 (when (and m (buffer-live-p (marker-buffer m)))
7353 (org-set-local var (with-current-buffer (marker-buffer m)
7354 (symbol-value var))))))
7356 (defun org-agenda-switch-to (&optional delete-other-windows)
7357 "Go to the Org-mode file which contains the item at point."
7358 (interactive)
7359 (if (and org-return-follows-link
7360 (not (org-get-at-bol 'org-marker))
7361 (org-in-regexp org-bracket-link-regexp))
7362 (org-open-link-from-string (match-string 0))
7363 (let* ((marker (or (org-get-at-bol 'org-marker)
7364 (org-agenda-error)))
7365 (buffer (marker-buffer marker))
7366 (pos (marker-position marker)))
7367 (org-pop-to-buffer-same-window buffer)
7368 (and delete-other-windows (delete-other-windows))
7369 (widen)
7370 (goto-char pos)
7371 (when (eq major-mode 'org-mode)
7372 (org-show-context 'agenda)
7373 (save-excursion
7374 (and (outline-next-heading)
7375 (org-flag-heading nil))) ; show the next heading
7376 (when (outline-invisible-p)
7377 (show-entry)))))) ; display invisible text
7379 (defun org-agenda-goto-mouse (ev)
7380 "Go to the Org-mode file which contains the item at the mouse click."
7381 (interactive "e")
7382 (mouse-set-point ev)
7383 (org-agenda-goto))
7385 (defun org-agenda-show (&optional full-entry)
7386 "Display the Org-mode file which contains the item at point.
7387 With prefix argument FULL-ENTRY, make the entire entry visible
7388 if it was hidden in the outline."
7389 (interactive "P")
7390 (let ((win (selected-window)))
7391 (if full-entry
7392 (let ((org-show-entry-below t))
7393 (org-agenda-goto t))
7394 (org-agenda-goto t))
7395 (select-window win)))
7397 (defvar org-agenda-show-window nil)
7398 (defun org-agenda-show-and-scroll-up (&optional arg)
7399 "Display the Org-mode file which contains the item at point.
7400 When called repeatedly, scroll the window that is displaying the buffer.
7401 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7402 `show-subtree' to display the item, so that drawers and logbooks stay
7403 folded."
7404 (interactive "P")
7405 (let ((win (selected-window)))
7406 (if (and (window-live-p org-agenda-show-window)
7407 (eq this-command last-command))
7408 (progn
7409 (select-window org-agenda-show-window)
7410 (ignore-errors (scroll-up)))
7411 (org-agenda-goto t)
7412 (if arg (org-show-entry) (show-subtree))
7413 (setq org-agenda-show-window (selected-window)))
7414 (select-window win)))
7416 (defun org-agenda-show-scroll-down ()
7417 "Scroll down the window showing the agenda."
7418 (interactive)
7419 (let ((win (selected-window)))
7420 (when (window-live-p org-agenda-show-window)
7421 (select-window org-agenda-show-window)
7422 (ignore-errors (scroll-down))
7423 (select-window win))))
7425 (defun org-agenda-show-1 (&optional more)
7426 "Display the Org-mode file which contains the item at point.
7427 The prefix arg selects the amount of information to display:
7429 0 hide the subtree
7430 1 just show the entry according to defaults.
7431 2 show the children view
7432 3 show the subtree view
7433 4 show the entire subtree and any LOGBOOK drawers
7434 5 show the entire subtree and any drawers
7435 With prefix argument FULL-ENTRY, make the entire entry visible
7436 if it was hidden in the outline."
7437 (interactive "p")
7438 (let ((win (selected-window)))
7439 (org-agenda-goto t)
7440 (org-recenter-heading 1)
7441 (cond
7442 ((= more 0)
7443 (hide-subtree)
7444 (save-excursion
7445 (org-back-to-heading)
7446 (run-hook-with-args 'org-cycle-hook 'folded))
7447 (message "Remote: FOLDED"))
7448 ((and (org-called-interactively-p 'any) (= more 1))
7449 (message "Remote: show with default settings"))
7450 ((= more 2)
7451 (show-entry)
7452 (show-children)
7453 (save-excursion
7454 (org-back-to-heading)
7455 (run-hook-with-args 'org-cycle-hook 'children))
7456 (message "Remote: CHILDREN"))
7457 ((= more 3)
7458 (show-subtree)
7459 (save-excursion
7460 (org-back-to-heading)
7461 (run-hook-with-args 'org-cycle-hook 'subtree))
7462 (message "Remote: SUBTREE"))
7463 ((= more 4)
7464 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7465 (org-drawer-regexp
7466 (concat "^[ \t]*:\\("
7467 (mapconcat 'regexp-quote org-drawers "\\|")
7468 "\\):[ \t]*$")))
7469 (show-subtree)
7470 (save-excursion
7471 (org-back-to-heading)
7472 (org-cycle-hide-drawers 'subtree)))
7473 (message "Remote: SUBTREE AND LOGBOOK"))
7474 ((> more 4)
7475 (show-subtree)
7476 (message "Remote: SUBTREE AND ALL DRAWERS")))
7477 (select-window win)))
7479 (defun org-recenter-heading (n)
7480 (save-excursion
7481 (org-back-to-heading)
7482 (recenter n)))
7484 (defvar org-agenda-cycle-counter nil)
7485 (defun org-agenda-cycle-show (&optional n)
7486 "Show the current entry in another window, with default settings.
7487 Default settings are taken from `org-show-hierarchy-above' and siblings.
7488 When use repeatedly in immediate succession, the remote entry will cycle
7489 through visibility
7491 children -> subtree -> folded
7493 When called with a numeric prefix arg, that arg will be passed through to
7494 `org-agenda-show-1'. For the interpretation of that argument, see the
7495 docstring of `org-agenda-show-1'."
7496 (interactive "P")
7497 (if (integerp n)
7498 (setq org-agenda-cycle-counter n)
7499 (if (not (eq last-command this-command))
7500 (setq org-agenda-cycle-counter 1)
7501 (if (equal org-agenda-cycle-counter 0)
7502 (setq org-agenda-cycle-counter 2)
7503 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7504 (if (> org-agenda-cycle-counter 3)
7505 (setq org-agenda-cycle-counter 0)))))
7506 (org-agenda-show-1 org-agenda-cycle-counter))
7508 (defun org-agenda-recenter (arg)
7509 "Display the Org-mode file which contains the item at point and recenter."
7510 (interactive "P")
7511 (let ((win (selected-window)))
7512 (org-agenda-goto t)
7513 (recenter arg)
7514 (select-window win)))
7516 (defun org-agenda-show-mouse (ev)
7517 "Display the Org-mode file which contains the item at the mouse click."
7518 (interactive "e")
7519 (mouse-set-point ev)
7520 (org-agenda-show))
7522 (defun org-agenda-check-no-diary ()
7523 "Check if the entry is a diary link and abort if yes."
7524 (if (org-get-at-bol 'org-agenda-diary-link)
7525 (org-agenda-error)))
7527 (defun org-agenda-error ()
7528 (error "Command not allowed in this line"))
7530 (defun org-agenda-tree-to-indirect-buffer ()
7531 "Show the subtree corresponding to the current entry in an indirect buffer.
7532 This calls the command `org-tree-to-indirect-buffer' from the original
7533 Org-mode buffer.
7534 With numerical prefix arg ARG, go up to this level and then take that tree.
7535 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7536 use the dedicated frame)."
7537 (interactive)
7538 (if (and current-prefix-arg (listp current-prefix-arg))
7539 (org-agenda-do-tree-to-indirect-buffer)
7540 (let ((agenda-window (selected-window))
7541 (indirect-window (and org-last-indirect-buffer (get-buffer-window org-last-indirect-buffer))))
7542 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7543 (unwind-protect
7544 (progn
7545 (unless (and indirect-window (window-live-p indirect-window))
7546 (setq indirect-window (split-window agenda-window)))
7547 (select-window indirect-window)
7548 (switch-to-buffer org-last-indirect-buffer :norecord)
7549 (fit-window-to-buffer indirect-window))
7550 (select-window agenda-window)))))
7552 (defun org-agenda-do-tree-to-indirect-buffer ()
7553 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7554 (org-agenda-check-no-diary)
7555 (let* ((marker (or (org-get-at-bol 'org-marker)
7556 (org-agenda-error)))
7557 (buffer (marker-buffer marker))
7558 (pos (marker-position marker)))
7559 (with-current-buffer buffer
7560 (save-excursion
7561 (goto-char pos)
7562 (call-interactively 'org-tree-to-indirect-buffer)))))
7564 (defvar org-last-heading-marker (make-marker)
7565 "Marker pointing to the headline that last changed its TODO state
7566 by a remote command from the agenda.")
7568 (defun org-agenda-todo-nextset ()
7569 "Switch TODO entry to next sequence."
7570 (interactive)
7571 (org-agenda-todo 'nextset))
7573 (defun org-agenda-todo-previousset ()
7574 "Switch TODO entry to previous sequence."
7575 (interactive)
7576 (org-agenda-todo 'previousset))
7578 (defun org-agenda-todo (&optional arg)
7579 "Cycle TODO state of line at point, also in Org-mode file.
7580 This changes the line at point, all other lines in the agenda referring to
7581 the same tree node, and the headline of the tree node in the Org-mode file."
7582 (interactive "P")
7583 (org-agenda-check-no-diary)
7584 (let* ((col (current-column))
7585 (marker (or (org-get-at-bol 'org-marker)
7586 (org-agenda-error)))
7587 (buffer (marker-buffer marker))
7588 (pos (marker-position marker))
7589 (hdmarker (org-get-at-bol 'org-hd-marker))
7590 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7591 (inhibit-read-only t)
7592 org-agenda-headline-snapshot-before-repeat newhead just-one)
7593 (org-with-remote-undo buffer
7594 (with-current-buffer buffer
7595 (widen)
7596 (goto-char pos)
7597 (org-show-context 'agenda)
7598 (save-excursion
7599 (and (outline-next-heading)
7600 (org-flag-heading nil))) ; show the next heading
7601 (let ((current-prefix-arg arg))
7602 (call-interactively 'org-todo))
7603 (and (bolp) (forward-char 1))
7604 (setq newhead (org-get-heading))
7605 (when (and (org-bound-and-true-p
7606 org-agenda-headline-snapshot-before-repeat)
7607 (not (equal org-agenda-headline-snapshot-before-repeat
7608 newhead))
7609 todayp)
7610 (setq newhead org-agenda-headline-snapshot-before-repeat
7611 just-one t))
7612 (save-excursion
7613 (org-back-to-heading)
7614 (move-marker org-last-heading-marker (point))))
7615 (beginning-of-line 1)
7616 (save-excursion
7617 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7618 (org-move-to-column col))))
7620 (defun org-agenda-add-note (&optional arg)
7621 "Add a time-stamped note to the entry at point."
7622 (interactive "P")
7623 (org-agenda-check-no-diary)
7624 (let* ((marker (or (org-get-at-bol 'org-marker)
7625 (org-agenda-error)))
7626 (buffer (marker-buffer marker))
7627 (pos (marker-position marker))
7628 (hdmarker (org-get-at-bol 'org-hd-marker))
7629 (inhibit-read-only t))
7630 (with-current-buffer buffer
7631 (widen)
7632 (goto-char pos)
7633 (org-show-context 'agenda)
7634 (save-excursion
7635 (and (outline-next-heading)
7636 (org-flag-heading nil))) ; show the next heading
7637 (org-add-note))))
7639 (defun org-agenda-change-all-lines (newhead hdmarker
7640 &optional fixface just-this)
7641 "Change all lines in the agenda buffer which match HDMARKER.
7642 The new content of the line will be NEWHEAD (as modified by
7643 `org-agenda-format-item'). HDMARKER is checked with
7644 `equal' against all `org-hd-marker' text properties in the file.
7645 If FIXFACE is non-nil, the face of each item is modified according to
7646 the new TODO state.
7647 If JUST-THIS is non-nil, change just the current line, not all.
7648 If FORCE-TAGS is non nil, the car of it returns the new tags."
7649 (let* ((inhibit-read-only t)
7650 (line (org-current-line))
7651 (org-agenda-buffer (current-buffer))
7652 (thetags (with-current-buffer (marker-buffer hdmarker)
7653 (save-excursion (save-restriction (widen)
7654 (goto-char hdmarker)
7655 (org-get-tags-at)))))
7656 props m pl undone-face done-face finish new dotime cat tags)
7657 (save-excursion
7658 (goto-char (point-max))
7659 (beginning-of-line 1)
7660 (while (not finish)
7661 (setq finish (bobp))
7662 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7663 (or (not just-this) (= (org-current-line) line))
7664 (equal m hdmarker))
7665 (setq props (text-properties-at (point))
7666 dotime (org-get-at-bol 'dotime)
7667 cat (org-get-at-bol 'org-category)
7668 tags thetags
7670 (let ((org-prefix-format-compiled
7671 (or (get-text-property (point) 'format)
7672 org-prefix-format-compiled)))
7673 (with-current-buffer (marker-buffer hdmarker)
7674 (save-excursion
7675 (save-restriction
7676 (widen)
7677 (org-agenda-format-item (org-get-at-bol 'extra)
7678 newhead cat tags dotime)))))
7679 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7680 undone-face (org-get-at-bol 'undone-face)
7681 done-face (org-get-at-bol 'done-face))
7682 (beginning-of-line 1)
7683 (cond
7684 ((equal new "")
7685 (and (looking-at ".*\n?") (replace-match "")))
7686 ((looking-at ".*")
7687 (replace-match new t t)
7688 (beginning-of-line 1)
7689 (add-text-properties (point-at-bol) (point-at-eol) props)
7690 (when fixface
7691 (add-text-properties
7692 (point-at-bol) (point-at-eol)
7693 (list 'face
7694 (if org-last-todo-state-is-todo
7695 undone-face done-face))))
7696 (org-agenda-highlight-todo 'line)
7697 (beginning-of-line 1))
7698 (t (error "Line update did not work"))))
7699 (beginning-of-line 0)))
7700 (org-finalize-agenda)))
7702 (defun org-agenda-align-tags (&optional line)
7703 "Align all tags in agenda items to `org-agenda-tags-column'."
7704 (let ((inhibit-read-only t) l c)
7705 (save-excursion
7706 (goto-char (if line (point-at-bol) (point-min)))
7707 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7708 (if line (point-at-eol) nil) t)
7709 (add-text-properties
7710 (match-beginning 2) (match-end 2)
7711 (list 'face (delq nil (let ((prop (get-text-property
7712 (match-beginning 2) 'face)))
7713 (or (listp prop) (setq prop (list prop)))
7714 (if (memq 'org-tag prop)
7715 prop
7716 (cons 'org-tag prop))))))
7717 (setq l (- (match-end 2) (match-beginning 2))
7718 c (if (< org-agenda-tags-column 0)
7719 (- (abs org-agenda-tags-column) l)
7720 org-agenda-tags-column))
7721 (delete-region (match-beginning 1) (match-end 1))
7722 (goto-char (match-beginning 1))
7723 (insert (org-add-props
7724 (make-string (max 1 (- c (current-column))) ?\ )
7725 (plist-put (copy-sequence (text-properties-at (point)))
7726 'face nil))))
7727 (goto-char (point-min))
7728 (org-font-lock-add-tag-faces (point-max)))))
7730 (defun org-agenda-priority-up ()
7731 "Increase the priority of line at point, also in Org-mode file."
7732 (interactive)
7733 (org-agenda-priority 'up))
7735 (defun org-agenda-priority-down ()
7736 "Decrease the priority of line at point, also in Org-mode file."
7737 (interactive)
7738 (org-agenda-priority 'down))
7740 (defun org-agenda-priority (&optional force-direction)
7741 "Set the priority of line at point, also in Org-mode file.
7742 This changes the line at point, all other lines in the agenda referring to
7743 the same tree node, and the headline of the tree node in the Org-mode file."
7744 (interactive)
7745 (unless org-enable-priority-commands
7746 (error "Priority commands are disabled"))
7747 (org-agenda-check-no-diary)
7748 (let* ((marker (or (org-get-at-bol 'org-marker)
7749 (org-agenda-error)))
7750 (hdmarker (org-get-at-bol 'org-hd-marker))
7751 (buffer (marker-buffer hdmarker))
7752 (pos (marker-position hdmarker))
7753 (inhibit-read-only t)
7754 newhead)
7755 (org-with-remote-undo buffer
7756 (with-current-buffer buffer
7757 (widen)
7758 (goto-char pos)
7759 (org-show-context 'agenda)
7760 (save-excursion
7761 (and (outline-next-heading)
7762 (org-flag-heading nil))) ; show the next heading
7763 (funcall 'org-priority force-direction)
7764 (end-of-line 1)
7765 (setq newhead (org-get-heading)))
7766 (org-agenda-change-all-lines newhead hdmarker)
7767 (beginning-of-line 1))))
7769 ;; FIXME: should fix the tags property of the agenda line.
7770 (defun org-agenda-set-tags (&optional tag onoff)
7771 "Set tags for the current headline."
7772 (interactive)
7773 (org-agenda-check-no-diary)
7774 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7775 (call-interactively 'org-change-tag-in-region)
7776 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7777 (org-agenda-error)))
7778 (buffer (marker-buffer hdmarker))
7779 (pos (marker-position hdmarker))
7780 (inhibit-read-only t)
7781 newhead)
7782 (org-with-remote-undo buffer
7783 (with-current-buffer buffer
7784 (widen)
7785 (goto-char pos)
7786 (save-excursion
7787 (org-show-context 'agenda))
7788 (save-excursion
7789 (and (outline-next-heading)
7790 (org-flag-heading nil))) ; show the next heading
7791 (goto-char pos)
7792 (if tag
7793 (org-toggle-tag tag onoff)
7794 (call-interactively 'org-set-tags))
7795 (end-of-line 1)
7796 (setq newhead (org-get-heading)))
7797 (org-agenda-change-all-lines newhead hdmarker)
7798 (beginning-of-line 1)))))
7800 (defun org-agenda-set-property ()
7801 "Set a property for the current headline."
7802 (interactive)
7803 (org-agenda-check-no-diary)
7804 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7805 (org-agenda-error)))
7806 (buffer (marker-buffer hdmarker))
7807 (pos (marker-position hdmarker))
7808 (inhibit-read-only t)
7809 newhead)
7810 (org-with-remote-undo buffer
7811 (with-current-buffer buffer
7812 (widen)
7813 (goto-char pos)
7814 (save-excursion
7815 (org-show-context 'agenda))
7816 (save-excursion
7817 (and (outline-next-heading)
7818 (org-flag-heading nil))) ; show the next heading
7819 (goto-char pos)
7820 (call-interactively 'org-set-property)))))
7822 (defun org-agenda-set-effort ()
7823 "Set the effort property for the current headline."
7824 (interactive)
7825 (org-agenda-check-no-diary)
7826 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7827 (org-agenda-error)))
7828 (buffer (marker-buffer hdmarker))
7829 (pos (marker-position hdmarker))
7830 (inhibit-read-only t)
7831 newhead)
7832 (org-with-remote-undo buffer
7833 (with-current-buffer buffer
7834 (widen)
7835 (goto-char pos)
7836 (save-excursion
7837 (org-show-context 'agenda))
7838 (save-excursion
7839 (and (outline-next-heading)
7840 (org-flag-heading nil))) ; show the next heading
7841 (goto-char pos)
7842 (call-interactively 'org-set-effort)
7843 (end-of-line 1)
7844 (setq newhead (org-get-heading)))
7845 (org-agenda-change-all-lines newhead hdmarker))))
7847 (defun org-agenda-toggle-archive-tag ()
7848 "Toggle the archive tag for the current entry."
7849 (interactive)
7850 (org-agenda-check-no-diary)
7851 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7852 (org-agenda-error)))
7853 (buffer (marker-buffer hdmarker))
7854 (pos (marker-position hdmarker))
7855 (inhibit-read-only t)
7856 newhead)
7857 (org-with-remote-undo buffer
7858 (with-current-buffer buffer
7859 (widen)
7860 (goto-char pos)
7861 (org-show-context 'agenda)
7862 (save-excursion
7863 (and (outline-next-heading)
7864 (org-flag-heading nil))) ; show the next heading
7865 (call-interactively 'org-toggle-archive-tag)
7866 (end-of-line 1)
7867 (setq newhead (org-get-heading)))
7868 (org-agenda-change-all-lines newhead hdmarker)
7869 (beginning-of-line 1))))
7871 (defun org-agenda-do-date-later (arg)
7872 (interactive "P")
7873 (cond
7874 ((or (equal arg '(16))
7875 (memq last-command
7876 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7877 (setq this-command 'org-agenda-date-later-minutes)
7878 (org-agenda-date-later-minutes 1))
7879 ((or (equal arg '(4))
7880 (memq last-command
7881 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7882 (setq this-command 'org-agenda-date-later-hours)
7883 (org-agenda-date-later-hours 1))
7885 (org-agenda-date-later (prefix-numeric-value arg)))))
7887 (defun org-agenda-do-date-earlier (arg)
7888 (interactive "P")
7889 (cond
7890 ((or (equal arg '(16))
7891 (memq last-command
7892 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7893 (setq this-command 'org-agenda-date-earlier-minutes)
7894 (org-agenda-date-earlier-minutes 1))
7895 ((or (equal arg '(4))
7896 (memq last-command
7897 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7898 (setq this-command 'org-agenda-date-earlier-hours)
7899 (org-agenda-date-earlier-hours 1))
7901 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7903 (defun org-agenda-date-later (arg &optional what)
7904 "Change the date of this item to ARG day(s) later."
7905 (interactive "p")
7906 (org-agenda-check-type t 'agenda 'timeline)
7907 (org-agenda-check-no-diary)
7908 (let* ((marker (or (org-get-at-bol 'org-marker)
7909 (org-agenda-error)))
7910 (buffer (marker-buffer marker))
7911 (pos (marker-position marker))
7912 cdate today)
7913 (org-with-remote-undo buffer
7914 (with-current-buffer buffer
7915 (widen)
7916 (goto-char pos)
7917 (if (not (org-at-timestamp-p))
7918 (error "Cannot find time stamp"))
7919 (when (and org-agenda-move-date-from-past-immediately-to-today
7920 (equal arg 1)
7921 (or (not what) (eq what 'day))
7922 (not (save-match-data (org-at-date-range-p))))
7923 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
7924 cdate (calendar-absolute-from-gregorian
7925 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
7926 today (org-today))
7927 (if (> today cdate)
7928 ;; immediately shift to today
7929 (setq arg (- today cdate))))
7930 (org-timestamp-change arg (or what 'day))
7931 (when (and (org-at-date-range-p)
7932 (re-search-backward org-tr-regexp-both (point-at-bol)))
7933 (let ((end org-last-changed-timestamp))
7934 (org-timestamp-change arg (or what 'day))
7935 (setq org-last-changed-timestamp
7936 (concat org-last-changed-timestamp "--" end)))))
7937 (org-agenda-show-new-time marker org-last-changed-timestamp))
7938 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7940 (defun org-agenda-date-earlier (arg &optional what)
7941 "Change the date of this item to ARG day(s) earlier."
7942 (interactive "p")
7943 (org-agenda-date-later (- arg) what))
7945 (defun org-agenda-date-later-minutes (arg)
7946 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7947 (interactive "p")
7948 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7949 (org-agenda-date-later arg 'minute))
7951 (defun org-agenda-date-earlier-minutes (arg)
7952 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7953 (interactive "p")
7954 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7955 (org-agenda-date-earlier arg 'minute))
7957 (defun org-agenda-date-later-hours (arg)
7958 "Change the time of this item, in hour steps."
7959 (interactive "p")
7960 (org-agenda-date-later arg 'hour))
7962 (defun org-agenda-date-earlier-hours (arg)
7963 "Change the time of this item, in hour steps."
7964 (interactive "p")
7965 (org-agenda-date-earlier arg 'hour))
7967 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7968 "Show new date stamp via text properties."
7969 ;; We use text properties to make this undoable
7970 (let ((inhibit-read-only t)
7971 (buffer-invisibility-spec))
7972 (setq stamp (concat " " prefix " => " stamp))
7973 (save-excursion
7974 (goto-char (point-max))
7975 (while (not (bobp))
7976 (when (equal marker (org-get-at-bol 'org-marker))
7977 (org-move-to-column (- (window-width) (length stamp)) t)
7978 (org-agenda-fix-tags-filter-overlays-at (point))
7979 (if (featurep 'xemacs)
7980 ;; Use `duplicable' property to trigger undo recording
7981 (let ((ex (make-extent nil nil))
7982 (gl (make-glyph stamp)))
7983 (set-glyph-face gl 'secondary-selection)
7984 (set-extent-properties
7985 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7986 (insert-extent ex (1- (point)) (point-at-eol)))
7987 (add-text-properties
7988 (1- (point)) (point-at-eol)
7989 (list 'display (org-add-props stamp nil
7990 'face 'secondary-selection))))
7991 (beginning-of-line 1))
7992 (beginning-of-line 0)))))
7994 (defun org-agenda-date-prompt (arg)
7995 "Change the date of this item. Date is prompted for, with default today.
7996 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7997 be used to request time specification in the time stamp."
7998 (interactive "P")
7999 (org-agenda-check-type t 'agenda 'timeline)
8000 (org-agenda-check-no-diary)
8001 (let* ((marker (or (org-get-at-bol 'org-marker)
8002 (org-agenda-error)))
8003 (buffer (marker-buffer marker))
8004 (pos (marker-position marker)))
8005 (org-with-remote-undo buffer
8006 (with-current-buffer buffer
8007 (widen)
8008 (goto-char pos)
8009 (if (not (org-at-timestamp-p t))
8010 (error "Cannot find time stamp"))
8011 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8012 (org-agenda-show-new-time marker org-last-changed-timestamp))
8013 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8015 (defun org-agenda-schedule (arg &optional time)
8016 "Schedule the item at point.
8017 ARG is passed through to `org-schedule'."
8018 (interactive "P")
8019 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8020 (org-agenda-check-no-diary)
8021 (let* ((marker (or (org-get-at-bol 'org-marker)
8022 (org-agenda-error)))
8023 (type (marker-insertion-type marker))
8024 (buffer (marker-buffer marker))
8025 (pos (marker-position marker))
8026 (org-insert-labeled-timestamps-at-point nil)
8028 (set-marker-insertion-type marker t)
8029 (org-with-remote-undo buffer
8030 (with-current-buffer buffer
8031 (widen)
8032 (goto-char pos)
8033 (setq ts (org-schedule arg time)))
8034 (org-agenda-show-new-time marker ts "S"))
8035 (message "Item scheduled for %s" ts)))
8037 (defun org-agenda-deadline (arg &optional time)
8038 "Schedule the item at point.
8039 ARG is passed through to `org-deadline'."
8040 (interactive "P")
8041 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8042 (org-agenda-check-no-diary)
8043 (let* ((marker (or (org-get-at-bol 'org-marker)
8044 (org-agenda-error)))
8045 (buffer (marker-buffer marker))
8046 (pos (marker-position marker))
8047 (org-insert-labeled-timestamps-at-point nil)
8049 (org-with-remote-undo buffer
8050 (with-current-buffer buffer
8051 (widen)
8052 (goto-char pos)
8053 (setq ts (org-deadline arg time)))
8054 (org-agenda-show-new-time marker ts "D"))
8055 (message "Deadline for this item set to %s" ts)))
8057 (defun org-agenda-action ()
8058 "Select entry for agenda action, or execute an agenda action.
8059 This command prompts for another letter. Valid inputs are:
8061 m Mark the entry at point for an agenda action
8062 s Schedule the marked entry to the date at the cursor
8063 d Set the deadline of the marked entry to the date at the cursor
8064 r Call `org-remember' with cursor date as the default date
8065 c Call `org-capture' with cursor date as the default date
8066 SPC Show marked entry in other window
8067 TAB Visit marked entry in other window
8069 The cursor may be at a date in the calendar, or in the Org agenda."
8070 (interactive)
8071 (let (ans)
8072 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8073 (setq ans (read-char-exclusive))
8074 (cond
8075 ((equal ans ?m)
8076 ;; Mark this entry
8077 (if (eq major-mode 'org-agenda-mode)
8078 (let ((m (or (org-get-at-bol 'org-hd-marker)
8079 (org-get-at-bol 'org-marker))))
8080 (if m
8081 (progn
8082 (move-marker org-agenda-action-marker
8083 (marker-position m) (marker-buffer m))
8084 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8085 (error "Don't know which entry to mark")))
8086 (error "This command works only in the agenda")))
8087 ((equal ans ?s)
8088 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8089 ((equal ans ?d)
8090 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8091 ((equal ans ?r)
8092 (org-agenda-do-action '(org-remember) t))
8093 ((equal ans ?c)
8094 (org-agenda-do-action '(org-capture) t))
8095 ((equal ans ?\ )
8096 (let ((cw (selected-window)))
8097 (org-switch-to-buffer-other-window
8098 (marker-buffer org-agenda-action-marker))
8099 (goto-char org-agenda-action-marker)
8100 (org-show-context 'agenda)
8101 (select-window cw)))
8102 ((equal ans ?\C-i)
8103 (org-switch-to-buffer-other-window
8104 (marker-buffer org-agenda-action-marker))
8105 (goto-char org-agenda-action-marker)
8106 (org-show-context 'agenda))
8107 (t (error "Invalid agenda action %c" ans)))))
8109 (defun org-agenda-do-action (form &optional current-buffer)
8110 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8111 (let ((org-overriding-default-time (org-get-cursor-date)))
8112 (if current-buffer
8113 (eval form)
8114 (if (not (marker-buffer org-agenda-action-marker))
8115 (error "No entry has been selected for agenda action")
8116 (with-current-buffer (marker-buffer org-agenda-action-marker)
8117 (save-excursion
8118 (save-restriction
8119 (widen)
8120 (goto-char org-agenda-action-marker)
8121 (eval form))))))))
8123 (defun org-agenda-clock-in (&optional arg)
8124 "Start the clock on the currently selected item."
8125 (interactive "P")
8126 (org-agenda-check-no-diary)
8127 (if (equal arg '(4))
8128 (org-clock-in arg)
8129 (let* ((marker (or (org-get-at-bol 'org-marker)
8130 (org-agenda-error)))
8131 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8132 marker))
8133 (pos (marker-position marker))
8134 newhead)
8135 (org-with-remote-undo (marker-buffer marker)
8136 (with-current-buffer (marker-buffer marker)
8137 (widen)
8138 (goto-char pos)
8139 (org-show-context 'agenda)
8140 (org-show-entry)
8141 (org-cycle-hide-drawers 'children)
8142 (org-clock-in arg)
8143 (setq newhead (org-get-heading)))
8144 (org-agenda-change-all-lines newhead hdmarker)))))
8146 (defun org-agenda-clock-out ()
8147 "Stop the currently running clock."
8148 (interactive)
8149 (unless (marker-buffer org-clock-marker)
8150 (error "No running clock"))
8151 (let ((marker (make-marker)) newhead)
8152 (org-with-remote-undo (marker-buffer org-clock-marker)
8153 (with-current-buffer (marker-buffer org-clock-marker)
8154 (save-excursion
8155 (save-restriction
8156 (widen)
8157 (goto-char org-clock-marker)
8158 (org-back-to-heading t)
8159 (move-marker marker (point))
8160 (org-clock-out)
8161 (setq newhead (org-get-heading))))))
8162 (org-agenda-change-all-lines newhead marker)
8163 (move-marker marker nil)))
8165 (defun org-agenda-clock-cancel (&optional arg)
8166 "Cancel the currently running clock."
8167 (interactive "P")
8168 (unless (marker-buffer org-clock-marker)
8169 (error "No running clock"))
8170 (org-with-remote-undo (marker-buffer org-clock-marker)
8171 (org-clock-cancel)))
8173 (defun org-agenda-clock-goto ()
8174 "Jump to the currently clocked in task within the agenda.
8175 If the currently clocked in task is not listed in the agenda
8176 buffer, display it in another window."
8177 (interactive)
8178 (let (pos)
8179 (mapc (lambda (o)
8180 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8181 (setq pos (overlay-start o))))
8182 (overlays-in (point-min) (point-max)))
8183 (cond (pos (goto-char pos))
8184 ;; If the currently clocked entry is not in the agenda
8185 ;; buffer, we visit it in another window:
8186 (org-clock-current-task
8187 (org-switch-to-buffer-other-window (org-clock-goto)))
8188 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8190 (defun org-agenda-diary-entry-in-org-file ()
8191 "Make a diary entry in the file `org-agenda-diary-file'."
8192 (let (d1 d2 char (text "") dp1 dp2)
8193 (if (equal (buffer-name) "*Calendar*")
8194 (setq d1 (calendar-cursor-to-date t)
8195 d2 (car calendar-mark-ring))
8196 (setq dp1 (get-text-property (point-at-bol) 'day))
8197 (unless dp1 (error "No date defined in current line"))
8198 (setq d1 (calendar-gregorian-from-absolute dp1)
8199 d2 (and (ignore-errors (mark))
8200 (save-excursion
8201 (goto-char (mark))
8202 (setq dp2 (get-text-property (point-at-bol) 'day)))
8203 (calendar-gregorian-from-absolute dp2))))
8204 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8205 (setq char (read-char-exclusive))
8206 (cond
8207 ((equal char ?d)
8208 (setq text (read-string "Day entry: "))
8209 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8210 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8211 ((equal char ?a)
8212 (setq d1 (list (car d1) (nth 1 d1)
8213 (read-number (format "Reference year [%d]: " (nth 2 d1))
8214 (nth 2 d1))))
8215 (setq text (read-string "Anniversary (use %d to show years): "))
8216 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8217 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8218 ((equal char ?b)
8219 (setq text (read-string "Block entry: "))
8220 (unless (and d1 d2 (not (equal d1 d2)))
8221 (error "No block of days selected"))
8222 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8223 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8224 ((equal char ?j)
8225 (org-switch-to-buffer-other-window
8226 (find-file-noselect org-agenda-diary-file))
8227 (require 'org-datetree)
8228 (org-datetree-find-date-create d1)
8229 (org-reveal t))
8230 (t (error "Invalid selection character `%c'" char)))))
8232 (defcustom org-agenda-insert-diary-strategy 'date-tree
8233 "Where in `org-agenda-diary-file' should new entries be added?
8234 Valid values:
8236 date-tree in the date tree, as child of the date
8237 top-level as top-level entries at the end of the file."
8238 :group 'org-agenda
8239 :type '(choice
8240 (const :tag "in a date tree" date-tree)
8241 (const :tag "as top level at end of file" top-level)))
8243 (defcustom org-agenda-insert-diary-extract-time nil
8244 "Non-nil means extract any time specification from the diary entry."
8245 :group 'org-agenda
8246 :version "24.1"
8247 :type 'boolean)
8249 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8250 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8251 If TEXT is not empty, it will become the headline of the new entry, and
8252 the resulting entry will not be shown. When TEXT is empty, switch to
8253 `org-agenda-diary-file' and let the user finish the entry there."
8254 (let ((cw (current-window-configuration)))
8255 (org-switch-to-buffer-other-window
8256 (find-file-noselect org-agenda-diary-file))
8257 (widen)
8258 (goto-char (point-min))
8259 (cond
8260 ((eq type 'anniversary)
8261 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8262 (progn
8263 (or (org-at-heading-p t)
8264 (progn
8265 (outline-next-heading)
8266 (insert "* Anniversaries\n\n")
8267 (beginning-of-line -1)))))
8268 (outline-next-heading)
8269 (org-back-over-empty-lines)
8270 (backward-char 1)
8271 (insert "\n")
8272 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8273 (nth 2 d1) (car d1) (nth 1 d1) text)))
8274 ((eq type 'day)
8275 (let ((org-prefix-has-time t)
8276 (org-agenda-time-leading-zero t)
8277 fmt time time2)
8278 (if org-agenda-insert-diary-extract-time
8279 ;; Use org-agenda-format-item to parse text for a time-range and
8280 ;; remove it. FIXME: This is a hack, we should refactor
8281 ;; that function to make time extraction available separately
8282 (setq fmt (org-agenda-format-item nil text nil nil t)
8283 time (get-text-property 0 'time fmt)
8284 time2 (if (> (length time) 0)
8285 ;; split-string removes trailing ...... if
8286 ;; no end time given. First space
8287 ;; separates time from date.
8288 (concat " " (car (split-string time "\\.")))
8289 nil)
8290 text (get-text-property 0 'txt fmt)))
8291 (if (eq org-agenda-insert-diary-strategy 'top-level)
8292 (org-agenda-insert-diary-as-top-level text)
8293 (require 'org-datetree)
8294 (org-datetree-find-date-create d1)
8295 (org-agenda-insert-diary-make-new-entry text))
8296 (org-insert-time-stamp (org-time-from-absolute
8297 (calendar-absolute-from-gregorian d1))
8298 nil nil nil nil time2))
8299 (end-of-line 0))
8300 ((eq type 'block)
8301 (if (> (calendar-absolute-from-gregorian d1)
8302 (calendar-absolute-from-gregorian d2))
8303 (setq d1 (prog1 d2 (setq d2 d1))))
8304 (if (eq org-agenda-insert-diary-strategy 'top-level)
8305 (org-agenda-insert-diary-as-top-level text)
8306 (require 'org-datetree)
8307 (org-datetree-find-date-create d1)
8308 (org-agenda-insert-diary-make-new-entry text))
8309 (org-insert-time-stamp (org-time-from-absolute
8310 (calendar-absolute-from-gregorian d1)))
8311 (insert "--")
8312 (org-insert-time-stamp (org-time-from-absolute
8313 (calendar-absolute-from-gregorian d2)))
8314 (end-of-line 0)))
8315 (if (string-match "\\S-" text)
8316 (progn
8317 (set-window-configuration cw)
8318 (message "%s entry added to %s"
8319 (capitalize (symbol-name type))
8320 (abbreviate-file-name org-agenda-diary-file)))
8321 (org-reveal t)
8322 (message "Please finish entry here"))))
8324 (defun org-agenda-insert-diary-as-top-level (text)
8325 "Make new entry as a top-level entry at the end of the file.
8326 Add TEXT as headline, and position the cursor in the second line so that
8327 a timestamp can be added there."
8328 (widen)
8329 (goto-char (point-max))
8330 (or (bolp) (insert "\n"))
8331 (insert "* " text "\n")
8332 (if org-adapt-indentation (org-indent-to-column 2)))
8334 (defun org-agenda-insert-diary-make-new-entry (text)
8335 "Make new entry as last child of current entry.
8336 Add TEXT as headline, and position the cursor in the second line so that
8337 a timestamp can be added there."
8338 (let ((org-show-following-heading t)
8339 (org-show-siblings t)
8340 (org-show-hierarchy-above t)
8341 (org-show-entry-below t)
8342 col)
8343 (outline-next-heading)
8344 (org-back-over-empty-lines)
8345 (or (looking-at "[ \t]*$")
8346 (progn (insert "\n") (backward-char 1)))
8347 (org-insert-heading nil t)
8348 (org-do-demote)
8349 (setq col (current-column))
8350 (insert text "\n")
8351 (if org-adapt-indentation (org-indent-to-column col))
8352 (let ((org-show-following-heading t)
8353 (org-show-siblings t)
8354 (org-show-hierarchy-above t)
8355 (org-show-entry-below t))
8356 (org-show-context))))
8358 (defun org-agenda-diary-entry ()
8359 "Make a diary entry, like the `i' command from the calendar.
8360 All the standard commands work: block, weekly etc.
8361 When `org-agenda-diary-file' points to a file,
8362 `org-agenda-diary-entry-in-org-file' is called instead to create
8363 entries in that Org-mode file."
8364 (interactive)
8365 (org-agenda-check-type t 'agenda 'timeline)
8366 (if (not (eq org-agenda-diary-file 'diary-file))
8367 (org-agenda-diary-entry-in-org-file)
8368 (require 'diary-lib)
8369 (let* ((char (progn
8370 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8371 (read-char-exclusive)))
8372 (cmd (cdr (assoc char
8373 '((?d . insert-diary-entry)
8374 (?w . insert-weekly-diary-entry)
8375 (?m . insert-monthly-diary-entry)
8376 (?y . insert-yearly-diary-entry)
8377 (?a . insert-anniversary-diary-entry)
8378 (?b . insert-block-diary-entry)
8379 (?c . insert-cyclic-diary-entry)))))
8380 (oldf (symbol-function 'calendar-cursor-to-date))
8381 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8382 (point (point))
8383 (mark (or (mark t) (point))))
8384 (unless cmd
8385 (error "No command associated with <%c>" char))
8386 (unless (and (get-text-property point 'day)
8387 (or (not (equal ?b char))
8388 (get-text-property mark 'day)))
8389 (error "Don't know which date to use for diary entry"))
8390 ;; We implement this by hacking the `calendar-cursor-to-date' function
8391 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8392 (let ((calendar-mark-ring
8393 (list (calendar-gregorian-from-absolute
8394 (or (get-text-property mark 'day)
8395 (get-text-property point 'day))))))
8396 (unwind-protect
8397 (progn
8398 (fset 'calendar-cursor-to-date
8399 (lambda (&optional error dummy)
8400 (calendar-gregorian-from-absolute
8401 (get-text-property point 'day))))
8402 (call-interactively cmd))
8403 (fset 'calendar-cursor-to-date oldf))))))
8405 (defun org-agenda-execute-calendar-command (cmd)
8406 "Execute a calendar command from the agenda, with the date associated to
8407 the cursor position."
8408 (org-agenda-check-type t 'agenda 'timeline)
8409 (require 'diary-lib)
8410 (unless (get-text-property (point) 'day)
8411 (error "Don't know which date to use for calendar command"))
8412 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8413 (point (point))
8414 (date (calendar-gregorian-from-absolute
8415 (get-text-property point 'day)))
8416 ;; the following 2 vars are needed in the calendar
8417 (displayed-month (car date))
8418 (displayed-year (nth 2 date)))
8419 (unwind-protect
8420 (progn
8421 (fset 'calendar-cursor-to-date
8422 (lambda (&optional error dummy)
8423 (calendar-gregorian-from-absolute
8424 (get-text-property point 'day))))
8425 (call-interactively cmd))
8426 (fset 'calendar-cursor-to-date oldf))))
8428 (defun org-agenda-phases-of-moon ()
8429 "Display the phases of the moon for the 3 months around the cursor date."
8430 (interactive)
8431 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8433 (defun org-agenda-holidays ()
8434 "Display the holidays for the 3 months around the cursor date."
8435 (interactive)
8436 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8438 (defvar calendar-longitude)
8439 (defvar calendar-latitude)
8440 (defvar calendar-location-name)
8442 (defun org-agenda-sunrise-sunset (arg)
8443 "Display sunrise and sunset for the cursor date.
8444 Latitude and longitude can be specified with the variables
8445 `calendar-latitude' and `calendar-longitude'. When called with prefix
8446 argument, latitude and longitude will be prompted for."
8447 (interactive "P")
8448 (require 'solar)
8449 (let ((calendar-longitude (if arg nil calendar-longitude))
8450 (calendar-latitude (if arg nil calendar-latitude))
8451 (calendar-location-name
8452 (if arg "the given coordinates" calendar-location-name)))
8453 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8455 (defun org-agenda-goto-calendar ()
8456 "Open the Emacs calendar with the date at the cursor."
8457 (interactive)
8458 (org-agenda-check-type t 'agenda 'timeline)
8459 (let* ((day (or (get-text-property (point) 'day)
8460 (error "Don't know which date to open in calendar")))
8461 (date (calendar-gregorian-from-absolute day))
8462 (calendar-move-hook nil)
8463 (calendar-view-holidays-initially-flag nil)
8464 (calendar-view-diary-initially-flag nil))
8465 (calendar)
8466 (calendar-goto-date date)))
8468 ;;;###autoload
8469 (defun org-calendar-goto-agenda ()
8470 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8471 This is a command that has to be installed in `calendar-mode-map'."
8472 (interactive)
8473 (org-agenda-list nil (calendar-absolute-from-gregorian
8474 (calendar-cursor-to-date))
8475 nil))
8477 (defun org-agenda-convert-date ()
8478 (interactive)
8479 (org-agenda-check-type t 'agenda 'timeline)
8480 (let ((day (get-text-property (point) 'day))
8481 date s)
8482 (unless day
8483 (error "Don't know which date to convert"))
8484 (setq date (calendar-gregorian-from-absolute day))
8485 (setq s (concat
8486 "Gregorian: " (calendar-date-string date) "\n"
8487 "ISO: " (calendar-iso-date-string date) "\n"
8488 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8489 "Julian: " (calendar-julian-date-string date) "\n"
8490 "Astron. JD: " (calendar-astro-date-string date)
8491 " (Julian date number at noon UTC)\n"
8492 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8493 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8494 "French: " (calendar-french-date-string date) "\n"
8495 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8496 "Mayan: " (calendar-mayan-date-string date) "\n"
8497 "Coptic: " (calendar-coptic-date-string date) "\n"
8498 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8499 "Persian: " (calendar-persian-date-string date) "\n"
8500 "Chinese: " (calendar-chinese-date-string date) "\n"))
8501 (with-output-to-temp-buffer "*Dates*"
8502 (princ s))
8503 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8505 ;;; Bulk commands
8507 (defvar org-agenda-bulk-marked-entries nil
8508 "List of markers that refer to marked entries in the agenda.")
8510 (defun org-agenda-bulk-marked-p ()
8511 (eq (get-char-property (point-at-bol) 'type)
8512 'org-marked-entry-overlay))
8514 (defun org-agenda-bulk-mark (&optional arg)
8515 "Mark the entry at point for future bulk action."
8516 (interactive "p")
8517 (dotimes (i (max arg 1))
8518 (unless (org-get-at-bol 'org-agenda-diary-link)
8519 (let* ((m (org-get-at-bol 'org-hd-marker))
8521 (unless (org-agenda-bulk-marked-p)
8522 (unless m (error "Nothing to mark at point"))
8523 (push m org-agenda-bulk-marked-entries)
8524 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8525 (org-overlay-display ov "> "
8526 (org-get-todo-face "TODO")
8527 'evaporate)
8528 (overlay-put ov 'type 'org-marked-entry-overlay))
8529 (beginning-of-line 2)
8530 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8531 (beginning-of-line 2))
8532 (message "%d entries marked for bulk action"
8533 (length org-agenda-bulk-marked-entries))))))
8535 (defun org-agenda-bulk-mark-regexp (regexp)
8536 "Mark entries match REGEXP."
8537 (interactive "sMark entries matching regexp: ")
8538 (let (entries-marked)
8539 (save-excursion
8540 (goto-char (point-min))
8541 (goto-char (next-single-property-change (point) 'txt))
8542 (while (re-search-forward regexp nil t)
8543 (when (string-match regexp (get-text-property (point) 'txt))
8544 (setq entries-marked (+ entries-marked 1))
8545 (call-interactively 'org-agenda-bulk-mark))))
8546 (if (not entries-marked)
8547 (message "No entry matching this regexp."))))
8549 (defun org-agenda-bulk-unmark ()
8550 "Unmark the entry at point for future bulk action."
8551 (interactive)
8552 (when (org-agenda-bulk-marked-p)
8553 (org-agenda-bulk-remove-overlays
8554 (point-at-bol) (+ 2 (point-at-bol)))
8555 (setq org-agenda-bulk-marked-entries
8556 (delete (org-get-at-bol 'org-hd-marker)
8557 org-agenda-bulk-marked-entries)))
8558 (beginning-of-line 2)
8559 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8560 (beginning-of-line 2))
8561 (message "%d entries marked for bulk action"
8562 (length org-agenda-bulk-marked-entries)))
8564 (defun org-agenda-bulk-toggle ()
8565 "Toggle marking the entry at point for bulk action."
8566 (interactive)
8567 (if (org-agenda-bulk-marked-p)
8568 (org-agenda-bulk-unmark)
8569 (org-agenda-bulk-mark)))
8571 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8572 "Remove the mark overlays between BEG and END in the agenda buffer.
8573 BEG and END default to the buffer limits.
8575 This only removes the overlays, it does not remove the markers
8576 from the list in `org-agenda-bulk-marked-entries'."
8577 (interactive)
8578 (mapc (lambda (ov)
8579 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8580 (delete-overlay ov)))
8581 (overlays-in (or beg (point-min)) (or end (point-max)))))
8583 (defun org-agenda-bulk-remove-all-marks ()
8584 "Remove all marks in the agenda buffer.
8585 This will remove the markers, and the overlays."
8586 (interactive)
8587 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8588 (setq org-agenda-bulk-marked-entries nil)
8589 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
8591 (defun org-agenda-bulk-action (&optional arg)
8592 "Execute an remote-editing action on all marked entries.
8593 The prefix arg is passed through to the command if possible."
8594 (interactive "P")
8595 ;; Make sure we have markers, and only valid ones
8596 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8597 (mapc
8598 (lambda (m)
8599 (unless (and (markerp m)
8600 (marker-buffer m)
8601 (buffer-live-p (marker-buffer m))
8602 (marker-position m))
8603 (error "Marker %s for bulk command is invalid" m)))
8604 org-agenda-bulk-marked-entries)
8606 ;; Prompt for the bulk command
8607 (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
8608 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
8609 (when org-agenda-bulk-custom-functions
8610 (concat " Custom: ["
8611 (mapconcat (lambda(f) (char-to-string (car f)))
8612 org-agenda-bulk-custom-functions "")
8613 "]"))))
8614 (let* ((action (read-char-exclusive))
8615 (org-log-refile (if org-log-refile 'time nil))
8616 (entries (reverse org-agenda-bulk-marked-entries))
8617 redo-at-end
8618 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8619 (cond
8620 ((equal action ?$)
8621 (setq cmd '(org-agenda-archive)))
8623 ((equal action ?A)
8624 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8626 ((member action '(?r ?w))
8627 (setq rfloc (org-refile-get-location
8628 "Refile to"
8629 (marker-buffer (car org-agenda-bulk-marked-entries))
8630 org-refile-allow-creating-parent-nodes))
8631 (if (nth 3 rfloc)
8632 (setcar (nthcdr 3 rfloc)
8633 (move-marker (make-marker) (nth 3 rfloc)
8634 (or (get-file-buffer (nth 1 rfloc))
8635 (find-buffer-visiting (nth 1 rfloc))
8636 (error "This should not happen")))))
8638 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8639 redo-at-end t))
8641 ((equal action ?t)
8642 (setq state (org-icompleting-read
8643 "Todo state: "
8644 (with-current-buffer (marker-buffer (car entries))
8645 (mapcar 'list org-todo-keywords-1))))
8646 (setq cmd `(let ((org-inhibit-blocking t)
8647 (org-inhibit-logging 'note))
8648 (org-agenda-todo ,state))))
8650 ((memq action '(?- ?+))
8651 (setq tag (org-icompleting-read
8652 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8653 (with-current-buffer (marker-buffer (car entries))
8654 (delq nil
8655 (mapcar (lambda (x)
8656 (if (stringp (car x)) x)) org-tag-alist)))))
8657 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8659 ((memq action '(?s ?d))
8660 (let* ((date (unless arg
8661 (org-read-date
8662 nil nil nil
8663 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8664 (ans (if arg nil org-read-date-final-answer))
8665 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8666 (setq cmd `(let* ((bound (fboundp 'read-string))
8667 (old (and bound (symbol-function 'read-string))))
8668 (unwind-protect
8669 (progn
8670 (fset 'read-string (lambda (&rest ignore) ,ans))
8671 (eval '(,c1 arg)))
8672 (if bound
8673 (fset 'read-string old)
8674 (fmakunbound 'read-string)))))))
8676 ((equal action ?S)
8677 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8678 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8679 (let ((days (read-number
8680 (format "Scatter tasks across how many %sdays: "
8681 (if arg "week" "")) 7)))
8682 (setq cmd
8683 `(let ((distance (1+ (random ,days))))
8684 (if arg
8685 (let ((dist distance)
8686 (day-of-week
8687 (calendar-day-of-week
8688 (calendar-gregorian-from-absolute (org-today)))))
8689 (dotimes (i (1+ dist))
8690 (while (member day-of-week org-agenda-weekend-days)
8691 (incf distance)
8692 (incf day-of-week)
8693 (if (= day-of-week 7)
8694 (setq day-of-week 0)))
8695 (incf day-of-week)
8696 (if (= day-of-week 7)
8697 (setq day-of-week 0)))))
8698 ;; silently fail when try to replan a sexp entry
8699 (condition-case nil
8700 (let* ((date (calendar-gregorian-from-absolute
8701 (+ (org-today) distance)))
8702 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8703 (nth 2 date))))
8704 (org-agenda-schedule nil time))
8705 (error nil)))))))
8707 ((assoc action org-agenda-bulk-custom-functions)
8708 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8709 redo-at-end t))
8711 ((equal action ?f)
8712 (setq cmd (list (intern
8713 (org-icompleting-read "Function: "
8714 obarray 'fboundp t nil nil)))))
8716 (t (error "Invalid bulk action")))
8718 ;; Sort the markers, to make sure that parents are handled before children
8719 (setq entries (sort entries
8720 (lambda (a b)
8721 (cond
8722 ((equal (marker-buffer a) (marker-buffer b))
8723 (< (marker-position a) (marker-position b)))
8725 (string< (buffer-name (marker-buffer a))
8726 (buffer-name (marker-buffer b))))))))
8728 ;; Now loop over all markers and apply cmd
8729 (while (setq e (pop entries))
8730 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8731 (if (not pos)
8732 (progn (message "Skipping removed entry at %s" e)
8733 (setq cntskip (1+ cntskip)))
8734 (goto-char pos)
8735 (let (org-loop-over-headlines-in-active-region)
8736 (eval cmd))
8737 (setq org-agenda-bulk-marked-entries
8738 (delete e org-agenda-bulk-marked-entries))
8739 (setq cnt (1+ cnt))))
8740 (setq org-agenda-bulk-marked-entries nil)
8741 (org-agenda-bulk-remove-all-marks)
8742 (when redo-at-end (org-agenda-redo))
8743 (message "Acted on %d entries%s"
8745 (if (= cntskip 0)
8747 (format ", skipped %d (disappeared before their turn)"
8748 cntskip)))))
8750 ;;; Flagging notes
8752 (defun org-agenda-show-the-flagging-note ()
8753 "Display the flagging note in the other window.
8754 When called a second time in direct sequence, offer to remove the FLAGGING
8755 tag and (if present) the flagging note."
8756 (interactive)
8757 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8758 (win (selected-window))
8759 note heading newhead)
8760 (unless hdmarker
8761 (error "No linked entry at point"))
8762 (if (and (eq this-command last-command)
8763 (y-or-n-p "Unflag and remove any flagging note? "))
8764 (progn
8765 (org-agenda-remove-flag hdmarker)
8766 (let ((win (get-buffer-window "*Flagging Note*")))
8767 (and win (delete-window win)))
8768 (message "Entry unflagged"))
8769 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8770 (unless note
8771 (error "No flagging note"))
8772 (org-kill-new note)
8773 (org-switch-to-buffer-other-window "*Flagging Note*")
8774 (erase-buffer)
8775 (insert note)
8776 (goto-char (point-min))
8777 (while (re-search-forward "\\\\n" nil t)
8778 (replace-match "\n" t t))
8779 (goto-char (point-min))
8780 (select-window win)
8781 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8783 (defun org-agenda-remove-flag (marker)
8784 "Remove the FLAGGED tag and any flagging note in the entry."
8785 (let (newhead)
8786 (org-with-point-at marker
8787 (org-toggle-tag "FLAGGED" 'off)
8788 (org-entry-delete nil "THEFLAGGINGNOTE")
8789 (setq newhead (org-get-heading)))
8790 (org-agenda-change-all-lines newhead marker)
8791 (message "Entry unflagged")))
8793 (defun org-agenda-get-any-marker (&optional pos)
8794 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8795 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8797 ;;; Appointment reminders
8799 (defvar appt-time-msg-list)
8801 ;;;###autoload
8802 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8803 "Activate appointments found in `org-agenda-files'.
8804 With a \\[universal-argument] prefix, refresh the list of
8805 appointments.
8807 If FILTER is t, interactively prompt the user for a regular
8808 expression, and filter out entries that don't match it.
8810 If FILTER is a string, use this string as a regular expression
8811 for filtering entries out.
8813 If FILTER is a function, filter out entries against which
8814 calling the function returns nil. This function takes one
8815 argument: an entry from `org-agenda-get-day-entries'.
8817 FILTER can also be an alist with the car of each cell being
8818 either 'headline or 'category. For example:
8820 '((headline \"IMPORTANT\")
8821 (category \"Work\"))
8823 will only add headlines containing IMPORTANT or headlines
8824 belonging to the \"Work\" category.
8826 ARGS are symbols indicating what kind of entries to consider.
8827 By default `org-agenda-to-appt' will use :deadline, :scheduled
8828 and :timestamp entries. See the docstring of `org-diary' for
8829 details and examples."
8830 (interactive "P")
8831 (if refresh (setq appt-time-msg-list nil))
8832 (if (eq filter t)
8833 (setq filter (read-from-minibuffer "Regexp filter: ")))
8834 (let* ((cnt 0) ; count added events
8835 (scope (or args '(:deadline :scheduled :timestamp)))
8836 (org-agenda-new-buffers nil)
8837 (org-deadline-warning-days 0)
8838 ;; Do not use `org-today' here because appt only takes
8839 ;; time and without date as argument, so it may pass wrong
8840 ;; information otherwise
8841 (today (org-date-to-gregorian
8842 (time-to-days (current-time))))
8843 (org-agenda-restrict nil)
8844 (files (org-agenda-files 'unrestricted)) entries file)
8845 ;; Get all entries which may contain an appt
8846 (org-prepare-agenda-buffers files)
8847 (while (setq file (pop files))
8848 (setq entries
8849 (delq nil
8850 (append entries
8851 (apply 'org-agenda-get-day-entries
8852 file today scope)))))
8853 ;; Map thru entries and find if we should filter them out
8854 (mapc
8855 (lambda(x)
8856 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8857 (cat (get-text-property 1 'org-category x))
8858 (tod (get-text-property 1 'time-of-day x))
8859 (ok (or (null filter)
8860 (and (stringp filter) (string-match filter evt))
8861 (and (functionp filter) (funcall filter x))
8862 (and (listp filter)
8863 (let ((cat-filter (cadr (assoc 'category filter)))
8864 (evt-filter (cadr (assoc 'headline filter))))
8865 (or (and (stringp cat-filter)
8866 (string-match cat-filter cat))
8867 (and (stringp evt-filter)
8868 (string-match evt-filter evt))))))))
8869 ;; FIXME: Shall we remove text-properties for the appt text?
8870 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8871 (when (and ok tod)
8872 (setq tod (concat "00" (number-to-string tod))
8873 tod (when (string-match
8874 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8875 (concat (match-string 1 tod) ":"
8876 (match-string 2 tod))))
8877 (appt-add tod evt)
8878 (setq cnt (1+ cnt))))) entries)
8879 (org-release-buffers org-agenda-new-buffers)
8880 (if (eq cnt 0)
8881 (message "No event to add")
8882 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8884 (defun org-agenda-todayp (date)
8885 "Does DATE mean today, when considering `org-extend-today-until'?"
8886 (let ((today (org-today))
8887 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8888 date)))
8889 (eq date today)))
8891 (defun org-agenda-todo-yesterday (&optional arg)
8892 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
8893 (interactive "P")
8894 (let* ((hour (third (decode-time
8895 (org-current-time))))
8896 (org-extend-today-until (1+ hour)))
8897 (org-agenda-todo arg)))
8899 (provide 'org-agenda)
8901 ;;; org-agenda.el ends here