diff options
| author | Dave Love | 2000-09-12 12:49:20 +0000 |
|---|---|---|
| committer | Dave Love | 2000-09-12 12:49:20 +0000 |
| commit | e26b2a2881694035e8bd037ac5e6d0c862aa38eb (patch) | |
| tree | fba22459309ead7bcb1f8b1de4bef5be42a943be | |
| parent | 3465cfd76fdf8e4851964d11f59264451666c5bc (diff) | |
| download | emacs-e26b2a2881694035e8bd037ac5e6d0c862aa38eb.tar.gz emacs-e26b2a2881694035e8bd037ac5e6d0c862aa38eb.zip | |
(imenu--truncate-items, imenu--cleanup)
(imenu--generic-function): Avoid mapcar.
(imenu--replace-spaces): Function removed.
(imenu--completion-buffer): Use subst-char-in-string.
(imenu-add-to-menubar): Use keymap inheritance.
| -rw-r--r-- | lisp/imenu.el | 144 |
1 files changed, 63 insertions, 81 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el index 393a1967ac1..cce78645c2b 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el | |||
| @@ -557,17 +557,15 @@ This variable is local in all buffers, once set.") | |||
| 557 | 557 | ||
| 558 | ;;; Truncate all strings in MENULIST to imenu-max-item-length | 558 | ;;; Truncate all strings in MENULIST to imenu-max-item-length |
| 559 | (defun imenu--truncate-items (menulist) | 559 | (defun imenu--truncate-items (menulist) |
| 560 | (mapcar (function | 560 | (dolist (item menulist) |
| 561 | (lambda (item) | 561 | (cond |
| 562 | (cond | 562 | ((consp (cdr item)) |
| 563 | ((consp (cdr item)) | 563 | (imenu--truncate-items (cdr item))) |
| 564 | (imenu--truncate-items (cdr item))) | 564 | (t |
| 565 | (t | 565 | ;; truncate if necessary |
| 566 | ;; truncate if necessary | 566 | (if (and (numberp imenu-max-item-length) |
| 567 | (if (and (numberp imenu-max-item-length) | 567 | (> (length (car item)) imenu-max-item-length)) |
| 568 | (> (length (car item)) imenu-max-item-length)) | 568 | (setcar item (substring (car item) 0 imenu-max-item-length))))))) |
| 569 | (setcar item (substring (car item) 0 imenu-max-item-length))))))) | ||
| 570 | menulist)) | ||
| 571 | 569 | ||
| 572 | 570 | ||
| 573 | (defun imenu--make-index-alist (&optional noerror) | 571 | (defun imenu--make-index-alist (&optional noerror) |
| @@ -618,16 +616,15 @@ as a way for the user to ask to recalculate the buffer's index alist." | |||
| 618 | (setq alist imenu--index-alist imenu--cleanup-seen (list alist))) | 616 | (setq alist imenu--index-alist imenu--cleanup-seen (list alist))) |
| 619 | 617 | ||
| 620 | (and alist | 618 | (and alist |
| 621 | (mapcar | 619 | (mapc |
| 622 | (function | 620 | (lambda (item) |
| 623 | (lambda (item) | 621 | (cond |
| 624 | (cond | 622 | ((markerp (cdr item)) |
| 625 | ((markerp (cdr item)) | 623 | (set-marker (cdr item) nil)) |
| 626 | (set-marker (cdr item) nil)) | 624 | ;; Don't process one alist twice. |
| 627 | ;; Don't process one alist twice. | 625 | ((memq (cdr item) imenu--cleanup-seen)) |
| 628 | ((memq (cdr item) imenu--cleanup-seen)) | 626 | ((imenu--subalist-p item) |
| 629 | ((imenu--subalist-p item) | 627 | (imenu--cleanup (cdr item))))) |
| 630 | (imenu--cleanup (cdr item)))))) | ||
| 631 | alist) | 628 | alist) |
| 632 | t)) | 629 | t)) |
| 633 | 630 | ||
| @@ -722,18 +719,6 @@ Their results are gathered into an index alist." | |||
| 722 | (t | 719 | (t |
| 723 | (error "This buffer cannot use `imenu-default-create-index-function'")))) | 720 | (error "This buffer cannot use `imenu-default-create-index-function'")))) |
| 724 | 721 | ||
| 725 | (defun imenu--replace-spaces (name replacement) | ||
| 726 | ;; Replace all spaces in NAME with REPLACEMENT. | ||
| 727 | ;; That second argument should be a string. | ||
| 728 | (mapconcat | ||
| 729 | (function | ||
| 730 | (lambda (ch) | ||
| 731 | (if (char-equal ch ?\ ) | ||
| 732 | replacement | ||
| 733 | (char-to-string ch)))) | ||
| 734 | name | ||
| 735 | "")) | ||
| 736 | |||
| 737 | ;; Not used and would require cl at run time | 722 | ;; Not used and would require cl at run time |
| 738 | ;;; (defun imenu--flatten-index-alist (index-alist &optional concat-names prefix) | 723 | ;;; (defun imenu--flatten-index-alist (index-alist &optional concat-names prefix) |
| 739 | ;;; ;; Takes a nested INDEX-ALIST and returns a flat index alist. | 724 | ;;; ;; Takes a nested INDEX-ALIST and returns a flat index alist. |
| @@ -806,10 +791,8 @@ PATTERNS." | |||
| 806 | ;; The character(s) to modify may be a single char or a string. | 791 | ;; The character(s) to modify may be a single char or a string. |
| 807 | (if (numberp (caar slist)) | 792 | (if (numberp (caar slist)) |
| 808 | (modify-syntax-entry (caar slist) (cdar slist) table) | 793 | (modify-syntax-entry (caar slist) (cdar slist) table) |
| 809 | (mapcar (function | 794 | (dolist (c (caar slist)) |
| 810 | (lambda (c) | 795 | (modify-syntax-entry c (cdar slist) table))) |
| 811 | (modify-syntax-entry c (cdar slist) table))) | ||
| 812 | (caar slist))) | ||
| 813 | (setq slist (cdr slist))) | 796 | (setq slist (cdr slist))) |
| 814 | (goto-char (point-max)) | 797 | (goto-char (point-max)) |
| 815 | (imenu-progress-message prev-pos 0 t) | 798 | (imenu-progress-message prev-pos 0 t) |
| @@ -818,39 +801,38 @@ PATTERNS." | |||
| 818 | (set-syntax-table table) | 801 | (set-syntax-table table) |
| 819 | ;; map over the elements of imenu-generic-expression | 802 | ;; map over the elements of imenu-generic-expression |
| 820 | ;; (typically functions, variables ...) | 803 | ;; (typically functions, variables ...) |
| 821 | (mapcar | 804 | (mapc |
| 822 | (function | 805 | (lambda (pat) |
| 823 | (lambda (pat) | 806 | (let ((menu-title (car pat)) |
| 824 | (let ((menu-title (car pat)) | 807 | (regexp (nth 1 pat)) |
| 825 | (regexp (nth 1 pat)) | 808 | (index (nth 2 pat)) |
| 826 | (index (nth 2 pat)) | 809 | (function (nth 3 pat)) |
| 827 | (function (nth 3 pat)) | 810 | (rest (nthcdr 4 pat))) |
| 828 | (rest (nthcdr 4 pat))) | 811 | ;; Go backwards for convenience of adding items in order. |
| 829 | ;; Go backwards for convenience of adding items in order. | 812 | (goto-char (point-max)) |
| 830 | (goto-char (point-max)) | 813 | (while (re-search-backward regexp nil t) |
| 831 | (while (re-search-backward regexp nil t) | 814 | (imenu-progress-message prev-pos nil t) |
| 832 | (imenu-progress-message prev-pos nil t) | 815 | (setq beg (match-beginning index)) |
| 833 | (setq beg (match-beginning index)) | 816 | ;; Add this sort of submenu only when we've found an |
| 834 | ;; Add this sort of submenu only when we've found an | 817 | ;; item for it, avoiding empty, duff menus. |
| 835 | ;; item for it, avoiding empty, duff menus. | 818 | (unless (assoc menu-title index-alist) |
| 836 | (unless (assoc menu-title index-alist) | 819 | (push (list menu-title) index-alist)) |
| 837 | (push (list menu-title) index-alist)) | 820 | (if imenu-use-markers |
| 838 | (if imenu-use-markers | 821 | (setq beg (copy-marker beg))) |
| 839 | (setq beg (set-marker (make-marker) beg))) | 822 | (let ((item |
| 840 | (let ((item | 823 | (if function |
| 841 | (if function | 824 | (nconc (list (match-string-no-properties index) |
| 842 | (nconc (list (match-string-no-properties index) | 825 | beg function) |
| 843 | beg function) | 826 | rest) |
| 844 | rest) | 827 | (cons (match-string-no-properties index) |
| 845 | (cons (match-string-no-properties index) | 828 | beg))) |
| 846 | beg))) | 829 | ;; This is the desired submenu, |
| 847 | ;; This is the desired submenu, | 830 | ;; starting with its title (or nil). |
| 848 | ;; starting with its title (or nil). | 831 | (menu (assoc menu-title index-alist))) |
| 849 | (menu (assoc menu-title index-alist))) | 832 | ;; Insert the item unless it is already present. |
| 850 | ;; Insert the item unless it is already present. | 833 | (unless (member item (cdr menu)) |
| 851 | (unless (member item (cdr menu)) | 834 | (setcdr menu |
| 852 | (setcdr menu | 835 | (cons item (cdr menu)))))))) |
| 853 | (cons item (cdr menu))))))))) | ||
| 854 | patterns) | 836 | patterns) |
| 855 | (set-syntax-table old-table))) | 837 | (set-syntax-table old-table))) |
| 856 | (imenu-progress-message prev-pos 100 t) | 838 | (imenu-progress-message prev-pos 100 t) |
| @@ -881,10 +863,10 @@ Returns t for rescan and otherwise a position number." | |||
| 881 | choice | 863 | choice |
| 882 | (prepared-index-alist | 864 | (prepared-index-alist |
| 883 | (mapcar | 865 | (mapcar |
| 884 | (function | 866 | (lambda (item) |
| 885 | (lambda (item) | 867 | (cons (subst-char-in-string ?\ (aref imenu-space-replacement 0) |
| 886 | (cons (imenu--replace-spaces (car item) imenu-space-replacement) | 868 | (car item)) |
| 887 | (cdr item)))) | 869 | (cdr item))) |
| 888 | index-alist))) | 870 | index-alist))) |
| 889 | (cond (prompt) | 871 | (cond (prompt) |
| 890 | ((and name (imenu--in-alist name prepared-index-alist)) | 872 | ((and name (imenu--in-alist name prepared-index-alist)) |
| @@ -1016,15 +998,15 @@ See the command `imenu' for more information." | |||
| 1016 | imenu-generic-expression | 998 | imenu-generic-expression |
| 1017 | (not (eq imenu-create-index-function | 999 | (not (eq imenu-create-index-function |
| 1018 | 'imenu-default-create-index-function))) | 1000 | 'imenu-default-create-index-function))) |
| 1019 | (let ((newmap (make-sparse-keymap)) | 1001 | (let ((newmap (make-sparse-keymap))) |
| 1020 | (menu-bar (lookup-key (current-local-map) [menu-bar]))) | 1002 | (set-keymap-parent newmap (current-local-map)) |
| 1021 | (setq imenu--last-menubar-index-alist nil) | 1003 | (setq imenu--last-menubar-index-alist nil) |
| 1022 | (define-key newmap [menu-bar] | 1004 | (define-key newmap [menu-bar] |
| 1023 | (append (make-sparse-keymap) menu-bar)) | 1005 | (let ((map (make-sparse-keymap))) |
| 1024 | (define-key newmap [menu-bar index] | 1006 | (define-key map [index] |
| 1025 | (cons name (nconc (make-sparse-keymap "Imenu") | 1007 | `(menu-item ,name ,(make-sparse-keymap "Imenu"))) |
| 1026 | (make-sparse-keymap)))) | 1008 | map)) |
| 1027 | (use-local-map (append newmap (current-local-map))) | 1009 | (use-local-map newmap) |
| 1028 | (add-hook 'menu-bar-update-hook 'imenu-update-menubar)) | 1010 | (add-hook 'menu-bar-update-hook 'imenu-update-menubar)) |
| 1029 | (error "The mode `%s' does not support Imenu" mode-name))) | 1011 | (error "The mode `%s' does not support Imenu" mode-name))) |
| 1030 | 1012 | ||