Fix #1500: rewrite font size adjustment commands
This commit is contained in:
parent
441fc5115c
commit
2dc50f49fc
1 changed files with 40 additions and 31 deletions
|
@ -44,21 +44,36 @@ acceptable values for this variable.")
|
||||||
(defun doom-adjust-font-size (increment &optional frame)
|
(defun doom-adjust-font-size (increment &optional frame)
|
||||||
"Increase size of font in FRAME by INCREMENT.
|
"Increase size of font in FRAME by INCREMENT.
|
||||||
FRAME parameter defaults to current frame."
|
FRAME parameter defaults to current frame."
|
||||||
(let* ((frame (or frame (selected-frame)))
|
(let (success)
|
||||||
(font (frame-parameter frame 'font))
|
(if (null increment)
|
||||||
(font (doom--font-name font frame)))
|
(let ((frames (doom--frame-list frame)))
|
||||||
(let ((new-size (+ (string-to-number (aref font xlfd-regexp-pixelsize-subnum))
|
(dolist (frame frames)
|
||||||
increment)))
|
(when (frame-parameter frame 'font-scale)
|
||||||
(unless (> new-size 0)
|
(set-frame-parameter frame 'font-scale nil)))
|
||||||
(error "Font is too small at %d" new-size))
|
(set-frame-font doom-font 'keep-size frames)
|
||||||
(aset font xlfd-regexp-pixelsize-subnum (number-to-string new-size)))
|
(setq success (and frames t)))
|
||||||
;; Set point size & width to "*", so frame width will adjust to new font size
|
(dolist (frame (doom--frame-list frame))
|
||||||
(aset font xlfd-regexp-pointsize-subnum "*")
|
(let* ((font (frame-parameter frame 'font))
|
||||||
(aset font xlfd-regexp-avgwidth-subnum "*")
|
(font (doom--font-name font frame))
|
||||||
(setq font (x-compose-font-name font))
|
(increment (* increment doom-font-increment))
|
||||||
(unless (x-list-fonts font)
|
(zoom-factor (or (frame-parameter frame 'font-scale) 0)))
|
||||||
(error "Cannot change font size"))
|
(let ((new-size (+ (string-to-number (aref font xlfd-regexp-pixelsize-subnum))
|
||||||
(set-frame-parameter frame 'font font)))
|
increment)))
|
||||||
|
(unless (> new-size 0)
|
||||||
|
(error "Font is too small at %d" new-size))
|
||||||
|
(aset font xlfd-regexp-pixelsize-subnum (number-to-string new-size)))
|
||||||
|
;; Set point size & width to "*", so frame width will adjust to new font size
|
||||||
|
(aset font xlfd-regexp-pointsize-subnum "*")
|
||||||
|
(aset font xlfd-regexp-avgwidth-subnum "*")
|
||||||
|
(setq font (x-compose-font-name font))
|
||||||
|
(unless (x-list-fonts font)
|
||||||
|
(error "Cannot change font size"))
|
||||||
|
(set-frame-parameter frame 'font font)
|
||||||
|
(set-frame-parameter frame 'font-scale (+ zoom-factor increment))
|
||||||
|
(setq success t))))
|
||||||
|
(when success
|
||||||
|
(run-hooks 'doom-change-font-size-hook)
|
||||||
|
t)))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -76,20 +91,15 @@ See `doom-init-fonts-h'."
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/increase-font-size (count)
|
(defun doom/increase-font-size (count)
|
||||||
"Enlargens the font size across the current frame."
|
"Enlargens the font size across the current and child frames."
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(let ((zoom-factor (or (frame-parameter nil 'font-scale) 0))
|
(doom-adjust-font-size count))
|
||||||
(increment (* count doom-font-increment)))
|
|
||||||
(setq zoom-factor (+ zoom-factor increment))
|
|
||||||
(doom-adjust-font-size increment)
|
|
||||||
(set-frame-parameter nil 'font-scale zoom-factor)
|
|
||||||
(run-hooks 'doom-change-font-size-hook)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/decrease-font-size (count)
|
(defun doom/decrease-font-size (count)
|
||||||
"Shrinks the font size across the current frame."
|
"Shrinks the font size across the current and child frames."
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(doom/increase-font-size (- count)))
|
(doom-adjust-font-size (- count)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/reset-font-size ()
|
(defun doom/reset-font-size ()
|
||||||
|
@ -103,13 +113,10 @@ Assuming it has been adjusted via `doom/increase-font-size' and
|
||||||
(/= text-scale-mode-amount 0))
|
(/= text-scale-mode-amount 0))
|
||||||
(text-scale-set 0)
|
(text-scale-set 0)
|
||||||
(setq success t))
|
(setq success t))
|
||||||
(when-let (factor (frame-parameter nil 'font-scale))
|
(when (doom-adjust-font-size nil)
|
||||||
(set-frame-font doom-font t)
|
|
||||||
(set-frame-parameter nil 'font-scale nil)
|
|
||||||
(setq success t))
|
(setq success t))
|
||||||
(unless success
|
(unless success
|
||||||
(user-error "The font hasn't been resized"))
|
(user-error "The font hasn't been resized"))))
|
||||||
(run-hooks 'doom-change-font-size-hook)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode doom-big-font-mode
|
(define-minor-mode doom-big-font-mode
|
||||||
|
@ -130,5 +137,7 @@ This uses `doom/increase-font-size' under the hood, and enlargens the font by
|
||||||
t (doom--frame-list frame))
|
t (doom--frame-list frame))
|
||||||
(run-hooks 'doom-change-font-size-hook))
|
(run-hooks 'doom-change-font-size-hook))
|
||||||
(set-frame-font doom-font t (doom--frame-list frame))
|
(set-frame-font doom-font t (doom--frame-list frame))
|
||||||
(when doom-big-font-mode
|
(when (and doom-big-font-mode
|
||||||
(doom-adjust-font-size doom-big-font-increment frame)))))
|
(integerp doom-big-font-increment)
|
||||||
|
(/= doom-big-font-increment 0))
|
||||||
|
(doom-adjust-font-size doom-big-font-increment)))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue