Working with timestamps and some minor beautification

master
Brady McDonough 3 years ago
parent a6635e36d0
commit 14a3837707

@ -1,3 +1,4 @@
;;; -*- lexical-binding: t -*-
;;; tacc.el --- A pomidoro timer supporting tags and customizable export ;;; tacc.el --- A pomidoro timer supporting tags and customizable export
;; Author: Brady McDonough <me@bradymcd.ca> ;; Author: Brady McDonough <me@bradymcd.ca>
@ -47,16 +48,13 @@
;; 10 Provides ;; 10 Provides
;;; Code: ;;; Code:
;;; -*- lexical-binding: t -*-
;; TODOS: ;; TODOS:
;; ERROR: mapconcat doesn't seem to respect lexical binding which leaves me unable to use a closure for a ticker
;; For now the code which relies on this will be noop'd
;; BUG : Countdown was ??? because 0 doesn't default to zero but "now".
;; That does leave an edgecase in the countdown display I'll need to explicitly check for
;; ERROR: timer shutdown seems to leave things in a wrong state and buffer doesn't die properly ;; ERROR: timer shutdown seems to leave things in a wrong state and buffer doesn't die properly
;; Check on the logic of push-current, needs predicates rather than lazy if conditions ;; Check on the logic of push-current, needs predicates rather than lazy if conditions
;; I'm not calling anything to destroy the buffer on desched ;; I'm not calling anything to destroy the buffer on desched
;; BUG: The buffer is immortal?
;;
;; Optional ;; Optional
(require 'icicles nil t) (require 'icicles nil t)
@ -209,19 +207,17 @@ Each function must have no required arguments and return a list of strings"
:group 'tacc-behavior) :group 'tacc-behavior)
(defun tacc-play-sound-file-emacs (file) (defun tacc-play-sound-file-emacs (file)
"Play some file using an asynchronous subprocess" "Play some file in a child emacs process"
(if (fboundp 'play-sound-internal) (if (fboundp 'play-sound-internal)
(start-process "tacc-play-sound" (start-process "tacc-play-sound"
tacc-buffer-name nil
(car command-line-args) (car command-line-args)
"-Q"
"--batch" "--batch"
"--eval" (format "(play-sound-file \"%s\")" file)) "--eval" (format "(play-sound-file \"%s\")" file))
(warn "Emacs lacks builtin sound support"))) (warn "Emacs lacks builtin sound support")))
(defcustom tacc-play-sound-file #'tacc-play-sound-file-emacs (defcustom tacc-play-sound-file #'tacc-play-sound-file-emacs
"Function used to play sounds. Set to nil to disable sound. "Asyncronous function to play sounds. Set to nil to disable sound"
It's best to use something asynchronous (like spawning a child emacs process)"
:type '(choice (const nil) :type '(choice (const nil)
function) function)
:group 'tacc-behavior) :group 'tacc-behavior)
@ -284,13 +280,17 @@ registered" sym-name)
;; (cond ((eq state 'break) (setq ticker (1+ ticker))) ;; (cond ((eq state 'break) (setq ticker (1+ ticker)))
;; ( 't ticker))))) ;; ( 't ticker)))))
(defvar tacc-info `((history . ()) (defun tacc-info-initial ()
(cycle . 0) "Returns the initial state of tacc-info"
(work-ts . nil) `((history . ())
(break-ts . nil) (cycle . 0)
(end-ts . nil) (work-ts . nil)
(state . work) (break-ts . nil)
(tag . "")) (end-ts . nil)
(state . stop)
(tag . "")))
(defvar tacc-info (tacc-info-initial)
"State information related to the timer") "State information related to the timer")
(defvar tacc-timer nil (defvar tacc-timer nil
@ -391,7 +391,7 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(if work-ts (if work-ts
(push `((ts . ,work-ts) (push `((ts . ,work-ts)
(end . ,(if (cdr break-ts) (end . ,(if (cdr break-ts)
(cdr break-ts) (time-seconds (cdr break-ts))
(cdr end-ts))) (cdr end-ts)))
(state . work) (state . work)
(tag . ,tag)) (tag . ,tag))
@ -549,20 +549,20 @@ float"
(tacc-insert-between (tacc-insert-between
.graph-start .graph-end .graph-start .graph-end
(let-alist tacc-info (let-alist tacc-info
(tacc-tag-render .tag) (concat (tacc-tag-render .tag)
(let* ((start-s (time-to-seconds start-ts)) (let* ((start-s (time-to-seconds start-ts))
(est-s (time-to-seconds est-ts)) (est-s (time-to-seconds est-ts))
(count-s (time-to-seconds countdown)) (count-s (time-to-seconds countdown))
(now-s (time-to-seconds now)) (now-s (time-to-seconds now))
(end-s (if (< est-s now-s) now-s est-s)) (end-s (if (< est-s now-s) now-s est-s))
(work-s (time-to-seconds .work-ts)) (work-s (time-to-seconds .work-ts))
(break-s (time-to-seconds .break-ts)) (break-s (time-to-seconds .break-ts))
(total (- end-s work-s)) (total (- end-s work-s))
(work-prop (/ (- (if (numberp break-s) break-s now-s) work-s) total)) (work-prop (/ (- (if (numberp break-s) break-s now-s) work-s) total))
(break-prop (/ (if (numberp break-s) (- now-s break-s) 0) total)) (break-prop (/ (if (numberp break-s) (- now-s break-s) 0) total))
(void-prop (- 1 (+ work-prop break-prop)))) (void-prop (- 1 (+ work-prop break-prop))))
(tacc-graph-bar-render width work-prop break-prop void-prop)))))) (tacc-graph-bar-render width work-prop break-prop void-prop)))))))
(defun tacc-new-graph-bar-render () (defun tacc-new-graph-bar-render ()
(tacc-render-with-buffer (tacc-render-with-buffer

Loading…
Cancel
Save