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