From: Francois Fleuret Date: Mon, 29 Aug 2011 06:06:35 +0000 (+0200) Subject: Fixed the energy/charge filename issue for the battery. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=a22b5d979d27f2cf3818a00b6513a92e9f835968;p=elisp.git Fixed the energy/charge filename issue for the battery. --- diff --git a/emacs.el b/emacs.el index a2278be..31b9abf 100644 --- a/emacs.el +++ b/emacs.el @@ -773,9 +773,12 @@ printer." (insert-file-contents-literally file) (buffer-substring (point-at-bol) (point-at-eol)))) -(defun ff/battery-percent () - (/ (* 100 (string-to-number (ff/file-first-line (concat ff/battery-dir "/charge_now")))) - (string-to-number (ff/file-first-line (concat ff/battery-dir "/charge_full"))))) +(defun ff/battery-percent (prefix) + (condition-case nil + (/ (* 100 (string-to-number (ff/file-first-line (format "%s/%s_now" ff/battery-dir prefix)))) + (string-to-number (ff/file-first-line (format "%s/%s_full" ff/battery-dir prefix)))) + (error -1)) + ) (defun ff/laptop-info-string () (interactive) (condition-case nil @@ -785,7 +788,7 @@ printer." (let ((temp (/ (string-to-number (ff/file-first-line ff/temperature-file)) 1000))) (if (> temp 50) (concat - (let ((s (format "%dC" temp))) + (let ((s (format "%dC " temp))) (if (> temp 65) (propertize s 'face 'font-lock-warning-face) s)) @@ -793,17 +796,15 @@ printer." ) ) - " " - ;; The battery (let ((battery-status (ff/file-first-line (concat ff/battery-dir "/status")))) (cond ((string= battery-status "Full") "L") - ((string= battery-status "Charging") (format "L%d%%" (ff/battery-percent))) - ((string= battery-status "Discharging") (format "B%d%%" (ff/battery-percent))) - (t "?"))) + ((string= battery-status "Charging") (format "L%d%%" (ff/battery-percent "energy"))) + ((string= battery-status "Discharging") (format "B%d%%" (ff/battery-percent "charge"))) + (t battery-status))) )