2

I want to change the emacs fringe to a gradient of two colours.

(set-face-background 'fringe <gradient>)

As set-face-background requires a colour name or hex, I'm unsure of how I can get it to show a gradient colour.

I believe the color.el function color-gradient could help with the interim step of determining the different shades of colours:

(color-gradient START STOP STEP-NUMBER)

(color-gradient '(255 192 203) '(250 128 114) 3)

But I'm unsure of how to take this list of colours and create the gradient colour along the fringe. I suspect I will need to advise the set-face-background function, or perhaps a function responsible for displaying the fringe itself, but not sure where to start / how best to approach. Could anyone point me in the right direction?

  • 1
    Perhaps "How can I display a colour gradient in the fringe?" or similar would be a more accurate title? – Basil Feb 3 '18 at 15:21
  • color-gradient just gives you a list of colors. How do you expect to use that in a single face? It's not clear what you are trying to do, in detail. – Drew Feb 3 '18 at 16:22
  • I'm looking for help on how to approach the problem. I believe Color-gradient solves the problem of figuring out what each shade of colour needs to be, between the two colours, but I'm unsure as to how to modify either the face function or fringe to accommodate this. – xeijin Feb 3 '18 at 16:27
  • You will need to use a color name like "red" or a hex "#FF0000" in conjunction with set-face-background, so convert your stuff into either format. If your question is simply how to convert a 255 192 203 to a hex, then there should be a function in color.el or in Drew's color / eye-dropper libraries. If your question is how to merge two of those (255 192 203 / 250 128 114) into one hex, then consider editing your question to say how do I merge these two animals into one hex ...? – lawlist Feb 3 '18 at 16:36
  • I've edited the question to hopefully make my objective a bit clearer. – xeijin Feb 3 '18 at 16:44
0

You'll have to make two changes.

First, set-face-background calls set-face-attribute, which calls internal-set-lisp-face-attribute which actually checks the arguments for validity before finally calling aset. So you could certainly advise set-face-background, and have your advice directly use aset when the argument is a gradient (and pass it through to the original set-face-background otherwise).

However, that's not going to be a great idea unless the rendering code can do something sensible with a gradient.

Rendering is different on every platform, so you'll either have to pick your favorite platform and skip the others or change them all. This isn't something you can do with advice either; you'll have to recompile Emacs.

I'm not an expert, but a quick look through xfont.c lead me to the C function xfont_draw, which draws a run of glyphs using a font. I think that you'll have to draw the background gradient yourself, and then arrange for the GC to have a transparent color for the background. Then the call XDrawImageString won't disrupt the gradient you've already drawn.

Of course, that's assuming that you're interested in the X Windows platform; if you use one of the others then the work will likely be similar.

  • Thank you. A lot more pain than I'd bargained for but definitely helpful to know. – xeijin Feb 3 '18 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.