* lisp/imenu.el (imenu--sort-by-position): Fix to accept lists beyond
pairs.
* test/lisp/imenu-tests.el: Add 2 tests for `imenu--sort-by-position`.
(string-lessp (car item1) (car item2)))
(defun imenu--sort-by-position (item1 item2)
- (< (cdr item1) (cdr item2)))
+ "Comparison function to sort items depending on their position.
+Return non-nil if and only if ITEM1's position is lower than ITEM2's
+position."
+ (if (listp (cdr item1))
+ (< (cadr item1) (cadr item2))
+ (< (cdr item1) (cdr item2))))
(defun imenu--relative-position (&optional reverse)
"Support function to calculate relative position in buffer.
}
" '("a" "b" "c" "ABC_D"))
+(ert-deftest imenu--sort-by-position-pairs ()
+ (should (imenu--sort-by-position '("a" . 2) '("a" . 3)))
+ (should-not (imenu--sort-by-position '("a" . 3) '("a" . 2))))
+
+;; Regression test for bug#26457: 25.2; Cannot pass a function to
+;; imenu-generic-expression
+(ert-deftest imenu--sort-by-position-list ()
+ (should (imenu--sort-by-position '("a" 2 nil) '("a" 3 nil)))
+ (should-not (imenu--sort-by-position '("a" 3 nil) '("a" 2 nil))))
+
(provide 'imenu-tests)
;;; imenu-tests.el ends here