104
104
(require 'syntax )
105
105
(require 'cl-lib )
106
106
(require 'imenu )
107
+ (require 'subr-x )
107
108
108
109
(defgroup purescript-decl-scan nil
109
110
" PureScript declaration scanning (`imenu' support)."
@@ -453,6 +454,12 @@ positions and the type is one of the symbols \"variable\", \"datatype\",
453
454
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
454
455
; ; Declaration scanning via `imenu' .
455
456
457
+ (defmacro purescript-when-let (spec &rest body )
458
+ " A wrapper to silence `when-let' deprecation warning"
459
+ (if (fboundp 'when-let* )
460
+ (list 'when-let* spec (macroexp-progn body))
461
+ (with-no-warnings (list 'when-let spec (macroexp-progn body)))))
462
+
456
463
;;;### autoload
457
464
(defun purescript-ds-create-imenu-index ()
458
465
" Function for finding `imenu' declarations in PureScript mode.
@@ -462,11 +469,7 @@ datatypes) in a PureScript file for the `imenu' package."
462
469
; ; These lists are nested using `(INDEX-TITLE . INDEX-ALIST)'.
463
470
(let* ((bird-literate (purescript-ds-bird-p))
464
471
(index-alist '())
465
- (index-class-alist '()) ; ; Classes
466
- (index-var-alist '()) ; ; Variables
467
- (index-imp-alist '()) ; ; Imports
468
- (index-inst-alist '()) ; ; Instances
469
- (index-type-alist '()) ; ; Datatypes
472
+ (imenu (make-hash-table :test 'equal ))
470
473
; ; Variables for showing progress.
471
474
(bufname (buffer-name ))
472
475
(divisor-of-progress (max 1 (/ (buffer-size ) 100 )))
@@ -486,40 +489,25 @@ datatypes) in a PureScript file for the `imenu' package."
486
489
(name (car name-posns))
487
490
(posns (cdr name-posns))
488
491
(start-pos (car posns))
489
- (type (cdr result))
490
- ; ; Place `(name . start-pos)' in the correct alist.
491
- (sym (cdr (assq type
492
- '((variable . index-var-alist)
493
- (datatype . index-type-alist)
494
- (class . index-class-alist)
495
- (import . index-imp-alist)
496
- (instance . index-inst-alist))))))
497
- (set sym (cons (cons name start-pos) (symbol-value sym))))))
492
+ (type (cdr result)))
493
+ (puthash type
494
+ (cons (cons name start-pos) (gethash type imenu '()))
495
+ imenu))))
498
496
; ; Now sort all the lists, label them, and place them in one list.
499
497
(message " Sorting declarations in %s ... " bufname)
500
- (when index-type-alist
501
- (push (cons " Datatypes"
502
- (sort index-type-alist 'purescript-ds-imenu-label-cmp ))
503
- index-alist))
504
- (when index-inst-alist
505
- (push (cons " Instances"
506
- (sort index-inst-alist 'purescript-ds-imenu-label-cmp ))
507
- index-alist))
508
- (when index-imp-alist
509
- (push (cons " Imports"
510
- (sort index-imp-alist 'purescript-ds-imenu-label-cmp ))
511
- index-alist))
512
- (when index-class-alist
513
- (push (cons " Classes"
514
- (sort index-class-alist 'purescript-ds-imenu-label-cmp ))
515
- index-alist))
516
- (when index-var-alist
498
+ (dolist (type '((datatype . " Datatypes" ) (instance . " Instances" )
499
+ (import . " Imports" ) (class . " Classes" )))
500
+ (purescript-when-let ((curr-alist (gethash (car type) imenu)))
501
+ (push (cons (cdr type)
502
+ (sort curr-alist 'purescript-ds-imenu-label-cmp ))
503
+ index-alist)))
504
+ (purescript-when-let ((var-alist (gethash 'variable imenu)))
517
505
(if purescript-decl-scan-bindings-as-variables
518
506
(push (cons " Variables"
519
- (sort index- var-alist 'purescript-ds-imenu-label-cmp ))
507
+ (sort var-alist 'purescript-ds-imenu-label-cmp ))
520
508
index-alist)
521
509
(setq index-alist (append index-alist
522
- (sort index- var-alist 'purescript-ds-imenu-label-cmp )))))
510
+ (sort var-alist 'purescript-ds-imenu-label-cmp )))))
523
511
(message " Sorting declarations in %s ...done " bufname)
524
512
; ; Return the alist.
525
513
index-alist))
0 commit comments