(shell-mode): Use define-derived-mode.
[emacs.git] / lisp / progmodes / etags.el
blob539e4ae57d5e7d21652b9f85924ba5ce5f49f8e6
1 ;;; etags.el --- etags facility for Emacs
2 ;; Copyright (C) 1985, 86, 88, 89, 92, 93, 94, 95, 96, 98, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Roland McGrath <roland@gnu.org>
6 ;; Maintainer: FSF
7 ;; Keywords: tools
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it 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.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;;; Code:
30 (require 'ring)
31 (eval-when-compile (require 'cl)) ; for `gensym'
33 ;;;###autoload
34 (defvar tags-file-name nil
35 "*File name of tags table.
36 To switch to a new tags table, setting this variable is sufficient.
37 If you set this variable, do not also set `tags-table-list'.
38 Use the `etags' program to make a tags table file.")
39 ;; Make M-x set-variable tags-file-name like M-x visit-tags-table.
40 ;;;###autoload (put 'tags-file-name 'variable-interactive "fVisit tags table: ")
42 (defgroup etags nil "Tags tables"
43 :group 'tools)
45 ;;;###autoload
46 (defcustom tags-case-fold-search 'default
47 "*Whether tags operations should be case-sensitive.
48 A value of t means case-insensitive, a value of nil means case-sensitive.
49 Any other value means use the setting of `case-fold-search'."
50 :group 'etags
51 :type '(choice (const :tag "Case-sensitive" nil)
52 (const :tag "Case-insensitive" t)
53 (other :tag "Use default" default))
54 :version "21.1")
56 ;;;###autoload
57 ;; Use `visit-tags-table-buffer' to cycle through tags tables in this list.
58 (defcustom tags-table-list nil
59 "*List of file names of tags tables to search.
60 An element that is a directory means the file \"TAGS\" in that directory.
61 To switch to a new list of tags tables, setting this variable is sufficient.
62 If you set this variable, do not also set `tags-file-name'.
63 Use the `etags' program to make a tags table file."
64 :group 'etags
65 :type '(repeat file))
67 ;;;###autoload
68 (defcustom tags-add-tables 'ask-user
69 "*Control whether to add a new tags table to the current list.
70 t means do; nil means don't (always start a new list).
71 Any other value means ask the user whether to add a new tags table
72 to the current list (as opposed to starting a new list)."
73 :group 'etags
74 :type '(choice (const :tag "Do" t)
75 (const :tag "Don't" nil)
76 (other :tag "Ask" ask-user)))
78 (defcustom tags-revert-without-query nil
79 "*Non-nil means reread a TAGS table without querying, if it has changed."
80 :group 'etags
81 :type 'boolean)
83 (defvar tags-table-computed-list nil
84 "List of tags tables to search, computed from `tags-table-list'.
85 This includes tables implicitly included by other tables. The list is not
86 always complete: the included tables of a table are not known until that
87 table is read into core. An element that is t is a placeholder
88 indicating that the preceding element is a table that has not been read
89 into core and might contain included tables to search.
90 See `tags-table-check-computed-list'.")
92 (defvar tags-table-computed-list-for nil
93 "Value of `tags-table-list' that `tags-table-computed-list' corresponds to.
94 If `tags-table-list' changes, `tags-table-computed-list' is thrown away and
95 recomputed; see `tags-table-check-computed-list'.")
97 (defvar tags-table-list-pointer nil
98 "Pointer into `tags-table-computed-list' for the current state of searching.
99 Use `visit-tags-table-buffer' to cycle through tags tables in this list.")
101 (defvar tags-table-list-started-at nil
102 "Pointer into `tags-table-computed-list', where the current search started.")
104 (defvar tags-table-set-list nil
105 "List of sets of tags table which have been used together in the past.
106 Each element is a list of strings which are file names.")
108 ;;;###autoload
109 (defcustom find-tag-hook nil
110 "*Hook to be run by \\[find-tag] after finding a tag. See `run-hooks'.
111 The value in the buffer in which \\[find-tag] is done is used,
112 not the value in the buffer \\[find-tag] goes to."
113 :group 'etags
114 :type 'hook)
116 ;;;###autoload
117 (defcustom find-tag-default-function nil
118 "*A function of no arguments used by \\[find-tag] to pick a default tag.
119 If nil, and the symbol that is the value of `major-mode'
120 has a `find-tag-default-function' property (see `put'), that is used.
121 Otherwise, `find-tag-default' is used."
122 :group 'etags
123 :type 'function)
125 (defcustom find-tag-marker-ring-length 16
126 "*Length of marker rings `find-tag-marker-ring' and `tags-location-ring'."
127 :group 'etags
128 :type 'integer
129 :version "20.3")
131 (defcustom tags-tag-face 'default
132 "*Face for tags in the output of `tags-apropos'."
133 :group 'etags
134 :type 'face
135 :version "21.1")
137 (defcustom tags-apropos-verbose nil
138 "If non-nil, print the name of the tags file in the *Tags List* buffer."
139 :group 'etags
140 :type 'boolean
141 :version "21.1")
143 (defcustom tags-apropos-additional-actions nil
144 "Specify additional actions for `tags-apropos'.
146 If non-nil, value should be a list of triples (TITLE FUNCTION
147 TO-SEARCH). For each triple, `tags-apropos' processes TO-SEARCH and
148 lists tags from it. TO-SEARCH should be an alist, obarray, or symbol.
149 If it is a symbol, the symbol's value is used.
150 TITLE, a string, is a title used to label the additional list of tags.
151 FUNCTION is a function to call when a symbol is selected in the
152 *Tags List* buffer. It will be called with one argument SYMBOL which
153 is the symbol being selected.
155 Example value:
157 '((\"Emacs Lisp\" Info-goto-emacs-command-node obarray)
158 (\"Common Lisp\" common-lisp-hyperspec common-lisp-hyperspec-obarray)
159 (\"SCWM\" scwm-documentation scwm-obarray))"
160 :group 'etags
161 :type 'list
162 :version "21.1")
164 (defvar find-tag-marker-ring (make-ring find-tag-marker-ring-length)
165 "Ring of markers which are locations from which \\[find-tag] was invoked.")
167 (defvar default-tags-table-function nil
168 "If non-nil, a function to choose a default tags file for a buffer.
169 This function receives no arguments and should return the default
170 tags table file to use for the current buffer.")
172 (defvar tags-location-ring (make-ring find-tag-marker-ring-length)
173 "Ring of markers which are locations visited by \\[find-tag].
174 Pop back to the last location with \\[negative-argument] \\[find-tag].")
176 ;; Tags table state.
177 ;; These variables are local in tags table buffers.
179 (defvar tags-table-files nil
180 "List of file names covered by current tags table.
181 nil means it has not yet been computed; use `tags-table-files' to do so.")
183 (defvar tags-completion-table nil
184 "Obarray of tag names defined in current tags table.")
186 (defvar tags-included-tables nil
187 "List of tags tables included by the current tags table.")
189 (defvar next-file-list nil
190 "List of files for \\[next-file] to process.")
192 ;; Hooks for file formats.
194 (defvar tags-table-format-functions '(etags-recognize-tags-table
195 tags-recognize-empty-tags-table)
196 "Hook to be called in a tags table buffer to identify the type of tags table.
197 The functions are called in order, with no arguments,
198 until one returns non-nil. The function should make buffer-local bindings
199 of the format-parsing tags function variables if successful.")
201 (defvar file-of-tag-function nil
202 "Function to do the work of `file-of-tag' (which see).")
203 (defvar tags-table-files-function nil
204 "Function to do the work of `tags-table-files' (which see).")
205 (defvar tags-completion-table-function nil
206 "Function to build the `tags-completion-table'.")
207 (defvar snarf-tag-function nil
208 "Function to get info about a matched tag for `goto-tag-location-function'.")
209 (defvar goto-tag-location-function nil
210 "Function of to go to the location in the buffer specified by a tag.
211 One argument, the tag info returned by `snarf-tag-function'.")
212 (defvar find-tag-regexp-search-function nil
213 "Search function passed to `find-tag-in-order' for finding a regexp tag.")
214 (defvar find-tag-regexp-tag-order nil
215 "Tag order passed to `find-tag-in-order' for finding a regexp tag.")
216 (defvar find-tag-regexp-next-line-after-failure-p nil
217 "Flag passed to `find-tag-in-order' for finding a regexp tag.")
218 (defvar find-tag-search-function nil
219 "Search function passed to `find-tag-in-order' for finding a tag.")
220 (defvar find-tag-tag-order nil
221 "Tag order passed to `find-tag-in-order' for finding a tag.")
222 (defvar find-tag-next-line-after-failure-p nil
223 "Flag passed to `find-tag-in-order' for finding a tag.")
224 (defvar list-tags-function nil
225 "Function to do the work of `list-tags' (which see).")
226 (defvar tags-apropos-function nil
227 "Function to do the work of `tags-apropos' (which see).")
228 (defvar tags-included-tables-function nil
229 "Function to do the work of `tags-included-tables' (which see).")
230 (defvar verify-tags-table-function nil
231 "Function to return t iff current buffer contains valid tags file.")
233 ;; Initialize the tags table in the current buffer.
234 ;; Returns non-nil iff it is a valid tags table. On
235 ;; non-nil return, the tags table state variable are
236 ;; made buffer-local and initialized to nil.
237 (defun initialize-new-tags-table ()
238 (set (make-local-variable 'tags-table-files) nil)
239 (set (make-local-variable 'tags-completion-table) nil)
240 (set (make-local-variable 'tags-included-tables) nil)
241 ;; We used to initialize find-tag-marker-ring and tags-location-ring
242 ;; here, to new empty rings. But that is wrong, because those
243 ;; are global.
245 ;; Value is t if we have found a valid tags table buffer.
246 (run-hook-with-args-until-success 'tags-table-format-functions))
248 ;;;###autoload
249 (defun visit-tags-table (file &optional local)
250 "Tell tags commands to use tags table file FILE.
251 FILE should be the name of a file created with the `etags' program.
252 A directory name is ok too; it means file TAGS in that directory.
254 Normally \\[visit-tags-table] sets the global value of `tags-file-name'.
255 With a prefix arg, set the buffer-local value instead.
256 When you find a tag with \\[find-tag], the buffer it finds the tag
257 in is given a local value of this variable which is the name of the tags
258 file the tag was in."
259 (interactive (list (read-file-name "Visit tags table: (default TAGS) "
260 default-directory
261 (expand-file-name "TAGS"
262 default-directory)
264 current-prefix-arg))
265 (or (stringp file) (signal 'wrong-type-argument (list 'stringp file)))
266 ;; Bind tags-file-name so we can control below whether the local or
267 ;; global value gets set. Calling visit-tags-table-buffer will
268 ;; initialize a buffer for the file and set tags-file-name to the
269 ;; Calling visit-tags-table-buffer with tags-file-name set to FILE will
270 ;; initialize a buffer for FILE and set tags-file-name to the
271 ;; fully-expanded name.
272 (let ((tags-file-name file))
273 (save-excursion
274 (or (visit-tags-table-buffer file)
275 (signal 'file-error (list "Visiting tags table"
276 "file does not exist"
277 file)))
278 ;; Set FILE to the expanded name.
279 (setq file tags-file-name)))
280 (if local
281 ;; Set the local value of tags-file-name.
282 (set (make-local-variable 'tags-file-name) file)
283 ;; Set the global value of tags-file-name.
284 (setq-default tags-file-name file)))
286 (defun tags-table-check-computed-list ()
287 "Compute `tags-table-computed-list' from `tags-table-list' if necessary."
288 (let ((expanded-list (mapcar 'tags-expand-table-name tags-table-list)))
289 (or (equal tags-table-computed-list-for expanded-list)
290 ;; The list (or default-directory) has changed since last computed.
291 (let* ((compute-for (mapcar 'copy-sequence expanded-list))
292 (tables (copy-sequence compute-for)) ;Mutated in the loop.
293 (computed nil)
294 table-buffer)
296 (while tables
297 (setq computed (cons (car tables) computed)
298 table-buffer (get-file-buffer (car tables)))
299 (if (and table-buffer
300 ;; There is a buffer visiting the file. Now make sure
301 ;; it is initialized as a tag table buffer.
302 (save-excursion
303 (tags-verify-table (buffer-file-name table-buffer))))
304 (save-excursion
305 (set-buffer table-buffer)
306 (if (tags-included-tables)
307 ;; Insert the included tables into the list we
308 ;; are processing.
309 (setcdr tables (nconc (mapcar 'tags-expand-table-name
310 (tags-included-tables))
311 (cdr tables)))))
312 ;; This table is not in core yet. Insert a placeholder
313 ;; saying we must read it into core to check for included
314 ;; tables before searching the next table in the list.
315 (setq computed (cons t computed)))
316 (setq tables (cdr tables)))
318 ;; Record the tags-table-list value (and the context of the
319 ;; current directory) we computed from.
320 (setq tags-table-computed-list-for compute-for
321 tags-table-computed-list (nreverse computed))))))
323 ;; Extend `tags-table-computed-list' to remove the first `t' placeholder.
324 ;; An element of the list that is `t' is a placeholder indicating that the
325 ;; preceding element is a table that has not been read into core and might
326 ;; contain included tables to search. On return, the first placeholder
327 ;; element will be gone and the element before it read into core and its
328 ;; included tables inserted into the list.
329 (defun tags-table-extend-computed-list ()
330 (let ((list tags-table-computed-list))
331 (while (not (eq (nth 1 list) t))
332 (setq list (cdr list)))
333 (save-excursion
334 (if (tags-verify-table (car list))
335 ;; We are now in the buffer visiting (car LIST). Extract its
336 ;; list of included tables and insert it into the computed list.
337 (let ((tables (tags-included-tables))
338 (computed nil)
339 table-buffer)
340 (while tables
341 (setq computed (cons (car tables) computed)
342 table-buffer (get-file-buffer (car tables)))
343 (if table-buffer
344 (save-excursion
345 (set-buffer table-buffer)
346 (if (tags-included-tables)
347 ;; Insert the included tables into the list we
348 ;; are processing.
349 (setcdr tables (append (tags-included-tables)
350 tables))))
351 ;; This table is not in core yet. Insert a placeholder
352 ;; saying we must read it into core to check for included
353 ;; tables before searching the next table in the list.
354 (setq computed (cons t computed)))
355 (setq tables (cdr tables)))
356 (setq computed (nreverse computed))
357 ;; COMPUTED now contains the list of included tables (and
358 ;; tables included by them, etc.). Now splice this into the
359 ;; current list.
360 (setcdr list (nconc computed (cdr (cdr list)))))
361 ;; It was not a valid table, so just remove the following placeholder.
362 (setcdr list (cdr (cdr list)))))))
364 ;; Expand tags table name FILE into a complete file name.
365 (defun tags-expand-table-name (file)
366 (setq file (expand-file-name file))
367 (if (file-directory-p file)
368 (expand-file-name "TAGS" file)
369 file))
371 ;; Like member, but comparison is done after tags-expand-table-name on both
372 ;; sides and elements of LIST that are t are skipped.
373 (defun tags-table-list-member (file list)
374 (setq file (tags-expand-table-name file))
375 (while (and list
376 (or (eq (car list) t)
377 (not (string= file (tags-expand-table-name (car list))))))
378 (setq list (cdr list)))
379 list)
381 (defun tags-verify-table (file)
382 "Read FILE into a buffer and verify that it is a valid tags table.
383 Sets the current buffer to one visiting FILE (if it exists).
384 Returns non-nil iff it is a valid table."
385 (if (get-file-buffer file)
386 ;; The file is already in a buffer. Check for the visited file
387 ;; having changed since we last used it.
388 (let (win)
389 (set-buffer (get-file-buffer file))
390 (setq win (or verify-tags-table-function (initialize-new-tags-table)))
391 (if (or (verify-visited-file-modtime (current-buffer))
392 ;; Decide whether to revert the file.
393 ;; revert-without-query can say to revert
394 ;; or the user can say to revert.
395 (not (or (let ((tail revert-without-query)
396 (found nil))
397 (while tail
398 (if (string-match (car tail) buffer-file-name)
399 (setq found t))
400 (setq tail (cdr tail)))
401 found)
402 tags-revert-without-query
403 (yes-or-no-p
404 (format "Tags file %s has changed, read new contents? "
405 file)))))
406 (and verify-tags-table-function
407 (funcall verify-tags-table-function))
408 (revert-buffer t t)
409 (initialize-new-tags-table)))
410 (and (file-exists-p file)
411 (progn
412 (set-buffer (find-file-noselect file))
413 (or (string= file buffer-file-name)
414 ;; find-file-noselect has changed the file name.
415 ;; Propagate the change to tags-file-name and tags-table-list.
416 (let ((tail (member file tags-table-list)))
417 (if tail
418 (setcar tail buffer-file-name))
419 (if (eq file tags-file-name)
420 (setq tags-file-name buffer-file-name))))
421 (initialize-new-tags-table)))))
423 ;; Subroutine of visit-tags-table-buffer. Search the current tags tables
424 ;; for one that has tags for THIS-FILE (or that includes a table that
425 ;; does). Return the name of the first table table listing THIS-FILE; if
426 ;; the table is one included by another table, it is the master table that
427 ;; we return. If CORE-ONLY is non-nil, check only tags tables that are
428 ;; already in buffers--don't visit any new files.
429 (defun tags-table-including (this-file core-only)
430 (let ((tables tags-table-computed-list)
431 (found nil))
432 ;; Loop over the list, looking for a table containing tags for THIS-FILE.
433 (while (and (not found)
434 tables)
436 (if core-only
437 ;; Skip tables not in core.
438 (while (eq (nth 1 tables) t)
439 (setq tables (cdr (cdr tables))))
440 (if (eq (nth 1 tables) t)
441 ;; This table has not been read into core yet. Read it in now.
442 (tags-table-extend-computed-list)))
444 (if tables
445 ;; Select the tags table buffer and get the file list up to date.
446 (let ((tags-file-name (car tables)))
447 (visit-tags-table-buffer 'same)
448 (if (member this-file (mapcar 'expand-file-name
449 (tags-table-files)))
450 ;; Found it.
451 (setq found tables))))
452 (setq tables (cdr tables)))
453 (if found
454 ;; Now determine if the table we found was one included by another
455 ;; table, not explicitly listed. We do this by checking each
456 ;; element of the computed list to see if it appears in the user's
457 ;; explicit list; the last element we will check is FOUND itself.
458 ;; Then we return the last one which did in fact appear in
459 ;; tags-table-list.
460 (let ((could-be nil)
461 (elt tags-table-computed-list))
462 (while (not (eq elt (cdr found)))
463 (if (tags-table-list-member (car elt) tags-table-list)
464 ;; This table appears in the user's list, so it could be
465 ;; the one which includes the table we found.
466 (setq could-be (car elt)))
467 (setq elt (cdr elt))
468 (if (eq t (car elt))
469 (setq elt (cdr elt))))
470 ;; The last element we found in the computed list before FOUND
471 ;; that appears in the user's list will be the table that
472 ;; included the one we found.
473 could-be))))
475 ;; Subroutine of visit-tags-table-buffer. Move tags-table-list-pointer
476 ;; along and set tags-file-name. Returns nil when out of tables.
477 (defun tags-next-table ()
478 ;; If there is a placeholder element next, compute the list to replace it.
479 (while (eq (nth 1 tags-table-list-pointer) t)
480 (tags-table-extend-computed-list))
482 ;; Go to the next table in the list.
483 (setq tags-table-list-pointer (cdr tags-table-list-pointer))
484 (or tags-table-list-pointer
485 ;; Wrap around.
486 (setq tags-table-list-pointer tags-table-computed-list))
488 (if (eq tags-table-list-pointer tags-table-list-started-at)
489 ;; We have come full circle. No more tables.
490 (setq tags-table-list-pointer nil)
491 ;; Set tags-file-name to the name from the list. It is already expanded.
492 (setq tags-file-name (car tags-table-list-pointer))))
494 (defun visit-tags-table-buffer (&optional cont)
495 "Select the buffer containing the current tags table.
496 If optional arg is a string, visit that file as a tags table.
497 If optional arg is t, visit the next table in `tags-table-list'.
498 If optional arg is the atom `same', don't look for a new table;
499 just select the buffer visiting `tags-file-name'.
500 If arg is nil or absent, choose a first buffer from information in
501 `tags-file-name', `tags-table-list', `tags-table-list-pointer'.
502 Returns t if it visits a tags table, or nil if there are no more in the list."
504 ;; Set tags-file-name to the tags table file we want to visit.
505 (cond ((eq cont 'same)
506 ;; Use the ambient value of tags-file-name.
507 (or tags-file-name
508 (error "%s"
509 (substitute-command-keys
510 (concat "No tags table in use; "
511 "use \\[visit-tags-table] to select one")))))
513 ((eq t cont)
514 ;; Find the next table.
515 (if (tags-next-table)
516 ;; Skip over nonexistent files.
517 (while (and (not (or (get-file-buffer tags-file-name)
518 (file-exists-p tags-file-name)))
519 (tags-next-table)))))
522 ;; Pick a table out of our hat.
523 (tags-table-check-computed-list) ;Get it up to date, we might use it.
524 (setq tags-file-name
526 ;; If passed a string, use that.
527 (if (stringp cont)
528 (prog1 cont
529 (setq cont nil)))
530 ;; First, try a local variable.
531 (cdr (assq 'tags-file-name (buffer-local-variables)))
532 ;; Second, try a user-specified function to guess.
533 (and default-tags-table-function
534 (funcall default-tags-table-function))
535 ;; Third, look for a tags table that contains tags for the
536 ;; current buffer's file. If one is found, the lists will
537 ;; be frobnicated, and CONT will be set non-nil so we don't
538 ;; do it below.
539 (and buffer-file-name
541 ;; First check only tables already in buffers.
542 (tags-table-including buffer-file-name t)
543 ;; Since that didn't find any, now do the
544 ;; expensive version: reading new files.
545 (tags-table-including buffer-file-name nil)))
546 ;; Fourth, use the user variable tags-file-name, if it is
547 ;; not already in the current list.
548 (and tags-file-name
549 (not (tags-table-list-member tags-file-name
550 tags-table-computed-list))
551 tags-file-name)
552 ;; Fifth, use the user variable giving the table list.
553 ;; Find the first element of the list that actually exists.
554 (let ((list tags-table-list)
555 file)
556 (while (and list
557 (setq file (tags-expand-table-name (car list)))
558 (not (get-file-buffer file))
559 (not (file-exists-p file)))
560 (setq list (cdr list)))
561 (car list))
562 ;; Finally, prompt the user for a file name.
563 (expand-file-name
564 (read-file-name "Visit tags table: (default TAGS) "
565 default-directory
566 "TAGS"
567 t))))))
569 ;; Expand the table name into a full file name.
570 (setq tags-file-name (tags-expand-table-name tags-file-name))
572 (unless (and (eq cont t) (null tags-table-list-pointer))
573 ;; Verify that tags-file-name names a valid tags table.
574 ;; Bind another variable with the value of tags-file-name
575 ;; before we switch buffers, in case tags-file-name is buffer-local.
576 (let ((curbuf (current-buffer))
577 (local-tags-file-name tags-file-name))
578 (if (tags-verify-table local-tags-file-name)
580 ;; We have a valid tags table.
581 (progn
582 ;; Bury the tags table buffer so it
583 ;; doesn't get in the user's way.
584 (bury-buffer (current-buffer))
586 ;; If this was a new table selection (CONT is nil), make
587 ;; sure tags-table-list includes the chosen table, and
588 ;; update the list pointer variables.
589 (or cont
590 ;; Look in the list for the table we chose.
591 (let ((found (tags-table-list-member
592 local-tags-file-name
593 tags-table-computed-list)))
594 (if found
595 ;; There it is. Just switch to it.
596 (setq tags-table-list-pointer found
597 tags-table-list-started-at found)
599 ;; The table is not in the current set.
600 ;; Try to find it in another previously used set.
601 (let ((sets tags-table-set-list))
602 (while (and sets
603 (not (tags-table-list-member
604 local-tags-file-name
605 (car sets))))
606 (setq sets (cdr sets)))
607 (if sets
608 ;; Found in some other set. Switch to that set.
609 (progn
610 (or (memq tags-table-list tags-table-set-list)
611 ;; Save the current list.
612 (setq tags-table-set-list
613 (cons tags-table-list
614 tags-table-set-list)))
615 (setq tags-table-list (car sets)))
617 ;; Not found in any existing set.
618 (if (and tags-table-list
619 (or (eq t tags-add-tables)
620 (and tags-add-tables
621 (y-or-n-p
622 (concat "Keep current list of "
623 "tags tables also? ")))))
624 ;; Add it to the current list.
625 (setq tags-table-list (cons local-tags-file-name
626 tags-table-list))
628 ;; Make a fresh list, and store the old one.
629 (message "Starting a new list of tags tables")
630 (or (null tags-table-list)
631 (memq tags-table-list tags-table-set-list)
632 (setq tags-table-set-list
633 (cons tags-table-list
634 tags-table-set-list)))
635 ;; Clear out buffers holding old tables.
636 (dolist (table tags-table-list)
637 ;; The list can contain items `t'.
638 (if (stringp table)
639 (let ((buffer (find-buffer-visiting table)))
640 (if buffer
641 (kill-buffer buffer)))))
642 (setq tags-table-list (list local-tags-file-name))))
644 ;; Recompute tags-table-computed-list.
645 (tags-table-check-computed-list)
646 ;; Set the tags table list state variables to start
647 ;; over from tags-table-computed-list.
648 (setq tags-table-list-started-at tags-table-computed-list
649 tags-table-list-pointer
650 tags-table-computed-list)))))
652 ;; Return of t says the tags table is valid.
655 ;; The buffer was not valid. Don't use it again.
656 (set-buffer curbuf)
657 (kill-local-variable 'tags-file-name)
658 (if (eq local-tags-file-name tags-file-name)
659 (setq tags-file-name nil))
660 (error "File %s is not a valid tags table" local-tags-file-name)))))
662 (defun tags-reset-tags-tables ()
663 "Reset tags state to cancel effect of any previous \\[visit-tags-table] or \\[find-tag]."
664 (interactive)
665 ;; Clear out the markers we are throwing away.
666 (let ((i 0))
667 (while (< i find-tag-marker-ring-length)
668 (if (aref (cddr tags-location-ring) i)
669 (set-marker (aref (cddr tags-location-ring) i) nil))
670 (if (aref (cddr find-tag-marker-ring) i)
671 (set-marker (aref (cddr find-tag-marker-ring) i) nil))
672 (setq i (1+ i))))
673 (setq tags-file-name nil
674 tags-location-ring (make-ring find-tag-marker-ring-length)
675 find-tag-marker-ring (make-ring find-tag-marker-ring-length)
676 tags-table-list nil
677 tags-table-computed-list nil
678 tags-table-computed-list-for nil
679 tags-table-list-pointer nil
680 tags-table-list-started-at nil
681 tags-table-set-list nil))
683 (defun file-of-tag ()
684 "Return the file name of the file whose tags point is within.
685 Assumes the tags table is the current buffer.
686 File name returned is relative to tags table file's directory."
687 (funcall file-of-tag-function))
689 ;;;###autoload
690 (defun tags-table-files ()
691 "Return a list of files in the current tags table.
692 Assumes the tags table is the current buffer. The file names are returned
693 as they appeared in the `etags' command that created the table, usually
694 without directory names."
695 (or tags-table-files
696 (setq tags-table-files
697 (funcall tags-table-files-function))))
699 (defun tags-included-tables ()
700 "Return a list of tags tables included by the current table.
701 Assumes the tags table is the current buffer."
702 (or tags-included-tables
703 (setq tags-included-tables (funcall tags-included-tables-function))))
705 ;; Build tags-completion-table on demand. The single current tags table
706 ;; and its included tags tables (and their included tables, etc.) have
707 ;; their tags included in the completion table.
708 (defun tags-completion-table ()
709 (or tags-completion-table
710 (condition-case ()
711 (prog2
712 (message "Making tags completion table for %s..." buffer-file-name)
713 (let ((included (tags-included-tables))
714 (table (funcall tags-completion-table-function)))
715 (save-excursion
716 ;; Iterate over the list of included tables, and combine each
717 ;; included table's completion obarray to the parent obarray.
718 (while included
719 ;; Visit the buffer.
720 (let ((tags-file-name (car included)))
721 (visit-tags-table-buffer 'same))
722 ;; Recurse in that buffer to compute its completion table.
723 (if (tags-completion-table)
724 ;; Combine the tables.
725 (mapatoms (lambda (sym) (intern (symbol-name sym) table))
726 tags-completion-table))
727 (setq included (cdr included))))
728 (setq tags-completion-table table))
729 (message "Making tags completion table for %s...done"
730 buffer-file-name))
731 (quit (message "Tags completion table construction aborted.")
732 (setq tags-completion-table nil)))))
734 ;; Completion function for tags. Does normal try-completion,
735 ;; but builds tags-completion-table on demand.
736 (defun tags-complete-tag (string predicate what)
737 (save-excursion
738 ;; If we need to ask for the tag table, allow that.
739 (let ((enable-recursive-minibuffers t))
740 (visit-tags-table-buffer))
741 (if (eq what t)
742 (all-completions string (tags-completion-table) predicate)
743 (try-completion string (tags-completion-table) predicate))))
745 ;; Return a default tag to search for, based on the text at point.
746 (defun find-tag-default ()
747 (save-excursion
748 (while (looking-at "\\sw\\|\\s_")
749 (forward-char 1))
750 (if (or (re-search-backward "\\sw\\|\\s_"
751 (save-excursion (beginning-of-line) (point))
753 (re-search-forward "\\(\\sw\\|\\s_\\)+"
754 (save-excursion (end-of-line) (point))
756 (progn (goto-char (match-end 0))
757 (buffer-substring (point)
758 (progn (forward-sexp -1)
759 (while (looking-at "\\s'")
760 (forward-char 1))
761 (point))))
762 nil)))
764 ;; Read a tag name from the minibuffer with defaulting and completion.
765 (defun find-tag-tag (string)
766 (let* ((default (funcall (or find-tag-default-function
767 (get major-mode 'find-tag-default-function)
768 'find-tag-default)))
769 (spec (completing-read (if default
770 (format "%s(default %s) " string default)
771 string)
772 'tags-complete-tag
773 nil nil nil nil default)))
774 (if (equal spec "")
775 (or default (error "There is no default tag"))
776 spec)))
778 (defvar last-tag nil
779 "Last tag found by \\[find-tag].")
781 ;; Get interactive args for find-tag{-noselect,-other-window,-regexp}.
782 (defun find-tag-interactive (prompt &optional no-default)
783 (if current-prefix-arg
784 (list nil (if (< (prefix-numeric-value current-prefix-arg) 0)
787 (list (if no-default
788 (read-string prompt)
789 (find-tag-tag prompt)))))
791 (defvar find-tag-history nil)
793 ;; Dynamic bondage:
794 (eval-when-compile
795 (defvar etags-case-fold-search)
796 (defvar etags-syntax-table))
798 ;;;###autoload
799 (defun find-tag-noselect (tagname &optional next-p regexp-p)
800 "Find tag (in current tags table) whose name contains TAGNAME.
801 Returns the buffer containing the tag's definition and moves its point there,
802 but does not select the buffer.
803 The default for TAGNAME is the expression in the buffer near point.
805 If second arg NEXT-P is t (interactively, with prefix arg), search for
806 another tag that matches the last tagname or regexp used. When there are
807 multiple matches for a tag, more exact matches are found first. If NEXT-P
808 is the atom `-' (interactively, with prefix arg that is a negative number
809 or just \\[negative-argument]), pop back to the previous tag gone to.
811 If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp.
813 A marker representing the point when this command is onvoked is pushed
814 onto a ring and may be popped back to with \\[pop-tag-mark].
815 Contrast this with the ring of marks gone to by the command.
817 See documentation of variable `tags-file-name'."
818 (interactive (find-tag-interactive "Find tag: "))
820 (setq find-tag-history (cons tagname find-tag-history))
821 ;; Save the current buffer's value of `find-tag-hook' before selecting the
822 ;; tags table buffer.
823 (let ((local-find-tag-hook find-tag-hook))
824 (if (eq '- next-p)
825 ;; Pop back to a previous location.
826 (if (ring-empty-p tags-location-ring)
827 (error "No previous tag locations")
828 (let ((marker (ring-remove tags-location-ring 0)))
829 (prog1
830 ;; Move to the saved location.
831 (set-buffer (or (marker-buffer marker)
832 (error "The marked buffer has been deleted")))
833 (goto-char (marker-position marker))
834 ;; Kill that marker so it doesn't slow down editing.
835 (set-marker marker nil nil)
836 ;; Run the user's hook. Do we really want to do this for pop?
837 (run-hooks 'local-find-tag-hook))))
838 ;; Record whence we came.
839 (ring-insert find-tag-marker-ring (point-marker))
840 (if next-p
841 ;; Find the same table we last used.
842 (visit-tags-table-buffer 'same)
843 ;; Pick a table to use.
844 (visit-tags-table-buffer)
845 ;; Record TAGNAME for a future call with NEXT-P non-nil.
846 (setq last-tag tagname))
847 ;; Record the location so we can pop back to it later.
848 (let ((marker (make-marker)))
849 (save-excursion
850 (set-buffer
851 ;; find-tag-in-order does the real work.
852 (find-tag-in-order
853 (if next-p last-tag tagname)
854 (if regexp-p
855 find-tag-regexp-search-function
856 find-tag-search-function)
857 (if regexp-p
858 find-tag-regexp-tag-order
859 find-tag-tag-order)
860 (if regexp-p
861 find-tag-regexp-next-line-after-failure-p
862 find-tag-next-line-after-failure-p)
863 (if regexp-p "matching" "containing")
864 (not next-p)))
865 (set-marker marker (point))
866 (run-hooks 'local-find-tag-hook)
867 (ring-insert tags-location-ring marker)
868 (current-buffer))))))
870 ;;;###autoload
871 (defun find-tag (tagname &optional next-p regexp-p)
872 "Find tag (in current tags table) whose name contains TAGNAME.
873 Select the buffer containing the tag's definition, and move point there.
874 The default for TAGNAME is the expression in the buffer around or before point.
876 If second arg NEXT-P is t (interactively, with prefix arg), search for
877 another tag that matches the last tagname or regexp used. When there are
878 multiple matches for a tag, more exact matches are found first. If NEXT-P
879 is the atom `-' (interactively, with prefix arg that is a negative number
880 or just \\[negative-argument]), pop back to the previous tag gone to.
882 If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp.
884 A marker representing the point when this command is onvoked is pushed
885 onto a ring and may be popped back to with \\[pop-tag-mark].
886 Contrast this with the ring of marks gone to by the command.
888 See documentation of variable `tags-file-name'."
889 (interactive (find-tag-interactive "Find tag: "))
890 (let ((buf (find-tag-noselect tagname next-p regexp-p)))
891 (condition-case nil
892 (switch-to-buffer buf)
893 (error (pop-to-buffer buf)))))
894 ;;;###autoload (define-key esc-map "." 'find-tag)
896 ;;;###autoload
897 (defun find-tag-other-window (tagname &optional next-p regexp-p)
898 "Find tag (in current tags table) whose name contains TAGNAME.
899 Select the buffer containing the tag's definition in another window, and
900 move point there. The default for TAGNAME is the expression in the buffer
901 around or before point.
903 If second arg NEXT-P is t (interactively, with prefix arg), search for
904 another tag that matches the last tagname or regexp used. When there are
905 multiple matches for a tag, more exact matches are found first. If NEXT-P
906 is negative (interactively, with prefix arg that is a negative number or
907 just \\[negative-argument]), pop back to the previous tag gone to.
909 If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp.
911 A marker representing the point when this command is onvoked is pushed
912 onto a ring and may be popped back to with \\[pop-tag-mark].
913 Contrast this with the ring of marks gone to by the command.
915 See documentation of variable `tags-file-name'."
916 (interactive (find-tag-interactive "Find tag other window: "))
918 ;; This hair is to deal with the case where the tag is found in the
919 ;; selected window's buffer; without the hair, point is moved in both
920 ;; windows. To prevent this, we save the selected window's point before
921 ;; doing find-tag-noselect, and restore it after.
922 (let* ((window-point (window-point (selected-window)))
923 (tagbuf (find-tag-noselect tagname next-p regexp-p))
924 (tagpoint (progn (set-buffer tagbuf) (point))))
925 (set-window-point (prog1
926 (selected-window)
927 (switch-to-buffer-other-window tagbuf)
928 ;; We have to set this new window's point; it
929 ;; might already have been displaying a
930 ;; different portion of tagbuf, in which case
931 ;; switch-to-buffer-other-window doesn't set
932 ;; the window's point from the buffer.
933 (set-window-point (selected-window) tagpoint))
934 window-point)))
935 ;;;###autoload (define-key ctl-x-4-map "." 'find-tag-other-window)
937 ;;;###autoload
938 (defun find-tag-other-frame (tagname &optional next-p)
939 "Find tag (in current tags table) whose name contains TAGNAME.
940 Select the buffer containing the tag's definition in another frame, and
941 move point there. The default for TAGNAME is the expression in the buffer
942 around or before point.
944 If second arg NEXT-P is t (interactively, with prefix arg), search for
945 another tag that matches the last tagname or regexp used. When there are
946 multiple matches for a tag, more exact matches are found first. If NEXT-P
947 is negative (interactively, with prefix arg that is a negative number or
948 just \\[negative-argument]), pop back to the previous tag gone to.
950 If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp.
952 A marker representing the point when this command is onvoked is pushed
953 onto a ring and may be popped back to with \\[pop-tag-mark].
954 Contrast this with the ring of marks gone to by the command.
956 See documentation of variable `tags-file-name'."
957 (interactive (find-tag-interactive "Find tag other frame: "))
958 (let ((pop-up-frames t))
959 (find-tag-other-window tagname next-p)))
960 ;;;###autoload (define-key ctl-x-5-map "." 'find-tag-other-frame)
962 ;;;###autoload
963 (defun find-tag-regexp (regexp &optional next-p other-window)
964 "Find tag (in current tags table) whose name matches REGEXP.
965 Select the buffer containing the tag's definition and move point there.
967 If second arg NEXT-P is t (interactively, with prefix arg), search for
968 another tag that matches the last tagname or regexp used. When there are
969 multiple matches for a tag, more exact matches are found first. If NEXT-P
970 is negative (interactively, with prefix arg that is a negative number or
971 just \\[negative-argument]), pop back to the previous tag gone to.
973 If third arg OTHER-WINDOW is non-nil, select the buffer in another window.
975 A marker representing the point when this command is onvoked is pushed
976 onto a ring and may be popped back to with \\[pop-tag-mark].
977 Contrast this with the ring of marks gone to by the command.
979 See documentation of variable `tags-file-name'."
980 (interactive (find-tag-interactive "Find tag regexp: " t))
981 ;; We go through find-tag-other-window to do all the display hair there.
982 (funcall (if other-window 'find-tag-other-window 'find-tag)
983 regexp next-p t))
984 ;;;###autoload (define-key esc-map [?\C-.] 'find-tag-regexp)
986 ;;;###autoload (define-key esc-map "*" 'pop-tag-mark)
988 ;;;###autoload
989 (defun pop-tag-mark ()
990 "Pop back to where \\[find-tag] was last invoked.
992 This is distinct from invoking \\[find-tag] with a negative argument
993 since that pops a stack of markers at which tags were found, not from
994 where they were found."
995 (interactive)
996 (if (ring-empty-p find-tag-marker-ring)
997 (error "No previous locations for find-tag invocation"))
998 (let ((marker (ring-remove find-tag-marker-ring 0)))
999 (switch-to-buffer (or (marker-buffer marker)
1000 (error "The marked buffer has been deleted")))
1001 (goto-char (marker-position marker))
1002 (set-marker marker nil nil)))
1004 ;; Internal tag finding function.
1006 ;; PATTERN is a string to pass to second arg SEARCH-FORWARD-FUNC, and to
1007 ;; any member of the function list ORDER (third arg). If ORDER is nil,
1008 ;; use saved state to continue a previous search.
1010 ;; Fourth arg MATCHING is a string, an English '-ing' word, to be used in
1011 ;; an error message.
1013 ;; Fifth arg NEXT-LINE-AFTER-FAILURE-P is non-nil if after a failed match,
1014 ;; point should be moved to the next line.
1016 ;; Algorithm is as follows. For each qualifier-func in ORDER, go to
1017 ;; beginning of tags file, and perform inner loop: for each naive match for
1018 ;; PATTERN found using SEARCH-FORWARD-FUNC, qualify the naive match using
1019 ;; qualifier-func. If it qualifies, go to the specified line in the
1020 ;; specified source file and return. Qualified matches are remembered to
1021 ;; avoid repetition. State is saved so that the loop can be continued.
1023 (defvar tag-lines-already-matched nil) ;matches remembered here between calls
1025 (defun find-tag-in-order (pattern
1026 search-forward-func
1027 order
1028 next-line-after-failure-p
1029 matching
1030 first-search)
1031 (let (file ;name of file containing tag
1032 tag-info ;where to find the tag in FILE
1033 (first-table t)
1034 (tag-order order)
1035 (match-marker (make-marker))
1036 goto-func
1037 (case-fold-search (if (memq tags-case-fold-search '(nil t))
1038 tags-case-fold-search
1039 case-fold-search))
1041 (save-excursion
1043 (if first-search
1044 ;; This is the start of a search for a fresh tag.
1045 ;; Clear the list of tags matched by the previous search.
1046 ;; find-tag-noselect has already put us in the first tags table
1047 ;; buffer before we got called.
1048 (setq tag-lines-already-matched nil)
1049 ;; Continuing to search for the tag specified last time.
1050 ;; tag-lines-already-matched lists locations matched in previous
1051 ;; calls so we don't visit the same tag twice if it matches twice
1052 ;; during two passes with different qualification predicates.
1053 ;; Switch to the current tags table buffer.
1054 (visit-tags-table-buffer 'same))
1056 ;; Get a qualified match.
1057 (catch 'qualified-match-found
1059 ;; Iterate over the list of tags tables.
1060 (while (or first-table
1061 (visit-tags-table-buffer t))
1063 (and first-search first-table
1064 ;; Start at beginning of tags file.
1065 (goto-char (point-min)))
1067 (setq first-table nil)
1069 ;; Iterate over the list of ordering predicates.
1070 (while order
1071 (while (funcall search-forward-func pattern nil t)
1072 ;; Naive match found. Qualify the match.
1073 (and (funcall (car order) pattern)
1074 ;; Make sure it is not a previous qualified match.
1075 (not (member (set-marker match-marker (save-excursion
1076 (beginning-of-line)
1077 (point)))
1078 tag-lines-already-matched))
1079 (throw 'qualified-match-found nil))
1080 (if next-line-after-failure-p
1081 (forward-line 1)))
1082 ;; Try the next flavor of match.
1083 (setq order (cdr order))
1084 (goto-char (point-min)))
1085 (setq order tag-order))
1086 ;; We throw out on match, so only get here if there were no matches.
1087 ;; Clear out the markers we use to avoid duplicate matches so they
1088 ;; don't slow down editting and are immediately available for GC.
1089 (while tag-lines-already-matched
1090 (set-marker (car tag-lines-already-matched) nil nil)
1091 (setq tag-lines-already-matched (cdr tag-lines-already-matched)))
1092 (set-marker match-marker nil nil)
1093 (error "No %stags %s %s" (if first-search "" "more ")
1094 matching pattern))
1096 ;; Found a tag; extract location info.
1097 (beginning-of-line)
1098 (setq tag-lines-already-matched (cons match-marker
1099 tag-lines-already-matched))
1100 ;; Expand the filename, using the tags table buffer's default-directory.
1101 (setq file (expand-file-name (file-of-tag))
1102 tag-info (funcall snarf-tag-function))
1104 ;; Get the local value in the tags table buffer before switching buffers.
1105 (setq goto-func goto-tag-location-function)
1107 ;; Find the right line in the specified file.
1108 (set-buffer (find-file-noselect file))
1109 (widen)
1110 (push-mark)
1111 (funcall goto-func tag-info)
1113 ;; Return the buffer where the tag was found.
1114 (current-buffer))))
1116 ;; `etags' TAGS file format support.
1118 ;; If the current buffer is a valid etags TAGS file, give it local values of
1119 ;; the tags table format variables, and return non-nil.
1120 (defun etags-recognize-tags-table ()
1121 (and (etags-verify-tags-table)
1122 ;; It is annoying to flash messages on the screen briefly,
1123 ;; and this message is not useful. -- rms
1124 ;; (message "%s is an `etags' TAGS file" buffer-file-name)
1125 (mapc (lambda (elt) (set (make-local-variable (car elt)) (cdr elt)))
1126 '((file-of-tag-function . etags-file-of-tag)
1127 (tags-table-files-function . etags-tags-table-files)
1128 (tags-completion-table-function . etags-tags-completion-table)
1129 (snarf-tag-function . etags-snarf-tag)
1130 (goto-tag-location-function . etags-goto-tag-location)
1131 (find-tag-regexp-search-function . re-search-forward)
1132 (find-tag-regexp-tag-order . (tag-re-match-p))
1133 (find-tag-regexp-next-line-after-failure-p . t)
1134 (find-tag-search-function . search-forward)
1135 (find-tag-tag-order . (tag-exact-file-name-match-p
1136 tag-exact-match-p
1137 tag-symbol-match-p
1138 tag-word-match-p
1139 tag-any-match-p))
1140 (find-tag-next-line-after-failure-p . nil)
1141 (list-tags-function . etags-list-tags)
1142 (tags-apropos-function . etags-tags-apropos)
1143 (tags-included-tables-function . etags-tags-included-tables)
1144 (verify-tags-table-function . etags-verify-tags-table)
1145 ))))
1147 ;; Return non-nil iff the current buffer is a valid etags TAGS file.
1148 (defun etags-verify-tags-table ()
1149 ;; Use eq instead of = in case char-after returns nil.
1150 (eq (char-after 1) ?\f))
1152 (defun etags-file-of-tag ()
1153 (save-excursion
1154 (re-search-backward "\f\n\\([^\n]+\\),[0-9]*\n")
1155 (expand-file-name (buffer-substring (match-beginning 1) (match-end 1))
1156 (file-truename default-directory))))
1159 (defun etags-tags-completion-table ()
1160 (let ((table (make-vector 511 0)))
1161 (save-excursion
1162 (goto-char (point-min))
1163 ;; This monster regexp matches an etags tag line.
1164 ;; \1 is the string to match;
1165 ;; \2 is not interesting;
1166 ;; \3 is the guessed tag name; XXX guess should be better eg DEFUN
1167 ;; \4 is not interesting;
1168 ;; \5 is the explicitly-specified tag name.
1169 ;; \6 is the line to start searching at;
1170 ;; \7 is the char to start searching at.
1171 (while (re-search-forward
1172 "^\\(\\([^\177]+[^-a-zA-Z0-9_+*$:\177]+\\)?\
1173 \\([-a-zA-Z0-9_+*$?:]+\\)[^-a-zA-Z0-9_+*$?:\177]*\\)\177\
1174 \\(\\([^\n\001]+\\)\001\\)?\\([0-9]+\\)?,\\([0-9]+\\)?\n"
1175 nil t)
1176 (intern (if (match-beginning 5)
1177 ;; There is an explicit tag name.
1178 (buffer-substring (match-beginning 5) (match-end 5))
1179 ;; No explicit tag name. Best guess.
1180 (buffer-substring (match-beginning 3) (match-end 3)))
1181 table)))
1182 table))
1184 (defun etags-snarf-tag ()
1185 (let (tag-text line startpos)
1186 (if (save-excursion
1187 (forward-line -1)
1188 (looking-at "\f\n"))
1189 ;; The match was for a source file name, not any tag within a file.
1190 ;; Give text of t, meaning to go exactly to the location we specify,
1191 ;; the beginning of the file.
1192 (setq tag-text t
1193 line nil
1194 startpos 1)
1196 ;; Find the end of the tag and record the whole tag text.
1197 (search-forward "\177")
1198 (setq tag-text (buffer-substring (1- (point))
1199 (save-excursion (beginning-of-line)
1200 (point))))
1201 ;; Skip explicit tag name if present.
1202 (search-forward "\001" (save-excursion (forward-line 1) (point)) t)
1203 (if (looking-at "[0-9]")
1204 (setq line (string-to-int (buffer-substring
1205 (point)
1206 (progn (skip-chars-forward "0-9")
1207 (point))))))
1208 (search-forward ",")
1209 (if (looking-at "[0-9]")
1210 (setq startpos (string-to-int (buffer-substring
1211 (point)
1212 (progn (skip-chars-forward "0-9")
1213 (point)))))))
1214 ;; Leave point on the next line of the tags file.
1215 (forward-line 1)
1216 (cons tag-text (cons line startpos))))
1218 ;; TAG-INFO is a cons (TEXT LINE . POSITION) where TEXT is the initial part
1219 ;; of a line containing the tag and POSITION is the character position of
1220 ;; TEXT within the file (starting from 1); LINE is the line number. If
1221 ;; TEXT is t, it means the tag refers to exactly LINE or POSITION
1222 ;; (whichever is present, LINE having preference, no searching. Either
1223 ;; LINE or POSITION may be nil; POSITION is used if present. If the tag
1224 ;; isn't exactly at the given position then look around that position using
1225 ;; a search window which expands until it hits the start of file.
1226 (defun etags-goto-tag-location (tag-info)
1227 (let ((startpos (cdr (cdr tag-info)))
1228 (line (car (cdr tag-info)))
1229 offset found pat)
1230 (if (eq (car tag-info) t)
1231 ;; Direct file tag.
1232 (cond (line (goto-line line))
1233 (startpos (goto-char startpos))
1234 (t (error "etags.el BUG: bogus direct file tag")))
1235 ;; This constant is 1/2 the initial search window.
1236 ;; There is no sense in making it too small,
1237 ;; since just going around the loop once probably
1238 ;; costs about as much as searching 2000 chars.
1239 (setq offset 1000
1240 found nil
1241 pat (concat (if (eq selective-display t)
1242 "\\(^\\|\^m\\)" "^")
1243 (regexp-quote (car tag-info))))
1244 ;; The character position in the tags table is 0-origin.
1245 ;; Convert it to a 1-origin Emacs character position.
1246 (if startpos (setq startpos (1+ startpos)))
1247 ;; If no char pos was given, try the given line number.
1248 (or startpos
1249 (if line
1250 (setq startpos (progn (goto-line line)
1251 (point)))))
1252 (or startpos
1253 (setq startpos (point-min)))
1254 ;; First see if the tag is right at the specified location.
1255 (goto-char startpos)
1256 (setq found (looking-at pat))
1257 (while (and (not found)
1258 (progn
1259 (goto-char (- startpos offset))
1260 (not (bobp))))
1261 (setq found
1262 (re-search-forward pat (+ startpos offset) t)
1263 offset (* 3 offset))) ; expand search window
1264 (or found
1265 (re-search-forward pat nil t)
1266 (error "Rerun etags: `%s' not found in %s"
1267 pat buffer-file-name)))
1268 ;; Position point at the right place
1269 ;; if the search string matched an extra Ctrl-m at the beginning.
1270 (and (eq selective-display t)
1271 (looking-at "\^m")
1272 (forward-char 1))
1273 (beginning-of-line)))
1275 (defun etags-list-tags (file)
1276 (goto-char 1)
1277 (when (search-forward (concat "\f\n" file ",") nil t)
1278 (forward-line 1)
1279 (while (not (or (eobp) (looking-at "\f")))
1280 (let ((tag (buffer-substring (point)
1281 (progn (skip-chars-forward "^\177")
1282 (point))))
1283 (props `(action find-tag-other-window mouse-face highlight
1284 face ,tags-tag-face))
1285 (pt (with-current-buffer standard-output (point))))
1286 (when (looking-at "[^\n]+\001")
1287 ;; There is an explicit tag name; use that.
1288 (setq tag (buffer-substring (1+ (point)) ; skip \177
1289 (progn (skip-chars-forward "^\001")
1290 (point)))))
1291 (princ tag)
1292 (when (= (aref tag 0) ?\() (princ " ...)"))
1293 (add-text-properties pt (with-current-buffer standard-output (point))
1294 (cons 'item (cons tag props)) standard-output))
1295 (terpri)
1296 (forward-line 1))
1299 (defmacro tags-with-face (face &rest body)
1300 "Execute BODY, give output to `standard-output' face FACE."
1301 (let ((pp (gensym "twf-")))
1302 `(let ((,pp (with-current-buffer standard-output (point))))
1303 ,@body
1304 (put-text-property ,pp (with-current-buffer standard-output (point))
1305 'face ,face standard-output))))
1307 (defun etags-tags-apropos-additional (regexp)
1308 "Display tags matching REGEXP from `tags-apropos-additional-actions'."
1309 (with-current-buffer standard-output
1310 (dolist (oba tags-apropos-additional-actions)
1311 (princ "\n\n")
1312 (tags-with-face 'highlight (princ (car oba)))
1313 (princ":\n\n")
1314 (let* ((props `(action ,(cadr oba) mouse-face highlight face
1315 ,tags-tag-face))
1316 (beg (point))
1317 (symbs (car (cddr oba)))
1318 (ins-symb (lambda (sy)
1319 (let ((sn (symbol-name sy)))
1320 (when (string-match regexp sn)
1321 (add-text-properties (point)
1322 (progn (princ sy) (point))
1323 (cons 'item (cons sn props)))
1324 (terpri))))))
1325 (when (symbolp symbs)
1326 (if (boundp symbs)
1327 (setq symbs (symbol-value symbs))
1328 (insert "symbol `" (symbol-name symbs) "' has no value\n")
1329 (setq symbs nil)))
1330 (if (vectorp symbs)
1331 (mapatoms ins-symb symbs)
1332 (dolist (sy symbs)
1333 (funcall ins-symb (car sy))))
1334 (sort-lines nil beg (point))))))
1336 (defun etags-tags-apropos (string)
1337 (when tags-apropos-verbose
1338 (princ "Tags in file `")
1339 (tags-with-face 'highlight (princ buffer-file-name))
1340 (princ "':\n\n"))
1341 (goto-char 1)
1342 (while (re-search-forward string nil t)
1343 (beginning-of-line)
1344 (let ((tag (buffer-substring (point)
1345 (progn (skip-chars-forward "^\177")
1346 (point))))
1347 (props `(action find-tag-other-window mouse-face highlight
1348 face ,tags-tag-face))
1349 (pt (with-current-buffer standard-output (point))))
1350 (princ tag)
1351 (when (= (aref tag 0) ?\() (princ " ...)"))
1352 (add-text-properties pt (with-current-buffer standard-output (point))
1353 `(item ,tag ,@props) standard-output))
1354 (terpri)
1355 (forward-line 1))
1356 (when tags-apropos-verbose (princ "\n")))
1358 (defun etags-tags-table-files ()
1359 (let ((files nil)
1360 beg)
1361 (goto-char (point-min))
1362 (while (search-forward "\f\n" nil t)
1363 (setq beg (point))
1364 (end-of-line)
1365 (skip-chars-backward "^," beg)
1366 (or (looking-at "include$")
1367 (setq files (cons (buffer-substring beg (1- (point))) files))))
1368 (nreverse files)))
1370 (defun etags-tags-included-tables ()
1371 (let ((files nil)
1372 beg)
1373 (goto-char (point-min))
1374 (while (search-forward "\f\n" nil t)
1375 (setq beg (point))
1376 (end-of-line)
1377 (skip-chars-backward "^," beg)
1378 (if (looking-at "include$")
1379 ;; Expand in the default-directory of the tags table buffer.
1380 (setq files (cons (expand-file-name (buffer-substring beg (1- (point))))
1381 files))))
1382 (nreverse files)))
1384 ;; Empty tags file support.
1386 ;; Recognize an empty file and give it local values of the tags table format
1387 ;; variables which do nothing.
1388 (defun tags-recognize-empty-tags-table ()
1389 (and (zerop (buffer-size))
1390 (mapc (lambda (sym) (set (make-local-variable sym) 'ignore))
1391 '(tags-table-files-function
1392 tags-completion-table-function
1393 find-tag-regexp-search-function
1394 find-tag-search-function
1395 tags-apropos-function
1396 tags-included-tables-function))
1397 (set (make-local-variable 'verify-tags-table-function)
1398 (lambda () (zerop (buffer-size))))))
1400 ;; Match qualifier functions for tagnames.
1401 ;; XXX these functions assume etags file format.
1403 ;; This might be a neat idea, but it's too hairy at the moment.
1404 ;;(defmacro tags-with-syntax (&rest body)
1405 ;; `(let ((current (current-buffer))
1406 ;; (otable (syntax-table))
1407 ;; (buffer (find-file-noselect (file-of-tag)))
1408 ;; table)
1409 ;; (unwind-protect
1410 ;; (progn
1411 ;; (set-buffer buffer)
1412 ;; (setq table (syntax-table))
1413 ;; (set-buffer current)
1414 ;; (set-syntax-table table)
1415 ;; ,@body)
1416 ;; (set-syntax-table otable))))
1417 ;;(put 'tags-with-syntax 'edebug-form-spec '(&rest form))
1419 ;; t if point is at a tag line that matches TAG exactly.
1420 ;; point should be just after a string that matches TAG.
1421 (defun tag-exact-match-p (tag)
1422 ;; The match is really exact if there is an explicit tag name.
1423 (or (and (eq (char-after (point)) ?\001)
1424 (eq (char-after (- (point) (length tag) 1)) ?\177))
1425 ;; We are not on the explicit tag name, but perhaps it follows.
1426 (looking-at (concat "[^\177\n]*\177" (regexp-quote tag) "\001"))))
1428 ;; t if point is at a tag line that matches TAG as a symbol.
1429 ;; point should be just after a string that matches TAG.
1430 (defun tag-symbol-match-p (tag)
1431 (and (looking-at "\\Sw.*\177") (looking-at "\\S_.*\177")
1432 (save-excursion
1433 (backward-char (1+ (length tag)))
1434 (and (looking-at "\\Sw") (looking-at "\\S_")))))
1436 ;; t if point is at a tag line that matches TAG as a word.
1437 ;; point should be just after a string that matches TAG.
1438 (defun tag-word-match-p (tag)
1439 (and (looking-at "\\b.*\177")
1440 (save-excursion (backward-char (length tag))
1441 (looking-at "\\b"))))
1443 (defun tag-exact-file-name-match-p (tag)
1444 (and (looking-at ",")
1445 (save-excursion (backward-char (length tag))
1446 (looking-at "\f\n"))))
1448 ;; t if point is in a tag line with a tag containing TAG as a substring.
1449 (defun tag-any-match-p (tag)
1450 (looking-at ".*\177"))
1452 ;; t if point is at a tag line that matches RE as a regexp.
1453 (defun tag-re-match-p (re)
1454 (save-excursion
1455 (beginning-of-line)
1456 (let ((bol (point)))
1457 (and (search-forward "\177" (save-excursion (end-of-line) (point)) t)
1458 (re-search-backward re bol t)))))
1460 (defcustom tags-loop-revert-buffers nil
1461 "*Non-nil means tags-scanning loops should offer to reread changed files.
1462 These loops normally read each file into Emacs, but when a file
1463 is already visited, they use the existing buffer.
1464 When this flag is non-nil, they offer to revert the existing buffer
1465 in the case where the file has changed since you visited it."
1466 :type 'boolean
1467 :group 'etags)
1469 ;;;###autoload
1470 (defun next-file (&optional initialize novisit)
1471 "Select next file among files in current tags table.
1473 A first argument of t (prefix arg, if interactive) initializes to the
1474 beginning of the list of files in the tags table. If the argument is
1475 neither nil nor t, it is evalled to initialize the list of files.
1477 Non-nil second argument NOVISIT means use a temporary buffer
1478 to save time and avoid uninteresting warnings.
1480 Value is nil if the file was already visited;
1481 if the file was newly read in, the value is the filename."
1482 ;; Make the interactive arg t if there was any prefix arg.
1483 (interactive (list (if current-prefix-arg t)))
1484 (cond ((not initialize)
1485 ;; Not the first run.
1487 ((eq initialize t)
1488 ;; Initialize the list from the tags table.
1489 (save-excursion
1490 ;; Visit the tags table buffer to get its list of files.
1491 (visit-tags-table-buffer)
1492 ;; Copy the list so we can setcdr below, and expand the file
1493 ;; names while we are at it, in this buffer's default directory.
1494 (setq next-file-list (mapcar 'expand-file-name (tags-table-files)))
1495 ;; Iterate over all the tags table files, collecting
1496 ;; a complete list of referenced file names.
1497 (while (visit-tags-table-buffer t)
1498 ;; Find the tail of the working list and chain on the new
1499 ;; sublist for this tags table.
1500 (let ((tail next-file-list))
1501 (while (cdr tail)
1502 (setq tail (cdr tail)))
1503 ;; Use a copy so the next loop iteration will not modify the
1504 ;; list later returned by (tags-table-files).
1505 (if tail
1506 (setcdr tail (mapcar 'expand-file-name (tags-table-files)))
1507 (setq next-file-list (mapcar 'expand-file-name
1508 (tags-table-files))))))))
1510 ;; Initialize the list by evalling the argument.
1511 (setq next-file-list (eval initialize))))
1512 (unless next-file-list
1513 (and novisit
1514 (get-buffer " *next-file*")
1515 (kill-buffer " *next-file*"))
1516 (error "All files processed"))
1517 (let* ((next (car next-file-list))
1518 (buffer (get-file-buffer next))
1519 (new (not buffer)))
1520 ;; Advance the list before trying to find the file.
1521 ;; If we get an error finding the file, don't get stuck on it.
1522 (setq next-file-list (cdr next-file-list))
1523 ;; Optionally offer to revert buffers
1524 ;; if the files have changed on disk.
1525 (and buffer tags-loop-revert-buffers
1526 (not (verify-visited-file-modtime buffer))
1527 (with-current-buffer buffer
1528 (revert-buffer t)))
1529 (if (not (and new novisit))
1530 (set-buffer (find-file-noselect next novisit))
1531 ;; Like find-file, but avoids random warning messages.
1532 (set-buffer (get-buffer-create " *next-file*"))
1533 (kill-all-local-variables)
1534 (erase-buffer)
1535 (setq new next)
1536 (insert-file-contents new nil))
1537 new))
1539 (defvar tags-loop-operate nil
1540 "Form for `tags-loop-continue' to eval to change one file.")
1542 (defvar tags-loop-scan
1543 '(error "%s"
1544 (substitute-command-keys
1545 "No \\[tags-search] or \\[tags-query-replace] in progress"))
1546 "Form for `tags-loop-continue' to eval to scan one file.
1547 If it returns non-nil, this file needs processing by evalling
1548 \`tags-loop-operate'. Otherwise, move on to the next file.")
1550 (defun tags-loop-eval (form)
1551 "Evaluate FORM and return its result.
1552 Bind `case-fold-search' during the evaluation, depending on the value of
1553 `tags-case-fold-search'."
1554 (let ((case-fold-search (if (memq tags-case-fold-search '(t nil))
1555 tags-case-fold-search
1556 case-fold-search)))
1557 (eval form)))
1560 ;;;###autoload
1561 (defun tags-loop-continue (&optional first-time)
1562 "Continue last \\[tags-search] or \\[tags-query-replace] command.
1563 Used noninteractively with non-nil argument to begin such a command (the
1564 argument is passed to `next-file', which see).
1566 Two variables control the processing we do on each file: the value of
1567 `tags-loop-scan' is a form to be executed on each file to see if it is
1568 interesting (it returns non-nil if so) and `tags-loop-operate' is a form to
1569 evaluate to operate on an interesting file. If the latter evaluates to
1570 nil, we exit; otherwise we scan the next file."
1571 (interactive)
1572 (let (new
1573 ;; Non-nil means we have finished one file
1574 ;; and should not scan it again.
1575 file-finished
1576 (messaged nil))
1577 (while
1578 (progn
1579 ;; Scan files quickly for the first or next interesting one.
1580 (while (or first-time file-finished
1581 (save-restriction
1582 (widen)
1583 (not (tags-loop-eval tags-loop-scan))))
1584 (setq file-finished nil)
1585 (setq new (next-file first-time t))
1586 ;; If NEW is non-nil, we got a temp buffer,
1587 ;; and NEW is the file name.
1588 (if (or messaged
1589 (and (not first-time)
1590 (> baud-rate search-slow-speed)
1591 (setq messaged t)))
1592 (message "Scanning file %s..." (or new buffer-file-name)))
1593 (setq first-time nil)
1594 (goto-char (point-min)))
1596 ;; If we visited it in a temp buffer, visit it now for real.
1597 (if new
1598 (let ((pos (point)))
1599 (erase-buffer)
1600 (set-buffer (find-file-noselect new))
1601 (setq new nil) ;No longer in a temp buffer.
1602 (widen)
1603 (goto-char pos)))
1605 (switch-to-buffer (current-buffer))
1607 ;; Now operate on the file.
1608 ;; If value is non-nil, continue to scan the next file.
1609 (tags-loop-eval tags-loop-operate))
1610 (setq file-finished t))
1611 (and messaged
1612 (null tags-loop-operate)
1613 (message "Scanning file %s...found" buffer-file-name))))
1614 ;;;###autoload (define-key esc-map "," 'tags-loop-continue)
1616 ;;;###autoload
1617 (defun tags-search (regexp &optional file-list-form)
1618 "Search through all files listed in tags table for match for REGEXP.
1619 Stops when a match is found.
1620 To continue searching for next match, use command \\[tags-loop-continue].
1622 See documentation of variable `tags-file-name'."
1623 (interactive "sTags search (regexp): ")
1624 (if (and (equal regexp "")
1625 (eq (car tags-loop-scan) 're-search-forward)
1626 (null tags-loop-operate))
1627 ;; Continue last tags-search as if by M-,.
1628 (tags-loop-continue nil)
1629 (setq tags-loop-scan
1630 (list 're-search-forward (list 'quote regexp) nil t)
1631 tags-loop-operate nil)
1632 (tags-loop-continue (or file-list-form t))))
1634 ;;;###autoload
1635 (defun tags-query-replace (from to &optional delimited file-list-form start end)
1636 "`Query-replace-regexp' FROM with TO through all files listed in tags table.
1637 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
1638 If you exit (\\[keyboard-quit] or ESC), you can resume the query-replace
1639 with the command \\[tags-loop-continue].
1641 See documentation of variable `tags-file-name'."
1642 (interactive (query-replace-read-args "Tags query replace (regexp)" t))
1643 (setq tags-loop-scan (list 'prog1
1644 (list 'if (list 're-search-forward
1645 (list 'quote from) nil t)
1646 ;; When we find a match, move back
1647 ;; to the beginning of it so perform-replace
1648 ;; will see it.
1649 '(goto-char (match-beginning 0))))
1650 tags-loop-operate (list 'perform-replace
1651 (list 'quote from) (list 'quote to) nil nil
1652 t t (list 'quote delimited)))
1653 (tags-loop-continue (or file-list-form t)))
1655 (defun tags-complete-tags-table-file (string predicate what)
1656 (save-excursion
1657 ;; If we need to ask for the tag table, allow that.
1658 (let ((enable-recursive-minibuffers t))
1659 (visit-tags-table-buffer))
1660 (if (eq what t)
1661 (all-completions string (mapcar 'list (tags-table-files))
1662 predicate)
1663 (try-completion string (mapcar 'list (tags-table-files))
1664 predicate))))
1666 ;;;###autoload
1667 (defun list-tags (file &optional next-match)
1668 "Display list of tags in file FILE.
1669 This searches only the first table in the list, and no included tables.
1670 FILE should be as it appeared in the `etags' command, usually without a
1671 directory specification."
1672 (interactive (list (completing-read "List tags in file: "
1673 'tags-complete-tags-table-file
1674 nil t nil)))
1675 (with-output-to-temp-buffer "*Tags List*"
1676 (princ "Tags in file `")
1677 (tags-with-face 'highlight (princ file))
1678 (princ "':\n\n")
1679 (save-excursion
1680 (let ((first-time t)
1681 (gotany nil))
1682 (while (visit-tags-table-buffer (not first-time))
1683 (setq first-time nil)
1684 (if (funcall list-tags-function file)
1685 (setq gotany t)))
1686 (or gotany
1687 (error "File %s not in current tags tables" file)))))
1688 (with-current-buffer "*Tags List*"
1689 (setq buffer-read-only t)
1690 (apropos-mode)))
1692 ;;;###autoload
1693 (defun tags-apropos (regexp)
1694 "Display list of all tags in tags table REGEXP matches."
1695 (interactive "sTags apropos (regexp): ")
1696 (with-output-to-temp-buffer "*Tags List*"
1697 (princ "Click mouse-2 to follow tags.\n\nTags matching regexp `")
1698 (tags-with-face 'highlight (princ regexp))
1699 (princ "':\n\n")
1700 (save-excursion
1701 (let ((first-time t))
1702 (while (visit-tags-table-buffer (not first-time))
1703 (setq first-time nil)
1704 (funcall tags-apropos-function regexp))))
1705 (etags-tags-apropos-additional regexp))
1706 (with-current-buffer "*Tags List*"
1707 (setq buffer-read-only t)
1708 (apropos-mode)))
1710 ;;; XXX Kludge interface.
1712 ;; XXX If a file is in multiple tables, selection may get the wrong one.
1713 ;;;###autoload
1714 (defun select-tags-table ()
1715 "Select a tags table file from a menu of those you have already used.
1716 The list of tags tables to select from is stored in `tags-table-set-list';
1717 see the doc of that variable if you want to add names to the list."
1718 (interactive)
1719 (pop-to-buffer "*Tags Table List*")
1720 (setq buffer-read-only nil)
1721 (erase-buffer)
1722 (let ((set-list tags-table-set-list)
1723 (desired-point nil))
1724 (when tags-table-list
1725 (setq desired-point (point-marker))
1726 (princ tags-table-list (current-buffer))
1727 (insert "\C-m")
1728 (prin1 (car tags-table-list) (current-buffer)) ;invisible
1729 (insert "\n"))
1730 (while set-list
1731 (unless (eq (car set-list) tags-table-list)
1732 (princ (car set-list) (current-buffer))
1733 (insert "\C-m")
1734 (prin1 (car (car set-list)) (current-buffer)) ;invisible
1735 (insert "\n"))
1736 (setq set-list (cdr set-list)))
1737 (when tags-file-name
1738 (or desired-point
1739 (setq desired-point (point-marker)))
1740 (insert tags-file-name "\C-m")
1741 (prin1 tags-file-name (current-buffer)) ;invisible
1742 (insert "\n"))
1743 (setq set-list (delete tags-file-name
1744 (apply 'nconc (cons (copy-sequence tags-table-list)
1745 (mapcar 'copy-sequence
1746 tags-table-set-list)))))
1747 (while set-list
1748 (insert (car set-list) "\C-m")
1749 (prin1 (car set-list) (current-buffer)) ;invisible
1750 (insert "\n")
1751 (setq set-list (delete (car set-list) set-list)))
1752 (goto-char 1)
1753 (insert-before-markers
1754 "Type `t' to select a tags table or set of tags tables:\n\n")
1755 (if desired-point
1756 (goto-char desired-point))
1757 (set-window-start (selected-window) 1 t))
1758 (set-buffer-modified-p nil)
1759 (select-tags-table-mode))
1761 (defvar select-tags-table-mode-map)
1762 (let ((map (make-sparse-keymap)))
1763 (define-key map "t" 'select-tags-table-select)
1764 (define-key map " " 'next-line)
1765 (define-key map "\^?" 'previous-line)
1766 (define-key map "n" 'next-line)
1767 (define-key map "p" 'previous-line)
1768 (define-key map "q" 'select-tags-table-quit)
1769 (setq select-tags-table-mode-map map))
1771 (defun select-tags-table-mode ()
1772 "Major mode for choosing a current tags table among those already loaded.
1774 \\{select-tags-table-mode-map}"
1775 (interactive)
1776 (kill-all-local-variables)
1777 (setq buffer-read-only t
1778 major-mode 'select-tags-table-mode
1779 mode-name "Select Tags Table")
1780 (use-local-map select-tags-table-mode-map)
1781 (setq selective-display t
1782 selective-display-ellipses nil))
1784 (defun select-tags-table-select ()
1785 "Select the tags table named on this line."
1786 (interactive)
1787 (search-forward "\C-m")
1788 (let ((name (read (current-buffer))))
1789 (visit-tags-table name)
1790 (select-tags-table-quit)
1791 (message "Tags table now %s" name)))
1793 (defun select-tags-table-quit ()
1794 "Kill the buffer and delete the selected window."
1795 (interactive)
1796 (quit-window t (selected-window)))
1798 ;;; Note, there is another definition of this function in bindings.el.
1799 ;;;###autoload
1800 (defun complete-tag ()
1801 "Perform tags completion on the text around point.
1802 Completes to the set of names listed in the current tags table.
1803 The string to complete is chosen in the same way as the default
1804 for \\[find-tag] (which see)."
1805 (interactive)
1806 (or tags-table-list
1807 tags-file-name
1808 (error "%s"
1809 (substitute-command-keys
1810 "No tags table loaded; try \\[visit-tags-table]")))
1811 (let ((pattern (funcall (or find-tag-default-function
1812 (get major-mode 'find-tag-default-function)
1813 'find-tag-default)))
1815 completion)
1816 (or pattern
1817 (error "Nothing to complete"))
1818 (search-backward pattern)
1819 (setq beg (point))
1820 (forward-char (length pattern))
1821 (setq completion (tags-complete-tag pattern nil nil))
1822 (cond ((eq completion t))
1823 ((null completion)
1824 (message "Can't find completion for \"%s\"" pattern)
1825 (ding))
1826 ((not (string= pattern completion))
1827 (delete-region beg (point))
1828 (insert completion))
1830 (message "Making completion list...")
1831 (with-output-to-temp-buffer "*Completions*"
1832 (display-completion-list
1833 (all-completions pattern 'tags-complete-tag nil)))
1834 (message "Making completion list...%s" "done")))))
1836 (dolist (x '("^No tags table in use; use .* to select one$"
1837 "^There is no default tag$"
1838 "^No previous tag locations$"
1839 "^File .* is not a valid tags table$"
1840 "^No \\(more \\|\\)tags \\(matching\\|containing\\) "
1841 "^Rerun etags: `.*' not found in "
1842 "^All files processed$"
1843 "^No .* or .* in progress$"
1844 "^File .* not in current tags tables$"
1845 "^No tags table loaded"
1846 "^Nothing to complete$"))
1847 (add-to-list 'debug-ignored-errors x))
1849 (provide 'etags)
1851 ;;; etags.el ends here