(error "%s does not contain a symbol %s"
(package-name package) name))))
+;;;###autoload
(cl-defun buffer-package (&optional (buffer (current-buffer)))
"Return the value of *package* set in BUFFER.
BUFFER must be either a buffer object or the name of an existing buffer."
- (let ((buffer (if (bufferp buffer)
- buffer
- (get-buffer buffer))))
- (with-current-buffer buffer
- (default-buffer-local-value '*package*))))
+ (let ((buffer (or (get-buffer buffer)
+ (error "Buffer not found: %s" buffer))))
+ (default-buffer-local-value '*package* buffer)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Macros
}
static union specbinding *
-default_buffer_local_binding (Lisp_Object symbol)
+default_buffer_local_binding (Lisp_Object symbol, Lisp_Object buffer)
{
union specbinding *binding = NULL;
- union specbinding *pdl = specpdl_ptr;
- while (pdl > specpdl)
- {
- switch ((--pdl)->kind)
- {
- case SPECPDL_LET_LOCAL:
- case SPECPDL_LET_DEFAULT:
- case SPECPDL_LET:
- if (EQ (specpdl_symbol (pdl), symbol))
- binding = pdl;
- break;
- default: break;
- }
- }
+ for (union specbinding *pdl = specpdl_ptr - 1; pdl >= specpdl; --pdl)
+ if (pdl->kind == SPECPDL_LET_LOCAL
+ && EQ (specpdl_symbol (pdl), symbol)
+ && EQ (pdl->let.where, buffer))
+ binding = pdl;
+
return binding;
}
return false;
}
+// clang-format off
+
DEFUN ("default-toplevel-value", Fdefault_toplevel_value, Sdefault_toplevel_value, 1, 1, 0,
doc: /* Return SYMBOL's toplevel default value.
"Toplevel" means outside of any let binding. */)
xsignal1 (Qvoid_variable, symbol);
}
-DEFUN ("default-buffer-local-value", Fdefault_buffer_local_value, Sdefault_buffer_local_value, 1, 1, 0,
- doc: /* Return SYMBOL's toplevel buffer-local value. */)
- (Lisp_Object symbol)
+DEFUN ("default-buffer-local-value", Fdefault_buffer_local_value,
+ Sdefault_buffer_local_value, 2, 2, 0,
+ doc: /* Return SYMBOL's toplevel buffer-local value in BUFFER. */)
+ (Lisp_Object symbol, Lisp_Object buffer)
{
- union specbinding *binding = default_buffer_local_binding (symbol);
+ union specbinding *binding = default_buffer_local_binding (symbol, buffer);
Lisp_Object value
= binding ? specpdl_old_value (binding) : Fdefault_value (symbol);
if (!BASE_EQ (value, Qunbound))
return Qnil;
}
+// clang-format on
+
static Lisp_Object
defvar (Lisp_Object sym, Lisp_Object initvalue, Lisp_Object docstring, bool eval)
{