From: Damien Cassou Date: Wed, 12 Apr 2017 05:35:56 +0000 (+0200) Subject: Fix imenu--sort-by-position for non-pairs parameters (bug#26457) X-Git-Tag: emacs-26.0.90~521^2~643 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4e77ff0d45b88cade7836c01344cd8d892adfde8;p=emacs.git Fix imenu--sort-by-position for non-pairs parameters (bug#26457) * 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`. --- diff --git a/lisp/imenu.el b/lisp/imenu.el index 0f47a92734e..c1fd4005ab6 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -499,7 +499,12 @@ An item looks like (NAME . 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. diff --git a/test/lisp/imenu-tests.el b/test/lisp/imenu-tests.el index 480368fcbb6..93090947139 100644 --- a/test/lisp/imenu-tests.el +++ b/test/lisp/imenu-tests.el @@ -83,6 +83,16 @@ function ABC_D() } " '("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