OmniSharp / omnisharp-emacs

Troll coworkers - use Emacs at work for csharp!
GNU General Public License v3.0
512 stars 94 forks source link

How to Code Formatting configuration #497

Open Pavllick opened 4 years ago

Pavllick commented 4 years ago

Cannot figure out how to config emacs to format code to any other styles other that to default. Can, please, anyone help me with configuration which on call omnisharp-code-format-entire-file format code to for instance "k&r" style?

razzmatazz commented 4 years ago

Hi @Pavllick

I am not using omnisharp-server-native formatting features, but the one from csharp-mode.

My init.el contains this code:

  (defun sm-csharp-mode-setup ()
    (setq indent-tabs-mode nil)
    (setq c-syntactic-indentation t)
    (c-set-style "ellemtel")
    (setq c-basic-offset 4)
    (setq truncate-lines t)
    (setq tab-width 4)
    (setq evil-shift-width 4))

  (add-hook 'csharp-mode-hook 'sm-csharp-mode-setup t)

I then do:

This does indentation for me using the "ellemtel" C-indentation style which I find most suitable for my code style.

Not sure omnisharp-code-format-entire-file' behaves, to be honest, -- hopefully my hint on(c-set-style "ellemtel")` is helpful to you.

Pavllick commented 4 years ago

Thank you Saulius for your hint. It's very helpful ) But still not exactly what I'm looking for. It solves a half of the problem. The function omnisharp-code-format-entire-file is not the panacea but format file, not only indent, it move brackets on it's places and so on. I'm not that advanced user of emacs and still explore it, so any other advises on how to do that would be appreciated.