comparison lisp/imenu.el @ 51024:4efabfff9aa1

(imenu--split-menu): Remove unused var `count'. Don't copy the sequence since we're already modifying it elsewhere. (imenu--create-keymap): Rename from imenu--create-keymap-1. Add optional `cmd' argument. Remove unused var `counter'. (imenu-update-menubar): Use the new arg to get the old behavior. (imenu--mouse-menu): Don't use the new arg to recover the lost behavior.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 16 May 2003 21:09:59 +0000
parents 1ac6f8245bff
children 695cf19ef79e
comparison
equal deleted inserted replaced
51023:684391d76c30 51024:4efabfff9aa1
1 ;;; imenu.el --- framework for mode-specific buffer indexes 1 ;;; imenu.el --- framework for mode-specific buffer indexes
2 2
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. 3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 2003 Free Software Foundation, Inc.
4 4
5 ;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se> 5 ;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se>
6 ;; Lars Lindberg <lli@sypro.cap.se> 6 ;; Lars Lindberg <lli@sypro.cap.se>
7 ;; Maintainer: FSF 7 ;; Maintainer: FSF
8 ;; Created: 8 Feb 1994 8 ;; Created: 8 Feb 1994
525 (if (memq imenu--rescan-item menulist) 525 (if (memq imenu--rescan-item menulist)
526 (setq keep-at-top (cons imenu--rescan-item nil) 526 (setq keep-at-top (cons imenu--rescan-item nil)
527 menulist (delq imenu--rescan-item menulist))) 527 menulist (delq imenu--rescan-item menulist)))
528 (setq tail menulist) 528 (setq tail menulist)
529 (dolist (item tail) 529 (dolist (item tail)
530 (if (imenu--subalist-p item) 530 (when (imenu--subalist-p item)
531 (setq keep-at-top (cons item keep-at-top) 531 (push item keep-at-top)
532 menulist (delq item menulist)))) 532 (setq menulist (delq item menulist))))
533 (if imenu-sort-function 533 (if imenu-sort-function
534 (setq menulist (sort menulist imenu-sort-function)))
535 (if (> (length menulist) imenu-max-items)
534 (setq menulist 536 (setq menulist
535 (sort 537 (mapcar
536 (copy-sequence menulist) 538 (lambda (menu)
537 imenu-sort-function))) 539 (cons (format "From: %s" (caar menu)) menu))
538 (if (> (length menulist) imenu-max-items) 540 (imenu--split menulist imenu-max-items))))
539 (let ((count 0))
540 (setq menulist
541 (mapcar
542 (function
543 (lambda (menu)
544 (cons (format "From: %s" (caar menu)) menu)))
545 (imenu--split menulist imenu-max-items)))))
546 (cons title 541 (cons title
547 (nconc (nreverse keep-at-top) menulist)))) 542 (nconc (nreverse keep-at-top) menulist))))
548 543
549 ;;; Split up each long alist that are nested within ALIST 544 ;;; Split up each long alist that are nested within ALIST
550 ;;; into nested alists. 545 ;;; into nested alists.
632 ((imenu--subalist-p item) 627 ((imenu--subalist-p item)
633 (imenu--cleanup (cdr item))))) 628 (imenu--cleanup (cdr item)))))
634 alist) 629 alist)
635 t)) 630 t))
636 631
637 (defun imenu--create-keymap-1 (title alist) 632 (defun imenu--create-keymap (title alist &optional cmd)
638 (let ((counter 0)) 633 (list* 'keymap title
639 (list* 'keymap title 634 (mapcar
640 (mapcar 635 (lambda (item)
641 (lambda (item) 636 (list* (car item) (car item)
642 (list* (car item) (car item) 637 (cond
643 (cond 638 ((imenu--subalist-p item)
644 ((imenu--subalist-p item) 639 (imenu--create-keymap (car item) (cdr item) cmd))
645 (imenu--create-keymap-1 (car item) (cdr item))) 640 (t
646 (t 641 `(lambda () (interactive)
647 `(lambda () (interactive) 642 ,(if cmd `(,cmd ',item) (list 'quote item)))))))
648 (imenu--menubar-select ',item)))))) 643 alist)))
649 alist))))
650 644
651 (defun imenu--in-alist (str alist) 645 (defun imenu--in-alist (str alist)
652 "Check whether the string STR is contained in multi-level ALIST." 646 "Check whether the string STR is contained in multi-level ALIST."
653 (let (elt head tail res) 647 (let (elt head tail res)
654 (setq res nil) 648 (setq res nil)
715 (imenu--generic-function imenu-generic-expression)) 709 (imenu--generic-function imenu-generic-expression))
716 (t 710 (t
717 (error "This buffer cannot use `imenu-default-create-index-function'")))) 711 (error "This buffer cannot use `imenu-default-create-index-function'"))))
718 712
719 ;; Not used and would require cl at run time 713 ;; Not used and would require cl at run time
720 ;;; (defun imenu--flatten-index-alist (index-alist &optional concat-names prefix) 714 ;; (defun imenu--flatten-index-alist (index-alist &optional concat-names prefix)
721 ;;; ;; Takes a nested INDEX-ALIST and returns a flat index alist. 715 ;; ;; Takes a nested INDEX-ALIST and returns a flat index alist.
722 ;;; ;; If optional CONCAT-NAMES is non-nil, then a nested index has its 716 ;; ;; If optional CONCAT-NAMES is non-nil, then a nested index has its
723 ;;; ;; name and a space concatenated to the names of the children. 717 ;; ;; name and a space concatenated to the names of the children.
724 ;;; ;; Third argument PREFIX is for internal use only. 718 ;; ;; Third argument PREFIX is for internal use only.
725 ;;; (mapcan 719 ;; (mapcan
726 ;;; (lambda (item) 720 ;; (lambda (item)
727 ;;; (let* ((name (car item)) 721 ;; (let* ((name (car item))
728 ;;; (pos (cdr item)) 722 ;; (pos (cdr item))
729 ;;; (new-prefix (and concat-names 723 ;; (new-prefix (and concat-names
730 ;;; (if prefix 724 ;; (if prefix
731 ;;; (concat prefix imenu-level-separator name) 725 ;; (concat prefix imenu-level-separator name)
732 ;;; name)))) 726 ;; name))))
733 ;;; (cond 727 ;; (cond
734 ;;; ((or (markerp pos) (numberp pos)) 728 ;; ((or (markerp pos) (numberp pos))
735 ;;; (list (cons new-prefix pos))) 729 ;; (list (cons new-prefix pos)))
736 ;;; (t 730 ;; (t
737 ;;; (imenu--flatten-index-alist pos new-prefix))))) 731 ;; (imenu--flatten-index-alist pos new-prefix)))))
738 ;;; index-alist)) 732 ;; index-alist))
739 733
740 ;;; 734 ;;;
741 ;;; Generic index gathering function. 735 ;;; Generic index gathering function.
742 ;;; 736 ;;;
743 737
903 INDEX-ALIST is the buffer index and EVENT is a mouse event. 897 INDEX-ALIST is the buffer index and EVENT is a mouse event.
904 898
905 Returns t for rescan and otherwise an element or subelement of INDEX-ALIST." 899 Returns t for rescan and otherwise an element or subelement of INDEX-ALIST."
906 (setq index-alist (imenu--split-submenus index-alist)) 900 (setq index-alist (imenu--split-submenus index-alist))
907 (let* ((menu (imenu--split-menu index-alist (or title (buffer-name)))) 901 (let* ((menu (imenu--split-menu index-alist (or title (buffer-name))))
908 (map (imenu--create-keymap-1 (car menu) 902 (map (imenu--create-keymap (car menu)
909 (if (< 1 (length (cdr menu))) 903 (cdr (if (< 1 (length (cdr menu)))
910 (cdr menu) 904 menu
911 (cdr (car (cdr menu))))))) 905 (car (cdr menu)))))))
912 (popup-menu map event))) 906 (popup-menu map event)))
913 907
914 (defun imenu-choose-buffer-index (&optional prompt alist) 908 (defun imenu-choose-buffer-index (&optional prompt alist)
915 "Let the user select from a buffer index and return the chosen index. 909 "Let the user select from a buffer index and return the chosen index.
916 910
999 (let (menu menu1 old) 993 (let (menu menu1 old)
1000 (setq imenu--last-menubar-index-alist index-alist) 994 (setq imenu--last-menubar-index-alist index-alist)
1001 (setq index-alist (imenu--split-submenus index-alist)) 995 (setq index-alist (imenu--split-submenus index-alist))
1002 (setq menu (imenu--split-menu index-alist 996 (setq menu (imenu--split-menu index-alist
1003 (buffer-name))) 997 (buffer-name)))
1004 (setq menu1 (imenu--create-keymap-1 (car menu) 998 (setq menu1 (imenu--create-keymap (car menu)
1005 (if (< 1 (length (cdr menu))) 999 (cdr (if (< 1 (length (cdr menu)))
1006 (cdr menu) 1000 menu
1007 (cdr (car (cdr menu)))))) 1001 (car (cdr menu))))
1002 'imenu--menubar-select))
1008 (setq old (lookup-key (current-local-map) [menu-bar index])) 1003 (setq old (lookup-key (current-local-map) [menu-bar index]))
1009 (setcdr old (cdr menu1))))))) 1004 (setcdr old (cdr menu1)))))))
1010 1005
1011 (defun imenu--menubar-select (item) 1006 (defun imenu--menubar-select (item)
1012 "Use Imenu to select the function or variable named in this menu ITEM." 1007 "Use Imenu to select the function or variable named in this menu ITEM."