1 ;;; ede/auto.el --- Autoload features for EDE
3 ;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs 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 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs 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. If not, see <http://www.gnu.org/licenses/>.
24 ;; EDE Autoloads are a way to refer to different project types without
25 ;; loading those projects into Emacs.
27 ;; These routines are used to detect a project in a filesystem before
28 ;; handing over control to the usual EDE project system.
34 (defclass ede-project-autoload
()
36 :documentation
"Name of this project type")
38 :documentation
"The lisp file belonging to this class.")
39 (proj-file :initarg
:proj-file
40 :documentation
"Name of a project file of this type.")
41 (proj-root :initarg
:proj-root
43 :documentation
"A function symbol to call for the project root.
44 This function takes no arguments, and returns the current directories
45 root, if available. Leave blank to use the EDE directory walking
47 (initializers :initarg
:initializers
50 "Initializers passed to the project object.
51 These are used so there can be multiple types of projects
52 associated with a single object class, based on the initilizeres used.")
53 (load-type :initarg
:load-type
54 :documentation
"Fn symbol used to load this project file.")
55 (class-sym :initarg
:class-sym
56 :documentation
"Symbol representing the project class to use.")
57 (new-p :initarg
:new-p
60 "Non-nil if this is an option when a user creates a project.")
61 (safe-p :initarg
:safe-p
64 "Non-nil if the project load files are \"safe\".
65 An unsafe project is one that loads project variables via Emacs
66 Lisp code. A safe project is one that loads project variables by
67 scanning files without loading Lisp code from them.")
69 "Class representing minimal knowledge set to run preliminary EDE functions.
70 When more advanced functionality is needed from a project type, that projects
71 type is required and the load function used.")
73 (defvar ede-project-class-files
75 (ede-project-autoload "edeproject-makefile"
76 :name
"Make" :file
'ede
/proj
77 :proj-file
"Project.ede"
78 :load-type
'ede-proj-load
79 :class-sym
'ede-proj-project
81 (ede-project-autoload "edeproject-automake"
82 :name
"Automake" :file
'ede
/proj
83 :proj-file
"Project.ede"
84 :initializers
'(:makefile-type Makefile.am
)
85 :load-type
'ede-proj-load
86 :class-sym
'ede-proj-project
88 (ede-project-autoload "automake"
89 :name
"automake" :file
'ede
/project-am
90 :proj-file
"Makefile.am"
91 :load-type
'project-am-load
92 :class-sym
'project-am-makefile
94 "List of vectors defining how to determine what type of projects exist.")
96 (put 'ede-project-class-files
'risky-local-variable t
)
98 ;;; EDE project-autoload methods
100 (defmethod ede-project-root ((this ede-project-autoload
))
101 "If a project knows its root, return it here.
102 Allows for one-project-object-for-a-tree type systems."
105 (defmethod ede-project-root-directory ((this ede-project-autoload
)
107 "If a project knows its root, return it here.
108 Allows for one-project-object-for-a-tree type systems.
109 Optional FILE is the file to test. If there is no FILE, use
112 (setq file default-directory
))
113 (when (slot-boundp this
:proj-root
)
114 (let ((rootfcn (oref this proj-root
)))
117 (funcall rootfcn file
)
122 (defmethod ede-dir-to-projectfile ((this ede-project-autoload
) dir
)
123 "Return a full file name of project THIS found in DIR.
124 Return nil if the project file does not exist."
125 (let* ((d (file-name-as-directory dir
))
126 (root (ede-project-root-directory this d
))
127 (pf (oref this proj-file
))
128 (f (cond ((stringp pf
)
129 (expand-file-name pf
(or root d
)))
130 ((and (symbolp pf
) (fboundp pf
))
131 (funcall pf
(or root d
)))))
133 (when (and f
(file-exists-p f
))
136 (defmethod ede-auto-load-project ((this ede-project-autoload
) dir
)
137 "Load in the project associated with THIS project autoload description.
138 THIS project description should be valid for DIR, where the project will
140 ;; Last line of defense: don't load unsafe projects.
141 (when (not (or (oref this
:safe-p
)
142 (ede-directory-safe-p dir
)))
143 (error "Attempt to load an unsafe project (bug elsewhere in EDE)"))
144 ;; Things are good - so load the project.
145 (let ((o (funcall (oref this load-type
) dir
)))
147 (error "Project type error: :load-type failed to create a project"))
148 (ede-add-project-to-global-list o
)))
152 ;;; ede/auto.el ends here