[Top][All Lists]

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

Re: Setting the modeline per (type of) buffer

From: Decebal
Subject: Re: Setting the modeline per (type of) buffer
Date: Sat, 17 Jan 2009 05:02:40 -0800 (PST)
User-agent: G2/1.0

On 17 jan, 12:39, Decebal <address@hidden> 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
  "*Number of chars in the buffer."

(defvar buffer-count-lines
  "*Number of lines in the buffer."

(defvar buffer-count-words
  "*Number of words in the buffer."

(defvar buffer-mode-line
  "*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
         (+ (buffer-count "\n") 1)

        (number-to-string (buffer-count "\\w+"))

        (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))

(unless buffer-mode-line
  (run-with-idle-timer 1 t '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?

reply via email to

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