3d05202e7aa209f6dc6e716bb7adbb68a8975339
[bpt/emacs.git] / lisp / cedet / ede.el
1 ;;; ede.el --- Emacs Development Environment gloss
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2007, 2008, 2009 Free Software Foundation, Inc.
5
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: project, make
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25 ;;
26 ;; EDE is the top level Lisp interface to a project management scheme
27 ;; for Emacs. Emacs does many things well, including editing,
28 ;; building, and debugging. Folks migrating from other IDEs don't
29 ;; seem to think this qualifies, however, because they still have to
30 ;; write the makefiles, and specify parameters to programs.
31 ;;
32 ;; This EDE mode will attempt to link these diverse programs together
33 ;; into a comprehensive single interface, instead of a bunch of
34 ;; different ones.
35
36 ;;; Install
37 ;;
38 ;; This command enables project mode on all files.
39 ;;
40 ;; (global-ede-mode t)
41
42 (require 'cedet)
43 (require 'eieio)
44 (require 'eieio-speedbar)
45 (require 'ede/source)
46 (require 'ede/loaddefs)
47
48 (declare-function ede-convert-path "ede/files")
49 (declare-function ede-directory-get-open-project "ede/files")
50 (declare-function ede-directory-get-toplevel-open-project "ede/files")
51 (declare-function ede-directory-project-p "ede/files")
52 (declare-function ede-find-subproject-for-directory "ede/files")
53 (declare-function ede-project-directory-remove-hash "ede/files")
54 (declare-function ede-project-root "ede/files")
55 (declare-function ede-project-root-directory "ede/files")
56 (declare-function ede-toplevel "ede/files")
57 (declare-function ede-toplevel-project "ede/files")
58 (declare-function ede-up-directory "ede/files")
59 (declare-function data-debug-new-buffer "data-debug")
60 (declare-function data-debug-insert-object-slots "eieio-datadebug")
61 (declare-function semantic-lex-make-spp-table "semantic/lex-spp")
62
63 (defconst ede-version "1.0pre7"
64 "Current version of the Emacs EDE.")
65
66 ;;; Code:
67 (defun ede-version ()
68 "Display the current running version of EDE."
69 (interactive) (message "EDE %s" ede-version))
70
71 (defgroup ede nil
72 "Emacs Development Environment gloss."
73 :group 'tools
74 :group 'convenience
75 )
76
77 (defcustom ede-auto-add-method 'ask
78 "Whether a new source file should be automatically added to a target.
79 Whenever a new file is encountered in a directory controlled by a
80 project file, all targets are queried to see if it should be added.
81 If the value is 'always, then the new file is added to the first
82 target encountered. If the value is 'multi-ask, then if more than one
83 target wants the file, the user is asked. If only one target wants
84 the file, then then it is automatically added to that target. If the
85 value is 'ask, then the user is always asked, unless there is no
86 target 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
98
99 ;;; Top level classes for projects and targets
100
101 (defclass ede-project-autoload ()
102 ((name :initarg :name
103 :documentation "Name of this project type")
104 (file :initarg :file
105 :documentation "The lisp file belonging to this class.")
106 (proj-file :initarg :proj-file
107 :documentation "Name of a project file of this type.")
108 (proj-root :initarg :proj-root
109 :type function
110 :documentation "A function symbol to call for the project root.
111 This function takes no arguments, and returns the current directories
112 root, if available. Leave blank to use the EDE directory walking
113 routine instead.")
114 (initializers :initarg :initializers
115 :initform nil
116 :documentation
117 "Initializers passed to the project object.
118 These are used so there can be multiple types of projects
119 associated with a single object class, based on the initilizeres used.")
120 (load-type :initarg :load-type
121 :documentation "Fn symbol used to load this project file.")
122 (class-sym :initarg :class-sym
123 :documentation "Symbol representing the project class to use.")
124 (new-p :initarg :new-p
125 :initform t
126 :documentation
127 "Non-nil if this is an option when a user creates a project.")
128 )
129 "Class representing minimal knowledge set to run preliminary EDE functions.
130 When more advanced functionality is needed from a project type, that projects
131 type is required and the load function used.")
132
133 (defvar ede-project-class-files
134 (list
135 (ede-project-autoload "edeproject-makefile"
136 :name "Make" :file 'ede/proj
137 :proj-file "Project.ede"
138 :load-type 'ede-proj-load
139 :class-sym 'ede-proj-project)
140 (ede-project-autoload "edeproject-automake"
141 :name "Automake" :file 'ede/proj
142 :proj-file "Project.ede"
143 :initializers '(:makefile-type Makefile.am)
144 :load-type 'ede-proj-load
145 :class-sym 'ede-proj-project)
146 (ede-project-autoload "automake"
147 :name "automake" :file 'ede/project-am
148 :proj-file "Makefile.am"
149 :load-type 'project-am-load
150 :class-sym 'project-am-makefile
151 :new-p nil)
152 (ede-project-autoload "cpp-root"
153 :name "CPP ROOT" :file 'ede/cpp-root
154 :proj-file 'ede-cpp-root-project-file-for-dir
155 :proj-root 'ede-cpp-root-project-root
156 :load-type 'ede-cpp-root-load
157 :class-sym 'ede-cpp-root
158 :new-p nil)
159 (ede-project-autoload "emacs"
160 :name "EMACS ROOT" :file 'ede/emacs
161 :proj-file "src/emacs.c"
162 :proj-root 'ede-emacs-project-root
163 :load-type 'ede-emacs-load
164 :class-sym 'ede-emacs-project
165 :new-p nil)
166 (ede-project-autoload "linux"
167 :name "LINUX ROOT" :file 'ede/linux
168 :proj-file "scripts/ver_linux"
169 :proj-root 'ede-linux-project-root
170 :load-type 'ede-linux-load
171 :class-sym 'ede-linux-project
172 :new-p nil)
173 (ede-project-autoload "simple-overlay"
174 :name "Simple" :file 'ede/simple
175 :proj-file 'ede-simple-projectfile-for-dir
176 :load-type 'ede-simple-load
177 :class-sym 'ede-simple-project))
178 "List of vectors defining how to determine what type of projects exist.")
179
180 ;;; Generic project information manager objects
181
182 (defclass ede-target (eieio-speedbar-directory-button)
183 ((buttonface :initform speedbar-file-face) ;override for superclass
184 (name :initarg :name
185 :type string
186 :custom string
187 :label "Name"
188 :group (default name)
189 :documentation "Name of this target.")
190 ;; @todo - I think this should be "dir", and not "path".
191 (path :initarg :path
192 :type string
193 ;:custom string
194 ;:label "Path to target"
195 ;:group (default name)
196 :documentation "The path to the sources of this target.
197 Relative to the path of the project it belongs to.")
198 (source :initarg :source
199 :initform nil
200 ;; I'd prefer a list of strings.
201 :type list
202 :custom (repeat (string :tag "File"))
203 :label "Source Files"
204 :group (default source)
205 :documentation "Source files in this target.")
206 (versionsource :initarg :versionsource
207 :initform nil
208 :type list
209 :custom (repeat (string :tag "File"))
210 :label "Source Files with Version String"
211 :group (source)
212 :documentation
213 "Source files with a version string in them.
214 These files are checked for a version string whenever the EDE version
215 of the master project is changed. When strings are found, the version
216 previously there is updated.")
217 ;; Class level slots
218 ;;
219 ; (takes-compile-command :allocation :class
220 ; :initarg :takes-compile-command
221 ; :type boolean
222 ; :initform nil
223 ; :documentation
224 ; "Non-nil if this target requires a user approved command.")
225 (sourcetype :allocation :class
226 :type list ;; list of symbols
227 :documentation
228 "A list of `ede-sourcecode' objects this class will handle.
229 This is used to match target objects with the compilers they can use, and
230 which files this object is interested in."
231 :accessor ede-object-sourcecode)
232 (keybindings :allocation :class
233 :initform (("D" . ede-debug-target))
234 :documentation
235 "Keybindings specialized to this type of target."
236 :accessor ede-object-keybindings)
237 (menu :allocation :class
238 :initform ( [ "Debug target" ede-debug-target
239 (and ede-object
240 (obj-of-class-p ede-object ede-target)) ]
241 )
242 [ "Run target" ede-run-target
243 (and ede-object
244 (obj-of-class-p ede-object ede-target)) ]
245 :documentation "Menu specialized to this type of target."
246 :accessor ede-object-menu)
247 )
248 "A top level target to build.")
249
250 (defclass ede-project-placeholder (eieio-speedbar-directory-button)
251 ((name :initarg :name
252 :initform "Untitled"
253 :type string
254 :custom string
255 :label "Name"
256 :group (default name)
257 :documentation "The name used when generating distribution files.")
258 (version :initarg :version
259 :initform "1.0"
260 :type string
261 :custom string
262 :label "Version"
263 :group (default name)
264 :documentation "The version number used when distributing files.")
265 (directory :type string
266 :initarg :directory
267 :documentation "Directory this project is associated with.")
268 (dirinode :documentation "The inode id for :directory.")
269 (file :type string
270 :initarg :file
271 :documentation "File name where this project is stored.")
272 (rootproject ; :initarg - no initarg, don't save this slot!
273 :initform nil
274 :type (or null ede-project-placeholder-child)
275 :documentation "Pointer to our root project.")
276 )
277 "Placeholder object for projects not loaded into memory.
278 Projects placeholders will be stored in a user specific location
279 and querying them will cause the actual project to get loaded.")
280
281 (defclass ede-project (ede-project-placeholder)
282 ((subproj :initform nil
283 :type list
284 :documentation "Sub projects controlled by this project.
285 For Automake based projects, each directory is treated as a project.")
286 (targets :initarg :targets
287 :type list
288 :custom (repeat (object :objectcreatefcn ede-new-target-custom))
289 :label "Local Targets"
290 :group (targets)
291 :documentation "List of top level targets in this project.")
292 (locate-obj :type (or null ede-locate-base-child)
293 :documentation
294 "A locate object to use as a backup to `ede-expand-filename'.")
295 (tool-cache :initarg :tool-cache
296 :type list
297 :custom (repeat object)
298 :label "Tool: "
299 :group tools
300 :documentation "List of tool cache configurations in this project.
301 This allows any tool to create, manage, and persist project-specific settings.")
302 (mailinglist :initarg :mailinglist
303 :initform ""
304 :type string
305 :custom string
306 :label "Mailing List Address"
307 :group name
308 :documentation
309 "An email address where users might send email for help.")
310 (web-site-url :initarg :web-site-url
311 :initform ""
312 :type string
313 :custom string
314 :label "Web Site URL"
315 :group name
316 :documentation "URL to this projects web site.
317 This is a URL to be sent to a web site for documentation.")
318 (web-site-directory :initarg :web-site-directory
319 :initform ""
320 :custom string
321 :label "Web Page Directory"
322 :group name
323 :documentation
324 "A directory where web pages can be found by Emacs.
325 For remote locations use a path compatible with ange-ftp or EFS.
326 You can also use TRAMP for use with rcp & scp.")
327 (web-site-file :initarg :web-site-file
328 :initform ""
329 :custom string
330 :label "Web Page File"
331 :group name
332 :documentation
333 "A file which contains the home page for this project.
334 This file can be relative to slot `web-site-directory'.
335 This can be a local file, use ange-ftp, EFS, or TRAMP.")
336 (ftp-site :initarg :ftp-site
337 :initform ""
338 :type string
339 :custom string
340 :label "FTP site"
341 :group name
342 :documentation
343 "FTP site where this project's distribution can be found.
344 This FTP site should be in Emacs form, as needed by `ange-ftp', but can
345 also be of a form used by TRAMP for use with scp, or rcp.")
346 (ftp-upload-site :initarg :ftp-upload-site
347 :initform ""
348 :type string
349 :custom string
350 :label "FTP Upload site"
351 :group name
352 :documentation
353 "FTP Site to upload new distributions to.
354 This FTP site should be in Emacs form as needed by `ange-ftp'.
355 If this slot is nil, then use `ftp-site' instead.")
356 (configurations :initarg :configurations
357 :initform ("debug" "release")
358 :type list
359 :custom (repeat string)
360 :label "Configuration Options"
361 :group (settings)
362 :documentation "List of available configuration types.
363 Individual target/project types can form associations between a configuration,
364 and target specific elements such as build variables.")
365 (configuration-default :initarg :configuration-default
366 :initform "debug"
367 :custom string
368 :label "Current Configuration"
369 :group (settings)
370 :documentation "The default configuration.")
371 (local-variables :initarg :local-variables
372 :initform nil
373 :custom (repeat (cons (sexp :tag "Variable")
374 (sexp :tag "Value")))
375 :label "Project Local Variables"
376 :group (settings)
377 :documentation "Project local variables")
378 (keybindings :allocation :class
379 :initform (("D" . ede-debug-target)
380 ("R" . ede-run-target))
381 :documentation "Keybindings specialized to this type of target."
382 :accessor ede-object-keybindings)
383 (menu :allocation :class
384 :initform
385 (
386 [ "Update Version" ede-update-version ede-object ]
387 [ "Version Control Status" ede-vc-project-directory ede-object ]
388 [ "Edit Project Homepage" ede-edit-web-page
389 (and ede-object (oref (ede-toplevel) web-site-file)) ]
390 [ "Browse Project URL" ede-web-browse-home
391 (and ede-object
392 (not (string= "" (oref (ede-toplevel) web-site-url)))) ]
393 "--"
394 [ "Rescan Project Files" ede-rescan-toplevel t ]
395 [ "Edit Projectfile" ede-edit-file-target
396 (and ede-object
397 (or (listp ede-object)
398 (not (obj-of-class-p ede-object ede-project)))) ]
399 )
400 :documentation "Menu specialized to this type of target."
401 :accessor ede-object-menu)
402 )
403 "Top level EDE project specification.
404 All specific project types must derive from this project."
405 :method-invocation-order :depth-first)
406 \f
407 ;;; Management variables
408
409 (defvar ede-projects nil
410 "A list of all active projects currently loaded in Emacs.")
411
412 (defvar ede-object-root-project nil
413 "The current buffer's current root project.
414 If a file is under a project, this specifies the project that is at
415 the root of a project tree.")
416 (make-variable-buffer-local 'ede-object-root-project)
417
418 (defvar ede-object-project nil
419 "The current buffer's current project at that level.
420 If a file is under a project, this specifies the project that contains the
421 current target.")
422 (make-variable-buffer-local 'ede-object-project)
423
424 (defvar ede-object nil
425 "The current buffer's target object.
426 This object's class determines how to compile and debug from a buffer.")
427 (make-variable-buffer-local 'ede-object)
428
429 (defvar ede-selected-object nil
430 "The currently user-selected project or target.
431 If `ede-object' is nil, then commands will operate on this object.")
432
433 (defvar ede-constructing nil
434 "Non nil when constructing a project hierarchy.")
435
436 (defvar ede-deep-rescan nil
437 "Non nil means scan down a tree, otherwise rescans are top level only.
438 Do not set this to non-nil globally. It is used internally.")
439 \f
440 ;;; The EDE persistent cache.
441 ;;
442 (defcustom ede-project-placeholder-cache-file
443 (locate-user-emacs-file "ede-projects.el" ".projects.ede")
444 "File containing the list of projects EDE has viewed."
445 :group 'ede
446 :type 'file)
447
448 (defvar ede-project-cache-files nil
449 "List of project files EDE has seen before.")
450
451 (defun ede-save-cache ()
452 "Save a cache of EDE objects that Emacs has seen before."
453 (interactive)
454 (let ((p ede-projects)
455 (c ede-project-cache-files)
456 (recentf-exclude '(ignore))
457 )
458 (condition-case nil
459 (progn
460 (set-buffer (find-file-noselect ede-project-placeholder-cache-file t))
461 (erase-buffer)
462 (insert ";; EDE project cache file.
463 ;; This contains a list of projects you have visited.\n(")
464 (while p
465 (when (and (car p) (ede-project-p p))
466 (let ((f (oref (car p) file)))
467 (when (file-exists-p f)
468 (insert "\n \"" f "\""))))
469 (setq p (cdr p)))
470 (while c
471 (insert "\n \"" (car c) "\"")
472 (setq c (cdr c)))
473 (insert "\n)\n")
474 (condition-case nil
475 (save-buffer 0)
476 (error
477 (message "File %s could not be saved."
478 ede-project-placeholder-cache-file)))
479 (kill-buffer (current-buffer))
480 )
481 (error
482 (message "File %s could not be read."
483 ede-project-placeholder-cache-file))
484
485 )))
486
487 (defun ede-load-cache ()
488 "Load the cache of EDE projects."
489 (save-excursion
490 (let ((cachebuffer nil))
491 (condition-case nil
492 (progn
493 (setq cachebuffer
494 (find-file-noselect ede-project-placeholder-cache-file t))
495 (set-buffer cachebuffer)
496 (goto-char (point-min))
497 (let ((c (read (current-buffer)))
498 (new nil)
499 (p ede-projects))
500 ;; Remove loaded projects from the cache.
501 (while p
502 (setq c (delete (oref (car p) file) c))
503 (setq p (cdr p)))
504 ;; Remove projects that aren't on the filesystem
505 ;; anymore.
506 (while c
507 (when (file-exists-p (car c))
508 (setq new (cons (car c) new)))
509 (setq c (cdr c)))
510 ;; Save it
511 (setq ede-project-cache-files (nreverse new))))
512 (error nil))
513 (when cachebuffer (kill-buffer cachebuffer))
514 )))
515 \f
516 ;;; Important macros for doing commands.
517 ;;
518 (defmacro ede-with-projectfile (obj &rest forms)
519 "For the project in which OBJ resides, execute FORMS."
520 (list 'save-window-excursion
521 (list 'let* (list
522 (list 'pf
523 (list 'if (list 'obj-of-class-p
524 obj 'ede-target)
525 ;; @todo -I think I can change
526 ;; this to not need ede-load-project-file
527 ;; but I'm not sure how to test well.
528 (list 'ede-load-project-file
529 (list 'oref obj 'path))
530 obj))
531 '(dbka (get-file-buffer (oref pf file))))
532 '(if (not dbka) (find-file (oref pf file))
533 (switch-to-buffer dbka))
534 (cons 'progn forms)
535 '(if (not dbka) (kill-buffer (current-buffer))))))
536 (put 'ede-with-projectfile 'lisp-indent-function 1)
537
538 \f
539 ;;; Prompting
540 ;;
541 (defun ede-singular-object (prompt)
542 "Using PROMPT, choose a single object from the current buffer."
543 (if (listp ede-object)
544 (ede-choose-object prompt ede-object)
545 ede-object))
546
547 (defun ede-choose-object (prompt list-o-o)
548 "Using PROMPT, ask the user which OBJECT to use based on the name field.
549 Argument LIST-O-O is the list of objects to choose from."
550 (let* ((al (object-assoc-list 'name list-o-o))
551 (ans (completing-read prompt al nil t)))
552 (setq ans (assoc ans al))
553 (cdr ans)))
554 \f
555 ;;; Menu and Keymap
556
557 (defvar ede-minor-mode-map
558 (let ((map (make-sparse-keymap))
559 (pmap (make-sparse-keymap)))
560 (define-key pmap "e" 'ede-edit-file-target)
561 (define-key pmap "a" 'ede-add-file)
562 (define-key pmap "d" 'ede-remove-file)
563 (define-key pmap "t" 'ede-new-target)
564 (define-key pmap "g" 'ede-rescan-toplevel)
565 (define-key pmap "s" 'ede-speedbar)
566 (define-key pmap "l" 'ede-load-project-file)
567 (define-key pmap "f" 'ede-find-file)
568 (define-key pmap "C" 'ede-compile-project)
569 (define-key pmap "c" 'ede-compile-target)
570 (define-key pmap "\C-c" 'ede-compile-selected)
571 (define-key pmap "D" 'ede-debug-target)
572 (define-key pmap "R" 'ede-run-target)
573 ;; bind our submap into map
574 (define-key map "\C-c." pmap)
575 map)
576 "Keymap used in project minor mode.")
577
578 (defvar global-ede-mode-map
579 (let ((map (make-sparse-keymap)))
580 (define-key map [menu-bar cedet-menu]
581 (cons "Development" cedet-menu-map))
582 map)
583 "Keymap used in `global-ede-mode'.")
584
585 ;; Activate the EDE items in cedet-menu-map
586
587 (define-key cedet-menu-map [ede-find-file]
588 '(menu-item "Find File in Project..." ede-find-file :enable ede-object))
589 (define-key cedet-menu-map [ede-speedbar]
590 '(menu-item "View Project Tree" ede-speedbar :enable ede-object))
591 (define-key cedet-menu-map [ede]
592 '(menu-item "Load Project" ede))
593 (define-key cedet-menu-map [ede-new]
594 '(menu-item "Create Project" ede-new
595 :enable (not ede-object)))
596 (define-key cedet-menu-map [ede-target-options]
597 '(menu-item "Target Options" ede-target-options
598 :filter ede-target-forms-menu))
599 (define-key cedet-menu-map [ede-project-options]
600 '(menu-item "Project Options" ede-project-options
601 :filter ede-project-forms-menu))
602 (define-key cedet-menu-map [ede-build-forms-menu]
603 '(menu-item "Build Project" ede-build-forms-menu
604 :filter ede-build-forms-menu
605 :enable ede-object))
606 (define-key cedet-menu-map [semantic-menu-separator] 'undefined)
607 (define-key cedet-menu-map [cedet-menu-separator] 'undefined)
608 (define-key cedet-menu-map [ede-menu-separator] '("--"))
609
610 (defun ede-menu-obj-of-class-p (class)
611 "Return non-nil if some member of `ede-object' is a child of CLASS."
612 (if (listp ede-object)
613 (eval (cons 'or (mapcar (lambda (o) (obj-of-class-p o class)) ede-object)))
614 (obj-of-class-p ede-object class)))
615
616 (defun ede-build-forms-menu (menu-def)
617 "Create a sub menu for building different parts of an EDE system.
618 Argument MENU-DEF is the menu definition to use."
619 (easy-menu-filter-return
620 (easy-menu-create-menu
621 "Build Forms"
622 (let ((obj (ede-current-project))
623 (newmenu nil) ;'([ "Build Selected..." ede-compile-selected t ]))
624 targets
625 targitems
626 ede-obj
627 (tskip nil))
628 (if (not obj)
629 nil
630 (setq targets (when (slot-boundp obj 'targets)
631 (oref obj targets))
632 ede-obj (if (listp ede-object) ede-object (list ede-object)))
633 ;; First, collect the build items from the project
634 (setq newmenu (append newmenu (ede-menu-items-build obj t)))
635 ;; Second, Declare the current target menu items
636 (if (and ede-obj (ede-menu-obj-of-class-p ede-target))
637 (while ede-obj
638 (setq newmenu (append newmenu
639 (ede-menu-items-build (car ede-obj) t))
640 tskip (car ede-obj)
641 ede-obj (cdr ede-obj))))
642 ;; Third, by name, enable builds for other local targets
643 (while targets
644 (unless (eq tskip (car targets))
645 (setq targitems (ede-menu-items-build (car targets) nil))
646 (setq newmenu
647 (append newmenu
648 (if (= 1 (length targitems))
649 targitems
650 (cons (ede-name (car targets))
651 targitems))))
652 )
653 (setq targets (cdr targets)))
654 ;; Fourth, build sub projects.
655 ;; -- nerp
656 ;; Fifth, Add make distribution
657 (append newmenu (list [ "Make distribution" ede-make-dist t ]))
658 )))))
659
660 (defun ede-target-forms-menu (menu-def)
661 "Create a target MENU-DEF based on the object belonging to this buffer."
662 (easy-menu-filter-return
663 (easy-menu-create-menu
664 "Target Forms"
665 (let ((obj (or ede-selected-object ede-object)))
666 (append
667 '([ "Add File" ede-add-file
668 (and (ede-current-project)
669 (oref (ede-current-project) targets)) ]
670 [ "Remove File" ede-remove-file
671 (and ede-object
672 (or (listp ede-object)
673 (not (obj-of-class-p ede-object ede-project)))) ]
674 "-")
675 (if (not obj)
676 nil
677 (if (and (not (listp obj)) (oref obj menu))
678 (oref obj menu)
679 (when (listp obj)
680 ;; This is bad, but I'm not sure what else to do.
681 (oref (car obj) menu)))))))))
682
683 (defun ede-project-forms-menu (menu-def)
684 "Create a target MENU-DEF based on the object belonging to this buffer."
685 (easy-menu-filter-return
686 (easy-menu-create-menu
687 "Project Forms"
688 (let* ((obj (ede-current-project))
689 (class (if obj (object-class obj)))
690 (menu nil))
691 (condition-case err
692 (progn
693 (while (and class (slot-exists-p class 'menu))
694 ;;(message "Looking at class %S" class)
695 (setq menu (append menu (oref class menu))
696 class (class-parent class))
697 (if (listp class) (setq class (car class))))
698 (append
699 '( [ "Add Target" ede-new-target (ede-current-project) ]
700 [ "Remove Target" ede-delete-target ede-object ]
701 "-")
702 menu
703 ))
704 (error (message "Err found: %S" err)
705 menu)
706 )))))
707
708 (defun ede-customize-forms-menu (menu-def)
709 "Create a menu of the project, and targets that can be customized.
710 Argument MENU-DEF is the definition of the current menu."
711 (easy-menu-filter-return
712 (easy-menu-create-menu
713 "Customize Project"
714 (let* ((obj (ede-current-project))
715 targ)
716 (when obj
717 (setq targ (when (slot-boundp obj 'targets)
718 (oref obj targets)))
719 ;; Make custom menus for everything here.
720 (append (list
721 (cons (concat "Project " (ede-name obj))
722 (eieio-customize-object-group obj))
723 [ "Reorder Targets" ede-project-sort-targets t ]
724 )
725 (mapcar (lambda (o)
726 (cons (concat "Target " (ede-name o))
727 (eieio-customize-object-group o)))
728 targ)))))))
729
730
731 (defun ede-apply-object-keymap (&optional default)
732 "Add target specific keybindings into the local map.
733 Optional argument DEFAULT indicates if this should be set to the default
734 version of the keymap."
735 (let ((object (or ede-object ede-selected-object)))
736 (condition-case nil
737 (let ((keys (ede-object-keybindings object)))
738 (while keys
739 (local-set-key (concat "\C-c." (car (car keys)))
740 (cdr (car keys)))
741 (setq keys (cdr keys))))
742 (error nil))))
743
744 ;;; Menu building methods for building
745 ;;
746 (defmethod ede-menu-items-build ((obj ede-project) &optional current)
747 "Return a list of menu items for building project OBJ.
748 If optional argument CURRENT is non-nil, return sub-menu code."
749 (if current
750 (list [ "Build Current Project" ede-compile-project t ])
751 (list (vector
752 (list
753 (concat "Build Project " (ede-name obj))
754 `(project-compile-project ,obj))))))
755
756 (defmethod ede-menu-items-build ((obj ede-target) &optional current)
757 "Return a list of menu items for building target OBJ.
758 If optional argument CURRENT is non-nil, return sub-menu code."
759 (if current
760 (list [ "Build Current Target" ede-compile-target t ])
761 (list (vector
762 (concat "Build Target " (ede-name obj))
763 `(project-compile-target ,obj)
764 t))))
765 \f
766 ;;; Mode Declarations
767 ;;
768 (eval-and-compile
769 (autoload 'ede-dired-minor-mode "ede/dired" "EDE commands for dired" t))
770
771 (defun ede-apply-target-options ()
772 "Apply options to the current buffer for the active project/target."
773 (if (ede-current-project)
774 (ede-set-project-variables (ede-current-project)))
775 (ede-apply-object-keymap)
776 (ede-apply-preprocessor-map)
777 )
778
779 (defun ede-turn-on-hook ()
780 "Turn on EDE minor mode in the current buffer if needed.
781 To be used in hook functions."
782 (if (or (and (stringp (buffer-file-name))
783 (stringp default-directory))
784 ;; Emacs 21 has no buffer file name for directory edits.
785 ;; so we need to add these hacks in.
786 (eq major-mode 'dired-mode)
787 (eq major-mode 'vc-dired-mode))
788 (ede-minor-mode 1)))
789
790 (define-minor-mode ede-minor-mode
791 "Toggle EDE (Emacs Development Environment) minor mode.
792 With non-nil argument ARG, enable EDE minor mode if ARG is
793 positive; otherwise, disable it.
794
795 If this file is contained, or could be contained in an EDE
796 controlled project, then this mode is activated automatically
797 provided `global-ede-mode' is enabled."
798 :group 'ede
799 (cond ((or (eq major-mode 'dired-mode)
800 (eq major-mode 'vc-dired-mode))
801 (ede-dired-minor-mode (if ede-minor-mode 1 -1)))
802 (ede-minor-mode
803 (if (and (not ede-constructing)
804 (ede-directory-project-p default-directory t))
805 (let* ((ROOT nil)
806 (proj (ede-directory-get-open-project default-directory
807 'ROOT)))
808 (when (not proj)
809 ;; @todo - this could be wasteful.
810 (setq proj (ede-load-project-file default-directory 'ROOT)))
811 (setq ede-object-project proj)
812 (setq ede-object-root-project
813 (or ROOT (ede-project-root proj)))
814 (setq ede-object (ede-buffer-object))
815 (if (and (not ede-object) ede-object-project)
816 (ede-auto-add-to-target))
817 (ede-apply-target-options))
818 ;; If we fail to have a project here, turn it back off.
819 (ede-minor-mode -1)))))
820
821 (defun ede-reset-all-buffers (onoff)
822 "Reset all the buffers due to change in EDE.
823 ONOFF indicates enabling or disabling the mode."
824 (let ((b (buffer-list)))
825 (while b
826 (when (buffer-file-name (car b))
827 (ede-buffer-object (car b))
828 )
829 (setq b (cdr b)))))
830
831 ;;;###autoload
832 (define-minor-mode global-ede-mode
833 "Toggle global EDE (Emacs Development Environment) mode.
834 With non-nil argument ARG, enable global EDE mode if ARG is
835 positive; otherwise, disable it.
836
837 This global minor mode enables `ede-minor-mode' in all buffers in
838 an EDE controlled project."
839 :global t
840 :group 'ede
841 (if global-ede-mode
842 ;; Turn on global-ede-mode
843 (progn
844 (add-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
845 (add-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
846 (add-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
847 (add-hook 'find-file-hook 'ede-turn-on-hook)
848 (add-hook 'dired-mode-hook 'ede-turn-on-hook)
849 (add-hook 'kill-emacs-hook 'ede-save-cache)
850 (ede-load-cache)
851 (ede-reset-all-buffers 1))
852 ;; Turn off global-ede-mode
853 (remove-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
854 (remove-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
855 (remove-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
856 (remove-hook 'find-file-hook 'ede-turn-on-hook)
857 (remove-hook 'dired-mode-hook 'ede-turn-on-hook)
858 (remove-hook 'kill-emacs-hook 'ede-save-cache)
859 (ede-save-cache)
860 (ede-reset-all-buffers -1)))
861
862 (defvar ede-ignored-file-alist
863 '( "\\.cvsignore$"
864 "\\.#"
865 "~$"
866 )
867 "List of file name patters that EDE will never ask about.")
868
869 (defun ede-ignore-file (filename)
870 "Should we ignore FILENAME?"
871 (let ((any nil)
872 (F ede-ignored-file-alist))
873 (while (and (not any) F)
874 (when (string-match (car F) filename)
875 (setq any t))
876 (setq F (cdr F)))
877 any))
878
879 (defun ede-auto-add-to-target ()
880 "Look for a target that wants to own the current file.
881 Follow the preference set with `ede-auto-add-method' and get the list
882 of objects with the `ede-want-file-p' method."
883 (if ede-object (error "Ede-object already defined for %s" (buffer-name)))
884 (if (or (eq ede-auto-add-method 'never)
885 (ede-ignore-file (buffer-file-name)))
886 nil
887 (let (wants desires)
888 ;; Find all the objects.
889 (setq wants (oref (ede-current-project) targets))
890 (while wants
891 (if (ede-want-file-p (car wants) (buffer-file-name))
892 (setq desires (cons (car wants) desires)))
893 (setq wants (cdr wants)))
894 (if desires
895 (cond ((or (eq ede-auto-add-method 'ask)
896 (and (eq ede-auto-add-method 'multi-ask)
897 (< 1 (length desires))))
898 (let* ((al (append
899 ;; some defaults
900 '(("none" . nil)
901 ("new target" . new))
902 ;; If we are in an unparented subdir,
903 ;; offer new a subproject
904 (if (ede-directory-project-p default-directory)
905 ()
906 '(("create subproject" . project)))
907 ;; Here are the existing objects we want.
908 (object-assoc-list 'name desires)))
909 (case-fold-search t)
910 (ans (completing-read
911 (format "Add %s to target: " (buffer-file-name))
912 al nil t)))
913 (setq ans (assoc ans al))
914 (cond ((eieio-object-p (cdr ans))
915 (ede-add-file (cdr ans)))
916 ((eq (cdr ans) 'new)
917 (ede-new-target))
918 (t nil))))
919 ((or (eq ede-auto-add-method 'always)
920 (and (eq ede-auto-add-method 'multi-ask)
921 (= 1 (length desires))))
922 (ede-add-file (car desires)))
923 (t nil))))))
924
925 \f
926 ;;; Interactive method invocations
927 ;;
928 (defun ede (file)
929 "Start up EDE on something.
930 Argument FILE is the file or directory to load a project from."
931 (interactive "fProject File: ")
932 (if (not (file-exists-p file))
933 (ede-new file)
934 (ede-load-project-file (file-name-directory file))))
935
936 (defun ede-new (type &optional name)
937 "Create a new project starting of project type TYPE.
938 Optional argument NAME is the name to give this project."
939 (interactive
940 (list (completing-read "Project Type: "
941 (object-assoc-list
942 'name
943 (let* ((l ede-project-class-files)
944 (cp (ede-current-project))
945 (cs (when cp (object-class cp)))
946 (r nil))
947 (while l
948 (if cs
949 (if (eq (oref (car l) :class-sym)
950 cs)
951 (setq r (cons (car l) r)))
952 (if (oref (car l) new-p)
953 (setq r (cons (car l) r))))
954 (setq l (cdr l)))
955 (when (not r)
956 (if cs
957 (error "No valid interactive sub project types for %s"
958 cs)
959 (error "EDE error: Can't fin project types to create")))
960 r)
961 )
962 nil t)))
963 ;; Make sure we have a valid directory
964 (when (not (file-exists-p default-directory))
965 (error "Cannot create project in non-existent directory %s" default-directory))
966 (when (not (file-writable-p default-directory))
967 (error "No write permissions for %s" default-directory))
968 ;; Create the project
969 (let* ((obj (object-assoc type 'name ede-project-class-files))
970 (nobj (let ((f (oref obj file))
971 (pf (oref obj proj-file)))
972 ;; We are about to make something new, changing the
973 ;; state of existing directories.
974 (ede-project-directory-remove-hash default-directory)
975 ;; Make sure this class gets loaded!
976 (require f)
977 (make-instance (oref obj class-sym)
978 :name (or name (read-string "Name: "))
979 :directory default-directory
980 :file (cond ((stringp pf)
981 (expand-file-name pf))
982 ((fboundp pf)
983 (funcall pf))
984 (t
985 (error
986 "Unknown file name specifier %S"
987 pf)))
988 :targets nil)))
989 (inits (oref obj initializers)))
990 ;; Force the name to match for new objects.
991 (object-set-name-string nobj (oref nobj :name))
992 ;; Handle init args.
993 (while inits
994 (eieio-oset nobj (car inits) (car (cdr inits)))
995 (setq inits (cdr (cdr inits))))
996 (let ((pp (ede-parent-project)))
997 (when pp
998 (ede-add-subproject pp nobj)
999 (ede-commit-project pp)))
1000 (ede-commit-project nobj))
1001 ;; Have the menu appear
1002 (setq ede-minor-mode t)
1003 ;; Allert the user
1004 (message "Project created and saved. You may now create targets."))
1005
1006 (defmethod ede-add-subproject ((proj-a ede-project) proj-b)
1007 "Add into PROJ-A, the subproject PROJ-B."
1008 (oset proj-a subproj (cons proj-b (oref proj-a subproj))))
1009
1010 (defmethod ede-subproject-relative-path ((proj ede-project) &optional parent-in)
1011 "Get a path name for PROJ which is relative to the parent project.
1012 If PARENT is specified, then be relative to the PARENT project.
1013 Specifying PARENT is useful for sub-sub projects relative to the root project."
1014 (let* ((parent (or parent-in (ede-parent-project proj)))
1015 (dir (file-name-directory (oref proj file))))
1016 (if (and parent (not (eq parent proj)))
1017 (file-relative-name dir (file-name-directory (oref parent file)))
1018 "")))
1019
1020 (defmethod ede-subproject-p ((proj ede-project))
1021 "Return non-nil if PROJ is a sub project."
1022 (ede-parent-project proj))
1023
1024 (defun ede-invoke-method (sym &rest args)
1025 "Invoke method SYM on the current buffer's project object.
1026 ARGS are additional arguments to pass to method sym."
1027 (if (not ede-object)
1028 (error "Cannot invoke %s for %s" (symbol-name sym)
1029 (buffer-name)))
1030 ;; Always query a target. There should never be multiple
1031 ;; projects in a single buffer.
1032 (apply sym (ede-singular-object "Target: ") args))
1033
1034 (defun ede-rescan-toplevel ()
1035 "Rescan all project files."
1036 (interactive)
1037 (let ((toppath (ede-toplevel-project default-directory))
1038 (ede-deep-rescan t))
1039 (project-rescan (ede-load-project-file toppath))
1040 (ede-reset-all-buffers 1)
1041 ))
1042
1043 (defun ede-new-target (&rest args)
1044 "Create a new target specific to this type of project file.
1045 Different projects accept different arguments ARGS.
1046 Typically you can specify NAME, target TYPE, and AUTOADD, where AUTOADD is
1047 a string \"y\" or \"n\", which answers the y/n question done interactively."
1048 (interactive)
1049 (apply 'project-new-target (ede-current-project) args)
1050 (setq ede-object nil)
1051 (setq ede-object (ede-buffer-object (current-buffer)))
1052 (ede-apply-target-options))
1053
1054 (defun ede-new-target-custom ()
1055 "Create a new target specific to this type of project file."
1056 (interactive)
1057 (project-new-target-custom (ede-current-project)))
1058
1059 (defun ede-delete-target (target)
1060 "Delete TARGET from the current project."
1061 (interactive (list
1062 (let ((ede-object (ede-current-project)))
1063 (ede-invoke-method 'project-interactive-select-target
1064 "Target: "))))
1065 ;; Find all sources in buffers associated with the condemned buffer.
1066 (let ((condemned (ede-target-buffers target)))
1067 (project-delete-target target)
1068 ;; Loop over all project controlled buffers
1069 (save-excursion
1070 (while condemned
1071 (set-buffer (car condemned))
1072 (setq ede-object nil)
1073 (setq ede-object (ede-buffer-object (current-buffer)))
1074 (setq condemned (cdr condemned))))
1075 (ede-apply-target-options)))
1076
1077 (defun ede-add-file (target)
1078 "Add the current buffer to a TARGET in the current project."
1079 (interactive (list
1080 (let ((ede-object (ede-current-project)))
1081 (ede-invoke-method 'project-interactive-select-target
1082 "Target: "))))
1083 (when (stringp target)
1084 (let* ((proj (ede-current-project))
1085 (ob (object-assoc-list 'name (oref proj targets))))
1086 (setq target (cdr (assoc target ob)))))
1087
1088 (when (not target)
1089 (error "Could not find specified target %S" target))
1090
1091 (project-add-file target (buffer-file-name))
1092 (setq ede-object nil)
1093 (setq ede-object (ede-buffer-object (current-buffer)))
1094 (when (not ede-object)
1095 (error "Can't add %s to target %s: Wrong file type"
1096 (file-name-nondirectory (buffer-file-name))
1097 (object-name target)))
1098 (ede-apply-target-options))
1099
1100 (defun ede-remove-file (&optional force)
1101 "Remove the current file from targets.
1102 Optional argument FORCE forces the file to be removed without asking."
1103 (interactive "P")
1104 (if (not ede-object)
1105 (error "Cannot invoke remove-file for %s" (buffer-name)))
1106 (let ((eo (if (listp ede-object)
1107 (prog1
1108 ede-object
1109 (setq force nil))
1110 (list ede-object))))
1111 (while eo
1112 (if (or force (y-or-n-p (format "Remove from %s? " (ede-name (car eo)))))
1113 (project-remove-file (car eo) (buffer-file-name)))
1114 (setq eo (cdr eo)))
1115 (setq ede-object nil)
1116 (setq ede-object (ede-buffer-object (current-buffer)))
1117 (ede-apply-target-options)))
1118
1119 (defun ede-edit-file-target ()
1120 "Enter the project file to hand edit the current buffer's target."
1121 (interactive)
1122 (ede-invoke-method 'project-edit-file-target))
1123
1124 (defun ede-compile-project ()
1125 "Compile the current project."
1126 (interactive)
1127 ;; @TODO - This just wants the root. There should be a better way.
1128 (let ((cp (ede-current-project)))
1129 (while (ede-parent-project cp)
1130 (setq cp (ede-parent-project cp)))
1131 (let ((ede-object cp))
1132 (ede-invoke-method 'project-compile-project))))
1133
1134 (defun ede-compile-selected (target)
1135 "Compile some TARGET from the current project."
1136 (interactive (list (project-interactive-select-target (ede-current-project)
1137 "Target to Build: ")))
1138 (project-compile-target target))
1139
1140 (defun ede-compile-target ()
1141 "Compile the current buffer's associated target."
1142 (interactive)
1143 (ede-invoke-method 'project-compile-target))
1144
1145 (defun ede-debug-target ()
1146 "Debug the current buffer's associated target."
1147 (interactive)
1148 (ede-invoke-method 'project-debug-target))
1149
1150 (defun ede-run-target ()
1151 "Debug the current buffer's assocated target."
1152 (interactive)
1153 (ede-invoke-method 'project-run-target))
1154
1155 (defun ede-make-dist ()
1156 "Create a distribution from the current project."
1157 (interactive)
1158 (let ((ede-object (ede-current-project)))
1159 (ede-invoke-method 'project-make-dist)))
1160
1161 ;;; Customization
1162 ;;
1163 ;; Routines for customizing projects and targets.
1164
1165 (defvar eieio-ede-old-variables nil
1166 "The old variables for a project.")
1167
1168 (defalias 'customize-project 'ede-customize-project)
1169 (defun ede-customize-project (&optional group)
1170 "Edit fields of the current project through EIEIO & Custom.
1171 Optional GROUP specifies the subgroup of slots to customize."
1172 (interactive "P")
1173 (require 'eieio-custom)
1174 (let* ((ov (oref (ede-current-project) local-variables))
1175 (cp (ede-current-project))
1176 (group (if group (eieio-read-customization-group cp))))
1177 (eieio-customize-object cp group)
1178 (make-local-variable 'eieio-ede-old-variables)
1179 (setq eieio-ede-old-variables ov)))
1180
1181 (defalias 'customize-target 'ede-customize-current-target)
1182 (defun ede-customize-current-target(&optional group)
1183 "Edit fields of the current target through EIEIO & Custom.
1184 Optional argument OBJ is the target object to customize.
1185 Optional argument GROUP is the slot group to display."
1186 (interactive "P")
1187 (require 'eieio-custom)
1188 (if (not (obj-of-class-p ede-object ede-target))
1189 (error "Current file is not part of a target"))
1190 (let ((group (if group (eieio-read-customization-group ede-object))))
1191 (ede-customize-target ede-object group)))
1192
1193 (defun ede-customize-target (obj group)
1194 "Edit fields of the current target through EIEIO & Custom.
1195 Optional argument OBJ is the target object to customize.
1196 Optional argument GROUP is the slot group to display."
1197 (require 'eieio-custom)
1198 (if (and obj (not (obj-of-class-p obj ede-target)))
1199 (error "No logical target to customize"))
1200 (eieio-customize-object obj (or group 'default)))
1201 ;;; Target Sorting
1202 ;;
1203 ;; Target order can be important, but custom doesn't support a way
1204 ;; to resort items in a list. This function by David Engster allows
1205 ;; targets to be re-arranged.
1206
1207 (defvar ede-project-sort-targets-order nil
1208 "Variable for tracking target order in `ede-project-sort-targets'.")
1209
1210 (defun ede-project-sort-targets ()
1211 "Create a custom-like buffer for sorting targets of current project."
1212 (interactive)
1213 (let ((proj (ede-current-project))
1214 (count 1)
1215 current order)
1216 (switch-to-buffer (get-buffer-create "*EDE sort targets*"))
1217 (erase-buffer)
1218 (setq ede-object-project proj)
1219 (widget-create 'push-button
1220 :notify (lambda (&rest ignore)
1221 (let ((targets (oref ede-object-project targets))
1222 cur newtargets)
1223 (while (setq cur (pop ede-project-sort-targets-order))
1224 (setq newtargets (append newtargets
1225 (list (nth cur targets)))))
1226 (oset ede-object-project targets newtargets))
1227 (ede-commit-project ede-object-project)
1228 (kill-buffer))
1229 " Accept ")
1230 (widget-insert " ")
1231 (widget-create 'push-button
1232 :notify (lambda (&rest ignore)
1233 (kill-buffer))
1234 " Cancel ")
1235 (widget-insert "\n\n")
1236 (setq ede-project-sort-targets-order nil)
1237 (mapc (lambda (x)
1238 (add-to-ordered-list
1239 'ede-project-sort-targets-order
1240 x x))
1241 (number-sequence 0 (1- (length (oref proj targets)))))
1242 (ede-project-sort-targets-list)
1243 (use-local-map widget-keymap)
1244 (widget-setup)
1245 (goto-char (point-min))))
1246
1247 (defun ede-project-sort-targets-list ()
1248 "Sort the target list while using `ede-project-sort-targets'."
1249 (save-excursion
1250 (let ((count 0)
1251 (targets (oref ede-object-project targets))
1252 (inhibit-read-only t)
1253 (inhibit-modification-hooks t))
1254 (goto-char (point-min))
1255 (forward-line 2)
1256 (delete-region (point) (point-max))
1257 (while (< count (length targets))
1258 (if (> count 0)
1259 (widget-create 'push-button
1260 :notify `(lambda (&rest ignore)
1261 (let ((cur ede-project-sort-targets-order))
1262 (add-to-ordered-list
1263 'ede-project-sort-targets-order
1264 (nth ,count cur)
1265 (1- ,count))
1266 (add-to-ordered-list
1267 'ede-project-sort-targets-order
1268 (nth (1- ,count) cur) ,count))
1269 (ede-project-sort-targets-list))
1270 " Up ")
1271 (widget-insert " "))
1272 (if (< count (1- (length targets)))
1273 (widget-create 'push-button
1274 :notify `(lambda (&rest ignore)
1275 (let ((cur ede-project-sort-targets-order))
1276 (add-to-ordered-list
1277 'ede-project-sort-targets-order
1278 (nth ,count cur) (1+ ,count))
1279 (add-to-ordered-list
1280 'ede-project-sort-targets-order
1281 (nth (1+ ,count) cur) ,count))
1282 (ede-project-sort-targets-list))
1283 " Down ")
1284 (widget-insert " "))
1285 (widget-insert (concat " " (number-to-string (1+ count)) ".: "
1286 (oref (nth (nth count ede-project-sort-targets-order)
1287 targets) name) "\n"))
1288 (setq count (1+ count))))))
1289
1290 ;;; Customization hooks
1291 ;;
1292 ;; These hooks are used when finishing up a customization.
1293 (defmethod eieio-done-customizing ((proj ede-project))
1294 "Call this when a user finishes customizing PROJ."
1295 (let ((ov eieio-ede-old-variables)
1296 (nv (oref proj local-variables)))
1297 (setq eieio-ede-old-variables nil)
1298 (while ov
1299 (if (not (assoc (car (car ov)) nv))
1300 (save-excursion
1301 (mapc (lambda (b)
1302 (set-buffer b)
1303 (kill-local-variable (car (car ov))))
1304 (ede-project-buffers proj))))
1305 (setq ov (cdr ov)))
1306 (mapc (lambda (b) (ede-set-project-variables proj b))
1307 (ede-project-buffers proj))))
1308
1309 (defmethod eieio-done-customizing ((target ede-target))
1310 "Call this when a user finishes customizing TARGET."
1311 nil)
1312
1313 (defmethod ede-commit-project ((proj ede-project))
1314 "Commit any change to PROJ to its file."
1315 nil
1316 )
1317
1318 \f
1319 ;;; EDE project placeholder methods
1320 ;;
1321 (defmethod ede-project-force-load ((this ede-project-placeholder))
1322 "Make sure the placeholder THIS is replaced with the real thing.
1323 Return the new object created in its place."
1324 this
1325 )
1326
1327 \f
1328 ;;; EDE project target baseline methods.
1329 ;;
1330 ;; If you are developing a new project type, you need to implement
1331 ;; all of these methods, unless, of course, they do not make sense
1332 ;; for your particular project.
1333 ;;
1334 ;; Your targets should inherit from `ede-target', and your project
1335 ;; files should inherit from `ede-project'. Create the appropriate
1336 ;; methods based on those below.
1337
1338 (defmethod project-interactive-select-target ((this ede-project-placeholder) prompt)
1339 ; checkdoc-params: (prompt)
1340 "Make sure placeholder THIS is replaced with the real thing, and pass through."
1341 (project-interactive-select-target (ede-project-force-load this) prompt))
1342
1343 (defmethod project-interactive-select-target ((this ede-project) prompt)
1344 "Interactively query for a target that exists in project THIS.
1345 Argument PROMPT is the prompt to use when querying the user for a target."
1346 (let ((ob (object-assoc-list 'name (oref this targets))))
1347 (cdr (assoc (completing-read prompt ob nil t) ob))))
1348
1349 (defmethod project-add-file ((this ede-project-placeholder) file)
1350 ; checkdoc-params: (file)
1351 "Make sure placeholder THIS is replaced with the real thing, and pass through."
1352 (project-add-file (ede-project-force-load this) file))
1353
1354 (defmethod project-add-file ((ot ede-target) file)
1355 "Add the current buffer into project project target OT.
1356 Argument FILE is the file to add."
1357 (error "add-file not supported by %s" (object-name ot)))
1358
1359 (defmethod project-remove-file ((ot ede-target) fnnd)
1360 "Remove the current buffer from project target OT.
1361 Argument FNND is an argument."
1362 (error "remove-file not supported by %s" (object-name ot)))
1363
1364 (defmethod project-edit-file-target ((ot ede-target))
1365 "Edit the target OT associated w/ this file."
1366 (find-file (oref (ede-current-project) file)))
1367
1368 (defmethod project-new-target ((proj ede-project) &rest args)
1369 "Create a new target. It is up to the project PROJ to get the name."
1370 (error "new-target not supported by %s" (object-name proj)))
1371
1372 (defmethod project-new-target-custom ((proj ede-project))
1373 "Create a new target. It is up to the project PROJ to get the name."
1374 (error "New-target-custom not supported by %s" (object-name proj)))
1375
1376 (defmethod project-delete-target ((ot ede-target))
1377 "Delete the current target OT from it's parent project."
1378 (error "add-file not supported by %s" (object-name ot)))
1379
1380 (defmethod project-compile-project ((obj ede-project) &optional command)
1381 "Compile the entire current project OBJ.
1382 Argument COMMAND is the command to use when compiling."
1383 (error "compile-project not supported by %s" (object-name obj)))
1384
1385 (defmethod project-compile-target ((obj ede-target) &optional command)
1386 "Compile the current target OBJ.
1387 Argument COMMAND is the command to use for compiling the target."
1388 (error "compile-target not supported by %s" (object-name obj)))
1389
1390 (defmethod project-debug-target ((obj ede-target))
1391 "Run the current project target OBJ in a debugger."
1392 (error "debug-target not supported by %s" (object-name obj)))
1393
1394 (defmethod project-run-target ((obj ede-target))
1395 "Run the current project target OBJ."
1396 (error "run-target not supported by %s" (object-name obj)))
1397
1398 (defmethod project-make-dist ((this ede-project))
1399 "Build a distribution for the project based on THIS project."
1400 (error "Make-dist not supported by %s" (object-name this)))
1401
1402 (defmethod project-dist-files ((this ede-project))
1403 "Return a list of files that constitutes a distribution of THIS project."
1404 (error "Dist-files is not supported by %s" (object-name this)))
1405
1406 (defmethod project-rescan ((this ede-project))
1407 "Rescan the EDE proj project THIS."
1408 (error "Rescanning a project is not supported by %s" (object-name this)))
1409 \f
1410 ;;; Default methods for EDE classes
1411 ;;
1412 ;; These are methods which you might want to override, but there is
1413 ;; no need to in most situations because they are either a) simple, or
1414 ;; b) cosmetic.
1415
1416 (defmethod ede-name ((this ede-target))
1417 "Return the name of THIS targt."
1418 (oref this name))
1419
1420 (defmethod ede-target-name ((this ede-target))
1421 "Return the name of THIS target, suitable for make or debug style commands."
1422 (oref this name))
1423
1424 (defmethod ede-name ((this ede-project))
1425 "Return a short-name for THIS project file.
1426 Do this by extracting the lowest directory name."
1427 (oref this name))
1428
1429 (defmethod ede-description ((this ede-project))
1430 "Return a description suitable for the minibuffer about THIS."
1431 (format "Project %s: %d subprojects, %d targets."
1432 (ede-name this) (length (oref this subproj))
1433 (length (oref this targets))))
1434
1435 (defmethod ede-description ((this ede-target))
1436 "Return a description suitable for the minibuffer about THIS."
1437 (format "Target %s: with %d source files."
1438 (ede-name this) (length (oref this source))))
1439
1440 (defmethod ede-want-file-p ((this ede-target) file)
1441 "Return non-nil if THIS target wants FILE."
1442 ;; By default, all targets reference the source object, and let it decide.
1443 (let ((src (ede-target-sourcecode this)))
1444 (while (and src (not (ede-want-file-p (car src) file)))
1445 (setq src (cdr src)))
1446 src))
1447
1448 (defmethod ede-want-file-source-p ((this ede-target) file)
1449 "Return non-nil if THIS target wants FILE."
1450 ;; By default, all targets reference the source object, and let it decide.
1451 (let ((src (ede-target-sourcecode this)))
1452 (while (and src (not (ede-want-file-source-p (car src) file)))
1453 (setq src (cdr src)))
1454 src))
1455
1456 (defun ede-header-file ()
1457 "Return the header file for the current buffer.
1458 Not all buffers need headers, so return nil if no applicable."
1459 (if ede-object
1460 (ede-buffer-header-file ede-object (current-buffer))
1461 nil))
1462
1463 (defmethod ede-buffer-header-file ((this ede-project) buffer)
1464 "Return nil, projects don't have header files."
1465 nil)
1466
1467 (defmethod ede-buffer-header-file ((this ede-target) buffer)
1468 "There are no default header files in EDE.
1469 Do a quick check to see if there is a Header tag in this buffer."
1470 (save-excursion
1471 (set-buffer buffer)
1472 (if (re-search-forward "::Header:: \\([a-zA-Z0-9.]+\\)" nil t)
1473 (buffer-substring-no-properties (match-beginning 1)
1474 (match-end 1))
1475 (let ((src (ede-target-sourcecode this))
1476 (found nil))
1477 (while (and src (not found))
1478 (setq found (ede-buffer-header-file (car src) (buffer-file-name))
1479 src (cdr src)))
1480 found))))
1481
1482 (defun ede-documentation-files ()
1483 "Return the documentation files for the current buffer.
1484 Not all buffers need documentations, so return nil if no applicable.
1485 Some projects may have multiple documentation files, so return a list."
1486 (if ede-object
1487 (ede-buffer-documentation-files ede-object (current-buffer))
1488 nil))
1489
1490 (defmethod ede-buffer-documentation-files ((this ede-project) buffer)
1491 "Return all documentation in project THIS based on BUFFER."
1492 ;; Find the info node.
1493 (ede-documentation this))
1494
1495 (defmethod ede-buffer-documentation-files ((this ede-target) buffer)
1496 "Check for some documentation files for THIS.
1497 Also do a quick check to see if there is a Documentation tag in this BUFFER."
1498 (save-excursion
1499 (set-buffer buffer)
1500 (if (re-search-forward "::Documentation:: \\([a-zA-Z0-9.]+\\)" nil t)
1501 (buffer-substring-no-properties (match-beginning 1)
1502 (match-end 1))
1503 ;; Check the master project
1504 (let ((cp (ede-toplevel)))
1505 (ede-buffer-documentation-files cp (current-buffer))))))
1506
1507 (defmethod ede-documentation ((this ede-project))
1508 "Return a list of files that provides documentation.
1509 Documentation is not for object THIS, but is provided by THIS for other
1510 files in the project."
1511 (let ((targ (oref this targets))
1512 (proj (oref this subproj))
1513 (found nil))
1514 (while targ
1515 (setq found (append (ede-documentation (car targ)) found)
1516 targ (cdr targ)))
1517 (while proj
1518 (setq found (append (ede-documentation (car proj)) found)
1519 proj (cdr proj)))
1520 found))
1521
1522 (defmethod ede-documentation ((this ede-target))
1523 "Return a list of files that provides documentation.
1524 Documentation is not for object THIS, but is provided by THIS for other
1525 files in the project."
1526 nil)
1527
1528 (defun ede-html-documentation-files ()
1529 "Return a list of HTML documentation files associated with this project."
1530 (ede-html-documentation (ede-toplevel))
1531 )
1532
1533 (defmethod ede-html-documentation ((this ede-project))
1534 "Return a list of HTML files provided by project THIS."
1535
1536 )
1537
1538 (defun ede-ecb-project-paths ()
1539 "Return a list of all paths for all active EDE projects.
1540 This functions is meant for use with ECB."
1541 (let ((p ede-projects)
1542 (d nil))
1543 (while p
1544 (setq d (cons (file-name-directory (oref (car p) file))
1545 d)
1546 p (cdr p)))
1547 d))
1548 \f
1549 ;;; EDE project-autoload methods
1550 ;;
1551 (defmethod ede-dir-to-projectfile ((this ede-project-autoload) dir)
1552 "Return a full file name of project THIS found in DIR.
1553 Return nil if the project file does not exist."
1554 (let* ((d (file-name-as-directory dir))
1555 (root (ede-project-root-directory this d))
1556 (pf (oref this proj-file))
1557 (f (cond ((stringp pf)
1558 (expand-file-name pf (or root d)))
1559 ((and (symbolp pf) (fboundp pf))
1560 (funcall pf (or root d)))))
1561 )
1562 (when (and f (file-exists-p f))
1563 f)))
1564
1565 ;;; EDE basic functions
1566 ;;
1567 (defun ede-add-project-to-global-list (proj)
1568 "Add the project PROJ to the master list of projects.
1569 On success, return the added project."
1570 (when (not proj)
1571 (error "No project created to add to master list"))
1572 (when (not (eieio-object-p proj))
1573 (error "Attempt to add Non-object to master project list"))
1574 (when (not (obj-of-class-p proj ede-project-placeholder))
1575 (error "Attempt to add a non-project to the ede projects list"))
1576 (add-to-list 'ede-projects proj)
1577 proj)
1578
1579 (defun ede-load-project-file (dir &optional rootreturn)
1580 "Project file independent way to read a project in from DIR.
1581 Optional ROOTRETURN will return the root project for DIR."
1582 ;; Only load if something new is going on. Flush the dirhash.
1583 (ede-project-directory-remove-hash dir)
1584 ;; Do the load
1585 ;;(message "EDE LOAD : %S" file)
1586 (let* ((file dir)
1587 (path (expand-file-name (file-name-directory file)))
1588 (pfc (ede-directory-project-p path))
1589 (toppath nil)
1590 (o nil))
1591 (cond
1592 ((not pfc)
1593 ;; @TODO - Do we really need to scan? Is this a waste of time?
1594 ;; Scan upward for a the next project file style.
1595 (let ((p path))
1596 (while (and p (not (ede-directory-project-p p)))
1597 (setq p (ede-up-directory p)))
1598 (if p (ede-load-project-file p)
1599 nil)
1600 ;; recomment as we go
1601 ;nil
1602 ))
1603 ;; Do nothing if we are buiding an EDE project already
1604 (ede-constructing
1605 nil)
1606 ;; Load in the project in question.
1607 (t
1608 (setq toppath (ede-toplevel-project path))
1609 ;; We found the top-most directory. Check to see if we already
1610 ;; have an object defining it's project.
1611 (setq pfc (ede-directory-project-p toppath t))
1612
1613 ;; See if it's been loaded before
1614 (setq o (object-assoc (ede-dir-to-projectfile pfc toppath) 'file
1615 ede-projects))
1616 (if (not o)
1617 ;; If not, get it now.
1618 (let ((ede-constructing t))
1619 (setq o (funcall (oref pfc load-type) toppath))
1620 (when (not o)
1621 (error "Project type error: :load-type failed to create a project"))
1622 (ede-add-project-to-global-list o)))
1623
1624 ;; Return the found root project.
1625 (when rootreturn (set rootreturn o))
1626
1627 (let (tocheck found)
1628 ;; Now find the project file belonging to FILE!
1629 (setq tocheck (list o))
1630 (setq file (ede-dir-to-projectfile pfc (expand-file-name path)))
1631 (while (and tocheck (not found))
1632 (let ((newbits nil))
1633 (when (car tocheck)
1634 (if (string= file (oref (car tocheck) file))
1635 (setq found (car tocheck)))
1636 (setq newbits (oref (car tocheck) subproj)))
1637 (setq tocheck
1638 (append (cdr tocheck) newbits))))
1639 (if (not found)
1640 (message "No project for %s, but passes project-p test" file)
1641 ;; Now that the file has been reset inside the project object, do
1642 ;; the cache maintenance.
1643 (setq ede-project-cache-files
1644 (delete (oref found file) ede-project-cache-files)))
1645 found)))))
1646
1647 (defun ede-parent-project (&optional obj)
1648 "Return the project belonging to the parent directory.
1649 nil if there is no previous directory.
1650 Optional argument OBJ is an object to find the parent of."
1651 (let* ((proj (or obj ede-object-project)) ;; Current project.
1652 (root (if obj (ede-project-root obj)
1653 ede-object-root-project)))
1654 ;; This case is a SHORTCUT if the project has defined
1655 ;; a way to calculate the project root.
1656 (if (and root proj (eq root proj))
1657 nil ;; we are at the root.
1658 ;; Else, we may have a nil proj or root.
1659 (let* ((thisdir (if obj (oref obj directory)
1660 default-directory))
1661 (updir (ede-up-directory thisdir)))
1662 (when updir
1663 ;; If there was no root, perhaps we can derive it from
1664 ;; updir now.
1665 (let ((root (or root (ede-directory-get-toplevel-open-project updir))))
1666 (or
1667 ;; This lets us find a subproject under root based on updir.
1668 (and root
1669 (ede-find-subproject-for-directory root updir))
1670 ;; Try the all structure based search.
1671 (ede-directory-get-open-project updir)
1672 ;; Load up the project file as a last resort.
1673 ;; Last resort since it uses file-truename, and other
1674 ;; slow features.
1675 (and (ede-directory-project-p updir)
1676 (ede-load-project-file
1677 (file-name-as-directory updir))))))))))
1678
1679 (defun ede-current-project (&optional dir)
1680 "Return the current project file.
1681 If optional DIR is provided, get the project for DIR instead."
1682 (let ((ans nil))
1683 ;; If it matches the current directory, do we have a pre-existing project?
1684 (when (and (or (not dir) (string= dir default-directory))
1685 ede-object-project)
1686 (setq ans ede-object-project)
1687 )
1688 ;; No current project.
1689 (when (not ans)
1690 (let* ((ldir (or dir default-directory)))
1691 (setq ans (ede-directory-get-open-project ldir))
1692 (or ans
1693 ;; No open project, if this dir pass project-p, then load.
1694 (when (ede-directory-project-p ldir)
1695 (setq ans (ede-load-project-file ldir))))))
1696 ;; Return what we found.
1697 ans))
1698
1699 (defun ede-buffer-object (&optional buffer)
1700 "Return the target object for BUFFER.
1701 This function clears cached values and recalculates."
1702 (save-excursion
1703 (if (not buffer) (setq buffer (current-buffer)))
1704 (set-buffer buffer)
1705 (setq ede-object nil)
1706 (let ((po (ede-current-project)))
1707 (if po (setq ede-object (ede-find-target po buffer))))
1708 (if (= (length ede-object) 1)
1709 (setq ede-object (car ede-object)))
1710 ede-object))
1711
1712 (defmethod ede-target-in-project-p ((proj ede-project) target)
1713 "Is PROJ the parent of TARGET?
1714 If TARGET belongs to a subproject, return that project file."
1715 (if (and (slot-boundp proj 'targets)
1716 (memq target (oref proj targets)))
1717 proj
1718 (let ((s (oref proj subproj))
1719 (ans nil))
1720 (while (and s (not ans))
1721 (setq ans (ede-target-in-project-p (car s) target))
1722 (setq s (cdr s)))
1723 ans)))
1724
1725 (defun ede-target-parent (target)
1726 "Return the project which is the parent of TARGET.
1727 It is recommended you track the project a different way as this function
1728 could become slow in time."
1729 ;; @todo - use ede-object-project as a starting point.
1730 (let ((ans nil) (projs ede-projects))
1731 (while (and (not ans) projs)
1732 (setq ans (ede-target-in-project-p (car projs) target)
1733 projs (cdr projs)))
1734 ans))
1735
1736 (defun ede-maybe-checkout (&optional buffer)
1737 "Check BUFFER out of VC if necessary."
1738 (save-excursion
1739 (if buffer (set-buffer buffer))
1740 (if (and buffer-read-only vc-mode
1741 (y-or-n-p "Checkout Makefile.am from VC? "))
1742 (vc-toggle-read-only))))
1743
1744 (defmethod ede-find-target ((proj ede-project) buffer)
1745 "Fetch the target in PROJ belonging to BUFFER or nil."
1746 (save-excursion
1747 (set-buffer buffer)
1748 (or ede-object
1749 (if (ede-buffer-mine proj buffer)
1750 proj
1751 (let ((targets (oref proj targets))
1752 (f nil))
1753 (while targets
1754 (if (ede-buffer-mine (car targets) buffer)
1755 (setq f (cons (car targets) f)))
1756 (setq targets (cdr targets)))
1757 f)))))
1758
1759 (defmethod ede-target-buffer-in-sourcelist ((this ede-target) buffer source)
1760 "Return non-nil if object THIS is in BUFFER to a SOURCE list.
1761 Handles complex path issues."
1762 (member (ede-convert-path this (buffer-file-name buffer)) source))
1763
1764 (defmethod ede-buffer-mine ((this ede-project) buffer)
1765 "Return non-nil if object THIS lays claim to the file in BUFFER."
1766 nil)
1767
1768 (defmethod ede-buffer-mine ((this ede-target) buffer)
1769 "Return non-nil if object THIS lays claim to the file in BUFFER."
1770 (condition-case nil
1771 (ede-target-buffer-in-sourcelist this buffer (oref this source))
1772 ;; An error implies a bad match.
1773 (error nil)))
1774
1775 \f
1776 ;;; Project mapping
1777 ;;
1778 (defun ede-project-buffers (project)
1779 "Return a list of all active buffers controlled by PROJECT.
1780 This includes buffers controlled by a specific target of PROJECT."
1781 (let ((bl (buffer-list))
1782 (pl nil))
1783 (while bl
1784 (save-excursion
1785 (set-buffer (car bl))
1786 (if (and ede-object (eq (ede-current-project) project))
1787 (setq pl (cons (car bl) pl))))
1788 (setq bl (cdr bl)))
1789 pl))
1790
1791 (defun ede-target-buffers (target)
1792 "Return a list of buffers that are controlled by TARGET."
1793 (let ((bl (buffer-list))
1794 (pl nil))
1795 (while bl
1796 (save-excursion
1797 (set-buffer (car bl))
1798 (if (if (listp ede-object)
1799 (memq target ede-object)
1800 (eq ede-object target))
1801 (setq pl (cons (car bl) pl))))
1802 (setq bl (cdr bl)))
1803 pl))
1804
1805 (defun ede-buffers ()
1806 "Return a list of all buffers controlled by an EDE object."
1807 (let ((bl (buffer-list))
1808 (pl nil))
1809 (while bl
1810 (save-excursion
1811 (set-buffer (car bl))
1812 (if ede-object
1813 (setq pl (cons (car bl) pl))))
1814 (setq bl (cdr bl)))
1815 pl))
1816
1817 (defun ede-map-buffers (proc)
1818 "Execute PROC on all buffers controlled by EDE."
1819 (mapcar proc (ede-buffers)))
1820
1821 (defmethod ede-map-project-buffers ((this ede-project) proc)
1822 "For THIS, execute PROC on all buffers belonging to THIS."
1823 (mapcar proc (ede-project-buffers this)))
1824
1825 (defmethod ede-map-target-buffers ((this ede-target) proc)
1826 "For THIS, execute PROC on all buffers belonging to THIS."
1827 (mapcar proc (ede-target-buffers this)))
1828
1829 ;; other types of mapping
1830 (defmethod ede-map-subprojects ((this ede-project) proc)
1831 "For object THIS, execute PROC on all direct subprojects.
1832 This function does not apply PROC to sub-sub projects.
1833 See also `ede-map-all-subprojects'."
1834 (mapcar proc (oref this subproj)))
1835
1836 (defmethod ede-map-all-subprojects ((this ede-project) allproc)
1837 "For object THIS, execute PROC on THIS and all subprojects.
1838 This function also applies PROC to sub-sub projects.
1839 See also `ede-map-subprojects'."
1840 (apply 'append
1841 (list (funcall allproc this))
1842 (ede-map-subprojects
1843 this
1844 (lambda (sp)
1845 (ede-map-all-subprojects sp allproc))
1846 )))
1847
1848 ;; (ede-map-all-subprojects (ede-load-project-file "../semantic/") (lambda (sp) (oref sp file)))
1849
1850 (defmethod ede-map-targets ((this ede-project) proc)
1851 "For object THIS, execute PROC on all targets."
1852 (mapcar proc (oref this targets)))
1853
1854 (defmethod ede-map-any-target-p ((this ede-project) proc)
1855 "For project THIS, map PROC to all targets and return if any non-nil.
1856 Return the first non-nil value returned by PROC."
1857 (eval (cons 'or (ede-map-targets this proc))))
1858
1859 \f
1860 ;;; Some language specific methods.
1861 ;;
1862 ;; These items are needed by ede-cpp-root to add better support for
1863 ;; configuring items for Semantic.
1864 (defun ede-apply-preprocessor-map ()
1865 "Apply preprocessor tables onto the current buffer."
1866 (when (and ede-object (boundp 'semantic-lex-spp-macro-symbol-obarray))
1867 (let ((map (ede-preprocessor-map ede-object)))
1868 (when map
1869 ;; We can't do a require for the below symbol.
1870 (setq semantic-lex-spp-macro-symbol-obarray
1871 (semantic-lex-make-spp-table map))
1872 ))))
1873
1874 (defmethod ede-system-include-path ((this ede-project))
1875 "Get the system include path used by project THIS."
1876 nil)
1877
1878 (defmethod ede-preprocessor-map ((this ede-project))
1879 "Get the pre-processor map for project THIS."
1880 nil)
1881
1882 (defmethod ede-system-include-path ((this ede-target))
1883 "Get the system include path used by project THIS."
1884 nil)
1885
1886 (defmethod ede-preprocessor-map ((this ede-target))
1887 "Get the pre-processor map for project THIS."
1888 nil)
1889
1890 \f
1891 ;;; Project-local variables
1892 ;;
1893 (defun ede-make-project-local-variable (variable &optional project)
1894 "Make VARIABLE project-local to PROJECT."
1895 (if (not project) (setq project (ede-current-project)))
1896 (if (assoc variable (oref project local-variables))
1897 nil
1898 (oset project local-variables (cons (list variable)
1899 (oref project local-variables)))
1900 (mapcar (lambda (b) (save-excursion
1901 (set-buffer b)
1902 (make-local-variable variable)))
1903 (ede-project-buffers project))))
1904
1905 (defmethod ede-set-project-variables ((project ede-project) &optional buffer)
1906 "Set variables local to PROJECT in BUFFER."
1907 (if (not buffer) (setq buffer (current-buffer)))
1908 (save-excursion
1909 (set-buffer buffer)
1910 (mapcar (lambda (v)
1911 (make-local-variable (car v))
1912 ;; set it's value here?
1913 (set (car v) (cdr v))
1914 )
1915 (oref project local-variables))))
1916
1917 (defun ede-set (variable value &optional proj)
1918 "Set the project local VARIABLE to VALUE.
1919 If VARIABLE is not project local, just use set. Optional argument PROJ
1920 is the project to use, instead of `ede-current-project'."
1921 (let ((p (or proj (ede-current-project)))
1922 a)
1923 (if (and p (setq a (assoc variable (oref p local-variables))))
1924 (progn
1925 (setcdr a value)
1926 (mapc (lambda (b) (save-excursion
1927 (set-buffer b)
1928 (set variable value)))
1929 (ede-project-buffers p)))
1930 (set variable value))
1931 (ede-commit-local-variables p))
1932 value)
1933
1934 (defmethod ede-commit-local-variables ((proj ede-project))
1935 "Commit change to local variables in PROJ."
1936 nil)
1937
1938 \f
1939 ;;; Accessors for more complex types where oref is inappropriate.
1940 ;;
1941 (defmethod ede-target-sourcecode ((this ede-target))
1942 "Return the sourcecode objects which THIS permits."
1943 (let ((sc (oref this sourcetype))
1944 (rs nil))
1945 (while (and (listp sc) sc)
1946 (setq rs (cons (symbol-value (car sc)) rs)
1947 sc (cdr sc)))
1948 rs))
1949
1950 \f
1951 ;;; Debugging.
1952
1953 (defun ede-adebug-project ()
1954 "Run adebug against the current ede project.
1955 Display the results as a debug list."
1956 (interactive)
1957 (require 'data-debug)
1958 (when (ede-current-project)
1959 (data-debug-new-buffer "*Analyzer ADEBUG*")
1960 (data-debug-insert-object-slots (ede-current-project) "")
1961 ))
1962
1963 (defun ede-adebug-project-parent ()
1964 "Run adebug against the current ede parent project.
1965 Display the results as a debug list."
1966 (interactive)
1967 (require 'data-debug)
1968 (when (ede-parent-project)
1969 (data-debug-new-buffer "*Analyzer ADEBUG*")
1970 (data-debug-insert-object-slots (ede-parent-project) "")
1971 ))
1972
1973 (defun ede-adebug-project-root ()
1974 "Run adebug against the current ede parent project.
1975 Display the results as a debug list."
1976 (interactive)
1977 (require 'data-debug)
1978 (when (ede-toplevel)
1979 (data-debug-new-buffer "*Analyzer ADEBUG*")
1980 (data-debug-insert-object-slots (ede-toplevel) "")
1981 ))
1982 \f
1983 ;;; Hooks & Autoloads
1984 ;;
1985 ;; These let us watch various activities, and respond apropriatly.
1986
1987 ;; (add-hook 'edebug-setup-hook
1988 ;; (lambda ()
1989 ;; (def-edebug-spec ede-with-projectfile
1990 ;; (form def-body))))
1991
1992 (provide 'ede)
1993
1994 ;; Include this last because it depends on ede.
1995 (require 'ede/files)
1996
1997 ;; If this does not occur after the provide, we can get a recursive
1998 ;; load. Yuck!
1999 (if (featurep 'speedbar)
2000 (ede-speedbar-file-setup)
2001 (add-hook 'speedbar-load-hook 'ede-speedbar-file-setup))
2002
2003 ;; arch-tag: 0e1e0eba-484f-4119-abdb-30951f725705
2004 ;;; ede.el ends here