Skip to content

Allow specifying diff program#56

Merged
fisker merged 1 commit intoprettier:masterfrom
sirn:rcs-diff-program
Jun 23, 2025
Merged

Allow specifying diff program#56
fisker merged 1 commit intoprettier:masterfrom
sirn:rcs-diff-program

Conversation

@sirn
Copy link
Contributor

@sirn sirn commented Apr 13, 2019

On some systems such as OpenBSD, the diff program does not support some of the features available under GNU diff, e.g. --strip-trailing-cr. AFAIK, there's no way to reproduce the behavior of --strip-trailing-cr without piping to tr or sed (which is probably not ideal).

So I think it might make sense to allow specifying diff program, so I can install gdiff and configure prettier-emacs to use it. This PR basically add prettier-js-diff-command to defcustom, and use it in place of the existing diff string.

Thanks!

@Aankhen
Copy link

Aankhen commented Mar 14, 2020

This would be very useful to have.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR allows users to specify a custom diff program, which is especially useful on systems where GNU diff options (e.g. --strip-trailing-cr) are unavailable. The changes include adding a new customizable variable (prettier-js-diff-command) and updating the call-process-region invocation to use this variable instead of a hardcoded "diff" command.

Comments suppressed due to low confidence (2)

prettier-js.el:57

  • Consider clarifying the docstring to indicate that this variable can be set to alternative diff programs (e.g. 'gdiff') on systems where GNU diff is not available.
(defcustom prettier-js-diff-command "diff"

prettier-js.el:194

  • Since non-GNU diff tools might not support the '--strip-trailing-cr' argument, consider adding a note in the documentation or making this argument configurable for different diff tools.
                 (call-process-region (point-min) (point-max) prettier-js-diff-command nil patchbuf nil "-n" "--strip-trailing-cr" "-"

@fisker
Copy link
Member

fisker commented Jun 23, 2025

@jacksonrayhamilton

Copy link
Collaborator

@jacksonrayhamilton jacksonrayhamilton left a comment

Choose a reason for hiding this comment

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

Good idea, this will improve cross-platform compat. It might also be nice if we had a note in the README directing BSD users to customize this. However, the code change is already fine, so I'm approving it.

@fisker fisker merged commit 8d63b11 into prettier:master Jun 23, 2025
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.

6 participants