From: Richard M. Stallman Date: Wed, 12 Jan 2000 03:04:55 +0000 (+0000) Subject: (with-syntax-table): Moved from simple.el. X-Git-Tag: emacs-pretest-21.0.90~5374 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7e8539cc6857c26a02d6577ed5057d2a610e2fe1;p=emacs.git (with-syntax-table): Moved from simple.el. --- 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)