Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs , is it running on laptop or on desktop?

Tags:

emacs

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)

like image 324
kindahero Avatar asked Apr 06 '11 07:04

kindahero


2 Answers

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))
like image 56
Trey Jackson Avatar answered Oct 11 '22 10:10

Trey Jackson


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)))
like image 27
link0ff Avatar answered Oct 11 '22 10:10

link0ff