OberonAssistant.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import sublime, sublime_plugin
  2. class OberonAssistant(sublime_plugin.EventListener):
  3. rs = {}
  4. inProcess = False
  5. 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']
  6. def on_modified(self,view):
  7. if len(view.sel())==1 and not self.inProcess:
  8. if self.rs != {}:
  9. self.rs = view.sel()
  10. curr = self.rs[0]
  11. scope = view.scope_name(curr.a)
  12. if not "oberon" in scope or "string" in scope or "comment" in scope:
  13. return
  14. ch = view.substr(sublime.Region(curr.a-1,curr.a))
  15. if ch==" " or ch=="\n" or ch==";" or ch=="(" or ch==")" :
  16. word = view.substr(view.word(sublime.Region(curr.a-1,curr.a-1)))
  17. shift = 1
  18. if ")" in word :
  19. word = view.substr(view.word(sublime.Region(curr.a-2,curr.a-2)))
  20. sublime.status_message(word)
  21. shift = 2
  22. if word.upper() in self.keywords:
  23. edit = view.begin_edit()
  24. view.replace(edit, view.word(sublime.Region(curr.a-shift,curr.a-shift)), word.upper())
  25. self.inProcess = True
  26. view.end_edit(edit)
  27. self.inProcess = False
  28. else:
  29. self.rs = view.sel()
  30. def on_selection_modified(self,view):
  31. self.rs = view.sel()
  32. curr = self.rs[0]
  33. #sublime.status_message(view.scope_name(curr.a))