From f6febc988725584810957fae5cc6d88b7bc19b57 Mon Sep 17 00:00:00 2001 From: Brady McDonough Date: Mon, 6 Feb 2023 15:19:36 -0700 Subject: [PATCH] Progress on runtime errors, reduced cleverness --- tacc.el | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/tacc.el b/tacc.el index 2c75d78..32514f1 100644 --- a/tacc.el +++ b/tacc.el @@ -53,7 +53,10 @@ ;; 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 ;; ERROR: tacc-tick is returning a (wrong-number-of-arguments) error. -;; ERROR: tag doesn't print, countdown is ??? +;; ERROR: tag doesn't print, +;; 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 ;; Optional (require 'icicles nil t) @@ -271,15 +274,18 @@ registered" sym-name) (graph-start . ,(copy-marker 0)) (graph-end . ,(copy-marker 0))))) -(defun cycle-ticker () - "A closure with an internal count, only increments when fed 'break timer state" - (let ((ticker 0)) - (lambda (&optional state) - (cond ((eq state 'break) (setq ticker (1+ ticker))) - ( 't ticker))))) - -(defvar tacc-info '((history . ()) - (cycle . ,(cycle-ticker)) +;; ERROR: It seems like this style of ticker doesn't work and I don't have time to look into it +;; more deeply. As far as I can tell I've copied the reference examples pretty closely. +;; In the meantime a "dumber" solution that works is being used +;; (defun cycle-ticker () +;; "A closure with an internal count, only increments when fed 'break timer state" +;; (let ((ticker 0)) +;; (lambda (&optional state) +;; (cond ((eq state 'break) (setq ticker (1+ ticker))) +;; ( 't ticker))))) + +(defvar tacc-info `((history . ()) + (cycle . 0) (work-ts . nil) (break-ts . nil) (end-ts . nil) @@ -352,24 +358,23 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info" "Time marches on. Called every second while a tacc timer is running" (let* ((now (current-time)) (state (alist-get 'state tacc-info)) - (cycle (funcall (alist-get 'cycle tacc-info) 't)) + (cycle (alist-get 'cycle tacc-info)) (work-ts (alist-get 'work-ts tacc-info)) (break-ts (alist-get 'break-ts tacc-info)) (start-ts (tacc-start-ts state work-ts break-ts)) (est (tacc-est-ts state cycle work-ts break-ts)) (countdown (time-subtract est now))) (tacc-timer-buffer-update state start-ts est countdown now) - (if (functionp tacc-play-sound-file) - (cond ((tacc-chime-p countdown) - (funcall tacc-play-sound-file tacc-sound-chime)) - (t (funcall tacc-play-sound-file tacc-sound-tick)))))) + (if (functionp tacc-play-sound-file) + (cond ((tacc-chime-p countdown) + (funcall tacc-play-sound-file tacc-sound-chime)) + (t (funcall tacc-play-sound-file tacc-sound-tick)))))) (defun tacc-schedule () "Note the time and schedule the first tick" (setcdr (assoc 'state tacc-info) 'work) (setcdr (assoc 'work-ts tacc-info) (current-time)) - (setq tacc-timer (run-with-timer 't 1 'tacc-tick - :timer-max-repeats 1))) + (setq tacc-timer (run-with-timer 't 1 'tacc-tick))) (defun tacc-deschedule () "Deschedule the timer" @@ -619,6 +624,13 @@ Returns the current tag if no prompt is made" (setcdr (assoc 'tag tacc-info) (tacc-tag-prompt))) (message "There isn't a live timer session to tag")) +(defun tacc-cycle-increment (state) + "Increments the cycle counter if the current state is a 'break" + (if (eq state 'break) + (let* ((cycle-place (assoc 'cycle tacc-info)) + (cycle (cdr cycle-place))) + (setcdr cycle-place (1+ cycle))))) + (defun tacc-timer-state-forward () "Move the tacc timer state forward" (interactive) @@ -637,8 +649,7 @@ Returns the current tag if no prompt is made" (setcdr work-ts ts) (setcdr state-place 'work) (tacc-new-graph-bar-render))) - (funcall (alist-get 'cycle tacc-info) state) - ) + (tacc-cycle-increment state)) (message "There is no timer to advance"))) (defun tacc-timer-state-skip () @@ -652,7 +663,7 @@ Returns the current tag if no prompt is made" (ts (current-time))) (setcdr end-ts ts) (tacc-push-current) - (funcall (alist-get 'cycle tacc-info) 'break) + (tacc-cycle-increment 'break) (setcdr work-ts ts) (setcdr state-place 'work) (tacc-new-graph-bar-render))))