Sublime Forum

Snippet problems

#1

I have a snippet i defined for my forth programming as follows…

<snippet> <content><![CDATA[ : ${1} ${2}( ${3} --- ${4} ) ${5} ;]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>:</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <!-- <scope>source.python</scope> --> </snippet>

if i use this and get to tab point 5 in order to activate a second snippet i have (say for an IF statemetn) i have to hit escape. it would be nice if i could didnt have to do this. But lets say i hit escape at point 5 and then activate my if snippet the indentations are messed up

: foo       ( x y z --- bar )
  if
    tab point here
  then ;   <-- **

** the “then” is pasted in with an extra space and is thus indented one space further in than the if. Here is my IF snippet

<snippet>
    <content><![CDATA[
if
  ${1}
then]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>if</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

edit: p.s. it would be nice if i could have a tab point called $(0) to define the final tab point in a snippet :smile:
edit: MAYBE if i just TRY something before suggesting it as an idea i might discover that someone far smarter than I am already thought of it :smile:

0 Likes

#2

You can use $0 to signify the end-point for snippets, but there is nothing special about it AFAIK - it’s just the last tab-position.

The extra space is before the ; in your first snippet so I suppose you could delete it if you don’t need it.

I use the following set of key-bindings so that I can use Ctrl-Alt-Right or Ctrl-Alt-Left to insert one snippet within another (or cycle through them).

[code] { “keys”: “ctrl+alt+right”], “command”: “insert_best_completion”, “args”: {“default”: “”, “exact”: true} },
{ “keys”: “ctrl+alt+right”], “command”: “insert_best_completion”, “args”: {“default”: “”, “exact”: false},
“context”:

		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
},
{ "keys": "ctrl+alt+right"], "command": "replace_completion_with_next_completion", "context":
	
		{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
},
{ "keys": "ctrl+alt+left"], "command": "replace_completion_with_prev_completion", "context":
	
		{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
		{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
	]
}[/code]
0 Likes