[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 23ad0f0: Don't account for character compositions in 'format' and
From: |
Eli Zaretskii |
Subject: |
master 23ad0f0: Don't account for character compositions in 'format' and friends |
Date: |
Sun, 30 May 2021 04:21:42 -0400 (EDT) |
branch: master
commit 23ad0f0c5adbeda9a0bd346138e2950cb5e5a136
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>
Don't account for character compositions in 'format' and friends
'lisp_string_width' is called from 'format' and 'format-message',
which can be called both very early into Emacs initialization and in
other contexts where using the font backend is impossible or
undesirable. So this commit changes 'lisp_string_width' to try
accounting for automatic compositions only when explicitly requested,
and only 'string-width' does that; 'format' and 'format-message'
don't.
* src/character.c (lisp_string_width): Accept an additional
argument AUTO_COMP; attempt accounting for auto-compositions only
if that argument is non-zero. (Bug#48732)
* src/editfns.c (styled_format):
* src/character.c (Fstring_width): Callers of 'lisp_string_width'
adjusted.
---
src/character.c | 13 ++++++++-----
src/character.h | 2 +-
src/editfns.c | 2 +-
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/character.c b/src/character.c
index e874cf5..70e6896 100644
--- a/src/character.c
+++ b/src/character.c
@@ -328,12 +328,14 @@ strwidth (const char *str, ptrdiff_t len)
compositions. If PRECISION > 0, return the width of longest
substring that doesn't exceed PRECISION, and set number of
characters and bytes of the substring in *NCHARS and *NBYTES
- respectively. FROM and TO are zero-based character indices
- that define the substring of STRING to consider. */
+ respectively. FROM and TO are zero-based character indices that
+ define the substring of STRING to consider. If AUTO_COMP is
+ non-zero, account for automatic compositions in STRING. */
ptrdiff_t
lisp_string_width (Lisp_Object string, ptrdiff_t from, ptrdiff_t to,
- ptrdiff_t precision, ptrdiff_t *nchars, ptrdiff_t *nbytes)
+ ptrdiff_t precision, ptrdiff_t *nchars, ptrdiff_t *nbytes,
+ bool auto_comp)
{
/* This set multibyte to 0 even if STRING is multibyte when it
contains only ascii and eight-bit-graphic, but that's
@@ -370,7 +372,8 @@ lisp_string_width (Lisp_Object string, ptrdiff_t from,
ptrdiff_t to,
bytes = string_char_to_byte (string, end) - i_byte;
}
#ifdef HAVE_WINDOW_SYSTEM
- else if (f && FRAME_WINDOW_P (f)
+ else if (auto_comp
+ && f && FRAME_WINDOW_P (f)
&& multibyte
&& find_automatic_composition (i, -1, &ignore, &end, &val,
string)
&& end > i)
@@ -471,7 +474,7 @@ usage: (string-width STRING &optional FROM TO) */)
CHECK_STRING (str);
validate_subarray (str, from, to, SCHARS (str), &ifrom, &ito);
- XSETFASTINT (val, lisp_string_width (str, ifrom, ito, -1, NULL, NULL));
+ XSETFASTINT (val, lisp_string_width (str, ifrom, ito, -1, NULL, NULL, true));
return val;
}
diff --git a/src/character.h b/src/character.h
index 75351cd..1a74548 100644
--- a/src/character.h
+++ b/src/character.h
@@ -573,7 +573,7 @@ extern ptrdiff_t strwidth (const char *, ptrdiff_t);
extern ptrdiff_t c_string_width (const unsigned char *, ptrdiff_t, int,
ptrdiff_t *, ptrdiff_t *);
extern ptrdiff_t lisp_string_width (Lisp_Object, ptrdiff_t, ptrdiff_t,
- ptrdiff_t, ptrdiff_t *, ptrdiff_t *);
+ ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool);
extern Lisp_Object Vchar_unify_table;
extern Lisp_Object string_escape_byte8 (Lisp_Object);
diff --git a/src/editfns.c b/src/editfns.c
index 182d3ba..aa0f46f 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3390,7 +3390,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool
message)
ptrdiff_t nch, nby;
nchars_string = SCHARS (arg);
width = lisp_string_width (arg, 0, nchars_string, prec,
- &nch, &nby);
+ &nch, &nby, false);
if (prec < 0)
nbytes = SBYTES (arg);
else
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 23ad0f0: Don't account for character compositions in 'format' and friends,
Eli Zaretskii <=