72

I'm using Emacs 24; I've installed the zenburn theme, which is great, except I cannot see the selection highlight easily with the highlight color provided by zenburn:

enter image description here

By "selection" color, I mean the color of text that I've selected by setting a mark (C-space and moving the cursor to select text).

For the life of me, I cannot figure out how to change it. I've tried changing every combination of highlight, selection, etc.. that I can think of in zenburn-theme.el, but nothing seems to change it.

**For sanity's sake, I've tried changing other colors in the theme to make sure Emacs is loading the file properly - it is - those changes work.*

I would have especially thought that changing highlight would work, but no customizations to the highlight line seem to work:

;;;; Built-in                                                                                                                                                                            
;;;;; basic coloring                                                 
   ...                                                                                                      
   `(highlight ((t (:background ,zenburn-bg-05 :foreground ,zenburn-yellow))))  

How can I change the selection color?

Rob
  • 25,984
  • 32
  • 109
  • 155

3 Answers3

99

What you're looking for is the region face. For example:

(set-face-attribute 'region nil :background "#666")
tungd
  • 14,467
  • 5
  • 41
  • 45
  • 1
    This does not apply for the selected texts on `isearch`, is there any way to change background color on the searched texts as well? – alper Jan 31 '20 at 20:47
  • 2
    @alper `isearch` uses a different face, a quick look at `isearch.el` reveal that it is quite complicated since `isearch` seems to be using `highlight-regex` for highlighting. You'll probably need to dig in a bit further to find the face name that you want. – tungd May 03 '20 at 11:39
45

In addition to tungd's solution. You could also then change the font color to make it more readable. E.g. to white

(set-face-attribute 'region nil :background "#666" :foreground "#ffffff")
Philippe
  • 655
  • 5
  • 7
  • Just as a heads-up to Emacs n00bs like myself, this solution is complete, but it also overwrites any syntax-highlighting you have on the selected region because of the `foreground`. – Mehrad Mahmoudian Apr 25 '22 at 13:46
37

You can use the customize interface.

M-x customize-face

When prompted for which face, enter region. Then you'll see something like:

enter image description here

Using customize makes it easy to experiment with lots of colors. Try clicking [ Choose ] to access the color-picker), then [ Apply and Save ]. It also nicely organizes your customizations into a single file (rather than further polluting your init.el).

Micah Elliott
  • 9,600
  • 5
  • 51
  • 54