diff options
| author | Glenn Morris | 2012-01-18 23:21:25 -0800 |
|---|---|---|
| committer | Glenn Morris | 2012-01-18 23:21:25 -0800 |
| commit | 1259009aa17da6dc038afff96963f6d9bbd3b8e1 (patch) | |
| tree | 83be407107aea29bea07036e65c41b1c0ea99475 /src | |
| parent | 54de86ac6216fc2eece477308dde090381d6b6c7 (diff) | |
| parent | 685305ebe0455a8d5211bedf41b588bccfb432c8 (diff) | |
| download | emacs-1259009aa17da6dc038afff96963f6d9bbd3b8e1.tar.gz emacs-1259009aa17da6dc038afff96963f6d9bbd3b8e1.zip | |
Merge from emacs-23; up to 2012-01-19T07:15:48Z!rgm@gnu.org.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/character.c | 67 |
2 files changed, 35 insertions, 38 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index aa4e92b4134..3a6e31eede4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2012-01-19 Kenichi Handa <handa@m17n.org> | ||
| 2 | |||
| 3 | * character.c (char_width): New function. | ||
| 4 | (Fchar_width, c_string_width, lisp_string_width): | ||
| 5 | Use char_width (Bug#9496). | ||
| 6 | |||
| 1 | 2012-01-16 Martin Rudalics <rudalics@gmx.at> | 7 | 2012-01-16 Martin Rudalics <rudalics@gmx.at> |
| 2 | 8 | ||
| 3 | * window.c (Vwindow_persistent_parameters): New variable. | 9 | * window.c (Vwindow_persistent_parameters): New variable. |
diff --git a/src/character.c b/src/character.c index a2cb416d770..593fbcece0b 100644 --- a/src/character.c +++ b/src/character.c | |||
| @@ -308,6 +308,31 @@ If the multibyte character does not represent a byte, return -1. */) | |||
| 308 | } | 308 | } |
| 309 | } | 309 | } |
| 310 | 310 | ||
| 311 | |||
| 312 | /* Return width (columns) of C considering the buffer display table DP. */ | ||
| 313 | |||
| 314 | static int | ||
| 315 | char_width (int c, struct Lisp_Char_Table *dp) | ||
| 316 | { | ||
| 317 | int width = CHAR_WIDTH (c); | ||
| 318 | |||
| 319 | if (dp) | ||
| 320 | { | ||
| 321 | Lisp_Object disp = DISP_CHAR_VECTOR (dp, c), ch; | ||
| 322 | int i; | ||
| 323 | |||
| 324 | if (VECTORP (disp)) | ||
| 325 | for (i = 0, width = 0; i < ASIZE (disp); i++) | ||
| 326 | { | ||
| 327 | ch = AREF (disp, i); | ||
| 328 | if (CHARACTERP (ch)) | ||
| 329 | width += CHAR_WIDTH (XFASTINT (ch)); | ||
| 330 | } | ||
| 331 | } | ||
| 332 | return width; | ||
| 333 | } | ||
| 334 | |||
| 335 | |||
| 311 | DEFUN ("char-width", Fchar_width, Schar_width, 1, 1, 0, | 336 | DEFUN ("char-width", Fchar_width, Schar_width, 1, 1, 0, |
| 312 | doc: /* Return width of CHAR when displayed in the current buffer. | 337 | doc: /* Return width of CHAR when displayed in the current buffer. |
| 313 | The width is measured by how many columns it occupies on the screen. | 338 | The width is measured by how many columns it occupies on the screen. |
| @@ -315,21 +340,11 @@ Tab is taken to occupy `tab-width' columns. | |||
| 315 | usage: (char-width CHAR) */) | 340 | usage: (char-width CHAR) */) |
| 316 | (Lisp_Object ch) | 341 | (Lisp_Object ch) |
| 317 | { | 342 | { |
| 318 | Lisp_Object disp; | ||
| 319 | int c, width; | 343 | int c, width; |
| 320 | struct Lisp_Char_Table *dp = buffer_display_table (); | ||
| 321 | 344 | ||
| 322 | CHECK_CHARACTER (ch); | 345 | CHECK_CHARACTER (ch); |
| 323 | c = XINT (ch); | 346 | c = XINT (ch); |
| 324 | 347 | width = char_width (c, buffer_display_table ()); | |
| 325 | /* Get the way the display table would display it. */ | ||
| 326 | disp = dp ? DISP_CHAR_VECTOR (dp, c) : Qnil; | ||
| 327 | |||
| 328 | if (VECTORP (disp)) | ||
| 329 | width = sanitize_char_width (ASIZE (disp)); | ||
| 330 | else | ||
| 331 | width = CHAR_WIDTH (c); | ||
| 332 | |||
| 333 | return make_number (width); | 348 | return make_number (width); |
| 334 | } | 349 | } |
| 335 | 350 | ||
| @@ -350,22 +365,9 @@ c_string_width (const unsigned char *str, EMACS_INT len, int precision, | |||
| 350 | 365 | ||
| 351 | while (i_byte < len) | 366 | while (i_byte < len) |
| 352 | { | 367 | { |
| 353 | int bytes, thiswidth; | 368 | int bytes; |
| 354 | Lisp_Object val; | ||
| 355 | int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes); | 369 | int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes); |
| 356 | 370 | int thiswidth = char_width (c, dp); | |
| 357 | if (dp) | ||
| 358 | { | ||
| 359 | val = DISP_CHAR_VECTOR (dp, c); | ||
| 360 | if (VECTORP (val)) | ||
| 361 | thiswidth = sanitize_char_width (ASIZE (val)); | ||
| 362 | else | ||
| 363 | thiswidth = CHAR_WIDTH (c); | ||
| 364 | } | ||
| 365 | else | ||
| 366 | { | ||
| 367 | thiswidth = CHAR_WIDTH (c); | ||
| 368 | } | ||
| 369 | 371 | ||
| 370 | if (precision > 0 | 372 | if (precision > 0 |
| 371 | && (width + thiswidth > precision)) | 373 | && (width + thiswidth > precision)) |
| @@ -447,18 +449,7 @@ lisp_string_width (Lisp_Object string, EMACS_INT precision, | |||
| 447 | else | 449 | else |
| 448 | c = str[i_byte], bytes = 1; | 450 | c = str[i_byte], bytes = 1; |
| 449 | chars = 1; | 451 | chars = 1; |
| 450 | if (dp) | 452 | thiswidth = char_width (c, dp); |
| 451 | { | ||
| 452 | val = DISP_CHAR_VECTOR (dp, c); | ||
| 453 | if (VECTORP (val)) | ||
| 454 | thiswidth = sanitize_char_width (ASIZE (val)); | ||
| 455 | else | ||
| 456 | thiswidth = CHAR_WIDTH (c); | ||
| 457 | } | ||
| 458 | else | ||
| 459 | { | ||
| 460 | thiswidth = CHAR_WIDTH (c); | ||
| 461 | } | ||
| 462 | } | 453 | } |
| 463 | 454 | ||
| 464 | if (precision <= 0) | 455 | if (precision <= 0) |