emacs/config/clipboard.el

37 lines
1.6 KiB
EmacsLisp
Raw Normal View History

2025-01-30 10:47:07 +07:00
;; Clipboard integration (Not work in terminal)
(setq select-enable-clipboard t)
(setq select-enable-primary t)
;; Clipboard integration for terminal (Need xclip)
(when (not (display-graphic-p)) ;; Check if Emacs is running in the terminal
(defun my-cut-to-clipboard ()
"Cut region to clipboard using xclip."
(interactive)
(if (use-region-p)
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
(with-temp-buffer
(insert text)
(call-process-region (point-min) (point-max) "xclip" nil 0 nil "-selection" "clipboard"))
(delete-region (region-beginning) (region-end))
(message "Cut to clipboard"))
(message "No region selected.")))
(defun my-copy-to-clipboard ()
"Copy region to clipboard using xclip."
(interactive)
(if (use-region-p)
(let ((text (buffer-substring-no-properties (region-beginning) (region-end))))
(with-temp-buffer
(insert text)
(call-process-region (point-min) (point-max) "xclip" nil 0 nil "-selection" "clipboard"))
(message "Copied to clipboard"))
(message "No region selected.")))
(defun my-paste-from-clipboard ()
"Paste clipboard content using xclip."
(interactive)
(let ((clipboard-text (with-temp-buffer
(process-file "xclip" nil t nil "-selection" "clipboard" "-o")
(buffer-string))))
(if clipboard-text
(progn (insert clipboard-text) (message "Paste from clipboard") )
(message "Clipboard is empty or xclip is not working.")))))