[ESS] change font-lock-string-face for back ticks
Munawar Cheema
mcheema at btinternet.com
Mon Feb 17 22:52:22 CET 2014
Peter,
That's brilliant thanks. I got as far as syntax tables but it felt like
layers of an onion so I gave up.
On 17/02/2014 21:06, Peter Meilstrup wrote:
> Here's some elisp I have to correct some things with ESS's syntax
> highlighting, including how to highlight backticks.
>
> (add-hook 'R-mode-hook 'pbm-fix-R-syntax-highlighting)
>
> (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 ?% "\"")
> ;; On the other hand ESS classes $ @ and : as word characters but they
> ;; are really punctuation
> (modify-syntax-entry ?$ ".")
> (modify-syntax-entry ?@ ".")
> (modify-syntax-entry ?: ".")
> (setq font-lock-syntactic-face-function 'pbm-R-syntactic-face-function)
> (font-lock-fontify-buffer))
>
> (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)))
>
>
>
> On Mon, Feb 17, 2014 at 10:22 AM, Munawar Cheema <mcheema at btinternet.com> wrote:
>> On 17/02/2014 18:08, Vitalie Spinu wrote:
>>>
>>> >>> Munawar Cheema on Mon, 17 Feb 2014 15:35:59 +0000 wrote:
>>>
>>> [...]
>>>
>>> > In my emacs statements such as:
>>> > `%weirdly-named-function` <- function(){}
>>> > `var-name` <- "djsf"
>>>
>>> > The face of the function is the string-face and not the face for
>>> > functions and similarly for the var-name face.
>>>
>>> For me the function is highlighted with
>>> font-lock-function-name-face. The `var-name` is indeed highlighted as a
>>> string. It kind of makes sense for it not to be.
>>>
>>> Vitalie
>>>
>>>
>>>
>>
>> Vitalie,
>> I just tried again without my customizations and you are right the function
>> does indeed get the font-lock-function-name-face.
>> I tried to figure out where Emacs sets the delimiters for strings but my
>> Emacs lisp foo fails me. There must be a way to tell it not to use back
>> ticks for strings in ESS-mode.
>>
>>
>> --
>> *Munawar Cheema *
>>
>>
>> ______________________________________________
>> ESS-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/ess-help
>
--
*Munawar Cheema *
More information about the ESS-help
mailing list