Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Clean up snippets in the python module #3

Open
wants to merge 7 commits into
base: default
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,18 @@ end
local snip = snippets.python
snip['.'] = 'self.'
snip.__ = '__%1(init)__'
snip.def = [[
def %1(name)(%2(arg)):
%3('''%4'''
)]]
snip.defs = [[
def %1(name)(self%2(, %3(arg))):
%4('''%5'''
)]]
snip.ifmain = [[
if __name__ == '__main__':
%1(main())]]
snip.class = [[
class %1(ClassName)%2((%3(object))):
%4('''%5(documentation)'''

)def __init__(self%6(, %7(arg))):
%8(super(%1, self).__init__())]]
snip.try = [[
try:
%0
except %2(Exception) as %3(e):
%4(pass)%5(
finally:
%6(pass))]]
snip.def = "def %1(name)(%2(self)%3(, %4(arg))):\n" ..
"\t%5('''%6'''\n" ..
"\t)\n"
snip.ifmain = "if __name__ == '__main__':\n" ..
"\t%1(main())\n"
snip.class = "class %1(ClassName)%0:\n\t'''%2(documentation)'''\n\n" ..
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would much rather prefer something like this:

snip.class = table.concat({
  "class %1(ClassName)%2((%3(object))):",
  "\t%4('''%5(documentation)'''",
  "",
  "\t)def __init__(self%6(, %7(arg))):",
  "\t\t%8(super(%1, self).__init__())"
}, '\n')

You've missed the trailing newline. It's easy to make that mistake with so many escapes.

I'm not sure this commit is an improvement over longstrings.

"\tdef __init__(self%3(, %4(arg))):\n\t\t%5(super(%1, self).__init__())n"
snip.try = "try:\n" ..
"\t%0\n"..
"except %2(Exception) as %3(e):\n" ..
"\t%4(pass)%5(\n" ..
"finally:\n" ..
"\t%6(pass))\n"

return M