Remove non-free old and crusty clearcase pkg
[packages] / xemacs-packages / semantic / semanticdb-skel.el
1 ;;; semanticdb-skel.el --- Semantic database extensions for SKEL
2
3 ;;; Copyright (C) 2002, 2003, 2004, 2005, 2006 Eric M. Ludlam
4
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: tags
7 ;; X-RCS: $Id: semanticdb-skel.el,v 1.1 2007-11-26 15:10:48 michaels Exp $
8
9 ;; This file is not part of GNU Emacs.
10
11 ;; Semanticdb is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; This software is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25 ;; 
26 ;;; Commentary:
27 ;;
28 ;; If you want to make an omniscient semanticdb database, start with
29 ;; this skeleton.  Replace `SKEL' with your language.  Implement those
30 ;; areas described by comments.
31 ;;
32
33 (require 'semanticdb-search)
34 (eval-when-compile
35   ;; For generic function searching.
36   (require 'eieio)
37   (require 'eieio-opt)
38   )
39 ;;; Code:
40
41 ;;; Classes:
42 (defclass semanticdb-table-SKEL (semanticdb-search-results-table)
43   ((major-mode :initform SKEL-mode)
44    )
45   "A table for returning search results from SKEL.")
46
47 (defclass semanticdb-project-database-SKEL
48   (semanticdb-project-database
49    ;; Use SINGLETON if there should be only one copy of this database.
50    ;; Do not use this if you need a different copy for different projects.
51    ;; eieio-singleton
52    )
53   ((new-table-class :initform semanticdb-table-SKEL
54                     :type class
55                     :documentation
56                     "New tables created for this database are of this class.")
57    )
58   "Database representing SKEL.")
59
60 ;; Create the database, and add it to searchable databases for SKEL mode.
61 (defvar-mode-local YOUR-MAJOR-mode semanticdb-project-system-databases
62   (list 
63    (semanticdb-project-database-SKEL "SKEL"))
64   "Search SKEL for symbols.")
65
66 ;; NOTE: Be sure to modify this to the best advantage of your
67 ;;       language.
68 (defvar-mode-local YOUR-MAJOR-mode semanticdb-find-default-throttle
69   '(project omniscience)
70   "Search project files, then search this omniscience database.
71 It is not necessary to to system or recursive searching because of
72 the omniscience database.")
73
74 ;;; Filename based methods
75 ;;
76 (defmethod semanticdb-get-database-tables ((obj semanticdb-project-database-SKEL))
77   "For a SKEL database, there are no explicit tables.
78 Create one of our special tables that can act as an intermediary."
79   ;; NOTE: This method overrides an accessor for the `tables' slot in 
80   ;;       a database.  You can either construct your own (like tmp here
81   ;;       or you can manage any number of tables.
82
83   ;; We need to return something since there is always the "master table"
84   ;; The table can then answer file name type questions.
85   (when (not (slot-boundp obj 'tables))
86     (let ((newtable (semanticdb-table-emacs-lisp "tmp")))
87       (oset obj tables (list newtable))
88       (oset newtable parent-db obj)
89       (oset newtable tags nil)
90       ))
91   (call-next-method))
92
93 (defmethod semanticdb-file-table ((obj semanticdb-project-database-SKEL) filename)
94   "From OBJ, return FILENAME's associated table object."
95   ;; NOTE: See not for `semanticdb-get-database-tables'.
96   (car (semanticdb-get-database-tables obj))
97   )
98
99 (defmethod semanticdb-get-tags ((table semanticdb-table-SKEL ))
100   "Return the list of tags belonging to TABLE."
101   ;; NOTE: Omniscient databases probably don't want to keep large tabes
102   ;;       lolly-gagging about.  Keep internal Emacs tables empty and
103   ;;       refer to alternate databases when you need something.
104   nil)
105
106 (defmethod semanticdb-equivalent-mode ((table semanticdb-table-SKEL) &optional buffer)
107   "Return non-nil if TABLE's mode is equivalent to BUFFER.
108 Equivalent modes are specified by by `semantic-equivalent-major-modes'
109 local variable."
110   (save-excursion
111     (set-buffer buffer)
112     (eq (or mode-local-active-mode major-mode) 'SKEL-mode)))
113
114 ;;; Usage
115 ;;
116 ;; Unlike other tables, an omniscent database does not need to
117 ;; be associated with a path.  Use this routine to always add ourselves
118 ;; to a search list.
119 (define-mode-local-override semanticdb-find-translate-path SKEL-mode
120   (path brutish)
121   "Return a list of semanticdb tables asociated with PATH.
122 If brutish, do the default action.
123 If not brutish, do the default action, and append the system
124 database (if available.)"
125   (let ((default
126           ;; When we recurse, disable searching of system databases
127           ;; so that our ELisp database only shows up once when
128           ;; we append it in this iteration.
129           (let ((semanticdb-search-system-databases nil)
130                 )
131             (semanticdb-find-translate-path-default path brutish))))
132     ;; Don't add anything if BRUTISH is on (it will be added in that fcn)
133     ;; or if we aren't supposed to search the system.
134     (if (or brutish (not semanticdb-search-system-databases))
135         default
136       (let ((tables (apply #'append
137                            (mapcar
138                             (lambda (db) (semanticdb-get-database-tables db))
139                             semanticdb-project-system-databases))))
140         (append default tables)))))
141
142 ;;; Search Overrides
143 ;;
144 ;; NOTE WHEN IMPLEMENTING: Be sure to add doc-string updates explaining
145 ;; how your new search routines are implemented.
146 ;;
147 (defmethod semanticdb-find-tags-by-name-method
148   ((table semanticdb-table-SKEL) name &optional tags)
149   "Find all tags named NAME in TABLE.
150 Return a list of tags."
151   (if tags
152       ;; If TAGS are passed in, then we don't need to do work here.
153       (call-next-method)
154     ;; YOUR IMPLEMENTATION HERE
155     ))
156
157 (defmethod semanticdb-find-tags-by-name-regexp-method
158   ((table semanticdb-table-SKEL) regex &optional tags)
159   "Find all tags with name matching REGEX in TABLE.
160 Optional argument TAGS is a list of tags to search.
161 Return a list of tags."
162   (if tags (call-next-method)
163     ;; YOUR IMPLEMENTATION HERE    
164     ))
165
166 (defmethod semanticdb-find-tags-for-completion-method
167   ((table semanticdb-table-SKEL) prefix &optional tags)
168   "In TABLE, find all occurances of tags matching PREFIX.
169 Optional argument TAGS is a list of tags to search.
170 Returns a table of all matching tags."
171   (if tags (call-next-method)
172     ;; YOUR IMPLEMENTATION HERE
173     ))
174
175 (defmethod semanticdb-find-tags-by-class-method
176   ((table semanticdb-table-SKEL) class &optional tags)
177   "In TABLE, find all occurances of tags of CLASS.
178 Optional argument TAGS is a list of tags to search.
179 Returns a table of all matching tags."
180   (if tags (call-next-method)
181     ;; YOUR IMPLEMENTATION HERE
182     ;;
183     ;; Note: This search method could be considered optional in an
184     ;;       omniscient database.  It may be unwise to return all tags
185     ;;       that exist for a language that are a variable or function.
186     ;;
187     ;; If it is optional, you can just delete this method.
188     nil))
189
190 ;;; Deep Searches
191 ;;
192 ;; If your language does not have a `deep' concept, these can be left
193 ;; alone, otherwise replace with implementations similar to those
194 ;; above. 
195 ;;
196 (defmethod semanticdb-deep-find-tags-by-name-method
197   ((table semanticdb-table-SKEL) name &optional tags)
198   "Find all tags name NAME in TABLE.
199 Optional argument TAGS is a list of tags t
200 Like `semanticdb-find-tags-by-name-method' for SKEL."
201   (semanticdb-find-tags-by-name-method table name tags))
202
203 (defmethod semanticdb-deep-find-tags-by-name-regexp-method
204   ((table semanticdb-table-SKEL) regex &optional tags)
205   "Find all tags with name matching REGEX in TABLE.
206 Optional argument TAGS is a list of tags to search.
207 Like `semanticdb-find-tags-by-name-method' for SKEL."
208   (semanticdb-find-tags-by-name-regexp-method table regex tags))
209
210 (defmethod semanticdb-deep-find-tags-for-completion-method
211   ((table semanticdb-table-SKEL) prefix &optional tags)
212   "In TABLE, find all occurances of tags matching PREFIX.
213 Optional argument TAGS is a list of tags to search.
214 Like `semanticdb-find-tags-for-completion-method' for SKEL."
215   (semanticdb-find-tags-for-completion-method table prefix tags))
216
217 ;;; Advanced Searches
218 ;;
219 (defmethod semanticdb-find-tags-external-children-of-type-method
220   ((table semanticdb-table-SKEL) type &optional tags)
221   "Find all nonterminals which are child elements of TYPE
222 Optional argument TAGS is a list of tags to search.
223 Return a list of tags."
224   (if tags (call-next-method)
225     ;; YOUR IMPLEMENTATION HERE
226     ;;
227     ;; OPTIONAL: This could be considered an optional function.  It is
228     ;;       used for `semantic-adopt-external-members' and may not
229     ;;       be possible to do in your language.
230     ;;
231     ;; If it is optional, you can just delete this method.
232     ))
233
234 (provide 'semanticdb-el)
235
236 ;;; semanticdb-el.el ends here