Comments (22)
My workaround:
(advice-add 'yas--modes-to-activate :around
(defun yas--get-snippet-tables@tree-sitter (orig-fn &optional mode)
(funcall orig-fn
(or (car (rassq (or mode major-mode) major-mode-remap-alist))
mode))))
from yasnippet.
In case somebody needs a workaround to work today, I found this that seems to work
from yasnippet.
from yasnippet.
from yasnippet.
from yasnippet.
For you you can get in working by adding (yas-activate-extra-mode 'python-mode)
to python-ts-mode-hook
from yasnippet.
@twlz0ne This is not working for me, at least for C++. Any other workaround?
from yasnippet.
@jvillasante Don't know why not working for you, the advice above just tells yas to use /path/to/snippets/lang-mode
instead of /path/to/snippets/lang-ts-mode
. Have you checked the major-mode-remap-alist
and snippet dirs?
(car (rassq 'c++-ts-mode major-mode-remap-alist))
;; => c++-mode
(and (yas--get-snippet-tables 'c++-mode) t)
;; => t
from yasnippet.
In case somebody needs a workaround to work today, I found this that seems to work
Thanks a lot @jvillasante, yasnippet-treesitter-shim looks like a great workaround - although IMHO really this should work out of the box with yasnippet rather than needing a separate package as a bandaid 😞
from yasnippet.
I got the shim working with use-package
and straight.el
and submitted fbrosda/yasnippet-treesitter-shim#1 to document this so that others can install it more easily.
from yasnippet.
@monnier Thanks so much for working on this! I have just tested, and can confirm it works 🚀
BTW I tested it by setting major-mode-remap-alist
with the help of treesit-auto.el
, although I note that that package only sets major-mode-remap-alist
locally by advising set-auto-mode-0
:
So I had to set it globally via:
M-: (setq major-mode-remap-alist (treesit-auto--build-major-mode-remap-alist))
This means that while your commit is working as intended, it won't work out of the box with treesit-auto.el
yet. I don't yet understand why the latter is only setting major-mode-remap-alist
locally not globally, so I'm not sure what the best full solution would be, but I guess the responsibility for fixing that is more likely to lie with treesit-auto.el
rather than yasnippet
.
from yasnippet.
I wrote:
This means that while your commit is working as intended, it won't work out of the box with
treesit-auto.el
yet. I don't yet understand why the latter is only settingmajor-mode-remap-alist
locally not globally, so I'm not sure what the best full solution would be, but I guess the responsibility for fixing that is more likely to lie withtreesit-auto.el
rather thanyasnippet
.
I've filed renzmann/treesit-auto#76 to track this.
from yasnippet.
from yasnippet.
I will do that when I get a moment (how did I use emacs for 30 years and only just hear about trace-function
?!), but I have already seen a weird thing which might explain this:
Somehow treesit-auto correctly executes the setq-local
when the file is first visited (proven via edebug
), but then when the buffer is opened, major-mode-remap-alist
somehow reverts to nil
.
from yasnippet.
I've commented the same point in renzmann/treesit-auto#76 (comment), so perhaps that would be a better place to continue this conversation for now, since it currently looks like more of an issue with treesitter-auto
rather than yasnippet
.
from yasnippet.
from yasnippet.
Yep, I appreciate the difference and did check that carefully: I see it as nil
in the buffer of the (Typescript) file where I want yasnippet activated. To clarify, this is what I did:
- Instrument
treesit-auto--set-major-remap
with Edebug. - Load the Typescript file
- Step through
treesit-auto--set-major-remap
and verify thatmajor-mode-remap-alist
is being set correctly. (At this point, pressinge
to evaluate(buffer-name)
in the context of the debugger proves that it's being set on the buffer of the Typescript file. In contrast, doingM-: (buffer-name)
at this point returnstreesit-auto.el
as expected.) - Allow
treesit-auto--set-major-remap
to complete, so that the Typescript file's buffer is now open. - Observe that
C-h v major-mode-remap-alist
now showsnil
.
It's strange, but perhaps something else is resetting the variable to nil
. Or more likely, I'm just being an idiot somehow.
Anyhow, I will try debug-on-variable-change
which is another great trick I somehow never discovered before! Perhaps I should find more issues so that I can continue learning from you ;-)
from yasnippet.
OK, this is interesting and seems relevant! I tried debug-on-variable-change
. Sure enough, it triggered the debugger as expected:
Debugger entered--setting major-mode-remap-alist in buffer Options.tsx to ((yaml-mode . yaml-ts-mode) (typescript-mode . typescript-ts-mode) (js2-mode . js-ts-mode) (javascript-mode . js-ts-mode) (js-mode . js-ts-mode) (sh-mode . bash-ts-mode)):
debug--implement-debug-watch(major-mode-remap-alist ((yaml-mode . yaml-ts-mode) (typescript-mode . typescript-ts-mode) (js2-mode . js-ts-mode) (javascript-mode . js-ts-mode) (js-mode . js-ts-mode) (sh-mode . bash-ts-mode)) set #<buffer Options.tsx>)
set(major-mode-remap-alist ((yaml-mode . yaml-ts-mode) (typescript-mode . typescript-ts-mode) (js2-mode . js-ts-mode) (javascript-mode . js-ts-mode) (js-mode . js-ts-mode) (sh-mode . bash-ts-mode)))
treesit-auto--set-major-remap(tsx-ts-mode nil)
apply(treesit-auto--set-major-remap (tsx-ts-mode nil))
set-auto-mode-0(tsx-ts-mode nil)
set-auto-mode--apply-alist((("\\(\\.js[mx]\\|\\.har\\)\\'" . js-ts-mode) ("\\.ya?ml\\'" . yaml-ts-mode) ("\\.ts\\'" . typescript-ts-mode) ("\\.tsx\\'" . tsx-ts-mode) ("\\.toml\\'" . toml-ts-mode) ("\\.rs\\'" . rust-ts-mode) ("\\(?:\\.\\(?:rbw?\\|ru\\|rake\\|thor\\|jbuilder\\|rabl\\|ge..." . ruby-ts-mode) ("\\.py[iw]?\\'" . python-ts-mode) ("\\.json\\'" . json-ts-mode) ("\\.js\\'" . js-ts-mode) ("\\.java\\'" . java-ts-mode) ("go\\.mod\\'" . go-mod-ts-mode) ("\\.go\\'" . go-ts-mode) ("\\Dockerfile\\'" . dockerfile-ts-mode) ("\\.css\\'" . css-ts-mode) ("\\.cpp\\'" . c++-ts-mode) ("\\.cmake\\'" . cmake-ts-mode) ("\\.cs\\'" . csharp-ts-mode) ("\\.c\\'" . c-ts-mode) ("\\.sh\\'" . bash-ts-mode) ("\\.odc\\'" . archive-mode) ("\\.odf\\'" . archive-mode) ("\\.odi\\'" . archive-mode) ("\\.otp\\'" . archive-mode) ("\\.odp\\'" . archive-mode) ("\\.otg\\'" . archive-mode) ("\\.odg\\'" . archive-mode) ("\\.ots\\'" . archive-mode) ("\\.ods\\'" . archive-mode) ("\\.odm\\'" . archive-mode) ("\\.ott\\'" . archive-mode) ("\\.odt\\'" . archive-mode) ("\\(?:\\(?:\\.\\(?:b\\(?:\\(?:abel\\|ower\\)rc\\)\\|json\\(?:l..." . json-mode) ("\\.scss\\'" . sass-mode) ("\\.sass\\'" . sass-mode) ("\\.haml\\'" . haml-mode) ("\\.\\(phtml\\|tpl\\.php\\|jsp\\|as[cp]x\\|erb\\|mustache\\|..." . web-mode) ("\\.json\\'" . json-mode) ("\\.ya?ml\\'" . yaml-mode) ("\\.\\(e?ya?\\|ra\\)ml\\'" . yaml-mode) ("\\.feature\\'" . feature-mode) ("/\\.zsh\\(env\\|rc\\|/functions/\\)\\|\\.stp$" . sh-mode) ("\\.sc\\'" . sclang-mode) ("\\.gem\\'" . tar-mode) ("\\(\\.\\(e?rb\\|rjs\\|rake\\)\\|Rakefile\\|Guardfile\\)\\'" . ruby-mode) ("\\.py\\'" . python-mode) ("\\.php\\'" . php-mode) ("\\.\\(?:php[s345]?\\|phtml\\)\\'" . php-mode-maybe) ("\\.\\(?:php\\.inc\\|stub\\)\\'" . php-mode) ("/\\.php_cs\\(?:\\.dist\\)?\\'" . php-mode) ...) nil nil)
#<subr set-auto-mode>()
so-long--set-auto-mode(#<subr set-auto-mode>)
apply(so-long--set-auto-mode #<subr set-auto-mode> nil)
set-auto-mode()
normal-mode(t)
after-find-file(nil nil t nil nil)
However after continuing from this, the debugger reactivated again with this:
Debugger entered--killing local value of major-mode-remap-alist in buffer Options.tsx:
debug--implement-debug-watch(major-mode-remap-alist nil makunbound #<buffer Options.tsx>)
prog-mode()
typescript-ts-base-mode()
tsx-ts-mode()
#<subr set-auto-mode-0>(tsx-ts-mode nil)
apply(#<subr set-auto-mode-0> (tsx-ts-mode nil))
set-auto-mode-0(tsx-ts-mode nil)
set-auto-mode--apply-alist((("\\(\\.js[mx]\\|\\.har\\)\\'" . js-ts-mode) ("\\.ya?ml\\'" . yaml-ts-mode) ("\\.ts\\'" . typescript-ts-mode) ("\\.tsx\\'" . tsx-ts-mode) ("\\.toml\\'" . toml-ts-mode) ("\\.rs\\'" . rust-ts-mode) ("\\(?:\\.\\(?:rbw?\\|ru\\|rake\\|thor\\|jbuilder\\|rabl\\|ge..." . ruby-ts-mode) ("\\.py[iw]?\\'" . python-ts-mode) ("\\.json\\'" . json-ts-mode) ("\\.js\\'" . js-ts-mode) ("\\.java\\'" . java-ts-mode) ("go\\.mod\\'" . go-mod-ts-mode) ("\\.go\\'" . go-ts-mode) ("\\Dockerfile\\'" . dockerfile-ts-mode) ("\\.css\\'" . css-ts-mode) ("\\.cpp\\'" . c++-ts-mode) ("\\.cmake\\'" . cmake-ts-mode) ("\\.cs\\'" . csharp-ts-mode) ("\\.c\\'" . c-ts-mode) ("\\.sh\\'" . bash-ts-mode) ("\\.odc\\'" . archive-mode) ("\\.odf\\'" . archive-mode) ("\\.odi\\'" . archive-mode) ("\\.otp\\'" . archive-mode) ("\\.odp\\'" . archive-mode) ("\\.otg\\'" . archive-mode) ("\\.odg\\'" . archive-mode) ("\\.ots\\'" . archive-mode) ("\\.ods\\'" . archive-mode) ("\\.odm\\'" . archive-mode) ("\\.ott\\'" . archive-mode) ("\\.odt\\'" . archive-mode) ("\\(?:\\(?:\\.\\(?:b\\(?:\\(?:abel\\|ower\\)rc\\)\\|json\\(?:l..." . json-mode) ("\\.scss\\'" . sass-mode) ("\\.sass\\'" . sass-mode) ("\\.haml\\'" . haml-mode) ("\\.\\(phtml\\|tpl\\.php\\|jsp\\|as[cp]x\\|erb\\|mustache\\|..." . web-mode) ("\\.json\\'" . json-mode) ("\\.ya?ml\\'" . yaml-mode) ("\\.\\(e?ya?\\|ra\\)ml\\'" . yaml-mode) ("\\.feature\\'" . feature-mode) ("/\\.zsh\\(env\\|rc\\|/functions/\\)\\|\\.stp$" . sh-mode) ("\\.sc\\'" . sclang-mode) ("\\.gem\\'" . tar-mode) ("\\(\\.\\(e?rb\\|rjs\\|rake\\)\\|Rakefile\\|Guardfile\\)\\'" . ruby-mode) ("\\.py\\'" . python-mode) ("\\.php\\'" . php-mode) ("\\.\\(?:php[s345]?\\|phtml\\)\\'" . php-mode-maybe) ("\\.\\(?:php\\.inc\\|stub\\)\\'" . php-mode) ("/\\.php_cs\\(?:\\.dist\\)?\\'" . php-mode) ...) nil nil)
#<subr set-auto-mode>()
so-long--set-auto-mode(#<subr set-auto-mode>)
apply(so-long--set-auto-mode #<subr set-auto-mode> nil)
set-auto-mode()
normal-mode(t)
after-find-file(nil nil t nil nil)
I can't figure out why prog-mode
would cause the local value of major-mode-remap-alist
to be killed, but I'm guessing you'll know the reason immediately :)
from yasnippet.
from yasnippet.
Hrm, so does this mean that treesit-auto
's approach is fundamentally flawed?
from yasnippet.
OK thanks, so for now the workarounds are either to use https://github.com/fbrosda/yasnippet-treesitter-shim or my hack of setting it globally:
(setq major-mode-remap-alist (treesit-auto--build-major-mode-remap-alist))
I think any further discussion on the treesit-auto side of things belongs in renzmann/treesit-auto#76.
from yasnippet.
Yep, that all makes sense.
from yasnippet.
Related Issues (20)
- csharp-mode bindings not working (sometimes) HOT 1
- please tag new release for Emacs 29 compat (affects MELPA stable and others) HOT 7
- Tests failing under Emacs 29+ HOT 13
- unwanted prompt when pressing TAB HOT 1
- self-defined function `expand-from-key-p`(which check current expanding come from key or binding) not work anymore after update to newest master. HOT 3
- update latex snippets for use with text selection
- Documentation webage 404s HOT 1
- yas--all-parents can fail to find all parents if called before snippet directory is loaded HOT 5
- Some functions don't work in yasnippet HOT 3
- Multi-line embedded lisp-code HOT 7
- Template variables do not work in template lines starting with # HOT 3
- delete-numberless-inner-snippet-issue-562 test failure (non-deterministic) HOT 6
- Error in condition evaluation: Symbol’s function definition is void: js2-node-type HOT 3
- elpy-snippet-init-assignments - "Symbol’s value as variable is void: start-point" HOT 1
- Suggestion: not preceded by space HOT 4
- special character
- elisp evaluation move cursor on new line
- elisp evaluation move cursor on new line in snippet body
- Suggestion for a repeat snippet feature. HOT 8
- Case sensitive major modes? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yasnippet.