From GNU Emacs Manual: 20.6.2:

If you prefer Emacs to display a temporary buffer in a different fashion, we recommend to customize the variable display-buffer-alist (see Choosing a Window for Display in The Emacs Lisp Reference Manual). For example, to display *Completions* by splitting a window as described in the previous section, use the following form in your initialization file (see Init File):

'(("\\*Completions\\* display-buffer-pop-up-window)))

I've used the code above in my init file, and it works, but I have a question. What are the \\s doing in the Completions buffer name? Does it make any difference if you just write "*Completions*" instead? I've tried this, and I can't see any difference, but I'm worried I might be missing something.


Take a look at the documentation for display-buffer-alist (Use C-h v to describe the variable). You'll see that each entry consists of a condition and an action, and that the condition is either a regular expression or a function.

In your example, the string is interpreted as a regular expression. To match a literal * character, you can escape it (\\*) or put it in a character alternative ([*]) . Generally a * in a regular expression means "zero or more" of whatever precedes it.

It happens to work in your example, but it could match names other than just *Completions*. More specifically, without the slashes you are creating a regular expression that will match "*Completion" followed by zero or more "s" characters.

The double slash is required by the Lisp string syntax, because a single slash is itself interpreted as a special character. (E.g. "\n" to represent a newline character.)


  • the Lisp string "\\*foo\\*"
  • represents the character sequence \*foo\*
  • which, when interpreted as a regular expression, will match the literal sequence of characters *foo*
| improve this answer | |
  • I see, so the ` \\ ` stops the ` * ` being treated as a wildcard. But in that case, why isn't one ` \ ` enough? – tcelferact Feb 2 '17 at 21:05
  • That is due to how Emacs handles strings. The slash is itself a special character -- for example, the sequence \n in a string represents a newline. To include a literal slash in a string you need to escape that, `\\`. – glucas Feb 2 '17 at 21:14
  • Ok, so if I've understood this correctly, \\ is used as the escape character because \ followed by certain other characters performs its own unique function? – tcelferact Feb 2 '17 at 21:28
  • 1
    (minor) An alternative to escaping it using \\* is to use [*]. So it is not exactly true that "you need to escape it using \\*". – Drew Feb 2 '17 at 21:36
  • True. Also I believe a * at the beginning of a regexp is treated as a literal, since there is nothing to apply it to, so you could just use \\* or [*] for the one at the end. – glucas Feb 2 '17 at 21:44

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.