Correcting behaviours and invalid state checks

master
Brady McDonough 2 years ago
parent 4449a1cc9e
commit 603b476762

@ -272,13 +272,13 @@ registered" sym-name)
(defun tacc-info-initial ()
"Returns the initial state of tacc-info"
`((history . ())
(cycle . 0)
(work-ts . nil)
(break-ts . nil)
(end-ts . nil)
(state . stop)
(tag . "")))
(copy-alist `((history . ())
(cycle . 0)
(work-ts . nil)
(break-ts . nil)
(end-ts . nil)
(state . stop)
(tag . ""))))
(defvar tacc-info (tacc-info-initial)
"State information related to the timer")
@ -287,29 +287,49 @@ registered" sym-name)
"Timer object controlling tacc's second-by-second update")
;; 05.2 State checks
;; TODO: tacc-running? needs to be replaced by tacc-session? and tacc-live? depending on context
(defun tacc-buffer ()
"Gets the tacc-timer buffer if there is one"
(get-buffer tacc-buffer-name))
(defun tacc-running? ()
(defun tacc-live-state? (state)
"Checks if the state supplied indicates a live timer"
(cond ((eq state 'pause) nil)
((eq state 'stop) nil)
((eq state 'work) t)
((eq state 'break) t)
('t (signal 'tacc-error-illegal-buffer-state state))))
(defun tacc-live? ()
"Checks if there is a live timer running"
(timerp tacc-timer))
(defun tacc-running-state? (state)
"Checks if the state supplied indicates a live timer"
(cond ((eq state 'pause) nil)
(defun tacc-session-state? (state)
"Checks if the state supplied indicates there should be session information"
(cond ((eq state 'pause) t)
((eq state 'stop) nil)
((eq state 'work) t)
((eq state 'break) t)
('t (signal 'tacc-error-illegal-buffer-state state))))
(defun tacc-session? ()
"Checks if tacc session info indicates there should be session information"
(tacc-running-state? (alist-get 'state tacc-info)))
(defun tacc-history? ()
"Checks if tacc session has history information"
(if (> 0 (length (alist-get 'history tacc-info)))
t
nil))
(defun tacc-invariant ()
"Returns t if tacc is in a legal state for mutating tacc-info
Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(if (bufferp (tacc-buffer))
(if (and (timerp tacc-timer)
(tacc-running-state? tacc-info))
(if (and (tacc-running?)
(tacc-live?))
t)
(signal 'tacc-error-illegal-buffer-state (tacc-buffer))))
@ -359,6 +379,12 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(funcall tacc-play-sound-file tacc-sound-chime))
(t (funcall tacc-play-sound-file tacc-sound-tick))))))
(defun tacc-timer-buffer-redraw ()
(let ((now (current-time))
(state (alist-get 'state tacc-info)))
(tacc-timer-buffer-update state)))
;; TODO
(defun tacc-schedule ()
"Note the time and schedule the first tick"
(setcdr (assoc 'state tacc-info) 'work)
@ -494,7 +520,8 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(defun tacc-clock-glyph (state)
"Returns the correct play or pause glyph for each state"
(string (cond ((eq state 'work) tacc-run-glyph)
(string
(cond ((eq state 'work) tacc-run-glyph)
((eq state 'break) tacc-run-glyph)
((eq state 'pause) tacc-pause-glyph)
((eq state 'stop) tacc-pause-glyph))))
@ -679,7 +706,8 @@ Returns the current tag if no prompt is made"
(let ((state (alist-get 'state tacc-info)))
(if (eq state 'pause)
(tacc-unpause-timer)
(tacc-pause-timer))))
(tacc-pause-timer))
(tacc-timer-buffer-redraw)))
(message "There isn't a live timer session to pause/unpause"))
(defun tacc-end-timer ()

Loading…
Cancel
Save