Cut to clipboard

This commit is contained in:
Dita Aji Pratama 2024-11-19 16:08:35 +07:00
parent f14028123c
commit 1c228db705

14
init.el
View File

@ -55,6 +55,17 @@ version 2022-06-09"
;; 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)
@ -66,7 +77,8 @@ version 2022-06-09"
(message "Copied to clipboard"))
(message "No region selected.")))
(global-set-key (kbd "C-c M-w") 'my-copy-to-clipboard))
(global-set-key (kbd "C-c C-w") 'my-cut-to-clipboard)
(global-set-key (kbd "C-c M-w") 'my-copy-to-clipboard)
;; For example, set the default tab width to 4 spaces