From a8674a4b29bd0a184979797a61f3e7bba252ec69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerd=20M=C3=B6llmann?= Date: Fri, 28 Oct 2022 15:38:36 +0200 Subject: [PATCH] Improve check for binding etc *package* * src/pkg.c (Fwatch_earmuffs_package): Check the makunbound case specially. (syms_of_pkg): Remove duplicate code. * test/src/pkg-tests.el (pkg-tests-*package*): Add tests. --- src/pkg.c | 18 ++++++++++++------ test/src/pkg-tests.el | 7 ++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/pkg.c b/src/pkg.c index 21feb12dea0..7f78c61cf32 100644 --- a/src/pkg.c +++ b/src/pkg.c @@ -27,6 +27,7 @@ along with GNU Emacs. If not, see . */ #include #include "lisp.h" +#include "buffer.h" #include "character.h" /*********************************************************************** @@ -102,7 +103,8 @@ h_next (struct h_iter *it) /* Sometimes useful for setting a breakpoint, after inserting it somewhere in the code. */ -void pkg_break (void) +void +pkg_break (void) { } @@ -891,9 +893,15 @@ DEFUN ("watch-*package*", Fwatch_earmuffs_package, Swatch_earmuffs_package, (Lisp_Object symbol, Lisp_Object newval, Lisp_Object operation, Lisp_Object where) { - if (!PACKAGEP (newval)) - error ("%s must be bound or set to a package object", - SDATA (SYMBOL_NAME (symbol))); + if (EQ (operation, Qmakunbound)) + { + if (!BUFFERP (where)) + error ("Cannot makunbound %s", SDATA (SYMBOL_NAME (symbol))); + } + else if (!PACKAGEP (newval)) + error ("%s must alwasy be bound to a package object (operation %s)", + SDATA (SYMBOL_NAME (symbol)), + SDATA (SYMBOL_NAME (operation))); return Qnil; } @@ -1003,8 +1011,6 @@ syms_of_pkg (void) doc: /* */); Fmake_variable_buffer_local (Qpackage_prefixes); - Fmake_variable_buffer_local (Qpackage_prefixes); - Fprovide (Qsymbol_packages, Qnil); } diff --git a/test/src/pkg-tests.el b/test/src/pkg-tests.el index 819a74dae65..df44859fa42 100644 --- a/test/src/pkg-tests.el +++ b/test/src/pkg-tests.el @@ -50,7 +50,12 @@ (should (eq (let ((*package* (find-package "emacs"))) 'good) 'good)) (should-error (let ((*package* :emacs)) nil)) (should-error (let ((*package* 1)))) - (should-error (setq *package* :keyword))) + (should-error (setq *package* :keyword)) + (should-error (makunbound *package*)) + (with-temp-buffer + (in-package* :emacs-user) + (kill-all-local-variables) + (should (eq *package* (find-package :emacs))))) (ert-deftest pkg-tests-standard-packages () (should (packagep (find-package "emacs"))) -- 2.39.2