How to convert list to string in Emacs Lisp

…衆ロ難τιáo~ 提交于 2019-12-03 04:50:05

问题


How can I convert a list to string so I can call insert or message with it? I need to display c-offsets-alist but I got Wrong type argument: char-or-string-p for insert or Wrong type argument: stringp for message.


回答1:


I am not sure of what you are trying to achieve, but format converts "stuff" to strings. For instance:

(format "%s" your-list)

will return a representation of your list. message uses format internally, so

(message "%s" your-list)

will print it




回答2:


(format) will embed parentheses in the string, e.g.:

ELISP> (format "%s" '("foo" "bar"))
"(foo bar)"

Thus if you need an analogue to Ruby/JavaScript-like join(), there is (mapconcat):

ELISP> (mapconcat 'identity '("foo" "bar") " ")
"foo bar"



回答3:


Or

(prin1-to-string your-string)

Finally something special

(princ your-string)



回答4:


M-x pp-eval-expression RET c-offsets-alist RET


来源:https://stackoverflow.com/questions/18979300/how-to-convert-list-to-string-in-emacs-lisp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!