lspitzner / brittany

haskell source code formatter
GNU Affero General Public License v3.0
690 stars 72 forks source link

Add note about Emacs integration in README #172

Closed ghost closed 6 years ago

ghost commented 6 years ago

Thanks for the great tool! I've been using it for a while and I think it does an excellent job. Using it from Emacs is straightforward. I made a change to README file to reflect my setting.

A note: when I hit "save" the editor also removed some trailing white spaces. Please let me know if it is a problem and I'll redo the change to exclude those.

ElvishJerricco commented 6 years ago

Why not use stuff like shell-command-on-region? i.e. send the Emacs buffer through stdin instead of the file through CLI, so that you don't have to save before formatting, and so you can format only a region.

ghost commented 6 years ago

shell-command-on-region is totally fine when you want to format a region. And I used to have that function as well. However, I found that in most cases I just want the whole file to be always formatted. I type in a few lines, hit the keys to verify the result and continue writing. I also have that function hooked on buffer save. And since formatting is idempotent there's no harm to run that multiple times, I think.

ElvishJerricco commented 6 years ago

@disya2 Right but there must surely be something like shell-command-on-region that applies to the whole file? It just seems wrong to work on the file level when the user is working on the buffer level.

ChickenProp commented 6 years ago

Note that haskell-mode provides haskell-mode-stylish-buffer and haskell-mode-buffer-apply-command which don't require a save. I have

(eval-after-load 'haskell-mode
  (lambda ()
    (progn
      (setq haskell-mode-stylish-haskell-path "brittany")
      (define-key haskell-mode-map "\C-c\C-f" #'haskell-mode-stylish-buffer))))
lspitzner commented 6 years ago

I don't use emacs, so I have no comment on how good of an approach this is. Still, I'd prefer to not drop the proposed code entirely if it works, and nobody has bothered to write something better yet, even if it has flaws.

I propose to put the code snippet in a separate file in the docs folder, together with a note of potential downsides, and add a link to this from the readme, under the emacs header.

@disya2 thanks for proposing this. Even though you closed this, would you be fine with the above?