[ESS] Fwd: change font-lock-string-face for back ticks

Peter Meilstrup peter.meilstrup at gmail.com
Tue Feb 18 14:42:45 CET 2014


>  >>> Peter Meilstrup on Mon, 17 Feb 2014 13:06:04 -0800 wrote:
>
>  > (defun pbm-fix-R-syntax-highlighting ()
>  > ;; ESS classes % as punctuation, but it's
>  > ;; really a sort of quote delimiter -- but since it doesn't
>  > ;; escape with \, there's a slight hole
>  > (modify-syntax-entry ?% "\"")
>
> Why do you need this one? I kind of like how %in% is displayed right
> now. Displaying it in string face doesn't appeal to me at all.

Because it is legal to have infix operators like %'%, %`%, %a phrase
with spaces% and so on, which, if "%" is not treated as a quote, would
break highlighting and movement commands. I display it in something
other than string face (actually I make the % but not the contents
very low contrast as they are visually noisy, but that is not included
here.) I also have customized paredit to auto-pair %% and ``
characters.

>  > ;; On the other hand ESS classes $ @ and : as word characters but they
>  > ;; are really punctuation
>  > (modify-syntax-entry ?$ ".")
>  > (modify-syntax-entry ?@ ".")
>  > (modify-syntax-entry ?: ".")
>
> $, @, and : are of class symbol, as they should be. Making them
> punctuation will most likely screw a lot of stuff, most notably
> completion and eldoc for complex symbols like foo$bar.

"A$B" is not parsed as a single symbol by R but as a call. A$B in R
means the same thing as `$`(A,B). A and B the arguments and "$" is an
operator. "A$B" is not a symbol in R syntax unless it is surrounded by
backticks. Similarly with "?", "@", and ":", "::", ":::". If ESS
depends on having an incorrect model of R syntax that is interesting,
but completion appears to work for me.

>  > (defun pbm-R-syntactic-face-function (state)
>  > (cond
>  > ((nth 3 state) ;strings and stringlike elements
>  > (case (nth 3 state)
>  > ;R has four things that are to be tokenized like quotes: single
>  > ;and double quoted strings, backtick symbols (which are names,
>  > ;not strings, so they shouldn't be in string face) and %custom%
>  > ;infix operators which shouldn't either
>  > (?\" font-lock-string-face)
>  > (?' font-lock-string-face)
>  > (?` font-lock-variable-name-face)
>  > (?% font-lock-constant-face)))
>  > (t font-lock-comment-face)))
>
> Modifying font-lock-syntactic-face-function just for the sake of % seems
> like an overkill, but could in principle be added if many more people
> find it annoying how %foo% is highlighted right now.

That would break on the example provided, `%weirdly-named-function` as
well as `weirdly"named-function` and things that regularly end up as
object component names like `a:b` and so on. I make heavy use of
paredit and sexp-level movement commands; if I issue
delete-forward-sexp it should not leave me with unbalanced backticks
or %, any more than it should leave me with unbalanced paren or
quotes.

Peter



More information about the ESS-help mailing list