Re-use tab when running python code with SublimeREPL
Asked Answered
S

3

15

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?

Smithsonite answered 7/5, 2015 at 12:18 Comment(0)
M
3

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.

Moskow answered 9/10, 2015 at 12:39 Comment(1)
The ticket is already there: github.com/wuub/SublimeREPL/issues/481 but the problem remains.Entoblast
A
13

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

Algie answered 22/9, 2017 at 18:2 Comment(7)
This is NOT working with Sublime Text 3 (3207). It will only build new tabs instead of re-using the same one.Jetta
Works as expected for ST3 (3207) on linux mint 19. The only thing missing is a message to visually separate previous results from the new ones. Any idea where to incorporate that? @AlgieRambo
to automatically change the focus to the the used repl view use window.focus_view(found) whitin the same if statementRambo
@John Stud - verified working in ST3 build 3211, please update to resolve.Algie
@Traxidus Wolf - I've been reading but so far nothing. I thought perhaps a possible option within the "repl_view_settings" under the SublimeREPL user-defined settings or something like that, perhaps.Algie
Works fine for me on Sublime Text 3 (3211) and SublimeREPL v2.1.2, under macOS 11.01 (Big Sur)Allege
this works for me on Windows with recent versions of ST3 and SublimeREPL except that this happens to break when I reorganize ST3 layout, e.g. pulling out the tab of the REPLIodine
M
3

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.

Moskow answered 9/10, 2015 at 12:39 Comment(1)
The ticket is already there: github.com/wuub/SublimeREPL/issues/481 but the problem remains.Entoblast
D
3

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

Dick answered 15/9, 2021 at 7:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.