Sfoglia il codice sorgente

Implement including archives into agenda.

trees that are marked with the ARCHIVE tag and even archive files
can now temporarily be included into an agenda view.

Press `v' in the agenda to get trees with ARCHIVE tags.
Press `C-u v' to get archive files included.
Carsten Dominik 17 anni fa
parent
commit
f41be4b87d
5 ha cambiato i file con 109 aggiunte e 42 eliminazioni
  1. 10 1
      doc/org.texi
  2. 2 2
      doc/orgcard.tex
  3. 17 0
      lisp/ChangeLog
  4. 61 16
      lisp/org-agenda.el
  5. 19 23
      lisp/org.el

+ 10 - 1
doc/org.texi

@@ -1006,7 +1006,9 @@ archived subtrees are not exposed, unless you configure the option
 @item
 During agenda view construction (@pxref{Agenda Views}), the content of
 archived trees is ignored unless you configure the option
-@code{org-agenda-skip-archived-trees}.
+@code{org-agenda-skip-archived-trees}, in which case these trees will always
+be included.  In the agenda you can press the @kbd{v} key to get archives
+temporarily included.
 @item
 Archived trees are not exported (@pxref{Exporting}), only the headline
 is.  Configure the details using the variable
@@ -5692,6 +5694,13 @@ Toggle Logbook mode.  In Logbook mode, entries that where marked DONE while
 logging was on (variable @code{org-log-done}) are shown in the agenda,
 as are entries that have been clocked on that day.
 @c
+@kindex v
+@item v
+Toggle Archives mode.  In archives mode, trees that are marked are also
+scanned when producing the agenda.  When you call this command with a
+@kbd{C-u} prefix argument, even all archive files are included.  To exit
+archives mode, press @kbd{v} again.
+@c
 @kindex R
 @item R
 Toggle Clockreport mode.  In clockreport mode, the daily/weekly agenda will

+ 2 - 2
doc/orgcard.tex

@@ -635,10 +635,10 @@ after  ``{\tt :}'', and dictionary words elsewhere.
 \key{toggle inclusion of diary entries}{D}
 \key{toggle time grid for daily schedule}{G}
 \key{toggle display of logbook entries}{l}
+\key{toggle inclusion of archived trees/files}{v / C-u v}
 \key{refresh agenda buffer with any changes}{r / g}
 \key{save all org-mode buffers}{s}
-\key{display the following \kbd{org-agenda-ndays}}{RIGHT}
-\key{display the previous \kbd{org-agenda-ndays}}{LEFT}
+\key{display next/previous day,week,...}{RIGHT/LEFT}
 \key{goto today}{.}
 
 {\bf Remote editing}

+ 17 - 0
lisp/ChangeLog

@@ -1,3 +1,20 @@
+2008-06-19  Carsten Dominik  <dominik@science.uva.nl>
+
+	* org.el (org-agenda-skip-archived-trees): Docstring now
+	discourages using this.
+	(org-scan-tags): Check for org-agenda-archives-mode.
+	(org-map-entries): Make sure org-agenda-archives-mode is nil.
+	(org-agenda-files): Functionality of second arg changed.
+
+	* org-agenda.el (org-agenda-archives-mode): New variable
+	(org-write-agenda, org-prepare-agenda, org-agenda-list)
+	(org-search-view, org-todo-list, org-tags-view)
+	(org-agenda-list-stuck-projects): Call `org-agenda-files' with
+	`ifmode' argument.
+	(org-agenda-quit): Reset the archives mode.
+	(org-agenda-archives-mode): New command.
+	(org-agenda-set-mode-name): Include archives info.
+
 2008-06-18  Carsten Dominik  <dominik@science.uva.nl>
 
 	* org.el (org-paste-subtree): Make sure the yanked headline is

+ 61 - 16
lisp/org-agenda.el

