From ef6e365d099f5f2cd75d8ca783436e503fa5dabe Mon Sep 17 00:00:00 2001 From: John Paul Wallington Date: Sat, 29 Mar 2003 02:57:19 +0000 Subject: [PATCH] (with-category-table): Use `make-symbol' to avoid variable capture. Set table within `unwind-protect'. Ensure table is restored in correct buffer. Add docstring. Basically, copy `with-syntax-table'. --- lisp/ChangeLog | 6 ++++++ lisp/international/mule.el | 24 +++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8a92d0d6b71..a7e5e0b7023 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2003-03-29 John Paul Wallington + + * international/mule.el (with-category-table): Use `make-symbol' + to avoid variable capture. Set table within `unwind-protect'. + Ensure table is restored in correct buffer. Add docstring. + 2003-03-29 Kenichi Handa * language/japan-util.el: If system-type is not for Windows, diff --git a/lisp/international/mule.el b/lisp/international/mule.el index d5e516ee059..0d96510edf8 100644 --- a/lisp/international/mule.el +++ b/lisp/international/mule.el @@ -593,7 +593,7 @@ character code range. Thus FUNC should iterate over [START, END]." (make-char charset (+ i start) (+ start chars -1))))))) (defun register-char-codings (coding-system safe-chars) - "This is an obsolete function. + "This is an obsolete function. It exists just for backward compatibility, and it does nothing.") (make-obsolete 'register-char-codings "Unnecessary function. Calling it has no effect." @@ -1985,12 +1985,22 @@ the table in `translation-table-vector'." (put 'with-category-table 'lisp-indent-function 1) -(defmacro with-category-table (category-table &rest body) - `(let ((current-category-table (category-table))) - (set-category-table ,category-table) - (unwind-protect - (progn ,@body) - (set-category-table current-category-table)))) +(defmacro with-category-table (table &rest body) + "Evaluate BODY with category table of current buffer set to TABLE. +The category table of the current buffer is saved, BODY is evaluated, +then the saved table is restored, even in case of an abnormal exit. +Value is what BODY returns." + (let ((old-table (make-symbol "old-table")) + (old-buffer (make-symbol "old-buffer"))) + `(let ((,old-table (category-table)) + (,old-buffer (current-buffer))) + (unwind-protect + (progn + (set-category-table ,table) + ,@body) + (save-current-buffer + (set-buffer ,old-buffer) + (set-category-table ,old-table)))))) (defun define-translation-hash-table (symbol table) "Define SYMBOL as the name of the hash translation TABLE for use in CCL. -- 2.39.2