Ok, thank you for this information.
I must have a problem with my configuration but I feel that I will have
trouble finding where my problem comes from.
Best regards
Le 06/02/2026 à 15:50, Naresh Gurbuxani a écrit :
With my default setup, I see character strings rendered in different colour.
Some keywords like “library” and “function” are also shown in different colour.
Sent from my iPhone
On Feb 2, 2026, at 12:06 PM, LaurentEss via ESS-help <[email protected]>
wrote:
Dear Ess-Help list,
I work with noweb files .Rnw and polymode. I can’t get the string coloring in
the R chunks of my files. And yet I searched for a while with the help of
chatGPT. Is it possible ? How do we get the string colored in the R chunk ? I
succeed to have the string coloring in the .R files but not in the R chunk.
When I do M-: major-mode in a R chunk of my .Rnw file I have the answer
ess-r-mode but the strings are not colored.
Thank you very much for your help.
Laurent
----o<--------------------------------------------------------------------------->o-----------------
Here below is what I put in my init.el file.
;; -*- lexical-binding: t; -*-
;;
;; highlighting R code for ESS in R chunk in .
;;
(with-eval-after-load 'ess-r-mode
;; 🔹 Catégories officielles ESS
(setq ess-R-font-lock-keywords
'((ess-R-fl-keyword:keywords . t)
(ess-R-fl-keyword:constants . t)
(ess-R-fl-keyword:modifiers . t)
(ess-R-fl-keyword:fun-defs . t)
(ess-R-fl-keyword:assign-ops . t)
(ess-R-fl-keyword:%op% . t)
(ess-fl-keyword:fun-calls . t)
(ess-fl-keyword:numbers . t)
(ess-fl-keyword:operators . t)
(ess-fl-keyword:delimiters . t)
(ess-fl-keyword:= . t)
(ess-R-fl-keyword:F&T . t)))
;; 🔹 Ajouter fonctions R et builtins supplémentaires
(setq ess-R-font-lock-keywords
(append ess-R-font-lock-keywords
'(("\\<\\(library\\|require\\|source\\|setwd\\|read\\.csv\\|readRDS\\)\\>"
. font-lock-builtin-face))))
;; 🔹 Coloration des chaînes
(font-lock-add-keywords
'ess-r-mode
'(("\"[^\"]*\"" . font-lock-string-face)
("'[^']*'" . font-lock-string-face)))
;; 🔹 Ajouter toutes les règles supplémentaires avec font-lock-add-keywords
(font-lock-add-keywords
'ess-r-mode
'(
;; Arguments nommés : x = ...
("\\(\\_<[[:alpha:].]+\\_>\\)[[:space:]]*="
1 font-lock-variable-name-face)
;; Pipes : %>% %<>% %$%
("%>%\\|%<>%\\|%\\$%" . font-lock-keyword-face)
;; Fonctions builtins classiques
("\\<\\(library\\|require\\|source\\|return\\|stop\\|warning\\|message\\)\\>"
. font-lock-builtin-face)
;; Nombres
("\\<\\([0-9]+\\(\\.[0-9]*\\)?\\)\\>" . font-lock-constant-face)
))
;; 🔹 Pretty symbols pour <- etc.
(setq ess-r-prettify-symbols t)
;; 🔹 Outils utiles
(add-hook 'ess-r-mode-hook #'outline-minor-mode)
(add-hook 'ess-r-mode-hook #'hl-todo-mode))
;; Recoloration automatique des chunks R polymode
(with-eval-after-load 'poly-noweb
(add-hook 'poly-noweb+r-mode-hook
(lambda ()
;; activer font-lock si ce n'est pas déjà fait
(font-lock-mode 1)
(font-lock-ensure))))
;; Wrapper interactif pour recoloration
(defun my/ess-r-font-lock-ensure ()
"Recolorer le buffer ESS-R courant."
(interactive)
(font-lock-ensure))
;; Raccourci dans tous les chunks R de polymode
(with-eval-after-load 'poly-noweb
(define-key poly-noweb+r-mode-map (kbd "C-c C-l")
#'my/ess-r-font-lock-ensure))
(with-eval-after-load 'poly-noweb
;; Hook pour tous les chunks R à l'ouverture
(add-hook 'poly-noweb+r-mode-hook
(lambda ()
;; activer font-lock si ce n'est pas déjà fait
(font-lock-mode 1)
;; Coloration personnalisée
(font-lock-add-keywords
nil
'(("\"[^\"]*\"" . font-lock-string-face)
("'[^']*'" . font-lock-string-face)))
;; Recoloration immédiate
(font-lock-ensure)
;; Outline et TODO
(outline-minor-mode 1)
(hl-todo-mode 1))))
;; 🔹 Recolorer tous les chunks R déjà ouverts
(dolist (buf (buffer-list))
(with-current-buffer buf
(when (derived-mode-p 'poly-noweb+r-mode)
;; s'assurer que font-lock est actif
(font-lock-mode 1)
;; appliquer les couleurs de chaînes
(font-lock-add-keywords
nil
'(("\"[^\"]*\"" . font-lock-string-face)
("'[^']*'" . font-lock-string-face)))
(font-lock-ensure))))
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help