From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: Using setq with global-mode-string Date: Sat, 17 Jan 2009 00:18:54 -0500 Organization: A noiseless patient Spider Message-ID: References: <0c68beb6-9085-400b-9fca-ec825ae4616a@f40g2000pri.googlegroups.com> NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1232170877 23694 80.91.229.12 (17 Jan 2009 05:41:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 17 Jan 2009 05:41:17 +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 06:42:29 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 1LO3wt-00043W-Vv for geh-help-gnu-emacs@m.gmane.org; Sat, 17 Jan 2009 06:42:24 +0100 Original-Received: from localhost ([127.0.0.1]:41648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LO3vc-0005N0-KH for geh-help-gnu-emacs@m.gmane.org; Sat, 17 Jan 2009 00:41:04 -0500 Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!feeder.erje.net!news.motzarella.org!motzarella.org!news.motzarella.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 83 Original-X-Trace: news.eternal-september.org U2FsdGVkX1+KcSuhbL3SSy10c8j7ssLHjx8LrhNN2FEUZXTTIH6CeRVOUZt8DWmxuuXsea3KdbH8bNv1pjEV/iAjElAGkw3xITyiyHrMobchQI9Up1CbW0i2jnjAAyw1E5IpggvNVYQ= Original-X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers Original-NNTP-Posting-Date: Sat, 17 Jan 2009 05:18:55 +0000 (UTC) X-Auth-Sender: U2FsdGVkX18MCHAdb0TYeagruz3Sq3JGh2AYihpGtWE= Cancel-Lock: sha1:vcsj6HJlFe24A2Z7Fe/RuUB5+/A= User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Mail-Copies-To: nobody Original-Xref: news.stanford.edu gnu.emacs.help:166094 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:61418 Archived-At: In article <0c68beb6-9085-400b-9fca-ec825ae4616a@f40g2000pri.googlegroups.com>, Decebal wrote: > I have the following code to display the number of lines, words and > chars in the modeline (needs Emacs 22): > > (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." > ) > > (defun buffer-count(expression) > (how-many expression (point-min) (point-max)) > ) > > (defun buffer-update-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")) > ) > (force-mode-line-update) > ) > > (unless buffer-count-lines > (run-with-idle-timer 1 t 'buffer-update-mode-line) > (buffer-update-mode-line) > ) > > (unless (memq 'buffer-count-lines global-mode-string) > (add-to-list 'global-mode-string " Lines: " t) > (add-to-list 'global-mode-string 'buffer-count-lines t) > (add-to-list 'global-mode-string " Words: " t) > (add-to-list 'global-mode-string 'buffer-count-words t) > (add-to-list 'global-mode-string " Chars: " t) > (add-to-list 'global-mode-string 'buffer-count-chars t) > (add-to-list 'global-mode-string " " t) > ; (setq global-mode-string > ; (list 'global-mode-string > ; " Lines: " 'buffer-count-lines > ; " Words: " 'buffer-count-words > ; " Chars: " 'buffer-count-chars > ; " " > ; ) > ; ) > ) > > This works okay. But I would prefer to use the commented setq instead > of the seven add-to-list. I would think it does the same, but when > using setq instead of the add-to-list's, only ' Lines: ' is displayed > and nothing else. Why? Try: (setq global-mode-string (append global-mode-string '(" Lines: " buffer-count-lines " Words: " buffer-count-words " Chars: " buffer-count-chars " "))) -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***