我需要在我的Emacs Lisp函数中选择一个字符串。
答案 0 :(得分:15)
所选文本在Emacs Universe中称为区域。见How do I access the contents of the current region in Emacs Lisp?
答案 1 :(得分:4)
被接受的答案使我找到了正确的答案。我想把这段代码留给更多像我这样的elisp
初学者使用。 regionp
包含“选择”(在eslip中称为区域)作为elisp
函数中的变量。 if
条件检查该区域是否处于活动状态。
(defun get-selected-text (start end)
(interactive "r")
(if (use-region-p)
(let ((regionp (buffer-substring start end)))
(message regionp))))