Mercurial > emacs
annotate lisp/progmodes/etags.el @ 2607:fcf578723758
(Fexpand_file_name): Undo last change--too risky for now.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 29 Apr 1993 13:17:56 +0000 |
parents | 9dace03bd76c |
children | 82797c755adc |
rev | line source |
---|---|
2229
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1976
diff
changeset
|
1 ;;; etags.el --- etags facility for Emacs |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
2 |
1806
da47cfb7624e
(visit-tags-table-buffer): Error if called with 'same and no current table.
Roland McGrath <roland@gnu.org>
parents:
1724
diff
changeset
|
3 ;; Copyright (C) 1985, 1986, 1988, 1989, 1992, 1993 |
da47cfb7624e
(visit-tags-table-buffer): Error if called with 'same and no current table.
Roland McGrath <roland@gnu.org>
parents:
1724
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
824
diff
changeset
|
5 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
6 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu> |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
7 ;; Keywords: tools |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
8 |
342 | 9 ;; This file is part of GNU Emacs. |
10 | |
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 | |
727 | 13 ;; the Free Software Foundation; either version 2, or (at your option) |
342 | 14 ;; any later version. |
15 | |
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. | |
20 | |
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 | |
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
25 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
26 |
360 | 27 ;;;###autoload |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
28 (defvar tags-file-name nil |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
29 "*File name of tags table. |
799 | 30 To switch to a new tags table, setting this variable is sufficient. |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
31 If you set this variable, do not also set `tags-table-list'. |
799 | 32 Use the `etags' program to make a tags table file.") |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
33 ;; Make M-x set-variable tags-file-name like M-x visit-tags-table. |
824 | 34 ;;;###autoload (put 'tags-file-name 'variable-interactive "fVisit tags table: ") |
799 | 35 |
36 ;;;###autoload | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
37 ;; Use `visit-tags-table-buffer' to cycle through tags tables in this list. |
799 | 38 (defvar tags-table-list nil |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
39 "*List of file names of tags tables to search. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
40 An element that is a directory means the file \"TAGS\" in that directory. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
41 To switch to a new list of tags tables, setting this variable is sufficient. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
42 If you set this variable, do not also set `tags-file-name'. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
43 Use the `etags' program to make a tags table file.") |
799 | 44 |
45 (defvar tags-table-list-pointer nil | |
1149 | 46 "Pointer into `tags-table-list' where the current state of searching is. |
47 Might instead point into a list of included tags tables. | |
48 Use `visit-tags-table-buffer' to cycle through tags tables in this list.") | |
49 | |
50 (defvar tags-table-list-started-at nil | |
51 "Pointer into `tags-table-list', where the current search started.") | |
342 | 52 |
799 | 53 (defvar tags-table-parent-pointer-list nil |
1149 | 54 "Saved state of the tags table that included this one. |
55 Each element is (POINTER . STARTED-AT), giving the values of | |
56 `tags-table-list-pointer' and `tags-table-list-started-at' from | |
57 before we moved into the current table.") | |
799 | 58 |
59 (defvar tags-table-set-list nil | |
60 "List of sets of tags table which have been used together in the past. | |
61 Each element is a list of strings which are file names.") | |
342 | 62 |
799 | 63 ;;;###autoload |
64 (defvar find-tag-hook nil | |
65 "*Hook to be run by \\[find-tag] after finding a tag. See `run-hooks'. | |
66 The value in the buffer in which \\[find-tag] is done is used, | |
67 not the value in the buffer \\[find-tag] goes to.") | |
68 | |
69 ;;;###autoload | |
70 (defvar find-tag-default-function nil | |
1149 | 71 "*A function of no arguments used by \\[find-tag] to pick a default tag. |
72 If nil, and the symbol that is the value of `major-mode' | |
799 | 73 has a `find-tag-default-function' property (see `put'), that is used. |
74 Otherwise, `find-tag-default' is used.") | |
342 | 75 |
360 | 76 ;;;###autoload |
799 | 77 (defvar default-tags-table-function nil |
78 "*If non-nil, a function of no arguments to choose a default tags file | |
79 for a particular buffer.") | |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
80 |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
81 (defvar tags-location-stack nil |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
82 "List of markers which are locations visited by \\[find-tag]. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
83 Pop back to the last location with \\[negative-argument] \\[find-tag].") |
799 | 84 |
85 ;; Tags table state. | |
86 ;; These variables are local in tags table buffers. | |
87 | |
88 (defvar tag-lines-already-matched nil | |
89 "List of positions of beginnings of lines within the tags table | |
90 that are already matched.") | |
91 | |
92 (defvar tags-table-files nil | |
93 "List of file names covered by current tags table. | |
94 nil means it has not yet been computed; use `tags-table-files' to do so.") | |
95 | |
96 (defvar tags-completion-table nil | |
97 "Alist of tag names defined in current tags table.") | |
98 | |
99 (defvar tags-included-tables nil | |
100 "List of tags tables included by the current tags table.") | |
101 | |
102 (defvar next-file-list nil | |
103 "List of files for \\[next-file] to process.") | |
104 | |
105 ;; Hooks for file formats. | |
106 | |
107 (defvar tags-table-format-hooks '(etags-recognize-tags-table | |
824 | 108 recognize-empty-tags-table) |
799 | 109 "List of functions to be called in a tags table buffer to identify |
110 the type of tags table. The functions are called in order, with no arguments, | |
111 until one returns non-nil. The function should make buffer-local bindings | |
112 of the format-parsing tags function variables if successful.") | |
113 | |
114 (defvar file-of-tag-function nil | |
115 "Function to do the work of `file-of-tag' (which see).") | |
116 (defvar tags-table-files-function nil | |
117 "Function to do the work of `tags-table-files' (which see).") | |
118 (defvar tags-completion-table-function nil | |
119 "Function to build the tags-completion-table.") | |
120 (defvar snarf-tag-function nil | |
121 "Function to get info about a matched tag for `goto-tag-location-function'.") | |
122 (defvar goto-tag-location-function nil | |
123 "Function of to go to the location in the buffer specified by a tag. | |
124 One argument, the tag info returned by `snarf-tag-function'.") | |
125 (defvar find-tag-regexp-search-function nil | |
126 "Search function passed to `find-tag-in-order' for finding a regexp tag.") | |
127 (defvar find-tag-regexp-tag-order nil | |
128 "Tag order passed to `find-tag-in-order' for finding a regexp tag.") | |
129 (defvar find-tag-regexp-next-line-after-failure-p nil | |
130 "Flag passed to `find-tag-in-order' for finding a regexp tag.") | |
131 (defvar find-tag-search-function nil | |
132 "Search function passed to `find-tag-in-order' for finding a tag.") | |
133 (defvar find-tag-tag-order nil | |
134 "Tag order passed to `find-tag-in-order' for finding a tag.") | |
135 (defvar find-tag-next-line-after-failure-p nil | |
136 "Flag passed to `find-tag-in-order' for finding a tag.") | |
137 (defvar list-tags-function nil | |
138 "Function to do the work of `list-tags' (which see).") | |
139 (defvar tags-apropos-function nil | |
140 "Function to do the work of `tags-apropos' (which see).") | |
141 (defvar tags-included-tables-function nil | |
142 "Function to do the work of `tags-included-tables' (which see).") | |
143 (defvar verify-tags-table-function nil | |
144 "Function to return t iff the current buffer vontains a valid | |
145 \(already initialized\) tags file.") | |
146 | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
147 ;; Initialize the tags table in the current buffer. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
148 ;; Returns non-nil iff it is a valid tags table. On |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
149 ;; non-nil return, the tags table state variable are |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
150 ;; made buffer-local and initialized to nil. |
799 | 151 (defun initialize-new-tags-table () |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
152 (set (make-local-variable 'tag-lines-already-matched) nil) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
153 (set (make-local-variable 'tags-table-files) nil) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
154 (set (make-local-variable 'tags-completion-table) nil) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
155 (set (make-local-variable 'tags-included-tables) nil) |
799 | 156 ;; Value is t if we have found a valid tags table buffer. |
157 (let ((hooks tags-table-format-hooks)) | |
158 (while (and hooks | |
159 (not (funcall (car hooks)))) | |
160 (setq hooks (cdr hooks))) | |
161 hooks)) | |
162 | |
163 ;;;###autoload | |
164 (defun visit-tags-table (file &optional local) | |
165 "Tell tags commands to use tags table file FILE. | |
342 | 166 FILE should be the name of a file created with the `etags' program. |
799 | 167 A directory name is ok too; it means file TAGS in that directory. |
168 | |
169 Normally \\[visit-tags-table] sets the global value of `tags-file-name'. | |
170 With a prefix arg, set the buffer-local value instead. | |
171 When you find a tag with \\[find-tag], the buffer it finds the tag | |
172 in is given a local value of this variable which is the name of the tags | |
173 file the tag was in." | |
342 | 174 (interactive (list (read-file-name "Visit tags table: (default TAGS) " |
175 default-directory | |
799 | 176 (expand-file-name "TAGS" |
177 default-directory) | |
178 t) | |
179 current-prefix-arg)) | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
180 ;; Calling visit-tags-table-buffer with tags-file-name set to FILE will |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
181 ;; initialize a buffer for FILE and set tags-file-name to the |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
182 ;; fully-expanded name. |
1138 | 183 (let ((tags-file-name file)) |
184 (save-excursion | |
1149 | 185 (or (visit-tags-table-buffer 'same) |
1138 | 186 (signal 'file-error (list "Visiting tags table" |
187 "file does not exist" | |
188 file))) | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
189 ;; Set FILE to the expanded name. |
1138 | 190 (setq file tags-file-name))) |
799 | 191 (if local |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
192 ;; Set the local value of tags-file-name. |
1149 | 193 (set (make-local-variable 'tags-file-name) file) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
194 ;; Set the global value of tags-file-name. |
1138 | 195 (setq-default tags-file-name file))) |
196 | |
197 ;; Move tags-table-list-pointer along and set tags-file-name. | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
198 ;; If NO-INCLUDES is non-nil, ignore included tags tables. |
1138 | 199 ;; Returns nil when out of tables. |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
200 (defun tags-next-table (&optional no-includes) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
201 ;; Do we have any included tables? |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
202 (if (and (not no-includes) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
203 (visit-tags-table-buffer 'same) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
204 (tags-included-tables)) |
1149 | 205 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
206 ;; Move into the included tags tables. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
207 (setq tags-table-parent-pointer-list |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
208 ;; Save the current state of what table we are in. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
209 (cons (cons tags-table-list-pointer tags-table-list-started-at) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
210 tags-table-parent-pointer-list) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
211 ;; Start the pointer in the list of included tables. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
212 tags-table-list-pointer tags-included-tables |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
213 tags-table-list-started-at tags-included-tables) |
1149 | 214 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
215 ;; No included tables. Go to the next table in the list. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
216 (setq tags-table-list-pointer |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
217 (cdr tags-table-list-pointer)) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
218 (or tags-table-list-pointer |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
219 ;; Wrap around. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
220 (setq tags-table-list-pointer tags-table-list)) |
1149 | 221 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
222 (if (eq tags-table-list-pointer tags-table-list-started-at) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
223 ;; We have come full circle. No more tables. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
224 (if tags-table-parent-pointer-list |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
225 ;; Pop back to the tags table which includes this one. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
226 (progn |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
227 ;; Restore the state variables. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
228 (setq tags-table-list-pointer |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
229 (car (car tags-table-parent-pointer-list)) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
230 tags-table-list-started-at |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
231 (cdr (car tags-table-parent-pointer-list)) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
232 tags-table-parent-pointer-list |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
233 (cdr tags-table-parent-pointer-list)) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
234 ;; Recurse to skip to the next table after the parent. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
235 (tags-next-table t)) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
236 ;; All out of tags tables. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
237 (setq tags-table-list-pointer nil)))) |
1149 | 238 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
239 (and tags-table-list-pointer |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
240 ;; Set tags-file-name to the fully-expanded name. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
241 (setq tags-file-name |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
242 (tags-expand-table-name (car tags-table-list-pointer))))) |
1149 | 243 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
244 ;; Expand tags table name FILE into a complete file name. |
1149 | 245 (defun tags-expand-table-name (file) |
246 (setq file (expand-file-name file)) | |
247 (if (file-directory-p file) | |
248 (expand-file-name "TAGS" file) | |
249 file)) | |
1138 | 250 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
251 ;; Return the cdr of LIST (default: tags-table-list) whose car |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
252 ;; is equal to FILE after tags-expand-table-name on both sides. |
1149 | 253 (defun tags-table-list-member (file &optional list) |
254 (or list | |
255 (setq list tags-table-list)) | |
256 (setq file (tags-expand-table-name file)) | |
257 (while (and list | |
258 (not (string= file (tags-expand-table-name (car list))))) | |
259 (setq list (cdr list))) | |
260 list) | |
261 | |
262 ;; Subroutine of visit-tags-table-buffer. Frobs its local vars. | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
263 ;; Search TABLES for one that has tags for THIS-FILE. Recurses |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
264 ;; on included tables. Returns the tail of TABLES (or of an |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
265 ;; inner included list) whose car is a table listing THIS-FILE. |
1149 | 266 (defun tags-table-including (this-file tables &optional recursing) |
267 (let ((found nil)) | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
268 ;; Loop over TABLES, looking for one containing tags for THIS-FILE. |
1149 | 269 (while (and (not found) |
270 tables) | |
271 (let ((tags-file-name (tags-expand-table-name (car tables)))) | |
272 (if (or (get-file-buffer tags-file-name) | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
273 (file-exists-p tags-file-name)) ;XXX check all in core first. |
1149 | 274 (progn |
275 ;; Select the tags table buffer and get the file list up to date. | |
276 (visit-tags-table-buffer 'same) | |
277 (or tags-table-files | |
278 (setq tags-table-files | |
279 (funcall tags-table-files-function))) | |
280 | |
281 (cond ((member this-file tags-table-files) | |
282 ;; Found it. | |
283 (setq found tables)) | |
1138 | 284 |
1149 | 285 ((tags-included-tables) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
286 ;; This table has included tables. Check them. |
1149 | 287 (let ((old tags-table-parent-pointer-list)) |
288 (unwind-protect | |
289 (progn | |
290 (or recursing | |
291 ;; At top level (not in an included tags | |
292 ;; table), set the list to nil so we can | |
293 ;; collect just the elts from this run. | |
294 (setq tags-table-parent-pointer-list nil)) | |
295 (setq found | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
296 ;; Recurse on the list of included tables. |
1149 | 297 (tags-table-including this-file |
298 tags-included-tables | |
299 t)) | |
300 (if found | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
301 ;; One of them lists THIS-FILE. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
302 ;; Set the table list state variables to move |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
303 ;; us inside the list of included tables. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
304 (setq tags-table-parent-pointer-list |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
305 (cons |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
306 (cons tags-table-list-pointer |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
307 tags-table-list-started-at) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
308 tags-table-parent-pointer-list) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
309 tags-table-list-pointer found |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
310 tags-table-list-started-at found |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
311 ;; CONT is a local variable of |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
312 ;; our caller, visit-tags-table-buffer. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
313 ;; Set it so we won't frob lists later. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
314 cont 'included))) |
1149 | 315 (or recursing |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
316 ;; tags-table-parent-pointer-list now describes |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
317 ;; the path of included tables taken by recursive |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
318 ;; invocations of this function. The recursive |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
319 ;; calls have consed onto the front of the list, |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
320 ;; so it is now outermost first. We want it |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
321 ;; innermost first, so reverse it. Then append |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
322 ;; the old list (from before we were called the |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
323 ;; outermost time), to get the complete current |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
324 ;; state of included tables. |
1149 | 325 (setq tags-table-parent-pointer-list |
326 (nconc (nreverse | |
327 tags-table-parent-pointer-list) | |
328 old)))))))))) | |
329 (setq tables (cdr tables))) | |
330 found)) | |
799 | 331 |
332 (defun visit-tags-table-buffer (&optional cont) | |
333 "Select the buffer containing the current tags table. | |
334 If optional arg is t, visit the next table in `tags-table-list'. | |
335 If optional arg is the atom `same', don't look for a new table; | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
336 just select the buffer visiting `tags-file-name'. |
1149 | 337 If arg is nil or absent, choose a first buffer from information in |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
338 `tags-file-name', `tags-table-list', `tags-table-list-pointer'. |
799 | 339 Returns t if it visits a tags table, or nil if there are no more in the list." |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
340 |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
341 ;; Set tags-file-name to the tags table file we want to visit. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
342 (cond ((eq cont 'same) |
1806
da47cfb7624e
(visit-tags-table-buffer): Error if called with 'same and no current table.
Roland McGrath <roland@gnu.org>
parents:
1724
diff
changeset
|
343 ;; Use the ambient value of tags-file-name. |
da47cfb7624e
(visit-tags-table-buffer): Error if called with 'same and no current table.
Roland McGrath <roland@gnu.org>
parents:
1724
diff
changeset
|
344 (or tags-file-name |
da47cfb7624e
(visit-tags-table-buffer): Error if called with 'same and no current table.
Roland McGrath <roland@gnu.org>
parents:
1724
diff
changeset
|
345 (error (substitute-command-keys |
da47cfb7624e
(visit-tags-table-buffer): Error if called with 'same and no current table.
Roland McGrath <roland@gnu.org>
parents:
1724
diff
changeset
|
346 (concat "No tags table in use! " |
da47cfb7624e
(visit-tags-table-buffer): Error if called with 'same and no current table.
Roland McGrath <roland@gnu.org>
parents:
1724
diff
changeset
|
347 "Use \\[visit-tags-table] to select one.")))) |
da47cfb7624e
(visit-tags-table-buffer): Error if called with 'same and no current table.
Roland McGrath <roland@gnu.org>
parents:
1724
diff
changeset
|
348 ;; Set CONT to nil so the code below will make sure tags-file-name |
da47cfb7624e
(visit-tags-table-buffer): Error if called with 'same and no current table.
Roland McGrath <roland@gnu.org>
parents:
1724
diff
changeset
|
349 ;; is in tags-table-list. |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
350 (setq cont nil)) |
1138 | 351 |
1149 | 352 (cont |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
353 ;; Find the next table. |
1149 | 354 (if (tags-next-table) |
355 ;; Skip over nonexistent files. | |
356 (while (and (let ((file (tags-expand-table-name tags-file-name))) | |
357 (not (or (get-file-buffer file) | |
358 (file-exists-p file)))) | |
359 (tags-next-table))))) | |
342 | 360 |
1149 | 361 (t |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
362 ;; Pick a table out of our hat. |
1149 | 363 (setq tags-file-name |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
364 (or |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
365 ;; First, try a local variable. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
366 (cdr (assq 'tags-file-name (buffer-local-variables))) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
367 ;; Second, try a user-specified function to guess. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
368 (and default-tags-table-function |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
369 (funcall default-tags-table-function)) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
370 ;; Third, look for a tags table that contains |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
371 ;; tags for the current buffer's file. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
372 ;; If one is found, the lists will be frobnicated, |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
373 ;; and CONT will be set non-nil so we don't do it below. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
374 (car (save-excursion (tags-table-including buffer-file-name |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
375 tags-table-list))) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
376 ;; Fourth, use the user variable tags-file-name, if it is not |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
377 ;; already in tags-table-list. |
1697
f14e1a6ac205
(visit-tags-table-buffer): Don't look in list for tags-file-name if nil.
Roland McGrath <roland@gnu.org>
parents:
1696
diff
changeset
|
378 (and tags-file-name |
f14e1a6ac205
(visit-tags-table-buffer): Don't look in list for tags-file-name if nil.
Roland McGrath <roland@gnu.org>
parents:
1696
diff
changeset
|
379 (not (tags-table-list-member tags-file-name)) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
380 tags-file-name) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
381 ;; Fifth, use the user variable giving the table list. |
1724
2dccfada2107
(visit-tags-table-buffer): When picking a table and using tags-table-list,
Roland McGrath <roland@gnu.org>
parents:
1723
diff
changeset
|
382 ;; Find the first element of the list that actually exists. |
2dccfada2107
(visit-tags-table-buffer): When picking a table and using tags-table-list,
Roland McGrath <roland@gnu.org>
parents:
1723
diff
changeset
|
383 (let ((list tags-table-list) |
2dccfada2107
(visit-tags-table-buffer): When picking a table and using tags-table-list,
Roland McGrath <roland@gnu.org>
parents:
1723
diff
changeset
|
384 file) |
2dccfada2107
(visit-tags-table-buffer): When picking a table and using tags-table-list,
Roland McGrath <roland@gnu.org>
parents:
1723
diff
changeset
|
385 (while (and list |
2dccfada2107
(visit-tags-table-buffer): When picking a table and using tags-table-list,
Roland McGrath <roland@gnu.org>
parents:
1723
diff
changeset
|
386 (setq file (tags-expand-table-name (car list))) |
2dccfada2107
(visit-tags-table-buffer): When picking a table and using tags-table-list,
Roland McGrath <roland@gnu.org>
parents:
1723
diff
changeset
|
387 (not (get-file-buffer file)) |
2dccfada2107
(visit-tags-table-buffer): When picking a table and using tags-table-list,
Roland McGrath <roland@gnu.org>
parents:
1723
diff
changeset
|
388 (not (file-exists-p file))) |
2dccfada2107
(visit-tags-table-buffer): When picking a table and using tags-table-list,
Roland McGrath <roland@gnu.org>
parents:
1723
diff
changeset
|
389 (setq list (cdr list))) |
2dccfada2107
(visit-tags-table-buffer): When picking a table and using tags-table-list,
Roland McGrath <roland@gnu.org>
parents:
1723
diff
changeset
|
390 (car list)) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
391 ;; Finally, prompt the user for a file name. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
392 (expand-file-name |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
393 (read-file-name "Visit tags table: (default TAGS) " |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
394 default-directory |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
395 "TAGS" |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
396 t)))))) |
1149 | 397 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
398 ;; Expand the table name into a full file name. |
1149 | 399 (setq tags-file-name (tags-expand-table-name tags-file-name)) |
400 | |
1156 | 401 (if (and (eq cont t) (null tags-table-list-pointer)) |
1149 | 402 ;; All out of tables. |
403 nil | |
1138 | 404 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
405 ;; Verify that tags-file-name is a valid tags table. |
1149 | 406 (if (if (get-file-buffer tags-file-name) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
407 ;; The file is already in a buffer. Check for the visited file |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
408 ;; having changed since we last used it. |
1149 | 409 (let (win) |
410 (set-buffer (get-file-buffer tags-file-name)) | |
411 (setq win (or verify-tags-table-function | |
412 (initialize-new-tags-table))) | |
413 (if (or (verify-visited-file-modtime (current-buffer)) | |
414 (not (yes-or-no-p | |
415 "Tags file has changed, read new contents? "))) | |
416 (and win (funcall verify-tags-table-function)) | |
417 (revert-buffer t t) | |
418 (initialize-new-tags-table))) | |
419 (set-buffer (find-file-noselect tags-file-name)) | |
420 (or (string= tags-file-name buffer-file-name) | |
421 ;; find-file-noselect has changed the file name. | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
422 ;; Propagate the change to tags-file-name and tags-table-list. |
1807
1059b972916c
(visit-tags-table-buffer): When propagating a change of name after
Roland McGrath <roland@gnu.org>
parents:
1806
diff
changeset
|
423 (let ((tail (member tags-file-name tags-table-list))) |
1149 | 424 (if tail |
425 (setcar tail buffer-file-name)) | |
426 (setq tags-file-name buffer-file-name))) | |
427 (initialize-new-tags-table)) | |
428 | |
429 ;; We have a valid tags table. | |
430 (progn | |
431 ;; Bury the tags table buffer so it | |
432 ;; doesn't get in the user's way. | |
433 (bury-buffer (current-buffer)) | |
799 | 434 |
1149 | 435 (if cont |
436 ;; No list frobbing required. | |
437 nil | |
438 | |
439 ;; Look in the list for the table we chose. | |
440 (let ((elt (tags-table-list-member tags-file-name))) | |
441 (or elt | |
442 ;; The table is not in the current set. | |
443 ;; Try to find it in another previously used set. | |
444 (let ((sets tags-table-set-list)) | |
445 (while (and sets | |
446 (not (setq elt (tags-table-list-member | |
447 tags-file-name (car sets))))) | |
448 (setq sets (cdr sets))) | |
449 (if sets | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
450 ;; Found in some other set. Switch to that set. |
1149 | 451 (progn |
1138 | 452 (or (memq tags-table-list tags-table-set-list) |
1149 | 453 ;; Save the current list. |
1138 | 454 (setq tags-table-set-list |
455 (cons tags-table-list | |
456 tags-table-set-list))) | |
1149 | 457 (setq tags-table-list (car sets))) |
458 | |
459 ;; Not found in any existing set. | |
460 (if (and tags-table-list | |
461 (y-or-n-p (concat "Add " tags-file-name | |
462 " to current list" | |
463 " of tags tables? "))) | |
464 ;; Add it to the current list. | |
465 (setq tags-table-list (cons tags-file-name | |
466 tags-table-list)) | |
467 ;; Make a fresh list, and store the old one. | |
468 (or (memq tags-table-list tags-table-set-list) | |
469 (setq tags-table-set-list | |
470 (cons tags-table-list tags-table-set-list))) | |
471 (setq tags-table-list (list tags-file-name))) | |
472 (setq elt tags-table-list)))) | |
473 | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
474 ;; Set the tags table list state variables to point at the table |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
475 ;; we want to use first. |
1149 | 476 (setq tags-table-list-started-at elt |
1156 | 477 tags-table-list-pointer elt))) |
478 | |
479 ;; Return of t says the tags table is valid. | |
480 t) | |
1149 | 481 |
482 ;; The buffer was not valid. Don't use it again. | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
483 (let ((file tags-file-name)) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
484 (kill-local-variable 'tags-file-name) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
485 (if (eq file tags-file-name) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
486 (setq tags-file-name nil))) |
1149 | 487 (error "File %s is not a valid tags table" buffer-file-name)))) |
1397
d469afe703c4
(visit-tags-table-buffer): When trying to pick table, call
Roland McGrath <roland@gnu.org>
parents:
1156
diff
changeset
|
488 |
342 | 489 (defun file-of-tag () |
490 "Return the file name of the file whose tags point is within. | |
799 | 491 Assumes the tags table is the current buffer. |
492 File name returned is relative to tags table file's directory." | |
493 (funcall file-of-tag-function)) | |
342 | 494 |
360 | 495 ;;;###autoload |
799 | 496 (defun tags-table-files () |
497 "Return a list of files in the current tags table. | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
498 Assumes the tags table is the current buffer. |
342 | 499 File names returned are absolute." |
1397
d469afe703c4
(visit-tags-table-buffer): When trying to pick table, call
Roland McGrath <roland@gnu.org>
parents:
1156
diff
changeset
|
500 (or tags-table-files |
d469afe703c4
(visit-tags-table-buffer): When trying to pick table, call
Roland McGrath <roland@gnu.org>
parents:
1156
diff
changeset
|
501 (setq tags-table-files |
d469afe703c4
(visit-tags-table-buffer): When trying to pick table, call
Roland McGrath <roland@gnu.org>
parents:
1156
diff
changeset
|
502 (funcall tags-table-files-function)))) |
799 | 503 |
504 (defun tags-included-tables () | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
505 "Return a list of tags tables included by the current table. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
506 Assumes the tags table is the current buffer." |
799 | 507 (or tags-included-tables |
508 (setq tags-included-tables (funcall tags-included-tables-function)))) | |
509 | |
510 ;; Build tags-completion-table on demand. The single current tags table | |
511 ;; and its included tags tables (and their included tables, etc.) have | |
512 ;; their tags included in the completion table. | |
513 (defun tags-completion-table () | |
514 (or tags-completion-table | |
515 (condition-case () | |
516 (prog2 | |
517 (message "Making tags completion table for %s..." buffer-file-name) | |
518 (let ((included (tags-included-tables)) | |
519 (table (funcall tags-completion-table-function))) | |
520 (save-excursion | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
521 ;; Iterate over the list of included tables, and combine each |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
522 ;; included table's completion obarray to the parent obarray. |
799 | 523 (while included |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
524 ;; Visit the buffer. |
799 | 525 (let ((tags-file-name (car included))) |
1149 | 526 (visit-tags-table-buffer 'same)) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
527 ;; Recurse in that buffer to compute its completion table. |
799 | 528 (if (tags-completion-table) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
529 ;; Combine the tables. |
799 | 530 (mapatoms (function |
531 (lambda (sym) | |
532 (intern (symbol-name sym) table))) | |
533 tags-completion-table)) | |
534 (setq included (cdr included)))) | |
535 (setq tags-completion-table table)) | |
536 (message "Making tags completion table for %s...done" | |
537 buffer-file-name)) | |
538 (quit (message "Tags completion table construction aborted.") | |
539 (setq tags-completion-table nil))))) | |
540 | |
541 ;; Completion function for tags. Does normal try-completion, | |
542 ;; but builds tags-completion-table on demand. | |
543 (defun tags-complete-tag (string predicate what) | |
544 (save-excursion | |
545 (visit-tags-table-buffer) | |
546 (if (eq what t) | |
547 (all-completions string (tags-completion-table) predicate) | |
548 (try-completion string (tags-completion-table) predicate)))) | |
1397
d469afe703c4
(visit-tags-table-buffer): When trying to pick table, call
Roland McGrath <roland@gnu.org>
parents:
1156
diff
changeset
|
549 |
342 | 550 ;; Return a default tag to search for, based on the text at point. |
551 (defun find-tag-default () | |
552 (save-excursion | |
553 (while (looking-at "\\sw\\|\\s_") | |
554 (forward-char 1)) | |
799 | 555 (if (or (re-search-backward "\\sw\\|\\s_" |
556 (save-excursion (beginning-of-line) (point)) | |
557 t) | |
558 (re-search-forward "\\(\\sw\\|\\s_\\)+" | |
559 (save-excursion (end-of-line) (point)) | |
560 t)) | |
561 (progn (goto-char (match-end 0)) | |
342 | 562 (buffer-substring (point) |
563 (progn (forward-sexp -1) | |
564 (while (looking-at "\\s'") | |
565 (forward-char 1)) | |
566 (point)))) | |
567 nil))) | |
568 | |
799 | 569 ;; Read a tag name from the minibuffer with defaulting and completion. |
342 | 570 (defun find-tag-tag (string) |
799 | 571 (let* ((default (funcall (or find-tag-default-function |
572 (get major-mode 'find-tag-default-function) | |
573 'find-tag-default))) | |
574 (spec (completing-read (if default | |
575 (format "%s(default %s) " string default) | |
576 string) | |
577 'tags-complete-tag))) | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
578 (if (equal spec "") |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
579 (or default (error "There is no default tag")) |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
580 spec))) |
342 | 581 |
852 | 582 (defvar last-tag nil |
583 "Last tag found by \\[find-tag].") | |
584 | |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
585 ;; Get interactive args for find-tag{-noselect,-other-window,-regexp}. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
586 (defun find-tag-interactive (prompt &optional no-default) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
587 (if current-prefix-arg |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
588 (list nil (if (< (prefix-numeric-value current-prefix-arg) 0) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
589 '- |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
590 t)) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
591 (list (if no-default |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
592 (read-string prompt) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
593 (find-tag-tag prompt))))) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
594 |
799 | 595 ;;;###autoload |
596 (defun find-tag-noselect (tagname &optional next-p regexp-p) | |
597 "Find tag (in current tags table) whose name contains TAGNAME. | |
1555
695c6eb2ff31
* etags.el (find-tag-noselect): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1397
diff
changeset
|
598 Returns the buffer containing the tag's definition and moves its point there, |
799 | 599 but does not select the buffer. |
600 The default for TAGNAME is the expression in the buffer near point. | |
474 | 601 |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
602 If second arg NEXT-P is t (interactively, with prefix arg), search for |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
603 another tag that matches the last tagname or regexp used. When there are |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
604 multiple matches for a tag, more exact matches are found first. If NEXT-P |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
605 is the atom `-' (interactively, with prefix arg that is a negative number |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
606 or just \\[negative-argument]), pop back to the previous tag gone to. |
450
0bac8c701777
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
449
diff
changeset
|
607 |
799 | 608 If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp. |
342 | 609 |
799 | 610 See documentation of variable `tags-file-name'." |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
611 (interactive (find-tag-interactive "Find tag: ")) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
612 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
613 ;; Save the current buffer's value of `find-tag-hook' before selecting the |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
614 ;; tags table buffer. |
799 | 615 (let ((local-find-tag-hook find-tag-hook)) |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
616 (if (eq '- next-p) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
617 ;; Pop back to a previous location. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
618 (if (null tags-location-stack) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
619 (error "No previous tag locations") |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
620 (let ((marker (car tags-location-stack))) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
621 ;; Pop the stack. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
622 (setq tags-location-stack (cdr tags-location-stack)) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
623 (prog1 |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
624 ;; Move to the saved location. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
625 (set-buffer (marker-buffer marker)) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
626 (goto-char (marker-position marker)) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
627 ;; Kill that marker so it doesn't slow down editting. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
628 (set-marker marker nil nil) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
629 ;; Run the user's hook. Do we really want to do this for pop? |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
630 (run-hooks 'local-find-tag-hook)))) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
631 (if next-p |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
632 ;; Find the same table we last used. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
633 (visit-tags-table-buffer 'same) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
634 ;; Pick a table to use. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
635 (visit-tags-table-buffer) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
636 ;; Record TAGNAME for a future call with NEXT-P non-nil. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
637 (setq last-tag tagname)) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
638 (prog1 |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
639 ;; Record the location so we can pop back to it later. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
640 (marker-buffer |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
641 (car |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
642 (setq tags-location-stack |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
643 (cons (let ((marker (make-marker))) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
644 (save-excursion |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
645 (set-buffer |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
646 ;; find-tag-in-order does the real work. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
647 (find-tag-in-order |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
648 (if next-p last-tag tagname) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
649 (if regexp-p |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
650 find-tag-regexp-search-function |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
651 find-tag-search-function) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
652 (if regexp-p |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
653 find-tag-regexp-tag-order |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
654 find-tag-tag-order) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
655 (if regexp-p |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
656 find-tag-regexp-next-line-after-failure-p |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
657 find-tag-next-line-after-failure-p) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
658 (if regexp-p "matching" "containing") |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
659 (not next-p))) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
660 (set-marker marker (point)))) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
661 tags-location-stack)))) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
662 (run-hooks 'local-find-tag-hook))))) |
360 | 663 |
664 ;;;###autoload | |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
665 (defun find-tag (tagname &optional next-p regexp-p) |
799 | 666 "Find tag (in current tags table) whose name contains TAGNAME. |
667 Select the buffer containing the tag's definition, and move point there. | |
668 The default for TAGNAME is the expression in the buffer around or before point. | |
342 | 669 |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
670 If second arg NEXT-P is t (interactively, with prefix arg), search for |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
671 another tag that matches the last tagname or regexp used. When there are |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
672 multiple matches for a tag, more exact matches are found first. If NEXT-P |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
673 is the atom `-' (interactively, with prefix arg that is a negative number |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
674 or just \\[negative-argument]), pop back to the previous tag gone to. |
799 | 675 |
676 See documentation of variable `tags-file-name'." | |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
677 (interactive (find-tag-interactive "Find tag: ")) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
678 (switch-to-buffer (find-tag-noselect tagname next-p regexp-p))) |
799 | 679 ;;;###autoload (define-key esc-map "." 'find-tag) |
342 | 680 |
727 | 681 ;;;###autoload |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
682 (defun find-tag-other-window (tagname &optional next-p regexp-p) |
799 | 683 "Find tag (in current tags table) whose name contains TAGNAME. |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
684 Select the buffer containing the tag's definition in another window, and |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
685 move point there. The default for TAGNAME is the expression in the buffer |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
686 around or before point. |
799 | 687 |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
688 If second arg NEXT-P is t (interactively, with prefix arg), search for |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
689 another tag that matches the last tagname or regexp used. When there are |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
690 multiple matches for a tag, more exact matches are found first. If NEXT-P |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
691 is negative (interactively, with prefix arg that is a negative number or |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
692 just \\[negative-argument]), pop back to the previous tag gone to. |
799 | 693 |
694 See documentation of variable `tags-file-name'." | |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
695 (interactive (find-tag-interactive "Find tag other window: ")) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
696 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
697 ;; This hair is to deal with the case where the tag is found in the |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
698 ;; selected window's buffer; without the hair, point is moved in both |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
699 ;; windows. To prevent this, we save the selected window's point before |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
700 ;; doing find-tag-noselect, and restore it after. |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
701 (let* ((window-point (window-point (selected-window))) |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
702 (tagbuf (find-tag-noselect tagname next-p regexp-p)) |
1976
eda7eec8f8ad
* etags.el (find-tag-other-window): If another window is already
Jim Blandy <jimb@redhat.com>
parents:
1816
diff
changeset
|
703 (tagpoint (progn (set-buffer tagbuf) (point)))) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
704 (set-window-point (prog1 |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
705 (selected-window) |
1976
eda7eec8f8ad
* etags.el (find-tag-other-window): If another window is already
Jim Blandy <jimb@redhat.com>
parents:
1816
diff
changeset
|
706 (switch-to-buffer-other-window tagbuf) |
eda7eec8f8ad
* etags.el (find-tag-other-window): If another window is already
Jim Blandy <jimb@redhat.com>
parents:
1816
diff
changeset
|
707 ;; We have to set this new window's point; it |
eda7eec8f8ad
* etags.el (find-tag-other-window): If another window is already
Jim Blandy <jimb@redhat.com>
parents:
1816
diff
changeset
|
708 ;; might already have been displaying a |
eda7eec8f8ad
* etags.el (find-tag-other-window): If another window is already
Jim Blandy <jimb@redhat.com>
parents:
1816
diff
changeset
|
709 ;; different portion of tagbuf, in which case |
eda7eec8f8ad
* etags.el (find-tag-other-window): If another window is already
Jim Blandy <jimb@redhat.com>
parents:
1816
diff
changeset
|
710 ;; switch-to-buffer-other-window doesn't set |
eda7eec8f8ad
* etags.el (find-tag-other-window): If another window is already
Jim Blandy <jimb@redhat.com>
parents:
1816
diff
changeset
|
711 ;; the window's point from the buffer. |
eda7eec8f8ad
* etags.el (find-tag-other-window): If another window is already
Jim Blandy <jimb@redhat.com>
parents:
1816
diff
changeset
|
712 (set-window-point (selected-window) tagpoint)) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
713 window-point))) |
799 | 714 ;;;###autoload (define-key ctl-x-4-map "." 'find-tag-other-window) |
715 | |
804 | 716 ;;;###autoload |
799 | 717 (defun find-tag-other-frame (tagname &optional next-p) |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
718 "Find tag (in current tags table) whose name contains TAGNAME. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
719 Select the buffer containing the tag's definition in another frame, and |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
720 move point there. The default for TAGNAME is the expression in the buffer |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
721 around or before point. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
722 |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
723 If second arg NEXT-P is t (interactively, with prefix arg), search for |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
724 another tag that matches the last tagname or regexp used. When there are |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
725 multiple matches for a tag, more exact matches are found first. If NEXT-P |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
726 is negative (interactively, with prefix arg that is a negative number or |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
727 just \\[negative-argument]), pop back to the previous tag gone to. |
727 | 728 |
799 | 729 See documentation of variable `tags-file-name'." |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
730 (interactive (find-tag-interactive "Find tag other frame: ")) |
799 | 731 (let ((pop-up-frames t)) |
732 (find-tag-other-window tagname next-p))) | |
733 ;;;###autoload (define-key ctl-x-5-map "." 'find-tag-other-frame) | |
342 | 734 |
360 | 735 ;;;###autoload |
799 | 736 (defun find-tag-regexp (regexp &optional next-p other-window) |
737 "Find tag (in current tags table) whose name matches REGEXP. | |
738 Select the buffer containing the tag's definition and move point there. | |
739 | |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
740 If second arg NEXT-P is t (interactively, with prefix arg), search for |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
741 another tag that matches the last tagname or regexp used. When there are |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
742 multiple matches for a tag, more exact matches are found first. If NEXT-P |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
743 is negative (interactively, with prefix arg that is a negative number or |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
744 just \\[negative-argument]), pop back to the previous tag gone to. |
799 | 745 |
746 If third arg OTHER-WINDOW is non-nil, select the buffer in another window. | |
747 | |
748 See documentation of variable `tags-file-name'." | |
2590
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
749 (interactive (find-tag-interactive "Find tag regexp: " t)) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
750 ;; We go through find-tag-other-window to do all the display hair there. |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
751 (funcall (if other-window 'find-tag-other-window 'find-tag) |
9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
Roland McGrath <roland@gnu.org>
parents:
2448
diff
changeset
|
752 regexp next-p t)) |
799 | 753 |
754 ;; Internal tag finding function. | |
755 | |
756 ;; PATTERN is a string to pass to second arg SEARCH-FORWARD-FUNC, and to | |
757 ;; any member of the function list ORDER (third arg). If ORDER is nil, | |
758 ;; use saved state to continue a previous search. | |
759 | |
760 ;; Fourth arg MATCHING is a string, an English '-ing' word, to be used in | |
761 ;; an error message. | |
762 | |
763 ;; Fifth arg NEXT-LINE-AFTER-FAILURE-P is non-nil if after a failed match, | |
764 ;; point should be moved to the next line. | |
765 | |
766 ;; Algorithm is as follows. For each qualifier-func in ORDER, go to | |
767 ;; beginning of tags file, and perform inner loop: for each naive match for | |
768 ;; PATTERN found using SEARCH-FORWARD-FUNC, qualify the naive match using | |
769 ;; qualifier-func. If it qualifies, go to the specified line in the | |
770 ;; specified source file and return. Qualified matches are remembered to | |
771 ;; avoid repetition. State is saved so that the loop can be continued. | |
772 | |
1555
695c6eb2ff31
* etags.el (find-tag-noselect): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1397
diff
changeset
|
773 (defun find-tag-in-order (pattern |
695c6eb2ff31
* etags.el (find-tag-noselect): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1397
diff
changeset
|
774 search-forward-func |
695c6eb2ff31
* etags.el (find-tag-noselect): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1397
diff
changeset
|
775 order |
695c6eb2ff31
* etags.el (find-tag-noselect): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1397
diff
changeset
|
776 next-line-after-failure-p |
695c6eb2ff31
* etags.el (find-tag-noselect): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1397
diff
changeset
|
777 matching |
695c6eb2ff31
* etags.el (find-tag-noselect): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
1397
diff
changeset
|
778 first-search) |
799 | 779 (let (file ;name of file containing tag |
780 tag-info ;where to find the tag in FILE | |
781 tags-table-file ;name of tags file | |
782 (first-table t) | |
783 (tag-order order) | |
784 goto-func | |
785 ) | |
786 (save-excursion | |
1149 | 787 (or first-search ;find-tag-noselect has already done it. |
788 (visit-tags-table-buffer 'same)) | |
789 | |
799 | 790 ;; Get a qualified match. |
791 (catch 'qualified-match-found | |
1149 | 792 |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
793 ;; Iterate over the list of tags tables. |
799 | 794 (while (or first-table |
795 (visit-tags-table-buffer t)) | |
796 | |
797 (if first-search | |
798 (setq tag-lines-already-matched nil)) | |
799 | |
884 | 800 (and first-search first-table |
801 ;; Start at beginning of tags file. | |
802 (goto-char (point-min))) | |
803 (setq first-table nil) | |
799 | 804 |
805 (setq tags-table-file buffer-file-name) | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
806 ;; Iterate over the list of ordering predicates. |
799 | 807 (while order |
808 (while (funcall search-forward-func pattern nil t) | |
809 ;; Naive match found. Qualify the match. | |
810 (and (funcall (car order) pattern) | |
811 ;; Make sure it is not a previous qualified match. | |
812 ;; Use of `memq' depends on numbers being eq. | |
813 (not (memq (save-excursion (beginning-of-line) (point)) | |
814 tag-lines-already-matched)) | |
815 (throw 'qualified-match-found nil)) | |
816 (if next-line-after-failure-p | |
817 (forward-line 1))) | |
818 ;; Try the next flavor of match. | |
819 (setq order (cdr order)) | |
820 (goto-char (point-min))) | |
821 (setq order tag-order)) | |
822 ;; We throw out on match, so only get here if there were no matches. | |
823 (error "No %stags %s %s" (if first-search "" "more ") | |
824 matching pattern)) | |
825 | |
826 ;; Found a tag; extract location info. | |
827 (beginning-of-line) | |
828 (setq tag-lines-already-matched (cons (point) | |
829 tag-lines-already-matched)) | |
830 ;; Expand the filename, using the tags table buffer's default-directory. | |
831 (setq file (expand-file-name (file-of-tag)) | |
832 tag-info (funcall snarf-tag-function)) | |
833 | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
834 ;; Get the local value in the tags table buffer before switching buffers. |
799 | 835 (setq goto-func goto-tag-location-function) |
836 | |
837 ;; Find the right line in the specified file. | |
838 (set-buffer (find-file-noselect file)) | |
839 (widen) | |
840 (push-mark) | |
841 (funcall goto-func tag-info) | |
842 | |
843 ;; Give this buffer a local value of tags-file-name. | |
844 ;; The next time visit-tags-table-buffer is called, | |
845 ;; it will use the same tags table that found a match in this buffer. | |
846 (make-local-variable 'tags-file-name) | |
847 (setq tags-file-name tags-table-file) | |
848 | |
849 ;; Return the buffer where the tag was found. | |
850 (current-buffer)))) | |
851 | |
852 ;; `etags' TAGS file format support. | |
853 | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
854 ;; If the current buffer is a valid etags TAGS file, give it local values of |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
855 ;; the tags table format variables, and return non-nil. |
799 | 856 (defun etags-recognize-tags-table () |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
857 (and (etags-verify-tags-table) |
1136 | 858 ;; It is annoying to flash messages on the screen briefly, |
859 ;; and this message is not useful. -- rms | |
860 ;; (message "%s is an `etags' TAGS file" buffer-file-name) | |
799 | 861 (mapcar (function (lambda (elt) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
862 (set (make-local-variable (car elt)) (cdr elt)))) |
799 | 863 '((file-of-tag-function . etags-file-of-tag) |
864 (tags-table-files-function . etags-tags-table-files) | |
865 (tags-completion-table-function . etags-tags-completion-table) | |
866 (snarf-tag-function . etags-snarf-tag) | |
867 (goto-tag-location-function . etags-goto-tag-location) | |
868 (find-tag-regexp-search-function . re-search-forward) | |
869 (find-tag-regexp-tag-order . (tag-re-match-p)) | |
870 (find-tag-regexp-next-line-after-failuire-p . t) | |
871 (find-tag-search-function . search-forward) | |
872 (find-tag-tag-order . (tag-exact-match-p tag-word-match-p | |
873 tag-any-match-p)) | |
874 (find-tag-next-line-after-failure-p . nil) | |
875 (list-tags-function . etags-list-tags) | |
876 (tags-apropos-function . etags-tags-apropos) | |
877 (tags-included-tables-function . etags-tags-included-tables) | |
878 (verify-tags-table-function . etags-verify-tags-table) | |
879 )))) | |
880 | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
881 ;; Return non-nil iff the current buffer is a valid etags TAGS file. |
799 | 882 (defun etags-verify-tags-table () |
1723
4023bea27d64
(etags-verify-tags-table): Use eq instead of = in case char-after returns
Roland McGrath <roland@gnu.org>
parents:
1697
diff
changeset
|
883 ;; Use eq instead of = in case char-after returns nil. |
4023bea27d64
(etags-verify-tags-table): Use eq instead of = in case char-after returns
Roland McGrath <roland@gnu.org>
parents:
1697
diff
changeset
|
884 (eq (char-after 1) ?\f)) |
799 | 885 |
886 (defun etags-file-of-tag () | |
887 (save-excursion | |
888 (search-backward "\f\n") | |
889 (forward-char 2) | |
890 (buffer-substring (point) | |
891 (progn (skip-chars-forward "^,") (point))))) | |
892 | |
893 (defun etags-tags-completion-table () | |
894 (let ((table (make-vector 511 0))) | |
895 (save-excursion | |
896 (goto-char (point-min)) | |
2448
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
897 ;; This monster regexp matches an etags tag line. |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
898 ;; \1 is the string to match; |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
899 ;; \2 is not interesting; |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
900 ;; \3 is the guessed tag name; XXX guess should be better eg DEFUN |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
901 ;; \4 is the char to start searching at; |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
902 ;; \5 is the line to start searching at; |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
903 ;; \6 is not interesting; |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
904 ;; \7 is the explicitly-specified tag name. |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
905 (while (re-search-forward |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
906 "^\\(\\(.+[ \t]+\\)?\\([-a-zA-Z0-9_$]+\\)[^-a-zA-Z0-9_$]*\\)\177\ |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
907 \\([0-9]+\\),\\([0-9]+\\)\\(,\001\\([^\n]+\\)\\)?\n" |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
908 nil t) |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
909 (intern (if (match-beginning 6) |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
910 ;; There is an explicit tag name. |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
911 (buffer-substring (match-beginning 6) (match-end 6)) |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
912 ;; No explicit tag name. Best guess. |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
913 (buffer-substring (match-beginning 3) (match-end 3))) |
0d7fdb12dcdb
(etags-tags-completion-table): Rewritten with a mondo regexp.
Roland McGrath <roland@gnu.org>
parents:
2445
diff
changeset
|
914 table))) |
799 | 915 table)) |
916 | |
917 (defun etags-snarf-tag () | |
918 (let (tag-text startpos) | |
919 (search-forward "\177") | |
920 (setq tag-text (buffer-substring (1- (point)) | |
921 (save-excursion (beginning-of-line) | |
922 (point)))) | |
923 (search-forward ",") | |
924 (setq startpos (string-to-int (buffer-substring | |
925 (point) | |
926 (progn (skip-chars-forward "0-9") | |
927 (point))))) | |
928 ;; Leave point on the next line of the tags file. | |
929 (forward-line 1) | |
930 (cons tag-text startpos))) | |
931 | |
932 (defun etags-goto-tag-location (tag-info) | |
933 (let ((startpos (cdr tag-info)) | |
934 ;; This constant is 1/2 the initial search window. | |
935 ;; There is no sense in making it too small, | |
936 ;; since just going around the loop once probably | |
937 ;; costs about as much as searching 2000 chars. | |
938 (offset 1000) | |
939 (found nil) | |
940 (pat (concat "^" (regexp-quote (car tag-info))))) | |
941 (or startpos | |
942 (setq startpos (point-min))) | |
943 (while (and (not found) | |
944 (progn | |
945 (goto-char (- startpos offset)) | |
946 (not (bobp)))) | |
947 (setq found | |
948 (re-search-forward pat (+ startpos offset) t) | |
949 offset (* 3 offset))) ; expand search window | |
950 (or found | |
951 (re-search-forward pat nil t) | |
952 (error "`%s' not found in %s; time to rerun etags" | |
953 pat buffer-file-name))) | |
954 (beginning-of-line)) | |
955 | |
956 (defun etags-list-tags (file) | |
957 (goto-char 1) | |
958 (if (not (search-forward (concat "\f\n" file ",") nil t)) | |
959 nil | |
960 (forward-line 1) | |
961 (while (not (or (eobp) (looking-at "\f"))) | |
962 (princ (buffer-substring (point) | |
963 (progn (skip-chars-forward "^\177") | |
964 (point)))) | |
965 (terpri) | |
966 (forward-line 1)))) | |
967 | |
968 (defun etags-tags-apropos (string) | |
969 (goto-char 1) | |
970 (while (re-search-forward string nil t) | |
971 (beginning-of-line) | |
972 (princ (buffer-substring (point) | |
973 (progn (skip-chars-forward "^\177") | |
974 (point)))) | |
975 (terpri) | |
976 (forward-line 1))) | |
977 | |
978 (defun etags-tags-table-files () | |
979 (let ((files nil) | |
980 beg) | |
981 (goto-char (point-min)) | |
982 (while (search-forward "\f\n" nil t) | |
983 (setq beg (point)) | |
984 (skip-chars-forward "^,\n") | |
985 (or (looking-at ",include$") | |
986 ;; Expand in the default-directory of the tags table buffer. | |
987 (setq files (cons (expand-file-name (buffer-substring beg (point))) | |
988 files)))) | |
989 (nreverse files))) | |
990 | |
991 (defun etags-tags-included-tables () | |
992 (let ((files nil) | |
993 beg) | |
994 (goto-char (point-min)) | |
995 (while (search-forward "\f\n" nil t) | |
996 (setq beg (point)) | |
997 (skip-chars-forward "^,\n") | |
998 (if (looking-at ",include$") | |
999 ;; Expand in the default-directory of the tags table buffer. | |
1000 (setq files (cons (expand-file-name (buffer-substring beg (point))) | |
1001 files)))) | |
1002 (nreverse files))) | |
1003 | |
1004 ;; Empty tags file support. | |
1005 | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
1006 ;; Recognize an empty file and give it local values of the tags table format |
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
1007 ;; variables which do nothing. |
799 | 1008 (defun recognize-empty-tags-table () |
1009 (and (zerop (buffer-size)) | |
1010 (mapcar (function (lambda (sym) | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
1011 (set (make-local-variable sym) 'ignore))) |
799 | 1012 '(tags-table-files-function |
1013 tags-completion-table-function | |
1014 find-tag-regexp-search-function | |
1015 find-tag-search-function | |
1016 tags-apropos-function | |
1017 tags-included-tables-function)) | |
1018 (set (make-local-variable 'verify-tags-table-function) | |
1019 (function (lambda () | |
1020 (zerop (buffer-size))))))) | |
1021 | |
1022 ;;; Match qualifier functions for tagnames. | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
1023 ;;; XXX these functions assume etags file format. |
799 | 1024 |
884 | 1025 ;; This might be a neat idea, but it's too hairy at the moment. |
1026 ;;(defmacro tags-with-syntax (&rest body) | |
1027 ;; (` (let ((current (current-buffer)) | |
1028 ;; (otable (syntax-table)) | |
1029 ;; (buffer (find-file-noselect (file-of-tag))) | |
1030 ;; table) | |
1031 ;; (unwind-protect | |
1032 ;; (progn | |
1033 ;; (set-buffer buffer) | |
1034 ;; (setq table (syntax-table)) | |
1035 ;; (set-buffer current) | |
1036 ;; (set-syntax-table table) | |
1037 ;; (,@ body)) | |
1038 ;; (set-syntax-table otable))))) | |
1039 ;;(put 'tags-with-syntax 'edebug-form-spec '(&rest form)) | |
877 | 1040 |
799 | 1041 ;; t if point is at a tag line that matches TAG "exactly". |
1042 ;; point should be just after a string that matches TAG. | |
884 | 1043 (defun tag-exact-match-p (tag) |
1044 (and (looking-at "\\Sw.*\177") (looking-at "\\S_.*\177") ;not a symbol char | |
1045 (save-excursion | |
1046 (backward-char (1+ (length tag))) | |
1047 (and (looking-at "\\Sw") (looking-at "\\S_"))))) | |
799 | 1048 |
1049 ;; t if point is at a tag line that matches TAG as a word. | |
1050 ;; point should be just after a string that matches TAG. | |
1051 (defun tag-word-match-p (tag) | |
1052 (and (looking-at "\\b.*\177") | |
1053 (save-excursion (backward-char (1+ (length tag))) | |
1054 (looking-at "\\b")))) | |
1055 | |
1056 ;; t if point is in a tag line with a tag containing TAG as a substring. | |
1057 (defun tag-any-match-p (tag) | |
1058 (looking-at ".*\177")) | |
1059 | |
1060 ;; t if point is at a tag line that matches RE as a regexp. | |
1061 (defun tag-re-match-p (re) | |
1062 (save-excursion | |
1063 (beginning-of-line) | |
1064 (let ((bol (point))) | |
1065 (and (search-forward "\177" (save-excursion (end-of-line) (point)) t) | |
1066 (re-search-backward re bol t))))) | |
1067 | |
1068 ;;;###autoload | |
1069 (defun next-file (&optional initialize novisit) | |
1070 "Select next file among files in current tags table. | |
1071 Non-nil first argument (prefix arg, if interactive) | |
1072 initializes to the beginning of the list of files in the tags table. | |
1073 | |
1074 Non-nil second argument NOVISIT means use a temporary buffer | |
1075 to save time and avoid uninteresting warnings. | |
1076 | |
1077 Value is nil if the file was already visited; | |
1078 if the file was newly read in, the value is the filename." | |
342 | 1079 (interactive "P") |
799 | 1080 (and initialize |
1081 (save-excursion | |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
1082 ;; Visit the tags table buffer to get its list of files. |
1149 | 1083 (visit-tags-table-buffer) |
799 | 1084 (setq next-file-list (tags-table-files)))) |
342 | 1085 (or next-file-list |
799 | 1086 (save-excursion |
1397
d469afe703c4
(visit-tags-table-buffer): When trying to pick table, call
Roland McGrath <roland@gnu.org>
parents:
1156
diff
changeset
|
1087 ;; Get the files from the next tags table. |
1152 | 1088 ;; When doing (visit-tags-table-buffer t), |
799 | 1089 ;; the tags table buffer must be current. |
1090 (if (and (visit-tags-table-buffer 'same) | |
1091 (visit-tags-table-buffer t)) | |
1092 (setq next-file-list (tags-table-files)) | |
1093 (and novisit | |
1094 (get-buffer " *next-file*") | |
1095 (kill-buffer " *next-file*")) | |
1096 (error "All files processed.")))) | |
1097 (let ((new (not (get-file-buffer (car next-file-list))))) | |
1098 (if (not (and new novisit)) | |
1099 (set-buffer (find-file-noselect (car next-file-list) novisit)) | |
1100 ;; Like find-file, but avoids random warning messages. | |
1101 (set-buffer (get-buffer-create " *next-file*")) | |
1102 (kill-all-local-variables) | |
1103 (erase-buffer) | |
1104 (setq new (car next-file-list)) | |
1105 (insert-file-contents new nil)) | |
1106 (setq next-file-list (cdr next-file-list)) | |
1107 new)) | |
342 | 1108 |
799 | 1109 (defvar tags-loop-operate nil |
1110 "Form for `tags-loop-continue' to eval to change one file.") | |
1111 | |
1808
60685747963c
(tags-loop-scan): Set default value to an error form.
Roland McGrath <roland@gnu.org>
parents:
1807
diff
changeset
|
1112 (defvar tags-loop-scan |
60685747963c
(tags-loop-scan): Set default value to an error form.
Roland McGrath <roland@gnu.org>
parents:
1807
diff
changeset
|
1113 '(error (substitute-command-keys |
60685747963c
(tags-loop-scan): Set default value to an error form.
Roland McGrath <roland@gnu.org>
parents:
1807
diff
changeset
|
1114 "No \\[tags-search] or \\[tags-query-replace] in progress.")) |
799 | 1115 "Form for `tags-loop-continue' to eval to scan one file. |
1116 If it returns non-nil, this file needs processing by evalling | |
1117 \`tags-loop-operate'. Otherwise, move on to the next file.") | |
342 | 1118 |
360 | 1119 ;;;###autoload |
342 | 1120 (defun tags-loop-continue (&optional first-time) |
1121 "Continue last \\[tags-search] or \\[tags-query-replace] command. | |
799 | 1122 Used noninteractively with non-nil argument to begin such a command. |
1123 Two variables control the processing we do on each file: | |
1124 the value of `tags-loop-scan' is a form to be executed on each file | |
1125 to see if it is interesting (it returns non-nil if so) | |
1126 and `tags-loop-operate' is a form to execute to operate on an interesting file | |
1127 If the latter returns non-nil, we exit; otherwise we scan the next file." | |
342 | 1128 (interactive) |
799 | 1129 (let (new |
1130 (messaged nil)) | |
1131 (while | |
1132 (progn | |
1133 ;; Scan files quickly for the first or next interesting one. | |
1134 (while (or first-time | |
1135 (save-restriction | |
1136 (widen) | |
1137 (not (eval tags-loop-scan)))) | |
1138 (setq new (next-file first-time t)) | |
1139 ;; If NEW is non-nil, we got a temp buffer, | |
1140 ;; and NEW is the file name. | |
1141 (if (or messaged | |
1142 (and (not first-time) | |
1143 (> baud-rate search-slow-speed) | |
1144 (setq messaged t))) | |
1145 (message "Scanning file %s..." (or new buffer-file-name))) | |
1146 (setq first-time nil) | |
1147 (goto-char (point-min))) | |
1148 | |
1149 ;; If we visited it in a temp buffer, visit it now for real. | |
1150 (if new | |
1151 (let ((pos (point))) | |
1152 (erase-buffer) | |
1153 (set-buffer (find-file-noselect new)) | |
1154 (widen) | |
1155 (goto-char pos))) | |
1156 | |
1157 (switch-to-buffer (current-buffer)) | |
1158 | |
1159 ;; Now operate on the file. | |
1160 ;; If value is non-nil, continue to scan the next file. | |
1161 (eval tags-loop-operate))) | |
1162 (and messaged | |
1163 (null tags-loop-operate) | |
1164 (message "Scanning file %s...found" buffer-file-name)))) | |
1165 ;;;###autoload (define-key esc-map "," 'tags-loop-continue) | |
342 | 1166 |
360 | 1167 ;;;###autoload |
342 | 1168 (defun tags-search (regexp) |
799 | 1169 "Search through all files listed in tags table for match for REGEXP. |
342 | 1170 Stops when a match is found. |
1171 To continue searching for next match, use command \\[tags-loop-continue]. | |
1172 | |
799 | 1173 See documentation of variable `tags-file-name'." |
342 | 1174 (interactive "sTags search (regexp): ") |
1175 (if (and (equal regexp "") | |
799 | 1176 (eq (car tags-loop-scan) 're-search-forward) |
1696
cceb5375ce40
Many comments added and docstrings fixed.
Roland McGrath <roland@gnu.org>
parents:
1555
diff
changeset
|
1177 (null tags-loop-operate)) |
799 | 1178 ;; Continue last tags-search as if by M-,. |
342 | 1179 (tags-loop-continue nil) |
799 | 1180 (setq tags-loop-scan |
1181 (list 're-search-forward regexp nil t) | |
1182 tags-loop-operate nil) | |
342 | 1183 (tags-loop-continue t))) |
1184 | |
360 | 1185 ;;;###autoload |
342 | 1186 (defun tags-query-replace (from to &optional delimited) |
799 | 1187 "Query-replace-regexp FROM with TO through all files listed in tags table. |
342 | 1188 Third arg DELIMITED (prefix arg) means replace only word-delimited matches. |
799 | 1189 If you exit (\\[keyboard-quit] or ESC), you can resume the query-replace |
342 | 1190 with the command \\[tags-loop-continue]. |
1191 | |
799 | 1192 See documentation of variable `tags-file-name'." |
1193 (interactive | |
1194 "sTags query replace (regexp): \nsTags query replace %s by: \nP") | |
804 | 1195 (setq tags-loop-scan (list 'prog1 |
1816 | 1196 (list 'if (list 're-search-forward from nil t) |
804 | 1197 ;; When we find a match, move back |
1198 ;; to the beginning of it so perform-replace | |
1199 ;; will see it. | |
1200 '(goto-char (match-beginning 0)))) | |
799 | 1201 tags-loop-operate (list 'perform-replace from to t t delimited)) |
342 | 1202 (tags-loop-continue t)) |
799 | 1203 |
1204 ;;;###autoload | |
1205 (defun list-tags (file) | |
1206 "Display list of tags in file FILE. | |
1207 FILE should not contain a directory specification | |
1208 unless it has one in the tags table." | |
1209 (interactive (list (completing-read "List tags in file: " nil | |
1210 'tags-table-files t nil))) | |
1211 (with-output-to-temp-buffer "*Tags List*" | |
1212 (princ "Tags in file ") | |
1213 (princ file) | |
1214 (terpri) | |
1215 (save-excursion | |
1216 (let ((first-time t) | |
1217 (gotany nil)) | |
1149 | 1218 (while (visit-tags-table-buffer (not first-time)) |
799 | 1219 (if (funcall list-tags-function file) |
1220 (setq gotany t))) | |
1221 (or gotany | |
1222 (error "File %s not in current tags tables")))))) | |
342 | 1223 |
360 | 1224 ;;;###autoload |
799 | 1225 (defun tags-apropos (regexp) |
1226 "Display list of all tags in tags table REGEXP matches." | |
1227 (interactive "sTags apropos (regexp): ") | |
342 | 1228 (with-output-to-temp-buffer "*Tags List*" |
799 | 1229 (princ "Tags matching regexp ") |
1230 (prin1 regexp) | |
342 | 1231 (terpri) |
1232 (save-excursion | |
1149 | 1233 (let ((first-time t)) |
1234 (while (visit-tags-table-buffer (not first-time)) | |
1235 (setq first-time nil) | |
1151 | 1236 (funcall tags-apropos-function regexp)))))) |
799 | 1237 |
1238 ;;; XXX Kludge interface. | |
342 | 1239 |
799 | 1240 ;; XXX If a file is in multiple tables, selection may get the wrong one. |
804 | 1241 ;;;###autoload |
799 | 1242 (defun select-tags-table () |
1243 "Select a tags table file from a menu of those you have already used. | |
1244 The list of tags tables to select from is stored in `tags-table-file-list'; | |
1245 see the doc of that variable if you want to add names to the list." | |
1246 (interactive) | |
1247 (pop-to-buffer "*Tags Table List*") | |
1248 (setq buffer-read-only nil) | |
1249 (erase-buffer) | |
1250 (setq selective-display t | |
1251 selective-display-ellipses nil) | |
1252 (let ((set-list tags-table-set-list) | |
1253 (desired-point nil)) | |
1254 (if tags-table-list | |
1255 (progn | |
1256 (setq desired-point (point-marker)) | |
1257 (princ tags-table-list (current-buffer)) | |
1258 (insert "\C-m") | |
1259 (prin1 (car tags-table-list) (current-buffer)) ;invisible | |
1260 (insert "\n"))) | |
1261 (while set-list | |
1262 (if (eq (car set-list) tags-table-list) | |
1263 ;; Already printed it. | |
1264 () | |
1265 (princ (car set-list) (current-buffer)) | |
1266 (insert "\C-m") | |
1267 (prin1 (car (car set-list)) (current-buffer)) ;invisible | |
1268 (insert "\n")) | |
1269 (setq set-list (cdr set-list))) | |
1270 (if tags-file-name | |
1271 (progn | |
1272 (or desired-point | |
1273 (setq desired-point (point-marker))) | |
1274 (insert tags-file-name "\C-m") | |
1275 (prin1 tags-file-name (current-buffer)) ;invisible | |
1276 (insert "\n"))) | |
1277 (setq set-list (delete tags-file-name | |
1278 (apply 'nconc (cons tags-table-list | |
1279 (mapcar 'copy-sequence | |
1280 tags-table-set-list))))) | |
1281 (while set-list | |
1282 (insert (car set-list) "\C-m") | |
1283 (prin1 (car set-list) (current-buffer)) ;invisible | |
1284 (insert "\n") | |
1285 (setq set-list (delete (car set-list) set-list))) | |
1286 (goto-char 1) | |
1287 (insert-before-markers | |
1288 "Type `t' to select a tags table or set of tags tables:\n\n") | |
1289 (if desired-point | |
1290 (goto-char desired-point)) | |
1291 (set-window-start (selected-window) 1 t)) | |
1292 (set-buffer-modified-p nil) | |
1293 (setq buffer-read-only t | |
1294 mode-name "Select Tags Table") | |
1295 (let ((map (make-sparse-keymap))) | |
1296 (define-key map "t" 'select-tags-table-select) | |
1297 (define-key map " " 'next-line) | |
1298 (define-key map "\^?" 'previous-line) | |
1299 (define-key map "n" 'next-line) | |
1300 (define-key map "p" 'previous-line) | |
1301 (define-key map "q" 'select-tags-table-quit) | |
1302 (use-local-map map))) | |
1303 | |
1304 (defun select-tags-table-select () | |
1305 "Select the tags table named on this line." | |
1306 (interactive) | |
1307 (search-forward "\C-m") | |
1308 (let ((name (read (current-buffer)))) | |
1309 (visit-tags-table name) | |
1310 (select-tags-table-quit) | |
1311 (message "Tags table now %s" name))) | |
1312 | |
1313 (defun select-tags-table-quit () | |
1314 "Kill the buffer and delete the selected window." | |
1315 (interactive) | |
1316 (kill-buffer (current-buffer)) | |
1317 (or (one-window-p) | |
1318 (delete-window))) | |
1319 | |
360 | 1320 ;;;###autoload |
799 | 1321 (defun complete-tag () |
1322 "Perform tags completion on the text around point. | |
1323 Completes to the set of names listed in the current tags table. | |
1324 The string to complete is chosen in the same way as the default | |
981 | 1325 for \\[find-tag] (which see)." |
799 | 1326 (interactive) |
981 | 1327 (or tags-table-list |
1328 tags-file-name | |
1329 (error (substitute-command-keys | |
1330 "No tags table loaded. Try \\[visit-tags-table]."))) | |
799 | 1331 (let ((pattern (funcall (or find-tag-default-function |
1332 (get major-mode 'find-tag-default-function) | |
1333 'find-tag-default))) | |
1334 beg | |
1335 completion) | |
1336 (or pattern | |
1337 (error "Nothing to complete")) | |
1338 (search-backward pattern) | |
1339 (setq beg (point)) | |
1340 (forward-char (length pattern)) | |
1341 (setq completion (try-completion pattern 'tags-complete-tag nil)) | |
1342 (cond ((eq completion t)) | |
1343 ((null completion) | |
1344 (message "Can't find completion for \"%s\"" pattern) | |
1345 (ding)) | |
1346 ((not (string= pattern completion)) | |
1347 (delete-region beg (point)) | |
1348 (insert completion)) | |
1349 (t | |
1350 (message "Making completion list...") | |
1351 (with-output-to-temp-buffer " *Completions*" | |
1352 (display-completion-list | |
1353 (all-completions pattern 'tags-complete-tag nil))) | |
1354 (message "Making completion list...%s" "done"))))) | |
884 | 1355 |
1356 ;;;###autoload (define-key esc-map "\t" 'complete-tag) | |
799 | 1357 |
584 | 1358 (provide 'etags) |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
1359 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
804
diff
changeset
|
1360 ;;; etags.el ends here |