unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Style in elisp: how to show a flag value in the modeline?
@ 2003-02-20  9:50 François Fleuret
  2003-02-20 11:46 ` Kai Großjohann
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: François Fleuret @ 2003-02-20  9:50 UTC (permalink / raw)


Hi,

What is the good way to show in the modeline the value of a boolean of
a flag associated to a major-mode ? The current solution I came with
is to change the value of `mode-name'. But I have the feeling that
should be done another way. Any advice ?

Regards,

FF

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-20  9:50 Style in elisp: how to show a flag value in the modeline? François Fleuret
@ 2003-02-20 11:46 ` Kai Großjohann
  2003-02-20 12:45   ` François Fleuret
  2003-02-20 12:48 ` Oliver Scholz
  2003-02-20 20:45 ` Stefan Monnier <foo@acm.com>
  2 siblings, 1 reply; 13+ messages in thread
From: Kai Großjohann @ 2003-02-20 11:46 UTC (permalink / raw)


francois.fleuret@noos.fr (François Fleuret) writes:

> What is the good way to show in the modeline the value of a boolean of
> a flag associated to a major-mode ? The current solution I came with
> is to change the value of `mode-name'. But I have the feeling that
> should be done another way. Any advice ?

Maybe minor-mode-alist is the right pointer?
-- 
A preposition is not a good thing to end a sentence with.

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-20 11:46 ` Kai Großjohann
@ 2003-02-20 12:45   ` François Fleuret
  2003-02-20 17:26     ` Kai Großjohann
  2003-02-20 17:26     ` Kai Großjohann
  0 siblings, 2 replies; 13+ messages in thread
From: François Fleuret @ 2003-02-20 12:45 UTC (permalink / raw)


Hi,

Kai Großjohann wrote on 20 Feb 2003 12:46:28 MET:

> Maybe minor-mode-alist is the right pointer?

I added

(setq minor-mode-alist
  (assq-delete-all 'mp3play-auto-mode minor-mode-alist))

in a function called by kill-buffer-hook, and

(setq minor-mode-alist
  (cons  '(mp3play-auto-mode " auto-play") minor-mode-alist))

in the initialization. Also, (force-mode-line-update) when the flag is
flipped. Is that the right way to go ? Using minor-mode-alist wihout
having defined a minor-mode ?

I still wonder a bit on two points. First, this variable is not
buffer-local, thus the flag appears in all buffers (on the other hand
I want the other monior mode to appear in my mp3play buffer.) Also to
avoid to add twice the same assoc in the list, should I ensure that
myself, or can it be handled in a smart way by the alist artillerie ?

Sorry for those questions, but I really have a hard time getting a
feeling on how things "should be" written in elisp.

Regards,

FF

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-20  9:50 Style in elisp: how to show a flag value in the modeline? François Fleuret
  2003-02-20 11:46 ` Kai Großjohann
@ 2003-02-20 12:48 ` Oliver Scholz
  2003-02-20 20:45 ` Stefan Monnier <foo@acm.com>
  2 siblings, 0 replies; 13+ messages in thread
From: Oliver Scholz @ 2003-02-20 12:48 UTC (permalink / raw)


francois.fleuret@noos.fr (François Fleuret) writes:

> Hi,
>
> What is the good way to show in the modeline the value of a boolean of
> a flag associated to a major-mode ? The current solution I came with
> is to change the value of `mode-name'. But I have the feeling that
> should be done another way. Any advice ?

Hmm, how about:

(defvar my-flag t)

(setq mode-line-format (copy-sequence mode-line-format))

(setcdr (nthcdr 4 mode-line-format)
	(cons '(:eval (if my-flag " True" " False"))
	      (nthcdr 5 mode-line-format)))


It seems like an odd way to modify the mode-line, but I can't think of
any better right now.

    Oliver
-- 
2 Ventôse an 211 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-20 12:45   ` François Fleuret
@ 2003-02-20 17:26     ` Kai Großjohann
  2003-02-20 17:26     ` Kai Großjohann
  1 sibling, 0 replies; 13+ messages in thread
From: Kai Großjohann @ 2003-02-20 17:26 UTC (permalink / raw)


francois.fleuret@noos.fr (François Fleuret) writes:

