unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Using setq with global-mode-string
@ 2009-01-16 23:35 Decebal
  2009-01-17  5:18 ` Barry Margolin
  0 siblings, 1 reply; 3+ messages in thread
From: Decebal @ 2009-01-16 23:35 UTC (permalink / raw)
  To: help-gnu-emacs

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?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using setq with global-mode-string
  2009-01-16 23:35 Using setq with global-mode-string Decebal
@ 2009-01-17  5:18 ` Barry Margolin
  2009-01-17 11:30   ` Decebal
  0 siblings, 1 reply; 3+ messages in thread
From: Barry Margolin @ 2009-01-17  5:18 UTC (permalink / raw)
  To: help-gnu-emacs

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 ***


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using setq with global-mode-string
  2009-01-17  5:18 ` Barry Margolin
@ 2009-01-17 11:30   ` Decebal
  0 siblings, 0 replies; 3+ messages in thread
From: Decebal @ 2009-01-17 11:30 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 17, 6:18 am, Barry Margolin <bar...@alum.mit.edu> wrote:
> >     (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
>                 " ")))

That works. Thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-01-17 11:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-16 23:35 Using setq with global-mode-string Decebal
2009-01-17  5:18 ` Barry Margolin
2009-01-17 11:30   ` Decebal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).