Skip to content

Commit acad691

Browse files
committed
Add elm-imports-list utility function
See #119, cc @mewa
1 parent 9c182db commit acad691

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

elm-interactive.el

+17-2
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ in the file."
484484
(ws+ (concat spaces "+"))
485485
(upcase "[A-Z][A-Za-z0-9_]*")
486486
(lowcase "[a-z][A-Za-z0-9_]*")
487-
(as-form (concat ws+ "as" ws+ upcase))
487+
(as-form (concat ws+ "as" ws+ "\\(" upcase "\\)"))
488488
(exposing-union-type
489489
(concat upcase
490490
(re-? ws
@@ -511,13 +511,28 @@ in the file."
511511
")")))
512512
(concat "^import"
513513
ws+
514-
(concat upcase (re-* "\\." upcase))
514+
(concat "\\(" upcase (re-* "\\." upcase) "\\)")
515515
(re-? (re-or (concat as-form (re-? exposing-form))
516516
(concat exposing-form (re-? as-form)))))))
517517
"Regex to match elm import (including multiline).
518518
Import consists of the word \"import\", real package name, and optional
519519
\"as\" part, and \"exposing\" part, which may be ordered in either way.")
520520

521+
(defun elm-imports-list ()
522+
"Find all imports in the current buffer.
523+
Return a list of pairs of (NAME . FULL_NAME)."
524+
(save-excursion
525+
(save-match-data
526+
(let ((matches ()))
527+
(goto-char (point-min))
528+
(while (re-search-forward elm-import--pattern nil t)
529+
(let ((full (match-string 1))
530+
(as (match-string 2)))
531+
(push (cons full full) matches)
532+
(when as
533+
(push (cons as full) matches))))
534+
matches))))
535+
521536
;;;###autoload
522537
(defun elm-sort-imports ()
523538
"Sort the import list in the current buffer."

0 commit comments

Comments
 (0)