annotate lisp/time.el @ 30167:83e9db7aeddb

Add optional version as 4th element of specs and use it for several things new in v21. Remove load-path. Fix type of line-number-display-limit.
author Dave Love <fx@gnu.org>
date Wed, 12 Jul 2000 17:25:28 +0000
parents 1030e638c8dd
children ceb42baae241
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29693
e7c50747bb2d (display-time-mail-function): New variable, to allow
Andrew Innes <andrewi@gnu.org>
parents: 28884
diff changeset
1 ;;; time.el --- display time, load and mail indicator in mode line of Emacs.
29706
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
2
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 96, 2000 Free Software Foundation, Inc.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
4
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
5 ;; Maintainer: FSF
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
6
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
7 ;; This file is part of GNU Emacs.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
8
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
12 ;; any later version.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
13
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
17 ;; GNU General Public License for more details.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
18
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
19 ;; You should have received a copy of the GNU General Public License
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
22 ;; Boston, MA 02111-1307, USA.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
23
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
24 ;;; Commentary:
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
25
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
26 ;; Facilities to display current time/date and a new-mail indicator
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
27 ;; in the Emacs mode line. The single entry point is `display-time'.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
28
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
29 ;;; Code:
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
30
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
31 (defgroup display-time nil
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
32 "Display time and load in mode line of Emacs."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
33 :group 'modeline
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
34 :group 'mail)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
35
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
36
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
37 ;;;###autoload
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
38 (defcustom display-time-mode nil
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
39 "Toggle display of time, load level, and mail flag in mode lines.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
40 Setting this variable directly does not take effect;
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
41 use either \\[customize] or the function `display-time-mode'."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
42 :set (lambda (symbol value)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
43 (display-time-mode (or value 0)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
44 :initialize 'custom-initialize-default
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
45 :type 'boolean
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
46 :group 'display-time
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
47 :require 'time
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
48 :version "20.3")
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
49
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
50
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
51 (defcustom display-time-mail-file nil
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
52 "*File name of mail inbox file, for indicating existence of new mail.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
53 Non-nil and not a string means don't check for mail. nil means use
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
54 default, which is system-dependent, and is the same as used by Rmail."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
55 :type '(choice (const :tag "(None)" none)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
56 (const :tag "Default" nil)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
57 (file :format "%v"))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
58 :group 'display-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
59
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
60 (defcustom display-time-mail-function nil
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
61 "*Function to call, for indicating existence of new mail.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
62 nil means use the default method of checking `display-time-mail-file'."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
63 :type '(choice (const :tag "Default" nil)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
64 (function))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
65 :group 'display-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
66
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
67 ;;;###autoload
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
68 (defcustom display-time-day-and-date nil "\
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
69 *Non-nil means \\[display-time] should display day and date as well as time."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
70 :type 'boolean
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
71 :group 'display-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
72
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
73 (defvar display-time-timer nil)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
74
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
75 (defcustom display-time-interval 60
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
76 "*Seconds between updates of time in the mode line."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
77 :type 'integer
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
78 :group 'display-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
79
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
80 (defcustom display-time-24hr-format nil
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
81 "*Non-nil indicates time should be displayed as hh:mm, 0 <= hh <= 23.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
82 Nil means 1 <= hh <= 12, and an AM/PM suffix is used."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
83 :type 'boolean
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
84 :group 'display-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
85
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
86 (defvar display-time-string nil)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
87
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
88 (defcustom display-time-hook nil
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
89 "*List of functions to be called when the time is updated on the mode line."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
90 :type 'hook
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
91 :group 'display-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
92
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
93 (defvar display-time-server-down-time nil
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
94 "Time when mail file's file system was recorded to be down.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
95 If that file system seems to be up, the value is nil.")
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
96
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
97 ;;;###autoload
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
98 (defun display-time ()
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
99 "Enable display of time, load level, and mail flag in mode lines.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
100 This display updates automatically every minute.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
101 If `display-time-day-and-date' is non-nil, the current day and date
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
102 are displayed as well.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
103 This runs the normal hook `display-time-hook' after each update."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
104 (interactive)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
105 (display-time-mode 1))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
106
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
107 ;;;###autoload
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
108 (defun display-time-mode (arg)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
109 "Toggle display of time, load level, and mail flag in mode lines.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
110 With a numeric arg, enable this display if arg is positive.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
111
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
112 When this display is enabled, it updates automatically every minute.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
113 If `display-time-day-and-date' is non-nil, the current day and date
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
114 are displayed as well.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
115 This runs the normal hook `display-time-hook' after each update."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
116 (interactive "P")
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
117 (let ((on (if (null arg)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
118 (not display-time-timer)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
119 (> (prefix-numeric-value arg) 0))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
120 (setq display-time-mode on)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
121 (and display-time-timer (cancel-timer display-time-timer))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
122 (setq display-time-timer nil)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
123 (setq display-time-string "")
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
124 (or global-mode-string (setq global-mode-string '("")))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
125 (if on
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
126 (progn
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
127 (or (memq 'display-time-string global-mode-string)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
128 (setq global-mode-string
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
129 (append global-mode-string '(display-time-string))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
130 ;; Set up the time timer.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
131 (setq display-time-timer
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
132 (run-at-time t display-time-interval
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
133 'display-time-event-handler))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
134 ;; Make the time appear right away.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
135 (display-time-update)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
136 ;; When you get new mail, clear "Mail" from the mode line.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
137 (add-hook 'rmail-after-get-new-mail-hook
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
138 'display-time-event-handler))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
139 (remove-hook 'rmail-after-get-new-mail-hook
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
140 'display-time-event-handler))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
141
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
142 (defcustom display-time-mail-face 'mode-line
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
143 "Face to use for `display-time-mail-string'.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
144 If `display-time-use-mail-icon' is non-nil, the image's background
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
145 colour is the background of this face. Set this to a face other than
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
146 `mode-line' to make the mail indicator stand out on a suitable
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
147 display."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
148 :group 'faces
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
149 :group 'display-time
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
150 :type 'face)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
151
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
152 (defvar display-time-mail-icon
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
153 (find-image '((:type xbm :file "letter.xbm" :ascent center)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
154 "Image specification to offer as the mail indicator on a graphic
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
155 display. See `display-time-use-mail-icon' and
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
156 `display-time-mail-face'.")
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
157
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
158 (defcustom display-time-use-mail-icon nil
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
159 "Non-nil means use an icon as the mail indicator on a graphic display.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
160 Otherwise use the string \"Mail\". The icon may consume less of the
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
161 mode line. It is specified by `display-time-mail-icon'."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
162 :group 'display-time
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
163 :type 'boolean)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
164
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
165 (defcustom display-time-format nil
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
166 "*A string specifying the format for displaying the time in the mode line.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
167 See the function `format-time-string' for an explanation of
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
168 how to write this string. If this is nil, the defaults
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
169 depend on `display-time-day-and-date' and `display-time-24hr-format'."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
170 :type '(choice (const :tag "Default" nil)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
171 string)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
172 :group 'display-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
173
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
174 (defcustom display-time-string-forms
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
175 '((if (and (not display-time-format) display-time-day-and-date)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
176 (format-time-string "%a %b %e " now)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
177 "")
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
178 (format-time-string (or display-time-format
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
179 (if display-time-24hr-format "%H:%M" "%-I:%M%p"))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
180 now)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
181 load
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
182 (if mail
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
183 ;; Build the string every time to act on customization.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
184 (concat " "
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
185 (propertize
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
186 "Mail"
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
187 'display `(when (and display-time-use-mail-icon
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
188 (display-graphic-p))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
189 ,@display-time-mail-icon
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
190 ,@(list :background (face-attribute
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
191 display-time-mail-face
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
192 :background)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
193 'help-echo "mouse-2: Read mail"
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
194 'local-map (make-mode-line-mouse2-map read-mail-command)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
195 ""))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
196 "*A list of expressions governing display of the time in the mode line.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
197 For most purposes, you can control the time format using `display-time-format'
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
198 which is a more standard interface.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
199
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
200 This expression is a list of expressions that can involve the keywords
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
201 `load', `day', `month', and `year', `12-hours', `24-hours', `minutes',
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
202 `seconds', all numbers in string form, and `monthname', `dayname', `am-pm',
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
203 and `time-zone' all alphabetic strings, and `mail' a true/nil value.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
204
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
205 For example, the form
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
206
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
207 '((substring year -2) \"/\" month \"/\" day
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
208 \" \" 24-hours \":\" minutes \":\" seconds
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
209 (if time-zone \" (\") time-zone (if time-zone \")\")
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
210 (if mail \" Mail\" \"\"))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
211
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
212 would give mode line times like `94/12/30 21:07:48 (UTC)'."
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
213 :type 'sexp
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
214 :group 'display-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
215
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
216 (defun display-time-event-handler ()
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
217 (display-time-update)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
218 ;; Do redisplay right now, if no input pending.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
219 (sit-for 0)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
220 (let* ((current (current-time))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
221 (timer display-time-timer)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
222 ;; Compute the time when this timer will run again, next.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
223 (next-time (timer-relative-time
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
224 (list (aref timer 1) (aref timer 2) (aref timer 3))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
225 (* 5 (aref timer 4)) 0)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
226 ;; If the activation time is far in the past,
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
227 ;; skip executions until we reach a time in the future.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
228 ;; This avoids a long pause if Emacs has been suspended for hours.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
229 (or (> (nth 0 next-time) (nth 0 current))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
230 (and (= (nth 0 next-time) (nth 0 current))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
231 (> (nth 1 next-time) (nth 1 current)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
232 (and (= (nth 0 next-time) (nth 0 current))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
233 (= (nth 1 next-time) (nth 1 current))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
234 (> (nth 2 next-time) (nth 2 current)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
235 (progn
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
236 (timer-set-time timer (timer-next-integral-multiple-of-time
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
237 current display-time-interval)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
238 display-time-interval)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
239 (timer-activate timer)))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
240
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
241 ;; Update the display-time info for the mode line
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
242 ;; but don't redisplay right now. This is used for
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
243 ;; things like Rmail `g' that want to force an update
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
244 ;; which can wait for the next redisplay.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
245 (defun display-time-update ()
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
246 (let* ((now (current-time))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
247 (time (current-time-string now))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
248 (load (condition-case ()
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
249 (if (zerop (car (load-average))) ""
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
250 ;; The load average number is mysterious, so
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
251 ;; propvide some help.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
252 (let ((str (format " %03d" (car (load-average)))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
253 (propertize
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
254 (concat (substring str 0 -2) "." (substring str -2))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
255 'help-echo "System load average")))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
256 (error "")))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
257 (mail-spool-file (or display-time-mail-file
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
258 (getenv "MAIL")
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
259 (concat rmail-spool-directory
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
260 (user-login-name))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
261 (mail (or (and display-time-mail-function
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
262 (funcall display-time-mail-function))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
263 (and (stringp mail-spool-file)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
264 (or (null display-time-server-down-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
265 ;; If have been down for 20 min, try again.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
266 (> (- (nth 1 now) display-time-server-down-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
267 1200)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
268 (and (< (nth 1 now) display-time-server-down-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
269 (> (- (nth 1 now) display-time-server-down-time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
270 -64336)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
271 (let ((start-time (current-time)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
272 (prog1
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
273 (display-time-file-nonempty-p mail-spool-file)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
274 (if (> (- (nth 1 (current-time)) (nth 1 start-time))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
275 20)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
276 ;; Record that mail file is not accessible.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
277 (setq display-time-server-down-time
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
278 (nth 1 (current-time)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
279 ;; Record that mail file is accessible.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
280 (setq display-time-server-down-time nil)))))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
281 (24-hours (substring time 11 13))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
282 (hour (string-to-int 24-hours))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
283 (12-hours (int-to-string (1+ (% (+ hour 11) 12))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
284 (am-pm (if (>= hour 12) "pm" "am"))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
285 (minutes (substring time 14 16))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
286 (seconds (substring time 17 19))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
287 (time-zone (car (cdr (current-time-zone now))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
288 (day (substring time 8 10))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
289 (year (substring time 20 24))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
290 (monthname (substring time 4 7))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
291 (month
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
292 (cdr
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
293 (assoc
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
294 monthname
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
295 '(("Jan" . "1") ("Feb" . "2") ("Mar" . "3") ("Apr" . "4")
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
296 ("May" . "5") ("Jun" . "6") ("Jul" . "7") ("Aug" . "8")
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
297 ("Sep" . "9") ("Oct" . "10") ("Nov" . "11") ("Dec" . "12")))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
298 (dayname (substring time 0 3)))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
299 (setq display-time-string
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
300 (mapconcat 'eval display-time-string-forms ""))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
301 ;; This is inside the let binding, but we are not going to document
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
302 ;; what variables are available.
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
303 (run-hooks 'display-time-hook))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
304 (force-mode-line-update))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
305
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
306 (defun display-time-file-nonempty-p (file)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
307 (and (file-exists-p file)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
308 (< 0 (nth 7 (file-attributes (file-chase-links file))))))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
309
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
310 (if display-time-mode
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
311 (display-time-mode t))
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
312
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
313 (provide 'time)
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
314
1030e638c8dd Remove trailing ^M that prevent CVS-merging.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29693
diff changeset
315 ;;; time.el ends here