Guest User

Untitled

a guest
Jul 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. (unless (featurep 'simpleclip) (require 'simpleclip))
  2. (defun test-simpleclip ()
  3. (unwind-protect
  4. (let (retval)
  5. (condition-case ex
  6. (progn
  7. (simpleclip-set-contents "testsimpleclip!")
  8. (setq retval
  9. (string= "testsimpleclip!"
  10. (simpleclip-get-contents))))
  11. ('error
  12. (message (format "Please install %s to support clipboard from terminal."
  13. (cond
  14. (or (eq system-type 'gnu/linux)
  15. (eq system-type 'linux)
  16. (eq system-type 'usg-unix-v)
  17. (eq system-type 'berkeley-unix))
  18. "xsel or xclip")
  19. ((or (eq system-type 'cygwin) (eq system-type 'windows-nt))
  20. "cygutils-extra from Cygwin")
  21. (t
  22. "CLI clipboard tools"))))
  23. (setq retval nil)))
  24. retval)))
  25. (setq simpleclip-works (test-simpleclip))
  26.  
  27. (defun my-gclip ()
  28. (cond
  29. (simpleclip-works
  30. (simpleclip-get-contents))
  31. ((eq system-type 'darwin)
  32. (with-output-to-string
  33. (with-current-buffer standard-output
  34. (call-process "/usr/bin/pbpaste" nil t nil "-Prefer" "txt"))))
  35. ((eq system-type 'cygwin)
  36. (with-output-to-string
  37. (with-current-buffer standard-output
  38. (call-process "getclip" nil t nil))))
  39. ((memq system-type '(gnu gnu/linux gnu/kfreebsd))
  40. (let* ((powershell-program (executable-find "powershell.exe")))
  41. (cond
  42. (powershell-program
  43. ;; PowerLine adds extra white space character at the end of text
  44. (string-trim-right
  45. (with-output-to-string
  46. (with-current-buffer standard-output
  47. (call-process powershell-program nil t nil "-command" "Get-Clipboard")))))
  48. (t
  49. (with-output-to-string
  50. (with-current-buffer standard-output
  51. (call-process "xsel" nil t nil "--clipboard" "--output")))))))))
  52.  
  53. (defun paste-from-x-clipboard()
  54. "Paste from clipboard."
  55. (interactive "P")
  56. ;; paste after the cursor in evil normal state
  57. (when (and (functionp 'evil-normal-state-p)
  58. (functionp 'evil-move-cursor-back)
  59. (evil-normal-state-p)
  60. (not (eolp))
  61. (not (eobp)))
  62. (forward-char))
  63. (insert (my-gclip)))
Add Comment
Please, Sign In to add comment