Skip to content

Commit

Permalink
Sort on just module names (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdone committed May 19, 2014
1 parent 8f2a7e0 commit fbdc679
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion haskell-sort-imports.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@

;;; Code:

(defvar haskell-sort-imports-regexp
(concat "^import[ ]+"
"\\(qualified \\)?"
"[ ]*\\(\"[^\"]*\" \\)?"
"[ ]*\\([A-Za-z0-9_.']*.*\\)"))

;;;###autoload
(defun haskell-sort-imports ()
(interactive)
Expand All @@ -52,12 +58,21 @@ within that region."
(delete-region start (point))
(mapc (lambda (import)
(insert import "\n"))
(sort imports #'string<))
(sort imports (lambda (a b)
(string< (haskell-sort-imports-normalize a)
(haskell-sort-imports-normalize b)))))
(goto-char start)
(when (search-forward current-string nil t 1)
(forward-char (- (length current-string)))
(forward-char current-offset))))))

(defun haskell-sort-imports-normalize (i)
"Normalize an import, if possible, so that it can be sorted."
(if (string-match haskell-sort-imports-regexp
i)
(match-string 3 i)
i))

(defun haskell-sort-imports-collect-imports ()
(let ((imports (list)))
(while (looking-at "import")
Expand Down

0 comments on commit fbdc679

Please sign in to comment.