mirror of
https://github.com/sstent/sublime-text-3.git
synced 2026-01-26 07:01:47 +00:00
backing up sublime settings
This commit is contained in:
38
Packages/SublimeREPL/config/Python/Default.sublime-commands
Normal file
38
Packages/SublimeREPL/config/Python/Default.sublime-commands
Normal file
@@ -0,0 +1,38 @@
|
||||
[
|
||||
{
|
||||
"caption": "SublimeREPL: Python",
|
||||
"command": "run_existing_window_command", "args":
|
||||
{
|
||||
"id": "repl_python",
|
||||
"file": "config/Python/Main.sublime-menu"
|
||||
}
|
||||
},
|
||||
{
|
||||
"caption": "SublimeREPL: Python - PDB current file",
|
||||
"command": "run_existing_window_command", "args":
|
||||
{
|
||||
"id": "repl_python_pdb",
|
||||
"file": "config/Python/Main.sublime-menu"
|
||||
}
|
||||
},
|
||||
{
|
||||
"caption": "SublimeREPL: Python - RUN current file",
|
||||
"command": "run_existing_window_command", "args":
|
||||
{
|
||||
"id": "repl_python_run",
|
||||
"file": "config/Python/Main.sublime-menu"
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "python_virtualenv_repl",
|
||||
"caption": "SublimeREPL: Python - virtualenv"
|
||||
},
|
||||
{
|
||||
"caption": "SublimeREPL: Python - IPython",
|
||||
"command": "run_existing_window_command", "args":
|
||||
{
|
||||
"id": "repl_python_ipython",
|
||||
"file": "config/Python/Main.sublime-menu"
|
||||
}
|
||||
}
|
||||
]
|
||||
86
Packages/SublimeREPL/config/Python/Main.sublime-menu
Normal file
86
Packages/SublimeREPL/config/Python/Main.sublime-menu
Normal file
@@ -0,0 +1,86 @@
|
||||
[
|
||||
{
|
||||
"id": "tools",
|
||||
"children":
|
||||
[{
|
||||
"caption": "SublimeREPL",
|
||||
"mnemonic": "r",
|
||||
"id": "SublimeREPL",
|
||||
"children":
|
||||
[
|
||||
{"caption": "Python",
|
||||
"id": "Python",
|
||||
|
||||
"children":[
|
||||
{"command": "repl_open",
|
||||
"caption": "Python",
|
||||
"id": "repl_python",
|
||||
"mnemonic": "p",
|
||||
"args": {
|
||||
"type": "subprocess",
|
||||
"encoding": "utf8",
|
||||
"cmd": ["python", "-i", "-u"],
|
||||
"cwd": "$file_path",
|
||||
"syntax": "Packages/Python/Python.tmLanguage",
|
||||
"external_id": "python",
|
||||
"extend_env": {"PYTHONIOENCODING": "utf-8"}
|
||||
}
|
||||
},
|
||||
{"command": "python_virtualenv_repl",
|
||||
"id": "python_virtualenv_repl",
|
||||
"caption": "Python - virtualenv"},
|
||||
{"command": "repl_open",
|
||||
"caption": "Python - PDB current file",
|
||||
"id": "repl_python_pdb",
|
||||
"mnemonic": "d",
|
||||
"args": {
|
||||
"type": "subprocess",
|
||||
"encoding": "utf8",
|
||||
"cmd": ["python", "-i", "-u", "-m", "pdb", "$file_basename"],
|
||||
"cwd": "$file_path",
|
||||
"syntax": "Packages/Python/Python.tmLanguage",
|
||||
"external_id": "python",
|
||||
"extend_env": {"PYTHONIOENCODING": "utf-8"}
|
||||
}
|
||||
},
|
||||
{"command": "repl_open",
|
||||
"caption": "Python - RUN current file",
|
||||
"id": "repl_python_run",
|
||||
"mnemonic": "d",
|
||||
"args": {
|
||||
"type": "subprocess",
|
||||
"encoding": "utf8",
|
||||
"cmd": ["python", "-u", "$file_basename"],
|
||||
"cwd": "$file_path",
|
||||
"syntax": "Packages/Python/Python.tmLanguage",
|
||||
"external_id": "python",
|
||||
"extend_env": {"PYTHONIOENCODING": "utf-8"}
|
||||
}
|
||||
},
|
||||
{"command": "repl_open",
|
||||
"caption": "Python - IPython",
|
||||
"id": "repl_python_ipython",
|
||||
"mnemonic": "p",
|
||||
"args": {
|
||||
"type": "subprocess",
|
||||
"encoding": "utf8",
|
||||
"autocomplete_server": true,
|
||||
"cmd": {
|
||||
"osx": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
|
||||
"linux": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
|
||||
"windows": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
|
||||
},
|
||||
"cwd": "$file_path",
|
||||
"syntax": "Packages/Python/Python.tmLanguage",
|
||||
"external_id": "python",
|
||||
"extend_env": {
|
||||
"PYTHONIOENCODING": "utf-8",
|
||||
"SUBLIMEREPL_EDITOR": "$editor"
|
||||
}
|
||||
}
|
||||
}
|
||||
]}
|
||||
]
|
||||
}]
|
||||
}
|
||||
]
|
||||
118
Packages/SublimeREPL/config/Python/ipy_repl.py
Normal file
118
Packages/SublimeREPL/config/Python/ipy_repl.py
Normal file
@@ -0,0 +1,118 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import socket
|
||||
import threading
|
||||
|
||||
activate_this = os.environ.get("SUBLIMEREPL_ACTIVATE_THIS", None)
|
||||
|
||||
# turn off pager
|
||||
os.environ['TERM'] = 'emacs'
|
||||
|
||||
if activate_this:
|
||||
with open(activate_this, "r") as f:
|
||||
exec(f.read(), {"__file__": activate_this})
|
||||
|
||||
try:
|
||||
import IPython
|
||||
IPYTHON = True
|
||||
except ImportError:
|
||||
IPYTHON = False
|
||||
|
||||
if not IPYTHON:
|
||||
# for virtualenvs w/o IPython
|
||||
import code
|
||||
code.InteractiveConsole().interact()
|
||||
|
||||
from IPython.config.loader import Config
|
||||
|
||||
editor = "subl -w"
|
||||
|
||||
cfg = Config()
|
||||
cfg.InteractiveShell.use_readline = False
|
||||
cfg.InteractiveShell.autoindent = False
|
||||
cfg.InteractiveShell.colors = "NoColor"
|
||||
cfg.InteractiveShell.editor = os.environ.get("SUBLIMEREPL_EDITOR", editor)
|
||||
|
||||
try:
|
||||
# IPython 1.0.0
|
||||
from IPython.terminal.console.app import ZMQTerminalIPythonApp
|
||||
|
||||
def kernel_client(zmq_shell):
|
||||
return zmq_shell.kernel_client
|
||||
except ImportError:
|
||||
# Older IPythons
|
||||
from IPython.frontend.terminal.console.app import ZMQTerminalIPythonApp
|
||||
|
||||
def kernel_client(zmq_shell):
|
||||
return zmq_shell.kernel_manager
|
||||
|
||||
|
||||
embedded_shell = ZMQTerminalIPythonApp(config=cfg, user_ns={})
|
||||
embedded_shell.initialize()
|
||||
|
||||
if os.name == "nt":
|
||||
# OMG what a fugly hack
|
||||
import IPython.utils.io as io
|
||||
io.stdout = io.IOStream(sys.__stdout__, fallback=io.devnull)
|
||||
io.stderr = io.IOStream(sys.__stderr__, fallback=io.devnull)
|
||||
embedded_shell.shell.show_banner() # ... my eyes, oh my eyes..
|
||||
|
||||
|
||||
ac_port = int(os.environ.get("SUBLIMEREPL_AC_PORT", "0"))
|
||||
ac_ip = os.environ.get("SUBLIMEREPL_AC_IP", "127.0.0.1")
|
||||
if ac_port:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((ac_ip, ac_port))
|
||||
|
||||
|
||||
def read_netstring(s):
|
||||
size = 0
|
||||
while True:
|
||||
ch = s.recv(1)
|
||||
if ch == b':':
|
||||
break
|
||||
size = size * 10 + int(ch)
|
||||
msg = b""
|
||||
while size != 0:
|
||||
msg += s.recv(size)
|
||||
size -= len(msg)
|
||||
ch = s.recv(1)
|
||||
assert ch == b','
|
||||
return msg
|
||||
|
||||
|
||||
def send_netstring(sock, msg):
|
||||
payload = b"".join([str(len(msg)).encode("ascii"), b':', msg.encode("utf-8"), b','])
|
||||
sock.sendall(payload)
|
||||
|
||||
|
||||
def complete(zmq_shell, req):
|
||||
kc = kernel_client(zmq_shell)
|
||||
msg_id = kc.shell_channel.complete(**req)
|
||||
msg = kc.shell_channel.get_msg(timeout=0.5)
|
||||
if msg['parent_header']['msg_id'] == msg_id:
|
||||
return msg["content"]["matches"]
|
||||
return []
|
||||
|
||||
|
||||
def handle():
|
||||
while True:
|
||||
msg = read_netstring(s).decode("utf-8")
|
||||
try:
|
||||
req = json.loads(msg)
|
||||
completions = complete(embedded_shell, req)
|
||||
result = (req["text"], completions)
|
||||
res = json.dumps(result)
|
||||
send_netstring(s, res)
|
||||
except Exception:
|
||||
send_netstring(s, b"[]")
|
||||
|
||||
if ac_port:
|
||||
t = threading.Thread(target=handle)
|
||||
t.start()
|
||||
|
||||
embedded_shell.start()
|
||||
|
||||
if ac_port:
|
||||
s.close()
|
||||
Reference in New Issue
Block a user