emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Samuel Wales <samologist@gmail.com>
To: John Kitchin <jkitchin@andrew.cmu.edu>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: using dates as property?
Date: Mon, 31 Aug 2015 14:52:48 -0700	[thread overview]
Message-ID: <CAJcAo8sVgF1cMUDm3VDN-D-iELZso9WBjR9WH9ZhvfjmZ_tOhA@mail.gmail.com> (raw)
In-Reply-To: <CAJcAo8uTOXx0vwcTbN7S5JBqLVHH4uFNsqt_bf+BZGBgTJtL7A@mail.gmail.com>

and here is my get function, likewise documented only for me and
written a long time ago but works well for me:

(defun alpha-org-entry-get (property &optional sg inherit)
  "Return the value of PROPERTY, whether you are in the outline
or the agenda, by calling `org-entry-get'.

SG \(string given\) is the agenda header string to use \(provided
by user-defined agenda sorting\) or nil.  If it is nil and you
are in the outline, use the current headline directly.  If it is
nil and you are in the agenda, use the current headline by going
to the outline.

INHERIT is the inherit argument for `org-entry-get'.

There are a few questions about Org properties:

  1) What does it mean to get alltags without inheritance or tags
     with inheritance?  I guess org-entry-get was originally
     meant for properties, not tags, so you don't use inherit?
  2) How do you get the first timestamp in an entry?  There seems
     to be no way without specifying the type of timestamp.

According to the manual at the time of this writing, possible
properties include these.

     TODO         The TODO keyword of the entry.
     TAGS         The tags defined directly in the headline.
     ALLTAGS      All tags, including inherited ones.
     CATEGORY     The category of an entry.
     PRIORITY     The priority of the entry, a string with a single letter.
     DEADLINE     The deadline time string, without the angular brackets.
     SCHEDULED    The scheduling timestamp, without the angular brackets.
     CLOSED       When was this entry closed?
     TIMESTAMP    The first keyword-less timestamp in the entry.
       - this works even in the headline
     TIMESTAMP_IA The first inactive timestamp in the entry.
       - this works even in the headline
       - it does not seem to report CLOSED ts -- use CLOSED
     CLOCKSUM     The sum of CLOCK intervals in the subtree.  org-clock-sum
                  must be run first to compute the values.
     ITEM         The content of the entry.

For anything else, you can use marker-buffer to get to the
outline and do manual parsing or use some other function.  Or
possibly modify org-entry-get to understand it and send a patch
to the org mailing list, along with an update of this docstring.

The idea is to use this as a single way to get most metadata no
matter where you are.
"
  ;;=doubtful do we want the literal-nil argument so that we can
  ;;ret "nil" as string?  check elsewhere here for nil vs. string
  ;;for todo kw or whatever.  we only need it if it helps with
  ;;consistency.  not important and prob useless for this
  ;;purpose.  (other ways of getting todo kw will not obey it so
  ;;it might not help.)
  ;;
  ;; fixme org-cached-entry-get
  (org-entry-get
   (ecase major-mode
     ((org-agenda-mode)
;;;
;;; will this work faster?  or is this for something other than
;;; agenda?
;;;
;;; my guess is it is just for doing things not getting things
;;;
;;; (org-with-point-at (org-get-at-bol 'org-hd-marker)
;;;     ;; do here what you need to do at the location of the entry
;;;     )

      ;; sg is provided by programmatic agenda use in sorting.
      ;;
      ;; should also be provided in sorting filter.
      ;;
      ;; is the buffer substring only needed for outline?  could
      ;; we get property from the agenda for sorting to avoid the
      ;; buffer substring?
      ;;
      ;; fixme for speed maybe we can get from the agenda buffer
      ;; if sg is not provided.  fixme check if sg is provided.
      ;; however, if we use
      ;; org-agenda-before-sorting-filter-function, it is
      ;; provided i guess.
      (let* ((s (or sg (buffer-substring (point-at-bol)
                                         (point-at-eol))))
             ;; get marker from sg or string
             ;;
             ;; what is the difference between these? supposedly
             ;; hd-marker is not always there.
             (m (or (get-text-property 1 'org-marker s)
                    (get-text-property 1 'org-hd-marker s))))
        ;;do this to get to the org outline buffer from the
        ;;agenda buffer if you need other data that org-entry-get
        ;;cannot extract
        ;;
        ;;(b (and m (marker-buffer m))))
;;;        (if b
;;;            (with-current-buffer b
;;;              (goto-char m)
        m))
     ((org-mode) (point)))
   property
   inherit))

  reply	other threads:[~2015-08-31 21:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-31 11:02 using dates as property? John Kitchin
2015-08-31 21:43 ` Samuel Wales
2015-08-31 21:49   ` Samuel Wales
2015-08-31 21:52     ` Samuel Wales [this message]
2015-09-05  0:31   ` John Kitchin

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=CAJcAo8sVgF1cMUDm3VDN-D-iELZso9WBjR9WH9ZhvfjmZ_tOhA@mail.gmail.com \
    --to=samologist@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jkitchin@andrew.cmu.edu \
    /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).