Function: with-mode-local-symbol

with-mode-local-symbol is a macro defined in mode-local.el.gz.

Signature

(with-mode-local-symbol MODE &rest BODY)

Documentation

With the local bindings of MODE symbol, evaluate BODY.

The current mode bindings are saved, BODY is evaluated, and the saved bindings are restored, even in case of an abnormal exit. Value is what BODY returns. This is like with-mode-local, except that MODE's value is used. To use the symbol MODE (quoted), use with-mode-local.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/mode-local.el.gz
(defmacro with-mode-local-symbol (mode &rest body)
  "With the local bindings of MODE symbol, evaluate BODY.
The current mode bindings are saved, BODY is evaluated, and the saved
bindings are restored, even in case of an abnormal exit.
Value is what BODY returns.
This is like `with-mode-local', except that MODE's value is used.
To use the symbol MODE (quoted), use `with-mode-local'."
  (declare (indent 1))
  (let ((old-mode  (make-symbol "mode"))
        (old-locals (make-symbol "old-locals"))
	(new-mode (make-symbol "new-mode"))
        (local (make-symbol "local")))
    `(let ((,old-mode mode-local-active-mode)
           (,old-locals nil)
	   (,new-mode ,mode)
	   )
       (unwind-protect
           (progn
             (mode-local--deactivate-bindings ,old-mode)
             (setq mode-local-active-mode ,new-mode)
             ;; Save the previous value of buffer-local variables
             ;; changed by `mode-local--activate-bindings'.
             (setq ,old-locals (mode-local--activate-bindings ,new-mode))
             ,@body)
         (mode-local--deactivate-bindings ,new-mode)
         ;; Restore the previous value of buffer-local variables.
         (dolist (,local ,old-locals)
           (set (car ,local) (cdr ,local)))
         ;; Restore the mode local variables.
         (setq mode-local-active-mode ,old-mode)
         (mode-local--activate-bindings ,old-mode)))))