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

New layer: clipboard support on terminal for multiple systems #4662

Closed
viccuad opened this issue Jan 18, 2016 · 23 comments
Closed

New layer: clipboard support on terminal for multiple systems #4662

viccuad opened this issue Jan 18, 2016 · 23 comments

Comments

@viccuad
Copy link
Contributor

viccuad commented Jan 18, 2016

Right now, there doesn't seem to be clipboard support with spacemacs TUI on Linux, and from the gitter chat I get that it doesn't work on other systems too.

Maybe is a good idea to gather here together the relevant configs to make a layer with them, with some layer docs on external dependencies.

@robbyoconnor
Copy link
Contributor

👍 If you make a PR, i'm sure people would love you.

@ghost
Copy link

ghost commented Jan 18, 2016

The only stuff I can find about the terminal so far is stuff involving custom functions that call out to xclip or some other external plugin. This might be interesting to look at, though. The wiki seems mildly useful. And lastly, as further research, this answer which gives a nice useful hint as to how yanking behavior changes from emacs 24 to emacs 25 (notably that x-get-selection is obsolete in 25.1 and a new method gui-get-primary-selection, deriving from gui-get-selection becomes available)

@StreakyCobra
Copy link
Contributor

@viccuad
Copy link
Contributor Author

viccuad commented Jan 18, 2016

Well, color my surprised. I have tried defining interprogram-cut-function and interprogram-paste-function myself and couldn't get it to work. I report it works with those definitions in the Arch wiki: (on Linux, with xclip installed in the system)

