emacs-orgmode
[Top][All Lists]
Advanced

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

[O] need function to extract time from timestamp in the description of t


From: Samuel Wales
Subject: [O] need function to extract time from timestamp in the description of the first link in an entry
Date: Thu, 1 Nov 2018 16:29:04 -0700

timestamps in link descriptions use {} instead of [].  are there
functions to get the time from those?

org-entry-get on "TIMESTAMP_IA" will get the time from this:

  * CONVERSATION [2018-11-01 Thu 11:09] cleaned using generic cetaphil

analogously, if the keyword is CONVLINK, i want to get the time from this:

  * CONVLINK [[id:8d3b3ad4-784a-4049-ba42-8409b24e4e7e][{2018-11-01
Thu 11:09} cleaned uvex with generic cetaphil]]

but there is no org-entry-get property for "TIMESTAMP_LINK".

suggestions?


p.s.

i have always used org-entry-get in this old code to sort in both
agenda and outline.  i don't know if this is good code or not.  but it
works wonderfully to abstract over outline and agenda.

(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 in the code below to
get to the outline and do manual parsing or use some other
function.

The idea is to use this as a single way to get most metadata no
matter where you are.
"

  (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.
      ;;
      ;; thus presumably the buffer substring only gets called
      ;; for outline.  otherwise we could maybe do
      ;; (get-text-property (point-at-bol) 'org-marker)
      ;;
      ;; 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.

             ;; fixme 0 is a total guess.  i had had 1.
             (m (or (get-text-property 0 'org-marker s)
                    (get-text-property 0 '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 via email to

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