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 12:09:41 -0800 (PST) [thread overview]
Message-ID: <75ed4e8a-8f5f-4daf-b8f4-8d090b62bb28@v5g2000prm.googlegroups.com> (raw)
In-Reply-To: 44f70c08-b395-458c-8995-3f2371bde9bf@r15g2000prh.googlegroups.com
On 17 jan, 14:02, Decebal <CLDWester...@gmail.com> wrote:
> 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?
I made an extra for Emacs-Lisp mode. It displays also the number or
functions in the source. It is expecting that every function
definition starts on a line. If that is not the case the number will
be wrong.
(defun buffer-descr-elisp()
(concat
"Functions: " (number-to-string (buffer-count "^(defun ")) " "
)
)
(defun buffer-update-mode-line()
(setq buffer-mode-line (buffer-default-mode-line))
(cond ((string-equal mode-name "Emacs-Lisp")
(setq buffer-mode-line
(concat buffer-mode-line (buffer-descr-elisp))
)
)
)
(force-mode-line-update)
)
prev parent reply other threads:[~2009-01-17 20:09 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
2009-01-17 20:09 ` Decebal [this message]
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=75ed4e8a-8f5f-4daf-b8f4-8d090b62bb28@v5g2000prm.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.