renzmann / treesit-auto

Automatic installation, usage, and fallback for tree-sitter major modes in Emacs 29
GNU General Public License v3.0
369 stars 28 forks source link

treesit-auto appears to be setting the mode of non-python files to `python-mode` #26

Closed jackson15j closed 1 year ago

jackson15j commented 1 year ago

I'm still trying to dig into this with my messy config (https://github.com/jackson15j/dot_emacs), but I think there may be some interaction with treesit-auto, lsp, projectile that is changing the mode of non-python files to be set to python-mode.

The auto-mode-alist looks sane with no mixing of python-mode to non-python files.

Reproduction:

Sorry for the rough reproduction steps. Happy to dig more if you can give me some advice.

Locally, I've commented out treesit-auto and nuked my ~/.emacs.d folder and now back to non-python files opening in the correct mode.

renzmann commented 1 year ago

What a wild bug! Before I get a chance to dig in, I see a few things we can try to narrow down the bug space.

First, when the bug is present, what's the value of major-mode-remap-alist? What we want to know is if it has (python-mode . python-ts-mode) or p(python-ts-mode . python-mode).

Then, with the treesit-auto config commented out, use (require 'treesit-auto) but don't enable global-treesit-auto-mode, and:

  1. After opening the markdown file, manually evaluate M-: (treesit-auto--maybe-install-grammar). This is the main "black magic" function and is usually where things break. If this is what causes the flip to python mode then that helps to know

  2. (add-to-list 'major-mode-remap-alist '(python-mode . python-ts-mode)), followed by opening the markdown file (or add the opposite cons cell, based on the answer to the previous section. It seems less likely that this is the culprit, but is the only other thing that this package modifies, so worth trying. If this is the problem, the bug is upstream in Emacs

If none of these reproduce the bug, I'll need to look more carefully, or get a minimum preproduction based on emacs -q

jackson15j commented 1 year ago

Sorry for the delay (and the fat fingers send - will edit the comment with details), had to keep my config stable for a few days. Right, testing against: treesit-auto-20230209.2222:

Then, with the treesit-auto config commented out, use (require 'treesit-auto) but don't enable global-treesit-auto-mode, and:

1.After opening the markdown file, manually evaluate M-: (treesit-auto--maybe-install-grammar). This is the main "black magic" function and is usually where things break. If this is what causes the flip to python mode then that helps to know

I get:

Debugger entered--Lisp error: (wrong-type-argument treesit-auto-recipe nil)
  treesit-auto--ready-p(markdown-mode)
  treesit-auto--maybe-install-grammar()
  eval-expression((treesit-auto--maybe-install-grammar) nil nil 127)
  funcall-interactively(eval-expression (treesit-auto--maybe-install-grammar) nil nil 127)
  command-execute(eval-expression)
  1. (add-to-list 'major-mode-remap-alist '(python-mode . python-ts-mode)), followed by opening the markdown file (or add the opposite cons cell, based on the answer to the previous section. It seems less likely that this is the culprit, but is the only other thing that this package modifies, so worth trying. If this is the problem, the bug is upstream in Emacs

Tried both ways of setting the python modes (on top of the above failure to install the grammar), but the markdown file still opens with markdown-mode.


M-x emacs-version is: GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.36, cairo version 1.17.6) of 2023-01-29, so going to build the latest and see if there have been any outside fixes.

jackson15j commented 1 year ago

I've upgraded emacs to current latest (GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.36, cairo version 1.17.6) of 2023-02-10) and that appears to have fixed this issue with the same version of treesit-auto + my current config.

Going to close it off. Thanks for the help and sorry for pointing the finger of blame in your direction :)