home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / alt / lucidem / help / 382 < prev    next >
Encoding:
Text File  |  1992-09-04  |  47.3 KB  |  1,358 lines

  1. x-gateway: rodan.UU.NET from help-lucid-emacs to alt.lucid-emacs.help; Fri, 4 Sep 1992 15:19:06 EDT
  2. Date: Fri, 4 Sep 1992 21:17:31 +0200
  3. From: h.b.furuseth%usit.uio.no@lucid.com
  4. Message-ID: <9209041917.AAdurin13402@durin.uio.no>
  5. Subject: Re: tags-query-replace
  6. Newsgroups: alt.lucid-emacs.help
  7. Path: sparky!uunet!wendy-fate.uu.net!help-lucid-emacs
  8. Sender: help-lucid-emacs-request@lucid.com
  9. Lines: 1347
  10.  
  11. > complains
  12. >       Wrong type argument: syntax-table-p, nil
  13. > What do I need to do make it work?
  14.  
  15. That does not happen to me.  But here is a fix I wrote some time ago
  16. for lemacs-19.2/lisp/packages/etags.el.  It probably still has bugs,
  17. but at least it works better, and gives fewer warnings when compiled.
  18.  
  19.  
  20. Regards,
  21.  
  22. Hallvard
  23.  
  24. ;; Enhanced tags facility for Emacs.
  25. ;; Copyright 1985, 1986, 1988, 1990 Free Software Foundation, Inc.
  26.  
  27. ;; This file is part of GNU Emacs.
  28.  
  29. ;; GNU Emacs is distributed in the hope that it will be useful,
  30. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  31. ;; accepts responsibility to anyone for the consequences of using it
  32. ;; or for whether it serves any particular purpose or works at all,
  33. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  34. ;; License for full details.
  35.  
  36. ;; Everyone is granted permission to copy, modify and redistribute
  37. ;; GNU Emacs, but only under the conditions described in the
  38. ;; GNU Emacs General Public License.   A copy of this license is
  39. ;; supposed to have been given to you along with GNU Emacs so you
  40. ;; can know your rights and responsibilities.  It should be in a
  41. ;; file named COPYING.  Among other things, the copyright notice
  42. ;; and this notice must be preserved on all copies.
  43.  
  44. ;; Created by: Joe Wells, jbw@bucsf.bu.edu
  45. ;; Created on: Thu Mar 22 20:17:40 1990
  46. ;; Last modified by: Jamie Zawinski <jwz@lucid.com>
  47. ;; Last modified on: Wed Jan  1 15:09:18 1992
  48. ;; Filename: tags-fix.el
  49. ;; Purpose: enhanced tags functionality
  50. ;; Change log: 
  51. ;; 
  52. ;; Wed Jan  1 15:09:18 1992  Jamie Zawinski <jwz@lucid.com>
  53. ;;
  54. ;;      * Added Harlan's definition of visit-tags-table.  
  55. ;;      Renamed variable tags-always-build-completion-table to
  56. ;;      tags-build-completion-table and changed its semantics.
  57. ;;      Made the explicit buffer-local tags file be searched 
  58. ;;      first instead of last.
  59. ;;
  60. ;; Sun May 10 15:48:00 1992  Hallvard B Furuseth <h.b.furuseth@usit.uio.no>
  61. ;;
  62. ;;    Inserted visit-tags-table-buffer from tags.el, handle
  63. ;;    tag-file-name=nil, improved some doc strings and variable declarations.
  64. ;;
  65. ;; Fri Mar 29 01:48:06 1991  Jamie Zawinski <jwz@lucid.com>
  66. ;;
  67. ;;    * Made link-chasing and invisible-tags-files optional.
  68. ;;    Renamed delete and remove-duplicates to avoid possible name conflicts.
  69. ;;    Moved "provide" to end.  Added some documentation.
  70. ;; 
  71. ;; Sat Sep 22 22:28:33 1990  Joseph Wells  (jbw at bucsf.bu.edu)
  72. ;; 
  73. ;;     * Added handling for case where tag is typedef name immediately
  74. ;;     following struct definition.
  75. ;; 
  76. ;; Thu Sep 13 21:09:15 1990  Joseph Wells  (jbw at bucsf.bu.edu)
  77. ;; 
  78. ;;     * Fixed behavior not to bomb on missing tag table file.
  79. ;; 
  80.  
  81. ;; Sat Aug 11 18:07:01 1990  Joe Wells  (jbw at dodge.uswest.com)
  82. ;; 
  83. ;;     * Moved calling find-tag-default-hook into find-tag-default.  Put
  84. ;;     it inside a condition-case.  Use find-tag-default method when
  85. ;;     find-tag-default-hook fails or returns nil.
  86. ;; 
  87. ;; Wed Jul 25 17:16:43 1990  Joe Wells  (jbw at dodge.uswest.com)
  88. ;; 
  89. ;;     * Made it an error for a buffer to have no associated tag tables.
  90. ;; 
  91.  
  92. ;; enhancements:
  93. ;;  1. default tag tables based on filename
  94. ;;  2. multiple tag tables possible per file
  95. ;;  3. tag name completion for find-tag
  96. ;;  4. find-tag using regexp
  97. ;;  5. tag name completion in the buffer
  98. ;;  6. find-tag-default now works at beginning of tag
  99. ;;  7. buffer-local find-tag hook (used for info enhancement)
  100. ;;  8. buffer-local find-tag-default hook (used for info enhancement)
  101. ;;  9. show short info on tag match in minibuffer
  102. ;; 10. stack for backtracking from find-tag
  103. ;; 11. widen buffers for tags-search
  104. ;; 12. display message on successful search
  105. ;; 13. don't pull all files into memory for tags-search
  106. ;; 14. don't leave searched buffers on top of buffer list
  107. ;; 15. find-tag can specify exact symbol matches
  108. ;; 16. find-tag-default specifies an exact symbol match
  109. ;; 17. tags-files can be invisible
  110.  
  111. ;; configuration variables:
  112. ;;   tag-table-alist        controls which tables apply to which buffers
  113. ;;   tags-file-name        a default tags table
  114. ;;   buffer-tag-table        another way of specifying a buffer-local table
  115. ;;   make-tags-files-invisible    whether tags tables should be very hidden
  116. ;;   tag-mark-stack-max        how many tags-based hops to remember
  117.  
  118. ;; TODO:
  119. ;; 1. place cursor in echo area while searching
  120. ;; 2. document!
  121. ;; 3. determine semantics of interactively setting the tags file for a buffer
  122.  
  123. ;; Comments with **** mean something is left to be done.
  124.  
  125. ;; Derived from the original lisp/tags.el.
  126.  
  127. ;; Ideas and code from the work of the following people:
  128. ;; Andy Norman <ange@hplb.hpl.hp.com>, author of ange-tags.el
  129. ;; Ramana Rao <rao@arisia.xerox.com>
  130. ;; John Sturdy <jcgs@harlqn.co.uk>, author of tags-helper.el
  131. ;; Henry Kautz <kautz@allegra.att.com>, author of tag-completion.el
  132. ;; Dan LaLiberte <liberte@cs.uiuc.edu>, author of local-tags.el
  133. ;; Tom Dietterich <tgd@turing.cs.orst.edu>, author of quest.el
  134. ;; The author(s) of lisp/simple.el
  135. ;; Duke Briscoe <briscoe@cs.yale.edu>
  136. ;; Lynn Slater <lrs@indetech.com>, author of location.el
  137. ;; Shinichirou Sugou <shin@sgtp.apple.juice.or.jp>
  138. ;; an unidentified anonymous elisp hacker
  139.  
  140. ;; Installation instructions:
  141. ;;
  142. ;; Name this file tags-fix.el.
  143. ;; Put tags-fix.el, symlink-fix.el, symbol-syntax.el in your load path.
  144. ;;
  145. ;; Put the following code in your .emacs (or lisp/default.el)
  146. ;;
  147. ;;(fmakunbound 'visit-tags-table) ; obsolete
  148. ;;(fmakunbound 'find-tag)
  149. ;;(autoload 'find-tag "tags-fix" nil t)
  150. ;;(fmakunbound 'find-tag-other-window)
  151. ;;(autoload 'find-tag-other-window "tags-fix" nil t)
  152. ;;(fmakunbound 'lisp-complete-symbol)
  153. ;;(autoload 'lisp-complete-symbol "tags-fix" nil t)
  154. ;;(fmakunbound 'tag-complete-symbol)
  155. ;;(autoload 'tag-complete-symbol "tags-fix" nil t)
  156. ;;(fmakunbound 'next-file)
  157. ;;(autoload 'next-file "tags-fix" nil t)
  158. ;;(fmakunbound 'tags-loop-continue)
  159. ;;(autoload 'tags-loop-continue "tags-fix" nil t)
  160. ;;(fmakunbound 'tags-search)
  161. ;;(autoload 'tags-search "tags-fix" nil t)
  162. ;;(fmakunbound 'tags-query-replace)
  163. ;;(autoload 'tags-query-replace "tags-fix" nil t)
  164. ;;(fmakunbound 'display-tag-info)
  165. ;;(autoload 'display-tag-info "tags-fix" nil t)
  166. ;;(fmakunbound 'pop-tag-mark)
  167. ;;(autoload 'pop-tag-mark "tags-fix" nil t)
  168. ;;
  169. ;;(define-key esc-map "?" 'display-tag-info)
  170. ;;(define-key esc-map "*" 'pop-tag-mark)
  171. ;;
  172. ;;;; The following are not really implemented:
  173. ;;;;(fmakunbound 'set-buffer-tag-table)
  174. ;;;;(autoload 'set-buffer-tag-table "tags-fix" nil t)
  175. ;;(fmakunbound 'list-tags)
  176. ;;;;(autoload 'list-tags "tags-fix" nil t)
  177. ;;(fmakunbound 'tags-apropos)
  178. ;;;;(autoload 'tags-apropos "tags-fix" nil t)
  179.  
  180.  
  181. ;; Auxiliary functions
  182.  
  183. (defun tags-delete (item list)
  184.   "delete the item from the list, testing with equal.  Copies the list."
  185.   (cond ((null list)
  186.      nil)
  187.     ((equal item (car list))
  188.      (tags-delete item (cdr list)))
  189.     (t
  190.      (cons (car list) (tags-delete item (cdr list))))))
  191.  
  192. (defun tags-remove-duplicates (list)
  193.   "delete equal duplicates from the list; copies the list."
  194.   (cond ((null list)
  195.      nil)
  196.     (t
  197.      (cons (car list)
  198.            (tags-remove-duplicates (tags-delete (car list) (cdr list)))))))
  199.  
  200. ;; derived from generate-new-buffer
  201. (defun generate-new-buffer-name (name)
  202.   "Foo"
  203.   (if (not (get-buffer name))
  204.       name
  205.     (let ((count 1)
  206.       (template (concat name "<%d>"))
  207.       tempname)
  208.       (catch 'found
  209.     (while t
  210.       (setq tempname (format template count))
  211.       (if (not (get-buffer tempname))
  212.           (throw 'found tempname))
  213.       (setq count (1+ count)))))))
  214.  
  215.  
  216. ;; Tag tables for a buffer
  217.  
  218. (defvar tags-build-completion-table 'ask
  219.   "*If this variable is nil, then tags completion is disabled.
  220. If this variable is t, then things which prompt for tags will do so with 
  221.  completion across all known tags.
  222. If this variable is the symbol `ask', then you will be asked whether each
  223.  tags table should be added to the completion list as it is read in.
  224.  (With the exception that for very small tags tables, you will not be asked,
  225.  since they can be parsed quickly.)")
  226.  
  227.  
  228. (defvar tag-table-alist nil
  229.   "*A list which determines which tags files should be active for a 
  230. given buffer.  This is not really an association list, in that all 
  231. elements are checked.  The CAR of each element of this list is a 
  232. pattern against which the buffer's file name is compared; if it 
  233. matches, then the CDR of the list should be the name of the tags
  234. table to use.  If more than one element of this list matches the
  235. buffer's file name, then all of the associated tags tables will be
  236. used.  Earlier ones will be searched first.
  237.  
  238. If the CAR of elements of this list are strings, then they are treated
  239. as regular-expressions against which the file is compared (like the
  240. auto-mode-alist).  If they are not strings, then they are evaluated.
  241. If they evaluate to non-nil, then the current buffer is considered to
  242. match.
  243.  
  244. If the CDR of the elements of this list are strings, then they are
  245. assumed to name a TAGS file.  If they name a directory, then the string
  246. \"TAGS\" is appended to them to get the file name.  If they are not 
  247. strings, then they are evaluated, and must return an appropriate string.
  248.  
  249. For example:
  250.   (setq tag-table-alist
  251.     '((\"/usr/src/public/perl/\" . \"/usr/src/public/perl/perl-3.0/\")
  252.      (\"\\\\.el$\" . \"/usr/local/emacs/src/\")
  253.      (\"/jbw/gnu/\" . \"/usr15/degree/stud/jbw/gnu/\")
  254.      (\"\" . \"/usr/local/emacs/src/\")
  255.      ))
  256.  
  257. This means that anything in the /usr/src/public/perl/ directory should use
  258. the TAGS file /usr/src/public/perl/perl-3.0/TAGS; and file ending in .el should
  259. use the TAGS file /usr/local/emacs/src/TAGS; and anything in or below the
  260. directory /jbw/gnu/ should use the TAGS file /usr15/degree/stud/jbw/gnu/TAGS.
  261. A file called something like \"/usr/jbw/foo.el\" would use both the TAGS files
  262. /usr/local/emacs/src/TAGS and /usr15/degree/stud/jbw/gnu/TAGS (in that order)
  263. because it matches both patterns.
  264.  
  265. If the buffer-local variable `buffer-tag-table' is set, then it names a tags
  266. table that is searched before all others when find-tag is executed from this
  267. buffer.
  268.  
  269. If there is a file called \"TAGS\" in the same directory as the file in 
  270. question, then that tags file will always be used as well (after the
  271. `buffer-tag-table' but before the tables specified by this list.)
  272.  
  273. If the variable tags-file-name is set, then the tags file it names will apply
  274. to all buffers (for backwards compatibility.)  It is searched first.
  275. ")
  276.  
  277. (defvar buffer-tag-table nil
  278.   "*The name of one TAGS table to be used for this buffer in addition to the
  279. TAGS tables that the variable `tag-table-alist' specifies.  You can set this
  280. with meta-x set-buffer-tag-table.  See the documentation for the variable
  281. `tag-table-alist' for more information.")
  282. (make-variable-buffer-local 'buffer-tag-table)
  283.  
  284. (defvar tags-file-name nil
  285.   "*The name of the tags-table used by all buffers.  This is for backwards
  286. compatibility, and is largely supplanted by the variable tag-table-alist.")
  287. ;; (setq tags-file-name nil)  ; nuke previous value.  Is this cool?
  288.  
  289. ;; This will be used if it's loaded; don't force it on those who don't want it.
  290. ;;(autoload 'symlink-expand-file-name "symlink-fix")
  291.  
  292. (defun buffer-tag-table-list ()
  293.   "Returns a list (ordered) of the tags tables which should be used for 
  294. the current buffer."
  295.   (let (result expression)
  296.     (if buffer-tag-table
  297.     (setq result (cons buffer-tag-table result)))
  298.     (if (file-readable-p (concat default-directory "TAGS"))
  299.     (setq result (cons (concat default-directory "TAGS") result)))
  300.     (let ((key (or buffer-file-name
  301.            (concat default-directory (buffer-name))))
  302.       (alist tag-table-alist))
  303.       (while alist
  304.     (setq expression (car (car alist)))
  305.     ;; If the car of the alist item is a string, apply it as a regexp
  306.     ;; to the buffer-file-name.  Otherwise, evaluate it.  If the
  307.     ;; regexp matches, or the expression evaluates non-nil, then this
  308.     ;; item in tag-table-alist applies to this buffer.
  309.     (if (if (stringp expression)
  310.         (string-match (car (car alist)) key)
  311.           (condition-case nil
  312.           (eval expression)
  313.         (error nil)))
  314.         ;; Now evaluate the cdr of the alist item to get the name of
  315.         ;; the tag table file.
  316.         (progn
  317.           (setq expression 
  318.             (condition-case nil
  319.             (eval (cdr (car alist)))
  320.               (error nil)))
  321.           (if (stringp expression)
  322.           (setq result (cons expression result))
  323.         (error "Expression in tag-table-alist evaluated to non-string"))))
  324.     (setq alist (cdr alist))))
  325.     (or result tags-file-name
  326.     ;; **** I don't know if this is the right place to do this,
  327.     ;; **** Maybe it would be better to do this after (delq nil result).
  328.     (call-interactively 'visit-tags-table))
  329.     (if tags-file-name
  330.     (setq result (nconc result (list tags-file-name))))
  331.     (setq result
  332.       (mapcar
  333.        (function
  334.         (lambda (name)
  335.           (if (file-directory-p name)
  336.           (setq name (concat name "TAGS")))
  337.           (if (file-readable-p name)
  338.           (save-excursion
  339.             ;; get-tag-table-buffer has side-effects
  340.             (set-buffer (get-tag-table-buffer name))
  341.             buffer-file-name))))
  342.        result))
  343.     (setq result (delq nil result))
  344.     (or result (error "Buffer has no associated tag tables"))
  345.     (tags-remove-duplicates (nreverse result))))
  346.  
  347. (defun visit-tags-table (file)
  348.   "Tell tags commands to use tags table file FILE first.
  349. FILE should be the name of a file created with the `etags' program.
  350. A directory name is ok too; it means file TAGS in that directory."
  351.   (interactive (list (read-file-name "Visit tags table: (default TAGS) "
  352.                      default-directory
  353.                      (expand-file-name "TAGS" default-directory)
  354.                      t)))
  355.   (if (string-equal file "") 
  356.       (setq tags-file-name nil)
  357.       (progn
  358.         (setq file (expand-file-name file))
  359.         (if (file-directory-p file)
  360.             (setq file (expand-file-name "TAGS" file)))
  361.         (setq tags-file-name file))))
  362.  
  363. ;; **** What should the semantics of this be?
  364. (defun set-buffer-tag-table (file)
  365.   "In addition to the tags tables specified by the variable `tag-table-alist',
  366. each buffer can have one additional table.  This command sets that.
  367. See the documentation for the variable `tag-table-alist' for more information."
  368.   (interactive
  369.    (list
  370.      (read-file-name "Visit tags table: (directory sufficient) "
  371.              nil default-directory t)))
  372.   (or file (error "No TAGS file name supplied"))
  373.   (setq file (expand-file-name file))
  374.   (if (file-directory-p file)
  375.       (setq file (concat file "TAGS")))
  376.   (or (file-exists-p file) (error "TAGS file missing: %s" file))
  377.   (setq buffer-tag-table file))
  378.  
  379.  
  380. ;; Manipulating the tag table buffer
  381.  
  382. (defconst tag-table-completion-status nil
  383.   "Indicates whether a completion table has been built, or has explicitly not 
  384. been built.  this is nil, t, or 'disabled.")
  385. (make-variable-buffer-local 'tag-table-completion-status)
  386.  
  387. (defvar make-tags-files-invisible nil
  388.   "*If true, TAGS-files will not show up in buffer-lists or be 
  389. selectable (or deletable.)")
  390.  
  391. (defconst tag-table-files nil
  392.   "If the current buffer is a TAGS table, this holds a list of the files 
  393. referenced by this file, or nil if that hasn't been computed yet.")
  394. (make-variable-buffer-local 'tag-table-files)
  395.  
  396. (defun get-tag-table-buffer (tag-table)
  397.   "Returns a buffer visiting the give TAGS table, reverting if appropriate,
  398. and possibly building a completion-table."
  399.   (or (stringp tag-table)
  400.       (error "Bad tags file name supplied: %s" tag-table))
  401.   ;; add support for removing symbolic links from name
  402.   (if (fboundp 'symlink-expand-file-name)
  403.       (setq tag-table (symlink-expand-file-name tag-table)))
  404.   (let (buf build-completion check-name)
  405.     (setq buf (get-file-buffer tag-table))
  406.     (or buf
  407.     (if (file-readable-p tag-table)
  408.         (setq buf (find-file-noselect tag-table)
  409.           check-name t)
  410.       (error "No such tags file: %s" tag-table)))
  411.     (save-excursion
  412.       (set-buffer buf)
  413.       ;; make the TAGS buffer invisible
  414.       (if (and check-name
  415.            make-tags-files-invisible
  416.            (string-match "\\`[^ ]" (buffer-name)))
  417.       (rename-buffer (generate-new-buffer-name
  418.               (concat " " (buffer-name)))))
  419.       (or (verify-visited-file-modtime buf)
  420.       (cond ((yes-or-no-p
  421.           (format "Tags file %s has changed, read new contents? "
  422.               tag-table))
  423.          (revert-buffer t t)
  424.          (if (eq tag-table-completion-status t)
  425.              (setq tag-table-completion-status nil))
  426.          (setq tag-table-files nil))))
  427.       (or (eq (char-after 1) ?\f)
  428.       (error "File %s not a valid tags file" tag-table))
  429.       (or (memq tag-table-completion-status '(t disabled))
  430.       (setq build-completion t))
  431.       (and build-completion
  432.        (if (cond
  433.         ((eq tags-build-completion-table nil)
  434.          nil)
  435.         ((eq tags-build-completion-table t)
  436.          t)
  437.         ((eq tags-build-completion-table 'ask)
  438.          ;; don't bother asking for small ones
  439.          (or (< (buffer-size) 20000)
  440.              (y-or-n-p
  441.               (format "Build tag completion table for %s? "
  442.                   tag-table))))
  443.         (t (error
  444.             "tags-build-completion-table is not t, nil, or ask.")))
  445.            (condition-case foo
  446.            (progn
  447.              (add-to-tag-completion-table)
  448.              (setq tag-table-completion-status t))
  449.          ;; Allow user to C-g out correctly
  450.          (quit
  451.           (setq tag-table-completion-status nil)
  452.           (setq quit-flag t)
  453.           (eval t)))
  454.          (setq tag-table-completion-status 'disabled))))
  455.     buf))
  456.  
  457. ;; This function is unchanged from lisp/tags.el:
  458. (defun file-of-tag ()
  459.   "Return the file name of the file whose tags point is within.
  460. Assumes the tag table is the current buffer.
  461. File name returned is relative to tag table file's directory."
  462.   (let ((opoint (point))
  463.     prev size)
  464.     (save-excursion
  465.      (goto-char (point-min))
  466.      (while (< (point) opoint)
  467.        (forward-line 1)
  468.        (end-of-line)
  469.        (skip-chars-backward "^,\n")
  470.        (setq prev (point))
  471.        (setq size (read (current-buffer)))
  472.        (goto-char prev)
  473.        (forward-line 1)
  474.        (forward-char size))
  475.      (goto-char (1- prev))
  476.      (buffer-substring (point)
  477.                (progn (beginning-of-line) (point))))))
  478.  
  479. (defun tag-table-files (tag-table)
  480.   "Returns a list of the files referenced by the named TAGS table."
  481.   (save-excursion
  482.     (set-buffer (get-tag-table-buffer tag-table))
  483.     (or tag-table-files
  484.     (let (files prev size)
  485.       (goto-char (point-min))
  486.       (while (not (eobp))
  487.         (forward-line 1)
  488.         (end-of-line)
  489.         (skip-chars-backward "^,\n")
  490.         (setq prev (point))
  491.         (setq size (read (current-buffer)))
  492.         (goto-char prev)
  493.         (setq files (cons (expand-file-name
  494.                    (buffer-substring (1- (point))
  495.                          (save-excursion
  496.                            (beginning-of-line)
  497.                            (point)))
  498.                    default-directory)
  499.                   files))
  500.         (forward-line 1)
  501.         (forward-char size))
  502.       (setq tag-table-files (nreverse files))))
  503.     tag-table-files))
  504.  
  505. ;; **** should this be on previous page?
  506. (defun buffer-tag-table-files ()
  507.   "Returns a list of all files referenced by all TAGS tables that 
  508. this buffer uses."
  509.   (apply (function append)
  510.      (mapcar (function tag-table-files)
  511.          (buffer-tag-table-list))))
  512.  
  513.  
  514. ;; Building the completion table
  515.  
  516. ;; Test cases for building completion table; must handle these properly:
  517. ;; Lisp_Int, XSETINT, current_column 60,2282
  518. ;;       Lisp_Int, XSETINT, point>NumCharacters ? 0 : CharAt(363,9935
  519. ;;       Lisp_Int, XSETINT, point<=FirstCharacter ? 0 : CharAt(366,10108
  520. ;;     point<=FirstCharacter || CharAt(378,10630
  521. ;;     point>NumCharacters || CharAt(382,10825
  522. ;; DEFUN ("x-set-foreground-color", Fx_set_foreground_color,191,4562
  523. ;; DEFUN ("x-set-foreground-color", Fx_set_foreground_color,191,4562
  524. ;; DEFUN ("*", Ftimes,1172,32079
  525. ;; DEFUN ("/=", Fneq,1035,28839
  526. ;; defun_internal 4199,101362
  527. ;; int pure[PURESIZE / sizeof 53,1564
  528. ;; char staticvec1[NSTATICS * sizeof 667,17608
  529. ;;  Date: 04 May 87 23:53:11 PDT 26,1077
  530. ;; #define anymacroname(324,4344
  531. ;; (define-key ctl-x-map 311,11784
  532. ;; (define-abbrev-table 'c-mode-abbrev-table 24,1016
  533. ;; static char *skip_white(116,3443
  534. ;; static foo 348,11643
  535. ;; (defun texinfo-insert-@code 91,3358
  536. ;; (defvar texinfo-kindex)29,1105
  537. ;; (defun texinfo-format-\. 548,18376
  538. ;; (defvar sm::menu-kludge-y 621,22726
  539. ;; (defvar *mouse-drag-window* 103,3642
  540. ;; (defun simula-back-level(317,11263
  541. ;; } DPxAC,380,14024
  542. ;; } BM_QCB;69,2990
  543. ;; #define MTOS_DONE\t
  544.  
  545. ;; "^[^ ]+ +\\([^ ]+\\) "
  546.  
  547. ;; void *find_cactus_segment(116,2444
  548. ;; void *find_pdb_segment(162,3688
  549. ;; void init_dclpool(410,10739
  550. ;; WORD insert_draw_command(342,8881
  551. ;; void *req_pdbmem(579,15574
  552.  
  553. (defvar tag-completion-table (make-vector 511 0))
  554.  
  555. (defvar tag-symbol)
  556. (defvar tag-table-symbol)
  557. (defvar tag-symbol-tables)
  558. (defvar buffer-tag-table-list)
  559.  
  560. ;; make two versions of this, macro and non-macro,
  561. ;; and have the correct one used depending whether it's byte compiled
  562. ;; (well I think that's a little silly -- only lusers run interpreted! -jwz)
  563. (defmacro intern-tag-symbol (tag)
  564.   (`(progn
  565.       (setq tag-symbol (intern (, tag) tag-completion-table)
  566.         tag-symbol-tables (and (boundp tag-symbol)
  567.                    (symbol-value tag-symbol)))
  568.       (or (memq tag-table-symbol tag-symbol-tables)
  569.       (set tag-symbol (cons tag-table-symbol tag-symbol-tables))))))
  570.  
  571. (defun intern-tag-symbol2 (tag)
  572.   (setq tag-symbol (intern tag tag-completion-table)
  573.     tag-symbol-tables (and (boundp tag-symbol)
  574.                    (symbol-value tag-symbol)))
  575.   (or (memq tag-table-symbol tag-symbol-tables)
  576.       (set tag-symbol (cons tag-table-symbol tag-symbol-tables))))
  577.  
  578. ;; This won't be evaluated at during byte-compilation, thus ensuring the
  579. ;; macro version will be used then.  Since the macro version is too slow
  580. ;; to use unless its usages are byte-compiled, we want to make sure we use
  581. ;; the non-macro version if we are using the non byte-compiled version of
  582. ;; add-to-tag-completion-table.
  583. (fset 'intern-tag-symbol (symbol-function 'intern-tag-symbol2))
  584.  
  585. ;; Can't use "\\s " in these patterns because that will include newline
  586. (defconst tags-DEFUN-pattern
  587.           "DEFUN[ \t]*(\"\\([^\"]+\\)\",[ \t]*\\(\\(\\sw\\|\\s_\\)+\\),\C-?")
  588. (defconst tags-array-pattern ".*[ \t]+\\([^ \[]+\\)\\[")
  589. (defconst tags-def-pattern
  590.           "\\(.*[ \t]+\\)?\\(\\(\\sw\\|\\s_\\)+\\)[ ();,\t]*\C-?"
  591. ;; "\\(.*[ \t]+\\)?\\(\\(\\sw\\|\\s_\\)+\\)[ ()]*\C-?"
  592. ;; "\\(\\sw\\|\\s_\\)+[ ()]*\C-?"
  593.       )
  594. (defconst tags-file-pattern "^\f\n\\([^,]+\\),[0-9]+\n")
  595.  
  596. (defun add-to-tag-completion-table ()
  597.   "Sucks the current buffer (a TAGS table) into the completion-table."
  598.   (message "Adding %s to tags completion table..."
  599.        buffer-file-name)
  600.   (goto-char (point-min))
  601.   (let ((tag-table-symbol (intern buffer-file-name tag-completion-table))
  602.     (original-syntax-table (syntax-table))
  603.     ;; tag-table-symbol is used by intern-tag-symbol
  604.     filename file-type name name2 tag-symbol eol-point
  605.     tag-symbol-tables file-type-syntax-table)
  606.     (unwind-protect
  607.     ;; loop over the files mentioned in the TAGS file
  608.     ;; for each file, try to find its major-mode,
  609.     ;; then process tags appropriately
  610.     (while (looking-at tags-file-pattern)
  611.       (goto-char (match-end 0))
  612.       (setq filename (buffer-substring (match-beginning 1) (match-end 1)))
  613.       (setq filename (file-name-sans-versions filename))
  614.       ;; clear loop variables
  615.       (setq file-type nil)
  616.       (setq file-type-syntax-table nil)
  617.       (setq name nil name2 nil)
  618.       (let ((alist auto-mode-alist)
  619.         (case-fold-search (eq system-type 'vax-vms)))
  620.         ;; loop over pairs of regexps and major-modes
  621.         (while (and (not file-type) alist)
  622.           (if (string-match (car (car alist)) filename)
  623.           (setq file-type (cdr (car alist))))
  624.           (setq alist (cdr alist))))
  625.       ;; try to find a syntax table whose name begins with the major-mode
  626.       (if file-type
  627.           (setq file-type-syntax-table
  628.             (intern (concat (symbol-name file-type)
  629.                     "-syntax-table"))))
  630.       ;;      (message "%s %s" filename file-type-syntax-table)
  631.       (if (and file-type-syntax-table (boundp file-type-syntax-table))
  632.           (set-syntax-table (symbol-value file-type-syntax-table))
  633.         (set-syntax-table (standard-syntax-table)))
  634.       ;; loop over the individual tag lines
  635.       (while (not (or (eobp) (eq (following-char) ?\f)))
  636.         (cond ((and (eq file-type 'c-mode)
  637.             (let ((case-fold-search nil))
  638.               (looking-at "DEFUN[ \t]")))
  639.            (or (looking-at tags-DEFUN-pattern)
  640.                (error "DEFUN doesn't fit pattern"))
  641.            (setq name (buffer-substring (match-beginning 1)
  642.                         (match-end 1)))
  643.            (setq name2 (buffer-substring (match-beginning 2)
  644.                          (match-end 2))))
  645.           ((looking-at "\\s ")
  646.            ;; skip probably bogus entry:
  647.            )
  648.           ((and (eq file-type 'c-mode)
  649.             (looking-at ".*\\["))
  650.            (or (looking-at tags-array-pattern)
  651.                (error "array definition doesn't fit pattern"))
  652.            (setq name (buffer-substring (match-beginning 1)
  653.                         (match-end 1))))
  654.           ((looking-at tags-def-pattern)
  655.            (setq name (buffer-substring (match-beginning 2)
  656.                         (match-end 2)))))
  657.         ;; add the tags we found to the completion table
  658.         (if name (intern-tag-symbol name))
  659.         (if name2 (intern-tag-symbol name2))
  660.         (forward-line 1)))
  661.       (set-syntax-table original-syntax-table))
  662.     (or (eobp) (error "Bad TAGS file")))
  663.   (message "Adding %s to tags completion table...done"
  664.        buffer-file-name))
  665.  
  666.  
  667. ;; Interactive find-tag
  668.  
  669. (defvar find-tag-default-hook nil
  670.   "****Function to call to create a default tag.
  671. Make it buffer-local in a mode hook.
  672. The function is called with no args.")
  673.  
  674. (defvar find-tag-hook nil
  675.   "****Function to call after a hook is found.
  676. Make it buffer-local in a mode hook.
  677. The function is called with no args.")
  678.  
  679. ;; Return a default tag to search for, based on the text at point.
  680. (defun find-tag-default ()
  681.   (or (and (boundp 'find-tag-default-hook)
  682.        (not (memq find-tag-default-hook '(nil find-tag-default)))
  683.        (condition-case data
  684.            (funcall find-tag-default-hook)
  685.          (error
  686.           (message "value of find-tag-default-hook signalled error: %s"
  687.                data)
  688.           (sit-for 1)
  689.           nil)))
  690.       (save-excursion
  691.     (if (not (memq (char-syntax (preceding-char)) '(?w ?_)))
  692.         (while (not (looking-at "\\sw\\|\\s_\\|\\'"))
  693.           (forward-char 1)))
  694.     (while (looking-at "\\sw\\|\\s_")
  695.       (forward-char 1))
  696.     (if (re-search-backward "\\sw\\|\\s_" nil t)
  697.         (regexp-quote
  698.          (progn (forward-char 1)
  699.             (buffer-substring (point)
  700.                       (progn (forward-sexp -1)
  701.                          (while (looking-at "\\s'")
  702.                            (forward-char 1))
  703.                          (point)))))
  704.       nil))))
  705.  
  706. ;;"\\(\\s \\|\\s.\\|\\s\(\\|\\s\)\\|\\s'\\|\\s\"\\|\\s$\\|\\s/\\|\\s\\\\|\\s<\\|\\s>\\)"
  707. ;;"[ \";]"
  708.  
  709. ;;(defun non-symbol-char-regexp ()
  710. ;;  (let ((i 0)
  711. ;;    (numchars (length (syntax-table)))
  712. ;;    symbol-chars)
  713. ;;    (while (< i numchars)
  714. ;;      (if (memq (char-syntax i) '(?w ?_))
  715. ;;      (setq symbol-chars (cons i symbol-chars)))
  716. ;;      (setq i (1+ i)))
  717. ;;    (concat symbol-chars)))
  718.  
  719. ;; This function depends on the following symbols being bound properly:
  720. ;; buffer-tag-table-list,
  721. ;; tag-symbol-tables (value irrelevant, bound outside for efficiency)
  722. (defun tag-completion-predicate (tag-symbol)
  723.   (and (boundp tag-symbol)
  724.        (setq tag-symbol-tables (symbol-value tag-symbol))
  725.        (catch 'found
  726.      (while tag-symbol-tables
  727.        (if (memq (car tag-symbol-tables) buffer-tag-table-list)
  728.            (throw 'found t))
  729.        (setq tag-symbol-tables (cdr tag-symbol-tables))))))
  730.  
  731. (defun buffer-tag-table-symbol-list ()
  732.   (mapcar (function
  733.        (lambda (table-name)
  734.          (intern table-name tag-completion-table)))
  735.       (buffer-tag-table-list)))
  736.     
  737. ;;(defun strip-regexp-border (pattern)
  738. ;;  ;; Avoid displaying ugly regexp borders to the user
  739. ;;  (cond (pattern
  740. ;;     (if (or (string-match "\\`\\[[^\]]+\\]" pattern)
  741. ;;         ;;(string-match "\\`\\\\(\\([^\\\\]\\|\\\\[^\)]\\)+\\\\)"
  742. ;;         ;;              pattern)
  743. ;;         ;;(string-match "\\`\\\\[b<>`'WsS]" pattern)
  744. ;;         )
  745. ;;         (setq pattern (substring pattern
  746. ;;                      (match-end 0))))
  747. ;;     (if (or (string-match "\\[[^\]]+\\]\\'" pattern)
  748. ;;         ;;(string-match "\\\\(\\([^\\\\]\\|\\\\[^\)]\\)+\\\\)\\'"
  749. ;;         ;;              pattern)
  750. ;;         ;;(string-match "\\\\[b<>`'WsS]\\'" pattern)
  751. ;;         )
  752. ;;         (setq pattern (substring pattern 0
  753. ;;                      (match-beginning 0))))))
  754. ;;  pattern)
  755.  
  756. (defun find-tag-tag (prompt)
  757.   (let* ((default (find-tag-default))
  758.      (buffer-tag-table-list (buffer-tag-table-symbol-list))
  759.      tag-symbol-tables tag-name)
  760.     (setq tag-name
  761.       (completing-read
  762.        (if default
  763.            (format "%s(default %s) " prompt default)
  764.          prompt)
  765.        tag-completion-table 'tag-completion-predicate nil nil))
  766.     (if (string-equal tag-name "")
  767.     (list default)            ;indicate exact symbol match
  768.       tag-name)))
  769.  
  770. (defvar last-tag-data nil
  771. "Information for continuing a tag search.
  772. Is of the form (TAG POINT TAG-TABLE TAG-TABLE ...).")
  773.  
  774. (defvar tags-loop-form nil
  775.   "Form for tags-loop-continue to eval to process one file.
  776. If it returns nil, it is through with one file; move on to next.")
  777.  
  778. (autoload 'get-symbol-syntax-table "symbol-syntax")
  779.  
  780. (defun find-tag-internal (tagname)
  781.   "Foo"
  782.   (let ((local-find-tag-hook find-tag-hook)
  783.     (next (null tagname))
  784.     (exact (consp tagname))
  785.     symbol-border tag-target
  786.     tag-tables tag-table-point file linebeg startpos target buf
  787.     offset found pat syn-tab)
  788.     (if exact (setq tagname (car tagname)))
  789.     (cond (next
  790.        (setq tag-tables (cdr (cdr last-tag-data)))
  791.        (setq tagname (car last-tag-data))
  792.        (setq tag-table-point (car (cdr last-tag-data))))
  793.       (t
  794.        (setq tag-tables (buffer-tag-table-list))
  795.        (setq tag-table-point 1)))
  796.     ;; If tagname is a list: (TAGNAME), this indicates requiring an exact
  797.     ;; symbol match.  Similarly, \_ in the tagname is used to indicate a
  798.     ;; symbol boundary.
  799.     (cond ((or exact
  800.            (string-match "\\\\_" tagname))
  801.        (setq symbol-border t)
  802.        (if exact
  803.            (setq tag-target (concat "\\_" tagname "\\_"))
  804.          (setq tag-target (copy-sequence tagname)))
  805.        (while (string-match "\\\\_" tag-target)
  806.          (aset tag-target (1- (match-end 0)) ?b))
  807.        (setq syn-tab (get-symbol-syntax-table (syntax-table)))
  808.        ;;       (let ((i 0)
  809.        ;;         (len (length tag-target))
  810.        ;;         j)
  811.        ;;         (while (< i len)
  812.        ;;           (cond ((eq ?\\ (aref tag-target i))
  813.        ;;              (setq j (1+ i))
  814.        ;;              (if (eq ?_ (aref tag-target j))
  815.        ;;              (aset tag-target j ?b))))
  816.        ;;           (setq i (1+ i))))
  817.        )
  818.       (t
  819.        (setq tag-target tagname)
  820.        (setq syn-tab (syntax-table))))
  821.     (save-excursion
  822.       (catch 'found
  823.     (while tag-tables
  824.       (set-buffer (get-tag-table-buffer (car tag-tables)))
  825.       (bury-buffer (current-buffer))
  826.       (goto-char (or tag-table-point (point-min)))
  827.       (setq tag-table-point nil)
  828.       (let ((osyn (syntax-table))
  829.         case-fold-search)
  830.         (set-syntax-table syn-tab)
  831.         (unwind-protect
  832.         ;; **** should there be support for non-regexp tag searches?
  833.         (while (re-search-forward tag-target nil t)
  834.           (if (looking-at "[^\n\C-?]*\C-?")
  835.               (throw 'found t)))
  836.           (set-syntax-table osyn)))
  837.       (setq tag-tables (cdr tag-tables)))
  838.     (error "No %sentries %s %s"
  839.            (if next "more " "")
  840.            (if exact "matching" "containing")
  841.            tagname))
  842.       (search-forward "\C-?")
  843.       (setq file (expand-file-name (file-of-tag)))
  844.       (setq linebeg
  845.         (buffer-substring (1- (point))
  846.                   (save-excursion (beginning-of-line) (point))))
  847.       (search-forward ",")
  848.       (setq startpos (read (current-buffer)))
  849.       (setq last-tag-data (nconc (list tagname (point)) tag-tables)))
  850.     (setq buf (find-file-noselect file))
  851.     (save-excursion
  852.       (set-buffer buf)
  853.       (save-excursion
  854.     (save-restriction
  855.       (widen)
  856.       (setq offset 1000)
  857.       (setq pat (concat "^" (regexp-quote linebeg)))
  858.       (or startpos (setq startpos (point-min)))
  859.       (while (and (not found)
  860.               (progn
  861.             (goto-char (- startpos offset))
  862.             (not (bobp))))
  863.         (setq found (re-search-forward pat (+ startpos offset) t))
  864.         (setq offset (* 3 offset)))
  865.       (or found
  866.           (re-search-forward pat nil t)
  867.           (error "%s not found in %s" pat file))
  868.       (beginning-of-line)
  869.       (setq startpos (point)))))
  870.     (cons buf startpos)))
  871.  
  872. (defun find-tag (tagname &optional other-window)
  873.   "*Find tag whose name contains TAGNAME.
  874.  Selects the buffer that the tag is contained in
  875. and puts point at its definition.
  876.  If TAGNAME is a null string, the expression in the buffer
  877. around or before point is used as the tag name.
  878.  If called interactively with a numeric argument, searches for the next tag
  879. in the tag table that matches the tagname used in the previous find-tag.
  880.  If second arg OTHER-WINDOW is non-nil, uses another window to display
  881. the tag.
  882.  
  883. This version of this function supports multiple active tags tables,
  884. and completion.
  885.  
  886. Variables of note:
  887.  
  888.   tag-table-alist        controls which tables apply to which buffers
  889.   tags-file-name        a default tags table
  890.   tags-build-completion-table   controls completion behavior
  891.   buffer-tag-table        another way of specifying a buffer-local table
  892.   make-tags-files-invisible    whether tags tables should be very hidden
  893.   tag-mark-stack-max        how many tags-based hops to remember"
  894.   (interactive (if current-prefix-arg
  895.            '(nil nil)
  896.          (list (find-tag-tag "Find tag: ") nil)))
  897.   (let* ((local-find-tag-hook find-tag-hook)
  898.      (next (null tagname))
  899.      (result (find-tag-internal tagname))
  900.      (tag-buf (car result))
  901.      (tag-point (cdr result)))
  902.     ;; push old position
  903.     (if (or (not next)
  904.         (not (memq last-command
  905.                '(find-tag find-tag-other-window tags-loop-continue))))
  906.     (push-tag-mark))
  907.     (if other-window
  908.     (pop-to-buffer tag-buf)
  909.       (switch-to-buffer tag-buf))
  910.     (widen)
  911.     (push-mark)
  912.     (goto-char tag-point)
  913.     (if find-tag-hook
  914.     (funcall find-tag-hook)
  915.       (if local-find-tag-hook
  916.       (funcall local-find-tag-hook))))
  917.   (setq tags-loop-form (list 'find-tag nil nil))
  918.   ;; Return t in case used as the tags-loop-form.
  919.   t)
  920.  
  921. ;; This function is unchanged from lisp/tags.el:
  922. (defun find-tag-other-window (tagname)
  923.   "*Find tag whose name contains TAGNAME.
  924.  Selects the buffer that the tag is contained in in another window
  925. and puts point at its definition.
  926.  If TAGNAME is a null string, the expression in the buffer
  927. around or before point is used as the tag name.
  928.  If second arg NEXT is non-nil (interactively, with prefix arg),
  929. searches for the next tag in the tag table
  930. that matches the tagname used in the previous find-tag.
  931.  
  932. This version of this function supports multiple active tags tables,
  933. and completion.
  934.  
  935. Variables of note:
  936.  
  937.   tag-table-alist        controls which tables apply to which buffers
  938.   tags-file-name        a default tags table
  939.   tags-build-completion-table   controls completion behavior
  940.   buffer-tag-table        another way of specifying a buffer-local table
  941.   make-tags-files-invisible    whether tags tables should be very hidden
  942.   tag-mark-stack-max        how many tags-based hops to remember"
  943.   (interactive (if current-prefix-arg
  944.            '(nil)
  945.          (list (find-tag-tag "Find tag other window: "))))
  946.   (find-tag tagname t))
  947.  
  948.  
  949. ;; Completion on tags in the buffer
  950.  
  951. (defun lisp-complete-symbol ()
  952.   "*Perform completion on Lisp symbol preceding point.
  953. That symbol is compared against the symbols that exist
  954. and any additional characters determined by what is there
  955. are inserted.
  956. If the symbol starts just after an open-parenthesis,
  957. only symbols with function definitions are considered.
  958. Otherwise, all symbols with function definitions, values
  959. or properties are considered."
  960.   (interactive)
  961.   (let ((buffer-syntax (syntax-table)))
  962.     (unwind-protect
  963.     (progn
  964.       (if lisp-mode-syntax-table
  965.           (set-syntax-table lisp-mode-syntax-table))
  966.       (let ((fn (save-excursion
  967.               (backward-sexp 1)
  968.               (while (= (char-syntax (following-char)) ?\')
  969.             (forward-char 1))
  970.               (eq (preceding-char) ?\())))
  971.         (complete-symbol
  972.          obarray
  973.          (if fn
  974.          'fboundp
  975.            (function
  976.         (lambda (sym)
  977.           (or (boundp sym)
  978.               (fboundp sym)
  979.               (symbol-plist sym)))))
  980.          (if (not fn)
  981.          ;; prettify the completion list by marking fns with " <f>"
  982.          (function
  983.           (lambda (list)
  984.             (let (new)
  985.               (while list
  986.             (setq new (cons (if (fboundp (intern (car list)))
  987.                         (list (car list) " <f>")
  988.                       (car list))
  989.                     new))
  990.             (setq list (cdr list)))
  991.               (nreverse new))))))))
  992.       ;; unwind-protected
  993.       (set-syntax-table buffer-syntax))))
  994.  
  995. (defun complete-symbol (&optional table predicate prettify)
  996.   (let* ((end (point))
  997.      (beg (save-excursion
  998.         (backward-sexp 1)
  999.         (while (= (char-syntax (following-char)) ?\')
  1000.           (forward-char 1))
  1001.         (point)))
  1002.      (pattern (buffer-substring beg end))
  1003.      (table (or table obarray))
  1004.      (completion (try-completion pattern table predicate)))
  1005.     (cond ((eq completion t))
  1006.       ((null completion)
  1007.        (message "Can't find completion for \"%s\"" pattern)
  1008.        (ding))
  1009.       ((not (string-equal pattern completion))
  1010.        (delete-region beg end)
  1011.        (insert completion))
  1012.       (t
  1013.        (message "Making completion list...")
  1014.        (let ((list (all-completions pattern table predicate)))
  1015.          (if prettify
  1016.          (setq list (funcall prettify list)))
  1017.          (with-output-to-temp-buffer "*Help*"
  1018.            (display-completion-list list)))
  1019.        (message "Making completion list...%s" "done")))))
  1020.  
  1021. (defun tag-complete-symbol ()
  1022.   "The function used to do tags-completion (using 'tag-completion-predicate)."
  1023.   (interactive)
  1024.   (let* ((buffer-tag-table-list (buffer-tag-table-symbol-list))
  1025.      tag-symbol-tables)
  1026.     (complete-symbol tag-completion-table 'tag-completion-predicate)))
  1027.  
  1028.  
  1029. ;; Applying a command to files mentioned in tag tables
  1030.  
  1031. (defvar next-file-list nil
  1032.   "List of files for next-file to process.")
  1033.  
  1034. (defun next-file (&optional initialize)
  1035.   "Select next file among files in current tag table(s).
  1036. Non-nil argument (prefix arg, if interactive) initializes to the beginning 
  1037. of the list of files in the (first) tag table."
  1038.   (interactive "P")
  1039.   (if initialize
  1040.       (setq next-file-list (buffer-tag-table-files)))
  1041.   (or next-file-list
  1042.       (error "All files processed."))
  1043.   (let* ((file (car next-file-list))
  1044.      (buf (get-file-buffer file))
  1045.      new)
  1046.     (setq next-file-list (cdr next-file-list))
  1047.     (or buf
  1048.     (setq buf (find-file-noselect file)
  1049.           new t))
  1050.     (switch-to-buffer buf t)
  1051.     (widen)
  1052.     (cond ((> (point) (point-min))
  1053.        (push-mark nil t)
  1054.        (goto-char (point-min))))
  1055.     new))
  1056.  
  1057. (defun tags-loop-continue (&optional first-time)
  1058.   "Continue last \\[tags-search] or \\[tags-query-replace] command.
  1059. Used noninteractively with non-nil argument
  1060. to begin such a command.  See variable tags-loop-form."
  1061.   (interactive)
  1062.   (let (buf-is-new message)
  1063.     (cond (first-time
  1064.        (setq buf-is-new (next-file t))
  1065.        (message "Scanning file %s..." buffer-file-name)
  1066.        (setq message t)))
  1067.     ;; **** (let ((cursor-in-echo-area t)))
  1068.     (while (not (eval tags-loop-form))
  1069.       (if (and buf-is-new (not (buffer-modified-p)))
  1070.       (kill-buffer (current-buffer)))
  1071.       (setq buf-is-new (next-file))
  1072.       (message "Scanning file %s..." buffer-file-name)
  1073.       (setq message t))
  1074.     (switch-to-buffer (current-buffer))
  1075.     (if message
  1076.     (message "Scanning file %s...done" buffer-file-name))))
  1077.  
  1078. ;; This function is unchanged from lisp/tags.el:
  1079. (defun tags-search (regexp)
  1080.   "Search through all files listed in tag table for match for REGEXP.
  1081. Stops when a match is found.
  1082. To continue searching for next match, use command \\[tags-loop-continue].
  1083.  
  1084. See documentation of variable tag-table-alist."
  1085.   (interactive "sTags search (regexp): ")
  1086.   (if (and (equal regexp "")
  1087.        (eq (car tags-loop-form) 're-search-forward))
  1088.       (tags-loop-continue nil)
  1089.     (setq tags-loop-form
  1090.       (list 're-search-forward regexp nil t))
  1091.     (tags-loop-continue t)))
  1092.  
  1093. ;; This function is unchanged from lisp/tags.el:
  1094. (defun tags-query-replace (from to &optional delimited)
  1095.   "Query-replace-regexp FROM with TO through all files listed in tag table.
  1096. Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
  1097. If you exit (C-G or ESC), you can resume the query-replace
  1098. with the command \\[tags-loop-continue].
  1099.  
  1100. See documentation of variable tag-table-alist."
  1101.   (interactive "sTags query replace (regexp): \nsTags query replace %s by: \nP")
  1102.   (setq tags-loop-form
  1103.     (list 'and (list 'save-excursion
  1104.              (list 're-search-forward from nil t))
  1105.           (list 'not (list 'perform-replace from to t t 
  1106.                    (not (null delimited))))))
  1107.   (tags-loop-continue t))
  1108.  
  1109.  
  1110. ;; Miscellaneous
  1111.  
  1112. ;; **** need to alter
  1113. ;; This function is unchanged from lisp/tags.el:
  1114. (defun list-tags (string)
  1115.   "Display list of tags in file FILE.
  1116. FILE should not contain a directory spec
  1117. unless it has one in the tag table."
  1118.   (interactive "sList tags (in file): ")
  1119.   (with-output-to-temp-buffer "*Tags List*"
  1120.     (princ "Tags in file ")
  1121.     (princ string)
  1122.     (terpri)
  1123.     (save-excursion
  1124.      (visit-tags-table-buffer)
  1125.      (goto-char 1)
  1126.      (search-forward (concat "\f\n" string ","))
  1127.      (forward-line 1)
  1128.      (while (not (or (eobp) (looking-at "\f")))
  1129.        (princ (buffer-substring (point)
  1130.                 (progn (skip-chars-forward "^\C-?")
  1131.                        (point))))
  1132.        (terpri)
  1133.        (forward-line 1)))))
  1134.  
  1135. ;; **** need to alter
  1136. ;; This function is unchanged from lisp/tags.el:
  1137. (defun tags-apropos (string)
  1138.   "Display list of all tags in tag table REGEXP matches."
  1139.   (interactive "sTag apropos (regexp): ")
  1140.   (with-output-to-temp-buffer "*Tags List*"
  1141.     (princ "Tags matching regexp ")
  1142.     (prin1 string)
  1143.     (terpri)
  1144.     (save-excursion
  1145.      (visit-tags-table-buffer)
  1146.      (goto-char 1)
  1147.      (while (re-search-forward string nil t)
  1148.        (beginning-of-line)
  1149.        (princ (buffer-substring (point)
  1150.                 (progn (skip-chars-forward "^\C-?")
  1151.                        (point))))
  1152.        (terpri)
  1153.        (forward-line 1)))))
  1154.  
  1155. ;; **** copied from tags.el
  1156. (defun visit-tags-table-buffer ()
  1157.   "Select the buffer containing the current tag table.
  1158. This is a file whose name is in the variable tags-file-name."
  1159.   (or tags-file-name
  1160.       (call-interactively 'visit-tags-table))
  1161.   (set-buffer (or (get-file-buffer tags-file-name)
  1162.           (progn
  1163.             (setq tag-table-files nil)
  1164.             (find-file-noselect tags-file-name))))
  1165.   (or (verify-visited-file-modtime (get-file-buffer tags-file-name))
  1166.       (cond ((yes-or-no-p "Tags file has changed, read new contents? ")
  1167.          (revert-buffer t t)
  1168.          (setq tag-table-files nil))))
  1169.   (or (eq (char-after 1) ?\^L)
  1170.       (error "File %s not a valid tag table" tags-file-name)))
  1171.  
  1172.  
  1173. ;; Sample uses of find-tag-hook and find-tag-default-hook
  1174.  
  1175. ;; Example buffer-local tag finding
  1176.  
  1177. (or (boundp 'emacs-lisp-mode-hook)
  1178.     (setq emacs-lisp-mode-hook nil))
  1179. (if (eq (car-safe emacs-lisp-mode-hook) 'lambda)
  1180.     (setq emacs-lisp-mode-hook (list emacs-lisp-mode-hook)))
  1181. (or (memq 'setup-emacs-lisp-default-tag-hook emacs-lisp-mode-hook)
  1182.     (setq emacs-lisp-mode-hook
  1183.       (cons 'setup-emacs-lisp-default-tag-hook emacs-lisp-mode-hook)))
  1184.  
  1185. (defun setup-emacs-lisp-default-tag-hook ()
  1186.   (cond ((eq major-mode 'emacs-lisp-mode)
  1187.      (make-variable-buffer-local 'find-tag-default-hook)
  1188.      (setq find-tag-default-hook 'emacs-lisp-default-tag))))
  1189. ;; Run it once immediately
  1190. (setup-emacs-lisp-default-tag-hook)
  1191. (if (get-buffer "*scratch*")
  1192.     (save-excursion (set-buffer "*scratch*")
  1193.             (setup-emacs-lisp-default-tag-hook)))
  1194.  
  1195. (defun emacs-lisp-default-tag ()
  1196.   "Function to return a default tag for Emacs-Lisp mode."
  1197.   (let ((tag (or (variable-at-point)
  1198.          (function-called-at-point))))
  1199.     (if tag (symbol-name tag))))
  1200.  
  1201. ;;(defun Info-find-tag-hook ()
  1202. ;;  "Function to call after finding a tag in Info-mode."
  1203. ;;  (let ((onode Info-current-node)
  1204. ;;    (ofile Info-current-file)
  1205. ;;    (opoint (point)))
  1206. ;;    (if (not (string= "*info*" (buffer-name)))
  1207. ;;    (progn                ; replace current *info* file
  1208. ;;      (kill-buffer "*info*")
  1209. ;;      (rename-buffer "*info*")))
  1210. ;;    (or (eq major-mode 'Info-mode)
  1211. ;;    (Info-mode))
  1212. ;;    (setq Info-current-file
  1213. ;;      (file-name-sans-versions buffer-file-name))
  1214. ;;    (Info-select-node)
  1215. ;;    (or (and (equal onode Info-current-node)
  1216. ;;         (equal ofile Info-current-file))
  1217. ;;    (setq Info-history (cons (list ofile onode opoint)
  1218. ;;                 Info-history)))))
  1219. ;;
  1220. ;;;; Info-mode does not have a hook, so patch in the necessary calls.
  1221. ;;
  1222. ;;(require 'info)
  1223. ;;
  1224. ;;;; Only do this once
  1225. ;;(fset 'Info-mode
  1226. ;;      (append (symbol-function 'Info-mode)
  1227. ;;          (list '(make-local-variable 'find-tag-hook)
  1228. ;;            '(setq find-tag-hook 'Info-find-tag-hook)
  1229. ;;            '(modify-syntax-entry ?\' "."))))
  1230.  
  1231.  
  1232. ;; Display short info on tag in minibuffer
  1233.  
  1234. (if (null (lookup-key esc-map "?"))
  1235.     (define-key esc-map "?" 'display-tag-info))
  1236.  
  1237. (defun display-tag-info (tagname)
  1238.   "Prints a description of the first tag matching TAGNAME in the echo area.
  1239. If this is an elisp function, prints something like \"(defun foo (x y z)\".
  1240. That is, is prints the first line of the definition of the form.
  1241. If this is a C-defined elisp function, it does something more clever."
  1242.   (interactive (if current-prefix-arg
  1243.            '(nil)
  1244.          (list (find-tag-tag "Display tag info: "))))
  1245.   (let* ((results (find-tag-internal tagname))
  1246.      (tag-buf (car results))
  1247.      (tag-point (cdr results))
  1248.      info lname min max fname args)
  1249.     (save-excursion
  1250.       (set-buffer tag-buf)
  1251.       (save-excursion
  1252.     (save-restriction
  1253.       (widen)
  1254.       (goto-char tag-point)
  1255.       (cond ((let ((case-fold-search nil))
  1256.            (looking-at "^DEFUN[ \t]"))
  1257.          (forward-sexp 1)
  1258.          (down-list 1)
  1259.          (setq lname (read (current-buffer))
  1260.                fname (buffer-substring
  1261.                   (progn (forward-sexp 1) (point))
  1262.                   (progn (backward-sexp 1) (point)))
  1263.                min (buffer-substring
  1264.                 (progn (forward-sexp 3) (point))
  1265.                 (progn (backward-sexp 1) (point)))
  1266.                max (buffer-substring
  1267.                 (progn (forward-sexp 2) (point))
  1268.                 (progn (backward-sexp 1) (point))))
  1269.          (backward-up-list 1)
  1270.          (setq args (buffer-substring
  1271.                  (progn (forward-sexp 2) (point))
  1272.                  (progn (backward-sexp 1) (point))))
  1273.          (setq info (format "Elisp: %s, C: %s %s, #args: %s"
  1274.                     lname
  1275.                     fname args
  1276.                     (if (string-equal min max)
  1277.                     min
  1278.                       (format "from %s to %s" min max)))))
  1279.         (t
  1280.          (setq info
  1281.                (buffer-substring
  1282.             (progn (beginning-of-line) (point))
  1283.             (progn (end-of-line) (point)))))))))
  1284.     (message "%s" info))
  1285.   (setq tags-loop-form '(display-tag-info nil))
  1286.   ;; Always return non-nil
  1287.   t)
  1288.  
  1289.  
  1290. ;; Keep track of old locations before finding tags
  1291.  
  1292. (defvar tag-mark-stack1 nil)
  1293. (defvar tag-mark-stack2 nil)
  1294. (defvar tag-mark-stack-max 16
  1295.   "*The maximum number of elements kept on the mark-stack used
  1296. by tags-search.  See also the commands push-tag-mark (\\[push-tag-mark])
  1297. and pop-tag-mark. (\\[pop-tag-mark]).")
  1298.  
  1299. (defun push-mark-on-stack (stack-symbol &optional max-size)
  1300.   (let ((stack (symbol-value stack-symbol)))
  1301.     (setq stack (cons (point-marker) stack))
  1302.     (cond ((and max-size
  1303.         (> (length stack) max-size))
  1304.        (set-marker (car (nthcdr max-size stack)) nil)
  1305.        (setcdr (nthcdr (1- max-size) stack) nil)))
  1306.     (set stack-symbol stack)))
  1307.  
  1308. (defun pop-mark-from-stack (stack-symbol1 stack-symbol2 &optional max-size)
  1309.   (let* ((stack (or (symbol-value stack-symbol1)
  1310.             (error "No more tag marks on stack")))
  1311.      (marker (car stack))
  1312.      (m-buf (marker-buffer marker)))
  1313.     (set stack-symbol1 (cdr stack))
  1314.     (or m-buf
  1315.     (error "Marker has no buffer"))
  1316.     (if (null (buffer-name m-buf))
  1317.     (error "Buffer has been killed"))
  1318.     (push-mark-on-stack stack-symbol2 max-size)
  1319.     (switch-to-buffer m-buf)
  1320.     (widen)
  1321.     (goto-char (marker-position marker))))
  1322.  
  1323. (defun push-tag-mark ()
  1324.   (push-mark-on-stack 'tag-mark-stack1 tag-mark-stack-max))
  1325.  
  1326. (if (memq (lookup-key esc-map "*") '(nil undefined))
  1327.     (define-key esc-map "*" 'pop-tag-mark))
  1328.  
  1329. (defun pop-tag-mark (arg)
  1330.   "find-tag maintains a mark-stack seperate from the \\[set-mark-command] mark-stack.
  1331. This function pops (and moves to) the tag at the top of this stack."
  1332.   (interactive "P")
  1333.   (if (not arg)
  1334.       (pop-mark-from-stack
  1335.        'tag-mark-stack1 'tag-mark-stack2 tag-mark-stack-max)
  1336.     (pop-mark-from-stack
  1337.      'tag-mark-stack2 'tag-mark-stack1 tag-mark-stack-max)))
  1338.  
  1339.  
  1340.  
  1341. ;; John Sturdy <jcgs@harlqn.co.uk>
  1342. ;; (defun lookup-tag (use-rec-edit)
  1343. ;;   "Show a tag from the current tags name list in the other window for
  1344. ;; reference, then restore the window layout after a pause. With prefix
  1345. ;; arg, go into a recursive edit instead of pausing."
  1346. ;;   (interactive "P")
  1347. ;;   (save-window-excursion
  1348. ;;     (save-excursion
  1349. ;;       (find-tag-other-window (completing-read "Tag name: " tags-name-list))
  1350. ;;       (if use-rec-edit
  1351. ;;           (recursive-edit)
  1352. ;;         (sit-for show-tag-time)))))
  1353.  
  1354. ;(provide 'tags-fix)
  1355. (provide 'tags)
  1356.