annotate lisp/etags.el @ 424:11054d720c21 r21-2-20

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