prompt-toolkit / ptpython

A better Python REPL
BSD 3-Clause "New" or "Revised" License
5.23k stars 281 forks source link

Eliminate Paste Mode #43

Open ryneeverett opened 9 years ago

ryneeverett commented 9 years ago

I'm sure there's a history behind it and a good rationale for initially adding it, but is there any possibility of getting rid of it? I'd prefer to not have to choose between clipboard access and "returning".

jonathanslenders commented 9 years ago

Hi @ryneeverett

How would you distinguish between a user pasting text and a user typing text? As far as i know from the application's point of view there is no difference. It's like Vi also has a :set paste option.

In paste mode, automatic indentation is off. This will paste verbatim and not insert additional spaces.

Jonathan

ryneeverett commented 9 years ago

@jonathanslenders Got it. I understand why it is currently needed. But couldn't we bind y, p, etc. to clipboard operations?

jonathanslenders commented 9 years ago

That could be possible, but system clipboard synchronisation is hard to do correctly without using libraries like gtk or qt. I prefer to not depend on this for now.

ryneeverett commented 9 years ago

@jonathanslenders Have you seen pyperclip? It's cross platform, lean (~200 loc), and appears to depend on any one of xclip, xsel, gtk, or qt on Linux. Would you be open to adding pyperclip as a dependency?

jonathanslenders commented 9 years ago

Yes, I have seen that. I'm not going to add another dependency, but I'll try to create an example of how to create an extension using this clipboard.

You can pass in any clipboard object in prompt-toolkit: https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/application.py#L49 I'll try to update ptpython, so that you can pass that through.

shanechin commented 9 years ago

Is it possible to add this in via some configuration? or would it require a fork as of today?

jonathanslenders commented 9 years ago

This is work in progress. I'm going to make this easier.

A PyperclipClipboard is already in prompt-toolkit: https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/examples/system-clipboard-integration.py

ryneeverett commented 9 years ago

Sweet! The example implementation looks pretty good.

It doesn't appear that there is any way to override the clipboard without forking ptpython so I'm assuming such a mechanism is forthcoming.

ryneeverett commented 8 years ago

A tip for my fellow vi users: repl.enable_open_in_editor = False.

mixmastamyk commented 7 years ago

Wouldn't bracketed paste be useful here?