diff options
| author | Karl Heuer | 1998-09-30 19:21:01 +0000 |
|---|---|---|
| committer | Karl Heuer | 1998-09-30 19:21:01 +0000 |
| commit | c01ee596b5946168f30e5c37b7ac368be6e6564c (patch) | |
| tree | 7cfec4799aeda2598590f20ea7f742b6d4747fe0 | |
| parent | 2a1c4b9034d07d3e939714e8dc7c1fc4523bb941 (diff) | |
| download | emacs-c01ee596b5946168f30e5c37b7ac368be6e6564c.tar.gz emacs-c01ee596b5946168f30e5c37b7ac368be6e6564c.zip | |
(imenu--generic-function): Sort each submenu by position.
(imenu--sort-by-position): New function.
| -rw-r--r-- | lisp/imenu.el | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el index 3b062dedd39..2f353e111ec 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el | |||
| @@ -128,7 +128,7 @@ in the buffer. | |||
| 128 | 128 | ||
| 129 | Set it to `imenu--sort-by-name' if you want alphabetic sorting. | 129 | Set it to `imenu--sort-by-name' if you want alphabetic sorting. |
| 130 | 130 | ||
| 131 | The function should take two arguments and return T if the first | 131 | The function should take two arguments and return t if the first |
| 132 | element should come before the second. The arguments are cons cells; | 132 | element should come before the second. The arguments are cons cells; |
| 133 | \(NAME . POSITION). Look at `imenu--sort-by-name' for an example." | 133 | \(NAME . POSITION). Look at `imenu--sort-by-name' for an example." |
| 134 | :type '(choice (const :tag "No sorting" nil) | 134 | :type '(choice (const :tag "No sorting" nil) |
| @@ -443,11 +443,14 @@ This variable is local in all buffers, once set.") | |||
| 443 | ;;; | 443 | ;;; |
| 444 | ;;; Sort function | 444 | ;;; Sort function |
| 445 | ;;; Sorts the items depending on their index name. | 445 | ;;; Sorts the items depending on their index name. |
| 446 | ;;; An item look like (NAME . POSITION). | 446 | ;;; An item looks like (NAME . POSITION). |
| 447 | ;;; | 447 | ;;; |
| 448 | (defun imenu--sort-by-name (item1 item2) | 448 | (defun imenu--sort-by-name (item1 item2) |
| 449 | (string-lessp (car item1) (car item2))) | 449 | (string-lessp (car item1) (car item2))) |
| 450 | 450 | ||
| 451 | (defun imenu--sort-by-position (item1 item2) | ||
| 452 | (< (cdr item1) (cdr item2))) | ||
| 453 | |||
| 451 | (defun imenu--relative-position (&optional reverse) | 454 | (defun imenu--relative-position (&optional reverse) |
| 452 | ;; Support function to calculate relative position in buffer | 455 | ;; Support function to calculate relative position in buffer |
| 453 | ;; Beginning of buffer is 0 and end of buffer is 100 | 456 | ;; Beginning of buffer is 0 and end of buffer is 100 |
| @@ -814,15 +817,24 @@ PATTERNS." | |||
| 814 | rest) | 817 | rest) |
| 815 | (cons (match-string-no-properties index) | 818 | (cons (match-string-no-properties index) |
| 816 | beg))) | 819 | beg))) |
| 817 | (menu (cdr (assoc menu-title index-alist)))) | 820 | ;; This is the desired submenu, |
| 818 | ;; avoid duplicates from, e.g. cc-mode patterns | 821 | ;; starting with its title (or nil). |
| 819 | (unless (member item menu) | 822 | (menu (assoc menu-title index-alist))) |
| 820 | ;; insert the item after the (sub-)menu title | 823 | ;; Insert the item unless it is already present. |
| 821 | (setcdr (assoc menu-title index-alist) | 824 | (unless (member item (cdr menu)) |
| 822 | (cons item menu)))))))) | 825 | (setcdr menu |
| 826 | (cons item (cdr menu))))))))) | ||
| 823 | patterns) | 827 | patterns) |
| 824 | (set-syntax-table old-table))) | 828 | (set-syntax-table old-table))) |
| 825 | (imenu-progress-message prev-pos 100 t) | 829 | (imenu-progress-message prev-pos 100 t) |
| 830 | ;; Sort each submenu by position. | ||
| 831 | ;; This is in case one submenu gets items from two different regexps. | ||
| 832 | (let ((tail index-alist)) | ||
| 833 | (while tail | ||
| 834 | (if (listp (car tail)) | ||
| 835 | (setcdr (car tail) | ||
| 836 | (sort (cdr (car tail)) 'imenu--sort-by-position))) | ||
| 837 | (setq tail (cdr tail)))) | ||
| 826 | (let ((main-element (assq nil index-alist))) | 838 | (let ((main-element (assq nil index-alist))) |
| 827 | (nconc (delq main-element (delq 'dummy index-alist)) | 839 | (nconc (delq main-element (delq 'dummy index-alist)) |
| 828 | (cdr main-element))))) | 840 | (cdr main-element))))) |