Skip to content

Commit 07e4d6e

Browse files
authored
Merge pull request #21 from Hi-Angel/fix-indent
Never fail to indent
2 parents ec8409e + cc34919 commit 07e4d6e

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

purescript-indentation.el

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -463,21 +463,39 @@ autofill-mode."
463463
(defun purescript-indentation-first-indentation ()
464464
(if (eq purescript-literate 'bird) '(2) '(0)))
465465

466+
(defun purescript-get-previous-indentation-hack ()
467+
"Return previous indentation level as a list element.
468+
469+
This function is a temporary workaround for
470+
`purescript-newline-and-indent' asking for indent before going to the
471+
new line, which makes it indistinguishable from just attempting to
472+
indent the current line. This has to be fixed elsewhere."
473+
(list
474+
(if (string= this-command "purescript-newline-and-indent")
475+
(current-indentation) ;; current line is actually previous one
476+
(save-excursion
477+
(forward-line -1)
478+
(current-indentation)))))
479+
466480
(defun purescript-indentation-find-indentations ()
467-
(let ((ppss (syntax-ppss)))
468-
(cond
469-
((nth 3 ppss)
470-
(purescript-indentation-first-indentation))
471-
((nth 4 ppss)
472-
(if (save-excursion
473-
(and (skip-syntax-forward "-")
474-
(eolp)
475-
(not (> (forward-line 1) 0))
476-
(not (nth 4 (syntax-ppss)))))
477-
(purescript-indentation-parse-to-indentations)
478-
(purescript-indentation-first-indentation)))
479-
(t
480-
(purescript-indentation-parse-to-indentations)))))
481+
(condition-case nil
482+
(let ((ppss (syntax-ppss)))
483+
(cond
484+
((nth 3 ppss)
485+
(purescript-indentation-first-indentation))
486+
((nth 4 ppss)
487+
(if (save-excursion
488+
(and (skip-syntax-forward "-")
489+
(eolp)
490+
(not (> (forward-line 1) 0))
491+
(not (nth 4 (syntax-ppss)))))
492+
(purescript-indentation-parse-to-indentations)
493+
(purescript-indentation-first-indentation)))
494+
(t
495+
(purescript-indentation-parse-to-indentations))))
496+
;; Ideally it should not return parse error but if it does just use the previous
497+
;; indentation.
498+
(parse-error (purescript-get-previous-indentation-hack))))
481499

482500
(defconst purescript-indentation-unicode-tokens
483501
'(("" . "->") ;; #x2192 RIGHTWARDS ARROW

0 commit comments

Comments
 (0)