| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
(require 'ring) |
|---|
| 33 |
(require 'button) |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
(defvar tags-file-name nil |
|---|
| 37 |
"*File name of tags table. |
|---|
| 38 |
To switch to a new tags table, setting this variable is sufficient. |
|---|
| 39 |
If you set this variable, do not also set `tags-table-list'. |
|---|
| 40 |
Use the `etags' program to make a tags table file.") |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
(defgroup etags nil "Tags tables." |
|---|
| 45 |
:group 'tools) |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
(defcustom tags-case-fold-search 'default |
|---|
| 49 |
"*Whether tags operations should be case-sensitive. |
|---|
| 50 |
A value of t means case-insensitive, a value of nil means case-sensitive. |
|---|
| 51 |
Any other value means use the setting of `case-fold-search'." |
|---|
| 52 |
:group 'etags |
|---|
| 53 |
:type '(choice (const :tag "Case-sensitive" nil) |
|---|
| 54 |
(const :tag "Case-insensitive" t) |
|---|
| 55 |
(other :tag "Use default" default)) |
|---|
| 56 |
:version "21.1") |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
(defcustom tags-table-list nil |
|---|
| 61 |
"*List of file names of tags tables to search. |
|---|
| 62 |
An element that is a directory means the file \"TAGS\" in that directory. |
|---|
| 63 |
To switch to a new list of tags tables, setting this variable is sufficient. |
|---|
| 64 |
If you set this variable, do not also set `tags-file-name'. |
|---|
| 65 |
Use the `etags' program to make a tags table file." |
|---|
| 66 |
:group 'etags |
|---|
| 67 |
:type '(repeat file)) |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
(defcustom tags-compression-info-list '("" ".Z" ".bz2" ".gz" ".tgz") |
|---|
| 71 |
"*List of extensions tried by etags when jka-compr is used. |
|---|
| 72 |
An empty string means search the non-compressed file. |
|---|
| 73 |
These extensions will be tried only if jka-compr was activated |
|---|
| 74 |
\(i.e. via customize of `auto-compression-mode' or by calling the function |
|---|
| 75 |
`auto-compression-mode')." |
|---|
| 76 |
:type '(repeat string) |
|---|
| 77 |
:group 'etags) |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
(defcustom tags-add-tables 'ask-user |
|---|
| 91 |
"*Control whether to add a new tags table to the current list. |
|---|
| 92 |
t means do; nil means don't (always start a new list). |
|---|
| 93 |
Any other value means ask the user whether to add a new tags table |
|---|
| 94 |
to the current list (as opposed to starting a new list)." |
|---|
| 95 |
:group 'etags |
|---|
| 96 |
:type '(choice (const :tag "Do" t) |
|---|
| 97 |
(const :tag "Don't" nil) |
|---|
| 98 |
(other :tag "Ask" ask-user))) |
|---|
| 99 |
|
|---|
| 100 |
(defcustom tags-revert-without-query nil |
|---|
| 101 |
"*Non-nil means reread a TAGS table without querying, if it has changed." |
|---|
| 102 |
:group 'etags |
|---|
| 103 |
:type 'boolean) |
|---|
| 104 |
|
|---|
| 105 |
(defvar tags-table-computed-list nil |
|---|
| 106 |
"List of tags tables to search, computed from `tags-table-list'. |
|---|
| 107 |
This includes tables implicitly included by other tables. The list is not |
|---|
| 108 |
always complete: the included tables of a table are not known until that |
|---|
| 109 |
table is read into core. An element that is t is a placeholder |
|---|
| 110 |
indicating that the preceding element is a table that has not been read |
|---|
| 111 |
into core and might contain included tables to search. |
|---|
| 112 |
See `tags-table-check-computed-list'.") |
|---|
| 113 |
|
|---|
| 114 |
(defvar tags-table-computed-list-for nil |
|---|
| 115 |
"Value of `tags-table-list' that `tags-table-computed-list' corresponds to. |
|---|
| 116 |
If `tags-table-list' changes, `tags-table-computed-list' is thrown away and |
|---|
| 117 |
recomputed; see `tags-table-check-computed-list'.") |
|---|
| 118 |
|
|---|
| 119 |
(defvar tags-table-list-pointer nil |
|---|
| 120 |
"Pointer into `tags-table-computed-list' for the current state of searching. |
|---|
| 121 |
Use `visit-tags-table-buffer' to cycle through tags tables in this list.") |
|---|
| 122 |
|
|---|
| 123 |
(defvar tags-table-list-started-at nil |
|---|
| 124 |
"Pointer into `tags-table-computed-list', where the current search started.") |
|---|
| 125 |
|
|---|
| 126 |
(defvar tags-table-set-list nil |
|---|
| 127 |
"List of sets of tags table which have been used together in the past. |
|---|
| 128 |
Each element is a list of strings which are file names.") |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
(defcustom find-tag-hook nil |
|---|
| 132 |
"*Hook to be run by \\[find-tag] after finding a tag. See `run-hooks'. |
|---|
| 133 |
The value in the buffer in which \\[find-tag] is done is used, |
|---|
| 134 |
not the value in the buffer \\[find-tag] goes to." |
|---|
| 135 |
:group 'etags |
|---|
| 136 |
:type 'hook) |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
(defcustom find-tag-default-function nil |
|---|
| 140 |
"*A function of no arguments used by \\[find-tag] to pick a default tag. |
|---|
| 141 |
If nil, and the symbol that is the value of `major-mode' |
|---|
| 142 |
has a `find-tag-default-function' property (see `put'), that is used. |
|---|
| 143 |
Otherwise, `find-tag-default' is used." |
|---|
| 144 |
:group 'etags |
|---|
| 145 |
:type '(choice (const nil) function)) |
|---|
| 146 |
|
|---|
| 147 |
(defcustom find-tag-marker-ring-length 16 |
|---|
| 148 |
"*Length of marker rings `find-tag-marker-ring' and `tags-location-ring'." |
|---|
| 149 |
:group 'etags |
|---|
| 150 |
:type 'integer |
|---|
| 151 |
:version "20.3") |
|---|
| 152 |
|
|---|
| 153 |
(defcustom tags-tag-face 'default |
|---|
| 154 |
"*Face for tags in the output of `tags-apropos'." |
|---|
| 155 |
:group 'etags |
|---|
| 156 |
:type 'face |
|---|
| 157 |
:version "21.1") |
|---|
| 158 |
|
|---|
| 159 |
(defcustom tags-apropos-verbose nil |
|---|
| 160 |
"If non-nil, print the name of the tags file in the *Tags List* buffer." |
|---|
| 161 |
:group 'etags |
|---|
| 162 |
:type 'boolean |
|---|
| 163 |
:version "21.1") |
|---|
| 164 |
|
|---|
| 165 |
(defcustom tags-apropos-additional-actions nil |
|---|
| 166 |
"Specify additional actions for `tags-apropos'. |
|---|
| 167 |
|
|---|
| 168 |
If non-nil, value should be a list of triples (TITLE FUNCTION |
|---|
| 169 |
TO-SEARCH). For each triple, `tags-apropos' processes TO-SEARCH and |
|---|
| 170 |
lists tags from it. TO-SEARCH should be an alist, obarray, or symbol. |
|---|
| 171 |
If it is a symbol, the symbol's value is used. |
|---|
| 172 |
TITLE, a string, is a title used to label the additional list of tags. |
|---|
| 173 |
FUNCTION is a function to call when a symbol is selected in the |
|---|
| 174 |
*Tags List* buffer. It will be called with one argument SYMBOL which |
|---|
| 175 |
is the symbol being selected. |
|---|
| 176 |
|
|---|
| 177 |
Example value: |
|---|
| 178 |
|
|---|
| 179 |
'((\"Emacs Lisp\" Info-goto-emacs-command-node obarray) |
|---|
| 180 |
(\"Common Lisp\" common-lisp-hyperspec common-lisp-hyperspec-obarray) |
|---|
| 181 |
(\"SCWM\" scwm-documentation scwm-obarray))" |
|---|
| 182 |
:group 'etags |
|---|
| 183 |
:type '(repeat (list (string :tag "Title") |
|---|
| 184 |
function |
|---|
| 185 |
(sexp :tag "Tags to search"))) |
|---|
| 186 |
:version "21.1") |
|---|
| 187 |
|
|---|
| 188 |
(defvar find-tag-marker-ring (make-ring find-tag-marker-ring-length) |
|---|
| 189 |
"Ring of markers which are locations from which \\[find-tag] was invoked.") |
|---|
| 190 |
|
|---|
| 191 |
(defvar default-tags-table-function nil |
|---|
| 192 |
"If non-nil, a function to choose a default tags file for a buffer. |
|---|
| 193 |
This function receives no arguments and should return the default |
|---|
| 194 |
tags table file to use for the current buffer.") |
|---|
| 195 |
|
|---|
| 196 |
(defvar tags-location-ring (make-ring find-tag-marker-ring-length) |
|---|
| 197 |
"Ring of markers which are locations visited by \\[find-tag]. |
|---|
| 198 |
Pop back to the last location with \\[negative-argument] \\[find-tag].") |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
(defvar tags-table-files nil |
|---|
| 204 |
"List of file names covered by current tags table. |
|---|
| 205 |
nil means it has not yet been computed; use `tags-table-files' to do so.") |
|---|
| 206 |
|
|---|
| 207 |
(defvar tags-completion-table nil |
|---|
| 208 |
"Obarray of tag names defined in current tags table.") |
|---|
| 209 |
|
|---|
| 210 |
(defvar tags-included-tables nil |
|---|
| 211 |
"List of tags tables included by the current tags table.") |
|---|
| 212 |
|
|---|
| 213 |
(defvar next-file-list nil |
|---|
| 214 |
"List of files for \\[next-file] to process.") |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
(defvar tags-table-format-functions '(etags-recognize-tags-table |
|---|
| 219 |
tags-recognize-empty-tags-table) |
|---|
| 220 |
"Hook to be called in a tags table buffer to identify the type of tags table. |
|---|
| 221 |
The functions are called in order, with no arguments, |
|---|
| 222 |
until one returns non-nil. The function should make buffer-local bindings |
|---|
| 223 |
of the format-parsing tags function variables if successful.") |
|---|
| 224 |
|
|---|
| 225 |
(defvar file-of-tag-function nil |
|---|
| 226 |
"Function to do the work of `file-of-tag' (which see). |
|---|
| 227 |
One optional argument, a boolean specifying to return complete path (nil) or |
|---|
| 228 |
relative path (non-nil).") |
|---|
| 229 |
(defvar tags-table-files-function nil |
|---|
| 230 |
"Function to do the work of `tags-table-files' (which see).") |
|---|
| 231 |
(defvar tags-completion-table-function nil |
|---|
| 232 |
"Function to build the `tags-completion-table'.") |
|---|
| 233 |
(defvar snarf-tag-function nil |
|---|
| 234 |
"Function to get info about a matched tag for `goto-tag-location-function'. |
|---|
| 235 |
One optional argument, specifying to use explicit tag (non-nil) or not (nil). |
|---|
| 236 |
The default is nil.") |
|---|
| 237 |
(defvar goto-tag-location-function nil |
|---|
| 238 |
"Function of to go to the location in the buffer specified by a tag. |
|---|
| 239 |
One argument, the tag info returned by `snarf-tag-function'.") |
|---|
| 240 |
(defvar find-tag-regexp-search-function nil |
|---|
| 241 |
"Search function passed to `find-tag-in-order' for finding a regexp tag.") |
|---|
| 242 |
(defvar find-tag-regexp-tag-order nil |
|---|
| 243 |
"Tag order passed to `find-tag-in-order' for finding a regexp tag.") |
|---|
| 244 |
(defvar find-tag-regexp-next-line-after-failure-p nil |
|---|
| 245 |
"Flag passed to `find-tag-in-order' for finding a regexp tag.") |
|---|
| 246 |
(defvar find-tag-search-function nil |
|---|
| 247 |
"Search function passed to `find-tag-in-order' for finding a tag.") |
|---|
| 248 |
(defvar find-tag-tag-order nil |
|---|
| 249 |
"Tag order passed to `find-tag-in-order' for finding a tag.") |
|---|
| 250 |
(defvar find-tag-next-line-after-failure-p nil |
|---|
| 251 |
"Flag passed to `find-tag-in-order' for finding a tag.") |
|---|
| 252 |
(defvar list-tags-function nil |
|---|
| 253 |
"Function to do the work of `list-tags' (which see).") |
|---|
| 254 |
(defvar tags-apropos-function nil |
|---|
| 255 |
"Function to do the work of `tags-apropos' (which see).") |
|---|
| 256 |
(defvar tags-included-tables-function nil |
|---|
| 257 |
"Function to do the work of `tags-included-tables' (which see).") |
|---|
| 258 |
(defvar verify-tags-table-function nil |
|---|
| 259 |
"Function to return t if current buffer contains valid tags file.") |
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
(defun initialize-new-tags-table () |
|---|
| 266 |
(set (make-local-variable 'tags-table-files) nil) |
|---|
| 267 |
(set (make-local-variable 'tags-completion-table) nil) |
|---|
| 268 |
(set (make-local-variable 'tags-included-tables) nil) |
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
(run-hook-with-args-until-success 'tags-table-format-functions)) |
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
(defun tags-table-mode () |
|---|
| 278 |
"Major mode for tags table file buffers." |
|---|
| 279 |
(interactive) |
|---|
| 280 |
(setq major-mode 'tags-table-mode |
|---|
| 281 |
mode-name "Tags Table" |
|---|
| 282 |
buffer-undo-list t) |
|---|
| 283 |
(initialize-new-tags-table)) |
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
(defun visit-tags-table (file &optional local) |
|---|
| 287 |
"Tell tags commands to use tags table file FILE. |
|---|
| 288 |
FILE should be the name of a file created with the `etags' program. |
|---|
| 289 |
A directory name is ok too; it means file TAGS in that directory. |
|---|
| 290 |
|
|---|
| 291 |
Normally \\[visit-tags-table] sets the global value of `tags-file-name'. |
|---|
| 292 |
With a prefix arg, set the buffer-local value instead. |
|---|
| 293 |
When you find a tag with \\[find-tag], the buffer it finds the tag |
|---|
| 294 |
in is given a local value of this variable which is the name of the tags |
|---|
| 295 |
file the tag was in." |
|---|
| 296 |
(interactive (list (read-file-name "Visit tags table (default TAGS): " |
|---|
| 297 |
default-directory |
|---|
| 298 |
(expand-file-name "TAGS" |
|---|
| 299 |
default-directory) |
|---|
| 300 |
t) |
|---|
| 301 |
current-prefix-arg)) |
|---|
| 302 |
(or (stringp file) (signal 'wrong-type-argument (list 'stringp file))) |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
(let ((tags-file-name file)) |
|---|
| 310 |
(save-excursion |
|---|
| 311 |
(or (visit-tags-table-buffer file) |
|---|
| 312 |
(signal 'file-error (list "Visiting tags table" |
|---|
| 313 |
"file does not exist" |
|---|
| 314 |
file))) |
|---|
| 315 |
|
|---|
| 316 |
(setq file tags-file-name))) |
|---|
| 317 |
(if local |
|---|
| 318 |
|
|---|
| 319 |
(set (make-local-variable 'tags-file-name) file) |
|---|
| 320 |
|
|---|
| 321 |
(setq-default tags-file-name file))) |
|---|
| 322 |
|
|---|
| 323 |
(defun tags-table-check-computed-list () |
|---|
| 324 |
"Compute `tags-table-computed-list' from `tags-table-list' if necessary." |
|---|
| 325 |
(let ((expanded-list (mapcar 'tags-expand-table-name tags-table-list))) |
|---|
| 326 |
(or (equal tags-table-computed-list-for expanded-list) |
|---|
| 327 |
|
|---|
| 328 |
(let* ((compute-for (mapcar 'copy-sequence expanded-list)) |
|---|
| 329 |
(tables (copy-sequence compute-for)) |
|---|
| 330 |
(computed nil) |
|---|
| 331 |
table-buffer) |
|---|
| 332 |
|
|---|
| 333 |
(while tables |
|---|
| 334 |
(setq computed (cons (car tables) computed) |
|---|
| 335 |
table-buffer (get-file-buffer (car tables))) |
|---|
| 336 |
(if (and table-buffer |
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
(save-excursion |
|---|
| 340 |
(tags-verify-table (buffer-file-name table-buffer)))) |
|---|
| 341 |
(save-excursion |
|---|
| 342 |
(set-buffer table-buffer) |
|---|
| 343 |
(if (tags-included-tables) |
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
(setcdr tables (nconc (mapcar 'tags-expand-table-name |
|---|
| 347 |
(tags-included-tables)) |
|---|
| 348 |
(cdr tables))))) |
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
(setq computed (cons t computed))) |
|---|
| 353 |
(setq tables (cdr tables))) |
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
(setq tags-table-computed-list-for compute-for |
|---|
| 358 |
tags-table-computed-list (nreverse computed)))))) |
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
(defun tags-table-extend-computed-list () |
|---|
| 367 |
(let ((list tags-table-computed-list)) |
|---|
| 368 |
(while (not (eq (nth 1 list) t)) |
|---|
| 369 |
(setq list (cdr list))) |
|---|
| 370 |
(save-excursion |
|---|
| 371 |
(if (tags-verify-table (car list)) |
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
(let ((tables (tags-included-tables)) |
|---|
| 375 |
(computed nil) |
|---|
| 376 |
table-buffer) |
|---|
| 377 |
(while tables |
|---|
| 378 |
(setq computed (cons (car tables) computed) |
|---|
| 379 |
table-buffer (get-file-buffer (car tables))) |
|---|
| 380 |
(if table-buffer |
|---|
| 381 |
(save-excursion |
|---|
| 382 |
(set-buffer table-buffer) |
|---|
| 383 |
(if (tags-included-tables) |
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
(setcdr tables (append (tags-included-tables) |
|---|
| 387 |
tables)))) |
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
(setq computed (cons t computed))) |
|---|
| 392 |
(setq tables (cdr tables))) |
|---|
| 393 |
(setq computed (nreverse computed)) |
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
(setcdr list (nconc computed (cdr (cdr list))))) |
|---|
| 398 |
|
|---|
| 399 |
(setcdr list (cdr (cdr list))))))) |
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
(defun tags-expand-table-name (file) |
|---|
| 403 |
(setq file (expand-file-name file)) |
|---|
| 404 |
(if (file-directory-p file) |
|---|
| 405 |
(expand-file-name "TAGS" file) |
|---|
| 406 |
file)) |
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
(defun tags-table-list-member (file list) |
|---|
| 411 |
(setq file (tags-expand-table-name file)) |
|---|
| 412 |
(while (and list |
|---|
| 413 |
(or (eq (car list) t) |
|---|
| 414 |
(not (string= file (tags-expand-table-name (car list)))))) |
|---|
| 415 |
(setq list (cdr list))) |
|---|
| 416 |
list) |
|---|
| 417 |
|
|---|
| 418 |
(defun tags-verify-table (file) |
|---|
| 419 |
"Read FILE into a buffer and verify that it is a valid tags table. |
|---|
| 420 |
Sets the current buffer to one visiting FILE (if it exists). |
|---|
| 421 |
Returns non-nil if it is a valid table." |
|---|
| 422 |
(if (get-file-buffer file) |
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
(let (win) |
|---|
| 426 |
(set-buffer (get-file-buffer file)) |
|---|
| 427 |
(setq win (or verify-tags-table-function (tags-table-mode))) |
|---|
| 428 |
(if (or (verify-visited-file-modtime (current-buffer)) |
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
(not (or (let ((tail revert-without-query) |
|---|
| 433 |
(found nil)) |
|---|
| 434 |
(while tail |
|---|
| 435 |
(if (string-match (car tail) buffer-file-name) |
|---|
| 436 |
(setq found t)) |
|---|
| 437 |
(setq tail (cdr tail))) |
|---|
| 438 |
found) |
|---|
| 439 |
tags-revert-without-query |
|---|
| 440 |
(yes-or-no-p |
|---|
| 441 |
(format "Tags file %s has changed, read new contents? " |
|---|
| 442 |
file))))) |
|---|
| 443 |
(and verify-tags-table-function |
|---|
| 444 |
(funcall verify-tags-table-function)) |
|---|
| 445 |
(revert-buffer t t) |
|---|
| 446 |
(tags-table-mode))) |
|---|
| 447 |
(and (file-exists-p file) |
|---|
| 448 |
(progn |
|---|
| 449 |
(set-buffer (find-file-noselect file)) |
|---|
| 450 |
(or (string= file buffer-file-name) |
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
(let ((tail (member file tags-table-list))) |
|---|
| 454 |
(if tail |
|---|
| 455 |
(setcar tail buffer-file-name)) |
|---|
| 456 |
(if (eq file tags-file-name) |
|---|
| 457 |
(setq tags-file-name buffer-file-name)))) |
|---|
| 458 |
(tags-table-mode))))) |
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
(defun tags-table-including (this-file core-only) |
|---|
| 467 |
(let ((tables tags-table-computed-list) |
|---|
| 468 |
(found nil)) |
|---|
| 469 |
|
|---|
| 470 |
(while (and (not found) |
|---|
| 471 |
tables) |
|---|
| 472 |
|
|---|
| 473 |
(if core-only |
|---|
| 474 |
|
|---|
| 475 |
(while (eq (nth 1 tables) t) |
|---|
| 476 |
(setq tables (cdr (cdr tables)))) |
|---|
| 477 |
(if (eq (nth 1 tables) t) |
|---|
| 478 |
|
|---|
| 479 |
(tags-table-extend-computed-list))) |
|---|
| 480 |
|
|---|
| 481 |
(if tables |
|---|
| 482 |
|
|---|
| 483 |
(let ((tags-file-name (car tables))) |
|---|
| 484 |
(visit-tags-table-buffer 'same) |
|---|
| 485 |
(if (member this-file (mapcar 'expand-file-name |
|---|
| 486 |
(tags-table-files))) |
|---|
| 487 |
|
|---|
| 488 |
(setq found tables)))) |
|---|
| 489 |
(setq tables (cdr tables))) |
|---|
| 490 |
(if found |
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
(let ((could-be nil) |
|---|
| 498 |
(elt tags-table-computed-list)) |
|---|
| 499 |
(while (not (eq elt (cdr found))) |
|---|
| 500 |
(if (tags-table-list-member (car elt) tags-table-list) |
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
(setq could-be (car elt))) |
|---|
| 504 |
(setq elt (cdr elt)) |
|---|
| 505 |
(if (eq t (car elt)) |
|---|
| 506 |
(setq elt (cdr elt)))) |
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
could-be)))) |
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
(defun tags-next-table () |
|---|
| 515 |
|
|---|
| 516 |
(while (eq (nth 1 tags-table-list-pointer) t) |
|---|
| 517 |
(tags-table-extend-computed-list)) |
|---|
| 518 |
|
|---|
| 519 |
|
|---|
| 520 |
(setq tags-table-list-pointer (cdr tags-table-list-pointer)) |
|---|
| 521 |
(or tags-table-list-pointer |
|---|
| 522 |
|
|---|
| 523 |
(setq tags-table-list-pointer tags-table-computed-list)) |
|---|
| 524 |
|
|---|
| 525 |
(if (eq tags-table-list-pointer tags-table-list-started-at) |
|---|
| 526 |
|
|---|
| 527 |
(setq tags-table-list-pointer nil) |
|---|
| 528 |
|
|---|
| 529 |
(setq tags-file-name (car tags-table-list-pointer)))) |
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
(defun visit-tags-table-buffer (&optional cont) |
|---|
| 533 |
"Select the buffer containing the current tags table. |
|---|
| 534 |
If optional arg is a string, visit that file as a tags table. |
|---|
| 535 |
If optional arg is t, visit the next table in `tags-table-list'. |
|---|
| 536 |
If optional arg is the atom `same', don't look for a new table; |
|---|
| 537 |
just select the buffer visiting `tags-file-name'. |
|---|
| 538 |
If arg is nil or absent, choose a first buffer from information in |
|---|
| 539 |
`tags-file-name', `tags-table-list', `tags-table-list-pointer'. |
|---|
| 540 |
Returns t if it visits a tags table, or nil if there are no more in the list." |
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
(cond ((eq cont 'same) |
|---|
| 544 |
|
|---|
| 545 |
(or tags-file-name |
|---|
| 546 |
(error "%s" |
|---|
| 547 |
(substitute-command-keys |
|---|
| 548 |
(concat "No tags table in use; " |
|---|
| 549 |
"use \\[visit-tags-table] to select one"))))) |
|---|
| 550 |
|
|---|
| 551 |
((eq t cont) |
|---|
| 552 |
|
|---|
| 553 |
(if (tags-next-table) |
|---|
| 554 |
|
|---|
| 555 |
(while (and (not (or (get-file-buffer tags-file-name) |
|---|
| 556 |
(file-exists-p tags-file-name))) |
|---|
| 557 |
(tags-next-table))))) |
|---|
| 558 |
|
|---|
| 559 |
(t |
|---|
| 560 |
|
|---|
| 561 |
(tags-table-check-computed-list) |
|---|
| 562 |
(setq tags-file-name |
|---|
| 563 |
(or |
|---|
| 564 |
|
|---|
| 565 |
(if (stringp cont) |
|---|
| 566 |
(prog1 cont |
|---|
| 567 |
(setq cont nil))) |
|---|
| 568 |
|
|---|
| 569 |
(cdr (assq 'tags-file-name (buffer-local-variables))) |
|---|
| 570 |
|
|---|
| 571 |
(and default-tags-table-function |
|---|
| 572 |
(funcall default-tags-table-function)) |
|---|
| 573 |
|
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
(and buffer-file-name |
|---|
| 578 |
(or |
|---|
| 579 |
|
|---|
| 580 |
(tags-table-including buffer-file-name t) |
|---|
| 581 |
|
|---|
| 582 |
|
|---|
| 583 |
(tags-table-including buffer-file-name nil))) |
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
(and tags-file-name |
|---|
| 587 |
(not (tags-table-list-member tags-file-name |
|---|
| 588 |
tags-table-computed-list)) |
|---|
| 589 |
tags-file-name) |
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
(let ((list tags-table-list) |
|---|
| 593 |
file) |
|---|
| 594 |
(while (and list |
|---|
| 595 |
(setq file (tags-expand-table-name (car list))) |
|---|
| 596 |
(not (get-file-buffer file)) |
|---|
| 597 |
(not (file-exists-p file))) |
|---|
| 598 |
(setq list (cdr list))) |
|---|
| 599 |
(car list)) |
|---|
| 600 |
|
|---|
| 601 |
(expand-file-name |
|---|
| 602 |
(read-file-name "Visit tags table (default TAGS): " |
|---|
| 603 |
default-directory |
|---|
| 604 |
"TAGS" |
|---|
| 605 |
t)))))) |
|---|
| 606 |
|
|---|
| 607 |
|
|---|
| 608 |
(setq tags-file-name (tags-expand-table-name tags-file-name)) |
|---|
| 609 |
|
|---|
| 610 |
(unless (and (eq cont t) (null tags-table-list-pointer)) |
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 |
(let ((curbuf (current-buffer)) |
|---|
| 615 |
(local-tags-file-name tags-file-name)) |
|---|
| 616 |
(if (tags-verify-table local-tags-file-name) |
|---|
| 617 |
|
|---|
| 618 |
|
|---|
| 619 |
(progn |
|---|
| 620 |
|
|---|
| 621 |
|
|---|
| 622 |
(bury-buffer (current-buffer)) |
|---|
| 623 |
|
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
|
|---|
| 627 |
(or cont |
|---|
| 628 |
|
|---|
| 629 |
(let ((found (tags-table-list-member |
|---|
| 630 |
local-tags-file-name |
|---|
| 631 |
tags-table-computed-list))) |
|---|
| 632 |
(if found |
|---|
| 633 |
|
|---|
| 634 |
(setq tags-table-list-pointer found |
|---|
| 635 |
tags-table-list-started-at found) |
|---|
| 636 |
|
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 |
(let ((sets tags-table-set-list)) |
|---|
| 640 |
(while (and sets |
|---|
| 641 |
(not (tags-table-list-member |
|---|
| 642 |
local-tags-file-name |
|---|
| 643 |
(car sets)))) |
|---|
| 644 |
(setq sets (cdr sets))) |
|---|
| 645 |
(if sets |
|---|
| 646 |
|
|---|
| 647 |
(progn |
|---|
| 648 |
(or (memq tags-table-list tags-table-set-list) |
|---|
| 649 |
|
|---|
| 650 |
(setq tags-table-set-list |
|---|
| 651 |
(cons tags-table-list |
|---|
| 652 |
tags-table-set-list))) |
|---|
| 653 |
(setq tags-table-list (car sets))) |
|---|
| 654 |
|
|---|
| 655 |
|
|---|
| 656 |
(if (and tags-table-list |
|---|
| 657 |
(or (eq t tags-add-tables) |
|---|
| 658 |
(and tags-add-tables |
|---|
| 659 |
(y-or-n-p |
|---|
| 660 |
(concat "Keep current list of " |
|---|
| 661 |
"tags tables also? "))))) |
|---|
| 662 |
|
|---|
| 663 |
(setq tags-table-list (cons local-tags-file-name |
|---|
| 664 |
tags-table-list)) |
|---|
| 665 |
|
|---|
| 666 |
|
|---|
| 667 |
(message "Starting a new list of tags tables") |
|---|
| 668 |
(or (null tags-table-list) |
|---|
| 669 |
(memq tags-table-list tags-table-set-list) |
|---|
| 670 |
(setq tags-table-set-list |
|---|
| 671 |
(cons tags-table-list |
|---|
| 672 |
tags-table-set-list))) |
|---|
| 673 |
|
|---|
| 674 |
(dolist (table tags-table-list) |
|---|
| 675 |
|
|---|
| 676 |
(if (stringp table) |
|---|
| 677 |
(let ((buffer (find-buffer-visiting table))) |
|---|
| 678 |
(if buffer |
|---|
| 679 |
(kill-buffer buffer))))) |
|---|
| 680 |
(setq tags-table-list (list local-tags-file-name)))) |
|---|
| 681 |
|
|---|
| 682 |
|
|---|
| 683 |
(tags-table-check-computed-list) |
|---|
| 684 |
|
|---|
| 685 |
|
|---|
| 686 |
(setq tags-table-list-started-at tags-table-computed-list |
|---|
| 687 |
tags-table-list-pointer |
|---|
| 688 |
tags-table-computed-list))))) |
|---|
| 689 |
|
|---|
| 690 |
|
|---|
| 691 |
t) |
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
(set-buffer curbuf) |
|---|
| 695 |
(kill-local-variable 'tags-file-name) |
|---|
| 696 |
(if (eq local-tags-file-name tags-file-name) |
|---|
| 697 |
(setq tags-file-name nil)) |
|---|
| 698 |
(error "File %s is not a valid tags table" local-tags-file-name))))) |
|---|
| 699 |
|
|---|
| 700 |
(defun tags-reset-tags-tables () |
|---|
| 701 |
"Reset tags state to cancel effect of any previous \\[visit-tags-table] or \\[find-tag]." |
|---|
| 702 |
(interactive) |
|---|
| 703 |
|
|---|
| 704 |
(let ((i 0)) |
|---|
| 705 |
(while (< i find-tag-marker-ring-length) |
|---|
| 706 |
(if (aref (cddr tags-location-ring) i) |
|---|
| 707 |
(set-marker (aref (cddr tags-location-ring) i) nil)) |
|---|
| 708 |
(if (aref (cddr find-tag-marker-ring) i) |
|---|
| 709 |
(set-marker (aref (cddr find-tag-marker-ring) i) nil)) |
|---|
| 710 |
(setq i (1+ i)))) |
|---|
| 711 |
(setq tags-file-name nil |
|---|
| 712 |
tags-location-ring (make-ring find-tag-marker-ring-length) |
|---|
| 713 |
find-tag-marker-ring (make-ring find-tag-marker-ring-length) |
|---|
| 714 |
tags-table-list nil |
|---|
| 715 |
tags-table-computed-list nil |
|---|
| 716 |
tags-table-computed-list-for nil |
|---|
| 717 |
tags-table-list-pointer nil |
|---|
| 718 |
tags-table-list-started-at nil |
|---|
| 719 |
tags-table-set-list nil)) |
|---|
| 720 |
|
|---|
| 721 |
(defun file-of-tag (&optional relative) |
|---|
| 722 |
"Return the file name of the file whose tags point is within. |
|---|
| 723 |
Assumes the tags table is the current buffer. |
|---|
| 724 |
If RELATIVE is non-nil, file name returned is relative to tags |
|---|
| 725 |
table file's directory. If RELATIVE is nil, file name returned |
|---|
| 726 |
is complete." |
|---|
| 727 |
(funcall file-of-tag-function relative)) |
|---|
| 728 |
|
|---|
| 729 |
|
|---|
| 730 |
(defun tags-table-files () |
|---|
| 731 |
"Return a list of files in the current tags table. |
|---|
| 732 |
Assumes the tags table is the current buffer. The file names are returned |
|---|
| 733 |
as they appeared in the `etags' command that created the table, usually |
|---|
| 734 |
without directory names." |
|---|
| 735 |
(or tags-table-files |
|---|
| 736 |
(setq tags-table-files |
|---|
| 737 |
(funcall tags-table-files-function)))) |
|---|
| 738 |
|
|---|
| 739 |
(defun tags-included-tables () |
|---|
| 740 |
"Return a list of tags tables included by the current table. |
|---|
| 741 |
Assumes the tags table is the current buffer." |
|---|
| 742 |
(or tags-included-tables |
|---|
| 743 |
(setq tags-included-tables (funcall tags-included-tables-function)))) |
|---|
| 744 |
|
|---|
| 745 |
|
|---|
| 746 |
|
|---|
| 747 |
|
|---|
| 748 |
(defun |
|---|