Migrate chronometrist-populate to s-expression format
Wow, how much shorter is that parsing code? :D
This commit is contained in:
parent
0c7e9f39ed
commit
d5a0e1c17e
|
@ -68,7 +68,7 @@ It returns t if the table was modified, else nil."
|
||||||
(defun chronometrist-events-populate ()
|
(defun chronometrist-events-populate ()
|
||||||
"Clear hash table `chronometrist-events' and populate it.
|
"Clear hash table `chronometrist-events' and populate it.
|
||||||
|
|
||||||
The data is acquired from `timeclock-file'.
|
The data is acquired from `chronometrist-file'.
|
||||||
|
|
||||||
Each key is a date in the form (YEAR MONTH DAY).
|
Each key is a date in the form (YEAR MONTH DAY).
|
||||||
|
|
||||||
|
@ -78,29 +78,14 @@ SECONDS \"PROJECT-NAME-OR-COMMENT\"\].
|
||||||
|
|
||||||
This function always returns nil."
|
This function always returns nil."
|
||||||
(clrhash chronometrist-events)
|
(clrhash chronometrist-events)
|
||||||
(with-current-buffer (find-file-noselect timeclock-file)
|
(with-current-buffer (find-file-noselect chronometrist-file)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(while (not (= (point) (point-max)))
|
(let ((expression)
|
||||||
(let* ((event-string (buffer-substring-no-properties (point-at-bol)
|
(index 0))
|
||||||
(point-at-eol)))
|
(while (setq expression (ignore-errors (read (current-buffer))))
|
||||||
(info-re (concat ". " chronometrist-date-re " " chronometrist-time-re-file))
|
(setq index (1+ index))
|
||||||
(project-or-comment (->> event-string
|
(puthash index expression chronometrist-events)))
|
||||||
(replace-regexp-in-string (concat info-re " ?") "")
|
|
||||||
(vector)))
|
|
||||||
(the-rest (--> (concat "\\(" info-re "\\)" ".*")
|
|
||||||
(replace-regexp-in-string it "\\1" event-string)
|
|
||||||
(split-string it "[ /:]")
|
|
||||||
(append (list (car it))
|
|
||||||
(mapcar #'string-to-number (-slice it 1 7)))))
|
|
||||||
(key (-slice the-rest 1 4))
|
|
||||||
(old-value (gethash key chronometrist-events))
|
|
||||||
(new-value (vector (vconcat the-rest ;; vconcat converts lists to vectors
|
|
||||||
project-or-comment))))
|
|
||||||
(if old-value
|
|
||||||
(puthash key (vconcat old-value new-value) chronometrist-events)
|
|
||||||
(puthash key new-value chronometrist-events)))
|
|
||||||
(forward-line))
|
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
(defun chronometrist-events-subset (start-date end-date)
|
(defun chronometrist-events-subset (start-date end-date)
|
||||||
|
|
Reference in New Issue