I have a setting in my .emacs like this
(display-battery-mode 1)
. It displays my battery status on mode line. That helps me when i am on laptop with fullscreen. But it goes ugly when i am working on desktop [N/A%][N/A C]
.
So I would like to make it on only when I am working on laptop.
like(if OnLaptop
(display-battery-mode 1))
Thanks.
UPDATE: they both are running Linux(Ubuntu)
I'd use the internals of the battery
package to determine whether or not the battery information was available. This code snippet should do the trick for you:
(require 'battery)
(when (and battery-status-function
(not (string-match-p "N/A"
(battery-format "%B"
(funcall battery-status-function)))))
(display-battery-mode 1))
I use
;; If not on AC power line, then display battery status on the mode line
(and (require 'battery nil t)
(functionp battery-status-function)
(or (equal (cdr (assoc ?L (funcall battery-status-function))) "on-line")
(display-battery-mode 1)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With