diff --git a/lisp/face-remap.el b/lisp/face-remap.el index c899a8d..53e99ec 100644 --- a/lisp/face-remap.el +++ b/lisp/face-remap.el @@ -203,6 +203,19 @@ Each positive or negative step scales the default face height by this amount." (defvar text-scale-mode-amount 0) (make-variable-buffer-local 'text-scale-mode-amount) +(defvar text-scale-mode-old-scale-factor nil + "Previously active scale factor for default face :height +attribute when `text-scale-mode-hook' is called, or nil if +text-scale-mode was not previously active (meaning the old scale +factor was 1.0).") +(make-variable-buffer-local 'text-scale-mode-old-scale-factor) + +(defvar text-scale-mode-scale-factor nil + "Scale factor for default face :height attribute when +`text-scale-mode-hook' is called, or nil if text-scale-mode will +be deactivated (meaning the scale factor is 1.0).") +(make-variable-buffer-local 'text-scale-mode-scale-factor) + (define-minor-mode text-scale-mode "Minor mode for displaying buffer text in a larger/smaller font than usual. @@ -221,14 +234,55 @@ disable `text-scale-mode' as necessary)." (setq text-scale-mode-lighter (format (if (>= text-scale-mode-amount 0) "+%d" "%d") text-scale-mode-amount)) + (setq text-scale-mode-old-scale-factor + (nth 2 text-scale-mode-remapping)) + (setq text-scale-mode-scale-factor + (and text-scale-mode + (expt text-scale-mode-step text-scale-mode-amount))) (setq text-scale-mode-remapping (and text-scale-mode (face-remap-add-relative 'default - :height - (expt text-scale-mode-step - text-scale-mode-amount)))) + :height text-scale-mode-scale-factor))) (force-window-update (current-buffer))) +(defun text-scale-mode-adjust-window-horizontal-size () + "Change the horizontal size of the current window corresponding to ratio +`text-scale-mode-scale-factor / text-scale-mode-old-scale-factor'. + +This function is intended to be used as a hook for `text-scale-mode-hook'." + (let* ((edges (window-edges)) + (owidth (- (nth 2 edges) (nth 0 edges))) + (scale-factor + (/ (or text-scale-mode-scale-factor 1.0) + (or text-scale-mode-old-scale-factor 1.0)))) + (condition-case nil + (enlarge-window-horizontally + (round (- (* owidth scale-factor) owidth))) + (error nil)))) + +(defun text-scale-mode-adjust-window-vertical-size () + "Change the vertical size of the current window corresponding to ratio +`text-scale-mode-scale-factor / text-scale-mode-old-scale-factor'. + +This function is intended to be used as a hook for `text-scale-mode-hook'." + (let* ((edges (window-edges)) + (oheight (- (nth 3 edges) (nth 1 edges))) + (scale-factor + (/ (or text-scale-mode-scale-factor 1.0) + (or text-scale-mode-old-scale-factor 1.0)))) + (condition-case nil + (enlarge-window + (round (- (* oheight scale-factor) oheight))) + (error nil)))) + +(defun text-scale-mode-adjust-window-size () + "Change the size of the current window corresponding to ratio +`text-scale-mode-scale-factor / text-scale-mode-old-scale-factor'. + +This function is intended to be used as a hook for `text-scale-mode-hook'." + (text-scale-mode-adjust-window-vertical-size) + (text-scale-mode-adjust-window-horizontal-size)) + ;;;###autoload (defun text-scale-set (level) "Set the scale factor of the default face in the current buffer to LEVEL.