Skip to content

Commit 814e4d3

Browse files
author
Kristof Bastiaensen
committed
Added support for bird-style lhs (with fixes)
1 parent 2c87fa1 commit 814e4d3

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

haskell-indentation.el

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
:type 'integer
7979
:group 'haskell-indentation)
8080

81+
(defcustom haskell-indentation-birdtrack-extra-space t
82+
"Append a space after every birdtrack in literate mode."
83+
:type 'boolean
84+
:group 'haskell-indentation)
85+
86+
8187
;; Avoid a global bogus definition (which the original run-time
8288
;; `defun' made), and support Emacs 21 without the syntax.el add-on.
8389
(eval-when-compile
@@ -236,13 +242,12 @@ Preserves indentation and removes extra whitespace"
236242
(skip-syntax-forward "-")
237243
(if (prog1 (and (eolp)
238244
(not (= (haskell-current-column) ci)))
245+
(delete-horizontal-space)
239246
(if (not (eq haskell-literate 'bird))
240-
(delete-horizontal-space)
241-
(skip-syntax-backward "-")
242-
(indent-to 2)
243-
(kill-region (point) (progn (end-of-line) (point))))
244-
(newline)
245-
(when (eq haskell-literate 'bird)
247+
(newline)
248+
(when haskell-indentation-birdtrack-extra-space
249+
(indent-to 2))
250+
(newline)
246251
(insert "> ")))
247252
(haskell-indentation-reindent
248253
(max (haskell-indentation-butlast indentations)
@@ -339,32 +344,33 @@ Preserves indentation and removes extra whitespace"
339344

340345
(defun haskell-indentation-delete-backward-char (n)
341346
(interactive "p")
342-
(if (haskell-indentation-outside-bird-line)
343-
(delete-backward-char n)
344-
(on-parse-error (delete-backward-char n)
345-
(cond
346-
((and delete-selection-mode
347-
mark-active
348-
(not (= (point) (mark))))
349-
(delete-region (mark) (point)))
350-
((or (= (haskell-current-column) 0)
351-
(> (haskell-current-column) (haskell-indentation-current-indentation))
352-
(nth 8 (syntax-ppss)))
353-
(delete-backward-char n))
354-
(t (let* ((ci (haskell-indentation-current-indentation))
355-
(pi (haskell-indentation-previous-indentation
356-
ci (haskell-indentation-find-indentations))))
357-
(save-excursion
358-
(cond (pi
359-
(move-to-column pi)
360-
(delete-region (point)
361-
(progn (move-to-column ci)
362-
(point))))
363-
(t
364-
(beginning-of-line)
365-
(delete-region (max (point-min) (- (point) 1))
366-
(progn (move-to-column ci)
367-
(point))))))))))))
347+
(on-parse-error
348+
(delete-backward-char n)
349+
(cond
350+
((haskell-indentation-outside-bird-line)
351+
(delete-backward-char n))
352+
((and delete-selection-mode
353+
mark-active
354+
(not (= (point) (mark))))
355+
(delete-region (mark) (point)))
356+
((or (= (haskell-current-column) 0)
357+
(> (haskell-current-column) (haskell-indentation-current-indentation))
358+
(nth 8 (syntax-ppss)))
359+
(delete-backward-char n))
360+
(t (let* ((ci (haskell-indentation-current-indentation))
361+
(pi (haskell-indentation-previous-indentation
362+
ci (haskell-indentation-find-indentations))))
363+
(save-excursion
364+
(cond (pi
365+
(move-to-column pi)
366+
(delete-region (point)
367+
(progn (move-to-column ci)
368+
(point))))
369+
(t
370+
(beginning-of-line)
371+
(delete-region (max (point-min) (- (point) 1))
372+
(progn (move-to-column ci)
373+
(point)))))))))))
368374

369375
(defun haskell-indentation-delete-char (n)
370376
(interactive "p")
@@ -399,6 +405,7 @@ Preserves indentation and removes extra whitespace"
399405
(if (eq haskell-literate 'bird)
400406
(catch 'return
401407
(while (not (bobp))
408+
(forward-line -1)
402409
(when (not (eq (char-after) ?>))
403410
(forward-line)
404411
(forward-char 2)
@@ -410,8 +417,7 @@ Preserves indentation and removes extra whitespace"
410417
(when (and (>= 2 (haskell-indentation-current-indentation))
411418
(not (looking-at ">\\s-*$")))
412419
(forward-char 2)
413-
(throw 'return nil))
414-
(forward-line -1)))
420+
(throw 'return nil))))
415421
;; not bird style
416422
(catch 'return
417423
(while (not (bobp))

0 commit comments

Comments
 (0)