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

Vitalie Spinu spinuvit at gmail.com
Tue Feb 18 12:44:55 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.

 > ;; 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.

 > (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.

To address the OP problem with backticks the following is enough:

   (modify-syntax-entry ?` "_" R-syntax-table)

If people don't disagree I would like to make this change to the ESS.


   Vitalie



More information about the ESS-help mailing list