Mercurial > hg > xemacs-beta
comparison lisp/packages/time.el @ 118:7d55a9ba150c r20-1b11
Import from CVS: tag r20-1b11
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:24:17 +0200 |
parents | 9f59509498e1 |
children | 1370575f1259 |
comparison
equal
deleted
inserted
replaced
117:578fd4947a72 | 118:7d55a9ba150c |
---|---|
1 ;;; time.el --- display time and load in mode line of Emacs. | 1 ;;; time.el --- display time and load in mode line of Emacs. |
2 | 2 |
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 1996 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 86, 87, 93, 94, 1996 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Maintainer: FSF, XEmacs add-ons (C) by Jens T. Lautenbacher | 5 ;; Maintainer: FSF for the original version. |
6 ;; mail <jens@lemming0.lem.uni-karlsruhe.de> | 6 ;; XEmacs add-ons and rewrite (C) by Jens Lautenbacher |
7 ;; for comments/fixes about the enhancements. | 7 ;; mail <jens@lemming0.lem.uni-karlsruhe.de> |
8 ;; for comments/fixes about the enhancements. | |
8 | 9 |
9 ;; This file is part of XEmacs. | 10 ;; This file is part of XEmacs. |
10 | 11 |
11 ;; XEmacs is free software; you can redistribute it and/or modify it | 12 ;; XEmacs is free software; you can redistribute it and/or modify it |
12 ;; under the terms of the GNU General Public License as published by | 13 ;; under the terms of the GNU General Public License as published by |
21 ;; You should have received a copy of the GNU General Public License | 22 ;; You should have received a copy of the GNU General Public License |
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free | 23 ;; along with XEmacs; see the file COPYING. If not, write to the Free |
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | 24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
24 ;; 02111-1307, USA. | 25 ;; 02111-1307, USA. |
25 | 26 |
26 ;;; Version: 1.10 (I choose the version number starting at 1.1 | 27 ;;; Version: 1.13 (I choose the version number starting at 1.1 |
27 ;;; to indicate that 1.0 was the old version | 28 ;;; to indicate that 1.0 was the old version |
28 ;;; before I hacked away on it -jtl) | 29 ;;; before I hacked away on it -jtl) |
29 | 30 |
30 ;;; Synched up with: Not synched with FSF. | 31 ;;; Synched up with: Not synched with FSF. |
31 | 32 |
54 | 55 |
55 ;;; Code: | 56 ;;; Code: |
56 | 57 |
57 (require 'itimer) | 58 (require 'itimer) |
58 | 59 |
60 (defconst display-time-version-number "1.13" "Version number of time.el") | |
61 (defconst display-time-version (format "Time.el version %s for XEmacs" | |
62 display-time-version-number) | |
63 "The full version string for time.el") | |
64 | |
59 (defgroup display-time nil | 65 (defgroup display-time nil |
60 "Facilities to display the current time/date/load and a new-mail indicator | 66 "Facilities to display the current time/date/load and a new-mail indicator |
61 in the XEmacs mode line or echo area." | 67 in the XEmacs mode line or echo area." |
62 :group 'applications) | 68 :group 'applications) |
69 | |
70 (defgroup display-time-balloon nil | |
71 "Fancy add-ons to display-time for using the `balloon-help' feature. | |
72 balloon-help must be loaded before these settings take effect." | |
73 :group 'display-time) | |
74 | |
63 | 75 |
64 (defcustom display-time-mail-file nil | 76 (defcustom display-time-mail-file nil |
65 "*File name of mail inbox file, for indicating existence of new mail. | 77 "*File name of mail inbox file, for indicating existence of new mail. |
66 Non-nil and not a string means don't check for mail. nil means use | 78 Non-nil and not a string means don't check for mail. nil means use |
67 default, which is system-dependent, and is the same as used by Rmail." | 79 default, which is system-dependent, and is the same as used by Rmail." |
202 | 214 |
203 (defcustom display-time-mail-balloon 'display-time-mail-balloon | 215 (defcustom display-time-mail-balloon 'display-time-mail-balloon |
204 "What to use to generate the ballon frame of the \"mail\" glyph | 216 "What to use to generate the ballon frame of the \"mail\" glyph |
205 if balloon-help is loaded. This can be the function | 217 if balloon-help is loaded. This can be the function |
206 display-time-mail-balloon, nil or a string." | 218 display-time-mail-balloon, nil or a string." |
207 :group 'display-time | 219 :group 'display-time-balloon |
208 :type '(choice (const display-time-mail-balloon) | 220 :type '(choice (const display-time-mail-balloon) |
209 (const nil) | 221 (const nil) |
210 (string))) | 222 (string))) |
211 | 223 |
212 (defcustom display-time-no-mail-balloon "No mail is good mail." | 224 (defcustom display-time-no-mail-balloon "No mail is good mail." |
213 "The string used in the ballon frame of the \"no mail\" glyph | 225 "The string used in the ballon frame of the \"no mail\" glyph |
214 if balloon-help is loaded. This can also be nil" | 226 if balloon-help is loaded. This can also be nil" |
215 :group 'display-time | 227 :group 'display-time-balloon |
216 :type '(choice (const nil) | 228 :type '(choice (const nil) |
217 (string))) | 229 (string))) |
218 | 230 |
219 (defcustom display-time-mail-balloon-show-gnus-group nil | 231 (defcustom display-time-mail-balloon-show-gnus-group nil |
220 "Show the mail group gnus would put this message in. | 232 "Show the mail group gnus would put this message in. |
221 This is only useful if you use gnus to read your mail and have set the variable | 233 This is only useful if you use gnus to read your mail and have set the variable |
222 nnmail-split-methods to split your incoming mail into different groups. | 234 nnmail-split-methods to split your incoming mail into different groups. |
223 Look at the documentation for gnus. If you don't know what we're talking about, | 235 Look at the documentation for gnus. If you don't know what we're talking about, |
224 don't care and leave this set to nil" | 236 don't care and leave this set to nil" |
225 :group 'display-time | 237 :group 'display-time-balloon |
226 :type 'boolean) | 238 :type 'boolean) |
227 | 239 |
228 (defface display-time-mail-balloon-enhance-face '((t (:background "orange"))) | 240 (defface display-time-mail-balloon-enhance-face '((t (:background "orange"))) |
229 "Face used for entries in the mail balloon which match the regexp | 241 "Face used for entries in the mail balloon which match the regexp |
230 display-time-mail-balloon-enhance" | 242 display-time-mail-balloon-enhance" |
231 :group 'display-time) | 243 :group 'display-time-balloon) |
232 | 244 |
233 (defface display-time-mail-balloon-gnus-group-face '((t (:foreground "blue"))) | 245 (defface display-time-mail-balloon-gnus-group-face '((t (:foreground "blue"))) |
234 "Face used for the gnus group entry in the mail balloon | 246 "Face used for the gnus group entry in the mail balloon |
235 if display-time-mail-balloon-show-gnus-group is t (see the documentation there | 247 if display-time-mail-balloon-show-gnus-group is t (see the documentation there |
236 before you set it to t)" | 248 before you set it to t)" |
237 :group 'display-time) | 249 :group 'display-time-balloon) |
238 | 250 |
239 (defcustom display-time-mail-balloon-max-displayed 10 | 251 (defcustom display-time-mail-balloon-max-displayed 10 |
240 "The maximum number of messaged which are displayed in the mail balloon. | 252 "The maximum number of messaged which are displayed in the mail balloon. |
241 You need to have balloon-help loaded to use this." | 253 You need to have balloon-help loaded to use this." |
242 :group 'display-time | 254 :group 'display-time-balloon |
243 :type 'number) | 255 :type 'number) |
244 | 256 |
245 (defcustom display-time-mail-balloon-from-width 20 | 257 (defcustom display-time-mail-balloon-from-width 20 |
246 "The width of the `From:' part of the mail balloon. | 258 "The width of the `From:' part of the mail balloon. |
247 You need to have ballon-help loaded to use this" | 259 You need to have ballon-help loaded to use this" |
248 :group 'display-time | 260 :group 'display-time-balloon |
249 :type 'number) | 261 :type 'number) |
250 | 262 |
251 (defcustom display-time-mail-balloon-subject-width 25 | 263 (defcustom display-time-mail-balloon-subject-width 25 |
252 "The width of the `Subject:' part of the mail balloon. | 264 "The width of the `Subject:' part of the mail balloon. |
253 You need to have ballon-help loaded to use this" | 265 You need to have ballon-help loaded to use this" |
254 :group 'display-time | 266 :group 'display-time-balloon |
255 :type 'number) | 267 :type 'number) |
256 | 268 |
257 (defcustom display-time-mail-balloon-gnus-split-width 10 | 269 (defcustom display-time-mail-balloon-gnus-split-width 10 |
258 "The width of the `Gnus Mail Group' part of the mail balloon. | 270 "The width of the `Gnus Mail Group' part of the mail balloon. |
259 This denotes the mail group gnus would decide to put this message in. | 271 This denotes the mail group gnus would decide to put this message in. |
260 For getting this information, it consults the relevant variables from gnus | 272 For getting this information, it consults the relevant variables from gnus |
261 (nnmail-split-methods). | 273 (nnmail-split-methods). |
262 You need to have ballon-help loaded to use this" | 274 You need to have ballon-help loaded to use this" |
263 :group 'display-time | 275 :group 'display-time-balloon |
264 :type 'number) | 276 :type 'number) |
265 | 277 |
266 (defcustom display-time-mail-balloon-enhance nil | 278 (defcustom display-time-mail-balloon-enhance nil |
267 "A list of regular expressions describing which messages should be highlighted | 279 "A list of regular expressions describing which messages should be highlighted |
268 in the mail balloon. The regexp will be matched against the complete header block | 280 in the mail balloon. The regexp will be matched against the complete header block |
269 of an email. You need to load balloon-help to use this" | 281 of an email. You need to load balloon-help to use this" |
270 :group 'display-time | 282 :group 'display-time-balloon |
271 :type '(repeat (string :tag "Regexp"))) | 283 :type '(repeat (string :tag "Regexp"))) |
272 | 284 |
273 (defcustom display-time-mail-balloon-suppress nil | 285 (defcustom display-time-mail-balloon-suppress nil |
274 "A list of regular expressions describing which messages should be completely suppressed | 286 "A list of regular expressions describing which messages should be completely suppressed |
275 in the mail balloon. The regexp will be matched against the complete header block | 287 in the mail balloon. The regexp will be matched against the complete header block |
276 of an email. It will only take effect if the message is not matched already | 288 of an email. It will only take effect if the message is not matched already |
277 by display-time-mail-balloon-enhance. | 289 by display-time-mail-balloon-enhance. |
278 You need to load balloon-help to use this" | 290 You need to load balloon-help to use this" |
279 :group 'display-time | 291 :group 'display-time-balloon |
280 :type '(repeat (string :tag "Regexp"))) | 292 :type '(repeat (string :tag "Regexp"))) |
281 | 293 |
282 (defcustom display-time-mail-balloon-enhance-gnus-group nil | 294 (defcustom display-time-mail-balloon-enhance-gnus-group nil |
283 "A list of regular expressions describing which messages should be highlighted | 295 "A list of regular expressions describing which messages should be highlighted |
284 in the mail balloon. The regexp will be matched against the group gnus would stuff | 296 in the mail balloon. The regexp will be matched against the group gnus would stuff |
285 this message into. It will only take effect if the message is not matched already | 297 this message into. It will only take effect if the message is not matched already |
286 by display-time-mail-balloon-suppress. | 298 by display-time-mail-balloon-suppress. |
287 | 299 |
288 This requires display-time-mail-balloon-show-gnus-group to be t | 300 This requires display-time-mail-balloon-show-gnus-group to be t |
289 and balloon-help to be loaded" | 301 and balloon-help to be loaded" |
290 :group 'display-time | 302 :group 'display-time-balloon |
291 :type '(repeat (string :tag "Regexp"))) | 303 :type '(repeat (string :tag "Regexp"))) |
292 | 304 |
293 (defcustom display-time-mail-balloon-suppress-gnus-group nil | 305 (defcustom display-time-mail-balloon-suppress-gnus-group nil |
294 "A list of regular expressions describing which messages should be completely suppressed | 306 "A list of regular expressions describing which messages should be completely suppressed |
295 in the mail balloon. The regexp will be matched against the group gnus would stuff | 307 in the mail balloon. The regexp will be matched against the group gnus would stuff |
296 this message into. It will only take effect if the message is not matched already | 308 this message into. It will only take effect if the message is not matched already |
297 by display-time-mail-balloon-enhance or display-time-mail-balloon-enhance-gnus-group. | 309 by display-time-mail-balloon-enhance or display-time-mail-balloon-enhance-gnus-group. |
298 | 310 |
299 This requires display-time-mail-balloon-show-gnus-group to be t | 311 This requires display-time-mail-balloon-show-gnus-group to be t |
300 and balloon-help to be loaded" | 312 and balloon-help to be loaded" |
301 :group 'display-time | 313 :group 'display-time-balloon |
302 :type '(repeat (string :tag "Regexp"))) | 314 :type '(repeat (string :tag "Regexp"))) |
303 | 315 |
304 (defvar display-time-spool-file-modification nil) | 316 (defvar display-time-spool-file-modification nil) |
305 | 317 |
306 (defvar display-time-mail-header nil) | 318 (defvar display-time-mail-header nil) |
437 display-time-display-time-foreground | 449 display-time-display-time-foreground |
438 display-time-display-time-bg-old | 450 display-time-display-time-bg-old |
439 display-time-display-time-background) | 451 display-time-display-time-background) |
440 )))) | 452 )))) |
441 | 453 |
442 (if (featurep 'xpm) | 454 (defun display-time-init-glyphs () |
455 "This is a hack to have all glyphs be displayed one time at startup. | |
456 It helps avoiding problems with the background color of the glyphs if a | |
457 balloon-help frame is open and a not yet displayed glyph is going to be | |
458 displayed." | |
459 (let ((i 0) | |
460 (list '("am" "pm" ":")) | |
461 elem mlist) | |
462 (while (< i 10) | |
463 (push (eval (intern-soft (concat "display-time-" | |
464 (number-to-string i) | |
465 "-glyph"))) mlist) | |
466 (setq i (1+ i))) | |
467 (setq i 0.0) | |
468 (while (<= i 3.0) | |
469 (push (eval (intern-soft (concat "display-time-load-" | |
470 (number-to-string i) | |
471 "-glyph"))) mlist) | |
472 (setq i (+ i 0.5))) | |
473 (while (setq elem (pop list)) | |
474 (push (eval (intern-soft (concat "display-time-" | |
475 elem "-glyph"))) mlist)) | |
476 (let ((global-mode-string mlist)) | |
477 (redisplay-frame)) | |
478 )) | |
479 | |
480 (if (featurep 'xpm) | |
443 (progn | 481 (progn |
444 (defvar display-time-mail-sign | 482 (defvar display-time-mail-sign |
445 (cons (make-extent nil nil) | 483 (cons (make-extent nil nil) |
446 (make-glyph (concat display-time-icons-dir "letter.xpm")))) | 484 (make-glyph (concat display-time-icons-dir "letter.xpm")))) |
447 (set-extent-property (car display-time-mail-sign) 'balloon-help | 485 (set-extent-property (car display-time-mail-sign) 'balloon-help |
471 (defvar display-time-load-2.0-glyph nil) | 509 (defvar display-time-load-2.0-glyph nil) |
472 (defvar display-time-load-2.5-glyph nil) | 510 (defvar display-time-load-2.5-glyph nil) |
473 (defvar display-time-load-3.0-glyph nil) | 511 (defvar display-time-load-3.0-glyph nil) |
474 (display-time-generate-time-glyphs 'force) | 512 (display-time-generate-time-glyphs 'force) |
475 (display-time-generate-load-glyphs 'force) | 513 (display-time-generate-load-glyphs 'force) |
514 (display-time-init-glyphs) | |
476 )) | 515 )) |
516 | |
477 | 517 |
478 (defun display-time-can-do-graphical-display (&optional textual) | 518 (defun display-time-can-do-graphical-display (&optional textual) |
479 (and display-time-show-icons-maybe | 519 (and display-time-show-icons-maybe |
480 (not textual) | 520 (not textual) |
481 (eq (console-type) 'x) | 521 (eq (console-type) 'x) |
539 (user-login-name)))) | 579 (user-login-name)))) |
540 (show-split (and display-time-mail-balloon-show-gnus-group | 580 (show-split (and display-time-mail-balloon-show-gnus-group |
541 (or (featurep 'nnmail) (require 'nnmail)))) | 581 (or (featurep 'nnmail) (require 'nnmail)))) |
542 (display-time-mail-balloon-gnus-split-width | 582 (display-time-mail-balloon-gnus-split-width |
543 (if (not show-split) 0 | 583 (if (not show-split) 0 |
544 (+ 3 display-time-mail-balloon-gnus-split-width))) ; <space>[...] -> +3 | 584 (+ 3 display-time-mail-balloon-gnus-split-width))) ; -><space>... = +3 |
545 (mod (nth 5 (file-attributes mail-spool-file))) | 585 (mod (nth 5 (file-attributes mail-spool-file))) |
546 header header-ext) | 586 header header-ext) |
547 (setq header "You have mail:") | 587 (setq header "You have mail:") |
548 (setq header-ext | 588 (setq header-ext |
549 (make-extent 0 (length header) header)) | 589 (make-extent 0 (length header) header)) |
610 (save-excursion | 650 (save-excursion |
611 (if display-time-mail-balloon-enhance | 651 (if display-time-mail-balloon-enhance |
612 (re-search-forward enhance-reg nil t)))) | 652 (re-search-forward enhance-reg nil t)))) |
613 (if show-split | 653 (if show-split |
614 (save-excursion | 654 (save-excursion |
615 (setq point (point-min)) | 655 (goto-char (point-min)) |
616 (nnmail-article-group '(lambda (name) (setq gnus-group name))))) | 656 (nnmail-article-group '(lambda (name) (setq gnus-group name))))) |
617 | 657 |
618 (if enhance () ; this takes prejudice over everything else | 658 (if enhance () ; this takes prejudice over everything else |
619 (setq suppress ; maybe set suppress only if not already enhanced | 659 (setq suppress ; maybe set suppress only if not already enhanced |
620 (save-excursion | 660 (save-excursion |
624 (or (setq enhance ;;maybe we enhance because of the gnus group name | 664 (or (setq enhance ;;maybe we enhance because of the gnus group name |
625 (save-excursion | 665 (save-excursion |
626 (if (and show-split gnus-group | 666 (if (and show-split gnus-group |
627 display-time-mail-balloon-enhance-gnus-group) | 667 display-time-mail-balloon-enhance-gnus-group) |
628 (string-match gnus-enhance-reg gnus-group)))) | 668 (string-match gnus-enhance-reg gnus-group)))) |
629 (setq suppress ;; if we didn't enhance then maybe we have to suppress it? | 669 (setq suppress ;; if we didn't enhance then maybe we have to |
670 ;; suppress it? | |
630 (save-excursion | 671 (save-excursion |
631 (if (and show-split gnus-group | 672 (if (and show-split gnus-group |
632 display-time-mail-balloon-suppress-gnus-group) | 673 display-time-mail-balloon-suppress-gnus-group) |
633 (string-match gnus-suppress-reg gnus-group))))))) | 674 (string-match gnus-suppress-reg gnus-group))))))) |
634 | 675 |
684 (set-extent-property line-ext 'face | 725 (set-extent-property line-ext 'face |
685 'display-time-mail-balloon-gnus-group-face) | 726 'display-time-mail-balloon-gnus-group-face) |
686 (set-extent-property line-ext 'duplicable t) | 727 (set-extent-property line-ext 'duplicable t) |
687 (set-extent-property line-ext 'end-open t))) | 728 (set-extent-property line-ext 'end-open t))) |
688 (push line mail-headers-list)) | 729 (push line mail-headers-list)) |
689 (setq point (point-max)) | 730 (goto-char (point-max)) |
690 (setq suppress nil | 731 (setq suppress nil |
691 gnus-group nil | 732 gnus-group nil |
692 enhance nil) | 733 enhance nil) |
693 (widen) | 734 (widen) |
694 ))) | 735 ))) |
736 (kill-buffer display-time-temp-buffer) | |
695 (if (> (length mail-headers-list) display-time-mail-balloon-max-displayed) | 737 (if (> (length mail-headers-list) display-time-mail-balloon-max-displayed) |
696 (setq not-displayed (- (length mail-headers-list) | 738 (setq not-displayed (- (length mail-headers-list) |
697 display-time-mail-balloon-max-displayed))) | 739 display-time-mail-balloon-max-displayed))) |
698 (while (< i display-time-mail-balloon-max-displayed) | 740 (while (< i display-time-mail-balloon-max-displayed) |
699 (setq mail-headers (concat mail-headers (pop mail-headers-list))) | 741 (setq mail-headers (concat mail-headers (pop mail-headers-list))) |
901 (if display-time-24hr-format 24-hours 12-hours) | 943 (if display-time-24hr-format 24-hours 12-hours) |
902 minutes | 944 minutes |
903 (if display-time-24hr-format "" am-pm)) | 945 (if display-time-24hr-format "" am-pm)) |
904 load | 946 load |
905 (if mail " Mail" "")) | 947 (if mail " Mail" "")) |
906 "*THIS IS OBSOLETE! It will only be used if display-time-compatible is t. | 948 "*It will only be used if display-time-compatible is t. |
907 A list of expressions governing display of the time in the mode line. | 949 A list of expressions governing display of the time in the mode line. |
908 This expression is a list of expressions that can involve the keywords | 950 This expression is a list of expressions that can involve the keywords |
909 `load', `day', `month', and `year', `12-hours', `24-hours', `minutes', | 951 `load', `day', `month', and `year', `12-hours', `24-hours', `minutes', |
910 `seconds', all numbers in string form, and `monthname', `dayname', `am-pm', | 952 `seconds', all numbers in string form, and `monthname', `dayname', `am-pm', |
911 and `time-zone' all alphabetic strings and `mail' a true/nil string value. | 953 and `time-zone' all alphabetic strings and `mail' a true/nil string value. |
915 '((substring year -2) \"/\" month \"/\" day | 957 '((substring year -2) \"/\" month \"/\" day |
916 \" \" 24-hours \":\" minutes \":\" seconds | 958 \" \" 24-hours \":\" minutes \":\" seconds |
917 (if time-zone \" (\") time-zone (if time-zone \")\")) | 959 (if time-zone \" (\") time-zone (if time-zone \")\")) |
918 | 960 |
919 would give mode line times like `94/12/30 21:07:48 (UTC)'.") | 961 would give mode line times like `94/12/30 21:07:48 (UTC)'.") |
962 | |
963 (make-obsolete-variable 'display-time-string-forms | |
964 "You should use the new facilities for `display-time'. | |
965 Look at display-time-form-list.") | |
920 | 966 |
921 (defun display-time-function () | 967 (defun display-time-function () |
922 (let* ((now (current-time)) | 968 (let* ((now (current-time)) |
923 (time (current-time-string now)) | 969 (time (current-time-string now)) |
924 (load (condition-case () | 970 (load (condition-case () |