4

Usually I have two windows vertical split layout when using Emacs. I'm curious is it possible to change default font size for one of them?

Typically, I use 14 points font height with 80 columns limit, when windows have same width this gives no line wrapping. But I've found bigger font size is better for eyes and eases viewing perception, however if windows have equal width the lines become too long and wrapping appears.

So the idea is to have one wide (major) window with bigger font size, and another window being narrowed with smaller font-size. I know I can set up font per buffer, but this is not what I need, e.g. I want same buffer being rendered with bigger font when visited in major window and with smaller font when visited in secondary window.

layout screenshot

On a screenshot above there are major window is outlined with green colour and secondary window is outlined with blue one. For example I want to have 18pt font size for major window and 12pt font size for blue window.

3
  • Can you post a screenshot so that we sure what you mean?
    – Adobe
    Commented Jun 18, 2015 at 13:27
  • 1
    (FWIW, if you use separate frames then the answer is trivially yes.)
    – Drew
    Commented Jun 18, 2015 at 13:43
  • @Drew, hm… interesting idea, but this is so unusual, and I'm afraid uncomfortable. Commented Jun 18, 2015 at 13:47

1 Answer 1

1

As long as you don't plan on having a buffer open in two windows at the same time this solution could work for you:

(require 'face-remap)

(defun buffer-resize-font-for-window ()
  "Scale the buffer's text for the current window."
  (let ((scale (or (window-parameter (selected-window) 'my-custom-font-scale) 0)))
    (when (integerp scale)
      (let ((text-scale-mode-amount scale))
        (text-scale-mode t)))))

(defun my-set-window-font-scale (&optional scale)
  "Set the window scale for the current window.
 0 is the default height."
  (interactive (list (string-to-number
                      (completing-read 
                       "Window Font Scale: " 
                       (mapcar 'number-to-string (number-sequence 0 5)) nil t))))
  (set-window-parameter (selected-window) 'my-custom-font-scale scale)
  (buffer-resize-font-for-window))


(add-hook 'buffer-list-update-hook 'buffer-resize-font-for-window)

After you evaluate that go the the window you want scaled larger and run M-x my-set-window-font-scale and choose a scale. You should see that every buffer you open in that window get's automatically scaled up.

This way every time you switch buffers or switch the current buffer in a window, Emacs will check for a window specific scaling value and scale the buffer accordingly. The scaling is buffer specific so if you have a buffer open in two windows with different scales they will both be scaled according to the last used window. Scaling is buffer-specific so you can hack it in fake window-specific support but it's just a hack.

This is more of a starting point than a solution ready for daily use, but hopefully you can build on it to make something really useful.

1
  • finally I've got a time to test this stuff. Thank you! Commented Jun 23, 2015 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.