[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Using setq with global-mode-string
From: |
Decebal |
Subject: |
Using setq with global-mode-string |
Date: |
Fri, 16 Jan 2009 15:35:35 -0800 (PST) |
User-agent: |
G2/1.0 |
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?
- Using setq with global-mode-string,
Decebal <=