I know you can set the :foreground of the region face so that it simply uses the :foreground of whatever is selected, while using the region's :background. And I know you can just set the foreground and get a single color always. What I'd like is to have the region foreground apply a function on the face it's selecting to decide on a foreground color, so I could do something like change the color for some faces but leave others the same, or lighten/darken all colors. I'm pretty sure this isn't possible within the standard face system, but if it is I'd love to hear it, and if not any pointers to a solution would be great.

  • You could use a custom function that chooses the color and sets the color with the face-remapping-alist. There are a few functions in simple.el that would need to be modified -- start with looking at: redisplay--pre-redisplay-functions. I used Drew's eye-dropper library and a few other functions to identify the face foreground/background at point (that could be font-lock, or an overlay, or text-proeprties) and adjust the new overlay properties programmatically based therein. In my own setup, I have XPM images that I color programmatically based on what' underneath, but beyond scope. – lawlist Jun 17 '17 at 20:41
  • See this related thread in the context of my previous comment to get some ideas -- "Get foreground color of face at point": emacs.stackexchange.com/questions/12277/… I've taken Drew's answer and modified it for my own setup, including adding additional conditions, but that should get you or anyone else who's interested, on the right track. Note that both of my comments contemplate changing the region color, not modifying what is underneath (which may also be possible, but I've never thought about it before). – lawlist Jun 17 '17 at 20:48
  • Note that you may also wish to set up certain custom preferences to deal with multiple faces at the same point and choose which should receive preferential treatment. In my own custom setup, if there is a list of faces at point (e.g., a font-lock face, and an overlay on top, then I may chose to give the overlay preferential treatment -- keeping in mind that the region will be yet another overlay when applied. You may also wish to play with the overlay priority property. – lawlist Jun 17 '17 at 21:13

Your Answer

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

Browse other questions tagged or ask your own question.