Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-use tab when running python code with SublimeREPL

In this question How to Run Python Code on SublimeREPL, an answer is given on how to use the usual Ctrl+b shortcut to run a python code using SublimeREPL within SublimeText.

The steps are simple:

1- Create a new empty file and paste into it the commands:

{
    "target": "run_existing_window_command", 
    "id": "repl_python_run",
    "file": "config/Python/Main.sublime-menu"
}

2- Save the file as:

/home/USER/.config/sublime-text-3/Packages/User/SublimeREPL-python.sublime-build

3- Go to your Python file tab and select:

Tools > Build System > SublimeREPL-python

After that the usual Ctrl+b shortcut will open a new tab where the code is executed.

The issue with this is that the tabs are not re-used. This means every time you hit Ctrl+b, a new tab opens up instead of the code running in the same tab that was opened before.

Is there a way to make SublimeREPL re-use the tab?

like image 756
Gabriel Avatar asked May 07 '15 12:05

Gabriel


3 Answers

Add the following line in the "repl_python_run" command in SublimeREPL\config\Python\Main.sublime-menu, right before the "external_id": "python" argument:

"view_id": "*REPL* [python]",

and then to change the line:

if view.id() == view_id

into:

if view.name() == view_id

in SublimeREPL\sublimerepl.py.

Found here. enter image description here

like image 156
Daniel Avatar answered Nov 02 '22 12:11

Daniel


Unfortunatly you can't do that even on the latest version of SublimREPL. What you can do is open a ticket to the developper to ask for this implementation. But I'm not sure Sublime Text is able to do that.

like image 28
VivienG Avatar answered Nov 02 '22 11:11

VivienG


I have found a better way to do this using Terminus

  1. install terminus
  2. create a new build system
  3. enter the following in the build system:
{
    "target": "terminus_open",
    "title": "Python REPL",
    "tag": "python-repl",
    "auto_close": false,
    "shell_cmd": "python -u -i \"$file\"",
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "env": {"PYTHONIOENCODING": "utf-8"},
}
  1. now build using this new build system

screenshot of using terminus like repl:

enter image description here

This will basically create a repl for you without the new tab opening after each build, you can further modify it with origami to show the console on right, left, up, bottom of your screen if you want too.

You can also use terminus and run it in the default output console window while accepting inputs and making it interactable too for this-

  1. create a new build system
  2. enter the following in the build system:
{
    "target": "terminus_exec",
    "cancel": "terminus_cancel_build",
    "focus": true,
    "timeit": false,
    "shell_cmd": "python -u -i \"$file\"",
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "env": {"PYTHONIOENCODING": "utf-8"},
}
  1. now build using this new build system
  2. also be sure to add these into the key - binding
[
    //----------------------- OPEN CMD CONSOLE -----------------------

    {
       "keys": ["ctrl+enter"], // you can change the keys
       "command": "terminus_open",
       "args" : {
           "cmd": "cmd.exe",
           "cwd": "${file_path:${folder}}",
           "panel_name": "Terminus"
       }
    },

    //----------------------- CLOSE TERMINUS CONSOLE -----------------------

    {
        "keys": ["ctrl+x"], "command": "terminus_close", // you can change the keys
        "context": [{ "key": "terminus_view"}]
    },
]
  1. the 1st one allows you to create a cmd shell in the default console area(ctrl + enter) and 2nd one allows to close the default console by closing terminus(ctrl + x) that's it enjoy.

screenshot of terminus in console:

enter image description here

I wasted a lot of time trying to find a way to re use tab in repl that's when i found out sublime repl isn't actively maintained anymore. thats how i found terminus which is actively maintained and can do similar things like repl, hope this helps you.

here is the github guide link: https://github.com/wuub/SublimeREPL/issues/481#issuecomment-917862655

like image 3
Jishnu Avatar answered Nov 02 '22 10:11

Jishnu