Mercurial > emacs
comparison lisp/imenu.el @ 6241:49538e6c482e
entered into RCS
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 07 Mar 1994 23:24:02 +0000 |
parents | 4c72f80598ae |
children | 9e59751db725 |
comparison
equal
deleted
inserted
replaced
6240:5ce2192f76e1 | 6241:49538e6c482e |
---|---|
3 ;; Copyright (C) 1994 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1994 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se> | 5 ;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se> |
6 ;; Lars Lindberg <lli@sypro.cap.se> | 6 ;; Lars Lindberg <lli@sypro.cap.se> |
7 ;; Created: 8 Feb 1994 | 7 ;; Created: 8 Feb 1994 |
8 ;; Version: 1.4 | 8 ;; Version: 1.6 |
9 ;; Keywords: tools | 9 ;; Keywords: tools |
10 ;; | 10 ;; |
11 ;; This program is free software; you can redistribute it and/or modify | 11 ;; This program is free software; you can redistribute it and/or modify |
12 ;; it under the terms of the GNU General Public License as published by | 12 ;; it under the terms of the GNU General Public License as published by |
13 ;; the Free Software Foundation; either version 2, or (at your option) | 13 ;; the Free Software Foundation; either version 2, or (at your option) |
47 ;; | 47 ;; |
48 ;; (autoload 'imenu-choose-buffer-index "imenu" "Menu of buffer index." t) | 48 ;; (autoload 'imenu-choose-buffer-index "imenu" "Menu of buffer index." t) |
49 ;; (autoload 'goto-index-pos "imenu" "Goto buffer index position." t) | 49 ;; (autoload 'goto-index-pos "imenu" "Goto buffer index position." t) |
50 ;; (define-key global-map "\C-cj" 'goto-index-pos) ;; Or some other key | 50 ;; (define-key global-map "\C-cj" 'goto-index-pos) ;; Or some other key |
51 ;; (cond (window-system | 51 ;; (cond (window-system |
52 ;; (define-key global-map [S-down-mouse-3] 'goto-index-pos)) | 52 ;; (define-key global-map [S-down-mouse-3] 'goto-index-pos))) |
53 ;; Also run the 'add-hook' examples at the bottom of imenu.el. | |
53 | 54 |
54 ;;; Change Log: | 55 ;;; Change Log: |
55 ;; v1.4 Feb 18 1994ine-key global-map [S-down-mouse-3] 'goto-index-pos)) | 56 ;; v1.6 Feb 28 1994 Ake Stenhoff |
56 | 57 ;; Added alist as an optional argument to |
57 ;;; Change Log: | 58 ;; 'imenu-choose-buffer-index'. |
59 ;; Thanks [dean]. | |
60 ;; v1.5 Feb 25 1994 Ake Stenhoff | |
61 ;; Added code to parse DEFSTRUCT, DEFCLASS, DEFTYPE, | |
62 ;; DEFINE-CONDITION in the lisp example function. | |
63 ;; Thanks [simon]. | |
58 ;; v1.4 Feb 18 1994 Ake Stenhoff | 64 ;; v1.4 Feb 18 1994 Ake Stenhoff |
59 ;; Added 'imenu-create-submenu-name' for creating a submenu name. | 65 ;; Added 'imenu-create-submenu-name' for creating a submenu name. |
60 ;; This is for getting a general look of submenu names. | 66 ;; This is for getting a general look of submenu names. |
61 ;; Added variable 'imenu-submenu-name-format' used by | 67 ;; Added variable 'imenu-submenu-name-format' used by |
62 ;; 'imenu-create-submenu-name'. | 68 ;; 'imenu-create-submenu-name'. |
72 ;; v1.1 Feb 9 1994 Ake Stenhoff & Lars Lindberg | 78 ;; v1.1 Feb 9 1994 Ake Stenhoff & Lars Lindberg |
73 ;; Better comments (?). | 79 ;; Better comments (?). |
74 ;; v1.0 Feb 8 1994 Ake Stenhoff & Lars Lindberg | 80 ;; v1.0 Feb 8 1994 Ake Stenhoff & Lars Lindberg |
75 ;; Based on func-menu.el 3.5. | 81 ;; Based on func-menu.el 3.5. |
76 | 82 |
83 ;;; Thanks goes to | |
84 ;; [simon] - Simon Leinen simon@lia.di.epfl.ch | |
85 ;; [dean] - Dean Andrews ada@unison.com | |
86 ;; | |
87 | |
77 ;;; Code | 88 ;;; Code |
78 (require 'cl) | 89 (require 'cl) |
79 | 90 |
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 91 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
81 ;;; | 92 ;;; |
155 index and it should return nil when it doesn't find another index. ") | 166 index and it should return nil when it doesn't find another index. ") |
156 (make-variable-buffer-local 'prev-index-position-function) | 167 (make-variable-buffer-local 'prev-index-position-function) |
157 | 168 |
158 (defvar extract-index-name-function nil | 169 (defvar extract-index-name-function nil |
159 "Function for extracting the index name. | 170 "Function for extracting the index name. |
160 | |
161 This function is called after the function pointed out by | |
162 'prev-index-position-functioname. | |
163 | 171 |
164 This function is called after the function pointed out by | 172 This function is called after the function pointed out by |
165 'prev-index-position-function'.") | 173 'prev-index-position-function'.") |
166 (make-variable-buffer-local 'extract-index-name-function) | 174 (make-variable-buffer-local 'extract-index-name-function) |
167 | 175 |
285 (defun imenu-default-create-index-function () | 293 (defun imenu-default-create-index-function () |
286 "*Wrapper for index searching functions. | 294 "*Wrapper for index searching functions. |
287 | 295 |
288 Moves point to end of buffer and then repeatedly calls | 296 Moves point to end of buffer and then repeatedly calls |
289 'prev-index-position-function' and 'extract-index-name-function'. | 297 'prev-index-position-function' and 'extract-index-name-function'. |
290 Their results are gathered into an index aliition-function' and 'extract-index-name-function'. | |
291 Their results are gathered into an index alist." | 298 Their results are gathered into an index alist." |
292 | 299 |
293 (or (and (fboundp prev-index-position-function) | 300 (or (and (fboundp prev-index-position-function) |
294 (fboundp extract-index-name-function)) | 301 (fboundp extract-index-name-function)) |
295 (error "The mode \"%s\" does not take full advantage of imenu.el yet." | 302 (error "The mode \"%s\" does not take full advantage of imenu.el yet." |
396 position) | 403 position) |
397 (setq position (x-popup-menu event menu)) | 404 (setq position (x-popup-menu event menu)) |
398 (cond | 405 (cond |
399 ((eq position nil) | 406 ((eq position nil) |
400 position) | 407 position) |
401 ((not (numberp position)) | 408 ((listp position) |
402 (imenu--mouse-menu position event | 409 (imenu--mouse-menu position event |
403 (if title | 410 (if title |
404 (concat title imenu-level-separator | 411 (concat title imenu-level-separator |
405 (car (rassq position index-alist))) | 412 (car (rassq position index-alist))) |
406 (car (rassq position index-alist))))) | 413 (car (rassq position index-alist))))) |
407 ((= position (cdr imenu--rescan-item)) | 414 ((= position (cdr imenu--rescan-item)) |
408 t) | 415 t) |
409 (t | 416 (t |
410 (rassq position index-alist))))) | 417 (rassq position index-alist))))) |
411 | 418 |
412 (defun imenu-choose-buffer-index (&optional prompt) | 419 (defun imenu-choose-buffer-index (&optional prompt alist) |
413 "Let the user select from a buffer index and return the chosen index. | 420 "Let the user select from a buffer index and return the chosen index. |
414 | 421 |
415 If the user originally activated this function with the mouse, a mouse | 422 If the user originally activated this function with the mouse, a mouse |
416 menu is used. Otherwise f the user originally activated this function with the mouse, a mouse | |
417 menu is used. Otherwise a completion buffer is used and the user is | 423 menu is used. Otherwise a completion buffer is used and the user is |
418 prompted with PROMPT. | 424 prompted with PROMPT. |
425 | |
426 If you call this function with index alist ALIST, then it lets the user | |
427 select from ALIST. | |
428 | |
429 With no index alist ALIST, it calls 'imenu--make-index-alist' to | |
430 create the index alist. | |
419 | 431 |
420 If 'imenu-always-use-completion-buffer-p' is non-nil, then the | 432 If 'imenu-always-use-completion-buffer-p' is non-nil, then the |
421 completion buffer is always used, no matter if the mouse was used or | 433 completion buffer is always used, no matter if the mouse was used or |
422 not. | 434 not. |
423 | 435 |
430 (and mouse-triggered | 442 (and mouse-triggered |
431 (let ((window (posn-window (event-start last-command-event)))) | 443 (let ((window (posn-window (event-start last-command-event)))) |
432 (or (framep window) (select-window window)))) | 444 (or (framep window) (select-window window)))) |
433 ;; Create a list for this buffer only when needed. | 445 ;; Create a list for this buffer only when needed. |
434 (while (eq result t) | 446 (while (eq result t) |
435 (setq index-alist (imenu--make-index-alist)) | 447 (setq index-alist (if alist alist (imenu--make-index-alist))) |
436 (setq result | 448 (setq result |
437 (if (and mouse-triggered | 449 (if (and mouse-triggered |
438 (not imenu-always-use-completion-buffer-p)) | 450 (not imenu-always-use-completion-buffer-p)) |
439 (imenu--mouse-menu index-alist last-command-event) | 451 (imenu--mouse-menu index-alist last-command-event) |
440 (imenu--completion-buffer index-alist prompt))) | 452 (imenu--completion-buffer index-alist prompt))) |
491 (defun imenu-example--create-lisp-index () | 503 (defun imenu-example--create-lisp-index () |
492 ;; Example of a candidate for 'imenu-create-index-function'. | 504 ;; Example of a candidate for 'imenu-create-index-function'. |
493 ;; It will generate a nested index of definitions. | 505 ;; It will generate a nested index of definitions. |
494 (let ((index-alist '()) | 506 (let ((index-alist '()) |
495 (index-var-alist '()) | 507 (index-var-alist '()) |
508 (index-type-alist '()) | |
496 (index-unknown-alist '())) | 509 (index-unknown-alist '())) |
497 (goto-char (point-max)) | 510 (goto-char (point-max)) |
498 (imenu-progress-message 0) | 511 (imenu-progress-message 0) |
499 ;; Search for the function | 512 ;; Search for the function |
500 (while (beginning-of-defun) | 513 (while (beginning-of-defun) |
510 index-var-alist)) | 523 index-var-alist)) |
511 ((looking-at "def\\(un\\|subst\\|macro\\|advice\\)") | 524 ((looking-at "def\\(un\\|subst\\|macro\\|advice\\)") |
512 (forward-sexp 2) | 525 (forward-sexp 2) |
513 (push (imenu-example--name-and-position) | 526 (push (imenu-example--name-and-position) |
514 index-alist)) | 527 index-alist)) |
528 ((looking-at "def\\(type\\|struct\\|class\\|ine-condition\\)") | |
529 (forward-sexp 2) | |
530 (if (= (char-after (1- (point))) ?\)) | |
531 (progn | |
532 (forward-sexp -1) | |
533 (down-list 1) | |
534 (forward-sexp 1))) | |
535 (push (imenu-example--name-and-position) | |
536 index-type-alist)) | |
515 (t | 537 (t |
516 (forward-sexp 2) | 538 (forward-sexp 2) |
517 (push (imenu-example--name-and-position) | 539 (push (imenu-example--name-and-position) |
518 index-unknown-alist))))))) | 540 index-unknown-alist))))))) |
519 (imenu-progress-message 100) | 541 (imenu-progress-message 100) |
520 (and index-var-alist | 542 (and index-var-alist |
521 (push (cons (imenu-create-submenu-name "Variables") index-var-alist) | 543 (push (cons (imenu-create-submenu-name "Variables") index-var-alist) |
522 index-alist)) | 544 index-alist)) |
545 (and index-type-alist | |
546 (push (cons (imenu-create-submenu-name "Types") index-type-alist) | |
547 index-alist)) | |
523 (and index-unknown-alist | 548 (and index-unknown-alist |
524 (push (cons (imenu-create-submenu-name "Syntax-unknown") index-unknown-alist) | 549 (push (cons (imenu-create-submenu-name "Syntax-unknown") index-unknown-alist) |
525 index-alist)) | 550 index-alist)) |
526 index-alist)) | 551 index-alist)) |
527 | 552 |
534 (concat | 559 (concat |
535 "^[a-zA-Z0-9]+[ \t]?" ; type specs; there can be no | 560 "^[a-zA-Z0-9]+[ \t]?" ; type specs; there can be no |
536 "\\([a-zA-Z0-9_*]+[ \t]+\\)?" ; more than 3 tokens, right? | 561 "\\([a-zA-Z0-9_*]+[ \t]+\\)?" ; more than 3 tokens, right? |
537 "\\([a-zA-Z0-9_*]+[ \t]+\\)?" | 562 "\\([a-zA-Z0-9_*]+[ \t]+\\)?" |
538 "\\([*&]+[ \t]*\\)?" ; pointer | 563 "\\([*&]+[ \t]*\\)?" ; pointer |
539 "\\([a-zA-Z0-9_*]+\\)[ \t]*(" ; name | |
540 )) | |
541 | |
542 (defun imenu-example--create-c-index (&opter | |
543 "\\([a-zA-Z0-9_*]+\\)[ \t]*(" ; name | 564 "\\([a-zA-Z0-9_*]+\\)[ \t]*(" ; name |
544 )) | 565 )) |
545 | 566 |
546 (defun imenu-example--create-c-index (&optional regexp) | 567 (defun imenu-example--create-c-index (&optional regexp) |
547 (let ((index-alist '()) | 568 (let ((index-alist '()) |