首页 > 解决方案 > 如何在 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))))

如何做到这一点?

标签: emacscommand

解决方案


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

(interactive "sAstring: ")

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

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

IE

(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)))))

并在最后关闭它。


推荐阅读