OberonAssistant.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import sublime, sublime_plugin
  2. class OberonCommand(sublime_plugin.TextCommand):
  3. def run(self, edit, start, end, word):
  4. self.view.replace(edit, self.view.word(sublime.Region(start, end)), word.upper())
  5. class OberonAssistant(sublime_plugin.EventListener):
  6. rs = {}
  7. inProcess = False
  8. keywords = ['ARRAY', 'IMPORT', 'THEN', 'BEGIN', 'IN', 'TO', 'BY', 'IS', 'TRUE', 'CASE', 'MOD', 'TYPE', 'CONST', 'MODULE', 'UNTIL', 'DIV', 'NIL', 'VAR', 'DO', 'OF', 'WHILE', 'ELSE', 'OR', 'ELSIF', 'POINTER', 'END', 'PROCEDURE', 'FALSE', 'RECORD', 'FOR', 'REPEAT', 'IF', 'RETURN', 'ABS', 'ASR', 'ASSERT', 'BOOLEAN', 'BYTE', 'CHAR', 'CHR', 'DEC', 'EXCL', 'FLOOR', 'FLT', 'INC', 'INCL', 'INTEGER', 'LEN', 'LSL', 'NEW', 'ODD', 'ORD', 'PACK', 'REAL', 'ROR', 'SELF', 'SET', 'STRING', 'SUPER', 'UNPK']
  9. def on_modified(self,view):
  10. if len(view.sel())==1 and not self.inProcess:
  11. if self.rs != {}:
  12. self.rs = view.sel()
  13. curr = self.rs[0]
  14. scope = view.scope_name(curr.a)
  15. if not "oberon" in scope or "string" in scope or "comment" in scope:
  16. return
  17. ch = view.substr(sublime.Region(curr.a-1,curr.a))
  18. if ch==" " or ch=="\n" or ch==";" or ch=="(" or ch==")" :
  19. word = view.substr(view.word(sublime.Region(curr.a-1,curr.a-1)))
  20. shift = 1
  21. if ")" in word :
  22. word = view.substr(view.word(sublime.Region(curr.a-2,curr.a-2)))
  23. sublime.status_message(word)
  24. shift = 2
  25. if word.upper() in self.keywords:
  26. self.inProcess = True
  27. view.run_command('oberon', {'start': curr.a-shift, 'end': curr.a-shift, 'word': word})
  28. self.inProcess = False
  29. else:
  30. self.rs = view.sel()
  31. def on_selection_modified(self,view):
  32. self.rs = view.sel()
  33. curr = self.rs[0]
  34. #sublime.status_message(view.scope_name(curr.a))