1 ;;; ede-source.el --- EDE source code object
3 ;;; Copyright (C) 2000 Eric M. Ludlam
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: project, make
7 ;; RCS: $Id: ede-source.el,v 1.1 2007-11-26 15:22:11 michaels Exp $
9 ;; This software is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This software is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
26 ;; Manage different types of source code. A master list of source code types
27 ;; will be maintained, and used to track target objects, what they accept,
28 ;; and what compilers can be used.
33 (defclass ede-sourcecode (eieio-instance-inheritor)
37 "The name of this type of source code.
38 Such as \"C\" or \"Emacs Lisp\"")
39 (sourcepattern :initarg :sourcepattern
43 "Emacs regex matching sourcecode this target accepts.")
44 (auxsourcepattern :initarg :auxsourcepattern
46 :type (or null string)
48 "Emacs regex matching auxiliary source code this target accepts.
49 Aux source are source code files needed for compilation, which are not comiled
51 (enable-subdirectories :initarg :enable-subdirectories
55 "Non nil if this sourcecode type uses subdirectores.
56 If sourcecode always lives near the target creating it, this should be nil.
57 If sourcecode can, or typically lives in a subdirectory of the owning
58 target, set this to t.")
59 (garbagepattern :initarg :garbagepattern
63 "Shell file regex matching files considered as garbage.
64 This is a list of items added to an `rm' command when executing a `clean'
67 "Description of some type of source code.
68 Objects will use sourcecode objects to define the types of source
69 that they are willing to use.")
71 (defvar ede-sourcecode-list nil
72 "The master list of all EDE compilers.")
76 (defmethod initialize-instance :AFTER ((this ede-sourcecode) &rest fields)
77 "Make sure that all ede compiler objects are cached in
79 (let ((lst ede-sourcecode-list))
80 ;; Find an object of the same name.
81 (while (and lst (not (string= (oref this name) (oref (car lst) name))))
84 ;; Replace old definition
86 ;; Add to the beginning of the list.
87 (setq ede-sourcecode-list (cons this ede-sourcecode-list)))))
89 (defmethod ede-want-file-p ((this ede-sourcecode) filename)
90 "Return non-nil if sourcecode definition THIS will take FILENAME."
91 (or (ede-want-file-source-p this filename)
92 (ede-want-file-auxiliary-p this filename)))
94 (defmethod ede-want-file-source-p ((this ede-sourcecode) filename)
95 "Return non-nil if THIS will take FILENAME as an auxiliary ."
96 (let ((case-fold-search nil))
97 (string-match (oref this sourcepattern) filename)))
99 (defmethod ede-want-file-auxiliary-p ((this ede-sourcecode) filename)
100 "Return non-nil if THIS will take FILENAME as an auxiliary ."
101 (let ((case-fold-search nil))
102 (and (slot-boundp this 'auxsourcepattern)
103 (oref this auxsourcepattern)
104 (string-match (oref this auxsourcepattern) filename))))
106 (defmethod ede-want-any-source-files-p ((this ede-sourcecode) filenames)
107 "Return non-nil if THIS will accept any source files in FILENAMES."
108 (ede-or (mapcar (lambda (c) (ede-want-file-source-p this c))
111 (defmethod ede-want-any-auxiliary-files-p ((this ede-sourcecode) filenames)
112 "Return non-nil if THIS will accept any aux files in FILENAMES."
113 (ede-or (mapcar (lambda (c) (ede-want-file-auxiliary-p this c))
116 (defmethod ede-want-any-files-p ((this ede-sourcecode) filenames)
117 "Return non-nil if THIS will accept any files in FILENAMES."
118 (ede-or (mapcar (lambda (c) (ede-want-file-p this c))
121 (defmethod ede-buffer-header-file ((this ede-sourcecode) filename)
122 "Return a list of file names of header files for THIS with FILENAME.
123 Used to guess header files, but uses the auxsource regular expression."
124 (let ((dn (file-name-directory filename))
125 (ts (file-name-sans-extension (file-name-nondirectory filename)))
126 (ae (oref this auxsourcepattern)))
129 (directory-files dn t (concat (regexp-quote ts) ae)))))
131 ;;; Utility functions
134 ;; not used at the moment.
135 (defun ede-source-find (name)
136 "Find the sourcecode object based on NAME."
137 (object-assoc name :name ede-sourcecode-list))
139 (defun ede-source-match (file)
140 "Find the list of soucecode objects which matches FILE."
141 (let ((lst ede-sourcecode-list)
144 ;; ede-file-mine doesn't exist yet
145 (if (ede-file-mine (car lst) file)
146 (setq match (cons (car lst) match)))
147 (setq lst (cdr lst)))
150 ;;; Master list of source code types
152 ;; This must appear at the end so that the init method will work.
153 (defvar ede-source-scheme
154 (ede-sourcecode "ede-source-scheme"
156 :sourcepattern "\\.scm$")
157 "Scheme source code definition.")
159 ;;(defvar ede-source-
160 ;; (ede-sourcecode "ede-source-"
162 ;; :sourcepattern "\\.$"
163 ;; :garbagepattern '("*."))
164 ;; " source code definition.")
166 (provide 'ede-source)
168 ;;; ede-source.el ends here