Different background color for different windows/modes

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Different background color for different windows/modes

Alexandre Oberlin-3
Hi all, I am using a hook to change my background color using stuff like:
(add-hook 'change-major-mode-hook 'change-my-background-color)

This is sub-optimal because
- there is a terrible flash as soon as I enter the minibuffer
- all the displayed windows change color (not only the one getting focus).

How can I have different colors for different window  modes?  If currently impossible, is something planned in that regard? Or maybe xemacs does this?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Different background color for different windows/modes

Emanuel Berg-4
Alexandre Oberlin wrote:

> Hi all, I am using a hook to change my
> background color using stuff like: (add-hook
> 'change-major-mode-hook
> 'change-my-background-color)

You want the background color to be a function
of the major mode?

And there are no mode-specific variables to
control this so you instead have a function
that maps on the fly?

Oh, man...

> This is sub-optimal because - there is
> a terrible flash as soon as I enter the
> minibuffer - all the displayed windows change
> color (not only the one getting focus).

*If* you are going to stick to this sub-optimal
solution indeed, I suppose you could write
a more advanced function that will examine if
the new context is such that the change of
background color should or shouldn't kick in.

--
underground experts united
http://user.it.uu.se/~embe8573


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Different background color for different windows/modes

Tomas Zerolo
In reply to this post by Alexandre Oberlin-3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, Jun 29, 2017 at 03:45:31AM -0700, Alexandre Oberlin wrote:
> Hi all, I am using a hook to change my background color using stuff like:
> (add-hook 'change-major-mode-hook 'change-my-background-color)
>
> This is sub-optimal because
> - there is a terrible flash as soon as I enter the minibuffer
> - all the displayed windows change color (not only the one getting focus).
>
> How can I have different colors for different window  modes?  If currently impossible, is something planned in that regard? Or maybe xemacs does this?

You don't state it explicitly, but I assume you want to change
the background color per buffer, perhaps per window.

For a long time it was only possible to set the whole frame's
(an Emacs frame is what the window manager considers a "window")
background color. This has changed since Emacs 24-ish, see for
example

  https://stackoverflow.com/questions/3094638/emacs-custom-background-color-by-mode

(this seems to be exactly what you're looking for).

Cheers
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAllU5ygACgkQBcgs9XrR2kYSgACfT8hG9yXfeclPQwLOGU5O7KEo
3McAniy9SLPfXdCYcsnZW2Xl+4HvM2rN
=OkVt
-----END PGP SIGNATURE-----

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Different background color for different windows/modes

Alexandre Oberlin-3
In reply to this post by Alexandre Oberlin-3
Hello,

Someone gave me a hint to do this in Emacs 24.4+ but I don't find the message on gnu.emacs.help (Is this NG dying?).

The trick is to uses defface and face-remap-add-relative. It works very well, including in GNU Emacs 24.5.1 (x86_64-unknown-cygwin) under Cygwin without X.

To modify the font and colors of your shell windows for instance, just add/load the code below from your .emacs and add more attributes and more modes (text, lisp, etc.) as desired.

The commented out entries are not necessary but may come handy when tweaking your config.

Important: this code should be loaded before you visit/find any concerned file or launch a shell from .emacs.

;;;;;;;;;;;;;;;;;;;;;;;; BEGIN .emacs CODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; (face-spec-reset-face 'myshellface)
(defface myshellface
  '((t :foreground "black"
       :background "aquamarine"
       :weight semi-bold
       :underline nil
       ))
  "Face for shells."
  :group 'myfaces )

;; (face-spec-set
;;  'myshellface
;;    '((t :foreground "black"
;;        :background "aquamarine"
;;        :weight semi-bold
;;        :underline nil
;;        ))
;;  'face-defface-spec
;;  )

;; (facep 'myshellface)
;; (boundp 'myshellface)
;; (remove-hook 'shell-mode-hook
;; (lambda ()
;;   (face-remap-add-relative 'default 'myshellface)))

(setq shell-mode-hook nil)
(add-hook 'shell-mode-hook
          (lambda ()
            (face-remap-add-relative 'default 'myshellface)))

;;;;;;;;;;;;;;;;;;;;;;;; END .emacs CODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Cheers,

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Different background color for different windows/modes

Emanuel Berg-4
Alexandre Oberlin wrote:

> Someone gave me a hint to do this in Emacs
> 24.4+ but I don't find the message on
> gnu.emacs.help (Is this NG dying?).

Usenet has been dying for a very long time.
Many once hugely populated groups are
completely quiet or consists only of senior
citizens telling their tales and reliving their
memories, not caring much what the topic of the
group is. They still have the knowledge tho so
it can be useful to ask questions. And not just
for the 1975 answer.

Are you getting gnu.emacs.help from aioe.org?
Well, the newsgroup is operational.

Last time I heard, the mailing list had a small
program attached that posted all incomings to
gnu.emacs.help, and reposted newsgroup posts as
mails - I suppose? - however that seemed not to
have ever worked perfectly, and now, it seems
it is left adrift even more so...

But there is no real reason to use
gnu.emacs.help anymore. If you want the mailing
list material but with the superior Usenet
common interface and organization, you can use
gmane.emacs.help - this is the hole purpose of
Gmane, to enable us to use mailing lists
as newsgroups.

Which is much better. Many people realize this,
while others are in denial.

Gmane is the best of both world, the
on-topicness of mailing lists, and the interface
and organization of Usenet. That's why I call
Gmane "Usenet 2.0" or "Usenet Reloaded".

Sadly, it is only partly true. Because what it
isn't, and never will be (why?), is the
computer culture, the Might and Magic world
that was old Usenet, with heroes, villains,
techno-wizards, and jesters - fuds that lasted
decades and discussions about virtually
*anything* - a whole superstructure of HUMANS
on top of the technology. Now there's only
technology left.

Where are the humans? H-e-l-l-o-o? Can anyone
read this?!

--
underground experts united
http://user.it.uu.se/~embe8573


Loading...