-
Notifications
You must be signed in to change notification settings - Fork 107
Implement $0 as a snippet exit point (à la TextMate or Sublime Text) #278
Description
Prerequisites
- [x ] Put an X between the brackets on this line if you have done all of the following
Description
Hi! Since this is my first contribution here, I'm happy to receive feedback on how to improve.
Take the following snippet:
'.source.ts':
'console log':
'prefix': 'cl'
'body': 'console.log($0)'
Current behavior
If you ype "cl" then "Tab" your snippet expands.
If you push "tab" again, nothing happens.
If you push "tab" again, a tab character is added
Expected behavior
If you type "cl" then "Tab" your snippet expands.
If you push "tab" again, a tab character is added (no "useless" tab)
Versions
Atom : 1.31.1
Electron: 2.0.7
Chrome : 61.0.3163.100
Node : 8.9.3
apm 2.1.1
npm 6.2.0
node 8.9.3 x64
atom 1.31.1
python 2.7.12
git 2.7.4
Ubuntu 16.04.4, 4.4.0-137-generic, Unity, 64bits
Why this enhancement would be useful
The current behavior feels strange when you push tab and nothing
happens.
The expected behavior saves a keystroke. It gives a meaning to $0
which becomes the "snippet exit point" variable.
It becomes more consistent with other text editor.
This enhancement is also related to the following issue:
Should snippets use $0?
atom/language-c#262
Other text editors or applications where this enhancement exists
Expected behavior is the behavior as described in TextMate documentation,
https://macromates.com/manual/en/snippets#tab_stops
it's also Sublime Text behavior.
http://sublimetext.info/docs/en/extensibility/snippets.html#fields
Additional Information
Would you like to help implementing this feature?
Yes, I've actually already implemented it locally.
To try it:
in file "lib/snippet-expansion.coffee"
replace your existing "goToNextTabStop" function by
goToNextTabStop: ->
nextIndex = @tabStopIndex + 1
if nextIndex < @tabStopMarkers.length
if @setTabStopIndex(nextIndex)
true
else
@goToNextTabStop()
else
if @snippet.tabStopList.list.Infinity? # If snippet uses $0 value, exit snippet
succeeded = false
@destroy()
else
succeeded = @goToEndOfLastTabStop()
@destroy()
succeeded
Does your modification break an existing feature?
Yes for those who use placeholders with $0
Ex. ${0:myplaceholder}
The placeholder won't work since $0 is the point where
the snippet exists.