From 6a7843bcb31491fe0f12b4f29e11628292ca6904 Mon Sep 17 00:00:00 2001 From: thalesmello Date: Thu, 7 Jul 2016 03:19:02 -0300 Subject: [PATCH] Include examples about how to create postfix Postfix snippets are an incredibly useful feature in IntelliJ IDE's. Only recently I came to realize this [could be implemented with UltiSnippets](https://github.com/sniphpets/sniphpets-postfix-codes/blob/master/UltiSnips/php.snippets). I think it would be a nice addition to the UltiSnippets documentation, in the hopes it could help others spend less time than I did trying to figure out how to put it together. --- doc/UltiSnips.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/doc/UltiSnips.txt b/doc/UltiSnips.txt index 5fcc5d3..13b6baf 100644 --- a/doc/UltiSnips.txt +++ b/doc/UltiSnips.txt @@ -1010,6 +1010,26 @@ expressions in this manner has some drawbacks: would end up with the above SNAP instead, not what you want. 2. The snippet is harder to read. +The biggest advantage, however, is that you can create snippets that take into +account the text preceding a "trigger". This way, you can use it to create +postfix snippets, which are popular in some IDEs. + +------------------- SNIP ------------------- +snippet "(\w+).par" "Parenthesis (postfix)" r +(`!p snip.rv = match.group(1)`$1)$0 +endsnippet +------------------- SNAP ------------------- +something.par -> +(something) + +------------------- SNIP ------------------- +snippet "([^\s].*)\.return" "Return (postfix)" r +return `!p snip.rv = match.group(1)`$0 +endsnippet +------------------- SNAP ------------------- +value.return -> +return value + 4.4.4 Global Snippets: *UltiSnips-globals*