[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Emanuel Berg
Subject: gui-get
Date: Fri, 12 Nov 2021 07:13:56 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

None of these work:


  (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) <>
;;; Created: 2021-05-04
;;; Keywords: unix
;;; License: GPL3+
;;; URL:
;;; 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'."
    (when (use-region-p)
      (delete-region (region-beginning) (region-end)) )
     (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'."
     (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'."
   (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."
  (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."
   (if (use-region-p)
     #'insert-x-clipboard) ))

(defalias 'x  #'x-clipboard-dwim)
(defalias 'xo #'insert-x-clipboard)

(provide 'xsel)
;;; xsel.el ends here
underground experts united

reply via email to

[Prev in Thread] Current Thread [Next in Thread]