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