Merge from emacs-24; up to 2012-04-22T13:58:00Z!cyd@gnu.org
[bpt/emacs.git] / lisp / org / org-agenda.el
index bdf6881..ddb56ca 100644 (file)
@@ -247,9 +247,7 @@ you can \"misuse\" it to also add other text to the header.  However,
 
 ;; Keep custom values for `org-agenda-filter-preset' compatible with
 ;; the new variable `org-agenda-tag-filter-preset'.
-(if (fboundp 'defvaralias)
-    (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
-    (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
+(defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
 
 (defconst org-agenda-custom-commands-local-options
   `(repeat :tag "Local settings for this command. Remember to quote values"
@@ -306,11 +304,13 @@ you can \"misuse\" it to also add other text to the header.  However,
                    (string :tag "+tag or -tag"))))
            (list :tag "Set daily/weekly entry types"
                  (const org-agenda-entry-types)
-                 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
-                      (const :deadline)
-                      (const :scheduled)
-                      (const :timestamp)
-                      (const :sexp)))
+                 (list
+                  (const :format "" quote)
+                  (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
+                       (const :deadline)
+                       (const :scheduled)
+                       (const :timestamp)
+                       (const :sexp))))
            (list :tag "Standard skipping condition"
                  :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
                  (const org-agenda-skip-function)
@@ -408,7 +408,7 @@ where
 
 desc   A description string to be displayed in the dispatcher menu.
 cmd    An agenda command, similar to the above.  However, tree commands
-       are no allowed, but instead you can get agenda and global todo list.
+       are not allowed, but instead you can get agenda and global todo list.
        So valid commands for a set are:
        (agenda \"\" settings)
        (alltodo \"\" settings)
@@ -649,6 +649,7 @@ See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
 to make his option also apply to the tags-todo list."
   :group 'org-agenda-skip
   :group 'org-agenda-todo-list
+  :version "24.1"
   :type '(choice
          (const :tag "Ignore future timestamp todos" future)
          (const :tag "Ignore past or present timestamp todos" past)
@@ -796,6 +797,7 @@ trigger you to schedule it, and then you don't want to be reminded of it
 because you will take care of it on the day when scheduled."
   :group 'org-agenda-skip
   :group 'org-agenda-daily/weekly
+  :version "24.1"
   :type '(choice
          (const :tag "Alwas show prewarning" nil)
          (const :tag "Remove prewarning if entry is scheduled" t)
@@ -860,6 +862,7 @@ property so than moving the mouse over the command shows it.
 Setting it to nil is good if matcher strings are very long and/or if
 you want to use two-column display (see `org-agenda-menu-two-column')."
   :group 'org-agenda
+  :version "24.1"
   :type 'boolean)
 
 (defcustom org-agenda-menu-two-column nil
@@ -867,6 +870,7 @@ you want to use two-column display (see `org-agenda-menu-two-column')."
 If you use this, you probably want to set `org-agenda-menu-show-matcher'
 to nil."
   :group 'org-agenda
+  :version "24.1"
   :type 'boolean)
 
 (defcustom org-finalize-agenda-hook nil
@@ -890,6 +894,7 @@ Needs to be set before org.el is loaded."
   "Non-nil means `org-agenda-follow-mode' displays only the
 current item's tree, in an indirect buffer."
   :group 'org-agenda
+  :version "24.1"
   :type 'boolean)
 
 (defcustom org-agenda-show-outline-path t
@@ -1042,11 +1047,13 @@ This function makes sure that dates are aligned for easy reading."
   "Non-nil means use leading zero for military times in agenda.
 For example, 9:30am would become 09:30 rather than  9:30."
   :group 'org-agenda-daily/weekly
+  :version "24.1"
   :type 'boolean)
 
 (defcustom org-agenda-timegrid-use-ampm nil
   "When set, show AM/PM style timestamps on the timegrid."
   :group 'org-agenda
+  :version "24.1"
   :type 'boolean)
 
 (defun org-agenda-time-of-day-to-ampm (time)
@@ -1094,6 +1101,7 @@ stamp currently points to the past, the first key press will move it
 to today.  WHen nil, just move one day forward even if the date stays
 in the past."
   :group 'org-agenda-daily/weekly
+  :version "24.1"
   :type 'boolean)
 
 (defcustom org-agenda-include-diary nil
@@ -1106,6 +1114,7 @@ Custom commands can set this variable in the options section."
   "If non-nil, include entries within their deadline warning period.
 Custom commands can set this variable in the options section."
   :group 'org-agenda-daily/weekly
+  :version "24.1"
   :type 'boolean)
 
 (defcustom org-agenda-repeating-timestamp-show-all t
@@ -1181,6 +1190,7 @@ issue display.
 :short-face           face for clock intervals that are too short"
   :group 'org-agenda-daily/weekly
   :group 'org-clock
+  :version "24.1"
   :type 'plist)
 
 (defcustom org-agenda-log-mode-add-notes t
@@ -1239,6 +1249,7 @@ by preceding the first snippet with \"+\" or \"-\".  If the first snippet
 is a regexp marked with braces like \"{abc}\", this will also switch to
 boolean search."
   :group 'org-agenda-search-view
+  :version "24.1"
   :type 'boolean)
 
 (if (fboundp 'defvaralias)
@@ -1249,6 +1260,7 @@ boolean search."
   "Non-nil means, search words must be matches as complete words.
 When nil, they may also match part of a word."
   :group 'org-agenda-search-view
+  :version "24.1"
   :type 'boolean)
 
 (defgroup org-agenda-time-grid nil
@@ -1312,12 +1324,14 @@ a grid line."
 (defcustom org-agenda-show-current-time-in-grid t
   "Non-nil means show the current time in the time grid."
   :group 'org-agenda-time-grid
+  :version "24.1"
   :type 'boolean)
 
 (defcustom org-agenda-current-time-string
   "now - - - - - - - - - - - - - - - - - - - - - - - - -"
   "The string for the current time marker in the agenda."
   :group 'org-agenda-time-grid
+  :version "24.1"
   :type 'string)
 
 (defgroup org-agenda-sorting nil
@@ -1528,6 +1542,7 @@ that passed since this item was scheduled first."
   "Text preceding item pulled into the agenda by inactive time stamps.
 These entries are added to the agenda when pressing \"[\"."
   :group 'org-agenda-line-format
+  :version "24.1"
   :type '(list
          (string :tag "Scheduled today     ")
          (string :tag "Scheduled previously")))
@@ -1566,6 +1581,7 @@ the headline/diary entry."
   "Non-nil means remove time ranges specifications in agenda
 items that span on several days."
   :group 'org-agenda-line-format
+  :version "24.1"
   :type 'boolean)
 
 (defcustom org-agenda-default-appointment-duration nil
@@ -1647,6 +1663,7 @@ The only argument passed to that function is the day. It should
 returns a face, or nil if does not want to specify a face and let
 the normal rules apply."
   :group 'org-agenda-line-format
+  :version "24.1"
   :type 'function)
 
 (defcustom org-agenda-category-icon-alist nil
@@ -1679,6 +1696,7 @@ category, you can use:
 
   (\"Emacs\" '(space . (:width (16))))"
   :group 'org-agenda-line-format
+  :version "24.1"
   :type '(alist :key-type (string :tag "Regexp matching category")
                :value-type (choice (list :tag "Icon"
                                          (string :tag "File or data")
@@ -1741,6 +1759,7 @@ With selected entries in an agenda buffer, `B R' will call
 the custom function `set-category' on the selected entries.
 Note that functions in this alist don't need to be quoted."
   :type 'alist
+  :version "24.1"
   :group 'org-agenda)
 
 (eval-when-compile
@@ -1770,7 +1789,7 @@ works you probably want to add it to `org-agenda-custom-commands' for good."
        (setcdr ass (cdr entry))
       (push entry org-agenda-custom-commands))))
 
-;;; Define the org-agenda-mode
+;;; Define the Org-agenda-mode
 
 (defvar org-agenda-mode-map (make-sparse-keymap)
   "Keymap for `org-agenda-mode'.")
@@ -3075,7 +3094,6 @@ the global options and expect it to be applied to the entire view.")
 
 (defun org-prepare-agenda (&optional name)
   (setq org-todo-keywords-for-agenda nil)
-  (setq org-done-keywords-for-agenda nil)
   (setq org-drawers-for-agenda nil)
   (unless org-agenda-persistent-filter
     (setq org-agenda-tag-filter nil
@@ -3094,6 +3112,7 @@ the global options and expect it to be applied to the entire view.")
                    (make-string (window-width) org-agenda-block-separator))
                  "\n"))
        (narrow-to-region (point) (point-max)))
+    (setq org-done-keywords-for-agenda nil)
     (org-agenda-reset-markers)
     (setq org-agenda-contributing-files nil)
     (setq org-agenda-columns-active nil)
@@ -4221,7 +4240,7 @@ See `org-agenda-skip-if' for details."
 (defun org-agenda-skip-if (subtree conditions)
   "Checks current entity for CONDITIONS.
 If SUBTREE is non-nil, the entire subtree is checked.  Otherwise, only
-the entry, i.e. the text before the next heading is checked.
+the entry (i.e. the text before the next heading) is checked.
 
 CONDITIONS is a list of symbols, boolean OR is used to combine the results
 from different tests.  Valid conditions are:
@@ -4247,12 +4266,12 @@ keywords, which may include \"*\" to match any todo keyword.
 
 would skip all entries with \"TODO\" or \"WAITING\" keywords.
 
-Instead of a list a keyword class may be given
+Instead of a list, a keyword class may be given.  For example:
 
     (org-agenda-skip-entry-if 'nottodo 'done)
 
 would skip entries that haven't been marked with any of \"DONE\"
-keywords. Possible classes are: `todo', `done', `any'.
+keywords.  Possible classes are: `todo', `done', `any'.
 
 If any of these conditions is met, this function returns the end point of
 the entity, causing the search to continue from there.  This is a function
@@ -4285,8 +4304,8 @@ that can be put into `org-agenda-skip-function' for the duration of a command."
           (stringp (nth 1 m))
           (not (re-search-forward (nth 1 m) end t)))
       (and (or
-           (setq m (memq 'todo conditions))
-           (setq m (memq 'nottodo conditions)))
+           (setq m (memq 'nottodo conditions))
+           (setq m (memq 'todo conditions)))
           (org-agenda-skip-if-todo m end)))
      end)))
 
@@ -4377,7 +4396,7 @@ of what a project is and how to check if it stuck, customize the variable
 ;;; Diary integration
 
 (defvar org-disable-agenda-to-diary nil)          ;Dynamically-scoped param.
-(defvar diary-list-entries-hook)
+(defvar list-diary-entries-hook)
 (defvar diary-time-regexp)
 (defun org-get-entries-from-diary (date)
   "Get the (Emacs Calendar) diary entries for DATE."
@@ -4386,8 +4405,8 @@ of what a project is and how to check if it stuck, customize the variable
         (diary-display-hook '(fancy-diary-display))
         (diary-display-function 'fancy-diary-display)
         (pop-up-frames nil)
-        (diary-list-entries-hook
-         (cons 'org-diary-default-entry diary-list-entries-hook))
+        (list-diary-entries-hook
+         (cons 'org-diary-default-entry list-diary-entries-hook))
         (diary-file-name-prefix-function nil) ; turn this feature off
         (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
         entries
@@ -5870,8 +5889,18 @@ could bind the variable in the options section of a custom command.")
       (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
        (setq re (get-text-property 0 'org-todo-regexp x))
        (when (and re
+                  ;; Test `pl' because if there's no heading content,
+                  ;; there's no point matching to highlight.  Note
+                  ;; that if we didn't test `pl' first, and there
+                  ;; happened to be no keyword from `org-todo-regexp'
+                  ;; on this heading line, then the `equal' comparison
+                  ;; afterwards would spuriously succeed in the case
+                  ;; where `pl' is nil -- causing an args-out-of-range
+                  ;; error when we try to add text properties to text
+                  ;; that isn't there.
+                  pl
                   (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
-                                       x (or pl 0)) pl))
+                                       x pl) pl))
          (add-text-properties
           (or (match-end 1) (match-end 0)) (match-end 0)
           (list 'face (org-get-todo-face (match-string 2 x)))
@@ -6182,8 +6211,8 @@ When this is the global TODO list, a prefix argument will be interpreted."
     (recenter window-line)))
 
 (defvar org-global-tags-completion-table nil)
-(defvar org-agenda-filtered-by-category nil)
 (defvar org-agenda-filter-form nil)
+(defvar org-agenda-filtered-by-category nil)
 
 (defun org-agenda-filter-by-category (strip)
   "Keep only those lines in the agenda buffer that have a specific category.
@@ -6336,7 +6365,9 @@ to switch to narrowing."
     (dolist (x (delete-dups
                (append (get 'org-agenda-category-filter
                             :preset-filter) org-agenda-category-filter)))
-      (setq f1 (list 'equal (substring x 1) 'cat))
+      (if (equal "-" (substring x 0 1))
+         (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
+       (setq f1 (list 'equal (substring x 1) 'cat)))
       (push f1 f))
     (cons 'and (nreverse f))))
 
@@ -6367,9 +6398,13 @@ If the line does not have an effort defined, return nil."
   (let (tags cat)
     (if (eq type 'tag)
        (setq org-agenda-tag-filter filter)
-      (setq org-agenda-category-filter filter
-           org-agenda-filtered-by-category t))
+      (setq org-agenda-category-filter filter))
     (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
+    (if (and (eq type 'category)
+            (not (equal (substring (car filter) 0 1) "-")))
+       ;; Only set `org-agenda-filtered-by-category' to t
+       ;; when a unique category is used as the filter
+       (setq org-agenda-filtered-by-category t))
     (org-agenda-set-mode-name)
     (save-excursion
       (goto-char (point-min))
@@ -6383,7 +6418,7 @@ If the line does not have an effort defined, return nil."
              (beginning-of-line 2))
          (beginning-of-line 2))))
     (if (get-char-property (point) 'invisible)
-       (org-agenda-previous-line))))
+       (ignore-errors (org-agenda-previous-line)))))
 
 (defun org-agenda-filter-hide-line (type)
   (let (ov)
@@ -7282,16 +7317,18 @@ use the dedicated frame)."
   (if (and current-prefix-arg (listp current-prefix-arg))
       (org-agenda-do-tree-to-indirect-buffer)
     (let ((agenda-window (selected-window))
-          (indirect-window (get-buffer-window org-last-indirect-buffer)))
+          (indirect-window
+          (and org-last-indirect-buffer
+               (get-buffer-window org-last-indirect-buffer))))
       (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
       (unwind-protect
           (progn
-            (unless indirect-window
+            (unless (and indirect-window (window-live-p indirect-window))
               (setq indirect-window (split-window agenda-window)))
             (select-window indirect-window)
             (switch-to-buffer org-last-indirect-buffer :norecord)
             (fit-window-to-buffer indirect-window))
-        (select-window agenda-window)))))
+        (select-window (get-buffer-window org-agenda-buffer-name))))))
 
 (defun org-agenda-do-tree-to-indirect-buffer ()
   "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
@@ -7986,6 +8023,7 @@ top-level    as top-level entries at the end of the file."
 (defcustom org-agenda-insert-diary-extract-time nil
   "Non-nil means extract any time specification from the diary entry."
   :group 'org-agenda
+  :version "24.1"
   :type 'boolean)
 
 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
@@ -8256,7 +8294,7 @@ This is a command that has to be installed in `calendar-mode-map'."
 (defun org-agenda-bulk-mark (&optional arg)
   "Mark the entry at point for future bulk action."
   (interactive "p")
-  (dotimes (i (max arg 1))
+  (dotimes (i (or arg 1))
     (unless (org-get-at-bol 'org-agenda-diary-link)
       (let* ((m (org-get-at-bol 'org-hd-marker))
             ov)