> I added
>
> (setq minor-mode-alist
>   (assq-delete-all 'mp3play-auto-mode minor-mode-alist))
>
> in a function called by kill-buffer-hook, and
>
> (setq minor-mode-alist
>   (cons  '(mp3play-auto-mode " auto-play") minor-mode-alist))
>
> in the initialization. Also, (force-mode-line-update) when the flag is
> flipped. Is that the right way to go ? Using minor-mode-alist wihout
> having defined a minor-mode ?

I suggest to just frob the variable mp3play-auto-mode and leave the
entry in at all times.  That's how it's intended to be used.

-- 
A preposition is not a good thing to end a sentence with.

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-20 12:45   ` François Fleuret
  2003-02-20 17:26     ` Kai Großjohann
@ 2003-02-20 17:26     ` Kai Großjohann
  2003-02-21  8:57       ` François Fleuret
  1 sibling, 1 reply; 13+ messages in thread
From: Kai Großjohann @ 2003-02-20 17:26 UTC (permalink / raw)


francois.fleuret@noos.fr (François Fleuret) writes:

> I still wonder a bit on two points. First, this variable is not
> buffer-local

Why not?  Why not make it so?
-- 
A preposition is not a good thing to end a sentence with.

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-20  9:50 Style in elisp: how to show a flag value in the modeline? François Fleuret
  2003-02-20 11:46 ` Kai Großjohann
  2003-02-20 12:48 ` Oliver Scholz
@ 2003-02-20 20:45 ` Stefan Monnier <foo@acm.com>
  2 siblings, 0 replies; 13+ messages in thread
From: Stefan Monnier <foo@acm.com> @ 2003-02-20 20:45 UTC (permalink / raw)


>>>>> "FF" == François Fleuret <francois.fleuret@noos.fr> writes:
> What is the good way to show in the modeline the value of a boolean of
> a flag associated to a major-mode ? The current solution I came with
> is to change the value of `mode-name'. But I have the feeling that
> should be done another way. Any advice ?

I think a standard way to do it is

  (set (make-local-variable 'mode-line-process)
       '("" (var-1 " var-1 is ON" " var-1 is OFF") var-2))

this would display the boolean status of var-1 and the current value
of var-2 right after the major-mode and before the minor modes.
At least that's what I use in PCL-CVS and it works well.
The value of mode-line-process (and of var-2 as well) is interpreted in
the same way as mode-line-format (except maybe that % escape thingies
don't work, IIRC).


        Stefan

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-20 17:26     ` Kai Großjohann
@ 2003-02-21  8:57       ` François Fleuret
  2003-02-21 17:54         ` Kai Großjohann
  0 siblings, 1 reply; 13+ messages in thread
From: François Fleuret @ 2003-02-21  8:57 UTC (permalink / raw)


Hi people,

Kai Großjohann wrote on 20 Feb 2003 18:26:42 MET:

> Why not?  Why not make it so?

Would the modifications to minor-mode-alist made in the futur taken
into account in that buffer too ? They should, shouldn't they ?

Regards,

FF

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-21  8:57       ` François Fleuret
@ 2003-02-21 17:54         ` Kai Großjohann
  2003-02-21 18:07           ` François Fleuret
  0 siblings, 1 reply; 13+ messages in thread
From: Kai Großjohann @ 2003-02-21 17:54 UTC (permalink / raw)


francois.fleuret@noos.fr (François Fleuret) writes:

> Hi people,
>
> Kai Großjohann wrote on 20 Feb 2003 18:26:42 MET:
>
>> Why not?  Why not make it so?
>
> Would the modifications to minor-mode-alist made in the futur taken
> into account in that buffer too ? They should, shouldn't they ?

Hm?

I was suggesting to make the variable mp4play-auto-mode buffer-local,
and to keep minor-mode-alist global.

Was there a misunderstanding?
-- 
A preposition is not a good thing to end a sentence with.

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-21 17:54         ` Kai Großjohann
@ 2003-02-21 18:07           ` François Fleuret
  2003-02-21 20:41             ` Kai Großjohann
  0 siblings, 1 reply; 13+ messages in thread
From: François Fleuret @ 2003-02-21 18:07 UTC (permalink / raw)


Hi,

Kai Großjohann wrote on 21 Feb 2003 18:54:50 MET:

> I was suggesting to make the variable mp4play-auto-mode buffer-local,
> and to keep minor-mode-alist global.
> 
> Was there a misunderstanding?

Yes, sorry.  I thought  you meant that  minor-mode-alist could  be set
buffer-local. Anyway. Thanks for the help.

Regards,

FF

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-21 18:07           ` François Fleuret
@ 2003-02-21 20:41             ` Kai Großjohann
  2003-02-21 21:18               ` François Fleuret
  0 siblings, 1 reply; 13+ messages in thread
From: Kai Großjohann @ 2003-02-21 20:41 UTC (permalink / raw)


francois.fleuret@noos.fr (François Fleuret) writes:

> Yes, sorry.  I thought  you meant that  minor-mode-alist could  be set
> buffer-local. Anyway. Thanks for the help.

So it works now?
-- 
A preposition is not a good thing to end a sentence with.

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-21 20:41             ` Kai Großjohann
@ 2003-02-21 21:18               ` François Fleuret
  2003-02-21 21:59                 ` Kai Großjohann
  0 siblings, 1 reply; 13+ messages in thread
From: François Fleuret @ 2003-02-21 21:18 UTC (permalink / raw)


Hi,

Kai Großjohann wrote on 21 Feb 2003 21:41:16 MET:

> So it works now?

Yes, but the flag appears in the modeline whatever the buffer is. I
still could not decide if this was a bad or a good thing. Let me think
about it a few more days :)

Regards,

FF

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

* Re: Style in elisp: how to show a flag value in the modeline?
  2003-02-21 21:18               ` François Fleuret
@ 2003-02-21 21:59                 ` Kai Großjohann
  0 siblings, 0 replies; 13+ messages in thread
From: Kai Großjohann @ 2003-02-21 21:59 UTC (permalink / raw)


francois.fleuret@noos.fr (François Fleuret) writes:

> Yes, but the flag appears in the modeline whatever the buffer is. I
> still could not decide if this was a bad or a good thing. Let me think
> about it a few more days :)

You could omit the flag if off.  (That's what Emacs does for the
other flags.)

Or you turn it into a three-way thing with values on, off, unset.
Then you can set the default value of the buffer-local variable to be
unset.

-- 
A preposition is not a good thing to end a sentence with.

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

end of thread, other threads:[~2003-02-21 21:59 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-20  9:50 Style in elisp: how to show a flag value in the modeline? François Fleuret
2003-02-20 11:46 ` Kai Großjohann
2003-02-20 12:45   ` François Fleuret
2003-02-20 17:26     ` Kai Großjohann
2003-02-20 17:26     ` Kai Großjohann
2003-02-21  8:57       ` François Fleuret
2003-02-21 17:54         ` Kai Großjohann
2003-02-21 18:07           ` François Fleuret
2003-02-21 20:41             ` Kai Großjohann
2003-02-21 21:18               ` François Fleuret
2003-02-21 21:59                 ` Kai Großjohann
2003-02-20 12:48 ` Oliver Scholz
2003-02-20 20:45 ` Stefan Monnier <foo@acm.com>

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).