Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert list to string in Emacs Lisp

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.

like image 517
jcubic Avatar asked Sep 24 '13 10:09

jcubic


4 Answers

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

like image 70
juanleon Avatar answered Nov 14 '22 14:11

juanleon


(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"
like image 45
Alexander Gromnitsky Avatar answered Nov 14 '22 14:11

Alexander Gromnitsky


Or

(prin1-to-string your-string)

Finally something special

(princ your-string)
like image 10
Andreas Röhler Avatar answered Nov 14 '22 15:11

Andreas Röhler


M-x pp-eval-expression RET c-offsets-alist RET
like image 1
muede Avatar answered Nov 14 '22 16:11

muede