diff options
| -rw-r--r-- | lisp/face-remap.el | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/lisp/face-remap.el b/lisp/face-remap.el index 0da6be7430b..9c2cae14b38 100644 --- a/lisp/face-remap.el +++ b/lisp/face-remap.el | |||
| @@ -256,6 +256,23 @@ disable `text-scale-mode' as necessary)." | |||
| 256 | text-scale-mode-amount)))) | 256 | text-scale-mode-amount)))) |
| 257 | (force-window-update (current-buffer))) | 257 | (force-window-update (current-buffer))) |
| 258 | 258 | ||
| 259 | (defun text-scale-min-amount () | ||
| 260 | "Return the minimum amount of text-scaling we allow." | ||
| 261 | ;; When the resulting pixel-height of characters will become smaller | ||
| 262 | ;; than 1 pixel, we can expect trouble from the display engine. | ||
| 263 | ;; E.g., it requires that the character glyph's ascent is | ||
| 264 | ;; non-negative. | ||
| 265 | (log (/ 1.0 (frame-char-height)) text-scale-mode-step)) | ||
| 266 | |||
| 267 | (defun text-scale-max-amount () | ||
| 268 | "Return the maximum amount of text-scaling we allow." | ||
| 269 | ;; The display engine uses a 16-bit short for pixel-width of | ||
| 270 | ;; characters, thus the 0xffff limitation. It also makes no sense | ||
| 271 | ;; to have characters wider than the display. | ||
| 272 | (log (/ (min (display-pixel-width) #xffff) | ||
| 273 | (frame-char-width)) | ||
| 274 | text-scale-mode-step)) | ||
| 275 | |||
| 259 | ;;;###autoload | 276 | ;;;###autoload |
| 260 | (defun text-scale-set (level) | 277 | (defun text-scale-set (level) |
| 261 | "Set the scale factor of the default face in the current buffer to LEVEL. | 278 | "Set the scale factor of the default face in the current buffer to LEVEL. |
| @@ -266,7 +283,8 @@ Each step scales the height of the default face by the variable | |||
| 266 | `text-scale-mode-step' (a negative number decreases the height by | 283 | `text-scale-mode-step' (a negative number decreases the height by |
| 267 | the same amount)." | 284 | the same amount)." |
| 268 | (interactive "p") | 285 | (interactive "p") |
| 269 | (setq text-scale-mode-amount level) | 286 | (setq text-scale-mode-amount |
| 287 | (max (min level (text-scale-max-amount)) (text-scale-min-amount))) | ||
| 270 | (text-scale-mode (if (zerop text-scale-mode-amount) -1 1))) | 288 | (text-scale-mode (if (zerop text-scale-mode-amount) -1 1))) |
| 271 | 289 | ||
| 272 | ;;;###autoload | 290 | ;;;###autoload |
| @@ -279,8 +297,13 @@ Each step scales the height of the default face by the variable | |||
| 279 | height by the same amount). As a special case, an argument of 0 | 297 | height by the same amount). As a special case, an argument of 0 |
| 280 | will remove any scaling currently active." | 298 | will remove any scaling currently active." |
| 281 | (interactive "p") | 299 | (interactive "p") |
| 282 | (setq text-scale-mode-amount | 300 | (let* ((current-value (if text-scale-mode text-scale-mode-amount 0)) |
| 283 | (if (= inc 0) 0 (+ (if text-scale-mode text-scale-mode-amount 0) inc))) | 301 | (new-value (if (= inc 0) 0 (+ current-value inc)))) |
| 302 | (if (or (> new-value (text-scale-max-amount)) | ||
| 303 | (< new-value (text-scale-min-amount))) | ||
| 304 | (user-error "Cannot %s the default face height more than it already is" | ||
| 305 | (if (> inc 0) "increase" "decrease"))) | ||
| 306 | (setq text-scale-mode-amount new-value)) | ||
| 284 | (text-scale-mode (if (zerop text-scale-mode-amount) -1 1))) | 307 | (text-scale-mode (if (zerop text-scale-mode-amount) -1 1))) |
| 285 | 308 | ||
| 286 | ;;;###autoload | 309 | ;;;###autoload |