aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Verona2012-12-16 04:26:54 +0100
committerJoakim Verona2012-12-16 04:26:54 +0100
commitb602e17e46e9d1b8bc58b3ac7505361447bb9770 (patch)
treee014bbeda60b5ff1a5da4632287868e1edca189c
parentd5359b8c81496ac51c3c937791c5c6d54062b57b (diff)
parent19b748ad448c37d08ae1df1212aec22ee1d55956 (diff)
downloademacs-b602e17e46e9d1b8bc58b3ac7505361447bb9770.tar.gz
emacs-b602e17e46e9d1b8bc58b3ac7505361447bb9770.zip
auto upstream
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/battery.el72
3 files changed, 80 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 9b847b5ee70..0063aedb0db 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -41,6 +41,10 @@ bound to <f11> and S-<f11>, respectively.
41 41
42* Changes in Specialized Modes and Packages in Emacs 24.4 42* Changes in Specialized Modes and Packages in Emacs 24.4
43 43
44** Battery
45
46*** Battery information via the BSD `apm' utility is now supported.
47
44** cl-lib 48** cl-lib
45 49
46*** New macro cl-tagbody. 50*** New macro cl-tagbody.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 24718e1af02..e56b44ba525 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12012-12-16 Timo Myyrä <timo.myyra@gmail.com>
2
3 * battery.el (battery-bsd-apm): New function.
4
12012-12-16 Jay Belanger <jay.p.belanger@gmail.com> 52012-12-16 Jay Belanger <jay.p.belanger@gmail.com>
2 6
3 * calc/calc.el (calc-standard-date-formats): Adjust one of the 7 * calc/calc.el (calc-standard-date-formats): Adjust one of the
diff --git a/lisp/battery.el b/lisp/battery.el
index 69d25643bb9..79d86c11ac2 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -53,6 +53,9 @@
53 (directory-files "/sys/class/power_supply/" nil 53 (directory-files "/sys/class/power_supply/" nil
54 battery--linux-sysfs-regexp)) 54 battery--linux-sysfs-regexp))
55 'battery-linux-sysfs) 55 'battery-linux-sysfs)
56 ((and (eq system-type 'berkeley-unix)
57 (file-executable-p "/usr/sbin/apm"))
58 'battery-bsd-apm)
56 ((and (eq system-type 'darwin) 59 ((and (eq system-type 'darwin)
57 (condition-case nil 60 (condition-case nil
58 (with-temp-buffer 61 (with-temp-buffer
@@ -523,6 +526,75 @@ The following %-sequences are provided:
523 "AC" 526 "AC"
524 "BAT") 527 "BAT")
525 "N/A"))))) 528 "N/A")))))
529
530
531;;; `apm' interface for BSD.
532(defun battery-bsd-apm ()
533 "Get APM status information from BSD apm binary.
534The following %-sequences are provided:
535%L AC line status (verbose)
536%B Battery status (verbose)
537%b Battery status, empty means high, `-' means low,
538 `!' means critical, and `+' means charging
539%P Advanced power saving mode state (verbose)
540%p Battery charge percentage
541%s Remaining battery charge time in seconds
542%m Remaining battery charge time in minutes
543%h Remaining battery charge time in hours
544%t Remaining battery charge time in the form `h:min'"
545 (let* ((os-name (car (split-string
546 (shell-command-to-string "/usr/bin/uname"))))
547 (apm-flag (if (equal os-name "OpenBSD") "P" "s"))
548 (apm-cmd (concat "/usr/sbin/apm -ablm" apm-flag))
549 (apm-output (split-string (shell-command-to-string apm-cmd)))
550 ;; Battery status
551 (battery-status
552 (let ((stat (string-to-number (nth 0 apm-output))))
553 (cond ((eq stat 0) '("high" . ""))
554 ((eq stat 1) '("low" . "-"))
555 ((eq stat 2) '("critical" . "!"))
556 ((eq stat 3) '("charging" . "+"))
557 ((eq stat 4) '("absent" . nil)))))
558 ;; Battery percentage
559 (battery-percentage (nth 1 apm-output))
560 ;; Battery life
561 (battery-life (nth 2 apm-output))
562 ;; AC status
563 (line-status
564 (let ((ac (string-to-number (nth 3 apm-output))))
565 (cond ((eq ac 0) "disconnected")
566 ((eq ac 1) "connected")
567 ((eq ac 2) "backup power"))))
568 ;; Advanced power savings mode
569 (apm-mode
570 (let ((apm (string-to-number (nth 4 apm-output))))
571 (if (string= os-name "OpenBSD")
572 (cond ((eq apm 0) "manual")
573 ((eq apm 1) "automatic")
574 ((eq apm 2) "cool running"))
575 (if (eq apm 1) "on" "off"))))
576 seconds minutes hours remaining-time)
577 (unless (member battery-life '("unknown" "-1"))
578 (if (member os-name '("OpenBSD" "NetBSD"))
579 (setq minutes (string-to-number battery-life)
580 seconds (* 60 minutes))
581 (setq seconds (string-to-number battery-life)
582 minutes (truncate (/ seconds 60))))
583 (setq hours (truncate (/ minutes 60))
584 remaining-time (format "%d:%02d" hours
585 (- minutes (* 60 hours)))))
586 (list (cons ?L (or line-status "N/A"))
587 (cons ?B (or (car battery-status) "N/A"))
588 (cons ?b (or (cdr battery-status) "N/A"))
589 (cons ?p (if (string= battery-percentage "255")
590 "N/A"
591 battery-percentage))
592 (cons ?P (or apm-mode "N/A"))
593 (cons ?s (or (and seconds (number-to-string seconds)) "N/A"))
594 (cons ?m (or (and minutes (number-to-string minutes)) "N/A"))
595 (cons ?h (or (and hours (number-to-string hours)) "N/A"))
596 (cons ?t (or remaining-time "N/A")))))
597
526 598
527;;; `pmset' interface for Darwin (OS X). 599;;; `pmset' interface for Darwin (OS X).
528 600