如何在Emacs Lisp中将列表转换为字符串

jcu*_*bic 28 string emacs elisp list

如何将列表转换为字符串以便我可以调用insertmessage使用它?我需要显示,c-offsets-alist但我得到Wrong type argument: char-or-string-p插入或Wrong type argument: stringp消息.

jua*_*eon 36

我不确定你想要实现什么,但format将"东西"转换为字符串.例如:

(format "%s" your-list)
Run Code Online (Sandbox Code Playgroud)

将返回您的列表的表示. message在内部使用格式,所以

(message "%s" your-list)
Run Code Online (Sandbox Code Playgroud)

会打印出来的

  • 用Lisp语法打印列表可能更好的`%S`而不是`%s`. (8认同)

Ale*_*sky 19

(format) 会在字符串中嵌入括号,例如:

ELISP> (format "%s" '("foo" "bar"))
"(foo bar)"
Run Code Online (Sandbox Code Playgroud)

因此,如果您需要类似Ruby/JavaScript的模拟join(),那么(mapconcat):

ELISP> (mapconcat 'identity '("foo" "bar") " ")
"foo bar"
Run Code Online (Sandbox Code Playgroud)


And*_*ler 8

要么

(prin1-to-string your-string)
Run Code Online (Sandbox Code Playgroud)

最后特别的东西

(princ your-string)
Run Code Online (Sandbox Code Playgroud)