Skip to content

Commit

Permalink
Fix #84
Browse files Browse the repository at this point in the history
  • Loading branch information
dcampos committed Oct 19, 2022
1 parent 88bb840 commit d732f34
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/snippy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ part of the description:
<
Please be aware that the legacy syntax doesn't support snippet options.

A single empty line at the end of the snippet body is discarded, regardless of
being indented. This is for maintaining compatibility with SnipMate, but also
allows snippets to be conveniently separated by a single blank line.

*snippy-snippet-options*

The `option`s control the behavior of the expansion of the snippet and are
Expand Down
4 changes: 2 additions & 2 deletions lua/snippy/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ local varmap = {
return fn.expand('<cword>')
end,
TM_LINE_INDEX = function()
return fn.line('.') - 1
return tostring(fn.line('.') - 1)
end,
TM_LINE_NUMBER = function()
return fn.line('.')
return tostring(fn.line('.'))
end,
TM_FILENAME = function()
return fn.expand('%:t')
Expand Down
3 changes: 3 additions & 0 deletions lua/snippy/reader/snipmate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ local function read_snippets_file(snippets_file)
end
end
if not snips[prefix] or snips[prefix].priority <= priority then
if #body > 1 and body[#body] == '' then
body = vim.list_slice(body, 1, #body - 1)
end
snips[prefix] = {
kind = 'snipmate',
prefix = prefix,
Expand Down
12 changes: 12 additions & 0 deletions test/snippets/blank.snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
snippet blank1
This is line 1.
This is line 2.
Then a blank line.


snippet blank2
Indented line is also removed.

snippet blank3
Blank line at the end of the file.

10 changes: 10 additions & 0 deletions test/unit/reader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,14 @@ describe('Snippet reader', function()
end
assert.is_same({}, total_failed)
end)

it('removes last blank line from snippet', function()
snippy.setup({ snippet_dirs = './test/snippets/', enable_auto = true })
vim.cmd('set filetype=blank')
assert.is_truthy(require('snippy.shared').config.snippet_dirs)
assert.is_not.same({}, require('snippy.reader.snipmate').list_available_scopes())
assert.is_same(4, #snippy.snippets.blank.blank1.body)
assert.is_same(1, #snippy.snippets.blank.blank2.body)
assert.is_same(1, #snippy.snippets.blank.blank3.body)
end)
end)

0 comments on commit d732f34

Please sign in to comment.