]> code.delx.au - gnu-emacs/blob - lisp/cedet/ede/auto.el
d08ab543b82979f110d3ed4a0af7e9d683234784
[gnu-emacs] / lisp / cedet / ede / auto.el
1 ;;; ede/auto.el --- Autoload features for EDE
2
3 ;; Copyright (C) 2010-2011 Free Software Foundation, Inc.
4
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6
7 ;; This file is part of GNU Emacs.
8
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.
13
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.
18
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/>.
21
22 ;;; Commentary:
23 ;;
24 ;; EDE Autoloads are a way to refer to different project types without
25 ;; loading those projects into Emacs.
26 ;;
27 ;; These routines are used to detect a project in a filesystem before
28 ;; handing over control to the usual EDE project system.
29
30 ;;; Code:
31
32 (require 'eieio)
33
34 (defclass ede-project-autoload ()
35 ((name :initarg :name
36 :documentation "Name of this project type")
37 (file :initarg :file
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
42 :type function
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
46 routine instead.")
47 (initializers :initarg :initializers
48 :initform nil
49 :documentation
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 initializers 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
58 :initform t
59 :documentation
60 "Non-nil if this is an option when a user creates a project.")
61 )
62 "Class representing minimal knowledge set to run preliminary EDE functions.
63 When more advanced functionality is needed from a project type, that projects
64 type is required and the load function used.")
65
66 (defvar ede-project-class-files
67 (list
68 (ede-project-autoload "edeproject-makefile"
69 :name "Make" :file 'ede/proj
70 :proj-file "Project.ede"
71 :load-type 'ede-proj-load
72 :class-sym 'ede-proj-project)
73 (ede-project-autoload "edeproject-automake"
74 :name "Automake" :file 'ede/proj
75 :proj-file "Project.ede"
76 :initializers '(:makefile-type Makefile.am)
77 :load-type 'ede-proj-load
78 :class-sym 'ede-proj-project)
79 (ede-project-autoload "automake"
80 :name "automake" :file 'ede/project-am
81 :proj-file "Makefile.am"
82 :load-type 'project-am-load
83 :class-sym 'project-am-makefile
84 :new-p nil))
85 "List of vectors defining how to determine what type of projects exist.")
86
87 ;;; EDE project-autoload methods
88 ;;
89 (defmethod ede-project-root ((this ede-project-autoload))
90 "If a project knows its root, return it here.
91 Allows for one-project-object-for-a-tree type systems."
92 nil)
93
94 (defmethod ede-project-root-directory ((this ede-project-autoload)
95 &optional file)
96 "If a project knows its root, return it here.
97 Allows for one-project-object-for-a-tree type systems.
98 Optional FILE is the file to test. If there is no FILE, use
99 the current buffer."
100 (when (not file)
101 (setq file default-directory))
102 (when (slot-boundp this :proj-root)
103 (let ((rootfcn (oref this proj-root)))
104 (when rootfcn
105 (condition-case nil
106 (funcall rootfcn file)
107 (error
108 (funcall rootfcn)))
109 ))))
110
111 (defmethod ede-dir-to-projectfile ((this ede-project-autoload) dir)
112 "Return a full file name of project THIS found in DIR.
113 Return nil if the project file does not exist."
114 (let* ((d (file-name-as-directory dir))
115 (root (ede-project-root-directory this d))
116 (pf (oref this proj-file))
117 (f (cond ((stringp pf)
118 (expand-file-name pf (or root d)))
119 ((and (symbolp pf) (fboundp pf))
120 (funcall pf (or root d)))))
121 )
122 (when (and f (file-exists-p f))
123 f)))
124
125
126 (provide 'ede/auto)
127
128 ;;; ede/auto.el ends here