spudlyo / clipetty

Manipulate the system (clip)board with (e)macs from a (tty)
GNU General Public License v3.0
167 stars 13 forks source link

Pasting from system clipboard into ssh/tmux/emacs session? #10

Open jojojames opened 4 years ago

jojojames commented 4 years ago

Hi! Amazing package! Thanks for pushing it out. :)

Is your feature request related to a problem? Please describe.

I was wondering how feasible it would be to go "in reverse", that is, copying from the system clipbord (say OSX clipboard) into my ssh->tmux->emacs session.

Thanks for reading!

spudlyo commented 4 years ago

I believe this would be possible, but I'm not sure a lot of terminals support it. Some authors of terminal emulators believe that the OSC features represent a security risk, and refuse to allow the ability to write to the clipboard. I just tested iTerm2, Kitty, and xterm and it seems that only xterm currently supports reading from the system clipboard.

It might be worth adding just for folks who run xterm, with the hopes that more terminal emulators will add it in the future. I'm curious why you think it'd be handy to have? I mean why not use the OS level hotkey to paste from the system clipboard? I personally think it might be nice for the contents I paste from the system clipboard get copied to the kill ring in Emacs.

spudlyo commented 4 years ago

Actually, I take that back about kitty. You can optionally allow clipboard read via OSC 52 via the the config file.

clipboard_control read-clipboard read-primary write-clipboard write-primary

Very cool.

jojojames commented 4 years ago

I'm curious why you think it'd be handy to have? I mean why not use the OS level hotkey to paste from the system clipboard?

I've never found a paste that came from OS clipboard through emacs to paste properly. Using evil along with it makes it even worse. I usually get a lot of random artififacts along with the paste.

Shooooooooo commented 4 years ago

+1 for this feature. It will be really handy.

herop commented 4 years ago

Maybe I' missing something out here:

spudlyo commented 4 years ago

@herop:

So Clipetty makes yy in emacs go to your computer's system clipboard (not Emacs' kill ring) when you're running Emacs in a TTY, which usually doesn't happen otherwise. This particular feature request is to be able to paste the contents of your system clipboard into Emacs using an Emacs binding, rather than hitting whatever key sequence is defined by your system to do this (think Ctrl-V in Windows)

Yes, yy and p work fine without Clipetty, in that they copy and paste to Emacs' kill ring, but they don't interface with the system clipboard.

Hope this helps.

herop commented 4 years ago

Thank you so much for pointing that out. I wrote to you because I expected that to happen but can't find that in you readme. 😄 So to wrap it up:

image

Reason being, I guess: I'm using Windows10 and the Windows Terminal Preview. Very sad, I must admit, since I might one of many users struggle with this culprit.

Shooooooooo commented 4 years ago

@herop The second statement you made has not been implemented. And that's the discussion of this thread. Windows Terminal Preview does not have OSC 52 support, so the first statement won't work either. I could not find any decent terminal emulator on Windows. Even Alacritty has some keybinding issue with Emacs on Windows. Hopefully, WT will get more support in the future.

NightMachinery commented 1 year ago

I tried adding support for this:

(defun osc52-paste ()
  (clipetty--emit
   (concat clipetty--osc-start "?" clipetty--osc-end)))

But I don't know how to read the terminal emulator's answer from the tty. Currently the answer goes as input to emacs which messes it up.