Skip to content

Commit 7f452cc

Browse files
authored
Merge pull request #1864 from pacastega/imenu-preserve-order
Add user option to preserve the order of imenu candidates
2 parents 8005478 + d7b05e4 commit 7f452cc

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

haskell-decl-scan.el

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
:group 'haskell-decl-scan
125125
:type 'boolean)
126126

127+
(defcustom haskell-decl-scan-sort-imenu t
128+
"Whether to sort the candidates in imenu."
129+
:group 'haskell-decl-scan
130+
:type 'boolean)
131+
127132
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128133
;; General declaration scanning functions.
129134

@@ -562,15 +567,21 @@ datatypes) in a Haskell file for the `imenu' package."
562567
(import . "Imports") (class . "Classes")))
563568
(when-let ((curr-alist (gethash (car type) imenu)))
564569
(push (cons (cdr type)
565-
(sort curr-alist 'haskell-ds-imenu-label-cmp))
570+
(if haskell-decl-scan-sort-imenu
571+
(sort curr-alist 'haskell-ds-imenu-label-cmp)
572+
(reverse curr-alist)))
566573
index-alist)))
567574
(when-let ((var-alist (gethash 'variable imenu)))
568575
(if haskell-decl-scan-bindings-as-variables
569576
(push (cons "Variables"
570-
(sort var-alist 'haskell-ds-imenu-label-cmp))
577+
(if haskell-decl-scan-sort-imenu
578+
(sort var-alist 'haskell-ds-imenu-label-cmp)
579+
(reverse var-alist)))
571580
index-alist)
572581
(setq index-alist (append index-alist
573-
(sort var-alist 'haskell-ds-imenu-label-cmp)))))
582+
(if haskell-decl-scan-sort-imenu
583+
(sort var-alist 'haskell-ds-imenu-label-cmp)
584+
(reverse var-alist))))))
574585
;; Return the alist.
575586
index-alist))
576587

0 commit comments

Comments
 (0)