Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / cedet / ede.el
CommitLineData
acc33231
CY
1;;; ede.el --- Emacs Development Environment gloss
2
73b0cd50 3;; Copyright (C) 1998-2005, 2007-2011 Free Software Foundation, Inc.
acc33231
CY
4
5;; Author: Eric M. Ludlam <zappo@gnu.org>
6;; Keywords: project, make
aad4679e 7;; Version: 1.0pre7
acc33231
CY
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24;;; Commentary:
25;;
26;; EDE is the top level Lisp interface to a project management scheme
27;; for Emacs. Emacs does many things well, including editing,
28;; building, and debugging. Folks migrating from other IDEs don't
29;; seem to think this qualifies, however, because they still have to
30;; write the makefiles, and specify parameters to programs.
31;;
32;; This EDE mode will attempt to link these diverse programs together
33;; into a comprehensive single interface, instead of a bunch of
34;; different ones.
35
36;;; Install
37;;
38;; This command enables project mode on all files.
39;;
40;; (global-ede-mode t)
41
715f35a5 42(require 'cedet)
acc33231
CY
43(require 'eieio)
44(require 'eieio-speedbar)
45(require 'ede/source)
cb85c0d8
EL
46(require 'ede/base)
47(require 'ede/auto)
48
fae4e5b9 49(load "ede/loaddefs" nil 'nomessage)
acc33231 50
cb85c0d8 51(declare-function ede-commit-project "ede/custom")
acc33231
CY
52(declare-function ede-convert-path "ede/files")
53(declare-function ede-directory-get-open-project "ede/files")
54(declare-function ede-directory-get-toplevel-open-project "ede/files")
55(declare-function ede-directory-project-p "ede/files")
56(declare-function ede-find-subproject-for-directory "ede/files")
57(declare-function ede-project-directory-remove-hash "ede/files")
9a1a272a 58(declare-function ede-toplevel "ede/base")
acc33231
CY
59(declare-function ede-toplevel-project "ede/files")
60(declare-function ede-up-directory "ede/files")
acc33231
CY
61(declare-function semantic-lex-make-spp-table "semantic/lex-spp")
62
cb85c0d8 63(defconst ede-version "1.0"
acc33231
CY
64 "Current version of the Emacs EDE.")
65
66;;; Code:
67(defun ede-version ()
68 "Display the current running version of EDE."
69 (interactive) (message "EDE %s" ede-version))
70
71(defgroup ede nil
ff90f4b0 72 "Emacs Development Environment."
acc33231 73 :group 'tools
ff90f4b0 74 :group 'extensions)
acc33231
CY
75
76(defcustom ede-auto-add-method 'ask
bd2afec2 77 "Whether a new source file should be automatically added to a target.
acc33231
CY
78Whenever a new file is encountered in a directory controlled by a
79project file, all targets are queried to see if it should be added.
80If the value is 'always, then the new file is added to the first
81target encountered. If the value is 'multi-ask, then if more than one
82target wants the file, the user is asked. If only one target wants
83the file, then then it is automatically added to that target. If the
84value is 'ask, then the user is always asked, unless there is no
85target willing to take the file. 'never means never perform the check."
86 :group 'ede
87 :type '(choice (const always)
88 (const multi-ask)
89 (const ask)
90 (const never)))
91
92(defcustom ede-debug-program-function 'gdb
93 "Default Emacs command used to debug a target."
94 :group 'ede
95 :type 'sexp) ; make this be a list of options some day
96
acc33231
CY
97\f
98;;; Management variables
99
100(defvar ede-projects nil
101 "A list of all active projects currently loaded in Emacs.")
102
103(defvar ede-object-root-project nil
104 "The current buffer's current root project.
105If a file is under a project, this specifies the project that is at
106the root of a project tree.")
107(make-variable-buffer-local 'ede-object-root-project)
108
109(defvar ede-object-project nil
110 "The current buffer's current project at that level.
111If a file is under a project, this specifies the project that contains the
112current target.")
113(make-variable-buffer-local 'ede-object-project)
114
115(defvar ede-object nil
116 "The current buffer's target object.
117This object's class determines how to compile and debug from a buffer.")
118(make-variable-buffer-local 'ede-object)
119
120(defvar ede-selected-object nil
121 "The currently user-selected project or target.
122If `ede-object' is nil, then commands will operate on this object.")
123
124(defvar ede-constructing nil
cb85c0d8
EL
125 "Non nil when constructing a project hierarchy.
126If the project is being constructed from an autoload, then the
127value is the autoload object being used.")
acc33231
CY
128
129(defvar ede-deep-rescan nil
130 "Non nil means scan down a tree, otherwise rescans are top level only.
131Do not set this to non-nil globally. It is used internally.")
acc33231
CY
132
133\f
134;;; Prompting
135;;
136(defun ede-singular-object (prompt)
137 "Using PROMPT, choose a single object from the current buffer."
138 (if (listp ede-object)
139 (ede-choose-object prompt ede-object)
140 ede-object))
141
142(defun ede-choose-object (prompt list-o-o)
143 "Using PROMPT, ask the user which OBJECT to use based on the name field.
144Argument LIST-O-O is the list of objects to choose from."
145 (let* ((al (object-assoc-list 'name list-o-o))
146 (ans (completing-read prompt al nil t)))
147 (setq ans (assoc ans al))
148 (cdr ans)))
149\f
150;;; Menu and Keymap
151
715f35a5 152(defvar ede-minor-mode-map
acc33231
CY
153 (let ((map (make-sparse-keymap))
154 (pmap (make-sparse-keymap)))
155 (define-key pmap "e" 'ede-edit-file-target)
156 (define-key pmap "a" 'ede-add-file)
157 (define-key pmap "d" 'ede-remove-file)
158 (define-key pmap "t" 'ede-new-target)
159 (define-key pmap "g" 'ede-rescan-toplevel)
160 (define-key pmap "s" 'ede-speedbar)
161 (define-key pmap "l" 'ede-load-project-file)
162 (define-key pmap "f" 'ede-find-file)
163 (define-key pmap "C" 'ede-compile-project)
164 (define-key pmap "c" 'ede-compile-target)
165 (define-key pmap "\C-c" 'ede-compile-selected)
166 (define-key pmap "D" 'ede-debug-target)
67d3ffe4 167 (define-key pmap "R" 'ede-run-target)
acc33231
CY
168 ;; bind our submap into map
169 (define-key map "\C-c." pmap)
170 map)
171 "Keymap used in project minor mode.")
172
715f35a5
CY
173(defvar global-ede-mode-map
174 (let ((map (make-sparse-keymap)))
175 (define-key map [menu-bar cedet-menu]
176 (cons "Development" cedet-menu-map))
177 map)
bd2afec2 178 "Keymap used in `global-ede-mode'.")
715f35a5
CY
179
180;; Activate the EDE items in cedet-menu-map
181
182(define-key cedet-menu-map [ede-find-file]
ebf5c4f5
CY
183 '(menu-item "Find File in Project..." ede-find-file :enable ede-object
184 :visible global-ede-mode))
715f35a5 185(define-key cedet-menu-map [ede-speedbar]
ebf5c4f5
CY
186 '(menu-item "View Project Tree" ede-speedbar :enable ede-object
187 :visible global-ede-mode))
715f35a5 188(define-key cedet-menu-map [ede]
ebf5c4f5
CY
189 '(menu-item "Load Project" ede
190 :visible global-ede-mode))
715f35a5
CY
191(define-key cedet-menu-map [ede-new]
192 '(menu-item "Create Project" ede-new
ebf5c4f5
CY
193 :enable (not ede-object)
194 :visible global-ede-mode))
715f35a5
CY
195(define-key cedet-menu-map [ede-target-options]
196 '(menu-item "Target Options" ede-target-options
ebf5c4f5
CY
197 :filter ede-target-forms-menu
198 :visible global-ede-mode))
715f35a5
CY
199(define-key cedet-menu-map [ede-project-options]
200 '(menu-item "Project Options" ede-project-options
ebf5c4f5
CY
201 :filter ede-project-forms-menu
202 :visible global-ede-mode))
715f35a5
CY
203(define-key cedet-menu-map [ede-build-forms-menu]
204 '(menu-item "Build Project" ede-build-forms-menu
205 :filter ede-build-forms-menu
ebf5c4f5
CY
206 :enable ede-object
207 :visible global-ede-mode))
acc33231 208
cb85c0d8
EL
209(defun ede-buffer-belongs-to-target-p ()
210 "Return non-nil if this buffer belongs to at least one target."
211 (let ((obj ede-object))
212 (if (consp obj)
213 (setq obj (car obj)))
214 (and obj (obj-of-class-p obj ede-target))))
215
216(defun ede-buffer-belongs-to-project-p ()
217 "Return non-nil if this buffer belongs to at least one target."
218 (if (or (null ede-object) (consp ede-object)) nil
219 (obj-of-class-p ede-object ede-project)))
220
acc33231
CY
221(defun ede-menu-obj-of-class-p (class)
222 "Return non-nil if some member of `ede-object' is a child of CLASS."
223 (if (listp ede-object)
b90caf50 224 (eval (cons 'or (mapcar (lambda (o) (obj-of-class-p o class)) ede-object)))
acc33231
CY
225 (obj-of-class-p ede-object class)))
226
227(defun ede-build-forms-menu (menu-def)
228 "Create a sub menu for building different parts of an EDE system.
229Argument MENU-DEF is the menu definition to use."
230 (easy-menu-filter-return
231 (easy-menu-create-menu
232 "Build Forms"
233 (let ((obj (ede-current-project))
234 (newmenu nil) ;'([ "Build Selected..." ede-compile-selected t ]))
235 targets
236 targitems
237 ede-obj
238 (tskip nil))
239 (if (not obj)
240 nil
241 (setq targets (when (slot-boundp obj 'targets)
242 (oref obj targets))
243 ede-obj (if (listp ede-object) ede-object (list ede-object)))
244 ;; First, collect the build items from the project
245 (setq newmenu (append newmenu (ede-menu-items-build obj t)))
246 ;; Second, Declare the current target menu items
247 (if (and ede-obj (ede-menu-obj-of-class-p ede-target))
248 (while ede-obj
249 (setq newmenu (append newmenu
250 (ede-menu-items-build (car ede-obj) t))
251 tskip (car ede-obj)
252 ede-obj (cdr ede-obj))))
253 ;; Third, by name, enable builds for other local targets
254 (while targets
255 (unless (eq tskip (car targets))
256 (setq targitems (ede-menu-items-build (car targets) nil))
257 (setq newmenu
258 (append newmenu
259 (if (= 1 (length targitems))
260 targitems
261 (cons (ede-name (car targets))
262 targitems))))
263 )
264 (setq targets (cdr targets)))
265 ;; Fourth, build sub projects.
266 ;; -- nerp
267 ;; Fifth, Add make distribution
268 (append newmenu (list [ "Make distribution" ede-make-dist t ]))
269 )))))
270
271(defun ede-target-forms-menu (menu-def)
272 "Create a target MENU-DEF based on the object belonging to this buffer."
273 (easy-menu-filter-return
274 (easy-menu-create-menu
275 "Target Forms"
276 (let ((obj (or ede-selected-object ede-object)))
277 (append
e6e267fc
CY
278 '([ "Add File" ede-add-file
279 (and (ede-current-project)
280 (oref (ede-current-project) targets)) ]
acc33231 281 [ "Remove File" ede-remove-file
cb85c0d8 282 (ede-buffer-belongs-to-project-p) ]
acc33231
CY
283 "-")
284 (if (not obj)
285 nil
286 (if (and (not (listp obj)) (oref obj menu))
287 (oref obj menu)
288 (when (listp obj)
289 ;; This is bad, but I'm not sure what else to do.
290 (oref (car obj) menu)))))))))
291
292(defun ede-project-forms-menu (menu-def)
293 "Create a target MENU-DEF based on the object belonging to this buffer."
294 (easy-menu-filter-return
295 (easy-menu-create-menu
296 "Project Forms"
297 (let* ((obj (ede-current-project))
298 (class (if obj (object-class obj)))
299 (menu nil))
300 (condition-case err
301 (progn
302 (while (and class (slot-exists-p class 'menu))
303 ;;(message "Looking at class %S" class)
304 (setq menu (append menu (oref class menu))
305 class (class-parent class))
306 (if (listp class) (setq class (car class))))
307 (append
308 '( [ "Add Target" ede-new-target (ede-current-project) ]
309 [ "Remove Target" ede-delete-target ede-object ]
310 "-")
311 menu
312 ))
313 (error (message "Err found: %S" err)
314 menu)
315 )))))
316
317(defun ede-customize-forms-menu (menu-def)
318 "Create a menu of the project, and targets that can be customized.
319Argument MENU-DEF is the definition of the current menu."
320 (easy-menu-filter-return
321 (easy-menu-create-menu
322 "Customize Project"
323 (let* ((obj (ede-current-project))
8bf997ef 324 targ)
acc33231 325 (when obj
cb85c0d8 326 (setq targ (when (and obj (slot-boundp obj 'targets))
8bf997ef 327 (oref obj targets)))
acc33231
CY
328 ;; Make custom menus for everything here.
329 (append (list
330 (cons (concat "Project " (ede-name obj))
331 (eieio-customize-object-group obj))
332 [ "Reorder Targets" ede-project-sort-targets t ]
333 )
334 (mapcar (lambda (o)
335 (cons (concat "Target " (ede-name o))
336 (eieio-customize-object-group o)))
337 targ)))))))
338
339
340(defun ede-apply-object-keymap (&optional default)
341 "Add target specific keybindings into the local map.
342Optional argument DEFAULT indicates if this should be set to the default
343version of the keymap."
344 (let ((object (or ede-object ede-selected-object)))
345 (condition-case nil
346 (let ((keys (ede-object-keybindings object)))
347 (while keys
348 (local-set-key (concat "\C-c." (car (car keys)))
349 (cdr (car keys)))
350 (setq keys (cdr keys))))
351 (error nil))))
352
353;;; Menu building methods for building
354;;
355(defmethod ede-menu-items-build ((obj ede-project) &optional current)
356 "Return a list of menu items for building project OBJ.
357If optional argument CURRENT is non-nil, return sub-menu code."
358 (if current
359 (list [ "Build Current Project" ede-compile-project t ])
360 (list (vector
361 (list
362 (concat "Build Project " (ede-name obj))
363 `(project-compile-project ,obj))))))
364
365(defmethod ede-menu-items-build ((obj ede-target) &optional current)
366 "Return a list of menu items for building target OBJ.
367If optional argument CURRENT is non-nil, return sub-menu code."
368 (if current
369 (list [ "Build Current Target" ede-compile-target t ])
370 (list (vector
371 (concat "Build Target " (ede-name obj))
372 `(project-compile-target ,obj)
373 t))))
374\f
375;;; Mode Declarations
376;;
377(eval-and-compile
8bf997ef 378 (autoload 'ede-dired-minor-mode "ede/dired" "EDE commands for dired" t))
acc33231
CY
379
380(defun ede-apply-target-options ()
381 "Apply options to the current buffer for the active project/target."
382 (if (ede-current-project)
383 (ede-set-project-variables (ede-current-project)))
384 (ede-apply-object-keymap)
385 (ede-apply-preprocessor-map)
386 )
387
388(defun ede-turn-on-hook ()
389 "Turn on EDE minor mode in the current buffer if needed.
390To be used in hook functions."
391 (if (or (and (stringp (buffer-file-name))
392 (stringp default-directory))
393 ;; Emacs 21 has no buffer file name for directory edits.
394 ;; so we need to add these hacks in.
395 (eq major-mode 'dired-mode)
396 (eq major-mode 'vc-dired-mode))
397 (ede-minor-mode 1)))
398
715f35a5
CY
399(define-minor-mode ede-minor-mode
400 "Toggle EDE (Emacs Development Environment) minor mode.
401With non-nil argument ARG, enable EDE minor mode if ARG is
402positive; otherwise, disable it.
acc33231 403
715f35a5
CY
404If this file is contained, or could be contained in an EDE
405controlled project, then this mode is activated automatically
406provided `global-ede-mode' is enabled."
407 :group 'ede
408 (cond ((or (eq major-mode 'dired-mode)
409 (eq major-mode 'vc-dired-mode))
410 (ede-dired-minor-mode (if ede-minor-mode 1 -1)))
411 (ede-minor-mode
cb85c0d8
EL
412 (if (not ede-constructing)
413 (ede-initialize-state-current-buffer)
715f35a5
CY
414 ;; If we fail to have a project here, turn it back off.
415 (ede-minor-mode -1)))))
acc33231 416
cb85c0d8
EL
417(defun ede-initialize-state-current-buffer ()
418 "Initialize the current buffer's state for EDE.
419Sets buffer local variables for EDE."
420 (let* ((ROOT nil)
421 (proj (ede-directory-get-open-project default-directory
422 'ROOT)))
423 (when (or proj ROOT
424 (ede-directory-project-p default-directory t))
425
426 (when (not proj)
427 ;; @todo - this could be wasteful.
428 (setq proj (ede-load-project-file default-directory 'ROOT)))
429
430 (setq ede-object (ede-buffer-object (current-buffer)
431 'ede-object-project))
432
433 (setq ede-object-root-project
434 (or ROOT (ede-project-root ede-object-project)))
435
436 (if (and (not ede-object) ede-object-project)
437 (ede-auto-add-to-target))
438
439 (ede-apply-target-options))))
440
acc33231
CY
441(defun ede-reset-all-buffers (onoff)
442 "Reset all the buffers due to change in EDE.
443ONOFF indicates enabling or disabling the mode."
444 (let ((b (buffer-list)))
445 (while b
446 (when (buffer-file-name (car b))
cb85c0d8
EL
447 (with-current-buffer (car b)
448 ;; Reset all state variables
449 (setq ede-object nil
450 ede-object-project nil
451 ede-object-root-project nil)
452 ;; Now re-initialize this buffer.
453 (ede-initialize-state-current-buffer)
454 )
acc33231
CY
455 )
456 (setq b (cdr b)))))
457
458;;;###autoload
715f35a5
CY
459(define-minor-mode global-ede-mode
460 "Toggle global EDE (Emacs Development Environment) mode.
461With non-nil argument ARG, enable global EDE mode if ARG is
462positive; otherwise, disable it.
463
464This global minor mode enables `ede-minor-mode' in all buffers in
465an EDE controlled project."
466 :global t
467 :group 'ede
468 (if global-ede-mode
469 ;; Turn on global-ede-mode
470 (progn
ebf5c4f5
CY
471 (if semantic-mode
472 (define-key cedet-menu-map [cedet-menu-separator] '("--")))
715f35a5
CY
473 (add-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
474 (add-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
475 (add-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
476 (add-hook 'find-file-hook 'ede-turn-on-hook)
477 (add-hook 'dired-mode-hook 'ede-turn-on-hook)
478 (add-hook 'kill-emacs-hook 'ede-save-cache)
479 (ede-load-cache)
480 (ede-reset-all-buffers 1))
481 ;; Turn off global-ede-mode
ebf5c4f5 482 (define-key cedet-menu-map [cedet-menu-separator] nil)
715f35a5
CY
483 (remove-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
484 (remove-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
485 (remove-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
486 (remove-hook 'find-file-hook 'ede-turn-on-hook)
487 (remove-hook 'dired-mode-hook 'ede-turn-on-hook)
488 (remove-hook 'kill-emacs-hook 'ede-save-cache)
489 (ede-save-cache)
490 (ede-reset-all-buffers -1)))
acc33231
CY
491
492(defvar ede-ignored-file-alist
493 '( "\\.cvsignore$"
494 "\\.#"
495 "~$"
496 )
497 "List of file name patters that EDE will never ask about.")
498
499(defun ede-ignore-file (filename)
500 "Should we ignore FILENAME?"
501 (let ((any nil)
502 (F ede-ignored-file-alist))
503 (while (and (not any) F)
504 (when (string-match (car F) filename)
505 (setq any t))
506 (setq F (cdr F)))
507 any))
508
509(defun ede-auto-add-to-target ()
510 "Look for a target that wants to own the current file.
511Follow the preference set with `ede-auto-add-method' and get the list
512of objects with the `ede-want-file-p' method."
513 (if ede-object (error "Ede-object already defined for %s" (buffer-name)))
514 (if (or (eq ede-auto-add-method 'never)
515 (ede-ignore-file (buffer-file-name)))
516 nil
517 (let (wants desires)
518 ;; Find all the objects.
519 (setq wants (oref (ede-current-project) targets))
520 (while wants
521 (if (ede-want-file-p (car wants) (buffer-file-name))
522 (setq desires (cons (car wants) desires)))
523 (setq wants (cdr wants)))
524 (if desires
525 (cond ((or (eq ede-auto-add-method 'ask)
526 (and (eq ede-auto-add-method 'multi-ask)
527 (< 1 (length desires))))
528 (let* ((al (append
529 ;; some defaults
530 '(("none" . nil)
531 ("new target" . new))
532 ;; If we are in an unparented subdir,
533 ;; offer new a subproject
534 (if (ede-directory-project-p default-directory)
535 ()
536 '(("create subproject" . project)))
537 ;; Here are the existing objects we want.
538 (object-assoc-list 'name desires)))
539 (case-fold-search t)
540 (ans (completing-read
541 (format "Add %s to target: " (buffer-file-name))
542 al nil t)))
543 (setq ans (assoc ans al))
544 (cond ((eieio-object-p (cdr ans))
545 (ede-add-file (cdr ans)))
546 ((eq (cdr ans) 'new)
547 (ede-new-target))
548 (t nil))))
549 ((or (eq ede-auto-add-method 'always)
550 (and (eq ede-auto-add-method 'multi-ask)
551 (= 1 (length desires))))
552 (ede-add-file (car desires)))
553 (t nil))))))
554
555\f
556;;; Interactive method invocations
557;;
558(defun ede (file)
559 "Start up EDE on something.
560Argument FILE is the file or directory to load a project from."
561 (interactive "fProject File: ")
562 (if (not (file-exists-p file))
563 (ede-new file)
564 (ede-load-project-file (file-name-directory file))))
565
566(defun ede-new (type &optional name)
567 "Create a new project starting of project type TYPE.
568Optional argument NAME is the name to give this project."
569 (interactive
570 (list (completing-read "Project Type: "
571 (object-assoc-list
572 'name
573 (let* ((l ede-project-class-files)
574 (cp (ede-current-project))
575 (cs (when cp (object-class cp)))
576 (r nil))
577 (while l
578 (if cs
579 (if (eq (oref (car l) :class-sym)
580 cs)
581 (setq r (cons (car l) r)))
582 (if (oref (car l) new-p)
583 (setq r (cons (car l) r))))
584 (setq l (cdr l)))
585 (when (not r)
586 (if cs
587 (error "No valid interactive sub project types for %s"
588 cs)
589 (error "EDE error: Can't fin project types to create")))
590 r)
591 )
592 nil t)))
cb85c0d8 593 (require 'ede/custom)
acc33231
CY
594 ;; Make sure we have a valid directory
595 (when (not (file-exists-p default-directory))
bd2afec2 596 (error "Cannot create project in non-existent directory %s" default-directory))
acc33231
CY
597 (when (not (file-writable-p default-directory))
598 (error "No write permissions for %s" default-directory))
599 ;; Create the project
600 (let* ((obj (object-assoc type 'name ede-project-class-files))
601 (nobj (let ((f (oref obj file))
602 (pf (oref obj proj-file)))
603 ;; We are about to make something new, changing the
604 ;; state of existing directories.
605 (ede-project-directory-remove-hash default-directory)
606 ;; Make sure this class gets loaded!
607 (require f)
608 (make-instance (oref obj class-sym)
609 :name (or name (read-string "Name: "))
610 :directory default-directory
611 :file (cond ((stringp pf)
612 (expand-file-name pf))
613 ((fboundp pf)
614 (funcall pf))
615 (t
616 (error
617 "Unknown file name specifier %S"
618 pf)))
619 :targets nil)))
620 (inits (oref obj initializers)))
621 ;; Force the name to match for new objects.
622 (object-set-name-string nobj (oref nobj :name))
623 ;; Handle init args.
624 (while inits
625 (eieio-oset nobj (car inits) (car (cdr inits)))
626 (setq inits (cdr (cdr inits))))
627 (let ((pp (ede-parent-project)))
628 (when pp
629 (ede-add-subproject pp nobj)
630 (ede-commit-project pp)))
631 (ede-commit-project nobj))
632 ;; Have the menu appear
633 (setq ede-minor-mode t)
634 ;; Allert the user
635 (message "Project created and saved. You may now create targets."))
636
637(defmethod ede-add-subproject ((proj-a ede-project) proj-b)
638 "Add into PROJ-A, the subproject PROJ-B."
639 (oset proj-a subproj (cons proj-b (oref proj-a subproj))))
640
acc33231
CY
641(defun ede-invoke-method (sym &rest args)
642 "Invoke method SYM on the current buffer's project object.
643ARGS are additional arguments to pass to method sym."
644 (if (not ede-object)
645 (error "Cannot invoke %s for %s" (symbol-name sym)
646 (buffer-name)))
647 ;; Always query a target. There should never be multiple
648 ;; projects in a single buffer.
649 (apply sym (ede-singular-object "Target: ") args))
650
651(defun ede-rescan-toplevel ()
652 "Rescan all project files."
653 (interactive)
654 (let ((toppath (ede-toplevel-project default-directory))
655 (ede-deep-rescan t))
656 (project-rescan (ede-load-project-file toppath))
657 (ede-reset-all-buffers 1)
658 ))
659
660(defun ede-new-target (&rest args)
661 "Create a new target specific to this type of project file.
662Different projects accept different arguments ARGS.
663Typically you can specify NAME, target TYPE, and AUTOADD, where AUTOADD is
664a string \"y\" or \"n\", which answers the y/n question done interactively."
665 (interactive)
666 (apply 'project-new-target (ede-current-project) args)
667 (setq ede-object nil)
668 (setq ede-object (ede-buffer-object (current-buffer)))
669 (ede-apply-target-options))
670
671(defun ede-new-target-custom ()
672 "Create a new target specific to this type of project file."
673 (interactive)
674 (project-new-target-custom (ede-current-project)))
675
676(defun ede-delete-target (target)
677 "Delete TARGET from the current project."
678 (interactive (list
679 (let ((ede-object (ede-current-project)))
680 (ede-invoke-method 'project-interactive-select-target
681 "Target: "))))
682 ;; Find all sources in buffers associated with the condemned buffer.
683 (let ((condemned (ede-target-buffers target)))
684 (project-delete-target target)
685 ;; Loop over all project controlled buffers
686 (save-excursion
687 (while condemned
688 (set-buffer (car condemned))
689 (setq ede-object nil)
690 (setq ede-object (ede-buffer-object (current-buffer)))
691 (setq condemned (cdr condemned))))
692 (ede-apply-target-options)))
693
694(defun ede-add-file (target)
695 "Add the current buffer to a TARGET in the current project."
696 (interactive (list
697 (let ((ede-object (ede-current-project)))
698 (ede-invoke-method 'project-interactive-select-target
699 "Target: "))))
700 (when (stringp target)
701 (let* ((proj (ede-current-project))
702 (ob (object-assoc-list 'name (oref proj targets))))
703 (setq target (cdr (assoc target ob)))))
704
705 (when (not target)
706 (error "Could not find specified target %S" target))
707
708 (project-add-file target (buffer-file-name))
709 (setq ede-object nil)
710 (setq ede-object (ede-buffer-object (current-buffer)))
711 (when (not ede-object)
712 (error "Can't add %s to target %s: Wrong file type"
713 (file-name-nondirectory (buffer-file-name))
714 (object-name target)))
715 (ede-apply-target-options))
716
717(defun ede-remove-file (&optional force)
718 "Remove the current file from targets.
719Optional argument FORCE forces the file to be removed without asking."
720 (interactive "P")
721 (if (not ede-object)
722 (error "Cannot invoke remove-file for %s" (buffer-name)))
723 (let ((eo (if (listp ede-object)
724 (prog1
725 ede-object
726 (setq force nil))
727 (list ede-object))))
728 (while eo
729 (if (or force (y-or-n-p (format "Remove from %s? " (ede-name (car eo)))))
730 (project-remove-file (car eo) (buffer-file-name)))
731 (setq eo (cdr eo)))
732 (setq ede-object nil)
733 (setq ede-object (ede-buffer-object (current-buffer)))
734 (ede-apply-target-options)))
735
736(defun ede-edit-file-target ()
737 "Enter the project file to hand edit the current buffer's target."
738 (interactive)
739 (ede-invoke-method 'project-edit-file-target))
740
741(defun ede-compile-project ()
742 "Compile the current project."
743 (interactive)
744 ;; @TODO - This just wants the root. There should be a better way.
745 (let ((cp (ede-current-project)))
746 (while (ede-parent-project cp)
747 (setq cp (ede-parent-project cp)))
748 (let ((ede-object cp))
749 (ede-invoke-method 'project-compile-project))))
750
751(defun ede-compile-selected (target)
752 "Compile some TARGET from the current project."
753 (interactive (list (project-interactive-select-target (ede-current-project)
754 "Target to Build: ")))
755 (project-compile-target target))
756
757(defun ede-compile-target ()
758 "Compile the current buffer's associated target."
759 (interactive)
760 (ede-invoke-method 'project-compile-target))
761
762(defun ede-debug-target ()
bd2afec2 763 "Debug the current buffer's associated target."
acc33231
CY
764 (interactive)
765 (ede-invoke-method 'project-debug-target))
766
67d3ffe4 767(defun ede-run-target ()
fa5f7c5f 768 "Run the current buffer's associated target."
67d3ffe4
CY
769 (interactive)
770 (ede-invoke-method 'project-run-target))
771
acc33231
CY
772(defun ede-make-dist ()
773 "Create a distribution from the current project."
774 (interactive)
cb85c0d8 775 (let ((ede-object (ede-toplevel)))
acc33231
CY
776 (ede-invoke-method 'project-make-dist)))
777
acc33231
CY
778\f
779;;; EDE project target baseline methods.
780;;
781;; If you are developing a new project type, you need to implement
782;; all of these methods, unless, of course, they do not make sense
783;; for your particular project.
784;;
785;; Your targets should inherit from `ede-target', and your project
786;; files should inherit from `ede-project'. Create the appropriate
787;; methods based on those below.
788
789(defmethod project-interactive-select-target ((this ede-project-placeholder) prompt)
cb85c0d8 790 ; checkdoc-params: (prompt)
acc33231 791 "Make sure placeholder THIS is replaced with the real thing, and pass through."
cb85c0d8 792 (project-interactive-select-target this prompt))
acc33231
CY
793
794(defmethod project-interactive-select-target ((this ede-project) prompt)
795 "Interactively query for a target that exists in project THIS.
796Argument PROMPT is the prompt to use when querying the user for a target."
797 (let ((ob (object-assoc-list 'name (oref this targets))))
798 (cdr (assoc (completing-read prompt ob nil t) ob))))
799
800(defmethod project-add-file ((this ede-project-placeholder) file)
cb85c0d8 801 ; checkdoc-params: (file)
acc33231 802 "Make sure placeholder THIS is replaced with the real thing, and pass through."
cb85c0d8 803 (project-add-file this file))
acc33231
CY
804
805(defmethod project-add-file ((ot ede-target) file)
806 "Add the current buffer into project project target OT.
807Argument FILE is the file to add."
808 (error "add-file not supported by %s" (object-name ot)))
809
810(defmethod project-remove-file ((ot ede-target) fnnd)
811 "Remove the current buffer from project target OT.
812Argument FNND is an argument."
813 (error "remove-file not supported by %s" (object-name ot)))
814
815(defmethod project-edit-file-target ((ot ede-target))
816 "Edit the target OT associated w/ this file."
817 (find-file (oref (ede-current-project) file)))
818
819(defmethod project-new-target ((proj ede-project) &rest args)
820 "Create a new target. It is up to the project PROJ to get the name."
821 (error "new-target not supported by %s" (object-name proj)))
822
823(defmethod project-new-target-custom ((proj ede-project))
824 "Create a new target. It is up to the project PROJ to get the name."
825 (error "New-target-custom not supported by %s" (object-name proj)))
826
827(defmethod project-delete-target ((ot ede-target))
fa5f7c5f 828 "Delete the current target OT from its parent project."
acc33231
CY
829 (error "add-file not supported by %s" (object-name ot)))
830
831(defmethod project-compile-project ((obj ede-project) &optional command)
832 "Compile the entire current project OBJ.
833Argument COMMAND is the command to use when compiling."
834 (error "compile-project not supported by %s" (object-name obj)))
835
836(defmethod project-compile-target ((obj ede-target) &optional command)
837 "Compile the current target OBJ.
838Argument COMMAND is the command to use for compiling the target."
839 (error "compile-target not supported by %s" (object-name obj)))
840
841(defmethod project-debug-target ((obj ede-target))
842 "Run the current project target OBJ in a debugger."
843 (error "debug-target not supported by %s" (object-name obj)))
844
67d3ffe4
CY
845(defmethod project-run-target ((obj ede-target))
846 "Run the current project target OBJ."
847 (error "run-target not supported by %s" (object-name obj)))
848
acc33231
CY
849(defmethod project-make-dist ((this ede-project))
850 "Build a distribution for the project based on THIS project."
851 (error "Make-dist not supported by %s" (object-name this)))
852
853(defmethod project-dist-files ((this ede-project))
fa5f7c5f 854 "Return a list of files that constitute a distribution of THIS project."
acc33231
CY
855 (error "Dist-files is not supported by %s" (object-name this)))
856
857(defmethod project-rescan ((this ede-project))
858 "Rescan the EDE proj project THIS."
859 (error "Rescanning a project is not supported by %s" (object-name this)))
acc33231
CY
860
861(defun ede-ecb-project-paths ()
862 "Return a list of all paths for all active EDE projects.
863This functions is meant for use with ECB."
864 (let ((p ede-projects)
865 (d nil))
866 (while p
867 (setq d (cons (file-name-directory (oref (car p) file))
868 d)
869 p (cdr p)))
870 d))
cb85c0d8
EL
871
872;;; PROJECT LOADING/TRACKING
acc33231
CY
873;;
874(defun ede-add-project-to-global-list (proj)
875 "Add the project PROJ to the master list of projects.
876On success, return the added project."
877 (when (not proj)
878 (error "No project created to add to master list"))
879 (when (not (eieio-object-p proj))
880 (error "Attempt to add Non-object to master project list"))
881 (when (not (obj-of-class-p proj ede-project-placeholder))
882 (error "Attempt to add a non-project to the ede projects list"))
883 (add-to-list 'ede-projects proj)
884 proj)
885
886(defun ede-load-project-file (dir &optional rootreturn)
887 "Project file independent way to read a project in from DIR.
888Optional ROOTRETURN will return the root project for DIR."
889 ;; Only load if something new is going on. Flush the dirhash.
890 (ede-project-directory-remove-hash dir)
891 ;; Do the load
892 ;;(message "EDE LOAD : %S" file)
893 (let* ((file dir)
894 (path (expand-file-name (file-name-directory file)))
895 (pfc (ede-directory-project-p path))
896 (toppath nil)
897 (o nil))
898 (cond
899 ((not pfc)
900 ;; @TODO - Do we really need to scan? Is this a waste of time?
901 ;; Scan upward for a the next project file style.
902 (let ((p path))
903 (while (and p (not (ede-directory-project-p p)))
904 (setq p (ede-up-directory p)))
905 (if p (ede-load-project-file p)
906 nil)
907 ;; recomment as we go
cb85c0d8 908 ;;nil
acc33231
CY
909 ))
910 ;; Do nothing if we are buiding an EDE project already
911 (ede-constructing
912 nil)
913 ;; Load in the project in question.
914 (t
915 (setq toppath (ede-toplevel-project path))
916 ;; We found the top-most directory. Check to see if we already
cb85c0d8 917 ;; have an object defining its project.
acc33231
CY
918 (setq pfc (ede-directory-project-p toppath t))
919
920 ;; See if it's been loaded before
921 (setq o (object-assoc (ede-dir-to-projectfile pfc toppath) 'file
922 ede-projects))
923 (if (not o)
924 ;; If not, get it now.
cb85c0d8 925 (let ((ede-constructing pfc))
acc33231
CY
926 (setq o (funcall (oref pfc load-type) toppath))
927 (when (not o)
928 (error "Project type error: :load-type failed to create a project"))
929 (ede-add-project-to-global-list o)))
930
931 ;; Return the found root project.
932 (when rootreturn (set rootreturn o))
933
934 (let (tocheck found)
935 ;; Now find the project file belonging to FILE!
936 (setq tocheck (list o))
937 (setq file (ede-dir-to-projectfile pfc (expand-file-name path)))
938 (while (and tocheck (not found))
939 (let ((newbits nil))
940 (when (car tocheck)
941 (if (string= file (oref (car tocheck) file))
942 (setq found (car tocheck)))
943 (setq newbits (oref (car tocheck) subproj)))
944 (setq tocheck
945 (append (cdr tocheck) newbits))))
946 (if (not found)
947 (message "No project for %s, but passes project-p test" file)
948 ;; Now that the file has been reset inside the project object, do
949 ;; the cache maintenance.
950 (setq ede-project-cache-files
951 (delete (oref found file) ede-project-cache-files)))
952 found)))))
953
cb85c0d8
EL
954;;; PROJECT ASSOCIATIONS
955;;
956;; Moving between relative projects. Associating between buffers and
957;; projects.
958
acc33231
CY
959(defun ede-parent-project (&optional obj)
960 "Return the project belonging to the parent directory.
cb85c0d8 961Return nil if there is no previous directory.
acc33231
CY
962Optional argument OBJ is an object to find the parent of."
963 (let* ((proj (or obj ede-object-project)) ;; Current project.
964 (root (if obj (ede-project-root obj)
965 ede-object-root-project)))
966 ;; This case is a SHORTCUT if the project has defined
967 ;; a way to calculate the project root.
968 (if (and root proj (eq root proj))
969 nil ;; we are at the root.
970 ;; Else, we may have a nil proj or root.
971 (let* ((thisdir (if obj (oref obj directory)
972 default-directory))
973 (updir (ede-up-directory thisdir)))
974 (when updir
975 ;; If there was no root, perhaps we can derive it from
976 ;; updir now.
977 (let ((root (or root (ede-directory-get-toplevel-open-project updir))))
978 (or
979 ;; This lets us find a subproject under root based on updir.
980 (and root
981 (ede-find-subproject-for-directory root updir))
982 ;; Try the all structure based search.
983 (ede-directory-get-open-project updir)
984 ;; Load up the project file as a last resort.
985 ;; Last resort since it uses file-truename, and other
986 ;; slow features.
987 (and (ede-directory-project-p updir)
988 (ede-load-project-file
989 (file-name-as-directory updir))))))))))
990
991(defun ede-current-project (&optional dir)
992 "Return the current project file.
993If optional DIR is provided, get the project for DIR instead."
994 (let ((ans nil))
995 ;; If it matches the current directory, do we have a pre-existing project?
996 (when (and (or (not dir) (string= dir default-directory))
997 ede-object-project)
998 (setq ans ede-object-project)
999 )
1000 ;; No current project.
1001 (when (not ans)
1002 (let* ((ldir (or dir default-directory)))
1003 (setq ans (ede-directory-get-open-project ldir))
1004 (or ans
1005 ;; No open project, if this dir pass project-p, then load.
1006 (when (ede-directory-project-p ldir)
1007 (setq ans (ede-load-project-file ldir))))))
1008 ;; Return what we found.
1009 ans))
1010
cb85c0d8 1011(defun ede-buffer-object (&optional buffer projsym)
acc33231 1012 "Return the target object for BUFFER.
cb85c0d8
EL
1013This function clears cached values and recalculates.
1014Optional PROJSYM is a symbol, which will be set to the project
1015that contains the target that becomes buffer's object."
acc33231
CY
1016 (save-excursion
1017 (if (not buffer) (setq buffer (current-buffer)))
1018 (set-buffer buffer)
1019 (setq ede-object nil)
cb85c0d8
EL
1020 (let* ((localpo (ede-current-project))
1021 (po localpo)
1022 (top (ede-toplevel po)))
1023 (if po (setq ede-object (ede-find-target po buffer)))
1024 ;; If we get nothing, go with the backup plan of slowly
1025 ;; looping upward
1026 (while (and (not ede-object) (not (eq po top)))
1027 (setq po (ede-parent-project po))
1028 (if po (setq ede-object (ede-find-target po buffer))))
1029 ;; Filter down to 1 project if there are dups.
1030 (if (= (length ede-object) 1)
1031 (setq ede-object (car ede-object)))
1032 ;; Track the project, if needed.
1033 (when (and projsym (symbolp projsym))
1034 (if ede-object
1035 ;; If we found a target, then PO is the
1036 ;; project to use.
1037 (set projsym po)
1038 ;; If there is no ede-object, then the projsym
1039 ;; is whichever part of the project is most local.
1040 (set projsym localpo))
1041 ))
1042 ;; Return our findings.
acc33231
CY
1043 ede-object))
1044
1045(defmethod ede-target-in-project-p ((proj ede-project) target)
1046 "Is PROJ the parent of TARGET?
1047If TARGET belongs to a subproject, return that project file."
1048 (if (and (slot-boundp proj 'targets)
1049 (memq target (oref proj targets)))
1050 proj
1051 (let ((s (oref proj subproj))
1052 (ans nil))
1053 (while (and s (not ans))
1054 (setq ans (ede-target-in-project-p (car s) target))
1055 (setq s (cdr s)))
1056 ans)))
1057
1058(defun ede-target-parent (target)
1059 "Return the project which is the parent of TARGET.
1060It is recommended you track the project a different way as this function
1061could become slow in time."
1062 ;; @todo - use ede-object-project as a starting point.
1063 (let ((ans nil) (projs ede-projects))
1064 (while (and (not ans) projs)
1065 (setq ans (ede-target-in-project-p (car projs) target)
1066 projs (cdr projs)))
1067 ans))
1068
acc33231
CY
1069(defmethod ede-find-target ((proj ede-project) buffer)
1070 "Fetch the target in PROJ belonging to BUFFER or nil."
0816d744 1071 (with-current-buffer buffer
acc33231
CY
1072 (or ede-object
1073 (if (ede-buffer-mine proj buffer)
1074 proj
1075 (let ((targets (oref proj targets))
1076 (f nil))
1077 (while targets
1078 (if (ede-buffer-mine (car targets) buffer)
1079 (setq f (cons (car targets) f)))
1080 (setq targets (cdr targets)))
1081 f)))))
1082
1083(defmethod ede-target-buffer-in-sourcelist ((this ede-target) buffer source)
1084 "Return non-nil if object THIS is in BUFFER to a SOURCE list.
1085Handles complex path issues."
1086 (member (ede-convert-path this (buffer-file-name buffer)) source))
1087
1088(defmethod ede-buffer-mine ((this ede-project) buffer)
1089 "Return non-nil if object THIS lays claim to the file in BUFFER."
1090 nil)
1091
1092(defmethod ede-buffer-mine ((this ede-target) buffer)
1093 "Return non-nil if object THIS lays claim to the file in BUFFER."
1094 (condition-case nil
1095 (ede-target-buffer-in-sourcelist this buffer (oref this source))
1096 ;; An error implies a bad match.
1097 (error nil)))
1098
1099\f
1100;;; Project mapping
1101;;
1102(defun ede-project-buffers (project)
1103 "Return a list of all active buffers controlled by PROJECT.
1104This includes buffers controlled by a specific target of PROJECT."
1105 (let ((bl (buffer-list))
1106 (pl nil))
1107 (while bl
0816d744 1108 (with-current-buffer (car bl)
cb85c0d8 1109 (if (ede-buffer-belongs-to-project-p)
acc33231
CY
1110 (setq pl (cons (car bl) pl))))
1111 (setq bl (cdr bl)))
1112 pl))
1113
1114(defun ede-target-buffers (target)
1115 "Return a list of buffers that are controlled by TARGET."
1116 (let ((bl (buffer-list))
1117 (pl nil))
1118 (while bl
0816d744 1119 (with-current-buffer (car bl)
acc33231
CY
1120 (if (if (listp ede-object)
1121 (memq target ede-object)
1122 (eq ede-object target))
1123 (setq pl (cons (car bl) pl))))
1124 (setq bl (cdr bl)))
1125 pl))
1126
1127(defun ede-buffers ()
bd2afec2 1128 "Return a list of all buffers controlled by an EDE object."
acc33231
CY
1129 (let ((bl (buffer-list))
1130 (pl nil))
1131 (while bl
0816d744 1132 (with-current-buffer (car bl)
acc33231
CY
1133 (if ede-object
1134 (setq pl (cons (car bl) pl))))
1135 (setq bl (cdr bl)))
1136 pl))
1137
1138(defun ede-map-buffers (proc)
bd2afec2 1139 "Execute PROC on all buffers controlled by EDE."
acc33231
CY
1140 (mapcar proc (ede-buffers)))
1141
1142(defmethod ede-map-project-buffers ((this ede-project) proc)
1143 "For THIS, execute PROC on all buffers belonging to THIS."
1144 (mapcar proc (ede-project-buffers this)))
1145
1146(defmethod ede-map-target-buffers ((this ede-target) proc)
1147 "For THIS, execute PROC on all buffers belonging to THIS."
1148 (mapcar proc (ede-target-buffers this)))
1149
1150;; other types of mapping
1151(defmethod ede-map-subprojects ((this ede-project) proc)
1152 "For object THIS, execute PROC on all direct subprojects.
1153This function does not apply PROC to sub-sub projects.
1154See also `ede-map-all-subprojects'."
1155 (mapcar proc (oref this subproj)))
1156
1157(defmethod ede-map-all-subprojects ((this ede-project) allproc)
1158 "For object THIS, execute PROC on THIS and all subprojects.
1159This function also applies PROC to sub-sub projects.
1160See also `ede-map-subprojects'."
1161 (apply 'append
1162 (list (funcall allproc this))
1163 (ede-map-subprojects
1164 this
1165 (lambda (sp)
1166 (ede-map-all-subprojects sp allproc))
1167 )))
1168
1169;; (ede-map-all-subprojects (ede-load-project-file "../semantic/") (lambda (sp) (oref sp file)))
1170
1171(defmethod ede-map-targets ((this ede-project) proc)
1172 "For object THIS, execute PROC on all targets."
1173 (mapcar proc (oref this targets)))
1174
1175(defmethod ede-map-any-target-p ((this ede-project) proc)
1176 "For project THIS, map PROC to all targets and return if any non-nil.
1177Return the first non-nil value returned by PROC."
b90caf50 1178 (eval (cons 'or (ede-map-targets this proc))))
acc33231 1179
cb85c0d8
EL
1180;;; VC Handling
1181;;
1182(defun ede-maybe-checkout (&optional buffer)
1183 "Check BUFFER out of VC if necessary."
1184 (save-excursion
1185 (if buffer (set-buffer buffer))
1186 (if (and buffer-read-only vc-mode
1187 (y-or-n-p "Checkout Makefile.am from VC? "))
1188 (vc-toggle-read-only))))
1189
acc33231
CY
1190\f
1191;;; Some language specific methods.
1192;;
1193;; These items are needed by ede-cpp-root to add better support for
1194;; configuring items for Semantic.
1195(defun ede-apply-preprocessor-map ()
1196 "Apply preprocessor tables onto the current buffer."
1197 (when (and ede-object (boundp 'semantic-lex-spp-macro-symbol-obarray))
1dc5c6f3
CY
1198 (let* ((objs ede-object)
1199 (map (ede-preprocessor-map (if (consp objs)
1200 (car objs)
1201 objs))))
acc33231
CY
1202 (when map
1203 ;; We can't do a require for the below symbol.
1204 (setq semantic-lex-spp-macro-symbol-obarray
1dc5c6f3
CY
1205 (semantic-lex-make-spp-table map)))
1206 (when (consp objs)
1207 (message "Choosing preprocessor syms for project %s"
1208 (object-name (car objs)))))))
acc33231
CY
1209
1210(defmethod ede-system-include-path ((this ede-project))
1211 "Get the system include path used by project THIS."
1212 nil)
1213
1214(defmethod ede-preprocessor-map ((this ede-project))
1215 "Get the pre-processor map for project THIS."
1216 nil)
1217
1218(defmethod ede-system-include-path ((this ede-target))
1219 "Get the system include path used by project THIS."
1220 nil)
1221
1222(defmethod ede-preprocessor-map ((this ede-target))
1223 "Get the pre-processor map for project THIS."
1224 nil)
1225
1226\f
1227;;; Project-local variables
1228;;
1229(defun ede-make-project-local-variable (variable &optional project)
1230 "Make VARIABLE project-local to PROJECT."
1231 (if (not project) (setq project (ede-current-project)))
1232 (if (assoc variable (oref project local-variables))
1233 nil
1234 (oset project local-variables (cons (list variable)
1235 (oref project local-variables)))
0816d744
SM
1236 (dolist (b (ede-project-buffers project))
1237 (with-current-buffer b
1238 (make-local-variable variable)))))
acc33231
CY
1239
1240(defmethod ede-set-project-variables ((project ede-project) &optional buffer)
1241 "Set variables local to PROJECT in BUFFER."
1242 (if (not buffer) (setq buffer (current-buffer)))
0816d744
SM
1243 (with-current-buffer buffer
1244 (dolist (v (oref project local-variables))
1245 (make-local-variable (car v))
cb85c0d8 1246 ;; set its value here?
0816d744 1247 (set (car v) (cdr v)))))
acc33231
CY
1248
1249(defun ede-set (variable value &optional proj)
1250 "Set the project local VARIABLE to VALUE.
bd2afec2
GM
1251If VARIABLE is not project local, just use set. Optional argument PROJ
1252is the project to use, instead of `ede-current-project'."
acc33231
CY
1253 (let ((p (or proj (ede-current-project)))
1254 a)
1255 (if (and p (setq a (assoc variable (oref p local-variables))))
1256 (progn
1257 (setcdr a value)
0816d744
SM
1258 (dolist (b (ede-project-buffers p))
1259 (with-current-buffer b
1260 (set variable value))))
acc33231
CY
1261 (set variable value))
1262 (ede-commit-local-variables p))
1263 value)
1264
1265(defmethod ede-commit-local-variables ((proj ede-project))
1266 "Commit change to local variables in PROJ."
1267 nil)
1268
acc33231
CY
1269(provide 'ede)
1270
1271;; Include this last because it depends on ede.
1272(require 'ede/files)
1273
1274;; If this does not occur after the provide, we can get a recursive
1275;; load. Yuck!
1276(if (featurep 'speedbar)
1277 (ede-speedbar-file-setup)
1278 (add-hook 'speedbar-load-hook 'ede-speedbar-file-setup))
1279
1280;;; ede.el ends here