所以我有这个功能,它给了我所选文本的开始和结束位置
(defun start-end (pos1 pos2)
"…"
(interactive "r")
; …
(message "start: %d. end: %d." pos1 pos2)
)
现在我想写入名为“result”的其他文件缓冲区(如果不存在,则创建缓冲区),例如:
pos1,pos2,param1,param2
其中 param1, param2 应该在 cmd 行上询问。我该如何做到这一点?
尝试类似:
(defun start-end (pos1 pos2 param1 param2)
(interactive "r\nsParam1: \nsParam2: ")
(message "%d,%d,%s,%s" pos1 pos2 param1 param2))
interactive支持一系列不同的输入形式。您可以用换行符分隔它们:s 以使用多个。事实上,您可以提供一个表达式而不是一个字符串,执行它来执行任何交互操作。
编辑:
要创建缓冲区,您可以使用以下内容,它允许您使用所有标准打印功能在新缓冲区中插入任何内容:
(defun start-end (pos1 pos2 param1 param2)
(interactive "r\nsParam1: \nsParam2: ")
(with-output-to-temp-buffer "*Result*"
(princ (format "%d,%d,%s,%s" pos1 pos2 param1 param2))))
这是创建缓冲区的代码(如果它不存在),然后将您想要的文本附加到它:
(defun start-end (pos1 pos2)
(interactive "nStart: \nnEnd: ")
(switch-to-buffer (get-buffer-create "*start-end*"))
(goto-char (point-max))
(insert (format "start: %d. end: %d.\n" pos1 pos2)))