diff options
Diffstat (limited to 'src/character.h')
| -rw-r--r-- | src/character.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/character.h b/src/character.h index 063b5147dc9..5ae6cb8c49c 100644 --- a/src/character.h +++ b/src/character.h | |||
| @@ -556,6 +556,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 556 | } while (0) | 556 | } while (0) |
| 557 | 557 | ||
| 558 | 558 | ||
| 559 | /* Return a non-outlandish value for the tab width. */ | ||
| 560 | |||
| 561 | #define SANE_TAB_WIDTH(buf) \ | ||
| 562 | sanitize_tab_width (XFASTINT (BVAR (buf, tab_width))) | ||
| 563 | static inline int | ||
| 564 | sanitize_tab_width (EMACS_INT width) | ||
| 565 | { | ||
| 566 | return 0 < width && width <= 1000 ? width : 8; | ||
| 567 | } | ||
| 568 | |||
| 559 | /* Return the width of ASCII character C. The width is measured by | 569 | /* Return the width of ASCII character C. The width is measured by |
| 560 | how many columns C will occupy on the screen when displayed in the | 570 | how many columns C will occupy on the screen when displayed in the |
| 561 | current buffer. */ | 571 | current buffer. */ |
| @@ -563,12 +573,20 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 563 | #define ASCII_CHAR_WIDTH(c) \ | 573 | #define ASCII_CHAR_WIDTH(c) \ |
| 564 | (c < 0x20 \ | 574 | (c < 0x20 \ |
| 565 | ? (c == '\t' \ | 575 | ? (c == '\t' \ |
| 566 | ? XFASTINT (BVAR (current_buffer, tab_width)) \ | 576 | ? SANE_TAB_WIDTH (current_buffer) \ |
| 567 | : (c == '\n' ? 0 : (NILP (BVAR (current_buffer, ctl_arrow)) ? 4 : 2))) \ | 577 | : (c == '\n' ? 0 : (NILP (BVAR (current_buffer, ctl_arrow)) ? 4 : 2))) \ |
| 568 | : (c < 0x7f \ | 578 | : (c < 0x7f \ |
| 569 | ? 1 \ | 579 | ? 1 \ |
| 570 | : ((NILP (BVAR (current_buffer, ctl_arrow)) ? 4 : 2)))) | 580 | : ((NILP (BVAR (current_buffer, ctl_arrow)) ? 4 : 2)))) |
| 571 | 581 | ||
| 582 | /* Return a non-outlandish value for a character width. */ | ||
| 583 | |||
| 584 | static inline int | ||
| 585 | sanitize_char_width (EMACS_INT width) | ||
| 586 | { | ||
| 587 | return 0 <= width && width <= 1000 ? width : 1000; | ||
| 588 | } | ||
| 589 | |||
| 572 | /* Return the width of character C. The width is measured by how many | 590 | /* Return the width of character C. The width is measured by how many |
| 573 | columns C will occupy on the screen when displayed in the current | 591 | columns C will occupy on the screen when displayed in the current |
| 574 | buffer. */ | 592 | buffer. */ |
| @@ -576,9 +594,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 576 | #define CHAR_WIDTH(c) \ | 594 | #define CHAR_WIDTH(c) \ |
| 577 | (ASCII_CHAR_P (c) \ | 595 | (ASCII_CHAR_P (c) \ |
| 578 | ? ASCII_CHAR_WIDTH (c) \ | 596 | ? ASCII_CHAR_WIDTH (c) \ |
| 579 | : XINT (CHAR_TABLE_REF (Vchar_width_table, c))) | 597 | : sanitize_char_width (XINT (CHAR_TABLE_REF (Vchar_width_table, c)))) |
| 580 | 598 | ||
| 581 | /* If C is a variation selector, return the index numnber of the | 599 | /* If C is a variation selector, return the index of the |
| 582 | variation selector (1..256). Otherwise, return 0. */ | 600 | variation selector (1..256). Otherwise, return 0. */ |
| 583 | 601 | ||
| 584 | #define CHAR_VARIATION_SELECTOR_P(c) \ | 602 | #define CHAR_VARIATION_SELECTOR_P(c) \ |