Skip to content

nix-format: support remote buffers - #206

Closed
jkxyz wants to merge 1 commit into
NixOS:masterfrom
jkxyz:nixfmt-tramp
Closed

nix-format: support remote buffers#206
jkxyz wants to merge 1 commit into
NixOS:masterfrom
jkxyz:nixfmt-tramp

Conversation

@jkxyz

@jkxyz jkxyz commented Mar 21, 2025

Copy link
Copy Markdown

Two changes need to be made to support Tramp remote buffers:

  1. Pass the second REMOTE arg to executable-find to find the executable on the remote host

  2. Avoid using call-process-region, which doesn't have a Tramp equivalent

This change replaces call-process-region with process-file which supports executing via Tramp. This function requires writing the buffer contents to a temporary file first.

Although writing the buffer to a file may have perfomance implications vs. writing from memory to stdin, they are likely to be negligibile. Furthermore, this approach is similar to other formatting libraries like prettier.el:

https://github.com/jscheid/prettier.el/blob/master/prettier.el#L1494

I've also found it to be more reliable than process-send-string.

Two changes need to be made to support Tramp remote buffers:

    1. Pass the second REMOTE arg to `executable-find` to find the
    executable on the remote host

    2. Avoid using `call-process-region`, which doesn't have a Tramp
    equivalent

This change replaces `call-process-region` with `process-file` which
supports executing via Tramp. This function requires writing the
buffer contents to a temporary file first.

Although writing the buffer to a file may have perfomance implications
vs. writing from memory to stdin, they are likely to be
negligibile. Furthermore, this approach is similar to other formatting
libraries like prettier.el:

https://github.com/jscheid/prettier.el/blob/master/prettier.el#L1494

I've also found it to be more reliable than `process-send-string`.
@matthewbauer

Copy link
Copy Markdown
Member

I merged a conflicting change in #211. I suspect the reformatter based version is probably compatible with Tramp?

@Dietr1ch

Copy link
Copy Markdown
Contributor

It seems it doesn't (purcell/emacs-reformatter#32), but adding support in reformatter benefits more packages.

@jkxyz

jkxyz commented Aug 10, 2026

Copy link
Copy Markdown
Author

Yes I'd say that upstream is the place to fix and would benefit other packages too.

@jkxyz jkxyz closed this Aug 10, 2026
@jkxyz
jkxyz deleted the nixfmt-tramp branch August 10, 2026 10:51
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