system.el 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ;;; system.el --- System integration functions -*- lexical-binding: t; -*-
  2. (defun my/system-cut (beg end)
  3. "Cut region directly to system clipboard, bypassing the kill ring."
  4. (interactive "r")
  5. (my/system-copy beg end)
  6. ;; delete-region deletes without adding to the kill ring
  7. (delete-region beg end))
  8. (defun my/system-copy (beg end)
  9. "Pure copy: Sends the active region directly to the system clipboard.
  10. Absolutely zero interaction with the Emacs kill ring."
  11. (interactive "r")
  12. (unless (region-active-p)
  13. (user-error "No active region to copy"))
  14. (let ((text (buffer-substring-no-properties beg end)))
  15. (if (display-graphic-p)
  16. ;; Low-level GUI primitive: talks directly to the OS clipboard manager
  17. (gui-backend-set-selection 'CLIPBOARD text)
  18. ;; TUI Fallback via Clipetty
  19. (if (fboundp 'clipetty-set-selection)
  20. (clipetty-set-selection text)
  21. (error "Clipetty not loaded")))
  22. (deactivate-mark)
  23. (message "Copied to system clipboard (pure)")))
  24. (defun my/system-paste ()
  25. "Pure paste: Inserts text directly from the system clipboard.
  26. Never falls back to or checks the Emacs kill ring."
  27. (interactive)
  28. (if (display-graphic-p)
  29. (let ((text (or (gui-backend-get-selection 'CLIPBOARD 'STRING)
  30. (gui-backend-get-selection 'CLIPBOARD 'UTF8_STRING)
  31. (gui-backend-get-selection 'PRIMARY 'STRING)
  32. ;; Wayland/Dolphin fallback from previous fix
  33. (when (executable-find "wl-paste")
  34. (let ((val (shell-command-to-string "wl-paste -n -t text/plain")))
  35. (unless (string-empty-p val) val))))))
  36. (if text
  37. (insert text)
  38. (user-error "System clipboard is empty")))
  39. ;; TUI Fallback
  40. (message "In a terminal, use your terminal emulator's native paste shortcut (e.g., Ctrl-Shift-V).")))
  41. (defun my/vterm-sync-here ()
  42. "Switch to vterm and instantly 'cd' to the current buffer's directory."
  43. (interactive)
  44. (let ((cwd default-directory))
  45. (vterm-toggle)
  46. (vterm-send-string (format "cd %s" (shell-quote-argument cwd)))
  47. (vterm-send-return)))
  48. (provide 'system)
  49. ;;unqualified-search-registries = ["docker.io"]