Search code examples
elisp

Declare a string in elisp and then inserting it in emacs lisp


I want to create i string and then insert it, but i get the error wrong argument char-or-stringp. What does it mean?

(defun test ()

   (string "1 2 3")
 )


(insert (test))

Solution

  • Your string call is incorrect. "1 2 3" is already a string. You seem to be looking for simply

    (insert "1 2 3")
    

    or if you want to demonstrate a function call,

    (defun test ()
      "1 2 3")
    
    (insert (test))
    

    The string form expects a sequence of characters, like this:

    (string ?1 ? ?2 ? ?3)
    => "1 2 3"