aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/subr.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el16
1 files changed, 16 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index f90d0d9da0..683bc24794 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)