106106(require 'haskell-mode )
107107(require 'syntax )
108108(require 'imenu )
109+ (require 'subr-x )
109110
110111(defgroup haskell-decl-scan nil
111112 " Haskell declaration scanning (`imenu' support)."
@@ -537,11 +538,7 @@ datatypes) in a Haskell file for the `imenu' package."
537538 ; ; These lists are nested using `(INDEX-TITLE . INDEX-ALIST)'.
538539 (let* ((bird-literate (haskell-ds-bird-p))
539540 (index-alist '())
540- (index-class-alist '()) ; ; Classes
541- (index-var-alist '()) ; ; Variables
542- (index-imp-alist '()) ; ; Imports
543- (index-inst-alist '()) ; ; Instances
544- (index-type-alist '()) ; ; Datatypes
541+ (imenu (make-hash-table :test 'equal ))
545542 ; ; The result we wish to return.
546543 result)
547544 (goto-char (point-min ))
@@ -557,47 +554,23 @@ datatypes) in a Haskell file for the `imenu' package."
557554 (posns (cdr name-posns))
558555 (start-pos (car posns))
559556 (type (cdr result)))
560- ; ; Place `(name . start-pos)' in the correct alist.
561- (cl-case type
562- (variable
563- (setq index-var-alist
564- (cl-acons name start-pos index-var-alist)))
565- (datatype
566- (setq index-type-alist
567- (cl-acons name start-pos index-type-alist)))
568- (class
569- (setq index-class-alist
570- (cl-acons name start-pos index-class-alist)))
571- (import
572- (setq index-imp-alist
573- (cl-acons name start-pos index-imp-alist)))
574- (instance
575- (setq index-inst-alist
576- (cl-acons name start-pos index-inst-alist)))))))
557+ (puthash type
558+ (cons (cons name start-pos) (gethash type imenu '()))
559+ imenu))))
577560 ; ; Now sort all the lists, label them, and place them in one list.
578- (when index-type-alist
579- (push (cons " Datatypes"
580- (sort index-type-alist 'haskell-ds-imenu-label-cmp ))
581- index-alist))
582- (when index-inst-alist
583- (push (cons " Instances"
584- (sort index-inst-alist 'haskell-ds-imenu-label-cmp ))
585- index-alist))
586- (when index-imp-alist
587- (push (cons " Imports"
588- (sort index-imp-alist 'haskell-ds-imenu-label-cmp ))
589- index-alist))
590- (when index-class-alist
591- (push (cons " Classes"
592- (sort index-class-alist 'haskell-ds-imenu-label-cmp ))
593- index-alist))
594- (when index-var-alist
561+ (dolist (type '((datatype . " Datatypes" ) (instance . " Instances" )
562+ (import . " Imports" ) (class . " Classes" )))
563+ (when-let ((curr-alist (gethash (car type) imenu)))
564+ (push (cons (cdr type)
565+ (sort curr-alist 'haskell-ds-imenu-label-cmp ))
566+ index-alist)))
567+ (when-let ((var-alist (gethash 'variable imenu)))
595568 (if haskell-decl-scan-bindings-as-variables
596569 (push (cons " Variables"
597- (sort index- var-alist 'haskell-ds-imenu-label-cmp ))
570+ (sort var-alist 'haskell-ds-imenu-label-cmp ))
598571 index-alist)
599572 (setq index-alist (append index-alist
600- (sort index- var-alist 'haskell-ds-imenu-label-cmp )))))
573+ (sort var-alist 'haskell-ds-imenu-label-cmp )))))
601574 ; ; Return the alist.
602575 index-alist))
603576
0 commit comments