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