Does not work with (treesit-defun-at-point) #118
-
I was adding a template to insert the current function name in my snippet, but it doesn't work.
Let say I have a function named bar in my Go code. Expanding fn will give me the funtion name, bar. Expanding ef will weirdly give me an empty string in the same function. I tried to recreate my intention using simple elisp function.
It also doesn't work, because the function My workaround is using a let statement to enclose the whole thing and get the name first.
Now the thing works. If I want it to work with tempel, now I have to change my ef snippet into this.
How could I do it with tempel without writing custom function? I suspect tempel suffers from the same bug of my first iteration of the function. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
In order for this to work
The variable can then be used later. See also https://github.com/minad/tempel#template-syntax for the supported syntax. In case you want to reuse a pattern often, you can define custom elements: https://github.com/minad/tempel#defining-custom-elements. |
Beta Was this translation helpful? Give feedback.
In order for this to work
(treesit-defun-name (treesit-defun-at-point))
should be evaluated first and bound to a variablename
. You can do this using(p FORM <NAME> <NOINSERT>)
:(p (treesit-defun-name (treesit-defun-at-point)) name t)
The variable can then be used later. See also https://github.com/minad/tempel#template-syntax for the supported syntax. In case you want to reuse a pattern often, you can define custom elements: https://github.com/minad/tempel#defining-custom-elements.