diff options
| author | Richard M. Stallman | 1994-04-16 02:38:40 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-04-16 02:38:40 +0000 |
| commit | 0ee4f8adff3fc2d89b290a38dcb579165ba25179 (patch) | |
| tree | e97de09ddf51f042841be08df747437c524ac3ef | |
| parent | b00c9734d89bc0314243652e86eb84d6a67ebc52 (diff) | |
| download | emacs-0ee4f8adff3fc2d89b290a38dcb579165ba25179.tar.gz emacs-0ee4f8adff3fc2d89b290a38dcb579165ba25179.zip | |
Require cl only at compile time.
(imenu--mouse-menu): Copy list by hand, not with copy-list.
| -rw-r--r-- | lisp/imenu.el | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el index f6aecb7b1ee..64b70d212a8 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.6 | 8 | ;; Version: 1.7 |
| 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 |
| @@ -25,6 +25,14 @@ | |||
| 25 | ;;; Commentary: | 25 | ;;; Commentary: |
| 26 | ;; | 26 | ;; |
| 27 | ;; Purpose of this package: | 27 | ;; Purpose of this package: |
| 28 | ;; | ||
| 29 | ;; Installation instructions | ||
| 30 | ;; | ||
| 31 | ;; Usage instructions: | ||
| 32 | ;; | ||
| 33 | ;; Known bugs: | ||
| 34 | ;; | ||
| 35 | ;; Purpose of this package: | ||
| 28 | ;; To present a framework for mode-specific buffer indexes. | 36 | ;; To present a framework for mode-specific buffer indexes. |
| 29 | ;; A buffer index is an alist of names and buffer positions. | 37 | ;; A buffer index is an alist of names and buffer positions. |
| 30 | ;; For instance all functions in a C-file and their positions. | 38 | ;; For instance all functions in a C-file and their positions. |
| @@ -53,6 +61,10 @@ | |||
| 53 | ;; Also run the 'add-hook' examples at the bottom of imenu.el. | 61 | ;; Also run the 'add-hook' examples at the bottom of imenu.el. |
| 54 | 62 | ||
| 55 | ;;; Change Log: | 63 | ;;; Change Log: |
| 64 | ;; v1.7 Apr 12 1994 Ake Stenhoff | ||
| 65 | ;; Changed doc strings refering to symbols. | ||
| 66 | ;; Require 'cl' when compiling only. | ||
| 67 | ;; Only uses 'cl' macros. | ||
| 56 | ;; v1.6 Feb 28 1994 Ake Stenhoff | 68 | ;; v1.6 Feb 28 1994 Ake Stenhoff |
| 57 | ;; Added alist as an optional argument to | 69 | ;; Added alist as an optional argument to |
| 58 | ;; 'imenu-choose-buffer-index'. | 70 | ;; 'imenu-choose-buffer-index'. |
| @@ -86,7 +98,7 @@ | |||
| 86 | ;; | 98 | ;; |
| 87 | 99 | ||
| 88 | ;;; Code | 100 | ;;; Code |
| 89 | (require 'cl) | 101 | (eval-when-compile (require 'cl)) |
| 90 | 102 | ||
| 91 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 103 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 92 | ;;; | 104 | ;;; |
| @@ -99,7 +111,7 @@ | |||
| 99 | 111 | ||
| 100 | Non-nil means always display the index in a completion buffer. | 112 | Non-nil means always display the index in a completion buffer. |
| 101 | Nil means display the index as a mouse menu when the mouse was | 113 | Nil means display the index as a mouse menu when the mouse was |
| 102 | used to trigger 'goto-index-pos'.") | 114 | used to trigger `goto-index-pos'.") |
| 103 | 115 | ||
| 104 | (defvar imenu-sort-function nil | 116 | (defvar imenu-sort-function nil |
| 105 | "*The function to use for sorting the index mouse-menu. | 117 | "*The function to use for sorting the index mouse-menu. |
| @@ -110,11 +122,11 @@ Set this to nil if you don't want any sorting (faster). | |||
| 110 | The items in the menu are then presented in the order they were found | 122 | The items in the menu are then presented in the order they were found |
| 111 | in the buffer. | 123 | in the buffer. |
| 112 | 124 | ||
| 113 | Set it to 'imenu--sort-by-name if you want alphabetic sorting. | 125 | Set it to `imenu--sort-by-name' if you want alphabetic sorting. |
| 114 | 126 | ||
| 115 | The function should take two arguments and return T if the first | 127 | The function should take two arguments and return T if the first |
| 116 | element should come before the second. The arguments are cons cells; | 128 | element should come before the second. The arguments are cons cells; |
| 117 | (NAME . POSITION). Look at 'imenu--sort-by-name' for an example.") | 129 | (NAME . POSITION). Look at `imenu--sort-by-name' for an example.") |
| 118 | 130 | ||
| 119 | (defvar imenu-max-items 25 | 131 | (defvar imenu-max-items 25 |
| 120 | "*Maximum number of elements in an index mouse-menu.") | 132 | "*Maximum number of elements in an index mouse-menu.") |
| @@ -124,7 +136,7 @@ element should come before the second. The arguments are cons cells; | |||
| 124 | If non NIL, user gets a message during the scanning of the buffer | 136 | If non NIL, user gets a message during the scanning of the buffer |
| 125 | 137 | ||
| 126 | Relevant only if the mode-specific function that creates the buffer | 138 | Relevant only if the mode-specific function that creates the buffer |
| 127 | index use 'imenu-progress-message'.") | 139 | index use `imenu-progress-message'.") |
| 128 | 140 | ||
| 129 | (defvar imenu-space-replacement "^" | 141 | (defvar imenu-space-replacement "^" |
| 130 | "*The replacement string for spaces in index names. | 142 | "*The replacement string for spaces in index names. |
| @@ -149,7 +161,7 @@ of the current buffer as an alist. The elements in the alist look | |||
| 149 | like: (INDEX-NAME . INDEX-POSITION). You may also nest index list like | 161 | like: (INDEX-NAME . INDEX-POSITION). You may also nest index list like |
| 150 | (INDEX-NAME . INDEX-ALIST). | 162 | (INDEX-NAME . INDEX-ALIST). |
| 151 | 163 | ||
| 152 | This function is called within a 'save-excursion'. | 164 | This function is called within a `save-excursion'. |
| 153 | 165 | ||
| 154 | The variable is buffer-local.") | 166 | The variable is buffer-local.") |
| 155 | (make-variable-buffer-local 'imenu-create-index-function) | 167 | (make-variable-buffer-local 'imenu-create-index-function) |
| @@ -157,8 +169,8 @@ The variable is buffer-local.") | |||
| 157 | (defvar prev-index-position-function 'beginning-of-defun | 169 | (defvar prev-index-position-function 'beginning-of-defun |
| 158 | "Function for finding the next index position. | 170 | "Function for finding the next index position. |
| 159 | 171 | ||
| 160 | If 'imenu-create-index-function' is set to | 172 | If `imenu-create-index-function' is set to |
| 161 | 'imenu-default-create-index-function, then you must set this variable | 173 | `imenu-default-create-index-function', then you must set this variable |
| 162 | to a function that will find the next index, looking backwards in the | 174 | to a function that will find the next index, looking backwards in the |
| 163 | file. | 175 | file. |
| 164 | 176 | ||
| @@ -170,7 +182,7 @@ index and it should return nil when it doesn't find another index. ") | |||
| 170 | "Function for extracting the index name. | 182 | "Function for extracting the index name. |
| 171 | 183 | ||
| 172 | This function is called after the function pointed out by | 184 | This function is called after the function pointed out by |
| 173 | 'prev-index-position-function'.") | 185 | `prev-index-position-function'.") |
| 174 | (make-variable-buffer-local 'extract-index-name-function) | 186 | (make-variable-buffer-local 'extract-index-name-function) |
| 175 | 187 | ||
| 176 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 188 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| @@ -234,7 +246,7 @@ This function is called after the function pointed out by | |||
| 234 | 246 | ||
| 235 | ;;; | 247 | ;;; |
| 236 | ;;; Function for suporting general looking submenu names. | 248 | ;;; Function for suporting general looking submenu names. |
| 237 | ;;; Uses 'imenu-submenu-name-format' for creating the name. | 249 | ;;; Uses `imenu-submenu-name-format' for creating the name. |
| 238 | ;;; NAME is the base of the new submenu name. | 250 | ;;; NAME is the base of the new submenu name. |
| 239 | ;;; | 251 | ;;; |
| 240 | (defun imenu-create-submenu-name (name) | 252 | (defun imenu-create-submenu-name (name) |
| @@ -294,7 +306,7 @@ This function is called after the function pointed out by | |||
| 294 | "*Wrapper for index searching functions. | 306 | "*Wrapper for index searching functions. |
| 295 | 307 | ||
| 296 | Moves point to end of buffer and then repeatedly calls | 308 | Moves point to end of buffer and then repeatedly calls |
| 297 | 'prev-index-position-function' and 'extract-index-name-function'. | 309 | `prev-index-position-function' and `extract-index-name-function'. |
| 298 | Their results are gathered into an index alist." | 310 | Their results are gathered into an index alist." |
| 299 | 311 | ||
| 300 | (or (and (fboundp prev-index-position-function) | 312 | (or (and (fboundp prev-index-position-function) |
| @@ -388,7 +400,6 @@ Returns t for rescan and otherwise a position number." | |||
| 388 | (imenu--completion-buffer (cdr choice) prompt)) | 400 | (imenu--completion-buffer (cdr choice) prompt)) |
| 389 | (t | 401 | (t |
| 390 | choice)))))) | 402 | choice)))))) |
| 391 | |||
| 392 | (defun imenu--mouse-menu (index-alist event &optional title) | 403 | (defun imenu--mouse-menu (index-alist event &optional title) |
| 393 | "Let the user select from a buffer index from a mouse menu. | 404 | "Let the user select from a buffer index from a mouse menu. |
| 394 | 405 | ||
| @@ -397,7 +408,13 @@ INDEX-ALIST is the buffer index and EVENT is a mouse event. | |||
| 397 | Returns t for rescan and otherwise a position number." | 408 | Returns t for rescan and otherwise a position number." |
| 398 | (let* ((menu (imenu--split-menu | 409 | (let* ((menu (imenu--split-menu |
| 399 | (if imenu-sort-function | 410 | (if imenu-sort-function |
| 400 | (sort (copy-list index-alist) imenu-sort-function) | 411 | (sort |
| 412 | (let ((res nil) | ||
| 413 | (oldlist index-alist)) | ||
| 414 | ;; Copy list method from the cl package `copy-list' | ||
| 415 | (while (consp oldlist) (push (pop oldlist) res)) | ||
| 416 | (prog1 (nreverse res) (setcdr res oldlist))) | ||
| 417 | imenu-sort-function) | ||
| 401 | index-alist) | 418 | index-alist) |
| 402 | (or title (buffer-name)))) | 419 | (or title (buffer-name)))) |
| 403 | position) | 420 | position) |
| @@ -426,10 +443,10 @@ prompted with PROMPT. | |||
| 426 | If you call this function with index alist ALIST, then it lets the user | 443 | If you call this function with index alist ALIST, then it lets the user |
| 427 | select from ALIST. | 444 | select from ALIST. |
| 428 | 445 | ||
| 429 | With no index alist ALIST, it calls 'imenu--make-index-alist' to | 446 | With no index alist ALIST, it calls `imenu--make-index-alist' to |
| 430 | create the index alist. | 447 | create the index alist. |
| 431 | 448 | ||
| 432 | If 'imenu-always-use-completion-buffer-p' is non-nil, then the | 449 | If `imenu-always-use-completion-buffer-p' is non-nil, then the |
| 433 | completion buffer is always used, no matter if the mouse was used or | 450 | completion buffer is always used, no matter if the mouse was used or |
| 434 | not. | 451 | not. |
| 435 | 452 | ||
| @@ -457,7 +474,7 @@ The returned value is on the form (INDEX-NAME . INDEX-POSITION)." | |||
| 457 | (defun goto-index-pos () | 474 | (defun goto-index-pos () |
| 458 | "Jump to selected part of buffer, using a buffer menu or mouse menu. | 475 | "Jump to selected part of buffer, using a buffer menu or mouse menu. |
| 459 | 476 | ||
| 460 | See 'imenu-choose-buffer-index' for more information." | 477 | See `imenu-choose-buffer-index' for more information." |
| 461 | (interactive) | 478 | (interactive) |
| 462 | (let ((index-item (imenu-choose-buffer-index))) | 479 | (let ((index-item (imenu-choose-buffer-index))) |
| 463 | (and index-item | 480 | (and index-item |
| @@ -487,7 +504,7 @@ See 'imenu-choose-buffer-index' for more information." | |||
| 487 | ;;; | 504 | ;;; |
| 488 | 505 | ||
| 489 | (defun imenu-example--lisp-extract-index-name () | 506 | (defun imenu-example--lisp-extract-index-name () |
| 490 | ;; Example of a candidate for 'imenu-extract-index-name-function'. | 507 | ;; Example of a candidate for `imenu-extract-index-name-function'. |
| 491 | ;; This will generate a flat index of definitions in a lisp file. | 508 | ;; This will generate a flat index of definitions in a lisp file. |
| 492 | (save-match-data | 509 | (save-match-data |
| 493 | (and (looking-at "(def") | 510 | (and (looking-at "(def") |
| @@ -501,7 +518,7 @@ See 'imenu-choose-buffer-index' for more information." | |||
| 501 | (error nil))))) | 518 | (error nil))))) |
| 502 | 519 | ||
| 503 | (defun imenu-example--create-lisp-index () | 520 | (defun imenu-example--create-lisp-index () |
| 504 | ;; Example of a candidate for 'imenu-create-index-function'. | 521 | ;; Example of a candidate for `imenu-create-index-function'. |
| 505 | ;; It will generate a nested index of definitions. | 522 | ;; It will generate a nested index of definitions. |
| 506 | (let ((index-alist '()) | 523 | (let ((index-alist '()) |
| 507 | (index-var-alist '()) | 524 | (index-var-alist '()) |