branch: elpa/haskell-mode
commit d7b05e4b047d34d73278ce81ec2d355d1a5d1c83
Author: Pablo Castellanos <p.cas....@gmail.com>
Commit: Pablo Castellanos <p.cas....@gmail.com>

    Add user option to preserve the order of imenu candidates
---
 haskell-decl-scan.el | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/haskell-decl-scan.el b/haskell-decl-scan.el
index f32515ac6f..8299f34e61 100644
--- a/haskell-decl-scan.el
+++ b/haskell-decl-scan.el
@@ -124,6 +124,11 @@
   :group 'haskell-decl-scan
   :type 'boolean)
 
+(defcustom haskell-decl-scan-sort-imenu t
+  "Whether to sort the candidates in imenu."
+  :group 'haskell-decl-scan
+  :type 'boolean)
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; General declaration scanning functions.
 
@@ -562,15 +567,21 @@ datatypes) in a Haskell file for the `imenu' package."
                     (import   . "Imports")   (class    . "Classes")))
       (when-let ((curr-alist (gethash (car type) imenu)))
         (push (cons (cdr type)
-                    (sort curr-alist 'haskell-ds-imenu-label-cmp))
+                    (if haskell-decl-scan-sort-imenu
+                        (sort curr-alist 'haskell-ds-imenu-label-cmp)
+                      (reverse curr-alist)))
               index-alist)))
     (when-let ((var-alist (gethash 'variable imenu)))
       (if haskell-decl-scan-bindings-as-variables
           (push (cons "Variables"
-                      (sort var-alist 'haskell-ds-imenu-label-cmp))
+                      (if haskell-decl-scan-sort-imenu
+                          (sort var-alist 'haskell-ds-imenu-label-cmp)
+                        (reverse var-alist)))
                 index-alist)
         (setq index-alist (append index-alist
-                                  (sort var-alist 
'haskell-ds-imenu-label-cmp)))))
+                                  (if haskell-decl-scan-sort-imenu
+                                      (sort var-alist 
'haskell-ds-imenu-label-cmp)
+                                    (reverse var-alist))))))
     ;; Return the alist.
     index-alist))
 

Reply via email to