1 ;;; ede.el --- Emacs Development Environment gloss
3 ;; Copyright (C) 1998-2005, 2007-2015 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; 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)
45 (require 'eieio-speedbar
)
52 (load "ede/loaddefs" nil
'nomessage
))
54 (declare-function ede-commit-project
"ede/custom")
55 (declare-function ede-convert-path
"ede/files")
56 (declare-function ede-directory-get-open-project
"ede/files")
57 (declare-function ede-directory-get-toplevel-open-project
"ede/files")
58 (declare-function ede-directory-project-p
"ede/files")
59 (declare-function ede-find-subproject-for-directory
"ede/files")
60 (declare-function ede-project-directory-remove-hash
"ede/files")
61 (declare-function ede-toplevel
"ede/base")
62 (declare-function ede-toplevel-project
"ede/files")
63 (declare-function ede-up-directory
"ede/files")
64 (declare-function semantic-lex-make-spp-table
"semantic/lex-spp")
66 (defconst ede-version
"2.0"
67 "Current version of the Emacs EDE.")
71 "Display the current running version of EDE."
72 (interactive) (message "EDE %s" ede-version
))
75 "Emacs Development Environment."
79 (defcustom ede-auto-add-method
'ask
80 "Whether a new source file should be automatically added to a target.
81 Whenever a new file is encountered in a directory controlled by a
82 project file, all targets are queried to see if it should be added.
83 If the value is 'always, then the new file is added to the first
84 target encountered. If the value is 'multi-ask, then if more than one
85 target wants the file, the user is asked. If only one target wants
86 the file, then it is automatically added to that target. If the
87 value is 'ask, then the user is always asked, unless there is no
88 target willing to take the file. 'never means never perform the check."
90 :type
'(choice (const always
)
95 (defcustom ede-debug-program-function
'gdb
96 "Default Emacs command used to debug a target."
98 :type
'sexp
) ; make this be a list of options some day
100 (defcustom ede-project-directories nil
101 "Directories in which EDE may search for project files.
102 If the value is t, EDE may search in any directory.
104 If the value is a function, EDE calls that function with one
105 argument, the directory name; the function should return t if
106 EDE should look for project files in the directory.
108 Otherwise, the value should be a list of fully-expanded directory
109 names. EDE searches for project files only in those directories.
110 If you invoke the commands \\[ede] or \\[ede-new] on a directory
111 that is not listed, Emacs will offer to add it to the list.
113 Any other value disables searching for EDE project files."
115 :type
'(choice (const :tag
"Any directory" t
)
116 (repeat :tag
"List of directories"
118 (function :tag
"Predicate"))
122 (defun ede-directory-safe-p (dir)
123 "Return non-nil if DIR is a safe directory to load projects from.
124 Projects that do not load a project definition as Emacs Lisp code
125 are safe, and can be loaded automatically. Other project types,
126 such as those created with Project.ede files, are safe only if
127 specified by `ede-project-directories'."
128 (setq dir
(directory-file-name (expand-file-name dir
)))
129 ;; Load only if allowed by `ede-project-directories'.
130 (or (eq ede-project-directories t
)
131 (and (functionp ede-project-directories
)
132 (funcall ede-project-directories dir
))
133 (and (listp ede-project-directories
)
134 (member dir ede-project-directories
))))
137 ;;; Management variables
139 (defvar ede-projects nil
140 "A list of all active projects currently loaded in Emacs.")
142 (defvar ede-object-root-project nil
143 "The current buffer's current root project.
144 If a file is under a project, this specifies the project that is at
145 the root of a project tree.")
146 (make-variable-buffer-local 'ede-object-root-project
)
148 (defvar ede-object-project nil
149 "The current buffer's current project at that level.
150 If a file is under a project, this specifies the project that contains the
152 (make-variable-buffer-local 'ede-object-project
)
154 (defvar ede-object nil
155 "The current buffer's target object.
156 This object's class determines how to compile and debug from a buffer.")
157 (make-variable-buffer-local 'ede-object
)
159 (defvar ede-selected-object nil
160 "The currently user-selected project or target.
161 If `ede-object' is nil, then commands will operate on this object.")
163 (defvar ede-constructing nil
164 "Non nil when constructing a project hierarchy.
165 If the project is being constructed from an autoload, then the
166 value is the autoload object being used.")
168 (defvar ede-deep-rescan nil
169 "Non nil means scan down a tree, otherwise rescans are top level only.
170 Do not set this to non-nil globally. It is used internally.")
175 (defun ede-singular-object (prompt)
176 "Using PROMPT, choose a single object from the current buffer."
177 (if (listp ede-object
)
178 (ede-choose-object prompt ede-object
)
181 (defun ede-choose-object (prompt list-o-o
)
182 "Using PROMPT, ask the user which OBJECT to use based on the name field.
183 Argument LIST-O-O is the list of objects to choose from."
184 (let* ((al (object-assoc-list 'name list-o-o
))
185 (ans (completing-read prompt al nil t
)))
186 (setq ans
(assoc ans al
))
191 (defvar ede-minor-mode-map
192 (let ((map (make-sparse-keymap))
193 (pmap (make-sparse-keymap)))
194 (define-key pmap
"e" 'ede-edit-file-target
)
195 (define-key pmap
"a" 'ede-add-file
)
196 (define-key pmap
"d" 'ede-remove-file
)
197 (define-key pmap
"t" 'ede-new-target
)
198 (define-key pmap
"g" 'ede-rescan-toplevel
)
199 (define-key pmap
"s" 'ede-speedbar
)
200 (define-key pmap
"f" 'ede-find-file
)
201 (define-key pmap
"C" 'ede-compile-project
)
202 (define-key pmap
"c" 'ede-compile-target
)
203 (define-key pmap
"\C-c" 'ede-compile-selected
)
204 (define-key pmap
"D" 'ede-debug-target
)
205 (define-key pmap
"R" 'ede-run-target
)
206 ;; bind our submap into map
207 (define-key map
"\C-c." pmap
)
209 "Keymap used in project minor mode.")
211 (defvar global-ede-mode-map
212 (let ((map (make-sparse-keymap)))
213 (define-key map
[menu-bar cedet-menu
]
214 (cons "Development" cedet-menu-map
))
216 "Keymap used in `global-ede-mode'.")
218 ;; Activate the EDE items in cedet-menu-map
220 (define-key cedet-menu-map
[ede-find-file
]
221 '(menu-item "Find File in Project..." ede-find-file
:enable ede-object
222 :visible global-ede-mode
))
223 (define-key cedet-menu-map
[ede-speedbar
]
224 '(menu-item "View Project Tree" ede-speedbar
:enable ede-object
225 :visible global-ede-mode
))
226 (define-key cedet-menu-map
[ede]
227 '(menu-item "Load Project" ede
228 :visible global-ede-mode))
229 (define-key cedet-menu-map [ede-new]
230 '(menu-item "Create Project" ede-new
231 :enable (not ede-object)
232 :visible global-ede-mode))
233 (define-key cedet-menu-map [ede-target-options]
234 '(menu-item "Target Options" ede-target-options
235 :filter ede-target-forms-menu
236 :visible global-ede-mode))
237 (define-key cedet-menu-map [ede-project-options]
238 '(menu-item "Project Options" ede-project-options
239 :filter ede-project-forms-menu
240 :visible global-ede-mode))
241 (define-key cedet-menu-map [ede-build-forms-menu]
242 '(menu-item "Build Project" ede-build-forms-menu
243 :filter ede-build-forms-menu
245 :visible global-ede-mode))
247 (defun ede-buffer-belongs-to-target-p ()
248 "Return non-nil if this buffer belongs to at least one target."
249 (let ((obj ede-object))
251 (setq obj (car obj)))
252 (and obj (obj-of-class-p obj 'ede-target))))
254 (defun ede-buffer-belongs-to-project-p ()
255 "Return non-nil if this buffer belongs to at least one project."
256 (if (or (null ede-object) (consp ede-object)) nil
257 (obj-of-class-p ede-object-project 'ede-project)))
259 (defun ede-menu-obj-of-class-p (class)
260 "Return non-nil if some member of `ede-object' is a child of CLASS."
261 (if (listp ede-object)
262 (eval (cons 'or (mapcar (lambda (o) (obj-of-class-p o class)) ede-object)))
263 (obj-of-class-p ede-object class)))
265 (defun ede-build-forms-menu (menu-def)
266 "Create a sub menu for building different parts of an EDE system.
267 Argument MENU-DEF is the menu definition to use."
268 (easy-menu-filter-return
269 (easy-menu-create-menu
271 (let ((obj (ede-current-project))
272 (newmenu nil) ;'([ "Build Selected..." ede-compile-selected t ]))
279 (setq targets (when (slot-boundp obj 'targets)
281 ede-obj (if (listp ede-object) ede-object (list ede-object)))
282 ;; First, collect the build items from the project
283 (setq newmenu (append newmenu (ede-menu-items-build obj t)))
284 ;; Second, declare the current target menu items
285 (if (and ede-obj (ede-menu-obj-of-class-p 'ede-target))
287 (setq newmenu (append newmenu
288 (ede-menu-items-build (car ede-obj) t))
290 ede-obj (cdr ede-obj))))
291 ;; Third, by name, enable builds for other local targets
293 (unless (eq tskip (car targets))
294 (setq targitems (ede-menu-items-build (car targets) nil))
297 (if (= 1 (length targitems))
299 (cons (ede-name (car targets))
302 (setq targets (cdr targets)))
303 ;; Fourth, build sub projects.
305 ;; Fifth, add make distribution
306 (append newmenu (list [ "Make distribution" ede-make-dist t ]))
309 (defun ede-target-forms-menu (menu-def)
310 "Create a target MENU-DEF based on the object belonging to this buffer."
311 (easy-menu-filter-return
312 (easy-menu-create-menu
314 (let ((obj (or ede-selected-object ede-object)))
316 '([ "Add File" ede-add-file
317 (and (ede-current-project)
318 (oref (ede-current-project) targets)) ]
319 [ "Remove File" ede-remove-file
320 (ede-buffer-belongs-to-project-p) ]
324 (if (and (not (listp obj)) (oref obj menu))
327 ;; This is bad, but I'm not sure what else to do.
328 (oref (car obj) menu)))))))))
330 (defun ede-project-forms-menu (menu-def)
331 "Create a target MENU-DEF based on the object belonging to this buffer."
332 (easy-menu-filter-return
333 (easy-menu-create-menu
335 (let* ((obj (ede-current-project))
336 (class (if obj (eieio-object-class obj)))
340 (while (and class (slot-exists-p class 'menu))
341 ;;(message "Looking at class %S" class)
342 (setq menu (append menu (oref-default class menu))
343 class (eieio-class-parent class))
344 (if (listp class) (setq class (car class))))
346 '( [ "Add Target" ede-new-target (ede-current-project) ]
347 [ "Remove Target" ede-delete-target ede-object ]
348 ( "Default configuration" :filter ede-configuration-forms-menu )
352 (error (message "Err found: %S" err)
356 (defun ede-configuration-forms-menu (menu-def)
357 "Create a submenu for selecting the default configuration for this project.
358 The current default is in the current object's CONFIGURATION-DEFAULT slot.
359 All possible configurations are in CONFIGURATIONS.
360 Argument MENU-DEF specifies the menu being created."
361 (easy-menu-filter-return
362 (easy-menu-create-menu
364 (let* ((obj (ede-current-project))
365 (conf (when obj (oref obj configurations)))
366 (cdef (when obj (oref obj configuration-default)))
369 (setq menu (cons (vector C (list 'ede-project-configurations-set C)
371 :selected (string= C cdef))
376 (defun ede-project-configurations-set (newconfig)
377 "Set the current project's current configuration to NEWCONFIG.
378 This function is designed to be used by `ede-configuration-forms-menu'
379 but can also be used interactively."
381 (list (let* ((proj (ede-current-project))
382 (configs (oref proj configurations)))
383 (completing-read "New configuration: "
385 (oref proj configuration-default)))))
386 (oset (ede-current-project) configuration-default newconfig)
387 (message "%s will now build in %s mode."
388 (eieio-object-name (ede-current-project))
391 (defun ede-customize-forms-menu (menu-def)
392 "Create a menu of the project, and targets that can be customized.
393 Argument MENU-DEF is the definition of the current menu."
394 (easy-menu-filter-return
395 (easy-menu-create-menu
397 (let* ((obj (ede-current-project))
400 (setq targ (when (and obj (slot-boundp obj 'targets))
402 ;; Make custom menus for everything here.
404 (cons (concat "Project " (ede-name obj))
405 (eieio-customize-object-group obj))
406 [ "Reorder Targets" ede-project-sort-targets t ]
409 (cons (concat "Target " (ede-name o))
410 (eieio-customize-object-group o)))
414 (defun ede-apply-object-keymap (&optional default)
415 "Add target specific keybindings into the local map.
416 Optional argument DEFAULT indicates if this should be set to the default
417 version of the keymap."
418 (let ((object (or ede-object ede-selected-object))
419 (proj ede-object-project))
421 (let ((keys (ede-object-keybindings object)))
422 ;; Add keys for the project to whatever is in the current object
423 ;; so long as it isn't the same.
424 (when (not (eq object proj))
425 (setq keys (append keys (ede-object-keybindings proj))))
427 (local-set-key (concat "\C-c." (car (car keys)))
429 (setq keys (cdr keys))))
432 ;;; Menu building methods for building
434 (cl-defmethod ede-menu-items-build ((obj ede-project) &optional current)
435 "Return a list of menu items for building project OBJ.
436 If optional argument CURRENT is non-nil, return sub-menu code."
438 (list [ "Build Current Project" ede-compile-project t ])
441 (concat "Build Project " (ede-name obj))
442 `(project-compile-project ,obj))))))
444 (cl-defmethod ede-menu-items-build ((obj ede-target) &optional current)
445 "Return a list of menu items for building target OBJ.
446 If optional argument CURRENT is non-nil, return sub-menu code."
448 (list [ "Build Current Target" ede-compile-target t ])
450 (concat "Build Target " (ede-name obj))
451 `(project-compile-target ,obj)
454 ;;; Mode Declarations
457 (defun ede-apply-target-options ()
458 "Apply options to the current buffer for the active project/target."
459 (ede-apply-project-local-variables)
460 ;; Apply keymaps and preprocessor symbols.
461 (ede-apply-object-keymap)
462 (ede-apply-preprocessor-map)
465 (defun ede-turn-on-hook ()
466 "Turn on EDE minor mode in the current buffer if needed.
467 To be used in hook functions."
468 (if (or (and (stringp (buffer-file-name))
469 (stringp default-directory))
470 ;; Emacs 21 has no buffer file name for directory edits.
471 ;; so we need to add these hacks in.
472 (eq major-mode 'dired-mode)
473 (eq major-mode 'vc-dired-mode))
476 (define-minor-mode ede-minor-mode
477 "Toggle EDE (Emacs Development Environment) minor mode.
478 With a prefix argument ARG, enable EDE minor mode if ARG is
479 positive, and disable it otherwise. If called from Lisp, enable
480 EDE minor mode if ARG is omitted or nil.
482 If this file is contained, or could be contained in an EDE
483 controlled project, then this mode is activated automatically
484 provided `global-ede-mode' is enabled."
486 (cond ((or (eq major-mode 'dired-mode)
487 (eq major-mode 'vc-dired-mode))
488 (ede-dired-minor-mode (if ede-minor-mode 1 -1)))
490 (if (not ede-constructing)
491 (ede-initialize-state-current-buffer)
492 ;; If we fail to have a project here, turn it back off.
493 (ede-minor-mode -1)))))
495 (defun ede-initialize-state-current-buffer ()
496 "Initialize the current buffer's state for EDE.
497 Sets buffer local variables for EDE."
498 ;; due to inode recycling, make sure we don't
499 ;; we flush projects deleted off the system.
500 (ede-flush-deleted-projects)
504 (proj (ede-directory-get-open-project default-directory
508 ;; If there is no open project, look up the project
509 ;; autoloader to see if we should initialize.
510 (let ((projdetect (ede-directory-project-cons default-directory)))
513 ;; No project was loaded, but we have a project description
514 ;; object. This means that we try to load it.
516 ;; Before loading, we need to check if it is a safe
517 ;; project to load before requesting it to be loaded.
519 (when (or (oref (cdr projdetect) safe-p)
520 ;; The project style is not safe, so check if it is
521 ;; in `ede-project-directories'.
522 (let ((top (car projdetect)))
523 (ede-directory-safe-p top)))
525 ;; The project is safe, so load it in.
526 (setq proj (ede-load-project-file default-directory projdetect 'ROOT))))))
528 ;; If PROJ is now loaded in, we can initialize our buffer to it.
531 ;; ede-object represents the specific EDE related class that best
532 ;; represents this buffer. It could be a project (for a project file)
533 ;; or a target. Also save off ede-object-project, the project that
534 ;; the buffer belongs to for the case where ede-object is a target.
535 (setq ede-object (ede-buffer-object (current-buffer)
536 'ede-object-project))
538 ;; Every project has a root. It might be the same as ede-object.
539 ;; Cache that also as the root is a very common thing to need.
540 (setq ede-object-root-project
541 (or ROOT (ede-project-root ede-object-project)))
543 ;; Check to see if we want to add this buffer to a target.
544 (if (and (not ede-object) ede-object-project)
545 (ede-auto-add-to-target))
547 ;; Apply any options from the found target.
548 (ede-apply-target-options))))
550 (defun ede-reset-all-buffers ()
551 "Reset all the buffers due to change in EDE."
553 (let ((b (buffer-list)))
555 (when (buffer-file-name (car b))
556 (with-current-buffer (car b)
557 ;; Reset all state variables
559 ede-object-project nil
560 ede-object-root-project nil)
561 ;; Now re-initialize this buffer.
562 (ede-initialize-state-current-buffer)
568 (define-minor-mode global-ede-mode
569 "Toggle global EDE (Emacs Development Environment) mode.
570 With a prefix argument ARG, enable global EDE mode if ARG is
571 positive, and disable it otherwise. If called from Lisp, enable
572 the mode if ARG is omitted or nil.
574 This global minor mode enables `ede-minor-mode' in all buffers in
575 an EDE controlled project."
579 ;; Turn on global-ede-mode
582 (define-key cedet-menu-map [cedet-menu-separator] '("--")))
583 (add-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
584 (add-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
585 (add-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
586 ;; Append our hook to the end. This allows mode-local to finish
587 ;; it's stuff before we start doing misc file loads, etc.
588 (add-hook 'find-file-hook 'ede-turn-on-hook t)
589 (add-hook 'dired-mode-hook 'ede-turn-on-hook)
590 (add-hook 'kill-emacs-hook 'ede-save-cache)
592 (ede-reset-all-buffers))
593 ;; Turn off global-ede-mode
594 (define-key cedet-menu-map [cedet-menu-separator] nil)
595 (remove-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p)
596 (remove-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil)
597 (remove-hook 'ecb-source-path-functions 'ede-ecb-project-paths)
598 (remove-hook 'find-file-hook 'ede-turn-on-hook)
599 (remove-hook 'dired-mode-hook 'ede-turn-on-hook)
600 (remove-hook 'kill-emacs-hook 'ede-save-cache)
602 (ede-reset-all-buffers)))
604 (defvar ede-ignored-file-alist
609 "List of file name patters that EDE will never ask about.")
611 (defun ede-ignore-file (filename)
612 "Should we ignore FILENAME?"
614 (F ede-ignored-file-alist))
615 (while (and (not any) F)
616 (when (string-match (car F) filename)
621 (defun ede-auto-add-to-target ()
622 "Look for a target that wants to own the current file.
623 Follow the preference set with `ede-auto-add-method' and get the list
624 of objects with the `ede-want-file-p' method."
625 (if ede-object (error "ede-object already defined for %s" (buffer-name)))
626 (if (or (eq ede-auto-add-method 'never)
627 (ede-ignore-file (buffer-file-name)))
630 ;; Find all the objects.
631 (setq wants (oref (ede-current-project) targets))
633 (if (ede-want-file-p (car wants) (buffer-file-name))
634 (setq desires (cons (car wants) desires)))
635 (setq wants (cdr wants)))
637 (cond ((or (eq ede-auto-add-method 'ask)
638 (and (eq ede-auto-add-method 'multi-ask)
639 (< 1 (length desires))))
643 ("new target" . new))
644 ;; If we are in an unparented subdir,
645 ;; offer new a subproject
646 (if (ede-directory-project-p default-directory)
648 '(("create subproject" . project)))
649 ;; Here are the existing objects we want.
650 (object-assoc-list 'name desires)))
652 (ans (completing-read
653 (format "Add %s to target: " (buffer-file-name))
655 (setq ans (assoc ans al))
656 (cond ((eieio-object-p (cdr ans))
657 (ede-add-file (cdr ans)))
661 ((or (eq ede-auto-add-method 'always)
662 (and (eq ede-auto-add-method 'multi-ask)
663 (= 1 (length desires))))
664 (ede-add-file (car desires)))
668 ;;; Interactive method invocations
671 "Start up EDE for directory DIR.
672 If DIR has an existing project file, load it.
673 Otherwise, create a new project for DIR."
675 ;; When choosing a directory to turn on, and we see some directory here,
676 ;; provide that as the default.
677 (let* ((top (ede-toplevel-project default-directory))
678 (promptdflt (or top default-directory)))
679 (list (read-directory-name "Project directory: "
680 promptdflt promptdflt t))))
681 (unless (file-directory-p dir)
682 (error "%s is not a directory" dir))
683 (when (ede-directory-get-open-project dir)
684 (error "%s already has an open project associated with it" dir))
686 ;; Check if the directory has been added to the list of safe
687 ;; directories. It can also add the directory to the safe list if
689 (if (ede-check-project-directory dir)
691 ;; Load the project in DIR, or make one.
692 ;; @TODO - IS THIS REAL?
693 (ede-load-project-file dir)
695 ;; Check if we loaded anything on the previous line.
696 (if (ede-current-project dir)
698 ;; We successfully opened an existing project. Some open
699 ;; buffers may also be referring to this project.
700 ;; Resetting all the buffers will get them to also point
701 ;; at this new open project.
702 (ede-reset-all-buffers)
705 ;; There was no project, so switch to `ede-new' which is how
706 ;; a user can select a new kind of project to create.
707 (let ((default-directory (expand-file-name dir)))
708 (call-interactively 'ede-new))))
710 ;; If the proposed directory isn't safe, then say so.
711 (error "%s is not an allowed project directory in `ede-project-directories'"
714 (defvar ede-check-project-query-fcn 'y-or-n-p
715 "Function used to ask the user if they want to permit a project to load.
716 This is abstracted out so that tests can answer this question.")
718 (defun ede-check-project-directory (dir)
719 "Check if DIR should be in `ede-project-directories'.
720 If it is not, try asking the user if it should be added; if so,
721 add it and save `ede-project-directories' via Customize.
722 Return nil if DIR should not be in `ede-project-directories'."
723 (setq dir (directory-file-name (expand-file-name dir))) ; strip trailing /
724 (or (eq ede-project-directories t)
725 (and (functionp ede-project-directories)
726 (funcall ede-project-directories dir))
727 ;; If `ede-project-directories' is a list, maybe add it.
728 (when (listp ede-project-directories)
729 (or (member dir ede-project-directories)
730 (when (funcall ede-check-project-query-fcn
732 "`%s' is not listed in `ede-project-directories'.
733 Add it to the list of allowed project directories? "
735 (push dir ede-project-directories)
736 ;; If possible, save `ede-project-directories'.
737 (if (or custom-file user-init-file)
738 (let ((coding-system-for-read nil))
739 (customize-save-variable
740 'ede-project-directories
741 ede-project-directories)))
744 (defun ede-new (type &optional name)
745 "Create a new project starting from project type TYPE.
746 Optional argument NAME is the name to give this project."
748 (list (completing-read "Project Type: "
751 (let* ((l ede-project-class-files)
752 (cp (ede-current-project))
753 (cs (when cp (eieio-object-class cp)))
757 (if (eq (oref (car l) :class-sym)
759 (setq r (cons (car l) r)))
760 (if (oref (car l) new-p)
761 (setq r (cons (car l) r))))
765 (error "No valid interactive sub project types for %s"
767 (error "EDE error: Can't find project types to create")))
771 (require 'ede/custom)
772 ;; Make sure we have a valid directory
773 (when (not (file-exists-p default-directory))
774 (error "Cannot create project in non-existent directory %s" default-directory))
775 (when (not (file-writable-p default-directory))
776 (error "No write permissions for %s" default-directory))
777 (unless (ede-check-project-directory default-directory)
778 (error "%s is not an allowed project directory in `ede-project-directories'"
780 ;; Make sure the project directory is loadable in the future.
781 (ede-check-project-directory default-directory)
782 ;; Create the project
783 (let* ((obj (object-assoc type 'name ede-project-class-files))
784 (nobj (let ((f (oref obj file))
785 (pf (oref obj proj-file)))
786 ;; We are about to make something new, changing the
787 ;; state of existing directories.
788 (ede-project-directory-remove-hash default-directory)
789 ;; Make sure this class gets loaded!
791 (make-instance (oref obj class-sym)
792 :name (or name (read-string "Name: "))
793 :directory default-directory
794 :file (cond ((stringp pf)
795 (expand-file-name pf))
800 "Unknown file name specifier %S"
805 (inits (oref obj initializers)))
806 ;; Force the name to match for new objects.
807 (eieio-object-set-name-string nobj (oref nobj :name))
810 (eieio-oset nobj (car inits) (car (cdr inits)))
811 (setq inits (cdr (cdr inits))))
812 (let ((pp (ede-parent-project)))
814 (ede-add-subproject pp nobj)
815 (ede-commit-project pp)))
816 (ede-commit-project nobj))
817 ;; Once the project is created, load it again. This used to happen
818 ;; lazily, but with project loading occurring less often and with
819 ;; security in mind, this is now the safe time to reload.
820 (ede-load-project-file default-directory)
821 ;; Have the menu appear
822 (setq ede-minor-mode t)
824 (message "Project created and saved. You may now create targets."))
826 (cl-defmethod ede-add-subproject ((proj-a ede-project) proj-b)
827 "Add into PROJ-A, the subproject PROJ-B."
828 (oset proj-a subproj (cons proj-b (oref proj-a subproj))))
830 (defun ede-invoke-method (sym &rest args)
831 "Invoke method SYM on the current buffer's project object.
832 ARGS are additional arguments to pass to method SYM."
834 (error "Cannot invoke %s for %s" (symbol-name sym)
836 ;; Always query a target. There should never be multiple
837 ;; projects in a single buffer.
838 (apply sym (ede-singular-object "Target: ") args))
840 (defun ede-rescan-toplevel ()
841 "Rescan all project files."
843 (when (not (ede-toplevel))
844 ;; This directory isn't open. Can't rescan.
845 (error "Attempt to rescan a project that isn't open"))
848 (let ((root (ede-toplevel))
851 (project-rescan root)
852 (ede-reset-all-buffers)
855 (defun ede-new-target (&rest args)
856 "Create a new target specific to this type of project file.
857 Different projects accept different arguments ARGS.
858 Typically you can specify NAME, target TYPE, and AUTOADD, where AUTOADD is
859 a string \"y\" or \"n\", which answers the y/n question done interactively."
861 (apply 'project-new-target (ede-current-project) args)
862 (when (and buffer-file-name
863 (not (file-directory-p buffer-file-name)))
864 (setq ede-object nil)
865 (setq ede-object (ede-buffer-object (current-buffer)))
866 (ede-apply-target-options)))
868 (defun ede-new-target-custom ()
869 "Create a new target specific to this type of project file."
871 (project-new-target-custom (ede-current-project)))
873 (defun ede-delete-target (target)
874 "Delete TARGET from the current project."
876 (let ((ede-object (ede-current-project)))
877 (ede-invoke-method 'project-interactive-select-target
879 ;; Find all sources in buffers associated with the condemned buffer.
880 (let ((condemned (ede-target-buffers target)))
881 (project-delete-target target)
882 ;; Loop over all project controlled buffers
885 (set-buffer (car condemned))
886 (setq ede-object nil)
887 (setq ede-object (ede-buffer-object (current-buffer)))
888 (setq condemned (cdr condemned))))
889 (ede-apply-target-options)))
891 (defun ede-add-file (target)
892 "Add the current buffer to a TARGET in the current project."
894 (let ((ede-object (ede-current-project)))
895 (ede-invoke-method 'project-interactive-select-target
897 (when (stringp target)
898 (let* ((proj (ede-current-project))
899 (ob (object-assoc-list 'name (oref proj targets))))
900 (setq target (cdr (assoc target ob)))))
903 (error "Could not find specified target %S" target))
905 (project-add-file target (buffer-file-name))
906 (setq ede-object nil)
908 ;; Setup buffer local variables.
909 (ede-initialize-state-current-buffer)
911 (when (not ede-object)
912 (error "Can't add %s to target %s: Wrong file type"
913 (file-name-nondirectory (buffer-file-name))
914 (eieio-object-name target)))
915 (ede-apply-target-options))
917 (defun ede-remove-file (&optional force)
918 "Remove the current file from targets.
919 Optional argument FORCE forces the file to be removed without asking."
922 (error "Cannot invoke remove-file for %s" (buffer-name)))
923 (let ((eo (if (listp ede-object)
929 (if (or force (y-or-n-p (format "Remove from %s? " (ede-name (car eo)))))
930 (project-remove-file (car eo) (buffer-file-name)))
932 (setq ede-object nil)
933 (setq ede-object (ede-buffer-object (current-buffer)))
934 (ede-apply-target-options)))
936 (defun ede-edit-file-target ()
937 "Enter the project file to hand edit the current buffer's target."
939 (ede-invoke-method 'project-edit-file-target))
941 ;;; Compilation / Debug / Run
943 (defun ede-compile-project ()
944 "Compile the current project."
946 ;; @TODO - This just wants the root. There should be a better way.
947 (let ((cp (ede-current-project)))
948 (while (ede-parent-project cp)
949 (setq cp (ede-parent-project cp)))
950 (let ((ede-object cp))
951 (ede-invoke-method 'project-compile-project))))
953 (defun ede-compile-selected (target)
954 "Compile some TARGET from the current project."
955 (interactive (list (project-interactive-select-target (ede-current-project)
956 "Target to Build: ")))
957 (project-compile-target target))
959 (defun ede-compile-target ()
960 "Compile the current buffer's associated target."
962 (ede-invoke-method 'project-compile-target))
964 (defun ede-debug-target ()
965 "Debug the current buffer's associated target."
967 (ede-invoke-method 'project-debug-target))
969 (defun ede-run-target ()
970 "Run the current buffer's associated target."
972 (ede-invoke-method 'project-run-target))
974 (defun ede-make-dist ()
975 "Create a distribution from the current project."
977 (let ((ede-object (ede-toplevel)))
978 (ede-invoke-method 'project-make-dist)))
981 ;;; EDE project target baseline methods.
983 ;; If you are developing a new project type, you need to implement
984 ;; all of these methods, unless, of course, they do not make sense
985 ;; for your particular project.
987 ;; Your targets should inherit from `ede-target', and your project
988 ;; files should inherit from `ede-project'. Create the appropriate
989 ;; methods based on those below.
991 (cl-defmethod project-interactive-select-target ((this ede-project-placeholder) prompt)
992 ; checkdoc-params: (prompt)
993 "Make sure placeholder THIS is replaced with the real thing, and pass through."
994 (project-interactive-select-target this prompt))
996 (cl-defmethod project-interactive-select-target ((this ede-project) prompt)
997 "Interactively query for a target that exists in project THIS.
998 Argument PROMPT is the prompt to use when querying the user for a target."
999 (let ((ob (object-assoc-list 'name (oref this targets))))
1000 (cdr (assoc (completing-read prompt ob nil t) ob))))
1002 (cl-defmethod project-add-file ((this ede-project-placeholder) file)
1003 ; checkdoc-params: (file)
1004 "Make sure placeholder THIS is replaced with the real thing, and pass through."
1005 (project-add-file this file))
1007 (cl-defmethod project-add-file ((ot ede-target) file)
1008 "Add the current buffer into project project target OT.
1009 Argument FILE is the file to add."
1010 (error "add-file not supported by %s" (eieio-object-name ot)))
1012 (cl-defmethod project-remove-file ((ot ede-target) fnnd)
1013 "Remove the current buffer from project target OT.
1014 Argument FNND is an argument."
1015 (error "remove-file not supported by %s" (eieio-object-name ot)))
1017 (cl-defmethod project-edit-file-target ((ot ede-target))
1018 "Edit the target OT associated with this file."
1019 (find-file (oref (ede-current-project) file)))
1021 (cl-defmethod project-new-target ((proj ede-project) &rest args)
1022 "Create a new target. It is up to the project PROJ to get the name."
1023 (error "new-target not supported by %s" (eieio-object-name proj)))
1025 (cl-defmethod project-new-target-custom ((proj ede-project))
1026 "Create a new target. It is up to the project PROJ to get the name."
1027 (error "New-target-custom not supported by %s" (eieio-object-name proj)))
1029 (cl-defmethod project-delete-target ((ot ede-target))
1030 "Delete the current target OT from its parent project."
1031 (error "add-file not supported by %s" (eieio-object-name ot)))
1033 (cl-defmethod project-compile-project ((obj ede-project) &optional command)
1034 "Compile the entire current project OBJ.
1035 Argument COMMAND is the command to use when compiling."
1036 (error "compile-project not supported by %s" (eieio-object-name obj)))
1038 (cl-defmethod project-compile-target ((obj ede-target) &optional command)
1039 "Compile the current target OBJ.
1040 Argument COMMAND is the command to use for compiling the target."
1041 (error "compile-target not supported by %s" (eieio-object-name obj)))
1043 (cl-defmethod project-debug-target ((obj ede-target))
1044 "Run the current project target OBJ in a debugger."
1045 (error "debug-target not supported by %s" (eieio-object-name obj)))
1047 (cl-defmethod project-run-target ((obj ede-target))
1048 "Run the current project target OBJ."
1049 (error "run-target not supported by %s" (eieio-object-name obj)))
1051 (cl-defmethod project-make-dist ((this ede-project))
1052 "Build a distribution for the project based on THIS project."
1053 (error "Make-dist not supported by %s" (eieio-object-name this)))
1055 (cl-defmethod project-dist-files ((this ede-project))
1056 "Return a list of files that constitute a distribution of THIS project."
1057 (error "Dist-files is not supported by %s" (eieio-object-name this)))
1059 (cl-defmethod project-rescan ((this ede-project))
1060 "Rescan the EDE project THIS."
1061 (error "Rescanning a project is not supported by %s" (eieio-object-name this)))
1063 (defun ede-ecb-project-paths ()
1064 "Return a list of all paths for all active EDE projects.
1065 This functions is meant for use with ECB."
1066 (let ((p ede-projects)
1069 (setq d (cons (file-name-directory (oref (car p) file))
1074 ;;; PROJECT LOADING/TRACKING
1076 (defun ede-add-project-to-global-list (proj)
1077 "Add the project PROJ to the master list of projects.
1078 On success, return the added project."
1080 (error "No project created to add to master list"))
1081 (when (not (eieio-object-p proj))
1082 (error "Attempt to add non-object to master project list"))
1083 (when (not (obj-of-class-p proj 'ede-project-placeholder))
1084 (error "Attempt to add a non-project to the ede projects list"))
1085 (add-to-list 'ede-projects proj)
1088 (defun ede-delete-project-from-global-list (proj)
1089 "Remove project PROJ from the master list of projects."
1090 (setq ede-projects (remove proj ede-projects)))
1092 (defun ede-flush-deleted-projects ()
1093 "Scan the projects list for projects which no longer exist.
1094 Flush the dead projects from the project cache."
1097 (dolist (P ede-projects)
1098 (when (not (file-exists-p (oref P :file)))
1099 (add-to-list 'dead P)))
1101 (ede-delete-project-from-global-list D))
1104 (defvar ede--disable-inode) ;Defined in ede/files.el.
1106 (defun ede-global-list-sanity-check ()
1107 "Perform a sanity check to make sure there are no duplicate projects."
1109 (let ((scanned nil))
1110 (dolist (P ede-projects)
1111 (if (member (oref P :directory) scanned)
1112 (error "Duplicate project (by dir) found in %s!" (oref P :directory))
1113 (push (oref P :directory) scanned)))
1114 (unless ede--disable-inode
1116 (dolist (P ede-projects)
1117 (if (member (ede--project-inode P) scanned)
1118 (error "Duplicate project (by inode) found in %s!" (ede--project-inode P))
1119 (push (ede--project-inode P) scanned))))
1120 (message "EDE by directory %sis still sane." (if ede--disable-inode "" "& inode "))))
1122 (defun ede-load-project-file (dir &optional detectin rootreturn)
1123 "Project file independent way to read a project in from DIR.
1124 Optional DETECTIN is an autoload cons from `ede-detect-directory-for-project'
1125 which can be passed in to save time.
1126 Optional ROOTRETURN will return the root project for DIR."
1127 ;; Don't do anything if we are in the process of
1128 ;; constructing an EDE object.
1130 ;; Prevent recursion.
1131 (unless ede-constructing
1133 ;; Only load if something new is going on. Flush the dirhash.
1134 (ede-project-directory-remove-hash dir)
1137 ;;(message "EDE LOAD : %S" file)
1139 (path (file-name-as-directory (expand-file-name dir)))
1140 (detect (or detectin (ede-directory-project-cons path)))
1146 (setq toppath (car detect))
1147 (setq autoloader (cdr detect))
1149 ;; See if it's been loaded before. Use exact matching since
1150 ;; know that 'toppath' is the root of the project.
1151 (setq o (ede-directory-get-toplevel-open-project toppath 'exact))
1153 ;; If not open yet, load it.
1155 ;; NOTE: We set ede-constructing to the autoloader we are using.
1156 ;; Some project types have one class, but many autoloaders
1157 ;; and this is how we tell the instantiation which kind of
1159 (let ((ede-constructing autoloader))
1161 ;; This is the only place `ede-auto-load-project' should be called.
1163 (setq o (ede-auto-load-project autoloader toppath))))
1165 ;; Return the found root project.
1166 (when rootreturn (set rootreturn o))
1168 ;; The project has been found (in the global list) or loaded from
1169 ;; disk (via autoloader.) We can now search for the project asked
1170 ;; for from DIR in the sub-list.
1171 (ede-find-subproject-for-directory o path)
1173 ;; Return the project.
1176 ;;; PROJECT ASSOCIATIONS
1178 ;; Moving between relative projects. Associating between buffers and
1180 (defun ede-parent-project (&optional obj)
1181 "Return the project belonging to the parent directory.
1182 Return nil if there is no previous directory.
1183 Optional argument OBJ is an object to find the parent of."
1184 (let* ((proj (or obj ede-object-project)) ;; Current project.
1185 (root (if obj (ede-project-root obj)
1186 ede-object-root-project)))
1187 ;; This case is a SHORTCUT if the project has defined
1188 ;; a way to calculate the project root.
1189 (if (and root proj (eq root proj))
1190 nil ;; we are at the root.
1191 ;; Else, we may have a nil proj or root.
1192 (let* ((thisdir (if obj (oref obj directory)
1194 (updir (ede-up-directory thisdir)))
1196 ;; If there was no root, perhaps we can derive it from
1198 (let ((root (or root (ede-directory-get-toplevel-open-project updir))))
1200 ;; This lets us find a subproject under root based on updir.
1202 (ede-find-subproject-for-directory root updir))
1203 ;; Try the all structure based search.
1204 (ede-directory-get-open-project updir))))))))
1206 (defun ede-current-project (&optional dir)
1207 "Return the current project file.
1208 If optional DIR is provided, get the project for DIR instead."
1209 ;; If it matches the current directory, do we have a pre-existing project?
1210 (let ((proj (when (and (or (not dir) (string= dir default-directory))
1212 ede-object-project)))
1213 ;; No current project.
1216 (let* ((ldir (or dir default-directory)))
1217 (ede-directory-get-open-project ldir)))))
1219 (defun ede-buffer-object (&optional buffer projsym)
1220 "Return the target object for BUFFER.
1221 This function clears cached values and recalculates.
1222 Optional PROJSYM is a symbol, which will be set to the project
1223 that contains the target that becomes buffer's object."
1225 (if (not buffer) (setq buffer (current-buffer)))
1227 (setq ede-object nil)
1228 (let* ((localpo (ede-current-project))
1230 (top (ede-toplevel po)))
1231 (if po (setq ede-object (ede-find-target po buffer)))
1232 ;; If we get nothing, go with the backup plan of slowly
1234 (while (and (not ede-object) (not (eq po top)))
1235 (setq po (ede-parent-project po))
1236 (if po (setq ede-object (ede-find-target po buffer))))
1237 ;; Filter down to 1 project if there are dups.
1238 (if (= (length ede-object) 1)
1239 (setq ede-object (car ede-object)))
1240 ;; Track the project, if needed.
1241 (when (and projsym (symbolp projsym))
1243 ;; If we found a target, then PO is the
1246 ;; If there is no ede-object, then the projsym
1247 ;; is whichever part of the project is most local.
1248 (set projsym localpo))
1250 ;; Return our findings.
1253 (cl-defmethod ede-target-in-project-p ((proj ede-project) target)
1254 "Is PROJ the parent of TARGET?
1255 If TARGET belongs to a subproject, return that project file."
1256 (if (and (slot-boundp proj 'targets)
1257 (memq target (oref proj targets)))
1259 (let ((s (oref proj subproj))
1261 (while (and s (not ans))
1262 (setq ans (ede-target-in-project-p (car s) target))
1266 (defun ede-target-parent (target)
1267 "Return the project which is the parent of TARGET.
1268 It is recommended you track the project a different way as this function
1269 could become slow in time."
1270 (or ede-object-project
1271 ;; If not cached, derive it from the current directory of the target.
1272 (let ((ans nil) (projs ede-projects))
1273 (while (and (not ans) projs)
1274 (setq ans (ede-target-in-project-p (car projs) target)
1278 (cl-defmethod ede-find-target ((proj ede-project) buffer)
1279 "Fetch the target in PROJ belonging to BUFFER or nil."
1280 (with-current-buffer buffer
1282 ;; We can do a short-ut if ede-object local variable is set.
1284 ;; If the buffer is already loaded with good EDE stuff, make sure the
1285 ;; saved project is the project we're looking for.
1286 (when (and ede-object-project (eq proj ede-object-project)) ede-object)
1288 ;; If the variable wasn't set, then we are probably initializing the buffer.
1289 ;; In that case, search the file system.
1290 (if (ede-buffer-mine proj buffer)
1292 (let ((targets (oref proj targets))
1295 (if (ede-buffer-mine (car targets) buffer)
1296 (setq f (cons (car targets) f)))
1297 (setq targets (cdr targets)))
1300 (cl-defmethod ede-target-buffer-in-sourcelist ((this ede-target) buffer source)
1301 "Return non-nil if object THIS is in BUFFER to a SOURCE list.
1302 Handles complex path issues."
1303 (member (ede-convert-path this (buffer-file-name buffer)) source))
1305 (cl-defmethod ede-buffer-mine ((this ede-project) buffer)
1306 "Return non-nil if object THIS lays claim to the file in BUFFER."
1309 (cl-defmethod ede-buffer-mine ((this ede-target) buffer)
1310 "Return non-nil if object THIS lays claim to the file in BUFFER."
1312 (ede-target-buffer-in-sourcelist this buffer (oref this source))
1313 ;; An error implies a bad match.
1319 (defun ede-project-buffers (project)
1320 "Return a list of all active buffers controlled by PROJECT.
1321 This includes buffers controlled by a specific target of PROJECT."
1322 (let ((bl (buffer-list))
1325 (with-current-buffer (car bl)
1326 (when (and ede-object (ede-find-target project (car bl)))
1327 (setq pl (cons (car bl) pl))))
1331 (defun ede-target-buffers (target)
1332 "Return a list of buffers that are controlled by TARGET."
1333 (let ((bl (buffer-list))
1336 (with-current-buffer (car bl)
1337 (if (if (listp ede-object)
1338 (memq target ede-object)
1339 (eq ede-object target))
1340 (setq pl (cons (car bl) pl))))
1344 (defun ede-buffers ()
1345 "Return a list of all buffers controlled by an EDE object."
1346 (let ((bl (buffer-list))
1349 (with-current-buffer (car bl)
1351 (setq pl (cons (car bl) pl))))
1355 (defun ede-map-buffers (proc)
1356 "Execute PROC on all buffers controlled by EDE."
1357 (mapcar proc (ede-buffers)))
1359 (cl-defmethod ede-map-project-buffers ((this ede-project) proc)
1360 "For THIS, execute PROC on all buffers belonging to THIS."
1361 (mapcar proc (ede-project-buffers this)))
1363 (cl-defmethod ede-map-target-buffers ((this ede-target) proc)
1364 "For THIS, execute PROC on all buffers belonging to THIS."
1365 (mapcar proc (ede-target-buffers this)))
1367 ;; other types of mapping
1368 (cl-defmethod ede-map-subprojects ((this ede-project) proc)
1369 "For object THIS, execute PROC on all direct subprojects.
1370 This function does not apply PROC to sub-sub projects.
1371 See also `ede-map-all-subprojects'."
1372 (mapcar proc (oref this subproj)))
1374 (cl-defmethod ede-map-all-subprojects ((this ede-project) allproc)
1375 "For object THIS, execute PROC on THIS and all subprojects.
1376 This function also applies PROC to sub-sub projects.
1377 See also `ede-map-subprojects'."
1379 (list (funcall allproc this))
1380 (ede-map-subprojects
1383 (ede-map-all-subprojects sp allproc))
1386 ;; (ede-map-all-subprojects (ede-load-project-file "../semantic/") (lambda (sp) (oref sp file)))
1388 (cl-defmethod ede-map-targets ((this ede-project) proc)
1389 "For object THIS, execute PROC on all targets."
1390 (mapcar proc (oref this targets)))
1392 (cl-defmethod ede-map-any-target-p ((this ede-project) proc)
1393 "For project THIS, map PROC to all targets and return if any non-nil.
1394 Return the first non-nil value returned by PROC."
1395 (eval (cons 'or (ede-map-targets this proc))))
1398 ;;; Some language specific methods.
1400 ;; These items are needed by ede-cpp-root to add better support for
1401 ;; configuring items for Semantic.
1404 (cl-defmethod ede-system-include-path ((this ede-project))
1405 "Get the system include path used by project THIS."
1408 (cl-defmethod ede-system-include-path ((this ede-target))
1409 "Get the system include path used by project THIS."
1412 (cl-defmethod ede-source-paths ((this ede-project) mode)
1413 "Get the base to all source trees in the current project for MODE.
1414 For example, <root>/src for sources of c/c++, Java, etc,
1415 and <root>/doc for doc sources."
1419 (defun ede-apply-preprocessor-map ()
1420 "Apply preprocessor tables onto the current buffer."
1421 ;; TODO - what if semantic-mode isn't enabled?
1422 ;; what if we never want to load a C mode? Does this matter?
1423 ;; Note: This require is needed for the case where EDE ends up
1424 ;; in the hook order before Semantic based hooks.
1425 (require 'semantic/lex-spp)
1426 (when (and ede-object
1427 (boundp 'semantic-lex-spp-project-macro-symbol-obarray))
1428 (let* ((objs ede-object)
1429 (map (ede-preprocessor-map (if (consp objs)
1433 ;; We can't do a require for the below symbol.
1434 (setq semantic-lex-spp-project-macro-symbol-obarray
1435 (semantic-lex-make-spp-table map)))
1437 (message "Choosing preprocessor syms for project %s"
1438 (eieio-object-name (car objs)))))))
1440 (cl-defmethod ede-system-include-path ((this ede-project))
1441 "Get the system include path used by project THIS."
1444 (cl-defmethod ede-preprocessor-map ((this ede-project))
1445 "Get the pre-processor map for project THIS."
1448 (cl-defmethod ede-preprocessor-map ((this ede-target))
1449 "Get the pre-processor map for project THIS."
1453 (cl-defmethod ede-java-classpath ((this ede-project))
1454 "Return the classpath for this project."
1455 ;; @TODO - Can JDEE add something here?
1459 ;;; Project-local variables
1461 (defun ede-set (variable value &optional proj)
1462 "Set the project local VARIABLE to VALUE.
1463 If VARIABLE is not project local, just use set. Optional argument PROJ
1464 is the project to use, instead of `ede-current-project'."
1465 (interactive "sVariable: \nxExpression: ")
1466 (let ((p (or proj (ede-toplevel)))
1469 (ede-make-project-local-variable variable p)
1470 (ede-set-project-local-variable variable value p)
1471 (ede-commit-local-variables p)
1473 ;; This is a heavy hammer, but will apply variables properly
1474 ;; based on stacking between the toplevel and child projects.
1475 (ede-map-buffers 'ede-apply-project-local-variables)
1479 (defun ede-apply-project-local-variables (&optional buffer)
1480 "Apply project local variables to the current buffer."
1481 (with-current-buffer (or buffer (current-buffer))
1482 ;; Always apply toplevel variables.
1483 (if (not (eq (ede-current-project) (ede-toplevel)))
1484 (ede-set-project-variables (ede-toplevel)))
1485 ;; Next apply more local project's variables.
1486 (if (ede-current-project)
1487 (ede-set-project-variables (ede-current-project)))
1490 (defun ede-make-project-local-variable (variable &optional project)
1491 "Make VARIABLE project-local to PROJECT."
1492 (if (not project) (setq project (ede-toplevel)))
1493 (if (assoc variable (oref project local-variables))
1495 (oset project local-variables (cons (list variable)
1496 (oref project local-variables)))))
1498 (defun ede-set-project-local-variable (variable value &optional project)
1499 "Set VARIABLE to VALUE for PROJECT.
1500 If PROJ isn't specified, use the current project.
1501 This function only assigns the value within the project structure.
1502 It does not apply the value to buffers."
1503 (if (not project) (setq project (ede-toplevel)))
1504 (let ((va (assoc variable (oref project local-variables))))
1506 (error "Cannot set project variable until it is added with `ede-make-project-local-variable'"))
1509 (cl-defmethod ede-set-project-variables ((project ede-project) &optional buffer)
1510 "Set variables local to PROJECT in BUFFER."
1511 (if (not buffer) (setq buffer (current-buffer)))
1512 (with-current-buffer buffer
1513 (dolist (v (oref project local-variables))
1514 (make-local-variable (car v))
1515 (set (car v) (cdr v)))))
1517 (cl-defmethod ede-commit-local-variables ((proj ede-project))
1518 "Commit change to local variables in PROJ."
1521 ;;; Integration with project.el
1523 (defun project-try-ede (dir)
1525 (locate-dominating-file
1528 (ede-directory-get-open-project dir 'ROOT)))))
1530 (ede-directory-get-open-project project-dir 'ROOT))))
1532 (cl-defmethod project-roots ((project ede-project))
1533 (list (ede-project-root-directory project)))
1535 (add-hook 'project-find-functions #'project-try-ede)
1539 ;; Include this last because it depends on ede.
1540 (require 'ede/files)
1542 ;; If this does not occur after the provide, we can get a recursive
1544 (if (featurep 'speedbar)
1545 (ede-speedbar-file-setup)
1546 (add-hook 'speedbar-load-hook 'ede-speedbar-file-setup))
1548 ;;; ede.el ends here