Browse Source

Implemented filtering of an existing agenda view with respect to a tag.

Carsten Dominik 17 years ago
parent
commit
7482b04df0
5 changed files with 77 additions and 10 deletions
  1. 21 0
      ORGWEBPAGE/Changes.org
  2. 15 8
      doc/org.texi
  3. 2 0
      lisp/ChangeLog
  4. 27 1
      lisp/org-agenda.el
  5. 12 1
      lisp/org.el

+ 21 - 0
ORGWEBPAGE/Changes.org

@@ -32,6 +32,27 @@
 
 
 ** Details
 ** Details
 
 
+*** Secondary filtering of agenda views.
+
+    You can now easily and interactively filter an existing
+    agenda view with respect to a tag.  This command is executed
+    with the =/= key in the agenda.  You will be prompted for a
+    tag selection key, and all entries that do not contain or
+    inherit the corresponding tag will be removed from the agenda
+    view.  With a prefix argument, the complementary filter is
+    applied: entries that do have the tag will be removed.
+    Narrowing the search results down with several successive
+    filtering operations is possible.
+
+    Note that this only removes the entries from the agenda
+    buffer, but it does not modify the query.  Therefore, the =r=
+    and =g= keys will restore the original agenda buffer.
+
+    This functionality was John Wiegleys idea and is a simpler
+    implementation of some of the query-editing features proposed
+    and implemented some time ago by Christopher League (see the
+    file contrib/lisp/org-interactive-query.el).
+
 *** Editing fixed-width regions with picture or artist mode
 *** Editing fixed-width regions with picture or artist mode
 
 
     The command @<code>C-c '@</code> (that is =C-c= followed by a
     The command @<code>C-c '@</code> (that is =C-c= followed by a

+ 15 - 8
doc/org.texi

@@ -5800,21 +5800,28 @@ that entry would be in the original buffer (taken from a property, from a
 @code{#+COLUMNS} line, or from the default variable
 @code{#+COLUMNS} line, or from the default variable
 @code{org-columns-default-format}), will be used in the agenda.
 @code{org-columns-default-format}), will be used in the agenda.
 
 
-@tsubheading{Query editing}
+@tsubheading{Secondary filtering and query editing}
 @cindex query editing, in agenda
 @cindex query editing, in agenda
 
 
+@kindex /
+@item /
+Filter the current agenda view with respect to a tag.  You will be prompted
+for a tag selection letter and all entries that do not contain this tag will
+be removed from the agenda display.  When called with prefix arg, remove the
+entries that @emph{do} have the tag.
+
 @kindex [
 @kindex [
 @kindex ]
 @kindex ]
 @kindex @{
 @kindex @{
 @kindex @}
 @kindex @}
 @item [ ] @{ @}
 @item [ ] @{ @}
-In the @i{search view} (@pxref{Keyword search}), these keys add new
-search words (@kbd{[} and @kbd{]}) or new regular expressions (@kbd{@{}
-and @kbd{@}}) to the query string.  The opening bracket/brace will add a
-positive search term prefixed by @samp{+}, indicating that this search
-term @i{must} occur/match in the entry.  Closing bracket/brace add a
-negative search term which @i{must not} occur/match in the entry for it
-to be selected.
+In the @i{search view} (@pxref{Keyword search}), these keys add new search
+words (@kbd{[} and @kbd{]}) or new regular expressions (@kbd{@{} and
+@kbd{@}}) to the query string.  The opening bracket/brace will add a positive
+search term prefixed by @samp{+}, indicating that this search term @i{must}
+occur/match in the entry.  The closing bracket/brace will add a negative
+search term which @i{must not} occur/match in the entry for it to be
+selected.
 
 
 
 
 @tsubheading{Remote editing}
 @tsubheading{Remote editing}

+ 2 - 0
lisp/ChangeLog

@@ -1,5 +1,7 @@
 2008-09-05  Carsten Dominik  <dominik@science.uva.nl>
 2008-09-05  Carsten Dominik  <dominik@science.uva.nl>
 
 
+	* org-agenda.el (org-agenda-filter-by-tag): New command.
+
 	* org-exp.el (org-get-current-options): Remove angular brackets
 	* org-exp.el (org-get-current-options): Remove angular brackets
 	from the date entry.
 	from the date entry.
 
 

+ 27 - 1
lisp/org-agenda.el

@@ -1159,6 +1159,7 @@ The following commands are available:
 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
+(org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
 
 
 (defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
 (defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
   "Local keymap for agenda entries from Org-mode.")
   "Local keymap for agenda entries from Org-mode.")
@@ -4078,6 +4079,32 @@ When this is the global TODO list, a prefix argument will be interpreted."
     (goto-line line)
     (goto-line line)
     (recenter window-line)))
     (recenter window-line)))
 
 
