Skip to content

Commit dc38a7d

Browse files
committed
clean space
1 parent a48bc2d commit dc38a7d

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

Custominsert.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -20,86 +20,86 @@ def get_local_ip():
2020

2121
class CustominsertCommand(sublime_plugin.TextCommand):
2222

23-
def get_settings_param(self,chains=[],default=''):
23+
def get_settings_param(self,chains = [],default = ''):
2424
'''get params in dict chains'''
25-
obj=self.settings
25+
obj = self.settings
2626
for e in chains:
27-
obj=obj.get(e)
27+
obj = obj.get(e)
2828
if not obj:
2929
return default
3030
return obj
3131

3232
def get_predefined_param(self,match):
3333
'''{%%}'''
34-
key=match.group(1)
35-
if key=='filename':
34+
key = match.group(1)
35+
if key == 'filename':
3636
return os.path.basename(self.view.file_name() or '')
37-
elif key=='filepath':
37+
elif key == 'filepath':
3838
return self.view.file_name() or ''
39-
elif key=='dirname':
39+
elif key == 'dirname':
4040
return os.path.dirname(self.view.file_name() or '')
41-
elif key=='platform':
41+
elif key == 'platform':
4242
return sublime.platform()
43-
elif key=='arch':
43+
elif key == 'arch':
4444
return sublime.arch()
45-
elif key=='encoding':
45+
elif key == 'encoding':
4646
encoding = self.view.encoding()
4747
return encoding if 'Undefined' != encoding else self.settings.get('default_encoding')
48-
elif key=='ip':
48+
elif key == 'ip':
4949
return get_local_ip()
50-
ipaddrlist=socket.gethostbyname_ex(socket.gethostname())
51-
ips=''
50+
ipaddrlist = socket.gethostbyname_ex(socket.gethostname())
51+
ips = ''
5252
for e in ipaddrlist:
5353
if isinstance(e,list):
5454
for k in e:
55-
ips+=" "+k
55+
ips += " "+k
5656
else:
57-
ips+=e
57+
ips += e
5858
return ips
59-
elif key=='user':
60-
user=os.getlogin() if 'windows' != sublime.platform() else ''
59+
elif key == 'user':
60+
user = os.getlogin() if 'windows' != sublime.platform() else ''
6161
if user:
6262
return user
6363
#windows?
64-
user=os.popen('whoami').read()
65-
p=re.compile('[\r\n]',re.M)
64+
user = os.popen('whoami').read()
65+
p = re.compile('[\r\n]',re.M)
6666
return re.sub(p,'',user)
67-
elif key=='ext':
68-
ext=os.path.splitext(self.view.file_name() or '')[1]
67+
elif key == 'ext':
68+
ext = os.path.splitext(self.view.file_name() or '')[1]
6969
#remove . at start position
70-
p=re.compile('^\.')
70+
p = re.compile('^\.')
7171
return re.sub(p,'',ext)
72-
elif key=='datetime':
73-
t=datetime.datetime.today()
72+
elif key == 'datetime':
73+
t = datetime.datetime.today()
7474
return t.strftime(self.get_action_param('datetime_format','%Y-%m-%d %H:%M:%S'))
7575
return match.group(1)
7676

7777
def get_defined_param(self,match):
7878
'''{{}} '''
79-
key=match.group(1)
79+
key = match.group(1)
8080
return self.get_settings_param(['actions',self.action,'data',key],self.get_settings_param(['data',key]))
8181

82-
def get_action_param(self,key,default=''):
82+
def get_action_param(self,key,default = ''):
8383
'''get params of actions'''
8484
return self.get_settings_param(['actions',self.action,key],self.get_settings_param([key]))
8585

86-
def run(self, edit,action=''):
87-
v=self.view
86+
def run(self, edit,action = ''):
87+
v = self.view
8888
settings_name = 'Custominsert'
8989
settings =sublime.load_settings(settings_name + '.sublime-settings') or {}
9090
#save settings
91-
self.settings=settings
91+
self.settings = settings
9292
#save action
93-
self.action=action;
94-
content=self.get_action_param('content')
93+
self.action = action;
94+
content = self.get_action_param('content')
9595
#replace {%%}
96-
p=re.compile('\{%\s*?([\w]+)\s*?%\}',re.LOCALE|re.MULTILINE)
97-
content=re.sub(p,self.get_predefined_param,content)
96+
p = re.compile('\{%\s*?([\w]+)\s*?%\}',re.LOCALE|re.MULTILINE)
97+
content = re.sub(p,self.get_predefined_param,content)
9898
#replace {{}}
99-
p=re.compile('\{\{\s*?([\w]+)\s*?\}\}',re.LOCALE|re.MULTILINE)
100-
content=re.sub(p,self.get_defined_param,content)
99+
p = re.compile('\{\{\s*?([\w]+)\s*?\}\}',re.LOCALE|re.MULTILINE)
100+
content = re.sub(p,self.get_defined_param,content)
101101
#insert position
102-
if 'start'==self.get_action_param('position'):
102+
if 'start' == self.get_action_param('position'):
103103
v.insert(edit, 0, content)
104104
else:
105105
for sel in v.sel():

0 commit comments

Comments
 (0)