* cedet/srecode/srt-mode.el (semantic-analyze-possible-completions):
[bpt/emacs.git] / lisp / cedet / ede.el
CommitLineData
acc33231
CY
1;;; ede.el --- Emacs Development Environment gloss
2
bd2afec2
GM
3;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4;; 2007, 2008, 2009 Free Software Foundation, Inc.
acc33231
CY
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
715f35a5 42(require 'cedet)
acc33231
CY
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
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]
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] '("--"))
acc33231
CY
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)
b90caf50 613 (eval (cons 'or (mapcar (lambda (o) (obj-of-class-p o class)) ede-object)))
acc33231
CY
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.
618Argument 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
e6e267fc
CY
667 '([ "Add File" ede-add-file
668 (and (ede-current-project)
669 (oref (ede-current-project) targets)) ]
acc33231
CY
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.
710Argument 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))
8bf997ef 715 targ)
acc33231 716 (when obj
8bf997ef
CY
717 (setq targ (when (slot-boundp obj 'targets)
718 (oref obj targets)))
acc33231
CY
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.
733Optional argument DEFAULT indicates if this should be set to the default
734version 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.
748If 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.
758If 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
8bf997ef 769 (autoload 'ede-dired-minor-mode "ede/dired" "EDE commands for dired" t))
acc33231
CY
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.
781To 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
715f35a5
CY
790(define-minor-mode ede-minor-mode
791 "Toggle EDE (Emacs Development Environment) minor mode.
792With non-nil argument ARG, enable EDE minor mode if ARG is
793positive; otherwise, disable it.
acc33231 794
715f35a5
CY
795If this file is contained, or could be contained in an EDE
796controlled project, then this mode is activated automatically
797provided `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)))))
acc33231
CY
820
821(defun ede-reset-all-buffers (onoff)
822 "Reset all the buffers due to change in EDE.
823ONOFF 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
715f35a5
CY
832(define-minor-mode global-ede-mode
833 "Toggle global EDE (Emacs Development Environment) mode.
834With non-nil argument ARG, enable global EDE mode if ARG is
835positive; otherwise, disable it.
836
837This global minor mode enables `ede-minor-mode' in all buffers in
838an 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)))
acc33231
CY
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.
881Follow the preference set with `ede-auto-add-method' and get the list
882of 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.
930Argument 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.
938Optional 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))
bd2afec2 965 (error "Cannot create project in non-existent directory %s" default-directory))
acc33231
CY
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.
1012If PARENT is specified, then be relative to the PARENT project.
1013Specifying 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.
1026ARGS 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.
1045Different projects accept different arguments ARGS.
1046Typically you can specify NAME, target TYPE, and AUTOADD, where AUTOADD is
1047a 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.
1102Optional 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 ()
bd2afec2 1146 "Debug the current buffer's associated target."
acc33231
CY
1147 (interactive)
1148 (ede-invoke-method 'project-debug-target))
1149
67d3ffe4
CY
1150(defun ede-run-target ()
1151 "Debug the current buffer's assocated target."
1152 (interactive)
1153 (ede-invoke-method 'project-run-target))
1154
acc33231
CY
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.
1171Optional 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.
1184Optional argument OBJ is the target object to customize.
1185Optional 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))
bd2afec2 1189 (error "Current file is not part of a target"))
acc33231
CY
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.
1195Optional argument OBJ is the target object to customize.
1196Optional 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.
1323Return 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.
1345Argument 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.
1356Argument 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.
1361Argument 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.
1382Argument 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.
1387Argument 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
67d3ffe4
CY
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
acc33231
CY
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.
1426Do 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.
1458Not 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.
1469Do a quick check to see if there is a Header tag in this buffer."
0816d744 1470 (with-current-buffer buffer
acc33231
CY
1471 (if (re-search-forward "::Header:: \\([a-zA-Z0-9.]+\\)" nil t)
1472 (buffer-substring-no-properties (match-beginning 1)
1473 (match-end 1))
1474 (let ((src (ede-target-sourcecode this))
1475 (found nil))
1476 (while (and src (not found))
1477 (setq found (ede-buffer-header-file (car src) (buffer-file-name))
1478 src (cdr src)))
1479 found))))
1480
1481(defun ede-documentation-files ()
1482 "Return the documentation files for the current buffer.
1483Not all buffers need documentations, so return nil if no applicable.
1484Some projects may have multiple documentation files, so return a list."
1485 (if ede-object
1486 (ede-buffer-documentation-files ede-object (current-buffer))
1487 nil))
1488
1489(defmethod ede-buffer-documentation-files ((this ede-project) buffer)
1490 "Return all documentation in project THIS based on BUFFER."
1491 ;; Find the info node.
1492 (ede-documentation this))
1493
1494(defmethod ede-buffer-documentation-files ((this ede-target) buffer)
1495 "Check for some documentation files for THIS.
1496Also do a quick check to see if there is a Documentation tag in this BUFFER."
0816d744 1497 (with-current-buffer buffer
acc33231
CY
1498 (if (re-search-forward "::Documentation:: \\([a-zA-Z0-9.]+\\)" nil t)
1499 (buffer-substring-no-properties (match-beginning 1)
1500 (match-end 1))
1501 ;; Check the master project
1502 (let ((cp (ede-toplevel)))
1503 (ede-buffer-documentation-files cp (current-buffer))))))
1504
1505(defmethod ede-documentation ((this ede-project))
1506 "Return a list of files that provides documentation.
1507Documentation is not for object THIS, but is provided by THIS for other
1508files in the project."
1509 (let ((targ (oref this targets))
1510 (proj (oref this subproj))
1511 (found nil))
1512 (while targ
1513 (setq found (append (ede-documentation (car targ)) found)
1514 targ (cdr targ)))
1515 (while proj
1516 (setq found (append (ede-documentation (car proj)) found)
1517 proj (cdr proj)))
1518 found))
1519
1520(defmethod ede-documentation ((this ede-target))
1521 "Return a list of files that provides documentation.
1522Documentation is not for object THIS, but is provided by THIS for other
1523files in the project."
1524 nil)
1525
1526(defun ede-html-documentation-files ()
1527 "Return a list of HTML documentation files associated with this project."
1528 (ede-html-documentation (ede-toplevel))
1529 )
1530
1531(defmethod ede-html-documentation ((this ede-project))
1532 "Return a list of HTML files provided by project THIS."
1533
1534 )
1535
1536(defun ede-ecb-project-paths ()
1537 "Return a list of all paths for all active EDE projects.
1538This functions is meant for use with ECB."
1539 (let ((p ede-projects)
1540 (d nil))
1541 (while p
1542 (setq d (cons (file-name-directory (oref (car p) file))
1543 d)
1544 p (cdr p)))
1545 d))
1546\f
1547;;; EDE project-autoload methods
1548;;
1549(defmethod ede-dir-to-projectfile ((this ede-project-autoload) dir)
1550 "Return a full file name of project THIS found in DIR.
1551Return nil if the project file does not exist."
1552 (let* ((d (file-name-as-directory dir))
1553 (root (ede-project-root-directory this d))
1554 (pf (oref this proj-file))
1555 (f (cond ((stringp pf)
1556 (expand-file-name pf (or root d)))
1557 ((and (symbolp pf) (fboundp pf))
1558 (funcall pf (or root d)))))
1559 )
1560 (when (and f (file-exists-p f))
1561 f)))
1562
1563;;; EDE basic functions
1564;;
1565(defun ede-add-project-to-global-list (proj)
1566 "Add the project PROJ to the master list of projects.
1567On success, return the added project."
1568 (when (not proj)
1569 (error "No project created to add to master list"))
1570 (when (not (eieio-object-p proj))
1571 (error "Attempt to add Non-object to master project list"))
1572 (when (not (obj-of-class-p proj ede-project-placeholder))
1573 (error "Attempt to add a non-project to the ede projects list"))
1574 (add-to-list 'ede-projects proj)
1575 proj)
1576
1577(defun ede-load-project-file (dir &optional rootreturn)
1578 "Project file independent way to read a project in from DIR.
1579Optional ROOTRETURN will return the root project for DIR."
1580 ;; Only load if something new is going on. Flush the dirhash.
1581 (ede-project-directory-remove-hash dir)
1582 ;; Do the load
1583 ;;(message "EDE LOAD : %S" file)
1584 (let* ((file dir)
1585 (path (expand-file-name (file-name-directory file)))
1586 (pfc (ede-directory-project-p path))
1587 (toppath nil)
1588 (o nil))
1589 (cond
1590 ((not pfc)
1591 ;; @TODO - Do we really need to scan? Is this a waste of time?
1592 ;; Scan upward for a the next project file style.
1593 (let ((p path))
1594 (while (and p (not (ede-directory-project-p p)))
1595 (setq p (ede-up-directory p)))
1596 (if p (ede-load-project-file p)
1597 nil)
1598 ;; recomment as we go
1599 ;nil
1600 ))
1601 ;; Do nothing if we are buiding an EDE project already
1602 (ede-constructing
1603 nil)
1604 ;; Load in the project in question.
1605 (t
1606 (setq toppath (ede-toplevel-project path))
1607 ;; We found the top-most directory. Check to see if we already
1608 ;; have an object defining it's project.
1609 (setq pfc (ede-directory-project-p toppath t))
1610
1611 ;; See if it's been loaded before
1612 (setq o (object-assoc (ede-dir-to-projectfile pfc toppath) 'file
1613 ede-projects))
1614 (if (not o)
1615 ;; If not, get it now.
1616 (let ((ede-constructing t))
1617 (setq o (funcall (oref pfc load-type) toppath))
1618 (when (not o)
1619 (error "Project type error: :load-type failed to create a project"))
1620 (ede-add-project-to-global-list o)))
1621
1622 ;; Return the found root project.
1623 (when rootreturn (set rootreturn o))
1624
1625 (let (tocheck found)
1626 ;; Now find the project file belonging to FILE!
1627 (setq tocheck (list o))
1628 (setq file (ede-dir-to-projectfile pfc (expand-file-name path)))
1629 (while (and tocheck (not found))
1630 (let ((newbits nil))
1631 (when (car tocheck)
1632 (if (string= file (oref (car tocheck) file))
1633 (setq found (car tocheck)))
1634 (setq newbits (oref (car tocheck) subproj)))
1635 (setq tocheck
1636 (append (cdr tocheck) newbits))))
1637 (if (not found)
1638 (message "No project for %s, but passes project-p test" file)
1639 ;; Now that the file has been reset inside the project object, do
1640 ;; the cache maintenance.
1641 (setq ede-project-cache-files
1642 (delete (oref found file) ede-project-cache-files)))
1643 found)))))
1644
1645(defun ede-parent-project (&optional obj)
1646 "Return the project belonging to the parent directory.
1647nil if there is no previous directory.
1648Optional argument OBJ is an object to find the parent of."
1649 (let* ((proj (or obj ede-object-project)) ;; Current project.
1650 (root (if obj (ede-project-root obj)
1651 ede-object-root-project)))
1652 ;; This case is a SHORTCUT if the project has defined
1653 ;; a way to calculate the project root.
1654 (if (and root proj (eq root proj))
1655 nil ;; we are at the root.
1656 ;; Else, we may have a nil proj or root.
1657 (let* ((thisdir (if obj (oref obj directory)
1658 default-directory))
1659 (updir (ede-up-directory thisdir)))
1660 (when updir
1661 ;; If there was no root, perhaps we can derive it from
1662 ;; updir now.
1663 (let ((root (or root (ede-directory-get-toplevel-open-project updir))))
1664 (or
1665 ;; This lets us find a subproject under root based on updir.
1666 (and root
1667 (ede-find-subproject-for-directory root updir))
1668 ;; Try the all structure based search.
1669 (ede-directory-get-open-project updir)
1670 ;; Load up the project file as a last resort.
1671 ;; Last resort since it uses file-truename, and other
1672 ;; slow features.
1673 (and (ede-directory-project-p updir)
1674 (ede-load-project-file
1675 (file-name-as-directory updir))))))))))
1676
1677(defun ede-current-project (&optional dir)
1678 "Return the current project file.
1679If optional DIR is provided, get the project for DIR instead."
1680 (let ((ans nil))
1681 ;; If it matches the current directory, do we have a pre-existing project?
1682 (when (and (or (not dir) (string= dir default-directory))
1683 ede-object-project)
1684 (setq ans ede-object-project)
1685 )
1686 ;; No current project.
1687 (when (not ans)
1688 (let* ((ldir (or dir default-directory)))
1689 (setq ans (ede-directory-get-open-project ldir))
1690 (or ans
1691 ;; No open project, if this dir pass project-p, then load.
1692 (when (ede-directory-project-p ldir)
1693 (setq ans (ede-load-project-file ldir))))))
1694 ;; Return what we found.
1695 ans))
1696
1697(defun ede-buffer-object (&optional buffer)
1698 "Return the target object for BUFFER.
1699This function clears cached values and recalculates."
1700 (save-excursion
1701 (if (not buffer) (setq buffer (current-buffer)))
1702 (set-buffer buffer)
1703 (setq ede-object nil)
1704 (let ((po (ede-current-project)))
1705 (if po (setq ede-object (ede-find-target po buffer))))
1706 (if (= (length ede-object) 1)
1707 (setq ede-object (car ede-object)))
1708 ede-object))
1709
1710(defmethod ede-target-in-project-p ((proj ede-project) target)
1711 "Is PROJ the parent of TARGET?
1712If TARGET belongs to a subproject, return that project file."
1713 (if (and (slot-boundp proj 'targets)
1714 (memq target (oref proj targets)))
1715 proj
1716 (let ((s (oref proj subproj))
1717 (ans nil))
1718 (while (and s (not ans))
1719 (setq ans (ede-target-in-project-p (car s) target))
1720 (setq s (cdr s)))
1721 ans)))
1722
1723(defun ede-target-parent (target)
1724 "Return the project which is the parent of TARGET.
1725It is recommended you track the project a different way as this function
1726could become slow in time."
1727 ;; @todo - use ede-object-project as a starting point.
1728 (let ((ans nil) (projs ede-projects))
1729 (while (and (not ans) projs)
1730 (setq ans (ede-target-in-project-p (car projs) target)
1731 projs (cdr projs)))
1732 ans))
1733
1734(defun ede-maybe-checkout (&optional buffer)
1735 "Check BUFFER out of VC if necessary."
1736 (save-excursion
1737 (if buffer (set-buffer buffer))
1738 (if (and buffer-read-only vc-mode
1739 (y-or-n-p "Checkout Makefile.am from VC? "))
1740 (vc-toggle-read-only))))
1741
1742(defmethod ede-find-target ((proj ede-project) buffer)
1743 "Fetch the target in PROJ belonging to BUFFER or nil."
0816d744 1744 (with-current-buffer buffer
acc33231
CY
1745 (or ede-object
1746 (if (ede-buffer-mine proj buffer)
1747 proj
1748 (let ((targets (oref proj targets))
1749 (f nil))
1750 (while targets
1751 (if (ede-buffer-mine (car targets) buffer)
1752 (setq f (cons (car targets) f)))
1753 (setq targets (cdr targets)))
1754 f)))))
1755
1756(defmethod ede-target-buffer-in-sourcelist ((this ede-target) buffer source)
1757 "Return non-nil if object THIS is in BUFFER to a SOURCE list.
1758Handles complex path issues."
1759 (member (ede-convert-path this (buffer-file-name buffer)) source))
1760
1761(defmethod ede-buffer-mine ((this ede-project) buffer)
1762 "Return non-nil if object THIS lays claim to the file in BUFFER."
1763 nil)
1764
1765(defmethod ede-buffer-mine ((this ede-target) buffer)
1766 "Return non-nil if object THIS lays claim to the file in BUFFER."
1767 (condition-case nil
1768 (ede-target-buffer-in-sourcelist this buffer (oref this source))
1769 ;; An error implies a bad match.
1770 (error nil)))
1771
1772\f
1773;;; Project mapping
1774;;
1775(defun ede-project-buffers (project)
1776 "Return a list of all active buffers controlled by PROJECT.
1777This includes buffers controlled by a specific target of PROJECT."
1778 (let ((bl (buffer-list))
1779 (pl nil))
1780 (while bl
0816d744 1781 (with-current-buffer (car bl)
acc33231
CY
1782 (if (and ede-object (eq (ede-current-project) project))
1783 (setq pl (cons (car bl) pl))))
1784 (setq bl (cdr bl)))
1785 pl))
1786
1787(defun ede-target-buffers (target)
1788 "Return a list of buffers that are controlled by TARGET."
1789 (let ((bl (buffer-list))
1790 (pl nil))
1791 (while bl
0816d744 1792 (with-current-buffer (car bl)
acc33231
CY
1793 (if (if (listp ede-object)
1794 (memq target ede-object)
1795 (eq ede-object target))
1796 (setq pl (cons (car bl) pl))))
1797 (setq bl (cdr bl)))
1798 pl))
1799
1800(defun ede-buffers ()
bd2afec2 1801 "Return a list of all buffers controlled by an EDE object."
acc33231
CY
1802 (let ((bl (buffer-list))
1803 (pl nil))
1804 (while bl
0816d744 1805 (with-current-buffer (car bl)
acc33231
CY
1806 (if ede-object
1807 (setq pl (cons (car bl) pl))))
1808 (setq bl (cdr bl)))
1809 pl))
1810
1811(defun ede-map-buffers (proc)
bd2afec2 1812 "Execute PROC on all buffers controlled by EDE."
acc33231
CY
1813 (mapcar proc (ede-buffers)))
1814
1815(defmethod ede-map-project-buffers ((this ede-project) proc)
1816 "For THIS, execute PROC on all buffers belonging to THIS."
1817 (mapcar proc (ede-project-buffers this)))
1818
1819(defmethod ede-map-target-buffers ((this ede-target) proc)
1820 "For THIS, execute PROC on all buffers belonging to THIS."
1821 (mapcar proc (ede-target-buffers this)))
1822
1823;; other types of mapping
1824(defmethod ede-map-subprojects ((this ede-project) proc)
1825 "For object THIS, execute PROC on all direct subprojects.
1826This function does not apply PROC to sub-sub projects.
1827See also `ede-map-all-subprojects'."
1828 (mapcar proc (oref this subproj)))
1829
1830(defmethod ede-map-all-subprojects ((this ede-project) allproc)
1831 "For object THIS, execute PROC on THIS and all subprojects.
1832This function also applies PROC to sub-sub projects.
1833See also `ede-map-subprojects'."
1834 (apply 'append
1835 (list (funcall allproc this))
1836 (ede-map-subprojects
1837 this
1838 (lambda (sp)
1839 (ede-map-all-subprojects sp allproc))
1840 )))
1841
1842;; (ede-map-all-subprojects (ede-load-project-file "../semantic/") (lambda (sp) (oref sp file)))
1843
1844(defmethod ede-map-targets ((this ede-project) proc)
1845 "For object THIS, execute PROC on all targets."
1846 (mapcar proc (oref this targets)))
1847
1848(defmethod ede-map-any-target-p ((this ede-project) proc)
1849 "For project THIS, map PROC to all targets and return if any non-nil.
1850Return the first non-nil value returned by PROC."
b90caf50 1851 (eval (cons 'or (ede-map-targets this proc))))
acc33231
CY
1852
1853\f
1854;;; Some language specific methods.
1855;;
1856;; These items are needed by ede-cpp-root to add better support for
1857;; configuring items for Semantic.
1858(defun ede-apply-preprocessor-map ()
1859 "Apply preprocessor tables onto the current buffer."
1860 (when (and ede-object (boundp 'semantic-lex-spp-macro-symbol-obarray))
1861 (let ((map (ede-preprocessor-map ede-object)))
1862 (when map
1863 ;; We can't do a require for the below symbol.
1864 (setq semantic-lex-spp-macro-symbol-obarray
1865 (semantic-lex-make-spp-table map))
1866 ))))
1867
1868(defmethod ede-system-include-path ((this ede-project))
1869 "Get the system include path used by project THIS."
1870 nil)
1871
1872(defmethod ede-preprocessor-map ((this ede-project))
1873 "Get the pre-processor map for project THIS."
1874 nil)
1875
1876(defmethod ede-system-include-path ((this ede-target))
1877 "Get the system include path used by project THIS."
1878 nil)
1879
1880(defmethod ede-preprocessor-map ((this ede-target))
1881 "Get the pre-processor map for project THIS."
1882 nil)
1883
1884\f
1885;;; Project-local variables
1886;;
1887(defun ede-make-project-local-variable (variable &optional project)
1888 "Make VARIABLE project-local to PROJECT."
1889 (if (not project) (setq project (ede-current-project)))
1890 (if (assoc variable (oref project local-variables))
1891 nil
1892 (oset project local-variables (cons (list variable)
1893 (oref project local-variables)))
0816d744
SM
1894 (dolist (b (ede-project-buffers project))
1895 (with-current-buffer b
1896 (make-local-variable variable)))))
acc33231
CY
1897
1898(defmethod ede-set-project-variables ((project ede-project) &optional buffer)
1899 "Set variables local to PROJECT in BUFFER."
1900 (if (not buffer) (setq buffer (current-buffer)))
0816d744
SM
1901 (with-current-buffer buffer
1902 (dolist (v (oref project local-variables))
1903 (make-local-variable (car v))
1904 ;; set it's value here?
1905 (set (car v) (cdr v)))))
acc33231
CY
1906
1907(defun ede-set (variable value &optional proj)
1908 "Set the project local VARIABLE to VALUE.
bd2afec2
GM
1909If VARIABLE is not project local, just use set. Optional argument PROJ
1910is the project to use, instead of `ede-current-project'."
acc33231
CY
1911 (let ((p (or proj (ede-current-project)))
1912 a)
1913 (if (and p (setq a (assoc variable (oref p local-variables))))
1914 (progn
1915 (setcdr a value)
0816d744
SM
1916 (dolist (b (ede-project-buffers p))
1917 (with-current-buffer b
1918 (set variable value))))
acc33231
CY
1919 (set variable value))
1920 (ede-commit-local-variables p))
1921 value)
1922
1923(defmethod ede-commit-local-variables ((proj ede-project))
1924 "Commit change to local variables in PROJ."
1925 nil)
1926
1927\f
1928;;; Accessors for more complex types where oref is inappropriate.
1929;;
1930(defmethod ede-target-sourcecode ((this ede-target))
1931 "Return the sourcecode objects which THIS permits."
1932 (let ((sc (oref this sourcetype))
1933 (rs nil))
1934 (while (and (listp sc) sc)
1935 (setq rs (cons (symbol-value (car sc)) rs)
1936 sc (cdr sc)))
1937 rs))
1938
1939\f
acc33231
CY
1940;;; Debugging.
1941
1942(defun ede-adebug-project ()
1943 "Run adebug against the current ede project.
1944Display the results as a debug list."
1945 (interactive)
1946 (require 'data-debug)
1947 (when (ede-current-project)
1948 (data-debug-new-buffer "*Analyzer ADEBUG*")
1949 (data-debug-insert-object-slots (ede-current-project) "")
1950 ))
1951
1952(defun ede-adebug-project-parent ()
1953 "Run adebug against the current ede parent project.
1954Display the results as a debug list."
1955 (interactive)
1956 (require 'data-debug)
1957 (when (ede-parent-project)
1958 (data-debug-new-buffer "*Analyzer ADEBUG*")
1959 (data-debug-insert-object-slots (ede-parent-project) "")
1960 ))
1961
1962(defun ede-adebug-project-root ()
1963 "Run adebug against the current ede parent project.
1964Display the results as a debug list."
1965 (interactive)
1966 (require 'data-debug)
1967 (when (ede-toplevel)
1968 (data-debug-new-buffer "*Analyzer ADEBUG*")
1969 (data-debug-insert-object-slots (ede-toplevel) "")
1970 ))
1971\f
1972;;; Hooks & Autoloads
1973;;
1974;; These let us watch various activities, and respond apropriatly.
1975
1976;; (add-hook 'edebug-setup-hook
1977;; (lambda ()
1978;; (def-edebug-spec ede-with-projectfile
1979;; (form def-body))))
1980
acc33231
CY
1981(provide 'ede)
1982
1983;; Include this last because it depends on ede.
1984(require 'ede/files)
1985
1986;; If this does not occur after the provide, we can get a recursive
1987;; load. Yuck!
1988(if (featurep 'speedbar)
1989 (ede-speedbar-file-setup)
1990 (add-hook 'speedbar-load-hook 'ede-speedbar-file-setup))
1991
3999968a 1992;; arch-tag: 0e1e0eba-484f-4119-abdb-30951f725705
acc33231 1993;;; ede.el ends here