Skip to content

Instantly share code, notes, and snippets.

@elim
Forked from hitode909/clipboard-to-kill-ring.el
Last active August 29, 2015 14:18
Show Gist options
  • Save elim/666807b53f2b2cf503c1 to your computer and use it in GitHub Desktop.
Save elim/666807b53f2b2cf503c1 to your computer and use it in GitHub Desktop.
;;; clipboard-to-kill-ring.el
;;; * 概要
;;; OS Xのクリップボードを定期的に監視してkill-ringに入れます
;;; deferred.elが必要です
;;;
;;; * 使い方
;;; (clipboard-to-kill-ring t)
;;; で監視を始めます
;;; clipboard-to-kill-ring:interval を設定するとポーリングの間隔を変えられます.
;;; デフォルトで1秒です.
(require 'deferred)
(defcustom clipboard-to-kill-ring:interval 1.0
"ポーリング間隔")
(defvar clipboard-to-kill-ring:timer nil)
(defun clipboard-to-kill-ring:observe ()
(let ((clip (funcall interprogram-paste-function)))
(when (and clip (not (string= (car kill-ring) clip)))
(kill-new clip)
(message clip))))
(defun clipboard-to-kill-ring (enable)
"enableがtrueのときクリップボードの監視を始めます"
(if (and enable clipboard-to-kill-ring:timer)
(clipboard-to-kill-ring nil))
(if enable
(setq clipboard-to-kill-ring:timer (run-with-timer
clipboard-to-kill-ring:interval
clipboard-to-kill-ring:interval
'clipboard-to-kill-ring:observe))
(when clipboard-to-kill-ring:timer
(cancel-timer clipboard-to-kill-ring:timer)
(setq clipboard-to-kill-ring:timer nil))))
(provide 'clipboard-to-kill-ring)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment