Search code examples
elisp

Emacs lisp; how to make a string from a variable of any type?


Like error messages for wrongly called functions show, eg.:

(message (file-attributes "."))

Produces the message:

"eval: Wrong type argument: stringp, ("/home14/tjones" 1 0 0 (20415 35598) (20211 19255) (20211 19255) 14 "lrwxrwxrwx" t ...)"

How do you do this type of translation intentionally, eg.:

(message (thing-to-string (file-attributes ".")))

To message something like:

("/home14/tjones" 1 0 0 (20415 35598) (20211 19255) (20211 19255) 14 "lrwxrwxrwx" t ...)

This is for debugging/info only. I'm assuming there's a way as message is doing it, but is this exposed to us users?


Solution

  • Look into prin1-to-string and related functions (prin1, princ, etc). And do try the manual! http://www.gnu.org/software/emacs/manual/html_node/elisp/Output-Functions.html