aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-04-05 21:41:59 +0000
committerRichard M. Stallman1997-04-05 21:41:59 +0000
commite7c8378c39bbb87659d3b9251dcc28b0d8cdb509 (patch)
tree6d385db0eee8985ea1b7067c94368d28dbdb95e2
parent5eb9cf977780042cf36619b01fa8caadd7ee89a7 (diff)
downloademacs-e7c8378c39bbb87659d3b9251dcc28b0d8cdb509.tar.gz
emacs-e7c8378c39bbb87659d3b9251dcc28b0d8cdb509.zip
(imenu-default-goto-function): Simplify.
Truncate imenu items. Make use of markers or integers an option. (imenu-use-markers, imenu-max-item-length): New variables. (imenu-max-items): Doc fix. (imenu-example--name-and-position): Handle imenu-use-markers. (imenu-default-create-index-function): Likewise. (imenu--generic-function): Likewise. (imenu--truncate-items): New function. (imenu--make-index-alist): Call imenu--truncate-items.
-rw-r--r--lisp/imenu.el96
1 files changed, 55 insertions, 41 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el
index c3f2c959555..495ca8f1b8e 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -65,20 +65,29 @@
65;;; 65;;;
66;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 66;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
67 67
68(defvar imenu-use-markers t
69 "*Non-nil means use markers instead of integers for Imenu buffer positions.
70Setting this to nil makes Imenu work faster.
71
72This might not yet be honored by all index-building functions.")
73
74(defvar imenu-max-item-length 60
75 "*If a number, truncate Imenu entries to that length.")
76
68(defvar imenu-auto-rescan nil 77(defvar imenu-auto-rescan nil
69 "*Non-nil means Imenu should always rescan the buffers.") 78 "*Non-nil means Imenu should always rescan the buffers.")
70 79
71(defvar imenu-auto-rescan-maxout 60000 80(defvar imenu-auto-rescan-maxout 60000
72 "* auto-rescan is disabled in buffers larger than this. 81 "*Imenu auto-rescan is disabled in buffers larger than this size.
73This variable is buffer-local.") 82This variable is buffer-local.")
74 83
75(defvar imenu-always-use-completion-buffer-p nil 84(defvar imenu-always-use-completion-buffer-p nil
76 "*Set this to non-nil for displaying the index in a completion buffer. 85 "*Set this to non-nil for displaying the index in a completion buffer.
77 86
78Non-nil means always display the index in a completion buffer. 87`never' means never automatically display a listing of any kind.
79Nil means display the index as a mouse menu when the mouse was 88A value of nil (the default) means display the index as a mouse menu
80used to invoke `imenu'. 89if the mouse was used to invoke `imenu'.
81`never' means never automatically display a listing of any kind.") 90Another non-nil value means always display the index in a completion buffer.")
82 91
83(defvar imenu-sort-function nil 92(defvar imenu-sort-function nil
84 "*The function to use for sorting the index mouse-menu. 93 "*The function to use for sorting the index mouse-menu.
@@ -96,7 +105,7 @@ element should come before the second. The arguments are cons cells;
96\(NAME . POSITION). Look at `imenu--sort-by-name' for an example.") 105\(NAME . POSITION). Look at `imenu--sort-by-name' for an example.")
97 106
98(defvar imenu-max-items 25 107(defvar imenu-max-items 25
99 "*Maximum number of elements in an mouse menu for Imenu.") 108 "*Maximum number of elements in a mouse menu for Imenu.")
100 109
101(defvar imenu-scanning-message "Scanning buffer for index (%3d%%)" 110(defvar imenu-scanning-message "Scanning buffer for index (%3d%%)"
102 "*Progress message during the index scanning of the buffer. 111 "*Progress message during the index scanning of the buffer.
@@ -232,12 +241,11 @@ The function in this variable is called when selecting a normal index-item.")
232(defun imenu-example--name-and-position () 241(defun imenu-example--name-and-position ()
233 (save-excursion 242 (save-excursion
234 (forward-sexp -1) 243 (forward-sexp -1)
235 (let ((beg (point)) 244 ;; [ydi] modified for imenu-use-markers
236 (end (progn (forward-sexp) (point))) 245 (let ((beg (if imenu-use-markers (point-marker) (point)))
237 (marker (make-marker))) 246 (end (progn (forward-sexp) (point))))
238 (set-marker marker beg)
239 (cons (buffer-substring beg end) 247 (cons (buffer-substring beg end)
240 marker)))) 248 beg))))
241 249
242;;; 250;;;
243;;; Lisp 251;;; Lisp
@@ -453,6 +461,21 @@ The function in this variable is called when selecting a normal index-item.")
453 elt))) 461 elt)))
454 alist)) 462 alist))
455 463
464;;; Truncate all strings in MENULIST to imenu-max-item-length
465(defun imenu--truncate-items (menulist)
466 (mapcar (function
467 (lambda (item)
468 (cond
469 ((consp (cdr item))
470 (imenu--truncate-items (cdr item)))
471 (t
472 ;; truncate if necessary
473 (if (and (numberp imenu-max-item-length)
474 (> (length (car item)) imenu-max-item-length))
475 (setcar item (substring (car item) 0 imenu-max-item-length)))))))
476 menulist))
477
478
456(defun imenu--make-index-alist (&optional noerror) 479(defun imenu--make-index-alist (&optional noerror)
457 "Create an index-alist for the definitions in the current buffer. 480 "Create an index-alist for the definitions in the current buffer.
458 481
@@ -468,12 +491,14 @@ as a way for the user to ask to recalculate the buffer's index alist."
468 (or (not imenu-auto-rescan) 491 (or (not imenu-auto-rescan)
469 (and imenu-auto-rescan 492 (and imenu-auto-rescan
470 (> (buffer-size) imenu-auto-rescan-maxout)))) 493 (> (buffer-size) imenu-auto-rescan-maxout))))
471 ;; Get the index 494 ;; Get the index; truncate if necessary
472 (setq imenu--index-alist 495 (progn
473 (save-excursion 496 (setq imenu--index-alist
474 (save-restriction 497 (save-excursion
475 (widen) 498 (save-restriction
476 (funcall imenu-create-index-function))))) 499 (widen)
500 (funcall imenu-create-index-function))))
501 (imenu--truncate-items imenu--index-alist)))
477 (or imenu--index-alist noerror 502 (or imenu--index-alist noerror
478 (error "No items suitable for an index found in this buffer")) 503 (error "No items suitable for an index found in this buffer"))
479 (or imenu--index-alist 504 (or imenu--index-alist
@@ -577,14 +602,16 @@ Their results are gathered into an index alist."
577 (save-excursion 602 (save-excursion
578 (setq name (funcall imenu-extract-index-name-function))) 603 (setq name (funcall imenu-extract-index-name-function)))
579 (and (stringp name) 604 (and (stringp name)
580 (push (cons name (point)) index-alist))) 605 ;; [ydi] updated for imenu-use-markers
606 (push (cons name (if imenu-use-markers (point-marker) (point)))
607 index-alist)))
581 (imenu-progress-message prev-pos 100 t) 608 (imenu-progress-message prev-pos 100 t)
582 index-alist)) 609 index-alist))
583 ;; Use generic expression if possible. 610 ;; Use generic expression if possible.
584 ((and imenu-generic-expression) 611 ((and imenu-generic-expression)
585 (imenu--generic-function imenu-generic-expression)) 612 (imenu--generic-function imenu-generic-expression))
586 (t 613 (t
587 (error "The mode `%s' does not support Imenu" mode-name)))) 614 (error "This buffer cannot use `imenu-default-create-index-function'"))))
588 615
589(defun imenu--replace-spaces (name replacement) 616(defun imenu--replace-spaces (name replacement)
590 ;; Replace all spaces in NAME with REPLACEMENT. 617 ;; Replace all spaces in NAME with REPLACEMENT.
@@ -683,13 +710,15 @@ pattern.
683 (rest (cddddr pat))) 710 (rest (cddddr pat)))
684 (if (and (not found) ; Only allow one entry; 711 (if (and (not found) ; Only allow one entry;
685 (looking-at regexp)) 712 (looking-at regexp))
686 (let ((beg (make-marker)) 713 (let ((beg (match-beginning index))
687 (end (match-end index))) 714 (end (match-end index)))
688 (set-marker beg (match-beginning index))
689 (setq found t) 715 (setq found t)
690 (push 716 (push
691 (let ((name 717 (let ((name
692 (buffer-substring-no-properties beg end))) 718 (buffer-substring-no-properties beg end)))
719 ;; [ydi] updated for imenu-use-markers
720 (if imenu-use-markers
721 (setq beg (set-marker (make-marker) beg)))
693 (if function 722 (if function
694 (nconc (list name beg function) 723 (nconc (list name beg function)
695 rest) 724 rest)
@@ -890,30 +919,15 @@ See the command `imenu' for more information."
890 (imenu item))) 919 (imenu item)))
891 920
892(defun imenu-default-goto-function (name position &optional rest) 921(defun imenu-default-goto-function (name position &optional rest)
893"This function is used for moving the point at POSITION. 922 "This function is used for moving the point to POSITION.
894The NAME and REST parameters are not used, they are here just to make 923The NAME and REST parameters are not used, they are here just to make
895this function have the same interface as a function placed in a special 924this function have the same interface as a function placed in a special
896index-item" 925index-item."
897 (cond 926 (if (or (< position (point-min))
898 ((markerp position) 927 (> position (point-max)))
899 (if (or (< (marker-position position) (point-min))
900 (> (marker-position position) (point-max)))
901 ;; widen if outside narrowing 928 ;; widen if outside narrowing
902 (widen)) 929 (widen))
903 (goto-char (marker-position position))) 930 (goto-char position))
904;;; ;this never happens!
905;;; ((imenu--subalist-p index-item)
906;;; (if (or (< (cdr index-item) (point-min))
907;;; (> (cdr index-item) (point-max)))
908;;; ;; widen if outside narrowing
909;;; (widen))
910;;; (goto-char (cdr index-item)))
911 (t
912 (if (or (< (cdr index-item) (point-min))
913 (> (cdr index-item) (point-max)))
914 ;; widen if outside narrowing
915 (widen))
916 (goto-char (cdr index-item)))))
917 931
918;;;###autoload 932;;;###autoload
919(defun imenu (index-item) 933(defun imenu (index-item)