diff options
| author | Stefan Monnier | 2008-03-26 20:46:47 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2008-03-26 20:46:47 +0000 |
| commit | 80e3db569f72e628b8fc999d39833dd4fdfca8d1 (patch) | |
| tree | 556beb30360872ee096664b46b5fb9e4fd573838 /src/indent.c | |
| parent | 6a1414ce27766c76f6a1cc37fefd4817c0f23eff (diff) | |
| download | emacs-80e3db569f72e628b8fc999d39833dd4fdfca8d1.tar.gz emacs-80e3db569f72e628b8fc999d39833dd4fdfca8d1.zip | |
(check_display_width): New fun.
(scan_for_column): Use it.
Diffstat (limited to 'src/indent.c')
| -rw-r--r-- | src/indent.c | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/indent.c b/src/indent.c index b4a47782e3e..5480cae2489 100644 --- a/src/indent.c +++ b/src/indent.c | |||
| @@ -504,6 +504,47 @@ current_column () | |||
| 504 | return col; | 504 | return col; |
| 505 | } | 505 | } |
| 506 | 506 | ||
| 507 | extern Lisp_Object Qspace, QCwidth, QCalign_to; | ||
| 508 | |||
| 509 | /* Check the presence of a display property and compute its width. | ||
| 510 | If a property was found and its width was found as well, return | ||
| 511 | its width (>= 0) and set the position of the end of the property | ||
| 512 | in ENDPOS. | ||
| 513 | Otherwise just return -1. */ | ||
| 514 | static int | ||
| 515 | check_display_width (EMACS_INT pos, EMACS_INT col, EMACS_INT *endpos) | ||
| 516 | { | ||
| 517 | Lisp_Object val, overlay; | ||
| 518 | |||
| 519 | if (CONSP (val = get_char_property_and_overlay | ||
| 520 | (make_number (pos), Qdisplay, Qnil, &overlay)) | ||
| 521 | && EQ (Qspace, XCAR (val))) | ||
| 522 | { /* FIXME: Use calc_pixel_width_or_height, as in term.c. */ | ||
| 523 | Lisp_Object plist = XCDR (val), prop; | ||
| 524 | int width = -1; | ||
| 525 | |||
| 526 | if ((prop = Fplist_get (plist, QCwidth), NATNUMP (prop))) | ||
| 527 | width = XINT (prop); | ||
| 528 | else if (FLOATP (prop)) | ||
| 529 | width = (int)(XFLOAT_DATA (prop) + 0.5); | ||
| 530 | else if ((prop = Fplist_get (plist, QCalign_to), NATNUMP (prop))) | ||
| 531 | width = XINT (prop) - col; | ||
| 532 | else if (FLOATP (prop)) | ||
| 533 | width = (int)(XFLOAT_DATA (prop) + 0.5) - col; | ||
| 534 | |||
| 535 | if (width >= 0) | ||
| 536 | { | ||
| 537 | EMACS_INT start; | ||
| 538 | if (OVERLAYP (overlay)) | ||
| 539 | *endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); | ||
| 540 | else | ||
| 541 | get_property_and_range (pos, Qdisplay, &val, &start, endpos, Qnil); | ||
| 542 | return width; | ||
| 543 | } | ||
| 544 | } | ||
| 545 | return -1; | ||
| 546 | } | ||
| 547 | |||
| 507 | /* Scanning from the beginning of the current line, stop at the buffer | 548 | /* Scanning from the beginning of the current line, stop at the buffer |
| 508 | position ENDPOS or at the column GOALCOL or at the end of line, whichever | 549 | position ENDPOS or at the column GOALCOL or at the end of line, whichever |
| 509 | comes first. | 550 | comes first. |
| @@ -560,8 +601,7 @@ scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol) | |||
| 560 | break; | 601 | break; |
| 561 | prev_col = col; | 602 | prev_col = col; |
| 562 | 603 | ||
| 563 | /* Check composition sequence. */ | 604 | { /* Check composition sequence. */ |
| 564 | { | ||
| 565 | int len, len_byte, width; | 605 | int len, len_byte, width; |
| 566 | 606 | ||
| 567 | if (check_composition (scan, scan_byte, end, | 607 | if (check_composition (scan, scan_byte, end, |
| @@ -575,6 +615,20 @@ scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol) | |||
| 575 | } | 615 | } |
| 576 | } | 616 | } |
| 577 | 617 | ||
| 618 | { /* Check display property. */ | ||
| 619 | EMACS_INT end; | ||
| 620 | int width = check_display_width (scan, col, &end); | ||
| 621 | if (width >= 0) | ||
| 622 | { | ||
| 623 | col += width; | ||
| 624 | if (end > scan) /* Avoid infinite loops with 0-width overlays. */ | ||
| 625 | { | ||
| 626 | scan = end; scan_byte = charpos_to_bytepos (scan); | ||
| 627 | continue; | ||
| 628 | } | ||
| 629 | } | ||
| 630 | } | ||
| 631 | |||
| 578 | c = FETCH_BYTE (scan_byte); | 632 | c = FETCH_BYTE (scan_byte); |
| 579 | 633 | ||
| 580 | /* See if there is a display table and it relates | 634 | /* See if there is a display table and it relates |