I am creating a plugin for sublime 4 on Ubuntu 22.04. The plugin uses pyclip (https://pypi.org/project/pyclip/) to copy text from the "clipboard" and perform certain formatting functions on the text before inserting it into the current views edit buffer.
Note: For this to work on Ubuntu you need to have xclip or xsel installed. I am using xclip
The standard use case is:
- The user copies a block of text from a webpage in a browser
- In sublime, the user runs the appropriate command that calls the plugin.
- The plugin calls the pyclip function to get the copied text: copied_text = pyclip.paste(text=True)
- The plugin performs some formatting on the text
- The plugin pastes the results into the current sublime window at the current cursor position.
This works great whenever the source program is a browser, another text editor, a spreadsheet, etc. HOWEVER, if the source of the text copied to the memory buffer in the cut-and-paste operation is sublime, then the function being called in the plugin to get the text, pyclip.paste(text=True), never returns and the only way to proceed is to restart sublime.
If anyone has any ideas what the issue may be it would be greatly appreciated!
I have dried this with pyperclip instead of pyclip, and with xsel instead of xclip. The problem is exactly the same. If the source program for the copy and paste operation is sublime, then sublime freezes. I have also tried this on ubuntu 20.04 and have the same results.
-
1have you considered just using Sublime's API to get the clipboard text instead of a Python package? sublimetext.com/docs/…Keith Hall– Keith Hall2023年10月12日 20:02:35 +00:00Commented Oct 12, 2023 at 20:02
-
As @KeithHall mentions, I was also going to ask what this library offers that is not already possible with the API. Do you need to try and grab non-text data or something?OdatNurd– OdatNurd2023年10月13日 02:43:15 +00:00Commented Oct 13, 2023 at 2:43
-
Thank you for the suggestion. The sublime api function works great.Jack Crowley– Jack Crowley2023年10月19日 21:38:56 +00:00Commented Oct 19, 2023 at 21:38