|
1
|
|
|
# coding=utf-8 |
|
2
|
|
|
import sublime |
|
3
|
|
|
import sublime_plugin |
|
4
|
|
|
import re |
|
5
|
|
|
|
|
6
|
|
|
class QuickGotoCommand(sublime_plugin.TextCommand): |
|
7
|
|
|
def doCommand(self, edit, prifix, reg, show_files = True): |
|
8
|
|
|
for sel in self.view.sel(): |
|
9
|
|
|
if sel.empty(): |
|
10
|
|
|
sel = self.view.word(sel) |
|
11
|
|
|
word_sel = self.view.substr(sel) |
|
12
|
|
|
word_sel = word_sel.strip() |
|
13
|
|
|
|
|
14
|
|
|
# delete prefix and suffix |
|
15
|
|
|
settings = sublime.load_settings('QuickGotoAnything.sublime-settings') |
|
16
|
|
|
del_prefix = settings.get('del_prefix') |
|
17
|
|
|
del_suffix = settings.get('del_suffix') |
|
18
|
|
|
if del_prefix and word_sel[0:len(del_prefix)] == del_prefix: |
|
19
|
|
|
word_sel = word_sel[len(del_prefix):len(word_sel)] |
|
20
|
|
|
if del_suffix and word_sel[-len(del_suffix):len(word_sel)] == del_suffix: |
|
21
|
|
|
word_sel = word_sel[0:-len(del_suffix)] |
|
22
|
|
|
|
|
23
|
|
|
if not re.match(reg, word_sel): |
|
24
|
|
|
word_sel = '' |
|
25
|
|
|
self.view.window().run_command("show_overlay", {"overlay": "goto", "show_files": show_files, "text": prifix+word_sel}) |
|
26
|
|
|
|
|
27
|
|
|
class QuickGotoFunctionCommand(QuickGotoCommand): |
|
28
|
|
|
def run(self, edit): |
|
29
|
|
|
self.doCommand(edit, '@', '^[a-zA-Z_]+[a-zA-Z0-9_]*$') |
|
30
|
|
|
|
|
31
|
|
|
class QuickGotoVariableCommand(QuickGotoCommand): |
|
32
|
|
|
def run(self, edit): |
|
33
|
|
|
self.doCommand(edit, '#', '^[a-zA-Z_]+[a-zA-Z0-9_]*$') |
|
34
|
|
|
|
|
35
|
|
|
class QuickGotoFileCommand(QuickGotoCommand): |
|
36
|
|
|
def run(self, edit, show_files = True): |
|
37
|
|
|
# space to '~' and not ':*?"<>|' |
|
38
|
|
|
self.doCommand(edit, '', '^[ !#-)+-9;=@-{}~]+$', show_files) |
|
39
|
|
|
|
|
40
|
|
|
|