unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* god-mode color
@ 2014-08-26 15:49 BP
  2014-08-28 22:03 ` Michael Heerdegen
  0 siblings, 1 reply; 2+ messages in thread
From: BP @ 2014-08-26 15:49 UTC (permalink / raw)
  To: help-gnu-emacs

Hi everyone!

I'm trying to make some cosmetic changes of my emacs depending on god-mode state. For now I have this :

(defun my-update-color ()
  (setq cursor-type (if (or god-local-mode buffer-read-only)
                        'box
                      'bar))
  (set-cursor-color (if (or god-local-mode buffer-read-only)
                        "firebrick1"
                      "LawnGreen"))
  (set-face-background 'mode-line (if (or god-local-mode buffer-read-only)
                        "red4"
                      "DarkCyan")))

(add-hook 'god-mode-enabled-hook 'my-update-color)
(add-hook 'god-mode-disabled-hook 'my-update-color)

However my-update-color is not called when I switch to another buffer and the appearance of emacs remains unchanged whatever the state of god-mode in the new buffer.

Does anyone have an idea to make the color update correctly?

Thanks,

BP


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

* Re: god-mode color
  2014-08-26 15:49 god-mode color BP
@ 2014-08-28 22:03 ` Michael Heerdegen
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Heerdegen @ 2014-08-28 22:03 UTC (permalink / raw)
  To: help-gnu-emacs

BP <baptiste.pannier@gmail.com> writes:

> I'm trying to make some cosmetic changes of my emacs depending on
> god-mode state. For now I have this :
>
> (defun my-update-color ()
>   (setq cursor-type (if (or god-local-mode buffer-read-only)
>                         'box
>                       'bar))
>   (set-cursor-color (if (or god-local-mode buffer-read-only)
>                         "firebrick1"
>                       "LawnGreen"))
>   (set-face-background 'mode-line (if (or god-local-mode
> buffer-read-only)
>                         "red4"
>                       "DarkCyan")))
>
> (add-hook 'god-mode-enabled-hook 'my-update-color)
> (add-hook 'god-mode-disabled-hook 'my-update-color)
>
> However my-update-color is not called when I switch to another buffer
> and the appearance of emacs remains unchanged whatever the state of
> god-mode in the new buffer.

Let's first ignore `buffer-read-only' and concentrate on the appearance
depending on god-local-mode.

You miss something very important: setting `cursor-type' is a buffer
local thing (good).  `set-cursor-color' sets the cursor color of a frame
(not so good).  `set-face-background' again has a global effect (not
good at all), unless you use the optional argument, which makes per
frame.

When you would use only per buffer settings, you would not need to do
anything when switching buffers.

The cursor-type thing already works.  Of course it only has an effect in
any buffer where the god-mode hooks were actually called.  Use
`setq-default' to set a default for all other buffers.

For cursor color and mode-line, face remapping would probably be the
better approach.  This is a per-buffer feature.

The buffer-read-only dependent appearance is harder.  I guess you would
also want to switch appearance when you toggle the read only state of a
buffer?  `buffer-read-only' is just a plain variable, so, there is no
easy way to run code automatically when it is toggled.

Michael.




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

end of thread, other threads:[~2014-08-28 22:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-26 15:49 god-mode color BP
2014-08-28 22:03 ` Michael Heerdegen

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