ELisp: How to execute several expressions in 'else' block?

elisp, emacs

Solution

You don't need `progn` for this, as this is already the default behaviour:

C-hf `if` RET

if is a special form in `C source code'.

(if COND THEN ELSE...)

If COND yields non-nil, do THEN, else do ELSE... Returns the value of THEN or the value of the last of the ELSE's. THEN must be one expression, but ELSE... can be zero or more expressions. If COND yields nil, and there are no ELSE's, the value is nil.

To re-use sindikat's example:

(if (> 1 2)
    (message "True")
  (message "False")
  (message "I repeat, completely false"))

You would, of course, use `progn` if you wished to evaluate multiple expressions in the `THEN` form.

Problem

How can I execute more than one expression in the `else` block of an `if` statement, when using ELisp?

Original source