Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Conversation

@bgluzman
Copy link

zig-format-buffer calls revert-buffer which ends up terminating minor modes like lsp. By saving the minor-mode-list context and then restoring it after the revert-buffer call (along with setting the PRESERVE-MODES parameter to true within the call), we are able to retain the minor modes (like lsp) across calls to zig-format-buffer.

I believe this addresses the issue pointed out in #49. This approach was inspired by this Github comment.

zig-format-buffer calls revert-buffer which ends up terminating
minor modes like lsp. By saving the minor-mode-list context and
then restoring it after the revert-buffer call (along with
setting the PRESERVE-MODES parameter to true withint he call),
we are able to retain the minor modes (like lsp) across calls to
zig-format-buffer.

This approach was inpsired by the following Github comment:
emacs-lsp/lsp-mode#3469 (comment)
Copy link
Contributor

@joachimschmidt557 joachimschmidt557 left a comment

Choose a reason for hiding this comment

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

Thanks! I think this will fix a lot of issues with using revert-buffer. I do still believe though that in the long run we should transition away from formatting the file on disk towards formatting the buffer. This can be achieved through e.g. reformatter. I'll open a GitHub discussion about this.

Comment on lines +161 to +163
(let ((active-minor-modes-list minor-mode-list))
(revert-buffer :ignore-auto :noconfirm :preserve-modes)
(setq minor-mode-list active-minor-modes-list))))))))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is nitpicky, but could you indent this with indent-tabs-mode off? It helps keep the indentation of this source consistent.

See also #65 (comment)

@joachimschmidt557
Copy link
Contributor

#51 was merged a few weeks ago, which removes all usages of revert-buffer.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants