0

Would it be possible that for a particular window width, I can automatically adapt the text to show up to a certain column number? If possible not via face attributes but using text-scale-mode at buffer-local level.

As example, use ruler-mode and change the window size until you get to column 32. Then call squeeze with desired column being 75. The result is not a window with extent of 75 characters on the ruler.

(defun squeeze (nc)
  (interactive "nDesired number of columns: ")

  (let ( (ncwin (window-width)) )
    (when (> ncwin 0)

      (let* ( (scaling-factor (/ (float nc) ncwin))
              (step text-scale-mode-step)
              (scale-steps (ceiling (/ scaling-factor step)))
              (print 1))

        (when (> nc ncwin)
          (setq scale-steps (* -1 scale-steps)))

        (text-scale-set scale-steps)) )))
10
  • The problem is that the levels used by text-scale-set are absolute, not relative to the current size (i.e. setting to level 1.1 will always be the same size and will not continue to scale the text). The scaling that occurs is relative to the height of face of the text in your buffer, not the current size of the display. Also, part of your problem with debugging may be that you are printing your scaling-factor as an integer in your message call rather than as a float.
    – D. Gillis
    Jul 14, 2023 at 22:47
  • I'm afraid I don't understand what you're asking for. Can you please provide an example of the buffer before you apply the code and after you apply the code? Here's an example of a question with that kind of example, if you need an example: emacs.stackexchange.com/questions/75469/…
    – Trevoke
    Jul 14, 2023 at 22:48
  • As for doing the scaling automatically, you could make a minor mode and remap self-insert-command to determine whether text-scaling should occur on each insertion. Org-mode does something similar using org-self-insert-command, which it puts into the keymap using org-remap.
    – D. Gillis
    Jul 14, 2023 at 22:51
  • I think visual-line-mode might just do what you want (show the text on one line between both margins and hide the rest of the line) but somehow I think you want something else.
    – Trevoke
    Jul 14, 2023 at 22:54
  • Also you might just be looking for olivetti-mode. github.com/rnkn/olivetti
    – Trevoke
    Jul 14, 2023 at 22:55

1 Answer 1

1

I believe this package solves your problem.

fit-text-scale is an automation to set the scale so that the text uses the maximal space to fit in the window.

Scale stands for the zoom of the font.

There are three functions:

  • Choose the maximal text scale to still see the full line.
  • Choose the maximal text scale to still see the full lines.
  • Choose the maximal text scale to still see all lines of a buffer.

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.