diff options
| -rw-r--r-- | lisp/tab-bar.el | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 0ed372de176..6a86962476e 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el | |||
| @@ -1194,19 +1194,29 @@ when the tab is current. Return the result as a keymap." | |||
| 1194 | `((add-tab menu-item ,tab-bar-new-button tab-bar-new-tab | 1194 | `((add-tab menu-item ,tab-bar-new-button tab-bar-new-tab |
| 1195 | :help "New tab")))) | 1195 | :help "New tab")))) |
| 1196 | 1196 | ||
| 1197 | (defvar tab-bar--align-right-hash nil | ||
| 1198 | "Memoization table for `tab-bar-format-align-right'.") | ||
| 1199 | |||
| 1197 | (defun tab-bar-format-align-right (&optional rest) | 1200 | (defun tab-bar-format-align-right (&optional rest) |
| 1198 | "Align the rest of tab bar items to the right. | 1201 | "Align the rest of tab bar items to the right. |
| 1199 | The argument `rest' is used for special handling of this item | 1202 | The argument `rest' is used for special handling of this item |
| 1200 | by `tab-bar-format-list' that collects the rest of formatted items. | 1203 | by `tab-bar-format-list' that collects the rest of formatted items. |
| 1201 | This prevents calling other non-idempotent items like | 1204 | This prevents calling other non-idempotent items like |
| 1202 | `tab-bar-format-global' twice." | 1205 | `tab-bar-format-global' twice." |
| 1206 | (unless tab-bar--align-right-hash | ||
| 1207 | (define-hash-table-test 'tab-bar--align-right-hash-test | ||
| 1208 | #'equal-including-properties | ||
| 1209 | #'sxhash-equal-including-properties) | ||
| 1210 | (setq tab-bar--align-right-hash | ||
| 1211 | (make-hash-table :test 'tab-bar--align-right-hash-test))) | ||
| 1203 | (let* ((rest (or rest (tab-bar-format-list | 1212 | (let* ((rest (or rest (tab-bar-format-list |
| 1204 | (cdr (memq 'tab-bar-format-align-right | 1213 | (cdr (memq 'tab-bar-format-align-right |
| 1205 | tab-bar-format))))) | 1214 | tab-bar-format))))) |
| 1206 | (rest (mapconcat (lambda (item) (nth 2 item)) rest "")) | 1215 | (rest (mapconcat (lambda (item) (nth 2 item)) rest "")) |
| 1207 | (hpos (progn | 1216 | (hpos (progn |
| 1208 | (add-face-text-property 0 (length rest) 'tab-bar t rest) | 1217 | (add-face-text-property 0 (length rest) 'tab-bar t rest) |
| 1209 | (string-pixel-width rest))) | 1218 | (with-memoization (gethash rest tab-bar--align-right-hash) |
| 1219 | (string-pixel-width rest)))) | ||
| 1210 | (str (propertize " " 'display | 1220 | (str (propertize " " 'display |
| 1211 | ;; The `right' spec doesn't work on TTY frames | 1221 | ;; The `right' spec doesn't work on TTY frames |
| 1212 | ;; when windows are split horizontally (bug#59620) | 1222 | ;; when windows are split horizontally (bug#59620) |