comparison lisp/imenu.el @ 7350:542ab48d0f18

(imenu-default-create-index-function): Temporarily build in handling of a few major modes. (imenu--completion-buffer): Set completion-reference-buffer properly.
author Richard M. Stallman <rms@gnu.org>
date Fri, 06 May 1994 06:06:08 +0000
parents cd73ba498964
children 67b7d1ea7b2e
comparison
equal deleted inserted replaced
7349:c1a962cf4e7a 7350:542ab48d0f18
288 "*Wrapper for index searching functions. 288 "*Wrapper for index searching functions.
289 289
290 Moves point to end of buffer and then repeatedly calls 290 Moves point to end of buffer and then repeatedly calls
291 `imenu-prev-index-position-function' and `imenu-extract-index-name-function'. 291 `imenu-prev-index-position-function' and `imenu-extract-index-name-function'.
292 Their results are gathered into an index alist." 292 Their results are gathered into an index alist."
293 293 ;; These should really be done by setting imenu-create-index-function
294 (or (and (fboundp imenu-prev-index-position-function) 294 ;; in these major modes. But save that change for later.
295 (fboundp imenu-extract-index-name-function)) 295 (cond ((eq major-mode 'emacs-lisp-mode)
296 (error "The mode \"%s\" does not take full advantage of imenu.el yet." 296 (imenu-example--create-lisp-index))
297 mode-name)) 297 ((eq major-mode 'lisp-mode)
298 (let ((index-alist '()) 298 (imenu-example--create-lisp-index))
299 name) 299 ((eq major-mode 'c++-mode)
300 (goto-char (point-max)) 300 (imenu-example--create-c++-index))
301 (imenu-progress-message 0 t) 301 ((eq major-mode 'c-mode)
302 ;; Search for the function 302 (imenu-example--create-c-index))
303 (while (funcall imenu-prev-index-position-function) 303 (t
304 (imenu-progress-message nil t) 304 (or (and (fboundp imenu-prev-index-position-function)
305 (save-excursion 305 (fboundp imenu-extract-index-name-function))
306 (setq name (funcall imenu-extract-index-name-function))) 306 (error "The mode \"%s\" does not take full advantage of imenu.el yet."
307 (and (stringp name) 307 mode-name))
308 (push (cons name (point)) index-alist))) 308 (let ((index-alist '())
309 (imenu-progress-message 100 t) 309 name)
310 index-alist)) 310 (goto-char (point-max))
311 (imenu-progress-message 0 t)
312 ;; Search for the function
313 (while (funcall imenu-prev-index-position-function)
314 (imenu-progress-message nil t)
315 (save-excursion
316 (setq name (funcall imenu-extract-index-name-function)))
317 (and (stringp name)
318 (push (cons name (point)) index-alist)))
319 (imenu-progress-message 100 t)
320 index-alist))))
311 321
312 (defun imenu--replace-spaces (name replacement) 322 (defun imenu--replace-spaces (name replacement)
313 ;; Replace all spaces in NAME with REPLACEMENT. 323 ;; Replace all spaces in NAME with REPLACEMENT.
314 ;; That second argument should be a string. 324 ;; That second argument should be a string.
315 (mapconcat 325 (mapconcat
364 (save-window-excursion 374 (save-window-excursion
365 ;; Display the completion buffer 375 ;; Display the completion buffer
366 (with-output-to-temp-buffer "*Completions*" 376 (with-output-to-temp-buffer "*Completions*"
367 (display-completion-list 377 (display-completion-list
368 (all-completions "" prepared-index-alist ))) 378 (all-completions "" prepared-index-alist )))
369 ;; Make a completion question 379 (let ((minibuffer-setup-hook
370 (setq name (completing-read (or prompt "Index item: ") 380 (function (lambda ()
381 (let ((buffer (current-buffer)))
382 (save-excursion
383 (set-buffer "*Completions*")
384 (setq completion-reference-buffer buffer)))))))
385 ;; Make a completion question
386 (setq name (completing-read (or prompt "Index item: ")
371 prepared-index-alist 387 prepared-index-alist
372 nil t nil 'imenu--history-list))) 388 nil t nil 'imenu--history-list))))
373 (cond 389 (cond ((not (stringp name))
374 ((not (stringp name)) 390 nil)
375 nil) 391 ((string= name (car imenu--rescan-item))
376 ((string= name (car imenu--rescan-item)) 392 t)
377 t) 393 (t
378 (t 394 (setq choice (assoc name prepared-index-alist))
379 (setq choice (assoc name prepared-index-alist)) 395 (if (listp (cdr choice))
380 (cond 396 (imenu--completion-buffer (cdr choice) prompt)
381 ((listp (cdr choice)) 397 choice)))))
382 (imenu--completion-buffer (cdr choice) prompt))
383 (t
384 choice))))))
385 398
386 (defun imenu--mouse-menu (index-alist event &optional title) 399 (defun imenu--mouse-menu (index-alist event &optional title)
387 "Let the user select from a buffer index from a mouse menu. 400 "Let the user select from a buffer index from a mouse menu.
388 401
389 INDEX-ALIST is the buffer index and EVENT is a mouse event. 402 INDEX-ALIST is the buffer index and EVENT is a mouse event.
598 "\\([a-zA-Z0-9_:*]+\\)[ \t]*(" ; name 611 "\\([a-zA-Z0-9_:*]+\\)[ \t]*(" ; name
599 )) 612 ))
600 (defun imenu-example--create-c++-index () 613 (defun imenu-example--create-c++-index ()
601 (imenu-example--create-c-index imenu-example--function-name-regexp-c++)) 614 (imenu-example--create-c-index imenu-example--function-name-regexp-c++))
602 615
603
604 ;;;
605 ;;; Example of hooks for the examples above
606 ;;; Put this in your .emacs.
607 ;;;
608 ;; (add-hook 'emacs-lisp-mode-hook
609 ;; (function
610 ;; (lambda ()
611 ;; (setq imenu-create-index-function
612 ;; (function imenu-example--create-lisp-index)))))
613
614 ;; (add-hook 'lisp-mode-hook
615 ;; (function
616 ;; (lambda ()
617 ;; (setq imenu-create-index-function
618 ;; (function imenu-example--create-lisp-index)))))
619
620 ;; (add-hook 'c++-mode-hook
621 ;; (function
622 ;; (lambda ()
623 ;; (setq imenu-create-index-function
624 ;; (function imenu-example--create-c++-index)))))
625
626 ;; (add-hook 'c-mode-hook
627 ;; (function
628 ;; (lambda ()
629 ;; (setq imenu-create-index-function
630 ;; (function imenu-example--create-c-index)))))
631
632 (provide 'imenu) 616 (provide 'imenu)
633 617
634 ;;; imenu.el ends here 618 ;;; imenu.el ends here