Advertisement
rcl_

Textadept snippets example

Oct 19th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.42 KB | None | 0 0
  1. events.connect(events.LEXER_LOADED, function(lang)
  2.   if lang == 'python' then
  3.     buffer.tab_width = 4
  4.     snippets['#!'] = '#!/usr/bin/env python\n%0'
  5.     snippets['***'] = '*args, **kwargs'
  6.     snippets['///'] = '""" %1(Docstring text) """'
  7.     snippets['_'] = '__%1(init)__%2'
  8.     snippets['class'] = 'class %1(ClassName)(%2(object)):\n\t""" %3(Docstring for class %1) """\n\tdef __init__(self%4):\n\t\t%5(pass)'
  9.     snippets['def'] = 'def %1(function)(%2(args)):\n\t%3(pass)'
  10.     snippets['defd'] = 'def %1(function)(%2(args)):\n\t""" %3(Docstring for function %1) """\n\t%4(pass)'
  11.     snippets['defs'] = 'def %1(method)(self,%2):\n\t%3(pass)'
  12.     snippets['defsd'] = 'def %1(method)(self,%2):""" %3(Docstring for method %1) """\n\t%4(pass)'
  13.     snippets['elif'] = 'elif %1(condition):\n\t%2(pass)'
  14.     snippets['for'] = 'for %1(item) in %2(iterable):\n\t%3(pass)'
  15.     snippets['from'] = 'from %1(sys) import %2(*)'
  16.     snippets['if'] = 'if %1(condition):\n\t%2(pass)'
  17.     snippets['ife'] = 'if %1(condition):\n\t%2(pass)\nelse:\n\t%3(pass)'
  18.     snippets['ifee'] = 'if %1(condition):\n\t%2(pass)\nelif %3(condition):\n\t%4(pass)\nelse:\n\t%5(pass)'
  19.     snippets['ifmain'] = 'if __name__ == \'__main__\':\n\t%3(main())'
  20.     snippets['join'] = 'str.join(%1(", "), %2(iterable))'
  21.     snippets['prt'] = 'print(%1)'
  22.     snippets['prts'] = 'print("%1")'
  23.     snippets['try'] = 'try:\n\t%1(pass)\nexcept %2(Exception) as %3(e):\n\t%4(pass)'
  24.     snippets['tryee'] = 'try:\n\t%1(pass)\nexcept %2(Exception) as %3(e):\n\t%4(pass)\nelse:\n\t%5(pass)'
  25.     snippets['tryeef'] = 'try:\n\t%1(pass)\nexcept %2(Exception) as %3(e):\n\t%4(pass)\nelse:\n\t%5(pass)\nfinally:\n\t%6(pass)'
  26.     snippets['tryef'] = 'try:\n\t%1(pass)\nexcept %2(Exception) as %3(e):\n\t%4(pass)\nfinally:\n\t%5(pass)'
  27.     snippets['while'] = 'while %1(condition):\n\t%2(pass)'
  28.     snippets['with'] = 'with %1(exp) as %2(target):\n\t%3(pass)'
  29.     -- unit testing
  30.     snippets['aae'] = 'self.assertAlmostEqual(%1(first), %2(second))'
  31.     snippets['ae'] = 'self.assertEqual(%1(first), %2(second))'
  32.     snippets['af'] = 'self.assertFalse(%1(exp))'
  33.     snippets['an'] = 'self.assertIsNone(%1(exp))'
  34.     snippets['ann'] = 'self.assertIsNotNone(%1(exp))'
  35.     snippets['at'] = 'self.assertTrue(%1(exp))'
  36.     snippets['clt'] = 'class Test%1(Class)(%2(unittest.TestCase)):\n\t""" %3(Docstring for testclass) """\n\tdef setUp(self):\n\t\t%4(pass)\n\n\tdef tearDown(self):\n\t\t%5(pass)\n\n\tdef test_%6(name)(self):\n\t\t%7(pass)'
  37.     snippets['tst'] = 'def test_%1(name)(self):\n\t\t%2(pass)'
  38.   elseif lang == 'ruby' then
  39.     buffer.tab_width = 2
  40.     snippets['#!'] = '#!/usr/bin/env ruby\n%0'
  41.     snippets['Do'] = 'do\n\t%1(# TODO)\nend'
  42.     snippets['For'] = '(%1(from)..%2(to)).each { |%3(i)| %4(# TODO) }'
  43.     snippets['If'] = '%1(command) if %2(exp)'
  44.     snippets['Unl'] = '%1(command) unless %2(exp)'
  45.     snippets['Until'] = 'begin\n\t%1(# TODO)\nend until %2(exp)'
  46.     snippets['While'] = 'begin\n\t%1(# TODO)\nend while %2(exp)'
  47.     snippets['bre'] = 'begin\n\t%1(# TODO)\nrescue %2(Exception)%3( => e)\n\t%4(# TODO)\nend'
  48.     snippets['cas'] = 'case %1(object)\nwhen %2(condition)\n\t%3(# TODO)\nend'
  49.     snippets['class'] = 'class %1(ClassName)\n\tdef initialize(%2(args))\n\t\t%3(# TODO)\n\tend\nend'
  50.     snippets['def'] = 'def %1(function)(%2(args))\n\t%3(# TODO)\nend'
  51.     snippets['do'] = 'do |%1(var)|\n\t%2(# TODO)\nend'
  52.     snippets['elsif'] = 'elsif %1(condition)\n\t%2(# TODO)'
  53.     snippets['for'] = '(%1(from)..%2(to)).each do |%3(i)|\n\t%4(# TODO)\nend'
  54.     snippets['if'] = 'if %1(condition)\n\t%2(# TODO)\nend'
  55.     snippets['ife'] = 'if %1(condition)\n\t%2(# TODO)\nelse\n\t%3(# TODO)\nend'
  56.     snippets['ifee'] = 'if %1(condition)\n\t%2(# TODO)\nelsif %3(condition)\n\t%4(# TODO)\nelse\n\t%5(# TODO)\nend'
  57.     snippets['unl'] = 'unless %1(condition)\n\t%2(# TODO)\nend'
  58.     snippets['unle'] = 'unless %1(condition)\n\t%2(# TODO)\nelse\n\t%3(# TODO)\nend'
  59.     snippets['unlee'] = 'unless %1(condition)\n\t%2(# TODO)\nelsif %3(condition)\n\t%4(# TODO)\nelse\n\t%5(# TODO)\nend'
  60.     snippets['until'] = 'until %1(condition)\n\t%2(# TODO)\nend'
  61.     snippets['when'] = 'when %1(condition)\n\t%2(# TODO)'
  62.     snippets['while'] = 'while %1(condition)\n\t%2(# TODO)\nend'
  63.     -- attribute access
  64.     snippets['r'] = 'attr_reader :%1(attr_names)'
  65.     snippets['w'] = 'attr_writer :%1(attr_names)'
  66.     snippets['rw'] = 'attr_accessor :%1(attr_names)'
  67.   else
  68.     buffer.tab_width = 2
  69.   end
  70. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement