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 05:02:40 -0800 (PST) Organization: http://groups.google.com Message-ID: <44f70c08-b395-458c-8995-3f2371bde9bf@r15g2000prh.googlegroups.com> References: <74ba016f-95cc-4889-97a4-a184217cef1e@v5g2000pre.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1232199643 28038 80.91.229.12 (17 Jan 2009 13:40:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 17 Jan 2009 13:40:43 +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 14:41:56 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 1LOBQw-0005Cu-Az for geh-help-gnu-emacs@m.gmane.org; Sat, 17 Jan 2009 14:41:54 +0100 Original-Received: from localhost ([127.0.0.1]:50527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LOBPf-00033O-JI for geh-help-gnu-emacs@m.gmane.org; Sat, 17 Jan 2009 08:40:35 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!r15g2000prh.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 79 Original-NNTP-Posting-Host: 84.53.123.169 Original-X-Trace: posting.google.com 1232197360 10612 127.0.0.1 (17 Jan 2009 13:02:40 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sat, 17 Jan 2009 13:02:40 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r15g2000prh.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/2008120121 Firefox/3.0.5,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:166100 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:61424 Archived-At: 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 nil "*Number of chars in the buffer." ) (defvar buffer-count-lines nil "*Number of lines in the buffer." ) (defvar buffer-count-words nil "*Number of words in the buffer." ) (defvar buffer-mode-line nil "*Extension of modeline in the buffer." ) (defun buffer-count(expression) (how-many expression (point-min) (point-max)) ) (defun buffer-default-mode-line() (setq buffer-count-lines (number-to-string (+ (buffer-count "\n") 1) ) buffer-count-words (number-to-string (buffer-count "\\w+")) buffer-count-chars (number-to-string (buffer-count ".\\|\n")) ) (concat "Lines: " buffer-count-lines " Words: " buffer-count-words " Chars: " buffer-count-chars " " ) ) (defun buffer-update-mode-line() (setq buffer-mode-line (buffer-default-mode-line)) (force-mode-line-update) ) (unless buffer-mode-line (run-with-idle-timer 1 t 'buffer-update-mode-line) (buffer-update-mode-line) ) (unless (memq 'buffer-mode-line global-mode-string) (setq global-mode-string (append global-mode-string '(" " buffer-mode-line) ) ) ) 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?