Groups | Search | Server Info | Login | Register


Groups > comp.emacs > #2509

Re: Sharing my split-window-preferred-function that splits at (pixel-wise) longer window-edge

From Aidan Hall <aidan.hall202@gmail.com>
Newsgroups comp.emacs
Subject Re: Sharing my split-window-preferred-function that splits at (pixel-wise) longer window-edge
Date 2025-12-17 19:16 +0000
Organization Black Mesa
Message-ID <87ecosvs05.fsf@gmail.com> (permalink)
References <871pmjqaxq.fsf@posteo.de>

Show all headers | View raw


Mekeor Melire <mekeor@posteo.de> writes:

> (defun split-window-rationally (&optional window)
>   "Split window at its pixelwise longer edge."
>   (interactive)
>   (let ((window (or window (selected-window)))
>         (split-height-threshold 0)
>         (split-width-threshold 0)
>         (ratio (>= (window-pixel-width) (window-pixel-height))))
>     (with-selected-window window
>         (cond ((and ratio (window-splittable-p window t))
>                (split-window-right))
>               ((and (not ratio) (window-splittable-p window))
>                (split-window-below))
>               ((window-splittable-p window t)
>                (split-window-right))
>               ((window-splittable-p window)
>                (split-window-below))))))

I like the general idea of splitting based on pixel widths, since it
makes the logic independent of a given window's text scale. One issue
with this function is that it doesn't account for characters generally
being taller than they are wide.

You could do something similar using "scale independent window
width/height in characters", computed like so:

(/ (window-pixel-width) (frame-char-width))

Both your approach and this degrade (somewhat) gracefully to character
counts in terminal frames, where:
(window-pixel-width) = (window-width)
(frame-char-width) = 1

Back to comp.emacs | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Sharing my split-window-preferred-function that splits at (pixel-wise) longer window-edge Mekeor Melire <mekeor@posteo.de> - 2025-10-31 17:43 +0100
  Re: Sharing my split-window-preferred-function that splits at (pixel-wise) longer window-edge Aidan Hall <aidan.hall202@gmail.com> - 2025-12-17 19:16 +0000
    Re: Sharing my split-window-preferred-function that splits at (pixel-wise) longer window-edge Mekeor Melire <mekeor@posteo.de> - 2025-12-19 11:10 +0100

csiph-web