[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs (in terminal): keeping clipboard synchronized with the system
From: |
Hugo Heden |
Subject: |
Re: Emacs (in terminal): keeping clipboard synchronized with the system global one? |
Date: |
Sun, 8 Mar 2009 11:05:28 +0100 |
On Fri, Mar 6, 2009 at 1:33 PM, Hugo Heden <hugoheden@gmail.com> wrote:
> Good day all,
>
> When running emacs in a terminal, I have problems synchronizing the
> emacs-clipboard with the system clipboard (or the "primary selection",
> it doesn't really matter)
>
> When using a regular x-window for emacs, the following works well:
>
> ;; emacs.d:
> (global-set-key "\C-w" 'clipboard-kill-region)
> (global-set-key "\M-w" 'clipboard-kill-ring-save)
> (global-set-key "\C-y" 'clipboard-yank)
>
> *But* this has no effect when running emacs within a *terminal*.
> Instead, one could use an external tool, "xsel"[1] for keeping the
> buffers synchronized.
I've fiddled with this a bit, and the following works well
---
(global-set-key "\C-w" 'clipboard-kill-region)
(global-set-key "\M-w" 'clipboard-kill-ring-save)
(global-set-key "\C-y" 'clipboard-yank)
(unless window-system
(defun copy-region-to-xsel()
;;(with-current-buffer (current-buffer)
(call-process-region (region-beginning) (region-end) "xsel" nil 0
nil "-p" "-i"))
;; )
(defun ext-kill-ring-save()
(interactive)
(copy-region-to-xsel)
(kill-ring-save (region-beginning) (region-end)))
(defun ext-kill-region()
(interactive)
(copy-region-to-xsel)
(kill-region (region-beginning) (region-end)))
(global-set-key "\M-w" 'ext-kill-ring-save)
(global-set-key "\C-w" 'ext-kill-region))
---
although I would prefer to have the three first lines within an
"if-then-clause" and the rest within an else clause, but I have not
figured out how to do this, I get "Invalid function: (global-set-key
^W (quote clipboard-kill-region))"
(if window-system
(
(global-set-key "\C-w" 'clipboard-kill-region)
(global-set-key "\M-w" 'clipboard-kill-ring-save)
(global-set-key "\C-y" 'clipboard-yank)
)
(
...
)
)
Sorry to be responding to myself, I just thought the above might be
valuable for future reference. Thank for all the help!
Best regards
Hugo Heden