emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/pkg a8674a4b29: Improve check for binding etc *package*


From: Gerd Moellmann
Subject: feature/pkg a8674a4b29: Improve check for binding etc *package*
Date: Fri, 28 Oct 2022 09:39:42 -0400 (EDT)

branch: feature/pkg
commit a8674a4b29bd0a184979797a61f3e7bba252ec69
Author: Gerd Möllmann <gerd@gnu.org>
Commit: Gerd Möllmann <gerd@gnu.org>

    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 21feb12dea..7f78c61cf3 100644
--- a/src/pkg.c
+++ b/src/pkg.c
@@ -27,6 +27,7 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 #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 819a74dae6..df44859fa4 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")))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]