From 7e8539cc6857c26a02d6577ed5057d2a610e2fe1 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Wed, 12 Jan 2000 03:04:55 +0000 Subject: [PATCH] (with-syntax-table): Moved from simple.el. --- lisp/subr.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lisp/subr.el b/lisp/subr.el index f90d0d9da05..683bc247941 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1060,6 +1060,22 @@ in BODY." . ,body) (combine-after-change-execute))) +(defmacro with-syntax-table (table &rest body) + "Evaluate BODY with syntax table of current buffer set to a copy of 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." + (let ((old-table (gensym)) + (old-buffer (gensym))) + `(let ((,old-table (syntax-table)) + (,old-buffer (current-buffer))) + (unwind-protect + (progn + (set-syntax-table (copy-syntax-table ,table)) + ,@body) + (save-current-buffer + (set-buffer ,old-buffer) + (set-syntax-table ,old-table)))))) (defvar save-match-data-internal) -- 2.39.5