aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland McGrath1993-04-26 19:21:01 +0000
committerRoland McGrath1993-04-26 19:21:01 +0000
commitd74e816f0467ca0c37bbee5acfffdf9d347768c6 (patch)
tree34254288b9065d1d1dc61d871998cfdb7bd9d029
parent57ef1664fefd5e4ffbc161205a0b97147eb159f0 (diff)
downloademacs-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.el173
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
79for a particular buffer.") 79for a particular buffer.")
80
81(defvar tags-location-stack nil
82 "List of markers which are locations visited by \\[find-tag].
83Pop 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,
585but does not select the buffer. 599but does not select the buffer.
586The default for TAGNAME is the expression in the buffer near point. 600The default for TAGNAME is the expression in the buffer near point.
587 601
588If second arg NEXT-P is non-nil (interactively, with prefix arg), search 602If second arg NEXT-P is t (interactively, with prefix arg), search for
589for another tag that matches the last tagname or regexp used. When there 603another tag that matches the last tagname or regexp used. When there are
590are multiple matches for a tag, more exact matches are found first. 604multiple matches for a tag, more exact matches are found first. If NEXT-P
605is the atom `-' (interactively, with prefix arg that is a negative number
606or just \\[negative-argument]), pop back to the previous tag gone to.
591 607
592If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp. 608If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp.
593 609
594See documentation of variable `tags-file-name'." 610See 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.
627Select the buffer containing the tag's definition, and move point there. 667Select the buffer containing the tag's definition, and move point there.
628The default for TAGNAME is the expression in the buffer around or before point. 668The default for TAGNAME is the expression in the buffer around or before point.
629 669
630If second arg NEXT-P is non-nil (interactively, with prefix arg), search 670If second arg NEXT-P is t (interactively, with prefix arg), search for
631for another tag that matches the last tagname used. When there are 671another tag that matches the last tagname or regexp used. When there are
632multiple matches, more exact matches are found first. 672multiple matches for a tag, more exact matches are found first. If NEXT-P
673is the atom `-' (interactively, with prefix arg that is a negative number
674or just \\[negative-argument]), pop back to the previous tag gone to.
633 675
634See documentation of variable `tags-file-name'." 676See 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.
644Select the buffer containing the tag's definition 684Select the buffer containing the tag's definition in another window, and
645in another window, and move point there. 685move point there. The default for TAGNAME is the expression in the buffer
646The default for TAGNAME is the expression in the buffer around or before point. 686around or before point.
647 687
648If second arg NEXT-P is non-nil (interactively, with prefix arg), search 688If second arg NEXT-P is t (interactively, with prefix arg), search for
649for another tag that matches the last tagname used. When there are 689another tag that matches the last tagname or regexp used. When there are
650multiple matches, more exact matches are found first. 690multiple matches for a tag, more exact matches are found first. If NEXT-P
691is negative (interactively, with prefix arg that is a negative number or
692just \\[negative-argument]), pop back to the previous tag gone to.
651 693
652See documentation of variable `tags-file-name'." 694See 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 719Select the buffer containing the tag's definition in another frame, and
679and puts point at its definition. 720move point there. The default for TAGNAME is the expression in the buffer
680 If TAGNAME is a null string, the expression in the buffer 721around or before point.
681around or before point is used as the tag name. 722
682 If second arg NEXT-P is non-nil (interactively, with prefix arg), 723If second arg NEXT-P is t (interactively, with prefix arg), search for
683searches for the next tag in the tag table 724another tag that matches the last tagname or regexp used. When there are
684that matches the tagname used in the previous find-tag. 725multiple matches for a tag, more exact matches are found first. If NEXT-P
726is negative (interactively, with prefix arg that is a negative number or
727just \\[negative-argument]), pop back to the previous tag gone to.
685 728
686See documentation of variable `tags-file-name'." 729See 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.
697Select the buffer containing the tag's definition and move point there. 738Select the buffer containing the tag's definition and move point there.
698 739
699If second arg NEXT-P is non-nil (interactively, with prefix arg), search 740If second arg NEXT-P is t (interactively, with prefix arg), search for
700for another tag that matches the last tagname used. 741another tag that matches the last tagname or regexp used. When there are
742multiple matches for a tag, more exact matches are found first. If NEXT-P
743is negative (interactively, with prefix arg that is a negative number or
744just \\[negative-argument]), pop back to the previous tag gone to.
701 745
702If third arg OTHER-WINDOW is non-nil, select the buffer in another window. 746If third arg OTHER-WINDOW is non-nil, select the buffer in another window.
703 747
704See documentation of variable `tags-file-name'." 748See 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