Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sublime, sublime_plugin, os, re, string
- from os.path import basename
- class pasfunc_GiveVerboseFunc(sublime_plugin.EventListener):
- def on_post_save(self, view):
- funcs = []
- ids = []
- open_folder_arr = view.window().views()
- for pasfile in open_folder_arr:
- tex = pasfile.file_name().lower()
- if tex.find(".pas") != -1:
- file_lines = open(tex, "rU")
- isimp = False
- for line in file_lines:
- templine = line.lower()
- if not isimp:
- isimp = (templine.find("implementation") > -1)
- continue
- if (((templine.find("function") != -1) \
- or (templine.find("procedure") != -1) \
- or (templine.find("constructor") != -1) \
- or (templine.find("destructor") != -1)) \
- and ((templine.find("=") == -1) \
- and (templine.find("forward") == -1))):
- funcs.append(os.path.split(pasfile.file_name())[1] + ": " + line.strip())
- words = re.findall('[_A-Za-z][_a-zA-Z0-9]*', line)
- fn = os.path.split(pasfile.file_name())[1]
- for word in words:
- if (len(word) >= 3):
- if not word in funcs:
- w = word.strip()
- if not w in ids:
- ids.append(w)
- #w = fn + ": " + word.strip()
- #if not w in funcs:
- # if not w in ids:
- # ids.append(w)
- #if (len(word) >= 3) and not (word in funcs) and not (word in ids):
- #ids.append(os.path.split(pasfile.file_name())[1] + ": " + word.strip())
- try:
- from win32com.shell import shellcon, shell
- homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
- except ImportError: # quick semi-nasty fallback for non-windows/win32com case
- homedir = os.path.expanduser("~")
- sugfile = homedir + "\\AppData\\Roaming\\Sublime Text 3\\Packages\\User\\" + \
- "Pascal.sublime-completions"
- f = open(sugfile, "w")
- f.writelines("{\n")
- f.writelines(' "scope": "source.pascal",\n')
- f.writelines(' "completions":\n [\n')
- for func in funcs:
- f.writelines(' { "trigger": "')
- index = 0
- for word in func.split():
- if index == 1:
- f.writelines(word[0:1] + ' ')
- else:
- f.writelines(word + ' ')
- index = index + 1
- f.writelines('", "contents": "')
- if len(func.split('.')) > 2: #Если в списке больше двух частей
- f.writelines(func.split('.')[2][0:len(func)])
- else:
- for i in range(2, 100):
- try:
- f.writelines(func.split()[i][0:1000] + ' ')
- except IndexError:
- break
- # f.writelines(func.split()[2][0:len(func)])
- f.writelines('" },\n')
- for i in ids:
- f.writelines(' { "trigger": "')
- index = 0
- f.writelines(i)
- f.writelines('", "contents": "')
- f.writelines(i)
- f.writelines('" },\n')
- f.writelines(' ]\n}')
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement