Skip to content

Do not assume that the default margin widths are zero#91

Open
emreyolcu wants to merge 1 commit intornkn:masterfrom
emreyolcu:master
Open

Do not assume that the default margin widths are zero#91
emreyolcu wants to merge 1 commit intornkn:masterfrom
emreyolcu:master

Conversation

@emreyolcu
Copy link
Copy Markdown
Contributor

@emreyolcu emreyolcu commented Aug 16, 2025

Hey Paul, when setting/resetting margin widths Olivetti currently assumes that the default values of left-margin-width and right-margin-width are 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-window sets the margin widths to zero.

EDIT 2: I've changed the functions olivetti-normalize-width and olivetti-set-window to 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.

@rnkn
Copy link
Copy Markdown
Owner

rnkn commented Aug 17, 2025

Looks great, thanks! Might be a week or so until I can test/merge if that's okay.

@rnkn
Copy link
Copy Markdown
Owner

rnkn commented Mar 30, 2026

Sorry I haven't got to this. @larstvei can you review and merge if there are no issues?

Copy link
Copy Markdown
Collaborator

@larstvei larstvei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment on lines +272 to 275
min-width-pix)
(setq min-width-pix (* char-width
(+ olivetti-minimum-body-width
(% olivetti-minimum-body-width 2))))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you now use let* anyways, it seems better to also bind min-width-pix in the same let. Something like this:

Suggested change
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)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants