Mercurial > hg > xemacs-beta
annotate lisp/etags.el @ 5353:38e24b8be4ea
Improve the lexical scoping in #'block, #'return-from.
lisp/ChangeLog addition:
2011-02-07 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el:
* bytecomp.el (byte-compile-initial-macro-environment):
Shadow `block', `return-from' here, we implement them differently
when byte-compiling.
* bytecomp.el (byte-compile-active-blocks): New.
* bytecomp.el (byte-compile-block-1): New.
* bytecomp.el (byte-compile-return-from-1): New.
* bytecomp.el (return-from-1): New.
* bytecomp.el (block-1): New.
These are two aliases that exist to have their own associated
byte-compile functions, which functions implement `block' and
`return-from'.
* cl-extra.el (cl-macroexpand-all):
Fix a bug here when macros in the environment have been compiled.
* cl-macs.el (block):
* cl-macs.el (return):
* cl-macs.el (return-from):
Be more careful about lexical scope in these macros.
* cl.el:
* cl.el ('cl-block-wrapper): Removed.
* cl.el ('cl-block-throw): Removed.
These aren't needed in code generated by this XEmacs. They
shouldn't be needed in code generated by XEmacs 21.4, but if it
turns out the packages do need them, we can put them back.
2011-01-30 Mike Sperber <mike@xemacs.org>
* font-lock.el (font-lock-fontify-pending-extents): Don't fail if
`font-lock-mode' is unset, which can happen in the middle of
`revert-buffer'.
2011-01-23 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (delete):
* cl-macs.el (delq):
* cl-macs.el (remove):
* cl-macs.el (remq):
Don't use the compiler macro if these functions were given the
wrong number of arguments, as happens in lisp-tests.el.
* cl-seq.el (remove, remq): Removed.
I added these to subr.el, and forgot to remove them from here.
2011-01-22 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-setq, byte-compile-set):
Remove kludge allowing keywords' values to be set, all the code
that does that is gone.
* cl-compat.el (elt-satisfies-test-p):
* faces.el (set-face-parent):
* faces.el (face-doc-string):
* gtk-font-menu.el:
* gtk-font-menu.el (gtk-reset-device-font-menus):
* msw-font-menu.el:
* msw-font-menu.el (mswindows-reset-device-font-menus):
* package-get.el (package-get-installedp):
* select.el (select-convert-from-image-data):
* sound.el:
* sound.el (load-sound-file):
* x-font-menu.el (x-reset-device-font-menus-core):
Don't quote keywords, they're self-quoting, and the
win from backward-compatibility is sufficiently small now that the
style problem overrides it.
2011-01-22 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (block, return-from): Require that NAME be a symbol
in these macros, as always documented in the #'block docstring and
as required by Common Lisp.
* descr-text.el (unidata-initialize-unihan-database):
Correct the use of non-symbols in #'block and #'return-from in
this function.
2011-01-15 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (concatenate): Accept more complicated TYPEs in this
function, handing the sequences over to #'coerce if we don't
understand them here.
* cl-macs.el (inline): Don't proclaim #'concatenate as inline, its
compiler macro is more useful than doing that.
2011-01-11 Aidan Kehoe <kehoea@parhasard.net>
* subr.el (delete, delq, remove, remq): Move #'remove, #'remq
here, they don't belong in cl-seq.el; move #'delete, #'delq here
from fns.c, implement them in terms of #'delete*, allowing support
for sequences generally.
* update-elc.el (do-autoload-commands): Use #'delete*, not #'delq
here, now the latter's no longer dumped.
* cl-macs.el (delete, delq): Add compiler macros transforming
#'delete and #'delq to #'delete* calls.
2011-01-10 Aidan Kehoe <kehoea@parhasard.net>
* dialog.el (make-dialog-box): Correct a misplaced parenthesis
here, thank you Mats Lidell in 87zkr9gqrh.fsf@mail.contactor.se !
2011-01-02 Aidan Kehoe <kehoea@parhasard.net>
* dialog.el (make-dialog-box):
* list-mode.el (display-completion-list):
These functions used to use cl-parsing-keywords; change them to
use defun* instead, fixing the build. (Not sure what led to me
not including this change in d1b17a33450b!)
2011-01-02 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (define-star-compiler-macros):
Make sure the form has ITEM and LIST specified before attempting
to change to calls with explicit tests; necessary for some tests
in lisp-tests.el to compile correctly.
(stable-union, stable-intersection): Add compiler macros for these
functions, in the same way we do for most of the other functions
in cl-seq.el.
2011-01-01 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (dolist, dotimes, do-symbols, macrolet)
(symbol-macrolet):
Define these macros with defmacro* instead of parsing the argument
list by hand, for the sake of style and readability; use backquote
where appropriate, instead of calling #'list and and friends, for
the same reason.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* x-misc.el (device-x-display):
Provide this function, documented in the Lispref for years, but
not existing previously. Thank you Julian Bradfield, thank you
Jeff Mincy.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* cl-seq.el:
Move the heavy lifting from this file to C. Dump the
cl-parsing-keywords macro, but don't use defun* for the functions
we define that do take keywords, dynamic scope lossage makes that
not practical.
* subr.el (sort, fillarray): Move these aliases here.
(map-plist): #'nsublis is now built-in, but at this point #'eql
isn't necessarily available as a test; use #'eq.
* obsolete.el (cl-delete-duplicates): Make this available for old
compiler macros and old code.
(memql): Document that this is equivalent to #'member*, and worse.
* cl.el (adjoin, subst): Removed. These are in C.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* simple.el (assoc-ignore-case): Remove a duplicate definition of
this function (it's already in subr.el).
* iso8859-1.el (char-width):
On non-Mule, make this function equivalent to that produced by
(constantly 1), but preserve its docstring.
* subr.el (subst-char-in-string): Define this in terms of
#'substitute, #'nsubstitute.
(string-width): Define this using #'reduce and #'char-width.
(char-width): Give this a simpler definition, it makes far more
sense to check for mule at load time and redefine, as we do in
iso8859-1.el.
(store-substring): Implement this in terms of #'replace, now
#'replace is cheap.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* update-elc.el (lisp-files-needed-for-byte-compilation)
(lisp-files-needing-early-byte-compilation):
cl-macs belongs in the former, not the latter, it is as
fundamental as bytecomp.el.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* cl.el:
Provde the Common Lisp program-error, type-error as error
symbols. This doesn't nearly go far enough for anyone using the
Common Lisp errors.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (delete-duplicates):
If the form has an incorrect number of arguments, don't attempt a
compiler macroexpansion.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (cl-safe-expr-p):
Forms that start with the symbol lambda are also safe.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (= < > <= >=):
For these functions' compiler macros, the optimisation is safe
even if the first and the last arguments have side effects, since
they're only used the once.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (inline-side-effect-free-compiler-macros):
Unroll a loop here at macro-expansion time, so these compiler
macros are compiled. Use #'eql instead of #'eq in a couple of
places for better style.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (notany, notevery): Avoid some dynamic scope
stupidity with local variable names in these functions, when they
weren't prefixed with cl-; go into some more detail in the doc
strings.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (side-effect-free-fns): #'remove, #'remq are
free of side-effects.
(side-effect-and-error-free-fns):
Drop dot, dot-marker from the list.
2010-11-17 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (coerce):
In the argument list, name the first argument OBJECT, not X; the
former name was always used in the doc string and is clearer.
Handle vector type specifications which include the length of the
target sequence, error if there's a mismatch.
* cl-macs.el (cl-make-type-test): Handle type specifications
starting with the symbol 'eql.
2010-11-14 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (eql): Don't remove the byte-compile property of this
symbol. That was necessary to override a bug in bytecomp.el where
#'eql was confused with #'eq, which bug we no longer have.
If neither expression is constant, don't attempt to handle the
expression in this compiler macro, leave it to byte-compile-eql,
which produces better code anyway.
* bytecomp.el (eq): #'eql is not the function associated with the
byte-eq byte code.
(byte-compile-eql): Add an explicit compile method for this
function, for cases where the cl-macs compiler macro hasn't
reduced it to #'eq or #'equal.
2010-10-25 Aidan Kehoe <kehoea@parhasard.net>
Add compiler macros and compilation sanity-checking for various
functions that take keywords.
* byte-optimize.el (side-effect-free-fns): #'symbol-value is
side-effect free and not error free.
* bytecomp.el (byte-compile-normal-call): Check keyword argument
lists for sanity; store information about the positions where
keyword arguments start using the new byte-compile-keyword-start
property.
* cl-macs.el (cl-const-expr-val): Take a new optional argument,
cl-not-constant, defaulting to nil, in this function; return it if
the expression is not constant.
(cl-non-fixnum-number-p): Make this into a separate function, we
want to pass it to #'every.
(eql): Use it.
(define-star-compiler-macros): Use the same code to generate the
member*, assoc* and rassoc* compiler macros; special-case some
code in #'add-to-list in subr.el.
(remove, remq): Add compiler macros for these two functions, in
preparation for #'remove being in C.
(define-foo-if-compiler-macros): Transform (remove-if-not ...) calls to
(remove ... :if-not) at compile time, which will be a real win
once the latter is in C.
(define-substitute-if-compiler-macros)
(define-subst-if-compiler-macros): Similarly for these functions.
(delete-duplicates): Change this compiler macro to use
#'plists-equal; if we don't have information about the type of
SEQUENCE at compile time, don't bother attempting to inline the
call, the function will be in C soon enough.
(equalp): Remove an old commented-out compiler macro for this, if
we want to see it it's in version control.
(subst-char-in-string): Transform this to a call to nsubstitute or
nsubstitute, if that is appropriate.
* cl.el (ldiff): Don't call setf here, this makes for a load-time
dependency problem in cl-macs.el
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* term/vt100.el:
Refer to XEmacs, not GNU Emacs, in permissions.
* term/bg-mouse.el:
* term/sup-mouse.el:
Put copyright notice in canonical "Copyright DATE AUTHOR" form.
Refer to XEmacs, not GNU Emacs, in permissions.
* site-load.el:
Add permission boilerplate.
* mule/canna-leim.el:
* alist.el:
Refer to XEmacs, not APEL/this program, in permissions.
* mule/canna-leim.el:
Remove my copyright, I've assigned it to the FSF.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* gtk.el:
* gtk-widget-accessors.el:
* gtk-package.el:
* gtk-marshal.el:
* gtk-compose.el:
* gnome.el:
Add copyright notice based on internal evidence.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* easymenu.el: Add reference to COPYING to permission notice.
* gutter.el:
* gutter-items.el:
* menubar-items.el:
Fix typo "Xmacs" in permissions notice.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* auto-save.el:
* font.el:
* fontconfig.el:
* mule/kinsoku.el:
Add "part of XEmacs" text to permission notice.
2010-10-14 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (side-effect-free-fns):
* cl-macs.el (remf, getf):
* cl-extra.el (tailp, cl-set-getf, cl-do-remf):
* cl.el (ldiff, endp):
Tighten up Common Lisp compatibility for #'ldiff, #'endp, #'tailp;
add circularity checking for the first two.
#'cl-set-getf and #'cl-do-remf were Lisp implementations of
#'plist-put and #'plist-remprop; change the names to aliases,
changes the macros that use them to using #'plist-put and
#'plist-remprop directly.
2010-10-12 Aidan Kehoe <kehoea@parhasard.net>
* abbrev.el (fundamental-mode-abbrev-table, global-abbrev-table):
Create both these abbrev tables using the usual
#'define-abbrev-table calls, rather than attempting to
special-case them.
* cl-extra.el: Force cl-macs to be loaded here, if cl-extra.el is
being loaded interpreted. Previously other, later files would
redundantly call (load "cl-macs") when interpreted, it's more
reasonable to do it here, once.
* cmdloop.el (read-quoted-char-radix): Use defcustom here, we
don't have any dump-order dependencies that would prevent that.
* custom.el (eval-when-compile): Don't load cl-macs when
interpreted or when byte-compiling, rely on cl-extra.el in the
former case and the appropriate entry in bytecomp-load-hook in the
latter. Get rid of custom-declare-variable-list, we have no
dump-time dependencies that would require it.
* faces.el (eval-when-compile): Don't load cl-macs when
interpreted or when byte-compiling.
* packages.el: Remove some inaccurate comments.
* post-gc.el (cleanup-simple-finalizers): Use #'delete-if-not
here, now the order of preloaded-file-list has been changed to
make it available.
* subr.el (custom-declare-variable-list): Remove. No need for it.
Also remove a stub define-abbrev-table from this file, given the
current order of preloaded-file-list there's no need for it.
2010-10-10 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-constp) Forms quoted with FUNCTION are
also constant.
(byte-compile-initial-macro-environment): In #'the, if FORM is
constant and does not match TYPE, warn at byte-compile time.
2010-10-10 Aidan Kehoe <kehoea@parhasard.net>
* backquote.el (bq-vector-contents, bq-list*): Remove; the former
is equivalent to (append VECTOR nil), the latter to (list* ...).
(bq-process-2): Use (append VECTOR nil) instead of using
#'bq-vector-contents to convert to a list.
(bq-process-1): Now we use list* instead of bq-list
* subr.el (list*): Moved from cl.el, since it is now required to
be available the first time a backquoted form is encountered.
* cl.el (list*): Move to subr.el.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* test-harness.el (Check-Message):
Add an omitted comma here, thank you the buildbot.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* hash-table.el (hash-table-key-list, hash-table-value-list)
(hash-table-key-value-alist, hash-table-key-value-plist):
Remove some useless #'nreverse calls in these files; our hash
tables have no order, it's not helpful to pretend they do.
* behavior.el (read-behavior):
Do the same in this file, in some code evidently copied from
hash-table.el.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* info.el (Info-insert-dir):
* format.el (format-deannotate-region):
* files.el (cd, save-buffers-kill-emacs):
Use #'some, #'every and related functions for applying boolean
operations to lists, instead of rolling our own ones that cons and
don't short-circuit.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-initial-macro-environment):
* cl-macs.el (the):
Rephrase the docstring, make its implementation when compiling
files a little nicer.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* descr-text.el (unidata-initialize-unicodedata-database)
(unidata-initialize-unihan-database, describe-char-unicode-data)
(describe-char-unicode-data):
Wrap calls to the database functions with (with-fboundp ...),
avoiding byte compile warnings on builds without support for the
database functions.
(describe-char): (reduce #'max ...), not (apply #'max ...), no
need to cons needlessly.
(describe-char): Remove a redundant lambda wrapping
#'extent-properties.
(describe-char-unicode-data): Call #'nsubst when replacing "" with
nil in the result of #'split-string, instead of consing inside
mapcar.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* x-faces.el (x-available-font-sizes):
* specifier.el (let-specifier):
* package-ui.el (pui-add-required-packages):
* msw-faces.el (mswindows-available-font-sizes):
* modeline.el (modeline-minor-mode-menu):
* minibuf.el (minibuf-directory-files):
Replace the O2N (delq nil (mapcar (lambda (W) (and X Y)) Z)) with
the ON (mapcan (lambda (W) (and X (list Y))) Z) in these files.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (= < > <= >=):
When these functions are handed more than two arguments, and those
arguments have no side effects, transform to a series of two
argument calls, avoiding funcall in the byte-compiled code.
* mule/mule-cmds.el (finish-set-language-environment):
Take advantage of this change in a function called 256 times at
startup.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-function-form, byte-compile-quote)
(byte-compile-quote-form):
Warn at compile time, and error at runtime, if a (quote ...) or a
(function ...) form attempts to quote more than one object.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (byte-optimize-apply): Transform (apply 'nconc
(mapcar ...)) to (mapcan ...); warn about use of the first idiom.
* update-elc.el (do-autoload-commands):
* packages.el (packages-find-package-library-path):
* frame.el (frame-list):
* extents.el (extent-descendants):
* etags.el (buffer-tag-table-files):
* dumped-lisp.el (preloaded-file-list):
* device.el (device-list):
* bytecomp-runtime.el (proclaim-inline, proclaim-notinline)
Use #'mapcan, not (apply #'nconc (mapcar ...) in all these files.
* bytecomp-runtime.el (eval-when-compile, eval-and-compile):
In passing, mention that these macros also evaluate the body when
interpreted.
tests/ChangeLog addition:
2011-02-07 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el:
Test lexical scope for `block', `return-from'; add a
Known-Bug-Expect-Failure for a contorted example that fails when
byte-compiled.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Mon, 07 Feb 2011 12:01:24 +0000 |
parents | 0d43872986b6 |
children | 8b70d37ab80e 308d34e9f07d |
rev | line source |
---|---|
428 | 1 ;;; etags.el --- etags facility for Emacs |
2 | |
1584 | 3 ;; Copyright 1985, 1986, 1988, 1990, 1997, 2003 Free Software Foundation, Inc. |
428 | 4 |
5 ;; Author: Their Name is Legion (see list below) | |
6 ;; Maintainer: XEmacs Development Team | |
7 ;; Keywords: tools | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
11 ;; XEmacs is free software; you can redistribute it and/or modify it | |
12 ;; under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; XEmacs is distributed in the hope that it will be useful, but | |
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 ;; General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with XEmacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Synched up with: Not synched with FSF. | |
27 | |
28 ;;; Commentary: | |
29 | |
30 ;; This file is completely different from FSF's etags.el. It appears | |
31 ;; that an early version of this file (tags.el) has been rewritten by | |
32 ;; two different people; we got one, FSF got the other. Various | |
33 ;; people have said that our version is better and faster. | |
34 | |
35 ;; TODO: | |
36 ;; - DOCUMENT! | |
37 | |
38 ;; Derived from the original lisp/tags.el. | |
39 | |
40 ;; Ideas and code from the work of the following people: | |
41 ;; Andy Norman <ange@hplb.hpl.hp.com>, author of ange-tags.el | |
42 ;; Ramana Rao <rao@arisia.xerox.com> | |
43 ;; John Sturdy <jcgs@harlqn.co.uk>, author of tags-helper.el | |
44 ;; Henry Kautz <kautz@allegra.att.com>, author of tag-completion.el | |
45 ;; Dan LaLiberte <liberte@cs.uiuc.edu>, author of local-tags.el | |
46 ;; Tom Dietterich <tgd@turing.cs.orst.edu>, author of quest.el | |
47 ;; The author(s) of lisp/simple.el | |
48 ;; Duke Briscoe <briscoe@cs.yale.edu> | |
49 ;; Lynn Slater <lrs@indetech.com>, author of location.el | |
50 ;; Shinichirou Sugou <shin@sgtp.apple.juice.or.jp> | |
51 ;; an unidentified anonymous elisp hacker | |
52 ;; Kyle Jones <kyle_jones@wonderworks.com> | |
53 ;; added "Exact match, then inexact" code | |
54 ;; added support for include directive. | |
55 ;; Hrvoje Niksic <hniksic@xemacs.org> | |
56 ;; various changes. | |
57 | |
58 | |
59 ;;; User variables. | |
60 | |
61 (defgroup etags nil | |
62 "Etags facility for Emacs. | |
63 Using etags, you can create tag tables for any number of files, and | |
64 easily access the symbols in those files, using the `\\[find-tag]' | |
65 command." | |
66 :prefix "tags-" | |
67 :group 'tools) | |
68 | |
69 | |
70 (defcustom tags-build-completion-table 'ask | |
71 "*If this variable is nil, then tags completion is disabled. | |
72 If it is t, then things which prompt for tags will do so with completion | |
73 across all known tags. | |
74 If it is the symbol `ask', you will be asked whether each tags table | |
75 should be added to the completion list as it is read in. (With the | |
76 exception that for very small tags tables, you will not be asked, | |
77 since they can be parsed quickly.)" | |
78 :type '(choice (const :tag "Disabled" nil) | |
79 (const :tag "Complete All" t) | |
80 (const :tag "Ask" ask)) | |
81 :group 'etags) | |
82 | |
83 (defcustom tags-always-exact nil | |
84 "*If this variable is non-nil, then tags always looks for exact matches. | |
85 If it is nil (the default), tags will first go through exact matches, | |
86 then through the non-exact ones." | |
87 :type 'boolean | |
88 :group 'etags) | |
89 | |
90 (defcustom tag-table-alist nil | |
91 "*A list which determines which tags files are active for a buffer. | |
92 This is not really an association list, in that all elements are | |
93 checked. The CAR of each element of this list is a pattern against | |
94 which the buffer's file name is compared; if it matches, then the CDR | |
95 of the list should be the name of the tags table to use. If more than | |
96 one element of this list matches the buffer's file name, then all of | |
97 the associated tags tables will be used. Earlier ones will be | |
98 searched first. | |
99 | |
100 If the CAR of elements of this list are strings, then they are treated | |
101 as regular-expressions against which the file is compared (like the | |
102 auto-mode-alist). If they are not strings, then they are evaluated. | |
103 If they evaluate to non-nil, then the current buffer is considered to | |
104 match. | |
105 | |
106 If the CDR of the elements of this list are strings, then they are | |
107 assumed to name a TAGS file. If they name a directory, then the string | |
108 \"TAGS\" is appended to them to get the file name. If they are not | |
109 strings, then they are evaluated, and must return an appropriate string. | |
110 | |
111 For example: | |
112 (setq tag-table-alist | |
113 '((\"/usr/src/public/perl/\" . \"/usr/src/public/perl/perl-3.0/\") | |
114 (\"\\\\.el$\" . \"/usr/local/emacs/src/\") | |
115 (\"/jbw/gnu/\" . \"/usr15/degree/stud/jbw/gnu/\") | |
116 (\"\" . \"/usr/local/emacs/src/\") | |
117 )) | |
118 | |
119 This means that anything in the /usr/src/public/perl/ directory should use | |
120 the TAGS file /usr/src/public/perl/perl-3.0/TAGS; and file ending in .el should | |
121 use the TAGS file /usr/local/emacs/src/TAGS; and anything in or below the | |
122 directory /jbw/gnu/ should use the TAGS file /usr15/degree/stud/jbw/gnu/TAGS. | |
123 A file called something like \"/usr/jbw/foo.el\" would use both the TAGS files | |
124 /usr/local/emacs/src/TAGS and /usr15/degree/stud/jbw/gnu/TAGS (in that order) | |
125 because it matches both patterns. | |
126 | |
127 If the buffer-local variable `buffer-tag-table' is set, then it names a tags | |
128 table that is searched before all others when find-tag is executed from this | |
129 buffer. | |
130 | |
131 If there is a file called \"TAGS\" in the same directory as the file in | |
132 question, then that tags file will always be used as well (after the | |
133 `buffer-tag-table' but before the tables specified by this list.) | |
134 | |
135 If the variable tags-file-name is set, then the tags file it names will apply | |
136 to all buffers (for backwards compatibility.) It is searched first." | |
137 :type '(repeat (cons :format "%v" | |
138 (choice :value "" | |
139 (regexp :tag "Buffer regexp") | |
140 sexp) | |
141 (choice :value "" | |
142 (string :tag "Tag file or directory") | |
143 sexp))) | |
144 :group 'etags) | |
145 | |
146 (defvar buffer-tag-table nil | |
147 "*The additional name of one TAGS table to be used for this buffer. | |
148 You can set this with `\\[set-buffer-tag-table]'. See the documentation | |
149 for the variable `tag-table-alist' for more information.") | |
150 (make-variable-buffer-local 'buffer-tag-table) | |
151 | |
152 (defvar tags-file-name nil | |
153 "The name of the tags-table used by all buffers. | |
154 This is for backwards compatibility, and is largely supplanted by the | |
155 variable tag-table-alist.") | |
156 | |
157 (defcustom tags-auto-read-changed-tag-files nil | |
158 "*If non-nil, always re-read changed TAGS file without prompting. | |
159 If nil, prompt whether to re-read the changed TAGS file." | |
160 :type 'boolean | |
161 :group 'etags) | |
162 | |
163 (defcustom make-tags-files-invisible nil | |
164 "*If non-nil, TAGS-files will not show up in buffer-lists or be | |
165 selectable (or deletable.)" | |
166 :type 'boolean | |
167 :group 'etags) | |
168 | |
169 (defcustom tags-search-nuke-uninteresting-buffers t | |
170 "*If non-nil, keep newly-visited files if they contain the search target. | |
171 This affects the `tags-search' and `tags-query-replace' commands." | |
172 :type 'boolean | |
173 :group 'etags) | |
174 | |
502 | 175 (defcustom tags-check-parent-directories-for-tag-files t |
176 "*If non-nil, look for TAGS files in all parent directories." | |
177 :type 'boolean | |
178 :group 'etags) | |
179 | |
2067 | 180 (defcustom tags-exuberant-ctags-optimization-p nil |
181 "*If this variable is nil (the default), then exact tag search is able | |
182 to find tag names in the name part of the tagtable (enclosed by ^?..^A) | |
183 and in the sourceline part of the tagtable ( enclosed by ^..^?). | |
184 This is needed by xemacs etags as not every tag has a name field. | |
185 It is slower for large tables and less precise than the other option. | |
186 | |
187 If it is non-nil, then exact tag will only search tag names in the name | |
188 part (enclosed by ^?..^A). This is faster and more precise than the other | |
189 option. This is only usable with exuberant etags, as it has a name field | |
190 entry for every tag." | |
191 :type 'boolean | |
192 :group 'etags) | |
428 | 193 |
194 ;; Buffer tag tables. | |
195 | |
196 (defun buffer-tag-table-list () | |
197 "Returns a list (ordered) of the tags tables which should be used for | |
198 the current buffer." | |
199 (let (result) | |
200 ;; Explicitly set buffer-tag-table | |
201 (when buffer-tag-table | |
202 (push buffer-tag-table result)) | |
203 ;; Current directory | |
204 (when (file-readable-p (concat default-directory "TAGS")) | |
205 (push (concat default-directory "TAGS") result)) | |
502 | 206 ;; Parent directories |
207 (when tags-check-parent-directories-for-tag-files | |
208 (let ((cur default-directory)) | |
593 | 209 ;; Fuck! Shouldn't there be a more obvious portable way |
210 ;; to determine if we're the root? Shouldn't we have a | |
211 ;; proper path manipulation API? Do you know how many | |
212 ;; god-damn bugs are lurking out there because of Unix/ | |
213 ;; Windows differences? And how much code is littered | |
214 ;; with stuff such as 10 lines down from here? | |
215 (while (not (and (equal (file-name-as-directory cur) cur) | |
216 (equal (directory-file-name cur) cur))) | |
217 (setq cur (expand-file-name ".." cur)) | |
502 | 218 (let ((parent-tag-file (expand-file-name "TAGS" cur))) |
219 (when (file-readable-p parent-tag-file) | |
220 (push parent-tag-file result)))))) | |
428 | 221 ;; tag-table-alist |
442 | 222 (let* ((key (or buffer-file-name |
223 (concat default-directory (buffer-name)))) | |
224 (key (if (eq system-type 'windows-nt) | |
225 (replace-in-string key "\\\\" "/") | |
226 key)) | |
227 expression) | |
428 | 228 (dolist (item tag-table-alist) |
229 (setq expression (car item)) | |
230 ;; If the car of the alist item is a string, apply it as a regexp | |
231 ;; to the buffer-file-name. Otherwise, evaluate it. If the | |
232 ;; regexp matches, or the expression evaluates non-nil, then this | |
233 ;; item in tag-table-alist applies to this buffer. | |
234 (when (if (stringp expression) | |
235 (string-match expression key) | |
236 (ignore-errors | |
237 (eval expression))) | |
238 ;; Now evaluate the cdr of the alist item to get the name of | |
239 ;; the tag table file. | |
240 (setq expression (ignore-errors | |
241 (eval (cdr item)))) | |
242 (if (stringp expression) | |
243 (push expression result) | |
244 (error "Expression in tag-table-alist evaluated to non-string"))))) | |
245 (setq result | |
246 (mapcar | |
247 (lambda (name) | |
248 (when (file-directory-p name) | |
249 (setq name (concat (file-name-as-directory name) "TAGS"))) | |
250 (and (file-readable-p name) | |
251 ;; get-tag-table-buffer has side-effects | |
252 (symbol-value-in-buffer 'buffer-file-name | |
253 (get-tag-table-buffer name)))) | |
254 result)) | |
255 (setq result (delq nil result)) | |
256 ;; If no TAGS file has been found, ask the user explicitly. | |
257 ;; #### tags-file-name is *evil*. | |
258 (or result tags-file-name | |
259 (call-interactively 'visit-tags-table)) | |
260 (when tags-file-name | |
261 (setq result (nconc result (list tags-file-name)))) | |
262 (or result (error "Buffer has no associated tag tables")) | |
263 (delete-duplicates (nreverse result) :test 'equal))) | |
264 | |
265 ;;;###autoload | |
266 (defun visit-tags-table (file) | |
267 "Tell tags commands to use tags table file FILE when all else fails. | |
268 FILE should be the name of a file created with the `etags' program. | |
269 A directory name is ok too; it means file TAGS in that directory." | |
270 (interactive (list (read-file-name "Visit tags table: (default TAGS) " | |
271 default-directory | |
272 (expand-file-name "TAGS" default-directory) | |
273 t))) | |
274 (if (string-equal file "") | |
275 (setq tags-file-name nil) | |
276 (setq file (expand-file-name file)) | |
277 (when (file-directory-p file) | |
278 (setq file (expand-file-name "TAGS" file))) | |
279 ;; It used to be that, if a user pressed RET by mistake, the bogus | |
280 ;; `tags-file-name' would remain, causing the error at | |
281 ;; `buffer-tag-table'. | |
282 (when (file-exists-p file) | |
283 (setq tags-file-name file)))) | |
284 | |
285 (defun set-buffer-tag-table (file) | |
286 "In addition to the tags tables specified by the variable `tag-table-alist', | |
287 each buffer can have one additional table. This command sets that. | |
288 See the documentation for the variable `tag-table-alist' for more information." | |
289 (interactive | |
290 (list | |
291 (read-file-name "Visit tags table: (directory sufficient) " | |
292 nil default-directory t))) | |
293 (or file (error "No TAGS file name supplied")) | |
294 (setq file (expand-file-name file)) | |
295 (when (file-directory-p file) | |
296 (setq file (expand-file-name "TAGS" file))) | |
297 (or (file-exists-p file) (error "TAGS file missing: %s" file)) | |
298 (setq buffer-tag-table file)) | |
299 | |
300 | |
301 ;; Manipulating the tag table buffer | |
302 | |
303 (defconst tag-table-completion-status nil | |
304 "Indicates whether a completion table has been built. | |
305 Either nil, t, or `disabled'.") | |
306 (make-variable-buffer-local 'tag-table-completion-status) | |
307 | |
308 (defconst tag-table-files nil | |
309 "If the current buffer is a TAGS table, this holds a list of the files | |
310 referenced by this file, or nil if that hasn't been computed yet.") | |
311 (make-variable-buffer-local 'tag-table-files) | |
312 | |
313 (defun get-tag-table-buffer (tag-table) | |
314 "Returns a buffer visiting the given TAGS table. | |
315 If appropriate, reverting the buffer, and possibly build a completion-table." | |
316 (or (stringp tag-table) | |
317 (error "Bad tags file name supplied: %s" tag-table)) | |
318 ;; Remove symbolic links from name. | |
319 (setq tag-table (symlink-expand-file-name tag-table)) | |
320 (let (buf build-completion check-name) | |
321 (setq buf (get-file-buffer tag-table)) | |
322 (unless buf | |
323 (if (file-readable-p tag-table) | |
324 (setq buf (find-file-noselect tag-table) | |
325 check-name t) | |
326 (error "No such tags file: %s" tag-table))) | |
327 (with-current-buffer buf | |
328 ;; Make the TAGS buffer invisible. | |
329 (when (and check-name | |
330 make-tags-files-invisible | |
331 (string-match "\\`[^ ]" (buffer-name))) | |
332 (rename-buffer (generate-new-buffer-name | |
333 (concat " " (buffer-name))))) | |
334 (or (verify-visited-file-modtime buf) | |
335 (cond ((or tags-auto-read-changed-tag-files | |
336 (yes-or-no-p | |
337 (format "Tags file %s has changed, read new contents? " | |
338 tag-table))) | |
339 (when tags-auto-read-changed-tag-files | |
340 (message "Tags file %s has changed, reading new contents..." | |
341 tag-table)) | |
342 (revert-buffer t t) | |
343 (when (eq tag-table-completion-status t) | |
344 (setq tag-table-completion-status nil)) | |
345 (setq tag-table-files nil)))) | |
346 (or (eq (char-after 1) ?\f) | |
347 (error "File %s not a valid tags file" tag-table)) | |
348 (or (memq tag-table-completion-status '(t disabled)) | |
349 (setq build-completion t)) | |
350 (when build-completion | |
351 (if (ecase tags-build-completion-table | |
352 ((nil) nil) | |
353 ((t) t) | |
354 ((ask) | |
355 ;; don't bother asking for small ones | |
356 (or (< (buffer-size) 20000) | |
357 (y-or-n-p | |
358 (format "Build tag completion table for %s? " | |
359 tag-table))))) | |
360 ;; The user wants to build the table: | |
361 (condition-case nil | |
362 (progn | |
2067 | 363 (if tags-exuberant-ctags-optimization-p |
364 (add-to-tag-completion-table-exuberant-ctags) | |
365 (add-to-tag-completion-table)) | |
428 | 366 (setq tag-table-completion-status t)) |
367 ;; Allow user to C-g out correctly | |
368 (quit | |
369 (message "Tags completion table construction aborted") | |
370 (setq tag-table-completion-status nil | |
371 quit-flag t) | |
372 t)) | |
373 ;; The table is verboten. | |
374 (setq tag-table-completion-status 'disabled)))) | |
375 buf)) | |
376 | |
377 (defun file-of-tag () | |
378 "Return the file name of the file whose tags point is within. | |
379 Assumes the tag table is the current buffer. | |
380 File name returned is relative to tag table file's directory." | |
381 (let ((opoint (point)) | |
382 prev size) | |
383 (save-excursion | |
384 (goto-char (point-min)) | |
385 (while (< (point) opoint) | |
386 (forward-line 1) | |
387 (end-of-line) | |
388 (skip-chars-backward "^,\n") | |
389 (setq prev (point) | |
390 size (read (current-buffer))) | |
391 (goto-char prev) | |
392 (forward-line 1) | |
393 ;; New include syntax | |
394 ;; filename,include | |
395 ;; tacked on to the end of a tag file means use filename | |
396 ;; as a tag file before giving up. | |
397 ;; Skip it here. | |
398 (unless (eq size 'include) | |
399 (forward-char size))) | |
400 (goto-char (1- prev)) | |
401 (buffer-substring (point) (point-at-bol))))) | |
402 | |
403 (defun tag-table-include-files () | |
404 "Return all file names associated with `include' directives in a tag buffer." | |
405 ;; New include syntax | |
406 ;; filename,include | |
407 ;; tacked on to the end of a tag file means use filename as a | |
408 ;; tag file before giving up. | |
409 (let ((files nil)) | |
410 (save-excursion | |
411 (goto-char (point-min)) | |
412 (while (re-search-forward "\f\n\\(.*\\),include$" nil t) | |
413 (push (match-string 1) files))) | |
414 files)) | |
415 | |
416 (defun tag-table-files (tag-table) | |
417 "Returns a list of the files referenced by the named TAGS table." | |
418 (with-current-buffer (get-tag-table-buffer tag-table) | |
419 (unless tag-table-files | |
420 (let (files prev size) | |
421 (goto-char (point-min)) | |
422 (while (not (eobp)) | |
423 (forward-line 1) | |
424 (end-of-line) | |
425 (skip-chars-backward "^,\n") | |
426 (setq prev (point) | |
427 size (read (current-buffer))) | |
428 (goto-char prev) | |
429 (push (expand-file-name (buffer-substring (1- (point)) | |
430 (point-at-bol)) | |
431 default-directory) | |
432 files) | |
433 (forward-line 1) | |
434 (forward-char size)) | |
435 (setq tag-table-files (nreverse files)))) | |
436 tag-table-files)) | |
437 | |
438 ;; #### should this be on previous page? | |
439 (defun buffer-tag-table-files () | |
440 "Returns a list of all files referenced by all TAGS tables that | |
441 this buffer uses." | |
5264
0d43872986b6
Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4755
diff
changeset
|
442 (mapcan #'tag-table-files (buffer-tag-table-list))) |
428 | 443 |
444 | |
445 ;; Building the completion table | |
446 | |
447 ;; Test cases for building completion table; must handle these properly: | |
448 ;; Lisp_Int, XSETINT, current_column 60,2282 | |
449 ;; Lisp_Int, XSETINT, point>NumCharacters ? 0 : CharAt(363,9935 | |
450 ;; Lisp_Int, XSETINT, point<=FirstCharacter ? 0 : CharAt(366,10108 | |
451 ;; point<=FirstCharacter || CharAt(378,10630 | |
452 ;; point>NumCharacters || CharAt(382,10825 | |
453 ;; DEFUN ("x-set-foreground-color", Fx_set_foreground_color,191,4562 | |
454 ;; DEFUN ("x-set-foreground-color", Fx_set_foreground_color,191,4562 | |
455 ;; DEFUN ("*", Ftimes,1172,32079 | |
456 ;; DEFUN ("/=", Fneq,1035,28839 | |
457 ;; defun_internal 4199,101362 | |
458 ;; int pure[PURESIZE / sizeof 53,1564 | |
459 ;; char staticvec1[NSTATICS * sizeof 667,17608 | |
460 ;; Date: 04 May 87 23:53:11 PDT 26,1077 | |
461 ;; #define anymacroname(324,4344 | |
462 ;; (define-key ctl-x-map 311,11784 | |
463 ;; (define-abbrev-table 'c-mode-abbrev-table 24,1016 | |
464 ;; static char *skip_white(116,3443 | |
465 ;; static foo 348,11643 | |
466 ;; (defun texinfo-insert-@code 91,3358 | |
467 ;; (defvar texinfo-kindex)29,1105 | |
468 ;; (defun texinfo-format-\. 548,18376 | |
469 ;; (defvar sm::menu-kludge-y 621,22726 | |
470 ;; (defvar *mouse-drag-window* 103,3642 | |
471 ;; (defun simula-back-level(317,11263 | |
472 ;; } DPxAC,380,14024 | |
473 ;; } BM_QCB;69,2990 | |
474 ;; #define MTOS_DONE\t | |
475 | |
476 ;; "^[^ ]+ +\\([^ ]+\\) " | |
477 | |
478 ;; void *find_cactus_segment(116,2444 | |
479 ;; void *find_pdb_segment(162,3688 | |
480 ;; void init_dclpool(410,10739 | |
481 ;; WORD insert_draw_command(342,8881 | |
482 ;; void *req_pdbmem(579,15574 | |
483 | |
484 (defvar tag-completion-table (make-vector 511 0)) | |
485 | |
486 (defvar tag-symbol) | |
487 (defvar tag-table-symbol) | |
488 (defvar tag-symbol-tables) | |
489 (defvar buffer-tag-table-list) | |
490 | |
491 (defmacro intern-tag-symbol (tag) | |
492 `(progn | |
493 (setq tag-symbol (intern ,tag tag-completion-table) | |
494 tag-symbol-tables (and (boundp tag-symbol) | |
495 (symbol-value tag-symbol))) | |
496 (or (memq tag-table-symbol tag-symbol-tables) | |
497 (set tag-symbol (cons tag-table-symbol tag-symbol-tables))))) | |
498 | |
1584 | 499 ;; Can't use "\\s-" in these patterns because that will include newline |
500 ;; \2 matches an explicit name. | |
501 (defconst tags-explicit-name-pattern "\177\\(\\([^\n\001]+\\)\001\\)?") | |
502 ;; \1 matches Lisp-name, \2 matches C-name, \5 (from | |
503 ;; tags-explicit-name-pattern) matches explicit name. | |
428 | 504 (defconst tags-DEFUN-pattern |
1584 | 505 (concat "DEFUN[ \t]*(\"\\([^\"]+\\)\",[ \t]*\\(\\(\\sw\\|\\s_\\)+\\)," |
506 tags-explicit-name-pattern)) | |
507 ;; \1 matches an array name. Explicit names unused? | |
428 | 508 (defconst tags-array-pattern ".*[ \t]+\\([^ \[]+\\)\\[") |
1584 | 509 ;; \2 matches a Lispish name, \5 (from tags-explicit-name-pattern) matches |
510 ;; explicit name. | |
428 | 511 (defconst tags-def-pattern |
1584 | 512 (concat "\\(.*[ \t]+\\)?\\**\\(\\(\\sw\\|\\s_\\)+\\)[ ();,\t]*" |
513 ;; "\\(.*[ \t]+\\)?\\(\\(\\sw\\|\\s_\\)+\\)[ ()]*" | |
514 ;; "\\(\\sw\\|\\s_\\)+[ ()]*" | |
515 tags-explicit-name-pattern) | |
428 | 516 ) |
1584 | 517 ;; \1 matches Schemish name, \4 (from tags-explicit-name-pattern) matches |
518 ;; explicit name | |
519 (defconst tags-schemish-pattern | |
520 (concat "\\s-*(\\s-*def\\sw*\\s-*(?\\s-*\\(\\(\\sw\\|\\s_\\|:\\)+\\))?\\s-*" | |
521 tags-explicit-name-pattern)) | |
428 | 522 (defconst tags-file-pattern "^\f\n\\(.+\\),[0-9]+\n") |
523 | |
2067 | 524 (defun add-to-tag-completion-table-exuberant-ctags () |
525 "Sucks the current buffer (a TAGS table) into the completion-table. | |
526 This is a version which is optimized for exuberant etags and will not | |
527 work with xemacs etags." | |
528 (message "Adding %s to tags completion table..." buffer-file-name) | |
529 (goto-char (point-min)) | |
530 (let ((tag-table-symbol (intern buffer-file-name tag-completion-table)) | |
531 ;; tag-table-symbol is used by intern-tag-symbol | |
532 name tag-symbol | |
533 tag-symbol-tables | |
534 (case-fold-search nil)) | |
535 (while (re-search-forward tags-explicit-name-pattern nil t) | |
536 ;; no need to check the mode here | |
537 (setq name (match-string 2)) | |
538 (intern-tag-symbol name))) | |
539 (message "Adding %s to tags completion table...done" buffer-file-name)) | |
540 | |
541 | |
428 | 542 ;; #### Should make it work with the `include' directive! |
543 (defun add-to-tag-completion-table () | |
544 "Sucks the current buffer (a TAGS table) into the completion-table." | |
545 (message "Adding %s to tags completion table..." buffer-file-name) | |
546 (goto-char (point-min)) | |
547 (let ((tag-table-symbol (intern buffer-file-name tag-completion-table)) | |
548 ;; tag-table-symbol is used by intern-tag-symbol | |
1584 | 549 filename file-type name name2 name3 tag-symbol |
428 | 550 tag-symbol-tables |
551 (case-fold-search nil)) | |
552 ;; Loop over the files mentioned in the TAGS file for each file, | |
553 ;; try to find its major-mode, then process tags appropriately. | |
554 (while (looking-at tags-file-pattern) | |
555 (goto-char (match-end 0)) | |
556 (setq filename (file-name-sans-versions (match-string 1)) | |
557 ;; We used to check auto-mode-alist for the proper | |
558 ;; file-type. This was way too slow, as it had to process | |
559 ;; an enormous amount of regexps for each time. Now we | |
560 ;; use the shotgun approach with only two regexps. | |
561 file-type (cond ((string-match "\\.\\([cC]\\|cc\\|cxx\\)\\'" | |
562 filename) | |
563 'c-mode) | |
564 ((string-match "\\.\\(el\\|cl\\|lisp\\)\\'" | |
565 filename) | |
566 'lisp-mode) | |
567 ((string-match "\\.scm\\'" filename) | |
568 'scheme-mode) | |
569 (t nil))) | |
442 | 570 (defvar c-mode-syntax-table) |
428 | 571 (set-syntax-table (cond ((and (eq file-type 'c-mode) |
572 c-mode-syntax-table) | |
573 c-mode-syntax-table) | |
574 ((eq file-type 'lisp-mode) | |
575 lisp-mode-syntax-table) | |
576 (t (standard-syntax-table)))) | |
577 ;; Clear loop variables. | |
1584 | 578 (setq name nil name2 nil name3 nil) |
428 | 579 (lmessage 'progress "%s..." filename) |
580 ;; Loop over the individual tag lines. | |
581 (while (not (or (eobp) (eq (char-after) ?\f))) | |
582 (cond ((and (eq file-type 'c-mode) | |
583 (looking-at "DEFUN[ \t]")) | |
584 ;; DEFUN | |
585 (or (looking-at tags-DEFUN-pattern) | |
586 (error "DEFUN doesn't fit pattern")) | |
587 (setq name (match-string 1) | |
1584 | 588 name2 (match-string 2) |
589 name3 (match-string 5))) | |
590 ;;((looking-at "\\s-") | |
428 | 591 ;; skip probably bogus entry: |
592 ;;) | |
593 ((and (eq file-type 'c-mode) | |
594 (looking-at ".*\\[")) | |
595 ;; Array | |
596 (cond ((not (looking-at tags-array-pattern)) | |
597 (message "array definition doesn't fit pattern") | |
598 (setq name nil)) | |
599 (t | |
600 (setq name (match-string 1))))) | |
601 ((and (eq file-type 'scheme-mode) | |
1584 | 602 (looking-at tags-schemish-pattern)) |
428 | 603 ;; Something Schemish (is this really necessary??) |
1584 | 604 (setq name (match-string 1) |
605 name2 (match-string 4))) | |
428 | 606 ((looking-at tags-def-pattern) |
607 ;; ??? | |
1584 | 608 (setq name (match-string 2) |
609 name2 (match-string 5)))) | |
428 | 610 ;; add the tags we found to the completion table |
611 (and name (intern-tag-symbol name)) | |
612 (and name2 (intern-tag-symbol name2)) | |
1584 | 613 (and name3 (intern-tag-symbol name3)) |
428 | 614 (forward-line 1))) |
615 (or (eobp) (error "Bad TAGS file"))) | |
616 (message "Adding %s to tags completion table...done" buffer-file-name)) | |
617 | |
618 | |
619 ;; Interactive find-tag | |
620 | |
621 (defvar find-tag-default-hook nil | |
622 "Function to call to create a default tag. | |
623 Make it buffer-local in a mode hook. The function is called with no | |
624 arguments.") | |
625 | |
626 (defvar find-tag-hook nil | |
627 "*Function to call after a tag is found. | |
628 Make it buffer-local in a mode hook. The function is called with no | |
629 arguments.") | |
630 | |
631 ;; Return a default tag to search for, based on the text at point. | |
632 (defun find-tag-default () | |
633 (or (and (not (memq find-tag-default-hook '(nil find-tag-default))) | |
793 | 634 (with-trapping-errors |
4755
c1784fd59d7d
Fix syntax of some uses of condition-case and with-trapping-errors.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
2067
diff
changeset
|
635 :operation 'find-tag-default-hook |
793 | 636 :error-form nil |
637 (funcall find-tag-default-hook))) | |
428 | 638 (symbol-near-point))) |
639 | |
640 ;; This function depends on the following symbols being bound properly: | |
641 ;; buffer-tag-table-list, | |
642 ;; tag-symbol-tables (value irrelevant, bound outside for efficiency) | |
643 (defun tag-completion-predicate (tag-symbol) | |
644 (and (boundp tag-symbol) | |
645 (setq tag-symbol-tables (symbol-value tag-symbol)) | |
646 (catch 'found | |
647 (while tag-symbol-tables | |
648 (when (memq (car tag-symbol-tables) buffer-tag-table-list) | |
649 (throw 'found t)) | |
650 (setq tag-symbol-tables (cdr tag-symbol-tables)))))) | |
651 | |
652 (defun buffer-tag-table-symbol-list () | |
653 (mapcar (lambda (table-name) | |
654 (intern table-name tag-completion-table)) | |
655 (buffer-tag-table-list))) | |
656 | |
657 (defvar find-tag-history nil "History list for find-tag-tag.") | |
658 | |
659 (defun find-tag-tag (prompt) | |
660 (let* ((default (find-tag-default)) | |
661 (buffer-tag-table-list (buffer-tag-table-symbol-list)) | |
662 tag-symbol-tables tag-name) | |
663 (setq tag-name | |
664 (completing-read | |
665 (if default | |
666 (format "%s(default %s) " prompt default) | |
667 prompt) | |
668 tag-completion-table 'tag-completion-predicate nil nil | |
440 | 669 'find-tag-history default)) |
670 tag-name)) | |
428 | 671 |
672 (defvar last-tag-data nil | |
673 "Information for continuing a tag search. | |
674 Is of the form (TAG POINT MATCHING-EXACT TAG-TABLE TAG-TABLE ...).") | |
675 | |
676 (defvar tags-loop-operate nil | |
677 "Form for `tags-loop-continue' to eval to change one file.") | |
678 | |
679 (defvar tags-loop-scan | |
680 '(error "%s" (substitute-command-keys | |
681 "No \\[tags-search] or \\[tags-query-replace] in progress.")) | |
682 "Form for `tags-loop-continue' to eval to scan one file. | |
683 If it returns non-nil, this file needs processing by evalling | |
684 \`tags-loop-operate'. Otherwise, move on to the next file.") | |
685 | |
686 (autoload 'get-symbol-syntax-table "symbol-syntax") | |
687 | |
688 (defun find-tag-internal (tagname) | |
487 | 689 |
428 | 690 (let ((next (null tagname)) |
691 (tmpnext (null tagname)) | |
692 ;; If tagname is a list: (TAGNAME), this indicates | |
693 ;; requiring an exact symbol match. | |
694 (exact (or tags-always-exact (consp tagname))) | |
695 (normal-syntax-table (syntax-table)) | |
696 (exact-syntax-table (get-symbol-syntax-table (syntax-table))) | |
697 tag-table-currently-matching-exact | |
698 tag-target exact-tagname | |
487 | 699 tag-tables tag-table-point file linebeg line startpos buf |
428 | 700 offset found pat syn-tab) |
701 (when (consp tagname) | |
702 (setq tagname (car tagname))) | |
703 (cond (next | |
704 (setq tagname (car last-tag-data)) | |
705 (setq tag-table-currently-matching-exact | |
706 (car (cdr (cdr last-tag-data))))) | |
707 (t | |
708 (setq tag-table-currently-matching-exact t))) | |
709 ;; \_ in the tagname is used to indicate a symbol boundary. | |
2067 | 710 (if tags-exuberant-ctags-optimization-p |
711 (setq exact-tagname (format "\C-?%s\C-a" tagname)) | |
712 (setq exact-tagname (format "\C-?%s\C-a\\|\ | |
713 \\_%s.?\C-?[0-9]*,[0-9]*$" tagname tagname)) | |
714 ) | |
428 | 715 (while (string-match "\\\\_" exact-tagname) |
716 (aset exact-tagname (1- (match-end 0)) ?b)) | |
717 (save-excursion | |
718 (catch 'found | |
719 ;; Loop searching for exact matches and then inexact matches. | |
720 (while (not (eq tag-table-currently-matching-exact 'neither)) | |
721 (cond (tmpnext | |
722 (setq tag-tables (cdr (cdr (cdr last-tag-data))) | |
723 tag-table-point (car (cdr last-tag-data))) | |
724 ;; Start from the beginning of the table list on the | |
725 ;; next iteration of the loop. | |
726 (setq tmpnext nil)) | |
727 (t | |
728 (setq tag-tables (buffer-tag-table-list) | |
729 tag-table-point 1))) | |
730 (if tag-table-currently-matching-exact | |
731 (setq tag-target exact-tagname | |
732 syn-tab exact-syntax-table) | |
733 (setq tag-target tagname | |
734 syn-tab normal-syntax-table)) | |
735 (with-search-caps-disable-folding tag-target t | |
736 (while tag-tables | |
737 (set-buffer (get-tag-table-buffer (car tag-tables))) | |
738 (bury-buffer (current-buffer)) | |
739 (goto-char (or tag-table-point (point-min))) | |
740 (setq tag-table-point nil) | |
741 (letf (((syntax-table) syn-tab) | |
742 (case-fold-search nil)) | |
743 ;; #### should there be support for non-regexp | |
744 ;; tag searches? | |
745 (while (re-search-forward tag-target nil t) | |
746 (and (save-match-data | |
442 | 747 (save-excursion |
748 (goto-char (match-beginning 0)) | |
749 (looking-at "[^\n\C-?]*\C-?"))) | |
428 | 750 ;; If we're looking for inexact matches, skip |
751 ;; exact matches since we've visited them | |
752 ;; already. | |
753 (or tag-table-currently-matching-exact | |
754 (letf (((syntax-table) exact-syntax-table)) | |
755 (save-excursion | |
756 (goto-char (match-beginning 0)) | |
757 (not (looking-at exact-tagname))))) | |
758 (throw 'found t)))) | |
759 (setq tag-tables | |
760 (nconc (tag-table-include-files) (cdr tag-tables))))) | |
761 (if (and (not exact) (eq tag-table-currently-matching-exact t)) | |
762 (setq tag-table-currently-matching-exact nil) | |
763 (setq tag-table-currently-matching-exact 'neither))) | |
764 (error "No %sentries %s %s" | |
765 (if next "more " "") | |
766 (if exact "matching" "containing") | |
767 tagname)) | |
442 | 768 (beginning-of-line) |
487 | 769 |
770 ;; from here down, synched with FSF 20.7 | |
771 ;; etags-snarf-tag and etags-goto-tag-location. --ben | |
772 | |
773 (if (save-excursion | |
774 (forward-line -1) | |
775 (looking-at "\f\n")) | |
776 (progn | |
777 ;; The match was for a source file name, not any tag | |
778 ;; within a file. Give text of t, meaning to go exactly | |
779 ;; to the location we specify, the beginning of the file. | |
780 (setq linebeg t | |
781 line nil | |
782 startpos 1) | |
783 (setq file | |
784 (expand-file-name (file-of-tag) | |
785 ;; In XEmacs, this needs to be | |
786 ;; relative to: | |
787 (or (file-name-directory (car tag-tables)) | |
788 "./")))) | |
789 (search-forward "\C-?") | |
790 (setq file | |
791 (expand-file-name (file-of-tag) | |
792 ;; In XEmacs, this needs to be | |
793 ;; relative to: | |
794 (or (file-name-directory (car tag-tables)) | |
795 "./"))) | |
796 (setq linebeg (buffer-substring (1- (point)) (point-at-bol))) | |
797 ;; Skip explicit tag name if present. | |
798 (search-forward "\001" (save-excursion (forward-line 1) (point)) t) | |
799 (if (looking-at "[0-9]") | |
800 (setq line (string-to-int (buffer-substring | |
801 (point) | |
802 (progn (skip-chars-forward "0-9") | |
803 (point)))))) | |
804 (search-forward ",") | |
805 (if (looking-at "[0-9]") | |
806 (setq startpos (string-to-int (buffer-substring | |
807 (point) | |
808 (progn (skip-chars-forward "0-9") | |
809 (point))))))) | |
810 ;; Leave point on the next line of the tags file. | |
811 (forward-line 1) | |
428 | 812 (setq last-tag-data |
813 (nconc (list tagname (point) tag-table-currently-matching-exact) | |
814 tag-tables)) | |
815 (setq buf (find-file-noselect file)) | |
487 | 816 |
817 ;; LINEBEG is the initial part of a line containing the tag and | |
818 ;; STARTPOS is the character position of LINEBEG within the file | |
819 ;; (starting from 1); LINE is the line number. If LINEBEG is t, | |
820 ;; it means the tag refers to exactly LINE or STARTPOS | |
821 ;; (whichever is present, LINE having preference, no searching). | |
822 ;; Either LINE or STARTPOS may be nil; STARTPOS is used if | |
823 ;; present. If the tag isn't exactly at the given position then | |
824 ;; look around that position using a search window which expands | |
825 ;; until it hits the start of file. | |
826 | |
428 | 827 (with-current-buffer buf |
828 (save-excursion | |
829 (save-restriction | |
830 (widen) | |
487 | 831 (if (eq linebeg t) |
832 ;; Direct file tag. | |
833 (cond (line (goto-line line)) | |
834 (startpos (goto-char startpos)) | |
835 (t (error "etags.el BUG: bogus direct file tag"))) | |
836 ;; Here we search for PAT in the range [STARTPOS - OFFSET, | |
837 ;; STARTPOS + OFFSET], with increasing values of OFFSET. | |
838 ;; | |
839 ;; We used to set the initial offset to 1000, but the | |
840 ;; actual sources show that finer-grained control is | |
841 ;; needed (e.g. two `hash_string's in src/symbols.c.) So, | |
842 ;; I changed 1000 to 100, and (* 3 offset) to (* 5 offset). | |
843 (setq offset 100) | |
844 (setq pat (concat (if (eq selective-display t) | |
845 "\\(^\\|\^m\\)" "^") | |
846 (regexp-quote linebeg))) | |
847 | |
848 ;; The character position in the tags table is 0-origin. | |
849 ;; Convert it to a 1-origin Emacs character position. | |
850 (if startpos (setq startpos (1+ startpos))) | |
851 ;; If no char pos was given, try the given line number. | |
852 (or startpos | |
853 (if line | |
854 (setq startpos (progn (goto-line line) | |
855 (point))))) | |
856 (or startpos | |
857 (setq startpos (point-min))) | |
858 ;; First see if the tag is right at the specified location. | |
859 (goto-char startpos) | |
860 (setq found (looking-at pat)) | |
861 (while (and (not found) | |
862 (progn | |
863 (goto-char (- startpos offset)) | |
864 (not (bobp)))) | |
865 (setq found | |
866 (re-search-forward pat (+ startpos offset) t) | |
867 offset (* 5 offset))) ; expand search window | |
868 ;; Finally, try finding it anywhere in the buffer. | |
869 (or found | |
870 (re-search-forward pat nil t) | |
871 (error "Rerun etags: `%s' not found in %s" | |
872 pat file)))) | |
873 ;; Position point at the right place | |
874 ;; if the search string matched an extra Ctrl-m at the beginning. | |
875 (and (eq selective-display t) | |
876 (looking-at "\^m") | |
877 (forward-char 1)) | |
878 (beginning-of-line) | |
879 (setq startpos (point)))) | |
428 | 880 (cons buf startpos)))) |
881 | |
882 ;;;###autoload | |
442 | 883 (defun find-tag-at-point (tagname &optional other-window) |
884 "*Find tag whose name contains TAGNAME. | |
885 Identical to `find-tag' but does not prompt for tag when called interactively; | |
886 instead, uses tag around or before point." | |
887 (interactive (if current-prefix-arg | |
888 '(nil nil) | |
889 (list (find-tag-default) nil))) | |
890 (find-tag tagname other-window)) | |
891 | |
892 ;;;###autoload | |
428 | 893 (defun find-tag (tagname &optional other-window) |
894 "*Find tag whose name contains TAGNAME. | |
895 Selects the buffer that the tag is contained in | |
896 and puts point at its definition. | |
897 If TAGNAME is a null string, the expression in the buffer | |
898 around or before point is used as the tag name. | |
899 If called interactively with a numeric argument, searches for the next tag | |
900 in the tag table that matches the tagname used in the previous find-tag. | |
901 If second arg OTHER-WINDOW is non-nil, uses another window to display | |
902 the tag. | |
903 | |
904 This version of this function supports multiple active tags tables, | |
905 and completion. | |
906 | |
907 Variables of note: | |
908 | |
909 tag-table-alist controls which tables apply to which buffers | |
910 tags-file-name a default tags table | |
911 tags-build-completion-table controls completion behavior | |
912 buffer-tag-table another way of specifying a buffer-local table | |
913 make-tags-files-invisible whether tags tables should be very hidden | |
914 tag-mark-stack-max how many tags-based hops to remember" | |
915 (interactive (if current-prefix-arg | |
916 '(nil nil) | |
917 (list (find-tag-tag "Find tag: ") nil))) | |
918 (let* ((local-find-tag-hook find-tag-hook) | |
919 (next (null tagname)) | |
920 (result (find-tag-internal tagname)) | |
921 (tag-buf (car result)) | |
922 (tag-point (cdr result))) | |
923 ;; Push old position on the tags mark stack. | |
924 (if (or (not next) | |
925 (not (memq last-command | |
926 '(find-tag find-tag-other-window tags-loop-continue)))) | |
927 (push-tag-mark)) | |
928 (if other-window | |
442 | 929 (pop-to-buffer tag-buf t) |
428 | 930 (switch-to-buffer tag-buf)) |
931 (widen) | |
932 (push-mark) | |
933 (goto-char tag-point) | |
934 (if find-tag-hook | |
935 (run-hooks 'find-tag-hook) | |
936 (if local-find-tag-hook | |
937 (run-hooks 'local-find-tag-hook)))) | |
938 (setq tags-loop-scan (list 'find-tag nil nil) | |
939 tags-loop-operate nil) | |
940 ;; Return t in case used as the tags-loop-scan. | |
941 t) | |
942 | |
943 ;;;###autoload | |
944 (defun find-tag-other-window (tagname &optional next) | |
442 | 945 "*Find tag whose name contains TAGNAME, in another window. |
428 | 946 Selects the buffer that the tag is contained in in another window |
947 and puts point at its definition. | |
948 If TAGNAME is a null string, the expression in the buffer | |
949 around or before point is used as the tag name. | |
950 If second arg NEXT is non-nil (interactively, with prefix arg), | |
951 searches for the next tag in the tag table | |
952 that matches the tagname used in the previous find-tag. | |
953 | |
954 This version of this function supports multiple active tags tables, | |
955 and completion. | |
956 | |
957 Variables of note: | |
958 | |
959 tag-table-alist controls which tables apply to which buffers | |
960 tags-file-name a default tags table | |
961 tags-build-completion-table controls completion behavior | |
962 buffer-tag-table another way of specifying a buffer-local table | |
963 make-tags-files-invisible whether tags tables should be very hidden | |
964 tag-mark-stack-max how many tags-based hops to remember" | |
965 (interactive (if current-prefix-arg | |
966 '(nil t) | |
967 (list (find-tag-tag "Find tag other window: ")))) | |
968 (if next | |
969 (find-tag nil t) | |
970 (find-tag tagname t))) | |
971 | |
972 | |
973 ;; Completion on tags in the buffer. | |
974 | |
975 (defun complete-symbol (&optional table predicate prettify) | |
976 (let* ((end (point)) | |
977 (beg (save-excursion | |
978 (backward-sexp 1) | |
979 ;;(while (= (char-syntax (following-char)) ?\') | |
980 ;; (forward-char 1)) | |
981 (skip-syntax-forward "'") | |
982 (point))) | |
983 (pattern (buffer-substring beg end)) | |
984 (table (or table obarray)) | |
985 (completion (try-completion pattern table predicate))) | |
986 (cond ((eq completion t)) | |
987 ((null completion) | |
988 (error "Can't find completion for \"%s\"" pattern)) | |
989 ((not (string-equal pattern completion)) | |
990 (delete-region beg end) | |
991 (insert completion)) | |
992 (t | |
993 (message "Making completion list...") | |
994 (let ((list (all-completions pattern table predicate))) | |
995 (if prettify | |
996 (setq list (funcall prettify list))) | |
997 (with-output-to-temp-buffer "*Help*" | |
998 (display-completion-list list))) | |
999 (message "Making completion list...%s" "done"))))) | |
1000 | |
1001 ;;;###autoload | |
1002 (defun tag-complete-symbol () | |
1003 "The function used to do tags-completion (using 'tag-completion-predicate)." | |
1004 (interactive) | |
1005 (let* ((buffer-tag-table-list (buffer-tag-table-symbol-list)) | |
1006 tag-symbol-tables) | |
1007 (complete-symbol tag-completion-table 'tag-completion-predicate))) | |
1008 | |
1009 | |
1010 ;; Applying a command to files mentioned in tag tables | |
1011 | |
1012 (defvar next-file-list nil | |
1013 "List of files for next-file to process.") | |
1014 | |
1015 ;;;###autoload | |
1016 (defun next-file (&optional initialize novisit) | |
1017 "Select next file among files in current tag table(s). | |
1018 | |
1019 A first argument of t (prefix arg, if interactive) initializes to the | |
1020 beginning of the list of files in the (first) tags table. If the argument | |
1021 is neither nil nor t, it is evalled to initialize the list of files. | |
1022 | |
1023 Non-nil second argument NOVISIT means use a temporary buffer | |
1024 to save time and avoid uninteresting warnings. | |
1025 | |
1026 Value is nil if the file was already visited; | |
1027 if the file was newly read in, the value is the filename." | |
1028 (interactive "P") | |
1029 (cond ((not initialize) | |
1030 ;; Not the first run. | |
1031 ) | |
1032 ((eq initialize t) | |
1033 ;; Initialize the list from the tags table. | |
1034 (setq next-file-list (buffer-tag-table-files))) | |
1035 (t | |
1036 ;; Initialize the list by evalling the argument. | |
1037 (setq next-file-list (eval initialize)))) | |
1038 (when (null next-file-list) | |
1039 (and novisit | |
1040 (get-buffer " *next-file*") | |
1041 (kill-buffer " *next-file*")) | |
1042 (error "All files processed")) | |
1043 (let* ((file (car next-file-list)) | |
1044 (buf (get-file-buffer file)) | |
1045 (new (not buf))) | |
1046 (pop next-file-list) | |
1047 | |
1048 (if (not (and new novisit)) | |
1049 (switch-to-buffer (find-file-noselect file novisit) t) | |
1050 ;; Like find-file, but avoids random junk. | |
1051 (set-buffer (get-buffer-create " *next-file*")) | |
1052 (kill-all-local-variables) | |
1053 (erase-buffer) | |
1054 (insert-file-contents file nil)) | |
1055 (widen) | |
1056 (when (> (point) (point-min)) | |
1057 (push-mark nil t) | |
1058 (goto-char (point-min))) | |
1059 (and new file))) | |
1060 | |
1061 ;;;###autoload | |
1062 (defun tags-loop-continue (&optional first-time) | |
1063 "Continue last \\[tags-search] or \\[tags-query-replace] command. | |
1064 Used noninteractively with non-nil argument to begin such a command (the | |
1065 argument is passed to `next-file', which see). | |
1066 Two variables control the processing we do on each file: | |
1067 the value of `tags-loop-scan' is a form to be executed on each file | |
1068 to see if it is interesting (it returns non-nil if so) | |
1069 and `tags-loop-operate' is a form to execute to operate on an interesting file | |
1070 If the latter returns non-nil, we exit; otherwise we scan the next file." | |
1071 (interactive) | |
1072 (let ((messaged nil) | |
1073 (more-files-p t) | |
1074 new) | |
1075 (while more-files-p | |
1076 ;; Scan files quickly for the first or next interesting one. | |
1077 (while (or first-time | |
1078 (save-restriction | |
1079 (widen) | |
1080 (not (eval tags-loop-scan)))) | |
1081 (setq new (next-file first-time | |
1082 tags-search-nuke-uninteresting-buffers)) | |
1083 ;; If NEW is non-nil, we got a temp buffer, | |
1084 ;; and NEW is the file name. | |
1085 (if (or messaged | |
1086 (and (not first-time) | |
1087 (> (device-baud-rate) search-slow-speed) | |
1088 (setq messaged t))) | |
1089 (lmessage 'progress | |
1090 "Scanning file %s..." (or new buffer-file-name))) | |
1091 (setq first-time nil) | |
1092 (goto-char (point-min))) | |
1093 | |
1094 ;; If we visited it in a temp buffer, visit it now for real. | |
1095 (if (and new tags-search-nuke-uninteresting-buffers) | |
1096 (let ((pos (point))) | |
1097 (erase-buffer) | |
1098 (set-buffer (find-file-noselect new)) | |
1099 (widen) | |
1100 (goto-char pos))) | |
1101 | |
1102 (switch-to-buffer (current-buffer)) | |
1103 | |
1104 ;; Now operate on the file. | |
1105 ;; If value is non-nil, continue to scan the next file. | |
1106 (setq more-files-p (eval tags-loop-operate))) | |
1107 (and messaged | |
1108 (null tags-loop-operate) | |
1109 (message "Scanning file %s...found" buffer-file-name)))) | |
1110 | |
1111 | |
1112 ;;;###autoload | |
1113 (defun tags-search (regexp &optional file-list-form) | |
1114 "Search through all files listed in tags table for match for REGEXP. | |
1115 Stops when a match is found. | |
1116 To continue searching for next match, use command \\[tags-loop-continue]. | |
1117 | |
1118 See documentation of variable `tag-table-alist'." | |
1119 (interactive "sTags search (regexp): ") | |
1120 (if (and (equal regexp "") | |
1121 (eq (car tags-loop-scan) 'with-search-caps-disable-folding) | |
1122 (null tags-loop-operate)) | |
1123 ;; Continue last tags-search as if by `M-,'. | |
1124 (tags-loop-continue nil) | |
1125 (setq tags-loop-scan `(with-search-caps-disable-folding ,regexp t | |
1126 (re-search-forward ,regexp nil t)) | |
1127 tags-loop-operate nil) | |
1128 (tags-loop-continue (or file-list-form t)))) | |
1129 | |
1130 ;;;###autoload | |
1131 (defun tags-query-replace (from to &optional delimited file-list-form) | |
1132 "Query-replace-regexp FROM with TO through all files listed in tags table. | |
1133 Third arg DELIMITED (prefix arg) means replace only word-delimited matches. | |
1134 If you exit (\\[keyboard-quit] or ESC), you can resume the query-replace | |
1135 with the command \\[tags-loop-continue]. | |
1136 | |
1137 See documentation of variable `tag-table-alist'." | |
1138 (interactive | |
1139 "sTags query replace (regexp): \nsTags query replace %s by: \nP") | |
1140 (setq tags-loop-scan `(with-search-caps-disable-folding ,from t | |
1141 (if (re-search-forward ,from nil t) | |
1142 ;; When we find a match, move back | |
1143 ;; to the beginning of it so perform-replace | |
1144 ;; will see it. | |
1145 (progn (goto-char (match-beginning 0)) t))) | |
1146 tags-loop-operate (list 'perform-replace from to t t | |
1147 (not (null delimited)))) | |
1148 (tags-loop-continue (or file-list-form t))) | |
1149 | |
1150 ;; Miscellaneous | |
1151 | |
1152 ;;;###autoload | |
1153 (defun list-tags (file) | |
1154 "Display list of tags in FILE." | |
1155 (interactive (list (read-file-name | |
1156 (if (buffer-file-name) | |
1157 (format "List tags (in file, %s by default): " | |
1158 (file-name-nondirectory (buffer-file-name))) | |
1159 "List tags (in file): ") | |
1160 nil (buffer-file-name) t))) | |
1161 (find-file-noselect file) | |
1162 (with-output-to-temp-buffer "*Tags List*" | |
1163 (princ "Tags in file ") | |
1164 (princ file) | |
1165 (terpri) | |
1166 (save-excursion | |
1167 (dolist (tags-file (with-current-buffer (get-file-buffer file) | |
1168 (buffer-tag-table-list))) | |
1169 ;; We don't want completions getting in the way. | |
1170 (let ((tags-build-completion-table nil)) | |
1171 (set-buffer (get-tag-table-buffer tags-file))) | |
1172 (goto-char (point-min)) | |
1173 (when | |
1174 (search-forward (concat "\f\n" (file-name-nondirectory file) ",") | |
1175 nil t) | |
1176 (forward-line 1) | |
1177 (while (not (or (eobp) (looking-at "\f"))) | |
1178 (princ (buffer-substring (point) | |
1179 (progn (skip-chars-forward "^\C-?") | |
1180 (point)))) | |
1181 (terpri) | |
1182 (forward-line 1))))))) | |
1183 | |
1184 ;;;###autoload | |
1185 (defun tags-apropos (string) | |
1186 "Display list of all tags in tag table REGEXP matches." | |
1187 (interactive "sTag apropos (regexp): ") | |
1188 (with-output-to-temp-buffer "*Tags List*" | |
1189 (princ "Tags matching regexp ") | |
1190 (prin1 string) | |
1191 (terpri) | |
1192 (save-excursion | |
1193 (visit-tags-table-buffer) | |
1194 (goto-char 1) | |
1195 (while (re-search-forward string nil t) | |
1196 (beginning-of-line) | |
1197 (princ (buffer-substring (point) | |
1198 (progn (skip-chars-forward "^\C-?") | |
1199 (point)))) | |
1200 (terpri) | |
1201 (forward-line 1))))) | |
1202 | |
1203 ;; #### copied from tags.el. This function is *very* big in FSF. | |
1204 (defun visit-tags-table-buffer () | |
1205 "Select the buffer containing the current tag table." | |
1206 (or tags-file-name | |
1207 (call-interactively 'visit-tags-table)) | |
1208 (set-buffer (or (get-file-buffer tags-file-name) | |
1209 (progn | |
1210 (setq tag-table-files nil) | |
1211 (find-file-noselect tags-file-name)))) | |
1212 (or (verify-visited-file-modtime (get-file-buffer tags-file-name)) | |
1213 (cond ((yes-or-no-p "Tags file has changed, read new contents? ") | |
1214 (revert-buffer t t) | |
1215 (setq tag-table-files nil)))) | |
1216 (or (eq (char-after 1) ?\^L) | |
1217 (error "File %s not a valid tag table" tags-file-name))) | |
1218 | |
1219 | |
1220 ;; Sample uses of find-tag-hook and find-tag-default-hook | |
1221 | |
1222 ;; This is wrong. We should either make this behavior default and | |
1223 ;; back it up, or not use it at all. For now, I've commented it out. | |
1224 ;; --hniksic | |
1225 | |
1226 ;; Example buffer-local tag finding | |
1227 | |
1228 ;(add-hook 'emacs-lisp-mode-hook 'setup-emacs-lisp-default-tag-hook) | |
1229 | |
1230 ;(defun setup-emacs-lisp-default-tag-hook () | |
1231 ; (cond ((eq major-mode 'emacs-lisp-mode) | |
1232 ; (make-variable-buffer-local 'find-tag-default-hook) | |
1233 ; (setq find-tag-default-hook 'emacs-lisp-default-tag)))) | |
1234 ;;; Run it once immediately | |
1235 ;(setup-emacs-lisp-default-tag-hook) | |
1236 ;(when (get-buffer "*scratch*") | |
1237 ; (with-current-buffer "*scratch*" | |
1238 ; (setup-emacs-lisp-default-tag-hook))) | |
1239 | |
1240 ;(defun emacs-lisp-default-tag () | |
1241 ; "Function to return a default tag for Emacs-Lisp mode." | |
1242 ; (let ((tag (or (variable-at-point) | |
1243 ; (function-at-point)))) | |
1244 ; (if tag (symbol-name tag)))) | |
1245 | |
1246 | |
1247 ;; Display short info on tag in minibuffer | |
1248 | |
1249 ;; Don't pollute `M-?' -- we may need it for more important stuff. --hniksic | |
1250 ;(if (null (lookup-key esc-map "?")) | |
1251 ; (define-key esc-map "?" 'display-tag-info)) | |
1252 | |
1253 (defun display-tag-info (tagname) | |
1254 "Prints a description of the first tag matching TAGNAME in the echo area. | |
1255 If this is an elisp function, prints something like \"(defun foo (x y z)\". | |
1256 That is, is prints the first line of the definition of the form. | |
1257 If this is a C-defined elisp function, it does something more clever." | |
1258 (interactive (if current-prefix-arg | |
1259 '(nil) | |
1260 (list (find-tag-tag "Display tag info: ")))) | |
1261 (let* ((results (find-tag-internal tagname)) | |
1262 (tag-buf (car results)) | |
1263 (tag-point (cdr results)) | |
1264 info lname min max fname args) | |
1265 (with-current-buffer tag-buf | |
1266 (save-excursion | |
1267 (save-restriction | |
1268 (widen) | |
1269 (goto-char tag-point) | |
1270 (cond ((let ((case-fold-search nil)) | |
1271 (looking-at "^DEFUN[ \t]")) | |
1272 (forward-sexp 1) | |
1273 (down-list 1) | |
1274 (setq lname (read (current-buffer)) | |
1275 fname (buffer-substring | |
1276 (progn (forward-sexp 1) (point)) | |
1277 (progn (backward-sexp 1) (point))) | |
1278 min (buffer-substring | |
1279 (progn (forward-sexp 3) (point)) | |
1280 (progn (backward-sexp 1) (point))) | |
1281 max (buffer-substring | |
1282 (progn (forward-sexp 2) (point)) | |
1283 (progn (backward-sexp 1) (point)))) | |
1284 (backward-up-list 1) | |
1285 (setq args (buffer-substring | |
1286 (progn (forward-sexp 2) (point)) | |
1287 (progn (backward-sexp 1) (point)))) | |
1288 (setq info (format "Elisp: %s, C: %s %s, #args: %s" | |
1289 lname | |
1290 fname args | |
1291 (if (string-equal min max) | |
1292 min | |
1293 (format "from %s to %s" min max))))) | |
1294 (t | |
1295 (setq info | |
1296 (buffer-substring | |
1297 (progn (beginning-of-line) (point)) | |
1298 (progn (end-of-line) (point))))))))) | |
1299 (message "%s" info)) | |
1300 (setq tags-loop-scan '(display-tag-info nil) | |
1301 tags-loop-operate nil) | |
1302 ;; Always return non-nil | |
1303 t) | |
1304 | |
1305 | |
1306 ;; Tag mark stack. | |
1307 | |
1308 (defvar tag-mark-stack1 nil) | |
1309 (defvar tag-mark-stack2 nil) | |
1310 | |
1311 (defcustom tag-mark-stack-max 16 | |
1312 "*The maximum number of elements kept on the mark-stack used | |
1313 by tags-search. See also the commands `\\[push-tag-mark]' and | |
1314 and `\\[pop-tag-mark]'." | |
1315 :type 'integer | |
1316 :group 'etags) | |
1317 | |
1318 (defun push-mark-on-stack (stack-symbol &optional max-size) | |
1319 (let ((stack (symbol-value stack-symbol))) | |
1320 (push (point-marker) stack) | |
1321 (cond ((and max-size | |
1322 (> (length stack) max-size)) | |
1323 (set-marker (car (nthcdr max-size stack)) nil) | |
1324 (setcdr (nthcdr (1- max-size) stack) nil))) | |
1325 (set stack-symbol stack))) | |
1326 | |
1327 (defun pop-mark-from-stack (stack-symbol1 stack-symbol2 &optional max-size) | |
1328 (let* ((stack (or (symbol-value stack-symbol1) | |
1329 (error "No more tag marks on stack"))) | |
1330 (marker (car stack)) | |
1331 (m-buf (marker-buffer marker))) | |
1332 (set stack-symbol1 (cdr stack)) | |
1333 (or m-buf | |
1334 (error "Marker has no buffer")) | |
1335 (or (buffer-live-p m-buf) | |
1336 (error "Buffer has been killed")) | |
1337 (push-mark-on-stack stack-symbol2 max-size) | |
1338 (switch-to-buffer m-buf) | |
1339 (widen) | |
1340 (goto-char marker))) | |
1341 | |
1342 (defun push-tag-mark () | |
1343 (push-mark-on-stack 'tag-mark-stack1 tag-mark-stack-max)) | |
1344 | |
1345 ;;;###autoload (define-key esc-map "*" 'pop-tag-mark) | |
1346 | |
1347 ;;;###autoload | |
1348 (defun pop-tag-mark (arg) | |
1349 "Go to last tag position. | |
1350 `find-tag' maintains a mark-stack seperate from the \\[set-mark-command] mark-stack. | |
1351 This function pops (and moves to) the tag at the top of this stack." | |
1352 (interactive "P") | |
1353 (if (not arg) | |
1354 (pop-mark-from-stack | |
1355 'tag-mark-stack1 'tag-mark-stack2 tag-mark-stack-max) | |
1356 (pop-mark-from-stack | |
1357 'tag-mark-stack2 'tag-mark-stack1 tag-mark-stack-max))) | |
1358 | |
1359 | |
1360 (provide 'etags) | |
1361 (provide 'tags) | |
1362 | |
1363 ;;; etags.el ends here |