Compare commits

..

10 Commits

@ -31,7 +31,7 @@ $(QUALIFIED_NAME):
$(QUALIFIED_NAME)/$(MAIN_EL) $(QUALIFIED_NAME)/$(BASE_PKG) $(SUPPLEMENTAL_NESTED): $(QUALIFIED_NAME)/%: % $(QUALIFIED_NAME)
cp -v $< $(QUALIFIED_NAME)
$(PACKAGE): load-test $(SUPPLEMENTAL_NESTED) $(QUALIFIED_NAME)/$(BASE_PKG) $(QUALIFIED_NAME)/$(MAIN_EL)
$(PACKAGE): $(SUPPLEMENTAL_NESTED) $(QUALIFIED_NAME)/$(BASE_PKG) $(QUALIFIED_NAME)/$(MAIN_EL)
echo "Packing..."
tar -cf $(PACKAGE) $(QUALIFIED_NAME)
echo "Done. $(PACKAGE) is a portable emacs package"

@ -49,6 +49,17 @@
;;; Code:
;;; -*- lexical-binding: t -*-
;; 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
;; ERROR: tacc-tick is returning a (wrong-number-of-arguments) error.
;; 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
;; ERROR: Current error is a wrong argument error where we're expecting a marker or position
;; Strictly before printing the graph bar and it gets fed a quadruple, constantly changes
;; Optional
(require 'icicles nil t)
@ -109,37 +120,37 @@
:prefix "tacc-")
(defface tacc-graph-work
'((t (:inherit 'success)))
'((t :inherit success))
"For work graph bars"
:group 'tacc-faces)
(defface tacc-graph-break
'((t (:inherit 'warning)))
'((t :inherit warning))
"For break graph bars"
:group 'tacc-faces)
(defface tacc-graph-void
'((t (:inherit 'shadow)))
'((t :inherit shadow))
"For filler graph bars"
:group 'tacc-faces)
(defface tacc-clock
'((t (:height 3.0)))
'((t :height 3.0))
"For the clock and timer"
:group 'tacc-faces)
(defface tacc-clock-pause
'((t (:inherit (tacc-clock ansi-slow-blink))))
'((t :inherit (tacc-clock italic ansi-slow-blink)))
"For the timer while the timer isn't running"
:group 'tacc-faces)
(defface tacc-overwork
'((t (:inherit (tacc-clock error))))
'((t :inherit (tacc-clock error)))
"for the timer whenever we are in overwork"
:group 'tacc-faces)
(defface tacc-tag
'((t (:inherit 'link-visited)))
'((t :inherit link-visited))
"The face the tag is printed in"
:group 'tacc-faces)
@ -259,21 +270,24 @@ registered" sym-name)
(define-derived-mode tacc-timer-mode
special-mode tacc-buffer-name
"Major mode for the tacc timer"
(setq-local lexical-binding t
(setq-local show-trailing-whitespace nil
tacc-locs `((clock-start . ,(copy-marker 0))
(clock-end . ,(copy-marker 0))
(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)
@ -315,8 +329,8 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(defun tacc-chime-p (countdown-ts)
"Should I play a chime on this second?"
(if (time-less-p countdown-ts 0)
(mod (time-to-seconds countdown-ts)
tacc-chime-interval)))
(= 0 (mod (time-to-seconds countdown-ts)
tacc-chime-interval))))
(defun tacc-work-period (cycle)
"How long is the current work period?"
@ -335,9 +349,10 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(defun tacc-est-ts (state cycle work-ts break-ts)
"Given the state and cycle, how long is the current time segment?"
(let ((start-ts (tacc-start-ts state work-ts break-ts)))
(if (eq state 'work)
(tacc-work-period cycle)
(tacc-break-period cycle))))
(time-add start-ts
(if (eq state 'work)
(tacc-work-period cycle)
(tacc-break-period cycle)))))
;; 05.3 State manipulation
@ -345,14 +360,14 @@ 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)))
(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 now )
(if tacc-play-sound-file
(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))))))
@ -361,8 +376,7 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
"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"
@ -382,7 +396,7 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(cdr break-ts)
(cdr end-ts)))
(state . work)
(tag . ,(cdr tag)))
(tag . ,tag))
(cdr stack)))
(if break-ts
(push `((ts . ,(cdr break-ts))
@ -417,13 +431,14 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(+ len (if (<= ticker rem) 1 0)))))
(defun gradient-string (width chars)
(mapconcat ((let ((ticker 0))
(lambda (c) (let ((rem (mod width (length chars)))
(len (/ width (length chars))))
(make-string (progn (setf ticker (1+ ticker))
(+ len (if (<= ticker rem) 1 0)))
c)))))
chars ""))
;; (mapconcat (let ((ticker 0)
;; (rem (mod width (length chars)))
;; (len (/ width (length chars))))
;; (lambda (c)
;; (make-string (+ len (if (<= (setq ticker (1+ ticker)) rem) 1 0))
;; c)))
;; chars ""))
(make-string width (aref chars 0)))
(defun tacc-header-render (width)
"Returns a string for the header of the tacc timer"
@ -484,75 +499,74 @@ Note, if there is no tacc-buffer then you shouldn't be touching tacc-info"
(set-marker .graph-end (point-max))
(tacc-insert-between
.graph-start .graph-end
"Tag:\n"
"Tag: \n"
(tacc-graph-bar-render width 0.0 0.0 1.0)))))))
(defun tacc-clock-glyph (state)
"Returns the correct play or pause glyph for each state"
(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)))
(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))))
(defun tacc-clock-render (state start est now)
(defun tacc-clock-render (state start countdown now)
"Draw the clock"
(let* ((elapsed (time-subtract now start))
(overwork (time-less-p elapsed est))
(countdown (if overwork (time-subtract elapsed est)
(time-subtract est elapsed)))
(let* ((overwork (time-less-p countdown 0))
(count-fmt (if overwork "+%M:%S" "-%M:%S"))
(count-face (cond (overwork 'tacc-overwork)
((eq state 'pause) 'tacc-clock-pause)
('t 'tacc-clock))))
(concat
(propertize (format-time-string "%T" now) 'tacc-clock)
(propertize (format-time-string count-fmt count-face))
(propertize (tacc-clock-glyph state) 'tacc-clock))))
(defun tacc-current-tag-render ()
"Draw the tag name"
(concat "Tag: " (propertize (alist-get 'tag tacc-info "<None>")
'tacc-tag)))
(propertize (format-time-string "%T" now) 'face 'tacc-clock)
(propertize (format-time-string count-fmt countdown) 'face count-face)
(propertize (tacc-clock-glyph state) 'face 'tacc-clock))))
(defun tacc-graph-bar-render (width work break void)
"Return a graph bar width characters wide with the given proportions as \
float"
(let ((width (- width 2)))
(let ((width (- width 5)))
(concat
""
" "
(propertize (make-string (round (* width work)) tacc-graph-char)
'tacc-graph-work)
'face 'tacc-graph-work)
(propertize (make-string (round (* width break)) tacc-graph-char)
'tacc-graph-break)
'face 'tacc-graph-break)
(propertize (make-string (round (* width void)) tacc-graph-char)
'tacc-graph-void)
" \n")))
'face 'tacc-graph-void)
" \n")))
(defun tacc-tag-render (tag)
(concat " Tag: "
(propertize (if (string= tag "") "<None>" tag)
'face 'tacc-tag)
"\n"))
(defun tacc-timer-buffer-update (state now)
(defun tacc-timer-buffer-update (state start-ts est-ts countdown now)
"Update the timer buffer rendering"
(tacc-render-with-buffer
(tacc-insert-between
.clock-start .clock-end
(let-alist tacc-info)
(tacc-clock-render state .work-ts .end-ts now)))
(let-alist tacc-info
(tacc-clock-render state start-ts countdown now)))
(tacc-insert-between
.graph-start .graph-end
(tacc-current-tag-render)
(let-alist tacc-info)
(let* ((end (if (> now .end-ts) now .end-ts))
(total (- end .work-ts))
(work-prop (/ (- (if .break-ts .break-ts now) .work-ts) total))
(break-prop (/ (if .break-ts (- now .break-ts) 0) total))
(void-prop (- 1 (+ work-prop break-prop))))
(tacc-graph-bar-render width work-prop break-prop void-prop))))
(let-alist tacc-info
(concat
(tacc-tag-render .tag)
(let* ((end (if (> now est-ts) now est-ts))
(total (- end .work-ts))
(work-prop (/ (- (if .break-ts .break-ts now) .work-ts) total))
(break-prop (/ (if .break-ts (- now .break-ts) 0) total))
(void-prop (- 1 (+ work-prop break-prop))))
(tacc-graph-bar-render width work-prop break-prop void-prop)))))))
(defun tacc-new-graph-bar-render ()
(tacc-render-with-buffer
(save-restriction
(narrow-to-region .graph-start .graph-start)
(goto-char (point-min))
(insert (tacc-current-tag-render)
(insert (tacc-tag-render .tag)
(tacc-graph-bar-render width 0 0 1)
"\n")
(set-marker .graph-start (point-min))
@ -572,7 +586,7 @@ float"
(defun tacc-tag-prompt ()
"Prompt for a tag and return the user's input"
(let ((last-tag (if (bufferp (tacc-buffer))
(alist-get 'tag tacc-info))
(alist-get 'tag tacc-info)
nil))
(completions (append (flatten-tree
(apply 'eval (if tacc-tag-completion-functions
@ -587,7 +601,7 @@ float"
'stringp
nil
nil
'tacc-tag-history))
'tacc-tag-history)))
(defun tacc-tag-prompt-soft ()
"Prompt for a tag unless the user doesn't want us to
@ -612,6 +626,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)
@ -630,8 +651,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 ()
@ -645,7 +665,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))))
@ -665,12 +685,11 @@ Returns the current tag if no prompt is made"
"Pause/unpause the tacc timer session"
(interactive)
(if (tacc-running?)
(tacc-with-buffer
(let ((state (alist-get 'state tacc-info)))
(if (eq state 'pause)
(tacc-unpause-timer)
(tacc-pause-timer))))
(message "There isn't a live timer session to pause/unpause")))
(let ((state (alist-get 'state tacc-info)))
(if (eq state 'pause)
(tacc-unpause-timer)
(tacc-pause-timer))))
(message "There isn't a live timer session to pause/unpause"))
(defun tacc-end-timer ()
"Ends the current timer session, runs serialization and kills the buffer"

Loading…
Cancel
Save