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: Setting the modeline per (type of) buffer Date: Sat, 17 Jan 2009 12:09:41 -0800 (PST) Organization: http://groups.google.com Message-ID: <75ed4e8a-8f5f-4daf-b8f4-8d090b62bb28@v5g2000prm.googlegroups.com> References: <74ba016f-95cc-4889-97a4-a184217cef1e@v5g2000pre.googlegroups.com> <44f70c08-b395-458c-8995-3f2371bde9bf@r15g2000prh.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 1232224851 32316 80.91.229.12 (17 Jan 2009 20:40:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 17 Jan 2009 20:40:51 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jan 17 21:42:03 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 1LOHzU-000888-W0 for geh-help-gnu-emacs@m.gmane.org; Sat, 17 Jan 2009 21:42:01 +0100 Original-Received: from localhost ([127.0.0.1]:57989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LOHyD-0007xD-Uo for geh-help-gnu-emacs@m.gmane.org; Sat, 17 Jan 2009 15:40:41 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!v5g2000prm.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 104 Original-NNTP-Posting-Host: 84.53.123.169 Original-X-Trace: posting.google.com 1232222981 23492 127.0.0.1 (17 Jan 2009 20:09:41 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sat, 17 Jan 2009 20:09:41 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v5g2000prm.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.5) Gecko/2008121300 SUSE/3.0.5-1.1 Firefox/3.0.5,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:166113 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:61435 Archived-At: On 17 jan, 14:02, Decebal wrote: > On 17 jan, 12:39, Decebal wrote: > > > I made something to display the lines, words and characters in the > > modeline with filling global-mode-string. But what if I wanted to > > displat different things in different modes/buffers? For example, > > maybe it would be handy to have the number of functions in my C-code. > > But that is of no use in a normal text-file. > > I found the first part. I made the following code: > > (defvar buffer-count-chars > =A0 nil > =A0 "*Number of chars in the buffer." > =A0 ) > > (defvar buffer-count-lines > =A0 nil > =A0 "*Number of lines in the buffer." > =A0 ) > > (defvar buffer-count-words > =A0 nil > =A0 "*Number of words in the buffer." > =A0 ) > > (defvar buffer-mode-line > =A0 nil > =A0 "*Extension of modeline in the buffer." > =A0 ) > > (defun buffer-count(expression) > =A0 (how-many expression (point-min) (point-max)) > =A0 ) > > (defun buffer-default-mode-line() > =A0 (setq buffer-count-lines > =A0 =A0 =A0 =A0 (number-to-string > =A0 =A0 =A0 =A0 =A0(+ (buffer-count "\n") 1) > =A0 =A0 =A0 =A0 ) > > =A0 =A0 =A0 =A0 buffer-count-words > =A0 =A0 =A0 =A0 (number-to-string (buffer-count "\\w+")) > > =A0 =A0 =A0 =A0 buffer-count-chars > =A0 =A0 =A0 =A0 (number-to-string (buffer-count ".\\|\n")) > =A0 =A0 =A0 =A0 ) > =A0 (concat "Lines: " buffer-count-lines > =A0 =A0 =A0 =A0 =A0 " Words: " buffer-count-words > =A0 =A0 =A0 =A0 =A0 " Chars: " buffer-count-chars > =A0 =A0 =A0 =A0 =A0 " " > =A0 =A0 =A0 =A0 =A0 ) > =A0 ) > > (defun buffer-update-mode-line() > =A0 (setq buffer-mode-line (buffer-default-mode-line)) > =A0 (force-mode-line-update) > =A0 ) > > (unless buffer-mode-line > =A0 (run-with-idle-timer 1 t 'buffer-update-mode-line) > =A0 (buffer-update-mode-line) > =A0 ) > > (unless (memq 'buffer-mode-line global-mode-string) > =A0 (setq global-mode-string > =A0 =A0 =A0 =A0 (append global-mode-string > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 '(" " buffer-mode-line) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ) > =A0 =A0 =A0 =A0 ) > =A0 ) > > In the function buffer-update-mode-line I could do things depending on > the mode. > One things puzzles me. In the setq global-mode-string I need the " > " (first parameter of the append), otherwise I get an invalid in my > modeline. Because of this the first displayed text needs not have a > space before it (otherwise it would get two). Why is this? > > Is this a good way to do this, or is there a better way? I made an extra for Emacs-Lisp mode. It displays also the number or functions in the source. It is expecting that every function definition starts on a line. If that is not the case the number will be wrong. (defun buffer-descr-elisp() (concat "Functions: " (number-to-string (buffer-count "^(defun ")) " " ) ) (defun buffer-update-mode-line() (setq buffer-mode-line (buffer-default-mode-line)) (cond ((string-equal mode-name "Emacs-Lisp") (setq buffer-mode-line (concat buffer-mode-line (buffer-descr-elisp)) ) ) ) (force-mode-line-update) )