haskell / haskell-mode

Emacs mode for Haskell
http://haskell.github.io/haskell-mode/
GNU General Public License v3.0
1.33k stars 342 forks source link

`haskell-mode-stylish-buffer` cannot work with the fourmolu formatter with custom configuration file #1765

Closed kenranunderscore closed 2 years ago

kenranunderscore commented 3 years ago

fourmolu is a formatter forked from ormolu, but with the option to load its configuration from a file. If one chooses to do so (by adding a fourmolu.yaml to the project root), it outputs a message like Loaded config from fourmolu.yaml to stderr.

Now haskell-buffer-apply-command - which is called by haskell-mode-stylish-buffer - never checks the error code (which is 0 here in my case, as the buffer can successfully be formatted), but only the contents of the error file, containing the above message.

I've created an issue with fourmolu (https://github.com/fourmolu/fourmolu/issues/110) to maybe suppress this message altogether, but I feel like disregarding the error code is not the optimal choice in this case.

I'd have created some PR for this, but I'm actually not really sure how to best handle the branches. Replacing the first check for err-file-empty-p with (= errcode 0) worked for me, but it leaves the case unhandled where:

purcell commented 3 years ago

Really the preferred method here would be to not even support stylish in haskell-mode: there are numerous separate packages which can trivially provide support for formatters, and be installed according to users' needs. My own reformatter package makes it easy to construct such things. I imagine that the existing ormolu emacs package can trivially be made to run fourmolu instead.

kenranunderscore commented 2 years ago

I'm using a patched version of fourmolu for now (for months, actually; just forgot to answer here).

I've installed reformatter (but haven't configured it yet) since what you're saying really makes sense and this will surely make my life easier with other languages in Emacs in the long run, thanks!