unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Writing a Lisp to show the capacity of the battery of the laptop
@ 2011-02-21 14:46 Thomas Dean
  2011-02-22 15:13 ` Le Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Thomas Dean @ 2011-02-21 14:46 UTC (permalink / raw)
  To: help-gnu-emacs


Hi,

I'm using Archlinux. I want to write a lisp to show the remaining
capacity of the battery of the laptop. It is expected to work like
this:

1. Read from /proc/acpi/battery/BAT0/state and obtain the remaining
capacity of the battery.
2. Read from /proc/acpi/battery/BAT0/info and obtain the full capacity
of the battery.
3. By calculating remaining / full, get the percentage and print it.

I writing the following lisp but it seems that it doesn't work.

;--------------------------------LISP---------------------------------

; get remaining capacity
(shell-command
 "cat /proc/acpi/battery/BAT0/state | grep \"remaining capacity\" | sed \"s/^[a-z][a-z: ]*\([0-9][0-9]*\).*$/\1/g\""
 "td-battery-temp-buffer")
(set-buffer "td-battery-temp-buffer")
(setq td-battery-full (string-to-number (buffer-string)))
(erase-buffer)

; get full capacity
(shell-command
 "cat /proc/acpi/battery/BAT0/info | grep \"last full capacity\" | sed \"s/^[a-z][a-z: ]*\([0-9][0-9]*\).*$/\1/g\""
 "td-battery-temp-buffer")
(setq td-battery-full (string-to-number (buffer-string)))

; calculate percentage
(message (concat "Remaining Capacity: " (number-to-string td-battery-remaining)
		 "\nFull Capacity: " (number-to-string td-battery-full)))

; kill temporary buffer
(set-buffer-modified-p nil)
(kill-buffer)

;----------------------LISP END-------------------------------

I'm new to lisp :-) So it maybe looks ugly.

Could you please show me a good lisp that can finish this task?

Thomas

-- 



^ permalink raw reply	[flat|nested] 9+ messages in thread
[parent not found: <mailman.14.1298381790.4429.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2011-02-22 17:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-21 14:46 Writing a Lisp to show the capacity of the battery of the laptop Thomas Dean
2011-02-22 15:13 ` Le Wang
2011-02-22 15:33 ` Deniz Dogan
2011-02-22 16:51   ` Alberto Luaces
2011-02-22 17:25     ` Deniz Dogan
2011-02-22 17:35       ` Alberto Luaces
2011-02-22 17:41         ` Deniz Dogan
2011-02-22 17:25 ` Eli Zaretskii
     [not found] <mailman.14.1298381790.4429.help-gnu-emacs@gnu.org>
2011-02-22 16:48 ` Pascal J. Bourguignon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).