* progmodes/python.el (python-send-region): Ensure, that the
[emacs.git] / lisp / cedet / ede.el
blobcc8b6f5324219ebf9c7ffcc9924e94f253c0caec
1 ;;; ede.el --- Emacs Development Environment gloss
3 ;; Copyright (C) 1998-2005, 2007-2012 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: project, make
7 ;; Version: 1.0pre7
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
24 ;;; Commentary:
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.
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.
36 ;;; Install
38 ;; This command enables project mode on all files.
40 ;; (global-ede-mode t)
42 (require 'cedet)
43 (require 'eieio)
44 (require 'eieio-speedbar)
45 (require 'ede/source)
46 (require 'ede/base)
47 (require 'ede/auto)
49 (load "ede/loaddefs" nil 'nomessage)
51 (declare-function ede-commit-project "ede/custom")
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")
58 (declare-function ede-toplevel "ede/base")
59 (declare-function ede-toplevel-project "ede/files")
60 (declare-function ede-up-directory "ede/files")
61 (declare-function semantic-lex-make-spp-table "semantic/lex-spp")
63 (defconst ede-version "1.0"
64 "Current version of the Emacs EDE.")
66 ;;; Code:
67 (defun ede-version ()
68 "Display the current running version of EDE."
69 (interactive) (message "EDE %s" ede-version))
71 (defgroup ede nil
72 "Emacs Development Environment."
73 :group 'tools
74 :group 'extensions)
76 (defcustom ede-auto-add-method 'ask
77 "Whether a new source file should be automatically added to a target.
78 Whenever a new file is encountered in a directory controlled by a
79 project file, all targets are queried to see if it should be added.
80 If the value is 'always, then the new file is added to the first
81 target encountered. If the value is 'multi-ask, then if more than one
82 target wants the file, the user is asked. If only one target wants
83 the file, then it is automatically added to that target. If the
84 value is 'ask, then the user is always asked, unless there is no
85 target 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)))
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
97 (defcustom ede-project-directories nil
98 "Directories in which EDE may search for project files.
99 If the value is t, EDE may search in any directory.
101 If the value is a function, EDE calls that function with one
102 argument, the directory name; the function should return t iff
103 EDE should look for project files in the directory.
105 Otherwise, the value should be a list of fully-expanded directory
106 names. EDE searches for project files only in those directories.
107 If you invoke the commands \\[ede] or \\[ede-new] on a directory
108 that is not listed, Emacs will offer to add it to the list.
110 Any other value disables searching for EDE project files."
111 :group 'ede
112 :type '(choice (const :tag "Any directory" t)
113 (repeat :tag "List of directories"
114 (directory))
115 (function :tag "Predicate"))
116 :version "23.4"
117 :risky t)
119 (defun ede-directory-safe-p (dir)
120 "Return non-nil if DIR is a safe directory to load projects from.
121 Projects that do not load a project definition as Emacs Lisp code
122 are safe, and can be loaded automatically. Other project types,
123 such as those created with Project.ede files, are safe only if
124 specified by `ede-project-directories'."
125 (setq dir (directory-file-name (expand-file-name dir)))
126 ;; Load only if allowed by `ede-project-directories'.
127 (or (eq ede-project-directories t)
128 (and (functionp ede-project-directories)
129 (funcall ede-project-directories dir))
130 (and (listp ede-project-directories)
131 (member dir ede-project-directories))))
134 ;;; Management variables
136 (defvar ede-projects nil
137 "A list of all active projects currently loaded in Emacs.")
139 (defvar ede-object-root-project nil
140 "The current buffer's current root project.
141 If a file is under a project, this specifies the project that is at
142 the root of a project tree.")
143 (make-variable-buffer-local 'ede-object-root-project)
145 (defvar ede-object-project nil
146 "The current buffer's current project at that level.
147 If a file is under a project, this specifies the project that contains the
148 current target.")
149 (make-variable-buffer-local 'ede-object-project)
151 (defvar ede-object nil
152 "The current buffer's target object.
153 This object's class determines how to compile and debug from a buffer.")
154 (make-variable-buffer-local 'ede-object)
156 (defvar ede-selected-object nil
157 "The currently user-selected project or target.
158 If `ede-object' is nil, then commands will operate on this object.")
160 (defvar ede-constructing nil
161 "Non nil when constructing a project hierarchy.
162 If the project is being constructed from an autoload, then the
163 value is the autoload object being used.")
165 (defvar ede-deep-rescan nil
166 "Non nil means scan down a tree, otherwise rescans are top level only.
167 Do not set this to non-nil globally. It is used internally.")
170 ;;; Prompting
172 (defun ede-singular-object (prompt)
173 "Using PROMPT, choose a single object from the current buffer."
174 (if (listp ede-object)
175 (ede-choose-object prompt ede-object)
176 ede-object))
178 (defun ede-choose-object (prompt list-o-o)
179 "Using PROMPT, ask the user which OBJECT to use based on the name field.
180 Argument LIST-O-O is the list of objects to choose from."
181 (let* ((al (object-assoc-list 'name list-o-o))
182 (ans (completing-read prompt al nil t)))
183 (setq ans (assoc ans al))
184 (cdr ans)))
186 ;;; Menu and Keymap
188 (defvar ede-minor-mode-map
189 (let ((map (make-sparse-keymap))
190 (pmap (make-sparse-keymap)))
191 (define-key pmap "e" 'ede-edit-file-target)
192 (define-key pmap "a" 'ede-add-file)
193 (define-key pmap "d" 'ede-remove-file)
194 (define-key pmap "t" 'ede-new-target)
195 (define-key pmap "g" 'ede-rescan-toplevel)
196 (define-key pmap "s" 'ede-speedbar)
197 (define-key pmap "l" 'ede-load-project-file)
198 (define-key pmap "f" 'ede-find-file)
199 (define-key pmap "C" 'ede-compile-project)
200 (define-key pmap "c" 'ede-compile-target)
201 (define-key pmap "\C-c" 'ede-compile-selected)
202 (define-key pmap "D" 'ede-debug-target)
203 (define-key pmap "R" 'ede-run-target)
204 ;; bind our submap into map
205 (define-key map "\C-c." pmap)
206 map)
207 "Keymap used in project minor mode.")
209 (defvar global-ede-mode-map
210 (let ((map (make-sparse-keymap)))
211 (define-key map [menu-bar cedet-menu]
212 (cons "Development" cedet-menu-map))
213 map)
214 "Keymap used in `global-ede-mode'.")
216 ;; Activate the EDE items in cedet-menu-map
218 (define-key cedet-menu-map [ede-find-file]
219 '(menu-item "Find File in Project..." ede-find-file :enable ede-object
220 :visible global-ede-mode))
221 (define-key cedet-menu-map [ede-speedbar]
222 '(menu-item "View Project Tree" ede-speedbar :enable ede-object
223 :visible global-ede-mode))
224 (define-key cedet-menu-map [ede]
225 '(menu-item "Load Project" ede
226 :visible global-ede-mode))
227 (define-key cedet-menu-map [ede-new]
228 '(menu-item "Create Project" ede-new
229 :enable (not ede-object)
230 :visible global-ede-mode))
231 (define-key cedet-menu-map [ede-target-options]
232 '(menu-item "Target Options" ede-target-options
233 :filter ede-target-forms-menu
234 :visible global-ede-mode))
235 (define-key cedet-menu-map [ede-project-options]
236 '(menu-item "Project Options" ede-project-options
237 :filter ede-project-forms-menu
238 :visible global-ede-mode))
239 (define-key cedet-menu-map [ede-build-forms-menu]
240 '(menu-item "Build Project" ede-build-forms-menu
241 :filter ede-build-forms-menu
242 :enable ede-object
243 :visible global-ede-mode))
245 (defun ede-buffer-belongs-to-target-p ()
246 "Return non-nil if this buffer belongs to at least one target."
247 (let ((obj ede-object))
248 (if (consp obj)
249 (setq obj (car obj)))
250 (and obj (obj-of-class-p obj ede-target))))
252 (defun ede-buffer-belongs-to-project-p ()
253 "Return non-nil if this buffer belongs to at least one project."
254 (if (or (null ede-object) (consp ede-object)) nil
255 (obj-of-class-p ede-object ede-project)))
257 (defun ede-menu-obj-of-class-p (class)
258 "Return non-nil if some member of `ede-object' is a child of CLASS."
259 (if (listp ede-object)
260 (eval (cons 'or (mapcar (lambda (o) (obj-of-class-p o class)) ede-object)))
261 (obj-of-class-p ede-object class)))
263 (defun ede-build-forms-menu (menu-def)
264 "Create a sub menu for building different parts of an EDE system.
265 Argument MENU-DEF is the menu definition to use."
266 (easy-menu-filter-return
267 (easy-menu-create-menu
268 "Build Forms"
269 (let ((obj (ede-current-project))
270 (newmenu nil) ;'([ "Build Selected..." ede-compile-selected t ]))
271 targets
272 targitems
273 ede-obj
274 (tskip nil))
275 (if (not obj)
277 (setq targets (when (slot-boundp obj 'targets)
278 (oref obj targets))
279 ede-obj (if (listp ede-object) ede-object (list ede-object)))
280 ;; First, collect the build items from the project
281 (setq newmenu (append newmenu (ede-menu-items-build obj t)))
282 ;; Second, declare the current target menu items
283 (if (and ede-obj (ede-menu-obj-of-class-p ede-target))
284 (while ede-obj
285 (setq newmenu (append newmenu
286 (ede-menu-items-build (car ede-obj) t))
287 tskip (car ede-obj)
288 ede-obj (cdr ede-obj))))
289 ;; Third, by name, enable builds for other local targets
290 (while targets
291 (unless (eq tskip (car targets))
292 (setq targitems (ede-menu-items-build (car targets) nil))
293 (setq newmenu
294 (append newmenu
295 (if (= 1 (length targitems))
296 targitems
297 (cons (ede-name (car targets))
298 targitems))))
300 (setq targets (cdr targets)))
301 ;; Fourth, build sub projects.
302 ;; -- nerp
303 ;; Fifth, add make distribution
304 (append newmenu (list [ "Make distribution" ede-make-dist t ]))
305 )))))
307 (defun ede-target-forms-menu (menu-def)
308 "Create a target MENU-DEF based on the object belonging to this buffer."
309 (easy-menu-filter-return
310 (easy-menu-create-menu
311 "Target Forms"
312 (let ((obj (or ede-selected-object ede-object)))
313 (append
314 '([ "Add File" ede-add-file
315 (and (ede-current-project)
316 (oref (ede-current-project) targets)) ]
317 [ "Remove File" ede-remove-file
318 (ede-buffer-belongs-to-project-p) ]
319 "-")
320 (if (not obj)
322 (if (and (not (listp obj)) (oref obj menu))
323 (oref obj menu)
324 (when (listp obj)
325 ;; This is bad, but I'm not sure what else to do.
326 (oref (car obj) menu)))))))))
328 (defun ede-project-forms-menu (menu-def)
329 "Create a target MENU-DEF based on the object belonging to this buffer."
330 (easy-menu-filter-return
331 (easy-menu-create-menu
332 "Project Forms"
333 (let* ((obj (ede-current-project))
334 (class (if obj (object-class obj)))
335 (menu nil))
336 (condition-case err
337 (progn
338 (while (and class (slot-exists-p class 'menu))
339 ;;(message "Looking at class %S" class)
340 (setq menu (append menu (oref class menu))
341 class (class-parent class))
342 (if (listp class) (setq class (car class))))
343 (append
344 '( [ "Add Target" ede-new-target (ede-current-project) ]
345 [ "Remove Target" ede-delete-target ede-object ]
346 "-")
347 menu
349 (error (message "Err found: %S" err)
350 menu)
351 )))))
353 (defun ede-customize-forms-menu (menu-def)
354 "Create a menu of the project, and targets that can be customized.
355 Argument MENU-DEF is the definition of the current menu."
356 (easy-menu-filter-return
357 (easy-menu-create-menu
358 "Customize Project"
359 (let* ((obj (ede-current-project))
360 targ)
361 (when obj
362 (setq targ (when (and obj (slot-boundp obj 'targets))
363 (oref obj targets)))
364 ;; Make custom menus for everything here.
365 (append (list
366 (cons (concat "Project " (ede-name obj))
367 (eieio-customize-object-group obj))
368 [ "Reorder Targets" ede-project-sort-targets t ]
370 (mapcar (lambda (o)
371 (cons (concat "Target " (ede-name o))
372 (eieio-customize-object-group o)))
373 targ)))))))
376 (defun ede-apply-object-keymap (&optional default)
377 "Add target specific keybindings into the local map.
378 Optional argument DEFAULT indicates if this should be set to the default
379 version of the keymap."
380 (let ((object (or ede-object ede-selected-object)))
381 (condition-case nil
382 (let ((keys (ede-object-keybindings object)))
383 (while keys
384 (local-set-key (concat "\C-c." (car (car keys)))
385 (cdr (car keys)))
386 (setq keys (cdr keys))))
387 (error nil))))
389 ;;; Menu building methods for building
391 (defmethod ede-menu-items-build ((obj ede-project) &optional current)
392 "Return a list of menu items for building project OBJ.
393 If optional argument CURRENT is non-nil, return sub-menu code."
394 (if current
395 (list [ "Build Current Project" ede-compile-project t ])
396 (list (vector
397 (list
398 (concat "Build Project " (ede-name obj))
399 `(project-compile-project ,obj))))))
401 (defmethod ede-menu-items-build ((obj ede-target) &optional current)
402 "Return a list of menu items for building target OBJ.
403 If optional argument CURRENT is non-nil, return sub-menu code."
404 (if current
405 (list [ "Build Current Target" ede-compile-target t ])
406 (list (vector
407 (concat "Build Target " (ede-name obj))
408 `(project-compile-target ,obj)
409 t))))
411 ;;; Mode Declarations
413 (eval-and-compile
414 (autoload 'ede-dired-minor-mode "ede/dired" "EDE commands for dired" t))
416 (defun ede-apply-target-options ()
417 "Apply options to the current buffer for the active project/target."
418 (if (ede-current-project)
419 (ede-set-project-variables (ede-current-project)))
420 (ede-apply-object-keymap)
421 (ede-apply-preprocessor-map)
424 (defun ede-turn-on-hook ()
425 "Turn on EDE minor mode in the current buffer if needed.
426 To be used in hook functions."
427 (if (or (and (stringp (buffer-file-name))
428 (stringp default-directory))
429 ;; Emacs 21 has no buffer file name for directory edits.
430 ;; so we need to add these hacks in.
431 (eq major-mode 'dired-mode)
432 (eq major-mode 'vc-dired-mode))
433 (ede-minor-mode 1)))
435 (define-minor-mode ede-minor-mode
436 "Toggle EDE (Emacs Development Environment) minor mode.
437 With a prefix argument ARG, enable EDE minor mode if ARG is
438 positive, and disable it otherwise. If called from Lisp, enable
439 EDE minor mode if ARG is omitted or nil.
441 If this file is contained, or could be contained in an EDE
442 controlled project, then this mode is activated automatically
443 provided `global-ede-mode' is enabled."
444 :group 'ede
445 (cond ((or (eq major-mode 'dired-mode)
446 (eq major-mode 'vc-dired-mode))
447 (ede-dired-minor-mode (if ede-minor-mode 1 -1)))
448 (ede-minor-mode
449 (if (not ede-constructing)
450 (ede-initialize-state-current-buffer)
451 ;; If we fail to have a project here, turn it back off.
452 (ede-minor-mode -1)))))
454 (defun ede-initialize-state-current-buffer ()
455 "Initialize the current buffer's state for EDE.
456 Sets buffer local variables for EDE."
457 (let* ((ROOT nil)
458 (proj (ede-directory-get-open-project default-directory
459 'ROOT))
460 (projauto nil))
462 (when (or proj ROOT
463 ;; If there is no open project, look up the project
464 ;; autoloader to see if we should initialize.
465 (setq projauto (ede-directory-project-p default-directory t)))
467 (when (and (not proj) projauto)
469 ;; No project was loaded, but we have a project description
470 ;; object. This means that we can check if it is a safe
471 ;; project to load before requesting it to be loaded.
473 (when (or (oref projauto safe-p)
474 ;; The project style is not safe, so check if it is
475 ;; in `ede-project-directories'.
476 (let ((top (ede-toplevel-project default-directory)))
477 (ede-directory-safe-p top)))
479 ;; The project is safe, so load it in.
480 (setq proj (ede-load-project-file default-directory 'ROOT))))
482 ;; Only initialize EDE state in this buffer if we found a project.
483 (when proj
485 (setq ede-object (ede-buffer-object (current-buffer)
486 'ede-object-project))
488 (setq ede-object-root-project
489 (or ROOT (ede-project-root ede-object-project)))
491 (if (and (not ede-object) ede-object-project)
492 (ede-auto-add-to-target))
494 (ede-apply-target-options)))))
496 (defun ede-reset-all-buffers (onoff)
497 "Reset all the buffers due to change in EDE.
498 ONOFF indicates enabling or disabling the mode."
499 (let ((b (buffer-list)))
500 (while b
501 (when (buffer-file-name (car b))
502 (with-current-buffer (car b)
503 ;; Reset all state variables
504 (setq ede-object nil
505 ede-object-project nil
506 ede-object-root-project nil)
507 ;; Now re-initialize this buffer.
508 (ede-initialize-state-current-buffer)
511 (setq b (cdr b)))))
513 ;;;###autoload
514 (define-minor-mode global-ede-mode
515 "Toggle global EDE (Emacs Development Environment) mode.
516 With a prefix argument ARG, enable global EDE mode if ARG is
517 positive, and disable it otherwise. If called from Lisp, enable
518 the mode if ARG is omitted or nil.
520 This global minor mode enables `ede-minor-mode' in all buffers in
521 an EDE controlled project."
522 :global t
523 :group 'ede
524 (if global-ede-mode
525 ;; Turn on global-ede-mode
526 (progn
527 (if semantic-mode
528 (define-key cedet-menu-map [cedet-menu-separator] '("--")))
529 (add-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
530 (add-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
531 (add-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
532 (add-hook 'find-file-hook 'ede-turn-on-hook)
533 (add-hook 'dired-mode-hook 'ede-turn-on-hook)
534 (add-hook 'kill-emacs-hook 'ede-save-cache)
535 (ede-load-cache)
536 (ede-reset-all-buffers 1))
537 ;; Turn off global-ede-mode
538 (define-key cedet-menu-map [cedet-menu-separator] nil)
539 (remove-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
540 (remove-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
541 (remove-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
542 (remove-hook 'find-file-hook 'ede-turn-on-hook)
543 (remove-hook 'dired-mode-hook 'ede-turn-on-hook)
544 (remove-hook 'kill-emacs-hook 'ede-save-cache)
545 (ede-save-cache)
546 (ede-reset-all-buffers -1)))
548 (defvar ede-ignored-file-alist
549 '( "\\.cvsignore$"
550 "\\.#"
551 "~$"
553 "List of file name patters that EDE will never ask about.")
555 (defun ede-ignore-file (filename)
556 "Should we ignore FILENAME?"
557 (let ((any nil)
558 (F ede-ignored-file-alist))
559 (while (and (not any) F)
560 (when (string-match (car F) filename)
561 (setq any t))
562 (setq F (cdr F)))
563 any))
565 (defun ede-auto-add-to-target ()
566 "Look for a target that wants to own the current file.
567 Follow the preference set with `ede-auto-add-method' and get the list
568 of objects with the `ede-want-file-p' method."
569 (if ede-object (error "ede-object already defined for %s" (buffer-name)))
570 (if (or (eq ede-auto-add-method 'never)
571 (ede-ignore-file (buffer-file-name)))
573 (let (wants desires)
574 ;; Find all the objects.
575 (setq wants (oref (ede-current-project) targets))
576 (while wants
577 (if (ede-want-file-p (car wants) (buffer-file-name))
578 (setq desires (cons (car wants) desires)))
579 (setq wants (cdr wants)))
580 (if desires
581 (cond ((or (eq ede-auto-add-method 'ask)
582 (and (eq ede-auto-add-method 'multi-ask)
583 (< 1 (length desires))))
584 (let* ((al (append
585 ;; some defaults
586 '(("none" . nil)
587 ("new target" . new))
588 ;; If we are in an unparented subdir,
589 ;; offer new a subproject
590 (if (ede-directory-project-p default-directory)
592 '(("create subproject" . project)))
593 ;; Here are the existing objects we want.
594 (object-assoc-list 'name desires)))
595 (case-fold-search t)
596 (ans (completing-read
597 (format "Add %s to target: " (buffer-file-name))
598 al nil t)))
599 (setq ans (assoc ans al))
600 (cond ((eieio-object-p (cdr ans))
601 (ede-add-file (cdr ans)))
602 ((eq (cdr ans) 'new)
603 (ede-new-target))
604 (t nil))))
605 ((or (eq ede-auto-add-method 'always)
606 (and (eq ede-auto-add-method 'multi-ask)
607 (= 1 (length desires))))
608 (ede-add-file (car desires)))
609 (t nil))))))
612 ;;; Interactive method invocations
614 (defun ede (dir)
615 "Start up EDE for directory DIR.
616 If DIR has an existing project file, load it.
617 Otherwise, create a new project for DIR."
618 (interactive
619 ;; When choosing a directory to turn on, and we see some directory here,
620 ;; provide that as the default.
621 (let* ((top (ede-toplevel-project default-directory))
622 (promptdflt (or top default-directory)))
623 (list (read-directory-name "Project directory: "
624 promptdflt promptdflt t))))
625 (unless (file-directory-p dir)
626 (error "%s is not a directory" dir))
627 (when (ede-directory-get-open-project dir)
628 (error "%s already has an open project associated with it" dir))
630 ;; Check if the directory has been added to the list of safe
631 ;; directories. It can also add the directory to the safe list if
632 ;; the user chooses.
633 (if (ede-check-project-directory dir)
634 (progn
635 ;; If there is a project in DIR, load it, otherwise do
636 ;; nothing.
637 (ede-load-project-file dir)
639 ;; Check if we loaded anything on the previous line.
640 (if (ede-current-project dir)
642 ;; We successfully opened an existing project. Some open
643 ;; buffers may also be referring to this project.
644 ;; Resetting all the buffers will get them to also point
645 ;; at this new open project.
646 (ede-reset-all-buffers 1)
648 ;; ELSE
649 ;; There was no project, so switch to `ede-new' which is how
650 ;; a user can select a new kind of project to create.
651 (let ((default-directory (expand-file-name dir)))
652 (call-interactively 'ede-new))))
654 ;; If the proposed directory isn't safe, then say so.
655 (error "%s is not an allowed project directory in `ede-project-directories'"
656 dir)))
658 (defun ede-check-project-directory (dir)
659 "Check if DIR should be in `ede-project-directories'.
660 If it is not, try asking the user if it should be added; if so,
661 add it and save `ede-project-directories' via Customize.
662 Return nil iff DIR should not be in `ede-project-directories'."
663 (setq dir (directory-file-name (expand-file-name dir))) ; strip trailing /
664 (or (eq ede-project-directories t)
665 (and (functionp ede-project-directories)
666 (funcall ede-project-directories dir))
667 ;; If `ede-project-directories' is a list, maybe add it.
668 (when (listp ede-project-directories)
669 (or (member dir ede-project-directories)
670 (when (y-or-n-p (format "`%s' is not listed in `ede-project-directories'.
671 Add it to the list of allowed project directories? "
672 dir))
673 (push dir ede-project-directories)
674 ;; If possible, save `ede-project-directories'.
675 (if (or custom-file user-init-file)
676 (let ((coding-system-for-read nil))
677 (customize-save-variable
678 'ede-project-directories
679 ede-project-directories)))
680 t)))))
682 (defun ede-new (type &optional name)
683 "Create a new project starting from project type TYPE.
684 Optional argument NAME is the name to give this project."
685 (interactive
686 (list (completing-read "Project Type: "
687 (object-assoc-list
688 'name
689 (let* ((l ede-project-class-files)
690 (cp (ede-current-project))
691 (cs (when cp (object-class cp)))
692 (r nil))
693 (while l
694 (if cs
695 (if (eq (oref (car l) :class-sym)
697 (setq r (cons (car l) r)))
698 (if (oref (car l) new-p)
699 (setq r (cons (car l) r))))
700 (setq l (cdr l)))
701 (when (not r)
702 (if cs
703 (error "No valid interactive sub project types for %s"
705 (error "EDE error: Can't fin project types to create")))
708 nil t)))
709 (require 'ede/custom)
710 ;; Make sure we have a valid directory
711 (when (not (file-exists-p default-directory))
712 (error "Cannot create project in non-existent directory %s" default-directory))
713 (when (not (file-writable-p default-directory))
714 (error "No write permissions for %s" default-directory))
715 (unless (ede-check-project-directory default-directory)
716 (error "%s is not an allowed project directory in `ede-project-directories'"
717 default-directory))
718 ;; Make sure the project directory is loadable in the future.
719 (ede-check-project-directory default-directory)
720 ;; Create the project
721 (let* ((obj (object-assoc type 'name ede-project-class-files))
722 (nobj (let ((f (oref obj file))
723 (pf (oref obj proj-file)))
724 ;; We are about to make something new, changing the
725 ;; state of existing directories.
726 (ede-project-directory-remove-hash default-directory)
727 ;; Make sure this class gets loaded!
728 (require f)
729 (make-instance (oref obj class-sym)
730 :name (or name (read-string "Name: "))
731 :directory default-directory
732 :file (cond ((stringp pf)
733 (expand-file-name pf))
734 ((fboundp pf)
735 (funcall pf))
737 (error
738 "Unknown file name specifier %S"
739 pf)))
740 :targets nil)))
741 (inits (oref obj initializers)))
742 ;; Force the name to match for new objects.
743 (object-set-name-string nobj (oref nobj :name))
744 ;; Handle init args.
745 (while inits
746 (eieio-oset nobj (car inits) (car (cdr inits)))
747 (setq inits (cdr (cdr inits))))
748 (let ((pp (ede-parent-project)))
749 (when pp
750 (ede-add-subproject pp nobj)
751 (ede-commit-project pp)))
752 (ede-commit-project nobj))
753 ;; Once the project is created, load it again. This used to happen
754 ;; lazily, but with project loading occurring less often and with
755 ;; security in mind, this is now the safe time to reload.
756 (ede-load-project-file default-directory)
757 ;; Have the menu appear
758 (setq ede-minor-mode t)
759 ;; Allert the user
760 (message "Project created and saved. You may now create targets."))
762 (defmethod ede-add-subproject ((proj-a ede-project) proj-b)
763 "Add into PROJ-A, the subproject PROJ-B."
764 (oset proj-a subproj (cons proj-b (oref proj-a subproj))))
766 (defun ede-invoke-method (sym &rest args)
767 "Invoke method SYM on the current buffer's project object.
768 ARGS are additional arguments to pass to method SYM."
769 (if (not ede-object)
770 (error "Cannot invoke %s for %s" (symbol-name sym)
771 (buffer-name)))
772 ;; Always query a target. There should never be multiple
773 ;; projects in a single buffer.
774 (apply sym (ede-singular-object "Target: ") args))
776 (defun ede-rescan-toplevel ()
777 "Rescan all project files."
778 (interactive)
779 (if (not (ede-directory-get-open-project default-directory))
780 ;; This directory isn't open. Can't rescan.
781 (error "Attempt to rescan a project that isn't open")
783 ;; Continue
784 (let ((toppath (ede-toplevel-project default-directory))
785 (ede-deep-rescan t))
787 (project-rescan (ede-load-project-file toppath))
788 (ede-reset-all-buffers 1))))
790 (defun ede-new-target (&rest args)
791 "Create a new target specific to this type of project file.
792 Different projects accept different arguments ARGS.
793 Typically you can specify NAME, target TYPE, and AUTOADD, where AUTOADD is
794 a string \"y\" or \"n\", which answers the y/n question done interactively."
795 (interactive)
796 (apply 'project-new-target (ede-current-project) args)
797 (setq ede-object nil)
798 (setq ede-object (ede-buffer-object (current-buffer)))
799 (ede-apply-target-options))
801 (defun ede-new-target-custom ()
802 "Create a new target specific to this type of project file."
803 (interactive)
804 (project-new-target-custom (ede-current-project)))
806 (defun ede-delete-target (target)
807 "Delete TARGET from the current project."
808 (interactive (list
809 (let ((ede-object (ede-current-project)))
810 (ede-invoke-method 'project-interactive-select-target
811 "Target: "))))
812 ;; Find all sources in buffers associated with the condemned buffer.
813 (let ((condemned (ede-target-buffers target)))
814 (project-delete-target target)
815 ;; Loop over all project controlled buffers
816 (save-excursion
817 (while condemned
818 (set-buffer (car condemned))
819 (setq ede-object nil)
820 (setq ede-object (ede-buffer-object (current-buffer)))
821 (setq condemned (cdr condemned))))
822 (ede-apply-target-options)))
824 (defun ede-add-file (target)
825 "Add the current buffer to a TARGET in the current project."
826 (interactive (list
827 (let ((ede-object (ede-current-project)))
828 (ede-invoke-method 'project-interactive-select-target
829 "Target: "))))
830 (when (stringp target)
831 (let* ((proj (ede-current-project))
832 (ob (object-assoc-list 'name (oref proj targets))))
833 (setq target (cdr (assoc target ob)))))
835 (when (not target)
836 (error "Could not find specified target %S" target))
838 (project-add-file target (buffer-file-name))
839 (setq ede-object nil)
840 (setq ede-object (ede-buffer-object (current-buffer)))
841 (when (not ede-object)
842 (error "Can't add %s to target %s: Wrong file type"
843 (file-name-nondirectory (buffer-file-name))
844 (object-name target)))
845 (ede-apply-target-options))
847 (defun ede-remove-file (&optional force)
848 "Remove the current file from targets.
849 Optional argument FORCE forces the file to be removed without asking."
850 (interactive "P")
851 (if (not ede-object)
852 (error "Cannot invoke remove-file for %s" (buffer-name)))
853 (let ((eo (if (listp ede-object)
854 (prog1
855 ede-object
856 (setq force nil))
857 (list ede-object))))
858 (while eo
859 (if (or force (y-or-n-p (format "Remove from %s? " (ede-name (car eo)))))
860 (project-remove-file (car eo) (buffer-file-name)))
861 (setq eo (cdr eo)))
862 (setq ede-object nil)
863 (setq ede-object (ede-buffer-object (current-buffer)))
864 (ede-apply-target-options)))
866 (defun ede-edit-file-target ()
867 "Enter the project file to hand edit the current buffer's target."
868 (interactive)
869 (ede-invoke-method 'project-edit-file-target))
871 (defun ede-compile-project ()
872 "Compile the current project."
873 (interactive)
874 ;; @TODO - This just wants the root. There should be a better way.
875 (let ((cp (ede-current-project)))
876 (while (ede-parent-project cp)
877 (setq cp (ede-parent-project cp)))
878 (let ((ede-object cp))
879 (ede-invoke-method 'project-compile-project))))
881 (defun ede-compile-selected (target)
882 "Compile some TARGET from the current project."
883 (interactive (list (project-interactive-select-target (ede-current-project)
884 "Target to Build: ")))
885 (project-compile-target target))
887 (defun ede-compile-target ()
888 "Compile the current buffer's associated target."
889 (interactive)
890 (ede-invoke-method 'project-compile-target))
892 (defun ede-debug-target ()
893 "Debug the current buffer's associated target."
894 (interactive)
895 (ede-invoke-method 'project-debug-target))
897 (defun ede-run-target ()
898 "Run the current buffer's associated target."
899 (interactive)
900 (ede-invoke-method 'project-run-target))
902 (defun ede-make-dist ()
903 "Create a distribution from the current project."
904 (interactive)
905 (let ((ede-object (ede-toplevel)))
906 (ede-invoke-method 'project-make-dist)))
909 ;;; EDE project target baseline methods.
911 ;; If you are developing a new project type, you need to implement
912 ;; all of these methods, unless, of course, they do not make sense
913 ;; for your particular project.
915 ;; Your targets should inherit from `ede-target', and your project
916 ;; files should inherit from `ede-project'. Create the appropriate
917 ;; methods based on those below.
919 (defmethod project-interactive-select-target ((this ede-project-placeholder) prompt)
920 ; checkdoc-params: (prompt)
921 "Make sure placeholder THIS is replaced with the real thing, and pass through."
922 (project-interactive-select-target this prompt))
924 (defmethod project-interactive-select-target ((this ede-project) prompt)
925 "Interactively query for a target that exists in project THIS.
926 Argument PROMPT is the prompt to use when querying the user for a target."
927 (let ((ob (object-assoc-list 'name (oref this targets))))
928 (cdr (assoc (completing-read prompt ob nil t) ob))))
930 (defmethod project-add-file ((this ede-project-placeholder) file)
931 ; checkdoc-params: (file)
932 "Make sure placeholder THIS is replaced with the real thing, and pass through."
933 (project-add-file this file))
935 (defmethod project-add-file ((ot ede-target) file)
936 "Add the current buffer into project project target OT.
937 Argument FILE is the file to add."
938 (error "add-file not supported by %s" (object-name ot)))
940 (defmethod project-remove-file ((ot ede-target) fnnd)
941 "Remove the current buffer from project target OT.
942 Argument FNND is an argument."
943 (error "remove-file not supported by %s" (object-name ot)))
945 (defmethod project-edit-file-target ((ot ede-target))
946 "Edit the target OT associated with this file."
947 (find-file (oref (ede-current-project) file)))
949 (defmethod project-new-target ((proj ede-project) &rest args)
950 "Create a new target. It is up to the project PROJ to get the name."
951 (error "new-target not supported by %s" (object-name proj)))
953 (defmethod project-new-target-custom ((proj ede-project))
954 "Create a new target. It is up to the project PROJ to get the name."
955 (error "New-target-custom not supported by %s" (object-name proj)))
957 (defmethod project-delete-target ((ot ede-target))
958 "Delete the current target OT from its parent project."
959 (error "add-file not supported by %s" (object-name ot)))
961 (defmethod project-compile-project ((obj ede-project) &optional command)
962 "Compile the entire current project OBJ.
963 Argument COMMAND is the command to use when compiling."
964 (error "compile-project not supported by %s" (object-name obj)))
966 (defmethod project-compile-target ((obj ede-target) &optional command)
967 "Compile the current target OBJ.
968 Argument COMMAND is the command to use for compiling the target."
969 (error "compile-target not supported by %s" (object-name obj)))
971 (defmethod project-debug-target ((obj ede-target))
972 "Run the current project target OBJ in a debugger."
973 (error "debug-target not supported by %s" (object-name obj)))
975 (defmethod project-run-target ((obj ede-target))
976 "Run the current project target OBJ."
977 (error "run-target not supported by %s" (object-name obj)))
979 (defmethod project-make-dist ((this ede-project))
980 "Build a distribution for the project based on THIS project."
981 (error "Make-dist not supported by %s" (object-name this)))
983 (defmethod project-dist-files ((this ede-project))
984 "Return a list of files that constitute a distribution of THIS project."
985 (error "Dist-files is not supported by %s" (object-name this)))
987 (defmethod project-rescan ((this ede-project))
988 "Rescan the EDE project THIS."
989 (error "Rescanning a project is not supported by %s" (object-name this)))
991 (defun ede-ecb-project-paths ()
992 "Return a list of all paths for all active EDE projects.
993 This functions is meant for use with ECB."
994 (let ((p ede-projects)
995 (d nil))
996 (while p
997 (setq d (cons (file-name-directory (oref (car p) file))
999 p (cdr p)))
1002 ;;; PROJECT LOADING/TRACKING
1004 (defun ede-add-project-to-global-list (proj)
1005 "Add the project PROJ to the master list of projects.
1006 On success, return the added project."
1007 (when (not proj)
1008 (error "No project created to add to master list"))
1009 (when (not (eieio-object-p proj))
1010 (error "Attempt to add non-object to master project list"))
1011 (when (not (obj-of-class-p proj ede-project-placeholder))
1012 (error "Attempt to add a non-project to the ede projects list"))
1013 (add-to-list 'ede-projects proj)
1014 proj)
1016 (defun ede-load-project-file (dir &optional rootreturn)
1017 "Project file independent way to read a project in from DIR.
1018 Optional ROOTRETURN will return the root project for DIR."
1019 ;; Only load if something new is going on. Flush the dirhash.
1020 (ede-project-directory-remove-hash dir)
1021 ;; Do the load
1022 ;;(message "EDE LOAD : %S" file)
1023 (let* ((file dir)
1024 (path (file-name-as-directory (expand-file-name dir)))
1025 (pfc (ede-directory-project-p path))
1026 (toppath nil)
1027 (o nil))
1028 (cond
1029 ((not pfc)
1030 ;; @TODO - Do we really need to scan? Is this a waste of time?
1031 ;; Scan upward for a the next project file style.
1032 (let ((p path))
1033 (while (and p (not (ede-directory-project-p p)))
1034 (setq p (ede-up-directory p)))
1035 (if p (ede-load-project-file p)
1036 nil)
1037 ;; recomment as we go
1038 ;;nil
1040 ;; Do nothing if we are building an EDE project already.
1041 (ede-constructing
1042 nil)
1043 ;; Load in the project in question.
1045 (setq toppath (ede-toplevel-project path))
1046 ;; We found the top-most directory. Check to see if we already
1047 ;; have an object defining its project.
1048 (setq pfc (ede-directory-project-p toppath t))
1050 ;; See if it's been loaded before
1051 (setq o (object-assoc (ede-dir-to-projectfile pfc toppath) 'file
1052 ede-projects))
1054 ;; If not open yet, load it.
1055 (unless o
1056 (let ((ede-constructing pfc))
1057 (setq o (ede-auto-load-project pfc toppath))))
1059 ;; Return the found root project.
1060 (when rootreturn (set rootreturn o))
1062 (let (tocheck found)
1063 ;; Now find the project file belonging to FILE!
1064 (setq tocheck (list o))
1065 (setq file (ede-dir-to-projectfile pfc (expand-file-name path)))
1066 (while (and tocheck (not found))
1067 (let ((newbits nil))
1068 (when (car tocheck)
1069 (if (string= file (oref (car tocheck) file))
1070 (setq found (car tocheck)))
1071 (setq newbits (oref (car tocheck) subproj)))
1072 (setq tocheck
1073 (append (cdr tocheck) newbits))))
1074 (if (not found)
1075 (message "No project for %s, but passes project-p test" file)
1076 ;; Now that the file has been reset inside the project object, do
1077 ;; the cache maintenance.
1078 (setq ede-project-cache-files
1079 (delete (oref found file) ede-project-cache-files)))
1080 found)))))
1082 ;;; PROJECT ASSOCIATIONS
1084 ;; Moving between relative projects. Associating between buffers and
1085 ;; projects.
1087 (defun ede-parent-project (&optional obj)
1088 "Return the project belonging to the parent directory.
1089 Return nil if there is no previous directory.
1090 Optional argument OBJ is an object to find the parent of."
1091 (let* ((proj (or obj ede-object-project)) ;; Current project.
1092 (root (if obj (ede-project-root obj)
1093 ede-object-root-project)))
1094 ;; This case is a SHORTCUT if the project has defined
1095 ;; a way to calculate the project root.
1096 (if (and root proj (eq root proj))
1097 nil ;; we are at the root.
1098 ;; Else, we may have a nil proj or root.
1099 (let* ((thisdir (if obj (oref obj directory)
1100 default-directory))
1101 (updir (ede-up-directory thisdir)))
1102 (when updir
1103 ;; If there was no root, perhaps we can derive it from
1104 ;; updir now.
1105 (let ((root (or root (ede-directory-get-toplevel-open-project updir))))
1107 ;; This lets us find a subproject under root based on updir.
1108 (and root
1109 (ede-find-subproject-for-directory root updir))
1110 ;; Try the all structure based search.
1111 (ede-directory-get-open-project updir))))))))
1113 (defun ede-current-project (&optional dir)
1114 "Return the current project file.
1115 If optional DIR is provided, get the project for DIR instead."
1116 (let ((ans nil))
1117 ;; If it matches the current directory, do we have a pre-existing project?
1118 (when (and (or (not dir) (string= dir default-directory))
1119 ede-object-project)
1120 (setq ans ede-object-project)
1122 ;; No current project.
1123 (when (not ans)
1124 (let* ((ldir (or dir default-directory)))
1125 (setq ans (ede-directory-get-open-project ldir))))
1126 ;; Return what we found.
1127 ans))
1129 (defun ede-buffer-object (&optional buffer projsym)
1130 "Return the target object for BUFFER.
1131 This function clears cached values and recalculates.
1132 Optional PROJSYM is a symbol, which will be set to the project
1133 that contains the target that becomes buffer's object."
1134 (save-excursion
1135 (if (not buffer) (setq buffer (current-buffer)))
1136 (set-buffer buffer)
1137 (setq ede-object nil)
1138 (let* ((localpo (ede-current-project))
1139 (po localpo)
1140 (top (ede-toplevel po)))
1141 (if po (setq ede-object (ede-find-target po buffer)))
1142 ;; If we get nothing, go with the backup plan of slowly
1143 ;; looping upward
1144 (while (and (not ede-object) (not (eq po top)))
1145 (setq po (ede-parent-project po))
1146 (if po (setq ede-object (ede-find-target po buffer))))
1147 ;; Filter down to 1 project if there are dups.
1148 (if (= (length ede-object) 1)
1149 (setq ede-object (car ede-object)))
1150 ;; Track the project, if needed.
1151 (when (and projsym (symbolp projsym))
1152 (if ede-object
1153 ;; If we found a target, then PO is the
1154 ;; project to use.
1155 (set projsym po)
1156 ;; If there is no ede-object, then the projsym
1157 ;; is whichever part of the project is most local.
1158 (set projsym localpo))
1160 ;; Return our findings.
1161 ede-object))
1163 (defmethod ede-target-in-project-p ((proj ede-project) target)
1164 "Is PROJ the parent of TARGET?
1165 If TARGET belongs to a subproject, return that project file."
1166 (if (and (slot-boundp proj 'targets)
1167 (memq target (oref proj targets)))
1168 proj
1169 (let ((s (oref proj subproj))
1170 (ans nil))
1171 (while (and s (not ans))
1172 (setq ans (ede-target-in-project-p (car s) target))
1173 (setq s (cdr s)))
1174 ans)))
1176 (defun ede-target-parent (target)
1177 "Return the project which is the parent of TARGET.
1178 It is recommended you track the project a different way as this function
1179 could become slow in time."
1180 (or ede-object-project
1181 ;; If not cached, derive it from the current directory of the target.
1182 (let ((ans nil) (projs ede-projects))
1183 (while (and (not ans) projs)
1184 (setq ans (ede-target-in-project-p (car projs) target)
1185 projs (cdr projs)))
1186 ans)))
1188 (defmethod ede-find-target ((proj ede-project) buffer)
1189 "Fetch the target in PROJ belonging to BUFFER or nil."
1190 (with-current-buffer buffer
1191 (or ede-object
1192 (if (ede-buffer-mine proj buffer)
1193 proj
1194 (let ((targets (oref proj targets))
1195 (f nil))
1196 (while targets
1197 (if (ede-buffer-mine (car targets) buffer)
1198 (setq f (cons (car targets) f)))
1199 (setq targets (cdr targets)))
1200 f)))))
1202 (defmethod ede-target-buffer-in-sourcelist ((this ede-target) buffer source)
1203 "Return non-nil if object THIS is in BUFFER to a SOURCE list.
1204 Handles complex path issues."
1205 (member (ede-convert-path this (buffer-file-name buffer)) source))
1207 (defmethod ede-buffer-mine ((this ede-project) buffer)
1208 "Return non-nil if object THIS lays claim to the file in BUFFER."
1209 nil)
1211 (defmethod ede-buffer-mine ((this ede-target) buffer)
1212 "Return non-nil if object THIS lays claim to the file in BUFFER."
1213 (condition-case nil
1214 (ede-target-buffer-in-sourcelist this buffer (oref this source))
1215 ;; An error implies a bad match.
1216 (error nil)))
1219 ;;; Project mapping
1221 (defun ede-project-buffers (project)
1222 "Return a list of all active buffers controlled by PROJECT.
1223 This includes buffers controlled by a specific target of PROJECT."
1224 (let ((bl (buffer-list))
1225 (pl nil))
1226 (while bl
1227 (with-current-buffer (car bl)
1228 (if (ede-buffer-belongs-to-project-p)
1229 (setq pl (cons (car bl) pl))))
1230 (setq bl (cdr bl)))
1231 pl))
1233 (defun ede-target-buffers (target)
1234 "Return a list of buffers that are controlled by TARGET."
1235 (let ((bl (buffer-list))
1236 (pl nil))
1237 (while bl
1238 (with-current-buffer (car bl)
1239 (if (if (listp ede-object)
1240 (memq target ede-object)
1241 (eq ede-object target))
1242 (setq pl (cons (car bl) pl))))
1243 (setq bl (cdr bl)))
1244 pl))
1246 (defun ede-buffers ()
1247 "Return a list of all buffers controlled by an EDE object."
1248 (let ((bl (buffer-list))
1249 (pl nil))
1250 (while bl
1251 (with-current-buffer (car bl)
1252 (if ede-object
1253 (setq pl (cons (car bl) pl))))
1254 (setq bl (cdr bl)))
1255 pl))
1257 (defun ede-map-buffers (proc)
1258 "Execute PROC on all buffers controlled by EDE."
1259 (mapcar proc (ede-buffers)))
1261 (defmethod ede-map-project-buffers ((this ede-project) proc)
1262 "For THIS, execute PROC on all buffers belonging to THIS."
1263 (mapcar proc (ede-project-buffers this)))
1265 (defmethod ede-map-target-buffers ((this ede-target) proc)
1266 "For THIS, execute PROC on all buffers belonging to THIS."
1267 (mapcar proc (ede-target-buffers this)))
1269 ;; other types of mapping
1270 (defmethod ede-map-subprojects ((this ede-project) proc)
1271 "For object THIS, execute PROC on all direct subprojects.
1272 This function does not apply PROC to sub-sub projects.
1273 See also `ede-map-all-subprojects'."
1274 (mapcar proc (oref this subproj)))
1276 (defmethod ede-map-all-subprojects ((this ede-project) allproc)
1277 "For object THIS, execute PROC on THIS and all subprojects.
1278 This function also applies PROC to sub-sub projects.
1279 See also `ede-map-subprojects'."
1280 (apply 'append
1281 (list (funcall allproc this))
1282 (ede-map-subprojects
1283 this
1284 (lambda (sp)
1285 (ede-map-all-subprojects sp allproc))
1288 ;; (ede-map-all-subprojects (ede-load-project-file "../semantic/") (lambda (sp) (oref sp file)))
1290 (defmethod ede-map-targets ((this ede-project) proc)
1291 "For object THIS, execute PROC on all targets."
1292 (mapcar proc (oref this targets)))
1294 (defmethod ede-map-any-target-p ((this ede-project) proc)
1295 "For project THIS, map PROC to all targets and return if any non-nil.
1296 Return the first non-nil value returned by PROC."
1297 (eval (cons 'or (ede-map-targets this proc))))
1300 ;;; Some language specific methods.
1302 ;; These items are needed by ede-cpp-root to add better support for
1303 ;; configuring items for Semantic.
1304 (defun ede-apply-preprocessor-map ()
1305 "Apply preprocessor tables onto the current buffer."
1306 (when (and ede-object (boundp 'semantic-lex-spp-macro-symbol-obarray))
1307 (let* ((objs ede-object)
1308 (map (ede-preprocessor-map (if (consp objs)
1309 (car objs)
1310 objs))))
1311 (when map
1312 ;; We can't do a require for the below symbol.
1313 (setq semantic-lex-spp-macro-symbol-obarray
1314 (semantic-lex-make-spp-table map)))
1315 (when (consp objs)
1316 (message "Choosing preprocessor syms for project %s"
1317 (object-name (car objs)))))))
1319 (defmethod ede-system-include-path ((this ede-project))
1320 "Get the system include path used by project THIS."
1321 nil)
1323 (defmethod ede-preprocessor-map ((this ede-project))
1324 "Get the pre-processor map for project THIS."
1325 nil)
1327 (defmethod ede-system-include-path ((this ede-target))
1328 "Get the system include path used by project THIS."
1329 nil)
1331 (defmethod ede-preprocessor-map ((this ede-target))
1332 "Get the pre-processor map for project THIS."
1333 nil)
1336 ;;; Project-local variables
1338 (defun ede-make-project-local-variable (variable &optional project)
1339 "Make VARIABLE project-local to PROJECT."
1340 (if (not project) (setq project (ede-current-project)))
1341 (if (assoc variable (oref project local-variables))
1343 (oset project local-variables (cons (list variable)
1344 (oref project local-variables)))
1345 (dolist (b (ede-project-buffers project))
1346 (with-current-buffer b
1347 (make-local-variable variable)))))
1349 (defmethod ede-set-project-variables ((project ede-project) &optional buffer)
1350 "Set variables local to PROJECT in BUFFER."
1351 (if (not buffer) (setq buffer (current-buffer)))
1352 (with-current-buffer buffer
1353 (dolist (v (oref project local-variables))
1354 (make-local-variable (car v))
1355 ;; set its value here?
1356 (set (car v) (cdr v)))))
1358 (defun ede-set (variable value &optional proj)
1359 "Set the project local VARIABLE to VALUE.
1360 If VARIABLE is not project local, just use set. Optional argument PROJ
1361 is the project to use, instead of `ede-current-project'."
1362 (let ((p (or proj (ede-current-project)))
1364 (if (and p (setq a (assoc variable (oref p local-variables))))
1365 (progn
1366 (setcdr a value)
1367 (dolist (b (ede-project-buffers p))
1368 (with-current-buffer b
1369 (set variable value))))
1370 (set variable value))
1371 (ede-commit-local-variables p))
1372 value)
1374 (defmethod ede-commit-local-variables ((proj ede-project))
1375 "Commit change to local variables in PROJ."
1376 nil)
1378 (provide 'ede)
1380 ;; Include this last because it depends on ede.
1381 (require 'ede/files)
1383 ;; If this does not occur after the provide, we can get a recursive
1384 ;; load. Yuck!
1385 (if (featurep 'speedbar)
1386 (ede-speedbar-file-setup)
1387 (add-hook 'speedbar-load-hook 'ede-speedbar-file-setup))
1389 ;;; ede.el ends here