Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jackson15j opened this issue Feb 7, 2023 · 3 comments

Comments

@jackson15j
Copy link

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.

jackson15j added a commit to jackson15j/dot_emacs that referenced this issue Feb 7, 2023
@renzmann
Copy link
Owner

renzmann commented Feb 8, 2023

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
Copy link
Author

jackson15j commented Feb 10, 2023

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:

  • major-mode-remap-alist contents:
    ((python-mode . python-ts-mode)
     ...
    (python-ts-mode . python-mode)
    (markdown-ts-mode . markdown-mode)
  • Removed (setq python-ts-mode-hook python-mode-hook) from .emacs changed the major-mode-remap-alist contents to:
    (...
    (python-mode . python-ts-mode)
    (markdown-ts-mode . markdown-mode)
    • Markdown file still being discovered as python-mode.
    • Hooks to: python-mode are not applied to python-ts-mode.
    • QUERY: Shouldn't it be (python-ts-mode . python-mode) in major-mode-remap-alist ?
      • Just tried setting the values as: (python-ts-mode . python-mode). This pulls in all of my python-mode-hook's on the markdown file.
  • Removed treesit-auto directory, commented out package, but kept: (setq python-ts-mode-hook python-mode-hook).
    • On restarting emacs, the markdown file is still marked as python-mode.
    • major-mode-remap-alist is nil.

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
Copy link
Author

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 :)

jackson15j added a commit to jackson15j/dot_emacs that referenced this issue Feb 10, 2023
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.

Issue: renzmann/treesit-auto#26.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants