Function: org-clock-get-table-data
org-clock-get-table-data is a byte-compiled function defined in
org-clock.el.gz.
Signature
(org-clock-get-table-data FILE PARAMS)
Documentation
Get the clocktable data for file FILE, with parameters PARAMS.
FILE is only for identification - this function assumes that the correct buffer is current, and that the wanted restriction is in place. The return value will be a list with the file name and the total file time (in minutes) as 1st and 2nd elements. The third element of this list will be a list of headline entries. Each entry has the following structure:
(LEVEL HEADLINE TAGS TIMESTAMP TIME PROPERTIES)
LEVEL: The level of the headline, as an integer. This will be
the reduced level, so 1,2,3,... even if only odd levels
are being used.
HEADLINE: The text of the headline. Depending on PARAMS, this may
already be formatted like a link.
TAGS: The list of tags of the headline.
TIMESTAMP: If PARAMS require it, this will be a time stamp found in the
entry, any of SCHEDULED, DEADLINE, NORMAL, or first inactive,
in this sequence.
TIME: The sum of all time spend in this tree, in minutes. This time
will of cause be restricted to the time block and tags match
specified in PARAMS.
PROPERTIES: The list properties specified in the :properties parameter
along with their value, as an alist following the pattern
(NAME . VALUE).
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-clock.el.gz
(defun org-clock-get-table-data (file params)
"Get the clocktable data for file FILE, with parameters PARAMS.
FILE is only for identification - this function assumes that
the correct buffer is current, and that the wanted restriction is
in place.
The return value will be a list with the file name and the total
file time (in minutes) as 1st and 2nd elements. The third element
of this list will be a list of headline entries. Each entry has the
following structure:
(LEVEL HEADLINE TAGS TIMESTAMP TIME PROPERTIES)
LEVEL: The level of the headline, as an integer. This will be
the reduced level, so 1,2,3,... even if only odd levels
are being used.
HEADLINE: The text of the headline. Depending on PARAMS, this may
already be formatted like a link.
TAGS: The list of tags of the headline.
TIMESTAMP: If PARAMS require it, this will be a time stamp found in the
entry, any of SCHEDULED, DEADLINE, NORMAL, or first inactive,
in this sequence.
TIME: The sum of all time spend in this tree, in minutes. This time
will of cause be restricted to the time block and tags match
specified in PARAMS.
PROPERTIES: The list properties specified in the `:properties' parameter
along with their value, as an alist following the pattern
(NAME . VALUE)."
(let* ((maxlevel (or (plist-get params :maxlevel) 3))
(timestamp (plist-get params :timestamp))
(ts (plist-get params :tstart))
(te (plist-get params :tend))
(ws (plist-get params :wstart))
(ms (plist-get params :mstart))
(block (plist-get params :block))
(link (plist-get params :link))
(tags (plist-get params :tags))
(match (plist-get params :match))
(properties (plist-get params :properties))
(inherit-property-p (plist-get params :inherit-props))
(matcher (and match (cdr (org-make-tags-matcher match))))
cc st p tbl)
(setq org-clock-file-total-minutes nil)
(when block
(setq cc (org-clock-special-range block nil t ws ms)
ts (car cc)
te (nth 1 cc)))
(when (integerp ts) (setq ts (calendar-gregorian-from-absolute ts)))
(when (integerp te) (setq te (calendar-gregorian-from-absolute te)))
(when (and ts (listp ts))
(setq ts (format "%4d-%02d-%02d" (nth 2 ts) (car ts) (nth 1 ts))))
(when (and te (listp te))
(setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
;; Now the times are strings we can parse.
(if ts (setq ts (org-matcher-time ts)))
(if te (setq te (org-matcher-time te)))
(save-excursion
(org-clock-sum ts te
(when matcher
(lambda ()
(let* ((todo (org-get-todo-state))
(tags-list (org-get-tags))
(org-scanner-tags tags-list)
(org-trust-scanner-tags t))
(funcall matcher todo tags-list nil)))))
(goto-char (point-min))
(setq st t)
(while (or (and (bobp) (prog1 st (setq st nil))
(get-text-property (point) :org-clock-minutes)
(setq p (point-min)))
(setq p (next-single-property-change
(point) :org-clock-minutes)))
(goto-char p)
(let ((time (get-text-property p :org-clock-minutes)))
(when (and time (> time 0) (org-at-heading-p))
(let ((level (org-reduced-level (org-current-level))))
(when (<= level maxlevel)
(let* ((headline (org-get-heading t t t t))
(hdl
(if (not link) headline
(let ((search
(org-link-heading-search-string headline)))
(org-link-make-string
(if (not (buffer-file-name)) search
(format "file:%s::%s" (buffer-file-name) search))
;; Prune statistics cookies. Replace
;; links with their description, or
;; a plain link if there is none.
(org-trim
(org-link-display-format
(replace-regexp-in-string
"\\[[0-9]*\\(?:%\\|/[0-9]*\\)\\]" ""
headline)))))))
(tgs (and tags (org-get-tags)))
(tsp
(and timestamp
(cl-some (lambda (p) (org-entry-get (point) p))
'("SCHEDULED" "DEADLINE" "TIMESTAMP"
"TIMESTAMP_IA"))))
(props
(and properties
(delq nil
(mapcar
(lambda (p)
(let ((v (org-entry-get
(point) p inherit-property-p)))
(and v (cons p v))))
properties)))))
(push (list level hdl tgs tsp time props) tbl)))))))
(list file org-clock-file-total-minutes (nreverse tbl)))))