Mercurial > emacs
annotate lisp/progmodes/etags.el @ 911:e18a3f6689a9
entered into RCS
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Mon, 03 Aug 1992 16:41:27 +0000 |
parents | 81e6b85a9261 |
children | 49a539ef702f |
rev | line source |
---|---|
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
1 ;; etags.el --- etags facility for Emacs |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
2 |
895
81e6b85a9261
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
884
diff
changeset
|
3 ;; Copyright (C) 1985, 1986, 1988, 1989, 1992 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
824
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
5 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu> |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
6 ;; Keywords: tools |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
7 |
342 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
727 | 12 ;; the Free Software Foundation; either version 2, or (at your option) |
342 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
24 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
25 |
360 | 26 ;;;###autoload |
27 (defvar tags-file-name nil "\ | |
799 | 28 *File name of tags table. |
29 To switch to a new tags table, setting this variable is sufficient. | |
30 Use the `etags' program to make a tags table file.") | |
824 | 31 ;;;###autoload (put 'tags-file-name 'variable-interactive "fVisit tags table: ") |
799 | 32 |
33 ;;;###autoload | |
34 (defvar tags-table-list nil | |
35 "*List of names of tags table files which are currently being searched. | |
36 An element of nil means to look for a file \"TAGS\" in the current directory. | |
37 Use `visit-tags-table-buffer' to cycle through tags tables in this list.") | |
38 | |
39 (defvar tags-table-list-pointer nil | |
40 "Pointer into `tags-table-list', or into a list of included tags tables, | |
41 where the current state of searching is. Use `visit-tags-table-buffer' to | |
42 cycle through tags tables in this list.") | |
342 | 43 |
799 | 44 (defvar tags-table-parent-pointer-list nil |
45 "List of values to restore into `tags-table-list-pointer' when it hits nil.") | |
46 | |
47 (defvar tags-table-set-list nil | |
48 "List of sets of tags table which have been used together in the past. | |
49 Each element is a list of strings which are file names.") | |
342 | 50 |
799 | 51 ;;;###autoload |
52 (defvar find-tag-hook nil | |
53 "*Hook to be run by \\[find-tag] after finding a tag. See `run-hooks'. | |
54 The value in the buffer in which \\[find-tag] is done is used, | |
55 not the value in the buffer \\[find-tag] goes to.") | |
56 | |
57 ;;;###autoload | |
58 (defvar find-tag-default-function nil | |
59 "*If non-nil, a function of no arguments used by \\[find-tag] to pick a | |
60 default tag. If nil, and the symbol that is the value of `major-mode' | |
61 has a `find-tag-default-function' property (see `put'), that is used. | |
62 Otherwise, `find-tag-default' is used.") | |
342 | 63 |
360 | 64 ;;;###autoload |
799 | 65 (defvar default-tags-table-function nil |
66 "*If non-nil, a function of no arguments to choose a default tags file | |
67 for a particular buffer.") | |
68 | |
69 ;; Tags table state. | |
70 ;; These variables are local in tags table buffers. | |
71 | |
72 (defvar tag-lines-already-matched nil | |
73 "List of positions of beginnings of lines within the tags table | |
74 that are already matched.") | |
75 | |
76 (defvar tags-table-files nil | |
77 "List of file names covered by current tags table. | |
78 nil means it has not yet been computed; use `tags-table-files' to do so.") | |
79 | |
80 (defvar tags-completion-table nil | |
81 "Alist of tag names defined in current tags table.") | |
82 | |
83 (defvar tags-included-tables nil | |
84 "List of tags tables included by the current tags table.") | |
85 | |
86 (defvar next-file-list nil | |
87 "List of files for \\[next-file] to process.") | |
88 | |
89 ;; Hooks for file formats. | |
90 | |
91 (defvar tags-table-format-hooks '(etags-recognize-tags-table | |
824 | 92 recognize-empty-tags-table) |
799 | 93 "List of functions to be called in a tags table buffer to identify |
94 the type of tags table. The functions are called in order, with no arguments, | |
95 until one returns non-nil. The function should make buffer-local bindings | |
96 of the format-parsing tags function variables if successful.") | |
97 | |
98 (defvar file-of-tag-function nil | |
99 "Function to do the work of `file-of-tag' (which see).") | |
100 (defvar tags-table-files-function nil | |
101 "Function to do the work of `tags-table-files' (which see).") | |
102 (defvar tags-completion-table-function nil | |
103 "Function to build the tags-completion-table.") | |
104 (defvar snarf-tag-function nil | |
105 "Function to get info about a matched tag for `goto-tag-location-function'.") | |
106 (defvar goto-tag-location-function nil | |
107 "Function of to go to the location in the buffer specified by a tag. | |
108 One argument, the tag info returned by `snarf-tag-function'.") | |
109 (defvar find-tag-regexp-search-function nil | |
110 "Search function passed to `find-tag-in-order' for finding a regexp tag.") | |
111 (defvar find-tag-regexp-tag-order nil | |
112 "Tag order passed to `find-tag-in-order' for finding a regexp tag.") | |
113 (defvar find-tag-regexp-next-line-after-failure-p nil | |
114 "Flag passed to `find-tag-in-order' for finding a regexp tag.") | |
115 (defvar find-tag-search-function nil | |
116 "Search function passed to `find-tag-in-order' for finding a tag.") | |
117 (defvar find-tag-tag-order nil | |
118 "Tag order passed to `find-tag-in-order' for finding a tag.") | |
119 (defvar find-tag-next-line-after-failure-p nil | |
120 "Flag passed to `find-tag-in-order' for finding a tag.") | |
121 (defvar list-tags-function nil | |
122 "Function to do the work of `list-tags' (which see).") | |
123 (defvar tags-apropos-function nil | |
124 "Function to do the work of `tags-apropos' (which see).") | |
125 (defvar tags-included-tables-function nil | |
126 "Function to do the work of `tags-included-tables' (which see).") | |
127 (defvar verify-tags-table-function nil | |
128 "Function to return t iff the current buffer vontains a valid | |
129 \(already initialized\) tags file.") | |
130 | |
131 (defun initialize-new-tags-table () | |
132 "Initialize the tags table in the current buffer. | |
133 Returns non-nil iff it is a valid tags table." | |
134 (make-local-variable 'tag-lines-already-matched) | |
135 (make-local-variable 'tags-table-files) | |
136 (make-local-variable 'tags-completion-table) | |
137 (make-local-variable 'tags-included-tables) | |
138 (setq tags-table-files nil | |
139 tag-lines-already-matched nil | |
140 tags-completion-table nil | |
141 tags-included-tables nil) | |
142 ;; Value is t if we have found a valid tags table buffer. | |
143 (let ((hooks tags-table-format-hooks)) | |
144 (while (and hooks | |
145 (not (funcall (car hooks)))) | |
146 (setq hooks (cdr hooks))) | |
147 hooks)) | |
148 | |
149 ;;;###autoload | |
150 (defun visit-tags-table (file &optional local) | |
151 "Tell tags commands to use tags table file FILE. | |
342 | 152 FILE should be the name of a file created with the `etags' program. |
799 | 153 A directory name is ok too; it means file TAGS in that directory. |
154 | |
155 Normally \\[visit-tags-table] sets the global value of `tags-file-name'. | |
156 With a prefix arg, set the buffer-local value instead. | |
157 When you find a tag with \\[find-tag], the buffer it finds the tag | |
158 in is given a local value of this variable which is the name of the tags | |
159 file the tag was in." | |
342 | 160 (interactive (list (read-file-name "Visit tags table: (default TAGS) " |
161 default-directory | |
799 | 162 (expand-file-name "TAGS" |
163 default-directory) | |
164 t) | |
165 current-prefix-arg)) | |
342 | 166 (if (file-directory-p file) |
799 | 167 (setq file (expand-file-name "TAGS" file))) |
168 (if local | |
169 (setq tags-file-name file) | |
170 (kill-local-variable 'tags-file-name) | |
171 (setq-default tags-file-name file)) | |
172 (save-excursion | |
173 (visit-tags-file t))) | |
174 | |
175 (defun visit-tags-table-buffer (&optional cont) | |
176 "Select the buffer containing the current tags table. | |
177 If optional arg is t, visit the next table in `tags-table-list'. | |
178 If optional arg is the atom `reset', reset to the head of `tags-table-list'. | |
179 If optional arg is the atom `same', don't look for a new table; | |
180 just select the buffer. | |
181 If arg is nil or absent, choose a buffer from information in | |
182 `tags-file-name', `tags-table-list', `tags-table-list-pointer'. | |
183 Returns t if it visits a tags table, or nil if there are no more in the list." | |
184 (if (eq cont 'same) | |
185 (let ((tags-file-name (car tags-table-list-pointer))) | |
186 (if (null tags-file-name) | |
187 nil | |
188 (visit-tags-file nil) | |
189 t)) | |
190 (let ((put-in-list t)) | |
191 (if (cond ((eq cont 'reset) | |
192 (setq tags-table-list-pointer tags-table-list | |
193 cont nil) | |
194 nil) | |
195 (cont | |
196 (setq tags-table-list-pointer (cdr tags-table-list-pointer)) | |
197 (if (tags-included-tables) | |
198 (progn | |
199 ;; Move into the included tags tables. | |
200 (if tags-table-list-pointer | |
201 (setq tags-table-parent-pointer-list | |
202 (cons tags-table-list-pointer | |
203 tags-table-parent-pointer-list))) | |
204 (setq tags-table-list-pointer tags-included-tables))) | |
205 (or tags-table-list-pointer | |
206 ;; Pop back to the tags table after the one which includes | |
207 ;; this one. | |
208 (setq tags-table-list-pointer | |
209 (car tags-table-parent-pointer-list) | |
210 tags-table-parent-pointer-list | |
211 (cdr tags-table-parent-pointer-list))) | |
212 (setq put-in-list nil) | |
213 (null tags-table-list-pointer))) | |
214 ;; No more tags table files in the list. | |
215 nil | |
216 (setq tags-file-name | |
217 (or (if cont | |
218 (and tags-table-list-pointer | |
219 (or (car tags-table-list-pointer) | |
220 ;; nil means look for TAGS in current directory. | |
221 (if (file-exists-p | |
222 (expand-file-name "TAGS" | |
223 default-directory)) | |
224 (expand-file-name "TAGS" | |
225 default-directory)))) | |
226 (cdr (assq 'tags-file-name (buffer-local-variables)))) | |
227 (and default-tags-table-function | |
228 (funcall default-tags-table-function)) | |
852 | 229 ;; Look for a tags table that contains |
230 ;; tags for the current buffer's file. | |
231 (let ((tables tags-table-list) | |
232 (this-file (buffer-file-name)) | |
233 (found nil)) | |
234 (save-excursion | |
235 (while tables | |
236 (if (assoc this-file | |
237 (let ((tags-file-name (car tables))) | |
238 (visit-tags-file nil) | |
239 (or tags-table-files | |
240 (setq tags-table-files | |
241 (funcall | |
242 tags-table-files-function))))) | |
243 (setq found (car tables) | |
244 tables nil) | |
245 (setq tables (cdr tables))))) | |
246 found) | |
799 | 247 (car tags-table-list-pointer) |
248 tags-file-name | |
249 (expand-file-name | |
250 (read-file-name "Visit tags table: (default TAGS) " | |
251 default-directory | |
252 (expand-file-name "TAGS" default-directory) | |
253 t)))) | |
254 (if (file-directory-p tags-file-name) | |
255 (setq tags-file-name (expand-file-name "TAGS" tags-file-name))) | |
256 (visit-tags-file put-in-list) | |
257 t)))) | |
342 | 258 |
799 | 259 ;; Visit tags-file-name and check that it's a valid tags table. |
260 ;; On return, tags-table-list and tags-table-list-pointer | |
261 ;; point to tags-file-name. | |
262 (defun visit-tags-file (put-in-list) | |
263 ;; FILE is never changed, but we don't just use tags-file-name | |
264 ;; directly because we don't want to get its buffer-local value | |
265 ;; in the buffer we switch to. | |
266 (let ((file tags-file-name)) | |
267 (if (if (get-file-buffer file) | |
268 (let (win) | |
269 (set-buffer (get-file-buffer file)) | |
270 (setq win (or verify-tags-table-function | |
271 (initialize-new-tags-table))) | |
272 (if (or (verify-visited-file-modtime (current-buffer)) | |
273 (not (yes-or-no-p | |
274 "Tags file has changed, read new contents? "))) | |
275 (and win (funcall verify-tags-table-function)) | |
276 (revert-buffer t t) | |
277 (initialize-new-tags-table))) | |
278 (set-buffer (find-file-noselect file)) | |
824 | 279 (or (string= file buffer-file-name) |
280 ;; find-file-noselect has changed the file name. | |
281 ;; Propagate the change to tags-file-name and tags-table-list. | |
282 (let ((tail (assoc file tags-table-list))) | |
283 (if tail | |
284 (setcar tail buffer-file-name)) | |
285 (setq tags-file-name buffer-file-name))) | |
799 | 286 (initialize-new-tags-table)) |
287 | |
288 (if (and put-in-list | |
289 (not (equal file (car tags-table-list-pointer)))) | |
290 (let (elt) | |
291 ;; Bury the tags table buffer so it | |
292 ;; doesn't get in the user's way. | |
293 (bury-buffer (current-buffer)) | |
294 ;; Look for this file in the current list of tags files. | |
295 (if (setq elt (member file tags-table-list)) | |
296 (if (eq elt tags-table-list) | |
297 ;; Already at the head of the list. | |
298 () | |
299 ;; Rotate this element to the head of the search list. | |
300 (setq tags-table-list-pointer (nconc elt tags-table-list)) | |
301 (while (not (eq (cdr tags-table-list) elt)) | |
302 (setq tags-table-list (cdr tags-table-list))) | |
303 (setcdr tags-table-list nil) | |
304 (setq tags-table-list tags-table-list-pointer)) | |
305 ;; The table is not in the current set. | |
306 ;; Try to find it in another previously used set. | |
307 (let ((sets tags-table-set-list)) | |
308 (while (and sets | |
309 (not (setq elt (member file | |
310 (car sets))))) | |
311 (setq sets (cdr sets))) | |
312 (if sets | |
313 (progn | |
314 ;; Found in some other set. Switch to that set, making | |
315 ;; the selected tags table the head of the search list. | |
316 (or (memq tags-table-list tags-table-set-list) | |
317 ;; Save the current list. | |
318 (setq tags-table-set-list | |
319 (cons tags-table-list tags-table-set-list))) | |
320 (setq tags-table-list (car sets)) | |
321 (if (eq elt tags-table-list) | |
322 ;; Already at the head of the list | |
323 () | |
324 ;; Rotate this element to the head of the list. | |
325 (setq tags-table-list-pointer | |
326 (nconc elt tags-table-list)) | |
327 (while (not (eq (cdr tags-table-list) elt)) | |
328 (setq tags-table-list (cdr tags-table-list))) | |
329 (setcdr tags-table-list nil) | |
330 (setq tags-table-list tags-table-list-pointer) | |
331 (setcar sets tags-table-list))) | |
332 ;; Not found in any current set. | |
333 (if (and tags-table-list | |
334 (y-or-n-p | |
335 (concat "Add " file | |
336 " to current list of tags tables? "))) | |
337 ;; Add it to the current list. | |
338 (setq tags-table-list | |
339 (cons file tags-table-list)) | |
340 ;; Make a fresh list, and store the old one. | |
341 (or (memq tags-table-list tags-table-set-list) | |
342 (setq tags-table-set-list | |
343 (cons tags-table-list tags-table-set-list))) | |
344 (setq tags-table-list (cons file nil))) | |
345 (setq tags-table-list-pointer tags-table-list)))))) | |
346 | |
347 ;; The buffer was not valid. Don't use it again. | |
348 (kill-local-variable 'tags-file-name) | |
349 (setq tags-file-name nil) | |
350 (error "File %s is not a valid tags table" buffer-file-name)))) | |
342 | 351 |
352 (defun file-of-tag () | |
353 "Return the file name of the file whose tags point is within. | |
799 | 354 Assumes the tags table is the current buffer. |
355 File name returned is relative to tags table file's directory." | |
356 (funcall file-of-tag-function)) | |
342 | 357 |
360 | 358 ;;;###autoload |
799 | 359 (defun tags-table-files () |
360 "Return a list of files in the current tags table. | |
342 | 361 File names returned are absolute." |
362 (save-excursion | |
799 | 363 (visit-tags-table-buffer) |
364 (or tags-table-files | |
365 (setq tags-table-files | |
366 (funcall tags-table-files-function))))) | |
367 | |
368 (defun tags-included-tables () | |
369 "Return a list of tags tables included by the current table." | |
370 (or tags-included-tables | |
371 (setq tags-included-tables (funcall tags-included-tables-function)))) | |
372 | |
373 ;; Build tags-completion-table on demand. The single current tags table | |
374 ;; and its included tags tables (and their included tables, etc.) have | |
375 ;; their tags included in the completion table. | |
376 (defun tags-completion-table () | |
377 (or tags-completion-table | |
378 (condition-case () | |
379 (prog2 | |
380 (message "Making tags completion table for %s..." buffer-file-name) | |
381 (let ((included (tags-included-tables)) | |
382 (table (funcall tags-completion-table-function))) | |
383 (save-excursion | |
384 (while included | |
385 (let ((tags-file-name (car included))) | |
386 (visit-tags-file nil)) | |
387 (if (tags-completion-table) | |
388 (mapatoms (function | |
389 (lambda (sym) | |
390 (intern (symbol-name sym) table))) | |
391 tags-completion-table)) | |
392 (setq included (cdr included)))) | |
393 (setq tags-completion-table table)) | |
394 (message "Making tags completion table for %s...done" | |
395 buffer-file-name)) | |
396 (quit (message "Tags completion table construction aborted.") | |
397 (setq tags-completion-table nil))))) | |
398 | |
399 ;; Completion function for tags. Does normal try-completion, | |
400 ;; but builds tags-completion-table on demand. | |
401 (defun tags-complete-tag (string predicate what) | |
402 (save-excursion | |
403 (visit-tags-table-buffer) | |
404 (if (eq what t) | |
405 (all-completions string (tags-completion-table) predicate) | |
406 (try-completion string (tags-completion-table) predicate)))) | |
342 | 407 |
408 ;; Return a default tag to search for, based on the text at point. | |
409 (defun find-tag-default () | |
410 (save-excursion | |
411 (while (looking-at "\\sw\\|\\s_") | |
412 (forward-char 1)) | |
799 | 413 (if (or (re-search-backward "\\sw\\|\\s_" |
414 (save-excursion (beginning-of-line) (point)) | |
415 t) | |
416 (re-search-forward "\\(\\sw\\|\\s_\\)+" | |
417 (save-excursion (end-of-line) (point)) | |
418 t)) | |
419 (progn (goto-char (match-end 0)) | |
342 | 420 (buffer-substring (point) |
421 (progn (forward-sexp -1) | |
422 (while (looking-at "\\s'") | |
423 (forward-char 1)) | |
424 (point)))) | |
425 nil))) | |
426 | |
799 | 427 ;; Read a tag name from the minibuffer with defaulting and completion. |
342 | 428 (defun find-tag-tag (string) |
799 | 429 (let* ((default (funcall (or find-tag-default-function |
430 (get major-mode 'find-tag-default-function) | |
431 'find-tag-default))) | |
432 (spec (completing-read (if default | |
433 (format "%s(default %s) " string default) | |
434 string) | |
435 'tags-complete-tag))) | |
342 | 436 (list (if (equal spec "") |
799 | 437 (or default (error "There is no default tag")) |
342 | 438 spec)))) |
439 | |
852 | 440 (defvar last-tag nil |
441 "Last tag found by \\[find-tag].") | |
442 | |
799 | 443 ;;;###autoload |
444 (defun find-tag-noselect (tagname &optional next-p regexp-p) | |
445 "Find tag (in current tags table) whose name contains TAGNAME. | |
446 Returns the buffer containing the tag's definition moves its point there, | |
447 but does not select the buffer. | |
448 The default for TAGNAME is the expression in the buffer near point. | |
474 | 449 |
799 | 450 If second arg NEXT-P is non-nil (interactively, with prefix arg), search |
451 for another tag that matches the last tagname or regexp used. When there | |
452 are multiple matches for a tag, more exact matches are found first. | |
450
0bac8c701777
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
449
diff
changeset
|
453 |
799 | 454 If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp. |
342 | 455 |
799 | 456 See documentation of variable `tags-file-name'." |
342 | 457 (interactive (if current-prefix-arg |
458 '(nil t) | |
459 (find-tag-tag "Find tag: "))) | |
799 | 460 (let ((local-find-tag-hook find-tag-hook)) |
852 | 461 (if next-p |
462 nil | |
463 (setq last-tag tagname) | |
464 (visit-tags-table-buffer 'reset)) | |
465 (prog1 | |
466 (find-tag-in-order (if next-p last-tag tagname) | |
467 (if regexp-p | |
468 find-tag-regexp-search-function | |
469 find-tag-search-function) | |
470 (if regexp-p | |
471 find-tag-regexp-tag-order | |
472 find-tag-tag-order) | |
473 (if regexp-p | |
474 find-tag-regexp-next-line-after-failure-p | |
475 find-tag-next-line-after-failure-p) | |
476 (if regexp-p "matching" "containing") | |
477 (not next-p)) | |
478 (run-hooks 'local-find-tag-hook)))) | |
360 | 479 |
480 ;;;###autoload | |
799 | 481 (defun find-tag (tagname &optional next-p) |
482 "Find tag (in current tags table) whose name contains TAGNAME. | |
483 Select the buffer containing the tag's definition, and move point there. | |
484 The default for TAGNAME is the expression in the buffer around or before point. | |
342 | 485 |
799 | 486 If second arg NEXT-P is non-nil (interactively, with prefix arg), search |
487 for another tag that matches the last tagname used. When there are | |
488 multiple matches, more exact matches are found first. | |
489 | |
490 See documentation of variable `tags-file-name'." | |
342 | 491 (interactive (if current-prefix-arg |
492 '(nil t) | |
884 | 493 (find-tag-tag "Find tag: "))) |
799 | 494 (switch-to-buffer (find-tag-noselect tagname next-p))) |
495 ;;;###autoload (define-key esc-map "." 'find-tag) | |
342 | 496 |
727 | 497 ;;;###autoload |
799 | 498 (defun find-tag-other-window (tagname &optional next-p) |
499 "Find tag (in current tags table) whose name contains TAGNAME. | |
500 Select the buffer containing the tag's definition | |
501 in another window, and move point there. | |
502 The default for TAGNAME is the expression in the buffer around or before point. | |
503 | |
504 If second arg NEXT-P is non-nil (interactively, with prefix arg), search | |
505 for another tag that matches the last tagname used. When there are | |
506 multiple matches, more exact matches are found first. | |
507 | |
508 See documentation of variable `tags-file-name'." | |
509 (interactive (if current-prefix-arg | |
510 '(nil t) | |
511 (find-tag-tag "Find tag other window: "))) | |
512 (switch-to-buffer-other-window (find-tag-noselect tagname next-p))) | |
513 ;;;###autoload (define-key ctl-x-4-map "." 'find-tag-other-window) | |
514 | |
804 | 515 ;;;###autoload |
799 | 516 (defun find-tag-other-frame (tagname &optional next-p) |
727 | 517 "Find tag (in current tag table) whose name contains TAGNAME. |
518 Selects the buffer that the tag is contained in in another frame | |
519 and puts point at its definition. | |
520 If TAGNAME is a null string, the expression in the buffer | |
521 around or before point is used as the tag name. | |
799 | 522 If second arg NEXT-P is non-nil (interactively, with prefix arg), |
727 | 523 searches for the next tag in the tag table |
524 that matches the tagname used in the previous find-tag. | |
525 | |
799 | 526 See documentation of variable `tags-file-name'." |
727 | 527 (interactive (if current-prefix-arg |
528 '(nil t) | |
529 (find-tag-tag "Find tag other window: "))) | |
799 | 530 (let ((pop-up-frames t)) |
531 (find-tag-other-window tagname next-p))) | |
532 ;;;###autoload (define-key ctl-x-5-map "." 'find-tag-other-frame) | |
342 | 533 |
360 | 534 ;;;###autoload |
799 | 535 (defun find-tag-regexp (regexp &optional next-p other-window) |
536 "Find tag (in current tags table) whose name matches REGEXP. | |
537 Select the buffer containing the tag's definition and move point there. | |
538 | |
539 If second arg NEXT-P is non-nil (interactively, with prefix arg), search | |
540 for another tag that matches the last tagname used. | |
541 | |
542 If third arg OTHER-WINDOW is non-nil, select the buffer in another window. | |
543 | |
544 See documentation of variable `tags-file-name'." | |
545 (interactive (if current-prefix-arg | |
546 '(nil t) | |
547 (read-string "Find tag regexp: "))) | |
548 (funcall (if other-window 'switch-to-buffer-other-window 'switch-to-buffer) | |
549 (find-tag-noselect regexp next-p t))) | |
550 | |
551 ;; Internal tag finding function. | |
552 | |
553 ;; PATTERN is a string to pass to second arg SEARCH-FORWARD-FUNC, and to | |
554 ;; any member of the function list ORDER (third arg). If ORDER is nil, | |
555 ;; use saved state to continue a previous search. | |
556 | |
557 ;; Fourth arg MATCHING is a string, an English '-ing' word, to be used in | |
558 ;; an error message. | |
559 | |
560 ;; Fifth arg NEXT-LINE-AFTER-FAILURE-P is non-nil if after a failed match, | |
561 ;; point should be moved to the next line. | |
562 | |
563 ;; Algorithm is as follows. For each qualifier-func in ORDER, go to | |
564 ;; beginning of tags file, and perform inner loop: for each naive match for | |
565 ;; PATTERN found using SEARCH-FORWARD-FUNC, qualify the naive match using | |
566 ;; qualifier-func. If it qualifies, go to the specified line in the | |
567 ;; specified source file and return. Qualified matches are remembered to | |
568 ;; avoid repetition. State is saved so that the loop can be continued. | |
569 | |
570 (defun find-tag-in-order (pattern search-forward-func order | |
571 next-line-after-failure-p matching | |
572 first-search) | |
573 (let (file ;name of file containing tag | |
574 tag-info ;where to find the tag in FILE | |
575 tags-table-file ;name of tags file | |
576 (first-table t) | |
577 (tag-order order) | |
578 goto-func | |
579 ) | |
580 (save-excursion | |
581 (or first-search | |
582 (visit-tags-table-buffer)) | |
583 ;; Get a qualified match. | |
584 (catch 'qualified-match-found | |
585 (while (or first-table | |
586 (visit-tags-table-buffer t)) | |
587 | |
588 (if first-search | |
589 (setq tag-lines-already-matched nil)) | |
590 | |
884 | 591 (and first-search first-table |
592 ;; Start at beginning of tags file. | |
593 (goto-char (point-min))) | |
594 (setq first-table nil) | |
799 | 595 |
596 (setq tags-table-file buffer-file-name) | |
597 (while order | |
598 (while (funcall search-forward-func pattern nil t) | |
599 ;; Naive match found. Qualify the match. | |
600 (and (funcall (car order) pattern) | |
601 ;; Make sure it is not a previous qualified match. | |
602 ;; Use of `memq' depends on numbers being eq. | |
603 (not (memq (save-excursion (beginning-of-line) (point)) | |
604 tag-lines-already-matched)) | |
605 (throw 'qualified-match-found nil)) | |
606 (if next-line-after-failure-p | |
607 (forward-line 1))) | |
608 ;; Try the next flavor of match. | |
609 (setq order (cdr order)) | |
610 (goto-char (point-min))) | |
611 (setq order tag-order)) | |
612 ;; We throw out on match, so only get here if there were no matches. | |
613 (error "No %stags %s %s" (if first-search "" "more ") | |
614 matching pattern)) | |
615 | |
616 ;; Found a tag; extract location info. | |
617 (beginning-of-line) | |
618 (setq tag-lines-already-matched (cons (point) | |
619 tag-lines-already-matched)) | |
620 ;; Expand the filename, using the tags table buffer's default-directory. | |
621 (setq file (expand-file-name (file-of-tag)) | |
622 tag-info (funcall snarf-tag-function)) | |
623 | |
624 ;; Get the local value in the tags table buffer. | |
625 (setq goto-func goto-tag-location-function) | |
626 | |
627 ;; Find the right line in the specified file. | |
628 (set-buffer (find-file-noselect file)) | |
629 (widen) | |
630 (push-mark) | |
631 (funcall goto-func tag-info) | |
632 | |
633 ;; Give this buffer a local value of tags-file-name. | |
634 ;; The next time visit-tags-table-buffer is called, | |
635 ;; it will use the same tags table that found a match in this buffer. | |
636 (make-local-variable 'tags-file-name) | |
637 (setq tags-file-name tags-table-file) | |
638 | |
639 ;; Return the buffer where the tag was found. | |
640 (current-buffer)))) | |
641 | |
642 ;; `etags' TAGS file format support. | |
643 | |
644 (defun etags-recognize-tags-table () | |
645 (and (eq (char-after 1) ?\f) | |
646 (message "%s is an `etags' TAGS file" buffer-file-name) | |
647 (mapcar (function (lambda (elt) | |
648 (make-local-variable (car elt)) | |
649 (set (car elt) (cdr elt)))) | |
650 '((file-of-tag-function . etags-file-of-tag) | |
651 (tags-table-files-function . etags-tags-table-files) | |
652 (tags-completion-table-function . etags-tags-completion-table) | |
653 (snarf-tag-function . etags-snarf-tag) | |
654 (goto-tag-location-function . etags-goto-tag-location) | |
655 (find-tag-regexp-search-function . re-search-forward) | |
656 (find-tag-regexp-tag-order . (tag-re-match-p)) | |
657 (find-tag-regexp-next-line-after-failuire-p . t) | |
658 (find-tag-search-function . search-forward) | |
659 (find-tag-tag-order . (tag-exact-match-p tag-word-match-p | |
660 tag-any-match-p)) | |
661 (find-tag-next-line-after-failure-p . nil) | |
662 (list-tags-function . etags-list-tags) | |
663 (tags-apropos-function . etags-tags-apropos) | |
664 (tags-included-tables-function . etags-tags-included-tables) | |
665 (verify-tags-table-function . etags-verify-tags-table) | |
666 )))) | |
667 | |
668 (defun etags-verify-tags-table () | |
669 (= (char-after 1) ?\f)) | |
670 | |
671 (defun etags-file-of-tag () | |
672 (save-excursion | |
673 (search-backward "\f\n") | |
674 (forward-char 2) | |
675 (buffer-substring (point) | |
676 (progn (skip-chars-forward "^,") (point))))) | |
677 | |
678 (defun etags-tags-completion-table () | |
679 (let ((table (make-vector 511 0))) | |
680 (save-excursion | |
681 (goto-char (point-min)) | |
682 (while (search-forward "\177" nil t) | |
683 ;; Handle multiple \177's on a line. | |
684 (save-excursion | |
685 (skip-chars-backward "^-A-Za-z0-9_$\n") ;sym syntax? XXX | |
686 (or (bolp) | |
687 (intern (buffer-substring | |
688 (point) | |
689 (progn | |
690 (skip-chars-backward "-A-Za-z0-9_$") | |
691 ;; ??? New | |
692 ;; `::' in the middle of a C++ tag. | |
693 (and (= (preceding-char) ?:) | |
694 (= (char-after (- (point) 2)) ?:) | |
695 (progn | |
696 (backward-char 2) | |
697 (skip-chars-backward | |
698 "-A-Za-z0-9_$"))) | |
699 (point))) | |
700 table))))) | |
701 table)) | |
702 | |
703 (defun etags-snarf-tag () | |
704 (let (tag-text startpos) | |
705 (search-forward "\177") | |
706 (setq tag-text (buffer-substring (1- (point)) | |
707 (save-excursion (beginning-of-line) | |
708 (point)))) | |
709 (search-forward ",") | |
710 (setq startpos (string-to-int (buffer-substring | |
711 (point) | |
712 (progn (skip-chars-forward "0-9") | |
713 (point))))) | |
714 ;; Leave point on the next line of the tags file. | |
715 (forward-line 1) | |
716 (cons tag-text startpos))) | |
717 | |
718 (defun etags-goto-tag-location (tag-info) | |
719 (let ((startpos (cdr tag-info)) | |
720 ;; This constant is 1/2 the initial search window. | |
721 ;; There is no sense in making it too small, | |
722 ;; since just going around the loop once probably | |
723 ;; costs about as much as searching 2000 chars. | |
724 (offset 1000) | |
725 (found nil) | |
726 (pat (concat "^" (regexp-quote (car tag-info))))) | |
727 (or startpos | |
728 (setq startpos (point-min))) | |
729 (while (and (not found) | |
730 (progn | |
731 (goto-char (- startpos offset)) | |
732 (not (bobp)))) | |
733 (setq found | |
734 (re-search-forward pat (+ startpos offset) t) | |
735 offset (* 3 offset))) ; expand search window | |
736 (or found | |
737 (re-search-forward pat nil t) | |
738 (error "`%s' not found in %s; time to rerun etags" | |
739 pat buffer-file-name))) | |
740 (beginning-of-line)) | |
741 | |
742 (defun etags-list-tags (file) | |
743 (goto-char 1) | |
744 (if (not (search-forward (concat "\f\n" file ",") nil t)) | |
745 nil | |
746 (forward-line 1) | |
747 (while (not (or (eobp) (looking-at "\f"))) | |
748 (princ (buffer-substring (point) | |
749 (progn (skip-chars-forward "^\177") | |
750 (point)))) | |
751 (terpri) | |
752 (forward-line 1)))) | |
753 | |
754 (defun etags-tags-apropos (string) | |
755 (goto-char 1) | |
756 (while (re-search-forward string nil t) | |
757 (beginning-of-line) | |
758 (princ (buffer-substring (point) | |
759 (progn (skip-chars-forward "^\177") | |
760 (point)))) | |
761 (terpri) | |
762 (forward-line 1))) | |
763 | |
764 (defun etags-tags-table-files () | |
765 (let ((files nil) | |
766 beg) | |
767 (goto-char (point-min)) | |
768 (while (search-forward "\f\n" nil t) | |
769 (setq beg (point)) | |
770 (skip-chars-forward "^,\n") | |
771 (or (looking-at ",include$") | |
772 ;; Expand in the default-directory of the tags table buffer. | |
773 (setq files (cons (expand-file-name (buffer-substring beg (point))) | |
774 files)))) | |
775 (nreverse files))) | |
776 | |
777 (defun etags-tags-included-tables () | |
778 (let ((files nil) | |
779 beg) | |
780 (goto-char (point-min)) | |
781 (while (search-forward "\f\n" nil t) | |
782 (setq beg (point)) | |
783 (skip-chars-forward "^,\n") | |
784 (if (looking-at ",include$") | |
785 ;; Expand in the default-directory of the tags table buffer. | |
786 (setq files (cons (expand-file-name (buffer-substring beg (point))) | |
787 files)))) | |
788 (nreverse files))) | |
789 | |
790 ;; Empty tags file support. | |
791 | |
792 (defun recognize-empty-tags-table () | |
793 (and (zerop (buffer-size)) | |
794 (mapcar (function (lambda (sym) | |
795 (make-local-variable sym) | |
800 | 796 (set sym 'ignore))) |
799 | 797 '(tags-table-files-function |
798 tags-completion-table-function | |
799 find-tag-regexp-search-function | |
800 find-tag-search-function | |
801 tags-apropos-function | |
802 tags-included-tables-function)) | |
803 (set (make-local-variable 'verify-tags-table-function) | |
804 (function (lambda () | |
805 (zerop (buffer-size))))))) | |
806 | |
807 ;;; Match qualifier functions for tagnames. | |
808 | |
884 | 809 ;; This might be a neat idea, but it's too hairy at the moment. |
810 ;;(defmacro tags-with-syntax (&rest body) | |
811 ;; (` (let ((current (current-buffer)) | |
812 ;; (otable (syntax-table)) | |
813 ;; (buffer (find-file-noselect (file-of-tag))) | |
814 ;; table) | |
815 ;; (unwind-protect | |
816 ;; (progn | |
817 ;; (set-buffer buffer) | |
818 ;; (setq table (syntax-table)) | |
819 ;; (set-buffer current) | |
820 ;; (set-syntax-table table) | |
821 ;; (,@ body)) | |
822 ;; (set-syntax-table otable))))) | |
823 ;;(put 'tags-with-syntax 'edebug-form-spec '(&rest form)) | |
877 | 824 |
799 | 825 ;; t if point is at a tag line that matches TAG "exactly". |
826 ;; point should be just after a string that matches TAG. | |
884 | 827 (defun tag-exact-match-p (tag) |
828 (and (looking-at "\\Sw.*\177") (looking-at "\\S_.*\177") ;not a symbol char | |
829 (save-excursion | |
830 (backward-char (1+ (length tag))) | |
831 (and (looking-at "\\Sw") (looking-at "\\S_"))))) | |
799 | 832 |
833 ;; t if point is at a tag line that matches TAG as a word. | |
834 ;; point should be just after a string that matches TAG. | |
835 (defun tag-word-match-p (tag) | |
836 (and (looking-at "\\b.*\177") | |
837 (save-excursion (backward-char (1+ (length tag))) | |
838 (looking-at "\\b")))) | |
839 | |
840 ;; t if point is in a tag line with a tag containing TAG as a substring. | |
841 (defun tag-any-match-p (tag) | |
842 (looking-at ".*\177")) | |
843 | |
844 ;; t if point is at a tag line that matches RE as a regexp. | |
845 (defun tag-re-match-p (re) | |
846 (save-excursion | |
847 (beginning-of-line) | |
848 (let ((bol (point))) | |
849 (and (search-forward "\177" (save-excursion (end-of-line) (point)) t) | |
850 (re-search-backward re bol t))))) | |
851 | |
852 ;;;###autoload | |
853 (defun next-file (&optional initialize novisit) | |
854 "Select next file among files in current tags table. | |
855 Non-nil first argument (prefix arg, if interactive) | |
856 initializes to the beginning of the list of files in the tags table. | |
857 | |
858 Non-nil second argument NOVISIT means use a temporary buffer | |
859 to save time and avoid uninteresting warnings. | |
860 | |
861 Value is nil if the file was already visited; | |
862 if the file was newly read in, the value is the filename." | |
342 | 863 (interactive "P") |
799 | 864 (and initialize |
865 (save-excursion | |
866 (visit-tags-table-buffer 'reset) | |
867 (setq next-file-list (tags-table-files)))) | |
342 | 868 (or next-file-list |
799 | 869 (save-excursion |
870 ;; When doing (visit-tag-table-buffer t), | |
871 ;; the tags table buffer must be current. | |
872 (if (and (visit-tags-table-buffer 'same) | |
873 (visit-tags-table-buffer t)) | |
874 (setq next-file-list (tags-table-files)) | |
875 (and novisit | |
876 (get-buffer " *next-file*") | |
877 (kill-buffer " *next-file*")) | |
878 (error "All files processed.")))) | |
879 (let ((new (not (get-file-buffer (car next-file-list))))) | |
880 (if (not (and new novisit)) | |
881 (set-buffer (find-file-noselect (car next-file-list) novisit)) | |
882 ;; Like find-file, but avoids random warning messages. | |
883 (set-buffer (get-buffer-create " *next-file*")) | |
884 (kill-all-local-variables) | |
885 (erase-buffer) | |
886 (setq new (car next-file-list)) | |
887 (insert-file-contents new nil)) | |
888 (setq next-file-list (cdr next-file-list)) | |
889 new)) | |
342 | 890 |
799 | 891 (defvar tags-loop-operate nil |
892 "Form for `tags-loop-continue' to eval to change one file.") | |
893 | |
894 (defvar tags-loop-scan nil | |
895 "Form for `tags-loop-continue' to eval to scan one file. | |
896 If it returns non-nil, this file needs processing by evalling | |
897 \`tags-loop-operate'. Otherwise, move on to the next file.") | |
342 | 898 |
360 | 899 ;;;###autoload |
342 | 900 (defun tags-loop-continue (&optional first-time) |
901 "Continue last \\[tags-search] or \\[tags-query-replace] command. | |
799 | 902 Used noninteractively with non-nil argument to begin such a command. |
903 Two variables control the processing we do on each file: | |
904 the value of `tags-loop-scan' is a form to be executed on each file | |
905 to see if it is interesting (it returns non-nil if so) | |
906 and `tags-loop-operate' is a form to execute to operate on an interesting file | |
907 If the latter returns non-nil, we exit; otherwise we scan the next file." | |
342 | 908 (interactive) |
799 | 909 (let (new |
910 (messaged nil)) | |
911 (while | |
912 (progn | |
913 ;; Scan files quickly for the first or next interesting one. | |
914 (while (or first-time | |
915 (save-restriction | |
916 (widen) | |
917 (not (eval tags-loop-scan)))) | |
918 (setq new (next-file first-time t)) | |
919 ;; If NEW is non-nil, we got a temp buffer, | |
920 ;; and NEW is the file name. | |
921 (if (or messaged | |
922 (and (not first-time) | |
923 (> baud-rate search-slow-speed) | |
924 (setq messaged t))) | |
925 (message "Scanning file %s..." (or new buffer-file-name))) | |
926 (setq first-time nil) | |
927 (goto-char (point-min))) | |
928 | |
929 ;; If we visited it in a temp buffer, visit it now for real. | |
930 (if new | |
931 (let ((pos (point))) | |
932 (erase-buffer) | |
933 (set-buffer (find-file-noselect new)) | |
934 (widen) | |
935 (goto-char pos))) | |
936 | |
937 (switch-to-buffer (current-buffer)) | |
938 | |
939 ;; Now operate on the file. | |
940 ;; If value is non-nil, continue to scan the next file. | |
941 (eval tags-loop-operate))) | |
942 (and messaged | |
943 (null tags-loop-operate) | |
944 (message "Scanning file %s...found" buffer-file-name)))) | |
945 | |
946 ;;;###autoload (define-key esc-map "," 'tags-loop-continue) | |
342 | 947 |
360 | 948 ;;;###autoload |
342 | 949 (defun tags-search (regexp) |
799 | 950 "Search through all files listed in tags table for match for REGEXP. |
342 | 951 Stops when a match is found. |
952 To continue searching for next match, use command \\[tags-loop-continue]. | |
953 | |
799 | 954 See documentation of variable `tags-file-name'." |
342 | 955 (interactive "sTags search (regexp): ") |
956 (if (and (equal regexp "") | |
799 | 957 (eq (car tags-loop-scan) 're-search-forward) |
958 (eq tags-loop-operate t)) | |
959 ;; Continue last tags-search as if by M-,. | |
342 | 960 (tags-loop-continue nil) |
799 | 961 (setq tags-loop-scan |
962 (list 're-search-forward regexp nil t) | |
963 tags-loop-operate nil) | |
342 | 964 (tags-loop-continue t))) |
965 | |
360 | 966 ;;;###autoload |
342 | 967 (defun tags-query-replace (from to &optional delimited) |
799 | 968 "Query-replace-regexp FROM with TO through all files listed in tags table. |
342 | 969 Third arg DELIMITED (prefix arg) means replace only word-delimited matches. |
799 | 970 If you exit (\\[keyboard-quit] or ESC), you can resume the query-replace |
342 | 971 with the command \\[tags-loop-continue]. |
972 | |
799 | 973 See documentation of variable `tags-file-name'." |
974 (interactive | |
975 "sTags query replace (regexp): \nsTags query replace %s by: \nP") | |
804 | 976 (setq tags-loop-scan (list 'prog1 |
977 (list 'if (list 're-search-forward form nil t) | |
978 ;; When we find a match, move back | |
979 ;; to the beginning of it so perform-replace | |
980 ;; will see it. | |
981 '(goto-char (match-beginning 0)))) | |
799 | 982 tags-loop-operate (list 'perform-replace from to t t delimited)) |
342 | 983 (tags-loop-continue t)) |
799 | 984 |
985 ;;;###autoload | |
986 (defun list-tags (file) | |
987 "Display list of tags in file FILE. | |
988 FILE should not contain a directory specification | |
989 unless it has one in the tags table." | |
990 (interactive (list (completing-read "List tags in file: " nil | |
991 'tags-table-files t nil))) | |
992 (with-output-to-temp-buffer "*Tags List*" | |
993 (princ "Tags in file ") | |
994 (princ file) | |
995 (terpri) | |
996 (save-excursion | |
997 (let ((first-time t) | |
998 (gotany nil)) | |
999 (while (visit-tags-table-buffer (if first-time 'reset t)) | |
1000 (if (funcall list-tags-function file) | |
1001 (setq gotany t))) | |
1002 (or gotany | |
1003 (error "File %s not in current tags tables")))))) | |
342 | 1004 |
360 | 1005 ;;;###autoload |
799 | 1006 (defun tags-apropos (regexp) |
1007 "Display list of all tags in tags table REGEXP matches." | |
1008 (interactive "sTags apropos (regexp): ") | |
342 | 1009 (with-output-to-temp-buffer "*Tags List*" |
799 | 1010 (princ "Tags matching regexp ") |
1011 (prin1 regexp) | |
342 | 1012 (terpri) |
1013 (save-excursion | |
799 | 1014 (let ((first-time nil)) |
1015 (while (visit-tags-table-buffer (if first-time 'reset t)) | |
1016 (funcall tags-apropos-function)))))) | |
1017 | |
1018 ;;; XXX Kludge interface. | |
342 | 1019 |
799 | 1020 ;; XXX If a file is in multiple tables, selection may get the wrong one. |
804 | 1021 ;;;###autoload |
799 | 1022 (defun select-tags-table () |
1023 "Select a tags table file from a menu of those you have already used. | |
1024 The list of tags tables to select from is stored in `tags-table-file-list'; | |
1025 see the doc of that variable if you want to add names to the list." | |
1026 (interactive) | |
1027 (pop-to-buffer "*Tags Table List*") | |
1028 (setq buffer-read-only nil) | |
1029 (erase-buffer) | |
1030 (setq selective-display t | |
1031 selective-display-ellipses nil) | |
1032 (let ((set-list tags-table-set-list) | |
1033 (desired-point nil)) | |
1034 (if tags-table-list | |
1035 (progn | |
1036 (setq desired-point (point-marker)) | |
1037 (princ tags-table-list (current-buffer)) | |
1038 (insert "\C-m") | |
1039 (prin1 (car tags-table-list) (current-buffer)) ;invisible | |
1040 (insert "\n"))) | |
1041 (while set-list | |
1042 (if (eq (car set-list) tags-table-list) | |
1043 ;; Already printed it. | |
1044 () | |
1045 (princ (car set-list) (current-buffer)) | |
1046 (insert "\C-m") | |
1047 (prin1 (car (car set-list)) (current-buffer)) ;invisible | |
1048 (insert "\n")) | |
1049 (setq set-list (cdr set-list))) | |
1050 (if tags-file-name | |
1051 (progn | |
1052 (or desired-point | |
1053 (setq desired-point (point-marker))) | |
1054 (insert tags-file-name "\C-m") | |
1055 (prin1 tags-file-name (current-buffer)) ;invisible | |
1056 (insert "\n"))) | |
1057 (setq set-list (delete tags-file-name | |
1058 (apply 'nconc (cons tags-table-list | |
1059 (mapcar 'copy-sequence | |
1060 tags-table-set-list))))) | |
1061 (while set-list | |
1062 (insert (car set-list) "\C-m") | |
1063 (prin1 (car set-list) (current-buffer)) ;invisible | |
1064 (insert "\n") | |
1065 (setq set-list (delete (car set-list) set-list))) | |
1066 (goto-char 1) | |
1067 (insert-before-markers | |
1068 "Type `t' to select a tags table or set of tags tables:\n\n") | |
1069 (if desired-point | |
1070 (goto-char desired-point)) | |
1071 (set-window-start (selected-window) 1 t)) | |
1072 (set-buffer-modified-p nil) | |
1073 (setq buffer-read-only t | |
1074 mode-name "Select Tags Table") | |
1075 (let ((map (make-sparse-keymap))) | |
1076 (define-key map "t" 'select-tags-table-select) | |
1077 (define-key map " " 'next-line) | |
1078 (define-key map "\^?" 'previous-line) | |
1079 (define-key map "n" 'next-line) | |
1080 (define-key map "p" 'previous-line) | |
1081 (define-key map "q" 'select-tags-table-quit) | |
1082 (use-local-map map))) | |
1083 | |
1084 (defun select-tags-table-select () | |
1085 "Select the tags table named on this line." | |
1086 (interactive) | |
1087 (search-forward "\C-m") | |
1088 (let ((name (read (current-buffer)))) | |
1089 (visit-tags-table name) | |
1090 (select-tags-table-quit) | |
1091 (message "Tags table now %s" name))) | |
1092 | |
1093 (defun select-tags-table-quit () | |
1094 "Kill the buffer and delete the selected window." | |
1095 (interactive) | |
1096 (kill-buffer (current-buffer)) | |
1097 (or (one-window-p) | |
1098 (delete-window))) | |
1099 | |
360 | 1100 ;;;###autoload |
799 | 1101 (defun complete-tag () |
1102 "Perform tags completion on the text around point. | |
1103 Completes to the set of names listed in the current tags table. | |
1104 The string to complete is chosen in the same way as the default | |
1105 for \\[find-tag] (which see). See also `visit-tags-table-buffer'." | |
1106 (interactive) | |
1107 (let ((pattern (funcall (or find-tag-default-function | |
1108 (get major-mode 'find-tag-default-function) | |
1109 'find-tag-default))) | |
1110 beg | |
1111 completion) | |
1112 (or pattern | |
1113 (error "Nothing to complete")) | |
1114 (search-backward pattern) | |
1115 (setq beg (point)) | |
1116 (forward-char (length pattern)) | |
1117 (setq completion (try-completion pattern 'tags-complete-tag nil)) | |
1118 (cond ((eq completion t)) | |
1119 ((null completion) | |
1120 (message "Can't find completion for \"%s\"" pattern) | |
1121 (ding)) | |
1122 ((not (string= pattern completion)) | |
1123 (delete-region beg (point)) | |
1124 (insert completion)) | |
1125 (t | |
1126 (message "Making completion list...") | |
1127 (with-output-to-temp-buffer " *Completions*" | |
1128 (display-completion-list | |
1129 (all-completions pattern 'tags-complete-tag nil))) | |
1130 (message "Making completion list...%s" "done"))))) | |
884 | 1131 |
1132 ;;;###autoload (define-key esc-map "\t" 'complete-tag) | |
799 | 1133 |
584 | 1134 (provide 'etags) |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
1135 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
1136 ;;; etags.el ends here |