emacs-diffs
[Top][All Lists]
Advanced

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

master 3a99f96: Improve handling of coding-system mnemonic indicators


From: Eli Zaretskii
Subject: master 3a99f96: Improve handling of coding-system mnemonic indicators
Date: Sun, 23 Aug 2020 14:25:59 -0400 (EDT)

branch: master
commit 3a99f966dc2dc9fb3922340caa0016b305789977
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    Improve handling of coding-system mnemonic indicators
    
    This fixes assertion violations when the mnemonic is
    given as a string, and allows non-ASCII characters be
    used as mode-line mnemonic of a coding-system.
    * src/xdisp.c (decode_mode_spec_coding): Handle multibyte
    characters as coding-system's mnemonic.
    (display_mode_element): If decode_mode_spec returns a multibyte
    string, display it as multibyte.
    * src/coding.c (Fdefine_coding_system_internal)
    (Fcoding_system_put): If :mnemonic is a string, use its first
    character.  This avoids assertion violations if someone uses a
    string as the mnemonic of a coding-system.
---
 src/coding.c | 10 ++++++++--
 src/xdisp.c  | 12 +++++++++---
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/coding.c b/src/coding.c
index 51bd441..221a9ca 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -10895,7 +10895,10 @@ usage: (define-coding-system-internal ...)  */)
   ASET (attrs, coding_attr_base_name, name);
 
   Lisp_Object val = args[coding_arg_mnemonic];
-  if (! STRINGP (val))
+  /* decode_mode_spec_coding assumes the mnemonic is a single character.  */
+  if (STRINGP (val))
+    val = make_fixnum (STRING_CHAR (SDATA (val)));
+  else
     CHECK_CHARACTER (val);
   ASET (attrs, coding_attr_mnemonic, val);
 
@@ -11408,7 +11411,10 @@ DEFUN ("coding-system-put", Fcoding_system_put, 
Scoding_system_put,
   attrs = AREF (spec, 0);
   if (EQ (prop, QCmnemonic))
     {
-      if (! STRINGP (val))
+      /* decode_mode_spec_coding assumes the mnemonic is a single character.  
*/
+      if (STRINGP (val))
+       val = make_fixnum (STRING_CHAR (SDATA (val)));
+      else
        CHECK_CHARACTER (val);
       ASET (attrs, coding_attr_mnemonic, val);
     }
diff --git a/src/xdisp.c b/src/xdisp.c
index e2ebbbd..9d2bec3 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -25637,6 +25637,11 @@ display_mode_element (struct it *it, int depth, int 
field_width, int precision,
                    spec = decode_mode_spec (it->w, c, field, &string);
                    eassert (NILP (string) || STRINGP (string));
                    multibyte = !NILP (string) && STRING_MULTIBYTE (string);
+                   /* Non-ASCII characters in SPEC should cause mode-line
+                      element be displayed as a multibyte string.  */
+                   ptrdiff_t nbytes = strlen (spec);
+                   if (multibyte_chars_in_text (spec, nbytes) != nbytes)
+                     multibyte = true;
 
                    switch (mode_line_target)
                      {
@@ -26255,9 +26260,10 @@ decode_mode_spec_coding (Lisp_Object coding_system, 
char *buf, bool eol_flag)
       attrs = AREF (val, 0);
       eolvalue = AREF (val, 2);
 
-      *buf++ = multibyte
-       ? XFIXNAT (CODING_ATTR_MNEMONIC (attrs))
-       : ' ';
+      if (multibyte)
+       buf += CHAR_STRING (XFIXNAT (CODING_ATTR_MNEMONIC (attrs)), buf);
+      else
+       *buf++ = ' ';
 
       if (eol_flag)
        {



reply via email to

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