help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: god-mode color


From: Michael Heerdegen
Subject: Re: god-mode color
Date: Fri, 29 Aug 2014 00:03:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.92 (gnu/linux)

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]