In common-lisp we have the library cl-heredoc, is there an equivalent in EmacsLisp?
Ordinary Emacs Lisp strings are multi-line-capable. You can simply put newlines in them.
cl-heredoc, it sounds like what you are looking for is "raw" strings. There was a proposal to add these to elisp a while back, but unfortunately it was rejected. (I hope rather than expect it could be resurrected.) Nor does elisp have the reader extensibility features needed to implement this oneself.
Last time the topic of user-defined reader macros came up, everyone seemed in favor. So I'm sure the only obstacle is human effort. Feb 1, 2015 at 10:14
If you are configuring emacs via an init.el file you might want to consider using an init.org instead.
Then you can use constructs like the following:
#+NAME: arbitrary-text #+begin_src xml <some> <random src="xml">or whatever... includes syntax highlighting!</random> </some> #+end_src #+begin_src emacs-lisp :var arb-text=arbitrary-text (eval `(defun a-test () (format "whoop there it is: %S" ,arb-text))) #+end_src
If you look in the generated
.el file you will see something like:
(let ((arb-text "escaped text here...")) (eval `(defun a-test () (format "whoop there it is: %S" ,arb-text))))
You can put the text and the code in any order. You can add names to Org lists, tables etc.
If this is for a library where you may not want to force collaborators to also use 'literate programming' then you could put the bulk of the code into an
.el file and generate an auxiliary
.el file using Org -- check the generated code into revision control.
4Maybe I'm missing something, but I don't see what init.org has to do with multi line strings. Jan 31, 2015 at 18:14
1@Malabarba: tl;dr: if you write your elisp in org-mode, you can do something sorta reminiscent of heredocs; otherwise, you've got to escape some stuff inside your multi-line string literals -- mostly
` and"`, iirc.– SamBJan 31, 2015 at 22:55
This is an interesting way around the problem, but a little too convoluted for my cases.– ocodoFeb 1, 2015 at 0:52
(format "next word is quoted %S" "word").
prin1). So, it will print its argument in a way suitable for the reader, for strings that would be with quotes.