Created
May 15, 2014 11:33
-
-
Save valexey/6ef7362eba0e22cc7b95 to your computer and use it in GitHub Desktop.
Oberon plugon for sublime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin | |
class OberonAssistant(sublime_plugin.EventListener): | |
rs = {} | |
inProcess = False | |
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 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=="(" 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: | |
self.inProcess = True | |
edit = view.begin_edit("smartCaps","1") | |
view.replace(edit, view.word(sublime.Region(curr.a-shift,curr.a-shift)), word.upper()) | |
view.end_edit(edit) | |
#view.run_command("select_all") | |
#view.run_command("insert",{"characters":"hello"}) | |
self.inProcess = False | |
else: | |
self.rs = view.sel() | |
def on_selection_modified(self,view): | |
self.rs = view.sel() | |
curr = self.rs[0] | |
sublime.status_message(view.scope_name(curr.a)) | |
class OberonCapsCommand(sublime_plugin.TextCommand): | |
def run(self, edit, args): | |
edit = self.view.begin_edit("test",args) | |
view.insert(edit, 1, "hello") | |
view.end_edit(edit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment