Skip to content

Commit 64cafbe

Browse files
committed
Code cleanup
1 parent 5a34c00 commit 64cafbe

File tree

2 files changed

+2
-102
lines changed

2 files changed

+2
-102
lines changed

pymode/run.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def run_code():
3333
# A false code will be treated as a
3434
# successful run, and the error will be hidden from Vim
3535
env.error("Script exited with code %s" % e.code)
36-
env.stop()
36+
return env.stop()
3737

3838
except Exception:
3939
import traceback
@@ -43,13 +43,9 @@ def run_code():
4343
err = sys.stderr.getvalue()
4444

4545
output = sys.stdout.getvalue().strip()
46+
output = env.prepare_value(output)
4647
sys.stdout, sys.stderr = stdout_, stderr_
4748

48-
try:
49-
output = output.decode('utf-8').encode(env.options.get('encoding'))
50-
except AttributeError:
51-
pass
52-
5349
errors += [er for er in err.splitlines() if er and "<string>" not in er]
5450

5551
env.let('l:traceback', errors[2:])

pymode/utils.py

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
""" Pymode utils. """
2-
import json
32
import os.path
43
import sys
54
import threading
@@ -18,92 +17,6 @@
1817
PY2 = sys.version_info[0] == 2
1918

2019

21-
def pymode_message(content):
22-
""" Show message. """
23-
24-
vim.command('call pymode#wide_message("%s")' % str(content))
25-
26-
27-
def pymode_confirm(yes=True, msg='Do the changes:'):
28-
""" Confirmation.
29-
30-
:return bool:
31-
32-
"""
33-
default = 'yes' if yes else 'no'
34-
action = pymode_input(msg, default)
35-
return action and 'yes'.startswith(action)
36-
37-
38-
def pymode_inputlist(msg, opts):
39-
""" Get user choice.
40-
41-
:return str: A choosen option
42-
43-
"""
44-
choices = ['[Pymode] %s' % msg]
45-
choices += ["%s. %s" % (num, opt) for num, opt in enumerate(opts, 1)]
46-
try:
47-
input_str = int(vim.eval('inputlist(%s)' % json.dumps(choices)))
48-
except (KeyboardInterrupt, ValueError):
49-
input_str = 0
50-
51-
if not input_str:
52-
pymode_message('Cancelled!')
53-
return False
54-
55-
try:
56-
return opts[input_str - 1]
57-
except (IndexError, ValueError):
58-
pymode_error('Invalid option: %s' % input_str)
59-
return pymode_inputlist(msg, opts)
60-
61-
62-
def pymode_input(umsg, udefault='', opts=None):
63-
""" Get user input.
64-
65-
:return str: A user input
66-
67-
"""
68-
msg = '[Pymode] %s ' % umsg
69-
default = udefault
70-
71-
if default != '':
72-
msg += '[%s] ' % default
73-
74-
try:
75-
vim.command('echohl Debug')
76-
input_str = vim.eval('input("%s> ")' % msg)
77-
vim.command('echohl none')
78-
except KeyboardInterrupt:
79-
input_str = ''
80-
81-
return input_str or default
82-
83-
84-
def pymode_error(content):
85-
""" Show error. """
86-
87-
vim.command('call pymode#error("%s")' % str(content))
88-
89-
90-
def catch_and_print_exceptions(func):
91-
""" Catch any exception.
92-
93-
:return func:
94-
95-
"""
96-
def wrapper(*args, **kwargs):
97-
try:
98-
return func(*args, **kwargs)
99-
except (Exception, vim.error) as e: # noqa
100-
if DEBUG:
101-
raise
102-
pymode_error(e)
103-
return None
104-
return wrapper
105-
106-
10720
@contextmanager
10821
def silence_stderr():
10922
""" Redirect stderr. """
@@ -127,12 +40,3 @@ def patch_paths():
12740
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'libs2'))
12841
else:
12942
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'libs3'))
130-
131-
132-
debug = lambda _: None
133-
134-
if DEBUG:
135-
def debug(msg): # noqa
136-
""" Debug message. """
137-
138-
print(msg)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy