changeset 27297:f5713c397636

(with-syntax-table): Moved from simple.el.
author Richard M. Stallman <rms@gnu.org>
date Wed, 12 Jan 2000 03:04:55 +0000
parents 6a6b75706812
children dbaaa90ea0eb
files lisp/subr.el
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Wed Jan 12 03:04:09 2000 +0000
+++ b/lisp/subr.el	Wed Jan 12 03:04:55 2000 +0000
@@ -1060,6 +1060,22 @@
 	 . ,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)