annotate lisp/etags.el @ 5726:179f4a9201b5

Merge.
author Mike Sperber <sperber@deinprogramm.de>
date Tue, 05 Mar 2013 08:55:56 +0100
parents 4dee0387b9de
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; etags.el --- etags facility for Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
3 ;; Copyright 1985, 1986, 1988, 1990, 1997, 2003 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Author: Their Name is Legion (see list below)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: tools
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
11 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
12 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
13 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
14 ;; option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
19 ;; for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;;; Synched up with: Not synched with FSF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;; This file is completely different from FSF's etags.el. It appears
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;; that an early version of this file (tags.el) has been rewritten by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; two different people; we got one, FSF got the other. Various
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; people have said that our version is better and faster.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; TODO:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; - DOCUMENT!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;; Derived from the original lisp/tags.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;; Ideas and code from the work of the following people:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;; Andy Norman <ange@hplb.hpl.hp.com>, author of ange-tags.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;; Ramana Rao <rao@arisia.xerox.com>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;; John Sturdy <jcgs@harlqn.co.uk>, author of tags-helper.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 ;; Henry Kautz <kautz@allegra.att.com>, author of tag-completion.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;; Dan LaLiberte <liberte@cs.uiuc.edu>, author of local-tags.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;; Tom Dietterich <tgd@turing.cs.orst.edu>, author of quest.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 ;; The author(s) of lisp/simple.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;; Duke Briscoe <briscoe@cs.yale.edu>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 ;; Lynn Slater <lrs@indetech.com>, author of location.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 ;; Shinichirou Sugou <shin@sgtp.apple.juice.or.jp>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 ;; an unidentified anonymous elisp hacker
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 ;; Kyle Jones <kyle_jones@wonderworks.com>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 ;; added "Exact match, then inexact" code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 ;; added support for include directive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 ;; Hrvoje Niksic <hniksic@xemacs.org>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 ;; various changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 ;;; User variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 (defgroup etags nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 "Etags facility for Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 Using etags, you can create tag tables for any number of files, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 easily access the symbols in those files, using the `\\[find-tag]'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 command."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 :prefix "tags-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 :group 'tools)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 (defcustom tags-build-completion-table 'ask
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 "*If this variable is nil, then tags completion is disabled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 If it is t, then things which prompt for tags will do so with completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 across all known tags.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 If it is the symbol `ask', you will be asked whether each tags table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 should be added to the completion list as it is read in. (With the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 exception that for very small tags tables, you will not be asked,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 since they can be parsed quickly.)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 :type '(choice (const :tag "Disabled" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 (const :tag "Complete All" t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (const :tag "Ask" ask))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 :group 'etags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (defcustom tags-always-exact nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 "*If this variable is non-nil, then tags always looks for exact matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 If it is nil (the default), tags will first go through exact matches,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 then through the non-exact ones."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 :group 'etags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (defcustom tag-table-alist nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 "*A list which determines which tags files are active for a buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 This is not really an association list, in that all elements are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 checked. The CAR of each element of this list is a pattern against
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 which the buffer's file name is compared; if it matches, then the CDR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 of the list should be the name of the tags table to use. If more than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 one element of this list matches the buffer's file name, then all of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 the associated tags tables will be used. Earlier ones will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 searched first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 If the CAR of elements of this list are strings, then they are treated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 as regular-expressions against which the file is compared (like the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 auto-mode-alist). If they are not strings, then they are evaluated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 If they evaluate to non-nil, then the current buffer is considered to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 If the CDR of the elements of this list are strings, then they are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 assumed to name a TAGS file. If they name a directory, then the string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 \"TAGS\" is appended to them to get the file name. If they are not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 strings, then they are evaluated, and must return an appropriate string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 (setq tag-table-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 '((\"/usr/src/public/perl/\" . \"/usr/src/public/perl/perl-3.0/\")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 (\"\\\\.el$\" . \"/usr/local/emacs/src/\")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 (\"/jbw/gnu/\" . \"/usr15/degree/stud/jbw/gnu/\")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 (\"\" . \"/usr/local/emacs/src/\")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 This means that anything in the /usr/src/public/perl/ directory should use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 the TAGS file /usr/src/public/perl/perl-3.0/TAGS; and file ending in .el should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 use the TAGS file /usr/local/emacs/src/TAGS; and anything in or below the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 directory /jbw/gnu/ should use the TAGS file /usr15/degree/stud/jbw/gnu/TAGS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 A file called something like \"/usr/jbw/foo.el\" would use both the TAGS files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 /usr/local/emacs/src/TAGS and /usr15/degree/stud/jbw/gnu/TAGS (in that order)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 because it matches both patterns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 If the buffer-local variable `buffer-tag-table' is set, then it names a tags
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 table that is searched before all others when find-tag is executed from this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 If there is a file called \"TAGS\" in the same directory as the file in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 question, then that tags file will always be used as well (after the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 `buffer-tag-table' but before the tables specified by this list.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 If the variable tags-file-name is set, then the tags file it names will apply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 to all buffers (for backwards compatibility.) It is searched first."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 :type '(repeat (cons :format "%v"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 (choice :value ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 (regexp :tag "Buffer regexp")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (choice :value ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (string :tag "Tag file or directory")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 sexp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 :group 'etags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 (defvar buffer-tag-table nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 "*The additional name of one TAGS table to be used for this buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 You can set this with `\\[set-buffer-tag-table]'. See the documentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 for the variable `tag-table-alist' for more information.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (make-variable-buffer-local 'buffer-tag-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (defvar tags-file-name nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 "The name of the tags-table used by all buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 This is for backwards compatibility, and is largely supplanted by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 variable tag-table-alist.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 (defcustom tags-auto-read-changed-tag-files nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 "*If non-nil, always re-read changed TAGS file without prompting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 If nil, prompt whether to re-read the changed TAGS file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 :group 'etags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (defcustom make-tags-files-invisible nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 "*If non-nil, TAGS-files will not show up in buffer-lists or be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 selectable (or deletable.)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 :group 'etags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 (defcustom tags-search-nuke-uninteresting-buffers t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 "*If non-nil, keep newly-visited files if they contain the search target.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 This affects the `tags-search' and `tags-query-replace' commands."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 :group 'etags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
173 (defcustom tags-check-parent-directories-for-tag-files t
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
174 "*If non-nil, look for TAGS files in all parent directories."
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
175 :type 'boolean
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
176 :group 'etags)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
177
2067
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
178 (defcustom tags-exuberant-ctags-optimization-p nil
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
179 "*If this variable is nil (the default), then exact tag search is able
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
180 to find tag names in the name part of the tagtable (enclosed by ^?..^A)
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
181 and in the sourceline part of the tagtable ( enclosed by ^..^?).
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
182 This is needed by xemacs etags as not every tag has a name field.
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
183 It is slower for large tables and less precise than the other option.
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
184
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
185 If it is non-nil, then exact tag will only search tag names in the name
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
186 part (enclosed by ^?..^A). This is faster and more precise than the other
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
187 option. This is only usable with exuberant etags, as it has a name field
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
188 entry for every tag."
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
189 :type 'boolean
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
190 :group 'etags)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 ;; Buffer tag tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (defun buffer-tag-table-list ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 "Returns a list (ordered) of the tags tables which should be used for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 (let (result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 ;; Explicitly set buffer-tag-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (when buffer-tag-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (push buffer-tag-table result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 ;; Current directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (when (file-readable-p (concat default-directory "TAGS"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (push (concat default-directory "TAGS") result))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
204 ;; Parent directories
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
205 (when tags-check-parent-directories-for-tag-files
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
206 (let ((cur default-directory))
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 502
diff changeset
207 ;; Fuck! Shouldn't there be a more obvious portable way
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 502
diff changeset
208 ;; to determine if we're the root? Shouldn't we have a
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 502
diff changeset
209 ;; proper path manipulation API? Do you know how many
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 502
diff changeset
210 ;; god-damn bugs are lurking out there because of Unix/
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 502
diff changeset
211 ;; Windows differences? And how much code is littered
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 502
diff changeset
212 ;; with stuff such as 10 lines down from here?
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 502
diff changeset
213 (while (not (and (equal (file-name-as-directory cur) cur)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 502
diff changeset
214 (equal (directory-file-name cur) cur)))
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 502
diff changeset
215 (setq cur (expand-file-name ".." cur))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
216 (let ((parent-tag-file (expand-file-name "TAGS" cur)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
217 (when (file-readable-p parent-tag-file)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
218 (push parent-tag-file result))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 ;; tag-table-alist
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
220 (let* ((key (or buffer-file-name
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
221 (concat default-directory (buffer-name))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
222 (key (if (eq system-type 'windows-nt)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
223 (replace-in-string key "\\\\" "/")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
224 key))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
225 expression)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 (dolist (item tag-table-alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 (setq expression (car item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 ;; If the car of the alist item is a string, apply it as a regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 ;; to the buffer-file-name. Otherwise, evaluate it. If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 ;; regexp matches, or the expression evaluates non-nil, then this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 ;; item in tag-table-alist applies to this buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (when (if (stringp expression)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (string-match expression key)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (ignore-errors
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (eval expression)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 ;; Now evaluate the cdr of the alist item to get the name of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 ;; the tag table file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (setq expression (ignore-errors
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (eval (cdr item))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (if (stringp expression)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (push expression result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (error "Expression in tag-table-alist evaluated to non-string")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (setq result
5367
8b70d37ab80e Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5264
diff changeset
244 (mapcan
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (lambda (name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (when (file-directory-p name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (setq name (concat (file-name-as-directory name) "TAGS")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (and (file-readable-p name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 ;; get-tag-table-buffer has side-effects
5367
8b70d37ab80e Use Common Lisp-derived builtins in a few more places in core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5264
diff changeset
250 (list (symbol-value-in-buffer 'buffer-file-name
5369
4141aeddc55b Eliminate byte-compile warnings, core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5367
diff changeset
251 (get-tag-table-buffer name)))))
4141aeddc55b Eliminate byte-compile warnings, core Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5367
diff changeset
252 result))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 ;; If no TAGS file has been found, ask the user explicitly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 ;; #### tags-file-name is *evil*.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (or result tags-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 (call-interactively 'visit-tags-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (when tags-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (setq result (nconc result (list tags-file-name))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (or result (error "Buffer has no associated tag tables"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (delete-duplicates (nreverse result) :test 'equal)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (defun visit-tags-table (file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 "Tell tags commands to use tags table file FILE when all else fails.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 FILE should be the name of a file created with the `etags' program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 A directory name is ok too; it means file TAGS in that directory."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (interactive (list (read-file-name "Visit tags table: (default TAGS) "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 default-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (expand-file-name "TAGS" default-directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (if (string-equal file "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (setq tags-file-name nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (setq file (expand-file-name file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (when (file-directory-p file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (setq file (expand-file-name "TAGS" file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 ;; It used to be that, if a user pressed RET by mistake, the bogus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 ;; `tags-file-name' would remain, causing the error at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 ;; `buffer-tag-table'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (when (file-exists-p file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (setq tags-file-name file))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (defun set-buffer-tag-table (file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 "In addition to the tags tables specified by the variable `tag-table-alist',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 each buffer can have one additional table. This command sets that.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 See the documentation for the variable `tag-table-alist' for more information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (read-file-name "Visit tags table: (directory sufficient) "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 nil default-directory t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (or file (error "No TAGS file name supplied"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (setq file (expand-file-name file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (when (file-directory-p file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 (setq file (expand-file-name "TAGS" file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (or (file-exists-p file) (error "TAGS file missing: %s" file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (setq buffer-tag-table file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 ;; Manipulating the tag table buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (defconst tag-table-completion-status nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 "Indicates whether a completion table has been built.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 Either nil, t, or `disabled'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (make-variable-buffer-local 'tag-table-completion-status)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (defconst tag-table-files nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 "If the current buffer is a TAGS table, this holds a list of the files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 referenced by this file, or nil if that hasn't been computed yet.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (make-variable-buffer-local 'tag-table-files)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (defun get-tag-table-buffer (tag-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 "Returns a buffer visiting the given TAGS table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 If appropriate, reverting the buffer, and possibly build a completion-table."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (or (stringp tag-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (error "Bad tags file name supplied: %s" tag-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 ;; Remove symbolic links from name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (setq tag-table (symlink-expand-file-name tag-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (let (buf build-completion check-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (setq buf (get-file-buffer tag-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (unless buf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (if (file-readable-p tag-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (setq buf (find-file-noselect tag-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 check-name t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (error "No such tags file: %s" tag-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (with-current-buffer buf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 ;; Make the TAGS buffer invisible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (when (and check-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 make-tags-files-invisible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (string-match "\\`[^ ]" (buffer-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (rename-buffer (generate-new-buffer-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (concat " " (buffer-name)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (or (verify-visited-file-modtime buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (cond ((or tags-auto-read-changed-tag-files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (yes-or-no-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (format "Tags file %s has changed, read new contents? "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 tag-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (when tags-auto-read-changed-tag-files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (message "Tags file %s has changed, reading new contents..."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 tag-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (revert-buffer t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (when (eq tag-table-completion-status t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (setq tag-table-completion-status nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (setq tag-table-files nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (or (eq (char-after 1) ?\f)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (error "File %s not a valid tags file" tag-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (or (memq tag-table-completion-status '(t disabled))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (setq build-completion t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (when build-completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (if (ecase tags-build-completion-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 ((nil) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 ((t) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 ((ask)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 ;; don't bother asking for small ones
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (or (< (buffer-size) 20000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (y-or-n-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (format "Build tag completion table for %s? "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 tag-table)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 ;; The user wants to build the table:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (progn
2067
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
360 (if tags-exuberant-ctags-optimization-p
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
361 (add-to-tag-completion-table-exuberant-ctags)
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
362 (add-to-tag-completion-table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (setq tag-table-completion-status t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 ;; Allow user to C-g out correctly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (quit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (message "Tags completion table construction aborted")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (setq tag-table-completion-status nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 quit-flag t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 ;; The table is verboten.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (setq tag-table-completion-status 'disabled))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (defun file-of-tag ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 "Return the file name of the file whose tags point is within.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 Assumes the tag table is the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 File name returned is relative to tag table file's directory."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (let ((opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 prev size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (while (< (point) opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (skip-chars-backward "^,\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 (setq prev (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 size (read (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (goto-char prev)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 ;; New include syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 ;; filename,include
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 ;; tacked on to the end of a tag file means use filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 ;; as a tag file before giving up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 ;; Skip it here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (unless (eq size 'include)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 (forward-char size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (goto-char (1- prev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (buffer-substring (point) (point-at-bol)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (defun tag-table-include-files ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 "Return all file names associated with `include' directives in a tag buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 ;; New include syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 ;; filename,include
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 ;; tacked on to the end of a tag file means use filename as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 ;; tag file before giving up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (let ((files nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (while (re-search-forward "\f\n\\(.*\\),include$" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (push (match-string 1) files)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 files))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (defun tag-table-files (tag-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 "Returns a list of the files referenced by the named TAGS table."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (with-current-buffer (get-tag-table-buffer tag-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (unless tag-table-files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (let (files prev size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 (while (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (skip-chars-backward "^,\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 (setq prev (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 size (read (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (goto-char prev)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (push (expand-file-name (buffer-substring (1- (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (point-at-bol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 default-directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 files)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (forward-char size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (setq tag-table-files (nreverse files))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 tag-table-files))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 ;; #### should this be on previous page?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (defun buffer-tag-table-files ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 "Returns a list of all files referenced by all TAGS tables that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 this buffer uses."
5264
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4755
diff changeset
439 (mapcan #'tag-table-files (buffer-tag-table-list)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 ;; Building the completion table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 ;; Test cases for building completion table; must handle these properly:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 ;; Lisp_Int, XSETINT, current_column 60,2282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 ;; Lisp_Int, XSETINT, point>NumCharacters ? 0 : CharAt(363,9935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 ;; Lisp_Int, XSETINT, point<=FirstCharacter ? 0 : CharAt(366,10108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 ;; point<=FirstCharacter || CharAt(378,10630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 ;; point>NumCharacters || CharAt(382,10825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 ;; DEFUN ("x-set-foreground-color", Fx_set_foreground_color,191,4562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 ;; DEFUN ("x-set-foreground-color", Fx_set_foreground_color,191,4562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 ;; DEFUN ("*", Ftimes,1172,32079
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 ;; DEFUN ("/=", Fneq,1035,28839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 ;; defun_internal 4199,101362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 ;; int pure[PURESIZE / sizeof 53,1564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 ;; char staticvec1[NSTATICS * sizeof 667,17608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 ;; Date: 04 May 87 23:53:11 PDT 26,1077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 ;; #define anymacroname(324,4344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 ;; (define-key ctl-x-map 311,11784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 ;; (define-abbrev-table 'c-mode-abbrev-table 24,1016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 ;; static char *skip_white(116,3443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 ;; static foo 348,11643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 ;; (defun texinfo-insert-@code 91,3358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 ;; (defvar texinfo-kindex)29,1105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 ;; (defun texinfo-format-\. 548,18376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 ;; (defvar sm::menu-kludge-y 621,22726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 ;; (defvar *mouse-drag-window* 103,3642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 ;; (defun simula-back-level(317,11263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 ;; } DPxAC,380,14024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 ;; } BM_QCB;69,2990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 ;; #define MTOS_DONE\t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 ;; "^[^ ]+ +\\([^ ]+\\) "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 ;; void *find_cactus_segment(116,2444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 ;; void *find_pdb_segment(162,3688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 ;; void init_dclpool(410,10739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 ;; WORD insert_draw_command(342,8881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 ;; void *req_pdbmem(579,15574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 (defvar tag-completion-table (make-vector 511 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 (defvar tag-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 (defvar tag-table-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (defvar tag-symbol-tables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (defvar buffer-tag-table-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (defmacro intern-tag-symbol (tag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 `(progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (setq tag-symbol (intern ,tag tag-completion-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 tag-symbol-tables (and (boundp tag-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (symbol-value tag-symbol)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 (or (memq tag-table-symbol tag-symbol-tables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 (set tag-symbol (cons tag-table-symbol tag-symbol-tables)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
496 ;; Can't use "\\s-" in these patterns because that will include newline
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
497 ;; \2 matches an explicit name.
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
498 (defconst tags-explicit-name-pattern "\177\\(\\([^\n\001]+\\)\001\\)?")
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
499 ;; \1 matches Lisp-name, \2 matches C-name, \5 (from
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
500 ;; tags-explicit-name-pattern) matches explicit name.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (defconst tags-DEFUN-pattern
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
502 (concat "DEFUN[ \t]*(\"\\([^\"]+\\)\",[ \t]*\\(\\(\\sw\\|\\s_\\)+\\),"
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
503 tags-explicit-name-pattern))
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
504 ;; \1 matches an array name. Explicit names unused?
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 (defconst tags-array-pattern ".*[ \t]+\\([^ \[]+\\)\\[")
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
506 ;; \2 matches a Lispish name, \5 (from tags-explicit-name-pattern) matches
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
507 ;; explicit name.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 (defconst tags-def-pattern
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
509 (concat "\\(.*[ \t]+\\)?\\**\\(\\(\\sw\\|\\s_\\)+\\)[ ();,\t]*"
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
510 ;; "\\(.*[ \t]+\\)?\\(\\(\\sw\\|\\s_\\)+\\)[ ()]*"
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
511 ;; "\\(\\sw\\|\\s_\\)+[ ()]*"
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
512 tags-explicit-name-pattern)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 )
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
514 ;; \1 matches Schemish name, \4 (from tags-explicit-name-pattern) matches
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
515 ;; explicit name
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
516 (defconst tags-schemish-pattern
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
517 (concat "\\s-*(\\s-*def\\sw*\\s-*(?\\s-*\\(\\(\\sw\\|\\s_\\|:\\)+\\))?\\s-*"
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
518 tags-explicit-name-pattern))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (defconst tags-file-pattern "^\f\n\\(.+\\),[0-9]+\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
2067
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
521 (defun add-to-tag-completion-table-exuberant-ctags ()
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
522 "Sucks the current buffer (a TAGS table) into the completion-table.
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
523 This is a version which is optimized for exuberant etags and will not
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
524 work with xemacs etags."
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
525 (message "Adding %s to tags completion table..." buffer-file-name)
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
526 (goto-char (point-min))
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
527 (let ((tag-table-symbol (intern buffer-file-name tag-completion-table))
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
528 ;; tag-table-symbol is used by intern-tag-symbol
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
529 name tag-symbol
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
530 tag-symbol-tables
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
531 (case-fold-search nil))
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
532 (while (re-search-forward tags-explicit-name-pattern nil t)
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
533 ;; no need to check the mode here
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
534 (setq name (match-string 2))
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
535 (intern-tag-symbol name)))
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
536 (message "Adding %s to tags completion table...done" buffer-file-name))
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
537
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
538
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 ;; #### Should make it work with the `include' directive!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (defun add-to-tag-completion-table ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 "Sucks the current buffer (a TAGS table) into the completion-table."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 (message "Adding %s to tags completion table..." buffer-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (let ((tag-table-symbol (intern buffer-file-name tag-completion-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 ;; tag-table-symbol is used by intern-tag-symbol
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
546 filename file-type name name2 name3 tag-symbol
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 tag-symbol-tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 ;; Loop over the files mentioned in the TAGS file for each file,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 ;; try to find its major-mode, then process tags appropriately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (while (looking-at tags-file-pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (goto-char (match-end 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 (setq filename (file-name-sans-versions (match-string 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 ;; We used to check auto-mode-alist for the proper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 ;; file-type. This was way too slow, as it had to process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 ;; an enormous amount of regexps for each time. Now we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 ;; use the shotgun approach with only two regexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 file-type (cond ((string-match "\\.\\([cC]\\|cc\\|cxx\\)\\'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 'c-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 ((string-match "\\.\\(el\\|cl\\|lisp\\)\\'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 'lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 ((string-match "\\.scm\\'" filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 'scheme-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 (t nil)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
567 (defvar c-mode-syntax-table)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 (set-syntax-table (cond ((and (eq file-type 'c-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 c-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 c-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 ((eq file-type 'lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 (t (standard-syntax-table))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 ;; Clear loop variables.
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
575 (setq name nil name2 nil name3 nil)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (lmessage 'progress "%s..." filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 ;; Loop over the individual tag lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 (while (not (or (eobp) (eq (char-after) ?\f)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 (cond ((and (eq file-type 'c-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 (looking-at "DEFUN[ \t]"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 ;; DEFUN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 (or (looking-at tags-DEFUN-pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 (error "DEFUN doesn't fit pattern"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 (setq name (match-string 1)
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
585 name2 (match-string 2)
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
586 name3 (match-string 5)))
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
587 ;;((looking-at "\\s-")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 ;; skip probably bogus entry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 ;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 ((and (eq file-type 'c-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 (looking-at ".*\\["))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 ;; Array
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 (cond ((not (looking-at tags-array-pattern))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 (message "array definition doesn't fit pattern")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (setq name nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 (setq name (match-string 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 ((and (eq file-type 'scheme-mode)
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
599 (looking-at tags-schemish-pattern))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 ;; Something Schemish (is this really necessary??)
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
601 (setq name (match-string 1)
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
602 name2 (match-string 4)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 ((looking-at tags-def-pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 ;; ???
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
605 (setq name (match-string 2)
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
606 name2 (match-string 5))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 ;; add the tags we found to the completion table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 (and name (intern-tag-symbol name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (and name2 (intern-tag-symbol name2))
1584
57bec9cc1e4f [xemacs-hg @ 2003-07-21 06:42:31 by stephent]
stephent
parents: 793
diff changeset
610 (and name3 (intern-tag-symbol name3))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 (forward-line 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 (or (eobp) (error "Bad TAGS file")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 (message "Adding %s to tags completion table...done" buffer-file-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 ;; Interactive find-tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 (defvar find-tag-default-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 "Function to call to create a default tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 Make it buffer-local in a mode hook. The function is called with no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 arguments.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 (defvar find-tag-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 "*Function to call after a tag is found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 Make it buffer-local in a mode hook. The function is called with no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 arguments.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 ;; Return a default tag to search for, based on the text at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 (defun find-tag-default ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 (or (and (not (memq find-tag-default-hook '(nil find-tag-default)))
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 593
diff changeset
631 (with-trapping-errors
4755
c1784fd59d7d Fix syntax of some uses of condition-case and with-trapping-errors.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 2067
diff changeset
632 :operation 'find-tag-default-hook
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 593
diff changeset
633 :error-form nil
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 593
diff changeset
634 (funcall find-tag-default-hook)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 (symbol-near-point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 ;; This function depends on the following symbols being bound properly:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 ;; buffer-tag-table-list,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 ;; tag-symbol-tables (value irrelevant, bound outside for efficiency)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 (defun tag-completion-predicate (tag-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 (and (boundp tag-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 (setq tag-symbol-tables (symbol-value tag-symbol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 (catch 'found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 (while tag-symbol-tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 (when (memq (car tag-symbol-tables) buffer-tag-table-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 (throw 'found t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (setq tag-symbol-tables (cdr tag-symbol-tables))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 (defun buffer-tag-table-symbol-list ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 (mapcar (lambda (table-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 (intern table-name tag-completion-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 (buffer-tag-table-list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 (defvar find-tag-history nil "History list for find-tag-tag.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 (defun find-tag-tag (prompt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 (let* ((default (find-tag-default))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (buffer-tag-table-list (buffer-tag-table-symbol-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 tag-symbol-tables tag-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 (setq tag-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 (completing-read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 (if default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 (format "%s(default %s) " prompt default)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 prompt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 tag-completion-table 'tag-completion-predicate nil nil
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
666 'find-tag-history default))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
667 tag-name))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 (defvar last-tag-data nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 "Information for continuing a tag search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 Is of the form (TAG POINT MATCHING-EXACT TAG-TABLE TAG-TABLE ...).")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 (defvar tags-loop-operate nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 "Form for `tags-loop-continue' to eval to change one file.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 (defvar tags-loop-scan
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 '(error "%s" (substitute-command-keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 "No \\[tags-search] or \\[tags-query-replace] in progress."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 "Form for `tags-loop-continue' to eval to scan one file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 If it returns non-nil, this file needs processing by evalling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 \`tags-loop-operate'. Otherwise, move on to the next file.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 (autoload 'get-symbol-syntax-table "symbol-syntax")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 (defun find-tag-internal (tagname)
487
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
686
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 (let ((next (null tagname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 (tmpnext (null tagname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 ;; If tagname is a list: (TAGNAME), this indicates
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 ;; requiring an exact symbol match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 (exact (or tags-always-exact (consp tagname)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 (normal-syntax-table (syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 (exact-syntax-table (get-symbol-syntax-table (syntax-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 tag-table-currently-matching-exact
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 tag-target exact-tagname
487
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
696 tag-tables tag-table-point file linebeg line startpos buf
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 offset found pat syn-tab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 (when (consp tagname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 (setq tagname (car tagname)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 (cond (next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 (setq tagname (car last-tag-data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 (setq tag-table-currently-matching-exact
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 (car (cdr (cdr last-tag-data)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 (setq tag-table-currently-matching-exact t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 ;; \_ in the tagname is used to indicate a symbol boundary.
2067
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
707 (if tags-exuberant-ctags-optimization-p
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
708 (setq exact-tagname (format "\C-?%s\C-a" tagname))
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
709 (setq exact-tagname (format "\C-?%s\C-a\\|\
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
710 \\_%s.?\C-?[0-9]*,[0-9]*$" tagname tagname))
0750eca4d23a [xemacs-hg @ 2004-05-10 06:26:31 by stephent]
stephent
parents: 1584
diff changeset
711 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 (while (string-match "\\\\_" exact-tagname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 (aset exact-tagname (1- (match-end 0)) ?b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 (catch 'found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 ;; Loop searching for exact matches and then inexact matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 (while (not (eq tag-table-currently-matching-exact 'neither))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 (cond (tmpnext
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 (setq tag-tables (cdr (cdr (cdr last-tag-data)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 tag-table-point (car (cdr last-tag-data)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 ;; Start from the beginning of the table list on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 ;; next iteration of the loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 (setq tmpnext nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 (setq tag-tables (buffer-tag-table-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 tag-table-point 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 (if tag-table-currently-matching-exact
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 (setq tag-target exact-tagname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 syn-tab exact-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 (setq tag-target tagname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 syn-tab normal-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 (with-search-caps-disable-folding tag-target t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 (while tag-tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 (set-buffer (get-tag-table-buffer (car tag-tables)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 (bury-buffer (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 (goto-char (or tag-table-point (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 (setq tag-table-point nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 (letf (((syntax-table) syn-tab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 (case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 ;; #### should there be support for non-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 ;; tag searches?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 (while (re-search-forward tag-target nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 (and (save-match-data
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
744 (save-excursion
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
745 (goto-char (match-beginning 0))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
746 (looking-at "[^\n\C-?]*\C-?")))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 ;; If we're looking for inexact matches, skip
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 ;; exact matches since we've visited them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 ;; already.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 (or tag-table-currently-matching-exact
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 (letf (((syntax-table) exact-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 (goto-char (match-beginning 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 (not (looking-at exact-tagname)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 (throw 'found t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 (setq tag-tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 (nconc (tag-table-include-files) (cdr tag-tables)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 (if (and (not exact) (eq tag-table-currently-matching-exact t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 (setq tag-table-currently-matching-exact nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 (setq tag-table-currently-matching-exact 'neither)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 (error "No %sentries %s %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 (if next "more " "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 (if exact "matching" "containing")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 tagname))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
765 (beginning-of-line)
487
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
766
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
767 ;; from here down, synched with FSF 20.7
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
768 ;; etags-snarf-tag and etags-goto-tag-location. --ben
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
769
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
770 (if (save-excursion
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
771 (forward-line -1)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
772 (looking-at "\f\n"))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
773 (progn
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
774 ;; The match was for a source file name, not any tag
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
775 ;; within a file. Give text of t, meaning to go exactly
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
776 ;; to the location we specify, the beginning of the file.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
777 (setq linebeg t
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
778 line nil
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
779 startpos 1)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
780 (setq file
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
781 (expand-file-name (file-of-tag)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
782 ;; In XEmacs, this needs to be
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
783 ;; relative to:
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
784 (or (file-name-directory (car tag-tables))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
785 "./"))))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
786 (search-forward "\C-?")
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
787 (setq file
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
788 (expand-file-name (file-of-tag)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
789 ;; In XEmacs, this needs to be
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
790 ;; relative to:
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
791 (or (file-name-directory (car tag-tables))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
792 "./")))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
793 (setq linebeg (buffer-substring (1- (point)) (point-at-bol)))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
794 ;; Skip explicit tag name if present.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
795 (search-forward "\001" (save-excursion (forward-line 1) (point)) t)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
796 (if (looking-at "[0-9]")
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
797 (setq line (string-to-int (buffer-substring
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
798 (point)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
799 (progn (skip-chars-forward "0-9")
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
800 (point))))))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
801 (search-forward ",")
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
802 (if (looking-at "[0-9]")
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
803 (setq startpos (string-to-int (buffer-substring
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
804 (point)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
805 (progn (skip-chars-forward "0-9")
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
806 (point)))))))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
807 ;; Leave point on the next line of the tags file.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
808 (forward-line 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 (setq last-tag-data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 (nconc (list tagname (point) tag-table-currently-matching-exact)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 tag-tables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 (setq buf (find-file-noselect file))
487
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
813
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
814 ;; LINEBEG is the initial part of a line containing the tag and
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
815 ;; STARTPOS is the character position of LINEBEG within the file
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
816 ;; (starting from 1); LINE is the line number. If LINEBEG is t,
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
817 ;; it means the tag refers to exactly LINE or STARTPOS
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
818 ;; (whichever is present, LINE having preference, no searching).
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
819 ;; Either LINE or STARTPOS may be nil; STARTPOS is used if
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
820 ;; present. If the tag isn't exactly at the given position then
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
821 ;; look around that position using a search window which expands
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
822 ;; until it hits the start of file.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
823
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 (with-current-buffer buf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 (widen)
487
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
828 (if (eq linebeg t)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
829 ;; Direct file tag.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
830 (cond (line (goto-line line))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
831 (startpos (goto-char startpos))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
832 (t (error "etags.el BUG: bogus direct file tag")))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
833 ;; Here we search for PAT in the range [STARTPOS - OFFSET,
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
834 ;; STARTPOS + OFFSET], with increasing values of OFFSET.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
835 ;;
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
836 ;; We used to set the initial offset to 1000, but the
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
837 ;; actual sources show that finer-grained control is
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
838 ;; needed (e.g. two `hash_string's in src/symbols.c.) So,
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
839 ;; I changed 1000 to 100, and (* 3 offset) to (* 5 offset).
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
840 (setq offset 100)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
841 (setq pat (concat (if (eq selective-display t)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
842 "\\(^\\|\^m\\)" "^")
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
843 (regexp-quote linebeg)))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
844
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
845 ;; The character position in the tags table is 0-origin.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
846 ;; Convert it to a 1-origin Emacs character position.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
847 (if startpos (setq startpos (1+ startpos)))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
848 ;; If no char pos was given, try the given line number.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
849 (or startpos
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
850 (if line
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
851 (setq startpos (progn (goto-line line)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
852 (point)))))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
853 (or startpos
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
854 (setq startpos (point-min)))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
855 ;; First see if the tag is right at the specified location.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
856 (goto-char startpos)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
857 (setq found (looking-at pat))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
858 (while (and (not found)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
859 (progn
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
860 (goto-char (- startpos offset))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
861 (not (bobp))))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
862 (setq found
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
863 (re-search-forward pat (+ startpos offset) t)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
864 offset (* 5 offset))) ; expand search window
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
865 ;; Finally, try finding it anywhere in the buffer.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
866 (or found
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
867 (re-search-forward pat nil t)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
868 (error "Rerun etags: `%s' not found in %s"
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
869 pat file))))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
870 ;; Position point at the right place
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
871 ;; if the search string matched an extra Ctrl-m at the beginning.
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
872 (and (eq selective-display t)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
873 (looking-at "\^m")
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
874 (forward-char 1))
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
875 (beginning-of-line)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 444
diff changeset
876 (setq startpos (point))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 (cons buf startpos))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 ;;;###autoload
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
880 (defun find-tag-at-point (tagname &optional other-window)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
881 "*Find tag whose name contains TAGNAME.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
882 Identical to `find-tag' but does not prompt for tag when called interactively;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
883 instead, uses tag around or before point."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
884 (interactive (if current-prefix-arg
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
885 '(nil nil)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
886 (list (find-tag-default) nil)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
887 (find-tag tagname other-window))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
888
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
889 ;;;###autoload
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 (defun find-tag (tagname &optional other-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 "*Find tag whose name contains TAGNAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 Selects the buffer that the tag is contained in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 and puts point at its definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 If TAGNAME is a null string, the expression in the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 around or before point is used as the tag name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 If called interactively with a numeric argument, searches for the next tag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 in the tag table that matches the tagname used in the previous find-tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 If second arg OTHER-WINDOW is non-nil, uses another window to display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 the tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 This version of this function supports multiple active tags tables,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 and completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 Variables of note:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 tag-table-alist controls which tables apply to which buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 tags-file-name a default tags table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 tags-build-completion-table controls completion behavior
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 buffer-tag-table another way of specifying a buffer-local table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 make-tags-files-invisible whether tags tables should be very hidden
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 tag-mark-stack-max how many tags-based hops to remember"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 (interactive (if current-prefix-arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 '(nil nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 (list (find-tag-tag "Find tag: ") nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (let* ((local-find-tag-hook find-tag-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 (next (null tagname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 (result (find-tag-internal tagname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 (tag-buf (car result))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (tag-point (cdr result)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 ;; Push old position on the tags mark stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 (if (or (not next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 (not (memq last-command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 '(find-tag find-tag-other-window tags-loop-continue))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 (push-tag-mark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 (if other-window
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
926 (pop-to-buffer tag-buf t)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 (switch-to-buffer tag-buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (push-mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 (goto-char tag-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 (if find-tag-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 (run-hooks 'find-tag-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 (if local-find-tag-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 (run-hooks 'local-find-tag-hook))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (setq tags-loop-scan (list 'find-tag nil nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 tags-loop-operate nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 ;; Return t in case used as the tags-loop-scan.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 (defun find-tag-other-window (tagname &optional next)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
942 "*Find tag whose name contains TAGNAME, in another window.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 Selects the buffer that the tag is contained in in another window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 and puts point at its definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 If TAGNAME is a null string, the expression in the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 around or before point is used as the tag name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 If second arg NEXT is non-nil (interactively, with prefix arg),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 searches for the next tag in the tag table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 that matches the tagname used in the previous find-tag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 This version of this function supports multiple active tags tables,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 and completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 Variables of note:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 tag-table-alist controls which tables apply to which buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 tags-file-name a default tags table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 tags-build-completion-table controls completion behavior
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 buffer-tag-table another way of specifying a buffer-local table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 make-tags-files-invisible whether tags tables should be very hidden
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 tag-mark-stack-max how many tags-based hops to remember"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 (interactive (if current-prefix-arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 '(nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 (list (find-tag-tag "Find tag other window: "))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 (if next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 (find-tag nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 (find-tag tagname t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 ;; Completion on tags in the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 (defun complete-symbol (&optional table predicate prettify)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (let* ((end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 (beg (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 (backward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 ;;(while (= (char-syntax (following-char)) ?\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 ;; (forward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 (skip-syntax-forward "'")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 (pattern (buffer-substring beg end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 (table (or table obarray))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (completion (try-completion pattern table predicate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 (cond ((eq completion t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 ((null completion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 (error "Can't find completion for \"%s\"" pattern))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 ((not (string-equal pattern completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 (delete-region beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 (insert completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 (message "Making completion list...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 (let ((list (all-completions pattern table predicate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 (if prettify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 (setq list (funcall prettify list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 (with-output-to-temp-buffer "*Help*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 (display-completion-list list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 (message "Making completion list...%s" "done")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 (defun tag-complete-symbol ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 "The function used to do tags-completion (using 'tag-completion-predicate)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 (let* ((buffer-tag-table-list (buffer-tag-table-symbol-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 tag-symbol-tables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 (complete-symbol tag-completion-table 'tag-completion-predicate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 ;; Applying a command to files mentioned in tag tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 (defvar next-file-list nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 "List of files for next-file to process.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (defun next-file (&optional initialize novisit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 "Select next file among files in current tag table(s).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 A first argument of t (prefix arg, if interactive) initializes to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 beginning of the list of files in the (first) tags table. If the argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 is neither nil nor t, it is evalled to initialize the list of files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 Non-nil second argument NOVISIT means use a temporary buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 to save time and avoid uninteresting warnings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 Value is nil if the file was already visited;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 if the file was newly read in, the value is the filename."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 (cond ((not initialize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 ;; Not the first run.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 ((eq initialize t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 ;; Initialize the list from the tags table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 (setq next-file-list (buffer-tag-table-files)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 ;; Initialize the list by evalling the argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 (setq next-file-list (eval initialize))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 (when (null next-file-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (and novisit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 (get-buffer " *next-file*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 (kill-buffer " *next-file*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 (error "All files processed"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 (let* ((file (car next-file-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (buf (get-file-buffer file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (new (not buf)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (pop next-file-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 (if (not (and new novisit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (switch-to-buffer (find-file-noselect file novisit) t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 ;; Like find-file, but avoids random junk.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 (set-buffer (get-buffer-create " *next-file*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 (insert-file-contents file nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 (when (> (point) (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 (push-mark nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 (goto-char (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (and new file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 (defun tags-loop-continue (&optional first-time)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 "Continue last \\[tags-search] or \\[tags-query-replace] command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 Used noninteractively with non-nil argument to begin such a command (the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 argument is passed to `next-file', which see).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 Two variables control the processing we do on each file:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 the value of `tags-loop-scan' is a form to be executed on each file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 to see if it is interesting (it returns non-nil if so)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 and `tags-loop-operate' is a form to execute to operate on an interesting file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 If the latter returns non-nil, we exit; otherwise we scan the next file."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 (let ((messaged nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 (more-files-p t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 (while more-files-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 ;; Scan files quickly for the first or next interesting one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 (while (or first-time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 (not (eval tags-loop-scan))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 (setq new (next-file first-time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 tags-search-nuke-uninteresting-buffers))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 ;; If NEW is non-nil, we got a temp buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 ;; and NEW is the file name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 (if (or messaged
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 (and (not first-time)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 (> (device-baud-rate) search-slow-speed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 (setq messaged t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 (lmessage 'progress
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 "Scanning file %s..." (or new buffer-file-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 (setq first-time nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 (goto-char (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 ;; If we visited it in a temp buffer, visit it now for real.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 (if (and new tags-search-nuke-uninteresting-buffers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 (let ((pos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 (set-buffer (find-file-noselect new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 (goto-char pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 (switch-to-buffer (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 ;; Now operate on the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 ;; If value is non-nil, continue to scan the next file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 (setq more-files-p (eval tags-loop-operate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 (and messaged
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 (null tags-loop-operate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 (message "Scanning file %s...found" buffer-file-name))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 (defun tags-search (regexp &optional file-list-form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 "Search through all files listed in tags table for match for REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 Stops when a match is found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 To continue searching for next match, use command \\[tags-loop-continue].
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 See documentation of variable `tag-table-alist'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 (interactive "sTags search (regexp): ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 (if (and (equal regexp "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 (eq (car tags-loop-scan) 'with-search-caps-disable-folding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 (null tags-loop-operate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 ;; Continue last tags-search as if by `M-,'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 (tags-loop-continue nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 (setq tags-loop-scan `(with-search-caps-disable-folding ,regexp t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 (re-search-forward ,regexp nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 tags-loop-operate nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 (tags-loop-continue (or file-list-form t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 (defun tags-query-replace (from to &optional delimited file-list-form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 "Query-replace-regexp FROM with TO through all files listed in tags table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 If you exit (\\[keyboard-quit] or ESC), you can resume the query-replace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 with the command \\[tags-loop-continue].
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 See documentation of variable `tag-table-alist'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 "sTags query replace (regexp): \nsTags query replace %s by: \nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 (setq tags-loop-scan `(with-search-caps-disable-folding ,from t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 (if (re-search-forward ,from nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 ;; When we find a match, move back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 ;; to the beginning of it so perform-replace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 ;; will see it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 (progn (goto-char (match-beginning 0)) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 tags-loop-operate (list 'perform-replace from to t t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 (not (null delimited))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 (tags-loop-continue (or file-list-form t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 ;; Miscellaneous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 (defun list-tags (file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 "Display list of tags in FILE."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 (interactive (list (read-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 (if (buffer-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 (format "List tags (in file, %s by default): "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 (file-name-nondirectory (buffer-file-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 "List tags (in file): ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 nil (buffer-file-name) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 (find-file-noselect file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 (with-output-to-temp-buffer "*Tags List*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 (princ "Tags in file ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 (princ file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 (dolist (tags-file (with-current-buffer (get-file-buffer file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 (buffer-tag-table-list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 ;; We don't want completions getting in the way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 (let ((tags-build-completion-table nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 (set-buffer (get-tag-table-buffer tags-file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 (when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 (search-forward (concat "\f\n" (file-name-nondirectory file) ",")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 (while (not (or (eobp) (looking-at "\f")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 (princ (buffer-substring (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 (progn (skip-chars-forward "^\C-?")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 (forward-line 1)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 (defun tags-apropos (string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 "Display list of all tags in tag table REGEXP matches."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 (interactive "sTag apropos (regexp): ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 (with-output-to-temp-buffer "*Tags List*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 (princ "Tags matching regexp ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 (prin1 string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 (visit-tags-table-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 (goto-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 (while (re-search-forward string nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 (princ (buffer-substring (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 (progn (skip-chars-forward "^\C-?")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 (forward-line 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 ;; #### copied from tags.el. This function is *very* big in FSF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 (defun visit-tags-table-buffer ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 "Select the buffer containing the current tag table."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 (or tags-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 (call-interactively 'visit-tags-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 (set-buffer (or (get-file-buffer tags-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 (setq tag-table-files nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 (find-file-noselect tags-file-name))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 (or (verify-visited-file-modtime (get-file-buffer tags-file-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 (cond ((yes-or-no-p "Tags file has changed, read new contents? ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 (revert-buffer t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 (setq tag-table-files nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 (or (eq (char-after 1) ?\^L)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 (error "File %s not a valid tag table" tags-file-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 ;; Sample uses of find-tag-hook and find-tag-default-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 ;; This is wrong. We should either make this behavior default and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 ;; back it up, or not use it at all. For now, I've commented it out.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 ;; --hniksic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 ;; Example buffer-local tag finding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 ;(add-hook 'emacs-lisp-mode-hook 'setup-emacs-lisp-default-tag-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 ;(defun setup-emacs-lisp-default-tag-hook ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 ; (cond ((eq major-mode 'emacs-lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 ; (make-variable-buffer-local 'find-tag-default-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 ; (setq find-tag-default-hook 'emacs-lisp-default-tag))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 ;;; Run it once immediately
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 ;(setup-emacs-lisp-default-tag-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 ;(when (get-buffer "*scratch*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 ; (with-current-buffer "*scratch*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 ; (setup-emacs-lisp-default-tag-hook)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 ;(defun emacs-lisp-default-tag ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 ; "Function to return a default tag for Emacs-Lisp mode."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 ; (let ((tag (or (variable-at-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 ; (function-at-point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 ; (if tag (symbol-name tag))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 ;; Display short info on tag in minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 ;; Don't pollute `M-?' -- we may need it for more important stuff. --hniksic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 ;(if (null (lookup-key esc-map "?"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 ; (define-key esc-map "?" 'display-tag-info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 (defun display-tag-info (tagname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 "Prints a description of the first tag matching TAGNAME in the echo area.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 If this is an elisp function, prints something like \"(defun foo (x y z)\".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 That is, is prints the first line of the definition of the form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 If this is a C-defined elisp function, it does something more clever."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 (interactive (if current-prefix-arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 '(nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 (list (find-tag-tag "Display tag info: "))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 (let* ((results (find-tag-internal tagname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 (tag-buf (car results))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 (tag-point (cdr results))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 info lname min max fname args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 (with-current-buffer tag-buf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 (goto-char tag-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 (cond ((let ((case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 (looking-at "^DEFUN[ \t]"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 (forward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 (down-list 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 (setq lname (read (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 fname (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 (progn (forward-sexp 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 (progn (backward-sexp 1) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 min (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 (progn (forward-sexp 3) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 (progn (backward-sexp 1) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 max (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 (progn (forward-sexp 2) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 (progn (backward-sexp 1) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 (backward-up-list 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 (setq args (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 (progn (forward-sexp 2) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 (progn (backward-sexp 1) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 (setq info (format "Elisp: %s, C: %s %s, #args: %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 lname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 fname args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 (if (string-equal min max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 min
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 (format "from %s to %s" min max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 (setq info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 (progn (beginning-of-line) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 (progn (end-of-line) (point)))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 (message "%s" info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 (setq tags-loop-scan '(display-tag-info nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 tags-loop-operate nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 ;; Always return non-nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 ;; Tag mark stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 (defvar tag-mark-stack1 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 (defvar tag-mark-stack2 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 (defcustom tag-mark-stack-max 16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 "*The maximum number of elements kept on the mark-stack used
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 by tags-search. See also the commands `\\[push-tag-mark]' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 and `\\[pop-tag-mark]'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 :group 'etags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 (defun push-mark-on-stack (stack-symbol &optional max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 (let ((stack (symbol-value stack-symbol)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 (push (point-marker) stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 (cond ((and max-size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 (> (length stack) max-size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 (set-marker (car (nthcdr max-size stack)) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 (setcdr (nthcdr (1- max-size) stack) nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 (set stack-symbol stack)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 (defun pop-mark-from-stack (stack-symbol1 stack-symbol2 &optional max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 (let* ((stack (or (symbol-value stack-symbol1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 (error "No more tag marks on stack")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 (marker (car stack))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 (m-buf (marker-buffer marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 (set stack-symbol1 (cdr stack))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 (or m-buf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 (error "Marker has no buffer"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 (or (buffer-live-p m-buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 (error "Buffer has been killed"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 (push-mark-on-stack stack-symbol2 max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 (switch-to-buffer m-buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 (goto-char marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 (defun push-tag-mark ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 (push-mark-on-stack 'tag-mark-stack1 tag-mark-stack-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 ;;;###autoload (define-key esc-map "*" 'pop-tag-mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 (defun pop-tag-mark (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 "Go to last tag position.
5384
3889ef128488 Fix misspelled words, and some grammar, across the entire source tree.
Jerry James <james@xemacs.org>
parents: 5369
diff changeset
1347 `find-tag' maintains a mark-stack separate from the \\[set-mark-command] mark-stack.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 This function pops (and moves to) the tag at the top of this stack."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 (if (not arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 (pop-mark-from-stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 'tag-mark-stack1 'tag-mark-stack2 tag-mark-stack-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 (pop-mark-from-stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 'tag-mark-stack2 'tag-mark-stack1 tag-mark-stack-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 (provide 'etags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 (provide 'tags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 ;;; etags.el ends here