emacs-diffs
[Top][All Lists]
Advanced

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

scratch/pkg 8d0c7f5e805: Preferably print package-local nickname


From: Gerd Moellmann
Subject: scratch/pkg 8d0c7f5e805: Preferably print package-local nickname
Date: Wed, 20 Dec 2023 03:15:30 -0500 (EST)

branch: scratch/pkg
commit 8d0c7f5e805cfdb5785b689d803f237628487eda
Author: Gerd Möllmann <gerd@gnu.org>
Commit: Gerd Möllmann <gerd@gnu.org>

    Preferably print package-local nickname
    
    If "package" has a local nickname "p", prefer printing package:foo as
    p:foo because that's why we have the nickname.
    
    * src/pkg.c (pkg_local_nickname): New function.
    * src/lisp.h: Declare new function.
    * src/print.c (print_symbol): Use it to find a nickname, if any.
---
 src/lisp.h  |  1 +
 src/pkg.c   | 22 +++++++++++++++-------
 src/print.c |  9 ++++++++-
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/src/lisp.h b/src/lisp.h
index daeb9e570bf..51b60ba58ba 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2317,6 +2317,7 @@ extern Lisp_Object pkg_find_symbol (Lisp_Object name, 
Lisp_Object package, Lisp_
 extern void pkg_in_emacs_package (void);
 extern Lisp_Object pkg_symbol_completion_string (Lisp_Object sym, Lisp_Object 
status);
 extern Lisp_Object pkg_strip_package_prefix (Lisp_Object string, Lisp_Object 
package);
+extern Lisp_Object pkg_local_nickname (Lisp_Object package);
 
 
 /* Return whether a value might be a valid docstring.
diff --git a/src/pkg.c b/src/pkg.c
index 3ad828d4ba5..28720c983f2 100644
--- a/src/pkg.c
+++ b/src/pkg.c
@@ -21,8 +21,7 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 /* Common Lisp style packages.
 
    Useful features that could be added:
-   hierarchical packages
-   package-local nicknames  */
+   hierarchical packages? */
 
 #include <config.h>
 #include "lisp.h"
@@ -144,16 +143,25 @@ pkg_find_package (Lisp_Object name)
   if (!NILP (local_nicknames))
     {
       const Lisp_Object entry = Fassoc (name, local_nicknames, Qnil);
-      if (!NILP (entry))
-       {
-         eassert (PACKAGEP (XCDR (entry)));
-         return XCDR (entry);
-       }
+      if (CONSP (entry))
+       return XCDR (entry);
     }
 
   return Fgethash (name, Vpackage_registry, Qnil);
 }
 
+/* If PACKAGE has a local nickname in the current package, return it,
+   else return nil.  */
+
+Lisp_Object
+pkg_local_nickname (Lisp_Object package)
+{
+  const Lisp_Object local_nicknames
+    = XPACKAGE (Vearmuffs_package)->local_nicknames;
+  const Lisp_Object entry = Frassoc (package, local_nicknames);
+  return CONSP (entry) ? XCAR (entry) : Qnil;
+}
+
 /* Register package PACKAGE in the package registry, that is, make it
    known under its name and all its nicknames.  */
 
diff --git a/src/print.c b/src/print.c
index 1483667ad1a..8d4ea3fcfc4 100644
--- a/src/print.c
+++ b/src/print.c
@@ -2316,7 +2316,14 @@ print_symbol (Lisp_Object symbol, Lisp_Object 
printcharfun,
       const bool accessible = !EQ (found, Qunbound);
       if (!accessible || !EQ (found, symbol))
        {
-         print_symbol_name (PACKAGE_NAMEX (package), printcharfun, escape, 
true);
+         /* If PACKAGE has a package-local nickname in the current
+            package, use that for printing, because that's why we
+            have the nickname.  */
+         const Lisp_Object nickname = pkg_local_nickname (package);
+         if (STRINGP (nickname))
+           print_symbol_name (nickname, printcharfun, escape, true);
+         else
+           print_symbol_name (PACKAGE_NAMEX (package), printcharfun, escape, 
true);
          const Lisp_Object found = pkg_find_symbol (name, package, &status);
          eassert (!EQ (found, Qunbound));
          if (EQ (status, QCexternal))



reply via email to

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