aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Love1998-01-25 23:06:37 +0000
committerDave Love1998-01-25 23:06:37 +0000
commitfea79780e0af6a9864b5056b8f2aa53dbc6cd5c4 (patch)
tree562351a6cce79bf2af3e14613216bcbe1c0d99b7
parent73f48953972a8fd51b23c559b291ec69e73668b6 (diff)
downloademacs-fea79780e0af6a9864b5056b8f2aa53dbc6cd5c4.tar.gz
emacs-fea79780e0af6a9864b5056b8f2aa53dbc6cd5c4.zip
(imenu-syntax-alist): New buffer-local variable.
(imenu--generic-function): Use it. (imenu--split-menu): Don't (setcdr nil) with, say, empty functions list.
-rw-r--r--lisp/imenu.el105
1 files changed, 68 insertions, 37 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el
index eeaae1670fa..97c18ed494e 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -469,7 +469,8 @@ The function in this variable is called when selecting a normal index-item.")
469 (oldlist menulist)) 469 (oldlist menulist))
470 ;; Copy list method from the cl package `copy-list' 470 ;; Copy list method from the cl package `copy-list'
471 (while (consp oldlist) (push (pop oldlist) res)) 471 (while (consp oldlist) (push (pop oldlist) res))
472 (prog1 (nreverse res) (setcdr res oldlist))) 472 (if res ; in case, e.g. no functions defined
473 (prog1 (nreverse res) (setcdr res oldlist))))
473 imenu-sort-function))) 474 imenu-sort-function)))
474 (if (> (length menulist) imenu-max-items) 475 (if (> (length menulist) imenu-max-items)
475 (let ((count 0)) 476 (let ((count 0))
@@ -614,6 +615,18 @@ as a way for the user to ask to recalculate the buffer's index alist."
614 (setq alist nil res elt)))) 615 (setq alist nil res elt))))
615 res)) 616 res))
616 617
618(defvar imenu-syntax-alist nil
619 "Alist of syntax table modifiers to use while executing `imenu--generic-function'.
620
621The car of the assocs may be either a character or a string and the
622cdr is a syntax description appropriate fo `modify-syntax-entry'. For
623a string, all the characters in the string get the specified syntax.
624
625This is typically used to give word syntax to characters which
626normallsymbol syntax to simplify `imenu-expression'
627and speed-up matching.")
628(make-variable-buffer-local 'imenu-syntax-alist)
629
617(defun imenu-default-create-index-function () 630(defun imenu-default-create-index-function ()
618 "*Wrapper for index searching functions. 631 "*Wrapper for index searching functions.
619 632
@@ -732,45 +745,63 @@ pattern.
732 patterns "\\)\\|\\(") 745 patterns "\\)\\|\\(")
733 "\\)")) 746 "\\)"))
734 prev-pos 747 prev-pos
735 (case-fold-search imenu-case-fold-search))
736 748
749 (case-fold-search imenu-case-fold-search)
750 (old-table (syntax-table))
751 (table (copy-syntax-table (syntax-table)))
752 (slist imenu-syntax-alist))
753 ;; Modify the syntax table used while matching regexps.
754 (while slist
755 ;; The character to modify may be a single CHAR or a STRING.
756 (let ((chars (if (numberp (car (car slist)))
757 (list (car (car slist)))
758 (mapcar 'identity (car (car slist)))))
759 (syntax (cdr (car slist))))
760 (while chars
761 (modify-syntax-entry (car chars) syntax table)
762 (setq chars (cdr chars)))
763 (setq slist (cdr slist))))
737 (goto-char (point-max)) 764 (goto-char (point-max))
738 (imenu-progress-message prev-pos 0 t) 765 (imenu-progress-message prev-pos 0 t)
739 (save-match-data 766 (unwind-protect
740 (while (re-search-backward global-regexp nil t) 767 (progn
741 (imenu-progress-message prev-pos nil t) 768 (set-syntax-table table)
742 (setq found nil) 769 (save-match-data
743 (save-excursion 770 (while (re-search-backward global-regexp nil t)
744 (goto-char (match-beginning 0)) 771 (imenu-progress-message prev-pos nil t)
745 (mapcar 772 (setq found nil)
746 (function 773 (save-excursion
747 (lambda (pat) 774 (goto-char (match-beginning 0))
748 (let ((menu-title (car pat)) 775 (mapcar
749 (regexp (cadr pat)) 776 (function
750 (index (caddr pat)) 777 (lambda (pat)
751 (function (cadddr pat)) 778 (let ((menu-title (car pat))
752 (rest (cddddr pat))) 779 (regexp (cadr pat))
753 (if (and (not found) ; Only allow one entry; 780 (index (caddr pat))
754 (looking-at regexp)) 781 (function (cadddr pat))
755 (let ((beg (match-beginning index)) 782 (rest (cddddr pat)))
756 (end (match-end index))) 783 (if (and (not found) ; Only allow one entry;
757 (setq found t) 784 (looking-at regexp))
758 (push 785 (let ((beg (match-beginning index))
759 (let ((name 786 (end (match-end index)))
760 (buffer-substring-no-properties beg end))) 787 (setq found t)
761 ;; [ydi] updated for imenu-use-markers 788 (push
762 (if imenu-use-markers 789 (let ((name
763 (setq beg (set-marker (make-marker) beg))) 790 (buffer-substring-no-properties beg end)))
764 (if function 791 ;; [ydi] updated for imenu-use-markers
765 (nconc (list name beg function) 792 (if imenu-use-markers
766 rest) 793 (setq beg (set-marker (make-marker) beg)))
767 (cons name beg))) 794 (if function
768 (cdr 795 (nconc (list name beg function)
769 (or (assoc menu-title index-alist) 796 rest)
770 (car (push 797 (cons name beg)))
771 (cons menu-title '()) 798 (cdr
772 index-alist)))))))))) 799 (or (assoc menu-title index-alist)
773 patterns)))) 800 (car (push
801 (cons menu-title '())
802 index-alist))))))))))
803 patterns)))
804 (set-syntax-table old-table))))
774 (imenu-progress-message prev-pos 100 t) 805 (imenu-progress-message prev-pos 100 t)
775 (let ((main-element (assq nil index-alist))) 806 (let ((main-element (assq nil index-alist)))
776 (nconc (delq main-element (delq 'dummy index-alist)) 807 (nconc (delq main-element (delq 'dummy index-alist))