From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Le Wang Newsgroups: gmane.emacs.help Subject: Re: Writing a Lisp to show the capacity of the battery of the laptop Date: Tue, 22 Feb 2011 23:13:24 +0800 Message-ID: References: <87r5b1phrr.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=20cf3054ab7df44acb049ce06bc2 X-Trace: dough.gmane.org 1298387662 20420 80.91.229.12 (22 Feb 2011 15:14:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 22 Feb 2011 15:14:22 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Thomas Dean Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 22 16:14:17 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PrtwL-0004JU-Up for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Feb 2011 16:14:14 +0100 Original-Received: from localhost ([127.0.0.1]:58062 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PrtwL-0002wP-73 for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Feb 2011 10:14:13 -0500 Original-Received: from [140.186.70.92] (port=59167 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Prtva-0002uW-Or for help-gnu-emacs@gnu.org; Tue, 22 Feb 2011 10:13:27 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PrtvZ-0005qf-FL for help-gnu-emacs@gnu.org; Tue, 22 Feb 2011 10:13:26 -0500 Original-Received: from mail-iy0-f169.google.com ([209.85.210.169]:36940) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PrtvZ-0005qF-89 for help-gnu-emacs@gnu.org; Tue, 22 Feb 2011 10:13:25 -0500 Original-Received: by iyf13 with SMTP id 13so3909958iyf.0 for ; Tue, 22 Feb 2011 07:13:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=5jtwld1WtzNdyMlXxVzi3z79Mh+AOB7r37GSMrdSqNI=; b=tnwish1SSOQhI3FMTQaffUgTpUf6e4YSReBM681vZKjxUXpB9G0tW85HJm66kO4uYy sbWIg3xFpzZU1Bk6L6Oaw6KDrbFMHU/uOJgWRl3331NAZBAYRLKLZju2aFTCfK5F1Xio 09a4hWnCk+kX51k/Chtn773RYzl8CVzwvcy9c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=C/CbUcM3cbCZk0GMvy0IV06NC4oHczzsyMRGOd6yMzh67VAvksfZ97KhxNn1QHG05E i5tmKV4KxUoXQLT4k/VuHczedCJXSQZ9JDcTBn5VmYXx7RNd+fQ2Jymt8l28lG9TFpVw LswwYSJrVbKtVhht+TKpHFumzeiUBL3TCYILc= Original-Received: by 10.42.227.129 with SMTP id ja1mr3622321icb.248.1298387604618; Tue, 22 Feb 2011 07:13:24 -0800 (PST) Original-Received: by 10.42.220.2 with HTTP; Tue, 22 Feb 2011 07:13:24 -0800 (PST) In-Reply-To: <87r5b1phrr.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.169 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:79324 Archived-At: --20cf3054ab7df44acb049ce06bc2 Content-Type: text/plain; charset=ISO-8859-1 Your Emacs probably came with "Emacs Lisp Intro" C-hi. That's a good place to start. On Mon, Feb 21, 2011 at 10:46 PM, Thomas Dean wrote: > > 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 > > -- > > -- Le --20cf3054ab7df44acb049ce06bc2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Your Emacs probably came with "Emacs Lisp Intro" C-hi. =A0That= 9;s a good place to start.

On Mon, Feb 21= , 2011 at 10:46 PM, Thomas Dean <tdean9db@gmail.com> wrote:

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
=A0"cat /proc/acpi/battery/BAT0/state | grep \"remaining capacity= \" | sed \"s/^[a-z][a-z: ]*\([0-9][0-9]*\).*$/\1/g\"" =A0"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
=A0"cat /proc/acpi/battery/BAT0/info | grep \"last full capacity\= " | sed \"s/^[a-z][a-z: ]*\([0-9][0-9]*\).*$/\1/g\"" =A0"td-battery-temp-buffer")
(setq td-battery-full (string-to-number (buffer-string)))

; calculate percentage
(message (concat "Remaining Capacity: " (number-to-string td-batt= ery-remaining)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "\nFull Capacity: " (number-to-s= tring 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

--




--
Le
--20cf3054ab7df44acb049ce06bc2--