I use something like this to control the background color of my selected text:

(region ((t (:background ,green))
            (t :inverse-video t)))

However some foreground colors don't go well with my background color and the text becomes hard to read. So I experimented with different background colors for region, but the results have not been satisfactory.

Now I wish for this behavior:

Interchange the background and foreground colors on my selected text.

The following images are for illustration of what I want:

  1. Without Selection:

without highlighting

  1. With Selection:

with highlighting

With this I feel, I will be able to demarcate the selected text all the while retaining my syntax highlighting along with readability.

How do I accomplish this within Emacs?

1 Answer 1


Perhaps I don't understand. Just customizing face region to (only) use inverse-video gives you what you're asking for, as far as I can see. So just get rid of the imposition of a green background:

enter image description here

  • That was really simple! Earlier I had tried C-h v to describe inverse-video, but I never quite understood what inverse-video did. A follow up question: How can I do some conditional formatting? For example I do not want inverse-video if the foreground color is white. If my foreground ground color is white I want to manually specify which foreground and background to use when highlighting selected text. Commented Oct 1, 2021 at 5:07
  • Post your follow-up question as a separate question, please.
    – Drew
    Commented Oct 1, 2021 at 17:21
  • I have posted the follow-up question here. Thanks! Commented Oct 1, 2021 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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