@@ -392,6 +392,13 @@ or `C-c a #' to produce the list."
  :tag "Org Agenda Skip"
  :group 'org-agenda)
 
+(defvar org-agenda-archives-mode nil
+  "Non-nil means, the agenda will include archived items.
+If this is the symbol `trees', trees in the selected agenda scope
+that are marked with the ARCHIVE tag will be included anyway.  When this is
+t, also all archive files associated with the current selection of agenda
+files will be included.")
+
 (defcustom org-agenda-skip-comment-trees t
   "Non-nil means, skip trees that start with teh COMMENT keyword.
 When nil, these trees are also scand by agenda commands."
@@ -1105,6 +1112,7 @@ The following commands are available:
 (org-defkey org-agenda-mode-map "f" 'org-agenda-follow-mode)
 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
+(org-defkey org-agenda-mode-map "v" 'org-agenda-archives-mode)
 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
@@ -1234,14 +1242,25 @@ The following commands are available:
      ["Year View" org-agenda-year-view :active (org-agenda-check-type nil 'agenda)
       :style radio :selected (member org-agenda-ndays '(365 366))]
      "--"
-     ["Show Logbook entries" org-agenda-log-mode
-      :style toggle :selected org-agenda-show-log :active (org-agenda-check-type nil 'agenda 'timeline)]
-     ["Show clock report" org-agenda-clockreport-mode
-     :style toggle :selected org-agenda-clockreport-mode :active (org-agenda-check-type nil 'agenda)]
      ["Include Diary" org-agenda-toggle-diary
-      :style toggle :selected org-agenda-include-diary :active (org-agenda-check-type nil 'agenda)]
+      :style toggle :selected org-agenda-include-diary
+      :active (org-agenda-check-type nil 'agenda)]
      ["Use Time Grid" org-agenda-toggle-time-grid
-      :style toggle :selected org-agenda-use-time-grid :active (org-agenda-check-type nil 'agenda)])
+      :style toggle :selected org-agenda-use-time-grid
+      :active (org-agenda-check-type nil 'agenda)]
+     "--"
+     ["Show clock report" org-agenda-clockreport-mode
+      :style toggle :selected org-agenda-clockreport-mode
+      :active (org-agenda-check-type nil 'agenda)]
+    "--"
+     ["Show Logbook entries" org-agenda-log-mode
+      :style toggle :selected org-agenda-show-log
+      :active (org-agenda-check-type nil 'agenda 'timeline)]
+     ["Include archived trees" org-agenda-archives-mode 
+      :style toggle :selected org-agenda-archives-mode :active t]
+     ["Include archive files" (org-agenda-archives-mode t)
+      :style toggle :selected (eq org-agenda-archives-mode t) :active t
+      :keys "C-u v"])
     ["Write view to file" org-write-agenda t]
     ["Rebuild buffer" org-agenda-redo t]
     ["Save all Org-mode Buffers" org-save-all-org-buffers t]
@@ -1855,7 +1874,8 @@ higher priority settings."
 		   (org-agenda-collect-markers)))
 		 (org-icalendar-verify-function 'org-check-agenda-marker-table)
 		 (org-combined-agenda-icalendar-file file))
-	     (apply 'org-export-icalendar 'combine (org-agenda-files))))
+	     (apply 'org-export-icalendar 'combine
+		    (org-agenda-files nil 'ifmode))))
 	  (t
 	   (let ((bs (buffer-string)))
 	     (find-file file)
@@ -1937,7 +1957,7 @@ higher priority settings."
     (org-agenda-reset-markers)
     (setq org-agenda-contributing-files nil)
     (setq org-agenda-columns-active nil)
-    (org-prepare-agenda-buffers (org-agenda-files))
+    (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
     (setq org-todo-keywords-for-agenda
 	  (org-uniquify org-todo-keywords-for-agenda))
     (setq org-done-keywords-for-agenda
@@ -2032,7 +2052,7 @@ it is through options in org-agenda-custom-commands.")
 Also moves point to the end of the skipped region, so that search can
 continue from there."
   (let ((p (point-at-bol)) to fp)
-    (and org-agenda-skip-archived-trees
+    (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
 	 (get-text-property p :org-archived)
 	 (org-end-of-subtree t)
 	 (throw :skip t))
@@ -2255,7 +2275,7 @@ given in `org-agenda-start-on-weekday'."
   (let* ((org-agenda-start-on-weekday
 	  (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
 	      org-agenda-start-on-weekday nil))
-	 (thefiles (org-agenda-files))
+	 (thefiles (org-agenda-files nil 'ifmode))
 	 (files thefiles)
 	 (today (time-to-days
 		 (time-subtract (current-time)
@@ -2373,7 +2393,7 @@ given in `org-agenda-start-on-weekday'."
 	    (put-text-property s (1- (point)) 'day d)
 	    (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
     (when (and org-agenda-clockreport-mode clocktable-start)
-      (let ((org-agenda-files (org-agenda-files))
+      (let ((org-agenda-files (org-agenda-files nil 'ifmode))
 	    ;; the above line is to ensure the restricted range!
 	    (p org-agenda-clockreport-parameter-plist)
 	    tbl)
@@ -2502,7 +2522,7 @@ in `org-agenda-text-search-extra-files'."
       (setq regexp (pop regexps+))
       (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
 					regexp))))
-    (setq files (org-agenda-files))
+    (setq files (org-agenda-files nil 'ifmode))
     (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
       (pop org-agenda-text-search-extra-files)
       (setq files (org-add-archive-files files)))
@@ -2633,7 +2653,7 @@ for a keyword.  A numeric prefix directly selects the Nth keyword in
     (org-set-local 'org-last-arg arg)
     (setq org-agenda-redo-command
 	  '(org-todo-list (or current-prefix-arg org-last-arg)))
-    (setq files (org-agenda-files)
+    (setq files (org-agenda-files nil 'ifmode)
 	  rtnall nil)
     (while (setq file (pop files))
       (catch 'nextfile
@@ -2690,7 +2710,7 @@ The prefix arg TODO-ONLY limits the search to TODO entries."
     (setq org-agenda-redo-command
 	  (list 'org-tags-view (list 'quote todo-only)
 		(list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
-    (setq files (org-agenda-files)
+    (setq files (org-agenda-files nil 'ifmode)
 	  rtnall nil)
     (while (setq file (pop files))
       (catch 'nextfile
@@ -2827,7 +2847,8 @@ MATCH is being ignored."
 	 (todo (nth 1 org-stuck-projects))
 	 (todo-wds (if (member "*" todo)
 		       (progn
-			 (org-prepare-agenda-buffers (org-agenda-files))
+			 (org-prepare-agenda-buffers (org-agenda-files
+						      nil 'ifmode))
 			 (org-delete-all
 			  org-done-keywords-for-agenda
 			  (copy-sequence org-todo-keywords-for-agenda)))
@@ -4002,7 +4023,8 @@ If ERROR is non-nil, throw an error, otherwise just return nil."
       (if (not (one-window-p)) (delete-window))
       (kill-buffer buf)
       (org-agenda-reset-markers)
-      (org-columns-remove-overlays))
+      (org-columns-remove-overlays)
+      (setq org-agenda-archives-mode nil))
     ;; Maybe restore the pre-agenda window configuration.
     (and org-agenda-restore-windows-after-quit
 	 (not (eq org-agenda-window-setup 'other-frame))
@@ -4340,6 +4362,24 @@ so that the date SD will be in that range."
   (message "Log mode is %s"
 	   (if org-agenda-show-log "on" "off")))
 
+(defun org-agenda-archives-mode (&optional with-files)
+  "Toggle log mode in an agenda buffer."
+  (interactive "P")
+  (setq org-agenda-archives-mode
+	(if with-files t (if org-agenda-archives-mode nil 'trees)))
+  (org-agenda-set-mode-name)
+  (org-agenda-redo)
+  (message
+   "%s"
+   (cond
+    ((eq org-agenda-archives-mode nil)
+     "No archives are included")
+    ((eq org-agenda-archives-mode 'trees)
+     (format "Trees with :%s: tag are included" org-archive-tag))
+    ((eq org-agenda-archives-mode t)
+     (format "Trees with :%s: tag and all active archive files are included"
+	     org-archive-tag)))))
+
 (defun org-agenda-toggle-diary ()
   "Toggle diary inclusion in an agenda buffer."
   (interactive)
@@ -4370,6 +4410,11 @@ so that the date SD will be in that range."
 		(if org-agenda-include-diary   " Diary"  "")
 		(if org-agenda-use-time-grid   " Grid"   "")
 		(if org-agenda-show-log        " Log"    "")
+		(if org-agenda-archives-mode
+		    (if (eq org-agenda-archives-mode t)
+			" Archives"
+		      (format " :%s:" org-archive-tag))
+		  "")
 		(if org-agenda-clockreport-mode " Clock"   "")))
   (force-mode-line-update))
 

+ 19 - 23
lisp/org.el

@@ -2573,7 +2573,9 @@ get the proper fontification."
 
 (defcustom org-agenda-skip-archived-trees t
   "Non-nil means, the agenda will skip any items located in archived trees.
-An archived tree is a tree marked with the tag ARCHIVE."
+An archived tree is a tree marked with the tag ARCHIVE.  The use of this
+variable is no longer recommended, you should leave it at the value t.
+Instead, use the key `v' to cycle the archives-mode in the agenda."
   :group 'org-archive
   :group 'org-agenda-skip
   :type 'boolean)
@@ -9207,6 +9209,7 @@ ACTION can be `set', `up', `down', or a character."
 
 ;;;; Tags
 
+(defvar org-agenda-archives-mode)
 (defun org-scan-tags (action matcher &optional todo-only)
   "Scan headline tags with inheritance and produce output ACTION.
 
@@ -9276,8 +9279,11 @@ only lines with a TODO keyword are included in the output."
 		    (org-remove-uniherited-tags (cdar tags-alist))))
 	  (when (and (or (not todo-only) (member todo org-not-done-keywords))
 		     (eval matcher)
-		     (or (not org-agenda-skip-archived-trees)
-			 (not (member org-archive-tag tags-list))))
+		     (or
+		      (not (member org-archive-tag tags-list))
+		      ;; we have an archive tag, should we use this anyway?
+		      (or (not org-agenda-skip-archived-trees)
+			  (and (eq action 'agenda) org-agenda-archives-mode))))
 	    (unless (eq action 'sparse-tree) (org-agenda-skip))
 
 	    ;; select this headline
@@ -10009,12 +10015,13 @@ the scanner.  The following items can be given here:
              the the function returns t, FUNC will not be called for that
              entry and search will continue from the point where the
              function leaves it."
-  (let* ((org-agenda-skip-archived-trees (memq 'archive skip))
+  (let* ((org-agenda-archives-mode nil) ; just to make sure
+	 (org-agenda-skip-archived-trees (memq 'archive skip))
 	 (org-agenda-skip-comment-trees (memq 'comment skip))
 	 (org-agenda-skip-function
 	  (car (org-delete-all '(comment archive) skip)))
 	 (org-tags-match-list-sublevels t)
-	 matcher pos)
+	 matcher pos file)
 
     (cond
      ((eq match t)   (setq matcher t))
@@ -11839,14 +11846,13 @@ If TMP is non-nil, don't include temporary buffers."
 	   (buffer-list)))
     (delete nil blist)))
 
-(defun org-agenda-files (&optional unrestricted ext)
+(defun org-agenda-files (&optional unrestricted archives)
   "Get the list of agenda files.
 Optional UNRESTRICTED means return the full list even if a restriction
 is currently in place.
-When EXT is non-nil, try to add all files that are created by adding EXT
-to the file nemes.  Basically, this is a way to add the archive files
-to the list, by setting EXT to \"_archive\"  If EXT is non-nil, but not
-a string, \"_archive\" will be used."
+When ARCHIVES is t, include all archive files hat are really being
+used by the agenda files.  If ARCHIVE is `ifmode', do this only if
+`org-agenda-archives-mode' is t."
   (let ((files
 	 (cond
 	  ((and (not unrestricted) (get 'org-agenda-files 'org-restrict)))
@@ -11866,16 +11872,9 @@ a string, \"_archive\" will be used."
 				 (lambda (file)
 				   (and (file-readable-p file) file)))
 				files))))
-    (when ext
-      (setq ext (if (and (stringp ext) (string-match "\\S-" ext))
-		    ext "_archive"))
-      (setq files (apply 'append
-			 (mapcar
-			  (lambda (f)
-			    (if (file-exists-p (concat f ext))
-				(list f (concat f ext))
-			      (list f)))
-			  files))))
+    (when (or (eq archives t)
+	      (and (eq archives 'ifmode) (eq org-agenda-archives-mode t)))
+      (setq files (org-add-archive-files files)))
     files))
 
 (defun org-edit-agenda-file-list ()
@@ -13231,9 +13230,6 @@ See the individual commands for more information."
      ["Cycling opens ARCHIVE trees"
       (setq org-cycle-open-archived-trees (not org-cycle-open-archived-trees))
       :style toggle :selected org-cycle-open-archived-trees]
-     ["Agenda includes ARCHIVE trees"
-      (setq org-agenda-skip-archived-trees (not org-agenda-skip-archived-trees))
-      :style toggle :selected (not org-agenda-skip-archived-trees)]
      "--"
      ["Move Subtree to Archive" org-advertized-archive-subtree t]
  ;    ["Check and Move Children" (org-archive-subtree '(4))