diff options
| -rw-r--r-- | lisp/imenu.el | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el index 20a29acf8ee..f8daa05aea9 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el | |||
| @@ -115,7 +115,7 @@ element should come before the second. The arguments are cons cells; | |||
| 115 | 115 | ||
| 116 | (defvar imenu-scanning-message "Scanning buffer for index. (%3d%%)" | 116 | (defvar imenu-scanning-message "Scanning buffer for index. (%3d%%)" |
| 117 | "*Progress message during the index scanning of the buffer. | 117 | "*Progress message during the index scanning of the buffer. |
| 118 | If non NIL, user gets a message during the scanning of the buffer | 118 | If non-nil, user gets a message during the scanning of the buffer |
| 119 | 119 | ||
| 120 | Relevant only if the mode-specific function that creates the buffer | 120 | Relevant only if the mode-specific function that creates the buffer |
| 121 | index use `imenu-progress-message'.") | 121 | index use `imenu-progress-message'.") |
| @@ -213,18 +213,22 @@ This function is called after the function pointed out by | |||
| 213 | (/ (* 100 (1- pos)) (max total 1))))) | 213 | (/ (* 100 (1- pos)) (max total 1))))) |
| 214 | 214 | ||
| 215 | ;;; | 215 | ;;; |
| 216 | ;;; Macro to display a progress message. This will probably be used | 216 | ;;; Macro to display a progress message. |
| 217 | ;;; in a tight loop, that is why we use a macro. | ||
| 218 | ;;; RELPOS is the relative position to display. | 217 | ;;; RELPOS is the relative position to display. |
| 219 | ;;; If RELPOS is nil, then the relative position in the buffer | 218 | ;;; If RELPOS is nil, then the relative position in the buffer |
| 220 | ;;; is calculated. | 219 | ;;; is calculated. |
| 221 | (defmacro imenu-progress-message (&optional relpos reverse) | 220 | ;;; PREVPOS is the variable in which we store the last position displayed. |
| 221 | (defmacro imenu-progress-message (prevpos &optional relpos reverse) | ||
| 222 | (` (and | 222 | (` (and |
| 223 | imenu-scanning-message | 223 | imenu-scanning-message |
| 224 | (message imenu-scanning-message | 224 | (let ((pos (, (if relpos |
| 225 | (, (if relpos | ||
| 226 | relpos | 225 | relpos |
| 227 | (` (imenu--relative-position (, reverse))))))))) | 226 | (` (imenu--relative-position (, reverse))))))) |
| 227 | (if (, (if relpos t | ||
| 228 | (` (> pos (+ 5 (, prevpos)))))) | ||
| 229 | (progn | ||
| 230 | (message imenu-scanning-message pos) | ||
| 231 | (setq (, prevpos) pos))))))) | ||
| 228 | 232 | ||
| 229 | ;;; | 233 | ;;; |
| 230 | ;;; Function for suporting general looking submenu names. | 234 | ;;; Function for suporting general looking submenu names. |
| @@ -306,17 +310,17 @@ Their results are gathered into an index alist." | |||
| 306 | (error "The mode \"%s\" does not take full advantage of imenu.el yet." | 310 | (error "The mode \"%s\" does not take full advantage of imenu.el yet." |
| 307 | mode-name)) | 311 | mode-name)) |
| 308 | (let ((index-alist '()) | 312 | (let ((index-alist '()) |
| 309 | name) | 313 | name prev-pos) |
| 310 | (goto-char (point-max)) | 314 | (goto-char (point-max)) |
| 311 | (imenu-progress-message 0 t) | 315 | (imenu-progress-message prev-pos 0 t) |
| 312 | ;; Search for the function | 316 | ;; Search for the function |
| 313 | (while (funcall imenu-prev-index-position-function) | 317 | (while (funcall imenu-prev-index-position-function) |
| 314 | (imenu-progress-message nil t) | 318 | (imenu-progress-message prev-pos nil t) |
| 315 | (save-excursion | 319 | (save-excursion |
| 316 | (setq name (funcall imenu-extract-index-name-function))) | 320 | (setq name (funcall imenu-extract-index-name-function))) |
| 317 | (and (stringp name) | 321 | (and (stringp name) |
| 318 | (push (cons name (point)) index-alist))) | 322 | (push (cons name (point)) index-alist))) |
| 319 | (imenu-progress-message 100 t) | 323 | (imenu-progress-message prev-pos 100 t) |
| 320 | index-alist)))) | 324 | index-alist)))) |
| 321 | 325 | ||
| 322 | (defun imenu--replace-spaces (name replacement) | 326 | (defun imenu--replace-spaces (name replacement) |
| @@ -448,12 +452,12 @@ not. | |||
| 448 | 452 | ||
| 449 | The returned value is on the form (INDEX-NAME . INDEX-POSITION)." | 453 | The returned value is on the form (INDEX-NAME . INDEX-POSITION)." |
| 450 | (let (index-alist | 454 | (let (index-alist |
| 451 | (mouse-triggered (listp last-command-event)) | 455 | (mouse-triggered (listp last-nonmenu-event)) |
| 452 | (result t) ) | 456 | (result t) ) |
| 453 | ;; If selected by mouse, see to that the window where the mouse is | 457 | ;; If selected by mouse, see to that the window where the mouse is |
| 454 | ;; really is selected. | 458 | ;; really is selected. |
| 455 | (and mouse-triggered | 459 | (and mouse-triggered |
| 456 | (let ((window (posn-window (event-start last-command-event)))) | 460 | (let ((window (posn-window (event-start last-nonmenu-event)))) |
| 457 | (or (framep window) (select-window window)))) | 461 | (or (framep window) (select-window window)))) |
| 458 | ;; Create a list for this buffer only when needed. | 462 | ;; Create a list for this buffer only when needed. |
| 459 | (while (eq result t) | 463 | (while (eq result t) |
| @@ -461,7 +465,7 @@ The returned value is on the form (INDEX-NAME . INDEX-POSITION)." | |||
| 461 | (setq result | 465 | (setq result |
| 462 | (if (and mouse-triggered | 466 | (if (and mouse-triggered |
| 463 | (not imenu-always-use-completion-buffer-p)) | 467 | (not imenu-always-use-completion-buffer-p)) |
| 464 | (imenu--mouse-menu index-alist last-command-event) | 468 | (imenu--mouse-menu index-alist last-nonmenu-event) |
| 465 | (imenu--completion-buffer index-alist prompt))) | 469 | (imenu--completion-buffer index-alist prompt))) |
| 466 | (and (eq result t) | 470 | (and (eq result t) |
| 467 | (setq imenu--index-alist nil))) | 471 | (setq imenu--index-alist nil))) |
| @@ -519,12 +523,13 @@ See `imenu-choose-buffer-index' for more information." | |||
| 519 | (let ((index-alist '()) | 523 | (let ((index-alist '()) |
| 520 | (index-var-alist '()) | 524 | (index-var-alist '()) |
| 521 | (index-type-alist '()) | 525 | (index-type-alist '()) |
| 522 | (index-unknown-alist '())) | 526 | (index-unknown-alist '()) |
| 527 | prev-pos) | ||
| 523 | (goto-char (point-max)) | 528 | (goto-char (point-max)) |
| 524 | (imenu-progress-message 0) | 529 | (imenu-progress-message prev-pos 0) |
| 525 | ;; Search for the function | 530 | ;; Search for the function |
| 526 | (while (beginning-of-defun) | 531 | (while (beginning-of-defun) |
| 527 | (imenu-progress-message nil t) | 532 | (imenu-progress-message prev-pos nil t) |
| 528 | (save-match-data | 533 | (save-match-data |
| 529 | (and (looking-at "(def") | 534 | (and (looking-at "(def") |
| 530 | (save-excursion | 535 | (save-excursion |
| @@ -551,7 +556,7 @@ See `imenu-choose-buffer-index' for more information." | |||
| 551 | (forward-sexp 2) | 556 | (forward-sexp 2) |
| 552 | (push (imenu-example--name-and-position) | 557 | (push (imenu-example--name-and-position) |
| 553 | index-unknown-alist))))))) | 558 | index-unknown-alist))))))) |
| 554 | (imenu-progress-message 100) | 559 | (imenu-progress-message prev-pos 100) |
| 555 | (and index-var-alist | 560 | (and index-var-alist |
| 556 | (push (cons (imenu-create-submenu-name "Variables") index-var-alist) | 561 | (push (cons (imenu-create-submenu-name "Variables") index-var-alist) |
| 557 | index-alist)) | 562 | index-alist)) |
| @@ -579,15 +584,15 @@ See `imenu-choose-buffer-index' for more information." | |||
| 579 | 584 | ||
| 580 | (defun imenu-example--create-c-index (&optional regexp) | 585 | (defun imenu-example--create-c-index (&optional regexp) |
| 581 | (let ((index-alist '()) | 586 | (let ((index-alist '()) |
| 582 | (char)) | 587 | prev-pos char) |
| 583 | (goto-char (point-min)) | 588 | (goto-char (point-min)) |
| 584 | (imenu-progress-message 0) | 589 | (imenu-progress-message prev-pos 0) |
| 585 | ;; Search for the function | 590 | ;; Search for the function |
| 586 | (save-match-data | 591 | (save-match-data |
| 587 | (while (re-search-forward | 592 | (while (re-search-forward |
| 588 | (or regexp imenu-example--function-name-regexp-c) | 593 | (or regexp imenu-example--function-name-regexp-c) |
| 589 | nil t) | 594 | nil t) |
| 590 | (imenu-progress-message) | 595 | (imenu-progress-message prev-pos) |
| 591 | (backward-up-list 1) | 596 | (backward-up-list 1) |
| 592 | (save-excursion | 597 | (save-excursion |
| 593 | (goto-char (scan-sexps (point) 1)) | 598 | (goto-char (scan-sexps (point) 1)) |
| @@ -595,7 +600,7 @@ See `imenu-choose-buffer-index' for more information." | |||
| 595 | ;; Skip this function name if it is a prototype declaration. | 600 | ;; Skip this function name if it is a prototype declaration. |
| 596 | (if (not (eq char ?\;)) | 601 | (if (not (eq char ?\;)) |
| 597 | (push (imenu-example--name-and-position) index-alist)))) | 602 | (push (imenu-example--name-and-position) index-alist)))) |
| 598 | (imenu-progress-message 100) | 603 | (imenu-progress-message prev-pos 100) |
| 599 | (nreverse index-alist))) | 604 | (nreverse index-alist))) |
| 600 | 605 | ||
| 601 | ;;; | 606 | ;;; |