ソースを参照

Agenda: Allow custom commands to specify a filter preset.

Custom commands can now bind `org-agenda-filter-preset'.  This filter
will then be present in the agenda view and persist through refresh
and further filtering.  Only a new agenda command will remove the
filter again.
Carsten Dominik 16 年 前
コミット
8c412ca71f
3 ファイル変更71 行追加23 行削除
  1. 28 12
      ORGWEBPAGE/Changes.org
  2. 11 0
      lisp/ChangeLog
  3. 32 11
      lisp/org-agenda.el

+ 28 - 12
ORGWEBPAGE/Changes.org

@@ -78,6 +78,18 @@ for example
     package by Taru Karttunen, /org-exp-bibtex.el/.  Kudos to
     Taru for this really nice addition.
 
+*** Custom agenda commands can specify a filter preset
+
+If a custom agenda command specified a value for
+=org-agenda-filter-preset= in its options, the initial view of
+the agenda will be filterd by the specified tags.  Applying a
+filter with =/= will then always add to that preset filter,
+clearing the filter with =/ /= will set it back to the preset.
+
+This is in response to a [[http://thread.gmane.org/gmane.emacs.orgmode/11752][thread on the mailing list]], started by
+Daniel Clemente and with great contributions by Bernt Hansen and
+Matt Lundin.
+
 *** Update of org2rem.el
 
 /org2rem.el/ has been updated significantly and now does a more
@@ -98,18 +110,6 @@ prefer the links to be shown in the text.  In this case, Org will
 make an attempt to wrap the line which may have become
 significantly longer by showing the link.
 
-*** Turning off time-of-day search in headline
-
-Some people like to put a creation time stamp into a headline and
-then get confused if the time-of-day found in there shows up as
-the time-of-day of the deadline/scheduling entry for this
-headline.  The reason for this is that Org searches the headline
-for a free-format time when trying to sort the entry into the
-agenda, and that search accidentally finds the time in the
-creation time stamp or something else that happens to look like a
-time.  If this is more painful than useful for you, configure the
-new variable =org-agenda-search-headline-for-time=.
-
 *** Clustering characters for undo
 
 When typing in Org-mode, undo will now remove up to 20 characters
@@ -191,6 +191,18 @@ Thanks to Austin Frank for requesting some of these changes.
 =M-right= and =M-left= now do demote and promote all headlines in
 an active region.
 
+*** Turning off time-of-day search in headline
+
+Some people like to put a creation time stamp into a headline and
+then get confused if the time-of-day found in there shows up as
+the time-of-day of the deadline/scheduling entry for this
+headline.  The reason for this is that Org searches the headline
+for a free-format time when trying to sort the entry into the
+agenda, and that search accidentally finds the time in the
+creation time stamp or something else that happens to look like a
+time.  If this is more painful than useful for you, configure the
+new variable =org-agenda-search-headline-for-time=.
+
 *** The match syntax for tags/properties is now described in a single place
 
 The manual chapters about tags and about properties now only
@@ -202,6 +214,10 @@ of tag/property matches is described.
 A new =<div id=content>= is wrapped around the entire page,
 everything that is inside =<body>=.
 
+This means that you need to update /org-info.js/ (if you have a
+local copy).  Thanks to Sebastian for making these changes so
+quicky.
+
 *** Faces for priority cookies can now be set freely
 
 The new variable =org-priority-faces= can be used to set faces

+ 11 - 0
lisp/ChangeLog

@@ -1,5 +1,16 @@
 2009-03-03  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-agenda.el (org-agenda-custom-commands-local-options): Add
+	option for tags filter preset.
+	(org-prepare-agenda): Store filter preset as a property on the
+	filter variable.
+	(org-finalize-agenda): Call the filter, if there is a preset.
+	(org-agenda-filter-by-tag): Filter again after clearing the
+	filter, when there still is a preset.
+	(org-agenda-filter-make-matcher, org-agenda-set-mode-name):
+	Include the preset filter.
+	(org-agenda-redo): Apply the filter again, also the preset filter.
+
 	* org-exp.el (org-export-as-html): Use IDs in the correct way.
 
 	* org.el (org-uuidgen-p): New funtion.

+ 32 - 11
lisp/org-agenda.el

@@ -186,15 +186,11 @@ you can \"misuse\" it to also add other text to the header.  However,
 	    (list :tag "Heading for this block"
 		  (const org-agenda-overriding-header)
 		  (string :tag "Headline"))
-	    (list :tag "Any variable"
-		  (variable :tag "Variable")
-		  (sexp :tag "Value (sexp)"))
 	    (list :tag "Files to be searched"
 		  (const org-agenda-files)
 		  (list
 		   (const :format "" quote)
-		   (repeat
-			   (file))))
+		   (repeat (file))))
 	    (list :tag "Sorting strategy"
 		  (const org-agenda-sorting-strategy)
 		  (list
@@ -221,6 +217,12 @@ you can \"misuse\" it to also add other text to the header.  However,
 	    (list :tag "Deadline Warning days"
 		  (const org-deadline-warning-days)
 		  (integer :value 1))
+	    (list :tag "Tags filter preset"
+		  (const org-agenda-filter-preset)
+		  (list
+		   (const :format "" quote)
+		   (repeat
+		    (string :tag "+tag or -tag"))))
 	    (list :tag "Standard skipping condition"
 		  :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
 		  (const org-agenda-skip-function)
@@ -245,7 +247,10 @@ you can \"misuse\" it to also add other text to the header.  However,
 	    (list :tag "Non-standard skipping condition"
 		  :value (org-agenda-skip-function)
 		  (const org-agenda-skip-function)
-		  (sexp :tag "Function or form (quoted!)"))))
+		  (sexp :tag "Function or form (quoted!)"))
+	    (list :tag "Any variable"
+		  (variable :tag "Variable")
+		  (sexp :tag "Value (sexp)"))))
   "Selection of examples for agenda command settings.
 This will be spliced into the custom type of
 `org-agenda-custom-commands'.")
