Skip to content

Commit

Permalink
Revert "improved code to fix issue spyder-ide#6379"
Browse files Browse the repository at this point in the history
This reverts commit 3206df3.
  • Loading branch information
chengtian5huang committed Feb 9, 2018
1 parent 1f836aa commit 488187e
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions spyder/plugins/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1860,22 +1860,13 @@ def _clone_file_everywhere(self, finfo):
for editorstack in self.editorstacks[1:]:
editor = editorstack.clone_editor_from(finfo, set_current=False)
self.register_widget_shortcuts(editor)

def _replace_tripe_quote(self, m, v=None):
try:
ans = m[0] % v
except:
ans = m[0]
return ans
else:
return ans

@Slot()
@Slot(str)
def new(self, fname=None, editorstack=None, text=None):
"""
Create a new file - Untitled
fname=None --> fname will be 'untitledXX.py' but do not create file
fname=<basestring> --> create file
"""
Expand All @@ -1884,6 +1875,7 @@ def new(self, fname=None, editorstack=None, text=None):
default_content = True
text, enc = encoding.read(self.TEMPLATE_PATH)
enc_match = re.search('-*- coding: ?([a-z0-9A-Z\-]*) -*-', text)
annotation_match = re.search('"""(?:(?!""").|[\n\r])*"""', text)
if enc_match:
enc = enc_match.group(1)
# Initialize template variables
Expand All @@ -1895,18 +1887,17 @@ def new(self, fname=None, editorstack=None, text=None):
username = encoding.to_unicode_from_fs(os.environ.get('USER',
'-'))
VARS = {
'date-spyder': time.ctime(),
'username-spyder': username,
'date': time.strftime("%Y-%m-%d %H:%M"),
'username': username,
}
try:
text = text % VARS
#text = text % VARS
text = re.sub('"""(?:(?!""").|[\n\r])*"""',
annotation_match[0] % VARS,
text,
count=1)
except:
from functools import partial
replace = partial(self._replace_tripe_quote, v=VARS)
pat = '"""(?:(?!""").|[\n\r])*"""'
text = re.sub(pat,
replace,
text)
pass
else:
default_content = False
enc = encoding.read(self.TEMPLATE_PATH)[1]
Expand Down

0 comments on commit 488187e

Please sign in to comment.