* gui-get
@ 2021-11-12 6:13 Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12 6:22 ` gui-get Po Lu
0 siblings, 1 reply; 3+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-11-12 6:13 UTC (permalink / raw)
To: help-gnu-emacs
None of these work:
(gui-get-primary-selection)
(gui-get-selection)
(gui-get-selection 'primary)
(gui-get-selection 'secondary)
(gui-get-selection 'clipboard)
My own old interface to xsel(1x) also don't work anymore but
if you set it up with commands it works.
But if you do Ctrl-C in the web browser's URL field and then
try to output it the above don't do anything ("No selection is
available", the first, the others just nil) and the below
Elisp stalls.
Even the xsel(1x) and xclip(1) don't do anything (they also
stall) so maybe it isn't even an Emacs issue. I guess not :P
GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, cairo version
1.16.0) of 2021-10-04
Hm .. how do you output the version of X(7)? Ah, just 11.
man page is "xorg-docs 1.7.1". Do people still work on X BTW?
;;; xsel.el --- use the X clipboard -*- lexical-binding: t -*-
;;;
;;; Commentary:
;;;
;;; Author: Emanuel Berg (incal) <moasenwood@zoho.eu>
;;; Created: 2021-05-04
;;; Keywords: unix
;;; License: GPL3+
;;; URL: https://dataswamp.org/~incal/emacs-init/xsel.el
;;; Version: 2.0.2
;;;
;;; This gives you access to the X clipboard from a Linux
;;; VT/console/tty Emacs instance (or any Emacs, actually).
;;;
;;; Possible: Insert the X clipboard at point.
;;;
;;; DWIM: If there is a region, replace it with the
;;; X clipboard.
;;;
;;; Also possible: set the X clipboard programmatically in
;;; Elisp or set it interactively to the contents of the
;;; region if there is one, else set it to the most recent
;;; Emacs kill, without popping the kill ring.
;;;
;;; This package can be used to get complete transparency -
;;; but it is probably, err, over"kill" to have it enabled for
;;; every single one. Let's drop X already and do everything
;;; in Emacs anyway, right?
;;;
;;; (setq interprogram-cut-function ...)
;;;
;;; If DISPLAY is set, it is used, else use ":0".
;;;
;;; Code:
(let ((xsel-x-display (or (getenv "DISPLAY") ":0")))
(defun insert-x-clipboard ()
"Insert the X clipboard at point using the X tool xsel.
Then, point is moved to the end of the inserted clipboard.
If there is a region, overwrite its contents with the clipboard.
See `set-x-clipboard-to-string'."
(interactive)
(when (use-region-p)
(delete-region (region-beginning) (region-end)) )
(shell-command
(format "xsel --display \"%s\" --clipboard -o" xsel-x-display)
1) ; insert into the current buffer
(goto-char (mark)) )
(declare-function insert-x-clipboard nil)
(defun set-x-clipboard-to-string (str)
"Set the X clipboard to STR.
See `set-x-clipboard' and `insert-x-clipboard'."
(shell-command
(format "echo -n %s | xsel --display %s -b -i"
(shell-quote-argument str)
xsel-x-display) ))
(declare-function set-x-clipboard-to-string nil) )
(defun set-x-clipboard (string)
"Set the X clipboard to STRING. When used interactively,
STRING is either the region content, if available,
else it is set to the most recent Emacs kill.
See `insert-x-clipboard'."
(interactive
(list (if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(encode-coding-string (current-kill 0 t) 'utf-8-unix) )))
(set-x-clipboard-to-string string) )
(defun x-copy-buffer ()
"Copy the buffer contents to the X clipboard."
(interactive)
(let ((str (encode-coding-string (buffer-string) 'utf-8-unix)))
(set-x-clipboard-to-string str) ))
(defun x-copy-symbol (sym)
"Copy the value of SYM to the X clipboard."
(interactive "S Symbol: ")
(let*((val (symbol-value sym))
(str (format "%s" val)) )
(set-x-clipboard-to-string str) ))
;; tests:
;; (progn (x-copy-symbol 'fill-column) (insert-x-clipboard))
;; (progn (call-interactively #'x-copy-symbol) (insert-x-clipboard))
(defun x-clipboard-dwim ()
"If the region is active, set the X clipboard, if not, insert it."
(interactive)
(call-interactively
(if (use-region-p)
#'set-x-clipboard
#'insert-x-clipboard) ))
(defalias 'x #'x-clipboard-dwim)
(defalias 'xo #'insert-x-clipboard)
(provide 'xsel)
;;; xsel.el ends here
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: gui-get
2021-11-12 6:13 gui-get Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-11-12 6:22 ` Po Lu
2021-11-12 7:12 ` gui-get Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 3+ messages in thread
From: Po Lu @ 2021-11-12 6:22 UTC (permalink / raw)
To: help-gnu-emacs
Emanuel Berg via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
> (gui-get-primary-selection)
>
> (gui-get-selection)
> (gui-get-selection 'primary)
> (gui-get-selection 'secondary)
> (gui-get-selection 'clipboard)
gui-get-selection uses the X selection names. So you should be doing:
(gui-get-selection 'PRIMARY)
(gui-get-selection 'SECONDARY)
(gui-get-selection 'CLIPBOARD)
Instead.
I suspect all you want is the value of the clipboard, so just use
'CLIPBOARD. The PRIMARY selection is probably not what you want here,
and the SECONDARY selection is a relic of X-Windows.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: gui-get
2021-11-12 6:22 ` gui-get Po Lu
@ 2021-11-12 7:12 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 3+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-11-12 7:12 UTC (permalink / raw)
To: help-gnu-emacs
Po Lu wrote:
>> (gui-get-selection 'primary)
>> (gui-get-selection 'secondary)
>> (gui-get-selection 'clipboard)
>
> gui-get-selection uses the X selection names. So you should
> be doing:
>
> (gui-get-selection 'PRIMARY)
> (gui-get-selection 'SECONDARY)
> (gui-get-selection 'CLIPBOARD)
OK, thanks, but the are still all nil.
Now xsel(1x) and xclip(1) started to work tho ... what did
you do? :O
$ DISPLAY=":0" xsel -o
the truth is out there
As does xsel.el [1] - sweet ... no idea why or why the
`gui-get-selection' don't work.
[1] https://dataswamp.org/~incal/emacs-init/xsel.le
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-12 7:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-12 6:13 gui-get Emanuel Berg via Users list for the GNU Emacs text editor
2021-11-12 6:22 ` gui-get Po Lu
2021-11-12 7:12 ` gui-get Emanuel Berg via Users list for the GNU Emacs text editor
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.