(unless window-system
  (when (getenv "DISPLAY")
    (defun xclip-cut-function (text &optional push)
      (with-temp-buffer
    (insert text)
    (call-process-region (point-min) (point-max) "xclip" nil 0 nil "-i" "-selection" "clipboard")))
    (defun xclip-paste-function()
      (let ((xclip-output (shell-command-to-string "xclip -o -selection clipboard")))
    (unless (string= (car kill-ring) xclip-output)
      xclip-output )))
    (setq interprogram-cut-function 'xclip-cut-function)
    (setq interprogram-paste-function 'xclip-paste-function)
    ))

Looking forward to see other working configs in other SOs, to bundle them in a layer.

@StreakyCobra
Copy link
Contributor

#3064 may as well be included here (instead of in spacemacs layer as I suggested there).

@jamesla
Copy link

jamesla commented Mar 27, 2017

+1

@cweill
Copy link
Contributor

cweill commented May 4, 2017

I have some custom elisp code that does just this and would be happy to make a pull request to fix this. It works across remote machines using xsel, and also works gracefully inside tmux when reattaching from different machines.

Where would be the appropriate place to put such code for custom spacemacs layer?

@viccuad
Copy link
Contributor Author

viccuad commented May 5, 2017

I'm personally glad that you are willing to share that code :), many thanks.

From what I know, You can use the configuration-layer/create-layer command from the contributing docs:
https://github.com/syl20bnr/spacemacs/blob/master/CONTRIBUTING.org#contributing-a-layer

This will create a all the needed file templates. For the layer structure, the read is:
https://github.com/syl20bnr/spacemacs/blob/master/doc/LAYERS.org

@cweill
Copy link
Contributor

cweill commented May 7, 2017

Thanks, I'll put a layer together. Which spacemacs/layers/ directory should this go under?

cweill added a commit to cweill/spacemacs that referenced this issue May 11, 2017
The X clipboard allows a user to copy and paste content between different X
windows, e.g. copying text from Chrome into a Terminal. Copy/pasting with the X
clipboard it well supported in GUI Emacs, but not so well in terminal Emacs
(i.e `emacs -nw` or `emacsclient -t`) without resorting to using the mouse,
since terminal Emacs has no awareness of X. There are several incomplete Elisp
solutions out that work for the most part, but may not have cross-platform
support, or may fail over SSH with X forwarding or within a `tmux` session.

This layer adds support for OSX, Linux, Windows, and Cygwin using the relevant
binary on each system. For example on Linux, it uses `xsel` or `xclip` to
interface with the clipboard, depending which one is available. It also adds
support for ssh'ing into a different OS with X forwarding via `ssh -Y hostname`,
and copy/pasting to and from a remote terminal Emacs. It also supports an edge
case of continuing to work in an Emacs instance running inside a `tmux` session
which may have been started by a different ssh session, which relies on
explicitly reseting the `$DISPLAY` environment variable before calling the
relevant binary.

Yank code inspired by https://github.com/tmux-plugins/tmux-yank.

Fix syl20bnr#4662.
@wilhelmy
Copy link

Any updates on this?

Looking forward to see it merged eventually.

@mgsloan
Copy link

mgsloan commented Jan 1, 2018

👍 I want convenient access to this too

@cweill
Copy link
Contributor

cweill commented Mar 18, 2018

I've just updated the PR to resolve the comments. PTAL.

@cweill
Copy link
Contributor

cweill commented May 7, 2018

This post on hacker news today is relevant to this topic. Maybe it will be useful for someone else here.

syl20bnr pushed a commit that referenced this issue May 11, 2018
The X clipboard allows a user to copy and paste content between different X
windows, e.g. copying text from Chrome into a Terminal. Copy/pasting with the X
clipboard it well supported in GUI Emacs, but not so well in terminal Emacs
(i.e `emacs -nw` or `emacsclient -t`) without resorting to using the mouse,
since terminal Emacs has no awareness of X. There are several incomplete Elisp
solutions out that work for the most part, but may not have cross-platform
support, or may fail over SSH with X forwarding or within a `tmux` session.

This layer adds support for OSX, Linux, Windows, and Cygwin using the relevant
binary on each system. For example on Linux, it uses `xsel` or `xclip` to
interface with the clipboard, depending which one is available. It also adds
support for ssh'ing into a different OS with X forwarding via `ssh -Y hostname`,
and copy/pasting to and from a remote terminal Emacs. It also supports an edge
case of continuing to work in an Emacs instance running inside a `tmux` session
which may have been started by a different ssh session, which relies on
explicitly reseting the `$DISPLAY` environment variable before calling the
relevant binary.

Yank code inspired by https://github.com/tmux-plugins/tmux-yank.

Fix #4662.

Tried to add xclip support but removed it since it freezes.
@syl20bnr syl20bnr reopened this May 11, 2018
@syl20bnr
Copy link
Owner

Oops wrongly closed it.
Thank you @cweill, merged in develop branch.

alanjferguson pushed a commit to alanjferguson/spacemacs that referenced this issue May 14, 2018
The X clipboard allows a user to copy and paste content between different X
windows, e.g. copying text from Chrome into a Terminal. Copy/pasting with the X
clipboard it well supported in GUI Emacs, but not so well in terminal Emacs
(i.e `emacs -nw` or `emacsclient -t`) without resorting to using the mouse,
since terminal Emacs has no awareness of X. There are several incomplete Elisp
solutions out that work for the most part, but may not have cross-platform
support, or may fail over SSH with X forwarding or within a `tmux` session.

This layer adds support for OSX, Linux, Windows, and Cygwin using the relevant
binary on each system. For example on Linux, it uses `xsel` or `xclip` to
interface with the clipboard, depending which one is available. It also adds
support for ssh'ing into a different OS with X forwarding via `ssh -Y hostname`,
and copy/pasting to and from a remote terminal Emacs. It also supports an edge
case of continuing to work in an Emacs instance running inside a `tmux` session
which may have been started by a different ssh session, which relies on
explicitly reseting the `$DISPLAY` environment variable before calling the
relevant binary.

Yank code inspired by https://github.com/tmux-plugins/tmux-yank.

Fix syl20bnr#4662.

Tried to add xclip support but removed it since it freezes.
@cweill
Copy link
Contributor

cweill commented May 16, 2018

@syl20bnr: My pleasure. Thank you for your review.

buckarooch pushed a commit to profilech/.emacs.d that referenced this issue May 19, 2018
The X clipboard allows a user to copy and paste content between different X
windows, e.g. copying text from Chrome into a Terminal. Copy/pasting with the X
clipboard it well supported in GUI Emacs, but not so well in terminal Emacs
(i.e `emacs -nw` or `emacsclient -t`) without resorting to using the mouse,
since terminal Emacs has no awareness of X. There are several incomplete Elisp
solutions out that work for the most part, but may not have cross-platform
support, or may fail over SSH with X forwarding or within a `tmux` session.

This layer adds support for OSX, Linux, Windows, and Cygwin using the relevant
binary on each system. For example on Linux, it uses `xsel` or `xclip` to
interface with the clipboard, depending which one is available. It also adds
support for ssh'ing into a different OS with X forwarding via `ssh -Y hostname`,
and copy/pasting to and from a remote terminal Emacs. It also supports an edge
case of continuing to work in an Emacs instance running inside a `tmux` session
which may have been started by a different ssh session, which relies on
explicitly reseting the `$DISPLAY` environment variable before calling the
relevant binary.

Yank code inspired by https://github.com/tmux-plugins/tmux-yank.

Fix syl20bnr#4662.

Tried to add xclip support but removed it since it freezes.
@NightMachinery
Copy link

Any way to make this work on macOS? I have xclip installed, but it doesn't work.

@NightMachinery
Copy link

@syl20bnr https://github.com/joddie/osx-clipboard-mode works great. I think it should be added to the osx layer.

@suonlight
Copy link
Contributor

@NightMachinary, @syl20bnr : I had a PR to add osx-clipboard-mode to osx layer: #11215

@wilhelmy
Copy link

wilhelmy commented Sep 10, 2018

I think the correct OS X commands to use instead of xclip (which is X11 specific) are pbcopy and pbpaste, there's no need for a separate mode.

Edit: just my 2 cents, in the spirit of code deduplication. I don't actually use OS X, so I don't really care that much.

@NightMachinery
Copy link

NightMachinery commented Sep 14, 2018 via email

CodingSolo pushed a commit to CodingSolo/spacemacs that referenced this issue Oct 29, 2018
The X clipboard allows a user to copy and paste content between different X
windows, e.g. copying text from Chrome into a Terminal. Copy/pasting with the X
clipboard it well supported in GUI Emacs, but not so well in terminal Emacs
(i.e `emacs -nw` or `emacsclient -t`) without resorting to using the mouse,
since terminal Emacs has no awareness of X. There are several incomplete Elisp
solutions out that work for the most part, but may not have cross-platform
support, or may fail over SSH with X forwarding or within a `tmux` session.

This layer adds support for OSX, Linux, Windows, and Cygwin using the relevant
binary on each system. For example on Linux, it uses `xsel` or `xclip` to
interface with the clipboard, depending which one is available. It also adds
support for ssh'ing into a different OS with X forwarding via `ssh -Y hostname`,
and copy/pasting to and from a remote terminal Emacs. It also supports an edge
case of continuing to work in an Emacs instance running inside a `tmux` session
which may have been started by a different ssh session, which relies on
explicitly reseting the `$DISPLAY` environment variable before calling the
relevant binary.

Yank code inspired by https://github.com/tmux-plugins/tmux-yank.

Fix syl20bnr#4662.

Tried to add xclip support but removed it since it freezes.
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
@elmarlee
Copy link

Is it possible to have this layer support cygwin terminal like https://github.com/ArthurTu/cygwin-terminal-clipboard

@JAremko JAremko added updated This issue has been updated since becoming stale - Forum - and removed stale marked as a stale issue/pr (usually by a bot) updated This issue has been updated since becoming stale labels May 26, 2020
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Mar 14, 2022
@github-actions github-actions bot closed this as completed May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests