emacs-fsharp-mode
emacs-fsharp-mode copied to clipboard
Is there an easy way to auto-indent the whole buffer?
Description
I'd like to C-x h <tab> to indent my buffer (or indent on save) but on this sample program nothing happens:
let printGreeting name =
let firstNumber = 2000 in
let secondNumber = 22 in
printfn $"The year is: {firstNumber + secondNumber}";
printfn $"Hello {name} from F#!"
For OCaml I have the following lines:
(use-package ocamlformat
:hook
(tuareg-mode . (lambda () (add-hook 'before-save-hook 'ocamlformat-before-save nil 'local)))
)
That will apply ocamlformat anytime I save.
Is there a corresponding package to do this in fsharp or some elisp shenanigans to have the same behaviour?
Why do I need this by the way? Because when following the tutorial (here for example), you're being asked to copy/paste some code but it will not be properly indented and currently I need to go on each line and hit <tab> to indent it properly because selecting the wrongly indented lines then hitting <tab> does nothing
This functionality is already part of eglot:
(use-package eglot :ensure t
:hook
(fsharp-mode . (lambda () (add-hook 'before-save-hook 'eglot-format-buffer nil 'local))))
eglot-fsharp is currently broken for fsac >= 0.59.3.
https://github.com/fsharp/emacs-fsharp-mode/issues/331
Workaround:
(setq eglot-fsharp-server-version "0.59.2")
fsautocomplete issue that is tracking this is https://github.com/fsharp/FsAutoComplete/issues/1087