@@ -2221,10 +2226,12 @@ Drawers will be excluded, also the line with scheduling/deadline info."
 (defvar org-agenda-columns-active nil)
 (defvar org-agenda-name nil)
 (defvar org-agenda-filter nil)
+(defvar org-agenda-filter-preset nil)
 (defun org-prepare-agenda (&optional name)
   (setq org-todo-keywords-for-agenda nil)
   (setq org-done-keywords-for-agenda nil)
   (setq org-agenda-filter nil)
+  (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
   (if org-agenda-multi
       (progn
 	(setq buffer-read-only nil)
@@ -2291,6 +2298,8 @@ Drawers will be excluded, also the line with scheduling/deadline info."
 	(org-agenda-dim-blocked-tasks))
       (run-hooks 'org-finalize-agenda-hook)
       (setq org-agenda-type (get-text-property (point) 'org-agenda-type))
+      (when (get 'org-agenda-filter :preset-filter)
+	(org-agenda-filter-apply org-agenda-filter))
       )))
 
 (defun org-agenda-fontify-priorities ()
@@ -4498,17 +4507,20 @@ When this is the global TODO list, a prefix argument will be interpreted."
   (interactive)
   (let* ((org-agenda-keep-modes t)
 	 (filter org-agenda-filter)
+	 (preset (get 'org-agenda-filter :preset-filter))
 	 (cols org-agenda-columns-active)
 	 (line (org-current-line))
 	 (window-line (- line (org-current-line (window-start))))
 	 (lprops (get 'org-agenda-redo-command 'org-lprops)))
+    (put 'org-agenda-filter :preset-filter nil)
     (and cols (org-columns-quit))
     (message "Rebuilding agenda buffer...")
     (org-let lprops '(eval org-agenda-redo-command))
     (setq org-agenda-undo-list nil
 	  org-agenda-pending-undo-list nil)
     (message "Rebuilding agenda buffer...done")
-    (and filter (org-agenda-filter-apply filter))
+    (put 'org-agenda-filter :preset-filter preset)
+    (and (or filter preset) (org-agenda-filter-apply filter))
     (and cols (interactive-p) (org-agenda-columns))
     (goto-line line)
     (recenter window-line)))
@@ -4571,7 +4583,10 @@ to switch to narrowing."
 	(setq tag (org-ido-completing-read
 		   "Tag: " org-global-tags-completion-table))))
     (cond
-     ((equal char ?/) (org-agenda-filter-by-tag-show-all))
+     ((equal char ?/)
+      (org-agenda-filter-by-tag-show-all)
+      (when (get 'org-agenda-filter :preset-filter)
+	(org-agenda-filter-apply org-agenda-filter)))
      ((or (equal char ?\ )
 	  (setq a (rassoc char alist))
 	  (and (>= char ?0) (<= char ?9)
@@ -4595,7 +4610,8 @@ to switch to narrowing."
 (defun org-agenda-filter-make-matcher ()
   "Create the form that tests a line for the agenda filter."
   (let (f f1)
-    (dolist (x org-agenda-filter)
+    (dolist (x (append (get 'org-agenda-filter :preset-filter)
+		       org-agenda-filter))
       (if (member x '("-" "+"))
 	  (setq f1 '(not tags))
 	(if (string-match "[<=>]" x)
@@ -5012,8 +5028,13 @@ With a double `C-u' prefix arg, show *only* log items, nothing else."
 		(if org-agenda-use-time-grid   " Grid"   "")
 		(if (consp org-agenda-show-log) " LogAll"
 		    (if org-agenda-show-log " Log" ""))
-		(if org-agenda-filter
-		    (concat " {" (mapconcat 'identity org-agenda-filter "") "}")
+		(if (or org-agenda-filter (get 'org-agenda-filter
+					       :preset-filter))
+		    (concat " {" (mapconcat
+				  'identity
+				  (append (get 'org-agenda-filter
+					       :preset-filter)
+					  org-agenda-filter) "") "}")
 		  "")
 		(if org-agenda-archives-mode
 		    (if (eq org-agenda-archives-mode t)