fsharp / emacs-fsharp-mode

F# Emacs mode
Apache License 2.0
206 stars 62 forks source link

Is there an easy way to auto-indent the whole buffer? #290

Closed mattiasdrp closed 1 year ago

mattiasdrp commented 2 years ago

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?

mattiasdrp commented 2 years ago

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

juergenhoetzel commented 1 year ago

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))))
juergenhoetzel commented 1 year ago

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")
razzmatazz commented 1 year ago

fsautocomplete issue that is tracking this is https://github.com/fsharp/FsAutoComplete/issues/1087