我正在编写简单的elisp函数,它具有三个交互参数: from、to和分离器。然后插入一个数字序列:
(defun gen-seq (from to sep)
"Generates sequence of numbers FROM .. TO with separator SEP"
(interactive "nFrom: \nnTo: \nMSeparator: ")
(insert (mapconcat 'number-to-string (number-sequence from to) sep)))但是,当sep是\n时,它会生成类似于
1\n2\n3\n4\n5\n6\n7\n8\n9\n10是否有可能在我的Emacs缓冲区中使用此函数实现一列数字?
发布于 2017-05-09 01:35:17
可以输入C-q C-j作为分隔符输入换行符。有关详细信息,请参阅emacs手册中的插入文本。
发布于 2017-05-09 03:13:07
Nick的回答是输入换行符的标准方法,但如果您真的希望Emacs将字符串参数作为引用的字符串读入,则可以这样做:
(defun gen-seq (from to sep)
"Generates sequence of numbers FROM .. TO with separator SEP"
(interactive "nFrom: \nnTo: \nMSeparator: ")
(let* ((sepesc (replace-regexp-in-string "\"" "\\\\\"" sep))
(sepnew (car (read-from-string (concat "\"" sepesc "\"")))))
(insert (mapconcat 'number-to-string (number-sequence from to) sepnew))))您也可以使用(interactive "x")来读取参数,除非用户需要键入双引号:"\n"。
https://stackoverflow.com/questions/43858781
复制相似问题