note63

事情

Emacs設定経過メモ(2)

EmacsとOSXのクリップボードを共有するように設定。 tmux上で動かした場合はさらにtmuxでの設定も必要なのでそれもメモしとく。

tmuxでpbcopy/pbpasteが動くようにする

のためにまずgithubからtmux-MacOSX-pasteboardを落としてコンパイルする。

git clone https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard.git
cd tmux-MacOSX-pasteboard/
make

これはtmux用のpbcopy/pbpasteのラッパーらしい。 こいつの設定を.tmux.confに追記する。僕は普段tmuxのプラグインとかは.tmux/以下に置いてるので以下のようになる。

set-option -g default-command "~/.tmux/tmux-MacOSX-pasteboard/reattach-to-user-namespace -l $SHELL"

これを書いたら一旦tmuxを再起動する。 設定ファイルの読み込みではない、再起動だ!!(これでハマったのはナイショ)

emacsとOSXのクリップボードを共有する

以下の設定をinit.elに追加する

; Emacs と Mac のクリップボード共有
(defun copy-from-osx ()
  (shell-command-to-string "pbpaste"))

(defun paste-to-osx (text &optional push)
  (let ((process-connection-type nil))
    (let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
      (process-send-string proc text)
      (process-send-eof proc))))

(when (or darwin-p carbon-p)
  (setq interprogram-cut-function 'paste-to-osx)
  (setq interprogram-paste-function 'copy-from-osx))

ここでdarwin-pとかは僕が勝手に定義(というか人の設定を参考にして追加した)もので以下のように定義した。

(setq darwin-p (eq system-type 'darwin)
      linux-p  (eq system-type 'gnu/linux)
      carbon-p (eq system-type 'mac))

これでいろいろと分岐を書くのが楽になるはず

参考