Adjusting term faces in the new Emacs 24.3
Asked Answered
S

3

13

How can I adjust the term face in the new Emacs to get the same control that was possible with ansi-term-color-vector?

One of the new features in Emacs 24.3 seems to be that it revamps the mechanism to control the face of term buffers, i.e.:

The variables term-default-fg-color and term-default-bg-color are now deprecated in favor of the customizable face term.

You can customize how to display ANSI terminal colors and styles by customizing the corresponding term-color-COLOR, term-color-underline and term-color-bold faces.

Mickey from Mastering Emacs comments the following:

If, like me, you customized ansi-color-names-vector to change the default term colours I suggest you switch to using the faces now. The good news here is you can, should desire to, change more than just the colours for each ANSI Color: there’s nothing stopping you from forcing a different font for certain colours

Like Mickey, I was also using ansi-color-names-vector to make sure that the color of my term buffers looked well on dark themes (e.g. tango-dark)

(setq ansi-term-color-vector [unspecified “black” “red3” “lime green” “yellow3” “DeepSkyBlue?3” “magenta3” “cyan3” “white”])

But this now results in an error:

"error in process filter: Invalid face; unspecified" 

In an attempt to use the new face term, when I go to M-x describe-face term, I see the following:

[] Font Family
[] Font Foundry
[] Width
[] Height
[] Weight
[] Slant
[] Underline
[] Overline
[] Strike-through
[] Box around text
[] Inverse-video
[] Foreground
[] Background
[] Stipple
[x]  Inherit

But how do I adjust these settings to get the same effect I achieved using ansi-term-color-vector?

Update

I am still unable to fix the colors. Here is the menu that I get for M-x customize-theme tango-dark:

enter image description here

And here is an example of one of the colors/faces in a terminal that are hard to see:

                              enter image description here

Skirling answered 27/3, 2013 at 14:27 Comment(0)
B
10

This worked for me in Emacs 24.3.1 to set the colors of term and ansi-term. Just change the colors to your preferred values (with the background adjusted accordingly).

;; term
(defface term-color-black 
  '((t (:foreground "#3f3f3f" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-red
  '((t (:foreground "#cc9393" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-green
  '((t (:foreground "#7f9f7f" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-yellow
  '((t (:foreground "#f0dfaf" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-blue 
  '((t (:foreground "#6d85ba" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-magenta 
  '((t (:foreground "#dc8cc3" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-cyan
  '((t (:foreground "#93e0e3" :background "#272822"))) 
  "Unhelpful docstring.")
(defface term-color-white
  '((t (:foreground "#dcdccc" :background "#272822"))) 
  "Unhelpful docstring.")
'(term-default-fg-color ((t (:inherit term-color-white))))
'(term-default-bg-color ((t (:inherit term-color-black))))

;; ansi-term colors
(setq ansi-term-color-vector
  [term term-color-black term-color-red term-color-green term-color-yellow 
    term-color-blue term-color-magenta term-color-cyan term-color-white])
Bloodyminded answered 2/8, 2013 at 23:54 Comment(0)
S
5

In Emacs 24.3 you'll need to adjust the following faces:

   ;; term
   `(term-color-black ((t (:foreground ,zenburn-bg
                                       :background ,zenburn-bg-1))))
   `(term-color-red ((t (:foreground ,zenburn-red-2
                                       :background ,zenburn-red-4))))
   `(term-color-green ((t (:foreground ,zenburn-green
                                       :background ,zenburn-green+2))))
   `(term-color-yellow ((t (:foreground ,zenburn-orange
                                       :background ,zenburn-yellow))))
   `(term-color-blue ((t (:foreground ,zenburn-blue-1
                                      :background ,zenburn-blue-4))))
   `(term-color-magenta ((t (:foreground ,zenburn-magenta
                                         :background ,zenburn-red))))
   `(term-color-cyan ((t (:foreground ,zenburn-cyan
                                       :background ,zenburn-blue))))
   `(term-color-white ((t (:foreground ,zenburn-fg
                                       :background ,zenburn-fg-1))))
   '(term-default-fg-color ((t (:inherit term-color-white))))
   '(term-default-bg-color ((t (:inherit term-color-black))))

This code is from the latest version of Zenburn. Personally I feel that the new way of customising the faces is an improvement over the use of the obscure vector.

Sorption answered 27/3, 2013 at 15:6 Comment(6)
Thanks. Any thoughts or pointers on how I could do this for a theme like tango-dark? (i.e. how can I find out the different colors supported by my theme? such as zenburn-bg-1, etc. but for tango-dark)Skirling
Just do a M-x describe-theme tango-dark and see the colour definitions in tango-dark-theme.el.Sorption
Thanks @Bodzhidar. I am sure you are right that I could follow your steps to fix this problem, but unfortunately I can't figure out how to make it work for tango-dark. It looks like tango-dark already sets ansi-color-names-vector to a given set of colors in tango-dark.el (see the code here: http://fossies.org/unix/misc/emacs-24.3.tar.gz:a/emacs-24.3/etc/themes/tango-dark-theme.el). Moreover, these colors seem to look fine when I look up M-x describe-theme tango-tark (see the images I posted in the OP), but for some reason they don't work well in terminals.Skirling
Another thing I don't understand is why your background colors in zenburn (the ones you defined above) are different for each term-color (shouldn't they be set to inherit the background color of the terminal?)Skirling
For each color you need a ligher foreground version and a darker background version. That's how the faces were defined in term.el(it's not something I inventited for zenburn) itself. Nothing in term actually uses those faces directly, they are just used to derive other faces.Sorption
Pasting this at the right place in the theme.el file worked. I had to remove ansi-color-names-vector and ansi-term-color-vector manually from .emacs.d/init.el. Running customize-group on term recreates them, then it breaks again and I must remove the lines once more. I am on emacs 25.0.50.2.Decembrist
O
3

I would suggest M-x customize-group RET term RET
as the easiest entry point to customizing those colours.

Ossification answered 17/9, 2014 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.