2018-05-11 04:19:21 +00:00
|
|
|
;;; spacemacs-xclipboard.el --- Add support for xclipboard in the terminal
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
;;
|
2021-03-22 20:11:29 +00:00
|
|
|
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
;;
|
|
|
|
;; Authors: Charles Weill <weill@google.com>
|
|
|
|
;; Google LLC.
|
2018-05-11 04:19:21 +00:00
|
|
|
;;; Commentary:
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
2021-03-24 03:31:44 +00:00
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2018-05-11 04:19:21 +00:00
|
|
|
;;
|
|
|
|
;;; Code:
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
|
2018-05-11 04:19:21 +00:00
|
|
|
(defun spacemacs/xclipboard-get-display ()
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
(shell-command-to-string "if [[ -n $TMUX ]]; then
|
|
|
|
export DISPLAY=$(tmux show-environment | grep -o '^DISPLAY.*$' | sed 's/DISPLAY=//')
|
|
|
|
fi
|
|
|
|
if [[ -z $DISPLAY ]]; then
|
|
|
|
export DISPLAY=:0
|
|
|
|
fi
|
2020-01-13 12:05:09 +00:00
|
|
|
printf $DISPLAY"))
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
|
|
|
|
(defun spacemacs//xclipboard-get-copy-command ()
|
2020-01-04 02:24:47 +00:00
|
|
|
(if xclipboard-copy-command
|
|
|
|
xclipboard-copy-command
|
|
|
|
(shell-command-to-string "command_exists() {
|
|
|
|
local command=\"$1\"
|
|
|
|
type \"$command\" >/dev/null 2>&1
|
|
|
|
}
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
|
2020-01-04 02:24:47 +00:00
|
|
|
# Installing reattach-to-user-namespace is recommended on macOS.
|
|
|
|
if command_exists \"pbcopy\"; then
|
|
|
|
if command_exists \"reattach-to-user-namespace\"; then
|
|
|
|
printf \"reattach-to-user-namespace pbcopy\"
|
|
|
|
else
|
|
|
|
printf \"pbcopy\"
|
|
|
|
fi
|
|
|
|
elif command_exists \"clip.exe\"; then # WSL clipboard command
|
|
|
|
printf \"clip.exe\"
|
|
|
|
elif command_exists \"xsel\"; then
|
|
|
|
printf \"xsel -ib\"
|
|
|
|
elif command_exists \"putclip\"; then # cygwin clipboard command
|
|
|
|
printf \"putclip\"
|
2020-01-13 12:05:09 +00:00
|
|
|
fi")))
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
|
|
|
|
(defun spacemacs//xclipboard-get-paste-command ()
|
2020-01-04 02:24:47 +00:00
|
|
|
(if xclipboard-paste-command
|
|
|
|
xclipboard-paste-command
|
|
|
|
(shell-command-to-string "command_exists() {
|
|
|
|
local command=\"$1\"
|
|
|
|
type \"$command\" >/dev/null 2>&1
|
|
|
|
}
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
|
2020-01-04 02:24:47 +00:00
|
|
|
# Installing reattach-to-user-namespace is recommended on macOS.
|
|
|
|
if command_exists \"pbpaste\"; then
|
|
|
|
if command_exists \"reattach-to-user-namespace\"; then
|
|
|
|
printf \"reattach-to-user-namespace pbpaste\"
|
|
|
|
else
|
|
|
|
printf \"pbpaste\"
|
|
|
|
fi
|
|
|
|
elif command_exists \"paste.exe\"; then # WSL clipboard command
|
|
|
|
printf \"paste.exe\"
|
|
|
|
elif command_exists \"xsel\"; then
|
|
|
|
printf \"xsel -ob\"
|
|
|
|
elif command_exists \"getclip\"; then # cygwin clipboard command
|
|
|
|
printf \"getclip\"
|
2020-01-13 12:05:09 +00:00
|
|
|
fi")))
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
|
|
|
|
(defun spacemacs/xclipboard-copy ()
|
|
|
|
"Copies selection to x-clipboard."
|
|
|
|
(interactive)
|
|
|
|
(if (display-graphic-p)
|
|
|
|
(progn
|
|
|
|
(message "Copied region to x-clipboard!")
|
2020-01-13 12:05:09 +00:00
|
|
|
(call-interactively 'clipboard-kill-ring-save))
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
(if (region-active-p)
|
|
|
|
(progn
|
2020-01-13 12:05:09 +00:00
|
|
|
(shell-command-on-region
|
|
|
|
(region-beginning) (region-end)
|
|
|
|
(format "DISPLAY=%s %s"
|
|
|
|
(spacemacs/xclipboard-get-display)
|
|
|
|
(spacemacs//xclipboard-get-copy-command)))
|
|
|
|
(message (format "Copied region to clipboard \"%s\"!"
|
|
|
|
(spacemacs/xclipboard-get-display)))
|
|
|
|
(deactivate-mark))
|
|
|
|
(message "No region active; can't copy to clipboard!"))))
|
Add X clipboard support layer to terminal emacs.
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.
2017-05-08 03:08:52 +00:00
|
|
|
|
|
|
|
(defun spacemacs/xclipboard-paste ()
|
|
|
|
"Pastes from x-clipboard."
|
|
|
|
(interactive)
|
|
|
|
(if (display-graphic-p)
|
|
|
|
(progn
|
|
|
|
(clipboard-yank)
|
2020-01-13 12:05:09 +00:00
|
|
|
(message "graphics active"))
|
|
|
|
(insert (shell-command-to-string
|
|
|
|
(format "DISPLAY=%s %s"
|
|
|
|
(spacemacs/xclipboard-get-display)
|
|
|
|
(spacemacs//xclipboard-get-paste-command)))))
|
|
|
|
(message (format "Pasted from clipboard \"%s\"!"
|
|
|
|
(spacemacs/xclipboard-get-display))))
|
2018-05-11 04:19:21 +00:00
|
|
|
|
|
|
|
(provide 'spacemacs-xclipboard)
|