diff options
| author | Richard M. Stallman | 1994-08-01 07:11:43 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-08-01 07:11:43 +0000 |
| commit | 5d3b0f182f500449cc404d56ec141d83eb35581c (patch) | |
| tree | 23bd5deddf9ac18f198a9d83031a82c809b3861a | |
| parent | f150bd2b3e0d5d2540ae45b5bfd3d09735a2ea8f (diff) | |
| download | emacs-5d3b0f182f500449cc404d56ec141d83eb35581c.tar.gz emacs-5d3b0f182f500449cc404d56ec141d83eb35581c.zip | |
(imenu, imenu--flatten-index-alist): Add marker support.
(imenu--cleanup): New function.
(imenu-example--name-and-position): Now uses markers.
(imenu-add-to-menubar): New function to add an entry
to the menubar for the buffer's current local keymap.
| -rw-r--r-- | lisp/imenu.el | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el index f8daa05aea9..efac45d8778 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el | |||
| @@ -5,7 +5,7 @@ | |||
| 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.7 | 8 | ;; Version: 1.11 |
| 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 |
| @@ -43,6 +43,15 @@ | |||
| 43 | ;; supplied. | 43 | ;; supplied. |
| 44 | 44 | ||
| 45 | ;;; Change Log: | 45 | ;;; Change Log: |
| 46 | ;; v1.11 Jul 26 1994 Ake Stenhoff | ||
| 47 | ;; Fixed bugs in 'imenu-add-to-menubar'. | ||
| 48 | ;; v1.10 Jul 21 1994 Ake Stenhoff | ||
| 49 | ;; Added support for markers. | ||
| 50 | ;; Changed the examples to use | ||
| 51 | ;; markers. | ||
| 52 | ;; Thanks [alon]. | ||
| 53 | ;; v1.9 Jun 14 1994 Ake Stenhoff | ||
| 54 | ;; Added 'imenu-add-to-menubar'. | ||
| 46 | ;; v1.7 Apr 12 1994 Ake Stenhoff | 55 | ;; v1.7 Apr 12 1994 Ake Stenhoff |
| 47 | ;; Changed doc strings refering to symbols. | 56 | ;; Changed doc strings refering to symbols. |
| 48 | ;; Require 'cl' when compiling only. | 57 | ;; Require 'cl' when compiling only. |
| @@ -77,7 +86,7 @@ | |||
| 77 | ;;; Thanks goes to | 86 | ;;; Thanks goes to |
| 78 | ;; [simon] - Simon Leinen simon@lia.di.epfl.ch | 87 | ;; [simon] - Simon Leinen simon@lia.di.epfl.ch |
| 79 | ;; [dean] - Dean Andrews ada@unison.com | 88 | ;; [dean] - Dean Andrews ada@unison.com |
| 80 | ;; | 89 | ;; [alon] - Alon Albert al@mercury.co.il |
| 81 | 90 | ||
| 82 | ;;; Code | 91 | ;;; Code |
| 83 | (eval-when-compile (require 'cl)) | 92 | (eval-when-compile (require 'cl)) |
| @@ -287,7 +296,25 @@ This function is called after the function pointed out by | |||
| 287 | (error "No items suitable for an index found in this buffer.")) | 296 | (error "No items suitable for an index found in this buffer.")) |
| 288 | ;; Add a rescan option to the index. | 297 | ;; Add a rescan option to the index. |
| 289 | (cons imenu--rescan-item imenu--index-alist)) | 298 | (cons imenu--rescan-item imenu--index-alist)) |
| 290 | 299 | ;;; | |
| 300 | ;;; Find all markers in alist and makes | ||
| 301 | ;;; them point nowhere. | ||
| 302 | ;;; | ||
| 303 | (defun imenu--cleanup (&optional alist) | ||
| 304 | ;; Sets the markers in imenu--index-alist | ||
| 305 | ;; point nowhere. | ||
| 306 | ;; if alist is provided use that list. | ||
| 307 | (and imenu--index-alist | ||
| 308 | (mapc | ||
| 309 | (function | ||
| 310 | (lambda (item) | ||
| 311 | (cond | ||
| 312 | ((markerp (cdr item)) | ||
| 313 | (set-marker (cdr item) nil)) | ||
| 314 | ((listp (cdr item)) | ||
| 315 | (imenu--cleanup (cdr item)))))) | ||
| 316 | (if alist alist imenu--index-alist)) | ||
| 317 | t)) | ||
| 291 | (defun imenu-default-create-index-function () | 318 | (defun imenu-default-create-index-function () |
| 292 | "*Wrapper for index searching functions. | 319 | "*Wrapper for index searching functions. |
| 293 | 320 | ||
| @@ -350,7 +377,7 @@ Their results are gathered into an index alist." | |||
| 350 | (concat prefix imenu-level-separator name) | 377 | (concat prefix imenu-level-separator name) |
| 351 | name)))) | 378 | name)))) |
| 352 | (cond | 379 | (cond |
| 353 | ((numberp pos) | 380 | ((or (markerp pos) (numberp pos)) |
| 354 | (list (cons new-prefix pos))) | 381 | (list (cons new-prefix pos))) |
| 355 | (t | 382 | (t |
| 356 | (imenu--flatten-index-alist pos new-prefix)))))) | 383 | (imenu--flatten-index-alist pos new-prefix)))))) |
| @@ -468,9 +495,20 @@ The returned value is on the form (INDEX-NAME . INDEX-POSITION)." | |||
| 468 | (imenu--mouse-menu index-alist last-nonmenu-event) | 495 | (imenu--mouse-menu index-alist last-nonmenu-event) |
| 469 | (imenu--completion-buffer index-alist prompt))) | 496 | (imenu--completion-buffer index-alist prompt))) |
| 470 | (and (eq result t) | 497 | (and (eq result t) |
| 498 | (imenu--cleanup) | ||
| 471 | (setq imenu--index-alist nil))) | 499 | (setq imenu--index-alist nil))) |
| 472 | result)) | 500 | result)) |
| 473 | 501 | ||
| 502 | (defun imenu-add-to-menubar (name) | ||
| 503 | "Adds an \"imenu\" entry to the menubar for the | ||
| 504 | current local keymap. | ||
| 505 | NAME is the string naming the menu to be added. | ||
| 506 | See 'imenu' for more information." | ||
| 507 | (interactive "sMenu name: ") | ||
| 508 | (and window-system | ||
| 509 | (define-key (current-local-map) [menu-bar index] | ||
| 510 | (cons name 'imenu)))) | ||
| 511 | |||
| 474 | ;;;###autoload | 512 | ;;;###autoload |
| 475 | (defun imenu () | 513 | (defun imenu () |
| 476 | "Jump to a place in the buffer chosen using a buffer menu or mouse menu. | 514 | "Jump to a place in the buffer chosen using a buffer menu or mouse menu. |
| @@ -480,7 +518,12 @@ See `imenu-choose-buffer-index' for more information." | |||
| 480 | (and index-item | 518 | (and index-item |
| 481 | (progn | 519 | (progn |
| 482 | (push-mark) | 520 | (push-mark) |
| 483 | (goto-char (cdr index-item)))))) | 521 | (cond |
| 522 | ((markerp (cdr index-item)) | ||
| 523 | (goto-char (marker-position (cdr index-item)))) | ||
| 524 | (t | ||
| 525 | (goto-char (cdr index-item)))))))) | ||
| 526 | |||
| 484 | 527 | ||
| 485 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 528 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 486 | ;;;; | 529 | ;;;; |
| @@ -495,9 +538,11 @@ See `imenu-choose-buffer-index' for more information." | |||
| 495 | (save-excursion | 538 | (save-excursion |
| 496 | (forward-sexp -1) | 539 | (forward-sexp -1) |
| 497 | (let ((beg (point)) | 540 | (let ((beg (point)) |
| 498 | (end (progn (forward-sexp) (point)))) | 541 | (end (progn (forward-sexp) (point))) |
| 542 | (marker (make-marker))) | ||
| 543 | (set-marker marker beg) | ||
| 499 | (cons (buffer-substring beg end) | 544 | (cons (buffer-substring beg end) |
| 500 | beg)))) | 545 | marker)))) |
| 501 | 546 | ||
| 502 | ;;; | 547 | ;;; |
| 503 | ;;; Lisp | 548 | ;;; Lisp |