mirror of
https://github.com/SqrtMinusOne/org-clock-agg.git
synced 2025-12-10 14:03:02 +03:00
org-clock-agg: select elements works
This commit is contained in:
parent
7ccf1521c6
commit
043aa82f86
1 changed files with 61 additions and 0 deletions
|
|
@ -29,6 +29,67 @@
|
|||
|
||||
;;; Code:
|
||||
(require 'compat)
|
||||
(require 'org)
|
||||
(require 'org-ql)
|
||||
|
||||
;; Reset org-ql cache
|
||||
(setq org-ql-cache (make-hash-table :weakness 'key))
|
||||
|
||||
(defun org-clock-agg--parse-clocks (headline)
|
||||
(let ((contents (buffer-substring-no-properties
|
||||
(org-element-property :contents-begin headline)
|
||||
(org-element-property :contents-end headline))))
|
||||
(with-temp-buffer
|
||||
(insert contents)
|
||||
(let (res)
|
||||
(org-element-map (org-element-parse-buffer) 'clock
|
||||
(lambda (clock)
|
||||
(let ((start )
|
||||
(end (time-convert
|
||||
(org-timestamp-to-time (org-element-property :value clock) t)
|
||||
'integer))))
|
||||
(push
|
||||
`((:start . ,(time-convert
|
||||
(org-timestamp-to-time (org-element-property :value clock))
|
||||
'integer))
|
||||
(:end . ,(time-convert
|
||||
(org-timestamp-to-time (org-element-property :value clock) t)
|
||||
'integer)))
|
||||
res))
|
||||
nil nil 'headline)
|
||||
res))))
|
||||
|
||||
(defun org-clock-agg--parse-headline ()
|
||||
(let* ((headline (org-element-headline-parser))
|
||||
(tags-val (org-ql--tags-at (point)))
|
||||
(tags (seq-filter
|
||||
#'stringp ;; to filter out `org-ql-nil'
|
||||
(append (unless (eq (car tags-val) 'org-ql-nil)
|
||||
(car tags-val))
|
||||
(unless (eq (cdr tags-val) 'org-ql-nil)
|
||||
(cdr tags-val)))))
|
||||
(file (buffer-file-name))
|
||||
(outline-path (mapcar
|
||||
#'substring-no-properties
|
||||
(org-ql--outline-path)))
|
||||
(category (org-get-category)))
|
||||
`((:headline . ,headline)
|
||||
(:tags . ,tags)
|
||||
(:file . ,file)
|
||||
(:outline-path . ,outline-path)
|
||||
(:category . ,category)
|
||||
(:clocks . ,(org-clock-agg--parse-clocks headline)))))
|
||||
|
||||
(defun org-clock-agg--query (from to files)
|
||||
(org-ql-query
|
||||
:select #'org-clock-agg--parse-headline
|
||||
:from files
|
||||
:where `(clocked :from ,from :to ,to)))
|
||||
|
||||
|
||||
(defun org-clock-agg ()
|
||||
(interactive)
|
||||
())
|
||||
|
||||
(provide 'org-clock-agg)
|
||||
;;; org-clock-agg.el ends here
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue