From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Yoni Rabkin Katzenell Newsgroups: gmane.emacs.devel Subject: wireless.el -- display wireless status on the mode-line Date: Fri, 23 Nov 2007 16:32:38 +0200 Message-ID: <87pry1jam1.fsf@actcom.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1195828641 3241 80.91.229.12 (23 Nov 2007 14:37:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Nov 2007 14:37:21 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Nov 23 15:37:27 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IvZem-00023v-7e for ged-emacs-devel@m.gmane.org; Fri, 23 Nov 2007 15:37:24 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IvZeX-0002mQ-NF for ged-emacs-devel@m.gmane.org; Fri, 23 Nov 2007 09:37:09 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IvZeT-0002lC-O9 for emacs-devel@gnu.org; Fri, 23 Nov 2007 09:37:05 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IvZeR-0002kN-Ti for emacs-devel@gnu.org; Fri, 23 Nov 2007 09:37:05 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IvZeR-0002kD-Mw for emacs-devel@gnu.org; Fri, 23 Nov 2007 09:37:03 -0500 Original-Received: from sa9.bezeqint.net ([192.115.104.23]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IvZeQ-0004vL-OM for emacs-devel@gnu.org; Fri, 23 Nov 2007 09:37:03 -0500 Original-Received: from localhost (unknown [127.0.0.1]) by sa9.bezeqint.net (Bezeq International SMTP out Mail Server) with ESMTP id 48D5033BCE for ; Fri, 23 Nov 2007 16:31:09 +0200 (IST) Original-Received: from sa9.bezeqint.net ([127.0.0.1]) by localhost (sa9.bezeqint.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 08457-03 for ; Fri, 23 Nov 2007 16:30:58 +0200 (IST) Original-Received: from ardbeg.actcom.com (unknown [79.182.238.34]) by sa9.bezeqint.net (Bezeq International SMTP out Mail Server) with ESMTP for ; Fri, 23 Nov 2007 16:30:58 +0200 (IST) X-Ethics: Use GNU User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux) X-Virus-Scanned: amavisd-new at bezeqint.net X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:83962 Archived-At: --=-=-= Hello, Attached is a small library to display the status (signal strength, interface name, etc.) of a GNU/Linux wireless network connection on the Emacs mode-line. I'm sending it in to the list in hopes that people will find it useful. I find it an excellent companion to battery.el on my laptop. It is implemented by parsing the /proc/net/wireless file found on some GNU/Linux systems with a working wireless interface. It can also be downloaded via Darcs with: $ darcs get http://yrk.nfshost.com/repos/wireless --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=wireless.el Content-Transfer-Encoding: quoted-printable Content-Description: wireless.el ;;; wireless --- Display wireless status information ;; Copyright (C) 2007 Yoni Rabkin ;; ;; Author: Yoni Rabkin ;;=20 ;; Derived from code from battery.el by Ralph Schleicher ;; ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 3 of ;; the License, or (at your option) any later version. ;;=20=20=20=20=20 ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;;=20=20=20=20=20 ;; You should have received a copy of the GNU General Public ;; License along with this program; if not, write to the Free ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. ;;; Commentary: ;; ;; To install this library, place it in your load path with: ;; ;; (add-to-list 'load-path "/PATH/TO/wireless") ;; ;; Then add to your .emacs: ;; ;; (require 'wireless) ;; (display-wireless-mode t) ;;; History: ;;=20 ;; Originally written in October of 2007. ;; ;; Thank you to Ralph Schleicher for kindly and patiently repling to ;; my emails about battery.el. ;;; Code: (require 'timer) (defgroup wireless nil "*Display wireless status information." :prefix "wireless-" :group 'wireless) (defcustom wireless-procfile "/proc/net/wireless" "*Location of the wireless information file." :type 'string :group 'wireless) (defcustom wireless-procfile-regexp "^[ ]+\\(....\\):[ ]+\\([0-9]+\\)[ ]+\\([0-9]+\\)[ .]+\\([0-9]+\\)[ .]+\\= ([0-9]+\\)" "*Regular expression for extracting proc-file data." :type 'string :group 'wireless) (defcustom wireless-mode-line-format "[%k]" "*Format string for mode-line display of the wireless status. All characters are printed as-is unless they are prefixed with %, in which case both the prefix and the control character are replaced with data corresponding to the following table (to print a single percent sign use \"%%\"): %n, name of the network interface %k, quality level (percentile) for the primary wireless network interface %l, signal level %s, noise level If any of the above are not available, \"N/A\" will be displayed instead." :type 'string :group 'wireless) (defvar wireless-mode-line-string "" "String to display in the mode line.") (defvar wireless-update-timer nil "Interval timer object.") (defun wireless-info-readable-p () "Return true if there is readable data available." (and (eq system-type 'gnu/linux) (file-readable-p wireless-procfile))) ;; This function should have separate COND clauses for each supported ;; system and should always return a list like: ;; ;; (list name status link level noise) ;; (defun wireless-read-interface-line () "Return a list of the interface data." (cond ((eq system-type 'gnu/linux) (let (name status link level noise) (re-search-forward wireless-procfile-regexp (point-at-eol) t) (setq name (match-string 1) status (match-string 2) link (match-string 3) level (match-string 4) noise (match-string 5)) (list name status link level noise))))) ;; this function should be system type agnostic (defun wireless-read () "Return a list of all interfaces with their data." (let (result) (with-temp-buffer (ignore-errors (insert-file-contents wireless-procfile)) (forward-line 2) ;; go past the comments (while (not (eobp)) (goto-char (point-at-bol)) (setq result (append result (list (wireless-read-interface-line)))) (forward-line 1))) result)) (defun wireless-format-function () "Return an alist that `wireless-format' can parse." (let* ((primary-interface (car (wireless-read))) (name (nth 0 primary-interface)) (link (nth 2 primary-interface)) (level (nth 3 primary-interface)) (noise (nth 4 primary-interface))) (list (cons ?n (or name "N/A")) (cons ?k (or link "N/A")) (cons ?l (or level "N/A")) (cons ?s (or noise "N/A"))))) (defun wireless-format (format) "Substitute %-sequences in FORMAT." (let ((alist (wireless-format-function))) (replace-regexp-in-string "%." (lambda (str) (let ((char (aref str 1))) (if (eq char ?%) "%" (or (cdr (assoc char alist)) "")))) format t t))) (defun wireless-update () "Update wireless status information in the mode line." (setq wireless-mode-line-string (wireless-format wireless-mode-line-forma= t)) (force-mode-line-update)) (defun wireless-update-handler () "Handler function for updating the mode-line." (wireless-update) (sit-for 0)) ;; If there are multiple wireless interfaces, they will be displayed ;; here. (defun wireless () "Display a message with wireless interface data." (interactive) (when (not (wireless-info-readable-p)) (error "No wireless info available or unsupported system type")) (let ((data (wireless-read)) (str "")) (mapc #'(lambda (e) (setq str (concat str (format "%s quality is at %s. " (nth 0 e) (nth 2 e)= )))) data) (message str))) ;;;###autoload (define-minor-mode display-wireless-mode "Display wireless status information." :global t :group 'wireless (setq wireless-mode-line-string "") (or global-mode-string (setq global-mode-string '(""))) (and wireless-update-timer (cancel-timer wireless-update-timer)) (if (not display-wireless-mode) (setq global-mode-string (delq 'wireless-mode-line-string global-mode-string)) (add-to-list 'global-mode-string 'wireless-mode-line-string t) (setq wireless-update-timer (run-at-time nil 60 'wireless-update-handler)) (wireless-update))) (provide 'wireless) ;;; wireless.el ends here --=-=-= -- "Cut your own wood and it will warm you twice" --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--