Is it possible to write a single line for an Elisp string:

"hello world"



Without inserting a newline character? (wrapping a string literal).

I read that adding a tilde at the end of the line does this in some lisp's, but its not working for me.


Yes, you can use a literal string that does not include the newline, so that the newline shows only for your code.

Use \ to escape the newline, so that it is not included in the string:

(setq foo "hello \

C-h v foo

"hello world"

One place where this is often used is in a doc string, where the literal string uses \\<...> or \\[...] constructs that make the doc string look long in the source code. When rendered as part of the help output the result might show a short key sequence, so you use \ to chop the literal string in the code but keep it all on one line in the help output.

For example, this doc-string sentence is all on one line, which appears as You can use this command only from the minibuffer (‘C-%’). in the help output. But in the source code does not appear as a single, long line - there is a newline after the \.

 You can use this command only from the minibuffer (`\\<minibuffer-local-completion-map>\

Edit, it seems multi-line literals are supported, keeping answer since it may be useful still.

You can however use concat. eg:

(concat "hello"

have you considered to use define-skeleton to insert predfined bloc of texts and more ? Emacs Skeleton

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.