Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use tab when running python code with SublimeREPL #481

Open
krlng opened this issue Jun 29, 2016 · 54 comments
Open

Re-use tab when running python code with SublimeREPL #481

krlng opened this issue Jun 29, 2016 · 54 comments

Comments

@krlng
Copy link

krlng commented Jun 29, 2016

This is a feature request for not creating a new tab every time a code gets executed in a repl, but re-use the existing tab, just as wished in the this stackoverflow question

@RobertMyles
Copy link

I'd also like to see this implemented, thanks!

@55Cancri
Copy link

I would also like to see this feature implemented. I've tried getting used to using the "cmd+w" shortcut to close the REPL window everytime I run a program, but on more than one occasion the main code window ends up closing instead. Having a re-usuable REPL window would solve this issue.

@ghost
Copy link

ghost commented Jul 16, 2016

That feature would be awesome.

@HyperplnMilan
Copy link

More than welcome...

@zephub
Copy link

zephub commented Sep 26, 2016

This would be a great feature.

@axil
Copy link

axil commented Oct 4, 2016

SublimeREPL seems to be the only feasible way to run interactive python program within sublime and reusing the tab is the one most natural thing it lacks.

@nafets33
Copy link

+1 this would be awesome ! Please develop :)

@margauxpanache
Copy link

Totally agree !

@zhz
Copy link

zhz commented Dec 16, 2016

+1 ,pls ,thanks!

@gmhurley
Copy link

+1

1 similar comment
@neilbramley
Copy link

+1

@vosilov
Copy link

vosilov commented Jan 9, 2017

+1
This would make my life so much better!

@margauxpanache
Copy link

+1

2 similar comments
@oro1989
Copy link

oro1989 commented Jan 23, 2017

+1

@KarimReefat
Copy link

+1

@Gabriel-p
Copy link

Gabriel-p commented Feb 3, 2017

People, for a while now Github added the ability to add a +1 directly to the comment, instead of adding a new comment saying '+1'.

Please stop adding comments saying +1? Just add a 👍 emoji to the top comment by clicking on the smiley face to the top right.

@gacelita
Copy link
Collaborator

gacelita commented Feb 3, 2017

@Gabriel-p +1 :)

@gacelita
Copy link
Collaborator

gacelita commented Feb 3, 2017

I'll try to do this when I have the time, but remember we are accepting (and merging) pull requests now.

@quantumds
Copy link

+1

4 similar comments
@KarimLulu
Copy link

+1

@univang
Copy link

univang commented Apr 19, 2017

+1

@mhdelta
Copy link

mhdelta commented Apr 20, 2017

+1

@fighterii
Copy link

+1

@MohamedAbdultawab
Copy link

That would be amazing to have this feature.

@AbhishekMawai
Copy link

Need this.

@ggstefanov
Copy link

A much needed feature indeed. My quick hack for this was to 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.

@fighterii
Copy link

@ggstefanov Nice one - works as expected!

Give this man a raise!

@JoeJazzy
Copy link

JoeJazzy commented Jun 1, 2017

@ggstefanov Thanks so much, this worked as expected!

Only thing it needs now is to switch to the tab automatically when it's re-run.

@wangyu0354
Copy link

@ggstefanov nice work!

@nafets33
Copy link

nafets33 commented Jun 12, 2017 via email

@pe224
Copy link

pe224 commented Jun 19, 2017

Here's my quick hack for automatically switching to the REPL when running it (built on @ggstefanov's solution): in the same file (SublimeREPL\sublimerepl.py), same line, add one statement

if view.name() == view_id:
   found = view
   window.focus_view(found)    # <-- add this line
   break

I hope this does not affect other features negatively...

@JoeJazzy
Copy link

@pe224 Yay! Nice work, this seems to work as expected!

@kychris
Copy link

kychris commented Jun 25, 2017

Thank you guys so much @ggstefanov and @pe224, it works perfectly, amazing!

@maohe
Copy link

maohe commented Jun 29, 2017

@ggstefanov
Thanks. That's what I need in SublimeREPL.

@apuhegde
Copy link

apuhegde commented Aug 8, 2017

Hello, has this been implemented? How can I use this feature? (Python + Sublime Text noob, sorry if the question is stupid). Thanks.

@dataecstasy
Copy link

Seach for the SublimeREPL in your installation drive.
inside the folder SublimeREPL, spot the file sublimerepl.py
and edit it by adding "view_id": "REPL [python]",
right before the line "external_id": "python"
in all the places.
and Then edit the file Main.sublime-menu inside the SublimeREPL/Config/Python folder
and replace view.id() == view_id:
with view.name() == view_id:

finally close everything and restart sublimetext3 and build multiple times, It will stick to on output tab of sublimeREPL.

@vasselai
Copy link

vasselai commented Aug 26, 2017

Although the solutions that appear here in the comments work pretty well, it is a pain to identify the analogous solution for each language that I work with. And the main reason to use a general purpose text editor like Sublime over specialized IDE like Spyder is exactly being able to handle multiple languages similarly.

Therefore, I would ask: is there any chance that this 1-year old requested feature will be officially addressed in the future? Considering that the last SublimeREPL commit was in September 2016, it seems to be the case that it won't be around any time soon.

@pkonings
Copy link

pkonings commented Nov 20, 2017

