The attached patch fixes this problem. It refines the
'haskell-indent-start-of-def' function, which previously searched for
the beginning of a definition by the first non-comment character after
searching backwards for an empty line. The code now searches backwards
for the furthest away line which is nonempty with zero indentation.

--
-David House, [EMAIL PROTECTED]
*** /home/david/sandbox/haskell-mode-2.1/haskell-indent.el      2005-11-07 
20:04:15.000000000 +0000
--- /home/david/hs/emacs/haskell-indent.el      2006-12-28 19:50:17.000000000 
+0000
***************
*** 320,327 ****
  
  (defun haskell-indent-start-of-def ()
    "Return the position of the start of a definition.
! It is at the first character which is not in a comment after nearest
! preceding non-empty line."
    (save-excursion
      (let (start-code
            (save-point (point)))
--- 320,327 ----
  
  (defun haskell-indent-start-of-def ()
    "Return the position of the start of a definition.
! It is at the first character which is not in a comment on nearest
! preceding 0-indentation line."
    (save-excursion
      (let (start-code
            (save-point (point)))
***************
*** 330,345 ****
                              (haskell-indent-within-literate-code)))
            (setq start-code (1+ start-code))
          (setq start-code (point-min)))
!       ;; go backward until the first preceding empty line
        (haskell-indent-forward-line -1)
!       (while (and (not (haskell-indent-empty-line-p))
                    (> (point) start-code)
                    (= 0 (haskell-indent-forward-line -1))))
-       ;; go forward after the empty line
-       (if (haskell-indent-empty-line-p)
-           (haskell-indent-forward-line 1))
-       (setq start-code (point))
        ;; find the first line of code which is not a comment
        (forward-comment (point-max))
        (if (> (point) save-point)
          start-code
--- 330,344 ----
                              (haskell-indent-within-literate-code)))
            (setq start-code (1+ start-code))
          (setq start-code (point-min)))
!       ;; go backward until the first 0-indentation line
        (haskell-indent-forward-line -1)
!       (while (and (or 
!                    (/= 0 (haskell-indent-current-indentation))
!                    (haskell-indent-empty-line-p))
                    (> (point) start-code)
                    (= 0 (haskell-indent-forward-line -1))))
        ;; find the first line of code which is not a comment
+       (setq start-code (point))
        (forward-comment (point-max))
        (if (> (point) save-point)
          start-code

Reply via email to