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

Doesn't work with yasnippet #76

Open
aspiers opened this issue Jan 2, 2024 · 5 comments
Open

Doesn't work with yasnippet #76

aspiers opened this issue Jan 2, 2024 · 5 comments

Comments

@aspiers
Copy link
Contributor

aspiers commented Jan 2, 2024

@monnier just announced that he's patched yasnippet to honor major-mode-remap-alist, so that for example if it contains the cons cell (typescript-mode . typescript-ts-mode), then activating typescript-ts-mode will also activate all the snippets for typescript-mode.

However, as I noted in my reply to his comment, it won't work out of the box with treesit-auto yet because the latter is only setting major-mode-remap-alist locally not globally. I don't yet understand why it was coded in this way, so I don't have a good solution to suggest yet, but hopefully someone here will 😁

@aspiers
Copy link
Contributor Author

aspiers commented Jan 4, 2024

Actually, as noted here, I suspect the problem is not so much that it's being set via setq-local, but instead that after the file is loaded, major-mode-remap-alist somehow reverts to nil.

@aspiers
Copy link
Contributor Author

aspiers commented Jan 4, 2024

In joaotavora/yasnippet#1169 (comment), @monnier has advised that resetting local variables is expected behaviour for activation of any major mode.

@aspiers
Copy link
Contributor Author

aspiers commented Jan 5, 2024

See joaotavora/yasnippet#1169 (comment) for a recommended way forward here using derived-mode-add-parents.

@renzmann
Copy link
Owner

renzmann commented Jan 20, 2024

... the latter is only setting major-mode-remap-alist locally not globally. I don't yet understand why it was coded in this way ...

The motivation here (and I agree that it's probaby a bit more convoluted than it needs to be) is so that we can revert any changes made by turning global-treesit-auto-mode, which is in keeping with the first ask in the GNU Emacs Lisp coding conventions. Since we're augmenting the major mode Emacs chooses for a buffer, this counts as "changing Emacs' editing behavior." I like to stick to these conventions as best we can for inclusion in MELPA. If we were to modify major-mode-remap-alist globally, there's no guarantee that we can revert our changes if you modify that alist and then turn off global-treesit-auto-mode later.

Whether or not we got the implementation right is definitely up for debate, since this is my first try at it and there's a lot I don't know about how Emacs works under the hood 🤷

I liked your snippet here:

(setq major-mode-remap-alist (treesit-auto--build-major-mode-remap-alist))

since this effectively does what I originally wanted this package to do: just set the damn major-mode-remap-alist. My current advice would be to continue using this if you don't care about the "revert" behavior I mentioned above. I haven't seen this derived-mode-add-parents before, since it looks like it might be for Emacs 30? My hope is that treesit-auto won't be needed for very long, and we get better built-in support for what I've hacked around in this package, but I can't quite tell from that conversation whether this is resolved or a solid workaround exists.

@monnier
Copy link

monnier commented Jan 20, 2024 via email

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

3 participants