8

Is there any way to define a face in Emacs (e.g. highlight such as hl-line) so that it only changes the background color (and have Emacs use the foreground color as if the word was not highlighted).

More specifically, I tried the following on the tango-dark theme

(custom-set-faces
 '(region ((t (:inherit nil :background "RoyalBlue4"))))
 '(highlight ((t (:inherit region :background "dark olive green"))))
 '(hl-line ((t (:inherit highlight)))))

and, as can be seen below, region highlighting does respect the foreground font (i.e. it only changes the background color):

                     enter image description here

but the highlighting of the current line does't:

                       enter image description here

Why? and how can I get the same effect with hl-line?

Update:

This seems to a bug in the tango-dark theme (a builtin theme of Emacs). The code works well with the default theme (which loads with emacs -Q). I posted this on the official bugs mailing list.

Community
  • 1
  • 1
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
  • check your parens on the region line; =) after i fixed that things seemed to work as you want; btw, having a mode helper like paredit will prevent most of these issues! – assem Apr 01 '13 at 02:07
  • More precisely, remove the closing parens after `custom-set-faces` and the `region` line -- after that, the code works fine for me on Emacs 23.1.1 – Thomas Apr 01 '13 at 02:39
  • Thanks @Thomas, I updated the code and the OP, but I still don't get the desired effect. Hmm – Amelio Vazquez-Reina Apr 01 '13 at 14:00
  • Thanks @assem. I updated the code and the OP but I still don't get the desired effect. – Amelio Vazquez-Reina Apr 01 '13 at 14:01
  • Could this be a side-effect of your theming? Can you try and see if the same effect happens when you start emacs with `-Q` ? – Thomas Apr 01 '13 at 14:25
  • @Thomas. You are right. I am not having this problem with the default theme that loads with `emacs -Q`. For reference, I am using `tango-dark` above. The odd thing is that this is one the themes that Emacs now provides. – Amelio Vazquez-Reina Apr 01 '13 at 14:56

2 Answers2

11

I struggled with this some time ago, and it seems to be a bug of the color theme.

I've come up with a workaround, however. This works for me:

(load-theme 'tango-dark t)
(set-face-attribute 'highlight nil :foreground 'unspecified)
shakurov
  • 2,358
  • 24
  • 27
0

I had a bit similar problem:

(add-hook 'after-make-frame-functions
  (lambda (frame)
    (select-frame frame)
      (when (display-graphic-p frame)
       (custom-set-faces '(region ((t (:inherit nil :background "RoyalBlue4")))))
     )
sistux
  • 1
  • 2