Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emacs
emacs
Commits
25ed9e61
Commit
25ed9e61
authored
Jan 13, 2012
by
Kenichi Handa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Take display-table into account on calculating character/string width (#Bug#9496).
parent
39ac3299
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
37 deletions
+35
-37
src/ChangeLog
src/ChangeLog
+6
-0
src/character.c
src/character.c
+29
-37
No files found.
src/ChangeLog
View file @
25ed9e61
2011-12-26 Kenichi Handa <handa@m17n.org>
* character.c (char_width): New function.
(Fchar_width, c_string_width, lisp_string_width): Use char_width
(Bug#9496).
2012-01-12 Sven Joachim <svenjoac@gmx.de>
* s/gnu-linux.h: Use CRT_DIR.
...
...
src/character.c
View file @
25ed9e61
...
...
@@ -361,6 +361,31 @@ usage: (char-bytes CHAR) */)
return
make_number
(
1
);
}
/* Return width (columns) of C considering the buffer display table DP. */
static
int
char_width
(
int
c
,
struct
Lisp_Char_Table
*
dp
)
{
int
width
=
CHAR_WIDTH
(
c
);
if
(
dp
)
{
Lisp_Object
disp
=
DISP_CHAR_VECTOR
(
dp
,
c
),
ch
;
int
i
;
if
(
VECTORP
(
disp
))
for
(
i
=
0
,
width
=
0
;
i
<
ASIZE
(
disp
);
i
++
)
{
ch
=
AREF
(
disp
,
i
);
if
(
CHARACTERP
(
ch
))
width
+=
CHAR_WIDTH
(
XFASTINT
(
ch
));
}
}
return
width
;
}
DEFUN
(
"char-width"
,
Fchar_width
,
Schar_width
,
1
,
1
,
0
,
doc
:
/* Return width of CHAR when displayed in the current buffer.
The width is measured by how many columns it occupies on the screen.
...
...
@@ -369,21 +394,12 @@ usage: (char-width CHAR) */)
(
ch
)
Lisp_Object
ch
;
{
Lisp_Object
disp
;
int
c
,
width
;
struct
Lisp_Char_Table
*
dp
=
buffer_display_table
();
CHECK_CHARACTER
(
ch
);
c
=
XINT
(
ch
);
/* Get the way the display table would display it. */
disp
=
dp
?
DISP_CHAR_VECTOR
(
dp
,
c
)
:
Qnil
;
if
(
VECTORP
(
disp
))
width
=
ASIZE
(
disp
);
else
width
=
CHAR_WIDTH
(
c
);
width
=
char_width
(
c
,
buffer_display_table
());
return
make_number
(
width
);
}
...
...
@@ -403,22 +419,9 @@ c_string_width (const unsigned char *str, int len, int precision, int *nchars, i
while
(
i_byte
<
len
)
{
int
bytes
,
thiswidth
;
Lisp_Object
val
;
int
bytes
;
int
c
=
STRING_CHAR_AND_LENGTH
(
str
+
i_byte
,
bytes
);
if
(
dp
)
{
val
=
DISP_CHAR_VECTOR
(
dp
,
c
);
if
(
VECTORP
(
val
))
thiswidth
=
XVECTOR_SIZE
(
val
);
else
thiswidth
=
CHAR_WIDTH
(
c
);
}
else
{
thiswidth
=
CHAR_WIDTH
(
c
);
}
int
thiswidth
=
char_width
(
c
,
dp
);
if
(
precision
>
0
&&
(
width
+
thiswidth
>
precision
))
...
...
@@ -499,18 +502,7 @@ lisp_string_width (string, precision, nchars, nbytes)
else
c
=
str
[
i_byte
],
bytes
=
1
;
chars
=
1
;
if
(
dp
)
{
val
=
DISP_CHAR_VECTOR
(
dp
,
c
);
if
(
VECTORP
(
val
))
thiswidth
=
XVECTOR_SIZE
(
val
);
else
thiswidth
=
CHAR_WIDTH
(
c
);
}
else
{
thiswidth
=
CHAR_WIDTH
(
c
);
}
thiswidth
=
char_width
(
c
,
dp
);
}
if
(
precision
>
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment