emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kevin Layer <layer@known.net>
To: Emacs-orgmode@gnu.org
Subject: Specialized sparse-tree via hook to show specific view in org mode
Date: Sun, 5 Feb 2023 17:12:28 -0800	[thread overview]
Message-ID: <CAGSZTjLLP9zgsiDrpYoPYF7OaqD7JMwiJO+CdR+b9uKDgZbyxw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2518 bytes --]

Hi.  I've been using Emacs since the 80's but I'm a new org mode user.
What a fantastic piece of software.  I had used my own todo mode, but org
is orders of magnitude better. Thank you!

My main todo file defines various TODO keywords and initial state like this:

#+STARTUP: indent overview
#+TODO: @NOW @NEXT @WIP @PENDING

What I really want is to initially only see items noted with those TODO
keywords and also due items.  Everything else should be hidden.

Since I didn't see an out-of-the-box way to do this, I hacked the following
together.  The purpose of this email is to see if this is the right way (or
a good way).

The hack starts with this at the end of the org file:

* Local Variables
;; Local Variables:
;; eval: (save-window-excursion (my-org-show-sparse-todo-tree))
;; End:

That function is defined thus:

(defun my-org-show-sparse-todo-tree ()
  (interactive)
  (message
   "%d TODO entries found"
   (org-occur (concat "^" org-outline-regexp " *"
     "\\("
     (mapconcat 'identity org-todo-keywords-1 "\\|")
     "\\)\\>")))

  ;; events due before 2 weeks from now:
  (org-check-before-date
   (format-time-string "%Y-%m-%d" (time-add nil (* 3600 8 14)))
   t))

which relies on the redefined version of org-check-before-date, so
keep-previous is passed to org-occur:

(defun org-check-before-date (d &optional keep-previous)
  "Check if there are deadlines or scheduled entries before date D.

Optional argument KEEP-PREVIOUS is passed directly to `org-occur'."
  (interactive (list (org-read-date)))
  (let* ((case-fold-search nil)
(regexp (org-re-timestamp org-ts-type))
(ts-type org-ts-type)
(callback
 (lambda ()
   (let ((match (match-string 1)))
     (and (if (memq ts-type '(active inactive all))
      (eq (org-element-type (save-excursion
      (backward-char)
      (org-element-context)))
  'timestamp)
    (org-at-planning-p))
  (time-less-p
   (org-time-string-to-time match)
   (org-time-string-to-time d)))))))
    (message "%d entries before %s"
    (org-occur regexp keep-previous callback)
    d)))

I find this shows me exactly what I want to see when I finish a task and
want to start something new.

If this is the right way and the maintainer wants me to submit a patch, I
would include these functions to get a new optional for keep-previous,
since they could all plausibly be used for the same thing that
org-check-before-date was:
* org-show-todo-tree
* org-check-deadlines
* org-check-before-date
* org-check-after-date
* org-check-dates-range

Thank you.

Kevin

[-- Attachment #2: Type: text/html, Size: 3372 bytes --]

             reply	other threads:[~2023-02-06  1:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06  1:12 Kevin Layer [this message]
2023-02-07 20:28 ` Specialized sparse-tree via hook to show specific view in org mode Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGSZTjLLP9zgsiDrpYoPYF7OaqD7JMwiJO+CdR+b9uKDgZbyxw@mail.gmail.com \
    --to=layer@known.net \
    --cc=Emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).