occivink / kakoune-snippets Goto Github PK
View Code? Open in Web Editor NEWSnippet support for kakoune
License: The Unlicense
Snippet support for kakoune
License: The Unlicense
It would be cool to see available triggers as you type, much like we are able to see completions of language facilities.
It could display a trigger, and info inside information field like so:
but instead of __fortify_function
there will be some trigger, say for
, instead of Interface
there will be Snip
or Snippet
, and instead __fortify_function
will be the snippet description for loop
I also wonder how it will play when https://github.com/mawww/kakoune/tree/completions-commands arrive. Could it be possible to expand snippets on completion, or if special key is pressed after the completion, and so on.
By now I have disabled auto expansion and I've mapped : snippets-menu<ret>/
to a key to have a fast way to open up a snippet search-and-insert menu.
Could it be possible to integrate/merge the snippets menu into kakoune autocomplete engine?
For example, when I type fo
the autocomplete menu could show both the for
word/ and the for
snippet (that expands when selected with c-n
).
Haven't yet looked into how autocomplete is implemented, implementing this would be really cool.
I think this should go in snippets-expand-trigger
but I'm not exactly sure as I'm still trying to make sense of the code.
I set a few of my snippets to trigger at the start of a line with respect to indentation by adding ^(\s*)
to the start of the trigger.
for example (\s*)do
triggers:
do
and
try:
do
but not
todo
or
to do
that way the snippet would work so long as the trigger is the first thing on the line, other than white space.
currently the function inserts the triggered snippet starting at the line (which makes sense because technically the whitespace was part of the trigger). it would make sense though to change this so that snippets could work with indentation.
This will allow to create snippet packs for users who don't want to define their own snippets, and will hugely help organize snippets for different languages.
The stcucture should look like that:
snippets # multiple files per fyletype directory
Cpp
for.snip
if.snip
Java
for.snip
if.snip
snippets single file for single filetype
cpp.snippets
java.snippets
Of course those fies can be an arbitrary kakoune scripts, but it would be more common to define a filetype for snippet files, add a syntax highlighting.
Snippets can be one snippet per file located in fyletype folder, like in yasnippet, or one file per filetype with all snippets for current language as shown in the example above.
After you jump to the placeholder the text is selected. Typing arbitrary text right after jump could perform c automatically for us.
Hello,
I think most of people expect from snippet plug to have to following behavior:
type for
then press a key so the for
expand to
for $X in $COL:
$BODY
and then press another key ( usually tab) to move from $X to $COL to $BODY.
I think this the default way of using snippet, but it's really not clear how to do that in the doc. I feel this should be inside the ##Usage
paragraph
There's only two commits at this point, but it's a great plugin already, and since I've already created a snippet manager for another editor, I'd like to provide a list of features that would be super great to have:
{{TEXT:SELECTION}}
, so selection could contain default text on expand.{{1:TEXT:SELECTION}
, so we could jump in needed order, and skip whole snippet if needed.${1:TEXT}
, $2
, so other snippets from other managers could be ported and used. This also will make possible to use LSP snippets. Here's a LSP snippet standard, but it's pretty common for other snippet managers too. I've implemented it in my snippet plugin for Vim.${1:TEXT}
and $1
will share same TEXT
on expansion.${0:TEXT}
or $0
as last placeholder${VISUAL}
${1|hello,world|}
, so on jumping popup menu will allow to select a candidate. I'm not sure if it is possible with Kakoune though.I'll dig into your implementation and see if I can help with implementing those features. I also might extend this list if I remember something that I've didn't mentioned.
At the moment commands snippets
and snippets-menu
list snippet names.
Usually when I type, I need to know what expansion token is, not what snippet name is. It is not very convenient, because there is no way to see expansion tokens available, without context switching.
In my opinion at least snippets-menu
should list snippet expansion tokens.
during testing #23 Ive encountered problem with loading jdj'\;;l - -=[]\,.kdj
. I don't think that anyone would use such thing, but obviously there shouldn't be any error since all characters are valid.
error running hook WinSetOption(snippets='-=[]\,.kdj' 'jdj''\;;l' 'snippets-insert ''vaiv'' ')/: 2:6: 'set' regex parse error: unknown atom escape ';' at '(jdj'\;<<<HERE>>>;l)'
Weirdly enough, when I first got this plugin it would automatically expand snippets by default despite saying that wasn't the default behavior.
More annoyingly though, is that it has suddenly stopped doing that for some reason I can't figure out. And I can't seem to get that behavior back:
set global snippets_auto_expand true
That line doesn't do anything, I've tried it with different snippets in different languages but it doesn't auto-expand.
I've also confirmed that using the :snippets-expand-trigger
and such commands manually does work, but that's hardly an efficient solution.
Is this a bug, or (more likely) am I just doing something wrong? I'm very new to kakoune, so I wouldn't be surprised if my syntax is incorrect. Thanks in advance for any help!
Maybe it is a good idea to include a dependency section.
For a starter it seems to depend on perl
.
Hi,
Even though it seems the development of this project has been 'abandoned' I was just wondering if a particular use-case could be dealt with by this kind of framework hypothetically -- for further reference, I suppose. I'm not aware that this is possible with other snippet managers but I very well could have missed it.
In LaTeX, bulleted and numbered lists are indicated by itemize
or enumerate
environments. In these, the bullets or numbers are denoted by \item
.
One of my snippets expands to
\begin{itemize}
\item |
\end{itemize}
(the pipe is where my cursor ends up).
What I imagined was that pressing <Tab>
could trigger a new \item
statement to appear:
\begin{itemize}
\item blah blah blah...
\item |
\end{itemize}
and so on each time <Tab>
is pressed in this environment.
I hope I was clear enough. Would this be feasible hypothetically or would we need something more powerful?
Thanks.
Currently if perl isn't installed, plugin works only in half way: snippet is inserted, but indentation and cursors are not. This may look misguiding for new users, because they may miss that Perl is required. It would be better if plugin tested command -v perl
and throwed an error and info message about it's requirements.
Documentation of transformations for LSP style snippets may be needed to support lsp snippets.
Basically transformations allows modifying the placeholder contents, before it is inserted with sed-like commands written inside the placeholder.
You can also check transformations in UltiSnips, which can actually execute shell, python and vimscript: UltiSnips#Interpolation
There's also yasnippet for Emacs, that allows to do some cool real time transformations. You can check the docs here
Hi,
I'm new to snippets (and to Kakoune) and loving it. Until now I've been using the snippets-directory extension, but I'd rather just have all my snippets for a given language written in one file (whose name could be interpreted as a regex like when using snippets-directory).
The thing is I simply can't figure out how to add a new snippet other than using the add-snippets command (which creates a file) or manually adding a file myself. Based on syntax that I saw written in other issues, I added this to my kakrc:
hook global WinSetOption filetype=latex %{
set -add buffer snippets "hello" "\h" %{snippets-insert %{\hello{$1} $0}}
}
But this only expands when I write "\h " and when it does it doesn't remove the "\h", the result is "\h\hello{}". Yet most (not all) of the snippets I added as a file using a directory work as expected (it's really nice!).
Is there something I'm not getting here? Sorry if this is a stupid question. Ideally I'd rather have all my snippets in one place. Thanks in advance.
I've accompanion kakoune-snippet-collection plugin installed and have following setting in my setup:
set-option -add global snippets_directories "%opt{plug_install_dir}/kakoune-snippet-collection/snippets"
However invoking :snippets-info
command in rust files shows nothing, I mean there is no pop up at all. This is strange as it works in go files for example. I tested in macos and arch linux and it is same behaviour.
The most common snippet syntax is adopted by many projects, like language servers, different editors like Visual Studio Code, Sublime Text, Emacs (via Yasnippet), Vim (via Ultisnips and SnipMate), TextMate, and possibly others.
The syntax for snippets can be found at LSP documentation: snippet syntax
Supporting universal snippets would allow to reuse snippet definitions from other editors wit less amout of reworking those.
Using kakoune master, the expand of a snippet always trigger my first snippet.
I have the following configuration for kakoune snippet:
set-option -add global snippets_directories "%opt{plug_install_dir}/kakoune-snippet-collection/snippets"
set-option global snippets_auto_expand true
map global insert '<c-s>' '<a-;>: snippets-expand-trigger<ret><esc>'
map global insert '<c-n>' '<a-;>: snippets-select-next-placeholders<ret><esc>'
map global normal '<c-n>' ': snippets-select-next-placeholders<ret>'
I work only on CPP. Whenever a snippet is triggered, the result is:
#include <iostream>
even if I typed for, main, ...
I also tried to call the snippet-expand-selection
manually with the same result.
Best,
Charles
Support for this kind of placeholders ${2:text ${1:other text}}
Another snippet for Rust.
filename: |} - Closure, anonymous function (block)
${1:move }|${2:what}| {
${0:/* body */}
}
Trying to load this snippet produces this error message:
error running hook WinSetOption(snippets='Closure, anonymous function (block)' '|}' 'snippets-insert ''${1:move }|${2:what}| {
${0:/* body */}
}'' ')/: 2:6: 'set' regex parse error: unexpected '}' at '(|<<<HERE>>>})'
The use case for this would be as follows:
\usepackage[possibly something]{definitely something}
could there be an option so that the default text of []
would be deleted if you just jumped to the next snippet?
Hope this makes sense and thanks for the great plugin!
I have the following snippets
set -add buffer snippets \
"comment" "/*" %{snippets-insert %{/*
* $1
*/}}
I would like to have the whilespace before the *
characters to persist into the snippets, currently it seems to be removed
defining this two snippets, will result in availability of only one of them:
set-option -add window snippets 'if {}' 'if' %{
snippets-insert 'if ($1) {
${indent}$0
}'
}
set-option -add window snippets 'if {} else {}' 'elif' %{
snippets-insert 'if ($1) {
${indent}$2
} else {
${indent}$0
}'
}
If I type elif
and hit my expand key, if
snippet will be expanded instead of elif
.
I noticed that the docs mention that snippets don't auto expand by default, but apparently they do:
https://github.com/occivink/kakoune-snippets/blob/master/snippets.kak#L125
Docs and code seem to be out of sync.
If I run kak in a headless session mode like kak -d -s mysession
, then connect to that session with kak -c mysession
, none of the plugin related commands work, same with snippet expansion in insert mode - it doesn't work.
simply executing of :set-option -add window snippets 'trigger' 'snippet'
results in endless waiting for shell to finish.
*debug*
buffer shows insanely huge log:
...
sh: line 5: shift: 3: shift count out of range
sh: line 5: shift: 3: shift count out of range
sh: line 5: shift: 3: shift count out of range
sh: line 5: shift: 3: shift count out of range
sh: line 5: shift: 3: shift count out of range
sh: line 5: shift: 3: shift count out of range
sh: line 5: shift: 3: shift count out of range
sh: line 5: shift: 3: shift count out of range
sh: line 5: shift: 3: shift count out of range
sh: line 5: shift: 3: shift count out of range
>>>
error running hook WinSetOption(snippets='trigger' 'snippet')/: 2:6: 'set' regex parse error: regex parsed to more than 32767 ast nodes at '\A�(snippet|snippet|snippet|snippet|snippet|snippet|snippet|snippet|snippet|snippet|snippet|snipp...
Jumping can accept the count
variable.
It also could be handy to be able jump backward in case you edited some placeholder wrong.
Ability to skip whole snippet and jump directly to the last placeholder also comes in handy when snippet is fine by default.
If I add this snippet for kak
filetype:
touch "^hello - (descr)"
echo snippet > \^hello\ -\ \(descr\)
kak test.kak
In *debug*
I see:
shell stderr: <<<
sh: 1: eval: Syntax error: "(" unexpected
Snippets itself seem to work fine. This is on auto-discard
branch.
The docs mention:
snippets [str-list] is a list of {name, trigger, command} tuples. The name is the identifier of the snippet, the trigger is a short string that identifies the snippet, and the command is what gets eval'd when the snippet is activated. In practice it's just a flat list that looks like snip1-name snip1-trigger snip1-command snip2-name snip2-trigger snip2-command...
While this is descriptive, I'm still having a bit of trouble figuring out how I'd configure this plugin if I have, say, a directory of snippets somewhere. A real world configuration example for the snippets option would be appreciated!
I have been trying this plugin for a while and it's great but I'm having a problem with trigger lengths. Some commits before, I could use some slightly longer triggers but now they are failing. After checking the source, the reason is that you are calling "h6h", limiting the trigger length to 6.
Is there a good reason why it's set to that number? Is it expected for the triggers to be always short?
I've ported my snippet collection to work with your plugin, and now I'm testing it.
I can't expand ||
snippet, which is defined like so:
filename: || - Closure, anonymous function (inline)
${1:move} |${2:entry}| { ${0:/* body */} }
The syntax is ${1|first,second,third|}
. Upon jump on such placeholder first option is selected an a popup menu is shown with other variants. If completion menu could be utilized for this it will be the best solution, since we can just dicard it without confirmation, and all other snippet managers use it.
A command like snippets-insert-replace-first-placeholder
which would trigger a prompt, to which you would write the name of your snippets, which preferably only has one placeholder. Then, your current main selection would be the default value for the first placeholder.
A nice usecase would be \textbf{}
and many other stuff in LaTeX.
It would be handy to have an option to expand snippets when some user-definde key is pressed. Automatic expansion is good feature, but not always wanted.
I like to expand snippets with Tab, and jump betwen placeholders with Tab too. This involves some problems when you actually want to insert tab character. When I've designed SimpleSnippets.vim, I've implemented a function, that checked if typed text is a trigger, and if it is it inserted a snippet, otherwise it acted as tab key was pressed. That allowed me to use tab to completions and snippets.
Hi, I'm trying to define some global scope snippets, I've been able to do so with a '(.*)' directory, but I also want to be able to declare
expansions in snippet and run it in the context I'm in, for example I often use this convention when commenting code to have
context about when that happened, and I would like to have it for any file type, and being able to eval those expressions easily,
%opt{comment_line} NOTE %sh{date}
, I clearly could do this with a user define command and mapping, but the idea to use snippets
for other purposes more than code itself would be an interesting idea, and the framework this plugin provides could be used to provide such feature, I would like to know what you think about.
thanks for you work!
Is it working ? abandoned ?
After upgrading to the latest version, kakoune always expand first snippet in the snippets directory
snippet dir:
https://ttm.sh/0TI.png
example:
https://asciinema.org/a/WwCNDqnluiqv72DJkGq4lmDDu
workaround:
reverting to 2021.11.08 fixes this issue
edit: didn't see #46 sorry
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.