emacs-diffs
[Top][All Lists]
Advanced

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

master 85da7b5: Make 'string-width' auto-composition aware


From: Eli Zaretskii
Subject: master 85da7b5: Make 'string-width' auto-composition aware
Date: Wed, 26 May 2021 13:09:53 -0400 (EDT)

branch: master
commit 85da7b57bc204c4cc6953156c1a9a4dc6e875541
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    Make 'string-width' auto-composition aware
    
    * src/composite.c (find_automatic_composition): Now extern.
    (char_composable_p): Don't assume 'unicode-category-table' is
    always available.
    * src/composite.h (find_automatic_composition): Add prototype.
    * src/character.c (lisp_string_width): Support automatic
    compositions; call 'find_automatic_composition' when
    'auto-composition-mode' is ON.
---
 src/character.c | 17 +++++++++++++++++
 src/composite.c | 10 +++++++---
 src/composite.h |  4 ++++
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/character.c b/src/character.c
index 41abb83..e0978bb 100644
--- a/src/character.c
+++ b/src/character.c
@@ -361,6 +361,23 @@ lisp_string_width (Lisp_Object string, ptrdiff_t from, 
ptrdiff_t to,
          chars = end - i;
          bytes = string_char_to_byte (string, end) - i_byte;
        }
+      else if (!NILP (BVAR (current_buffer, enable_multibyte_characters))
+              && ! NILP (Vauto_composition_mode)
+              && find_automatic_composition (i, -1, &ignore, &end, &val, 
string)
+              && end > i)
+       {
+         int j;
+         for (thiswidth = 0, j = 0; j < LGSTRING_GLYPH_LEN (val); j++)
+           {
+             Lisp_Object g = LGSTRING_GLYPH (val, j);
+
+             if (NILP (g))
+               break;
+             thiswidth += char_width (LGLYPH_CHAR (g), dp);
+           }
+         chars = end - i;
+         bytes = string_char_to_byte (string, end) - i_byte;
+       }
       else
        {
          int c;
diff --git a/src/composite.c b/src/composite.c
index f1c0112..17d5914 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -953,8 +953,12 @@ char_composable_p (int c)
   Lisp_Object val;
   return (c >= ' '
          && (c == ZERO_WIDTH_NON_JOINER || c == ZERO_WIDTH_JOINER
-             || (val = CHAR_TABLE_REF (Vunicode_category_table, c),
-                 (FIXNUMP (val) && (XFIXNUM (val) <= UNICODE_CATEGORY_Zs)))));
+             /* unicode-category-table may not be available during
+                dumping.  */
+             || (CHAR_TABLE_P (Vunicode_category_table)
+                 && (val = CHAR_TABLE_REF (Vunicode_category_table, c),
+                     (FIXNUMP (val)
+                      && (XFIXNUM (val) <= UNICODE_CATEGORY_Zs))))));
 }
 
 /* Update cmp_it->stop_pos to the next position after CHARPOS (and
@@ -1475,7 +1479,7 @@ struct position_record
    representing the composition, and return true.  Otherwise, *GSTRING to
    Qnil, and return false.  */
 
-static bool
+bool
 find_automatic_composition (ptrdiff_t pos, ptrdiff_t limit,
                            ptrdiff_t *start, ptrdiff_t *end,
                            Lisp_Object *gstring, Lisp_Object string)
diff --git a/src/composite.h b/src/composite.h
index c5d3c0f..75e5f9b 100644
--- a/src/composite.h
+++ b/src/composite.h
@@ -320,6 +320,10 @@ extern bool composition_gstring_p (Lisp_Object);
 extern int composition_gstring_width (Lisp_Object, ptrdiff_t, ptrdiff_t,
                                       struct font_metrics *);
 
+extern bool find_automatic_composition (ptrdiff_t, ptrdiff_t, ptrdiff_t *,
+                                       ptrdiff_t *, Lisp_Object *,
+                                       Lisp_Object);
+
 extern void composition_compute_stop_pos (struct composition_it *,
                                           ptrdiff_t, ptrdiff_t, ptrdiff_t,
                                           Lisp_Object);



reply via email to

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