Pergunta

I am using Emacs 24.3 and ESS 13.05 with the theme tangotango.el. While the theme is restful on the eyes, variable names in R don't appear to be highlighted. In tangotango-theme.el I can find the following line:

 `(font-lock-variable-name-face ((t (:foreground "tomato"))))

but this doesn't appear to have any effect. For example, in the screenshot below I would expect the variable orl to be highlighted in some shade of red. Instead it is the standard text colour for this theme.

tangotango theme

If I delve into ESS there is a file named ess-font-lock.el which contains a few references to the variable name face, like this one:

  (set-face-foreground 'font-lock-variable-name-face "Black"))

So it looks as if font-lock-variable-name-face has competing definitions. I don't understand the interaction between Emacs themes and these ESS definitions. Is ESS overriding the tangotango theme and if so, will changing the above line in ess-font-lock.el restore variable name highlighting? Or should I be looking somewhere else entirely?

Edit: note that Cperl mode does seem to respect the font lock:

perl

Foi útil?

Solução

You are looking in a wrong place. ess-font-lock defines themes. Some 10 years ago that was useful. Now there are generic themes like your tango-tango and ESS doesn't interfere with them.

The issue is that ESS does not define a font lock keyword that you are looking for. The reason is that <- is an assignment operator, and there is no an explisit variable definition statement in R. ESS only treats function definitions. That is, assignment of a function will be highlighted:

foo <- function(){}

Believe me or not, but you really don't want to highlight all your assignments. You can try it though with:

(defvar ess-R-fl-keyword:assign-vars
  (cons "\\(\\(?2:\\s\"\\).+\\2\\|\\sw+\\)\\s-*\\(<-\\)"
        '(1 font-lock-variable-name-face)))

(add-to-list 'ess-R-font-lock-keywords '(ess-R-fl-keyword:assign-vars . t) t)

ESS implements a flexible font lock customisation mechanism on top of emacs font-lock system. See ESS>font-lock submenu.

enter image description here

Outras dicas

Yes, it sounds like it. If you see the problem only in that mode, and that mode explicitly changes the face, then that sounds like the culprit. You should not need to change the source code, however. Just do something like this (untested):

 (add-hook 'ess-mode (lambda () (set-face-foreground "tomato")))

(I assume that's the right mode name; if not, correct it.)

But this is an ugly workaround -- you should not need to do that. Consider filing a bug against the ess-mode.el code. It should not trample on user settings such as faces that way. If it wants to change the appearance by default then it should give users a new face that they can customize, instead of simply screwing with an existing face in a hard-coded way.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top