1 ;;; ede.el --- Emacs Development Environment gloss
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: project, make
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; EDE is the top level Lisp interface to a project management scheme
27 ;; for Emacs. Emacs does many things well, including editing,
28 ;; building, and debugging. Folks migrating from other IDEs don't
29 ;; seem to think this qualifies, however, because they still have to
30 ;; write the makefiles, and specify parameters to programs.
32 ;; This EDE mode will attempt to link these diverse programs together
33 ;; into a comprehensive single interface, instead of a bunch of
38 ;; This command enables project mode on all files.
40 ;; (global-ede-mode t)
44 (require 'eieio-speedbar
)
46 (load "ede/loaddefs" nil
'nomessage
)
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")
63 (defconst ede-version
"1.0pre7"
64 "Current version of the Emacs EDE.")
68 "Display the current running version of EDE."
69 (interactive) (message "EDE %s" ede-version
))
72 "Emacs Development Environment gloss."
77 (defcustom ede-auto-add-method
'ask
78 "Whether a new source file should be automatically added to a target.
79 Whenever a new file is encountered in a directory controlled by a
80 project file, all targets are queried to see if it should be added.
81 If the value is 'always, then the new file is added to the first
82 target encountered. If the value is 'multi-ask, then if more than one
83 target wants the file, the user is asked. If only one target wants
84 the file, then then it is automatically added to that target. If the
85 value is 'ask, then the user is always asked, unless there is no
86 target willing to take the file. 'never means never perform the check."
88 :type
'(choice (const always
)
93 (defcustom ede-debug-program-function
'gdb
94 "Default Emacs command used to debug a target."
96 :type
'sexp
) ; make this be a list of options some day
99 ;;; Top level classes for projects and targets
101 (defclass ede-project-autoload
()
102 ((name :initarg
:name
103 :documentation
"Name of this project type")
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
110 :documentation
"A function symbol to call for the project root.
111 This function takes no arguments, and returns the current directories
112 root, if available. Leave blank to use the EDE directory walking
114 (initializers :initarg
:initializers
117 "Initializers passed to the project object.
118 These are used so there can be multiple types of projects
119 associated with a single object class, based on the initilizeres used.")
120 (load-type :initarg
:load-type
121 :documentation
"Fn symbol used to load this project file.")
122 (class-sym :initarg
:class-sym
123 :documentation
"Symbol representing the project class to use.")
124 (new-p :initarg
:new-p
127 "Non-nil if this is an option when a user creates a project.")
129 "Class representing minimal knowledge set to run preliminary EDE functions.
130 When more advanced functionality is needed from a project type, that projects
131 type is required and the load function used.")
133 (defvar ede-project-class-files
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
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
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
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
173 (ede-project-autoload "simple-overlay"
174 :name
"Simple" :file
'ede
/simple
175 :proj-file
'ede-simple-projectfile-for-dir
176 :load-type
'ede-simple-load
177 :class-sym
'ede-simple-project
))
178 "List of vectors defining how to determine what type of projects exist.")
180 ;;; Generic project information manager objects
182 (defclass ede-target
(eieio-speedbar-directory-button)
183 ((buttonface :initform speedbar-file-face
) ;override for superclass
188 :group
(default name
)
189 :documentation
"Name of this target.")
190 ;; @todo - I think this should be "dir", and not "path".
194 ;:label "Path to target"
195 ;:group (default name)
196 :documentation
"The path to the sources of this target.
197 Relative to the path of the project it belongs to.")
198 (source :initarg
:source
200 ;; I'd prefer a list of strings.
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
209 :custom
(repeat (string :tag
"File"))
210 :label
"Source Files with Version String"
213 "Source files with a version string in them.
214 These files are checked for a version string whenever the EDE version
215 of the master project is changed. When strings are found, the version
216 previously there is updated.")
219 ; (takes-compile-command :allocation :class
220 ; :initarg :takes-compile-command
224 ; "Non-nil if this target requires a user approved command.")
225 (sourcetype :allocation
:class
226 :type list
;; list of symbols
228 "A list of `ede-sourcecode' objects this class will handle.
229 This is used to match target objects with the compilers they can use, and
230 which files this object is interested in."
231 :accessor ede-object-sourcecode
)
232 (keybindings :allocation
:class
233 :initform
(("D" . ede-debug-target
))
235 "Keybindings specialized to this type of target."
236 :accessor ede-object-keybindings
)
237 (menu :allocation
:class
238 :initform
( [ "Debug target" ede-debug-target
240 (obj-of-class-p ede-object ede-target
)) ]
242 [ "Run target" ede-run-target
244 (obj-of-class-p ede-object ede-target
)) ]
245 :documentation
"Menu specialized to this type of target."
246 :accessor ede-object-menu
)
248 "A top level target to build.")
250 (defclass ede-project-placeholder
(eieio-speedbar-directory-button)
251 ((name :initarg
:name
256 :group
(default name
)
257 :documentation
"The name used when generating distribution files.")
258 (version :initarg
:version
263 :group
(default name
)
264 :documentation
"The version number used when distributing files.")
265 (directory :type string
267 :documentation
"Directory this project is associated with.")
268 (dirinode :documentation
"The inode id for :directory.")
271 :documentation
"File name where this project is stored.")
272 (rootproject ; :initarg - no initarg, don't save this slot!
274 :type
(or null ede-project-placeholder-child
)
275 :documentation
"Pointer to our root project.")
277 "Placeholder object for projects not loaded into memory.
278 Projects placeholders will be stored in a user specific location
279 and querying them will cause the actual project to get loaded.")
281 (defclass ede-project
(ede-project-placeholder)
282 ((subproj :initform nil
284 :documentation
"Sub projects controlled by this project.
285 For Automake based projects, each directory is treated as a project.")
286 (targets :initarg
:targets
288 :custom
(repeat (object :objectcreatefcn ede-new-target-custom
))
289 :label
"Local Targets"
291 :documentation
"List of top level targets in this project.")
292 (locate-obj :type
(or null ede-locate-base-child
)
294 "A locate object to use as a backup to `ede-expand-filename'.")
295 (tool-cache :initarg
:tool-cache
297 :custom
(repeat object
)
300 :documentation
"List of tool cache configurations in this project.
301 This allows any tool to create, manage, and persist project-specific settings.")
302 (mailinglist :initarg
:mailinglist
306 :label
"Mailing List Address"
309 "An email address where users might send email for help.")
310 (web-site-url :initarg
:web-site-url
314 :label
"Web Site URL"
316 :documentation
"URL to this projects web site.
317 This is a URL to be sent to a web site for documentation.")
318 (web-site-directory :initarg
:web-site-directory
321 :label
"Web Page Directory"
324 "A directory where web pages can be found by Emacs.
325 For remote locations use a path compatible with ange-ftp or EFS.
326 You can also use TRAMP for use with rcp & scp.")
327 (web-site-file :initarg
:web-site-file
330 :label
"Web Page File"
333 "A file which contains the home page for this project.
334 This file can be relative to slot `web-site-directory'.
335 This can be a local file, use ange-ftp, EFS, or TRAMP.")
336 (ftp-site :initarg
:ftp-site
343 "FTP site where this project's distribution can be found.
344 This FTP site should be in Emacs form, as needed by `ange-ftp', but can
345 also be of a form used by TRAMP for use with scp, or rcp.")
346 (ftp-upload-site :initarg
:ftp-upload-site
350 :label
"FTP Upload site"
353 "FTP Site to upload new distributions to.
354 This FTP site should be in Emacs form as needed by `ange-ftp'.
355 If this slot is nil, then use `ftp-site' instead.")
356 (configurations :initarg
:configurations
357 :initform
("debug" "release")
359 :custom
(repeat string
)
360 :label
"Configuration Options"
362 :documentation
"List of available configuration types.
363 Individual target/project types can form associations between a configuration,
364 and target specific elements such as build variables.")
365 (configuration-default :initarg
:configuration-default
368 :label
"Current Configuration"
370 :documentation
"The default configuration.")
371 (local-variables :initarg
:local-variables
373 :custom
(repeat (cons (sexp :tag
"Variable")
374 (sexp :tag
"Value")))
375 :label
"Project Local Variables"
377 :documentation
"Project local variables")
378 (keybindings :allocation
:class
379 :initform
(("D" . ede-debug-target
)
380 ("R" . ede-run-target
))
381 :documentation
"Keybindings specialized to this type of target."
382 :accessor ede-object-keybindings
)
383 (menu :allocation
:class
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
392 (not (string= "" (oref (ede-toplevel) web-site-url
)))) ]
394 [ "Rescan Project Files" ede-rescan-toplevel t
]
395 [ "Edit Projectfile" ede-edit-file-target
397 (or (listp ede-object
)
398 (not (obj-of-class-p ede-object ede-project
)))) ]
400 :documentation
"Menu specialized to this type of target."
401 :accessor ede-object-menu
)
403 "Top level EDE project specification.
404 All specific project types must derive from this project."
405 :method-invocation-order
:depth-first
)
407 ;;; Management variables
409 (defvar ede-projects nil
410 "A list of all active projects currently loaded in Emacs.")
412 (defvar ede-object-root-project nil
413 "The current buffer's current root project.
414 If a file is under a project, this specifies the project that is at
415 the root of a project tree.")
416 (make-variable-buffer-local 'ede-object-root-project
)
418 (defvar ede-object-project nil
419 "The current buffer's current project at that level.
420 If a file is under a project, this specifies the project that contains the
422 (make-variable-buffer-local 'ede-object-project
)
424 (defvar ede-object nil
425 "The current buffer's target object.
426 This object's class determines how to compile and debug from a buffer.")
427 (make-variable-buffer-local 'ede-object
)
429 (defvar ede-selected-object nil
430 "The currently user-selected project or target.
431 If `ede-object' is nil, then commands will operate on this object.")
433 (defvar ede-constructing nil
434 "Non nil when constructing a project hierarchy.")
436 (defvar ede-deep-rescan nil
437 "Non nil means scan down a tree, otherwise rescans are top level only.
438 Do not set this to non-nil globally. It is used internally.")
440 ;;; The EDE persistent cache.
442 (defcustom ede-project-placeholder-cache-file
443 (locate-user-emacs-file "ede-projects.el" ".projects.ede")
444 "File containing the list of projects EDE has viewed."
448 (defvar ede-project-cache-files nil
449 "List of project files EDE has seen before.")
451 (defun ede-save-cache ()
452 "Save a cache of EDE objects that Emacs has seen before."
454 (let ((p ede-projects
)
455 (c ede-project-cache-files
)
456 (recentf-exclude '(ignore))
460 (set-buffer (find-file-noselect ede-project-placeholder-cache-file t
))
462 (insert ";; EDE project cache file.
463 ;; This contains a list of projects you have visited.\n(")
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
"\""))))
471 (insert "\n \"" (car c
) "\"")
477 (message "File %s could not be saved."
478 ede-project-placeholder-cache-file
)))
479 (kill-buffer (current-buffer))
482 (message "File %s could not be read."
483 ede-project-placeholder-cache-file
))
487 (defun ede-load-cache ()
488 "Load the cache of EDE projects."
490 (let ((cachebuffer nil
))
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)))
500 ;; Remove loaded projects from the cache.
502 (setq c
(delete (oref (car p
) file
) c
))
504 ;; Remove projects that aren't on the filesystem
507 (when (file-exists-p (car c
))
508 (setq new
(cons (car c
) new
)))
511 (setq ede-project-cache-files
(nreverse new
))))
513 (when cachebuffer
(kill-buffer cachebuffer
))
516 ;;; Important macros for doing commands.
518 (defmacro ede-with-projectfile
(obj &rest forms
)
519 "For the project in which OBJ resides, execute FORMS."
520 (list 'save-window-excursion
523 (list 'if
(list 'obj-of-class-p
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
))
531 '(dbka (get-file-buffer (oref pf file
))))
532 '(if (not dbka
) (find-file (oref pf file
))
533 (switch-to-buffer dbka
))
535 '(if (not dbka
) (kill-buffer (current-buffer))))))
536 (put 'ede-with-projectfile
'lisp-indent-function
1)
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
)
547 (defun ede-choose-object (prompt list-o-o
)
548 "Using PROMPT, ask the user which OBJECT to use based on the name field.
549 Argument LIST-O-O is the list of objects to choose from."
550 (let* ((al (object-assoc-list 'name list-o-o
))
551 (ans (completing-read prompt al nil t
)))
552 (setq ans
(assoc ans al
))
557 (defvar ede-minor-mode-map
558 (let ((map (make-sparse-keymap))
559 (pmap (make-sparse-keymap)))
560 (define-key pmap
"e" 'ede-edit-file-target
)
561 (define-key pmap
"a" 'ede-add-file
)
562 (define-key pmap
"d" 'ede-remove-file
)
563 (define-key pmap
"t" 'ede-new-target
)
564 (define-key pmap
"g" 'ede-rescan-toplevel
)
565 (define-key pmap
"s" 'ede-speedbar
)
566 (define-key pmap
"l" 'ede-load-project-file
)
567 (define-key pmap
"f" 'ede-find-file
)
568 (define-key pmap
"C" 'ede-compile-project
)
569 (define-key pmap
"c" 'ede-compile-target
)
570 (define-key pmap
"\C-c" 'ede-compile-selected
)
571 (define-key pmap
"D" 'ede-debug-target
)
572 (define-key pmap
"R" 'ede-run-target
)
573 ;; bind our submap into map
574 (define-key map
"\C-c." pmap
)
576 "Keymap used in project minor mode.")
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
))
583 "Keymap used in `global-ede-mode'.")
585 ;; Activate the EDE items in cedet-menu-map
587 (define-key cedet-menu-map
[ede-find-file
]
588 '(menu-item "Find File in Project..." ede-find-file
:enable ede-object
589 :visible global-ede-mode
))
590 (define-key cedet-menu-map
[ede-speedbar
]
591 '(menu-item "View Project Tree" ede-speedbar
:enable ede-object
592 :visible global-ede-mode
))
593 (define-key cedet-menu-map
[ede]
594 '(menu-item "Load Project" ede
595 :visible global-ede-mode))
596 (define-key cedet-menu-map [ede-new]
597 '(menu-item "Create Project" ede-new
598 :enable (not ede-object)
599 :visible global-ede-mode))
600 (define-key cedet-menu-map [ede-target-options]
601 '(menu-item "Target Options" ede-target-options
602 :filter ede-target-forms-menu
603 :visible global-ede-mode))
604 (define-key cedet-menu-map [ede-project-options]
605 '(menu-item "Project Options" ede-project-options
606 :filter ede-project-forms-menu
607 :visible global-ede-mode))
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
612 :visible global-ede-mode))
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)
617 (eval (cons 'or (mapcar (lambda (o) (obj-of-class-p o class)) ede-object)))
618 (obj-of-class-p ede-object class)))
620 (defun ede-build-forms-menu (menu-def)
621 "Create a sub menu for building different parts of an EDE system.
622 Argument MENU-DEF is the menu definition to use."
623 (easy-menu-filter-return
624 (easy-menu-create-menu
626 (let ((obj (ede-current-project))
627 (newmenu nil) ;'([ "Build Selected..." ede-compile-selected t ]))
634 (setq targets (when (slot-boundp 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))
642 (setq newmenu (append newmenu
643 (ede-menu-items-build (car ede-obj) t))
645 ede-obj (cdr ede-obj))))
646 ;; Third, by name, enable builds for other local targets
648 (unless (eq tskip (car targets))
649 (setq targitems (ede-menu-items-build (car targets) nil))
652 (if (= 1 (length targitems))
654 (cons (ede-name (car targets))
657 (setq targets (cdr targets)))
658 ;; Fourth, build sub projects.
660 ;; Fifth, Add make distribution
661 (append newmenu (list [ "Make distribution" ede-make-dist t ]))
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
669 (let ((obj (or ede-selected-object ede-object)))
671 '([ "Add File" ede-add-file
672 (and (ede-current-project)
673 (oref (ede-current-project) targets)) ]
674 [ "Remove File" ede-remove-file
676 (or (listp ede-object)
677 (not (obj-of-class-p ede-object ede-project)))) ]
681 (if (and (not (listp obj)) (oref obj menu))
684 ;; This is bad, but I'm not sure what else to do.
685 (oref (car obj) menu)))))))))
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
692 (let* ((obj (ede-current-project))
693 (class (if obj (object-class obj)))
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))))
703 '( [ "Add Target" ede-new-target (ede-current-project) ]
704 [ "Remove Target" ede-delete-target ede-object ]
708 (error (message "Err found: %S" err)
712 (defun ede-customize-forms-menu (menu-def)
713 "Create a menu of the project, and targets that can be customized.
714 Argument MENU-DEF is the definition of the current menu."
715 (easy-menu-filter-return
716 (easy-menu-create-menu
718 (let* ((obj (ede-current-project))
721 (setq targ (when (slot-boundp obj 'targets)
723 ;; Make custom menus for everything here.
725 (cons (concat "Project " (ede-name obj))
726 (eieio-customize-object-group obj))
727 [ "Reorder Targets" ede-project-sort-targets t ]
730 (cons (concat "Target " (ede-name o))
731 (eieio-customize-object-group o)))
735 (defun ede-apply-object-keymap (&optional default)
736 "Add target specific keybindings into the local map.
737 Optional argument DEFAULT indicates if this should be set to the default
738 version of the keymap."
739 (let ((object (or ede-object ede-selected-object)))
741 (let ((keys (ede-object-keybindings object)))
743 (local-set-key (concat "\C-c." (car (car keys)))
745 (setq keys (cdr keys))))
748 ;;; Menu building methods for building
750 (defmethod ede-menu-items-build ((obj ede-project) &optional current)
751 "Return a list of menu items for building project OBJ.
752 If optional argument CURRENT is non-nil, return sub-menu code."
754 (list [ "Build Current Project" ede-compile-project t ])
757 (concat "Build Project " (ede-name obj))
758 `(project-compile-project ,obj))))))
760 (defmethod ede-menu-items-build ((obj ede-target) &optional current)
761 "Return a list of menu items for building target OBJ.
762 If optional argument CURRENT is non-nil, return sub-menu code."
764 (list [ "Build Current Target" ede-compile-target t ])
766 (concat "Build Target " (ede-name obj))
767 `(project-compile-target ,obj)
770 ;;; Mode Declarations
773 (autoload 'ede-dired-minor-mode "ede/dired" "EDE commands for dired" t))
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)
783 (defun ede-turn-on-hook ()
784 "Turn on EDE minor mode in the current buffer if needed.
785 To 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))
794 (define-minor-mode ede-minor-mode
795 "Toggle EDE (Emacs Development Environment) minor mode.
796 With non-nil argument ARG, enable EDE minor mode if ARG is
797 positive; otherwise, disable it.
799 If this file is contained, or could be contained in an EDE
800 controlled project, then this mode is activated automatically
801 provided `global-ede-mode' is enabled."
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)))
807 (if (and (not ede-constructing)
808 (ede-directory-project-p default-directory t))
810 (proj (ede-directory-get-open-project default-directory
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)))))
825 (defun ede-reset-all-buffers (onoff)
826 "Reset all the buffers due to change in EDE.
827 ONOFF indicates enabling or disabling the mode."
828 (let ((b (buffer-list)))
830 (when (buffer-file-name (car b))
831 (ede-buffer-object (car b))
836 (define-minor-mode global-ede-mode
837 "Toggle global EDE (Emacs Development Environment) mode.
838 With non-nil argument ARG, enable global EDE mode if ARG is
839 positive; otherwise, disable it.
841 This global minor mode enables `ede-minor-mode' in all buffers in
842 an EDE controlled project."
846 ;; Turn on global-ede-mode
849 (define-key cedet-menu-map [cedet-menu-separator] '("--")))
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)
857 (ede-reset-all-buffers 1))
858 ;; Turn off global-ede-mode
859 (define-key cedet-menu-map [cedet-menu-separator] nil)
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)
867 (ede-reset-all-buffers -1)))
869 (defvar ede-ignored-file-alist
874 "List of file name patters that EDE will never ask about.")
876 (defun ede-ignore-file (filename)
877 "Should we ignore FILENAME?"
879 (F ede-ignored-file-alist))
880 (while (and (not any) F)
881 (when (string-match (car F) filename)
886 (defun ede-auto-add-to-target ()
887 "Look for a target that wants to own the current file.
888 Follow the preference set with `ede-auto-add-method' and get the list
889 of 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)))
895 ;; Find all the objects.
896 (setq wants (oref (ede-current-project) targets))
898 (if (ede-want-file-p (car wants) (buffer-file-name))
899 (setq desires (cons (car wants) desires)))
900 (setq wants (cdr wants)))
902 (cond ((or (eq ede-auto-add-method 'ask)
903 (and (eq ede-auto-add-method 'multi-ask)
904 (< 1 (length desires))))
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)
913 '(("create subproject" . project)))
914 ;; Here are the existing objects we want.
915 (object-assoc-list 'name desires)))
917 (ans (completing-read
918 (format "Add %s to target: " (buffer-file-name))
920 (setq ans (assoc ans al))
921 (cond ((eieio-object-p (cdr ans))
922 (ede-add-file (cdr ans)))
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)))
933 ;;; Interactive method invocations
936 "Start up EDE on something.
937 Argument FILE is the file or directory to load a project from."
938 (interactive "fProject File: ")
939 (if (not (file-exists-p file))
941 (ede-load-project-file (file-name-directory file))))
943 (defun ede-new (type &optional name)
944 "Create a new project starting of project type TYPE.
945 Optional argument NAME is the name to give this project."
947 (list (completing-read "Project Type: "
950 (let* ((l ede-project-class-files)
951 (cp (ede-current-project))
952 (cs (when cp (object-class cp)))
956 (if (eq (oref (car l) :class-sym)
958 (setq r (cons (car l) r)))
959 (if (oref (car l) new-p)
960 (setq r (cons (car l) r))))
964 (error "No valid interactive sub project types for %s"
966 (error "EDE error: Can't fin project types to create")))
970 ;; Make sure we have a valid directory
971 (when (not (file-exists-p default-directory))
972 (error "Cannot create project in non-existent directory %s" default-directory))
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!
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))
993 "Unknown file name specifier %S"
996 (inits (oref obj initializers)))
997 ;; Force the name to match for new objects.
998 (object-set-name-string nobj (oref nobj :name))
1001 (eieio-oset nobj (car inits) (car (cdr inits)))
1002 (setq inits (cdr (cdr inits))))
1003 (let ((pp (ede-parent-project)))
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)
1011 (message "Project created and saved. You may now create targets."))
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))))
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.
1019 If PARENT is specified, then be relative to the PARENT project.
1020 Specifying 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)))
1027 (defmethod ede-subproject-p ((proj ede-project))
1028 "Return non-nil if PROJ is a sub project."
1029 (ede-parent-project proj))
1031 (defun ede-invoke-method (sym &rest args)
1032 "Invoke method SYM on the current buffer's project object.
1033 ARGS are additional arguments to pass to method sym."
1034 (if (not ede-object)
1035 (error "Cannot invoke %s for %s" (symbol-name sym)
1037 ;; Always query a target. There should never be multiple
1038 ;; projects in a single buffer.
1039 (apply sym (ede-singular-object "Target: ") args))
1041 (defun ede-rescan-toplevel ()
1042 "Rescan all project files."
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)
1050 (defun ede-new-target (&rest args)
1051 "Create a new target specific to this type of project file.
1052 Different projects accept different arguments ARGS.
1053 Typically you can specify NAME, target TYPE, and AUTOADD, where AUTOADD is
1054 a string \"y\" or \"n\", which answers the y/n question done interactively."
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))
1061 (defun ede-new-target-custom ()
1062 "Create a new target specific to this type of project file."
1064 (project-new-target-custom (ede-current-project)))
1066 (defun ede-delete-target (target)
1067 "Delete TARGET from the current project."
1069 (let ((ede-object (ede-current-project)))
1070 (ede-invoke-method 'project-interactive-select-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
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)))
1084 (defun ede-add-file (target)
1085 "Add the current buffer to a TARGET in the current project."
1087 (let ((ede-object (ede-current-project)))
1088 (ede-invoke-method 'project-interactive-select-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)))))
1096 (error "Could not find specified target %S" target))
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))
1107 (defun ede-remove-file (&optional force)
1108 "Remove the current file from targets.
1109 Optional argument FORCE forces the file to be removed without asking."
1111 (if (not ede-object)
1112 (error "Cannot invoke remove-file for %s" (buffer-name)))
1113 (let ((eo (if (listp ede-object)
1117 (list ede-object))))
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)))
1122 (setq ede-object nil)
1123 (setq ede-object (ede-buffer-object (current-buffer)))
1124 (ede-apply-target-options)))
1126 (defun ede-edit-file-target ()
1127 "Enter the project file to hand edit the current buffer's target."
1129 (ede-invoke-method 'project-edit-file-target))
1131 (defun ede-compile-project ()
1132 "Compile the current project."
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))))
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))
1147 (defun ede-compile-target ()
1148 "Compile the current buffer's associated target."
1150 (ede-invoke-method 'project-compile-target))
1152 (defun ede-debug-target ()
1153 "Debug the current buffer's associated target."
1155 (ede-invoke-method 'project-debug-target))
1157 (defun ede-run-target ()
1158 "Debug the current buffer's assocated target."
1160 (ede-invoke-method 'project-run-target))
1162 (defun ede-make-dist ()
1163 "Create a distribution from the current project."
1165 (let ((ede-object (ede-current-project)))
1166 (ede-invoke-method 'project-make-dist)))
1170 ;; Routines for customizing projects and targets.
1172 (defvar eieio-ede-old-variables nil
1173 "The old variables for a project.")
1175 (defalias 'customize-project 'ede-customize-project)
1176 (defun ede-customize-project (&optional group)
1177 "Edit fields of the current project through EIEIO & Custom.
1178 Optional GROUP specifies the subgroup of slots to customize."
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)))
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.
1191 Optional argument OBJ is the target object to customize.
1192 Optional argument GROUP is the slot group to display."
1194 (require 'eieio-custom)
1195 (if (not (obj-of-class-p ede-object ede-target))
1196 (error "Current file is not part of a target"))
1197 (let ((group (if group (eieio-read-customization-group ede-object))))
1198 (ede-customize-target ede-object group)))
1200 (defun ede-customize-target (obj group)
1201 "Edit fields of the current target through EIEIO & Custom.
1202 Optional argument OBJ is the target object to customize.
1203 Optional 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)))
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.
1214 (defvar ede-project-sort-targets-order nil
1215 "Variable for tracking target order in `ede-project-sort-targets'.")
1217 (defun ede-project-sort-targets ()
1218 "Create a custom-like buffer for sorting targets of current project."
1220 (let ((proj (ede-current-project))
1223 (switch-to-buffer (get-buffer-create "*EDE sort targets*"))
1225 (setq ede-object-project proj)
1226 (widget-create 'push-button
1227 :notify (lambda (&rest ignore)
1228 (let ((targets (oref ede-object-project targets))
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)
1238 (widget-create 'push-button
1239 :notify (lambda (&rest ignore)
1242 (widget-insert "\n\n")
1243 (setq ede-project-sort-targets-order nil)
1245 (add-to-ordered-list
1246 'ede-project-sort-targets-order
1248 (number-sequence 0 (1- (length (oref proj targets)))))
1249 (ede-project-sort-targets-list)
1250 (use-local-map widget-keymap)
1252 (goto-char (point-min))))
1254 (defun ede-project-sort-targets-list ()
1255 "Sort the target list while using `ede-project-sort-targets'."
1258 (targets (oref ede-object-project targets))
1259 (inhibit-read-only t)
1260 (inhibit-modification-hooks t))
1261 (goto-char (point-min))
1263 (delete-region (point) (point-max))
1264 (while (< count (length targets))
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
1273 (add-to-ordered-list
1274 'ede-project-sort-targets-order
1275 (nth (1- ,count) cur) ,count))
1276 (ede-project-sort-targets-list))
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))
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))))))
1297 ;;; Customization hooks
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)
1306 (if (not (assoc (car (car ov)) nv))
1310 (kill-local-variable (car (car ov))))
1311 (ede-project-buffers proj))))
1313 (mapc (lambda (b) (ede-set-project-variables proj b))
1314 (ede-project-buffers proj))))
1316 (defmethod eieio-done-customizing ((target ede-target))
1317 "Call this when a user finishes customizing TARGET."
1320 (defmethod ede-commit-project ((proj ede-project))
1321 "Commit any change to PROJ to its file."
1326 ;;; EDE project placeholder methods
1328 (defmethod ede-project-force-load ((this ede-project-placeholder))
1329 "Make sure the placeholder THIS is replaced with the real thing.
1330 Return the new object created in its place."
1335 ;;; EDE project target baseline methods.
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.
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.
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))
1350 (defmethod project-interactive-select-target ((this ede-project) prompt)
1351 "Interactively query for a target that exists in project THIS.
1352 Argument 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))))
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))
1361 (defmethod project-add-file ((ot ede-target) file)
1362 "Add the current buffer into project project target OT.
1363 Argument FILE is the file to add."
1364 (error "add-file not supported by %s" (object-name ot)))
1366 (defmethod project-remove-file ((ot ede-target) fnnd)
1367 "Remove the current buffer from project target OT.
1368 Argument FNND is an argument."
1369 (error "remove-file not supported by %s" (object-name ot)))
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)))
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)))
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)))
1383 (defmethod project-delete-target ((ot ede-target))
1384 "Delete the current target OT from it's parent project."
1385 (error "add-file not supported by %s" (object-name ot)))
1387 (defmethod project-compile-project ((obj ede-project) &optional command)
1388 "Compile the entire current project OBJ.
1389 Argument COMMAND is the command to use when compiling."
1390 (error "compile-project not supported by %s" (object-name obj)))
1392 (defmethod project-compile-target ((obj ede-target) &optional command)
1393 "Compile the current target OBJ.
1394 Argument COMMAND is the command to use for compiling the target."
1395 (error "compile-target not supported by %s" (object-name obj)))
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)))
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)))
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)))
1409 (defmethod project-dist-files ((this ede-project))
1410 "Return a list of files that constitutes a distribution of THIS project."
1411 (error "Dist-files is not supported by %s" (object-name this)))
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)))
1417 ;;; Default methods for EDE classes
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
1423 (defmethod ede-name ((this ede-target))
1424 "Return the name of THIS targt."
1427 (defmethod ede-target-name ((this ede-target))
1428 "Return the name of THIS target, suitable for make or debug style commands."
1431 (defmethod ede-name ((this ede-project))
1432 "Return a short-name for THIS project file.
1433 Do this by extracting the lowest directory name."
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))))
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))))
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)))
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)))
1463 (defun ede-header-file ()
1464 "Return the header file for the current buffer.
1465 Not all buffers need headers, so return nil if no applicable."
1467 (ede-buffer-header-file ede-object (current-buffer))
1470 (defmethod ede-buffer-header-file ((this ede-project) buffer)
1471 "Return nil, projects don't have header files."
1474 (defmethod ede-buffer-header-file ((this ede-target) buffer)
1475 "There are no default header files in EDE.
1476 Do a quick check to see if there is a Header tag in this buffer."
1477 (with-current-buffer buffer
1478 (if (re-search-forward "::Header:: \\([a-zA-Z0-9.]+\\)" nil t)
1479 (buffer-substring-no-properties (match-beginning 1)
1481 (let ((src (ede-target-sourcecode this))
1483 (while (and src (not found))
1484 (setq found (ede-buffer-header-file (car src) (buffer-file-name))
1488 (defun ede-documentation-files ()
1489 "Return the documentation files for the current buffer.
1490 Not all buffers need documentations, so return nil if no applicable.
1491 Some projects may have multiple documentation files, so return a list."
1493 (ede-buffer-documentation-files ede-object (current-buffer))
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))
1501 (defmethod ede-buffer-documentation-files ((this ede-target) buffer)
1502 "Check for some documentation files for THIS.
1503 Also do a quick check to see if there is a Documentation tag in this BUFFER."
1504 (with-current-buffer buffer
1505 (if (re-search-forward "::Documentation:: \\([a-zA-Z0-9.]+\\)" nil t)
1506 (buffer-substring-no-properties (match-beginning 1)
1508 ;; Check the master project
1509 (let ((cp (ede-toplevel)))
1510 (ede-buffer-documentation-files cp (current-buffer))))))
1512 (defmethod ede-documentation ((this ede-project))
1513 "Return a list of files that provides documentation.
1514 Documentation is not for object THIS, but is provided by THIS for other
1515 files in the project."
1516 (let ((targ (oref this targets))
1517 (proj (oref this subproj))
1520 (setq found (append (ede-documentation (car targ)) found)
1523 (setq found (append (ede-documentation (car proj)) found)
1527 (defmethod ede-documentation ((this ede-target))
1528 "Return a list of files that provides documentation.
1529 Documentation is not for object THIS, but is provided by THIS for other
1530 files in the project."
1533 (defun ede-html-documentation-files ()
1534 "Return a list of HTML documentation files associated with this project."
1535 (ede-html-documentation (ede-toplevel))
1538 (defmethod ede-html-documentation ((this ede-project))
1539 "Return a list of HTML files provided by project THIS."
1543 (defun ede-ecb-project-paths ()
1544 "Return a list of all paths for all active EDE projects.
1545 This functions is meant for use with ECB."
1546 (let ((p ede-projects)
1549 (setq d (cons (file-name-directory (oref (car p) file))
1554 ;;; EDE project-autoload methods
1556 (defmethod ede-dir-to-projectfile ((this ede-project-autoload) dir)
1557 "Return a full file name of project THIS found in DIR.
1558 Return 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)))))
1567 (when (and f (file-exists-p f))
1570 ;;; EDE basic functions
1572 (defun ede-add-project-to-global-list (proj)
1573 "Add the project PROJ to the master list of projects.
1574 On success, return the added project."
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)
1584 (defun ede-load-project-file (dir &optional rootreturn)
1585 "Project file independent way to read a project in from DIR.
1586 Optional 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)
1590 ;;(message "EDE LOAD : %S" file)
1592 (path (expand-file-name (file-name-directory file)))
1593 (pfc (ede-directory-project-p path))
1598 ;; @TODO - Do we really need to scan? Is this a waste of time?
1599 ;; Scan upward for a the next project file style.
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)
1605 ;; recomment as we go
1608 ;; Do nothing if we are buiding an EDE project already
1611 ;; Load in the project in question.
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))
1618 ;; See if it's been loaded before
1619 (setq o (object-assoc (ede-dir-to-projectfile pfc toppath) 'file
1622 ;; If not, get it now.
1623 (let ((ede-constructing t))
1624 (setq o (funcall (oref pfc load-type) toppath))
1626 (error "Project type error: :load-type failed to create a project"))
1627 (ede-add-project-to-global-list o)))
1629 ;; Return the found root project.
1630 (when rootreturn (set rootreturn o))
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))
1639 (if (string= file (oref (car tocheck) file))
1640 (setq found (car tocheck)))
1641 (setq newbits (oref (car tocheck) subproj)))
1643 (append (cdr tocheck) newbits))))
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)))
1652 (defun ede-parent-project (&optional obj)
1653 "Return the project belonging to the parent directory.
1654 nil if there is no previous directory.
1655 Optional 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)
1666 (updir (ede-up-directory thisdir)))
1668 ;; If there was no root, perhaps we can derive it from
1670 (let ((root (or root (ede-directory-get-toplevel-open-project updir))))
1672 ;; This lets us find a subproject under root based on updir.
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
1680 (and (ede-directory-project-p updir)
1681 (ede-load-project-file
1682 (file-name-as-directory updir))))))))))
1684 (defun ede-current-project (&optional dir)
1685 "Return the current project file.
1686 If optional DIR is provided, get the project for DIR instead."
1688 ;; If it matches the current directory, do we have a pre-existing project?
1689 (when (and (or (not dir) (string= dir default-directory))
1691 (setq ans ede-object-project)
1693 ;; No current project.
1695 (let* ((ldir (or dir default-directory)))
1696 (setq ans (ede-directory-get-open-project ldir))
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.
1704 (defun ede-buffer-object (&optional buffer)
1705 "Return the target object for BUFFER.
1706 This function clears cached values and recalculates."
1708 (if (not buffer) (setq buffer (current-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)))
1717 (defmethod ede-target-in-project-p ((proj ede-project) target)
1718 "Is PROJ the parent of TARGET?
1719 If TARGET belongs to a subproject, return that project file."
1720 (if (and (slot-boundp proj 'targets)
1721 (memq target (oref proj targets)))
1723 (let ((s (oref proj subproj))
1725 (while (and s (not ans))
1726 (setq ans (ede-target-in-project-p (car s) target))
1730 (defun ede-target-parent (target)
1731 "Return the project which is the parent of TARGET.
1732 It is recommended you track the project a different way as this function
1733 could 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)
1741 (defun ede-maybe-checkout (&optional buffer)
1742 "Check BUFFER out of VC if necessary."
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))))
1749 (defmethod ede-find-target ((proj ede-project) buffer)
1750 "Fetch the target in PROJ belonging to BUFFER or nil."
1751 (with-current-buffer buffer
1753 (if (ede-buffer-mine proj buffer)
1755 (let ((targets (oref proj targets))
1758 (if (ede-buffer-mine (car targets) buffer)
1759 (setq f (cons (car targets) f)))
1760 (setq targets (cdr targets)))
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.
1765 Handles complex path issues."
1766 (member (ede-convert-path this (buffer-file-name buffer)) source))
1768 (defmethod ede-buffer-mine ((this ede-project) buffer)
1769 "Return non-nil if object THIS lays claim to the file in BUFFER."
1772 (defmethod ede-buffer-mine ((this ede-target) buffer)
1773 "Return non-nil if object THIS lays claim to the file in BUFFER."
1775 (ede-target-buffer-in-sourcelist this buffer (oref this source))
1776 ;; An error implies a bad match.
1782 (defun ede-project-buffers (project)
1783 "Return a list of all active buffers controlled by PROJECT.
1784 This includes buffers controlled by a specific target of PROJECT."
1785 (let ((bl (buffer-list))
1788 (with-current-buffer (car bl)
1789 (if (and ede-object (eq (ede-current-project) project))
1790 (setq pl (cons (car bl) pl))))
1794 (defun ede-target-buffers (target)
1795 "Return a list of buffers that are controlled by TARGET."
1796 (let ((bl (buffer-list))
1799 (with-current-buffer (car bl)
1800 (if (if (listp ede-object)
1801 (memq target ede-object)
1802 (eq ede-object target))
1803 (setq pl (cons (car bl) pl))))
1807 (defun ede-buffers ()
1808 "Return a list of all buffers controlled by an EDE object."
1809 (let ((bl (buffer-list))
1812 (with-current-buffer (car bl)
1814 (setq pl (cons (car bl) pl))))
1818 (defun ede-map-buffers (proc)
1819 "Execute PROC on all buffers controlled by EDE."
1820 (mapcar proc (ede-buffers)))
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)))
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)))
1830 ;; other types of mapping
1831 (defmethod ede-map-subprojects ((this ede-project) proc)
1832 "For object THIS, execute PROC on all direct subprojects.
1833 This function does not apply PROC to sub-sub projects.
1834 See also `ede-map-all-subprojects'."
1835 (mapcar proc (oref this subproj)))
1837 (defmethod ede-map-all-subprojects ((this ede-project) allproc)
1838 "For object THIS, execute PROC on THIS and all subprojects.
1839 This function also applies PROC to sub-sub projects.
1840 See also `ede-map-subprojects'."
1842 (list (funcall allproc this))
1843 (ede-map-subprojects
1846 (ede-map-all-subprojects sp allproc))
1849 ;; (ede-map-all-subprojects (ede-load-project-file "../semantic/") (lambda (sp) (oref sp file)))
1851 (defmethod ede-map-targets ((this ede-project) proc)
1852 "For object THIS, execute PROC on all targets."
1853 (mapcar proc (oref this targets)))
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.
1857 Return the first non-nil value returned by PROC."
1858 (eval (cons 'or (ede-map-targets this proc))))
1861 ;;; Some language specific methods.
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))
1868 (let* ((objs ede-object)
1869 (map (ede-preprocessor-map (if (consp objs)
1873 ;; We can't do a require for the below symbol.
1874 (setq semantic-lex-spp-macro-symbol-obarray
1875 (semantic-lex-make-spp-table map)))
1877 (message "Choosing preprocessor syms for project %s"
1878 (object-name (car objs)))))))
1880 (defmethod ede-system-include-path ((this ede-project))
1881 "Get the system include path used by project THIS."
1884 (defmethod ede-preprocessor-map ((this ede-project))
1885 "Get the pre-processor map for project THIS."
1888 (defmethod ede-system-include-path ((this ede-target))
1889 "Get the system include path used by project THIS."
1892 (defmethod ede-preprocessor-map ((this ede-target))
1893 "Get the pre-processor map for project THIS."
1897 ;;; Project-local variables
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))
1904 (oset project local-variables (cons (list variable)
1905 (oref project local-variables)))
1906 (dolist (b (ede-project-buffers project))
1907 (with-current-buffer b
1908 (make-local-variable variable)))))
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)))
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)))))
1919 (defun ede-set (variable value &optional proj)
1920 "Set the project local VARIABLE to VALUE.
1921 If VARIABLE is not project local, just use set. Optional argument PROJ
1922 is the project to use, instead of `ede-current-project'."
1923 (let ((p (or proj (ede-current-project)))
1925 (if (and p (setq a (assoc variable (oref p local-variables))))
1928 (dolist (b (ede-project-buffers p))
1929 (with-current-buffer b
1930 (set variable value))))
1931 (set variable value))
1932 (ede-commit-local-variables p))
1935 (defmethod ede-commit-local-variables ((proj ede-project))
1936 "Commit change to local variables in PROJ."
1940 ;;; Accessors for more complex types where oref is inappropriate.
1942 (defmethod ede-target-sourcecode ((this ede-target))
1943 "Return the sourcecode objects which THIS permits."
1944 (let ((sc (oref this sourcetype))
1946 (while (and (listp sc) sc)
1947 (setq rs (cons (symbol-value (car sc)) rs)
1954 (defun ede-adebug-project ()
1955 "Run adebug against the current ede project.
1956 Display the results as a debug list."
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) "")
1964 (defun ede-adebug-project-parent ()
1965 "Run adebug against the current ede parent project.
1966 Display the results as a debug list."
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) "")
1974 (defun ede-adebug-project-root ()
1975 "Run adebug against the current ede parent project.
1976 Display the results as a debug list."
1978 (require 'data-debug)
1979 (when (ede-toplevel)
1980 (data-debug-new-buffer "*Analyzer ADEBUG*")
1981 (data-debug-insert-object-slots (ede-toplevel) "")
1984 ;;; Hooks & Autoloads
1986 ;; These let us watch various activities, and respond apropriatly.
1988 ;; (add-hook 'edebug-setup-hook
1990 ;; (def-edebug-spec ede-with-projectfile
1991 ;; (form def-body))))
1995 ;; Include this last because it depends on ede.
1996 (require 'ede/files)
1998 ;; If this does not occur after the provide, we can get a recursive
2000 (if (featurep 'speedbar)
2001 (ede-speedbar-file-setup)
2002 (add-hook 'speedbar-load-hook 'ede-speedbar-file-setup))
2004 ;; arch-tag: 0e1e0eba-484f-4119-abdb-30951f725705
2005 ;;; ede.el ends here