From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: gui-get
Date: Fri, 12 Nov 2021 07:13:56 +0100 [thread overview]
Message-ID: <87k0hd7vff.fsf@zoho.eu> (raw)
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
next reply other threads:[~2021-11-12 6:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-12 6:13 Emanuel Berg via Users list for the GNU Emacs text editor [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k0hd7vff.fsf@zoho.eu \
--to=help-gnu-emacs@gnu.org \
--cc=moasenwood@zoho.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).