When I need to change the font size I evaluate the following region:
(set-frame-font "JetBrains Mono-14")
This is far from optimal since it involves a lot of typing.
I'm looking for an interactive function that would ask me for the new font size and modify the numeric value passed to
As a workaround I wrote the following function:
(defun change-font-size (new-size) "Change the font size to the given value" (interactive "sNew font size: ") (set-frame-font (concat (face-attribute 'default :family) "-" new-size) ) ) (bind-key "C-x f" #'change-font-size)
But I wonder if there's a better way of doing this.
The best solution for me would be to change the font size of emacs based in the monitor in which it is being displayed, but I could not find any satisfactory solution. I do not want to do busy waiting on my emacs, instead I'd like emacs listening to notifications of the windows manager. However I do not know whether this is possible.
EDIT using the suggestion in one of the answers I wrote this hook to resize the window based on the display emacs is in.
(defun my/adjust-font-size-based-on-display () (let ((display-width (nth 3 (assq 'geometry (frame-monitor-attributes)))) ) (change-font-size (cond ((<= display-width 1920) 18) ;; HD ((<= display-width 2560) 11) ;; UWHD ((<= display-width 4096) 14) ;; 4K ) ) ) ) (add-hook 'window-size-change-functions (lambda (frame) (my/adjust-font-size-based-on-display))) (add-hook 'focus-in-hook 'my/adjust-font-size-based-on-display)
Suggestions on how to improve the hook above are welcome!