Created
March 14, 2019 11:02
-
-
Save yorickvP/6132f237fbc289a45c808d8d75e0e1fb to your computer and use it in GitHub Desktop.
teach emacs to use wl-copy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(setq wl-copy-process nil) | |
(defun wl-copy (text) | |
(setq wl-copy-process (make-process :name "wl-copy" | |
:buffer nil | |
:command '("wl-copy" "-f" "-n") | |
:connection-type 'pipe)) | |
(process-send-string wl-copy-process text) | |
(process-send-eof wl-copy-process)) | |
(defun wl-paste () | |
(if (and wl-copy-process (process-live-p wl-copy-process)) | |
nil ; should return nil if we're the current paste owner | |
(shell-command-to-string "wl-paste -n | tr -d \r"))) | |
(setq interprogram-cut-function 'wl-copy) | |
(setq interprogram-paste-function 'wl-paste) |
I improved the snippet a bit to limit the use of wl-copy
and wl-paste
to Emacs running in terminal only:
;; Set up wl-copy and wl-paste in terminal Emacs
(when (and (string= (getenv "XDG_SESSION_TYPE") "wayland")
(executable-find "wl-copy")
(executable-find "wl-paste"))
(defun my-wl-copy (text)
"Copy with wl-copy if in terminal, otherwise use the original value of `interprogram-cut-function'."
(if (display-graphic-p)
(gui-select-text text)
(let ((wl-copy-process
(make-process :name "wl-copy"
:buffer nil
:command '("wl-copy")
:connection-type 'pipe)))
(process-send-string wl-copy-process text)
(process-send-eof wl-copy-process))))
(defun my-wl-paste ()
"Paste with wl-paste if in terminal, otherwise use the original value of `interprogram-paste-function'."
(if (display-graphic-p)
(gui-selection-value)
(shell-command-to-string "wl-paste --no-newline")))
(setq interprogram-cut-function #'my-wl-copy)
(setq interprogram-paste-function #'my-wl-paste))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yorickvP You still need this when running Emacs in a terminal.