Emacs Lisp: Block of Expression

By Xah Lee. Date: .

Sometimes you need to group several expressions together as one single expression. This can be done with progn.

(progn
  (message "a")
  (message "b"))

;; is equivalent to
(message "a")
(message "b")

The purpose of (progn …) is similar to a block of code {…} in C-like languages. It is used to group together a bunch of expressions into one single parenthesized expression. Most of the time it's used inside “if”.

(if something
    (progn ; true
      ;; code here
      )
  (progn ; else
    ;; code here
    ))

progn returns the last expression in its body.

(progn 3 4 ) ; 4

(info "(elisp) Sequencing")

Lisp Basics

ErgoEmacs mascot-s276x226
Buy Xah Emacs Tutorial

Lisp Basics

Basics

Lisp Data Structure

Function

Lisp Symbol

Lisp Misc

Working with Elisp