Add "Version:" and "Package:" Lisp file headers.
[bpt/emacs.git] / lisp / cedet / ede.el
CommitLineData
acc33231
CY
1;;; ede.el --- Emacs Development Environment gloss
2
bd2afec2 3;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
114f9c96 4;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
acc33231
CY
5
6;; Author: Eric M. Ludlam <zappo@gnu.org>
7;; Keywords: project, make
aad4679e 8;; Version: 1.0pre7
acc33231
CY
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software: you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25;;; Commentary:
26;;
27;; EDE is the top level Lisp interface to a project management scheme
28;; for Emacs. Emacs does many things well, including editing,
29;; building, and debugging. Folks migrating from other IDEs don't
30;; seem to think this qualifies, however, because they still have to
31;; write the makefiles, and specify parameters to programs.
32;;
33;; This EDE mode will attempt to link these diverse programs together
34;; into a comprehensive single interface, instead of a bunch of
35;; different ones.
36
37;;; Install
38;;
39;; This command enables project mode on all files.
40;;
41;; (global-ede-mode t)
42
715f35a5 43(require 'cedet)
acc33231
CY
44(require 'eieio)
45(require 'eieio-speedbar)
46(require 'ede/source)
fae4e5b9 47(load "ede/loaddefs" nil 'nomessage)
acc33231
CY
48
49(declare-function ede-convert-path "ede/files")
50(declare-function ede-directory-get-open-project "ede/files")
51(declare-function ede-directory-get-toplevel-open-project "ede/files")
52(declare-function ede-directory-project-p "ede/files")
53(declare-function ede-find-subproject-for-directory "ede/files")
54(declare-function ede-project-directory-remove-hash "ede/files")
55(declare-function ede-project-root "ede/files")
56(declare-function ede-project-root-directory "ede/files")
57(declare-function ede-toplevel "ede/files")
58(declare-function ede-toplevel-project "ede/files")
59(declare-function ede-up-directory "ede/files")
60(declare-function data-debug-new-buffer "data-debug")
61(declare-function data-debug-insert-object-slots "eieio-datadebug")
62(declare-function semantic-lex-make-spp-table "semantic/lex-spp")
63
64(defconst ede-version "1.0pre7"
65 "Current version of the Emacs EDE.")
66
67;;; Code:
68(defun ede-version ()
69 "Display the current running version of EDE."
70 (interactive) (message "EDE %s" ede-version))
71
72(defgroup ede nil
ff90f4b0 73 "Emacs Development Environment."
acc33231 74 :group 'tools
ff90f4b0 75 :group 'extensions)
acc33231
CY
76
77(defcustom ede-auto-add-method 'ask
bd2afec2 78 "Whether a new source file should be automatically added to a target.
acc33231
CY
79Whenever a new file is encountered in a directory controlled by a
80project file, all targets are queried to see if it should be added.
81If the value is 'always, then the new file is added to the first
82target encountered. If the value is 'multi-ask, then if more than one
83target wants the file, the user is asked. If only one target wants
84the file, then then it is automatically added to that target. If the
85value is 'ask, then the user is always asked, unless there is no
86target willing to take the file. 'never means never perform the check."
87 :group 'ede
88 :type '(choice (const always)
89 (const multi-ask)
90 (const ask)
91 (const never)))
92
93(defcustom ede-debug-program-function 'gdb
94 "Default Emacs command used to debug a target."
95 :group 'ede
96 :type 'sexp) ; make this be a list of options some day
97
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.
111This function takes no arguments, and returns the current directories
112root, if available. Leave blank to use the EDE directory walking
113routine instead.")
114 (initializers :initarg :initializers
115 :initform nil
116 :documentation
117 "Initializers passed to the project object.
118These are used so there can be multiple types of projects
119associated 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.
130When more advanced functionality is needed from a project type, that projects
131type 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))
bd2afec2 178 "List of vectors defining how to determine what type of projects exist.")
acc33231
CY
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.
197Relative 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.
214These files are checked for a version string whenever the EDE version
215of the master project is changed. When strings are found, the version
216previously 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.
229This is used to match target objects with the compilers they can use, and
230which 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 )
67d3ffe4
CY
242 [ "Run target" ede-run-target
243 (and ede-object
244 (obj-of-class-p ede-object ede-target)) ]
acc33231
CY
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.
278Projects placeholders will be stored in a user specific location
279and 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.
285For 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.
301This 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.
317This 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.
325For remote locations use a path compatible with ange-ftp or EFS.
326You 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.
334This file can be relative to slot `web-site-directory'.
335This 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.
344This FTP site should be in Emacs form, as needed by `ange-ftp', but can
345also 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.
354This FTP site should be in Emacs form as needed by `ange-ftp'.
355If 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.
363Individual target/project types can form associations between a configuration,
364and 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
67d3ffe4
CY
379 :initform (("D" . ede-debug-target)
380 ("R" . ede-run-target))
acc33231
CY
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.
404All 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.
414If a file is under a project, this specifies the project that is at
415the 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.
420If a file is under a project, this specifies the project that contains the
421current target.")
422(make-variable-buffer-local 'ede-object-project)
423
424(defvar ede-object nil
425 "The current buffer's target object.
426This 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.
431If `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.
438Do 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
0fd9cb9c 443 (locate-user-emacs-file "ede-projects.el" ".projects.ede")
acc33231
CY
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.
549Argument 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
715f35a5 557(defvar ede-minor-mode-map
acc33231
CY
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)
67d3ffe4 572 (define-key pmap "R" 'ede-run-target)
acc33231
CY
573 ;; bind our submap into map
574 (define-key map "\C-c." pmap)
575 map)
576 "Keymap used in project minor mode.")
577
715f35a5
CY
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)
bd2afec2 583 "Keymap used in `global-ede-mode'.")
715f35a5
CY
584
585;; Activate the EDE items in cedet-menu-map
586
587(define-key cedet-menu-map [ede-find-file]
ebf5c4f5
CY
588 '(menu-item "Find File in Project..." ede-find-file :enable ede-object
589 :visible global-ede-mode))
715f35a5 590(define-key cedet-menu-map [ede-speedbar]
ebf5c4f5
CY
591 '(menu-item "View Project Tree" ede-speedbar :enable ede-object
592 :visible global-ede-mode))
715f35a5 593(define-key cedet-menu-map [ede]
ebf5c4f5
CY
594 '(menu-item "Load Project" ede
595 :visible global-ede-mode))
715f35a5
CY
596(define-key cedet-menu-map [ede-new]
597 '(menu-item "Create Project" ede-new
ebf5c4f5
CY
598 :enable (not ede-object)
599 :visible global-ede-mode))
715f35a5
CY
600(define-key cedet-menu-map [ede-target-options]
601 '(menu-item "Target Options" ede-target-options
ebf5c4f5
CY
602 :filter ede-target-forms-menu
603 :visible global-ede-mode))
715f35a5
CY
604(define-key cedet-menu-map [ede-project-options]
605 '(menu-item "Project Options" ede-project-options
ebf5c4f5
CY
606 :filter ede-project-forms-menu
607 :visible global-ede-mode))
715f35a5
CY
608(define-key cedet-menu-map [ede-build-forms-menu]
609 '(menu-item "Build Project" ede-build-forms-menu
610 :filter ede-build-forms-menu
ebf5c4f5
CY
611 :enable ede-object
612 :visible global-ede-mode))
acc33231
CY
613
614(defun ede-menu-obj-of-class-p (class)
615 "Return non-nil if some member of `ede-object' is a child of CLASS."
616 (if (listp ede-object)
b90caf50 617 (eval (cons 'or (mapcar (lambda (o) (obj-of-class-p o class)) ede-object)))
acc33231
CY
618 (obj-of-class-p ede-object class)))
619
620(defun ede-build-forms-menu (menu-def)
621 "Create a sub menu for building different parts of an EDE system.
622Argument MENU-DEF is the menu definition to use."
623 (easy-menu-filter-return
624 (easy-menu-create-menu
625 "Build Forms"
626 (let ((obj (ede-current-project))
627 (newmenu nil) ;'([ "Build Selected..." ede-compile-selected t ]))
628 targets
629 targitems
630 ede-obj
631 (tskip nil))
632 (if (not obj)
633 nil
634 (setq targets (when (slot-boundp obj 'targets)
635 (oref obj targets))
636 ede-obj (if (listp ede-object) ede-object (list ede-object)))
637 ;; First, collect the build items from the project
638 (setq newmenu (append newmenu (ede-menu-items-build obj t)))
639 ;; Second, Declare the current target menu items
640 (if (and ede-obj (ede-menu-obj-of-class-p ede-target))
641 (while ede-obj
642 (setq newmenu (append newmenu
643 (ede-menu-items-build (car ede-obj) t))
644 tskip (car ede-obj)
645 ede-obj (cdr ede-obj))))
646 ;; Third, by name, enable builds for other local targets
647 (while targets
648 (unless (eq tskip (car targets))
649 (setq targitems (ede-menu-items-build (car targets) nil))
650 (setq newmenu
651 (append newmenu
652 (if (= 1 (length targitems))
653 targitems
654 (cons (ede-name (car targets))
655 targitems))))
656 )
657 (setq targets (cdr targets)))
658 ;; Fourth, build sub projects.
659 ;; -- nerp
660 ;; Fifth, Add make distribution
661 (append newmenu (list [ "Make distribution" ede-make-dist t ]))
662 )))))
663
664(defun ede-target-forms-menu (menu-def)
665 "Create a target MENU-DEF based on the object belonging to this buffer."
666 (easy-menu-filter-return
667 (easy-menu-create-menu
668 "Target Forms"
669 (let ((obj (or ede-selected-object ede-object)))
670 (append
e6e267fc
CY
671 '([ "Add File" ede-add-file
672 (and (ede-current-project)
673 (oref (ede-current-project) targets)) ]
acc33231
CY
674 [ "Remove File" ede-remove-file
675 (and ede-object
676 (or (listp ede-object)
677 (not (obj-of-class-p ede-object ede-project)))) ]
678 "-")
679 (if (not obj)
680 nil
681 (if (and (not (listp obj)) (oref obj menu))
682 (oref obj menu)
683 (when (listp obj)
684 ;; This is bad, but I'm not sure what else to do.
685 (oref (car obj) menu)))))))))
686
687(defun ede-project-forms-menu (menu-def)
688 "Create a target MENU-DEF based on the object belonging to this buffer."
689 (easy-menu-filter-return
690 (easy-menu-create-menu
691 "Project Forms"
692 (let* ((obj (ede-current-project))
693 (class (if obj (object-class obj)))
694 (menu nil))
695 (condition-case err
696 (progn
697 (while (and class (slot-exists-p class 'menu))
698 ;;(message "Looking at class %S" class)
699 (setq menu (append menu (oref class menu))
700 class (class-parent class))
701 (if (listp class) (setq class (car class))))
702 (append
703 '( [ "Add Target" ede-new-target (ede-current-project) ]
704 [ "Remove Target" ede-delete-target ede-object ]
705 "-")
706 menu
707 ))
708 (error (message "Err found: %S" err)
709 menu)
710 )))))
711
712(defun ede-customize-forms-menu (menu-def)
713 "Create a menu of the project, and targets that can be customized.
714Argument MENU-DEF is the definition of the current menu."
715 (easy-menu-filter-return
716 (easy-menu-create-menu
717 "Customize Project"
718 (let* ((obj (ede-current-project))
8bf997ef 719 targ)
acc33231 720 (when obj
8bf997ef
CY
721 (setq targ (when (slot-boundp obj 'targets)
722 (oref obj targets)))
acc33231
CY
723 ;; Make custom menus for everything here.
724 (append (list
725 (cons (concat "Project " (ede-name obj))
726 (eieio-customize-object-group obj))
727 [ "Reorder Targets" ede-project-sort-targets t ]
728 )
729 (mapcar (lambda (o)
730 (cons (concat "Target " (ede-name o))
731 (eieio-customize-object-group o)))
732 targ)))))))
733
734
735(defun ede-apply-object-keymap (&optional default)
736 "Add target specific keybindings into the local map.
737Optional argument DEFAULT indicates if this should be set to the default
738version of the keymap."
739 (let ((object (or ede-object ede-selected-object)))
740 (condition-case nil
741 (let ((keys (ede-object-keybindings object)))
742 (while keys
743 (local-set-key (concat "\C-c." (car (car keys)))
744 (cdr (car keys)))
745 (setq keys (cdr keys))))
746 (error nil))))
747
748;;; Menu building methods for building
749;;
750(defmethod ede-menu-items-build ((obj ede-project) &optional current)
751 "Return a list of menu items for building project OBJ.
752If optional argument CURRENT is non-nil, return sub-menu code."
753 (if current
754 (list [ "Build Current Project" ede-compile-project t ])
755 (list (vector
756 (list
757 (concat "Build Project " (ede-name obj))
758 `(project-compile-project ,obj))))))
759
760(defmethod ede-menu-items-build ((obj ede-target) &optional current)
761 "Return a list of menu items for building target OBJ.
762If optional argument CURRENT is non-nil, return sub-menu code."
763 (if current
764 (list [ "Build Current Target" ede-compile-target t ])
765 (list (vector
766 (concat "Build Target " (ede-name obj))
767 `(project-compile-target ,obj)
768 t))))
769\f
770;;; Mode Declarations
771;;
772(eval-and-compile
8bf997ef 773 (autoload 'ede-dired-minor-mode "ede/dired" "EDE commands for dired" t))
acc33231
CY
774
775(defun ede-apply-target-options ()
776 "Apply options to the current buffer for the active project/target."
777 (if (ede-current-project)
778 (ede-set-project-variables (ede-current-project)))
779 (ede-apply-object-keymap)
780 (ede-apply-preprocessor-map)
781 )
782
783(defun ede-turn-on-hook ()
784 "Turn on EDE minor mode in the current buffer if needed.
785To be used in hook functions."
786 (if (or (and (stringp (buffer-file-name))
787 (stringp default-directory))
788 ;; Emacs 21 has no buffer file name for directory edits.
789 ;; so we need to add these hacks in.
790 (eq major-mode 'dired-mode)
791 (eq major-mode 'vc-dired-mode))
792 (ede-minor-mode 1)))
793
715f35a5
CY
794(define-minor-mode ede-minor-mode
795 "Toggle EDE (Emacs Development Environment) minor mode.
796With non-nil argument ARG, enable EDE minor mode if ARG is
797positive; otherwise, disable it.
acc33231 798
715f35a5
CY
799If this file is contained, or could be contained in an EDE
800controlled project, then this mode is activated automatically
801provided `global-ede-mode' is enabled."
802 :group 'ede
803 (cond ((or (eq major-mode 'dired-mode)
804 (eq major-mode 'vc-dired-mode))
805 (ede-dired-minor-mode (if ede-minor-mode 1 -1)))
806 (ede-minor-mode
807 (if (and (not ede-constructing)
808 (ede-directory-project-p default-directory t))
809 (let* ((ROOT nil)
810 (proj (ede-directory-get-open-project default-directory
811 'ROOT)))
812 (when (not proj)
813 ;; @todo - this could be wasteful.
814 (setq proj (ede-load-project-file default-directory 'ROOT)))
815 (setq ede-object-project proj)
816 (setq ede-object-root-project
817 (or ROOT (ede-project-root proj)))
818 (setq ede-object (ede-buffer-object))
819 (if (and (not ede-object) ede-object-project)
820 (ede-auto-add-to-target))
821 (ede-apply-target-options))
822 ;; If we fail to have a project here, turn it back off.
823 (ede-minor-mode -1)))))
acc33231
CY
824
825(defun ede-reset-all-buffers (onoff)
826 "Reset all the buffers due to change in EDE.
827ONOFF indicates enabling or disabling the mode."
828 (let ((b (buffer-list)))
829 (while b
830 (when (buffer-file-name (car b))
831 (ede-buffer-object (car b))
832 )
833 (setq b (cdr b)))))
834
835;;;###autoload
715f35a5
CY
836(define-minor-mode global-ede-mode
837 "Toggle global EDE (Emacs Development Environment) mode.
838With non-nil argument ARG, enable global EDE mode if ARG is
839positive; otherwise, disable it.
840
841This global minor mode enables `ede-minor-mode' in all buffers in
842an EDE controlled project."
843 :global t
844 :group 'ede
845 (if global-ede-mode
846 ;; Turn on global-ede-mode
847 (progn
ebf5c4f5
CY
848 (if semantic-mode
849 (define-key cedet-menu-map [cedet-menu-separator] '("--")))
715f35a5
CY
850 (add-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
851 (add-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
852 (add-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
853 (add-hook 'find-file-hook 'ede-turn-on-hook)
854 (add-hook 'dired-mode-hook 'ede-turn-on-hook)
855 (add-hook 'kill-emacs-hook 'ede-save-cache)
856 (ede-load-cache)
857 (ede-reset-all-buffers 1))
858 ;; Turn off global-ede-mode
ebf5c4f5 859 (define-key cedet-menu-map [cedet-menu-separator] nil)
715f35a5
CY
860 (remove-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
861 (remove-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
862 (remove-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
863 (remove-hook 'find-file-hook 'ede-turn-on-hook)
864 (remove-hook 'dired-mode-hook 'ede-turn-on-hook)
865 (remove-hook 'kill-emacs-hook 'ede-save-cache)
866 (ede-save-cache)
867 (ede-reset-all-buffers -1)))
acc33231
CY
868
869(defvar ede-ignored-file-alist
870 '( "\\.cvsignore$"
871 "\\.#"
872 "~$"
873 )
874 "List of file name patters that EDE will never ask about.")
875
876(defun ede-ignore-file (filename)
877 "Should we ignore FILENAME?"
878 (let ((any nil)
879 (F ede-ignored-file-alist))
880 (while (and (not any) F)
881 (when (string-match (car F) filename)
882 (setq any t))
883 (setq F (cdr F)))
884 any))
885
886(defun ede-auto-add-to-target ()
887 "Look for a target that wants to own the current file.
888Follow the preference set with `ede-auto-add-method' and get the list
889of objects with the `ede-want-file-p' method."
890 (if ede-object (error "Ede-object already defined for %s" (buffer-name)))
891 (if (or (eq ede-auto-add-method 'never)
892 (ede-ignore-file (buffer-file-name)))
893 nil
894 (let (wants desires)
895 ;; Find all the objects.
896 (setq wants (oref (ede-current-project) targets))
897 (while wants
898 (if (ede-want-file-p (car wants) (buffer-file-name))
899 (setq desires (cons (car wants) desires)))
900 (setq wants (cdr wants)))
901 (if desires
902 (cond ((or (eq ede-auto-add-method 'ask)
903 (and (eq ede-auto-add-method 'multi-ask)
904 (< 1 (length desires))))
905 (let* ((al (append
906 ;; some defaults
907 '(("none" . nil)
908 ("new target" . new))
909 ;; If we are in an unparented subdir,
910 ;; offer new a subproject
911 (if (ede-directory-project-p default-directory)
912 ()
913 '(("create subproject" . project)))
914 ;; Here are the existing objects we want.
915 (object-assoc-list 'name desires)))
916 (case-fold-search t)
917 (ans (completing-read
918 (format "Add %s to target: " (buffer-file-name))
919 al nil t)))
920 (setq ans (assoc ans al))
921 (cond ((eieio-object-p (cdr ans))
922 (ede-add-file (cdr ans)))
923 ((eq (cdr ans) 'new)
924 (ede-new-target))
925 (t nil))))
926 ((or (eq ede-auto-add-method 'always)
927 (and (eq ede-auto-add-method 'multi-ask)
928 (= 1 (length desires))))
929 (ede-add-file (car desires)))
930 (t nil))))))
931
932\f
933;;; Interactive method invocations
934;;
935(defun ede (file)
936 "Start up EDE on something.
937Argument FILE is the file or directory to load a project from."
938 (interactive "fProject File: ")
939 (if (not (file-exists-p file))
940 (ede-new file)
941 (ede-load-project-file (file-name-directory file))))
942
943(defun ede-new (type &optional name)
944 "Create a new project starting of project type TYPE.
945Optional argument NAME is the name to give this project."
946 (interactive
947 (list (completing-read "Project Type: "
948 (object-assoc-list
949 'name
950 (let* ((l ede-project-class-files)
951 (cp (ede-current-project))
952 (cs (when cp (object-class cp)))
953 (r nil))
954 (while l
955 (if cs
956 (if (eq (oref (car l) :class-sym)
957 cs)
958 (setq r (cons (car l) r)))
959 (if (oref (car l) new-p)
960 (setq r (cons (car l) r))))
961 (setq l (cdr l)))
962 (when (not r)
963 (if cs
964 (error "No valid interactive sub project types for %s"
965 cs)
966 (error "EDE error: Can't fin project types to create")))
967 r)
968 )
969 nil t)))
970 ;; Make sure we have a valid directory
971 (when (not (file-exists-p default-directory))
bd2afec2 972 (error "Cannot create project in non-existent directory %s" default-directory))
acc33231
CY
973 (when (not (file-writable-p default-directory))
974 (error "No write permissions for %s" default-directory))
975 ;; Create the project
976 (let* ((obj (object-assoc type 'name ede-project-class-files))
977 (nobj (let ((f (oref obj file))
978 (pf (oref obj proj-file)))
979 ;; We are about to make something new, changing the
980 ;; state of existing directories.
981 (ede-project-directory-remove-hash default-directory)
982 ;; Make sure this class gets loaded!
983 (require f)
984 (make-instance (oref obj class-sym)
985 :name (or name (read-string "Name: "))
986 :directory default-directory
987 :file (cond ((stringp pf)
988 (expand-file-name pf))
989 ((fboundp pf)
990 (funcall pf))
991 (t
992 (error
993 "Unknown file name specifier %S"
994 pf)))
995 :targets nil)))
996 (inits (oref obj initializers)))
997 ;; Force the name to match for new objects.
998 (object-set-name-string nobj (oref nobj :name))
999 ;; Handle init args.
1000 (while inits
1001 (eieio-oset nobj (car inits) (car (cdr inits)))
1002 (setq inits (cdr (cdr inits))))
1003 (let ((pp (ede-parent-project)))
1004 (when pp
1005 (ede-add-subproject pp nobj)
1006 (ede-commit-project pp)))
1007 (ede-commit-project nobj))
1008 ;; Have the menu appear
1009 (setq ede-minor-mode t)
1010 ;; Allert the user
1011 (message "Project created and saved. You may now create targets."))
1012
1013(defmethod ede-add-subproject ((proj-a ede-project) proj-b)
1014 "Add into PROJ-A, the subproject PROJ-B."
1015 (oset proj-a subproj (cons proj-b (oref proj-a subproj))))
1016
1017(defmethod ede-subproject-relative-path ((proj ede-project) &optional parent-in)
1018 "Get a path name for PROJ which is relative to the parent project.
1019If PARENT is specified, then be relative to the PARENT project.
1020Specifying PARENT is useful for sub-sub projects relative to the root project."
1021 (let* ((parent (or parent-in (ede-parent-project proj)))
1022 (dir (file-name-directory (oref proj file))))
1023 (if (and parent (not (eq parent proj)))
1024 (file-relative-name dir (file-name-directory (oref parent file)))
1025 "")))
1026
1027(defmethod ede-subproject-p ((proj ede-project))
1028 "Return non-nil if PROJ is a sub project."
1029 (ede-parent-project proj))
1030
1031(defun ede-invoke-method (sym &rest args)
1032 "Invoke method SYM on the current buffer's project object.
1033ARGS are additional arguments to pass to method sym."
1034 (if (not ede-object)
1035 (error "Cannot invoke %s for %s" (symbol-name sym)
1036 (buffer-name)))
1037 ;; Always query a target. There should never be multiple
1038 ;; projects in a single buffer.
1039 (apply sym (ede-singular-object "Target: ") args))
1040
1041(defun ede-rescan-toplevel ()
1042 "Rescan all project files."
1043 (interactive)
1044 (let ((toppath (ede-toplevel-project default-directory))
1045 (ede-deep-rescan t))
1046 (project-rescan (ede-load-project-file toppath))
1047 (ede-reset-all-buffers 1)
1048 ))
1049
1050(defun ede-new-target (&rest args)
1051 "Create a new target specific to this type of project file.
1052Different projects accept different arguments ARGS.
1053Typically you can specify NAME, target TYPE, and AUTOADD, where AUTOADD is
1054a string \"y\" or \"n\", which answers the y/n question done interactively."
1055 (interactive)
1056 (apply 'project-new-target (ede-current-project) args)
1057 (setq ede-object nil)
1058 (setq ede-object (ede-buffer-object (current-buffer)))
1059 (ede-apply-target-options))
1060
1061(defun ede-new-target-custom ()
1062 "Create a new target specific to this type of project file."
1063 (interactive)
1064 (project-new-target-custom (ede-current-project)))
1065
1066(defun ede-delete-target (target)
1067 "Delete TARGET from the current project."
1068 (interactive (list
1069 (let ((ede-object (ede-current-project)))
1070 (ede-invoke-method 'project-interactive-select-target
1071 "Target: "))))
1072 ;; Find all sources in buffers associated with the condemned buffer.
1073 (let ((condemned (ede-target-buffers target)))
1074 (project-delete-target target)
1075 ;; Loop over all project controlled buffers
1076 (save-excursion
1077 (while condemned
1078 (set-buffer (car condemned))
1079 (setq ede-object nil)
1080 (setq ede-object (ede-buffer-object (current-buffer)))
1081 (setq condemned (cdr condemned))))
1082 (ede-apply-target-options)))
1083
1084(defun ede-add-file (target)
1085 "Add the current buffer to a TARGET in the current project."
1086 (interactive (list
1087 (let ((ede-object (ede-current-project)))
1088 (ede-invoke-method 'project-interactive-select-target
1089 "Target: "))))
1090 (when (stringp target)
1091 (let* ((proj (ede-current-project))
1092 (ob (object-assoc-list 'name (oref proj targets))))
1093 (setq target (cdr (assoc target ob)))))
1094
1095 (when (not target)
1096 (error "Could not find specified target %S" target))
1097
1098 (project-add-file target (buffer-file-name))
1099 (setq ede-object nil)
1100 (setq ede-object (ede-buffer-object (current-buffer)))
1101 (when (not ede-object)
1102 (error "Can't add %s to target %s: Wrong file type"
1103 (file-name-nondirectory (buffer-file-name))
1104 (object-name target)))
1105 (ede-apply-target-options))
1106
1107(defun ede-remove-file (&optional force)
1108 "Remove the current file from targets.
1109Optional argument FORCE forces the file to be removed without asking."
1110 (interactive "P")
1111 (if (not ede-object)
1112 (error "Cannot invoke remove-file for %s" (buffer-name)))
1113 (let ((eo (if (listp ede-object)
1114 (prog1
1115 ede-object
1116 (setq force nil))
1117 (list ede-object))))
1118 (while eo
1119 (if (or force (y-or-n-p (format "Remove from %s? " (ede-name (car eo)))))
1120 (project-remove-file (car eo) (buffer-file-name)))
1121 (setq eo (cdr eo)))
1122 (setq ede-object nil)
1123 (setq ede-object (ede-buffer-object (current-buffer)))
1124 (ede-apply-target-options)))
1125
1126(defun ede-edit-file-target ()
1127 "Enter the project file to hand edit the current buffer's target."
1128 (interactive)
1129 (ede-invoke-method 'project-edit-file-target))
1130
1131(defun ede-compile-project ()
1132 "Compile the current project."
1133 (interactive)
1134 ;; @TODO - This just wants the root. There should be a better way.
1135 (let ((cp (ede-current-project)))
1136 (while (ede-parent-project cp)
1137 (setq cp (ede-parent-project cp)))
1138 (let ((ede-object cp))
1139 (ede-invoke-method 'project-compile-project))))
1140
1141(defun ede-compile-selected (target)
1142 "Compile some TARGET from the current project."
1143 (interactive (list (project-interactive-select-target (ede-current-project)
1144 "Target to Build: ")))
1145 (project-compile-target target))
1146
1147(defun ede-compile-target ()
1148 "Compile the current buffer's associated target."
1149 (interactive)
1150 (ede-invoke-method 'project-compile-target))
1151
1152(defun ede-debug-target ()
bd2afec2 1153 "Debug the current buffer's associated target."
acc33231
CY
1154 (interactive)
1155 (ede-invoke-method 'project-debug-target))
1156
67d3ffe4 1157(defun ede-run-target ()
fa5f7c5f 1158 "Run the current buffer's associated target."
67d3ffe4
CY
1159 (interactive)
1160 (ede-invoke-method 'project-run-target))
1161
acc33231
CY
1162(defun ede-make-dist ()
1163 "Create a distribution from the current project."
1164 (interactive)
1165 (let ((ede-object (ede-current-project)))
1166 (ede-invoke-method 'project-make-dist)))
1167
1168;;; Customization
1169;;
1170;; Routines for customizing projects and targets.
1171
1172(defvar eieio-ede-old-variables nil
1173 "The old variables for a project.")
1174
1175(defalias 'customize-project 'ede-customize-project)
1176(defun ede-customize-project (&optional group)
1177 "Edit fields of the current project through EIEIO & Custom.
1178Optional GROUP specifies the subgroup of slots to customize."
1179 (interactive "P")
1180 (require 'eieio-custom)
1181 (let* ((ov (oref (ede-current-project) local-variables))
1182 (cp (ede-current-project))
1183 (group (if group (eieio-read-customization-group cp))))
1184 (eieio-customize-object cp group)
1185 (make-local-variable 'eieio-ede-old-variables)
1186 (setq eieio-ede-old-variables ov)))
1187
1188(defalias 'customize-target 'ede-customize-current-target)
1189(defun ede-customize-current-target(&optional group)
1190 "Edit fields of the current target through EIEIO & Custom.
1191Optional argument OBJ is the target object to customize.
1192Optional argument GROUP is the slot group to display."
1193 (interactive "P")
1194 (require 'eieio-custom)
1195 (if (not (obj-of-class-p ede-object ede-target))
bd2afec2 1196 (error "Current file is not part of a target"))
acc33231
CY
1197 (let ((group (if group (eieio-read-customization-group ede-object))))
1198 (ede-customize-target ede-object group)))
1199
1200(defun ede-customize-target (obj group)
1201 "Edit fields of the current target through EIEIO & Custom.
1202Optional argument OBJ is the target object to customize.
1203Optional argument GROUP is the slot group to display."
1204 (require 'eieio-custom)
1205 (if (and obj (not (obj-of-class-p obj ede-target)))
1206 (error "No logical target to customize"))
1207 (eieio-customize-object obj (or group 'default)))
1208;;; Target Sorting
1209;;
1210;; Target order can be important, but custom doesn't support a way
1211;; to resort items in a list. This function by David Engster allows
1212;; targets to be re-arranged.
1213
1214(defvar ede-project-sort-targets-order nil
1215 "Variable for tracking target order in `ede-project-sort-targets'.")
1216
1217(defun ede-project-sort-targets ()
1218 "Create a custom-like buffer for sorting targets of current project."
1219 (interactive)
1220 (let ((proj (ede-current-project))
1221 (count 1)
1222 current order)
1223 (switch-to-buffer (get-buffer-create "*EDE sort targets*"))
1224 (erase-buffer)
1225 (setq ede-object-project proj)
1226 (widget-create 'push-button
1227 :notify (lambda (&rest ignore)
1228 (let ((targets (oref ede-object-project targets))
1229 cur newtargets)
1230 (while (setq cur (pop ede-project-sort-targets-order))
1231 (setq newtargets (append newtargets
1232 (list (nth cur targets)))))
1233 (oset ede-object-project targets newtargets))
1234 (ede-commit-project ede-object-project)
1235 (kill-buffer))
1236 " Accept ")
1237 (widget-insert " ")
1238 (widget-create 'push-button
1239 :notify (lambda (&rest ignore)
1240 (kill-buffer))
1241 " Cancel ")
1242 (widget-insert "\n\n")
1243 (setq ede-project-sort-targets-order nil)
1244 (mapc (lambda (x)
1245 (add-to-ordered-list
1246 'ede-project-sort-targets-order
1247 x x))
1248 (number-sequence 0 (1- (length (oref proj targets)))))
1249 (ede-project-sort-targets-list)
1250 (use-local-map widget-keymap)
1251 (widget-setup)
1252 (goto-char (point-min))))
1253
1254(defun ede-project-sort-targets-list ()
1255 "Sort the target list while using `ede-project-sort-targets'."
1256 (save-excursion
1257 (let ((count 0)
1258 (targets (oref ede-object-project targets))
1259 (inhibit-read-only t)
1260 (inhibit-modification-hooks t))
1261 (goto-char (point-min))
1262 (forward-line 2)
1263 (delete-region (point) (point-max))
1264 (while (< count (length targets))
1265 (if (> count 0)
1266 (widget-create 'push-button
1267 :notify `(lambda (&rest ignore)
1268 (let ((cur ede-project-sort-targets-order))
1269 (add-to-ordered-list
1270 'ede-project-sort-targets-order
1271 (nth ,count cur)
1272 (1- ,count))
1273 (add-to-ordered-list
1274 'ede-project-sort-targets-order
1275 (nth (1- ,count) cur) ,count))
1276 (ede-project-sort-targets-list))
1277 " Up ")
1278 (widget-insert " "))
1279 (if (< count (1- (length targets)))
1280 (widget-create 'push-button
1281 :notify `(lambda (&rest ignore)
1282 (let ((cur ede-project-sort-targets-order))
1283 (add-to-ordered-list
1284 'ede-project-sort-targets-order
1285 (nth ,count cur) (1+ ,count))
1286 (add-to-ordered-list
1287 'ede-project-sort-targets-order
1288 (nth (1+ ,count) cur) ,count))
1289 (ede-project-sort-targets-list))
1290 " Down ")
1291 (widget-insert " "))
1292 (widget-insert (concat " " (number-to-string (1+ count)) ".: "
1293 (oref (nth (nth count ede-project-sort-targets-order)
1294 targets) name) "\n"))
1295 (setq count (1+ count))))))
1296
1297;;; Customization hooks
1298;;
1299;; These hooks are used when finishing up a customization.
1300(defmethod eieio-done-customizing ((proj ede-project))
1301 "Call this when a user finishes customizing PROJ."
1302 (let ((ov eieio-ede-old-variables)
1303 (nv (oref proj local-variables)))
1304 (setq eieio-ede-old-variables nil)
1305 (while ov
1306 (if (not (assoc (car (car ov)) nv))
1307 (save-excursion
1308 (mapc (lambda (b)
1309 (set-buffer b)
1310 (kill-local-variable (car (car ov))))
1311 (ede-project-buffers proj))))
1312 (setq ov (cdr ov)))
1313 (mapc (lambda (b) (ede-set-project-variables proj b))
1314 (ede-project-buffers proj))))
1315
1316(defmethod eieio-done-customizing ((target ede-target))
1317 "Call this when a user finishes customizing TARGET."
1318 nil)
1319
1320(defmethod ede-commit-project ((proj ede-project))
1321 "Commit any change to PROJ to its file."
1322 nil
1323 )
1324
1325\f
1326;;; EDE project placeholder methods
1327;;
1328(defmethod ede-project-force-load ((this ede-project-placeholder))
1329 "Make sure the placeholder THIS is replaced with the real thing.
1330Return the new object created in its place."
1331 this
1332 )
1333
1334\f
1335;;; EDE project target baseline methods.
1336;;
1337;; If you are developing a new project type, you need to implement
1338;; all of these methods, unless, of course, they do not make sense
1339;; for your particular project.
1340;;
1341;; Your targets should inherit from `ede-target', and your project
1342;; files should inherit from `ede-project'. Create the appropriate
1343;; methods based on those below.
1344
1345(defmethod project-interactive-select-target ((this ede-project-placeholder) prompt)
1346 ; checkdoc-params: (prompt)
1347 "Make sure placeholder THIS is replaced with the real thing, and pass through."
1348 (project-interactive-select-target (ede-project-force-load this) prompt))
1349
1350(defmethod project-interactive-select-target ((this ede-project) prompt)
1351 "Interactively query for a target that exists in project THIS.
1352Argument PROMPT is the prompt to use when querying the user for a target."
1353 (let ((ob (object-assoc-list 'name (oref this targets))))
1354 (cdr (assoc (completing-read prompt ob nil t) ob))))
1355
1356(defmethod project-add-file ((this ede-project-placeholder) file)
1357 ; checkdoc-params: (file)
1358 "Make sure placeholder THIS is replaced with the real thing, and pass through."
1359 (project-add-file (ede-project-force-load this) file))
1360
1361(defmethod project-add-file ((ot ede-target) file)
1362 "Add the current buffer into project project target OT.
1363Argument FILE is the file to add."
1364 (error "add-file not supported by %s" (object-name ot)))
1365
1366(defmethod project-remove-file ((ot ede-target) fnnd)
1367 "Remove the current buffer from project target OT.
1368Argument FNND is an argument."
1369 (error "remove-file not supported by %s" (object-name ot)))
1370
1371(defmethod project-edit-file-target ((ot ede-target))
1372 "Edit the target OT associated w/ this file."
1373 (find-file (oref (ede-current-project) file)))
1374
1375(defmethod project-new-target ((proj ede-project) &rest args)
1376 "Create a new target. It is up to the project PROJ to get the name."
1377 (error "new-target not supported by %s" (object-name proj)))
1378
1379(defmethod project-new-target-custom ((proj ede-project))
1380 "Create a new target. It is up to the project PROJ to get the name."
1381 (error "New-target-custom not supported by %s" (object-name proj)))
1382
1383(defmethod project-delete-target ((ot ede-target))
fa5f7c5f 1384 "Delete the current target OT from its parent project."
acc33231
CY
1385 (error "add-file not supported by %s" (object-name ot)))
1386
1387(defmethod project-compile-project ((obj ede-project) &optional command)
1388 "Compile the entire current project OBJ.
1389Argument COMMAND is the command to use when compiling."
1390 (error "compile-project not supported by %s" (object-name obj)))
1391
1392(defmethod project-compile-target ((obj ede-target) &optional command)
1393 "Compile the current target OBJ.
1394Argument COMMAND is the command to use for compiling the target."
1395 (error "compile-target not supported by %s" (object-name obj)))
1396
1397(defmethod project-debug-target ((obj ede-target))
1398 "Run the current project target OBJ in a debugger."
1399 (error "debug-target not supported by %s" (object-name obj)))
1400
67d3ffe4
CY
1401(defmethod project-run-target ((obj ede-target))
1402 "Run the current project target OBJ."
1403 (error "run-target not supported by %s" (object-name obj)))
1404
acc33231
CY
1405(defmethod project-make-dist ((this ede-project))
1406 "Build a distribution for the project based on THIS project."
1407 (error "Make-dist not supported by %s" (object-name this)))
1408
1409(defmethod project-dist-files ((this ede-project))
fa5f7c5f 1410 "Return a list of files that constitute a distribution of THIS project."
acc33231
CY
1411 (error "Dist-files is not supported by %s" (object-name this)))
1412
1413(defmethod project-rescan ((this ede-project))
1414 "Rescan the EDE proj project THIS."
1415 (error "Rescanning a project is not supported by %s" (object-name this)))
1416\f
1417;;; Default methods for EDE classes
1418;;
1419;; These are methods which you might want to override, but there is
1420;; no need to in most situations because they are either a) simple, or
1421;; b) cosmetic.
1422
1423(defmethod ede-name ((this ede-target))
fa5f7c5f 1424 "Return the name of THIS target."
acc33231
CY
1425 (oref this name))
1426
1427(defmethod ede-target-name ((this ede-target))
1428 "Return the name of THIS target, suitable for make or debug style commands."
1429 (oref this name))
1430
1431(defmethod ede-name ((this ede-project))
1432 "Return a short-name for THIS project file.
1433Do this by extracting the lowest directory name."
1434 (oref this name))
1435
1436(defmethod ede-description ((this ede-project))
1437 "Return a description suitable for the minibuffer about THIS."
1438 (format "Project %s: %d subprojects, %d targets."
1439 (ede-name this) (length (oref this subproj))
1440 (length (oref this targets))))
1441
1442(defmethod ede-description ((this ede-target))
1443 "Return a description suitable for the minibuffer about THIS."
1444 (format "Target %s: with %d source files."
1445 (ede-name this) (length (oref this source))))
1446
1447(defmethod ede-want-file-p ((this ede-target) file)
1448 "Return non-nil if THIS target wants FILE."
1449 ;; By default, all targets reference the source object, and let it decide.
1450 (let ((src (ede-target-sourcecode this)))
1451 (while (and src (not (ede-want-file-p (car src) file)))
1452 (setq src (cdr src)))
1453 src))
1454
1455(defmethod ede-want-file-source-p ((this ede-target) file)
1456 "Return non-nil if THIS target wants FILE."
1457 ;; By default, all targets reference the source object, and let it decide.
1458 (let ((src (ede-target-sourcecode this)))
1459 (while (and src (not (ede-want-file-source-p (car src) file)))
1460 (setq src (cdr src)))
1461 src))
1462
1463(defun ede-header-file ()
1464 "Return the header file for the current buffer.
1465Not all buffers need headers, so return nil if no applicable."
1466 (if ede-object
1467 (ede-buffer-header-file ede-object (current-buffer))
1468 nil))
1469
1470(defmethod ede-buffer-header-file ((this ede-project) buffer)
1471 "Return nil, projects don't have header files."
1472 nil)
1473
1474(defmethod ede-buffer-header-file ((this ede-target) buffer)
1475 "There are no default header files in EDE.
1476Do a quick check to see if there is a Header tag in this buffer."
0816d744 1477 (with-current-buffer buffer
acc33231
CY
1478 (if (re-search-forward "::Header:: \\([a-zA-Z0-9.]+\\)" nil t)
1479 (buffer-substring-no-properties (match-beginning 1)
1480 (match-end 1))
1481 (let ((src (ede-target-sourcecode this))
1482 (found nil))
1483 (while (and src (not found))
1484 (setq found (ede-buffer-header-file (car src) (buffer-file-name))
1485 src (cdr src)))
1486 found))))
1487
1488(defun ede-documentation-files ()
1489 "Return the documentation files for the current buffer.
1490Not all buffers need documentations, so return nil if no applicable.
1491Some projects may have multiple documentation files, so return a list."
1492 (if ede-object
1493 (ede-buffer-documentation-files ede-object (current-buffer))
1494 nil))
1495
1496(defmethod ede-buffer-documentation-files ((this ede-project) buffer)
1497 "Return all documentation in project THIS based on BUFFER."
1498 ;; Find the info node.
1499 (ede-documentation this))
1500
1501(defmethod ede-buffer-documentation-files ((this ede-target) buffer)
1502 "Check for some documentation files for THIS.
1503Also do a quick check to see if there is a Documentation tag in this BUFFER."
0816d744 1504 (with-current-buffer buffer
acc33231
CY
1505 (if (re-search-forward "::Documentation:: \\([a-zA-Z0-9.]+\\)" nil t)
1506 (buffer-substring-no-properties (match-beginning 1)
1507 (match-end 1))
1508 ;; Check the master project
1509 (let ((cp (ede-toplevel)))
1510 (ede-buffer-documentation-files cp (current-buffer))))))
1511
1512(defmethod ede-documentation ((this ede-project))
fa5f7c5f 1513 "Return a list of files that provide documentation.
acc33231
CY
1514Documentation is not for object THIS, but is provided by THIS for other
1515files in the project."
1516 (let ((targ (oref this targets))
1517 (proj (oref this subproj))
1518 (found nil))
1519 (while targ
1520 (setq found (append (ede-documentation (car targ)) found)
1521 targ (cdr targ)))
1522 (while proj
1523 (setq found (append (ede-documentation (car proj)) found)
1524 proj (cdr proj)))
1525 found))
1526
1527(defmethod ede-documentation ((this ede-target))
fa5f7c5f 1528 "Return a list of files that provide documentation.
acc33231
CY
1529Documentation is not for object THIS, but is provided by THIS for other
1530files in the project."
1531 nil)
1532
1533(defun ede-html-documentation-files ()
1534 "Return a list of HTML documentation files associated with this project."
1535 (ede-html-documentation (ede-toplevel))
1536 )
1537
1538(defmethod ede-html-documentation ((this ede-project))
1539 "Return a list of HTML files provided by project THIS."
1540
1541 )
1542
1543(defun ede-ecb-project-paths ()
1544 "Return a list of all paths for all active EDE projects.
1545This functions is meant for use with ECB."
1546 (let ((p ede-projects)
1547 (d nil))
1548 (while p
1549 (setq d (cons (file-name-directory (oref (car p) file))
1550 d)
1551 p (cdr p)))
1552 d))
1553\f
1554;;; EDE project-autoload methods
1555;;
1556(defmethod ede-dir-to-projectfile ((this ede-project-autoload) dir)
1557 "Return a full file name of project THIS found in DIR.
1558Return nil if the project file does not exist."
1559 (let* ((d (file-name-as-directory dir))
1560 (root (ede-project-root-directory this d))
1561 (pf (oref this proj-file))
1562 (f (cond ((stringp pf)
1563 (expand-file-name pf (or root d)))
1564 ((and (symbolp pf) (fboundp pf))
1565 (funcall pf (or root d)))))
1566 )
1567 (when (and f (file-exists-p f))
1568 f)))
1569
1570;;; EDE basic functions
1571;;
1572(defun ede-add-project-to-global-list (proj)
1573 "Add the project PROJ to the master list of projects.
1574On success, return the added project."
1575 (when (not proj)
1576 (error "No project created to add to master list"))
1577 (when (not (eieio-object-p proj))
1578 (error "Attempt to add Non-object to master project list"))
1579 (when (not (obj-of-class-p proj ede-project-placeholder))
1580 (error "Attempt to add a non-project to the ede projects list"))
1581 (add-to-list 'ede-projects proj)
1582 proj)
1583
1584(defun ede-load-project-file (dir &optional rootreturn)
1585 "Project file independent way to read a project in from DIR.
1586Optional ROOTRETURN will return the root project for DIR."
1587 ;; Only load if something new is going on. Flush the dirhash.
1588 (ede-project-directory-remove-hash dir)
1589 ;; Do the load
1590 ;;(message "EDE LOAD : %S" file)
1591 (let* ((file dir)
1592 (path (expand-file-name (file-name-directory file)))
1593 (pfc (ede-directory-project-p path))
1594 (toppath nil)
1595 (o nil))
1596 (cond
1597 ((not pfc)
1598 ;; @TODO - Do we really need to scan? Is this a waste of time?
1599 ;; Scan upward for a the next project file style.
1600 (let ((p path))
1601 (while (and p (not (ede-directory-project-p p)))
1602 (setq p (ede-up-directory p)))
1603 (if p (ede-load-project-file p)
1604 nil)
1605 ;; recomment as we go
1606 ;nil
1607 ))
1608 ;; Do nothing if we are buiding an EDE project already
1609 (ede-constructing
1610 nil)
1611 ;; Load in the project in question.
1612 (t
1613 (setq toppath (ede-toplevel-project path))
1614 ;; We found the top-most directory. Check to see if we already
1615 ;; have an object defining it's project.
1616 (setq pfc (ede-directory-project-p toppath t))
1617
1618 ;; See if it's been loaded before
1619 (setq o (object-assoc (ede-dir-to-projectfile pfc toppath) 'file
1620 ede-projects))
1621 (if (not o)
1622 ;; If not, get it now.
1623 (let ((ede-constructing t))
1624 (setq o (funcall (oref pfc load-type) toppath))
1625 (when (not o)
1626 (error "Project type error: :load-type failed to create a project"))
1627 (ede-add-project-to-global-list o)))
1628
1629 ;; Return the found root project.
1630 (when rootreturn (set rootreturn o))
1631
1632 (let (tocheck found)
1633 ;; Now find the project file belonging to FILE!
1634 (setq tocheck (list o))
1635 (setq file (ede-dir-to-projectfile pfc (expand-file-name path)))
1636 (while (and tocheck (not found))
1637 (let ((newbits nil))
1638 (when (car tocheck)
1639 (if (string= file (oref (car tocheck) file))
1640 (setq found (car tocheck)))
1641 (setq newbits (oref (car tocheck) subproj)))
1642 (setq tocheck
1643 (append (cdr tocheck) newbits))))
1644 (if (not found)
1645 (message "No project for %s, but passes project-p test" file)
1646 ;; Now that the file has been reset inside the project object, do
1647 ;; the cache maintenance.
1648 (setq ede-project-cache-files
1649 (delete (oref found file) ede-project-cache-files)))
1650 found)))))
1651
1652(defun ede-parent-project (&optional obj)
1653 "Return the project belonging to the parent directory.
fa5f7c5f 1654Returns nil if there is no previous directory.
acc33231
CY
1655Optional argument OBJ is an object to find the parent of."
1656 (let* ((proj (or obj ede-object-project)) ;; Current project.
1657 (root (if obj (ede-project-root obj)
1658 ede-object-root-project)))
1659 ;; This case is a SHORTCUT if the project has defined
1660 ;; a way to calculate the project root.
1661 (if (and root proj (eq root proj))
1662 nil ;; we are at the root.
1663 ;; Else, we may have a nil proj or root.
1664 (let* ((thisdir (if obj (oref obj directory)
1665 default-directory))
1666 (updir (ede-up-directory thisdir)))
1667 (when updir
1668 ;; If there was no root, perhaps we can derive it from
1669 ;; updir now.
1670 (let ((root (or root (ede-directory-get-toplevel-open-project updir))))
1671 (or
1672 ;; This lets us find a subproject under root based on updir.
1673 (and root
1674 (ede-find-subproject-for-directory root updir))
1675 ;; Try the all structure based search.
1676 (ede-directory-get-open-project updir)
1677 ;; Load up the project file as a last resort.
1678 ;; Last resort since it uses file-truename, and other
1679 ;; slow features.
1680 (and (ede-directory-project-p updir)
1681 (ede-load-project-file
1682 (file-name-as-directory updir))))))))))
1683
1684(defun ede-current-project (&optional dir)
1685 "Return the current project file.
1686If optional DIR is provided, get the project for DIR instead."
1687 (let ((ans nil))
1688 ;; If it matches the current directory, do we have a pre-existing project?
1689 (when (and (or (not dir) (string= dir default-directory))
1690 ede-object-project)
1691 (setq ans ede-object-project)
1692 )
1693 ;; No current project.
1694 (when (not ans)
1695 (let* ((ldir (or dir default-directory)))
1696 (setq ans (ede-directory-get-open-project ldir))
1697 (or ans
1698 ;; No open project, if this dir pass project-p, then load.
1699 (when (ede-directory-project-p ldir)
1700 (setq ans (ede-load-project-file ldir))))))
1701 ;; Return what we found.
1702 ans))
1703
1704(defun ede-buffer-object (&optional buffer)
1705 "Return the target object for BUFFER.
1706This function clears cached values and recalculates."
1707 (save-excursion
1708 (if (not buffer) (setq buffer (current-buffer)))
1709 (set-buffer buffer)
1710 (setq ede-object nil)
1711 (let ((po (ede-current-project)))
1712 (if po (setq ede-object (ede-find-target po buffer))))
1713 (if (= (length ede-object) 1)
1714 (setq ede-object (car ede-object)))
1715 ede-object))
1716
1717(defmethod ede-target-in-project-p ((proj ede-project) target)
1718 "Is PROJ the parent of TARGET?
1719If TARGET belongs to a subproject, return that project file."
1720 (if (and (slot-boundp proj 'targets)
1721 (memq target (oref proj targets)))
1722 proj
1723 (let ((s (oref proj subproj))
1724 (ans nil))
1725 (while (and s (not ans))
1726 (setq ans (ede-target-in-project-p (car s) target))
1727 (setq s (cdr s)))
1728 ans)))
1729
1730(defun ede-target-parent (target)
1731 "Return the project which is the parent of TARGET.
1732It is recommended you track the project a different way as this function
1733could become slow in time."
1734 ;; @todo - use ede-object-project as a starting point.
1735 (let ((ans nil) (projs ede-projects))
1736 (while (and (not ans) projs)
1737 (setq ans (ede-target-in-project-p (car projs) target)
1738 projs (cdr projs)))
1739 ans))
1740
1741(defun ede-maybe-checkout (&optional buffer)
1742 "Check BUFFER out of VC if necessary."
1743 (save-excursion
1744 (if buffer (set-buffer buffer))
1745 (if (and buffer-read-only vc-mode
1746 (y-or-n-p "Checkout Makefile.am from VC? "))
1747 (vc-toggle-read-only))))
1748
1749(defmethod ede-find-target ((proj ede-project) buffer)
1750 "Fetch the target in PROJ belonging to BUFFER or nil."
0816d744 1751 (with-current-buffer buffer
acc33231
CY
1752 (or ede-object
1753 (if (ede-buffer-mine proj buffer)
1754 proj
1755 (let ((targets (oref proj targets))
1756 (f nil))
1757 (while targets
1758 (if (ede-buffer-mine (car targets) buffer)
1759 (setq f (cons (car targets) f)))
1760 (setq targets (cdr targets)))
1761 f)))))
1762
1763(defmethod ede-target-buffer-in-sourcelist ((this ede-target) buffer source)
1764 "Return non-nil if object THIS is in BUFFER to a SOURCE list.
1765Handles complex path issues."
1766 (member (ede-convert-path this (buffer-file-name buffer)) source))
1767
1768(defmethod ede-buffer-mine ((this ede-project) buffer)
1769 "Return non-nil if object THIS lays claim to the file in BUFFER."
1770 nil)
1771
1772(defmethod ede-buffer-mine ((this ede-target) buffer)
1773 "Return non-nil if object THIS lays claim to the file in BUFFER."
1774 (condition-case nil
1775 (ede-target-buffer-in-sourcelist this buffer (oref this source))
1776 ;; An error implies a bad match.
1777 (error nil)))
1778
1779\f
1780;;; Project mapping
1781;;
1782(defun ede-project-buffers (project)
1783 "Return a list of all active buffers controlled by PROJECT.
1784This includes buffers controlled by a specific target of PROJECT."
1785 (let ((bl (buffer-list))
1786 (pl nil))
1787 (while bl
0816d744 1788 (with-current-buffer (car bl)
acc33231
CY
1789 (if (and ede-object (eq (ede-current-project) project))
1790 (setq pl (cons (car bl) pl))))
1791 (setq bl (cdr bl)))
1792 pl))
1793
1794(defun ede-target-buffers (target)
1795 "Return a list of buffers that are controlled by TARGET."
1796 (let ((bl (buffer-list))
1797 (pl nil))
1798 (while bl
0816d744 1799 (with-current-buffer (car bl)
acc33231
CY
1800 (if (if (listp ede-object)
1801 (memq target ede-object)
1802 (eq ede-object target))
1803 (setq pl (cons (car bl) pl))))
1804 (setq bl (cdr bl)))
1805 pl))
1806
1807(defun ede-buffers ()
bd2afec2 1808 "Return a list of all buffers controlled by an EDE object."
acc33231
CY
1809 (let ((bl (buffer-list))
1810 (pl nil))
1811 (while bl
0816d744 1812 (with-current-buffer (car bl)
acc33231
CY
1813 (if ede-object
1814 (setq pl (cons (car bl) pl))))
1815 (setq bl (cdr bl)))
1816 pl))
1817
1818(defun ede-map-buffers (proc)
bd2afec2 1819 "Execute PROC on all buffers controlled by EDE."
acc33231
CY
1820 (mapcar proc (ede-buffers)))
1821
1822(defmethod ede-map-project-buffers ((this ede-project) proc)
1823 "For THIS, execute PROC on all buffers belonging to THIS."
1824 (mapcar proc (ede-project-buffers this)))
1825
1826(defmethod ede-map-target-buffers ((this ede-target) proc)
1827 "For THIS, execute PROC on all buffers belonging to THIS."
1828 (mapcar proc (ede-target-buffers this)))
1829
1830;; other types of mapping
1831(defmethod ede-map-subprojects ((this ede-project) proc)
1832 "For object THIS, execute PROC on all direct subprojects.
1833This function does not apply PROC to sub-sub projects.
1834See also `ede-map-all-subprojects'."
1835 (mapcar proc (oref this subproj)))
1836
1837(defmethod ede-map-all-subprojects ((this ede-project) allproc)
1838 "For object THIS, execute PROC on THIS and all subprojects.
1839This function also applies PROC to sub-sub projects.
1840See also `ede-map-subprojects'."
1841 (apply 'append
1842 (list (funcall allproc this))
1843 (ede-map-subprojects
1844 this
1845 (lambda (sp)
1846 (ede-map-all-subprojects sp allproc))
1847 )))
1848
1849;; (ede-map-all-subprojects (ede-load-project-file "../semantic/") (lambda (sp) (oref sp file)))
1850
1851(defmethod ede-map-targets ((this ede-project) proc)
1852 "For object THIS, execute PROC on all targets."
1853 (mapcar proc (oref this targets)))
1854
1855(defmethod ede-map-any-target-p ((this ede-project) proc)
1856 "For project THIS, map PROC to all targets and return if any non-nil.
1857Return the first non-nil value returned by PROC."
b90caf50 1858 (eval (cons 'or (ede-map-targets this proc))))
acc33231
CY
1859
1860\f
1861;;; Some language specific methods.
1862;;
1863;; These items are needed by ede-cpp-root to add better support for
1864;; configuring items for Semantic.
1865(defun ede-apply-preprocessor-map ()
1866 "Apply preprocessor tables onto the current buffer."
1867 (when (and ede-object (boundp 'semantic-lex-spp-macro-symbol-obarray))
1dc5c6f3
CY
1868 (let* ((objs ede-object)
1869 (map (ede-preprocessor-map (if (consp objs)
1870 (car objs)
1871 objs))))
acc33231
CY
1872 (when map
1873 ;; We can't do a require for the below symbol.
1874 (setq semantic-lex-spp-macro-symbol-obarray
1dc5c6f3
CY
1875 (semantic-lex-make-spp-table map)))
1876 (when (consp objs)
1877 (message "Choosing preprocessor syms for project %s"
1878 (object-name (car objs)))))))
acc33231
CY
1879
1880(defmethod ede-system-include-path ((this ede-project))
1881 "Get the system include path used by project THIS."
1882 nil)
1883
1884(defmethod ede-preprocessor-map ((this ede-project))
1885 "Get the pre-processor map for project THIS."
1886 nil)
1887
1888(defmethod ede-system-include-path ((this ede-target))
1889 "Get the system include path used by project THIS."
1890 nil)
1891
1892(defmethod ede-preprocessor-map ((this ede-target))
1893 "Get the pre-processor map for project THIS."
1894 nil)
1895
1896\f
1897;;; Project-local variables
1898;;
1899(defun ede-make-project-local-variable (variable &optional project)
1900 "Make VARIABLE project-local to PROJECT."
1901 (if (not project) (setq project (ede-current-project)))
1902 (if (assoc variable (oref project local-variables))
1903 nil
1904 (oset project local-variables (cons (list variable)
1905 (oref project local-variables)))
0816d744
SM
1906 (dolist (b (ede-project-buffers project))
1907 (with-current-buffer b
1908 (make-local-variable variable)))))
acc33231
CY
1909
1910(defmethod ede-set-project-variables ((project ede-project) &optional buffer)
1911 "Set variables local to PROJECT in BUFFER."
1912 (if (not buffer) (setq buffer (current-buffer)))
0816d744
SM
1913 (with-current-buffer buffer
1914 (dolist (v (oref project local-variables))
1915 (make-local-variable (car v))
1916 ;; set it's value here?
1917 (set (car v) (cdr v)))))
acc33231
CY
1918
1919(defun ede-set (variable value &optional proj)
1920 "Set the project local VARIABLE to VALUE.
bd2afec2
GM
1921If VARIABLE is not project local, just use set. Optional argument PROJ
1922is the project to use, instead of `ede-current-project'."
acc33231
CY
1923 (let ((p (or proj (ede-current-project)))
1924 a)
1925 (if (and p (setq a (assoc variable (oref p local-variables))))
1926 (progn
1927 (setcdr a value)
0816d744
SM
1928 (dolist (b (ede-project-buffers p))
1929 (with-current-buffer b
1930 (set variable value))))
acc33231
CY
1931 (set variable value))
1932 (ede-commit-local-variables p))
1933 value)
1934
1935(defmethod ede-commit-local-variables ((proj ede-project))
1936 "Commit change to local variables in PROJ."
1937 nil)
1938
1939\f
1940;;; Accessors for more complex types where oref is inappropriate.
1941;;
1942(defmethod ede-target-sourcecode ((this ede-target))
1943 "Return the sourcecode objects which THIS permits."
1944 (let ((sc (oref this sourcetype))
1945 (rs nil))
1946 (while (and (listp sc) sc)
1947 (setq rs (cons (symbol-value (car sc)) rs)
1948 sc (cdr sc)))
1949 rs))
1950
1951\f
acc33231
CY
1952;;; Debugging.
1953
1954(defun ede-adebug-project ()
fa5f7c5f 1955 "Run adebug against the current EDE project.
acc33231
CY
1956Display the results as a debug list."
1957 (interactive)
1958 (require 'data-debug)
1959 (when (ede-current-project)
1960 (data-debug-new-buffer "*Analyzer ADEBUG*")
1961 (data-debug-insert-object-slots (ede-current-project) "")
1962 ))
1963
1964(defun ede-adebug-project-parent ()
fa5f7c5f 1965 "Run adebug against the current EDE parent project.
acc33231
CY
1966Display the results as a debug list."
1967 (interactive)
1968 (require 'data-debug)
1969 (when (ede-parent-project)
1970 (data-debug-new-buffer "*Analyzer ADEBUG*")
1971 (data-debug-insert-object-slots (ede-parent-project) "")
1972 ))
1973
1974(defun ede-adebug-project-root ()
fa5f7c5f 1975 "Run adebug against the current EDE parent project.
acc33231
CY
1976Display the results as a debug list."
1977 (interactive)
1978 (require 'data-debug)
1979 (when (ede-toplevel)
1980 (data-debug-new-buffer "*Analyzer ADEBUG*")
1981 (data-debug-insert-object-slots (ede-toplevel) "")
1982 ))
1983\f
1984;;; Hooks & Autoloads
1985;;
fa5f7c5f 1986;; These let us watch various activities, and respond appropriately.
acc33231
CY
1987
1988;; (add-hook 'edebug-setup-hook
1989;; (lambda ()
1990;; (def-edebug-spec ede-with-projectfile
1991;; (form def-body))))
1992
acc33231
CY
1993(provide 'ede)
1994
1995;; Include this last because it depends on ede.
1996(require 'ede/files)
1997
1998;; If this does not occur after the provide, we can get a recursive
1999;; load. Yuck!
2000(if (featurep 'speedbar)
2001 (ede-speedbar-file-setup)
2002 (add-hook 'speedbar-load-hook 'ede-speedbar-file-setup))
2003
3999968a 2004;; arch-tag: 0e1e0eba-484f-4119-abdb-30951f725705
acc33231 2005;;; ede.el ends here