diff options
| author | Richard M. Stallman | 1997-09-13 08:44:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-09-13 08:44:55 +0000 |
| commit | be9778f8dec0000095275916fb9b262804948cf7 (patch) | |
| tree | 56c0f17f512942c83931e714ae31b6b35434e37d /lisp | |
| parent | a3788d533273afd5e3cd6b0441ebf1cf1f3f2b88 (diff) | |
| download | emacs-be9778f8dec0000095275916fb9b262804948cf7.tar.gz emacs-be9778f8dec0000095275916fb9b262804948cf7.zip | |
(truncate-string-to-width):
Rename arg WIDTH to END-COLUMN. Fix the case when START-COLUMN
is after END-COLUMN. Doc fixes.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/international/mule-util.el | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/lisp/international/mule-util.el b/lisp/international/mule-util.el index 7a5bbe03775..fb5cc61eeeb 100644 --- a/lisp/international/mule-util.el +++ b/lisp/international/mule-util.el | |||
| @@ -73,12 +73,20 @@ TYPE should be `list' or `vector'." | |||
| 73 | string)) | 73 | string)) |
| 74 | 74 | ||
| 75 | ;;;###autoload | 75 | ;;;###autoload |
| 76 | (defun truncate-string-to-width (str width &optional start-column padding) | 76 | (defun truncate-string-to-width (str end-column &optional start-column padding) |
| 77 | "Truncate string STR to fit in WIDTH columns. | 77 | "Truncate string STR to end at column END-COLUMN. |
| 78 | Optional 1st arg START-COLUMN if non-nil specifies the starting column. | 78 | The optional 2nd arg START-COLUMN, if non-nil, specifies |
| 79 | Optional 2nd arg PADDING if non-nil is a padding character to be padded at | 79 | the starting column; that means to return the characters occupying |
| 80 | the head and tail of the resulting string to fit in WIDTH if necessary. | 80 | columns START-COLUMN ... END-COLUMN of STR. |
| 81 | If PADDING is nil, the resulting string may be narrower than WIDTH." | 81 | |
| 82 | The optional 3rd arg PADDING, if non-nil, specifies a padding character | ||
| 83 | to add at the end of the result if STR doesn't reach column END-COLUMN, | ||
| 84 | or if END-COLUMN comes in the middle of a character in STR. | ||
| 85 | PADDING is also added at the beginning of the result | ||
| 86 | if column START-COLUMN appears in the middle fo a character in STR. | ||
| 87 | |||
| 88 | If PADDING is nil, no padding is added in these cases, so | ||
| 89 | the resulting string may be narrower than END-COLUMN." | ||
| 82 | (or start-column | 90 | (or start-column |
| 83 | (setq start-column 0)) | 91 | (setq start-column 0)) |
| 84 | (let ((len (length str)) | 92 | (let ((len (length str)) |
| @@ -93,22 +101,24 @@ If PADDING is nil, the resulting string may be narrower than WIDTH." | |||
| 93 | idx (+ idx (char-bytes ch)))) | 101 | idx (+ idx (char-bytes ch)))) |
| 94 | (args-out-of-range (setq idx len))) | 102 | (args-out-of-range (setq idx len))) |
| 95 | (if (< column start-column) | 103 | (if (< column start-column) |
| 96 | (if padding (make-string width padding) "") | 104 | (if padding (make-string end-column padding) "") |
| 97 | (if (and padding (> column start-column)) | 105 | (if (and padding (> column start-column)) |
| 98 | (setq head-padding (make-string (- column start-column) ?\ ))) | 106 | (setq head-padding (make-string (- column start-column) ?\ ))) |
| 99 | (setq from-idx idx) | 107 | (setq from-idx idx) |
| 100 | (condition-case nil | 108 | (if (< end-column column) |
| 101 | (while (< column width) | 109 | (setq idx from-idx) |
| 102 | (setq last-column column | 110 | (condition-case nil |
| 103 | last-idx idx | 111 | (while (< column end-column) |
| 104 | ch (sref str idx) | 112 | (setq last-column column |
| 105 | column (+ column (char-width ch)) | 113 | last-idx idx |
| 106 | idx (+ idx (char-bytes ch)))) | 114 | ch (sref str idx) |
| 107 | (args-out-of-range (setq idx len))) | 115 | column (+ column (char-width ch)) |
| 108 | (if (> column width) | 116 | idx (+ idx (char-bytes ch)))) |
| 109 | (setq column last-column idx last-idx)) | 117 | (args-out-of-range (setq idx len))) |
| 110 | (if (and padding (< column width)) | 118 | (if (> column end-column) |
| 111 | (setq tail-padding (make-string (- width column) padding))) | 119 | (setq column last-column idx last-idx)) |
| 120 | (if (and padding (< column end-column)) | ||
| 121 | (setq tail-padding (make-string (- end-column column) padding)))) | ||
| 112 | (setq str (substring str from-idx idx)) | 122 | (setq str (substring str from-idx idx)) |
| 113 | (if padding | 123 | (if padding |
| 114 | (concat head-padding str tail-padding) | 124 | (concat head-padding str tail-padding) |