I work with emacs28.1.

I discovered that my trouble came from the fact that I activate tree-sitter in my init.el (I found that the coloration was better with tree-sitter). When I disable tree-sitter I do have the strings coloration in the chunks R with polymode. When I am in a .R file, in order to activate tree-sitter, I use the following function:

;; activate/desactivate tree-sitter on demand
(defun my-toggle-tree-sitter ()
  (interactive)
  (if (bound-and-true-p tree-sitter-mode)
      (progn
        (tree-sitter-mode -1)
        (tree-sitter-hl-mode -1)
        (message "Tree-sitter désactivé"))
    (progn
      (tree-sitter-mode 1)
      (tree-sitter-hl-mode 1)
      (message "Tree-sitter activé"))))


(define-key ess-r-mode-map (kbd "C-c t") #'my-toggle-tree-sitter)

I tried to use the following code in my init.el to disable tree-sitter in the chunks R with polymode but it doesn't work:

;; desactivate tree-sitter-mode in the chunks R in polymode
(defun my-polymode-r-disable-treesitter ()
  (when (bound-and-true-p tree-sitter-mode)
    (tree-sitter-mode -1))
  (when (bound-and-true-p tree-sitter-hl-mode)
    (tree-sitter-hl-mode -1)))

(add-hook 'poly-noweb+r-mode-hook #'my-polymode-r-disable-treesitter)



Le 11/02/2026 à 10:52, Martin Maechler a écrit :
Dirk Eddelbuettel via ESS-help
     on Sat, 7 Feb 2026 10:46:24 -0600 writes:
     > On 7 February 2026 at 17:13, LaurentEss via ESS-help wrote:
     > | 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.

     > Three+ decades emacs user here who also still struggles comprehending a
     > 'built over 30+ years' "superfund site" of his own ~/.emacs ... but I 
added
     > these lines a while back, and it seems to do the trick (thanks to the 
code in
     > ess and poly* modes):

     > ;;; MARKDOWN
     > (add-to-list 'auto-mode-alist '("\\.md" . poly-markdown-mode))
     > ;;; R modes
     > (add-to-list 'auto-mode-alist '("\\.Snw" . poly-noweb+r-mode))
     > (add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode))
     > (add-to-list 'auto-mode-alist '("\\.Rmd" . poly-markdown+r-mode))

Thank you, Dirk.

I wonder why / if the above is still needed, as you do mention
the polymode packages poly-*  and of course have and use
poly-R , no?  It already has such definitions, see

   https://github.com/polymode/poly-R/blob/master/poly-R.el#L736

and so I do wonder ...

Martin

     > I edit mixed use files all the time as Rmd with code snippets, even if I
     > often just rely on the mixed-mode highlighting.  But works in output and
     > during editing. Otherwise mostly defaults for both ess and poly-* (modulo
     > some small overrides I had for years).

     > Dirk

     > --
     > dirk.eddelbuettel.com | @eddelbuettel | [email protected]

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help

Reply via email to