bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#43866: 26.3; italian postfix additions


From: Juri Linkov
Subject: bug#43866: 26.3; italian postfix additions
Date: Wed, 21 Oct 2020 22:39:08 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>> >> (prin1 '(("'A" . [?Á])
>> >>          ("'E" . [?É])
>> >>          ("'I" . [?Í])
>> >>          ("'O" . [?Ó])
>> >>          ("'U" . [?Ú])
>> >>          ("'Y" . [?Ý]))
>> >>        (current-buffer))
>> >
>> > Why do you have to use prin1?
>>
>> Actually I need to use pp-to-string to pretty-print the list,
>> but pp-to-string calls '(prin1 object (current-buffer))'.
>
> prin1 accepts a function as its 2nd argument; can you use that?

I tried to use a function in the 2nd argument, but it's called
for every digit of the integer that represents a character,
so I don't know what to do with these digits.

However, do you think something like the following is a good idea?

Let-binding a new variable 'print-integers-as-chars' to t:

(let ((print-integers-as-chars t))
  (pp '(("'A" . [?Á])
        ("'E" . [?É])
        ("'I" . [?Í])
        ("'O" . [?Ó])
        ("'U" . [?Ú])
        ("'Y" . [?Ý]))
      (current-buffer)))

prints integers as characters:

(("'A" .  [?Á])
 ("'E" .  [?É])
 ("'I" .  [?Í])
 ("'O" .  [?Ó])
 ("'U" .  [?Ú])
 ("'Y" .  [?Ý]))

with this patch:

diff --git a/src/print.c b/src/print.c
index dca095f281..1755eea738 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1908,8 +1908,16 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, 
bool escapeflag)
     {
     case_Lisp_Int:
       {
-       int len = sprintf (buf, "%"pI"d", XFIXNUM (obj));
-       strout (buf, len, len, printcharfun);
+        if (!NILP (Vprint_integers_as_chars) && CHARACTERP (obj))
+          {
+            int len = sprintf (buf, "%s", SDATA (call1 (intern ("prin1-char"), 
obj)));
+            strout (buf, len, len, printcharfun);
+          }
+        else
+          {
+            int len = sprintf (buf, "%"pI"d", XFIXNUM (obj));
+            strout (buf, len, len, printcharfun);
+          }
       }
       break;
 
@@ -2247,6 +2255,10 @@ syms_of_print (void)
 that represents the number without losing information.  */);
   Vfloat_output_format = Qnil;
 
+  DEFVAR_LISP ("print-integers-as-chars", Vprint_integers_as_chars,
+              doc: /* Print integers as characters.  */);
+  Vprint_integers_as_chars = Qnil;
+
   DEFVAR_LISP ("print-length", Vprint_length,
               doc: /* Maximum length of list to print before abbreviating.
 A value of nil means no limit.  See also `eval-expression-print-length'.  */);

reply via email to

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