astoff / code-cells.el

Emacs utilities for code split into cells, including Jupyter notebooks
GNU General Public License v3.0
180 stars 11 forks source link

Using tree-sitter modes #19

Closed rossviljoen closed 10 months ago

rossviljoen commented 1 year ago

Thanks for the excellent package!

It would be nice if there were an easy way to use the new built-in tree-sitter modes in Emacs 29 (e.g. python-ts-mode instead of python-mode). As far as I can tell, the only way to currently change which mode is activated is by passing an argument to code-cells-convert-ipynb-style, but as far as I can tell this doesn't provide a way to set a new mode per-language.

Perhaps a nice way of generalising this would be to allow the argument to code-cells-convert-ipynb-style to be a function which can then compute the mode from the lang? Let me know if there's any interest in this and I can have a crack at a PR.

astoff commented 1 year ago

Thanks for the bug report. This makes sense, and a PR is welcome (but note that code-cells is on GNU ELPA, so you need to have the FSF copyright assignment paperwork).

astoff commented 10 months ago

Would it be sufficient to take major-mode-remap-alist into account? Or is there a good reason to support the case where the user adds something directly to auto-mode-alist?

astoff commented 10 months ago

I implemented now what you suggested, see code-cells--guess-mode. One could customize things by advicing that function. It is a backwards-imcompatible change of the option code-cells-convert-ipynb-style, so let's see if someone complains.