help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: NonGNU ELPA


From: Emanuel Berg
Subject: Re: NonGNU ELPA
Date: Sun, 23 Jan 2022 17:39:50 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

> The question w.r.t `xsel.el` is whether the functionality it
> offers via `xsel` is different from that offered by
> `xclip.el` (eithef via `xsel` or via other means), and if so
> whether the two shoud be combined/merged or kept separate
> (like `gpastel.el` is currently kept separate).

xsel.el is only 85 lines (including the bulk of standard
documentation) so please find out ...

It is a getter, a setter, two Emacs-specific applications and
a shorthand.

Very basic one would think?

;;; 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.3.7
;;;
;;; This gives you access to the X clipboard from a Linux
;;; VT/console/tty Emacs instance (or any Emacs, possibly).
;;; Set and/or Insert the X clipboard at point.
;;;
;;; DWIM: If there is a region, replace it with the
;;; X clipboard.
;;;
;;; Feature: Set the X clipboard programmatically in Elisp or
;;; set it interactively to the contents of the region (if
;;; there is one), otherwise set it to the most recent
;;; Emacs kill.
;;;
;;; Use $DISPLAY or ":0" with xsel(1x).
;;;
;;; Code:

(let ((xsel-x-display (or (getenv "DISPLAY") ":0")))
  (defun insert-x-clipboard ()
    "Insert the X clipboard at point using xsel(1x).
If there is a region it is overwritten."
    (interactive)
    (when (use-region-p)
      (delete-region (region-beginning) (region-end)) )
    (shell-command
     (format "xsel --display \"%s\" --clipboard -o" xsel-x-display)
     1) ; insert in current buffer
    (goto-char (mark)) )
  (declare-function insert-x-clipboard nil)

  (defun set-x-clipboard (str)
    "Set the X clipboard to STR. When used interactively, STR
is either what is in the region, if available, if not the most
recent Emacs kill is used."
    (interactive
     (list (if (use-region-p)
               (buffer-substring-no-properties (region-beginning) (region-end))
             (encode-coding-string (current-kill 0 t) 'utf-8-unix) )))
    (shell-command
     (format "echo -n %s | xsel --display %s -b -i"
             (shell-quote-argument str)
             xsel-x-display) ))
  (declare-function set-x-clipboard nil) )

(defun x-copy (&optional beg end)
  "Copy the buffer text from BEG to END to the X clipboard.
Unless optional arguments are provided the whole buffer text is used."
  (interactive (when (use-region-p)
                 (list (region-beginning) (region-end)) ))
  (let ((b (or beg (point-min)))
        (e (or end (point-max))) )
    (set-x-clipboard (buffer-substring b e) )))

(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 str) ))
;; (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




reply via email to

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