Annotation of 43BSD/contrib/emacs/lisp/time.el, revision 1.1.1.1

1.1       root        1: ;; Display time and load in mode line of Emacs.
                      2: ;; Copyright (C) 1985 Richard M. Stallman.
                      3: 
                      4: ;; This file is part of GNU Emacs.
                      5: 
                      6: ;; GNU Emacs is distributed in the hope that it will be useful,
                      7: ;; but WITHOUT ANY WARRANTY.  No author or distributor
                      8: ;; accepts responsibility to anyone for the consequences of using it
                      9: ;; or for whether it serves any particular purpose or works at all,
                     10: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
                     11: ;; License for full details.
                     12: 
                     13: ;; Everyone is granted permission to copy, modify and redistribute
                     14: ;; GNU Emacs, but only under the conditions described in the
                     15: ;; GNU Emacs General Public License.   A copy of this license is
                     16: ;; supposed to have been given to you along with GNU Emacs so you
                     17: ;; can know your rights and responsibilities.  It should be in a
                     18: ;; file named COPYING.  Among other things, the copyright notice
                     19: ;; and this notice must be preserved on all copies.
                     20: 
                     21: 
                     22: (defvar display-time-process nil)
                     23: 
                     24: (defun display-time ()
                     25:   "Display current time and load level in mode line of each buffer.
                     26: Updates automatically every minute."
                     27:   (interactive)
                     28:   (let ((live (and display-time-process
                     29:                   (eq (process-status display-time-process) 'run))))
                     30:     (if (not live)
                     31:        (save-excursion
                     32:          (if display-time-process
                     33:              (delete-process display-time-process))
                     34:          (setq global-mode-string "time and load")
                     35:          (setq display-time-process
                     36:                (start-process "display-time" nil
                     37:                               (expand-file-name "loadst" exec-directory)
                     38:                               "-n" "60"))
                     39:          (process-kill-without-query display-time-process)
                     40:          (set-process-sentinel display-time-process 'display-time-sentinel)
                     41:          (set-process-filter display-time-process 'display-time-filter)))))
                     42: 
                     43: (defun display-time-sentinel (proc reason)
                     44:   (or (eq (process-status proc) 'run)
                     45:       (setq global-mode-string ""))
                     46:   ;; Force mode-line updates
                     47:   (save-excursion (set-buffer (other-buffer)))
                     48:   (set-buffer-modified-p (buffer-modified-p))
                     49:   (sit-for 0))
                     50: 
                     51: (defun display-time-filter (proc string)
                     52:   ;; Desired data can't need more than the last 30 chars,
                     53:   ;; so save time by flushing the rest.
                     54:   ;; This way, if we have many different times all collected at once,
                     55:   ;; we can discard all but the last few very fast.
                     56:   (if (> (length string) 30)
                     57:       (setq string (substring string -30)))
                     58:   ;; Now discard all but the very last one.
                     59:   (while (string-match "[0-9]+:" string 4)
                     60:     (setq string (substring string (match-beginning 0))))
                     61:   ;; Append the date if desired.
                     62:   (if display-time-day-and-date
                     63:       (setq string (concat (substring (current-time-string) 0 11) string)))
                     64:   ;; Install the new time for display.
                     65:   (setq global-mode-string string)
                     66:   ;; Force redisplay of all buffers' mode lines to be considered.
                     67:   (save-excursion (set-buffer (other-buffer)))
                     68:   (set-buffer-modified-p (buffer-modified-p))
                     69:   ;; Do redisplay right now, if no input pending.
                     70:   (sit-for 0))

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.