12

How can I post a block of Emacs Lisp code?

How can I post some buffer content including special characters and not have them interpreted as markup?

0

To include some text in a monospaced font with no formatting, put ``` on a line on its own, then the text, then a ``` line again. You may be familiar with this syntax from Github and other Markdown engines. This syntax is now available on Stack Exchange. Thanks balpha! You can use ~~~ instead of ``` if you prefer.


Here's an example:

This paragraph is <pre>formatted.
It uses a `code fence'.

The part of this post between the two horizontal lines above uses the following source syntax:

Here's an example:
```
This paragraph is <pre>formatted.
It uses a `code fence'.
```

You can get the same effect by indenting the preformatted block with four spaces.

To typeset Emacs Lisp code, start with ```lang-el or ~~~lang-el instead of a plain ``` or ~~~. This turns on syntax-based coloring.

(if syntax-indicator (setq coloring t))

can be entered with

```lang-elisp
(if syntax-indicator (setq coloring t))
```

To get syntax coloring with four-space-indent code blocks, put <!-- language: lang-el --> in a paragraph of its own immediately before the code block. To get syntax coloring on all the code blocks in an answer, put <!-- language-all: lang-el --> before the first code block.

If you include a code snippet in some other programming language, you can get syntax coloring with the appropriate lang-xxx indicator. (Note that on Emacs.SE, because most of the code is Elisp regardless of the tags on a question, the code highlighting is not based on tags.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .