help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to make a timer in emacs


From: Joakim Hove
Subject: Re: how to make a timer in emacs
Date: Wed, 21 Apr 2004 10:20:41 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Joel Smith <joelvsmith@earthlink.net> writes:

> so my question is how does one make a timer in emacs, i.e.  print in
> the same place on the same line something that continually updates
> so that the size of the buffer remains constant?  any help would be
> greatly appreciated.

Maybe a solution already exists?

This is a quick *hack* which displays the current time, maybe this
could be an inspiration for a proper solution: M-x start-clock to start 
a clock at point, and M-x stop-clock to stop it again.

HTH - Joakim


(defun start-clock ()
  (interactive)
  (insert "Current time: ")
  (let* ((p1 (point))
         (time-string (format-time-string "%H:%M:%S" (current-time)))
         (p2 (+ p1 (length time-string))))
    (insert time-string)
    (setq global-clock-timer (run-at-time nil 1 'update-clock p1 p2))))

(defun update-clock (p1 p2)
  (save-excursion
    (delete-region p1 p2)
    (goto-char p1)
    (insert (format-time-string "%H:%M:%S" (current-time)))))

(defun stop-clock ()
  (interactive)
  (cancel-timer global-clock-timer))



-- 
  /--------------------------------------------------------------------\
 / Joakim Hove  / hove@bccs.no  /  (55 5) 84076       |                 \
 | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
 | CMU                                                | 5231 Paradis    |
 \ Thormøhlensgt.55, 5020 Bergen.                     | 55 91 28 18     /
  \--------------------------------------------------------------------/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]