TIL: yasnippets and .yas-parents
As Emacs treesitter support matures, I've been adopting more and more of the built-in converted modes, for example python-ts-mode
in place of python-mode
, etc. There's a great article at masteringemacs.org
on the process, but essentially you can specify that when python-mode
would have been invoked, you should instead use python-ts-mode
.
This is not copmletely transparent; in particular, hooks defined for the old python-mode
don't automatically run for python-ts-mode
as well.
The other day I found another omission, albeit with a fairly unobtrusive workaround. I use the yasnippet package for snippets1, and mostly rely on the yasnippet-snippets predefined collection. These are grouped by modes, and… not surprisingly a snippet defined in python-mode
does not automatically become available in python-ts-mode
.
However — this examples assumes that you also load ~/.emacs.d/snippets/
— if you add a file ~/.emacs.d/snippets/python-ts-mode/.yas-parents
, containing the single line "python-mode
", then all snippets defined in python-mode
will also be loaded and available in python-ts-mode
.
(prompted by this toot)
For eg, in Python I can type init
followed by <TAB>
, and get a complete skeleton for def __init__
, with the cursor in the right place etc.