[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Copying URLs to X-clipboard [PATCH]]
On 2017-11-20 14:41, Katsumi Yamaoka wrote:
> In [emacs-w3m:12820]
> On Sun, 19 Nov 2017 23:53:45 -0500, Boruch Baum wrote:
> > That looks like it should also work, but what I did with a shell "here
> > variable", the "<<<" may be more cpu efficient, because it doesn't need
> > 'echo' or the pipe.
>
> Ok, here it is:
>
> (defun my-nox-select-text (text)
> "Send TEXT to `xsel -i'."
> (call-process-region text nil "xsel" nil nil nil "-i"))
>
> This works even on my shell that doesn't support "<<<". ;-)
Yes, that's a proper consideration, since some shells don't.
Okay, here's what I've ACTUALLY been using these past months ...
;━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
; x-clip support for emacs-nox / emacs-nw
(defun my-copy-to-xclipboard(arg)
(interactive "P")
(cond
((not (use-region-p))
(message "Nothing to yank to X-clipboard"))
((and (not (display-graphic-p))
(/= 0 (shell-command-on-region
(region-beginning) (region-end) "xsel -i -b")))
(error "Is program `xsel' installed?"))
(t
(when (display-graphic-p)
(call-interactively 'clipboard-kill-ring-save))
(message "Yanked region to X-clipboard")
(when arg
(kill-region (region-beginning) (region-end)))
(deactivate-mark))))
(defun my-cut-to-xclipboard()
(interactive)
(my-copy-to-xclipboard t))
(defun my-paste-from-xclipboard()
"Uses shell command `xsel -o' to paste from x-clipboard. With
one prefix arg, pastes from X-PRIMARY, and with two prefix args,
pastes from X-SECONDARY."
(interactive)
(if (display-graphic-p)
(clipboard-yank)
(let*
((opt (prefix-numeric-value current-prefix-arg))
(opt (cond
((= 1 opt) "b")
((= 4 opt) "p")
((= 16 opt) "s"))))
(insert (shell-command-to-string (concat "xsel -o -" opt))))))
(global-set-key (kbd "C-c C-w") 'my-cut-to-xclipboard)
(global-set-key (kbd "C-c M-w") 'my-copy-to-xclipboard)
(global-set-key (kbd "C-c C-y") 'my-paste-from-xclipboard)
;━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0