Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom commands for running ocamlformat #2577

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ profile. This started with version 0.26.0.
- Support OCaml 5.2 syntax (#2519, @Julow)
This includes:
+ Local open in types.
- Allow a custom command to be used to run ocamlformat in the emacs plugin (#2577, @gridbugs)

### Changed

Expand Down
18 changes: 14 additions & 4 deletions emacs/ocamlformat.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@

(defcustom ocamlformat-command "ocamlformat"
"The `ocamlformat' command."
:type 'string
:type '(choice
(string :tag "The name of the ocamlformat executable")
(repeat :tag "The prefix of the command to run to run ocamlformat" string))
:group 'ocamlformat)

(defcustom ocamlformat-enable 'enable
Expand Down Expand Up @@ -266,15 +268,23 @@ is nil."
((eq ocamlformat-file-kind 'implementation)
(list "--impl"))
((eq ocamlformat-file-kind 'interface)
(list "--intf")))))
(list "--intf"))))
(ocamlformat-exe
(if (listp ocamlformat-command)
(car ocamlformat-command)
ocamlformat-command))
(ocamlformat-prefix-args
(if (listp ocamlformat-command)
(cdr ocamlformat-command)
'())))
(unwind-protect
(save-restriction
(widen)
(write-region nil nil bufferfile)
(if (zerop
(apply #'call-process
ocamlformat-command nil (list :file errorfile) nil
(append margin-args enable-args extension-args
ocamlformat-exe nil (list :file errorfile) nil
(append ocamlformat-prefix-args margin-args enable-args extension-args
(list
"--name" buffer-file-name
"--output" outputfile bufferfile))))
Expand Down
Loading