1 |
;;; imenu.el --- framework for mode-specific buffer indexes |
;;; imenu.el --- framework for mode-specific buffer indexes |
2 |
|
|
3 |
;; Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. |
;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 2003 Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se> |
;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se> |
6 |
;; Lars Lindberg <lli@sypro.cap.se> |
;; Lars Lindberg <lli@sypro.cap.se> |
527 |
menulist (delq imenu--rescan-item menulist))) |
menulist (delq imenu--rescan-item menulist))) |
528 |
(setq tail menulist) |
(setq tail menulist) |
529 |
(dolist (item tail) |
(dolist (item tail) |
530 |
(if (imenu--subalist-p item) |
(when (imenu--subalist-p item) |
531 |
(setq keep-at-top (cons item keep-at-top) |
(push item keep-at-top) |
532 |
menulist (delq item menulist)))) |
(setq menulist (delq item menulist)))) |
533 |
(if imenu-sort-function |
(if imenu-sort-function |
534 |
(setq menulist |
(setq menulist (sort menulist imenu-sort-function))) |
|
(sort |
|
|
(copy-sequence menulist) |
|
|
imenu-sort-function))) |
|
535 |
(if (> (length menulist) imenu-max-items) |
(if (> (length menulist) imenu-max-items) |
536 |
(let ((count 0)) |
(setq menulist |
537 |
(setq menulist |
(mapcar |
538 |
(mapcar |
(lambda (menu) |
539 |
(function |
(cons (format "From: %s" (caar menu)) menu)) |
540 |
(lambda (menu) |
(imenu--split menulist imenu-max-items)))) |
|
(cons (format "From: %s" (caar menu)) menu))) |
|
|
(imenu--split menulist imenu-max-items))))) |
|
541 |
(cons title |
(cons title |
542 |
(nconc (nreverse keep-at-top) menulist)))) |
(nconc (nreverse keep-at-top) menulist)))) |
543 |
|
|
629 |
alist) |
alist) |
630 |
t)) |
t)) |
631 |
|
|
632 |
(defun imenu--create-keymap-1 (title alist) |
(defun imenu--create-keymap (title alist &optional cmd) |
633 |
(let ((counter 0)) |
(list* 'keymap title |
634 |
(list* 'keymap title |
(mapcar |
635 |
(mapcar |
(lambda (item) |
636 |
(lambda (item) |
(list* (car item) (car item) |
637 |
(list* (car item) (car item) |
(cond |
638 |
(cond |
((imenu--subalist-p item) |
639 |
((imenu--subalist-p item) |
(imenu--create-keymap (car item) (cdr item) cmd)) |
640 |
(imenu--create-keymap-1 (car item) (cdr item))) |
(t |
641 |
(t |
`(lambda () (interactive) |
642 |
`(lambda () (interactive) |
,(if cmd `(,cmd ',item) (list 'quote item))))))) |
643 |
(imenu--menubar-select ',item)))))) |
alist))) |
|
alist)))) |
|
644 |
|
|
645 |
(defun imenu--in-alist (str alist) |
(defun imenu--in-alist (str alist) |
646 |
"Check whether the string STR is contained in multi-level ALIST." |
"Check whether the string STR is contained in multi-level ALIST." |
711 |
(error "This buffer cannot use `imenu-default-create-index-function'")))) |
(error "This buffer cannot use `imenu-default-create-index-function'")))) |
712 |
|
|
713 |
;; Not used and would require cl at run time |
;; Not used and would require cl at run time |
714 |
;;; (defun imenu--flatten-index-alist (index-alist &optional concat-names prefix) |
;; (defun imenu--flatten-index-alist (index-alist &optional concat-names prefix) |
715 |
;;; ;; Takes a nested INDEX-ALIST and returns a flat index alist. |
;; ;; Takes a nested INDEX-ALIST and returns a flat index alist. |
716 |
;;; ;; If optional CONCAT-NAMES is non-nil, then a nested index has its |
;; ;; If optional CONCAT-NAMES is non-nil, then a nested index has its |
717 |
;;; ;; name and a space concatenated to the names of the children. |
;; ;; name and a space concatenated to the names of the children. |
718 |
;;; ;; Third argument PREFIX is for internal use only. |
;; ;; Third argument PREFIX is for internal use only. |
719 |
;;; (mapcan |
;; (mapcan |
720 |
;;; (lambda (item) |
;; (lambda (item) |
721 |
;;; (let* ((name (car item)) |
;; (let* ((name (car item)) |
722 |
;;; (pos (cdr item)) |
;; (pos (cdr item)) |
723 |
;;; (new-prefix (and concat-names |
;; (new-prefix (and concat-names |
724 |
;;; (if prefix |
;; (if prefix |
725 |
;;; (concat prefix imenu-level-separator name) |
;; (concat prefix imenu-level-separator name) |
726 |
;;; name)))) |
;; name)))) |
727 |
;;; (cond |
;; (cond |
728 |
;;; ((or (markerp pos) (numberp pos)) |
;; ((or (markerp pos) (numberp pos)) |
729 |
;;; (list (cons new-prefix pos))) |
;; (list (cons new-prefix pos))) |
730 |
;;; (t |
;; (t |
731 |
;;; (imenu--flatten-index-alist pos new-prefix))))) |
;; (imenu--flatten-index-alist pos new-prefix))))) |
732 |
;;; index-alist)) |
;; index-alist)) |
733 |
|
|
734 |
;;; |
;;; |
735 |
;;; Generic index gathering function. |
;;; Generic index gathering function. |
899 |
Returns t for rescan and otherwise an element or subelement of INDEX-ALIST." |
Returns t for rescan and otherwise an element or subelement of INDEX-ALIST." |
900 |
(setq index-alist (imenu--split-submenus index-alist)) |
(setq index-alist (imenu--split-submenus index-alist)) |
901 |
(let* ((menu (imenu--split-menu index-alist (or title (buffer-name)))) |
(let* ((menu (imenu--split-menu index-alist (or title (buffer-name)))) |
902 |
(map (imenu--create-keymap-1 (car menu) |
(map (imenu--create-keymap (car menu) |
903 |
(if (< 1 (length (cdr menu))) |
(cdr (if (< 1 (length (cdr menu))) |
904 |
(cdr menu) |
menu |
905 |
(cdr (car (cdr menu))))))) |
(car (cdr menu))))))) |
906 |
(popup-menu map event))) |
(popup-menu map event))) |
907 |
|
|
908 |
(defun imenu-choose-buffer-index (&optional prompt alist) |
(defun imenu-choose-buffer-index (&optional prompt alist) |
995 |
(setq index-alist (imenu--split-submenus index-alist)) |
(setq index-alist (imenu--split-submenus index-alist)) |
996 |
(setq menu (imenu--split-menu index-alist |
(setq menu (imenu--split-menu index-alist |
997 |
(buffer-name))) |
(buffer-name))) |
998 |
(setq menu1 (imenu--create-keymap-1 (car menu) |
(setq menu1 (imenu--create-keymap (car menu) |
999 |
(if (< 1 (length (cdr menu))) |
(cdr (if (< 1 (length (cdr menu))) |
1000 |
(cdr menu) |
menu |
1001 |
(cdr (car (cdr menu)))))) |
(car (cdr menu)))) |
1002 |
|
'imenu--menubar-select)) |
1003 |
(setq old (lookup-key (current-local-map) [menu-bar index])) |
(setq old (lookup-key (current-local-map) [menu-bar index])) |
1004 |
(setcdr old (cdr menu1))))))) |
(setcdr old (cdr menu1))))))) |
1005 |
|
|