Fix typos.
[emacs.git] / lisp / cedet / ede / source.el
blobe5dc12d064f56cfc6538133c353e0a41a88eaf75
1 ;; ede/source.el --- EDE source code object
3 ;; Copyright (C) 2000, 2008-2011 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: project, make
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Manage different types of source code. A master list of source code types
26 ;; will be maintained, and used to track target objects, what they accept,
27 ;; and what compilers can be used.
29 (require 'eieio-base)
31 ;;; Code:
32 (defclass ede-sourcecode (eieio-instance-inheritor)
33 ((name :initarg :name
34 :type string
35 :documentation
36 "The name of this type of source code.
37 Such as \"C\" or \"Emacs Lisp\"")
38 (sourcepattern :initarg :sourcepattern
39 :initform ".*"
40 :type string
41 :documentation
42 "Emacs regexp matching sourcecode this target accepts.")
43 (auxsourcepattern :initarg :auxsourcepattern
44 :initform nil
45 :type (or null string)
46 :documentation
47 "Emacs regexp matching auxiliary source code this target accepts.
48 Aux source are source code files needed for compilation, which are not compiled
49 themselves.")
50 (enable-subdirectories :initarg :enable-subdirectories
51 :initform nil
52 :type boolean
53 :documentation
54 "Non nil if this sourcecode type uses subdirectories.
55 If sourcecode always lives near the target creating it, this should be nil.
56 If sourcecode can, or typically lives in a subdirectory of the owning
57 target, set this to t.")
58 (garbagepattern :initarg :garbagepattern
59 :initform nil
60 :type list
61 :documentation
62 "Shell file regexp matching files considered as garbage.
63 This is a list of items added to an `rm' command when executing a `clean'
64 type directive.")
66 "Description of some type of source code.
67 Objects will use sourcecode objects to define the types of source
68 that they are willing to use.")
70 (defvar ede-sourcecode-list nil
71 "The master list of all EDE compilers.")
73 ;;; Methods
75 (defmethod initialize-instance :AFTER ((this ede-sourcecode) &rest fields)
76 "Make sure that all ede compiler objects are cached in
77 `ede-compiler-list'."
78 (let ((lst ede-sourcecode-list))
79 ;; Find an object of the same name.
80 (while (and lst (not (string= (oref this name) (oref (car lst) name))))
81 (setq lst (cdr lst)))
82 (if lst
83 ;; Replace old definition
84 (setcar lst this)
85 ;; Add to the beginning of the list.
86 (setq ede-sourcecode-list (cons this ede-sourcecode-list)))))
88 (defmethod ede-want-file-p ((this ede-sourcecode) filename)
89 "Return non-nil if sourcecode definition THIS will take FILENAME."
90 (or (ede-want-file-source-p this filename)
91 (ede-want-file-auxiliary-p this filename)))
93 (defmethod ede-want-file-source-p ((this ede-sourcecode) filename)
94 "Return non-nil if THIS will take FILENAME as an auxiliary ."
95 (let ((case-fold-search nil))
96 (string-match (oref this sourcepattern) filename)))
98 (defmethod ede-want-file-auxiliary-p ((this ede-sourcecode) filename)
99 "Return non-nil if THIS will take FILENAME as an auxiliary ."
100 (let ((case-fold-search nil))
101 (and (slot-boundp this 'auxsourcepattern)
102 (oref this auxsourcepattern)
103 (string-match (oref this auxsourcepattern) filename))))
105 (defmethod ede-want-any-source-files-p ((this ede-sourcecode) filenames)
106 "Return non-nil if THIS will accept any source files in FILENAMES."
107 (let (found)
108 (while (and (not found) filenames)
109 (setq found (ede-want-file-source-p this (pop filenames))))
110 found))
112 (defmethod ede-want-any-auxiliary-files-p ((this ede-sourcecode) filenames)
113 "Return non-nil if THIS will accept any aux files in FILENAMES."
114 (let (found)
115 (while (and (not found) filenames)
116 (setq found (ede-want-file-auxiliary-p this (pop filenames))))
117 found))
119 (defmethod ede-want-any-files-p ((this ede-sourcecode) filenames)
120 "Return non-nil if THIS will accept any files in FILENAMES."
121 (let (found)
122 (while (and (not found) filenames)
123 (setq found (ede-want-file-p this (pop filenames))))
124 found))
126 (defmethod ede-buffer-header-file ((this ede-sourcecode) filename)
127 "Return a list of file names of header files for THIS with FILENAME.
128 Used to guess header files, but uses the auxsource regular expression."
129 (let ((dn (file-name-directory filename))
130 (ts (file-name-sans-extension (file-name-nondirectory filename)))
131 (ae (oref this auxsourcepattern)))
132 (if (not ae)
134 (directory-files dn t (concat (regexp-quote ts) ae)))))
136 ;;; Utility functions
138 (when nil
139 ;; not used at the moment.
140 (defun ede-source-find (name)
141 "Find the sourcecode object based on NAME."
142 (object-assoc name :name ede-sourcecode-list))
144 (defun ede-source-match (file)
145 "Find the list of sourcecode objects which matches FILE."
146 (let ((lst ede-sourcecode-list)
147 (match nil))
148 (while lst
149 ;; ede-file-mine doesn't exist yet
150 (if (ede-file-mine (car lst) file)
151 (setq match (cons (car lst) match)))
152 (setq lst (cdr lst)))
153 match))
155 ;;; Master list of source code types
157 ;; This must appear at the end so that the init method will work.
158 (defvar ede-source-scheme
159 (ede-sourcecode "ede-source-scheme"
160 :name "Scheme"
161 :sourcepattern "\\.scm$")
162 "Scheme source code definition.")
164 ;;(defvar ede-source-
165 ;; (ede-sourcecode "ede-source-"
166 ;; :name ""
167 ;; :sourcepattern "\\.$"
168 ;; :garbagepattern '("*."))
169 ;; " source code definition.")
171 (provide 'ede/source)
173 ;;; ede/source.el ends here