+(defun org-agenda-filter-by-tag (strip &optional char)
+  "Keep only those lines in the agenda buffer that have a specific tag.
+The tag is selected with its fast selection letter, as configured.
+With prefix argument STRIP, remove all lines that do have the tag."
+  (interactive "P")
+  (let (char a tag (inhibit-read-only t))
+    (message "Tag selection character [%s]"
+	     (mapconcat
+	      (lambda (x) (if (cdr x) (char-to-string (cdr x)) ""))
+	      org-tag-alist-for-agenda ""))
+    (setq char (read-char-exclusive))
+    (unless (setq a (rassoc char org-tag-alist-for-agenda))
+      (error "invalid tag selection character %c" char))
+    (setq tag (car a))
+    (save-excursion
+      (goto-char (point-min))
+      (while (not (eobp))
+	(if (get-text-property (point) 'org-marker)
+	    (progn
+	      (setq tags (get-text-property (point) 'tags))
+	      (if (or (and (member tag tags) strip)
+		      (and (not (member tag tags)) (not strip)))
+		  (delete-region (point) (1+ (point-at-eol)))
+		(beginning-of-line 2)))
+	  (beginning-of-line 2))))))
+
 (defun org-agenda-manipulate-query-add ()
 (defun org-agenda-manipulate-query-add ()
   "Manipulate the query by adding a search term with positive selection.
   "Manipulate the query by adding a search term with positive selection.
 Positive selection means, the term must be matched for selection of an entry."
 Positive selection means, the term must be matched for selection of an entry."
@@ -5316,4 +5343,3 @@ belonging to the \"Work\" category."
 
 
 ;;; org-agenda.el ends here
 ;;; org-agenda.el ends here
 
 
-

+ 12 - 1
lisp/org.el

@@ -1357,6 +1357,8 @@ taken from the (otherwise obsolete) variable `org-todo-interpretation'."
 (make-variable-buffer-local 'org-todo-keywords-1)
 (make-variable-buffer-local 'org-todo-keywords-1)
 (defvar org-todo-keywords-for-agenda nil)
 (defvar org-todo-keywords-for-agenda nil)
 (defvar org-done-keywords-for-agenda nil)
 (defvar org-done-keywords-for-agenda nil)
+(defvar org-todo-keyword-alist-for-agenda nil)
+(defvar org-tag-alist-for-agenda nil)
 (defvar org-agenda-contributing-files nil)
 (defvar org-agenda-contributing-files nil)
 (defvar org-not-done-keywords nil)
 (defvar org-not-done-keywords nil)
 (make-variable-buffer-local 'org-not-done-keywords)
 (make-variable-buffer-local 'org-not-done-keywords)
@@ -12216,6 +12218,11 @@ When a buffer is unmodified, it is just killed.  When modified, it is saved
 		(append org-todo-keywords-for-agenda org-todo-keywords-1))
 		(append org-todo-keywords-for-agenda org-todo-keywords-1))
 	  (setq org-done-keywords-for-agenda
 	  (setq org-done-keywords-for-agenda
 		(append org-done-keywords-for-agenda org-done-keywords))
 		(append org-done-keywords-for-agenda org-done-keywords))
+	  (setq org-todo-keyword-alist-for-agenda
+		(append org-todo-keyword-alist-for-agenda org-todo-key-alist))
+	  (setq org-tag-alist-for-agenda 
+		(append org-tag-alist-for-agenda org-tag-alist))
+
 	  (save-excursion
 	  (save-excursion
 	    (remove-text-properties (point-min) (point-max) pall)
 	    (remove-text-properties (point-min) (point-max) pall)
 	    (when org-agenda-skip-archived-trees
 	    (when org-agenda-skip-archived-trees
@@ -12228,7 +12235,11 @@ When a buffer is unmodified, it is just killed.  When modified, it is saved
 	    (while (re-search-forward re nil t)
 	    (while (re-search-forward re nil t)
 	      (add-text-properties
 	      (add-text-properties
 	       (match-beginning 0) (org-end-of-subtree t) pc)))
 	       (match-beginning 0) (org-end-of-subtree t) pc)))
-	  (set-buffer-modified-p bmp))))))
+	  (set-buffer-modified-p bmp))))
+    (setq debug-on-error t)
+    (setq org-todo-keyword-alist-for-agenda
+	  (org-uniquify org-todo-keyword-alist-for-agenda)
+	  org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
 
 
 ;;;; Embedded LaTeX
 ;;;; Embedded LaTeX