all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Decebal <CLDWesterhof@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Setting the modeline per (type of) buffer
Date: Sat, 17 Jan 2009 05:02:40 -0800 (PST)	[thread overview]
Message-ID: <44f70c08-b395-458c-8995-3f2371bde9bf@r15g2000prh.googlegroups.com> (raw)
In-Reply-To: 74ba016f-95cc-4889-97a4-a184217cef1e@v5g2000pre.googlegroups.com

On 17 jan, 12:39, Decebal <CLDWester...@gmail.com> 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
  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."
  )

(defvar buffer-mode-line
  nil
  "*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
	(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"))
	)
  (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))
  (force-mode-line-update)
  )

(unless buffer-mode-line
  (run-with-idle-timer 1 t 'buffer-update-mode-line)
  (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	other threads:[~2009-01-17 13:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-17 11:39 Setting the modeline per (type of) buffer Decebal
2009-01-17 13:02 ` Decebal [this message]
2009-01-17 20:09   ` Decebal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44f70c08-b395-458c-8995-3f2371bde9bf@r15g2000prh.googlegroups.com \
    --to=cldwesterhof@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.