/[emacs]/emacs/lisp/imenu.el
ViewVC logotype

Diff of /emacs/lisp/imenu.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.93 by monnier, Tue May 6 15:16:27 2003 UTC revision 1.94 by monnier, Fri May 16 21:09:59 2003 UTC
# Line 1  Line 1 
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>
# Line 527  This variable is local in all buffers, o Line 527  This variable is local in all buffers, o
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    
# Line 634  as a way for the user to ask to recalcul Line 629  as a way for the user to ask to recalcul
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."
# Line 717  Their results are gathered into an index Line 711  Their results are gathered into an index
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.
# Line 905  INDEX-ALIST is the buffer index and EVEN Line 899  INDEX-ALIST is the buffer index and EVEN
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)
# Line 1001  This value becomes local in every buffer Line 995  This value becomes local in every buffer
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    

Legend:
Removed from v.1.93  
changed lines
  Added in v.1.94

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26