branch: elpa/haskell-ts-mode
commit 3c9d85bc8874818d0f19970bdc0f7c6c8a2521fc
Author: Pranshu Sharma <pran...@bauherren.ovh>
Commit: Pranshu Sharma <pran...@bauherren.ovh>

    adding instruction for using a formatter in readme
---
 README.md | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/README.md b/README.md
index 169a1e9779..a6306b9aa7 100644
--- a/README.md
+++ b/README.md
@@ -113,7 +113,24 @@ development:
 
     (setq haskell-ts-use-indent nil)
 
+## Use a formatter (e.g. hindent, ormolu/formolu)
 
+Put the following code in your init file to bind `C-c C-f` to format
+the code in the selected region using
+[ormolu](https://hackage.haskell.org/package/ormolu).  You can adjust
+this to use another formatter.
+
+```
+(defun format-haskell (start end)
+  (interactive "r")
+  (let ((file (or buffer-file-name (error "Need to be visiting file")))
+       (text (buffer-substring-no-properties start end)))
+    (shell-command-on-region start end (concat "ormolu --stdin-input-file " 
file) nil t)
+    (message "Formatted the code")))
+
+(with-eval-after-load 'haskell-ts-mode
+    (define-key haskell-ts-mode-map (kbd "C-c C-f") 'format-haskell))
+```
 
 ## Pretify Symbols mode
 

Reply via email to