Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. # coding: utf-8
  2. # author: Cody Kochmann
  3. # date: Sat 06 Feb 2016 09:30:29 AM EST
  4. # description: interactively make sublime text completitions
  5.  
  6. """ sample json for .sublime-completions file
  7. {
  8. "scope": "text.html - source - meta.tag, punctuation.definition.tag.begin",
  9.  
  10. "completions":
  11. [
  12. { "trigger": "a", "contents": "<a href=\"$1\">$0</a>" },
  13. { "trigger": "abbr", "contents": "<abbr>$0</abbr>" },
  14. { "trigger": "acronym", "contents": "<acronym>$0</acronym>" },
  15.  
  16. "ninja",
  17. "robot",
  18. "pizza"
  19. ]
  20. }
  21. """
  22.  
  23. global autocomplete_dictionary
  24. autocomplete_dictionary=[]
  25.  
  26. class Autocomplete_Dictionary:
  27. def __init__(self, save_path=''):
  28. self.completition
  29.  
  30.  
  31. import json
  32.  
  33. class Completion:
  34. def __init__(self, scope='', contents='', trigger=''):
  35. self.data={}
  36. self.data['scope']=scope
  37. self.data['completions'] = []
  38.  
  39. if trigger != '':
  40. completion_data={}
  41. completion_data['trigger']=trigger
  42. completion_data['contents']=contents
  43. self.data['completions'].append(completion_data)
  44. else:
  45. self.data['completions'].append(contents)
  46.  
  47. self.to_string=(json.dumps(self.data))
  48.  
  49.  
  50. def remove_all(substring='',target=''):
  51. if substring in target:
  52. target = ''.join(target.split(substring))
  53. return target
  54.  
  55.  
  56.  
  57. def append_to_file(s='',path=''):
  58. with open(path,'a') as f:
  59. f.write(s+'\n')
  60.  
  61. def write_to_file(s='',path=''):
  62. with open(path,'w') as f:
  63. f.write(s)
  64.  
  65. def read_file(path=''):
  66. with open(path,'r') as f:
  67. return f.read()
  68.  
  69. def random_hash(length=256):
  70. import random
  71. return random.getrandbits(length)
  72.  
  73. file_name='sublime-completions/'+str(random_hash())+'.sublime-completions'
  74.  
  75. contents=raw_input('enter the completition ( one line ): ')
  76. trigger=raw_input('enter the trigger ( leave blank if none ): ')
  77. scope=raw_input('enter the scope ( example: py ): ')
  78. snippet = Completion(scope,contents,trigger)
  79.  
  80. write_to_file(snippet.to_string, file_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement