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
731 (format "`%s' is not listed in `ede-project-directories'.
732 Add it to the list of allowed project directories? "
734 (push dir ede-project-directories)
735 ;; If possible, save `ede-project-directories'.
736 (if (or custom-file user-init-file)
737 (let ((coding-system-for-read nil))
738 (customize-save-variable
739 'ede-project-directories
740 ede-project-directories)))
743 (defun ede-new (type &optional name)
744 "Create a new project starting from project type TYPE.
745 Optional argument NAME is the name to give this project."
747 (list (completing-read "Project Type: "
750 (let* ((l ede-project-class-files)
751 (cp (ede-current-project))
752 (cs (when cp (eieio-object-class cp)))
756 (if (eq (oref (car l) :class-sym)
758 (setq r (cons (car l) r)))
759 (if (oref (car l) new-p)
760 (setq r (cons (car l) r))))
764 (error "No valid interactive sub project types for %s"
766 (error "EDE error: Can't fin project types to create")))
770 (require 'ede/custom)
771 ;; Make sure we have a valid directory
772 (when (not (file-exists-p default-directory))
773 (error "Cannot create project in non-existent directory %s" default-directory))
774 (when (not (file-writable-p default-directory))
775 (error "No write permissions for %s" default-directory))
776 (unless (ede-check-project-directory default-directory)
777 (error "%s is not an allowed project directory in `ede-project-directories'"
779 ;; Make sure the project directory is loadable in the future.
780 (ede-check-project-directory default-directory)
781 ;; Create the project
782 (let* ((obj (object-assoc type 'name ede-project-class-files))
783 (nobj (let ((f (oref obj file))
784 (pf (oref obj proj-file)))
785 ;; We are about to make something new, changing the
786 ;; state of existing directories.
787 (ede-project-directory-remove-hash default-directory)
788 ;; Make sure this class gets loaded!
790 (make-instance (oref obj class-sym)
791 :name (or name (read-string "Name: "))
792 :directory default-directory
793 :file (cond ((stringp pf)
794 (expand-file-name pf))
799 "Unknown file name specifier %S"
804 (inits (oref obj initializers)))
805 ;; Force the name to match for new objects.
806 (eieio-object-set-name-string nobj (oref nobj :name))
809 (eieio-oset nobj (car inits) (car (cdr inits)))
810 (setq inits (cdr (cdr inits))))
811 (let ((pp (ede-parent-project)))
813 (ede-add-subproject pp nobj)
814 (ede-commit-project pp)))
815 (ede-commit-project nobj))
816 ;; Once the project is created, load it again. This used to happen
817 ;; lazily, but with project loading occurring less often and with
818 ;; security in mind, this is now the safe time to reload.
819 (ede-load-project-file default-directory)
820 ;; Have the menu appear
821 (setq ede-minor-mode t)
823 (message "Project created and saved. You may now create targets."))
825 (cl-defmethod ede-add-subproject ((proj-a ede-project) proj-b)
826 "Add into PROJ-A, the subproject PROJ-B."
827 (oset proj-a subproj (cons proj-b (oref proj-a subproj))))
829 (defun ede-invoke-method (sym &rest args)
830 "Invoke method SYM on the current buffer's project object.
831 ARGS are additional arguments to pass to method SYM."
833 (error "Cannot invoke %s for %s" (symbol-name sym)
835 ;; Always query a target. There should never be multiple
836 ;; projects in a single buffer.
837 (apply sym (ede-singular-object "Target: ") args))
839 (defun ede-rescan-toplevel ()
840 "Rescan all project files."
842 (when (not (ede-toplevel))
843 ;; This directory isn't open. Can't rescan.
844 (error "Attempt to rescan a project that isn't open"))
847 (let ((root (ede-toplevel))
850 (project-rescan root)
851 (ede-reset-all-buffers)
854 (defun ede-new-target (&rest args)
855 "Create a new target specific to this type of project file.
856 Different projects accept different arguments ARGS.
857 Typically you can specify NAME, target TYPE, and AUTOADD, where AUTOADD is
858 a string \"y\" or \"n\", which answers the y/n question done interactively."
860 (apply 'project-new-target (ede-current-project) args)
861 (when (and buffer-file-name
862 (not (file-directory-p buffer-file-name)))
863 (setq ede-object nil)
864 (setq ede-object (ede-buffer-object (current-buffer)))
865 (ede-apply-target-options)))
867 (defun ede-new-target-custom ()
868 "Create a new target specific to this type of project file."
870 (project-new-target-custom (ede-current-project)))
872 (defun ede-delete-target (target)
873 "Delete TARGET from the current project."
875 (let ((ede-object (ede-current-project)))
876 (ede-invoke-method 'project-interactive-select-target
878 ;; Find all sources in buffers associated with the condemned buffer.
879 (let ((condemned (ede-target-buffers target)))
880 (project-delete-target target)
881 ;; Loop over all project controlled buffers
884 (set-buffer (car condemned))
885 (setq ede-object nil)
886 (setq ede-object (ede-buffer-object (current-buffer)))
887 (setq condemned (cdr condemned))))
888 (ede-apply-target-options)))
890 (defun ede-add-file (target)
891 "Add the current buffer to a TARGET in the current project."
893 (let ((ede-object (ede-current-project)))
894 (ede-invoke-method 'project-interactive-select-target
896 (when (stringp target)
897 (let* ((proj (ede-current-project))
898 (ob (object-assoc-list 'name (oref proj targets))))
899 (setq target (cdr (assoc target ob)))))
902 (error "Could not find specified target %S" target))
904 (project-add-file target (buffer-file-name))
905 (setq ede-object nil)
907 ;; Setup buffer local variables.
908 (ede-initialize-state-current-buffer)
910 (when (not ede-object)
911 (error "Can't add %s to target %s: Wrong file type"
912 (file-name-nondirectory (buffer-file-name))
913 (eieio-object-name target)))
914 (ede-apply-target-options))
916 (defun ede-remove-file (&optional force)
917 "Remove the current file from targets.
918 Optional argument FORCE forces the file to be removed without asking."
921 (error "Cannot invoke remove-file for %s" (buffer-name)))
922 (let ((eo (if (listp ede-object)
928 (if (or force (y-or-n-p (format "Remove from %s? " (ede-name (car eo)))))
929 (project-remove-file (car eo) (buffer-file-name)))
931 (setq ede-object nil)
932 (setq ede-object (ede-buffer-object (current-buffer)))
933 (ede-apply-target-options)))
935 (defun ede-edit-file-target ()
936 "Enter the project file to hand edit the current buffer's target."
938 (ede-invoke-method 'project-edit-file-target))
940 ;;; Compilation / Debug / Run
942 (defun ede-compile-project ()
943 "Compile the current project."
945 ;; @TODO - This just wants the root. There should be a better way.
946 (let ((cp (ede-current-project)))
947 (while (ede-parent-project cp)
948 (setq cp (ede-parent-project cp)))
949 (let ((ede-object cp))
950 (ede-invoke-method 'project-compile-project))))
952 (defun ede-compile-selected (target)
953 "Compile some TARGET from the current project."
954 (interactive (list (project-interactive-select-target (ede-current-project)
955 "Target to Build: ")))
956 (project-compile-target target))
958 (defun ede-compile-target ()
959 "Compile the current buffer's associated target."
961 (ede-invoke-method 'project-compile-target))
963 (defun ede-debug-target ()
964 "Debug the current buffer's associated target."
966 (ede-invoke-method 'project-debug-target))
968 (defun ede-run-target ()
969 "Run the current buffer's associated target."
971 (ede-invoke-method 'project-run-target))
973 (defun ede-make-dist ()
974 "Create a distribution from the current project."
976 (let ((ede-object (ede-toplevel)))
977 (ede-invoke-method 'project-make-dist)))
980 ;;; EDE project target baseline methods.
982 ;; If you are developing a new project type, you need to implement
983 ;; all of these methods, unless, of course, they do not make sense
984 ;; for your particular project.
986 ;; Your targets should inherit from `ede-target', and your project
987 ;; files should inherit from `ede-project'. Create the appropriate
988 ;; methods based on those below.
990 (cl-defmethod project-interactive-select-target ((this ede-project-placeholder) prompt)
991 ; checkdoc-params: (prompt)
992 "Make sure placeholder THIS is replaced with the real thing, and pass through."
993 (project-interactive-select-target this prompt))
995 (cl-defmethod project-interactive-select-target ((this ede-project) prompt)
996 "Interactively query for a target that exists in project THIS.
997 Argument PROMPT is the prompt to use when querying the user for a target."
998 (let ((ob (object-assoc-list 'name (oref this targets))))
999 (cdr (assoc (completing-read prompt ob nil t) ob))))
1001 (cl-defmethod project-add-file ((this ede-project-placeholder) file)
1002 ; checkdoc-params: (file)
1003 "Make sure placeholder THIS is replaced with the real thing, and pass through."
1004 (project-add-file this file))
1006 (cl-defmethod project-add-file ((ot ede-target) file)
1007 "Add the current buffer into project project target OT.
1008 Argument FILE is the file to add."
1009 (error "add-file not supported by %s" (eieio-object-name ot)))
1011 (cl-defmethod project-remove-file ((ot ede-target) fnnd)
1012 "Remove the current buffer from project target OT.
1013 Argument FNND is an argument."
1014 (error "remove-file not supported by %s" (eieio-object-name ot)))
1016 (cl-defmethod project-edit-file-target ((ot ede-target))
1017 "Edit the target OT associated with this file."
1018 (find-file (oref (ede-current-project) file)))
1020 (cl-defmethod project-new-target ((proj ede-project) &rest args)
1021 "Create a new target. It is up to the project PROJ to get the name."
1022 (error "new-target not supported by %s" (eieio-object-name proj)))
1024 (cl-defmethod project-new-target-custom ((proj ede-project))
1025 "Create a new target. It is up to the project PROJ to get the name."
1026 (error "New-target-custom not supported by %s" (eieio-object-name proj)))
1028 (cl-defmethod project-delete-target ((ot ede-target))
1029 "Delete the current target OT from its parent project."
1030 (error "add-file not supported by %s" (eieio-object-name ot)))
1032 (cl-defmethod project-compile-project ((obj ede-project) &optional command)
1033 "Compile the entire current project OBJ.
1034 Argument COMMAND is the command to use when compiling."
1035 (error "compile-project not supported by %s" (eieio-object-name obj)))
1037 (cl-defmethod project-compile-target ((obj ede-target) &optional command)
1038 "Compile the current target OBJ.
1039 Argument COMMAND is the command to use for compiling the target."
1040 (error "compile-target not supported by %s" (eieio-object-name obj)))
1042 (cl-defmethod project-debug-target ((obj ede-target))
1043 "Run the current project target OBJ in a debugger."
1044 (error "debug-target not supported by %s" (eieio-object-name obj)))
1046 (cl-defmethod project-run-target ((obj ede-target))
1047 "Run the current project target OBJ."
1048 (error "run-target not supported by %s" (eieio-object-name obj)))
1050 (cl-defmethod project-make-dist ((this ede-project))
1051 "Build a distribution for the project based on THIS project."
1052 (error "Make-dist not supported by %s" (eieio-object-name this)))
1054 (cl-defmethod project-dist-files ((this ede-project))
1055 "Return a list of files that constitute a distribution of THIS project."
1056 (error "Dist-files is not supported by %s" (eieio-object-name this)))
1058 (cl-defmethod project-rescan ((this ede-project))
1059 "Rescan the EDE project THIS."
1060 (error "Rescanning a project is not supported by %s" (eieio-object-name this)))
1062 (defun ede-ecb-project-paths ()
1063 "Return a list of all paths for all active EDE projects.
1064 This functions is meant for use with ECB."
1065 (let ((p ede-projects)
1068 (setq d (cons (file-name-directory (oref (car p) file))
1073 ;;; PROJECT LOADING/TRACKING
1075 (defun ede-add-project-to-global-list (proj)
1076 "Add the project PROJ to the master list of projects.
1077 On success, return the added project."
1079 (error "No project created to add to master list"))
1080 (when (not (eieio-object-p proj))
1081 (error "Attempt to add non-object to master project list"))
1082 (when (not (obj-of-class-p proj 'ede-project-placeholder))
1083 (error "Attempt to add a non-project to the ede projects list"))
1084 (add-to-list 'ede-projects proj)
1087 (defun ede-delete-project-from-global-list (proj)
1088 "Remove project PROJ from the master list of projects."
1089 (setq ede-projects (remove proj ede-projects)))
1091 (defun ede-flush-deleted-projects ()
1092 "Scan the projects list for projects which no longer exist.
1093 Flush the dead projects from the project cache."
1096 (dolist (P ede-projects)
1097 (when (not (file-exists-p (oref P :file)))
1098 (add-to-list 'dead P)))
1100 (ede-delete-project-from-global-list D))
1103 (defvar ede--disable-inode) ;Defined in ede/files.el.
1105 (defun ede-global-list-sanity-check ()
1106 "Perform a sanity check to make sure there are no duplicate projects."
1108 (let ((scanned nil))
1109 (dolist (P ede-projects)
1110 (if (member (oref P :directory) scanned)
1111 (error "Duplicate project (by dir) found in %s!" (oref P :directory))
1112 (push (oref P :directory) scanned)))
1113 (unless ede--disable-inode
1115 (dolist (P ede-projects)
1116 (if (member (ede--project-inode P) scanned)
1117 (error "Duplicate project (by inode) found in %s!" (ede--project-inode P))
1118 (push (ede--project-inode P) scanned))))
1119 (message "EDE by directory %sis still sane." (if ede--disable-inode "" "& inode "))))
1121 (defun ede-load-project-file (dir &optional detectin rootreturn)
1122 "Project file independent way to read a project in from DIR.
1123 Optional DETECTIN is an autoload cons from `ede-detect-directory-for-project'
1124 which can be passed in to save time.
1125 Optional ROOTRETURN will return the root project for DIR."
1126 ;; Don't do anything if we are in the process of
1127 ;; constructing an EDE object.
1129 ;; Prevent recursion.
1130 (unless ede-constructing
1132 ;; Only load if something new is going on. Flush the dirhash.
1133 (ede-project-directory-remove-hash dir)
1136 ;;(message "EDE LOAD : %S" file)
1138 (path (file-name-as-directory (expand-file-name dir)))
1139 (detect (or detectin (ede-directory-project-cons path)))
1145 (setq toppath (car detect))
1146 (setq autoloader (cdr detect))
1148 ;; See if it's been loaded before. Use exact matching since
1149 ;; know that 'toppath' is the root of the project.
1150 (setq o (ede-directory-get-toplevel-open-project toppath 'exact))
1152 ;; If not open yet, load it.
1154 ;; NOTE: We set ede-constructing to the autoloader we are using.
1155 ;; Some project types have one class, but many autoloaders
1156 ;; and this is how we tell the instantiation which kind of
1158 (let ((ede-constructing autoloader))
1160 ;; This is the only place `ede-auto-load-project' should be called.
1162 (setq o (ede-auto-load-project autoloader toppath))))
1164 ;; Return the found root project.
1165 (when rootreturn (set rootreturn o))
1167 ;; The project has been found (in the global list) or loaded from
1168 ;; disk (via autoloader.) We can now search for the project asked
1169 ;; for from DIR in the sub-list.
1170 (ede-find-subproject-for-directory o path)
1172 ;; Return the project.
1175 ;;; PROJECT ASSOCIATIONS
1177 ;; Moving between relative projects. Associating between buffers and
1179 (defun ede-parent-project (&optional obj)
1180 "Return the project belonging to the parent directory.
1181 Return nil if there is no previous directory.
1182 Optional argument OBJ is an object to find the parent of."
1183 (let* ((proj (or obj ede-object-project)) ;; Current project.
1184 (root (if obj (ede-project-root obj)
1185 ede-object-root-project)))
1186 ;; This case is a SHORTCUT if the project has defined
1187 ;; a way to calculate the project root.
1188 (if (and root proj (eq root proj))
1189 nil ;; we are at the root.
1190 ;; Else, we may have a nil proj or root.
1191 (let* ((thisdir (if obj (oref obj directory)
1193 (updir (ede-up-directory thisdir)))
1195 ;; If there was no root, perhaps we can derive it from
1197 (let ((root (or root (ede-directory-get-toplevel-open-project updir))))
1199 ;; This lets us find a subproject under root based on updir.
1201 (ede-find-subproject-for-directory root updir))
1202 ;; Try the all structure based search.
1203 (ede-directory-get-open-project updir))))))))
1205 (defun ede-current-project (&optional dir)
1206 "Return the current project file.
1207 If optional DIR is provided, get the project for DIR instead."
1208 ;; If it matches the current directory, do we have a pre-existing project?
1209 (let ((proj (when (and (or (not dir) (string= dir default-directory))
1211 ede-object-project)))
1212 ;; No current project.
1215 (let* ((ldir (or dir default-directory)))
1216 (ede-directory-get-open-project ldir)))))
1218 (defun ede-buffer-object (&optional buffer projsym)
1219 "Return the target object for BUFFER.
1220 This function clears cached values and recalculates.
1221 Optional PROJSYM is a symbol, which will be set to the project
1222 that contains the target that becomes buffer's object."
1224 (if (not buffer) (setq buffer (current-buffer)))
1226 (setq ede-object nil)
1227 (let* ((localpo (ede-current-project))
1229 (top (ede-toplevel po)))
1230 (if po (setq ede-object (ede-find-target po buffer)))
1231 ;; If we get nothing, go with the backup plan of slowly
1233 (while (and (not ede-object) (not (eq po top)))
1234 (setq po (ede-parent-project po))
1235 (if po (setq ede-object (ede-find-target po buffer))))
1236 ;; Filter down to 1 project if there are dups.
1237 (if (= (length ede-object) 1)
1238 (setq ede-object (car ede-object)))
1239 ;; Track the project, if needed.
1240 (when (and projsym (symbolp projsym))
1242 ;; If we found a target, then PO is the
1245 ;; If there is no ede-object, then the projsym
1246 ;; is whichever part of the project is most local.
1247 (set projsym localpo))
1249 ;; Return our findings.
1252 (cl-defmethod ede-target-in-project-p ((proj ede-project) target)
1253 "Is PROJ the parent of TARGET?
1254 If TARGET belongs to a subproject, return that project file."
1255 (if (and (slot-boundp proj 'targets)
1256 (memq target (oref proj targets)))
1258 (let ((s (oref proj subproj))
1260 (while (and s (not ans))
1261 (setq ans (ede-target-in-project-p (car s) target))
1265 (defun ede-target-parent (target)
1266 "Return the project which is the parent of TARGET.
1267 It is recommended you track the project a different way as this function
1268 could become slow in time."
1269 (or ede-object-project
1270 ;; If not cached, derive it from the current directory of the target.
1271 (let ((ans nil) (projs ede-projects))
1272 (while (and (not ans) projs)
1273 (setq ans (ede-target-in-project-p (car projs) target)
1277 (cl-defmethod ede-find-target ((proj ede-project) buffer)
1278 "Fetch the target in PROJ belonging to BUFFER or nil."
1279 (with-current-buffer buffer
1281 ;; We can do a short-ut if ede-object local variable is set.
1283 ;; If the buffer is already loaded with good EDE stuff, make sure the
1284 ;; saved project is the project we're looking for.
1285 (when (and ede-object-project (eq proj ede-object-project)) ede-object)
1287 ;; If the variable wasn't set, then we are probably initializing the buffer.
1288 ;; In that case, search the file system.
1289 (if (ede-buffer-mine proj buffer)
1291 (let ((targets (oref proj targets))
1294 (if (ede-buffer-mine (car targets) buffer)
1295 (setq f (cons (car targets) f)))
1296 (setq targets (cdr targets)))
1299 (cl-defmethod ede-target-buffer-in-sourcelist ((this ede-target) buffer source)
1300 "Return non-nil if object THIS is in BUFFER to a SOURCE list.
1301 Handles complex path issues."
1302 (member (ede-convert-path this (buffer-file-name buffer)) source))
1304 (cl-defmethod ede-buffer-mine ((this ede-project) buffer)
1305 "Return non-nil if object THIS lays claim to the file in BUFFER."
1308 (cl-defmethod ede-buffer-mine ((this ede-target) buffer)
1309 "Return non-nil if object THIS lays claim to the file in BUFFER."
1311 (ede-target-buffer-in-sourcelist this buffer (oref this source))
1312 ;; An error implies a bad match.
1318 (defun ede-project-buffers (project)
1319 "Return a list of all active buffers controlled by PROJECT.
1320 This includes buffers controlled by a specific target of PROJECT."
1321 (let ((bl (buffer-list))
1324 (with-current-buffer (car bl)
1325 (when (and ede-object (ede-find-target project (car bl)))
1326 (setq pl (cons (car bl) pl))))
1330 (defun ede-target-buffers (target)
1331 "Return a list of buffers that are controlled by TARGET."
1332 (let ((bl (buffer-list))
1335 (with-current-buffer (car bl)
1336 (if (if (listp ede-object)
1337 (memq target ede-object)
1338 (eq ede-object target))
1339 (setq pl (cons (car bl) pl))))
1343 (defun ede-buffers ()
1344 "Return a list of all buffers controlled by an EDE object."
1345 (let ((bl (buffer-list))
1348 (with-current-buffer (car bl)
1350 (setq pl (cons (car bl) pl))))
1354 (defun ede-map-buffers (proc)
1355 "Execute PROC on all buffers controlled by EDE."
1356 (mapcar proc (ede-buffers)))
1358 (cl-defmethod ede-map-project-buffers ((this ede-project) proc)
1359 "For THIS, execute PROC on all buffers belonging to THIS."
1360 (mapcar proc (ede-project-buffers this)))
1362 (cl-defmethod ede-map-target-buffers ((this ede-target) proc)
1363 "For THIS, execute PROC on all buffers belonging to THIS."
1364 (mapcar proc (ede-target-buffers this)))
1366 ;; other types of mapping
1367 (cl-defmethod ede-map-subprojects ((this ede-project) proc)
1368 "For object THIS, execute PROC on all direct subprojects.
1369 This function does not apply PROC to sub-sub projects.
1370 See also `ede-map-all-subprojects'."
1371 (mapcar proc (oref this subproj)))
1373 (cl-defmethod ede-map-all-subprojects ((this ede-project) allproc)
1374 "For object THIS, execute PROC on THIS and all subprojects.
1375 This function also applies PROC to sub-sub projects.
1376 See also `ede-map-subprojects'."
1378 (list (funcall allproc this))
1379 (ede-map-subprojects
1382 (ede-map-all-subprojects sp allproc))
1385 ;; (ede-map-all-subprojects (ede-load-project-file "../semantic/") (lambda (sp) (oref sp file)))
1387 (cl-defmethod ede-map-targets ((this ede-project) proc)
1388 "For object THIS, execute PROC on all targets."
1389 (mapcar proc (oref this targets)))
1391 (cl-defmethod ede-map-any-target-p ((this ede-project) proc)
1392 "For project THIS, map PROC to all targets and return if any non-nil.
1393 Return the first non-nil value returned by PROC."
1394 (eval (cons 'or (ede-map-targets this proc))))
1397 ;;; Some language specific methods.
1399 ;; These items are needed by ede-cpp-root to add better support for
1400 ;; configuring items for Semantic.
1403 (cl-defmethod ede-system-include-path ((this ede-project))
1404 "Get the system include path used by project THIS."
1407 (cl-defmethod ede-system-include-path ((this ede-target))
1408 "Get the system include path used by project THIS."
1411 (cl-defmethod ede-source-paths ((this ede-project) mode)
1412 "Get the base to all source trees in the current project for MODE.
1413 For example, <root>/src for sources of c/c++, Java, etc,
1414 and <root>/doc for doc sources."
1418 (defun ede-apply-preprocessor-map ()
1419 "Apply preprocessor tables onto the current buffer."
1420 ;; TODO - what if semantic-mode isn't enabled?
1421 ;; what if we never want to load a C mode? Does this matter?
1422 ;; Note: This require is needed for the case where EDE ends up
1423 ;; in the hook order before Semantic based hooks.
1424 (require 'semantic/lex-spp)
1425 (when (and ede-object
1426 (boundp 'semantic-lex-spp-project-macro-symbol-obarray))
1427 (let* ((objs ede-object)
1428 (map (ede-preprocessor-map (if (consp objs)
1432 ;; We can't do a require for the below symbol.
1433 (setq semantic-lex-spp-project-macro-symbol-obarray
1434 (semantic-lex-make-spp-table map)))
1436 (message "Choosing preprocessor syms for project %s"
1437 (eieio-object-name (car objs)))))))
1439 (cl-defmethod ede-system-include-path ((this ede-project))
1440 "Get the system include path used by project THIS."
1443 (cl-defmethod ede-preprocessor-map ((this ede-project))
1444 "Get the pre-processor map for project THIS."
1447 (cl-defmethod ede-preprocessor-map ((this ede-target))
1448 "Get the pre-processor map for project THIS."
1452 (cl-defmethod ede-java-classpath ((this ede-project))
1453 "Return the classpath for this project."
1454 ;; @TODO - Can JDEE add something here?
1458 ;;; Project-local variables
1460 (defun ede-set (variable value &optional proj)
1461 "Set the project local VARIABLE to VALUE.
1462 If VARIABLE is not project local, just use set. Optional argument PROJ
1463 is the project to use, instead of `ede-current-project'."
1464 (interactive "sVariable: \nxExpression: ")
1465 (let ((p (or proj (ede-toplevel)))
1468 (ede-make-project-local-variable variable p)
1469 (ede-set-project-local-variable variable value p)
1470 (ede-commit-local-variables p)
1472 ;; This is a heavy hammer, but will apply variables properly
1473 ;; based on stacking between the toplevel and child projects.
1474 (ede-map-buffers 'ede-apply-project-local-variables)
1478 (defun ede-apply-project-local-variables (&optional buffer)
1479 "Apply project local variables to the current buffer."
1480 (with-current-buffer (or buffer (current-buffer))
1481 ;; Always apply toplevel variables.
1482 (if (not (eq (ede-current-project) (ede-toplevel)))
1483 (ede-set-project-variables (ede-toplevel)))
1484 ;; Next apply more local project's variables.
1485 (if (ede-current-project)
1486 (ede-set-project-variables (ede-current-project)))
1489 (defun ede-make-project-local-variable (variable &optional project)
1490 "Make VARIABLE project-local to PROJECT."
1491 (if (not project) (setq project (ede-toplevel)))
1492 (if (assoc variable (oref project local-variables))
1494 (oset project local-variables (cons (list variable)
1495 (oref project local-variables)))))
1497 (defun ede-set-project-local-variable (variable value &optional project)
1498 "Set VARIABLE to VALUE for PROJECT.
1499 If PROJ isn't specified, use the current project.
1500 This function only assigns the value within the project structure.
1501 It does not apply the value to buffers."
1502 (if (not project) (setq project (ede-toplevel)))
1503 (let ((va (assoc variable (oref project local-variables))))
1505 (error "Cannot set project variable until it is added with `ede-make-project-local-variable'"))
1508 (cl-defmethod ede-set-project-variables ((project ede-project) &optional buffer)
1509 "Set variables local to PROJECT in BUFFER."
1510 (if (not buffer) (setq buffer (current-buffer)))
1511 (with-current-buffer buffer
1512 (dolist (v (oref project local-variables))
1513 (make-local-variable (car v))
1514 (set (car v) (cdr v)))))
1516 (cl-defmethod ede-commit-local-variables ((proj ede-project))
1517 "Commit change to local variables in PROJ."
1520 ;;; Integration with project.el
1522 (defun project-try-ede (dir)
1524 (locate-dominating-file
1527 (ede-directory-get-open-project dir 'ROOT)))))
1529 (ede-directory-get-open-project project-dir 'ROOT))))
1531 (cl-defmethod project-roots ((project ede-project))
1532 (list (ede-project-root-directory project)))
1534 (add-hook 'project-find-functions #'project-try-ede)
1538 ;; Include this last because it depends on ede.
1539 (require 'ede/files)
1541 ;; If this does not occur after the provide, we can get a recursive
1543 (if (featurep 'speedbar)
1544 (ede-speedbar-file-setup)
1545 (add-hook 'speedbar-load-hook 'ede-speedbar-file-setup))
1547 ;;; ede.el ends here