A Task Timer for MicroEmacs
A common option (and good option) with issue trackers these days is time tracking. It allows the developer to estimate the time required and then log the actual time spent on the issue. Why? It improves the developers ability to estimate the time for a given task thus releases are better scheduled and work isn’t taken on with unrealistic timeframes.
So, that leads me to a task timer for MicroEmacs. It need not be complicated. I created a simple one that allows you to start the timer and then report how long it has been since the timer has been started. Only one timer can run at a given time, no need for more with simple time tracking. I bound the keys C-c b
to begin the timer and C-c s
to report the status of the timer. You can bind as you see fit. There is no reset or restart functionality. If you want to start working on a new issue, simply start the timer again. That is the reset.
The code is rather simple. When you start it simply sets a global variable to the current date and time. When you ask for a timer status the duration is computed from start date and time to the current date and time and reported in the status area. That’s it!
The code:
; Start the timer by setting $timer-started-at to the current $time
define-macro timer-begin
set-variable $timer-started-at $time
!emacro
; Report the difference between $timer-started-at and $time in a human
; consumable format
define-macro timer-status
set-variable #l0 $timer-started-at
set-variable #l1 $time
set-variable #l2 &add &mid #l0 16 2 &mul 60 &add &mid #l0 14 2 &mul 60 &mid #l0 12 2
set-variable #l3 &add &mid #l1 16 2 &mul 60 &add &mid #l1 14 2 &mul 60 &mid #l1 12 2
!if &les &set #l4 &sub &rig #l1 18 &rig #l0 18 0
set-variable #l2 &add #l2 1
set-variable #l4 &add 1000 #l4
!endif
set-variable #l0 &sub #l3 #l2 ; difference in seconds
set-variable #l1 0 ; day count
set-variable #l2 0 ; hour count
set-variable #l3 0 ; minute count
set-variable #l4 0 ; second count
!if &great #l0 86400
set-variable #l1 &div #l0 86000
set-variable #l0 &sub #l0 &mul 86000 #l1
!endif
!if &great #l0 3600
set-variable #l2 &div #l0 3600
set-variable #l0 &sub #l0 &mul 3600 #l2
!endif
!if &great #l0 60
set-variable #l3 &div #l0 60
set-variable #l0 &sub #l0 &mul 60 #l3
!endif
set-variable #l4 #l0
!if &great #l1 0
ml-write &spr "%d day %d hour %d min %d sec" #l1 #l2 #l3 #l4
!elif &great #l2 0
ml-write &spr "%d hour %d min %d sec" #l2 #l3 #l4
!elif &great #l3 0
ml-write &spr "%d min %d sec" #l3 #l4
!else
ml-write &spr "%d sec" #l4
!endif
!emacro
; Time tracking bindings
global-bind-key timer-begin "C-c b"
global-bind-key timer-status "C-c s"
For more information on MicroEmacs please see the MicroEmacs Home Page. Please do not be put off by the “Micro” part of the name. It is by no means Micro! Please do not be put off by the “Emacs” part of the name. It has little in common with the modern Emacs and nothing in common with Lisp, as you can see above.