diff options
| -rw-r--r-- | lisp/imenu.el | 7 | ||||
| -rw-r--r-- | test/lisp/imenu-tests.el | 10 |
2 files changed, 16 insertions, 1 deletions
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)." | |||
| 499 | (string-lessp (car item1) (car item2))) | 499 | (string-lessp (car item1) (car item2))) |
| 500 | 500 | ||
| 501 | (defun imenu--sort-by-position (item1 item2) | 501 | (defun imenu--sort-by-position (item1 item2) |
| 502 | (< (cdr item1) (cdr item2))) | 502 | "Comparison function to sort items depending on their position. |
| 503 | Return non-nil if and only if ITEM1's position is lower than ITEM2's | ||
| 504 | position." | ||
| 505 | (if (listp (cdr item1)) | ||
| 506 | (< (cadr item1) (cadr item2)) | ||
| 507 | (< (cdr item1) (cdr item2)))) | ||
| 503 | 508 | ||
| 504 | (defun imenu--relative-position (&optional reverse) | 509 | (defun imenu--relative-position (&optional reverse) |
| 505 | "Support function to calculate relative position in buffer. | 510 | "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() | |||
| 83 | } | 83 | } |
| 84 | " '("a" "b" "c" "ABC_D")) | 84 | " '("a" "b" "c" "ABC_D")) |
| 85 | 85 | ||
| 86 | (ert-deftest imenu--sort-by-position-pairs () | ||
| 87 | (should (imenu--sort-by-position '("a" . 2) '("a" . 3))) | ||
| 88 | (should-not (imenu--sort-by-position '("a" . 3) '("a" . 2)))) | ||
| 89 | |||
| 90 | ;; Regression test for bug#26457: 25.2; Cannot pass a function to | ||
| 91 | ;; imenu-generic-expression | ||
| 92 | (ert-deftest imenu--sort-by-position-list () | ||
| 93 | (should (imenu--sort-by-position '("a" 2 nil) '("a" 3 nil))) | ||
| 94 | (should-not (imenu--sort-by-position '("a" 3 nil) '("a" 2 nil)))) | ||
| 95 | |||
| 86 | (provide 'imenu-tests) | 96 | (provide 'imenu-tests) |
| 87 | 97 | ||
| 88 | ;;; imenu-tests.el ends here | 98 | ;;; imenu-tests.el ends here |