Files
lypacamacs/custom/system.el
T
2026-05-26 03:17:52 +02:00

54 lines
2.2 KiB
EmacsLisp

;;; system.el --- System integration functions -*- lexical-binding: t; -*-
(defun my/system-cut (beg end)
"Cut region directly to system clipboard, bypassing the kill ring."
(interactive "r")
(my/system-copy beg end)
;; delete-region deletes without adding to the kill ring
(delete-region beg end))
(defun my/system-copy (beg end)
"Pure copy: Sends the active region directly to the system clipboard.
Absolutely zero interaction with the Emacs kill ring."
(interactive "r")
(unless (region-active-p)
(user-error "No active region to copy"))
(let ((text (buffer-substring-no-properties beg end)))
(if (display-graphic-p)
;; Low-level GUI primitive: talks directly to the OS clipboard manager
(gui-backend-set-selection 'CLIPBOARD text)
;; TUI Fallback via Clipetty
(if (fboundp 'clipetty-set-selection)
(clipetty-set-selection text)
(error "Clipetty not loaded")))
(deactivate-mark)
(message "Copied to system clipboard (pure)")))
(defun my/system-paste ()
"Pure paste: Inserts text directly from the system clipboard.
Never falls back to or checks the Emacs kill ring."
(interactive)
(if (display-graphic-p)
(let ((text (or (gui-backend-get-selection 'CLIPBOARD 'STRING)
(gui-backend-get-selection 'CLIPBOARD 'UTF8_STRING)
(gui-backend-get-selection 'PRIMARY 'STRING)
;; Wayland/Dolphin fallback from previous fix
(when (executable-find "wl-paste")
(let ((val (shell-command-to-string "wl-paste -n -t text/plain")))
(unless (string-empty-p val) val))))))
(if text
(insert text)
(user-error "System clipboard is empty")))
;; TUI Fallback
(message "In a terminal, use your terminal emulator's native paste shortcut (e.g., Ctrl-Shift-V).")))
(defun my/vterm-sync-here ()
"Switch to vterm and instantly 'cd' to the current buffer's directory."
(interactive)
(let ((cwd default-directory))
(vterm-toggle)
(vterm-send-string (format "cd %s" (shell-quote-argument cwd)))
(vterm-send-return)))
(provide 'system)
;;unqualified-search-registries = ["docker.io"]