;;; echotime.el --- time, date, and battery info in Emacs echo area ;; Copyright (C) 2009 Neil Van Dyke ;; ;; Author: Neil Van Dyke ;; Version: 1.0 ;; Date: 2009-10-25 ;; Keywords: time ;; Web: http://www.neilvandyke.org/echotime-emacs/ ;; CVS: $Id: echotime.el,v 1.8 2009/10/25 14:09:19 neilpair Exp $ ;; This file is NOT part of GNU Emacs. ;; ;; This is free software: you can redistribute it and/or modify it under the ;; terms of the GNU General Public License as published by the Free Software ;; Foundation, either version 3 of the License, or (at your option) any later ;; version. ;; ;; This is distributed in the hope that it will be useful, but without any ;; warranty; without even the implied warranty of merchantability or fitness for ;; a particular purpose. See the GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License along with ;; GNU Emacs. If not, see . ;;; Commentary: ;;; `echotime' is a small Emacs function that will display the date, time of ;;; day, and battery information in the echo area, on command. Both local time ;;; and UTC time are displayed. ;;; ;;; I bind it to a key sequence, like so: ;;; ;;; (global-set-key "\C-ct" 'echotime) ;;; ;;; I wrote `echotime' a long time ago, when spending most of my time shuffling ;;; around town, trying to find power for my little old laptop, and conserving ;;; power by not running much other than Emacs. I'm releasing it because I ;;; still find it a convenient way to check this information. ;;; Code: (require 'battery nil t) (defun echotime () (interactive) (let* ((time (current-time)) (fg "black") (bg "gray90") (dim "gray60") (t-str (propertize "T" 'face `(:foreground ,dim :background ,bg))) (space1 (propertize " " 'face `(:foreground ,dim :background ,bg))) (space3 (propertize " " 'face `(:foreground ,dim :background ,bg)))) ;; TODO: Generalize redundant code for time formatting. (message "%s%s%s" (concat space1 (propertize (format-time-string "%a " time) 'face `(:weight bold :foreground ,fg :background ,bg )) (propertize (format-time-string "%Y-" time) 'face `(:foreground ,fg :background ,bg )) (propertize (format-time-string "%m-%d" time) 'face `(:weight bold :foreground ,fg :background ,bg )) t-str (propertize (format-time-string "%H:%M" time) 'face `(:weight bold :foreground "black" :background "yellow")) (propertize (format-time-string ":%S" time) 'face `(:foreground "black" :background ,bg )) (propertize (format-time-string "%z" time) 'face `(:foreground "gray40" :background ,bg))) (if (member (nth 1 (current-time-zone time)) '("UTC" "GMT")) "" (concat space3 (propertize (format-time-string "%Y-" time t) 'face `(:foreground ,fg :background ,bg)) (propertize (format-time-string "%m-%d" time t) 'face `( :foreground ,fg :background ,bg)) t-str (propertize (format-time-string "%H:%M" time t) 'face `(:weight bold :foreground ,fg :background ,bg )) (propertize (format-time-string ":%S" time t) 'face `(:foreground ,fg :background ,bg)) (propertize "Z" 'face `(:foreground ,dim :background ,bg)))) (if (featurep 'battery) (let* ((bat (funcall battery-status-function)) (onlinep (member (battery-format "%L" bat) '("AC" "on-line")))) (concat space3 (if onlinep (concat (propertize " AC-Line " 'face '(:weight bold :foreground "white" :background "green4")) space1) (concat (propertize " Battery " 'face '(:weight bold :foreground "white" :background "orange")) space1)) (propertize (battery-format "%p%% %t" bat) 'face `(:foreground ,fg :background ,bg)) space1)) (concat space3 (propertize " Power " 'face '(:weight bold :foreground "white" :background "blue")) space1))))) (provide 'echotime) ;;; echotime.el ends here