Do not assume that the default margin widths are zero#91
Do not assume that the default margin widths are zero#91larstvei merged 2 commits intornkn:masterfrom
Conversation
|
Looks great, thanks! Might be a week or so until I can test/merge if that's okay. |
|
Sorry I haven't got to this. @larstvei can you review and merge if there are no issues? |
larstvei
left a comment
There was a problem hiding this comment.
Hi! Sorry for responding late.
I was able to reproduce the bug, and it does seem like this fixes it, so I think this can be merged.
I have one suggestion which I think is a clear improvement.
The other is that the logic introduced in olivetti-normalize-width is repeated in olivetti-set-window. Could you perhaps extract that in a separate function before I merge?
| min-width-pix) | ||
| (setq min-width-pix (* char-width | ||
| (+ olivetti-minimum-body-width | ||
| (% olivetti-minimum-body-width 2)))) |
There was a problem hiding this comment.
Because you now use let* anyways, it seems better to also bind min-width-pix in the same let. Something like this:
| min-width-pix) | |
| (setq min-width-pix (* char-width | |
| (+ olivetti-minimum-body-width | |
| (% olivetti-minimum-body-width 2)))) | |
| (min-width-pix (* char-width | |
| (+ olivetti-minimum-body-width | |
| (% olivetti-minimum-body-width 2))))) |
|
I've made both changes. Could you check again? |
|
Looks good! Thank you for the contribution. |
Hey Paul, when setting/resetting margin widths Olivetti currently assumes that the default values of
left-margin-widthandright-margin-widthare zero. This assumption was partly removed after #78 in 1690a3c, but we forgot to account for the two other places where the same assumption is made. Those places result in more subtle bugs than the previous one, so I've only recently noticed a problem. When the current window is not wide enough and Olivetti is active (not necessarily in the current window), margins are set to zero instead of their default values. This PR fixes that.EDIT 1: I apparently forgot the mistake I made in #78 and incorporated the same change here. I'll try to see how to calculate the additional width correctly without assuming that
olivetti-reset-windowsets the margin widths to zero.EDIT 2: I've changed the functions
olivetti-normalize-widthandolivetti-set-windowto compute the window's width in pixels by taking the margins into account. If the default margin widths are zero, nothing changes from before; otherwise, margins are treated as if they are part of the window's text area (while fringes, vertical dividers, or scroll bars are still excluded). In my testing this results in the same behavior as before while also respecting the default margin widths.