diff options
| author | Roland McGrath | 1993-04-26 19:21:01 +0000 |
|---|---|---|
| committer | Roland McGrath | 1993-04-26 19:21:01 +0000 |
| commit | d74e816f0467ca0c37bbee5acfffdf9d347768c6 (patch) | |
| tree | 34254288b9065d1d1dc61d871998cfdb7bd9d029 | |
| parent | 57ef1664fefd5e4ffbc161205a0b97147eb159f0 (diff) | |
| download | emacs-d74e816f0467ca0c37bbee5acfffdf9d347768c6.tar.gz emacs-d74e816f0467ca0c37bbee5acfffdf9d347768c6.zip | |
(find-tag-interactive): New function to read args for find-tag et al.
(find-tag-noselect, find-tag, find-tag-other-window, find-tag-other-frame,
find-tag-regexp): Use it.
(find-tag, find-tag-other-window): Take new arg REGEXP-P, pass to
find-tag-noselect.
(find-tag-regexp): Call either find-tag-other-window or find-tag, rather
than find-tag-noselect and switch-to-buffer[-other-window].
(tags-location-stack): New defvar.
(find-tag-noselect): If NEXT-P is '-, pop location off tags-location-stack.
| -rw-r--r-- | lisp/progmodes/etags.el | 173 |
1 files changed, 108 insertions, 65 deletions
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index 45528ccef8f..098b82c1376 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el | |||
| @@ -77,6 +77,10 @@ Otherwise, `find-tag-default' is used.") | |||
| 77 | (defvar default-tags-table-function nil | 77 | (defvar default-tags-table-function nil |
| 78 | "*If non-nil, a function of no arguments to choose a default tags file | 78 | "*If non-nil, a function of no arguments to choose a default tags file |
| 79 | for a particular buffer.") | 79 | for a particular buffer.") |
| 80 | |||
| 81 | (defvar tags-location-stack nil | ||
| 82 | "List of markers which are locations visited by \\[find-tag]. | ||
| 83 | Pop back to the last location with \\[negative-argument] \\[find-tag].") | ||
| 80 | 84 | ||
| 81 | ;; Tags table state. | 85 | ;; Tags table state. |
| 82 | ;; These variables are local in tags table buffers. | 86 | ;; These variables are local in tags table buffers. |
| @@ -578,6 +582,16 @@ Assumes the tags table is the current buffer." | |||
| 578 | (defvar last-tag nil | 582 | (defvar last-tag nil |
| 579 | "Last tag found by \\[find-tag].") | 583 | "Last tag found by \\[find-tag].") |
| 580 | 584 | ||
| 585 | ;; Get interactive args for find-tag{-noselect,-other-window,-regexp}. | ||
| 586 | (defun find-tag-interactive (prompt &optional no-default) | ||
| 587 | (if current-prefix-arg | ||
| 588 | (list nil (if (< (prefix-numeric-value current-prefix-arg) 0) | ||
| 589 | '- | ||
| 590 | t)) | ||
| 591 | (list (if no-default | ||
| 592 | (read-string prompt) | ||
| 593 | (find-tag-tag prompt))))) | ||
| 594 | |||
| 581 | ;;;###autoload | 595 | ;;;###autoload |
| 582 | (defun find-tag-noselect (tagname &optional next-p regexp-p) | 596 | (defun find-tag-noselect (tagname &optional next-p regexp-p) |
| 583 | "Find tag (in current tags table) whose name contains TAGNAME. | 597 | "Find tag (in current tags table) whose name contains TAGNAME. |
| @@ -585,80 +599,107 @@ Returns the buffer containing the tag's definition and moves its point there, | |||
| 585 | but does not select the buffer. | 599 | but does not select the buffer. |
| 586 | The default for TAGNAME is the expression in the buffer near point. | 600 | The default for TAGNAME is the expression in the buffer near point. |
| 587 | 601 | ||
| 588 | If second arg NEXT-P is non-nil (interactively, with prefix arg), search | 602 | If second arg NEXT-P is t (interactively, with prefix arg), search for |
| 589 | for another tag that matches the last tagname or regexp used. When there | 603 | another tag that matches the last tagname or regexp used. When there are |
| 590 | are multiple matches for a tag, more exact matches are found first. | 604 | multiple matches for a tag, more exact matches are found first. If NEXT-P |
| 605 | is the atom `-' (interactively, with prefix arg that is a negative number | ||
| 606 | or just \\[negative-argument]), pop back to the previous tag gone to. | ||
| 591 | 607 | ||
| 592 | If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp. | 608 | If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp. |
| 593 | 609 | ||
| 594 | See documentation of variable `tags-file-name'." | 610 | See documentation of variable `tags-file-name'." |
| 595 | (interactive (if current-prefix-arg | 611 | (interactive (find-tag-interactive "Find tag: ")) |
| 596 | '(nil t) | 612 | |
| 597 | (list (find-tag-tag "Find tag: ")))) | ||
| 598 | ;; Save the current buffer's value of `find-tag-hook' before selecting the | 613 | ;; Save the current buffer's value of `find-tag-hook' before selecting the |
| 599 | ;; tags table buffer. | 614 | ;; tags table buffer. |
| 600 | (let ((local-find-tag-hook find-tag-hook)) | 615 | (let ((local-find-tag-hook find-tag-hook)) |
| 601 | (if next-p | 616 | (if (eq '- next-p) |
| 602 | ;; Find the same table we last used. | 617 | ;; Pop back to a previous location. |
| 603 | (visit-tags-table-buffer 'same) | 618 | (if (null tags-location-stack) |
| 604 | ;; Pick a table to use. | 619 | (error "No previous tag locations") |
| 605 | (visit-tags-table-buffer) | 620 | (let ((marker (car tags-location-stack))) |
| 606 | ;; Record TAGNAME for a future call with NEXT-P non-nil. | 621 | ;; Pop the stack. |
| 607 | (setq last-tag tagname)) | 622 | (setq tags-location-stack (cdr tags-location-stack)) |
| 608 | (prog1 | 623 | (prog1 |
| 609 | ;; find-tag-in-order does the real work. | 624 | ;; Move to the saved location. |
| 610 | (find-tag-in-order (if next-p last-tag tagname) | 625 | (set-buffer (marker-buffer marker)) |
| 611 | (if regexp-p | 626 | (goto-char (marker-position marker)) |
| 612 | find-tag-regexp-search-function | 627 | ;; Kill that marker so it doesn't slow down editting. |
| 613 | find-tag-search-function) | 628 | (set-marker marker nil nil) |
| 614 | (if regexp-p | 629 | ;; Run the user's hook. Do we really want to do this for pop? |
| 615 | find-tag-regexp-tag-order | 630 | (run-hooks 'local-find-tag-hook)))) |
| 616 | find-tag-tag-order) | 631 | (if next-p |
| 617 | (if regexp-p | 632 | ;; Find the same table we last used. |
| 618 | find-tag-regexp-next-line-after-failure-p | 633 | (visit-tags-table-buffer 'same) |
| 619 | find-tag-next-line-after-failure-p) | 634 | ;; Pick a table to use. |
| 620 | (if regexp-p "matching" "containing") | 635 | (visit-tags-table-buffer) |
| 621 | (not next-p)) | 636 | ;; Record TAGNAME for a future call with NEXT-P non-nil. |
| 622 | (run-hooks 'local-find-tag-hook)))) | 637 | (setq last-tag tagname)) |
| 638 | (prog1 | ||
| 639 | ;; Record the location so we can pop back to it later. | ||
| 640 | (marker-buffer | ||
| 641 | (car | ||
| 642 | (setq tags-location-stack | ||
| 643 | (cons (let ((marker (make-marker))) | ||
| 644 | (save-excursion | ||
| 645 | (set-buffer | ||
| 646 | ;; find-tag-in-order does the real work. | ||
| 647 | (find-tag-in-order | ||
| 648 | (if next-p last-tag tagname) | ||
| 649 | (if regexp-p | ||
| 650 | find-tag-regexp-search-function | ||
| 651 | find-tag-search-function) | ||
| 652 | (if regexp-p | ||
| 653 | find-tag-regexp-tag-order | ||
| 654 | find-tag-tag-order) | ||
| 655 | (if regexp-p | ||
| 656 | find-tag-regexp-next-line-after-failure-p | ||
| 657 | find-tag-next-line-after-failure-p) | ||
| 658 | (if regexp-p "matching" "containing") | ||
| 659 | (not next-p))) | ||
| 660 | (set-marker marker (point)))) | ||
| 661 | tags-location-stack)))) | ||
| 662 | (run-hooks 'local-find-tag-hook))))) | ||
| 623 | 663 | ||
| 624 | ;;;###autoload | 664 | ;;;###autoload |
| 625 | (defun find-tag (tagname &optional next-p) | 665 | (defun find-tag (tagname &optional next-p regexp-p) |
| 626 | "Find tag (in current tags table) whose name contains TAGNAME. | 666 | "Find tag (in current tags table) whose name contains TAGNAME. |
| 627 | Select the buffer containing the tag's definition, and move point there. | 667 | Select the buffer containing the tag's definition, and move point there. |
| 628 | The default for TAGNAME is the expression in the buffer around or before point. | 668 | The default for TAGNAME is the expression in the buffer around or before point. |
| 629 | 669 | ||
| 630 | If second arg NEXT-P is non-nil (interactively, with prefix arg), search | 670 | If second arg NEXT-P is t (interactively, with prefix arg), search for |
| 631 | for another tag that matches the last tagname used. When there are | 671 | another tag that matches the last tagname or regexp used. When there are |
| 632 | multiple matches, more exact matches are found first. | 672 | multiple matches for a tag, more exact matches are found first. If NEXT-P |
| 673 | is the atom `-' (interactively, with prefix arg that is a negative number | ||
| 674 | or just \\[negative-argument]), pop back to the previous tag gone to. | ||
| 633 | 675 | ||
| 634 | See documentation of variable `tags-file-name'." | 676 | See documentation of variable `tags-file-name'." |
| 635 | (interactive (if current-prefix-arg | 677 | (interactive (find-tag-interactive "Find tag: ")) |
| 636 | '(nil t) | 678 | (switch-to-buffer (find-tag-noselect tagname next-p regexp-p))) |
| 637 | (list (find-tag-tag "Find tag: ")))) | ||
| 638 | (switch-to-buffer (find-tag-noselect tagname next-p))) | ||
| 639 | ;;;###autoload (define-key esc-map "." 'find-tag) | 679 | ;;;###autoload (define-key esc-map "." 'find-tag) |
| 640 | 680 | ||
| 641 | ;;;###autoload | 681 | ;;;###autoload |
| 642 | (defun find-tag-other-window (tagname &optional next-p) | 682 | (defun find-tag-other-window (tagname &optional next-p regexp-p) |
| 643 | "Find tag (in current tags table) whose name contains TAGNAME. | 683 | "Find tag (in current tags table) whose name contains TAGNAME. |
| 644 | Select the buffer containing the tag's definition | 684 | Select the buffer containing the tag's definition in another window, and |
| 645 | in another window, and move point there. | 685 | move point there. The default for TAGNAME is the expression in the buffer |
| 646 | The default for TAGNAME is the expression in the buffer around or before point. | 686 | around or before point. |
| 647 | 687 | ||
| 648 | If second arg NEXT-P is non-nil (interactively, with prefix arg), search | 688 | If second arg NEXT-P is t (interactively, with prefix arg), search for |
| 649 | for another tag that matches the last tagname used. When there are | 689 | another tag that matches the last tagname or regexp used. When there are |
| 650 | multiple matches, more exact matches are found first. | 690 | multiple matches for a tag, more exact matches are found first. If NEXT-P |
| 691 | is negative (interactively, with prefix arg that is a negative number or | ||
| 692 | just \\[negative-argument]), pop back to the previous tag gone to. | ||
| 651 | 693 | ||
| 652 | See documentation of variable `tags-file-name'." | 694 | See documentation of variable `tags-file-name'." |
| 653 | (interactive (if current-prefix-arg | 695 | (interactive (find-tag-interactive "Find tag other window: ")) |
| 654 | '(nil t) | 696 | |
| 655 | (list (find-tag-tag "Find tag other window: ")))) | ||
| 656 | ;; This hair is to deal with the case where the tag is found in the | 697 | ;; This hair is to deal with the case where the tag is found in the |
| 657 | ;; selected window's buffer; without the hair, point is moved in both | 698 | ;; selected window's buffer; without the hair, point is moved in both |
| 658 | ;; windows. To prevent this, we save the selected window's point before | 699 | ;; windows. To prevent this, we save the selected window's point before |
| 659 | ;; doing find-tag-noselect, and restore it after. | 700 | ;; doing find-tag-noselect, and restore it after. |
| 660 | (let* ((window-point (window-point (selected-window))) | 701 | (let* ((window-point (window-point (selected-window))) |
| 661 | (tagbuf (find-tag-noselect tagname next-p)) | 702 | (tagbuf (find-tag-noselect tagname next-p regexp-p)) |
| 662 | (tagpoint (progn (set-buffer tagbuf) (point)))) | 703 | (tagpoint (progn (set-buffer tagbuf) (point)))) |
| 663 | (set-window-point (prog1 | 704 | (set-window-point (prog1 |
| 664 | (selected-window) | 705 | (selected-window) |
| @@ -674,19 +715,19 @@ See documentation of variable `tags-file-name'." | |||
| 674 | 715 | ||
| 675 | ;;;###autoload | 716 | ;;;###autoload |
| 676 | (defun find-tag-other-frame (tagname &optional next-p) | 717 | (defun find-tag-other-frame (tagname &optional next-p) |
| 677 | "Find tag (in current tag table) whose name contains TAGNAME. | 718 | "Find tag (in current tags table) whose name contains TAGNAME. |
| 678 | Selects the buffer that the tag is contained in in another frame | 719 | Select the buffer containing the tag's definition in another frame, and |
| 679 | and puts point at its definition. | 720 | move point there. The default for TAGNAME is the expression in the buffer |
| 680 | If TAGNAME is a null string, the expression in the buffer | 721 | around or before point. |
| 681 | around or before point is used as the tag name. | 722 | |
| 682 | If second arg NEXT-P is non-nil (interactively, with prefix arg), | 723 | If second arg NEXT-P is t (interactively, with prefix arg), search for |
| 683 | searches for the next tag in the tag table | 724 | another tag that matches the last tagname or regexp used. When there are |
| 684 | that matches the tagname used in the previous find-tag. | 725 | multiple matches for a tag, more exact matches are found first. If NEXT-P |
| 726 | is negative (interactively, with prefix arg that is a negative number or | ||
| 727 | just \\[negative-argument]), pop back to the previous tag gone to. | ||
| 685 | 728 | ||
| 686 | See documentation of variable `tags-file-name'." | 729 | See documentation of variable `tags-file-name'." |
| 687 | (interactive (if current-prefix-arg | 730 | (interactive (find-tag-interactive "Find tag other frame: ")) |
| 688 | '(nil t) | ||
| 689 | (list (find-tag-tag "Find tag other window: ")))) | ||
| 690 | (let ((pop-up-frames t)) | 731 | (let ((pop-up-frames t)) |
| 691 | (find-tag-other-window tagname next-p))) | 732 | (find-tag-other-window tagname next-p))) |
| 692 | ;;;###autoload (define-key ctl-x-5-map "." 'find-tag-other-frame) | 733 | ;;;###autoload (define-key ctl-x-5-map "." 'find-tag-other-frame) |
| @@ -696,17 +737,19 @@ See documentation of variable `tags-file-name'." | |||
| 696 | "Find tag (in current tags table) whose name matches REGEXP. | 737 | "Find tag (in current tags table) whose name matches REGEXP. |
| 697 | Select the buffer containing the tag's definition and move point there. | 738 | Select the buffer containing the tag's definition and move point there. |
| 698 | 739 | ||
| 699 | If second arg NEXT-P is non-nil (interactively, with prefix arg), search | 740 | If second arg NEXT-P is t (interactively, with prefix arg), search for |
| 700 | for another tag that matches the last tagname used. | 741 | another tag that matches the last tagname or regexp used. When there are |
| 742 | multiple matches for a tag, more exact matches are found first. If NEXT-P | ||
| 743 | is negative (interactively, with prefix arg that is a negative number or | ||
| 744 | just \\[negative-argument]), pop back to the previous tag gone to. | ||
| 701 | 745 | ||
| 702 | If third arg OTHER-WINDOW is non-nil, select the buffer in another window. | 746 | If third arg OTHER-WINDOW is non-nil, select the buffer in another window. |
| 703 | 747 | ||
| 704 | See documentation of variable `tags-file-name'." | 748 | See documentation of variable `tags-file-name'." |
| 705 | (interactive (if current-prefix-arg | 749 | (interactive (find-tag-interactive "Find tag regexp: " t)) |
| 706 | '(nil t) | 750 | ;; We go through find-tag-other-window to do all the display hair there. |
| 707 | (list (read-string "Find tag regexp: ")))) | 751 | (funcall (if other-window 'find-tag-other-window 'find-tag) |
| 708 | (funcall (if other-window 'switch-to-buffer-other-window 'switch-to-buffer) | 752 | regexp next-p t)) |
| 709 | (find-tag-noselect regexp next-p t))) | ||
| 710 | 753 | ||
| 711 | ;; Internal tag finding function. | 754 | ;; Internal tag finding function. |
| 712 | 755 | ||