help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using setq with global-mode-string


From: Barry Margolin
Subject: Re: Using setq with global-mode-string
Date: Sat, 17 Jan 2009 00:18:54 -0500
User-agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)

In article 
<0c68beb6-9085-400b-9fca-ec825ae4616a@f40g2000pri.googlegroups.com>,
 Decebal <CLDWesterhof@gmail.com> 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 ***


reply via email to

[Prev in Thread] Current Thread [Next in Thread]