org-agenda.el: New variable for custom bulk action functions.
[org-mode/org-kjn.git] / lisp / org-agenda.el
blob4209b4505e67b1801dc86055beb8217b91adf5bc
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 7.6
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
31 ;;; Code:
33 (require 'org)
34 (eval-when-compile
35 (require 'cl))
37 (declare-function diary-add-to-list "diary-lib"
38 (date string specifier &optional marker globcolor literal))
39 (declare-function calendar-absolute-from-iso "cal-iso" (date))
40 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
41 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
42 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
43 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
44 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
45 (declare-function calendar-french-date-string "cal-french" (&optional date))
46 (declare-function calendar-goto-date "cal-move" (date))
47 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
48 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
49 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
50 (declare-function calendar-iso-from-absolute "cal-iso" (date))
51 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
52 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
53 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
54 (declare-function org-datetree-find-date-create "org-datetree"
55 (date &optional keep-restriction))
56 (declare-function org-columns-quit "org-colview" ())
57 (declare-function diary-date-display-form "diary-lib" (&optional type))
58 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
59 (declare-function org-habit-insert-consistency-graphs
60 "org-habit" (&optional line))
61 (declare-function org-is-habit-p "org-habit" (&optional pom))
62 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
63 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
64 (defvar calendar-mode-map)
65 (defvar org-clock-current-task) ; defined in org-clock.el
66 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
67 (defvar org-habit-show-habits)
68 (defvar org-habit-show-habits-only-for-today)
70 ;; Defined somewhere in this file, but used before definition.
71 (defvar org-agenda-buffer-name)
72 (defvar org-agenda-overriding-header)
73 (defvar org-agenda-title-append nil)
74 (defvar entry)
75 (defvar date)
76 (defvar org-agenda-undo-list)
77 (defvar org-agenda-pending-undo-list)
78 (defvar original-date) ; dynamically scoped, calendar.el does scope this
80 (defcustom org-agenda-confirm-kill 1
81 "When set, remote killing from the agenda buffer needs confirmation.
82 When t, a confirmation is always needed. When a number N, confirmation is
83 only needed when the text to be killed contains more than N non-white lines."
84 :group 'org-agenda
85 :type '(choice
86 (const :tag "Never" nil)
87 (const :tag "Always" t)
88 (integer :tag "When more than N lines")))
90 (defcustom org-agenda-compact-blocks nil
91 "Non-nil means make the block agenda more compact.
92 This is done globally by leaving out lines like the agenda span
93 name and week number or the separator lines."
94 :group 'org-agenda
95 :type 'boolean)
97 (defcustom org-agenda-block-separator ?=
98 "The separator between blocks in the agenda.
99 If this is a string, it will be used as the separator, with a newline added.
100 If it is a character, it will be repeated to fill the window width.
101 If nil the separator is disabled. In `org-agenda-custom-commands' this
102 addresses the separator between the current and the previous block."
103 :group 'org-agenda
104 :type '(choice
105 (const :tag "Disabled" nil)
106 (character)
107 (string)))
109 (defgroup org-agenda-export nil
110 "Options concerning exporting agenda views in Org-mode."
111 :tag "Org Agenda Export"
112 :group 'org-agenda)
114 (defcustom org-agenda-with-colors t
115 "Non-nil means use colors in agenda views."
116 :group 'org-agenda-export
117 :type 'boolean)
119 (defcustom org-agenda-exporter-settings nil
120 "Alist of variable/value pairs that should be active during agenda export.
121 This is a good place to set options for ps-print and for htmlize.
122 Note that the way this is implemented, the values will be evaluated
123 before assigned to the variables. So make sure to quote values you do
124 *not* want evaluated, for example
126 (setq org-agenda-exporter-settings
127 '((ps-print-color-p 'black-white)))"
128 :group 'org-agenda-export
129 :type '(repeat
130 (list
131 (variable)
132 (sexp :tag "Value"))))
134 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
135 "Hook run in temporary buffer before writing it to an export file.
136 A useful function is `org-agenda-add-entry-text'."
137 :group 'org-agenda-export
138 :type 'hook
139 :options '(org-agenda-add-entry-text))
141 (defcustom org-agenda-add-entry-text-maxlines 0
142 "Maximum number of entry text lines to be added to agenda.
143 This is only relevant when `org-agenda-add-entry-text' is part of
144 `org-agenda-before-write-hook', which it is by default.
145 When this is 0, nothing will happen. When it is greater than 0, it
146 specifies the maximum number of lines that will be added for each entry
147 that is listed in the agenda view.
149 Note that this variable is not used during display, only when exporting
150 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
151 and `org-agenda-entry-text-maxlines'."
152 :group 'org-agenda
153 :type 'integer)
155 (defcustom org-agenda-add-entry-text-descriptive-links t
156 "Non-nil means export org-links as descriptive links in agenda added text.
157 This variable applies to the text added to the agenda when
158 `org-agenda-add-entry-text-maxlines' is larger than 0.
159 When this variable nil, the URL will (also) be shown."
160 :group 'org-agenda
161 :type 'boolean)
163 (defcustom org-agenda-export-html-style ""
164 "The style specification for exported HTML Agenda files.
165 If this variable contains a string, it will replace the default <style>
166 section as produced by `htmlize'.
167 Since there are different ways of setting style information, this variable
168 needs to contain the full HTML structure to provide a style, including the
169 surrounding HTML tags. The style specifications should include definitions
170 the fonts used by the agenda, here is an example:
172 <style type=\"text/css\">
173 p { font-weight: normal; color: gray; }
174 .org-agenda-structure {
175 font-size: 110%;
176 color: #003399;
177 font-weight: 600;
179 .org-todo {
180 color: #cc6666;
181 font-weight: bold;
183 .org-agenda-done {
184 color: #339933;
186 .org-done {
187 color: #339933;
189 .title { text-align: center; }
190 .todo, .deadline { color: red; }
191 .done { color: green; }
192 </style>
194 or, if you want to keep the style in a file,
196 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
198 As the value of this option simply gets inserted into the HTML <head> header,
199 you can \"misuse\" it to also add other text to the header. However,
200 <style>...</style> is required, if not present the variable will be ignored."
201 :group 'org-agenda-export
202 :group 'org-export-html
203 :type 'string)
205 (defcustom org-agenda-persistent-filter nil
206 "When set, keep filters from one agenda view to the next."
207 :group 'org-agenda
208 :type 'boolean)
210 (defgroup org-agenda-custom-commands nil
211 "Options concerning agenda views in Org-mode."
212 :tag "Org Agenda Custom Commands"
213 :group 'org-agenda)
215 (defconst org-sorting-choice
216 '(choice
217 (const time-up) (const time-down)
218 (const category-keep) (const category-up) (const category-down)
219 (const tag-down) (const tag-up)
220 (const priority-up) (const priority-down)
221 (const todo-state-up) (const todo-state-down)
222 (const effort-up) (const effort-down)
223 (const habit-up) (const habit-down)
224 (const alpha-up) (const alpha-down)
225 (const user-defined-up) (const user-defined-down))
226 "Sorting choices.")
228 (defconst org-agenda-custom-commands-local-options
229 `(repeat :tag "Local settings for this command. Remember to quote values"
230 (choice :tag "Setting"
231 (list :tag "Heading for this block"
232 (const org-agenda-overriding-header)
233 (string :tag "Headline"))
234 (list :tag "Files to be searched"
235 (const org-agenda-files)
236 (list
237 (const :format "" quote)
238 (repeat (file))))
239 (list :tag "Sorting strategy"
240 (const org-agenda-sorting-strategy)
241 (list
242 (const :format "" quote)
243 (repeat
244 ,org-sorting-choice)))
245 (list :tag "Prefix format"
246 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
247 (string))
248 (list :tag "Number of days in agenda"
249 (const org-agenda-span)
250 (choice (const :tag "Day" 'day)
251 (const :tag "Week" 'week)
252 (const :tag "Month" 'month)
253 (const :tag "Year" 'year)
254 (integer :tag "Custom")))
255 (list :tag "Fixed starting date"
256 (const org-agenda-start-day)
257 (string :value "2007-11-01"))
258 (list :tag "Start on day of week"
259 (const org-agenda-start-on-weekday)
260 (choice :value 1
261 (const :tag "Today" nil)
262 (integer :tag "Weekday No.")))
263 (list :tag "Include data from diary"
264 (const org-agenda-include-diary)
265 (boolean))
266 (list :tag "Deadline Warning days"
267 (const org-deadline-warning-days)
268 (integer :value 1))
269 (list :tag "Tags filter preset"
270 (const org-agenda-filter-preset)
271 (list
272 (const :format "" quote)
273 (repeat
274 (string :tag "+tag or -tag"))))
275 (list :tag "Set daily/weekly entry types"
276 (const org-agenda-entry-types)
277 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
278 (const :deadline)
279 (const :scheduled)
280 (const :timestamp)
281 (const :sexp)))
282 (list :tag "Standard skipping condition"
283 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
284 (const org-agenda-skip-function)
285 (list
286 (const :format "" quote)
287 (list
288 (choice
289 :tag "Skipping range"
290 (const :tag "Skip entry" org-agenda-skip-entry-if)
291 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
292 (repeat :inline t :tag "Conditions for skipping"
293 (choice
294 :tag "Condition type"
295 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
296 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
297 (list :tag "TODO state is" :inline t
298 (const 'todo)
299 (choice
300 (const :tag "any not-done state" 'todo)
301 (const :tag "any done state" 'done)
302 (const :tag "any state" 'any)
303 (list :tag "Keyword list"
304 (const :format "" quote)
305 (repeat (string :tag "Keyword")))))
306 (list :tag "TODO state is not" :inline t
307 (const 'nottodo)
308 (choice
309 (const :tag "any not-done state" 'todo)
310 (const :tag "any done state" 'done)
311 (const :tag "any state" 'any)
312 (list :tag "Keyword list"
313 (const :format "" quote)
314 (repeat (string :tag "Keyword")))))
315 (const :tag "scheduled" 'scheduled)
316 (const :tag "not scheduled" 'notscheduled)
317 (const :tag "deadline" 'deadline)
318 (const :tag "no deadline" 'notdeadline)
319 (const :tag "timestamp" 'timestamp)
320 (const :tag "no timestamp" 'nottimestamp))))))
321 (list :tag "Non-standard skipping condition"
322 :value (org-agenda-skip-function)
323 (const org-agenda-skip-function)
324 (sexp :tag "Function or form (quoted!)"))
325 (list :tag "Any variable"
326 (variable :tag "Variable")
327 (sexp :tag "Value (sexp)"))))
328 "Selection of examples for agenda command settings.
329 This will be spliced into the custom type of
330 `org-agenda-custom-commands'.")
333 (defcustom org-agenda-custom-commands nil
334 "Custom commands for the agenda.
335 These commands will be offered on the splash screen displayed by the
336 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
338 (key desc type match settings files)
340 key The key (one or more characters as a string) to be associated
341 with the command.
342 desc A description of the command, when omitted or nil, a default
343 description is built using MATCH.
344 type The command type, any of the following symbols:
345 agenda The daily/weekly agenda.
346 todo Entries with a specific TODO keyword, in all agenda files.
347 search Entries containing search words entry or headline.
348 tags Tags/Property/TODO match in all agenda files.
349 tags-todo Tags/P/T match in all agenda files, TODO entries only.
350 todo-tree Sparse tree of specific TODO keyword in *current* file.
351 tags-tree Sparse tree with all tags matches in *current* file.
352 occur-tree Occur sparse tree for *current* file.
353 ... A user-defined function.
354 match What to search for:
355 - a single keyword for TODO keyword searches
356 - a tags match expression for tags searches
357 - a word search expression for text searches.
358 - a regular expression for occur searches
359 For all other commands, this should be the empty string.
360 settings A list of option settings, similar to that in a let form, so like
361 this: ((opt1 val1) (opt2 val2) ...). The values will be
362 evaluated at the moment of execution, so quote them when needed.
363 files A list of files file to write the produced agenda buffer to
364 with the command `org-store-agenda-views'.
365 If a file name ends in \".html\", an HTML version of the buffer
366 is written out. If it ends in \".ps\", a postscript version is
367 produced. Otherwise, only the plain text is written to the file.
369 You can also define a set of commands, to create a composite agenda buffer.
370 In this case, an entry looks like this:
372 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
374 where
376 desc A description string to be displayed in the dispatcher menu.
377 cmd An agenda command, similar to the above. However, tree commands
378 are no allowed, but instead you can get agenda and global todo list.
379 So valid commands for a set are:
380 (agenda \"\" settings)
381 (alltodo \"\" settings)
382 (stuck \"\" settings)
383 (todo \"match\" settings files)
384 (search \"match\" settings files)
385 (tags \"match\" settings files)
386 (tags-todo \"match\" settings files)
388 Each command can carry a list of options, and another set of options can be
389 given for the whole set of commands. Individual command options take
390 precedence over the general options.
392 When using several characters as key to a command, the first characters
393 are prefix commands. For the dispatcher to display useful information, you
394 should provide a description for the prefix, like
396 (setq org-agenda-custom-commands
397 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
398 (\"hl\" tags \"+HOME+Lisa\")
399 (\"hp\" tags \"+HOME+Peter\")
400 (\"hk\" tags \"+HOME+Kim\")))"
401 :group 'org-agenda-custom-commands
402 :type `(repeat
403 (choice :value ("x" "Describe command here" tags "" nil)
404 (list :tag "Single command"
405 (string :tag "Access Key(s) ")
406 (option (string :tag "Description"))
407 (choice
408 (const :tag "Agenda" agenda)
409 (const :tag "TODO list" alltodo)
410 (const :tag "Search words" search)
411 (const :tag "Stuck projects" stuck)
412 (const :tag "Tags/Property match (all agenda files)" tags)
413 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
414 (const :tag "TODO keyword search (all agenda files)" todo)
415 (const :tag "Tags sparse tree (current buffer)" tags-tree)
416 (const :tag "TODO keyword tree (current buffer)" todo-tree)
417 (const :tag "Occur tree (current buffer)" occur-tree)
418 (sexp :tag "Other, user-defined function"))
419 (string :tag "Match (only for some commands)")
420 ,org-agenda-custom-commands-local-options
421 (option (repeat :tag "Export" (file :tag "Export to"))))
422 (list :tag "Command series, all agenda files"
423 (string :tag "Access Key(s)")
424 (string :tag "Description ")
425 (repeat :tag "Component"
426 (choice
427 (list :tag "Agenda"
428 (const :format "" agenda)
429 (const :tag "" :format "" "")
430 ,org-agenda-custom-commands-local-options)
431 (list :tag "TODO list (all keywords)"
432 (const :format "" alltodo)
433 (const :tag "" :format "" "")
434 ,org-agenda-custom-commands-local-options)
435 (list :tag "Search words"
436 (const :format "" search)
437 (string :tag "Match")
438 ,org-agenda-custom-commands-local-options)
439 (list :tag "Stuck projects"
440 (const :format "" stuck)
441 (const :tag "" :format "" "")
442 ,org-agenda-custom-commands-local-options)
443 (list :tag "Tags search"
444 (const :format "" tags)
445 (string :tag "Match")
446 ,org-agenda-custom-commands-local-options)
447 (list :tag "Tags search, TODO entries only"
448 (const :format "" tags-todo)
449 (string :tag "Match")
450 ,org-agenda-custom-commands-local-options)
451 (list :tag "TODO keyword search"
452 (const :format "" todo)
453 (string :tag "Match")
454 ,org-agenda-custom-commands-local-options)
455 (list :tag "Other, user-defined function"
456 (symbol :tag "function")
457 (string :tag "Match")
458 ,org-agenda-custom-commands-local-options)))
460 (repeat :tag "Settings for entire command set"
461 (list (variable :tag "Any variable")
462 (sexp :tag "Value")))
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (cons :tag "Prefix key documentation"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")))))
468 (defcustom org-agenda-query-register ?o
469 "The register holding the current query string.
470 The purpose of this is that if you construct a query string interactively,
471 you can then use it to define a custom command."
472 :group 'org-agenda-custom-commands
473 :type 'character)
475 (defcustom org-stuck-projects
476 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
477 "How to identify stuck projects.
478 This is a list of four items:
479 1. A tags/todo/property matcher string that is used to identify a project.
480 See the manual for a description of tag and property searches.
481 The entire tree below a headline matched by this is considered one project.
482 2. A list of TODO keywords identifying non-stuck projects.
483 If the project subtree contains any headline with one of these todo
484 keywords, the project is considered to be not stuck. If you specify
485 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
486 3. A list of tags identifying non-stuck projects.
487 If the project subtree contains any headline with one of these tags,
488 the project is considered to be not stuck. If you specify \"*\" as
489 a tag, any tag will mark the project unstuck. Note that this is about
490 the explicit presence of a tag somewhere in the subtree, inherited
491 tags to not count here. If inherited tags make a project not stuck,
492 use \"-TAG\" in the tags part of the matcher under (1.) above.
493 4. An arbitrary regular expression matching non-stuck projects.
495 If the project turns out to be not stuck, search continues also in the
496 subtree to see if any of the subtasks have project status.
498 See also the variable `org-tags-match-list-sublevels' which applies
499 to projects matched by this search as well.
501 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
502 or `C-c a #' to produce the list."
503 :group 'org-agenda-custom-commands
504 :type '(list
505 (string :tag "Tags/TODO match to identify a project")
506 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
507 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
508 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
510 (defcustom org-agenda-filter-effort-default-operator "<"
511 "The default operator for effort estimate filtering.
512 If you select an effort estimate limit without first pressing an operator,
513 this one will be used."
514 :group 'org-agenda-custom-commands
515 :type '(choice (const :tag "less or equal" "<")
516 (const :tag "greater or equal"">")
517 (const :tag "equal" "=")))
519 (defgroup org-agenda-skip nil
520 "Options concerning skipping parts of agenda files."
521 :tag "Org Agenda Skip"
522 :group 'org-agenda)
524 (defcustom org-agenda-skip-function-global nil
525 "Function to be called at each match during agenda construction.
526 If this function returns nil, the current match should not be skipped.
527 If the function decided to skip an agenda match, is must return the
528 buffer position from which the search should be continued.
529 This may also be a Lisp form, which will be evaluated.
531 This variable will be applied to every agenda match, including
532 tags/property searches and TODO lists. So try to make the test function
533 do its checking as efficiently as possible. To implement a skipping
534 condition just for specific agenda commands, use the variable
535 `org-agenda-skip-function' which can be set in the options section
536 of custom agenda commands."
537 :group 'org-agenda-skip
538 :type 'sexp)
540 (defgroup org-agenda-daily/weekly nil
541 "Options concerning the daily/weekly agenda."
542 :tag "Org Agenda Daily/Weekly"
543 :group 'org-agenda)
544 (defgroup org-agenda-todo-list nil
545 "Options concerning the global todo list agenda view."
546 :tag "Org Agenda Todo List"
547 :group 'org-agenda)
548 (defgroup org-agenda-match-view nil
549 "Options concerning the general tags/property/todo match agenda view."
550 :tag "Org Agenda Match View"
551 :group 'org-agenda)
552 (defgroup org-agenda-search-view nil
553 "Options concerning the general tags/property/todo match agenda view."
554 :tag "Org Agenda Match View"
555 :group 'org-agenda)
557 (defvar org-agenda-archives-mode nil
558 "Non-nil means the agenda will include archived items.
559 If this is the symbol `trees', trees in the selected agenda scope
560 that are marked with the ARCHIVE tag will be included anyway. When this is
561 t, also all archive files associated with the current selection of agenda
562 files will be included.")
564 (defcustom org-agenda-skip-comment-trees t
565 "Non-nil means skip trees that start with the COMMENT keyword.
566 When nil, these trees are also scanned by agenda commands."
567 :group 'org-agenda-skip
568 :type 'boolean)
570 (defcustom org-agenda-todo-list-sublevels t
571 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
572 When nil, the sublevels of a TODO entry are not checked, resulting in
573 potentially much shorter TODO lists."
574 :group 'org-agenda-skip
575 :group 'org-agenda-todo-list
576 :type 'boolean)
578 (defcustom org-agenda-todo-ignore-with-date nil
579 "Non-nil means don't show entries with a date in the global todo list.
580 You can use this if you prefer to mark mere appointments with a TODO keyword,
581 but don't want them to show up in the TODO list.
582 When this is set, it also covers deadlines and scheduled items, the settings
583 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
584 will be ignored.
585 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
586 :group 'org-agenda-skip
587 :group 'org-agenda-todo-list
588 :type 'boolean)
590 (defcustom org-agenda-todo-ignore-timestamp nil
591 "Non-nil means don't show entries with a timestamp.
592 This applies when creating the global todo list.
593 Valid values are:
595 past Don't show entries for today or in the past.
597 future Don't show entries with a timestamp in the future.
598 The idea behind this is that if it has a future
599 timestamp, you don't want to think about it until the
600 date.
602 all Don't show any entries with a timestamp in the global todo list.
603 The idea behind this is that by setting a timestamp, you
604 have already \"taken care\" of this item.
606 This variable can also have an integer as a value. If positive (N),
607 todos with a timestamp N or more days in the future will be ignored. If
608 negative (-N), todos with a timestamp N or more days in the past will be
609 ignored. If 0, todos with a timestamp either today or in the future will
610 be ignored. For example, a value of -1 will exclude todos with a
611 timestamp in the past (yesterday or earlier), while a value of 7 will
612 exclude todos with a timestamp a week or more in the future.
614 See also `org-agenda-todo-ignore-with-date'.
615 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
616 to make his option also apply to the tags-todo list."
617 :group 'org-agenda-skip
618 :group 'org-agenda-todo-list
619 :type '(choice
620 (const :tag "Ignore future timestamp todos" future)
621 (const :tag "Ignore past or present timestamp todos" past)
622 (const :tag "Ignore all timestamp todos" all)
623 (const :tag "Show timestamp todos" nil)
624 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
626 (defcustom org-agenda-todo-ignore-scheduled nil
627 "Non-nil means, ignore some scheduled TODO items when making TODO list.
628 This applies when creating the global todo list.
629 Valid values are:
631 past Don't show entries scheduled today or in the past.
633 future Don't show entries scheduled in the future.
634 The idea behind this is that by scheduling it, you don't want to
635 think about it until the scheduled date.
637 all Don't show any scheduled entries in the global todo list.
638 The idea behind this is that by scheduling it, you have already
639 \"taken care\" of this item.
641 t Same as `all', for backward compatibility.
643 This variable can also have an integer as a value. See
644 `org-agenda-todo-ignore-timestamp' for more details.
646 See also `org-agenda-todo-ignore-with-date'.
647 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
648 to make his option also apply to the tags-todo list."
649 :group 'org-agenda-skip
650 :group 'org-agenda-todo-list
651 :type '(choice
652 (const :tag "Ignore future-scheduled todos" future)
653 (const :tag "Ignore past- or present-scheduled todos" past)
654 (const :tag "Ignore all scheduled todos" all)
655 (const :tag "Ignore all scheduled todos (compatibility)" t)
656 (const :tag "Show scheduled todos" nil)
657 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
659 (defcustom org-agenda-todo-ignore-deadlines nil
660 "Non-nil means ignore some deadlined TODO items when making TODO list.
661 There are different motivations for using different values, please think
662 carefully when configuring this variable.
664 This applies when creating the global todo list.
665 Valid values are:
667 near Don't show near deadline entries. A deadline is near when it is
668 closer than `org-deadline-warning-days' days. The idea behind this
669 is that such items will appear in the agenda anyway.
671 far Don't show TODO entries where a deadline has been defined, but
672 the deadline is not near. This is useful if you don't want to
673 use the todo list to figure out what to do now.
675 past Don't show entries with a deadline timestamp for today or in the past.
677 future Don't show entries with a deadline timestamp in the future, not even
678 when they become `near' ones. Use it with caution.
680 all Ignore all TODO entries that do have a deadline.
682 t Same as `near', for backward compatibility.
684 This variable can also have an integer as a value. See
685 `org-agenda-todo-ignore-timestamp' for more details.
687 See also `org-agenda-todo-ignore-with-date'.
688 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
689 to make his option also apply to the tags-todo list."
690 :group 'org-agenda-skip
691 :group 'org-agenda-todo-list
692 :type '(choice
693 (const :tag "Ignore near deadlines" near)
694 (const :tag "Ignore near deadlines (compatibility)" t)
695 (const :tag "Ignore far deadlines" far)
696 (const :tag "Ignore all TODOs with a deadlines" all)
697 (const :tag "Show all TODOs, even if they have a deadline" nil)
698 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
700 (defcustom org-agenda-tags-todo-honor-ignore-options nil
701 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
702 The variables
703 `org-agenda-todo-ignore-with-date',
704 `org-agenda-todo-ignore-timestamp',
705 `org-agenda-todo-ignore-scheduled',
706 `org-agenda-todo-ignore-deadlines'
707 make the global TODO list skip entries that have time stamps of certain
708 kinds. If this option is set, the same options will also apply for the
709 tags-todo search, which is the general tags/property matcher
710 restricted to unfinished TODO entries only."
711 :group 'org-agenda-skip
712 :group 'org-agenda-todo-list
713 :group 'org-agenda-match-view
714 :type 'boolean)
716 (defcustom org-agenda-skip-scheduled-if-done nil
717 "Non-nil means don't show scheduled items in agenda when they are done.
718 This is relevant for the daily/weekly agenda, not for the TODO list. And
719 it applies only to the actual date of the scheduling. Warnings about
720 an item with a past scheduling dates are always turned off when the item
721 is DONE."
722 :group 'org-agenda-skip
723 :group 'org-agenda-daily/weekly
724 :type 'boolean)
726 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
727 "Non-nil means skip scheduling line if same entry shows because of deadline.
728 In the agenda of today, an entry can show up multiple times because
729 it is both scheduled and has a nearby deadline, and maybe a plain time
730 stamp as well.
731 When this variable is t, then only the deadline is shown and the fact that
732 the entry is scheduled today or was scheduled previously is not shown.
733 When this variable is nil, the entry will be shown several times. When
734 the variable is the symbol `not-today', then skip scheduled previously,
735 but not scheduled today."
736 :group 'org-agenda-skip
737 :group 'org-agenda-daily/weekly
738 :type '(choice
739 (const :tag "Never" nil)
740 (const :tag "Always" t)
741 (const :tag "Not when scheduled today" not-today)))
743 (defcustom org-agenda-skip-deadline-if-done nil
744 "Non-nil means don't show deadlines when the corresponding item is done.
745 When nil, the deadline is still shown and should give you a happy feeling.
746 This is relevant for the daily/weekly agenda. And it applied only to the
747 actually date of the deadline. Warnings about approaching and past-due
748 deadlines are always turned off when the item is DONE."
749 :group 'org-agenda-skip
750 :group 'org-agenda-daily/weekly
751 :type 'boolean)
753 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
754 "Non-nil means skip deadline prewarning when entry is also scheduled.
755 This will apply on all days where a prewarning for the deadline would
756 be shown, but not at the day when the entry is actually due. On that day,
757 the deadline will be shown anyway.
758 This variable may be set to nil, t, or a number which will then give
759 the number of days before the actual deadline when the prewarnings
760 should resume.
761 This can be used in a workflow where the first showing of the deadline will
762 trigger you to schedule it, and then you don't want to be reminded of it
763 because you will take care of it on the day when scheduled."
764 :group 'org-agenda-skip
765 :group 'org-agenda-daily/weekly
766 :type '(choice
767 (const :tag "Alwas show prewarning" nil)
768 (const :tag "Remove prewarning if entry is scheduled" t)
769 (integer :tag "Restart prewarning N days before deadline")))
771 (defcustom org-agenda-skip-additional-timestamps-same-entry t
772 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
773 When non-nil, after the search for timestamps has matched once in an
774 entry, the rest of the entry will not be searched."
775 :group 'org-agenda-skip
776 :type 'boolean)
778 (defcustom org-agenda-skip-timestamp-if-done nil
779 "Non-nil means don't select item by timestamp or -range if it is DONE."
780 :group 'org-agenda-skip
781 :group 'org-agenda-daily/weekly
782 :type 'boolean)
784 (defcustom org-agenda-dim-blocked-tasks t
785 "Non-nil means dim blocked tasks in the agenda display.
786 This causes some overhead during agenda construction, but if you
787 have turned on `org-enforce-todo-dependencies',
788 `org-enforce-todo-checkbox-dependencies', or any other blocking
789 mechanism, this will create useful feedback in the agenda.
791 Instead of t, this variable can also have the value `invisible'.
792 Then blocked tasks will be invisible and only become visible when
793 they become unblocked. An exemption to this behavior is when a task is
794 blocked because of unchecked checkboxes below it. Since checkboxes do
795 not show up in the agenda views, making this task invisible you remove any
796 trace from agenda views that there is something to do. Therefore, a task
797 that is blocked because of checkboxes will never be made invisible, it
798 will only be dimmed."
799 :group 'org-agenda-daily/weekly
800 :group 'org-agenda-todo-list
801 :type '(choice
802 (const :tag "Do not dim" nil)
803 (const :tag "Dim to a grey face" t)
804 (const :tag "Make invisible" invisible)))
806 (defcustom org-timeline-show-empty-dates 3
807 "Non-nil means `org-timeline' also shows dates without an entry.
808 When nil, only the days which actually have entries are shown.
809 When t, all days between the first and the last date are shown.
810 When an integer, show also empty dates, but if there is a gap of more than
811 N days, just insert a special line indicating the size of the gap."
812 :group 'org-agenda-skip
813 :type '(choice
814 (const :tag "None" nil)
815 (const :tag "All" t)
816 (integer :tag "at most")))
818 (defgroup org-agenda-startup nil
819 "Options concerning initial settings in the Agenda in Org Mode."
820 :tag "Org Agenda Startup"
821 :group 'org-agenda)
823 (defcustom org-agenda-menu-show-matcher t
824 "Non-nil means show the match string in the agenda dispatcher menu.
825 When nil, the matcher string is not shown, but is put into the help-echo
826 property so than moving the mouse over the command shows it.
827 Setting it to nil is good if matcher strings are very long and/or if
828 you want to use two-column display (see `org-agenda-menu-two-column')."
829 :group 'org-agenda
830 :type 'boolean)
832 (defcustom org-agenda-menu-two-column nil
833 "Non-nil means, use two columns to show custom commands in the dispatcher.
834 If you use this, you probably want to set `org-agenda-menu-show-matcher'
835 to nil."
836 :group 'org-agenda
837 :type 'boolean)
839 (defcustom org-finalize-agenda-hook nil
840 "Hook run just before displaying an agenda buffer."
841 :group 'org-agenda-startup
842 :type 'hook)
844 (defcustom org-agenda-mouse-1-follows-link nil
845 "Non-nil means mouse-1 on a link will follow the link in the agenda.
846 A longer mouse click will still set point. Does not work on XEmacs.
847 Needs to be set before org.el is loaded."
848 :group 'org-agenda-startup
849 :type 'boolean)
851 (defcustom org-agenda-start-with-follow-mode nil
852 "The initial value of follow mode in a newly created agenda window."
853 :group 'org-agenda-startup
854 :type 'boolean)
856 (defcustom org-agenda-show-outline-path t
857 "Non-nil means show outline path in echo area after line motion."
858 :group 'org-agenda-startup
859 :type 'boolean)
861 (defcustom org-agenda-start-with-entry-text-mode nil
862 "The initial value of entry-text-mode in a newly created agenda window."
863 :group 'org-agenda-startup
864 :type 'boolean)
866 (defcustom org-agenda-entry-text-maxlines 5
867 "Number of text lines to be added when `E' is pressed in the agenda.
869 Note that this variable only used during agenda display. Add add entry text
870 when exporting the agenda, configure the variable
871 `org-agenda-add-entry-ext-maxlines'."
872 :group 'org-agenda
873 :type 'integer)
875 (defcustom org-agenda-entry-text-exclude-regexps nil
876 "List of regular expressions to clean up entry text.
877 The complete matches of all regular expressions in this list will be
878 removed from entry text before it is shown in the agenda."
879 :group 'org-agenda
880 :type '(repeat (regexp)))
882 (defvar org-agenda-entry-text-cleanup-hook nil
883 "Hook that is run after basic cleanup of entry text to be shown in agenda.
884 This cleanup is done in a temporary buffer, so the function may inspect and
885 change the entire buffer.
886 Some default stuff like drawers and scheduling/deadline dates will already
887 have been removed when this is called, as will any matches for regular
888 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
890 (defvar org-agenda-include-inactive-timestamps nil
891 "Non-nil means include inactive time stamps in agenda and timeline.")
893 (defgroup org-agenda-windows nil
894 "Options concerning the windows used by the Agenda in Org Mode."
895 :tag "Org Agenda Windows"
896 :group 'org-agenda)
898 (defcustom org-agenda-window-setup 'reorganize-frame
899 "How the agenda buffer should be displayed.
900 Possible values for this option are:
902 current-window Show agenda in the current window, keeping all other windows.
903 other-window Use `switch-to-buffer-other-window' to display agenda.
904 reorganize-frame Show only two windows on the current frame, the current
905 window and the agenda.
906 other-frame Use `switch-to-buffer-other-frame' to display agenda.
907 Also, when exiting the agenda, kill that frame.
908 See also the variable `org-agenda-restore-windows-after-quit'."
909 :group 'org-agenda-windows
910 :type '(choice
911 (const current-window)
912 (const other-frame)
913 (const other-window)
914 (const reorganize-frame)))
916 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
917 "The min and max height of the agenda window as a fraction of frame height.
918 The value of the variable is a cons cell with two numbers between 0 and 1.
919 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
920 :group 'org-agenda-windows
921 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
923 (defcustom org-agenda-restore-windows-after-quit nil
924 "Non-nil means restore window configuration upon exiting agenda.
925 Before the window configuration is changed for displaying the agenda,
926 the current status is recorded. When the agenda is exited with
927 `q' or `x' and this option is set, the old state is restored. If
928 `org-agenda-window-setup' is `other-frame', the value of this
929 option will be ignored."
930 :group 'org-agenda-windows
931 :type 'boolean)
933 (defcustom org-agenda-ndays nil
934 "Number of days to include in overview display.
935 Should be 1 or 7.
936 Obsolete, see `org-agenda-span'."
937 :group 'org-agenda-daily/weekly
938 :type 'integer)
940 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
942 (defcustom org-agenda-span 'week
943 "Number of days to include in overview display.
944 Can be day, week, month, year, or any number of days.
945 Custom commands can set this variable in the options section."
946 :group 'org-agenda-daily/weekly
947 :type '(choice (const :tag "Day" day)
948 (const :tag "Week" week)
949 (const :tag "Month" month)
950 (const :tag "Year" year)
951 (integer :tag "Custom")))
953 (defcustom org-agenda-start-on-weekday 1
954 "Non-nil means start the overview always on the specified weekday.
955 0 denotes Sunday, 1 denotes Monday etc.
956 When nil, always start on the current day.
957 Custom commands can set this variable in the options section."
958 :group 'org-agenda-daily/weekly
959 :type '(choice (const :tag "Today" nil)
960 (integer :tag "Weekday No.")))
962 (defcustom org-agenda-show-all-dates t
963 "Non-nil means `org-agenda' shows every day in the selected range.
964 When nil, only the days which actually have entries are shown."
965 :group 'org-agenda-daily/weekly
966 :type 'boolean)
968 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
969 "Format string for displaying dates in the agenda.
970 Used by the daily/weekly agenda and by the timeline. This should be
971 a format string understood by `format-time-string', or a function returning
972 the formatted date as a string. The function must take a single argument,
973 a calendar-style date list like (month day year)."
974 :group 'org-agenda-daily/weekly
975 :type '(choice
976 (string :tag "Format string")
977 (function :tag "Function")))
979 (defun org-agenda-format-date-aligned (date)
980 "Format a date string for display in the daily/weekly agenda, or timeline.
981 This function makes sure that dates are aligned for easy reading."
982 (require 'cal-iso)
983 (let* ((dayname (calendar-day-name date))
984 (day (cadr date))
985 (day-of-week (calendar-day-of-week date))
986 (month (car date))
987 (monthname (calendar-month-name month))
988 (year (nth 2 date))
989 (iso-week (org-days-to-iso-week
990 (calendar-absolute-from-gregorian date)))
991 (weekyear (cond ((and (= month 1) (>= iso-week 52))
992 (1- year))
993 ((and (= month 12) (<= iso-week 1))
994 (1+ year))
995 (t year)))
996 (weekstring (if (= day-of-week 1)
997 (format " W%02d" iso-week)
998 "")))
999 (format "%-10s %2d %s %4d%s"
1000 dayname day monthname year weekstring)))
1002 (defcustom org-agenda-time-leading-zero nil
1003 "Non-nil means use leading zero for military times in agenda.
1004 For example, 9:30am would become 09:30 rather than 9:30."
1005 :group 'org-agenda-daily/weekly
1006 :type 'boolean)
1008 (defcustom org-agenda-timegrid-use-ampm nil
1009 "When set, show AM/PM style timestamps on the timegrid."
1010 :group 'org-agenda
1011 :type 'boolean)
1013 (defun org-agenda-time-of-day-to-ampm (time)
1014 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1015 (let* ((hour-number (string-to-number (substring time 0 -3)))
1016 (minute (substring time -2))
1017 (ampm "am"))
1018 (cond
1019 ((equal hour-number 12)
1020 (setq ampm "pm"))
1021 ((> hour-number 12)
1022 (setq ampm "pm")
1023 (setq hour-number (- hour-number 12))))
1024 (concat
1025 (if org-agenda-time-leading-zero
1026 (format "%02d" hour-number)
1027 (format "%02s" (number-to-string hour-number)))
1028 ":" minute ampm)))
1030 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1031 "Conditionally convert TIME to AM/PM format
1032 based on `org-agenda-timegrid-use-ampm'"
1033 (if org-agenda-timegrid-use-ampm
1034 (org-agenda-time-of-day-to-ampm time)
1035 time))
1037 (defcustom org-agenda-weekend-days '(6 0)
1038 "Which days are weekend?
1039 These days get the special face `org-agenda-date-weekend' in the agenda
1040 and timeline buffers."
1041 :group 'org-agenda-daily/weekly
1042 :type '(set :greedy t
1043 (const :tag "Monday" 1)
1044 (const :tag "Tuesday" 2)
1045 (const :tag "Wednesday" 3)
1046 (const :tag "Thursday" 4)
1047 (const :tag "Friday" 5)
1048 (const :tag "Saturday" 6)
1049 (const :tag "Sunday" 0)))
1051 (defcustom org-agenda-include-diary nil
1052 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1053 Custom commands can set this variable in the options section."
1054 :group 'org-agenda-daily/weekly
1055 :type 'boolean)
1057 (defcustom org-agenda-include-deadlines t
1058 "If non-nil, include entries within their deadline warning period.
1059 Custom commands can set this variable in the options section."
1060 :group 'org-agenda-daily/weekly
1061 :type 'boolean)
1063 (defcustom org-agenda-include-all-todo nil
1064 "Set means weekly/daily agenda will always contain all TODO entries.
1065 The TODO entries will be listed at the top of the agenda, before
1066 the entries for specific days.
1067 This option is deprecated, it is better to define a block agenda instead."
1068 :group 'org-agenda-daily/weekly
1069 :type 'boolean)
1071 (defcustom org-agenda-repeating-timestamp-show-all t
1072 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1073 When set to a list of strings, only show occurrences of repeating
1074 stamps for these TODO keywords. When nil, only one occurrence is
1075 shown, either today or the nearest into the future."
1076 :group 'org-agenda-daily/weekly
1077 :type '(choice
1078 (const :tag "Show repeating stamps" t)
1079 (repeat :tag "Show repeating stamps for these TODO keywords"
1080 (string :tag "TODO Keyword"))
1081 (const :tag "Don't show repeating stamps" nil)))
1083 (defcustom org-scheduled-past-days 10000
1084 "No. of days to continue listing scheduled items that are not marked DONE.
1085 When an item is scheduled on a date, it shows up in the agenda on this
1086 day and will be listed until it is marked done for the number of days
1087 given here."
1088 :group 'org-agenda-daily/weekly
1089 :type 'integer)
1091 (defcustom org-agenda-log-mode-items '(closed clock)
1092 "List of items that should be shown in agenda log mode.
1093 This list may contain the following symbols:
1095 closed Show entries that have been closed on that day.
1096 clock Show entries that have received clocked time on that day.
1097 state Show all logged state changes.
1098 Note that instead of changing this variable, you can also press `C-u l' in
1099 the agenda to display all available LOG items temporarily."
1100 :group 'org-agenda-daily/weekly
1101 :type '(set :greedy t (const closed) (const clock) (const state)))
1103 (defcustom org-agenda-clock-consistency-checks
1104 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1105 :gap-ok-around ("4:00")
1106 :default-face ((:background "DarkRed") (:foreground "white"))
1107 :overlap-face nil :gap-face nil :no-end-time-face nil
1108 :long-face nil :short-face nil)
1109 "This is a property list, with the following keys:
1111 :max-duration Mark clocking chunks that are longer than this time.
1112 This is a time string like \"HH:MM\", or the number
1113 of minutes as an integer.
1115 :min-duration Mark clocking chunks that are shorter that this.
1116 This is a time string like \"HH:MM\", or the number
1117 of minutes as an integer.
1119 :max-gap Mark gaps between clocking chunks that are longer than
1120 this duration. A number of minutes, or a string
1121 like \"HH:MM\".
1123 :gap-ok-around List of times during the day which are usually not working
1124 times. When a gap is detected, but the gap contains any
1125 of these times, the gap is *not* reported. For example,
1126 if this is (\"4:00\" \"13:00\") then gaps that contain
1127 4:00 in the morning (i.e. the night) and 13:00
1128 (i.e. a typical lunch time) do not cause a warning.
1129 You should have at least one time during the night in this
1130 list, or otherwise the first task each morning will trigger
1131 a warning because it follows a long gap.
1133 Furthermore, the following properties can be used to define faces for
1134 issue display.
1136 :default-face the default face, if the specific face is undefined
1137 :overlap-face face for overlapping clocks
1138 :gap-face face for gaps between clocks
1139 :no-end-time-face face for incomplete clocks
1140 :long-face face for clock intervals that are too long
1141 :short-face face for clock intervals that are too short"
1142 :group 'org-agenda-daily/weekly
1143 :group 'org-clock
1144 :type 'plist)
1146 (defcustom org-agenda-log-mode-add-notes t
1147 "Non-nil means add first line of notes to log entries in agenda views.
1148 If a log item like a state change or a clock entry is associated with
1149 notes, the first line of these notes will be added to the entry in the
1150 agenda display."
1151 :group 'org-agenda-daily/weekly
1152 :type 'boolean)
1154 (defcustom org-agenda-start-with-log-mode nil
1155 "The initial value of log-mode in a newly created agenda window."
1156 :group 'org-agenda-startup
1157 :group 'org-agenda-daily/weekly
1158 :type 'boolean)
1160 (defcustom org-agenda-start-with-clockreport-mode nil
1161 "The initial value of clockreport-mode in a newly created agenda window."
1162 :group 'org-agenda-startup
1163 :group 'org-agenda-daily/weekly
1164 :type 'boolean)
1166 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1167 "Property list with parameters for the clocktable in clockreport mode.
1168 This is the display mode that shows a clock table in the daily/weekly
1169 agenda, the properties for this dynamic block can be set here.
1170 The usual clocktable parameters are allowed here, but you cannot set
1171 the properties :name, :tstart, :tend, :block, and :scope - these will
1172 be overwritten to make sure the content accurately reflects the
1173 current display in the agenda."
1174 :group 'org-agenda-daily/weekly
1175 :type 'plist)
1177 (defcustom org-agenda-search-view-always-boolean nil
1178 "Non-nil means the search string is interpreted as individual parts.
1180 The search string for search view can either be interpreted as a phrase,
1181 or as a list of snippets that define a boolean search for a number of
1182 strings.
1184 When this is non-nil, the string will be split on whitespace, and each
1185 snippet will be searched individually, and all must match in order to
1186 select an entry. A snippet is then a single string of non-white
1187 characters, or a string in double quotes, or a regexp in {} braces.
1188 If a snippet is preceded by \"-\", the snippet must *not* match.
1189 \"+\" is syntactic sugar for positive selection. Each snippet may
1190 be found as a full word or a partial word, but see the variable
1191 `org-agenda-search-view-force-full-words'.
1193 When this is nil, search will look for the entire search phrase as one,
1194 with each space character matching any amount of whitespace, including
1195 line breaks.
1197 Even when this is nil, you can still switch to Boolean search dynamically
1198 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1199 is a regexp marked with braces like \"{abc}\", this will also switch to
1200 boolean search."
1201 :group 'org-agenda-search-view
1202 :type 'boolean)
1204 (if (fboundp 'defvaralias)
1205 (defvaralias 'org-agenda-search-view-search-words-only
1206 'org-agenda-search-view-always-boolean))
1208 (defcustom org-agenda-search-view-force-full-words nil
1209 "Non-nil means, search words must be matches as complete words.
1210 When nil, they may also match part of a word."
1211 :group 'org-agenda-search-view
1212 :type 'boolean)
1214 (defgroup org-agenda-time-grid nil
1215 "Options concerning the time grid in the Org-mode Agenda."
1216 :tag "Org Agenda Time Grid"
1217 :group 'org-agenda)
1219 (defcustom org-agenda-search-headline-for-time t
1220 "Non-nil means search headline for a time-of-day.
1221 If the headline contains a time-of-day in one format or another, it will
1222 be used to sort the entry into the time sequence of items for a day.
1223 Some people have time stamps in the headline that refer to the creation
1224 time or so, and then this produces an unwanted side effect. If this is
1225 the case for your, use this variable to turn off searching the headline
1226 for a time."
1227 :group 'org-agenda-time-grid
1228 :type 'boolean)
1230 (defcustom org-agenda-use-time-grid t
1231 "Non-nil means show a time grid in the agenda schedule.
1232 A time grid is a set of lines for specific times (like every two hours between
1233 8:00 and 20:00). The items scheduled for a day at specific times are
1234 sorted in between these lines.
1235 For details about when the grid will be shown, and what it will look like, see
1236 the variable `org-agenda-time-grid'."
1237 :group 'org-agenda-time-grid
1238 :type 'boolean)
1240 (defcustom org-agenda-time-grid
1241 '((daily today require-timed)
1242 "----------------"
1243 (800 1000 1200 1400 1600 1800 2000))
1245 "The settings for time grid for agenda display.
1246 This is a list of three items. The first item is again a list. It contains
1247 symbols specifying conditions when the grid should be displayed:
1249 daily if the agenda shows a single day
1250 weekly if the agenda shows an entire week
1251 today show grid on current date, independent of daily/weekly display
1252 require-timed show grid only if at least one item has a time specification
1254 The second item is a string which will be placed behind the grid time.
1256 The third item is a list of integers, indicating the times that should have
1257 a grid line."
1258 :group 'org-agenda-time-grid
1259 :type
1260 '(list
1261 (set :greedy t :tag "Grid Display Options"
1262 (const :tag "Show grid in single day agenda display" daily)
1263 (const :tag "Show grid in weekly agenda display" weekly)
1264 (const :tag "Always show grid for today" today)
1265 (const :tag "Show grid only if any timed entries are present"
1266 require-timed)
1267 (const :tag "Skip grid times already present in an entry"
1268 remove-match))
1269 (string :tag "Grid String")
1270 (repeat :tag "Grid Times" (integer :tag "Time"))))
1272 (defcustom org-agenda-show-current-time-in-grid t
1273 "Non-nil means show the current time in the time grid."
1274 :group 'org-agenda-time-grid
1275 :type 'boolean)
1277 (defcustom org-agenda-current-time-string
1278 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1279 "The string for the current time marker in the agenda."
1280 :group 'org-agenda-time-grid
1281 :type 'string)
1283 (defgroup org-agenda-sorting nil
1284 "Options concerning sorting in the Org-mode Agenda."
1285 :tag "Org Agenda Sorting"
1286 :group 'org-agenda)
1288 (defcustom org-agenda-sorting-strategy
1289 '((agenda habit-down time-up priority-down category-keep)
1290 (todo priority-down category-keep)
1291 (tags priority-down category-keep)
1292 (search category-keep))
1293 "Sorting structure for the agenda items of a single day.
1294 This is a list of symbols which will be used in sequence to determine
1295 if an entry should be listed before another entry. The following
1296 symbols are recognized:
1298 time-up Put entries with time-of-day indications first, early first
1299 time-down Put entries with time-of-day indications first, late first
1300 category-keep Keep the default order of categories, corresponding to the
1301 sequence in `org-agenda-files'.
1302 category-up Sort alphabetically by category, A-Z.
1303 category-down Sort alphabetically by category, Z-A.
1304 tag-up Sort alphabetically by last tag, A-Z.
1305 tag-down Sort alphabetically by last tag, Z-A.
1306 priority-up Sort numerically by priority, high priority last.
1307 priority-down Sort numerically by priority, high priority first.
1308 todo-state-up Sort by todo state, tasks that are done last.
1309 todo-state-down Sort by todo state, tasks that are done first.
1310 effort-up Sort numerically by estimated effort, high effort last.
1311 effort-down Sort numerically by estimated effort, high effort first.
1312 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1313 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1314 habit-up Put entries that are habits first
1315 habit-down Put entries that are habits last
1316 alpha-up Sort headlines alphabetically
1317 alpha-down Sort headlines alphabetically, reversed
1319 The different possibilities will be tried in sequence, and testing stops
1320 if one comparison returns a \"not-equal\". For example, the default
1321 '(time-up category-keep priority-down)
1322 means: Pull out all entries having a specified time of day and sort them,
1323 in order to make a time schedule for the current day the first thing in the
1324 agenda listing for the day. Of the entries without a time indication, keep
1325 the grouped in categories, don't sort the categories, but keep them in
1326 the sequence given in `org-agenda-files'. Within each category sort by
1327 priority.
1329 Leaving out `category-keep' would mean that items will be sorted across
1330 categories by priority.
1332 Instead of a single list, this can also be a set of list for specific
1333 contents, with a context symbol in the car of the list, any of
1334 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1336 Custom commands can bind this variable in the options section."
1337 :group 'org-agenda-sorting
1338 :type `(choice
1339 (repeat :tag "General" ,org-sorting-choice)
1340 (list :tag "Individually"
1341 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1342 (repeat ,org-sorting-choice))
1343 (cons (const :tag "Strategy for TODO lists" todo)
1344 (repeat ,org-sorting-choice))
1345 (cons (const :tag "Strategy for Tags matches" tags)
1346 (repeat ,org-sorting-choice))
1347 (cons (const :tag "Strategy for search matches" search)
1348 (repeat ,org-sorting-choice)))))
1350 (defcustom org-agenda-cmp-user-defined nil
1351 "A function to define the comparison `user-defined'.
1352 This function must receive two arguments, agenda entry a and b.
1353 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1354 the user comparison, return nil.
1355 When this is defined, you can make `user-defined-up' and `user-defined-down'
1356 part of an agenda sorting strategy."
1357 :group 'org-agenda-sorting
1358 :type 'symbol)
1360 (defcustom org-sort-agenda-notime-is-late t
1361 "Non-nil means items without time are considered late.
1362 This is only relevant for sorting. When t, items which have no explicit
1363 time like 15:30 will be considered as 99:01, i.e. later than any items which
1364 do have a time. When nil, the default time is before 0:00. You can use this
1365 option to decide if the schedule for today should come before or after timeless
1366 agenda entries."
1367 :group 'org-agenda-sorting
1368 :type 'boolean)
1370 (defcustom org-sort-agenda-noeffort-is-high t
1371 "Non-nil means items without effort estimate are sorted as high effort.
1372 This also applies when filtering an agenda view with respect to the
1373 < or > effort operator. Then, tasks with no effort defined will be treated
1374 as tasks with high effort.
1375 When nil, such items are sorted as 0 minutes effort."
1376 :group 'org-agenda-sorting
1377 :type 'boolean)
1379 (defgroup org-agenda-line-format nil
1380 "Options concerning the entry prefix in the Org-mode agenda display."
1381 :tag "Org Agenda Line Format"
1382 :group 'org-agenda)
1384 (defcustom org-agenda-prefix-format
1385 '((agenda . " %i %-12:c%?-12t% s")
1386 (timeline . " % s")
1387 (todo . " %i %-12:c")
1388 (tags . " %i %-12:c")
1389 (search . " %i %-12:c"))
1390 "Format specifications for the prefix of items in the agenda views.
1391 An alist with four entries, for the different agenda types. The keys to the
1392 sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
1393 are format strings.
1394 This format works similar to a printf format, with the following meaning:
1396 %c the category of the item, \"Diary\" for entries from the diary, or
1397 as given by the CATEGORY keyword or derived from the file name.
1398 %i the icon category of the item, as give in
1399 `org-agenda-category-icon-alist'.
1400 %T the *last* tag of the item. Last because inherited tags come
1401 first in the list.
1402 %t the time-of-day specification if one applies to the entry, in the
1403 format HH:MM
1404 %s Scheduling/Deadline information, a short string
1405 %(expression) Eval EXPRESSION and replace the control string
1406 by the result
1408 All specifiers work basically like the standard `%s' of printf, but may
1409 contain two additional characters: A question mark just after the `%' and
1410 a whitespace/punctuation character just before the final letter.
1412 If the first character after `%' is a question mark, the entire field
1413 will only be included if the corresponding value applies to the
1414 current entry. This is useful for fields which should have fixed
1415 width when present, but zero width when absent. For example,
1416 \"%?-12t\" will result in a 12 character time field if a time of the
1417 day is specified, but will completely disappear in entries which do
1418 not contain a time.
1420 If there is punctuation or whitespace character just before the final
1421 format letter, this character will be appended to the field value if
1422 the value is not empty. For example, the format \"%-12:c\" leads to
1423 \"Diary: \" if the category is \"Diary\". If the category were be
1424 empty, no additional colon would be inserted.
1426 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1427 - Indent the line with two space characters
1428 - Give the category in a 12 chars wide field, padded with whitespace on
1429 the right (because of `-'). Append a colon if there is a category
1430 (because of `:').
1431 - If there is a time-of-day, put it into a 12 chars wide field. If no
1432 time, don't put in an empty field, just skip it (because of '?').
1433 - Finally, put the scheduling information and append a whitespace.
1435 As another example, if you don't want the time-of-day of entries in
1436 the prefix, you could use:
1438 (setq org-agenda-prefix-format \" %-11:c% s\")
1440 See also the variables `org-agenda-remove-times-when-in-prefix' and
1441 `org-agenda-remove-tags'.
1443 Custom commands can set this variable in the options section."
1444 :type '(choice
1445 (string :tag "General format")
1446 (list :greedy t :tag "View dependent"
1447 (cons (const agenda) (string :tag "Format"))
1448 (cons (const timeline) (string :tag "Format"))
1449 (cons (const todo) (string :tag "Format"))
1450 (cons (const tags) (string :tag "Format"))
1451 (cons (const search) (string :tag "Format"))))
1452 :group 'org-agenda-line-format)
1454 (defvar org-prefix-format-compiled nil
1455 "The compiled version of the most recently used prefix format.
1456 See the variable `org-agenda-prefix-format'.")
1458 (defcustom org-agenda-todo-keyword-format "%-1s"
1459 "Format for the TODO keyword in agenda lines.
1460 Set this to something like \"%-12s\" if you want all TODO keywords
1461 to occupy a fixed space in the agenda display."
1462 :group 'org-agenda-line-format
1463 :type 'string)
1465 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1466 "Text preceding timerange entries in the agenda view.
1467 This is a list with two strings. The first applies when the range
1468 is entirely on one day. The second applies if the range spans several days.
1469 The strings may have two \"%d\" format specifiers which will be filled
1470 with the sequence number of the days, and the total number of days in the
1471 range, respectively."
1472 :group 'org-agenda-line-format
1473 :type '(list
1474 (string :tag "Deadline today ")
1475 (choice :tag "Deadline relative"
1476 (string :tag "Format string")
1477 (function))))
1479 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1480 "Text preceding scheduled items in the agenda view.
1481 This is a list with two strings. The first applies when the item is
1482 scheduled on the current day. The second applies when it has been scheduled
1483 previously, it may contain a %d indicating that this is the nth time that
1484 this item is scheduled, due to automatic rescheduling of unfinished items
1485 for the following day. So this number is one larger than the number of days
1486 that passed since this item was scheduled first."
1487 :group 'org-agenda-line-format
1488 :type '(list
1489 (string :tag "Scheduled today ")
1490 (string :tag "Scheduled previously")))
1492 (defcustom org-agenda-inactive-leader "["
1493 "Text preceding item pulled into the agenda by inactive time stamps.
1494 These entries are added to the agenda when pressing \"[\"."
1495 :group 'org-agenda-line-format
1496 :type '(list
1497 (string :tag "Scheduled today ")
1498 (string :tag "Scheduled previously")))
1500 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1501 "Text preceding deadline items in the agenda view.
1502 This is a list with two strings. The first applies when the item has its
1503 deadline on the current day. The second applies when it is in the past or
1504 in the future, it may contain %d to capture how many days away the deadline
1505 is (was)."
1506 :group 'org-agenda-line-format
1507 :type '(list
1508 (string :tag "Deadline today ")
1509 (choice :tag "Deadline relative"
1510 (string :tag "Format string")
1511 (function))))
1513 (defcustom org-agenda-remove-times-when-in-prefix t
1514 "Non-nil means remove duplicate time specifications in agenda items.
1515 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1516 time-of-day specification in a headline or diary entry is extracted and
1517 placed into the prefix. If this option is non-nil, the original specification
1518 \(a timestamp or -range, or just a plain time(range) specification like
1519 11:30-4pm) will be removed for agenda display. This makes the agenda less
1520 cluttered.
1521 The option can be t or nil. It may also be the symbol `beg', indicating
1522 that the time should only be removed when it is located at the beginning of
1523 the headline/diary entry."
1524 :group 'org-agenda-line-format
1525 :type '(choice
1526 (const :tag "Always" t)
1527 (const :tag "Never" nil)
1528 (const :tag "When at beginning of entry" beg)))
1530 (defcustom org-agenda-remove-timeranges-from-blocks nil
1531 "Non-nil means remove time ranges specifications in agenda
1532 items that span on several days."
1533 :group 'org-agenda-line-format
1534 :type 'boolean)
1536 (defcustom org-agenda-default-appointment-duration nil
1537 "Default duration for appointments that only have a starting time.
1538 When nil, no duration is specified in such cases.
1539 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1540 :group 'org-agenda-line-format
1541 :type '(choice
1542 (integer :tag "Minutes")
1543 (const :tag "No default duration")))
1545 (defcustom org-agenda-show-inherited-tags t
1546 "Non-nil means show inherited tags in each agenda line."
1547 :group 'org-agenda-line-format
1548 :type 'boolean)
1550 (defcustom org-agenda-hide-tags-regexp nil
1551 "Regular expression used to filter away specific tags in agenda views.
1552 This means that these tags will be present, but not be shown in the agenda
1553 line. Secondary filtering will still work on the hidden tags.
1554 Nil means don't hide any tags."
1555 :group 'org-agenda-line-format
1556 :type '(choice
1557 (const :tag "Hide none" nil)
1558 (string :tag "Regexp ")))
1560 (defcustom org-agenda-remove-tags nil
1561 "Non-nil means remove the tags from the headline copy in the agenda.
1562 When this is the symbol `prefix', only remove tags when
1563 `org-agenda-prefix-format' contains a `%T' specifier."
1564 :group 'org-agenda-line-format
1565 :type '(choice
1566 (const :tag "Always" t)
1567 (const :tag "Never" nil)
1568 (const :tag "When prefix format contains %T" prefix)))
1570 (if (fboundp 'defvaralias)
1571 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1572 'org-agenda-remove-tags))
1574 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1575 "Shift tags in agenda items to this column.
1576 If this number is positive, it specifies the column. If it is negative,
1577 it means that the tags should be flushright to that column. For example,
1578 -80 works well for a normal 80 character screen."
1579 :group 'org-agenda-line-format
1580 :type 'integer)
1582 (if (fboundp 'defvaralias)
1583 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1585 (defcustom org-agenda-fontify-priorities 'cookies
1586 "Non-nil means highlight low and high priorities in agenda.
1587 When t, the highest priority entries are bold, lowest priority italic.
1588 However, settings in `org-priority-faces' will overrule these faces.
1589 When this variable is the symbol `cookies', only fontify the
1590 cookies, not the entire task.
1591 This may also be an association list of priority faces, whose
1592 keys are the character values of `org-highest-priority',
1593 `org-default-priority', and `org-lowest-priority' (the default values
1594 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1595 color as a string, or a list like `(:background \"Red\")'.
1596 If it is a color, the variable `org-faces-easy-properties'
1597 determines if it is a foreground or a background color."
1598 :group 'org-agenda-line-format
1599 :type '(choice
1600 (const :tag "Never" nil)
1601 (const :tag "Defaults" t)
1602 (const :tag "Cookies only" cookies)
1603 (repeat :tag "Specify"
1604 (list (character :tag "Priority" :value ?A)
1605 (choice :tag "Face "
1606 (string :tag "Color")
1607 (sexp :tag "Face"))))))
1609 (defcustom org-agenda-day-face-function nil
1610 "Function called to determine what face should be used to display a day.
1611 The only argument passed to that function is the day. It should
1612 returns a face, or nil if does not want to specify a face and let
1613 the normal rules apply."
1614 :group 'org-agenda-line-format
1615 :type 'function)
1617 (defcustom org-agenda-category-icon-alist nil
1618 "Alist of category icon to be displayed in agenda views.
1620 Each entry should have the following format:
1622 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1624 Where CATEGORY-REGEXP is a regexp matching the categories where
1625 the icon should be displayed.
1626 FILE-OR-DATA either a file path or a string containing image data.
1628 The other fields can be omited safely if not needed:
1629 TYPE indicates the image type.
1630 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1631 image data.
1632 PROPS are additional image attributes to assign to the image,
1633 like, e.g. `:ascent center'.
1635 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1637 If you want to set the display properties yourself, just put a
1638 list as second element:
1640 (CATEGORY-REGEXP (MY PROPERTY LIST))
1642 For example, to display a 16px horizontal space for Emacs
1643 category, you can use:
1645 (\"Emacs\" '(space . (:width (16))))"
1646 :group 'org-agenda-line-format
1647 :type '(alist :key-type (string :tag "Regexp matching category")
1648 :value-type (choice (list :tag "Icon"
1649 (string :tag "File or data")
1650 (symbol :tag "Type")
1651 (boolean :tag "Data?")
1652 (repeat :tag "Extra image properties" :inline t symbol))
1653 (list :tag "Display properties" sexp))))
1655 (defgroup org-agenda-column-view nil
1656 "Options concerning column view in the agenda."
1657 :tag "Org Agenda Column View"
1658 :group 'org-agenda)
1660 (defcustom org-agenda-columns-show-summaries t
1661 "Non-nil means show summaries for columns displayed in the agenda view."
1662 :group 'org-agenda-column-view
1663 :type 'boolean)
1665 (defcustom org-agenda-columns-compute-summary-properties t
1666 "Non-nil means recompute all summary properties before column view.
1667 When column view in the agenda is listing properties that have a summary
1668 operator, it can go to all relevant buffers and recompute the summaries
1669 there. This can mean overhead for the agenda column view, but is necessary
1670 to have thing up to date.
1671 As a special case, a CLOCKSUM property also makes sure that the clock
1672 computations are current."
1673 :group 'org-agenda-column-view
1674 :type 'boolean)
1676 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1677 "Non-nil means the duration of an appointment will add to day effort.
1678 The property to which appointment durations will be added is the one given
1679 in the option `org-effort-property'. If an appointment does not have
1680 an end time, `org-agenda-default-appointment-duration' will be used. If that
1681 is not set, an appointment without end time will not contribute to the time
1682 estimate."
1683 :group 'org-agenda-column-view
1684 :type 'boolean)
1686 (defcustom org-agenda-auto-exclude-function nil
1687 "A function called with a tag to decide if it is filtered on '/ RET'.
1688 The sole argument to the function, which is called once for each
1689 possible tag, is a string giving the name of the tag. The
1690 function should return either nil if the tag should be included
1691 as normal, or \"-<TAG>\" to exclude the tag.
1692 Note that for the purpose of tag filtering, only the lower-case version of
1693 all tags will be considered, so that this function will only ever see
1694 the lower-case version of all tags."
1695 :group 'org-agenda
1696 :type 'function)
1698 (defcustom org-agenda-bulk-custom-functions nil
1699 "Alist of characters and custom functions for bulk action.
1700 For example, this value makes those two functions available:
1702 '((?R set-category)
1703 (?C bulk-cut))
1705 With selected entries in an agenda buffer, `B R' will execute
1706 set-category on the selected entries. Note that functions in
1707 this alist don't need to be quoted."
1708 :type 'alist
1709 :group 'org-agenda)
1711 (eval-when-compile
1712 (require 'cl))
1713 (require 'org)
1715 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1716 "Execute BODY with point at location given by `org-hd-marker' property.
1717 If STRING is non-nil, the text property will be fetched from position 0
1718 in that string. If STRING is nil, it will be fetched from the beginning
1719 of the current line."
1720 `(let ((marker (get-text-property (if string 0 (point-at-bol))
1721 'org-hd-marker string)))
1722 (with-current-buffer (marker-buffer marker)
1723 (save-excursion
1724 (goto-char marker)
1725 ,@body))))
1727 (defun org-add-agenda-custom-command (entry)
1728 "Replace or add a command in `org-agenda-custom-commands'.
1729 This is mostly for hacking and trying a new command - once the command
1730 works you probably want to add it to `org-agenda-custom-commands' for good."
1731 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1732 (if ass
1733 (setcdr ass (cdr entry))
1734 (push entry org-agenda-custom-commands))))
1736 ;;; Define the Org-agenda-mode
1738 (defvar org-agenda-mode-map (make-sparse-keymap)
1739 "Keymap for `org-agenda-mode'.")
1740 (if (fboundp 'defvaralias)
1741 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1743 (defvar org-agenda-menu) ; defined later in this file.
1744 (defvar org-agenda-restrict) ; defined later in this file.
1745 (defvar org-agenda-follow-mode nil)
1746 (defvar org-agenda-entry-text-mode nil)
1747 (defvar org-agenda-clockreport-mode nil)
1748 (defvar org-agenda-show-log nil)
1749 (defvar org-agenda-redo-command nil)
1750 (defvar org-agenda-query-string nil)
1751 (defvar org-agenda-mode-hook nil
1752 "Hook for `org-agenda-mode', run after the mode is turned on.")
1753 (defvar org-agenda-type nil)
1754 (defvar org-agenda-force-single-file nil)
1755 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1757 (defun org-agenda-mode ()
1758 "Mode for time-sorted view on action items in Org-mode files.
1760 The following commands are available:
1762 \\{org-agenda-mode-map}"
1763 (interactive)
1764 (kill-all-local-variables)
1765 (setq org-agenda-undo-list nil
1766 org-agenda-pending-undo-list nil
1767 org-agenda-bulk-marked-entries nil)
1768 (setq major-mode 'org-agenda-mode)
1769 ;; Keep global-font-lock-mode from turning on font-lock-mode
1770 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1771 (setq mode-name "Org-Agenda")
1772 (use-local-map org-agenda-mode-map)
1773 (easy-menu-add org-agenda-menu)
1774 (if org-startup-truncated (setq truncate-lines t))
1775 (org-set-local 'line-move-visual nil)
1776 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1777 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1778 ;; Make sure properties are removed when copying text
1779 (when (boundp 'buffer-substring-filters)
1780 (org-set-local 'buffer-substring-filters
1781 (cons (lambda (x)
1782 (set-text-properties 0 (length x) nil x) x)
1783 buffer-substring-filters)))
1784 (unless org-agenda-keep-modes
1785 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1786 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1787 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1788 org-agenda-show-log org-agenda-start-with-log-mode))
1790 (easy-menu-change
1791 '("Agenda") "Agenda Files"
1792 (append
1793 (list
1794 (vector
1795 (if (get 'org-agenda-files 'org-restrict)
1796 "Restricted to single file"
1797 "Edit File List")
1798 '(org-edit-agenda-file-list)
1799 (not (get 'org-agenda-files 'org-restrict)))
1800 "--")
1801 (mapcar 'org-file-menu-entry (org-agenda-files))))
1802 (org-agenda-set-mode-name)
1803 (apply
1804 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1805 (list 'org-agenda-mode-hook)))
1807 (substitute-key-definition 'undo 'org-agenda-undo
1808 org-agenda-mode-map global-map)
1809 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1810 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1811 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1812 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1813 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1814 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1815 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
1816 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1817 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1818 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
1819 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1820 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1821 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1822 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1823 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1824 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1825 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1826 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1827 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1828 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1829 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1830 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1831 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1832 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1833 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1834 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1835 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1836 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1837 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1838 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1839 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1840 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1841 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1842 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1843 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1844 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1845 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1846 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1847 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1848 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1849 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1850 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1851 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1852 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1853 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1855 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1856 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1857 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1858 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1859 (while l (org-defkey org-agenda-mode-map
1860 (int-to-string (pop l)) 'digit-argument)))
1862 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1863 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1864 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1865 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1866 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1867 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1868 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1869 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1870 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1871 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1872 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1873 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1874 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1875 'org-clock-modify-effort-estimate)
1876 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1877 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1878 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1879 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1880 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1881 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1882 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1883 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1884 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1885 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1886 (substitute-key-definition 'next-line 'org-agenda-next-line
1887 org-agenda-mode-map global-map)
1888 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1889 org-agenda-mode-map global-map)
1890 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1891 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1892 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1893 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1894 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1895 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1896 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1897 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1898 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1899 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1900 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1901 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1902 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1903 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1904 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1905 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1906 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1907 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1908 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1909 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1910 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1911 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1912 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1913 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1914 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1915 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1916 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1917 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1918 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1919 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1921 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1922 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1923 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1924 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1925 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1926 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1927 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1928 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1929 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1930 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1932 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1933 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1934 (when org-agenda-mouse-1-follows-link
1935 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1936 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1937 '("Agenda"
1938 ("Agenda Files")
1939 "--"
1940 ("Agenda Dates"
1941 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1942 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1943 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1944 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1945 "--"
1946 ("View"
1947 ["Day View" org-agenda-day-view
1948 :active (org-agenda-check-type nil 'agenda)
1949 :style radio :selected (eq org-agenda-current-span 'day)
1950 :keys "v d (or just d)"]
1951 ["Week View" org-agenda-week-view
1952 :active (org-agenda-check-type nil 'agenda)
1953 :style radio :selected (eq org-agenda-current-span 'week)
1954 :keys "v w (or just w)"]
1955 ["Month View" org-agenda-month-view
1956 :active (org-agenda-check-type nil 'agenda)
1957 :style radio :selected (eq org-agenda-current-span 'month)
1958 :keys "v m"]
1959 ["Year View" org-agenda-year-view
1960 :active (org-agenda-check-type nil 'agenda)
1961 :style radio :selected (eq org-agenda-current-span 'year)
1962 :keys "v y"]
1963 "--"
1964 ["Include Diary" org-agenda-toggle-diary
1965 :style toggle :selected org-agenda-include-diary
1966 :active (org-agenda-check-type nil 'agenda)]
1967 ["Include Deadlines" org-agenda-toggle-deadlines
1968 :style toggle :selected org-agenda-include-deadlines
1969 :active (org-agenda-check-type nil 'agenda)]
1970 ["Use Time Grid" org-agenda-toggle-time-grid
1971 :style toggle :selected org-agenda-use-time-grid
1972 :active (org-agenda-check-type nil 'agenda)]
1973 "--"
1974 ["Show clock report" org-agenda-clockreport-mode
1975 :style toggle :selected org-agenda-clockreport-mode
1976 :active (org-agenda-check-type nil 'agenda)]
1977 ["Show some entry text" org-agenda-entry-text-mode
1978 :style toggle :selected org-agenda-entry-text-mode
1979 :active t]
1980 "--"
1981 ["Show Logbook entries" org-agenda-log-mode
1982 :style toggle :selected org-agenda-show-log
1983 :active (org-agenda-check-type nil 'agenda 'timeline)
1984 :keys "v l (or just l)"]
1985 ["Include archived trees" org-agenda-archives-mode
1986 :style toggle :selected org-agenda-archives-mode :active t
1987 :keys "v a"]
1988 ["Include archive files" (org-agenda-archives-mode t)
1989 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1990 :keys "v A"]
1991 "--"
1992 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1993 ["Write view to file" org-write-agenda t]
1994 ["Rebuild buffer" org-agenda-redo t]
1995 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1996 "--"
1997 ["Show original entry" org-agenda-show t]
1998 ["Go To (other window)" org-agenda-goto t]
1999 ["Go To (this window)" org-agenda-switch-to t]
2000 ["Follow Mode" org-agenda-follow-mode
2001 :style toggle :selected org-agenda-follow-mode :active t]
2002 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2003 "--"
2004 ("TODO"
2005 ["Cycle TODO" org-agenda-todo t]
2006 ["Next TODO set" org-agenda-todo-nextset t]
2007 ["Previous TODO set" org-agenda-todo-previousset t]
2008 ["Add note" org-agenda-add-note t])
2009 ("Archive/Refile/Delete"
2010 ["Archive default" org-agenda-archive-default t]
2011 ["Archive default" org-agenda-archive-default-with-confirmation t]
2012 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2013 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2014 ["Archive subtree" org-agenda-archive t]
2015 "--"
2016 ["Refile" org-agenda-refile t]
2017 "--"
2018 ["Delete subtree" org-agenda-kill t])
2019 ("Bulk action"
2020 ["Mark entry" org-agenda-bulk-mark t]
2021 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2022 ["Unmark entry" org-agenda-bulk-unmark t]
2023 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
2024 ["Act on all marked" org-agenda-bulk-action t]
2025 "--"
2026 ("Tags and Properties"
2027 ["Show all Tags" org-agenda-show-tags t]
2028 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2029 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2030 "--"
2031 ["Column View" org-columns t])
2032 ("Deadline/Schedule"
2033 ["Schedule" org-agenda-schedule t]
2034 ["Set Deadline" org-agenda-deadline t]
2035 "--"
2036 ["Mark item" org-agenda-action :active t :keys "k m"]
2037 ["Show mark item" org-agenda-action :active t :keys "k v"]
2038 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2039 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2040 "--"
2041 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2042 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2043 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2044 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2045 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2046 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2047 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2048 ("Clock and Effort"
2049 ["Clock in" org-agenda-clock-in t]
2050 ["Clock out" org-agenda-clock-out t]
2051 ["Clock cancel" org-agenda-clock-cancel t]
2052 ["Goto running clock" org-clock-goto t]
2053 "--"
2054 ["Set Effort" org-agenda-set-effort t]
2055 ["Change clocked effort" org-clock-modify-effort-estimate
2056 (org-clock-is-active)])
2057 ("Priority"
2058 ["Set Priority" org-agenda-priority t]
2059 ["Increase Priority" org-agenda-priority-up t]
2060 ["Decrease Priority" org-agenda-priority-down t]
2061 ["Show Priority" org-agenda-show-priority t])
2062 ("Calendar/Diary"
2063 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2064 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2065 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2066 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2067 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2068 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2069 "--"
2070 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2071 "--"
2072 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2073 "--"
2074 ("MobileOrg"
2075 ["Push Files and Views" org-mobile-push t]
2076 ["Get Captured and Flagged" org-mobile-pull t]
2077 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2078 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2079 "--"
2080 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2081 "--"
2082 ["Quit" org-agenda-quit t]
2083 ["Exit and Release Buffers" org-agenda-exit t]
2086 ;;; Agenda undo
2088 (defvar org-agenda-allow-remote-undo t
2089 "Non-nil means allow remote undo from the agenda buffer.")
2090 (defvar org-agenda-undo-list nil
2091 "List of undoable operations in the agenda since last refresh.")
2092 (defvar org-agenda-undo-has-started-in nil
2093 "Buffers that have already seen `undo-start' in the current undo sequence.")
2094 (defvar org-agenda-pending-undo-list nil
2095 "In a series of undo commands, this is the list of remaining undo items.")
2097 (defun org-agenda-undo ()
2098 "Undo a remote editing step in the agenda.
2099 This undoes changes both in the agenda buffer and in the remote buffer
2100 that have been changed along."
2101 (interactive)
2102 (or org-agenda-allow-remote-undo
2103 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2104 (if (not (eq this-command last-command))
2105 (setq org-agenda-undo-has-started-in nil
2106 org-agenda-pending-undo-list org-agenda-undo-list))
2107 (if (not org-agenda-pending-undo-list)
2108 (error "No further undo information"))
2109 (let* ((entry (pop org-agenda-pending-undo-list))
2110 buf line cmd rembuf)
2111 (setq cmd (pop entry) line (pop entry))
2112 (setq rembuf (nth 2 entry))
2113 (org-with-remote-undo rembuf
2114 (while (bufferp (setq buf (pop entry)))
2115 (if (pop entry)
2116 (with-current-buffer buf
2117 (let ((last-undo-buffer buf)
2118 (inhibit-read-only t))
2119 (unless (memq buf org-agenda-undo-has-started-in)
2120 (push buf org-agenda-undo-has-started-in)
2121 (make-local-variable 'pending-undo-list)
2122 (undo-start))
2123 (while (and pending-undo-list
2124 (listp pending-undo-list)
2125 (not (car pending-undo-list)))
2126 (pop pending-undo-list))
2127 (undo-more 1))))))
2128 (org-goto-line line)
2129 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2131 (defun org-verify-change-for-undo (l1 l2)
2132 "Verify that a real change occurred between the undo lists L1 and L2."
2133 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2134 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2135 (not (eq l1 l2)))
2137 ;;; Agenda dispatch
2139 (defvar org-agenda-restrict nil)
2140 (defvar org-agenda-restrict-begin (make-marker))
2141 (defvar org-agenda-restrict-end (make-marker))
2142 (defvar org-agenda-last-dispatch-buffer nil)
2143 (defvar org-agenda-overriding-restriction nil)
2145 ;;;###autoload
2146 (defun org-agenda (&optional arg keys restriction)
2147 "Dispatch agenda commands to collect entries to the agenda buffer.
2148 Prompts for a command to execute. Any prefix arg will be passed
2149 on to the selected command. The default selections are:
2151 a Call `org-agenda-list' to display the agenda for current day or week.
2152 t Call `org-todo-list' to display the global todo list.
2153 T Call `org-todo-list' to display the global todo list, select only
2154 entries with a specific TODO keyword (the user gets a prompt).
2155 m Call `org-tags-view' to display headlines with tags matching
2156 a condition (the user is prompted for the condition).
2157 M Like `m', but select only TODO entries, no ordinary headlines.
2158 L Create a timeline for the current buffer.
2159 e Export views to associated files.
2160 s Search entries for keywords.
2161 / Multi occur across all agenda files and also files listed
2162 in `org-agenda-text-search-extra-files'.
2163 < Restrict agenda commands to buffer, subtree, or region.
2164 Press several times to get the desired effect.
2165 > Remove a previous restriction.
2166 # List \"stuck\" projects.
2167 ! Configure what \"stuck\" means.
2168 C Configure custom agenda commands.
2170 More commands can be added by configuring the variable
2171 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2172 searches can be pre-defined in this way.
2174 If the current buffer is in Org-mode and visiting a file, you can also
2175 first press `<' once to indicate that the agenda should be temporarily
2176 \(until the next use of \\[org-agenda]) restricted to the current file.
2177 Pressing `<' twice means to restrict to the current subtree or region
2178 \(if active)."
2179 (interactive "P")
2180 (catch 'exit
2181 (let* ((prefix-descriptions nil)
2182 (org-agenda-window-setup (if (equal (buffer-name)
2183 org-agenda-buffer-name)
2184 'current-window
2185 org-agenda-window-setup))
2186 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2187 (org-agenda-custom-commands
2188 ;; normalize different versions
2189 (delq nil
2190 (mapcar
2191 (lambda (x)
2192 (cond ((stringp (cdr x))
2193 (push x prefix-descriptions)
2194 nil)
2195 ((stringp (nth 1 x)) x)
2196 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2197 (t (cons (car x) (cons "" (cdr x))))))
2198 org-agenda-custom-commands)))
2199 (buf (current-buffer))
2200 (bfn (buffer-file-name (buffer-base-buffer)))
2201 entry key type match lprops ans)
2202 ;; Turn off restriction unless there is an overriding one,
2203 (unless org-agenda-overriding-restriction
2204 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2205 ;; There is a request to keep the file list in place
2206 (put 'org-agenda-files 'org-restrict nil))
2207 (setq org-agenda-restrict nil)
2208 (move-marker org-agenda-restrict-begin nil)
2209 (move-marker org-agenda-restrict-end nil))
2210 ;; Delete old local properties
2211 (put 'org-agenda-redo-command 'org-lprops nil)
2212 ;; Delete previously set last-arguments
2213 (put 'org-agenda-redo-command 'last-args nil)
2214 ;; Remember where this call originated
2215 (setq org-agenda-last-dispatch-buffer (current-buffer))
2216 (unless keys
2217 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2218 keys (car ans)
2219 restriction (cdr ans)))
2220 ;; Establish the restriction, if any
2221 (when (and (not org-agenda-overriding-restriction) restriction)
2222 (put 'org-agenda-files 'org-restrict (list bfn))
2223 (cond
2224 ((eq restriction 'region)
2225 (setq org-agenda-restrict t)
2226 (move-marker org-agenda-restrict-begin (region-beginning))
2227 (move-marker org-agenda-restrict-end (region-end)))
2228 ((eq restriction 'subtree)
2229 (save-excursion
2230 (setq org-agenda-restrict t)
2231 (org-back-to-heading t)
2232 (move-marker org-agenda-restrict-begin (point))
2233 (move-marker org-agenda-restrict-end
2234 (progn (org-end-of-subtree t)))))))
2236 ;; For example the todo list should not need it (but does...)
2237 (cond
2238 ((setq entry (assoc keys org-agenda-custom-commands))
2239 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2240 (progn
2241 (setq type (nth 2 entry) match (eval (nth 3 entry))
2242 lprops (nth 4 entry))
2243 (put 'org-agenda-redo-command 'org-lprops lprops)
2244 (cond
2245 ((eq type 'agenda)
2246 (org-let lprops '(org-agenda-list current-prefix-arg)))
2247 ((eq type 'alltodo)
2248 (org-let lprops '(org-todo-list current-prefix-arg)))
2249 ((eq type 'search)
2250 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2251 ((eq type 'stuck)
2252 (org-let lprops '(org-agenda-list-stuck-projects
2253 current-prefix-arg)))
2254 ((eq type 'tags)
2255 (org-let lprops '(org-tags-view current-prefix-arg match)))
2256 ((eq type 'tags-todo)
2257 (org-let lprops '(org-tags-view '(4) match)))
2258 ((eq type 'todo)
2259 (org-let lprops '(org-todo-list match)))
2260 ((eq type 'tags-tree)
2261 (org-check-for-org-mode)
2262 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2263 ((eq type 'todo-tree)
2264 (org-check-for-org-mode)
2265 (org-let lprops
2266 '(org-occur (concat "^" outline-regexp "[ \t]*"
2267 (regexp-quote match) "\\>"))))
2268 ((eq type 'occur-tree)
2269 (org-check-for-org-mode)
2270 (org-let lprops '(org-occur match)))
2271 ((functionp type)
2272 (org-let lprops '(funcall type match)))
2273 ((fboundp type)
2274 (org-let lprops '(funcall type match)))
2275 (t (error "Invalid custom agenda command type %s" type))))
2276 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2277 ((equal keys "C")
2278 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2279 (customize-variable 'org-agenda-custom-commands))
2280 ((equal keys "a") (call-interactively 'org-agenda-list))
2281 ((equal keys "s") (call-interactively 'org-search-view))
2282 ((equal keys "t") (call-interactively 'org-todo-list))
2283 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2284 ((equal keys "m") (call-interactively 'org-tags-view))
2285 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2286 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2287 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2288 (org-add-hook
2289 'post-command-hook
2290 (lambda ()
2291 (unless (current-message)
2292 (let* ((m (org-agenda-get-any-marker))
2293 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2294 (when note
2295 (message (concat
2296 "FLAGGING-NOTE ([?] for more info): "
2297 (org-add-props
2298 (replace-regexp-in-string
2299 "\\\\n" "//"
2300 (copy-sequence note))
2301 nil 'face 'org-warning)))))))
2302 t t))
2303 ((equal keys "L")
2304 (unless (org-mode-p)
2305 (error "This is not an Org-mode file"))
2306 (unless restriction
2307 (put 'org-agenda-files 'org-restrict (list bfn))
2308 (org-call-with-arg 'org-timeline arg)))
2309 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2310 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2311 ((equal keys "!") (customize-variable 'org-stuck-projects))
2312 (t (error "Invalid agenda key"))))))
2314 (defun org-agenda-append-agenda ()
2315 "Append another agenda view to the current one.
2316 This function allows interactive building of block agendas.
2317 Agenda views are separated by `org-agenda-block-separator'."
2318 (interactive)
2319 (unless (string= (buffer-name) org-agenda-buffer-name)
2320 (error "Can only append from within agenda buffer"))
2321 (let ((org-agenda-multi t))
2322 (org-agenda)
2323 (widen)))
2325 (defun org-agenda-normalize-custom-commands (cmds)
2326 (delq nil
2327 (mapcar
2328 (lambda (x)
2329 (cond ((stringp (cdr x)) nil)
2330 ((stringp (nth 1 x)) x)
2331 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2332 (t (cons (car x) (cons "" (cdr x))))))
2333 cmds)))
2335 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2336 "The user interface for selecting an agenda command."
2337 (catch 'exit
2338 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2339 (restrict-ok (and bfn (org-mode-p)))
2340 (region-p (org-region-active-p))
2341 (custom org-agenda-custom-commands)
2342 (selstring "")
2343 restriction second-time
2344 c entry key type match prefixes rmheader header-end custom1 desc
2345 line lines left right n n1)
2346 (save-window-excursion
2347 (delete-other-windows)
2348 (org-switch-to-buffer-other-window " *Agenda Commands*")
2349 (erase-buffer)
2350 (insert (eval-when-compile
2351 (let ((header
2353 Press key for an agenda command: < Buffer, subtree/region restriction
2354 -------------------------------- > Remove restriction
2355 a Agenda for current week or day e Export agenda views
2356 t List of all TODO entries T Entries with special TODO kwd
2357 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2358 L Timeline for current buffer # List stuck projects (!=configure)
2359 s Search for keywords C Configure custom agenda commands
2360 / Multi-occur ? Find :FLAGGED: entries
2362 (start 0))
2363 (while (string-match
2364 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2365 header start)
2366 (setq start (match-end 0))
2367 (add-text-properties (match-beginning 2) (match-end 2)
2368 '(face bold) header))
2369 header)))
2370 (setq header-end (move-marker (make-marker) (point)))
2371 (while t
2372 (setq custom1 custom)
2373 (when (eq rmheader t)
2374 (org-goto-line 1)
2375 (re-search-forward ":" nil t)
2376 (delete-region (match-end 0) (point-at-eol))
2377 (forward-char 1)
2378 (looking-at "-+")
2379 (delete-region (match-end 0) (point-at-eol))
2380 (move-marker header-end (match-end 0)))
2381 (goto-char header-end)
2382 (delete-region (point) (point-max))
2384 ;; Produce all the lines that describe custom commands and prefixes
2385 (setq lines nil)
2386 (while (setq entry (pop custom1))
2387 (setq key (car entry) desc (nth 1 entry)
2388 type (nth 2 entry)
2389 match (nth 3 entry))
2390 (if (> (length key) 1)
2391 (add-to-list 'prefixes (string-to-char key))
2392 (setq line
2393 (format
2394 "%-4s%-14s"
2395 (org-add-props (copy-sequence key)
2396 '(face bold))
2397 (cond
2398 ((string-match "\\S-" desc) desc)
2399 ((eq type 'agenda) "Agenda for current week or day")
2400 ((eq type 'alltodo) "List of all TODO entries")
2401 ((eq type 'search) "Word search")
2402 ((eq type 'stuck) "List of stuck projects")
2403 ((eq type 'todo) "TODO keyword")
2404 ((eq type 'tags) "Tags query")
2405 ((eq type 'tags-todo) "Tags (TODO)")
2406 ((eq type 'tags-tree) "Tags tree")
2407 ((eq type 'todo-tree) "TODO kwd tree")
2408 ((eq type 'occur-tree) "Occur tree")
2409 ((functionp type) (if (symbolp type)
2410 (symbol-name type)
2411 "Lambda expression"))
2412 (t "???"))))
2413 (if org-agenda-menu-show-matcher
2414 (setq line
2415 (concat line ": "
2416 (cond
2417 ((stringp match)
2418 (setq match (copy-sequence match))
2419 (org-add-props match nil 'face 'org-warning))
2420 (match
2421 (format "set of %d commands" (length match)))
2422 (t ""))))
2423 (if (org-string-nw-p match)
2424 (add-text-properties
2425 0 (length line) (list 'help-echo
2426 (concat "Matcher: "match)) line)))
2427 (push line lines)))
2428 (setq lines (nreverse lines))
2429 (when prefixes
2430 (mapc (lambda (x)
2431 (push
2432 (format "%s %s"
2433 (org-add-props (char-to-string x)
2434 nil 'face 'bold)
2435 (or (cdr (assoc (concat selstring
2436 (char-to-string x))
2437 prefix-descriptions))
2438 "Prefix key"))
2439 lines))
2440 prefixes))
2442 ;; Check if we should display in two columns
2443 (if org-agenda-menu-two-column
2444 (progn
2445 (setq n (length lines)
2446 n1 (+ (/ n 2) (mod n 2))
2447 right (nthcdr n1 lines)
2448 left (copy-sequence lines))
2449 (setcdr (nthcdr (1- n1) left) nil))
2450 (setq left lines right nil))
2451 (while left
2452 (insert "\n" (pop left))
2453 (when right
2454 (if (< (current-column) 40)
2455 (move-to-column 40 t)
2456 (insert " "))
2457 (insert (pop right))))
2459 ;; Make the window the right size
2460 (goto-char (point-min))
2461 (if second-time
2462 (if (not (pos-visible-in-window-p (point-max)))
2463 (org-fit-window-to-buffer))
2464 (setq second-time t)
2465 (org-fit-window-to-buffer))
2467 ;; Ask for selection
2468 (message "Press key for agenda command%s:"
2469 (if (or restrict-ok org-agenda-overriding-restriction)
2470 (if org-agenda-overriding-restriction
2471 " (restriction lock active)"
2472 (if restriction
2473 (format " (restricted to %s)" restriction)
2474 " (unrestricted)"))
2475 ""))
2476 (setq c (read-char-exclusive))
2477 (message "")
2478 (cond
2479 ((assoc (char-to-string c) custom)
2480 (setq selstring (concat selstring (char-to-string c)))
2481 (throw 'exit (cons selstring restriction)))
2482 ((memq c prefixes)
2483 (setq selstring (concat selstring (char-to-string c))
2484 prefixes nil
2485 rmheader (or rmheader t)
2486 custom (delq nil (mapcar
2487 (lambda (x)
2488 (if (or (= (length (car x)) 1)
2489 (/= (string-to-char (car x)) c))
2491 (cons (substring (car x) 1) (cdr x))))
2492 custom))))
2493 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2494 (message "Restriction is only possible in Org-mode buffers")
2495 (ding) (sit-for 1))
2496 ((eq c ?1)
2497 (org-agenda-remove-restriction-lock 'noupdate)
2498 (setq restriction 'buffer))
2499 ((eq c ?0)
2500 (org-agenda-remove-restriction-lock 'noupdate)
2501 (setq restriction (if region-p 'region 'subtree)))
2502 ((eq c ?<)
2503 (org-agenda-remove-restriction-lock 'noupdate)
2504 (setq restriction
2505 (cond
2506 ((eq restriction 'buffer)
2507 (if region-p 'region 'subtree))
2508 ((memq restriction '(subtree region))
2509 nil)
2510 (t 'buffer))))
2511 ((eq c ?>)
2512 (org-agenda-remove-restriction-lock 'noupdate)
2513 (setq restriction nil))
2514 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2515 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2516 ((and (> (length selstring) 0) (eq c ?\d))
2517 (delete-window)
2518 (org-agenda-get-restriction-and-command prefix-descriptions))
2520 ((equal c ?q) (error "Abort"))
2521 (t (error "Invalid key %c" c))))))))
2523 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2524 (defvar org-agenda-last-arguments nil
2525 "The arguments of the previous call to `org-agenda'.")
2526 (defun org-agenda-run-series (name series)
2527 (org-let (nth 1 series) '(org-prepare-agenda name))
2528 (let* ((org-agenda-multi t)
2529 (redo (list 'org-agenda-run-series name (list 'quote series)))
2530 (org-agenda-overriding-arguments
2531 (or org-agenda-overriding-arguments
2532 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2533 (get 'org-agenda-redo-command 'last-args))))
2534 (cmds (car series))
2535 (gprops (nth 1 series))
2536 match ;; The byte compiler incorrectly complains about this. Keep it!
2537 cmd type lprops)
2538 (while (setq cmd (pop cmds))
2539 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2540 (cond
2541 ((eq type 'agenda)
2542 (org-let2 gprops lprops
2543 '(call-interactively 'org-agenda-list)))
2544 ((eq type 'alltodo)
2545 (org-let2 gprops lprops
2546 '(call-interactively 'org-todo-list)))
2547 ((eq type 'search)
2548 (org-let2 gprops lprops
2549 '(org-search-view current-prefix-arg match nil)))
2550 ((eq type 'stuck)
2551 (org-let2 gprops lprops
2552 '(call-interactively 'org-agenda-list-stuck-projects)))
2553 ((eq type 'tags)
2554 (org-let2 gprops lprops
2555 '(org-tags-view current-prefix-arg match)))
2556 ((eq type 'tags-todo)
2557 (org-let2 gprops lprops
2558 '(org-tags-view '(4) match)))
2559 ((eq type 'todo)
2560 (org-let2 gprops lprops
2561 '(org-todo-list match)))
2562 ((fboundp type)
2563 (org-let2 gprops lprops
2564 '(funcall type match)))
2565 (t (error "Invalid type in command series"))))
2566 (widen)
2567 (setq org-agenda-redo-command redo)
2568 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2569 (goto-char (point-min)))
2570 (org-fit-agenda-window)
2571 (org-let (nth 1 series) '(org-finalize-agenda)))
2573 ;;;###autoload
2574 (defmacro org-batch-agenda (cmd-key &rest parameters)
2575 "Run an agenda command in batch mode and send the result to STDOUT.
2576 If CMD-KEY is a string of length 1, it is used as a key in
2577 `org-agenda-custom-commands' and triggers this command. If it is a
2578 longer string it is used as a tags/todo match string.
2579 Parameters are alternating variable names and values that will be bound
2580 before running the agenda command."
2581 (let (pars)
2582 (while parameters
2583 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2584 (if (> (length cmd-key) 2)
2585 (eval (list 'let (nreverse pars)
2586 (list 'org-tags-view nil cmd-key)))
2587 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2588 (set-buffer org-agenda-buffer-name)
2589 (princ (org-encode-for-stdout (buffer-string)))))
2591 ;(defun org-encode-for-stdout (string)
2592 ; (if (fboundp 'encode-coding-string)
2593 ; (encode-coding-string string buffer-file-coding-system)
2594 ; string))
2596 (defun org-encode-for-stdout (string)
2597 string)
2599 (defvar org-agenda-info nil)
2601 ;;;###autoload
2602 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2603 "Run an agenda command in batch mode and send the result to STDOUT.
2604 If CMD-KEY is a string of length 1, it is used as a key in
2605 `org-agenda-custom-commands' and triggers this command. If it is a
2606 longer string it is used as a tags/todo match string.
2607 Parameters are alternating variable names and values that will be bound
2608 before running the agenda command.
2610 The output gives a line for each selected agenda item. Each
2611 item is a list of comma-separated values, like this:
2613 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2615 category The category of the item
2616 head The headline, without TODO kwd, TAGS and PRIORITY
2617 type The type of the agenda entry, can be
2618 todo selected in TODO match
2619 tagsmatch selected in tags match
2620 diary imported from diary
2621 deadline a deadline on given date
2622 scheduled scheduled on given date
2623 timestamp entry has timestamp on given date
2624 closed entry was closed on given date
2625 upcoming-deadline warning about deadline
2626 past-scheduled forwarded scheduled item
2627 block entry has date block including g. date
2628 todo The todo keyword, if any
2629 tags All tags including inherited ones, separated by colons
2630 date The relevant date, like 2007-2-14
2631 time The time, like 15:00-16:50
2632 extra Sting with extra planning info
2633 priority-l The priority letter if any was given
2634 priority-n The computed numerical priority
2635 agenda-day The day in the agenda where this is listed"
2637 (let (pars)
2638 (while parameters
2639 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2640 (push (list 'org-agenda-remove-tags t) pars)
2641 (if (> (length cmd-key) 2)
2642 (eval (list 'let (nreverse pars)
2643 (list 'org-tags-view nil cmd-key)))
2644 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2645 (set-buffer org-agenda-buffer-name)
2646 (let* ((lines (org-split-string (buffer-string) "\n"))
2647 line)
2648 (while (setq line (pop lines))
2649 (catch 'next
2650 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2651 (setq org-agenda-info
2652 (org-fix-agenda-info (text-properties-at 0 line)))
2653 (princ
2654 (org-encode-for-stdout
2655 (mapconcat 'org-agenda-export-csv-mapper
2656 '(org-category txt type todo tags date time extra
2657 priority-letter priority agenda-day)
2658 ",")))
2659 (princ "\n"))))))
2661 (defun org-fix-agenda-info (props)
2662 "Make sure all properties on an agenda item have a canonical form.
2663 This ensures the export commands can easily use it."
2664 (let (tmp re)
2665 (when (setq tmp (plist-get props 'tags))
2666 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2667 (when (setq tmp (plist-get props 'date))
2668 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2669 (let ((calendar-date-display-form '(year "-" month "-" day)))
2670 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2672 (setq tmp (calendar-date-string tmp)))
2673 (setq props (plist-put props 'date tmp)))
2674 (when (setq tmp (plist-get props 'day))
2675 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2676 (let ((calendar-date-display-form '(year "-" month "-" day)))
2677 (setq tmp (calendar-date-string tmp)))
2678 (setq props (plist-put props 'day tmp))
2679 (setq props (plist-put props 'agenda-day tmp)))
2680 (when (setq tmp (plist-get props 'txt))
2681 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2682 (plist-put props 'priority-letter (match-string 1 tmp))
2683 (setq tmp (replace-match "" t t tmp)))
2684 (when (and (setq re (plist-get props 'org-todo-regexp))
2685 (setq re (concat "\\`\\.*" re " ?"))
2686 (string-match re tmp))
2687 (plist-put props 'todo (match-string 1 tmp))
2688 (setq tmp (replace-match "" t t tmp)))
2689 (plist-put props 'txt tmp)))
2690 props)
2692 (defun org-agenda-export-csv-mapper (prop)
2693 (let ((res (plist-get org-agenda-info prop)))
2694 (setq res
2695 (cond
2696 ((not res) "")
2697 ((stringp res) res)
2698 (t (prin1-to-string res))))
2699 (while (string-match "," res)
2700 (setq res (replace-match ";" t t res)))
2701 (org-trim res)))
2704 ;;;###autoload
2705 (defun org-store-agenda-views (&rest parameters)
2706 (interactive)
2707 (eval (list 'org-batch-store-agenda-views)))
2709 ;; FIXME, why is this a macro?????
2710 ;;;###autoload
2711 (defmacro org-batch-store-agenda-views (&rest parameters)
2712 "Run all custom agenda commands that have a file argument."
2713 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2714 (pop-up-frames nil)
2715 (dir default-directory)
2716 pars cmd thiscmdkey files opts cmd-or-set)
2717 (while parameters
2718 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2719 (setq pars (reverse pars))
2720 (save-window-excursion
2721 (while cmds
2722 (setq cmd (pop cmds)
2723 thiscmdkey (car cmd)
2724 cmd-or-set (nth 2 cmd)
2725 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2726 files (nth (if (listp cmd-or-set) 4 5) cmd))
2727 (if (stringp files) (setq files (list files)))
2728 (when files
2729 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2730 (list 'org-agenda nil thiscmdkey)))
2731 (set-buffer org-agenda-buffer-name)
2732 (while files
2733 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2734 (list 'org-write-agenda
2735 (expand-file-name (pop files) dir) nil t))))
2736 (and (get-buffer org-agenda-buffer-name)
2737 (kill-buffer org-agenda-buffer-name)))))))
2739 (defun org-agenda-mark-header-line (pos)
2740 "Mark the line at POS as an agenda structure header."
2741 (save-excursion
2742 (goto-char pos)
2743 (put-text-property (point-at-bol) (point-at-eol)
2744 'org-agenda-structural-header t)
2745 (when org-agenda-title-append
2746 (put-text-property (point-at-bol) (point-at-eol)
2747 'org-agenda-title-append org-agenda-title-append))))
2749 (defvar org-mobile-creating-agendas)
2750 (defun org-write-agenda (file &optional open nosettings)
2751 "Write the current buffer (an agenda view) as a file.
2752 Depending on the extension of the file name, plain text (.txt),
2753 HTML (.html or .htm) or Postscript (.ps) is produced.
2754 If the extension is .ics, run icalendar export over all files used
2755 to construct the agenda and limit the export to entries listed in the
2756 agenda now.
2757 With prefix argument OPEN, open the new file immediately.
2758 If NOSETTINGS is given, do not scope the settings of
2759 `org-agenda-exporter-settings' into the export commands. This is used when
2760 the settings have already been scoped and we do not wish to overrule other,
2761 higher priority settings."
2762 (interactive "FWrite agenda to file: \nP")
2763 (if (not (file-writable-p file))
2764 (error "Cannot write agenda to file %s" file))
2765 (org-let (if nosettings nil org-agenda-exporter-settings)
2766 '(save-excursion
2767 (save-window-excursion
2768 (org-agenda-mark-filtered-text)
2769 (let ((bs (copy-sequence (buffer-string))) beg)
2770 (org-agenda-unmark-filtered-text)
2771 (with-temp-buffer
2772 (rename-buffer "Agenda View" t)
2773 (set-buffer-modified-p nil)
2774 (insert bs)
2775 (org-agenda-remove-marked-text 'org-filtered)
2776 (while (setq beg (text-property-any (point-min) (point-max)
2777 'org-filtered t))
2778 (delete-region
2779 beg (or (next-single-property-change beg 'org-filtered)
2780 (point-max))))
2781 (run-hooks 'org-agenda-before-write-hook)
2782 (cond
2783 ((org-bound-and-true-p org-mobile-creating-agendas)
2784 (org-mobile-write-agenda-for-mobile file))
2785 ((string-match "\\.html?\\'" file)
2786 (require 'htmlize)
2787 (set-buffer (htmlize-buffer (current-buffer)))
2789 (when (and org-agenda-export-html-style
2790 (string-match "<style>" org-agenda-export-html-style))
2791 ;; replace <style> section with org-agenda-export-html-style
2792 (goto-char (point-min))
2793 (kill-region (- (search-forward "<style") 6)
2794 (search-forward "</style>"))
2795 (insert org-agenda-export-html-style))
2796 (write-file file)
2797 (kill-buffer (current-buffer))
2798 (message "HTML written to %s" file))
2799 ((string-match "\\.ps\\'" file)
2800 (require 'ps-print)
2801 (ps-print-buffer-with-faces file)
2802 (message "Postscript written to %s" file))
2803 ((string-match "\\.pdf\\'" file)
2804 (require 'ps-print)
2805 (ps-print-buffer-with-faces
2806 (concat (file-name-sans-extension file) ".ps"))
2807 (call-process "ps2pdf" nil nil nil
2808 (expand-file-name
2809 (concat (file-name-sans-extension file) ".ps"))
2810 (expand-file-name file))
2811 (delete-file (concat (file-name-sans-extension file) ".ps"))
2812 (message "PDF written to %s" file))
2813 ((string-match "\\.ics\\'" file)
2814 (require 'org-icalendar)
2815 (let ((org-agenda-marker-table
2816 (org-create-marker-find-array
2817 (org-agenda-collect-markers)))
2818 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2819 (org-combined-agenda-icalendar-file file))
2820 (apply 'org-export-icalendar 'combine
2821 (org-agenda-files nil 'ifmode))))
2823 (let ((bs (buffer-string)))
2824 (find-file file)
2825 (erase-buffer)
2826 (insert bs)
2827 (save-buffer 0)
2828 (kill-buffer (current-buffer))
2829 (message "Plain text written to %s" file))))))))
2830 (set-buffer org-agenda-buffer-name))
2831 (when open (org-open-file file)))
2833 (defvar org-agenda-filter-overlays nil)
2835 (defun org-agenda-mark-filtered-text ()
2836 "Mark all text hidden by filtering with a text property."
2837 (let ((inhibit-read-only t))
2838 (mapc
2839 (lambda (o)
2840 (when (equal (overlay-buffer o) (current-buffer))
2841 (put-text-property
2842 (overlay-start o) (overlay-end o)
2843 'org-filtered t)))
2844 org-agenda-filter-overlays)))
2846 (defun org-agenda-unmark-filtered-text ()
2847 "Remove the filtering text property."
2848 (let ((inhibit-read-only t))
2849 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2851 (defun org-agenda-remove-marked-text (property &optional value)
2852 "Delete all text marked with VALUE of PROPERTY.
2853 VALUE defaults to t."
2854 (let (beg)
2855 (setq value (or value t))
2856 (while (setq beg (text-property-any (point-min) (point-max)
2857 property value))
2858 (delete-region
2859 beg (or (next-single-property-change beg 'org-filtered)
2860 (point-max))))))
2862 (defun org-agenda-add-entry-text ()
2863 "Add entry text to agenda lines.
2864 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2865 entry text following headings shown in the agenda.
2866 Drawers will be excluded, also the line with scheduling/deadline info."
2867 (when (and (> org-agenda-add-entry-text-maxlines 0)
2868 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2869 (let (m txt)
2870 (goto-char (point-min))
2871 (while (not (eobp))
2872 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2873 (beginning-of-line 2)
2874 (setq txt (org-agenda-get-some-entry-text
2875 m org-agenda-add-entry-text-maxlines " > "))
2876 (end-of-line 1)
2877 (if (string-match "\\S-" txt)
2878 (insert "\n" txt)
2879 (or (eobp) (forward-char 1))))))))
2881 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2882 &rest keep)
2883 "Extract entry text from MARKER, at most N-LINES lines.
2884 This will ignore drawers etc, just get the text.
2885 If INDENT is given, prefix every line with this string. If KEEP is
2886 given, it is a list of symbols, defining stuff that should not be
2887 removed from the entry content. Currently only `planning' is allowed here."
2888 (let (txt drawer-re kwd-time-re ind)
2889 (save-excursion
2890 (with-current-buffer (marker-buffer marker)
2891 (if (not (org-mode-p))
2892 (setq txt "")
2893 (save-excursion
2894 (save-restriction
2895 (widen)
2896 (goto-char marker)
2897 (end-of-line 1)
2898 (setq txt (buffer-substring
2899 (min (1+ (point)) (point-max))
2900 (progn (outline-next-heading) (point)))
2901 drawer-re org-drawer-regexp
2902 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2903 ".*\n?"))
2904 (with-temp-buffer
2905 (insert txt)
2906 (when org-agenda-add-entry-text-descriptive-links
2907 (goto-char (point-min))
2908 (while (org-activate-bracket-links (point-max))
2909 (add-text-properties (match-beginning 0) (match-end 0)
2910 '(face org-link))))
2911 (goto-char (point-min))
2912 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2913 (set-text-properties (match-beginning 0) (match-end 0)
2914 nil))
2915 (goto-char (point-min))
2916 (while (re-search-forward drawer-re nil t)
2917 (delete-region
2918 (match-beginning 0)
2919 (progn (re-search-forward
2920 "^[ \t]*:END:.*\n?" nil 'move)
2921 (point))))
2922 (unless (member 'planning keep)
2923 (goto-char (point-min))
2924 (while (re-search-forward kwd-time-re nil t)
2925 (replace-match "")))
2926 (goto-char (point-min))
2927 (when org-agenda-entry-text-exclude-regexps
2928 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2929 (while (setq re (pop re-list))
2930 (goto-char (point-min))
2931 (while (re-search-forward re nil t)
2932 (replace-match "")))))
2933 (goto-char (point-max))
2934 (skip-chars-backward " \t\n")
2935 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2937 ;; find and remove min common indentation
2938 (goto-char (point-min))
2939 (untabify (point-min) (point-max))
2940 (setq ind (org-get-indentation))
2941 (while (not (eobp))
2942 (unless (looking-at "[ \t]*$")
2943 (setq ind (min ind (org-get-indentation))))
2944 (beginning-of-line 2))
2945 (goto-char (point-min))
2946 (while (not (eobp))
2947 (unless (looking-at "[ \t]*$")
2948 (move-to-column ind)
2949 (delete-region (point-at-bol) (point)))
2950 (beginning-of-line 2))
2952 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2954 (goto-char (point-min))
2955 (when indent
2956 (while (and (not (eobp)) (re-search-forward "^" nil t))
2957 (replace-match indent t t)))
2958 (goto-char (point-min))
2959 (while (looking-at "[ \t]*\n") (replace-match ""))
2960 (goto-char (point-max))
2961 (when (> (org-current-line)
2962 n-lines)
2963 (org-goto-line (1+ n-lines))
2964 (backward-char 1))
2965 (setq txt (buffer-substring (point-min) (point)))))))))
2966 txt))
2968 (defun org-agenda-collect-markers ()
2969 "Collect the markers pointing to entries in the agenda buffer."
2970 (let (m markers)
2971 (save-excursion
2972 (goto-char (point-min))
2973 (while (not (eobp))
2974 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2975 (org-get-at-bol 'org-marker)))
2976 (push m markers))
2977 (beginning-of-line 2)))
2978 (nreverse markers)))
2980 (defun org-create-marker-find-array (marker-list)
2981 "Create a alist of files names with all marker positions in that file."
2982 (let (f tbl m a p)
2983 (while (setq m (pop marker-list))
2984 (setq p (marker-position m)
2985 f (buffer-file-name (or (buffer-base-buffer
2986 (marker-buffer m))
2987 (marker-buffer m))))
2988 (if (setq a (assoc f tbl))
2989 (push (marker-position m) (cdr a))
2990 (push (list f p) tbl)))
2991 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2992 tbl)))
2994 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2995 (defun org-check-agenda-marker-table ()
2996 "Check of the current entry is on the marker list."
2997 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2999 (and (setq a (assoc file org-agenda-marker-table))
3000 (save-match-data
3001 (save-excursion
3002 (org-back-to-heading t)
3003 (member (point) (cdr a)))))))
3005 (defun org-check-for-org-mode ()
3006 "Make sure current buffer is in org-mode. Error if not."
3007 (or (org-mode-p)
3008 (error "Cannot execute org-mode agenda command on buffer in %s"
3009 major-mode)))
3011 (defun org-fit-agenda-window ()
3012 "Fit the window to the buffer size."
3013 (and (memq org-agenda-window-setup '(reorganize-frame))
3014 (fboundp 'fit-window-to-buffer)
3015 (org-fit-window-to-buffer
3017 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3018 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3020 ;;; Agenda prepare and finalize
3022 (defvar org-agenda-multi nil) ; dynamically scoped
3023 (defvar org-agenda-buffer-name "*Org Agenda*")
3024 (defvar org-pre-agenda-window-conf nil)
3025 (defvar org-agenda-columns-active nil)
3026 (defvar org-agenda-name nil)
3027 (defvar org-agenda-filter nil)
3028 (defvar org-agenda-filter-while-redo nil)
3029 (defvar org-agenda-filter-preset nil
3030 "A preset of the tags filter used for secondary agenda filtering.
3031 This must be a list of strings, each string must be a single tag preceded
3032 by \"+\" or \"-\".
3033 This variable should not be set directly, but agenda custom commands can
3034 bind it in the options section. The preset filter is a global property of
3035 the entire agenda view. In a block agenda, it will not work reliably to
3036 define a filter for one of the individual blocks. You need to set it in
3037 the global options and expect it to be applied to the entire view.")
3039 (defun org-prepare-agenda (&optional name)
3040 (setq org-todo-keywords-for-agenda nil)
3041 (setq org-done-keywords-for-agenda nil)
3042 (setq org-drawers-for-agenda nil)
3043 (unless org-agenda-persistent-filter
3044 (setq org-agenda-filter nil))
3045 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
3046 (if org-agenda-multi
3047 (progn
3048 (setq buffer-read-only nil)
3049 (goto-char (point-max))
3050 (unless (or (bobp) org-agenda-compact-blocks
3051 (not org-agenda-block-separator))
3052 (insert "\n"
3053 (if (stringp org-agenda-block-separator)
3054 org-agenda-block-separator
3055 (make-string (window-width) org-agenda-block-separator))
3056 "\n"))
3057 (narrow-to-region (point) (point-max)))
3058 (org-agenda-reset-markers)
3059 (setq org-agenda-contributing-files nil)
3060 (setq org-agenda-columns-active nil)
3061 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3062 (setq org-todo-keywords-for-agenda
3063 (org-uniquify org-todo-keywords-for-agenda))
3064 (setq org-done-keywords-for-agenda
3065 (org-uniquify org-done-keywords-for-agenda))
3066 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3067 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
3068 (awin (get-buffer-window abuf)))
3069 (cond
3070 ((equal (current-buffer) abuf) nil)
3071 (awin (select-window awin))
3072 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
3073 ((equal org-agenda-window-setup 'current-window)
3074 (switch-to-buffer abuf))
3075 ((equal org-agenda-window-setup 'other-window)
3076 (org-switch-to-buffer-other-window abuf))
3077 ((equal org-agenda-window-setup 'other-frame)
3078 (switch-to-buffer-other-frame abuf))
3079 ((equal org-agenda-window-setup 'reorganize-frame)
3080 (delete-other-windows)
3081 (org-switch-to-buffer-other-window abuf)))
3082 ;; additional test in case agenda is invoked from within agenda
3083 ;; buffer via elisp link
3084 (unless (equal (current-buffer) abuf)
3085 (switch-to-buffer abuf)))
3086 (setq buffer-read-only nil)
3087 (let ((inhibit-read-only t)) (erase-buffer))
3088 (org-agenda-mode)
3089 (and name (not org-agenda-name)
3090 (org-set-local 'org-agenda-name name)))
3091 (setq buffer-read-only nil))
3093 (defun org-finalize-agenda ()
3094 "Finishing touch for the agenda buffer, called just before displaying it."
3095 (unless org-agenda-multi
3096 (save-excursion
3097 (let ((inhibit-read-only t))
3098 (goto-char (point-min))
3099 (while (org-activate-bracket-links (point-max))
3100 (add-text-properties (match-beginning 0) (match-end 0)
3101 '(face org-link)))
3102 (org-agenda-align-tags)
3103 (unless org-agenda-with-colors
3104 (remove-text-properties (point-min) (point-max) '(face nil))))
3105 (if (and (boundp 'org-agenda-overriding-columns-format)
3106 org-agenda-overriding-columns-format)
3107 (org-set-local 'org-agenda-overriding-columns-format
3108 org-agenda-overriding-columns-format))
3109 (if (and (boundp 'org-agenda-view-columns-initially)
3110 org-agenda-view-columns-initially)
3111 (org-agenda-columns))
3112 (when org-agenda-fontify-priorities
3113 (org-agenda-fontify-priorities))
3114 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3115 (org-agenda-dim-blocked-tasks))
3116 (org-agenda-mark-clocking-task)
3117 (when org-agenda-entry-text-mode
3118 (org-agenda-entry-text-hide)
3119 (org-agenda-entry-text-show))
3120 (if (functionp 'org-habit-insert-consistency-graphs)
3121 (org-habit-insert-consistency-graphs))
3122 (run-hooks 'org-finalize-agenda-hook)
3123 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3124 (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
3125 (org-agenda-filter-apply org-agenda-filter))
3128 (defun org-agenda-mark-clocking-task ()
3129 "Mark the current clock entry in the agenda if it is present."
3130 (mapc (lambda (o)
3131 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3132 (delete-overlay o)))
3133 (overlays-in (point-min) (point-max)))
3134 (when (marker-buffer org-clock-hd-marker)
3135 (save-excursion
3136 (goto-char (point-min))
3137 (let (s ov)
3138 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3139 (goto-char s)
3140 (when (equal (org-get-at-bol 'org-hd-marker)
3141 org-clock-hd-marker)
3142 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3143 (overlay-put ov 'type 'org-agenda-clocking)
3144 (overlay-put ov 'face 'org-agenda-clocking)
3145 (overlay-put ov 'help-echo
3146 "The clock is running in this item")))))))
3148 (defun org-agenda-fontify-priorities ()
3149 "Make highest priority lines bold, and lowest italic."
3150 (interactive)
3151 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3152 (delete-overlay o)))
3153 (overlays-in (point-min) (point-max)))
3154 (save-excursion
3155 (let ((inhibit-read-only t)
3156 b e p ov h l)
3157 (goto-char (point-min))
3158 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3159 (setq h (or (get-char-property (point) 'org-highest-priority)
3160 org-highest-priority)
3161 l (or (get-char-property (point) 'org-lowest-priority)
3162 org-lowest-priority)
3163 p (string-to-char (match-string 1))
3164 b (match-beginning 0)
3165 e (if (eq org-agenda-fontify-priorities 'cookies)
3166 (match-end 0)
3167 (point-at-eol))
3168 ov (make-overlay b e))
3169 (overlay-put
3170 ov 'face
3171 (cond ((org-face-from-face-or-color
3172 'priority nil
3173 (cdr (assoc p org-priority-faces))))
3174 ((and (listp org-agenda-fontify-priorities)
3175 (org-face-from-face-or-color
3176 'priority nil
3177 (cdr (assoc p org-agenda-fontify-priorities)))))
3178 ((equal p l) 'italic)
3179 ((equal p h) 'bold)))
3180 (overlay-put ov 'org-type 'org-priority)))))
3182 (defun org-agenda-dim-blocked-tasks ()
3183 "Dim currently blocked TODO's in the agenda display."
3184 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3185 (delete-overlay o)))
3186 (overlays-in (point-min) (point-max)))
3187 (save-excursion
3188 (let ((inhibit-read-only t)
3189 (org-depend-tag-blocked nil)
3190 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3191 org-blocked-by-checkboxes
3192 invis1 b e p ov h l)
3193 (goto-char (point-min))
3194 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3195 (and pos (goto-char (1+ pos))))
3196 (setq org-blocked-by-checkboxes nil invis1 invis)
3197 (let ((marker (org-get-at-bol 'org-hd-marker)))
3198 (when (and marker
3199 (not (with-current-buffer (marker-buffer marker)
3200 (save-excursion
3201 (goto-char marker)
3202 (if (org-entry-get nil "NOBLOCKING")
3203 t ;; Never block this entry
3204 (run-hook-with-args-until-failure
3205 'org-blocker-hook
3206 (list :type 'todo-state-change
3207 :position marker
3208 :from 'todo
3209 :to 'done)))))))
3210 (if org-blocked-by-checkboxes (setq invis1 nil))
3211 (setq b (if invis1
3212 (max (point-min) (1- (point-at-bol)))
3213 (point-at-bol))
3214 e (point-at-eol)
3215 ov (make-overlay b e))
3216 (if invis1
3217 (overlay-put ov 'invisible t)
3218 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3219 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3221 (defvar org-agenda-skip-function nil
3222 "Function to be called at each match during agenda construction.
3223 If this function returns nil, the current match should not be skipped.
3224 Otherwise, the function must return a position from where the search
3225 should be continued.
3226 This may also be a Lisp form, it will be evaluated.
3227 Never set this variable using `setq' or so, because then it will apply
3228 to all future agenda commands. If you do want a global skipping condition,
3229 use the option `org-agenda-skip-function-global' instead.
3230 The correct usage for `org-agenda-skip-function' is to bind it with
3231 `let' to scope it dynamically into the agenda-constructing command.
3232 A good way to set it is through options in `org-agenda-custom-commands'.")
3234 (defun org-agenda-skip ()
3235 "Throw to `:skip' in places that should be skipped.
3236 Also moves point to the end of the skipped region, so that search can
3237 continue from there."
3238 (let ((p (point-at-bol)) to)
3239 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3240 (get-text-property p :org-archived)
3241 (org-end-of-subtree t)
3242 (throw :skip t))
3243 (and org-agenda-skip-comment-trees
3244 (get-text-property p :org-comment)
3245 (org-end-of-subtree t)
3246 (throw :skip t))
3247 (if (equal (char-after p) ?#) (throw :skip t))
3248 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3249 (org-agenda-skip-eval org-agenda-skip-function)))
3250 (goto-char to)
3251 (throw :skip t))))
3253 (defun org-agenda-skip-eval (form)
3254 "If FORM is a function or a list, call (or eval) is and return result.
3255 `save-excursion' and `save-match-data' are wrapped around the call, so point
3256 and match data are returned to the previous state no matter what these
3257 functions do."
3258 (let (fp)
3259 (and form
3260 (or (setq fp (functionp form))
3261 (consp form))
3262 (save-excursion
3263 (save-match-data
3264 (if fp
3265 (funcall form)
3266 (eval form)))))))
3268 (defvar org-agenda-markers nil
3269 "List of all currently active markers created by `org-agenda'.")
3270 (defvar org-agenda-last-marker-time (org-float-time)
3271 "Creation time of the last agenda marker.")
3273 (defun org-agenda-new-marker (&optional pos)
3274 "Return a new agenda marker.
3275 Org-mode keeps a list of these markers and resets them when they are
3276 no longer in use."
3277 (let ((m (copy-marker (or pos (point)))))
3278 (setq org-agenda-last-marker-time (org-float-time))
3279 (push m org-agenda-markers)
3282 (defun org-agenda-reset-markers ()
3283 "Reset markers created by `org-agenda'."
3284 (while org-agenda-markers
3285 (move-marker (pop org-agenda-markers) nil)))
3287 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3288 "Save relative positions of markers in region."
3289 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3290 org-agenda-markers))
3292 ;;; Entry text mode
3294 (defun org-agenda-entry-text-show-here ()
3295 "Add some text from the entry as context to the current line."
3296 (let (m txt o)
3297 (setq m (org-get-at-bol 'org-hd-marker))
3298 (unless (marker-buffer m)
3299 (error "No marker points to an entry here"))
3300 (setq txt (concat "\n" (org-no-properties
3301 (org-agenda-get-some-entry-text
3302 m org-agenda-entry-text-maxlines " > "))))
3303 (when (string-match "\\S-" txt)
3304 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3305 (overlay-put o 'evaporate t)
3306 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3307 (overlay-put o 'after-string txt))))
3309 (defun org-agenda-entry-text-show ()
3310 "Add entry context for all agenda lines."
3311 (interactive)
3312 (save-excursion
3313 (goto-char (point-max))
3314 (beginning-of-line 1)
3315 (while (not (bobp))
3316 (when (org-get-at-bol 'org-hd-marker)
3317 (org-agenda-entry-text-show-here))
3318 (beginning-of-line 0))))
3320 (defun org-agenda-entry-text-hide ()
3321 "Remove any shown entry context."
3322 (delq nil
3323 (mapcar (lambda (o)
3324 (if (eq (overlay-get o 'org-overlay-type)
3325 'agenda-entry-content)
3326 (progn (delete-overlay o) t)))
3327 (overlays-in (point-min) (point-max)))))
3329 (defun org-agenda-get-day-face (date)
3330 "Return the face DATE should be displayed with."
3331 (or (and (functionp org-agenda-day-face-function)
3332 (funcall org-agenda-day-face-function date))
3333 (cond ((org-agenda-todayp date)
3334 'org-agenda-date-today)
3335 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3336 'org-agenda-date-weekend)
3337 (t 'org-agenda-date))))
3339 ;;; Agenda timeline
3341 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3343 (defun org-timeline (&optional include-all)
3344 "Show a time-sorted view of the entries in the current org file.
3345 Only entries with a time stamp of today or later will be listed. With
3346 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3347 under the current date.
3348 If the buffer contains an active region, only check the region for
3349 dates."
3350 (interactive "P")
3351 (org-compile-prefix-format 'timeline)
3352 (org-set-sorting-strategy 'timeline)
3353 (let* ((dopast t)
3354 (dotodo include-all)
3355 (doclosed org-agenda-show-log)
3356 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3357 (current-buffer))))
3358 (date (calendar-current-date))
3359 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3360 (end (if (org-region-active-p) (region-end) (point-max)))
3361 (day-numbers (org-get-all-dates beg end 'no-ranges
3362 t doclosed ; always include today
3363 org-timeline-show-empty-dates))
3364 (org-deadline-warning-days 0)
3365 (org-agenda-only-exact-dates t)
3366 (today (org-today))
3367 (past t)
3368 args
3369 s e rtn d emptyp)
3370 (setq org-agenda-redo-command
3371 (list 'progn
3372 (list 'org-switch-to-buffer-other-window (current-buffer))
3373 (list 'org-timeline (list 'quote include-all))))
3374 (if (not dopast)
3375 ;; Remove past dates from the list of dates.
3376 (setq day-numbers (delq nil (mapcar (lambda(x)
3377 (if (>= x today) x nil))
3378 day-numbers))))
3379 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3380 (if doclosed (push :closed args))
3381 (push :timestamp args)
3382 (push :deadline args)
3383 (push :scheduled args)
3384 (push :sexp args)
3385 (if dotodo (push :todo args))
3386 (insert "Timeline of file " entry "\n")
3387 (add-text-properties (point-min) (point)
3388 (list 'face 'org-agenda-structure))
3389 (org-agenda-mark-header-line (point-min))
3390 (while (setq d (pop day-numbers))
3391 (if (and (listp d) (eq (car d) :omitted))
3392 (progn
3393 (setq s (point))
3394 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3395 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3396 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3397 (if (and (>= d today)
3398 dopast
3399 past)
3400 (progn
3401 (setq past nil)
3402 (insert (make-string 79 ?-) "\n")))
3403 (setq date (calendar-gregorian-from-absolute d))
3404 (setq s (point))
3405 (setq rtn (and (not emptyp)
3406 (apply 'org-agenda-get-day-entries entry
3407 date args)))
3408 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3409 (progn
3410 (insert
3411 (if (stringp org-agenda-format-date)
3412 (format-time-string org-agenda-format-date
3413 (org-time-from-absolute date))
3414 (funcall org-agenda-format-date date))
3415 "\n")
3416 (put-text-property s (1- (point)) 'face
3417 (org-agenda-get-day-face date))
3418 (put-text-property s (1- (point)) 'org-date-line t)
3419 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3420 (if (equal d today)
3421 (put-text-property s (1- (point)) 'org-today t))
3422 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3423 (put-text-property s (1- (point)) 'day d)))))
3424 (goto-char (point-min))
3425 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3426 (point-min)))
3427 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3428 (org-finalize-agenda)
3429 (setq buffer-read-only t)))
3431 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3432 "Return a list of all relevant day numbers from BEG to END buffer positions.
3433 If NO-RANGES is non-nil, include only the start and end dates of a range,
3434 not every single day in the range. If FORCE-TODAY is non-nil, make
3435 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3436 inactive time stamps (those in square brackets) are included.
3437 When EMPTY is non-nil, also include days without any entries."
3438 (let ((re (concat
3439 (if pre-re pre-re "")
3440 (if inactive org-ts-regexp-both org-ts-regexp)))
3441 dates dates1 date day day1 day2 ts1 ts2)
3442 (if force-today
3443 (setq dates (list (org-today))))
3444 (save-excursion
3445 (goto-char beg)
3446 (while (re-search-forward re end t)
3447 (setq day (time-to-days (org-time-string-to-time
3448 (substring (match-string 1) 0 10))))
3449 (or (memq day dates) (push day dates)))
3450 (unless no-ranges
3451 (goto-char beg)
3452 (while (re-search-forward org-tr-regexp end t)
3453 (setq ts1 (substring (match-string 1) 0 10)
3454 ts2 (substring (match-string 2) 0 10)
3455 day1 (time-to-days (org-time-string-to-time ts1))
3456 day2 (time-to-days (org-time-string-to-time ts2)))
3457 (while (< (setq day1 (1+ day1)) day2)
3458 (or (memq day1 dates) (push day1 dates)))))
3459 (setq dates (sort dates '<))
3460 (when empty
3461 (while (setq day (pop dates))
3462 (setq day2 (car dates))
3463 (push day dates1)
3464 (when (and day2 empty)
3465 (if (or (eq empty t)
3466 (and (numberp empty) (<= (- day2 day) empty)))
3467 (while (< (setq day (1+ day)) day2)
3468 (push (list day) dates1))
3469 (push (cons :omitted (- day2 day)) dates1))))
3470 (setq dates (nreverse dates1)))
3471 dates)))
3473 ;;; Agenda Daily/Weekly
3475 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3476 "Start day for the agenda view.
3477 Custom commands can set this variable in the options section.")
3478 (defvar org-starting-day nil) ; local variable in the agenda buffer
3479 (defvar org-agenda-current-span nil
3480 "The current span used in the agenda view.") ; local variable in the agenda buffer
3481 (defvar org-include-all-loc nil) ; local variable
3483 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3484 "List of types searched for when creating the daily/weekly agenda.
3485 This variable is a list of symbols that controls the types of
3486 items that appear in the daily/weekly agenda. Allowed symbols in this
3487 list are are
3489 :timestamp List items containing a date stamp or date range matching
3490 the selected date. This includes sexp entries in
3491 angular brackets.
3493 :sexp List entries resulting from plain diary-like sexps.
3495 :deadline List deadline due on that date. When the date is today,
3496 also list any deadlines past due, or due within
3497 `org-deadline-warning-days'. `:deadline' must appear before
3498 `:scheduled' if the setting of
3499 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3500 any effect.
3502 :scheduled List all items which are scheduled for the given date.
3503 The diary for *today* also contains items which were
3504 scheduled earlier and are not yet marked DONE.
3506 By default, all four types are turned on.
3508 Never set this variable globally using `setq', because then it
3509 will apply to all future agenda commands. Instead, bind it with
3510 `let' to scope it dynamically into the agenda-constructing
3511 command. A good way to set it is through options in
3512 `org-agenda-custom-commands'. For a more flexible (though
3513 somewhat less efficient) way of determining what is included in
3514 the daily/weekly agenda, see `org-agenda-skip-function'.")
3516 ;;;###autoload
3517 (defun org-agenda-list (&optional include-all start-day span)
3518 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3519 The view will be for the current day or week, but from the overview buffer
3520 you will be able to go to other days/weeks.
3522 With a numeric prefix argument in an interactive call, the agenda will
3523 span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
3524 the number of days. SPAN defaults to `org-agenda-span'.
3526 START-DAY defaults to TODAY, or to the most recent match for the weekday
3527 given in `org-agenda-start-on-weekday'."
3528 (interactive "P")
3529 (if (and (integerp include-all) (> include-all 0))
3530 (setq span include-all include-all nil))
3531 (setq start-day (or start-day org-agenda-start-day))
3532 (if org-agenda-overriding-arguments
3533 (setq include-all (car org-agenda-overriding-arguments)
3534 start-day (nth 1 org-agenda-overriding-arguments)
3535 span (nth 2 org-agenda-overriding-arguments)))
3536 (if (stringp start-day)
3537 ;; Convert to an absolute day number
3538 (setq start-day (time-to-days (org-read-date nil t start-day))))
3539 (setq org-agenda-last-arguments (list include-all start-day span))
3540 (org-compile-prefix-format 'agenda)
3541 (org-set-sorting-strategy 'agenda)
3542 (let* ((span (org-agenda-ndays-to-span
3543 (or span org-agenda-ndays org-agenda-span)))
3544 (today (org-today))
3545 (sd (or start-day today))
3546 (ndays (org-agenda-span-to-ndays span sd))
3547 (org-agenda-start-on-weekday
3548 (if (eq ndays 7)
3549 org-agenda-start-on-weekday))
3550 (thefiles (org-agenda-files nil 'ifmode))
3551 (files thefiles)
3552 (start (if (or (null org-agenda-start-on-weekday)
3553 (< ndays 7))
3555 (let* ((nt (calendar-day-of-week
3556 (calendar-gregorian-from-absolute sd)))
3557 (n1 org-agenda-start-on-weekday)
3558 (d (- nt n1)))
3559 (- sd (+ (if (< d 0) 7 0) d)))))
3560 (day-numbers (list start))
3561 (day-cnt 0)
3562 (inhibit-redisplay (not debug-on-error))
3563 s e rtn rtnall file date d start-pos end-pos todayp
3564 clocktable-start clocktable-end filter)
3565 (setq org-agenda-redo-command
3566 (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
3567 (dotimes (n (1- ndays))
3568 (push (1+ (car day-numbers)) day-numbers))
3569 (setq day-numbers (nreverse day-numbers))
3570 (setq clocktable-start (car day-numbers)
3571 clocktable-end (1+ (or (org-last day-numbers) 0)))
3572 (org-prepare-agenda "Day/Week")
3573 (org-set-local 'org-starting-day (car day-numbers))
3574 (org-set-local 'org-include-all-loc include-all)
3575 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3576 (unless org-agenda-compact-blocks
3577 (let* ((d1 (car day-numbers))
3578 (d2 (org-last day-numbers))
3579 (w1 (org-days-to-iso-week d1))
3580 (w2 (org-days-to-iso-week d2)))
3581 (setq s (point))
3582 (if org-agenda-overriding-header
3583 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3584 nil 'face 'org-agenda-structure) "\n")
3585 (insert (org-agenda-span-name span)
3586 "-agenda"
3587 (if (< (- d2 d1) 350)
3588 (if (= w1 w2)
3589 (format " (W%02d)" w1)
3590 (format " (W%02d-W%02d)" w1 w2))
3592 ":\n")))
3593 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3594 'org-date-line t))
3595 (org-agenda-mark-header-line s))
3596 (while (setq d (pop day-numbers))
3597 (setq date (calendar-gregorian-from-absolute d)
3598 s (point))
3599 (if (or (setq todayp (= d today))
3600 (and (not start-pos) (= d sd)))
3601 (setq start-pos (point))
3602 (if (and start-pos (not end-pos))
3603 (setq end-pos (point))))
3604 (setq files thefiles
3605 rtnall nil)
3606 (while (setq file (pop files))
3607 (catch 'nextfile
3608 (org-check-agenda-file file)
3609 (let ((org-agenda-entry-types org-agenda-entry-types))
3610 (unless org-agenda-include-deadlines
3611 (setq org-agenda-entry-types
3612 (delq :deadline org-agenda-entry-types)))
3613 (cond
3614 ((memq org-agenda-show-log '(only clockcheck))
3615 (setq rtn (org-agenda-get-day-entries
3616 file date :closed)))
3617 (org-agenda-show-log
3618 (setq rtn (apply 'org-agenda-get-day-entries
3619 file date
3620 (append '(:closed) org-agenda-entry-types))))
3622 (setq rtn (apply 'org-agenda-get-day-entries
3623 file date
3624 org-agenda-entry-types)))))
3625 (setq rtnall (append rtnall rtn))))
3626 (if org-agenda-include-diary
3627 (let ((org-agenda-search-headline-for-time t))
3628 (require 'diary-lib)
3629 (setq rtn (org-get-entries-from-diary date))
3630 (setq rtnall (append rtnall rtn))))
3631 (if (or rtnall org-agenda-show-all-dates)
3632 (progn
3633 (setq day-cnt (1+ day-cnt))
3634 (insert
3635 (if (stringp org-agenda-format-date)
3636 (format-time-string org-agenda-format-date
3637 (org-time-from-absolute date))
3638 (funcall org-agenda-format-date date))
3639 "\n")
3640 (put-text-property s (1- (point)) 'face
3641 (org-agenda-get-day-face date))
3642 (put-text-property s (1- (point)) 'org-date-line t)
3643 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3644 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3645 (when todayp
3646 (put-text-property s (1- (point)) 'org-today t))
3647 (if rtnall (insert
3648 (org-finalize-agenda-entries
3649 (org-agenda-add-time-grid-maybe
3650 rtnall ndays todayp))
3651 "\n"))
3652 (put-text-property s (1- (point)) 'day d)
3653 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3654 (when (and org-agenda-clockreport-mode clocktable-start)
3655 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3656 ;; the above line is to ensure the restricted range!
3657 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3658 tbl)
3659 (setq p (org-plist-delete p :block))
3660 (setq p (plist-put p :tstart clocktable-start))
3661 (setq p (plist-put p :tend clocktable-end))
3662 (setq p (plist-put p :scope 'agenda))
3663 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3664 (setq filter (or org-agenda-filter-while-redo
3665 (get 'org-agenda-filter :preset-filter))))
3666 (setq p (plist-put p :tags (mapconcat (lambda (x)
3667 (if (string-match "[<>=]" x)
3670 filter ""))))
3671 (setq tbl (apply 'org-get-clocktable p))
3672 (insert tbl)))
3673 (goto-char (point-min))
3674 (or org-agenda-multi (org-fit-agenda-window))
3675 (unless (and (pos-visible-in-window-p (point-min))
3676 (pos-visible-in-window-p (point-max)))
3677 (goto-char (1- (point-max)))
3678 (recenter -1)
3679 (if (not (pos-visible-in-window-p (or start-pos 1)))
3680 (progn
3681 (goto-char (or start-pos 1))
3682 (recenter 1))))
3683 (goto-char (or start-pos 1))
3684 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3685 (if (eq org-agenda-show-log 'clockcheck)
3686 (org-agenda-show-clocking-issues))
3687 (org-finalize-agenda)
3688 (setq buffer-read-only t)
3689 (message "")))
3691 (defun org-agenda-ndays-to-span (n)
3692 "Return a span symbol for a span of N days, or N if none matches."
3693 (cond ((symbolp n) n)
3694 ((= n 1) 'day)
3695 ((= n 7) 'week)
3696 (t n)))
3698 (defun org-agenda-span-to-ndays (span start-day)
3699 "Return ndays from SPAN starting at START-DAY."
3700 (cond ((numberp span) span)
3701 ((eq span 'day) 1)
3702 ((eq span 'week) 7)
3703 ((eq span 'month)
3704 (let ((date (calendar-gregorian-from-absolute start-day)))
3705 (calendar-last-day-of-month (car date) (caddr date))))
3706 ((eq span 'year)
3707 (let ((date (calendar-gregorian-from-absolute start-day)))
3708 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3710 (defun org-agenda-span-name (span)
3711 "Return a SPAN name."
3712 (if (null span)
3714 (if (symbolp span)
3715 (capitalize (symbol-name span))
3716 (format "%d days" span))))
3718 ;;; Agenda word search
3720 (defvar org-agenda-search-history nil)
3721 (defvar org-todo-only nil)
3723 (defvar org-search-syntax-table nil
3724 "Special syntax table for org-mode search.
3725 In this table, we have single quotes not as word constituents, to
3726 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3728 (defun org-search-syntax-table ()
3729 (unless org-search-syntax-table
3730 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3731 (modify-syntax-entry ?' "." org-search-syntax-table)
3732 (modify-syntax-entry ?` "." org-search-syntax-table))
3733 org-search-syntax-table)
3735 (defvar org-agenda-last-search-view-search-was-boolean nil)
3737 ;;;###autoload
3738 (defun org-search-view (&optional todo-only string edit-at)
3739 "Show all entries that contain a phrase or words or regular expressions.
3741 With optional prefix argument TODO-ONLY, only consider entries that are
3742 TODO entries. The argument STRING can be used to pass a default search
3743 string into this function. If EDIT-AT is non-nil, it means that the
3744 user should get a chance to edit this string, with cursor at position
3745 EDIT-AT.
3747 The search string can be viewed either as a phrase that should be found as
3748 is, or it can be broken into a number of snippets, each of which must match
3749 in a Boolean way to select an entry. The default depends on the variable
3750 `org-agenda-search-view-always-boolean'.
3751 Even if this is turned off (the default) you can always switch to
3752 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3754 The default is a direct search of the whole phrase, where each space in
3755 the search string can expand to an arbitrary amount of whitespace,
3756 including newlines.
3758 If using a Boolean search, the search string is split on whitespace and
3759 each snippet is searched separately, with logical AND to select an entry.
3760 Words prefixed with a minus must *not* occur in the entry. Words without
3761 a prefix or prefixed with a plus must occur in the entry. Matching is
3762 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3763 match whole words, not parts of a word) if
3764 `org-agenda-search-view-force-full-words' is set (default is nil).
3766 Boolean search snippets enclosed by curly braces are interpreted as
3767 regular expressions that must or (when preceded with \"-\") must not
3768 match in the entry. Snippets enclosed into double quotes will be taken
3769 as a whole, to include whitespace.
3771 - If the search string starts with an asterisk, search only in headlines.
3772 - If (possibly after the leading star) the search string starts with an
3773 exclamation mark, this also means to look at TODO entries only, an effect
3774 that can also be achieved with a prefix argument.
3775 - If (possibly after star and exclamation mark) the search string starts
3776 with a colon, this will mean that the (non-regexp) snippets of the
3777 Boolean search must match as full words.
3779 This command searches the agenda files, and in addition the files listed
3780 in `org-agenda-text-search-extra-files'."
3781 (interactive "P")
3782 (org-compile-prefix-format 'search)
3783 (org-set-sorting-strategy 'search)
3784 (org-prepare-agenda "SEARCH")
3785 (let* ((props (list 'face nil
3786 'done-face 'org-agenda-done
3787 'org-not-done-regexp org-not-done-regexp
3788 'org-todo-regexp org-todo-regexp
3789 'org-complex-heading-regexp org-complex-heading-regexp
3790 'mouse-face 'highlight
3791 'help-echo (format "mouse-2 or RET jump to location")))
3792 (full-words org-agenda-search-view-force-full-words)
3793 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3794 regexp rtn rtnall files file pos
3795 marker category tags c neg re boolean
3796 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3797 (unless (and (not edit-at)
3798 (stringp string)
3799 (string-match "\\S-" string))
3800 (setq string (read-string
3801 (if org-agenda-search-view-always-boolean
3802 "[+-]Word/{Regexp} ...: "
3803 "Phrase, or [+-]Word/{Regexp} ...: ")
3804 (cond
3805 ((integerp edit-at) (cons string edit-at))
3806 (edit-at string))
3807 'org-agenda-search-history)))
3808 (org-set-local 'org-todo-only todo-only)
3809 (setq org-agenda-redo-command
3810 (list 'org-search-view (if todo-only t nil) string
3811 '(if current-prefix-arg 1 nil)))
3812 (setq org-agenda-query-string string)
3814 (if (equal (string-to-char string) ?*)
3815 (setq hdl-only t
3816 words (substring string 1))
3817 (setq words string))
3818 (when (equal (string-to-char words) ?!)
3819 (setq todo-only t
3820 words (substring words 1)))
3821 (when (equal (string-to-char words) ?:)
3822 (setq full-words t
3823 words (substring words 1)))
3824 (if (or org-agenda-search-view-always-boolean
3825 (member (string-to-char words) '(?- ?+ ?\{)))
3826 (setq boolean t))
3827 (setq words (org-split-string words))
3828 (let (www w)
3829 (while (setq w (pop words))
3830 (while (and (string-match "\\\\\\'" w) words)
3831 (setq w (concat (substring w 0 -1) " " (pop words))))
3832 (push w www))
3833 (setq words (nreverse www) www nil)
3834 (while (setq w (pop words))
3835 (when (and (string-match "\\`[-+]?{" w)
3836 (not (string-match "}\\'" w)))
3837 (while (and words (not (string-match "}\\'" (car words))))
3838 (setq w (concat w " " (pop words))))
3839 (setq w (concat w " " (pop words))))
3840 (push w www))
3841 (setq words (nreverse www)))
3842 (setq org-agenda-last-search-view-search-was-boolean boolean)
3843 (when boolean
3844 (let (wds w)
3845 (while (setq w (pop words))
3846 (if (or (equal (substring w 0 1) "\"")
3847 (and (> (length w) 1)
3848 (member (substring w 0 1) '("+" "-"))
3849 (equal (substring w 1 2) "\"")))
3850 (while (and words (not (equal (substring w -1) "\"")))
3851 (setq w (concat w " " (pop words)))))
3852 (and (string-match "\\`\\([-+]?\\)\"" w)
3853 (setq w (replace-match "\\1" nil nil w)))
3854 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3855 (push w wds))
3856 (setq words (nreverse wds))))
3857 (if boolean
3858 (mapc (lambda (w)
3859 (setq c (string-to-char w))
3860 (if (equal c ?-)
3861 (setq neg t w (substring w 1))
3862 (if (equal c ?+)
3863 (setq neg nil w (substring w 1))
3864 (setq neg nil)))
3865 (if (string-match "\\`{.*}\\'" w)
3866 (setq re (substring w 1 -1))
3867 (if full-words
3868 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3869 (setq re (regexp-quote (downcase w)))))
3870 (if neg (push re regexps-) (push re regexps+)))
3871 words)
3872 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3873 regexps+))
3874 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3875 (if (not regexps+)
3876 (setq regexp (concat "^" org-outline-regexp))
3877 (setq regexp (pop regexps+))
3878 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3879 regexp))))
3880 (setq files (org-agenda-files nil 'ifmode))
3881 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3882 (pop org-agenda-text-search-extra-files)
3883 (setq files (org-add-archive-files files)))
3884 (setq files (append files org-agenda-text-search-extra-files)
3885 rtnall nil)
3886 (while (setq file (pop files))
3887 (setq ee nil)
3888 (catch 'nextfile
3889 (org-check-agenda-file file)
3890 (setq buffer (if (file-exists-p file)
3891 (org-get-agenda-file-buffer file)
3892 (error "No such file %s" file)))
3893 (if (not buffer)
3894 ;; If file does not exist, make sure an error message is sent
3895 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3896 file))))
3897 (with-current-buffer buffer
3898 (with-syntax-table (org-search-syntax-table)
3899 (unless (org-mode-p)
3900 (error "Agenda file %s is not in `org-mode'" file))
3901 (let ((case-fold-search t))
3902 (save-excursion
3903 (save-restriction
3904 (if org-agenda-restrict
3905 (narrow-to-region org-agenda-restrict-begin
3906 org-agenda-restrict-end)
3907 (widen))
3908 (goto-char (point-min))
3909 (unless (or (org-on-heading-p)
3910 (outline-next-heading))
3911 (throw 'nextfile t))
3912 (goto-char (max (point-min) (1- (point))))
3913 (while (re-search-forward regexp nil t)
3914 (org-back-to-heading t)
3915 (skip-chars-forward "* ")
3916 (setq beg (point-at-bol)
3917 beg1 (point)
3918 end (progn (outline-next-heading) (point)))
3919 (catch :skip
3920 (goto-char beg)
3921 (org-agenda-skip)
3922 (setq str (buffer-substring-no-properties
3923 (point-at-bol)
3924 (if hdl-only (point-at-eol) end)))
3925 (mapc (lambda (wr) (when (string-match wr str)
3926 (goto-char (1- end))
3927 (throw :skip t)))
3928 regexps-)
3929 (mapc (lambda (wr) (unless (string-match wr str)
3930 (goto-char (1- end))
3931 (throw :skip t)))
3932 (if todo-only
3933 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3934 regexps+)
3935 regexps+))
3936 (goto-char beg)
3937 (setq marker (org-agenda-new-marker (point))
3938 category (org-get-category)
3939 tags (org-get-tags-at (point))
3940 txt (org-format-agenda-item
3942 (buffer-substring-no-properties
3943 beg1 (point-at-eol))
3944 category tags))
3945 (org-add-props txt props
3946 'org-marker marker 'org-hd-marker marker
3947 'org-todo-regexp org-todo-regexp
3948 'org-complex-heading-regexp org-complex-heading-regexp
3949 'priority 1000 'org-category category
3950 'type "search")
3951 (push txt ee)
3952 (goto-char (1- end))))))))))
3953 (setq rtn (nreverse ee))
3954 (setq rtnall (append rtnall rtn)))
3955 (if org-agenda-overriding-header
3956 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3957 nil 'face 'org-agenda-structure) "\n")
3958 (insert "Search words: ")
3959 (add-text-properties (point-min) (1- (point))
3960 (list 'face 'org-agenda-structure))
3961 (setq pos (point))
3962 (insert string "\n")
3963 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3964 (setq pos (point))
3965 (unless org-agenda-multi
3966 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3967 (add-text-properties pos (1- (point))
3968 (list 'face 'org-agenda-structure))))
3969 (org-agenda-mark-header-line (point-min))
3970 (when rtnall
3971 (insert (org-finalize-agenda-entries rtnall) "\n"))
3972 (goto-char (point-min))
3973 (or org-agenda-multi (org-fit-agenda-window))
3974 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3975 (org-finalize-agenda)
3976 (setq buffer-read-only t)))
3978 ;;; Agenda TODO list
3980 (defvar org-select-this-todo-keyword nil)
3981 (defvar org-last-arg nil)
3983 ;;;###autoload
3984 (defun org-todo-list (arg)
3985 "Show all (not done) TODO entries from all agenda file in a single list.
3986 The prefix arg can be used to select a specific TODO keyword and limit
3987 the list to these. When using \\[universal-argument], you will be prompted
3988 for a keyword. A numeric prefix directly selects the Nth keyword in
3989 `org-todo-keywords-1'."
3990 (interactive "P")
3991 (org-compile-prefix-format 'todo)
3992 (org-set-sorting-strategy 'todo)
3993 (org-prepare-agenda "TODO")
3994 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3995 (let* ((today (org-today))
3996 (date (calendar-gregorian-from-absolute today))
3997 (kwds org-todo-keywords-for-agenda)
3998 (completion-ignore-case t)
3999 (org-select-this-todo-keyword
4000 (if (stringp arg) arg
4001 (and arg (integerp arg) (> arg 0)
4002 (nth (1- arg) kwds))))
4003 rtn rtnall files file pos)
4004 (when (equal arg '(4))
4005 (setq org-select-this-todo-keyword
4006 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4007 (mapcar 'list kwds) nil nil)))
4008 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4009 (org-set-local 'org-last-arg arg)
4010 (setq org-agenda-redo-command
4011 '(org-todo-list (or current-prefix-arg org-last-arg)))
4012 (setq files (org-agenda-files nil 'ifmode)
4013 rtnall nil)
4014 (while (setq file (pop files))
4015 (catch 'nextfile
4016 (org-check-agenda-file file)
4017 (setq rtn (org-agenda-get-day-entries file date :todo))
4018 (setq rtnall (append rtnall rtn))))
4019 (if org-agenda-overriding-header
4020 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4021 nil 'face 'org-agenda-structure) "\n")
4022 (insert "Global list of TODO items of type: ")
4023 (add-text-properties (point-min) (1- (point))
4024 (list 'face 'org-agenda-structure
4025 'short-heading
4026 (concat "ToDo: "
4027 (or org-select-this-todo-keyword "ALL"))))
4028 (org-agenda-mark-header-line (point-min))
4029 (setq pos (point))
4030 (insert (or org-select-this-todo-keyword "ALL") "\n")
4031 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4032 (setq pos (point))
4033 (unless org-agenda-multi
4034 (insert "Available with `N r': (0)ALL")
4035 (let ((n 0) s)
4036 (mapc (lambda (x)
4037 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4038 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4039 (insert "\n "))
4040 (insert " " s))
4041 kwds))
4042 (insert "\n"))
4043 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4044 (org-agenda-mark-header-line (point-min))
4045 (when rtnall
4046 (insert (org-finalize-agenda-entries rtnall) "\n"))
4047 (goto-char (point-min))
4048 (or org-agenda-multi (org-fit-agenda-window))
4049 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4050 (org-finalize-agenda)
4051 (setq buffer-read-only t)))
4053 ;;; Agenda tags match
4055 ;;;###autoload
4056 (defun org-tags-view (&optional todo-only match)
4057 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4058 The prefix arg TODO-ONLY limits the search to TODO entries."
4059 (interactive "P")
4060 (org-compile-prefix-format 'tags)
4061 (org-set-sorting-strategy 'tags)
4062 (let* ((org-tags-match-list-sublevels
4063 org-tags-match-list-sublevels)
4064 (completion-ignore-case t)
4065 rtn rtnall files file pos matcher
4066 buffer)
4067 (when (and (stringp match) (not (string-match "\\S-" match)))
4068 (setq match nil))
4069 (setq matcher (org-make-tags-matcher match)
4070 match (car matcher) matcher (cdr matcher))
4071 (org-prepare-agenda (concat "TAGS " match))
4072 (setq org-agenda-query-string match)
4073 (setq org-agenda-redo-command
4074 (list 'org-tags-view (list 'quote todo-only)
4075 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4076 (setq files (org-agenda-files nil 'ifmode)
4077 rtnall nil)
4078 (while (setq file (pop files))
4079 (catch 'nextfile
4080 (org-check-agenda-file file)
4081 (setq buffer (if (file-exists-p file)
4082 (org-get-agenda-file-buffer file)
4083 (error "No such file %s" file)))
4084 (if (not buffer)
4085 ;; If file does not exist, error message to agenda
4086 (setq rtn (list
4087 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4088 rtnall (append rtnall rtn))
4089 (with-current-buffer buffer
4090 (unless (org-mode-p)
4091 (error "Agenda file %s is not in `org-mode'" file))
4092 (save-excursion
4093 (save-restriction
4094 (if org-agenda-restrict
4095 (narrow-to-region org-agenda-restrict-begin
4096 org-agenda-restrict-end)
4097 (widen))
4098 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4099 (setq rtnall (append rtnall rtn))))))))
4100 (if org-agenda-overriding-header
4101 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4102 nil 'face 'org-agenda-structure) "\n")
4103 (insert "Headlines with TAGS match: ")
4104 (add-text-properties (point-min) (1- (point))
4105 (list 'face 'org-agenda-structure
4106 'short-heading
4107 (concat "Match: " match)))
4108 (setq pos (point))
4109 (insert match "\n")
4110 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4111 (setq pos (point))
4112 (unless org-agenda-multi
4113 (insert "Press `C-u r' to search again with new search string\n"))
4114 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4115 (org-agenda-mark-header-line (point-min))
4116 (when rtnall
4117 (insert (org-finalize-agenda-entries rtnall) "\n"))
4118 (goto-char (point-min))
4119 (or org-agenda-multi (org-fit-agenda-window))
4120 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4121 (org-finalize-agenda)
4122 (setq buffer-read-only t)))
4124 ;;; Agenda Finding stuck projects
4126 (defvar org-agenda-skip-regexp nil
4127 "Regular expression used in skipping subtrees for the agenda.
4128 This is basically a temporary global variable that can be set and then
4129 used by user-defined selections using `org-agenda-skip-function'.")
4131 (defvar org-agenda-overriding-header nil
4132 "When set during agenda, todo and tags searches it replaces the header.
4133 This variable should not be set directly, but custom commands can bind it
4134 in the options section.")
4136 (defun org-agenda-skip-entry-when-regexp-matches ()
4137 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4138 If yes, it returns the end position of this entry, causing agenda commands
4139 to skip the entry but continuing the search in the subtree. This is a
4140 function that can be put into `org-agenda-skip-function' for the duration
4141 of a command."
4142 (let ((end (save-excursion (org-end-of-subtree t)))
4143 skip)
4144 (save-excursion
4145 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4146 (and skip end)))
4148 (defun org-agenda-skip-subtree-when-regexp-matches ()
4149 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4150 If yes, it returns the end position of this tree, causing agenda commands
4151 to skip this subtree. This is a function that can be put into
4152 `org-agenda-skip-function' for the duration of a command."
4153 (let ((end (save-excursion (org-end-of-subtree t)))
4154 skip)
4155 (save-excursion
4156 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4157 (and skip end)))
4159 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4160 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4161 If yes, it returns the end position of the current entry (NOT the tree),
4162 causing agenda commands to skip the entry but continuing the search in
4163 the subtree. This is a function that can be put into
4164 `org-agenda-skip-function' for the duration of a command. An important
4165 use of this function is for the stuck project list."
4166 (let ((end (save-excursion (org-end-of-subtree t)))
4167 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4168 skip)
4169 (save-excursion
4170 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4171 (and skip entry-end)))
4173 (defun org-agenda-skip-entry-if (&rest conditions)
4174 "Skip entry if any of CONDITIONS is true.
4175 See `org-agenda-skip-if' for details."
4176 (org-agenda-skip-if nil conditions))
4178 (defun org-agenda-skip-subtree-if (&rest conditions)
4179 "Skip entry if any of CONDITIONS is true.
4180 See `org-agenda-skip-if' for details."
4181 (org-agenda-skip-if t conditions))
4183 (defun org-agenda-skip-if (subtree conditions)
4184 "Checks current entity for CONDITIONS.
4185 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4186 the entry, i.e. the text before the next heading is checked.
4188 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4189 from different tests. Valid conditions are:
4191 scheduled Check if there is a scheduled cookie
4192 notscheduled Check if there is no scheduled cookie
4193 deadline Check if there is a deadline
4194 notdeadline Check if there is no deadline
4195 timestamp Check if there is a timestamp (also deadline or scheduled)
4196 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4197 regexp Check if regexp matches
4198 notregexp Check if regexp does not match.
4199 todo Check if TODO keyword matches
4200 nottodo Check if TODO keyword does not match
4202 The regexp is taken from the conditions list, it must come right after
4203 the `regexp' or `notregexp' element.
4205 `todo' and `nottodo' accept as an argument a list of todo
4206 keywords, which may include \"*\" to match any todo keyword.
4208 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4210 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4212 Instead of a list a keyword class may be given
4214 (org-agenda-skip-entry-if 'nottodo 'done)
4216 would skip entries that haven't been marked with any of \"DONE\"
4217 keywords. Possible classes are: `todo', `done', `any'.
4219 If any of these conditions is met, this function returns the end point of
4220 the entity, causing the search to continue from there. This is a function
4221 that can be put into `org-agenda-skip-function' for the duration of a command."
4222 (let (beg end m)
4223 (org-back-to-heading t)
4224 (setq beg (point)
4225 end (if subtree
4226 (progn (org-end-of-subtree t) (point))
4227 (progn (outline-next-heading) (1- (point)))))
4228 (goto-char beg)
4229 (and
4231 (and (memq 'scheduled conditions)
4232 (re-search-forward org-scheduled-time-regexp end t))
4233 (and (memq 'notscheduled conditions)
4234 (not (re-search-forward org-scheduled-time-regexp end t)))
4235 (and (memq 'deadline conditions)
4236 (re-search-forward org-deadline-time-regexp end t))
4237 (and (memq 'notdeadline conditions)
4238 (not (re-search-forward org-deadline-time-regexp end t)))
4239 (and (memq 'timestamp conditions)
4240 (re-search-forward org-ts-regexp end t))
4241 (and (memq 'nottimestamp conditions)
4242 (not (re-search-forward org-ts-regexp end t)))
4243 (and (setq m (memq 'regexp conditions))
4244 (stringp (nth 1 m))
4245 (re-search-forward (nth 1 m) end t))
4246 (and (setq m (memq 'notregexp conditions))
4247 (stringp (nth 1 m))
4248 (not (re-search-forward (nth 1 m) end t)))
4249 (and (or
4250 (setq m (memq 'todo conditions))
4251 (setq m (memq 'nottodo conditions)))
4252 (org-agenda-skip-if-todo m end)))
4253 end)))
4255 (defun org-agenda-skip-if-todo (args end)
4256 "Helper function for `org-agenda-skip-if', do not use it directly.
4257 ARGS is a list with first element either `todo' or `nottodo'.
4258 The remainder is either a list of TODO keywords, or a state symbol
4259 `todo' or `done' or `any'."
4260 (let ((kw (car args))
4261 (arg (cadr args))
4262 todo-wds todo-re)
4263 (setq todo-wds
4264 (org-uniquify
4265 (cond
4266 ((listp arg) ;; list of keywords
4267 (if (member "*" arg)
4268 (mapcar 'substring-no-properties org-todo-keywords-1)
4269 arg))
4270 ((symbolp arg) ;; keyword class name
4271 (cond
4272 ((eq arg 'todo)
4273 (org-delete-all org-done-keywords
4274 (mapcar 'substring-no-properties
4275 org-todo-keywords-1)))
4276 ((eq arg 'done) org-done-keywords)
4277 ((eq arg 'any)
4278 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4279 (setq todo-re
4280 (concat "^\\*+[ \t]+\\<\\("
4281 (mapconcat 'identity todo-wds "\\|")
4282 "\\)\\>"))
4283 (if (eq kw 'todo)
4284 (re-search-forward todo-re end t)
4285 (not (re-search-forward todo-re end t)))))
4287 ;;;###autoload
4288 (defun org-agenda-list-stuck-projects (&rest ignore)
4289 "Create agenda view for projects that are stuck.
4290 Stuck projects are project that have no next actions. For the definitions
4291 of what a project is and how to check if it stuck, customize the variable
4292 `org-stuck-projects'."
4293 (interactive)
4294 (let* ((org-agenda-skip-function
4295 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4296 ;; We could have used org-agenda-skip-if here.
4297 (org-agenda-overriding-header
4298 (or org-agenda-overriding-header "List of stuck projects: "))
4299 (matcher (nth 0 org-stuck-projects))
4300 (todo (nth 1 org-stuck-projects))
4301 (todo-wds (if (member "*" todo)
4302 (progn
4303 (org-prepare-agenda-buffers (org-agenda-files
4304 nil 'ifmode))
4305 (org-delete-all
4306 org-done-keywords-for-agenda
4307 (copy-sequence org-todo-keywords-for-agenda)))
4308 todo))
4309 (todo-re (concat "^\\*+[ \t]+\\("
4310 (mapconcat 'identity todo-wds "\\|")
4311 "\\)\\>"))
4312 (tags (nth 2 org-stuck-projects))
4313 (tags-re (if (member "*" tags)
4314 (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
4315 (if tags
4316 (concat "^\\*+ .*:\\("
4317 (mapconcat 'identity tags "\\|")
4318 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4319 (gen-re (nth 3 org-stuck-projects))
4320 (re-list
4321 (delq nil
4322 (list
4323 (if todo todo-re)
4324 (if tags tags-re)
4325 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4326 gen-re)))))
4327 (setq org-agenda-skip-regexp
4328 (if re-list
4329 (mapconcat 'identity re-list "\\|")
4330 (error "No information how to identify unstuck projects")))
4331 (org-tags-view nil matcher)
4332 (with-current-buffer org-agenda-buffer-name
4333 (setq org-agenda-redo-command
4334 '(org-agenda-list-stuck-projects
4335 (or current-prefix-arg org-last-arg))))))
4337 ;;; Diary integration
4339 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4340 (defvar list-diary-entries-hook)
4341 (defvar diary-time-regexp)
4342 (defun org-get-entries-from-diary (date)
4343 "Get the (Emacs Calendar) diary entries for DATE."
4344 (require 'diary-lib)
4345 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4346 (diary-display-hook '(fancy-diary-display))
4347 (diary-display-function 'fancy-diary-display)
4348 (pop-up-frames nil)
4349 (list-diary-entries-hook
4350 (cons 'org-diary-default-entry list-diary-entries-hook))
4351 (diary-file-name-prefix-function nil) ; turn this feature off
4352 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4353 entries
4354 (org-disable-agenda-to-diary t))
4355 (save-excursion
4356 (save-window-excursion
4357 (funcall (if (fboundp 'diary-list-entries)
4358 'diary-list-entries 'list-diary-entries)
4359 date 1)))
4360 (if (not (get-buffer diary-fancy-buffer))
4361 (setq entries nil)
4362 (with-current-buffer diary-fancy-buffer
4363 (setq buffer-read-only nil)
4364 (if (zerop (buffer-size))
4365 ;; No entries
4366 (setq entries nil)
4367 ;; Omit the date and other unnecessary stuff
4368 (org-agenda-cleanup-fancy-diary)
4369 ;; Add prefix to each line and extend the text properties
4370 (if (zerop (buffer-size))
4371 (setq entries nil)
4372 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4373 (setq entries
4374 (with-temp-buffer
4375 (insert entries) (goto-char (point-min))
4376 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4377 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4378 (replace-match (concat "; " (match-string 1)))))
4379 (buffer-string)))))
4380 (set-buffer-modified-p nil)
4381 (kill-buffer diary-fancy-buffer)))
4382 (when entries
4383 (setq entries (org-split-string entries "\n"))
4384 (setq entries
4385 (mapcar
4386 (lambda (x)
4387 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4388 ;; Extend the text properties to the beginning of the line
4389 (org-add-props x (text-properties-at (1- (length x)) x)
4390 'type "diary" 'date date 'face 'org-agenda-diary))
4391 entries)))))
4393 (defvar org-agenda-cleanup-fancy-diary-hook nil
4394 "Hook run when the fancy diary buffer is cleaned up.")
4396 (defun org-agenda-cleanup-fancy-diary ()
4397 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4398 This gets rid of the date, the underline under the date, and
4399 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4400 date. It also removes lines that contain only whitespace."
4401 (goto-char (point-min))
4402 (if (looking-at ".*?:[ \t]*")
4403 (progn
4404 (replace-match "")
4405 (re-search-forward "\n=+$" nil t)
4406 (replace-match "")
4407 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4408 (re-search-forward "\n=+$" nil t)
4409 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4410 (goto-char (point-min))
4411 (while (re-search-forward "^ +\n" nil t)
4412 (replace-match ""))
4413 (goto-char (point-min))
4414 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4415 (replace-match ""))
4416 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4418 ;; Make sure entries from the diary have the right text properties.
4419 (eval-after-load "diary-lib"
4420 '(if (boundp 'diary-modify-entry-list-string-function)
4421 ;; We can rely on the hook, nothing to do
4423 ;; Hook not available, must use advice to make this work
4424 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4425 "Make the position visible."
4426 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4427 (stringp string)
4428 buffer-file-name)
4429 (setq string (org-modify-diary-entry-string string))))))
4431 (defun org-modify-diary-entry-string (string)
4432 "Add text properties to string, allowing org-mode to act on it."
4433 (org-add-props string nil
4434 'mouse-face 'highlight
4435 'help-echo (if buffer-file-name
4436 (format "mouse-2 or RET jump to diary file %s"
4437 (abbreviate-file-name buffer-file-name))
4439 'org-agenda-diary-link t
4440 'org-marker (org-agenda-new-marker (point-at-bol))))
4442 (defun org-diary-default-entry ()
4443 "Add a dummy entry to the diary.
4444 Needed to avoid empty dates which mess up holiday display."
4445 ;; Catch the error if dealing with the new add-to-diary-alist
4446 (when org-disable-agenda-to-diary
4447 (condition-case nil
4448 (org-add-to-diary-list original-date "Org-mode dummy" "")
4449 (error
4450 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4452 (defun org-add-to-diary-list (&rest args)
4453 (if (fboundp 'diary-add-to-list)
4454 (apply 'diary-add-to-list args)
4455 (apply 'add-to-diary-list args)))
4457 (defvar org-diary-last-run-time nil)
4459 ;;;###autoload
4460 (defun org-diary (&rest args)
4461 "Return diary information from org-files.
4462 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4463 It accesses org files and extracts information from those files to be
4464 listed in the diary. The function accepts arguments specifying what
4465 items should be listed. For a list of arguments allowed here, see the
4466 variable `org-agenda-entry-types'.
4468 The call in the diary file should look like this:
4470 &%%(org-diary) ~/path/to/some/orgfile.org
4472 Use a separate line for each org file to check. Or, if you omit the file name,
4473 all files listed in `org-agenda-files' will be checked automatically:
4475 &%%(org-diary)
4477 If you don't give any arguments (as in the example above), the default
4478 arguments (:deadline :scheduled :timestamp :sexp) are used.
4479 So the example above may also be written as
4481 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4483 The function expects the lisp variables `entry' and `date' to be provided
4484 by the caller, because this is how the calendar works. Don't use this
4485 function from a program - use `org-agenda-get-day-entries' instead."
4486 (when (> (- (org-float-time)
4487 org-agenda-last-marker-time)
4489 (org-agenda-reset-markers))
4490 (org-compile-prefix-format 'agenda)
4491 (org-set-sorting-strategy 'agenda)
4492 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4493 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4494 (list entry)
4495 (org-agenda-files t)))
4496 (time (org-float-time))
4497 file rtn results)
4498 (when (or (not org-diary-last-run-time)
4499 (> (- time
4500 org-diary-last-run-time)
4502 (org-prepare-agenda-buffers files))
4503 (setq org-diary-last-run-time time)
4504 ;; If this is called during org-agenda, don't return any entries to
4505 ;; the calendar. Org Agenda will list these entries itself.
4506 (if org-disable-agenda-to-diary (setq files nil))
4507 (while (setq file (pop files))
4508 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4509 (setq results (append results rtn)))
4510 (if results
4511 (concat (org-finalize-agenda-entries results) "\n"))))
4513 ;;; Agenda entry finders
4515 (defun org-agenda-get-day-entries (file date &rest args)
4516 "Does the work for `org-diary' and `org-agenda'.
4517 FILE is the path to a file to be checked for entries. DATE is date like
4518 the one returned by `calendar-current-date'. ARGS are symbols indicating
4519 which kind of entries should be extracted. For details about these, see
4520 the documentation of `org-diary'."
4521 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4522 (let* ((org-startup-folded nil)
4523 (org-startup-align-all-tables nil)
4524 (buffer (if (file-exists-p file)
4525 (org-get-agenda-file-buffer file)
4526 (error "No such file %s" file)))
4527 arg results rtn deadline-results)
4528 (if (not buffer)
4529 ;; If file does not exist, make sure an error message ends up in diary
4530 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4531 (with-current-buffer buffer
4532 (unless (org-mode-p)
4533 (error "Agenda file %s is not in `org-mode'" file))
4534 (let ((case-fold-search nil))
4535 (save-excursion
4536 (save-restriction
4537 (if org-agenda-restrict
4538 (narrow-to-region org-agenda-restrict-begin
4539 org-agenda-restrict-end)
4540 (widen))
4541 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4542 (while (setq arg (pop args))
4543 (cond
4544 ((and (eq arg :todo)
4545 (equal date (calendar-gregorian-from-absolute
4546 (org-today))))
4547 (setq rtn (org-agenda-get-todos))
4548 (setq results (append results rtn)))
4549 ((eq arg :timestamp)
4550 (setq rtn (org-agenda-get-blocks))
4551 (setq results (append results rtn))
4552 (setq rtn (org-agenda-get-timestamps))
4553 (setq results (append results rtn)))
4554 ((eq arg :sexp)
4555 (setq rtn (org-agenda-get-sexps))
4556 (setq results (append results rtn)))
4557 ((eq arg :scheduled)
4558 (setq rtn (org-agenda-get-scheduled deadline-results))
4559 (setq results (append results rtn)))
4560 ((eq arg :closed)
4561 (setq rtn (org-agenda-get-progress))
4562 (setq results (append results rtn)))
4563 ((eq arg :deadline)
4564 (setq rtn (org-agenda-get-deadlines))
4565 (setq deadline-results (copy-sequence rtn))
4566 (setq results (append results rtn))))))))
4567 results))))
4569 (defun org-agenda-get-todos ()
4570 "Return the TODO information for agenda display."
4571 (let* ((props (list 'face nil
4572 'done-face 'org-agenda-done
4573 'org-not-done-regexp org-not-done-regexp
4574 'org-todo-regexp org-todo-regexp
4575 'org-complex-heading-regexp org-complex-heading-regexp
4576 'mouse-face 'highlight
4577 'help-echo
4578 (format "mouse-2 or RET jump to org file %s"
4579 (abbreviate-file-name buffer-file-name))))
4580 (regexp (concat "^\\*+[ \t]+\\("
4581 (if org-select-this-todo-keyword
4582 (if (equal org-select-this-todo-keyword "*")
4583 org-todo-regexp
4584 (concat "\\<\\("
4585 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4586 "\\)\\>"))
4587 org-not-done-regexp)
4588 "[^\n\r]*\\)"))
4589 marker priority category tags todo-state
4590 ee txt beg end)
4591 (goto-char (point-min))
4592 (while (re-search-forward regexp nil t)
4593 (catch :skip
4594 (save-match-data
4595 (beginning-of-line)
4596 (org-agenda-skip)
4597 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4598 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4599 (goto-char (1+ beg))
4600 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4601 (throw :skip nil)))
4602 (goto-char (match-beginning 1))
4603 (setq marker (org-agenda-new-marker (match-beginning 0))
4604 category (org-get-category)
4605 txt (match-string 1)
4606 tags (org-get-tags-at (point))
4607 txt (org-format-agenda-item "" txt category tags)
4608 priority (1+ (org-get-priority txt))
4609 todo-state (org-get-todo-state))
4610 (org-add-props txt props
4611 'org-marker marker 'org-hd-marker marker
4612 'priority priority 'org-category category
4613 'type "todo" 'todo-state todo-state)
4614 (push txt ee)
4615 (if org-agenda-todo-list-sublevels
4616 (goto-char (match-end 1))
4617 (org-end-of-subtree 'invisible))))
4618 (nreverse ee)))
4620 (defun org-agenda-todo-custom-ignore-p (time n)
4621 "Check whether timestamp is farther away then n number of days.
4622 This function is invoked if `org-agenda-todo-ignore-deadlines',
4623 `org-agenda-todo-ignore-scheduled' or
4624 `org-agenda-todo-ignore-timestamp' is set to an integer."
4625 (let ((days (org-days-to-time time)))
4626 (if (>= n 0)
4627 (>= days n)
4628 (<= days n))))
4630 ;;;###autoload
4631 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4632 (&optional end)
4633 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4634 (when (or org-agenda-todo-ignore-with-date
4635 org-agenda-todo-ignore-scheduled
4636 org-agenda-todo-ignore-deadlines
4637 org-agenda-todo-ignore-timestamp)
4638 (setq end (or end (save-excursion (outline-next-heading) (point))))
4639 (save-excursion
4640 (or (and org-agenda-todo-ignore-with-date
4641 (re-search-forward org-ts-regexp end t))
4642 (and org-agenda-todo-ignore-scheduled
4643 (re-search-forward org-scheduled-time-regexp end t)
4644 (cond
4645 ((eq org-agenda-todo-ignore-scheduled 'future)
4646 (> (org-days-to-time (match-string 1)) 0))
4647 ((eq org-agenda-todo-ignore-scheduled 'past)
4648 (<= (org-days-to-time (match-string 1)) 0))
4649 ((numberp org-agenda-todo-ignore-scheduled)
4650 (org-agenda-todo-custom-ignore-p
4651 (match-string 1) org-agenda-todo-ignore-scheduled))
4652 (t)))
4653 (and org-agenda-todo-ignore-deadlines
4654 (re-search-forward org-deadline-time-regexp end t)
4655 (cond
4656 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4657 ((eq org-agenda-todo-ignore-deadlines 'far)
4658 (not (org-deadline-close (match-string 1))))
4659 ((eq org-agenda-todo-ignore-deadlines 'future)
4660 (> (org-days-to-time (match-string 1)) 0))
4661 ((eq org-agenda-todo-ignore-deadlines 'past)
4662 (<= (org-days-to-time (match-string 1)) 0))
4663 ((numberp org-agenda-todo-ignore-deadlines)
4664 (org-agenda-todo-custom-ignore-p
4665 (match-string 1) org-agenda-todo-ignore-deadlines))
4666 (t (org-deadline-close (match-string 1)))))
4667 (and org-agenda-todo-ignore-timestamp
4668 (let ((buffer (current-buffer))
4669 (regexp
4670 (concat
4671 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4672 (start (point)))
4673 ;; Copy current buffer into a temporary one
4674 (with-temp-buffer
4675 (insert-buffer-substring buffer start end)
4676 (goto-char (point-min))
4677 ;; Delete SCHEDULED and DEADLINE items
4678 (while (re-search-forward regexp end t)
4679 (delete-region (match-beginning 0) (match-end 0)))
4680 (goto-char (point-min))
4681 ;; No search for timestamp left
4682 (when (re-search-forward org-ts-regexp nil t)
4683 (cond
4684 ((eq org-agenda-todo-ignore-timestamp 'future)
4685 (> (org-days-to-time (match-string 1)) 0))
4686 ((eq org-agenda-todo-ignore-timestamp 'past)
4687 (<= (org-days-to-time (match-string 1)) 0))
4688 ((numberp org-agenda-todo-ignore-timestamp)
4689 (org-agenda-todo-custom-ignore-p
4690 (match-string 1) org-agenda-todo-ignore-timestamp))
4691 (t))))))))))
4693 (defconst org-agenda-no-heading-message
4694 "No heading for this item in buffer or region.")
4696 (defun org-agenda-get-timestamps ()
4697 "Return the date stamp information for agenda display."
4698 (let* ((props (list 'face nil
4699 'org-not-done-regexp org-not-done-regexp
4700 'org-todo-regexp org-todo-regexp
4701 'org-complex-heading-regexp org-complex-heading-regexp
4702 'mouse-face 'highlight
4703 'help-echo
4704 (format "mouse-2 or RET jump to org file %s"
4705 (abbreviate-file-name buffer-file-name))))
4706 (d1 (calendar-absolute-from-gregorian date))
4707 (remove-re
4708 (concat
4709 (regexp-quote
4710 (format-time-string
4711 "<%Y-%m-%d"
4712 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4713 ".*?>"))
4714 (regexp
4715 (concat
4716 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4717 (regexp-quote
4718 (substring
4719 (format-time-string
4720 (car org-time-stamp-formats)
4721 (apply 'encode-time ; DATE bound by calendar
4722 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4723 1 11))
4724 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4725 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4726 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4727 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4728 todo-state end-of-match show-all)
4729 (goto-char (point-min))
4730 (while (setq end-of-match (re-search-forward regexp nil t))
4731 (setq b0 (match-beginning 0)
4732 b3 (match-beginning 3) e3 (match-end 3)
4733 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4734 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4735 (member todo-state
4736 org-agenda-repeating-timestamp-show-all)))
4737 (catch :skip
4738 (and (org-at-date-range-p) (throw :skip nil))
4739 (org-agenda-skip)
4740 (if (and (match-end 1)
4741 (not (= d1 (org-time-string-to-absolute
4742 (match-string 1) d1 nil show-all))))
4743 (throw :skip nil))
4744 (if (and e3
4745 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4746 (throw :skip nil))
4747 (setq tmp (buffer-substring (max (point-min)
4748 (- b0 org-ds-keyword-length))
4750 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4751 inactivep (= (char-after b0) ?\[)
4752 deadlinep (string-match org-deadline-regexp tmp)
4753 scheduledp (string-match org-scheduled-regexp tmp)
4754 closedp (and org-agenda-include-inactive-timestamps
4755 (string-match org-closed-string tmp))
4756 clockp (and org-agenda-include-inactive-timestamps
4757 (or (string-match org-clock-string tmp)
4758 (string-match "]-+\\'" tmp)))
4759 donep (member todo-state org-done-keywords))
4760 (if (or scheduledp deadlinep closedp clockp
4761 (and donep org-agenda-skip-timestamp-if-done))
4762 (throw :skip t))
4763 (if (string-match ">" timestr)
4764 ;; substring should only run to end of time stamp
4765 (setq timestr (substring timestr 0 (match-end 0))))
4766 (setq marker (org-agenda-new-marker b0)
4767 category (org-get-category b0))
4768 (save-excursion
4769 (if (not (re-search-backward "^\\*+ " nil t))
4770 (setq txt org-agenda-no-heading-message)
4771 (goto-char (match-beginning 0))
4772 (setq hdmarker (org-agenda-new-marker)
4773 tags (org-get-tags-at))
4774 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4775 (setq head (or (match-string 1) ""))
4776 (setq txt (org-format-agenda-item
4777 (if inactivep org-agenda-inactive-leader nil)
4778 head category tags timestr
4779 remove-re)))
4780 (setq priority (org-get-priority txt))
4781 (org-add-props txt props
4782 'org-marker marker 'org-hd-marker hdmarker)
4783 (org-add-props txt nil 'priority priority
4784 'org-category category 'date date
4785 'todo-state todo-state
4786 'type "timestamp")
4787 (push txt ee))
4788 (if org-agenda-skip-additional-timestamps-same-entry
4789 (outline-next-heading)
4790 (goto-char end-of-match))))
4791 (nreverse ee)))
4793 (defun org-agenda-get-sexps ()
4794 "Return the sexp information for agenda display."
4795 (require 'diary-lib)
4796 (let* ((props (list 'mouse-face 'highlight
4797 'help-echo
4798 (format "mouse-2 or RET jump to org file %s"
4799 (abbreviate-file-name buffer-file-name))))
4800 (regexp "^&?%%(")
4801 marker category ee txt tags entry result beg b sexp sexp-entry
4802 todo-state)
4803 (goto-char (point-min))
4804 (while (re-search-forward regexp nil t)
4805 (catch :skip
4806 (org-agenda-skip)
4807 (setq beg (match-beginning 0))
4808 (goto-char (1- (match-end 0)))
4809 (setq b (point))
4810 (forward-sexp 1)
4811 (setq sexp (buffer-substring b (point)))
4812 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4813 (org-trim (match-string 1))
4814 ""))
4815 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4816 (when result
4817 (setq marker (org-agenda-new-marker beg)
4818 category (org-get-category beg)
4819 todo-state (org-get-todo-state))
4821 (dolist (r (if (stringp result)
4822 (list result)
4823 result)) ;; we expect a list here
4824 (if (string-match "\\S-" r)
4825 (setq txt r)
4826 (setq txt "SEXP entry returned empty string"))
4828 (setq txt (org-format-agenda-item
4829 "" txt category tags 'time))
4830 (org-add-props txt props 'org-marker marker)
4831 (org-add-props txt nil
4832 'org-category category 'date date 'todo-state todo-state
4833 'type "sexp")
4834 (push txt ee)))))
4835 (nreverse ee)))
4837 ;; Calendar sanity: define some functions that are independent of
4838 ;; `calendar-date-style'.
4839 ;; Normally I would like to use ISO format when calling the diary functions,
4840 ;; but to make sure we still have Emacs 22 compatibility we bind
4841 ;; also `european-calendar-style' and use european format
4842 (defun org-anniversary (year month day &optional mark)
4843 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
4844 (org-no-warnings
4845 (let ((calendar-date-style 'european) (european-calendar-style t))
4846 (diary-anniversary day month year mark))))
4847 (defun org-cyclic (N year month day &optional mark)
4848 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
4849 (org-no-warnings
4850 (let ((calendar-date-style 'european) (european-calendar-style t))
4851 (diary-cyclic N day month year mark))))
4852 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
4853 "Like `diary-block', but with fixed (ISO) order of arguments."
4854 (org-no-warnings
4855 (let ((calendar-date-style 'european) (european-calendar-style t))
4856 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
4857 (defun org-date (year month day &optional mark)
4858 "Like `diary-date', but with fixed (ISO) order of arguments."
4859 (org-no-warnings
4860 (let ((calendar-date-style 'european) (european-calendar-style t))
4861 (diary-date day month year mark))))
4862 (defalias 'org-float 'diary-float)
4864 ;; Define the` org-class' function
4865 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
4866 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4867 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4868 is any number of ISO weeks in the block period for which the item should
4869 be skipped."
4870 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
4871 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
4872 (d (calendar-absolute-from-gregorian date)))
4873 (and
4874 (<= date1 d)
4875 (<= d date2)
4876 (= (calendar-day-of-week date) dayname)
4877 (or (not skip-weeks)
4878 (progn
4879 (require 'cal-iso)
4880 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4881 entry)))
4883 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4884 "Like `org-class', but honor `calendar-date-style'.
4885 The order of the first 2 times 3 arguments depends on the variable
4886 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4887 So for American calendars, give this as MONTH DAY YEAR, for European as
4888 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4889 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4890 is any number of ISO weeks in the block period for which the item should
4891 be skipped.
4893 This function is here only for backward compatibility and it is deprecated,
4894 please use `org-class' instead."
4895 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
4896 (date2 (org-order-calendar-date-args m2 d2 y2)))
4897 (org-class
4898 (nth 2 date1) (car date1) (nth 1 date1)
4899 (nth 2 date2) (car date2) (nth 1 date2)
4900 dayname skip-weeks)))
4902 (defalias 'org-get-closed 'org-agenda-get-progress)
4903 (defun org-agenda-get-progress ()
4904 "Return the logged TODO entries for agenda display."
4905 (let* ((props (list 'mouse-face 'highlight
4906 'org-not-done-regexp org-not-done-regexp
4907 'org-todo-regexp org-todo-regexp
4908 'org-complex-heading-regexp org-complex-heading-regexp
4909 'help-echo
4910 (format "mouse-2 or RET jump to org file %s"
4911 (abbreviate-file-name buffer-file-name))))
4912 (items (if (consp org-agenda-show-log)
4913 org-agenda-show-log
4914 (if (eq org-agenda-show-log 'clockcheck)
4915 '(clock)
4916 org-agenda-log-mode-items)))
4917 (parts
4918 (delq nil
4919 (list
4920 (if (memq 'closed items) (concat "\\<" org-closed-string))
4921 (if (memq 'clock items) (concat "\\<" org-clock-string))
4922 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4923 (parts-re (if parts (mapconcat 'identity parts "\\|")
4924 (error "`org-agenda-log-mode-items' is empty")))
4925 (regexp (concat
4926 "\\(" parts-re "\\)"
4927 " *\\["
4928 (regexp-quote
4929 (substring
4930 (format-time-string
4931 (car org-time-stamp-formats)
4932 (apply 'encode-time ; DATE bound by calendar
4933 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4934 1 11))))
4935 (org-agenda-search-headline-for-time nil)
4936 marker hdmarker priority category tags closedp statep clockp state
4937 ee txt extra timestr rest clocked)
4938 (goto-char (point-min))
4939 (while (re-search-forward regexp nil t)
4940 (catch :skip
4941 (org-agenda-skip)
4942 (setq marker (org-agenda-new-marker (match-beginning 0))
4943 closedp (equal (match-string 1) org-closed-string)
4944 statep (equal (string-to-char (match-string 1)) ?-)
4945 clockp (not (or closedp statep))
4946 state (and statep (match-string 2))
4947 category (org-get-category (match-beginning 0))
4948 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4950 (when (string-match "\\]" timestr)
4951 ;; substring should only run to end of time stamp
4952 (setq rest (substring timestr (match-end 0))
4953 timestr (substring timestr 0 (match-end 0)))
4954 (if (and (not closedp) (not statep)
4955 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4956 (progn (setq timestr (concat (substring timestr 0 -1)
4957 "-" (match-string 1 rest) "]"))
4958 (setq clocked (match-string 2 rest)))
4959 (setq clocked "-")))
4960 (save-excursion
4961 (setq extra
4962 (cond
4963 ((not org-agenda-log-mode-add-notes) nil)
4964 (statep
4965 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4966 (match-string 1)))
4967 (clockp
4968 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4969 (match-string 1)))))
4970 (if (not (re-search-backward "^\\*+ " nil t))
4971 (setq txt org-agenda-no-heading-message)
4972 (goto-char (match-beginning 0))
4973 (setq hdmarker (org-agenda-new-marker)
4974 tags (org-get-tags-at))
4975 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4976 (setq txt (match-string 1))
4977 (when extra
4978 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4979 (setq txt (concat (substring txt 0 (match-beginning 1))
4980 " - " extra " " (match-string 2 txt)))
4981 (setq txt (concat txt " - " extra))))
4982 (setq txt (org-format-agenda-item
4983 (cond
4984 (closedp "Closed: ")
4985 (statep (concat "State: (" state ")"))
4986 (t (concat "Clocked: (" clocked ")")))
4987 txt category tags timestr)))
4988 (setq priority 100000)
4989 (org-add-props txt props
4990 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4991 'priority priority 'org-category category
4992 'type "closed" 'date date
4993 'undone-face 'org-warning 'done-face 'org-agenda-done)
4994 (push txt ee))
4995 (goto-char (point-at-eol))))
4996 (nreverse ee)))
4998 (defun org-agenda-show-clocking-issues ()
4999 "Add overlays, showing issues with clocking.
5000 See also the user option `org-agenda-clock-consistency-checks'."
5001 (interactive)
5002 (let* ((pl org-agenda-clock-consistency-checks)
5003 (re (concat "^[ \t]*"
5004 org-clock-string
5005 "[ \t]+"
5006 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5007 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5008 (tlstart 0.)
5009 (tlend 0.)
5010 (maxtime (org-hh:mm-string-to-minutes
5011 (or (plist-get pl :max-duration) "24:00")))
5012 (mintime (org-hh:mm-string-to-minutes
5013 (or (plist-get pl :min-duration) 0)))
5014 (maxgap (org-hh:mm-string-to-minutes
5015 ;; default 30:00 means never complain
5016 (or (plist-get pl :max-gap) "30:00")))
5017 (gapok (mapcar 'org-hh:mm-string-to-minutes
5018 (plist-get pl :gap-ok-around)))
5019 (def-face (or (plist-get pl :default-face)
5020 '((:background "DarkRed") (:foreground "white"))))
5021 issue face m te ts dt ov)
5022 (goto-char (point-min))
5023 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5024 (setq issue nil face def-face)
5025 (catch 'next
5026 (setq m (org-get-at-bol 'org-marker)
5027 te nil ts nil)
5028 (unless (and m (markerp m))
5029 (setq issue "No valid clock line") (throw 'next t))
5030 (org-with-point-at m
5031 (save-excursion
5032 (goto-char (point-at-bol))
5033 (unless (looking-at re)
5034 (error "No valid Clock line")
5035 (throw 'next t))
5036 (unless (match-end 3)
5037 (setq issue "No end time"
5038 face (or (plist-get pl :no-end-time-face) face))
5039 (throw 'next t))
5040 (setq ts (match-string 1)
5041 te (match-string 3)
5042 ts (org-float-time
5043 (apply 'encode-time (org-parse-time-string ts)))
5044 te (org-float-time
5045 (apply 'encode-time (org-parse-time-string te)))
5046 dt (- te ts))))
5047 (cond
5048 ((> dt (* 60 maxtime))
5049 ;; a very long clocking chunk
5050 (setq issue (format "Clocking interval is very long: %s"
5051 (org-minutes-to-hh:mm-string
5052 (floor (/ (float dt) 60.))))
5053 face (or (plist-get pl :long-face) face)))
5054 ((< dt (* 60 mintime))
5055 ;; a very short clocking chunk
5056 (setq issue (format "Clocking interval is very short: %s"
5057 (org-minutes-to-hh:mm-string
5058 (floor (/ (float dt) 60.))))
5059 face (or (plist-get pl :short-face) face)))
5060 ((and (> tlend 0) (< ts tlend))
5061 ;; Two clock entries are overlapping
5062 (setq issue (format "Clocking overlap: %d minutes"
5063 (/ (- tlend ts) 60))
5064 face (or (plist-get pl :overlap-face) face)))
5065 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5066 ;; There is a gap, lets see if we need to report it
5067 (unless (org-agenda-check-clock-gap tlend ts gapok)
5068 (setq issue (format "Clocking gap: %d minutes"
5069 (/ (- ts tlend) 60))
5070 face (or (plist-get pl :gap-face) face))))
5071 (t nil)))
5072 (setq tlend (or te tlend) tlstart (or ts tlstart))
5073 (when issue
5074 ;; OK, there was some issue, add an overlay to show the issue
5075 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5076 (overlay-put ov 'before-string
5077 (concat
5078 (org-add-props
5079 (format "%-43s" (concat " " issue))
5081 'face face)
5082 "\n"))
5083 (overlay-put ov 'evaporate t)))))
5085 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5086 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5087 (catch 'exit
5088 (unless ok-list
5089 ;; there are no OK times for gaps...
5090 (throw 'exit nil))
5091 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5092 ;; This is more than 24 hours, so it is OK.
5093 ;; because we have at least one OK time, that must be in the
5094 ;; 24 hour interval.
5095 (throw 'exit t))
5096 ;; We have a shorter gap.
5097 ;; Now we have to get the minute of the day when these times are
5098 (let* ((t1dec (decode-time (seconds-to-time t1)))
5099 (t2dec (decode-time (seconds-to-time t2)))
5100 ;; compute the minute on the day
5101 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5102 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5103 (when (< min2 min1)
5104 ;; if min2 is smaller than min1, this means it is on the next day.
5105 ;; Wrap it to after midnight.
5106 (setq min2 (+ min2 1440)))
5107 ;; Now check if any of the OK times is in the gap
5108 (mapc (lambda (x)
5109 ;; Wrap the time to after midnight if necessary
5110 (if (< x min1) (setq x (+ x 1440)))
5111 ;; Check if in interval
5112 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5113 ok-list)
5114 ;; Nope, this gap is not OK
5115 nil)))
5117 (defun org-agenda-get-deadlines ()
5118 "Return the deadline information for agenda display."
5119 (let* ((props (list 'mouse-face 'highlight
5120 'org-not-done-regexp org-not-done-regexp
5121 'org-todo-regexp org-todo-regexp
5122 'org-complex-heading-regexp org-complex-heading-regexp
5123 'help-echo
5124 (format "mouse-2 or RET jump to org file %s"
5125 (abbreviate-file-name buffer-file-name))))
5126 (regexp org-deadline-time-regexp)
5127 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5128 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5129 d2 diff dfrac wdays pos pos1 category tags
5130 suppress-prewarning
5131 ee txt head face s todo-state show-all upcomingp donep timestr)
5132 (goto-char (point-min))
5133 (while (re-search-forward regexp nil t)
5134 (setq suppress-prewarning nil)
5135 (catch :skip
5136 (org-agenda-skip)
5137 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5138 (save-match-data
5139 (string-match org-scheduled-time-regexp
5140 (buffer-substring (point-at-bol)
5141 (point-at-eol)))))
5142 (setq suppress-prewarning
5143 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5144 org-agenda-skip-deadline-prewarning-if-scheduled
5145 0)))
5146 (setq s (match-string 1)
5147 txt nil
5148 pos (1- (match-beginning 1))
5149 todo-state (save-match-data (org-get-todo-state))
5150 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5151 (member todo-state
5152 org-agenda-repeating-timestamp-show-all))
5153 d2 (org-time-string-to-absolute
5154 (match-string 1) d1 'past show-all)
5155 diff (- d2 d1)
5156 wdays (if suppress-prewarning
5157 (let ((org-deadline-warning-days suppress-prewarning))
5158 (org-get-wdays s))
5159 (org-get-wdays s))
5160 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
5161 upcomingp (and todayp (> diff 0)))
5162 ;; When to show a deadline in the calendar:
5163 ;; If the expiration is within wdays warning time.
5164 ;; Past-due deadlines are only shown on the current date
5165 (if (and (or (and (<= diff wdays)
5166 (and todayp (not org-agenda-only-exact-dates)))
5167 (= diff 0)))
5168 (save-excursion
5169 ;; (setq todo-state (org-get-todo-state))
5170 (setq donep (member todo-state org-done-keywords))
5171 (if (and donep
5172 (or org-agenda-skip-deadline-if-done
5173 (not (= diff 0))))
5174 (setq txt nil)
5175 (setq category (org-get-category))
5176 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5177 (setq txt org-agenda-no-heading-message)
5178 (goto-char (match-end 0))
5179 (setq pos1 (match-beginning 0))
5180 (setq tags (org-get-tags-at pos1))
5181 (setq head (buffer-substring-no-properties
5182 (point)
5183 (progn (skip-chars-forward "^\r\n")
5184 (point))))
5185 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5186 (setq timestr
5187 (concat (substring s (match-beginning 1)) " "))
5188 (setq timestr 'time))
5189 (setq txt (org-format-agenda-item
5190 (if (= diff 0)
5191 (car org-agenda-deadline-leaders)
5192 (if (functionp
5193 (nth 1 org-agenda-deadline-leaders))
5194 (funcall
5195 (nth 1 org-agenda-deadline-leaders)
5196 diff date)
5197 (format (nth 1 org-agenda-deadline-leaders)
5198 diff)))
5199 head category tags
5200 (if (not (= diff 0)) nil timestr)))))
5201 (when txt
5202 (setq face (org-agenda-deadline-face dfrac wdays))
5203 (org-add-props txt props
5204 'org-marker (org-agenda-new-marker pos)
5205 'org-hd-marker (org-agenda-new-marker pos1)
5206 'priority (+ (- diff)
5207 (org-get-priority txt))
5208 'org-category category
5209 'todo-state todo-state
5210 'type (if upcomingp "upcoming-deadline" "deadline")
5211 'date (if upcomingp date d2)
5212 'face (if donep 'org-agenda-done face)
5213 'undone-face face 'done-face 'org-agenda-done)
5214 (push txt ee))))))
5215 (nreverse ee)))
5217 (defun org-agenda-deadline-face (fraction &optional wdays)
5218 "Return the face to displaying a deadline item.
5219 FRACTION is what fraction of the head-warning time has passed."
5220 (if (equal wdays 0) (setq fraction 1.))
5221 (let ((faces org-agenda-deadline-faces) f)
5222 (catch 'exit
5223 (while (setq f (pop faces))
5224 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5226 (defun org-agenda-get-scheduled (&optional deadline-results)
5227 "Return the scheduled information for agenda display."
5228 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5229 'org-todo-regexp org-todo-regexp
5230 'org-complex-heading-regexp org-complex-heading-regexp
5231 'done-face 'org-agenda-done
5232 'mouse-face 'highlight
5233 'help-echo
5234 (format "mouse-2 or RET jump to org file %s"
5235 (abbreviate-file-name buffer-file-name))))
5236 (regexp org-scheduled-time-regexp)
5237 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5238 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5240 (deadline-position-alist
5241 (mapcar (lambda (a) (and (setq mm (get-text-property
5242 0 'org-hd-marker a))
5243 (cons (marker-position mm) a)))
5244 deadline-results))
5245 d2 diff pos pos1 category tags donep
5246 ee txt head pastschedp todo-state face timestr s habitp show-all)
5247 (goto-char (point-min))
5248 (while (re-search-forward regexp nil t)
5249 (catch :skip
5250 (org-agenda-skip)
5251 (setq s (match-string 1)
5252 txt nil
5253 pos (1- (match-beginning 1))
5254 todo-state (save-match-data (org-get-todo-state))
5255 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5256 (member todo-state
5257 org-agenda-repeating-timestamp-show-all))
5258 d2 (org-time-string-to-absolute
5259 (match-string 1) d1 'past show-all)
5260 diff (- d2 d1))
5261 (setq pastschedp (and todayp (< diff 0)))
5262 ;; When to show a scheduled item in the calendar:
5263 ;; If it is on or past the date.
5264 (when (or (and (< diff 0)
5265 (< (abs diff) org-scheduled-past-days)
5266 (and todayp (not org-agenda-only-exact-dates)))
5267 (= diff 0))
5268 (save-excursion
5269 (setq donep (member todo-state org-done-keywords))
5270 (if (and donep
5271 (or org-agenda-skip-scheduled-if-done
5272 (not (= diff 0))
5273 (and (functionp 'org-is-habit-p)
5274 (org-is-habit-p))))
5275 (setq txt nil)
5276 (setq habitp (and (functionp 'org-is-habit-p)
5277 (org-is-habit-p)))
5278 (setq category (org-get-category))
5279 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5280 (setq txt org-agenda-no-heading-message)
5281 (goto-char (match-end 0))
5282 (setq pos1 (match-beginning 0))
5283 (if habitp
5284 (if (or (not org-habit-show-habits)
5285 (and (not todayp)
5286 org-habit-show-habits-only-for-today))
5287 (throw :skip nil))
5288 (if (and
5289 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5290 (and org-agenda-skip-scheduled-if-deadline-is-shown
5291 pastschedp))
5292 (setq mm (assoc pos1 deadline-position-alist)))
5293 (throw :skip nil)))
5294 (setq tags (org-get-tags-at))
5295 (setq head (buffer-substring-no-properties
5296 (point)
5297 (progn (skip-chars-forward "^\r\n") (point))))
5298 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5299 (setq timestr
5300 (concat (substring s (match-beginning 1)) " "))
5301 (setq timestr 'time))
5302 (setq txt (org-format-agenda-item
5303 (if (= diff 0)
5304 (car org-agenda-scheduled-leaders)
5305 (format (nth 1 org-agenda-scheduled-leaders)
5306 (- 1 diff)))
5307 head category tags
5308 (if (not (= diff 0)) nil timestr)
5309 nil habitp))))
5310 (when txt
5311 (setq face
5312 (cond
5313 ((and (not habitp) pastschedp)
5314 'org-scheduled-previously)
5315 (todayp 'org-scheduled-today)
5316 (t 'org-scheduled))
5317 habitp (and habitp (org-habit-parse-todo)))
5318 (org-add-props txt props
5319 'undone-face face
5320 'face (if donep 'org-agenda-done face)
5321 'org-marker (org-agenda-new-marker pos)
5322 'org-hd-marker (org-agenda-new-marker pos1)
5323 'type (if pastschedp "past-scheduled" "scheduled")
5324 'date (if pastschedp d2 date)
5325 'priority (if habitp
5326 (org-habit-get-priority habitp)
5327 (+ 94 (- 5 diff) (org-get-priority txt)))
5328 'org-category category
5329 'org-habit-p habitp
5330 'todo-state todo-state)
5331 (push txt ee))))))
5332 (nreverse ee)))
5334 (defun org-agenda-get-blocks ()
5335 "Return the date-range information for agenda display."
5336 (let* ((props (list 'face nil
5337 'org-not-done-regexp org-not-done-regexp
5338 'org-todo-regexp org-todo-regexp
5339 'org-complex-heading-regexp org-complex-heading-regexp
5340 'mouse-face 'highlight
5341 'help-echo
5342 (format "mouse-2 or RET jump to org file %s"
5343 (abbreviate-file-name buffer-file-name))))
5344 (regexp org-tr-regexp)
5345 (d0 (calendar-absolute-from-gregorian date))
5346 marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
5347 head donep)
5348 (goto-char (point-min))
5349 (while (re-search-forward regexp nil t)
5350 (catch :skip
5351 (org-agenda-skip)
5352 (setq pos (point))
5353 (let ((start-time (match-string 1))
5354 (end-time (match-string 2)))
5355 (setq s1 (match-string 1)
5356 s2 (match-string 2)
5357 d1 (time-to-days (org-time-string-to-time s1))
5358 d2 (time-to-days (org-time-string-to-time s2)))
5359 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5360 ;; Only allow days between the limits, because the normal
5361 ;; date stamps will catch the limits.
5362 (save-excursion
5363 (setq todo-state (org-get-todo-state))
5364 (setq donep (member todo-state org-done-keywords))
5365 (if (and donep org-agenda-skip-timestamp-if-done)
5366 (throw :skip t))
5367 (setq marker (org-agenda-new-marker (point)))
5368 (setq category (org-get-category))
5369 (if (not (re-search-backward "^\\*+ " nil t))
5370 (setq txt org-agenda-no-heading-message)
5371 (goto-char (match-beginning 0))
5372 (setq hdmarker (org-agenda-new-marker (point)))
5373 (setq tags (org-get-tags-at))
5374 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5375 (setq head (match-string 1))
5376 (let ((remove-re
5377 (if org-agenda-remove-timeranges-from-blocks
5378 (concat
5379 "<" (regexp-quote s1) ".*?>"
5380 "--"
5381 "<" (regexp-quote s2) ".*?>")
5382 nil)))
5383 (setq txt (org-format-agenda-item
5384 (format
5385 (nth (if (= d1 d2) 0 1)
5386 org-agenda-timerange-leaders)
5387 (1+ (- d0 d1)) (1+ (- d2 d1)))
5388 head category tags
5389 (cond ((= d1 d0)
5390 (concat "<" start-time ">"))
5391 ((= d2 d0)
5392 (concat "<" end-time ">"))
5393 (t nil))
5394 remove-re))))
5395 (org-add-props txt props
5396 'org-marker marker 'org-hd-marker hdmarker
5397 'type "block" 'date date
5398 'todo-state todo-state
5399 'priority (org-get-priority txt) 'org-category category)
5400 (push txt ee))))
5401 (goto-char pos)))
5402 ;; Sort the entries by expiration date.
5403 (nreverse ee)))
5405 ;;; Agenda presentation and sorting
5407 (defvar org-prefix-has-time nil
5408 "A flag, set by `org-compile-prefix-format'.
5409 The flag is set if the currently compiled format contains a `%t'.")
5410 (defvar org-prefix-has-tag nil
5411 "A flag, set by `org-compile-prefix-format'.
5412 The flag is set if the currently compiled format contains a `%T'.")
5413 (defvar org-prefix-has-effort nil
5414 "A flag, set by `org-compile-prefix-format'.
5415 The flag is set if the currently compiled format contains a `%e'.")
5416 (defvar org-prefix-category-length nil
5417 "Used by `org-compile-prefix-format' to remember the category field width.")
5418 (defvar org-prefix-category-max-length nil
5419 "Used by `org-compile-prefix-format' to remember the category field width.")
5421 (defun org-agenda-get-category-icon (category)
5422 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5423 (dolist (entry org-agenda-category-icon-alist)
5424 (when (org-string-match-p (car entry) category)
5425 (if (listp (cadr entry))
5426 (return (cadr entry))
5427 (return (apply 'create-image (cdr entry)))))))
5429 (defun org-format-agenda-item (extra txt &optional category tags dotime
5430 remove-re habitp)
5431 "Format TXT to be inserted into the agenda buffer.
5432 In particular, it adds the prefix and corresponding text properties. EXTRA
5433 must be a string and replaces the `%s' specifier in the prefix format.
5434 CATEGORY (string, symbol or nil) may be used to overrule the default
5435 category taken from local variable or file name. It will replace the `%c'
5436 specifier in the format. DOTIME, when non-nil, indicates that a
5437 time-of-day should be extracted from TXT for sorting of this entry, and for
5438 the `%t' specifier in the format. When DOTIME is a string, this string is
5439 searched for a time before TXT is. TAGS can be the tags of the headline.
5440 Any match of REMOVE-RE will be removed from TXT."
5441 (save-match-data
5442 ;; Diary entries sometimes have extra whitespace at the beginning
5443 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5445 ;; Fix the tags part in txt
5446 (setq txt (org-agenda-fix-displayed-tags
5447 txt tags
5448 org-agenda-show-inherited-tags
5449 org-agenda-hide-tags-regexp))
5450 (let* ((category (or category
5451 (if (stringp org-category)
5452 org-category
5453 (and org-category (symbol-name org-category)))
5454 (if buffer-file-name
5455 (file-name-sans-extension
5456 (file-name-nondirectory buffer-file-name))
5457 "")))
5458 (category-icon (org-agenda-get-category-icon category))
5459 (category-icon (if category-icon
5460 (propertize " " 'display category-icon)
5461 ""))
5462 ;; time, tag, effort are needed for the eval of the prefix format
5463 (tag (if tags (nth (1- (length tags)) tags) ""))
5464 time effort neffort
5465 (ts (if dotime (concat
5466 (if (stringp dotime) dotime "")
5467 (and org-agenda-search-headline-for-time txt))))
5468 (time-of-day (and dotime (org-get-time-of-day ts)))
5469 stamp plain s0 s1 s2 rtn srp l
5470 duration thecategory)
5471 (and (org-mode-p) buffer-file-name
5472 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5473 (when (and dotime time-of-day)
5474 ;; Extract starting and ending time and move them to prefix
5475 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5476 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5477 (setq s0 (match-string 0 ts)
5478 srp (and stamp (match-end 3))
5479 s1 (match-string (if plain 1 2) ts)
5480 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5482 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5483 ;; them, we might want to remove them there to avoid duplication.
5484 ;; The user can turn this off with a variable.
5485 (if (and org-prefix-has-time
5486 org-agenda-remove-times-when-in-prefix (or stamp plain)
5487 (string-match (concat (regexp-quote s0) " *") txt)
5488 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5489 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5490 (= (match-beginning 0) 0)
5492 (setq txt (replace-match "" nil nil txt))))
5493 ;; Normalize the time(s) to 24 hour
5494 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5495 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5497 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5498 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5499 (setq s2
5500 (org-minutes-to-hh:mm-string
5501 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5503 ;; Compute the duration
5504 (when s2
5505 (setq duration (- (org-hh:mm-string-to-minutes s2)
5506 (org-hh:mm-string-to-minutes s1)))))
5508 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5509 txt)
5510 ;; Tags are in the string
5511 (if (or (eq org-agenda-remove-tags t)
5512 (and org-agenda-remove-tags
5513 org-prefix-has-tag))
5514 (setq txt (replace-match "" t t txt))
5515 (setq txt (replace-match
5516 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5517 (match-string 2 txt))
5518 t t txt))))
5519 (when (org-mode-p)
5520 (setq effort
5521 (condition-case nil
5522 (org-get-effort
5523 (or (get-text-property 0 'org-hd-marker txt)
5524 (get-text-property 0 'org-marker txt)))
5525 (error nil)))
5526 (when effort
5527 (setq neffort (org-duration-string-to-minutes effort)
5528 effort (setq effort (concat "[" effort "]" )))))
5530 (when remove-re
5531 (while (string-match remove-re txt)
5532 (setq txt (replace-match "" t t txt))))
5534 ;; Set org-heading property on `txt' to mark the start of the
5535 ;; heading.
5536 (add-text-properties 0 (length txt) '(org-heading t) txt)
5538 ;; Prepare the variables needed in the eval of the compiled format
5539 (setq time (cond (s2 (concat
5540 (org-agenda-time-of-day-to-ampm-maybe s1)
5541 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5542 (if org-agenda-timegrid-use-ampm " ")))
5543 (s1 (concat
5544 (org-agenda-time-of-day-to-ampm-maybe s1)
5545 (if org-agenda-timegrid-use-ampm
5546 "........ "
5547 "......")))
5548 (t ""))
5549 extra (or (and (not habitp) extra) "")
5550 category (if (symbolp category) (symbol-name category) category)
5551 thecategory (copy-sequence category))
5552 (if (string-match org-bracket-link-regexp category)
5553 (progn
5554 (setq l (if (match-end 3)
5555 (- (match-end 3) (match-beginning 3))
5556 (- (match-end 1) (match-beginning 1))))
5557 (when (< l (or org-prefix-category-length 0))
5558 (setq category (copy-sequence category))
5559 (org-add-props category nil
5560 'extra-space (make-string
5561 (- org-prefix-category-length l 1) ?\ ))))
5562 (if (and org-prefix-category-max-length
5563 (>= (length category) org-prefix-category-max-length))
5564 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5565 ;; Evaluate the compiled format
5566 (setq rtn (concat (eval org-prefix-format-compiled) txt))
5568 ;; And finally add the text properties
5569 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5570 (org-add-props rtn nil
5571 'org-category (if thecategory (downcase thecategory) category)
5572 'tags (mapcar 'org-downcase-keep-props tags)
5573 'org-highest-priority org-highest-priority
5574 'org-lowest-priority org-lowest-priority
5575 'time-of-day time-of-day
5576 'duration duration
5577 'effort effort
5578 'effort-minutes neffort
5579 'txt txt
5580 'time time
5581 'extra extra
5582 'dotime dotime))))
5584 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5585 "Remove tags string from TXT, and add a modified list of tags.
5586 The modified list may contain inherited tags, and tags matched by
5587 `org-agenda-hide-tags-regexp' will be removed."
5588 (when (or add-inherited hide-re)
5589 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5590 (setq txt (substring txt 0 (match-beginning 0))))
5591 (setq tags
5592 (delq nil
5593 (mapcar (lambda (tg)
5594 (if (or (and hide-re (string-match hide-re tg))
5595 (and (not add-inherited)
5596 (get-text-property 0 'inherited tg)))
5598 tg))
5599 tags)))
5600 (when tags
5601 (let ((have-i (get-text-property 0 'inherited (car tags)))
5603 (setq txt (concat txt " :"
5604 (mapconcat
5605 (lambda (x)
5606 (setq i (get-text-property 0 'inherited x))
5607 (if (and have-i (not i))
5608 (progn
5609 (setq have-i nil)
5610 (concat ":" x))
5612 tags ":")
5613 (if have-i "::" ":"))))))
5614 txt)
5616 (defun org-downcase-keep-props (s)
5617 (let ((props (text-properties-at 0 s)))
5618 (setq s (downcase s))
5619 (add-text-properties 0 (length s) props s)
5622 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5623 (defvar org-agenda-sorting-strategy-selected nil)
5625 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5626 (catch 'exit
5627 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5628 ((and todayp (member 'today (car org-agenda-time-grid))))
5629 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5630 ((member 'weekly (car org-agenda-time-grid)))
5631 (t (throw 'exit list)))
5632 (let* ((have (delq nil (mapcar
5633 (lambda (x) (get-text-property 1 'time-of-day x))
5634 list)))
5635 (string (nth 1 org-agenda-time-grid))
5636 (gridtimes (nth 2 org-agenda-time-grid))
5637 (req (car org-agenda-time-grid))
5638 (remove (member 'remove-match req))
5639 new time)
5640 (if (and (member 'require-timed req) (not have))
5641 ;; don't show empty grid
5642 (throw 'exit list))
5643 (while (setq time (pop gridtimes))
5644 (unless (and remove (member time have))
5645 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5646 (push (org-format-agenda-item
5647 nil string "" nil
5648 (concat (substring time 0 -2) ":" (substring time -2)))
5649 new)
5650 (put-text-property
5651 2 (length (car new)) 'face 'org-time-grid (car new))))
5652 (when (and todayp org-agenda-show-current-time-in-grid)
5653 (push (org-format-agenda-item
5655 org-agenda-current-time-string
5656 "" nil
5657 (format-time-string "%H:%M "))
5658 new)
5659 (put-text-property
5660 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5662 (if (member 'time-up org-agenda-sorting-strategy-selected)
5663 (append new list)
5664 (append list new)))))
5666 (defun org-compile-prefix-format (key)
5667 "Compile the prefix format into a Lisp form that can be evaluated.
5668 The resulting form is returned and stored in the variable
5669 `org-prefix-format-compiled'."
5670 (setq org-prefix-has-time nil org-prefix-has-tag nil
5671 org-prefix-category-length nil org-prefix-has-effort nil)
5672 (let ((s (cond
5673 ((stringp org-agenda-prefix-format)
5674 org-agenda-prefix-format)
5675 ((assq key org-agenda-prefix-format)
5676 (cdr (assq key org-agenda-prefix-format)))
5677 (t " %-12:c%?-12t% s")))
5678 (start 0)
5679 varform vars var e c f opt)
5680 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5681 s start)
5682 (setq var (or (cdr (assoc (match-string 4 s)
5683 '(("c" . category) ("t" . time) ("s" . extra)
5684 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5685 'eval)
5686 c (or (match-string 3 s) "")
5687 opt (match-beginning 1)
5688 start (1+ (match-beginning 0)))
5689 (if (equal var 'time) (setq org-prefix-has-time t))
5690 (if (equal var 'tag) (setq org-prefix-has-tag t))
5691 (if (equal var 'effort) (setq org-prefix-has-effort t))
5692 (setq f (concat "%" (match-string 2 s) "s"))
5693 (when (equal var 'category)
5694 (setq org-prefix-category-length
5695 (floor (abs (string-to-number (match-string 2 s)))))
5696 (setq org-prefix-category-max-length
5697 (let ((x (match-string 2 s)))
5698 (save-match-data
5699 (if (string-match "\\.[0-9]+" x)
5700 (string-to-number (substring (match-string 0 x) 1)))))))
5701 (if (eq var 'eval)
5702 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5703 (if opt
5704 (setq varform
5705 `(if (equal "" ,var)
5707 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5708 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5709 (setq s (replace-match "%s" t nil s))
5710 (push varform vars))
5711 (setq vars (nreverse vars))
5712 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5714 (defun org-set-sorting-strategy (key)
5715 (if (symbolp (car org-agenda-sorting-strategy))
5716 ;; the old format
5717 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5718 (setq org-agenda-sorting-strategy-selected
5719 (or (cdr (assq key org-agenda-sorting-strategy))
5720 (cdr (assq 'agenda org-agenda-sorting-strategy))
5721 '(time-up category-keep priority-down)))))
5723 (defun org-get-time-of-day (s &optional string mod24)
5724 "Check string S for a time of day.
5725 If found, return it as a military time number between 0 and 2400.
5726 If not found, return nil.
5727 The optional STRING argument forces conversion into a 5 character wide string
5728 HH:MM."
5729 (save-match-data
5730 (when
5731 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5732 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5733 (let* ((h (string-to-number (match-string 1 s)))
5734 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5735 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5736 (am-p (equal ampm "am"))
5737 (h1 (cond ((not ampm) h)
5738 ((= h 12) (if am-p 0 12))
5739 (t (+ h (if am-p 0 12)))))
5740 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5741 (mod h1 24) h1))
5742 (t0 (+ (* 100 h2) m))
5743 (t1 (concat (if (>= h1 24) "+" " ")
5744 (if (and org-agenda-time-leading-zero
5745 (< t0 1000)) "0" "")
5746 (if (< t0 100) "0" "")
5747 (if (< t0 10) "0" "")
5748 (int-to-string t0))))
5749 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5751 (defvar org-agenda-before-sorting-filter-function nil
5752 "Function to be applied to agenda items prior to sorting.
5753 Prior to sorting also means just before they are inserted into the agenda.
5755 To aid sorting, you may revisit the original entries and add more text
5756 properties which will later be used by the sorting functions.
5758 The function should take a string argument, an agenda line.
5759 It has access to the text properties in that line, which contain among
5760 other things, the property `org-hd-marker' that points to the entry
5761 where the line comes from. Note that not all lines going into the agenda
5762 have this property, only most.
5764 The function should return the modified string. It is probably best
5765 to ONLY change text properties.
5767 You can also use this function as a filter, by returning nil for lines
5768 you don't want to have in the agenda at all. For this application, you
5769 could bind the variable in the options section of a custom command.")
5771 (defun org-finalize-agenda-entries (list &optional nosort)
5772 "Sort and concatenate the agenda items."
5773 (setq list (mapcar 'org-agenda-highlight-todo list))
5774 (if nosort
5775 list
5776 (when org-agenda-before-sorting-filter-function
5777 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5778 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5780 (defun org-agenda-highlight-todo (x)
5781 (let ((org-done-keywords org-done-keywords-for-agenda)
5782 (case-fold-search nil)
5784 (if (eq x 'line)
5785 (save-excursion
5786 (beginning-of-line 1)
5787 (setq re (org-get-at-bol 'org-todo-regexp))
5788 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
5789 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5790 (add-text-properties (match-beginning 0) (match-end 1)
5791 (list 'face (org-get-todo-face 1)))
5792 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5793 (delete-region (match-beginning 1) (1- (match-end 0)))
5794 (goto-char (match-beginning 1))
5795 (insert (format org-agenda-todo-keyword-format s)))))
5796 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
5797 (setq re (get-text-property 0 'org-todo-regexp x))
5798 (when (and re
5799 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5800 x (or pl 0)) pl))
5801 (add-text-properties
5802 (or (match-end 1) (match-end 0)) (match-end 0)
5803 (list 'face (org-get-todo-face (match-string 2 x)))
5805 (when (match-end 1)
5806 (setq x (concat (substring x 0 (match-end 1))
5807 (format org-agenda-todo-keyword-format
5808 (match-string 2 x))
5809 (org-add-props " " (text-properties-at 0 x))
5810 (substring x (match-end 3)))))))
5811 x)))
5813 (defsubst org-cmp-priority (a b)
5814 "Compare the priorities of string A and B."
5815 (let ((pa (or (get-text-property 1 'priority a) 0))
5816 (pb (or (get-text-property 1 'priority b) 0)))
5817 (cond ((> pa pb) +1)
5818 ((< pa pb) -1)
5819 (t nil))))
5821 (defsubst org-cmp-effort (a b)
5822 "Compare the priorities of string A and B."
5823 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5824 (ea (or (get-text-property 1 'effort-minutes a) def))
5825 (eb (or (get-text-property 1 'effort-minutes b) def)))
5826 (cond ((> ea eb) +1)
5827 ((< ea eb) -1)
5828 (t nil))))
5830 (defsubst org-cmp-category (a b)
5831 "Compare the string values of categories of strings A and B."
5832 (let ((ca (or (get-text-property 1 'org-category a) ""))
5833 (cb (or (get-text-property 1 'org-category b) "")))
5834 (cond ((string-lessp ca cb) -1)
5835 ((string-lessp cb ca) +1)
5836 (t nil))))
5838 (defsubst org-cmp-todo-state (a b)
5839 "Compare the todo states of strings A and B."
5840 (let* ((ma (or (get-text-property 1 'org-marker a)
5841 (get-text-property 1 'org-hd-marker a)))
5842 (mb (or (get-text-property 1 'org-marker b)
5843 (get-text-property 1 'org-hd-marker b)))
5844 (fa (and ma (marker-buffer ma)))
5845 (fb (and mb (marker-buffer mb)))
5846 (todo-kwds
5847 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5848 (and fb (with-current-buffer fb org-todo-keywords-1))))
5849 (ta (or (get-text-property 1 'todo-state a) ""))
5850 (tb (or (get-text-property 1 'todo-state b) ""))
5851 (la (- (length (member ta todo-kwds))))
5852 (lb (- (length (member tb todo-kwds))))
5853 (donepa (member ta org-done-keywords-for-agenda))
5854 (donepb (member tb org-done-keywords-for-agenda)))
5855 (cond ((and donepa (not donepb)) -1)
5856 ((and (not donepa) donepb) +1)
5857 ((< la lb) -1)
5858 ((< lb la) +1)
5859 (t nil))))
5861 (defsubst org-cmp-alpha (a b)
5862 "Compare the headlines, alphabetically."
5863 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
5864 (plb (text-property-any 0 (length b) 'org-heading t b))
5865 (ta (and pla (substring a pla)))
5866 (tb (and plb (substring b plb))))
5867 (when pla
5868 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5869 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5870 (setq ta (substring ta (match-end 0))))
5871 (setq ta (downcase ta)))
5872 (when plb
5873 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5874 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5875 (setq tb (substring tb (match-end 0))))
5876 (setq tb (downcase tb)))
5877 (cond ((not ta) +1)
5878 ((not tb) -1)
5879 ((string-lessp ta tb) -1)
5880 ((string-lessp tb ta) +1)
5881 (t nil))))
5883 (defsubst org-cmp-tag (a b)
5884 "Compare the string values of the first tags of A and B."
5885 (let ((ta (car (last (get-text-property 1 'tags a))))
5886 (tb (car (last (get-text-property 1 'tags b)))))
5887 (cond ((not ta) +1)
5888 ((not tb) -1)
5889 ((string-lessp ta tb) -1)
5890 ((string-lessp tb ta) +1)
5891 (t nil))))
5893 (defsubst org-cmp-time (a b)
5894 "Compare the time-of-day values of strings A and B."
5895 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5896 (ta (or (get-text-property 1 'time-of-day a) def))
5897 (tb (or (get-text-property 1 'time-of-day b) def)))
5898 (cond ((< ta tb) -1)
5899 ((< tb ta) +1)
5900 (t nil))))
5902 (defsubst org-cmp-habit-p (a b)
5903 "Compare the todo states of strings A and B."
5904 (let ((ha (get-text-property 1 'org-habit-p a))
5905 (hb (get-text-property 1 'org-habit-p b)))
5906 (cond ((and ha (not hb)) -1)
5907 ((and (not ha) hb) +1)
5908 (t nil))))
5910 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5912 (defun org-entries-lessp (a b)
5913 "Predicate for sorting agenda entries."
5914 ;; The following variables will be used when the form is evaluated.
5915 ;; So even though the compiler complains, keep them.
5916 (let* ((ss org-agenda-sorting-strategy-selected)
5917 (time-up (and (org-em 'time-up 'time-down ss)
5918 (org-cmp-time a b)))
5919 (time-down (if time-up (- time-up) nil))
5920 (priority-up (and (org-em 'priority-up 'priority-down ss)
5921 (org-cmp-priority a b)))
5922 (priority-down (if priority-up (- priority-up) nil))
5923 (effort-up (and (org-em 'effort-up 'effort-down ss)
5924 (org-cmp-effort a b)))
5925 (effort-down (if effort-up (- effort-up) nil))
5926 (category-up (and (or (org-em 'category-up 'category-down ss)
5927 (memq 'category-keep ss))
5928 (org-cmp-category a b)))
5929 (category-down (if category-up (- category-up) nil))
5930 (category-keep (if category-up +1 nil))
5931 (tag-up (and (org-em 'tag-up 'tag-down ss)
5932 (org-cmp-tag a b)))
5933 (tag-down (if tag-up (- tag-up) nil))
5934 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5935 (org-cmp-todo-state a b)))
5936 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5937 (habit-up (and (org-em 'habit-up 'habit-down ss)
5938 (org-cmp-habit-p a b)))
5939 (habit-down (if habit-up (- habit-up) nil))
5940 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5941 (org-cmp-alpha a b)))
5942 (alpha-down (if alpha-up (- alpha-up) nil))
5943 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5944 user-defined-up user-defined-down)
5945 (if (and need-user-cmp org-agenda-cmp-user-defined
5946 (functionp org-agenda-cmp-user-defined))
5947 (setq user-defined-up
5948 (funcall org-agenda-cmp-user-defined a b)
5949 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5950 (cdr (assoc
5951 (eval (cons 'or org-agenda-sorting-strategy-selected))
5952 '((-1 . t) (1 . nil) (nil . nil))))))
5954 ;;; Agenda restriction lock
5956 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5957 "Overlay to mark the headline to which agenda commands are restricted.")
5958 (overlay-put org-agenda-restriction-lock-overlay
5959 'face 'org-agenda-restriction-lock)
5960 (overlay-put org-agenda-restriction-lock-overlay
5961 'help-echo "Agendas are currently limited to this subtree.")
5962 (org-detach-overlay org-agenda-restriction-lock-overlay)
5964 (defun org-agenda-set-restriction-lock (&optional type)
5965 "Set restriction lock for agenda, to current subtree or file.
5966 Restriction will be the file if TYPE is `file', or if type is the
5967 universal prefix '(4), or if the cursor is before the first headline
5968 in the file. Otherwise, restriction will be to the current subtree."
5969 (interactive "P")
5970 (and (equal type '(4)) (setq type 'file))
5971 (setq type (cond
5972 (type type)
5973 ((org-at-heading-p) 'subtree)
5974 ((condition-case nil (org-back-to-heading t) (error nil))
5975 'subtree)
5976 (t 'file)))
5977 (if (eq type 'subtree)
5978 (progn
5979 (setq org-agenda-restrict t)
5980 (setq org-agenda-overriding-restriction 'subtree)
5981 (put 'org-agenda-files 'org-restrict
5982 (list (buffer-file-name (buffer-base-buffer))))
5983 (org-back-to-heading t)
5984 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5985 (move-marker org-agenda-restrict-begin (point))
5986 (move-marker org-agenda-restrict-end
5987 (save-excursion (org-end-of-subtree t)))
5988 (message "Locking agenda restriction to subtree"))
5989 (put 'org-agenda-files 'org-restrict
5990 (list (buffer-file-name (buffer-base-buffer))))
5991 (setq org-agenda-restrict nil)
5992 (setq org-agenda-overriding-restriction 'file)
5993 (move-marker org-agenda-restrict-begin nil)
5994 (move-marker org-agenda-restrict-end nil)
5995 (message "Locking agenda restriction to file"))
5996 (setq current-prefix-arg nil)
5997 (org-agenda-maybe-redo))
5999 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6000 "Remove the agenda restriction lock."
6001 (interactive "P")
6002 (org-detach-overlay org-agenda-restriction-lock-overlay)
6003 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6004 (setq org-agenda-overriding-restriction nil)
6005 (setq org-agenda-restrict nil)
6006 (put 'org-agenda-files 'org-restrict nil)
6007 (move-marker org-agenda-restrict-begin nil)
6008 (move-marker org-agenda-restrict-end nil)
6009 (setq current-prefix-arg nil)
6010 (message "Agenda restriction lock removed")
6011 (or noupdate (org-agenda-maybe-redo)))
6013 (defun org-agenda-maybe-redo ()
6014 "If there is any window showing the agenda view, update it."
6015 (let ((w (get-buffer-window org-agenda-buffer-name t))
6016 (w0 (selected-window)))
6017 (when w
6018 (select-window w)
6019 (org-agenda-redo)
6020 (select-window w0)
6021 (if org-agenda-overriding-restriction
6022 (message "Agenda view shifted to new %s restriction"
6023 org-agenda-overriding-restriction)
6024 (message "Agenda restriction lock removed")))))
6026 ;;; Agenda commands
6028 (defun org-agenda-check-type (error &rest types)
6029 "Check if agenda buffer is of allowed type.
6030 If ERROR is non-nil, throw an error, otherwise just return nil."
6031 (if (memq org-agenda-type types)
6033 (if error
6034 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6035 nil)))
6037 (defun org-agenda-quit ()
6038 "Exit agenda by removing the window or the buffer."
6039 (interactive)
6040 (if org-agenda-columns-active
6041 (org-columns-quit)
6042 (let ((buf (current-buffer)))
6043 (if (eq org-agenda-window-setup 'other-frame)
6044 (progn
6045 (kill-buffer buf)
6046 (org-agenda-reset-markers)
6047 (org-columns-remove-overlays)
6048 (setq org-agenda-archives-mode nil)
6049 (delete-frame))
6050 (and (not (eq org-agenda-window-setup 'current-window))
6051 (not (one-window-p))
6052 (delete-window))
6053 (kill-buffer buf)
6054 (org-agenda-reset-markers)
6055 (org-columns-remove-overlays)
6056 (setq org-agenda-archives-mode nil)))
6057 ;; Maybe restore the pre-agenda window configuration.
6058 (and org-agenda-restore-windows-after-quit
6059 (not (eq org-agenda-window-setup 'other-frame))
6060 org-pre-agenda-window-conf
6061 (set-window-configuration org-pre-agenda-window-conf))))
6063 (defun org-agenda-exit ()
6064 "Exit agenda by removing the window or the buffer.
6065 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6066 Org-mode buffers visited directly by the user will not be touched."
6067 (interactive)
6068 (org-release-buffers org-agenda-new-buffers)
6069 (setq org-agenda-new-buffers nil)
6070 (org-agenda-quit))
6072 (defun org-agenda-execute (arg)
6073 "Execute another agenda command, keeping same window.
6074 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6075 in the agenda."
6076 (interactive "P")
6077 (let ((org-agenda-window-setup 'current-window))
6078 (org-agenda arg)))
6080 (defun org-agenda-redo ()
6081 "Rebuild Agenda.
6082 When this is the global TODO list, a prefix argument will be interpreted."
6083 (interactive)
6084 (let* ((org-agenda-keep-modes t)
6085 (filter org-agenda-filter)
6086 (preset (get 'org-agenda-filter :preset-filter))
6087 (org-agenda-filter-while-redo (or filter preset))
6088 (cols org-agenda-columns-active)
6089 (line (org-current-line))
6090 (window-line (- line (org-current-line (window-start))))
6091 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6092 (put 'org-agenda-filter :preset-filter nil)
6093 (and cols (org-columns-quit))
6094 (message "Rebuilding agenda buffer...")
6095 (org-let lprops '(eval org-agenda-redo-command))
6096 (setq org-agenda-undo-list nil
6097 org-agenda-pending-undo-list nil)
6098 (message "Rebuilding agenda buffer...done")
6099 (put 'org-agenda-filter :preset-filter preset)
6100 (and (or filter preset) (org-agenda-filter-apply filter))
6101 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6102 (org-goto-line line)
6103 (recenter window-line)))
6106 (defvar org-global-tags-completion-table nil)
6107 (defvar org-agenda-filter-form nil)
6108 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6109 "Keep only those lines in the agenda buffer that have a specific tag.
6110 The tag is selected with its fast selection letter, as configured.
6111 With prefix argument STRIP, remove all lines that do have the tag.
6112 A lisp caller can specify CHAR. NARROW means that the new tag should be
6113 used to narrow the search - the interactive user can also press `-' or `+'
6114 to switch to narrowing."
6115 (interactive "P")
6116 (let* ((alist org-tag-alist-for-agenda)
6117 (tag-chars (mapconcat
6118 (lambda (x) (if (and (not (symbolp (car x)))
6119 (cdr x))
6120 (char-to-string (cdr x))
6121 ""))
6122 alist ""))
6123 (efforts (org-split-string
6124 (or (cdr (assoc (concat org-effort-property "_ALL")
6125 org-global-properties))
6126 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6127 "")))
6128 (effort-op org-agenda-filter-effort-default-operator)
6129 (effort-prompt "")
6130 (inhibit-read-only t)
6131 (current org-agenda-filter)
6132 maybe-refresh a n tag)
6133 (unless char
6134 (message
6135 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6136 (if narrow "Narrow" "Filter") tag-chars
6137 (if org-agenda-auto-exclude-function "[RET], " ""))
6138 (setq char (read-char)))
6139 (when (member char '(?+ ?-))
6140 ;; Narrowing down
6141 (cond ((equal char ?-) (setq strip t narrow t))
6142 ((equal char ?+) (setq strip nil narrow t)))
6143 (message
6144 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6145 (setq char (read-char)))
6146 (when (member char '(?< ?> ?= ??))
6147 ;; An effort operator
6148 (setq effort-op (char-to-string char))
6149 (setq alist nil) ; to make sure it will be interpreted as effort.
6150 (unless (equal char ??)
6151 (loop for i from 0 to 9 do
6152 (setq effort-prompt
6153 (concat
6154 effort-prompt " ["
6155 (if (= i 9) "0" (int-to-string (1+ i)))
6156 "]" (nth i efforts))))
6157 (message "Effort%s: %s " effort-op effort-prompt)
6158 (setq char (read-char))
6159 (when (or (< char ?0) (> char ?9))
6160 (error "Need 1-9,0 to select effort" ))))
6161 (when (equal char ?\t)
6162 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6163 (org-set-local 'org-global-tags-completion-table
6164 (org-global-tags-completion-table)))
6165 (let ((completion-ignore-case t))
6166 (setq tag (org-icompleting-read
6167 "Tag: " org-global-tags-completion-table))))
6168 (cond
6169 ((equal char ?\r)
6170 (org-agenda-filter-by-tag-show-all)
6171 (when org-agenda-auto-exclude-function
6172 (setq org-agenda-filter '())
6173 (dolist (tag (org-agenda-get-represented-tags))
6174 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6175 (if modifier
6176 (push modifier org-agenda-filter))))
6177 (if (not (null org-agenda-filter))
6178 (org-agenda-filter-apply org-agenda-filter)))
6179 (setq maybe-refresh t))
6180 ((equal char ?/)
6181 (org-agenda-filter-by-tag-show-all)
6182 (when (get 'org-agenda-filter :preset-filter)
6183 (org-agenda-filter-apply org-agenda-filter))
6184 (setq maybe-refresh t))
6185 ((or (equal char ?\ )
6186 (setq a (rassoc char alist))
6187 (and (>= char ?0) (<= char ?9)
6188 (setq n (if (= char ?0) 9 (- char ?0 1))
6189 tag (concat effort-op (nth n efforts))
6190 a (cons tag nil)))
6191 (and (= char ??)
6192 (setq tag "?eff")
6193 a (cons tag nil))
6194 (and tag (setq a (cons tag nil))))
6195 (org-agenda-filter-by-tag-show-all)
6196 (setq tag (car a))
6197 (setq org-agenda-filter
6198 (cons (concat (if strip "-" "+") tag)
6199 (if narrow current nil)))
6200 (org-agenda-filter-apply org-agenda-filter)
6201 (setq maybe-refresh t))
6202 (t (error "Invalid tag selection character %c" char)))
6203 (when (and maybe-refresh
6204 (eq org-agenda-clockreport-mode 'with-filter))
6205 (org-agenda-redo))))
6207 (defun org-agenda-get-represented-tags ()
6208 "Get a list of all tags currently represented in the agenda."
6209 (let (p tags)
6210 (save-excursion
6211 (goto-char (point-min))
6212 (while (setq p (next-single-property-change (point) 'tags))
6213 (goto-char p)
6214 (mapc (lambda (x) (add-to-list 'tags x))
6215 (get-text-property (point) 'tags))))
6216 tags))
6218 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6219 "Refine the current filter. See `org-agenda-filter-by-tag."
6220 (interactive "P")
6221 (org-agenda-filter-by-tag strip char 'refine))
6223 (defun org-agenda-filter-make-matcher ()
6224 "Create the form that tests a line for the agenda filter."
6225 (let (f f1)
6226 (dolist (x (append (get 'org-agenda-filter :preset-filter)
6227 org-agenda-filter))
6228 (if (member x '("-" "+"))
6229 (setq f1 (if (equal x "-") 'tags '(not tags)))
6230 (if (string-match "[<=>?]" x)
6231 (setq f1 (org-agenda-filter-effort-form x))
6232 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6233 (if (equal (string-to-char x) ?-)
6234 (setq f1 (list 'not f1))))
6235 (push f1 f))
6236 (cons 'and (nreverse f))))
6238 (defun org-agenda-filter-effort-form (e)
6239 "Return the form to compare the effort of the current line with what E says.
6240 E looks like \"+<2:25\"."
6241 (let (op)
6242 (setq e (substring e 1))
6243 (setq op (string-to-char e) e (substring e 1))
6244 (setq op (cond ((equal op ?<) '<=)
6245 ((equal op ?>) '>=)
6246 ((equal op ??) op)
6247 (t '=)))
6248 (list 'org-agenda-compare-effort (list 'quote op)
6249 (org-duration-string-to-minutes e))))
6251 (defun org-agenda-compare-effort (op value)
6252 "Compare the effort of the current line with VALUE, using OP.
6253 If the line does not have an effort defined, return nil."
6254 (let ((eff (org-get-at-bol 'effort-minutes)))
6255 (if (equal op ??)
6256 (not eff)
6257 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6258 value))))
6260 (defun org-agenda-filter-apply (filter)
6261 "Set FILTER as the new agenda filter and apply it."
6262 (let (tags)
6263 (setq org-agenda-filter filter
6264 org-agenda-filter-form (org-agenda-filter-make-matcher))
6265 (org-agenda-set-mode-name)
6266 (save-excursion
6267 (goto-char (point-min))
6268 (while (not (eobp))
6269 (if (org-get-at-bol 'org-marker)
6270 (progn
6271 (setq tags (org-get-at-bol 'tags)) ; used in eval
6272 (if (not (eval org-agenda-filter-form))
6273 (org-agenda-filter-by-tag-hide-line))
6274 (beginning-of-line 2))
6275 (beginning-of-line 2))))
6276 (if (get-char-property (point) 'invisible)
6277 (org-agenda-previous-line))))
6279 (defun org-agenda-filter-by-tag-hide-line ()
6280 (let (ov)
6281 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6282 (point-at-eol)))
6283 (overlay-put ov 'invisible t)
6284 (overlay-put ov 'type 'tags-filter)
6285 (push ov org-agenda-filter-overlays)))
6287 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6288 (setq pos (or pos (point)))
6289 (save-excursion
6290 (dolist (ov (overlays-at pos))
6291 (when (and (overlay-get ov 'invisible)
6292 (eq (overlay-get ov 'type) 'tags-filter))
6293 (goto-char pos)
6294 (if (< (overlay-start ov) (point-at-eol))
6295 (move-overlay ov (point-at-eol)
6296 (overlay-end ov)))))))
6298 (defun org-agenda-filter-by-tag-show-all ()
6299 (mapc 'delete-overlay org-agenda-filter-overlays)
6300 (setq org-agenda-filter-overlays nil)
6301 (setq org-agenda-filter nil)
6302 (setq org-agenda-filter-form nil)
6303 (org-agenda-set-mode-name))
6305 (defun org-agenda-manipulate-query-add ()
6306 "Manipulate the query by adding a search term with positive selection.
6307 Positive selection means the term must be matched for selection of an entry."
6308 (interactive)
6309 (org-agenda-manipulate-query ?\[))
6310 (defun org-agenda-manipulate-query-subtract ()
6311 "Manipulate the query by adding a search term with negative selection.
6312 Negative selection means term must not be matched for selection of an entry."
6313 (interactive)
6314 (org-agenda-manipulate-query ?\]))
6315 (defun org-agenda-manipulate-query-add-re ()
6316 "Manipulate the query by adding a search regexp with positive selection.
6317 Positive selection means the regexp must match for selection of an entry."
6318 (interactive)
6319 (org-agenda-manipulate-query ?\{))
6320 (defun org-agenda-manipulate-query-subtract-re ()
6321 "Manipulate the query by adding a search regexp with negative selection.
6322 Negative selection means regexp must not match for selection of an entry."
6323 (interactive)
6324 (org-agenda-manipulate-query ?\}))
6325 (defun org-agenda-manipulate-query (char)
6326 (cond
6327 ((memq org-agenda-type '(timeline agenda))
6328 (let ((org-agenda-include-inactive-timestamps t))
6329 (org-agenda-redo))
6330 (message "Display now includes inactive timestamps as well"))
6331 ((eq org-agenda-type 'search)
6332 (org-add-to-string
6333 'org-agenda-query-string
6334 (if org-agenda-last-search-view-search-was-boolean
6335 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6336 (?\{ . " +{}") (?\} . " -{}"))))
6337 " "))
6338 (setq org-agenda-redo-command
6339 (list 'org-search-view
6340 org-todo-only
6341 org-agenda-query-string
6342 (+ (length org-agenda-query-string)
6343 (if (member char '(?\{ ?\})) 0 1))))
6344 (set-register org-agenda-query-register org-agenda-query-string)
6345 (org-agenda-redo))
6346 (t (error "Cannot manipulate query for %s-type agenda buffers"
6347 org-agenda-type))))
6349 (defun org-add-to-string (var string)
6350 (set var (concat (symbol-value var) string)))
6352 (defun org-agenda-goto-date (date)
6353 "Jump to DATE in agenda."
6354 (interactive (list (let ((org-read-date-prefer-future
6355 (eval org-agenda-jump-prefer-future)))
6356 (org-read-date))))
6357 (org-agenda-list nil date))
6359 (defun org-agenda-goto-today ()
6360 "Go to today."
6361 (interactive)
6362 (org-agenda-check-type t 'timeline 'agenda)
6363 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6364 (cond
6365 (tdpos (goto-char tdpos))
6366 ((eq org-agenda-type 'agenda)
6367 (let* ((sd (org-agenda-compute-starting-span
6368 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6369 (org-agenda-overriding-arguments org-agenda-last-arguments))
6370 (setf (nth 1 org-agenda-overriding-arguments) sd)
6371 (org-agenda-redo)
6372 (org-agenda-find-same-or-today-or-agenda)))
6373 (t (error "Cannot find today")))))
6375 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6376 (goto-char
6377 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6378 (text-property-any (point-min) (point-max) 'org-today t)
6379 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6380 (point-min))))
6382 (defun org-agenda-later (arg)
6383 "Go forward in time by thee current span.
6384 With prefix ARG, go forward that many times the current span."
6385 (interactive "p")
6386 (org-agenda-check-type t 'agenda)
6387 (let* ((span org-agenda-current-span)
6388 (sd org-starting-day)
6389 (greg (calendar-gregorian-from-absolute sd))
6390 (cnt (org-get-at-bol 'org-day-cnt))
6391 greg2)
6392 (cond
6393 ((eq span 'day)
6394 (setq sd (+ arg sd)))
6395 ((eq span 'week)
6396 (setq sd (+ (* 7 arg) sd)))
6397 ((eq span 'month)
6398 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6399 sd (calendar-absolute-from-gregorian greg2))
6400 (setcar greg2 (1+ (car greg2))))
6401 ((eq span 'year)
6402 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6403 sd (calendar-absolute-from-gregorian greg2))
6404 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6406 (setq sd (+ (* span arg) sd))))
6407 (let ((org-agenda-overriding-arguments
6408 (list (car org-agenda-last-arguments) sd span t)))
6409 (org-agenda-redo)
6410 (org-agenda-find-same-or-today-or-agenda cnt))))
6412 (defun org-agenda-earlier (arg)
6413 "Go backward in time by the current span.
6414 With prefix ARG, go backward that many times the current span."
6415 (interactive "p")
6416 (org-agenda-later (- arg)))
6418 (defun org-agenda-view-mode-dispatch ()
6419 "Call one of the view mode commands."
6420 (interactive)
6421 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6422 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6423 [a]rch-trees [A]rch-files clock[R]eport include[D]iary
6424 [E]ntryText")
6425 (let ((a (read-char-exclusive)))
6426 (case a
6427 (?\ (call-interactively 'org-agenda-reset-view))
6428 (?d (call-interactively 'org-agenda-day-view))
6429 (?w (call-interactively 'org-agenda-week-view))
6430 (?m (call-interactively 'org-agenda-month-view))
6431 (?y (call-interactively 'org-agenda-year-view))
6432 (?l (call-interactively 'org-agenda-log-mode))
6433 (?L (org-agenda-log-mode '(4)))
6434 (?c (org-agenda-log-mode 'clockcheck))
6435 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6436 (?a (call-interactively 'org-agenda-archives-mode))
6437 (?A (org-agenda-archives-mode 'files))
6438 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6439 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6440 (?G (call-interactively 'org-agenda-toggle-time-grid))
6441 (?D (call-interactively 'org-agenda-toggle-diary))
6442 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6443 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6444 (org-agenda-check-type t 'timeline 'agenda)
6445 (org-agenda-redo))
6446 (message "Display now includes inactive timestamps as well"))
6447 (?q (message "Abort"))
6448 (otherwise (error "Invalid key" )))))
6450 (defun org-agenda-reset-view ()
6451 "Switch to default view for agenda."
6452 (interactive)
6453 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6454 (defun org-agenda-day-view (&optional day-of-year)
6455 "Switch to daily view for agenda.
6456 With argument DAY-OF-YEAR, switch to that day of the year."
6457 (interactive "P")
6458 (org-agenda-change-time-span 'day day-of-year))
6459 (defun org-agenda-week-view (&optional iso-week)
6460 "Switch to daily view for agenda.
6461 With argument ISO-WEEK, switch to the corresponding ISO week.
6462 If ISO-WEEK has more then 2 digits, only the last two encode the
6463 week. Any digits before this encode a year. So 200712 means
6464 week 12 of year 2007. Years in the range 1938-2037 can also be
6465 written as 2-digit years."
6466 (interactive "P")
6467 (org-agenda-change-time-span 'week iso-week))
6468 (defun org-agenda-month-view (&optional month)
6469 "Switch to monthly view for agenda.
6470 With argument MONTH, switch to that month."
6471 (interactive "P")
6472 (org-agenda-change-time-span 'month month))
6473 (defun org-agenda-year-view (&optional year)
6474 "Switch to yearly view for agenda.
6475 With argument YEAR, switch to that year.
6476 If MONTH has more then 2 digits, only the last two encode the
6477 month. Any digits before this encode a year. So 200712 means
6478 December year 2007. Years in the range 1938-2037 can also be
6479 written as 2-digit years."
6480 (interactive "P")
6481 (when year
6482 (setq year (org-small-year-to-year year)))
6483 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6484 (org-agenda-change-time-span 'year year)
6485 (error "Abort")))
6487 (defun org-agenda-change-time-span (span &optional n)
6488 "Change the agenda view to SPAN.
6489 SPAN may be `day', `week', `month', `year'."
6490 (org-agenda-check-type t 'agenda)
6491 (if (and (not n) (equal org-agenda-current-span span))
6492 (error "Viewing span is already \"%s\"" span))
6493 (let* ((sd (or (org-get-at-bol 'day)
6494 org-starting-day))
6495 (sd (org-agenda-compute-starting-span sd span n))
6496 (org-agenda-overriding-arguments
6497 (or org-agenda-overriding-arguments
6498 (list (car org-agenda-last-arguments) sd span t))))
6499 (org-agenda-redo)
6500 (org-agenda-find-same-or-today-or-agenda))
6501 (org-agenda-set-mode-name)
6502 (message "Switched to %s view" span))
6504 (defun org-agenda-compute-starting-span (sd span &optional n)
6505 "Compute starting date for agenda.
6506 SPAN may be `day', `week', `month', `year'. The return value
6507 is a cons cell with the starting date and the number of days,
6508 so that the date SD will be in that range."
6509 (let* ((greg (calendar-gregorian-from-absolute sd))
6510 (dg (nth 1 greg))
6511 (mg (car greg))
6512 (yg (nth 2 greg)))
6513 (cond
6514 ((eq span 'day)
6515 (when n
6516 (setq sd (+ (calendar-absolute-from-gregorian
6517 (list mg 1 yg))
6518 n -1))))
6519 ((eq span 'week)
6520 (let* ((nt (calendar-day-of-week
6521 (calendar-gregorian-from-absolute sd)))
6522 (d (if org-agenda-start-on-weekday
6523 (- nt org-agenda-start-on-weekday)
6526 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6527 (when n
6528 (require 'cal-iso)
6529 (when (> n 99)
6530 (setq y1 (org-small-year-to-year (/ n 100))
6531 n (mod n 100)))
6532 (setq sd
6533 (calendar-absolute-from-iso
6534 (list n 1
6535 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6536 ((eq span 'month)
6537 (let (y1)
6538 (when (and n (> n 99))
6539 (setq y1 (org-small-year-to-year (/ n 100))
6540 n (mod n 100)))
6541 (setq sd (calendar-absolute-from-gregorian
6542 (list (or n mg) 1 (or y1 yg))))))
6543 ((eq span 'year)
6544 (setq sd (calendar-absolute-from-gregorian
6545 (list 1 1 (or n yg))))))
6546 sd))
6548 (defun org-agenda-next-date-line (&optional arg)
6549 "Jump to the next line indicating a date in agenda buffer."
6550 (interactive "p")
6551 (org-agenda-check-type t 'agenda 'timeline)
6552 (beginning-of-line 1)
6553 ;; This does not work if user makes date format that starts with a blank
6554 (if (looking-at "^\\S-") (forward-char 1))
6555 (if (not (re-search-forward "^\\S-" nil t arg))
6556 (progn
6557 (backward-char 1)
6558 (error "No next date after this line in this buffer")))
6559 (goto-char (match-beginning 0)))
6561 (defun org-agenda-previous-date-line (&optional arg)
6562 "Jump to the previous line indicating a date in agenda buffer."
6563 (interactive "p")
6564 (org-agenda-check-type t 'agenda 'timeline)
6565 (beginning-of-line 1)
6566 (if (not (re-search-backward "^\\S-" nil t arg))
6567 (error "No previous date before this line in this buffer")))
6569 ;; Initialize the highlight
6570 (defvar org-hl (make-overlay 1 1))
6571 (overlay-put org-hl 'face 'highlight)
6573 (defun org-highlight (begin end &optional buffer)
6574 "Highlight a region with overlay."
6575 (move-overlay org-hl begin end (or buffer (current-buffer))))
6577 (defun org-unhighlight ()
6578 "Detach overlay INDEX."
6579 (org-detach-overlay org-hl))
6581 ;; FIXME this is currently not used.
6582 (defun org-highlight-until-next-command (beg end &optional buffer)
6583 "Move the highlight overlay to BEG/END, remove it before the next command."
6584 (org-highlight beg end buffer)
6585 (add-hook 'pre-command-hook 'org-unhighlight-once))
6586 (defun org-unhighlight-once ()
6587 "Remove the highlight from its position, and this function from the hook."
6588 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6589 (org-unhighlight))
6591 (defun org-agenda-follow-mode ()
6592 "Toggle follow mode in an agenda buffer."
6593 (interactive)
6594 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6595 (org-agenda-set-mode-name)
6596 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6597 (org-agenda-show))
6598 (message "Follow mode is %s"
6599 (if org-agenda-follow-mode "on" "off")))
6601 (defun org-agenda-entry-text-mode (&optional arg)
6602 "Toggle entry text mode in an agenda buffer."
6603 (interactive "P")
6604 (setq org-agenda-entry-text-mode (or (integerp arg)
6605 (not org-agenda-entry-text-mode)))
6606 (org-agenda-entry-text-hide)
6607 (and org-agenda-entry-text-mode
6608 (let ((org-agenda-entry-text-maxlines
6609 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6610 (org-agenda-entry-text-show)))
6611 (org-agenda-set-mode-name)
6612 (message "Entry text mode is %s. Maximum number of lines is %d"
6613 (if org-agenda-entry-text-mode "on" "off")
6614 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6616 (defun org-agenda-clockreport-mode (&optional with-filter)
6617 "Toggle clocktable mode in an agenda buffer.
6618 With prefix arg WITH-FILTER, make the clocktable respect the current
6619 agenda filter."
6620 (interactive "P")
6621 (org-agenda-check-type t 'agenda)
6622 (if with-filter
6623 (setq org-agenda-clockreport-mode 'with-filter)
6624 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6625 (org-agenda-set-mode-name)
6626 (org-agenda-redo)
6627 (message "Clocktable mode is %s"
6628 (if org-agenda-clockreport-mode "on" "off")))
6630 (defun org-agenda-log-mode (&optional special)
6631 "Toggle log mode in an agenda buffer.
6632 With argument SPECIAL, show all possible log items, not only the ones
6633 configured in `org-agenda-log-mode-items'.
6634 With a double `C-u' prefix arg, show *only* log items, nothing else."
6635 (interactive "P")
6636 (org-agenda-check-type t 'agenda 'timeline)
6637 (setq org-agenda-show-log
6638 (cond
6639 ((equal special '(16)) 'only)
6640 ((eq special 'clockcheck)
6641 (if (eq org-agenda-show-log 'clockcheck)
6642 nil 'clockcheck))
6643 (special '(closed clock state))
6644 (t (not org-agenda-show-log))))
6645 (org-agenda-set-mode-name)
6646 (org-agenda-redo)
6647 (message "Log mode is %s"
6648 (if org-agenda-show-log "on" "off")))
6650 (defun org-agenda-archives-mode (&optional with-files)
6651 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6652 When called with a prefix argument, include all archive files as well."
6653 (interactive "P")
6654 (setq org-agenda-archives-mode
6655 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6656 (org-agenda-set-mode-name)
6657 (org-agenda-redo)
6658 (message
6659 "%s"
6660 (cond
6661 ((eq org-agenda-archives-mode nil)
6662 "No archives are included")
6663 ((eq org-agenda-archives-mode 'trees)
6664 (format "Trees with :%s: tag are included" org-archive-tag))
6665 ((eq org-agenda-archives-mode t)
6666 (format "Trees with :%s: tag and all active archive files are included"
6667 org-archive-tag)))))
6669 (defun org-agenda-toggle-diary ()
6670 "Toggle diary inclusion in an agenda buffer."
6671 (interactive)
6672 (org-agenda-check-type t 'agenda)
6673 (setq org-agenda-include-diary (not org-agenda-include-diary))
6674 (org-agenda-redo)
6675 (org-agenda-set-mode-name)
6676 (message "Diary inclusion turned %s"
6677 (if org-agenda-include-diary "on" "off")))
6679 (defun org-agenda-toggle-deadlines ()
6680 "Toggle inclusion of entries with a deadline in an agenda buffer."
6681 (interactive)
6682 (org-agenda-check-type t 'agenda)
6683 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6684 (org-agenda-redo)
6685 (org-agenda-set-mode-name)
6686 (message "Deadlines inclusion turned %s"
6687 (if org-agenda-include-deadlines "on" "off")))
6689 (defun org-agenda-toggle-time-grid ()
6690 "Toggle time grid in an agenda buffer."
6691 (interactive)
6692 (org-agenda-check-type t 'agenda)
6693 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6694 (org-agenda-redo)
6695 (org-agenda-set-mode-name)
6696 (message "Time-grid turned %s"
6697 (if org-agenda-use-time-grid "on" "off")))
6699 (defun org-agenda-set-mode-name ()
6700 "Set the mode name to indicate all the small mode settings."
6701 (setq mode-name
6702 (list "Org-Agenda"
6703 (if (get 'org-agenda-files 'org-restrict) " []" "")
6705 '(:eval (org-agenda-span-name org-agenda-current-span))
6706 (if org-agenda-follow-mode " Follow" "")
6707 (if org-agenda-entry-text-mode " ETxt" "")
6708 (if org-agenda-include-diary " Diary" "")
6709 (if org-agenda-include-deadlines " Ddl" "")
6710 (if org-agenda-use-time-grid " Grid" "")
6711 (if (and (boundp 'org-habit-show-habits)
6712 org-habit-show-habits) " Habit" "")
6713 (cond
6714 ((consp org-agenda-show-log) " LogAll")
6715 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
6716 (org-agenda-show-log " Log")
6717 (t ""))
6718 (if (or org-agenda-filter (get 'org-agenda-filter
6719 :preset-filter))
6720 (concat " {" (mapconcat
6721 'identity
6722 (append (get 'org-agenda-filter
6723 :preset-filter)
6724 org-agenda-filter) "") "}")
6726 (if org-agenda-archives-mode
6727 (if (eq org-agenda-archives-mode t)
6728 " Archives"
6729 (format " :%s:" org-archive-tag))
6731 (if org-agenda-clockreport-mode
6732 (if (eq org-agenda-clockreport-mode 'with-filter)
6733 " Clock{}" " Clock")
6734 "")))
6735 (force-mode-line-update))
6737 (defun org-agenda-post-command-hook ()
6738 (setq org-agenda-type
6739 (or (get-text-property (point) 'org-agenda-type)
6740 (get-text-property (max (point-min) (1- (point)))
6741 'org-agenda-type))))
6743 (defun org-agenda-next-line ()
6744 "Move cursor to the next line, and show if follow mode is active."
6745 (interactive)
6746 (call-interactively 'next-line)
6747 (org-agenda-do-context-action))
6749 (defun org-agenda-previous-line ()
6750 "Move cursor to the previous line, and show if follow-mode is active."
6751 (interactive)
6752 (call-interactively 'previous-line)
6753 (org-agenda-do-context-action))
6755 (defun org-agenda-do-context-action ()
6756 "Show outline path and, maybe, follow mode window."
6757 (let ((m (org-get-at-bol 'org-marker)))
6758 (if (and org-agenda-follow-mode m)
6759 (org-agenda-show))
6760 (if (and m org-agenda-show-outline-path)
6761 (org-with-point-at m
6762 (org-display-outline-path t)))))
6764 (defun org-agenda-show-priority ()
6765 "Show the priority of the current item.
6766 This priority is composed of the main priority given with the [#A] cookies,
6767 and by additional input from the age of a schedules or deadline entry."
6768 (interactive)
6769 (let* ((pri (org-get-at-bol 'priority)))
6770 (message "Priority is %d" (if pri pri -1000))))
6772 (defun org-agenda-show-tags ()
6773 "Show the tags applicable to the current item."
6774 (interactive)
6775 (let* ((tags (org-get-at-bol 'tags)))
6776 (if tags
6777 (message "Tags are :%s:"
6778 (org-no-properties (mapconcat 'identity tags ":")))
6779 (message "No tags associated with this line"))))
6781 (defun org-agenda-goto (&optional highlight)
6782 "Go to the Org-mode file which contains the item at point."
6783 (interactive)
6784 (let* ((marker (or (org-get-at-bol 'org-marker)
6785 (org-agenda-error)))
6786 (buffer (marker-buffer marker))
6787 (pos (marker-position marker)))
6788 (switch-to-buffer-other-window buffer)
6789 (widen)
6790 (push-mark)
6791 (goto-char pos)
6792 (when (org-mode-p)
6793 (org-show-context 'agenda)
6794 (save-excursion
6795 (and (outline-next-heading)
6796 (org-flag-heading nil)))) ; show the next heading
6797 (when (outline-invisible-p)
6798 (show-entry)) ; display invisible text
6799 (recenter (/ (window-height) 2))
6800 (run-hooks 'org-agenda-after-show-hook)
6801 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6803 (defvar org-agenda-after-show-hook nil
6804 "Normal hook run after an item has been shown from the agenda.
6805 Point is in the buffer where the item originated.")
6807 (defun org-agenda-kill ()
6808 "Kill the entry or subtree belonging to the current agenda entry."
6809 (interactive)
6810 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6811 (let* ((marker (or (org-get-at-bol 'org-marker)
6812 (org-agenda-error)))
6813 (buffer (marker-buffer marker))
6814 (pos (marker-position marker))
6815 (type (org-get-at-bol 'type))
6816 dbeg dend (n 0) conf)
6817 (org-with-remote-undo buffer
6818 (with-current-buffer buffer
6819 (save-excursion
6820 (goto-char pos)
6821 (if (and (org-mode-p) (not (member type '("sexp"))))
6822 (setq dbeg (progn (org-back-to-heading t) (point))
6823 dend (org-end-of-subtree t t))
6824 (setq dbeg (point-at-bol)
6825 dend (min (point-max) (1+ (point-at-eol)))))
6826 (goto-char dbeg)
6827 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6828 (setq conf (or (eq t org-agenda-confirm-kill)
6829 (and (numberp org-agenda-confirm-kill)
6830 (> n org-agenda-confirm-kill))))
6831 (and conf
6832 (not (y-or-n-p
6833 (format "Delete entry with %d lines in buffer \"%s\"? "
6834 n (buffer-name buffer))))
6835 (error "Abort"))
6836 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6837 (with-current-buffer buffer (delete-region dbeg dend))
6838 (message "Agenda item and source killed"))))
6840 (defvar org-archive-default-command)
6841 (defun org-agenda-archive-default ()
6842 "Archive the entry or subtree belonging to the current agenda entry."
6843 (interactive)
6844 (require 'org-archive)
6845 (org-agenda-archive-with org-archive-default-command))
6847 (defun org-agenda-archive-default-with-confirmation ()
6848 "Archive the entry or subtree belonging to the current agenda entry."
6849 (interactive)
6850 (require 'org-archive)
6851 (org-agenda-archive-with org-archive-default-command 'confirm))
6853 (defun org-agenda-archive ()
6854 "Archive the entry or subtree belonging to the current agenda entry."
6855 (interactive)
6856 (org-agenda-archive-with 'org-archive-subtree))
6858 (defun org-agenda-archive-to-archive-sibling ()
6859 "Move the entry to the archive sibling."
6860 (interactive)
6861 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6863 (defun org-agenda-archive-with (cmd &optional confirm)
6864 "Move the entry to the archive sibling."
6865 (interactive)
6866 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6867 (let* ((marker (or (org-get-at-bol 'org-marker)
6868 (org-agenda-error)))
6869 (buffer (marker-buffer marker))
6870 (pos (marker-position marker)))
6871 (org-with-remote-undo buffer
6872 (with-current-buffer buffer
6873 (if (org-mode-p)
6874 (if (and confirm
6875 (not (y-or-n-p "Archive this subtree or entry? ")))
6876 (error "Abort")
6877 (save-excursion
6878 (goto-char pos)
6879 (org-remove-subtree-entries-from-agenda)
6880 (org-back-to-heading t)
6881 (funcall cmd)))
6882 (error "Archiving works only in Org-mode files"))))))
6884 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6885 "Remove all lines in the agenda that correspond to a given subtree.
6886 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6887 If this information is not given, the function uses the tree at point."
6888 (let ((buf (or buf (current-buffer))) m p)
6889 (save-excursion
6890 (unless (and beg end)
6891 (org-back-to-heading t)
6892 (setq beg (point))
6893 (org-end-of-subtree t)
6894 (setq end (point)))
6895 (set-buffer (get-buffer org-agenda-buffer-name))
6896 (save-excursion
6897 (goto-char (point-max))
6898 (beginning-of-line 1)
6899 (while (not (bobp))
6900 (when (and (setq m (org-get-at-bol 'org-marker))
6901 (equal buf (marker-buffer m))
6902 (setq p (marker-position m))
6903 (>= p beg)
6904 (< p end))
6905 (let ((inhibit-read-only t))
6906 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6907 (beginning-of-line 0))))))
6909 (defun org-agenda-refile (&optional goto rfloc no-update)
6910 "Refile the item at point."
6911 (interactive "P")
6912 (if (equal goto '(16))
6913 (org-refile-goto-last-stored)
6914 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6915 (org-agenda-error)))
6916 (buffer (marker-buffer marker))
6917 (pos (marker-position marker))
6918 (rfloc (or rfloc
6919 (org-refile-get-location
6920 (if goto "Goto" "Refile to") buffer
6921 org-refile-allow-creating-parent-nodes))))
6922 (with-current-buffer buffer
6923 (save-excursion
6924 (save-restriction
6925 (widen)
6926 (goto-char marker)
6927 (org-remove-subtree-entries-from-agenda)
6928 (org-refile goto buffer rfloc)))))
6929 (unless no-update (org-agenda-redo))))
6931 (defun org-agenda-open-link (&optional arg)
6932 "Follow the link in the current line, if any.
6933 This looks for a link in the displayed line in the agenda. It also looks
6934 at the text of the entry itself."
6935 (interactive "P")
6936 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6937 (org-get-at-bol 'org-marker)))
6938 (buffer (and marker (marker-buffer marker)))
6939 (prefix (buffer-substring
6940 (point-at-bol) (point-at-eol))))
6941 (cond
6942 (buffer
6943 (with-current-buffer buffer
6944 (save-excursion
6945 (save-restriction
6946 (widen)
6947 (goto-char marker)
6948 (org-offer-links-in-entry arg prefix)))))
6949 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6950 (save-excursion
6951 (beginning-of-line 1)
6952 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6953 (org-open-link-from-string (match-string 1)))
6954 (t (error "No link to open here")))))
6956 (defun org-agenda-copy-local-variable (var)
6957 "Get a variable from a referenced buffer and install it here."
6958 (let ((m (org-get-at-bol 'org-marker)))
6959 (when (and m (buffer-live-p (marker-buffer m)))
6960 (org-set-local var (with-current-buffer (marker-buffer m)
6961 (symbol-value var))))))
6963 (defun org-agenda-switch-to (&optional delete-other-windows)
6964 "Go to the Org-mode file which contains the item at point."
6965 (interactive)
6966 (if (and org-return-follows-link
6967 (not (org-get-at-bol 'org-marker))
6968 (org-in-regexp org-bracket-link-regexp))
6969 (org-open-link-from-string (match-string 0))
6970 (let* ((marker (or (org-get-at-bol 'org-marker)
6971 (org-agenda-error)))
6972 (buffer (marker-buffer marker))
6973 (pos (marker-position marker)))
6974 (switch-to-buffer buffer)
6975 (and delete-other-windows (delete-other-windows))
6976 (widen)
6977 (goto-char pos)
6978 (when (org-mode-p)
6979 (org-show-context 'agenda)
6980 (save-excursion
6981 (and (outline-next-heading)
6982 (org-flag-heading nil))) ; show the next heading
6983 (when (outline-invisible-p)
6984 (show-entry)))))) ; display invisible text
6986 (defun org-agenda-goto-mouse (ev)
6987 "Go to the Org-mode file which contains the item at the mouse click."
6988 (interactive "e")
6989 (mouse-set-point ev)
6990 (org-agenda-goto))
6992 (defun org-agenda-show (&optional full-entry)
6993 "Display the Org-mode file which contains the item at point.
6994 With prefix argument FULL-ENTRY, make the entire entry visible
6995 if it was hidden in the outline."
6996 (interactive "P")
6997 (let ((win (selected-window)))
6998 (if full-entry
6999 (let ((org-show-entry-below t))
7000 (org-agenda-goto t))
7001 (org-agenda-goto t))
7002 (select-window win)))
7004 (defvar org-agenda-show-window nil)
7005 (defun org-agenda-show-and-scroll-up ()
7006 "Display the Org-mode file which contains the item at point.
7007 When called repeatedly, scroll the window that is displaying the buffer."
7008 (interactive)
7009 (let ((win (selected-window)))
7010 (if (and (window-live-p org-agenda-show-window)
7011 (eq this-command last-command))
7012 (progn
7013 (select-window org-agenda-show-window)
7014 (ignore-errors (scroll-up)))
7015 (org-agenda-goto t)
7016 (show-subtree)
7017 (setq org-agenda-show-window (selected-window)))
7018 (select-window win)))
7020 (defun org-agenda-show-scroll-down ()
7021 "Scroll down the window showing the agenda."
7022 (interactive)
7023 (let ((win (selected-window)))
7024 (when (window-live-p org-agenda-show-window)
7025 (select-window org-agenda-show-window)
7026 (ignore-errors (scroll-down))
7027 (select-window win))))
7029 (defun org-agenda-show-1 (&optional more)
7030 "Display the Org-mode file which contains the item at point.
7031 The prefix arg selects the amount of information to display:
7033 0 hide the subtree
7034 1 just show the entry according to defaults.
7035 2 show the children view
7036 3 show the subtree view
7037 4 show the entire subtree and any LOGBOOK drawers
7038 5 show the entire subtree and any drawers
7039 With prefix argument FULL-ENTRY, make the entire entry visible
7040 if it was hidden in the outline."
7041 (interactive "p")
7042 (let ((win (selected-window)))
7043 (org-agenda-goto t)
7044 (org-recenter-heading 1)
7045 (cond
7046 ((= more 0)
7047 (hide-subtree)
7048 (save-excursion
7049 (org-back-to-heading)
7050 (run-hook-with-args 'org-cycle-hook 'folded))
7051 (message "Remote: FOLDED"))
7052 ((and (org-called-interactively-p 'any) (= more 1))
7053 (message "Remote: show with default settings"))
7054 ((= more 2)
7055 (show-entry)
7056 (show-children)
7057 (save-excursion
7058 (org-back-to-heading)
7059 (run-hook-with-args 'org-cycle-hook 'children))
7060 (message "Remote: CHILDREN"))
7061 ((= more 3)
7062 (show-subtree)
7063 (save-excursion
7064 (org-back-to-heading)
7065 (run-hook-with-args 'org-cycle-hook 'subtree))
7066 (message "Remote: SUBTREE"))
7067 ((= more 4)
7068 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7069 (org-drawer-regexp
7070 (concat "^[ \t]*:\\("
7071 (mapconcat 'regexp-quote org-drawers "\\|")
7072 "\\):[ \t]*$")))
7073 (show-subtree)
7074 (save-excursion
7075 (org-back-to-heading)
7076 (org-cycle-hide-drawers 'subtree)))
7077 (message "Remote: SUBTREE AND LOGBOOK"))
7078 ((> more 4)
7079 (show-subtree)
7080 (message "Remote: SUBTREE AND ALL DRAWERS")))
7081 (select-window win)))
7083 (defun org-recenter-heading (n)
7084 (save-excursion
7085 (org-back-to-heading)
7086 (recenter n)))
7088 (defvar org-agenda-cycle-counter nil)
7089 (defun org-agenda-cycle-show (&optional n)
7090 "Show the current entry in another window, with default settings.
7091 Default settings are taken from `org-show-hierarchy-above' and siblings.
7092 When use repeatedly in immediate succession, the remote entry will cycle
7093 through visibility
7095 children -> subtree -> folded
7097 When called with a numeric prefix arg, that arg will be passed through to
7098 `org-agenda-show-1'. For the interpretation of that argument, see the
7099 docstring of `org-agenda-show-1'."
7100 (interactive "P")
7101 (if (integerp n)
7102 (setq org-agenda-cycle-counter n)
7103 (if (not (eq last-command this-command))
7104 (setq org-agenda-cycle-counter 1)
7105 (if (equal org-agenda-cycle-counter 0)
7106 (setq org-agenda-cycle-counter 2)
7107 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7108 (if (> org-agenda-cycle-counter 3)
7109 (setq org-agenda-cycle-counter 0)))))
7110 (org-agenda-show-1 org-agenda-cycle-counter))
7112 (defun org-agenda-recenter (arg)
7113 "Display the Org-mode file which contains the item at point and recenter."
7114 (interactive "P")
7115 (let ((win (selected-window)))
7116 (org-agenda-goto t)
7117 (recenter arg)
7118 (select-window win)))
7120 (defun org-agenda-show-mouse (ev)
7121 "Display the Org-mode file which contains the item at the mouse click."
7122 (interactive "e")
7123 (mouse-set-point ev)
7124 (org-agenda-show))
7126 (defun org-agenda-check-no-diary ()
7127 "Check if the entry is a diary link and abort if yes."
7128 (if (org-get-at-bol 'org-agenda-diary-link)
7129 (org-agenda-error)))
7131 (defun org-agenda-error ()
7132 (error "Command not allowed in this line"))
7134 (defun org-agenda-tree-to-indirect-buffer ()
7135 "Show the subtree corresponding to the current entry in an indirect buffer.
7136 This calls the command `org-tree-to-indirect-buffer' from the original
7137 Org-mode buffer.
7138 With numerical prefix arg ARG, go up to this level and then take that tree.
7139 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7140 use the dedicated frame)."
7141 (interactive)
7142 (org-agenda-check-no-diary)
7143 (let* ((marker (or (org-get-at-bol 'org-marker)
7144 (org-agenda-error)))
7145 (buffer (marker-buffer marker))
7146 (pos (marker-position marker)))
7147 (with-current-buffer buffer
7148 (save-excursion
7149 (goto-char pos)
7150 (call-interactively 'org-tree-to-indirect-buffer)))))
7152 (defvar org-last-heading-marker (make-marker)
7153 "Marker pointing to the headline that last changed its TODO state
7154 by a remote command from the agenda.")
7156 (defun org-agenda-todo-nextset ()
7157 "Switch TODO entry to next sequence."
7158 (interactive)
7159 (org-agenda-todo 'nextset))
7161 (defun org-agenda-todo-previousset ()
7162 "Switch TODO entry to previous sequence."
7163 (interactive)
7164 (org-agenda-todo 'previousset))
7166 (defun org-agenda-todo (&optional arg)
7167 "Cycle TODO state of line at point, also in Org-mode file.
7168 This changes the line at point, all other lines in the agenda referring to
7169 the same tree node, and the headline of the tree node in the Org-mode file."
7170 (interactive "P")
7171 (org-agenda-check-no-diary)
7172 (let* ((col (current-column))
7173 (marker (or (org-get-at-bol 'org-marker)
7174 (org-agenda-error)))
7175 (buffer (marker-buffer marker))
7176 (pos (marker-position marker))
7177 (hdmarker (org-get-at-bol 'org-hd-marker))
7178 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7179 (inhibit-read-only t)
7180 org-agenda-headline-snapshot-before-repeat newhead just-one)
7181 (org-with-remote-undo buffer
7182 (with-current-buffer buffer
7183 (widen)
7184 (goto-char pos)
7185 (org-show-context 'agenda)
7186 (save-excursion
7187 (and (outline-next-heading)
7188 (org-flag-heading nil))) ; show the next heading
7189 (let ((current-prefix-arg arg))
7190 (call-interactively 'org-todo))
7191 (and (bolp) (forward-char 1))
7192 (setq newhead (org-get-heading))
7193 (when (and (org-bound-and-true-p
7194 org-agenda-headline-snapshot-before-repeat)
7195 (not (equal org-agenda-headline-snapshot-before-repeat
7196 newhead))
7197 todayp)
7198 (setq newhead org-agenda-headline-snapshot-before-repeat
7199 just-one t))
7200 (save-excursion
7201 (org-back-to-heading)
7202 (move-marker org-last-heading-marker (point))))
7203 (beginning-of-line 1)
7204 (save-excursion
7205 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7206 (org-move-to-column col))))
7208 (defun org-agenda-add-note (&optional arg)
7209 "Add a time-stamped note to the entry at point."
7210 (interactive "P")
7211 (org-agenda-check-no-diary)
7212 (let* ((marker (or (org-get-at-bol 'org-marker)
7213 (org-agenda-error)))
7214 (buffer (marker-buffer marker))
7215 (pos (marker-position marker))
7216 (hdmarker (org-get-at-bol 'org-hd-marker))
7217 (inhibit-read-only t))
7218 (with-current-buffer buffer
7219 (widen)
7220 (goto-char pos)
7221 (org-show-context 'agenda)
7222 (save-excursion
7223 (and (outline-next-heading)
7224 (org-flag-heading nil))) ; show the next heading
7225 (org-add-note))))
7227 (defun org-agenda-change-all-lines (newhead hdmarker
7228 &optional fixface just-this)
7229 "Change all lines in the agenda buffer which match HDMARKER.
7230 The new content of the line will be NEWHEAD (as modified by
7231 `org-format-agenda-item'). HDMARKER is checked with
7232 `equal' against all `org-hd-marker' text properties in the file.
7233 If FIXFACE is non-nil, the face of each item is modified according to
7234 the new TODO state.
7235 If JUST-THIS is non-nil, change just the current line, not all.
7236 If FORCE-TAGS is non nil, the car of it returns the new tags."
7237 (let* ((inhibit-read-only t)
7238 (line (org-current-line))
7239 (thetags (with-current-buffer (marker-buffer hdmarker)
7240 (save-excursion (save-restriction (widen)
7241 (goto-char hdmarker)
7242 (org-get-tags-at)))))
7243 props m pl undone-face done-face finish new dotime cat tags)
7244 (save-excursion
7245 (goto-char (point-max))
7246 (beginning-of-line 1)
7247 (while (not finish)
7248 (setq finish (bobp))
7249 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7250 (or (not just-this) (= (org-current-line) line))
7251 (equal m hdmarker))
7252 (setq props (text-properties-at (point))
7253 dotime (org-get-at-bol 'dotime)
7254 cat (org-get-at-bol 'org-category)
7255 tags thetags
7256 new (org-format-agenda-item (org-get-at-bol 'extra)
7257 newhead cat tags dotime)
7258 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7259 undone-face (org-get-at-bol 'undone-face)
7260 done-face (org-get-at-bol 'done-face))
7261 (beginning-of-line 1)
7262 (cond
7263 ((equal new "")
7264 (and (looking-at ".*\n?") (replace-match "")))
7265 ((looking-at ".*")
7266 (replace-match new t t)
7267 (beginning-of-line 1)
7268 (add-text-properties (point-at-bol) (point-at-eol) props)
7269 (when fixface
7270 (add-text-properties
7271 (point-at-bol) (point-at-eol)
7272 (list 'face
7273 (if org-last-todo-state-is-todo
7274 undone-face done-face))))
7275 (org-agenda-highlight-todo 'line)
7276 (beginning-of-line 1))
7277 (t (error "Line update did not work"))))
7278 (beginning-of-line 0)))
7279 (org-finalize-agenda)))
7281 (defun org-agenda-align-tags (&optional line)
7282 "Align all tags in agenda items to `org-agenda-tags-column'."
7283 (let ((inhibit-read-only t) l c)
7284 (save-excursion
7285 (goto-char (if line (point-at-bol) (point-min)))
7286 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7287 (if line (point-at-eol) nil) t)
7288 (add-text-properties
7289 (match-beginning 2) (match-end 2)
7290 (list 'face (delq nil (let ((prop (get-text-property
7291 (match-beginning 2) 'face)))
7292 (or (listp prop) (setq prop (list prop)))
7293 (if (memq 'org-tag prop)
7294 prop
7295 (cons 'org-tag prop))))))
7296 (setq l (- (match-end 2) (match-beginning 2))
7297 c (if (< org-agenda-tags-column 0)
7298 (- (abs org-agenda-tags-column) l)
7299 org-agenda-tags-column))
7300 (delete-region (match-beginning 1) (match-end 1))
7301 (goto-char (match-beginning 1))
7302 (insert (org-add-props
7303 (make-string (max 1 (- c (current-column))) ?\ )
7304 (plist-put (copy-sequence (text-properties-at (point)))
7305 'face nil))))
7306 (goto-char (point-min))
7307 (org-font-lock-add-tag-faces (point-max)))))
7309 (defun org-agenda-priority-up ()
7310 "Increase the priority of line at point, also in Org-mode file."
7311 (interactive)
7312 (org-agenda-priority 'up))
7314 (defun org-agenda-priority-down ()
7315 "Decrease the priority of line at point, also in Org-mode file."
7316 (interactive)
7317 (org-agenda-priority 'down))
7319 (defun org-agenda-priority (&optional force-direction)
7320 "Set the priority of line at point, also in Org-mode file.
7321 This changes the line at point, all other lines in the agenda referring to
7322 the same tree node, and the headline of the tree node in the Org-mode file."
7323 (interactive)
7324 (unless org-enable-priority-commands
7325 (error "Priority commands are disabled"))
7326 (org-agenda-check-no-diary)
7327 (let* ((marker (or (org-get-at-bol 'org-marker)
7328 (org-agenda-error)))
7329 (hdmarker (org-get-at-bol 'org-hd-marker))
7330 (buffer (marker-buffer hdmarker))
7331 (pos (marker-position hdmarker))
7332 (inhibit-read-only t)
7333 newhead)
7334 (org-with-remote-undo buffer
7335 (with-current-buffer buffer
7336 (widen)
7337 (goto-char pos)
7338 (org-show-context 'agenda)
7339 (save-excursion
7340 (and (outline-next-heading)
7341 (org-flag-heading nil))) ; show the next heading
7342 (funcall 'org-priority force-direction)
7343 (end-of-line 1)
7344 (setq newhead (org-get-heading)))
7345 (org-agenda-change-all-lines newhead hdmarker)
7346 (beginning-of-line 1))))
7348 ;; FIXME: should fix the tags property of the agenda line.
7349 (defun org-agenda-set-tags (&optional tag onoff)
7350 "Set tags for the current headline."
7351 (interactive)
7352 (org-agenda-check-no-diary)
7353 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7354 (call-interactively 'org-change-tag-in-region)
7355 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7356 (org-agenda-error)))
7357 (buffer (marker-buffer hdmarker))
7358 (pos (marker-position hdmarker))
7359 (inhibit-read-only t)
7360 newhead)
7361 (org-with-remote-undo buffer
7362 (with-current-buffer buffer
7363 (widen)
7364 (goto-char pos)
7365 (save-excursion
7366 (org-show-context 'agenda))
7367 (save-excursion
7368 (and (outline-next-heading)
7369 (org-flag-heading nil))) ; show the next heading
7370 (goto-char pos)
7371 (if tag
7372 (org-toggle-tag tag onoff)
7373 (call-interactively 'org-set-tags))
7374 (end-of-line 1)
7375 (setq newhead (org-get-heading)))
7376 (org-agenda-change-all-lines newhead hdmarker)
7377 (beginning-of-line 1)))))
7379 (defun org-agenda-set-property ()
7380 "Set a property for the current headline."
7381 (interactive)
7382 (org-agenda-check-no-diary)
7383 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7384 (org-agenda-error)))
7385 (buffer (marker-buffer hdmarker))
7386 (pos (marker-position hdmarker))
7387 (inhibit-read-only t)
7388 newhead)
7389 (org-with-remote-undo buffer
7390 (with-current-buffer buffer
7391 (widen)
7392 (goto-char pos)
7393 (save-excursion
7394 (org-show-context 'agenda))
7395 (save-excursion
7396 (and (outline-next-heading)
7397 (org-flag-heading nil))) ; show the next heading
7398 (goto-char pos)
7399 (call-interactively 'org-set-property)))))
7401 (defun org-agenda-set-effort ()
7402 "Set the effort property for the current headline."
7403 (interactive)
7404 (org-agenda-check-no-diary)
7405 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7406 (org-agenda-error)))
7407 (buffer (marker-buffer hdmarker))
7408 (pos (marker-position hdmarker))
7409 (inhibit-read-only t)
7410 newhead)
7411 (org-with-remote-undo buffer
7412 (with-current-buffer buffer
7413 (widen)
7414 (goto-char pos)
7415 (save-excursion
7416 (org-show-context 'agenda))
7417 (save-excursion
7418 (and (outline-next-heading)
7419 (org-flag-heading nil))) ; show the next heading
7420 (goto-char pos)
7421 (call-interactively 'org-set-effort)
7422 (end-of-line 1)))))
7424 (defun org-agenda-toggle-archive-tag ()
7425 "Toggle the archive tag for the current entry."
7426 (interactive)
7427 (org-agenda-check-no-diary)
7428 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7429 (org-agenda-error)))
7430 (buffer (marker-buffer hdmarker))
7431 (pos (marker-position hdmarker))
7432 (inhibit-read-only t)
7433 newhead)
7434 (org-with-remote-undo buffer
7435 (with-current-buffer buffer
7436 (widen)
7437 (goto-char pos)
7438 (org-show-context 'agenda)
7439 (save-excursion
7440 (and (outline-next-heading)
7441 (org-flag-heading nil))) ; show the next heading
7442 (call-interactively 'org-toggle-archive-tag)
7443 (end-of-line 1)
7444 (setq newhead (org-get-heading)))
7445 (org-agenda-change-all-lines newhead hdmarker)
7446 (beginning-of-line 1))))
7448 (defun org-agenda-do-date-later (arg)
7449 (interactive "P")
7450 (cond
7451 ((or (equal arg '(16))
7452 (memq last-command
7453 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7454 (setq this-command 'org-agenda-date-later-minutes)
7455 (org-agenda-date-later-minutes 1))
7456 ((or (equal arg '(4))
7457 (memq last-command
7458 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7459 (setq this-command 'org-agenda-date-later-hours)
7460 (org-agenda-date-later-hours 1))
7462 (org-agenda-date-later (prefix-numeric-value arg)))))
7464 (defun org-agenda-do-date-earlier (arg)
7465 (interactive "P")
7466 (cond
7467 ((or (equal arg '(16))
7468 (memq last-command
7469 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7470 (setq this-command 'org-agenda-date-earlier-minutes)
7471 (org-agenda-date-earlier-minutes 1))
7472 ((or (equal arg '(4))
7473 (memq last-command
7474 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7475 (setq this-command 'org-agenda-date-earlier-hours)
7476 (org-agenda-date-earlier-hours 1))
7478 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7480 (defun org-agenda-date-later (arg &optional what)
7481 "Change the date of this item to ARG day(s) later."
7482 (interactive "p")
7483 (org-agenda-check-type t 'agenda 'timeline)
7484 (org-agenda-check-no-diary)
7485 (let* ((marker (or (org-get-at-bol 'org-marker)
7486 (org-agenda-error)))
7487 (buffer (marker-buffer marker))
7488 (pos (marker-position marker)))
7489 (org-with-remote-undo buffer
7490 (with-current-buffer buffer
7491 (widen)
7492 (goto-char pos)
7493 (if (not (org-at-timestamp-p))
7494 (error "Cannot find time stamp"))
7495 (org-timestamp-change arg (or what 'day)))
7496 (org-agenda-show-new-time marker org-last-changed-timestamp))
7497 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7499 (defun org-agenda-date-earlier (arg &optional what)
7500 "Change the date of this item to ARG day(s) earlier."
7501 (interactive "p")
7502 (org-agenda-date-later (- arg) what))
7504 (defun org-agenda-date-later-minutes (arg)
7505 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7506 (interactive "p")
7507 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7508 (org-agenda-date-later arg 'minute))
7510 (defun org-agenda-date-earlier-minutes (arg)
7511 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7512 (interactive "p")
7513 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7514 (org-agenda-date-earlier arg 'minute))
7516 (defun org-agenda-date-later-hours (arg)
7517 "Change the time of this item, in hour steps."
7518 (interactive "p")
7519 (org-agenda-date-later arg 'hour))
7521 (defun org-agenda-date-earlier-hours (arg)
7522 "Change the time of this item, in hour steps."
7523 (interactive "p")
7524 (org-agenda-date-earlier arg 'hour))
7526 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7527 "Show new date stamp via text properties."
7528 ;; We use text properties to make this undoable
7529 (let ((inhibit-read-only t)
7530 (buffer-invisibility-spec))
7531 (setq stamp (concat " " prefix " => " stamp))
7532 (save-excursion
7533 (goto-char (point-max))
7534 (while (not (bobp))
7535 (when (equal marker (org-get-at-bol 'org-marker))
7536 (org-move-to-column (- (window-width) (length stamp)) t)
7537 (org-agenda-fix-tags-filter-overlays-at (point))
7538 (if (featurep 'xemacs)
7539 ;; Use `duplicable' property to trigger undo recording
7540 (let ((ex (make-extent nil nil))
7541 (gl (make-glyph stamp)))
7542 (set-glyph-face gl 'secondary-selection)
7543 (set-extent-properties
7544 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7545 (insert-extent ex (1- (point)) (point-at-eol)))
7546 (add-text-properties
7547 (1- (point)) (point-at-eol)
7548 (list 'display (org-add-props stamp nil
7549 'face 'secondary-selection))))
7550 (beginning-of-line 1))
7551 (beginning-of-line 0)))))
7553 (defun org-agenda-date-prompt (arg)
7554 "Change the date of this item. Date is prompted for, with default today.
7555 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7556 be used to request time specification in the time stamp."
7557 (interactive "P")
7558 (org-agenda-check-type t 'agenda 'timeline)
7559 (org-agenda-check-no-diary)
7560 (let* ((marker (or (org-get-at-bol 'org-marker)
7561 (org-agenda-error)))
7562 (buffer (marker-buffer marker))
7563 (pos (marker-position marker)))
7564 (org-with-remote-undo buffer
7565 (with-current-buffer buffer
7566 (widen)
7567 (goto-char pos)
7568 (if (not (org-at-timestamp-p t))
7569 (error "Cannot find time stamp"))
7570 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7571 (org-agenda-show-new-time marker org-last-changed-timestamp))
7572 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7574 (defun org-agenda-schedule (arg &optional time)
7575 "Schedule the item at point.
7576 Arg is passed through to `org-schedule'."
7577 (interactive "P")
7578 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7579 (org-agenda-check-no-diary)
7580 (let* ((marker (or (org-get-at-bol 'org-marker)
7581 (org-agenda-error)))
7582 (type (marker-insertion-type marker))
7583 (buffer (marker-buffer marker))
7584 (pos (marker-position marker))
7585 (org-insert-labeled-timestamps-at-point nil)
7587 (set-marker-insertion-type marker t)
7588 (org-with-remote-undo buffer
7589 (with-current-buffer buffer
7590 (widen)
7591 (goto-char pos)
7592 (setq ts (org-schedule arg time)))
7593 (org-agenda-show-new-time marker ts "S"))
7594 (message "Item scheduled for %s" ts)))
7596 (defun org-agenda-deadline (arg &optional time)
7597 "Schedule the item at point.
7598 Arg is passed through to `org-deadline'."
7599 (interactive "P")
7600 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7601 (org-agenda-check-no-diary)
7602 (let* ((marker (or (org-get-at-bol 'org-marker)
7603 (org-agenda-error)))
7604 (buffer (marker-buffer marker))
7605 (pos (marker-position marker))
7606 (org-insert-labeled-timestamps-at-point nil)
7608 (org-with-remote-undo buffer
7609 (with-current-buffer buffer
7610 (widen)
7611 (goto-char pos)
7612 (setq ts (org-deadline arg time)))
7613 (org-agenda-show-new-time marker ts "D"))
7614 (message "Deadline for this item set to %s" ts)))
7616 (defun org-agenda-action ()
7617 "Select entry for agenda action, or execute an agenda action.
7618 This command prompts for another letter. Valid inputs are:
7620 m Mark the entry at point for an agenda action
7621 s Schedule the marked entry to the date at the cursor
7622 d Set the deadline of the marked entry to the date at the cursor
7623 r Call `org-remember' with cursor date as the default date
7624 c Call `org-capture' with cursor date as the default date
7625 SPC Show marked entry in other window
7626 TAB Visit marked entry in other window
7628 The cursor may be at a date in the calendar, or in the Org agenda."
7629 (interactive)
7630 (let (ans)
7631 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7632 (setq ans (read-char-exclusive))
7633 (cond
7634 ((equal ans ?m)
7635 ;; Mark this entry
7636 (if (eq major-mode 'org-agenda-mode)
7637 (let ((m (or (org-get-at-bol 'org-hd-marker)
7638 (org-get-at-bol 'org-marker))))
7639 (if m
7640 (progn
7641 (move-marker org-agenda-action-marker
7642 (marker-position m) (marker-buffer m))
7643 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7644 (error "Don't know which entry to mark")))
7645 (error "This command works only in the agenda")))
7646 ((equal ans ?s)
7647 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7648 ((equal ans ?d)
7649 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7650 ((equal ans ?r)
7651 (org-agenda-do-action '(org-remember) t))
7652 ((equal ans ?c)
7653 (org-agenda-do-action '(org-capture) t))
7654 ((equal ans ?\ )
7655 (let ((cw (selected-window)))
7656 (org-switch-to-buffer-other-window
7657 (marker-buffer org-agenda-action-marker))
7658 (goto-char org-agenda-action-marker)
7659 (org-show-context 'agenda)
7660 (select-window cw)))
7661 ((equal ans ?\C-i)
7662 (org-switch-to-buffer-other-window
7663 (marker-buffer org-agenda-action-marker))
7664 (goto-char org-agenda-action-marker)
7665 (org-show-context 'agenda))
7666 (t (error "Invalid agenda action %c" ans)))))
7668 (defun org-agenda-do-action (form &optional current-buffer)
7669 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7670 (let ((org-overriding-default-time (org-get-cursor-date)))
7671 (if current-buffer
7672 (eval form)
7673 (if (not (marker-buffer org-agenda-action-marker))
7674 (error "No entry has been selected for agenda action")
7675 (with-current-buffer (marker-buffer org-agenda-action-marker)
7676 (save-excursion
7677 (save-restriction
7678 (widen)
7679 (goto-char org-agenda-action-marker)
7680 (eval form))))))))
7682 (defun org-agenda-clock-in (&optional arg)
7683 "Start the clock on the currently selected item."
7684 (interactive "P")
7685 (org-agenda-check-no-diary)
7686 (if (equal arg '(4))
7687 (org-clock-in arg)
7688 (let* ((marker (or (org-get-at-bol 'org-marker)
7689 (org-agenda-error)))
7690 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7691 marker))
7692 (pos (marker-position marker))
7693 newhead)
7694 (org-with-remote-undo (marker-buffer marker)
7695 (with-current-buffer (marker-buffer marker)
7696 (widen)
7697 (goto-char pos)
7698 (org-show-context 'agenda)
7699 (org-show-entry)
7700 (org-cycle-hide-drawers 'children)
7701 (org-clock-in arg)
7702 (setq newhead (org-get-heading)))
7703 (org-agenda-change-all-lines newhead hdmarker)))))
7705 (defun org-agenda-clock-out ()
7706 "Stop the currently running clock."
7707 (interactive)
7708 (unless (marker-buffer org-clock-marker)
7709 (error "No running clock"))
7710 (let ((marker (make-marker)) newhead)
7711 (org-with-remote-undo (marker-buffer org-clock-marker)
7712 (with-current-buffer (marker-buffer org-clock-marker)
7713 (save-excursion
7714 (save-restriction
7715 (widen)
7716 (goto-char org-clock-marker)
7717 (org-back-to-heading t)
7718 (move-marker marker (point))
7719 (org-clock-out)
7720 (setq newhead (org-get-heading))))))
7721 (org-agenda-change-all-lines newhead marker)
7722 (move-marker marker nil)))
7724 (defun org-agenda-clock-cancel (&optional arg)
7725 "Cancel the currently running clock."
7726 (interactive "P")
7727 (unless (marker-buffer org-clock-marker)
7728 (error "No running clock"))
7729 (org-with-remote-undo (marker-buffer org-clock-marker)
7730 (org-clock-cancel)))
7732 (defun org-agenda-clock-goto ()
7733 "Jump to the currently clocked in task within the agenda.
7734 If the currently clocked in task is not listed in the agenda
7735 buffer, display it in another window."
7736 (interactive)
7737 (let (pos)
7738 (mapc (lambda (o)
7739 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7740 (setq pos (overlay-start o))))
7741 (overlays-in (point-min) (point-max)))
7742 (cond (pos (goto-char pos))
7743 ;; If the currently clocked entry is not in the agenda
7744 ;; buffer, we visit it in another window:
7745 (org-clock-current-task
7746 (org-switch-to-buffer-other-window (org-clock-goto)))
7747 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7749 (defun org-agenda-diary-entry-in-org-file ()
7750 "Make a diary entry in the file `org-agenda-diary-file'."
7751 (let (d1 d2 char (text "") dp1 dp2)
7752 (if (equal (buffer-name) "*Calendar*")
7753 (setq d1 (calendar-cursor-to-date t)
7754 d2 (car calendar-mark-ring))
7755 (setq dp1 (get-text-property (point-at-bol) 'day))
7756 (unless dp1 (error "No date defined in current line"))
7757 (setq d1 (calendar-gregorian-from-absolute dp1)
7758 d2 (and (ignore-errors (mark))
7759 (save-excursion
7760 (goto-char (mark))
7761 (setq dp2 (get-text-property (point-at-bol) 'day)))
7762 (calendar-gregorian-from-absolute dp2))))
7763 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7764 (setq char (read-char-exclusive))
7765 (cond
7766 ((equal char ?d)
7767 (setq text (read-string "Day entry: "))
7768 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7769 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7770 ((equal char ?a)
7771 (setq d1 (list (car d1) (nth 1 d1)
7772 (read-number (format "Reference year [%d]: " (nth 2 d1))
7773 (nth 2 d1))))
7774 (setq text (read-string "Anniversary (use %d to show years): "))
7775 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7776 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7777 ((equal char ?b)
7778 (setq text (read-string "Block entry: "))
7779 (unless (and d1 d2 (not (equal d1 d2)))
7780 (error "No block of days selected"))
7781 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7782 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7783 ((equal char ?j)
7784 (org-switch-to-buffer-other-window
7785 (find-file-noselect org-agenda-diary-file))
7786 (require 'org-datetree)
7787 (org-datetree-find-date-create d1)
7788 (org-reveal t))
7789 (t (error "Invalid selection character `%c'" char)))))
7791 (defcustom org-agenda-insert-diary-strategy 'date-tree
7792 "Where in `org-agenda-diary-file' should new entries be added?
7793 Valid values:
7795 date-tree in the date tree, as child of the date
7796 top-level as top-level entries at the end of the file."
7797 :group 'org-agenda
7798 :type '(choice
7799 (const :tag "in a date tree" date-tree)
7800 (const :tag "as top level at end of file" top-level)))
7802 (defcustom org-agenda-insert-diary-extract-time nil
7803 "Non-nil means extract any time specification from the diary entry."
7804 :group 'org-agenda
7805 :type 'boolean)
7807 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7808 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7809 If TEXT is not empty, it will become the headline of the new entry, and
7810 the resulting entry will not be shown. When TEXT is empty, switch to
7811 `org-agenda-diary-file' and let the user finish the entry there."
7812 (let ((cw (current-window-configuration)))
7813 (org-switch-to-buffer-other-window
7814 (find-file-noselect org-agenda-diary-file))
7815 (widen)
7816 (goto-char (point-min))
7817 (cond
7818 ((eq type 'anniversary)
7819 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7820 (progn
7821 (or (org-on-heading-p t)
7822 (progn
7823 (outline-next-heading)
7824 (insert "* Anniversaries\n\n")
7825 (beginning-of-line -1)))))
7826 (outline-next-heading)
7827 (org-back-over-empty-lines)
7828 (backward-char 1)
7829 (insert "\n")
7830 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
7831 (nth 2 d1) (car d1) (nth 1 d1) text)))
7832 ((eq type 'day)
7833 (let ((org-prefix-has-time t)
7834 (org-agenda-time-leading-zero t)
7835 fmt time time2)
7836 (if org-agenda-insert-diary-extract-time
7837 ;; Use org-format-agenda-item to parse text for a time-range and
7838 ;; remove it. FIXME: This is a hack, we should refactor
7839 ;; that function to make time extraction available separately
7840 (setq fmt (org-format-agenda-item nil text nil nil t)
7841 time (get-text-property 0 'time fmt)
7842 time2 (if (> (length time) 0)
7843 ;; split-string removes trailing ...... if
7844 ;; no end time given. First space
7845 ;; separates time from date.
7846 (concat " " (car (split-string time "\\.")))
7847 nil)
7848 text (get-text-property 0 'txt fmt)))
7849 (if (eq org-agenda-insert-diary-strategy 'top-level)
7850 (org-agenda-insert-diary-as-top-level text)
7851 (require 'org-datetree)
7852 (org-datetree-find-date-create d1)
7853 (org-agenda-insert-diary-make-new-entry text))
7854 (org-insert-time-stamp (org-time-from-absolute
7855 (calendar-absolute-from-gregorian d1))
7856 nil nil nil nil time2))
7857 (end-of-line 0))
7858 ((eq type 'block)
7859 (if (> (calendar-absolute-from-gregorian d1)
7860 (calendar-absolute-from-gregorian d2))
7861 (setq d1 (prog1 d2 (setq d2 d1))))
7862 (if (eq org-agenda-insert-diary-strategy 'top-level)
7863 (org-agenda-insert-diary-as-top-level text)
7864 (require 'org-datetree)
7865 (org-datetree-find-date-create d1)
7866 (org-agenda-insert-diary-make-new-entry text))
7867 (org-insert-time-stamp (org-time-from-absolute
7868 (calendar-absolute-from-gregorian d1)))
7869 (insert "--")
7870 (org-insert-time-stamp (org-time-from-absolute
7871 (calendar-absolute-from-gregorian d2)))
7872 (end-of-line 0)))
7873 (if (string-match "\\S-" text)
7874 (progn
7875 (set-window-configuration cw)
7876 (message "%s entry added to %s"
7877 (capitalize (symbol-name type))
7878 (abbreviate-file-name org-agenda-diary-file)))
7879 (org-reveal t)
7880 (message "Please finish entry here"))))
7882 (defun org-agenda-insert-diary-as-top-level (text)
7883 "Make new entry as a top-level entry at the end of the file.
7884 Add TEXT as headline, and position the cursor in the second line so that
7885 a timestamp can be added there."
7886 (widen)
7887 (goto-char (point-max))
7888 (or (bolp) (insert "\n"))
7889 (insert "* " text "\n")
7890 (if org-adapt-indentation (org-indent-to-column 2)))
7892 (defun org-agenda-insert-diary-make-new-entry (text)
7893 "Make new entry as last child of current entry.
7894 Add TEXT as headline, and position the cursor in the second line so that
7895 a timestamp can be added there."
7896 (let ((org-show-following-heading t)
7897 (org-show-siblings t)
7898 (org-show-hierarchy-above t)
7899 (org-show-entry-below t)
7900 col)
7901 (outline-next-heading)
7902 (org-back-over-empty-lines)
7903 (or (looking-at "[ \t]*$")
7904 (progn (insert "\n") (backward-char 1)))
7905 (org-insert-heading nil t)
7906 (org-do-demote)
7907 (setq col (current-column))
7908 (insert text "\n")
7909 (if org-adapt-indentation (org-indent-to-column col))
7910 (let ((org-show-following-heading t)
7911 (org-show-siblings t)
7912 (org-show-hierarchy-above t)
7913 (org-show-entry-below t))
7914 (org-show-context))))
7916 (defun org-agenda-diary-entry ()
7917 "Make a diary entry, like the `i' command from the calendar.
7918 All the standard commands work: block, weekly etc.
7919 When `org-agenda-diary-file' points to a file,
7920 `org-agenda-diary-entry-in-org-file' is called instead to create
7921 entries in that Org-mode file."
7922 (interactive)
7923 (org-agenda-check-type t 'agenda 'timeline)
7924 (if (not (eq org-agenda-diary-file 'diary-file))
7925 (org-agenda-diary-entry-in-org-file)
7926 (require 'diary-lib)
7927 (let* ((char (progn
7928 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7929 (read-char-exclusive)))
7930 (cmd (cdr (assoc char
7931 '((?d . insert-diary-entry)
7932 (?w . insert-weekly-diary-entry)
7933 (?m . insert-monthly-diary-entry)
7934 (?y . insert-yearly-diary-entry)
7935 (?a . insert-anniversary-diary-entry)
7936 (?b . insert-block-diary-entry)
7937 (?c . insert-cyclic-diary-entry)))))
7938 (oldf (symbol-function 'calendar-cursor-to-date))
7939 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7940 (point (point))
7941 (mark (or (mark t) (point))))
7942 (unless cmd
7943 (error "No command associated with <%c>" char))
7944 (unless (and (get-text-property point 'day)
7945 (or (not (equal ?b char))
7946 (get-text-property mark 'day)))
7947 (error "Don't know which date to use for diary entry"))
7948 ;; We implement this by hacking the `calendar-cursor-to-date' function
7949 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7950 (let ((calendar-mark-ring
7951 (list (calendar-gregorian-from-absolute
7952 (or (get-text-property mark 'day)
7953 (get-text-property point 'day))))))
7954 (unwind-protect
7955 (progn
7956 (fset 'calendar-cursor-to-date
7957 (lambda (&optional error dummy)
7958 (calendar-gregorian-from-absolute
7959 (get-text-property point 'day))))
7960 (call-interactively cmd))
7961 (fset 'calendar-cursor-to-date oldf))))))
7963 (defun org-agenda-execute-calendar-command (cmd)
7964 "Execute a calendar command from the agenda, with the date associated to
7965 the cursor position."
7966 (org-agenda-check-type t 'agenda 'timeline)
7967 (require 'diary-lib)
7968 (unless (get-text-property (point) 'day)
7969 (error "Don't know which date to use for calendar command"))
7970 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7971 (point (point))
7972 (date (calendar-gregorian-from-absolute
7973 (get-text-property point 'day)))
7974 ;; the following 2 vars are needed in the calendar
7975 (displayed-month (car date))
7976 (displayed-year (nth 2 date)))
7977 (unwind-protect
7978 (progn
7979 (fset 'calendar-cursor-to-date
7980 (lambda (&optional error dummy)
7981 (calendar-gregorian-from-absolute
7982 (get-text-property point 'day))))
7983 (call-interactively cmd))
7984 (fset 'calendar-cursor-to-date oldf))))
7986 (defun org-agenda-phases-of-moon ()
7987 "Display the phases of the moon for the 3 months around the cursor date."
7988 (interactive)
7989 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7991 (defun org-agenda-holidays ()
7992 "Display the holidays for the 3 months around the cursor date."
7993 (interactive)
7994 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7996 (defvar calendar-longitude)
7997 (defvar calendar-latitude)
7998 (defvar calendar-location-name)
8000 (defun org-agenda-sunrise-sunset (arg)
8001 "Display sunrise and sunset for the cursor date.
8002 Latitude and longitude can be specified with the variables
8003 `calendar-latitude' and `calendar-longitude'. When called with prefix
8004 argument, latitude and longitude will be prompted for."
8005 (interactive "P")
8006 (require 'solar)
8007 (let ((calendar-longitude (if arg nil calendar-longitude))
8008 (calendar-latitude (if arg nil calendar-latitude))
8009 (calendar-location-name
8010 (if arg "the given coordinates" calendar-location-name)))
8011 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8013 (defun org-agenda-goto-calendar ()
8014 "Open the Emacs calendar with the date at the cursor."
8015 (interactive)
8016 (org-agenda-check-type t 'agenda 'timeline)
8017 (let* ((day (or (get-text-property (point) 'day)
8018 (error "Don't know which date to open in calendar")))
8019 (date (calendar-gregorian-from-absolute day))
8020 (calendar-move-hook nil)
8021 (calendar-view-holidays-initially-flag nil)
8022 (calendar-view-diary-initially-flag nil))
8023 (calendar)
8024 (calendar-goto-date date)))
8026 ;;;###autoload
8027 (defun org-calendar-goto-agenda ()
8028 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8029 This is a command that has to be installed in `calendar-mode-map'."
8030 (interactive)
8031 (org-agenda-list nil (calendar-absolute-from-gregorian
8032 (calendar-cursor-to-date))
8033 nil))
8035 (defun org-agenda-convert-date ()
8036 (interactive)
8037 (org-agenda-check-type t 'agenda 'timeline)
8038 (let ((day (get-text-property (point) 'day))
8039 date s)
8040 (unless day
8041 (error "Don't know which date to convert"))
8042 (setq date (calendar-gregorian-from-absolute day))
8043 (setq s (concat
8044 "Gregorian: " (calendar-date-string date) "\n"
8045 "ISO: " (calendar-iso-date-string date) "\n"
8046 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8047 "Julian: " (calendar-julian-date-string date) "\n"
8048 "Astron. JD: " (calendar-astro-date-string date)
8049 " (Julian date number at noon UTC)\n"
8050 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8051 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8052 "French: " (calendar-french-date-string date) "\n"
8053 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8054 "Mayan: " (calendar-mayan-date-string date) "\n"
8055 "Coptic: " (calendar-coptic-date-string date) "\n"
8056 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8057 "Persian: " (calendar-persian-date-string date) "\n"
8058 "Chinese: " (calendar-chinese-date-string date) "\n"))
8059 (with-output-to-temp-buffer "*Dates*"
8060 (princ s))
8061 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8063 ;;; Bulk commands
8065 (defvar org-agenda-bulk-marked-entries nil
8066 "List of markers that refer to marked entries in the agenda.")
8068 (defun org-agenda-bulk-marked-p ()
8069 (eq (get-char-property (point-at-bol) 'type)
8070 'org-marked-entry-overlay))
8072 (defun org-agenda-bulk-mark (&optional arg)
8073 "Mark the entry at point for future bulk action."
8074 (interactive "p")
8075 (dotimes (i (max arg 1))
8076 (unless (org-get-at-bol 'org-agenda-diary-link)
8077 (let* ((m (org-get-at-bol 'org-hd-marker))
8079 (unless (org-agenda-bulk-marked-p)
8080 (unless m (error "Nothing to mark at point"))
8081 (push m org-agenda-bulk-marked-entries)
8082 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8083 (org-overlay-display ov "> "
8084 (org-get-todo-face "TODO")
8085 'evaporate)
8086 (overlay-put ov 'type 'org-marked-entry-overlay))
8087 (beginning-of-line 2)
8088 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8089 (beginning-of-line 2))
8090 (message "%d entries marked for bulk action"
8091 (length org-agenda-bulk-marked-entries))))))
8093 (defun org-agenda-bulk-mark-regexp (regexp)
8094 "Mark entries match REGEXP."
8095 (interactive "sMark entries matching regexp: ")
8096 (let (entries-marked)
8097 (save-excursion
8098 (goto-char (point-min))
8099 (goto-char (next-single-property-change (point) 'txt))
8100 (while (re-search-forward regexp nil t)
8101 (when (string-match regexp (get-text-property (point) 'txt))
8102 (setq entries-marked (+ entries-marked 1))
8103 (call-interactively 'org-agenda-bulk-mark))))
8104 (if (not entries-marked)
8105 (message "No entry matching this regexp."))))
8107 (defun org-agenda-bulk-unmark ()
8108 "Unmark the entry at point for future bulk action."
8109 (interactive)
8110 (when (org-agenda-bulk-marked-p)
8111 (org-agenda-bulk-remove-overlays
8112 (point-at-bol) (+ 2 (point-at-bol)))
8113 (setq org-agenda-bulk-marked-entries
8114 (delete (org-get-at-bol 'org-hd-marker)
8115 org-agenda-bulk-marked-entries)))
8116 (beginning-of-line 2)
8117 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8118 (beginning-of-line 2))
8119 (message "%d entries marked for bulk action"
8120 (length org-agenda-bulk-marked-entries)))
8122 (defun org-agenda-bulk-toggle ()
8123 "Toggle marking the entry at point for bulk action."
8124 (interactive)
8125 (if (org-agenda-bulk-marked-p)
8126 (org-agenda-bulk-unmark)
8127 (org-agenda-bulk-mark)))
8129 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8130 "Remove the mark overlays between BEG and END in the agenda buffer.
8131 BEG and END default to the buffer limits.
8133 This only removes the overlays, it does not remove the markers
8134 from the list in `org-agenda-bulk-marked-entries'."
8135 (interactive)
8136 (mapc (lambda (ov)
8137 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8138 (delete-overlay ov)))
8139 (overlays-in (or beg (point-min)) (or end (point-max)))))
8141 (defun org-agenda-bulk-remove-all-marks ()
8142 "Remove all marks in the agenda buffer.
8143 This will remove the markers, and the overlays."
8144 (interactive)
8145 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8146 (setq org-agenda-bulk-marked-entries nil)
8147 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
8149 (defun org-agenda-bulk-action (&optional arg)
8150 "Execute an remote-editing action on all marked entries.
8151 The prefix arg is passed through to the command if possible."
8152 (interactive "P")
8153 ;; Make sure we have markers, and only valid ones
8154 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8155 (mapc
8156 (lambda (m)
8157 (unless (and (markerp m)
8158 (marker-buffer m)
8159 (buffer-live-p (marker-buffer m))
8160 (marker-position m))
8161 (error "Marker %s for bulk command is invalid" m)))
8162 org-agenda-bulk-marked-entries)
8164 ;; Prompt for the bulk command
8165 (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
8166 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
8167 (when org-agenda-bulk-custom-functions
8168 (concat " Custom: ["
8169 (mapconcat (lambda(f) (char-to-string (car f)))
8170 org-agenda-bulk-custom-functions "")
8171 "]"))))
8172 (let* ((action (read-char-exclusive))
8173 (org-log-refile (if org-log-refile 'time nil))
8174 (entries (reverse org-agenda-bulk-marked-entries))
8175 redo-at-end
8176 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8177 (cond
8178 ((equal action ?$)
8179 (setq cmd '(org-agenda-archive)))
8181 ((equal action ?A)
8182 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8184 ((member action '(?r ?w))
8185 (setq rfloc (org-refile-get-location
8186 "Refile to"
8187 (marker-buffer (car org-agenda-bulk-marked-entries))
8188 org-refile-allow-creating-parent-nodes))
8189 (if (nth 3 rfloc)
8190 (setcar (nthcdr 3 rfloc)
8191 (move-marker (make-marker) (nth 3 rfloc)
8192 (or (get-file-buffer (nth 1 rfloc))
8193 (find-buffer-visiting (nth 1 rfloc))
8194 (error "This should not happen")))))
8196 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8197 redo-at-end t))
8199 ((equal action ?t)
8200 (setq state (org-icompleting-read
8201 "Todo state: "
8202 (with-current-buffer (marker-buffer (car entries))
8203 (mapcar 'list org-todo-keywords-1))))
8204 (setq cmd `(let ((org-inhibit-blocking t)
8205 (org-inhibit-logging 'note))
8206 (org-agenda-todo ,state))))
8208 ((memq action '(?- ?+))
8209 (setq tag (org-icompleting-read
8210 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8211 (with-current-buffer (marker-buffer (car entries))
8212 (delq nil
8213 (mapcar (lambda (x)
8214 (if (stringp (car x)) x)) org-tag-alist)))))
8215 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8217 ((memq action '(?s ?d))
8218 (let* ((date (unless arg
8219 (org-read-date
8220 nil nil nil
8221 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8222 (ans (if arg nil org-read-date-final-answer))
8223 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8224 (setq cmd `(let* ((bound (fboundp 'read-string))
8225 (old (and bound (symbol-function 'read-string))))
8226 (unwind-protect
8227 (progn
8228 (fset 'read-string (lambda (&rest ignore) ,ans))
8229 (eval '(,c1 arg)))
8230 (if bound
8231 (fset 'read-string old)
8232 (fmakunbound 'read-string)))))))
8234 ((equal action ?S)
8235 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8236 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8237 (let ((days (read-number
8238 (format "Scatter tasks across how many %sdays: "
8239 (if arg "week" "")) 7)))
8240 (setq cmd
8241 `(let ((distance (1+ (random ,days))))
8242 (if arg
8243 (let ((dist distance)
8244 (day-of-week
8245 (calendar-day-of-week
8246 (calendar-gregorian-from-absolute (org-today)))))
8247 (dotimes (i (1+ dist))
8248 (while (member day-of-week org-agenda-weekend-days)
8249 (incf distance)
8250 (incf day-of-week)
8251 (if (= day-of-week 7)
8252 (setq day-of-week 0)))
8253 (incf day-of-week)
8254 (if (= day-of-week 7)
8255 (setq day-of-week 0)))))
8256 ;; silently fail when try to replan a sexp entry
8257 (condition-case nil
8258 (let* ((date (calendar-gregorian-from-absolute
8259 (+ (org-today) distance)))
8260 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8261 (nth 2 date))))
8262 (org-agenda-schedule nil time))
8263 (error nil)))))))
8265 ((assoc action org-agenda-bulk-custom-functions)
8266 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8267 redo-at-end t))
8269 ((equal action ?f)
8270 (setq cmd (list (intern
8271 (org-icompleting-read "Function: "
8272 obarray 'fboundp t nil nil)))))
8274 (t (error "Invalid bulk action")))
8276 ;; Sort the markers, to make sure that parents are handled before children
8277 (setq entries (sort entries
8278 (lambda (a b)
8279 (cond
8280 ((equal (marker-buffer a) (marker-buffer b))
8281 (< (marker-position a) (marker-position b)))
8283 (string< (buffer-name (marker-buffer a))
8284 (buffer-name (marker-buffer b))))))))
8286 ;; Now loop over all markers and apply cmd
8287 (while (setq e (pop entries))
8288 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8289 (if (not pos)
8290 (progn (message "Skipping removed entry at %s" e)
8291 (setq cntskip (1+ cntskip)))
8292 (goto-char pos)
8293 (eval cmd)
8294 (setq org-agenda-bulk-marked-entries
8295 (delete e org-agenda-bulk-marked-entries))
8296 (setq cnt (1+ cnt))))
8297 (setq org-agenda-bulk-marked-entries nil)
8298 (org-agenda-bulk-remove-all-marks)
8299 (when redo-at-end (org-agenda-redo))
8300 (message "Acted on %d entries%s"
8302 (if (= cntskip 0)
8304 (format ", skipped %d (disappeared before their turn)"
8305 cntskip)))))
8307 ;;; Flagging notes
8309 (defun org-agenda-show-the-flagging-note ()
8310 "Display the flagging note in the other window.
8311 When called a second time in direct sequence, offer to remove the FLAGGING
8312 tag and (if present) the flagging note."
8313 (interactive)
8314 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8315 (win (selected-window))
8316 note heading newhead)
8317 (unless hdmarker
8318 (error "No linked entry at point"))
8319 (if (and (eq this-command last-command)
8320 (y-or-n-p "Unflag and remove any flagging note? "))
8321 (progn
8322 (org-agenda-remove-flag hdmarker)
8323 (let ((win (get-buffer-window "*Flagging Note*")))
8324 (and win (delete-window win)))
8325 (message "Entry unflaged"))
8326 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8327 (unless note
8328 (error "No flagging note"))
8329 (org-kill-new note)
8330 (org-switch-to-buffer-other-window "*Flagging Note*")
8331 (erase-buffer)
8332 (insert note)
8333 (goto-char (point-min))
8334 (while (re-search-forward "\\\\n" nil t)
8335 (replace-match "\n" t t))
8336 (goto-char (point-min))
8337 (select-window win)
8338 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8340 (defun org-agenda-remove-flag (marker)
8341 "Remove the FLAGGED tag and any flagging note in the entry."
8342 (let (newhead)
8343 (org-with-point-at marker
8344 (org-toggle-tag "FLAGGED" 'off)
8345 (org-entry-delete nil "THEFLAGGINGNOTE")
8346 (setq newhead (org-get-heading)))
8347 (org-agenda-change-all-lines newhead marker)
8348 (message "Entry unflaged")))
8350 (defun org-agenda-get-any-marker (&optional pos)
8351 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8352 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8354 ;;; Appointment reminders
8356 (defvar appt-time-msg-list)
8358 ;;;###autoload
8359 (defun org-agenda-to-appt (&optional refresh filter)
8360 "Activate appointments found in `org-agenda-files'.
8361 With a \\[universal-argument] prefix, refresh the list of
8362 appointments.
8364 If FILTER is t, interactively prompt the user for a regular
8365 expression, and filter out entries that don't match it.
8367 If FILTER is a string, use this string as a regular expression
8368 for filtering entries out.
8370 FILTER can also be an alist with the car of each cell being
8371 either 'headline or 'category. For example:
8373 '((headline \"IMPORTANT\")
8374 (category \"Work\"))
8376 will only add headlines containing IMPORTANT or headlines
8377 belonging to the \"Work\" category."
8378 (interactive "P")
8379 (if refresh (setq appt-time-msg-list nil))
8380 (if (eq filter t)
8381 (setq filter (read-from-minibuffer "Regexp filter: ")))
8382 (let* ((cnt 0) ; count added events
8383 (org-agenda-new-buffers nil)
8384 (org-deadline-warning-days 0)
8385 ;; Do not use `org-today' here because appt only takes
8386 ;; time and without date as argument, so it may pass wrong
8387 ;; information otherwise
8388 (today (org-date-to-gregorian
8389 (time-to-days (current-time))))
8390 (org-agenda-restrict nil)
8391 (files (org-agenda-files 'unrestricted)) entries file)
8392 ;; Get all entries which may contain an appt
8393 (org-prepare-agenda-buffers files)
8394 (while (setq file (pop files))
8395 (setq entries
8396 (append entries
8397 (org-agenda-get-day-entries
8398 file today :timestamp :scheduled :deadline))))
8399 (setq entries (delq nil entries))
8400 ;; Map thru entries and find if we should filter them out
8401 (mapc
8402 (lambda(x)
8403 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8404 (cat (get-text-property 1 'org-category x))
8405 (tod (get-text-property 1 'time-of-day x))
8406 (ok (or (null filter)
8407 (and (stringp filter) (string-match filter evt))
8408 (and (listp filter)
8409 (or (string-match
8410 (cadr (assoc 'category filter)) cat)
8411 (string-match
8412 (cadr (assoc 'headline filter)) evt))))))
8413 ;; FIXME: Shall we remove text-properties for the appt text?
8414 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8415 (when (and ok tod)
8416 (setq tod (concat "00" (number-to-string tod))
8417 tod (when (string-match
8418 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8419 (concat (match-string 1 tod) ":"
8420 (match-string 2 tod))))
8421 (appt-add tod evt)
8422 (setq cnt (1+ cnt))))) entries)
8423 (org-release-buffers org-agenda-new-buffers)
8424 (if (eq cnt 0)
8425 (message "No event to add")
8426 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8428 (defun org-agenda-todayp (date)
8429 "Does DATE mean today, when considering `org-extend-today-until'?"
8430 (let ((today (org-today))
8431 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8432 date)))
8433 (eq date today)))
8435 (provide 'org-agenda)
8437 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
8439 ;;; org-agenda.el ends here