[Org] Add markers to reporting function

In this way, more information can be extracted from the actual formatting
functions.
This commit is contained in:
Daniel - 2017-12-02 20:55:14 +01:00
parent bab4ae2b07
commit e95ca2da9a
Signed by: dbo
GPG Key ID: 4F63DB96D45AA9C6
1 changed files with 32 additions and 28 deletions

View File

@ -969,14 +969,14 @@ Current Task: %`org-clock-current-task; "
clocking times attached, provied they lie between TSTART and clocking times attached, provied they lie between TSTART and
TEND. The resulting list conists of elements of the form TEND. The resulting list conists of elements of the form
(HEADLINE . CLOCK-TIMES) (MARKER . CLOCK-TIMES)
where HEADLINE is the headline of the corresponding task and where MARKER is a marker to the begnning of the corresponding
CLOCK-TIMES consists of cons cells of the form (START . END), heading and CLOCK-TIMES consists of cons cells of the form (START
where START and END are the starting and ending times of a clock . END), where START and END are the starting and ending times of
line for this task. START and END are times as returned by a clock line for this task. START and END are times as returned
FLOAT-TIME, which see. No truncation with respect to TSTART and by FLOAT-TIME, which see. No truncation with respect to TSTART
TEND is done, i.e., START or END may lie outside of these and TEND is done, i.e., START or END may lie outside of these
limits, provided that TSTART END or START TEND." limits, provided that TSTART END or START TEND."
;; adapted from `org-clock-sum ;; adapted from `org-clock-sum
(when (eq major-mode 'org-mode) (when (eq major-mode 'org-mode)
@ -1024,25 +1024,19 @@ limits, provided that TSTART ≤ END or START ≤ TEND."
(push (cons (float-time) (float-time org-clock-start-time)) (push (cons (float-time) (float-time org-clock-start-time))
times)) times))
(when (not (null times)) (when (not (null times))
(setq headline (push (cons (point-marker) times) task-clock-times)
(save-match-data
(let ((heading (thing-at-point 'line t)))
(string-match (format "^\\(\\*+\\)\\(?: +%s\\)?\\(?: %s\\)? +\\(.*?\\)[ \t]*\\(?::\\(?:[A-Za-z]+:\\)+\\)?$"
(regexp-opt org-todo-keywords-1)
org-priority-regexp)
heading)
(match-string 4 heading))))
(push (cons headline times) task-clock-times)
(setq times nil)))))) (setq times nil))))))
task-clock-times))) task-clock-times)))
(defun db/org-timeline-in-range (tstart tend &optional files) (defun db/org-timeline-in-range (tstart tend &optional files)
"Return list of clocked times from FILES between TSTART and TEND. Each element in this list is of the form "Return list of clocked times from FILES between TSTART and
TEND. Each element in this list is of the form
(START END HEADLINE), (START END MARKER),
where START, END, HEADLINE are as return from where START, END, MARKER are as return from
`db/org-clocking-time-in-range, which see. Entries in the resulting list are sorted by START, ascending." `db/org-clocking-time-in-range, which see. Entries in the
resulting list are sorted by START, ascending."
(or files (setq files org-agenda-files)) (or files (setq files org-agenda-files))
(let ((task-clock-times (cl-loop for file in files (let ((task-clock-times (cl-loop for file in files
when (file-exists-p file) when (file-exists-p file)
@ -1050,8 +1044,8 @@ where START, END, HEADLINE are as return from
(find-file-noselect file)) (find-file-noselect file))
(db/org-clocking-time-in-range tstart tend)))) (db/org-clocking-time-in-range tstart tend))))
timeline) timeline)
(cl-dolist (headline task-clock-times) (dolist (headline task-clock-times)
(cl-dolist (clock-time (cdr headline)) (dolist (clock-time (cdr headline))
(push (list (car clock-time) (cdr clock-time) (car headline)) (push (list (car clock-time) (cdr clock-time) (car headline))
timeline))) timeline)))
(setq timeline (setq timeline
@ -1071,12 +1065,22 @@ When not given, FILES defaults to `org-agenda-files."
(insert "|--|\n") (insert "|--|\n")
(insert "| Start | End | Duration | Task |\n") (insert "| Start | End | Duration | Task |\n")
(insert "|--|\n") (insert "|--|\n")
(cl-dolist (entry timeline) (dolist (entry timeline)
(insert (format "| %s | %s | %s min | %s |\n" (cl-destructuring-bind (start end marker) entry
(format-time-string "%Y-%m-%d %H:%m" (elt entry 0)) (insert (format "| %s | %s | %s min | %s |\n"
(format-time-string "%Y-%m-%d %H:%m" (elt entry 1)) (format-time-string "%Y-%m-%d %H:%m" start)
(floor (/ (- (elt entry 1) (elt entry 0)) 60)) (format-time-string "%Y-%m-%d %H:%m" end)
(elt entry 2)))) (floor (/ (- end start) 60))
(save-match-data
(let* ((heading (save-mark-and-excursion
(with-current-buffer (marker-buffer marker)
(goto-char (marker-position marker))
(thing-at-point 'line t)))))
(string-match (format "^\\(\\*+\\)\\(?: +%s\\)?\\(?: %s\\)? +\\(.*?\\)[ \t]*\\(?::\\(?:[A-Za-z]+:\\)+\\)?$"
(regexp-opt org-todo-keywords-1)
org-priority-regexp)
heading)
(match-string 4 heading)))))))
(insert "|--|\n") (insert "|--|\n")
(goto-char (point-min)) (goto-char (point-min))
(org-table-align)) (org-table-align))