Skip to content

Instantly share code, notes, and snippets.

@tsu-nera
Forked from ffevotte/clocktable-by-tag.el
Last active July 22, 2020 00:31
Show Gist options
  • Save tsu-nera/d9ffa6a51a6e7bdb957b to your computer and use it in GitHub Desktop.
Save tsu-nera/d9ffa6a51a6e7bdb957b to your computer and use it in GitHub Desktop.

Revisions

  1. tsu-nera revised this gist Dec 28, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion clocktable-by-tag.el
    Original file line number Diff line number Diff line change
    @@ -45,4 +45,4 @@
    (clocktable-by-tag/insert-tag params))
    tags)))

    (provide clocktable-by-tag)
    (provide 'clocktable-by-tag)
  2. tsu-nera revised this gist Dec 28, 2014. 1 changed file with 25 additions and 21 deletions.
    46 changes: 25 additions & 21 deletions clocktable-by-tag.el
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    (require 'org-table)
    (require 'org-clock)

    (defun clocktable-by-tag/shift-cell (n)
    (let ((str ""))
    (dotimes (i n)
    @@ -9,36 +12,37 @@
    (insert "|--\n")
    (insert (format "| %s | *Tag time* |\n" tag))
    (let ((total 0))
    (mapcar
    ;; (mapcar
    (mapc
    (lambda (file)
    (let ((clock-data (with-current-buffer (find-file-noselect file)
    (org-clock-get-table-data (buffer-name) params))))
    (when (> (nth 1 clock-data) 0)
    (setq total (+ total (nth 1 clock-data)))
    (insert (format "| | File *%s* | %.2f |\n"
    (file-name-nondirectory file)
    (/ (nth 1 clock-data) 60.0)))
    (dolist (entry (nth 2 clock-data))
    (insert (format "| | . %s%s | %s %.2f |\n"
    (org-clocktable-indent-string (nth 0 entry))
    (nth 1 entry)
    (clocktable-by-tag/shift-cell (nth 0 entry))
    (/ (nth 3 entry) 60.0)))))))
    (let ((clock-data (with-current-buffer (find-file-noselect file)
    (org-clock-get-table-data (buffer-name) params))))
    (when (> (nth 1 clock-data) 0)
    (setq total (+ total (nth 1 clock-data)))
    (insert (format "| | File *%s* | %.2f |\n"
    (file-name-nondirectory file)
    (/ (nth 1 clock-data) 60.0)))
    (dolist (entry (nth 2 clock-data))
    (insert (format "| | . %s%s | %s %.2f |\n"
    (org-clocktable-indent-string (nth 0 entry))
    (nth 1 entry)
    (clocktable-by-tag/shift-cell (nth 0 entry))
    (/ (nth 3 entry) 60.0)))))))
    (org-agenda-files))
    (save-excursion
    (re-search-backward "*Tag time*")
    (org-table-next-field)
    (org-table-blank-field)
    (insert (format "*%.2f*" (/ total 60.0)))))
    (re-search-backward "*Tag time*")
    (org-table-next-field)
    (org-table-blank-field)
    (insert (format "*%.2f*" (/ total 60.0)))))
    (org-table-align)))

    (defun org-dblock-write:clocktable-by-tag (params)
    (insert "| Tag | Headline | Time (h) |\n")
    (insert "| | | <r> |\n")
    (let ((tags (plist-get params :tags)))
    (mapcar (lambda (tag)
    (setq params (plist-put params :tags tag))
    (clocktable-by-tag/insert-tag params))
    tags)))
    (setq params (plist-put params :tags tag))
    (clocktable-by-tag/insert-tag params))
    tags)))

    (provide clocktable-by-tag)
  3. tsu-nera revised this gist Dec 28, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion clocktable-by-tag.el
    Original file line number Diff line number Diff line change
    @@ -39,4 +39,6 @@
    (mapcar (lambda (tag)
    (setq params (plist-put params :tags tag))
    (clocktable-by-tag/insert-tag params))
    tags)))
    tags)))

    (provide clocktable-by-tag)
  4. @ffevotte ffevotte created this gist Jul 1, 2013.
    42 changes: 42 additions & 0 deletions clocktable-by-tag.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    (defun clocktable-by-tag/shift-cell (n)
    (let ((str ""))
    (dotimes (i n)
    (setq str (concat str "| ")))
    str))

    (defun clocktable-by-tag/insert-tag (params)
    (let ((tag (plist-get params :tags)))
    (insert "|--\n")
    (insert (format "| %s | *Tag time* |\n" tag))
    (let ((total 0))
    (mapcar
    (lambda (file)
    (let ((clock-data (with-current-buffer (find-file-noselect file)
    (org-clock-get-table-data (buffer-name) params))))
    (when (> (nth 1 clock-data) 0)
    (setq total (+ total (nth 1 clock-data)))
    (insert (format "| | File *%s* | %.2f |\n"
    (file-name-nondirectory file)
    (/ (nth 1 clock-data) 60.0)))
    (dolist (entry (nth 2 clock-data))
    (insert (format "| | . %s%s | %s %.2f |\n"
    (org-clocktable-indent-string (nth 0 entry))
    (nth 1 entry)
    (clocktable-by-tag/shift-cell (nth 0 entry))
    (/ (nth 3 entry) 60.0)))))))
    (org-agenda-files))
    (save-excursion
    (re-search-backward "*Tag time*")
    (org-table-next-field)
    (org-table-blank-field)
    (insert (format "*%.2f*" (/ total 60.0)))))
    (org-table-align)))

    (defun org-dblock-write:clocktable-by-tag (params)
    (insert "| Tag | Headline | Time (h) |\n")
    (insert "| | | <r> |\n")
    (let ((tags (plist-get params :tags)))
    (mapcar (lambda (tag)
    (setq params (plist-put params :tags tag))
    (clocktable-by-tag/insert-tag params))
    tags)))