Unfortunately I cannot get the mentioned workaround ("view_id": "REPL [python]" etc) working in a recent Sublime Text Build 3143 x64 portable setup. I also tried (REPL[python] , without a space and/or without *) and "view.name() in view_id" but no success. Would appreciate any direction if this is still
working or verification cause I don't know how to debug this anymore (figured out that deleting sublimerepl.py did not make a difference at all so that file is not used...?)

@ericxyun
Copy link

@ggstefanov Thanks again for this little hack. I have no idea how you figured this one out..

Just to take this one step further, I was wondering if anyone knew how to have the REPL start on a new line after a new build instead of outputting immediately to the right of the last output.

I hope this question was clear enough and thank you in advance!

@uluQulu
Copy link

uluQulu commented Jan 9, 2019

Thank you very much @ggstefanov and @pe224 🐬
Fix works flawlessly on Windows 10 latest as of today (Sublime Text & SublimeREPL latest).

@Gseguelg
Copy link

Gseguelg commented Aug 23, 2019

Thank you @ggstefanov and @pe224 !

Any Idea on how to print to the output, so that it's easier to identify previous results from the new ones?

print and sys.stdout.write funcitons only print to console.

@RrnR
Copy link

RrnR commented Nov 11, 2019

Search for the SublimeREPL in your installation drive.
inside the folder SublimeREPL, spot the file sublimerepl.py
and edit it by adding "view_id": "REPL [python]",
right before the line "external_id": "python"
in all the places.

I cannot find the string "external_id": "python" in my copy of sublimerepl.py. Also - that looks like JSON, not Python. Is anyone able to help here? (Windows 10-64, Sublime 3.2.2.3211, Python 3.7.5)

@xinxilas
Copy link

Now we need close the last Python.exe process, because it is opening again and again everytime we Build again...

@xinxilas
Copy link

I did it:

            if view.name() == view_id: #if view.id() == view_id:
                window.focus_view(view)
                window.run_command("repl_kill")
                found = view
                break

@marcofaga
Copy link

The hack didn't work in Arch Linux.

@marcofaga
Copy link

Although the solutions that appear here in the comments work pretty well, it is a pain to identify the analogous solution for each language that I work with. And the main reason to use a general purpose text editor like Sublime over specialized IDE like Spyder is exactly being able to handle multiple languages similarly.

Therefore, I would ask: is there any chance that this 1-year old requested feature will be officially addressed in the future? Considering that the last SublimeREPL commit was in September 2016, it seems to be the case that it won't be around any time soon.

It's already 2020....

@ryamair
Copy link

ryamair commented Jan 3, 2021

I can't get this to work in sublimetext version 3.2.2 build 3211. Can anybody confirm that this hack still works? Thank you

@ffd8
Copy link

ffd8 commented Jan 5, 2021

Thankyouverymuch @ggstefanov + @pe224 for your solutions!
One small addition to contribute...

To clear the output window on each new build, add the following:

if view.name() == view_id:
    found = view
    window.focus_view(found)
    window.run_command("repl_clear") # <--- added to clear window
    break

@Uhrien
Copy link

Uhrien commented Apr 18, 2021

I guess I'm missing something!
Whenever I press ctrl + b, it opens a new tab, can someone make a small and basic guide on how to set the whole thing up? ^_^
Maybe there's an issue with my build system or something ç_ç

@Uhrien
Copy link

Uhrien commented Apr 18, 2021

Alright, I fixed the whole thing:
I opened Sublime Text 3>Packages>SublimeREPL>sublimerepl.py and replaced the if view.id() == view_id statement with this: if view.name() == view_id: window.focus_view(view) window.run_command("repl_kill") window.run_command("repl_clear") found = view break
I then opened "\Sublime Text 3\Packages\SublimeREPL\config\Python\Main.sublime-menu" and added: "view_id": "*REPL* [python]", before EVERY "external_id": "python", including this part: {"command": "repl_open", "caption": "Python - RUN current file", "id": "repl_python_run", "mnemonic": "R", "args": { "type": "subprocess", "encoding": "utf8", "cmd": ["python", "-u", "$file_basename"], "cwd": "$file_path", "syntax": "Packages/Python/Python.tmLanguage", "view_id": "*REPL* [python]", "external_id": "python", "extend_env": {"PYTHONIOENCODING": "utf-8"} }
Also I added this: { "keys": ["ctrl+b"], "command": "run_existing_window_command", "args": { "id": "repl_python_run", "file": "config/Python/Main.sublime-menu"} } to my key bindings and BOOM, it finally works!

@RainjaDanger
Copy link

It's May 2021 and @ggstefanov and @pe224 are still providing the solution that Sublime has not. Thanks, legends!

@mjishnu
Copy link

mjishnu commented Sep 13, 2021

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: https://i.stack.imgur.com/HgfpB.png

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: https://i.stack.imgur.com/nj4jj.png

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.

@infiPython
Copy link

infiPython commented Mar 10, 2024

@pe224 Good job! And I wonder if there is an implementation such that every Python script can be re-executed in different tabs, respectively? Thanks~

@infiPython
Copy link

@pe224 Good job! And I wonder if there is an implementation such that every Python script can be re-executed in different tabs, respectively? Thanks~

I have implemented this idea after several days' exploration. Besides, I seem to find a bug that there will occur an error when an REPL view is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests