- package controll install SublimeREPL
- add python 3 build system Tools/Build System/New (optional)
{
"cmd": ["python3", "-i", "-u", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python"
}
This will save the file to Users/pkomsit/Library/Application Support/Sublime Text 3/Packages/User/Python3.sublime-build Try with Command+B with this code
import sys
print (sys.version)- add Python3 to SublimeREPL menu /Users/pkomsit/Library/Application Support/Sublime Text 3/Packages/SublimeREPL/config/Python/Main.sublime-menu
{
"caption": "Python",
"id": "Python",
"children":[
{"command": "repl_open",
"caption": "Python3",
"id": "repl_python3",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-i", "-u"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
]
}
- custom settings
Preferences/Package Settings/SublimeREPL/Settings - User
{
// Where to look for python virtualenvs
"python_virtualenv_paths": [
"~/.virtualenvs", // virtualenvwrapper
"~/.venv" // venv.bash https://github.com/wuub/venv
],
// If set to true, SublimeREPL will try to append evaluated code to repl
// output before evaluation (e.g. Ctrl+, f)
"show_transferred_text": true,
// If set to true repl view (tab) that receives text for evaluation will
// be brought to front after text transfer. Note: This will not fire if repl view
// is in the same tab group as the view from which the code is sent.
"focus_view_on_transfer": false
}
Preferences/Key Bindings Default (OSX).sublime-keymap -- User
// custom SublimeREPL
{ "keys": ["super+shift+enter"], "command": "repl_transfer_current", "args": {"scope": "selection"}, "context": [{"key": "selector", "operator": "equal", "operand": "source.python"}]},
{ "keys": ["super+enter"], "command": "repl_transfer_current", "args": {"scope": "lines"}, "context": [{"key": "selector", "operator": "equal", "operand": "source.python"}]}
- more example
import urllib.request
fp = urllib.request.urlopen("http://www.python.org")
mybytes = fp.read()
mystr = mybytes.decode("utf8")
fp.close()
print(mystr)
Combining q and R
We can use sublime-q with sublimeREPL to write q (for data preparation) and R (for plotting) in the same source (.q) file
Here is an example usage
R console
Startup (every session)
Setup (one time)
/Users/pkomsit/Library/Application Support/Sublime Text 3/Packages/User/Main.sublime-menu). This will add custom R session nameR (q)in menu Tools/SublimeREPL/R (q)`.[ { "id": "tools", "children": [{ "caption": "SublimeREPL", "mnemonic": "R", "id": "SublimeREPL", "children": [ {"command": "repl_open", "caption": "R (q)", "id": "repl_r_q", "mnemonic": "R", "args": { "type": "subprocess", "external_id": "r", "additional_scopes": ["tex.latex.knitr", "q"], "encoding": { "windows": "$win_cmd_encoding", "linux": "utf8", "osx": "utf8" }, "soft_quit": "\nquit(save=\"no\")\n", "cmd": {"linux": ["R", "--interactive", "--no-readline"], "osx": ["R", "--interactive", "--no-readline"], "windows": ["Rterm.exe", "--ess", "--encoding=$win_cmd_encoding"]}, "cwd": "$file_path", "extend_env": {"osx": {"PATH": "{PATH}:/usr/local/bin"}, "linux": {"PATH": "{PATH}:/usr/local/bin"}, "windows": {}}, "cmd_postfix": "\n", "suppress_echo": {"osx": true, "linux": true, "windows": false}, "syntax": "Packages/R/R Console.tmLanguage" } } ] }] } ]Open menu
Sublime Text/Preferences/Key Bindingsand add below line{ "keys": ["super+r"], "command": "repl_transfer_current", "args": {"scope": "lines"}, "context": [{"key": "selector", "operator": "equal", "operand": "source.q"}]}Extra Explanation
The menu config is just a copy from original one with one line change by adding
qtoadditional_scopesto tell SublimeText to also send command from q source file to R session. (The original is in/Users/pkomsit/Library/Application Support/Sublime Text 3/Packages/SublimeREPL/config/R/Main.sublime-menu).We need to do this because SublimeREPL selects REPL session based on scope of the source file (file extension). But we want to send R code from q source file, so we need to tell R REPL session to accepts text from q source file by adding
additional_scopesconfig.We can also do it the other way by calling sublime-q from R source, but I prefer q syntax highlighting. And this will not work if you already have another custom REPL session for q.
Note: file name must be
Main.sublime-menubecause we are adding a new item to the main menu.