如何在 Emacs 中复制字符串并粘贴子字符串?

How to copy a string and paste a substring in Emacs?

在网上找到这个:

(defun clipboard/set (astring)
  "Copy a string to clipboard"
   (with-temp-buffer
    (insert astring)
    (clipboard-kill-region (point-min) (point-max))))

我想让它交互,运行 字符串通过子字符串,然后复制到剪贴板

(defun clipboard/set (astring)
  "Copy a string to clipboard"
(interactive)
(let (bstring (substring astring -11)))   
(with-temp-buffer
    (insert bstring)
    (clipboard-kill-region (point-min) (point-max))))

如何做到这一点?

您需要告诉 interactive 如何填充参数:

(interactive "sAstring: ")

此外,let的语法不同,它以变量和值列表的列表开头,即

(let ((bstring (substring astring -11)))
;    ^^

(defun clipboard/set (astring)
  "Copy a string to clipboard"
  (interactive "sAstring: ")
  (let ((bstring (substring astring -11)))
    (with-temp-buffer
      (insert bstring)
      (clipboard-kill-region (point-min) (point-max)))))

并在最后关闭它。