From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Decebal Newsgroups: gmane.emacs.help Subject: Re: Extra info in modeline (tip and questions) Date: Wed, 15 Apr 2009 04:06:28 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <533fdd2a-8d26-47ce-9413-1bd2300ee2d1@s20g2000yqh.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1239795662 27004 80.91.229.12 (15 Apr 2009 11:41:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 15 Apr 2009 11:41:02 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 15 13:42:21 2009 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.50) id 1Lu3VL-00021J-AS for geh-help-gnu-emacs@m.gmane.org; Wed, 15 Apr 2009 13:42:11 +0200 Original-Received: from localhost ([127.0.0.1]:49954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lu3Tw-0002IQ-Ey for geh-help-gnu-emacs@m.gmane.org; Wed, 15 Apr 2009 07:40:44 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!r33g2000yqn.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 76 Original-NNTP-Posting-Host: 84.53.123.169 Original-X-Trace: posting.google.com 1239793589 9241 127.0.0.1 (15 Apr 2009 11:06:29 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 15 Apr 2009 11:06:29 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r33g2000yqn.googlegroups.com; posting-host=84.53.123.169; posting-account=K-cdeAoAAAD_0d505kUtHXJaT5LFIu-3 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; nl; rv:1.9.0.8) Gecko/2009032600 SUSE/3.0.8-1.1.1 Firefox/3.0.8,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:168479 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:63753 Archived-At: On 14 apr, 16:03, Decebal wrote: I was not happy with get-mode-line-field. Especially with the (catch 'break I understand that this is the default way to handle a break out of a loop, but I found it ugly, and I expect it is also expensive. So I rewrote it in such a way that the catch is not neccesary anymore. I made it also a little bit more general. I do not need it at the moment, but I made a function to fetch the struct with the right type. So I changed: > =A0 =A0 (defun get-mode-line-field(type) > =A0 =A0 =A0 (let ((i =A0 =A0 0) > =A0 =A0 =A0 =A0 =A0 =A0 (field (format "*%s*" type)) > =A0 =A0 =A0 =A0 =A0 =A0 (total (length mode-line-array)) > =A0 =A0 =A0 =A0 =A0 =A0 ) > =A0 =A0 =A0 =A0 (catch 'break > =A0 =A0 =A0 =A0 =A0 (while (< i total) > =A0 =A0 =A0 =A0 =A0 =A0 (if (equal type (mode-line-struct-type (aref mode= -line- > array i))) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (progn (setq field > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(format "%s: %= s " > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0(mode-line-struct-display (aref > mode-line-array i)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0(funcall (mode-line-struct- > function (aref mode-line-array i))) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(throw 'break nil) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 ) > =A0 =A0 =A0 =A0 =A0 =A0 (incf i) > =A0 =A0 =A0 =A0 =A0 =A0 ) > =A0 =A0 =A0 =A0 =A0 ) > =A0 =A0 =A0 =A0 field > =A0 =A0 =A0 =A0 ) > =A0 =A0 =A0 ) into: (defun get-mode-line-struct(type) (let ((i 0) (this-struct nil) (not-ready t) (total (length mode-line-array)) ) (while (and not-ready (< i total)) (if (equal type (mode-line-struct-type (aref mode-line-array i))) (setq this-struct (aref mode-line-array i) not-ready nil ) (incf i) ) ) this-struct ) ) (defun get-mode-line-field(type) (let ((field (format "*%s*" type)) (this-struct (get-mode-line-struct type)) ) (if this-struct (setq field (format "%s: %s " (mode-line-struct-display this-struct) (funcall (mode-line-struct-function this- struct)) ) ) ) field ) )