Fix bug #12242 with crashes in ralloc.c on OpenBSD.
[emacs.git] / lisp / cedet / ede / auto.el
bloba5ea81788580a8e2768c221aeb5e6047ecd4a218
1 ;;; ede/auto.el --- Autoload features for EDE
3 ;; Copyright (C) 2010-2012 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/>.
22 ;;; Commentary:
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.
30 ;;; Code:
32 (require 'eieio)
34 (declare-function ede-directory-safe-p "ede")
35 (declare-function ede-add-project-to-global-list "ede")
37 (defclass ede-project-autoload ()
38 ((name :initarg :name
39 :documentation "Name of this project type")
40 (file :initarg :file
41 :documentation "The lisp file belonging to this class.")
42 (proj-file :initarg :proj-file
43 :documentation "Name of a project file of this type.")
44 (proj-root :initarg :proj-root
45 :type function
46 :documentation "A function symbol to call for the project root.
47 This function takes no arguments, and returns the current directories
48 root, if available. Leave blank to use the EDE directory walking
49 routine instead.")
50 (initializers :initarg :initializers
51 :initform nil
52 :documentation
53 "Initializers passed to the project object.
54 These are used so there can be multiple types of projects
55 associated with a single object class, based on the initializers used.")
56 (load-type :initarg :load-type
57 :documentation "Fn symbol used to load this project file.")
58 (class-sym :initarg :class-sym
59 :documentation "Symbol representing the project class to use.")
60 (new-p :initarg :new-p
61 :initform t
62 :documentation
63 "Non-nil if this is an option when a user creates a project.")
64 (safe-p :initarg :safe-p
65 :initform t
66 :documentation
67 "Non-nil if the project load files are \"safe\".
68 An unsafe project is one that loads project variables via Emacs
69 Lisp code. A safe project is one that loads project variables by
70 scanning files without loading Lisp code from them.")
72 "Class representing minimal knowledge set to run preliminary EDE functions.
73 When more advanced functionality is needed from a project type, that projects
74 type is required and the load function used.")
76 (defvar ede-project-class-files
77 (list
78 (ede-project-autoload "edeproject-makefile"
79 :name "Make" :file 'ede/proj
80 :proj-file "Project.ede"
81 :load-type 'ede-proj-load
82 :class-sym 'ede-proj-project
83 :safe-p nil)
84 (ede-project-autoload "edeproject-automake"
85 :name "Automake" :file 'ede/proj
86 :proj-file "Project.ede"
87 :initializers '(:makefile-type Makefile.am)
88 :load-type 'ede-proj-load
89 :class-sym 'ede-proj-project
90 :safe-p nil)
91 (ede-project-autoload "automake"
92 :name "automake" :file 'ede/project-am
93 :proj-file "Makefile.am"
94 :load-type 'project-am-load
95 :class-sym 'project-am-makefile
96 :new-p nil))
97 "List of vectors defining how to determine what type of projects exist.")
99 (put 'ede-project-class-files 'risky-local-variable t)
101 ;;; EDE project-autoload methods
103 (defmethod ede-project-root ((this ede-project-autoload))
104 "If a project knows its root, return it here.
105 Allows for one-project-object-for-a-tree type systems."
106 nil)
108 (defmethod ede-project-root-directory ((this ede-project-autoload)
109 &optional file)
110 "If a project knows its root, return it here.
111 Allows for one-project-object-for-a-tree type systems.
112 Optional FILE is the file to test. If there is no FILE, use
113 the current buffer."
114 (when (not file)
115 (setq file default-directory))
116 (when (slot-boundp this :proj-root)
117 (let ((rootfcn (oref this proj-root)))
118 (when rootfcn
119 (condition-case nil
120 (funcall rootfcn file)
121 (error
122 (funcall rootfcn)))
123 ))))
125 (defmethod ede-dir-to-projectfile ((this ede-project-autoload) dir)
126 "Return a full file name of project THIS found in DIR.
127 Return nil if the project file does not exist."
128 (let* ((d (file-name-as-directory dir))
129 (root (ede-project-root-directory this d))
130 (pf (oref this proj-file))
131 (f (cond ((stringp pf)
132 (expand-file-name pf (or root d)))
133 ((and (symbolp pf) (fboundp pf))
134 (funcall pf (or root d)))))
136 (when (and f (file-exists-p f))
137 f)))
139 (defmethod ede-auto-load-project ((this ede-project-autoload) dir)
140 "Load in the project associated with THIS project autoload description.
141 THIS project description should be valid for DIR, where the project will
142 be loaded."
143 ;; Last line of defense: don't load unsafe projects.
144 (when (not (or (oref this :safe-p)
145 (ede-directory-safe-p dir)))
146 (error "Attempt to load an unsafe project (bug elsewhere in EDE)"))
147 ;; Things are good - so load the project.
148 (let ((o (funcall (oref this load-type) dir)))
149 (when (not o)
150 (error "Project type error: :load-type failed to create a project"))
151 (ede-add-project-to-global-list o)))
153 (provide 'ede/auto)
155 ;;; ede/auto.el ends here