Syntax highlighting for |> for ESS

246 Views Asked by At

I'd like to have the new R operator |> get the same syntax coloring as magrittr::%>% does in ESS. How can I achieve this?

1

There are 1 best solutions below

0
Rorschach On

There are quite a few options to modify syntax highlighting in ess-custom, see C-h v ess-R-font-lock-keywords.

I don't see one that specifically handles the new pipe operator alone (this seems like an option that might get attention if you file a request on github - or there might already be a way to do it precisely with the current custom options that I missed), but a couple alternatives are

;; highlight along with current assignment ops
;; ess-R-font-lock-keywords contains (ess-R-fl-assign-ops . t) by default
(with-eval-after-load 'ess
  (cl-pushnew "|>" ess-R-assign-ops :test 'string=))

Or add highlighting to all operators by customizing ess-R-font-lock-keywords to contain (ess-fl-keyword:operators . t)