Function: with-syntax-table

with-syntax-table is a macro defined in subr.el.gz.

Signature

(with-syntax-table TABLE &rest BODY)

Documentation

Evaluate BODY with syntax table of current buffer set to TABLE.

The syntax table of the current buffer is saved, BODY is evaluated, and the saved table is restored, even in case of an abnormal exit. Value is what BODY returns.

Probably introduced at or before Emacs version 21.1.

Aliases

ediff-with-syntax-table (obsolete since 27.1)

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
;;;; Syntax tables.

(defmacro with-syntax-table (table &rest body)
  "Evaluate BODY with syntax table of current buffer set to TABLE.
The syntax table of the current buffer is saved, BODY is evaluated, and the
saved table is restored, even in case of an abnormal exit.
Value is what BODY returns."
  (declare (debug t) (indent 1))
  (let ((old-table (make-symbol "table"))
	(old-buffer (make-symbol "buffer")))
    `(let ((,old-table (syntax-table))
	   (,old-buffer (current-buffer)))
       (unwind-protect
	   (progn
	     (set-syntax-table ,table)
	     ,@body)
	 (save-current-buffer
	   (set-buffer ,old-buffer)
	   (set-syntax-table ,old-table))))))