Skip to content

Instantly share code, notes, and snippets.

@donilan
Created July 31, 2017 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donilan/52fca391d50689516dfd5ca9cd6701e0 to your computer and use it in GitHub Desktop.
Save donilan/52fca391d50689516dfd5ca9cd6701e0 to your computer and use it in GitHub Desktop.
Copy/paste with system clipboard, support Chinese or other unicode.
(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil)
(lang (getenv "LANG"))
(default-directory "~"))
(setenv "LANG" "en_US.UTF-8")
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))
(setenv "LANG" lang)))
(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment