Function: haskell-sort-imports
haskell-sort-imports is an interactive and natively compiled function
defined in haskell-sort-imports.el.
Signature
(haskell-sort-imports)
Documentation
Sort the import list at point. It sorts the current group i.e. an import list separated by blank lines on either side.
If the region is active, it will restrict the imports to sort within that region.
Key Bindings
This command is not in any keymaps.
Source Code
;; Defined in /nix/store/9lz2mhw95f9fqxr9mnq46k3f6qz3aq83-emacs-packages-deps/share/emacs/site-lisp/elpa/haskell-mode-20260904.1042/haskell-sort-imports.el
;;;###autoload
(defun haskell-sort-imports ()
"Sort the import list at point. It sorts the current group
i.e. an import list separated by blank lines on either side.
If the region is active, it will restrict the imports to sort
within that region."
(interactive)
(when (haskell-sort-imports-at-import)
(let* ((points (haskell-sort-imports-decl-points))
(current-string (buffer-substring-no-properties (car points)
(cdr points)))
(current-offset (- (point) (car points))))
(if (region-active-p)
(progn (goto-char (region-beginning))
(haskell-sort-imports-goto-import-start))
(haskell-sort-imports-goto-group-start))
(let* ((start (point))
(imports (haskell-sort-imports-collect-imports))
(sorted (sort (cl-copy-list imports)
(lambda (a b)
(string< (haskell-sort-imports-normalize a)
(haskell-sort-imports-normalize b))))))
(when (not (equal imports sorted))
(delete-region start (point))
(mapc (lambda (import) (insert import "\n")) sorted))
(goto-char start)
(when (search-forward current-string nil t 1)
(forward-char (- (length current-string)))
(forward-char current-offset))))))