all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Setting the modeline per (type of) buffer
@ 2009-01-17 11:39 Decebal
  2009-01-17 13:02 ` Decebal
  0 siblings, 1 reply; 3+ messages in thread
From: Decebal @ 2009-01-17 11:39 UTC (permalink / raw
  To: help-gnu-emacs

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.


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

* Re: Setting the modeline per (type of) buffer
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Decebal @ 2009-01-17 13:02 UTC (permalink / raw
  To: help-gnu-emacs

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?


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

* Re: Setting the modeline per (type of) buffer
  2009-01-17 13:02 ` Decebal
@ 2009-01-17 20:09   ` Decebal
  0 siblings, 0 replies; 3+ messages in thread
From: Decebal @ 2009-01-17 20:09 UTC (permalink / raw
  To: help-gnu-emacs

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



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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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.