emacs-diffs
[Top][All Lists]
Advanced

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

feature/pkg 647046687a: Fix priting of :1


From: Gerd Moellmann
Subject: feature/pkg 647046687a: Fix priting of :1
Date: Sat, 22 Oct 2022 03:28:31 -0400 (EDT)

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

    Fix priting of :1
    
    * src/print.c (print_symbol_name, print_symbol): Don't check for
    symbol names looking like a number when we have already printed a
    package prefix.
    * test/src/editfns-tests.el (format-%s-keywords): Test for :1.
---
 src/print.c               | 17 ++++++++++++-----
 test/src/editfns-tests.el |  4 ++--
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/print.c b/src/print.c
index 7cb7165cb0..0bae167c00 100644
--- a/src/print.c
+++ b/src/print.c
@@ -2196,9 +2196,11 @@ looks_like_number_p (Lisp_Object name)
 
 static void
 print_symbol_name (Lisp_Object name, Lisp_Object printcharfun,
-                  bool escape)
+                  bool escape, bool check_number)
 {
-  bool like_number_p = looks_like_number_p (name);
+  /* Don't check if the name looks like a number if we already know it
+     doesn't.  For example, for keywords.  */
+  bool like_number_p = check_number ? looks_like_number_p (name) : false;
   for (ptrdiff_t ibyte = 0, ichar = 0; ibyte < SBYTES (name);)
     {
       const int c = fetch_string_char_advance (name, &ichar, &ibyte);
@@ -2221,9 +2223,13 @@ print_symbol (Lisp_Object symbol, Lisp_Object 
printcharfun,
 {
   const Lisp_Object name = SYMBOL_NAME (symbol);
   const Lisp_Object package = SYMBOL_PACKAGE (symbol);
+  bool check_number_p = true;
 
   if (EQ (package, Vkeyword_package))
-    print_c_string (":", printcharfun);
+    {
+      print_c_string (":", printcharfun);
+      check_number_p = false;
+    }
   else if (EQ (package, Vearmuffs_package))
     ;
   else if (NILP (package))
@@ -2239,13 +2245,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);
+         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))
            print_c_string (":", printcharfun);
          else
            print_c_string ("::", printcharfun);
+         check_number_p = false;
        }
     }
 
@@ -2255,7 +2262,7 @@ print_symbol (Lisp_Object symbol, Lisp_Object 
printcharfun,
   if (SBYTES (name) == 0 && !EQ (package, Vkeyword_package))
     print_c_string ("##", printcharfun);
   else
-    print_symbol_name (name, printcharfun, escape);
+    print_symbol_name (name, printcharfun, escape, check_number_p);
 }
 
 
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index bffa7865d5..74327fcb32 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -427,7 +427,7 @@
     (should (= (field-end) (point-max)))))
 
 (ert-deftest format-%s-keywords ()
-  (should (string-equal (format "%s" :hansi) ":hansi")))
-
+  (should (string-equal (format "%s" :hansi) ":hansi"))
+  (should (string-equal (format "%s" :1) ":1")))
 
 ;;; editfns-tests.el ends here



reply via email to

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