[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Re: postponing todos

From: ignotus
Subject: [Orgmode] Re: postponing todos
Date: Sat, 11 Aug 2007 17:31:59 +0200
User-agent: Gnus/5.110003 (No Gnus v0.3) XEmacs/21.4 (Constant Variable, linux)

I hack together something that does what I needed.  I don't know org
internal workings, so it is just a quick and dirty hack.  I don't really
know about agenda views as such, maybe what I want to do is possible
with actual org mode stuff, but with my modification org does exactly
what I want the way I want it.  Please Carsten, consider adding
something like this to org-mode.  

Bastien posted another solution that probably does something very
similar but with lot less internal hacking, Bastien please comment.

> ------------------------------------------------------------------------

GOAL: be able to tell org-tags-view to only list entries, that are not
scheduled into the future.  With org-scan-not-future set to nil, users
get standard org behaviour.

CODE:  one new variable and one modified function (ORG-SCAN-TAGS)
 lines marked with ADDED are added by me.

(defvar org-scan-not-future t           ;<<-- ADDED
  "Don't include entries, that are scheduled into the future.")

(defun org-scan-tags (action matcher &optional todo-only)
  "Scan headline tags with inheritance and produce output ACTION.
ACTION can be `sparse-tree' or `agenda'.  MATCHER is a Lisp form to be
evaluated, testing if a given set of tags qualifies a headline for
inclusion.  When TODO-ONLY is non-nil, only lines with a TODO keyword
are included in the output."
  (let* ((re (concat "[\n\r]" outline-regexp " *\\(\\<\\("
                     (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
                      "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@:]+:\\)?[ \t]*$")))
         (props (list 'face nil
                      'done-face 'org-done
                      'undone-face nil
                      'mouse-face 'highlight
                      'org-not-done-regexp org-not-done-regexp
                      'org-todo-regexp org-todo-regexp
                      'keymap org-agenda-keymap
                      (format "mouse-2 or RET jump to org file %s"
                              (abbreviate-file-name buffer-file-name))))
         (case-fold-search nil)
         (org-props nil)                ; <<-- ADDED
         tags tags-list tags-alist (llast 0) rtn level category i txt
         todo marker entry priority)
      (goto-char (point-min))
      (when (eq action 'sparse-tree) (org-overview))
      (while (re-search-forward re nil t)
        (catch :skip
          (setq org-props               ; <<-- ADDED
                (save-match-data        ; <<-- ADDED
                  (save-excursion       ; <<-- ADDED
                    (save-restriction   ; <<-- ADDED
                      (org-entry-properties))))) ; <<-- ADDED
          (setq todo (if (match-end 1) (match-string 2))
                tags (if (match-end 4) (match-string 4)))
          (goto-char (setq lspos (1+ (match-beginning 0))))
          (setq level (org-reduced-level (funcall outline-level))
                category (org-get-category))
          (setq i llast llast level)
          ;; remove tag lists from same and sublevels
          (while (>= i level)
            (when (setq entry (assoc i tags-alist))
              (setq tags-alist (delete entry tags-alist)))
            (setq i (1- i)))
          ;; add the nex tags
          (when tags
            (setq tags (mapcar 'downcase (org-split-string tags ":"))
                  (cons (cons level tags) tags-alist)))
          ;; compile tags for current headline
          (setq tags-list
                (if org-use-tag-inheritance
                    (apply 'append (mapcar 'cdr 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)))
            (and (eq action 'agenda) (org-agenda-skip))
            ;; list this headline
            (if (eq action 'sparse-tree)
                  (org-show-context 'tags-tree))
              (setq txt (org-format-agenda-item
                          (if org-tags-match-list-sublevels
                              (make-string (1- level) ?.) "")
                         category tags-list)
                    priority (org-get-priority txt))
              (goto-char lspos)
              (setq marker (org-agenda-new-marker))
              (org-add-props txt props
                'org-marker marker 'org-hd-marker marker 'org-category category
                'priority priority 'type "tagsmatch")
              ; v-- ADDED
              (if org-scan-not-future
                  (if (assoc "SCHEDULED" org-props)
                      ;; scheduled for today, or past?
                      (and (<= (org-days-to-time (cdr (assoc "SCHEDULED" 
                           (push txt rtn))
                      ;; not scheduled, keeper
                      (push txt rtn))
                  (push txt rtn))
              ; ^-- ADDED
              ;;(push txt rtn)        ; <<-- ADDED (commented out)
            ;; if we are to skip sublevels, jump to end of subtree
            (or org-tags-match-list-sublevels (org-end-of-subtree t)))
    (when (and (eq action 'sparse-tree)
               (not org-sparse-tree-open-archived-trees))
      (org-hide-archived-subtrees (point-min) (point-max)))
    (nreverse rtn)))

Udv, Ricsi

reply via email to

[Prev in Thread] Current Thread [Next in Thread]