فهرست منبع

Update OberonAssistant.py

Added exception for comments and string literals.
Also added special case for ")" in function declaration.
valexey 11 سال پیش
والد
کامیت
e8f3640428
1فایلهای تغییر یافته به همراه13 افزوده شده و 5 حذف شده
  1. 13 5
      OberonAssistant.py

+ 13 - 5
OberonAssistant.py

@@ -7,18 +7,24 @@ class OberonAssistant(sublime_plugin.EventListener):
 	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', 'SET', 'UNPK']
 
 	def on_modified(self,view):
-		if view.settings().get('syntax') != "Packages/Oberon/Oberon.tmLanguage":
-			return
 		if len(view.sel())==1 and not self.inProcess:
 			if self.rs != {}:
 				self.rs = view.sel()
 				curr = self.rs[0]
+				scope = view.scope_name(curr.a)
+				if not "oberon" in scope or "string" in scope or "comment" in scope:
+					return
 				ch = view.substr(sublime.Region(curr.a-1,curr.a))
-				if ch==" " or ch=="\n" or ch==";" or ch=="(" :
-					word = view.substr(view.word(sublime.Region(curr.a-1,curr.a-1)))					
+				if ch==" " or ch=="\n" or ch==";" or ch=="(" or ch==")" :
+					word = view.substr(view.word(sublime.Region(curr.a-1,curr.a-1)))
+					shift = 1
+					if ")" in word :
+						word = view.substr(view.word(sublime.Region(curr.a-2,curr.a-2)))
+						sublime.status_message(word)
+						shift = 2					
 					if word.upper() in self.keywords:
 						edit = view.begin_edit()
-						view.replace(edit, view.word(sublime.Region(curr.a-1,curr.a-1)), word.upper())
+						view.replace(edit, view.word(sublime.Region(curr.a-shift,curr.a-shift)), word.upper())
 						self.inProcess = True
 						view.end_edit(edit)
 						self.inProcess = False
@@ -27,4 +33,6 @@ class OberonAssistant(sublime_plugin.EventListener):
 
 	def on_selection_modified(self,view):
 			self.rs = view.sel()
+			curr = self.rs[0]
+			sublime.status_message(view.scope_name(curr.a))