Closed IllustratedMan-code closed 1 year ago
That seems like a good snippet format to support in this plugin! Would you be interested in making a PR for the implementation? Also can you give an example of "emacs modes" in a snippet definition?
An emacs major mode is just the terminology used for different languages. Major modes are analoguos to the &filetype
variable in vim/neovim. This isn't actually part of the snippet, but a part of the directory structure of a snippet directory.
snippet_dir
|
|___ python-mode
| |____ mysnip
|
|___ ess-mode
|____ anothersnip
Generally, the mode name is just the language followed by "mode", but in some cases like ess-mode (the mode name for the r language), the mode name won't line up with the language. This is furthur complicated by .yas-parents
files which can allow snippets to be shared between modes.
A yasnippet generally looks something like this:
# -*- mode: snippet -*-
# name: function
# key: f
# group: definitions
# --
def ${1:fun}(${2:args}):
$0
The first line is a mode annotation for emacs so emacs knows how to do syntax highlighting for the snippet file; this line isn't always present, but should be ignored. Some other "directives" aren't relavent to vim, like # group
. Some are analogous to other snippet formats (key: f
is identical to "prefix": "f"
in vscode style snippets. The actual snippet begins after the # --
line.
Similar to how luasnip snippets can be written in pure lua, yasnippets can be written in elisp (a variant of lisp). These are defined when # type: command
is in the header. I think trying to convert these is beyond the scope of snippet-converter.nvim
. These snippets should just be ignored (maybe with a warning?).
In terms of a PR, I'm not the most confident in lua and I'm a little intimidated by your parser code to be honest. It would definitely be slow going. I can try to give it a go, but I would love to hear your development/debugging workflow. I've developed one neovim extension before and debugging was pretty awful.
I'm very much happy to test though!
Thanks for your good explanation, that really helped me during the implementation!
These are defined when # type: command is in the header. I think trying to convert these is beyond the scope of snippet-converter.nvim. These snippets should just be ignored (maybe with a warning?).
That's a very good idea, I'll add this.
Could you help me with the following:
# -*- mode: snippet -*-
is part of the snippet body or part of the header of the next snippet
I made an issue on the luasnip repo and was directed here.
Syntax appears to be similar to textmate/lsp. Only problem I can see is that yasnippet uses emacs modes which would have to be converted to vim buffer types.