3

Is there a way to easily modify the font-face under cursor?

For example, the text in blue below is hard to read:

                           enter image description here

The above is the output of

ipython --color "Linux"

running on an ansi-term with tango-dark in Emacs 24.1, i.e. (load-theme 'tango-dark t)

If I run what-cursor-position on the image above (described here: Get font face under cursor in Emacs), I get:

             position: 30385 of 30477 (100%), column: 22
            character: / (displayed as /) (codepoint 47, #o57, #x2f)
    preferred charset: ascii (ASCII (ISO646 IRV))
code point in charset: 0x2F
               syntax: _    which means: symbol
             category: .:Base, a:ASCII, l:Latin, r:Roman
          buffer code: #x2F
            file code: #x2F (encoded by coding system nil)
              display: by this font (glyph code)
    xft:-unknown-DejaVu LGC Sans Mono-bold-normal-normal-*-11-*-*-*-m-0-iso10646-1 (#x12)

Character code properties: customize what to show
  name: SOLIDUS
  old-name: SLASH
  general-category: Po (Punctuation, Other)
  decomposition: (47) ('/')

There are text properties here:
  face                 (:weight bold :foreground "blue2" :background unspecified)

How can I modify this font?

In case you are wondering IPython only supports three color sets:

  • Nocolor
  • Linux (the one I am using above)
  • LightBG (for light backgrounds)

Update:

I think font-lock-string-face is a different face:

                        enter image description here

In fact, I think that's not the face that IPython uses to represent strings, but the face that python-mode uses to represent strings in a buffer with regular python code (in tango-dark) -- see below --.

                                          enter image description here

Community
  • 1
  • 1
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564

3 Answers3

5

M-x customize-face with your cursor over the particular thing you want to modify. Also available are set-face-foreground and set-face-background depending on what you want to do (sometimes it's good to change the backing color to make the font easier to see in terminals).

So I checked out IPython as mentioned in my comment below and ipython.el does no highlighting of its own. The coloring is all done by using terminal ANSI colors. It's possible in some terminals to change the colors via a .bashrc or .zshrc or whatever your shell is and running it from M-x term possibly. Through Emacs itself I cannot see a way of changing it as IPython only has 3 default schemes and no way to specify anything specific as far as I can see.

Jesus Ramos
  • 22,940
  • 10
  • 58
  • 88
  • Thanks, but when I invoke `M-x customize-face` it prompts me with `Customize face (default 'all faces')`. I think `all faces` does not refer to the face under the cursor in my picture above. Am I wrong? – Amelio Vazquez-Reina Jan 24 '13 at 21:04
  • @user273158 It should be `font-lock-string-face` – Jesus Ramos Jan 24 '13 at 21:06
  • Thanks. Why is emacs not prompting me for that face? Shouldn't that be the one that it asks me by `default`? (i.e. the one under cursor). Also, how do you know that `font-lock-string-face` is specifically the face I have under the cursor? – Amelio Vazquez-Reina Jan 24 '13 at 21:09
  • @user273158 You'll have to believe me on this one, I'm not sure why your Emacs isn't detecting it correctly, mine works in both terminal and X. – Jesus Ramos Jan 24 '13 at 21:10
  • Thanks Jesus. I have updated the OP with more info about this (see the section `Update`) – Amelio Vazquez-Reina Jan 24 '13 at 21:20
  • 1
    @user273158 I don't use IPython so I'm not sure but I can check for you :) – Jesus Ramos Jan 24 '13 at 21:22
  • 1
    @user273158 It seems that ipython does it's own coloring outside of Emacs using ansi-colors. As such I don't think you can modify the colors except to one of the 3 color sets described. I looked through `ipython.el` and found no way to do this :\ – Jesus Ramos Jan 24 '13 at 21:26
  • Should I look for a method to keep this blue, and only change the color of the direct character at point? – PascalVKooten Jan 24 '13 at 21:53
  • @Dualinity He could try `TERM=xterm-mono` to disable ansi color output. – Jesus Ramos Jan 24 '13 at 21:58
3

It is possible to change the way ansi colors are shown:

(defface term-color-red
    '((t (:foreground "#ff0000" :background "#ff0000")))
  "Unhelpful docstring.")

Here is the whole bunch:

term-color-red
term-color-green
term-color-black
term-color-yellow
term-color-blue
term-color-magenta
term-color-cyan
term-color-white
sabof
  • 8,062
  • 4
  • 28
  • 52
  • Thanks sabof. Can I then presume that the text in dark blue that I see in the first picture I posted is `term-color-blue`? Also, does `ansi-term` only support the 9 colors you listed? – Amelio Vazquez-Reina Jan 25 '13 at 03:50
  • term-color-blue, would be my guess. Yes, to the best of my knowledge it's those 9. If using the above form doesn't work, you could try using customize-face, or adding them to your theme definition. – sabof Jan 25 '13 at 12:06
  • I've listed red twice, actually it's 8 – sabof Jan 26 '13 at 00:03
1

Like sabof, I think the color you are seeing is set by ansi-term, and not by Emacs' color theme.

A way to configure these colors consists in setting the ansi-term-color-vector variable. Looking at the code in term.el helps understanding the meaning of this variable: it contains color specifications for the 8 ansi color escape codes:

(defvar ansi-term-color-vector
  [unspecified "black" "red3" "green3" "yellow3" "blue2"
   "magenta3" "cyan3" "white"])

Here is my setup (which might suit you since I'm also using a dark Tango theme) :

;; ANSI Term colors
(setq ansi-term-color-vector
      [unspecified "#000000" "#b21818" "#18b218" "#BE5F00"
                   "#6D85BA" "#b218b2" "#18b2b2" "#b2b2b2"])
Community
  • 1
  • 1
François Févotte
  • 19,520
  • 4
  • 51
  • 74
  • Thanks! Do you know how can I test/look-up hexadecimal codes from color appearance? (i.e. like a color palette that shows me the hexadecimal code) – Amelio Vazquez-Reina Jan 25 '13 at 19:38
  • a google search on "html color palette" should give you thousands of results. Here are a few examples: http://www.colorschemer.com/online.html - http://www.colorcombos.com/ - http://fillster.com/colorcodes/colorpalette.html – François Févotte Jan 25 '13 at 20:00
  • I see. Thanks. I didn't know it was a `html` specification. Do you know if there is a way of having `ansi-term` support more colors than just 8? – Amelio Vazquez-Reina Jan 25 '13 at 20:16
  • As far as I know, there exist only 8 ansi escape codes corresponding to colors (or 16 if you consider normal and bright colors to be different). Please see my edit for a link to the wikipedia article on ansi escape sequences. – François Févotte Jan 25 '13 at 21:43