- ;; Only load if something new is going on. Flush the dirhash.
- (ede-project-directory-remove-hash dir)
- ;; Do the load
- ;;(message "EDE LOAD : %S" file)
- (let* ((file dir)
- (path (file-name-as-directory (expand-file-name dir)))
- (pfc (ede-directory-project-p path))
- (toppath nil)
- (o nil))
- (cond
- ((not pfc)
- ;; @TODO - Do we really need to scan? Is this a waste of time?
- ;; Scan upward for a the next project file style.
- (let ((p path))
- (while (and p (not (ede-directory-project-p p)))
- (setq p (ede-up-directory p)))
- (if p (ede-load-project-file p)
- nil)
- ;; recomment as we go
- ;;nil
- ))
- ;; Do nothing if we are building an EDE project already.
- (ede-constructing
- nil)
- ;; Load in the project in question.
- (t
- (setq toppath (ede-toplevel-project path))
- ;; We found the top-most directory. Check to see if we already
- ;; have an object defining its project.
- (setq pfc (ede-directory-project-p toppath t))
-
- ;; See if it's been loaded before
- (setq o (object-assoc (ede-dir-to-projectfile pfc toppath) 'file
- ede-projects))
-
- ;; If not open yet, load it.
- (unless o
- (let ((ede-constructing pfc))
- (setq o (ede-auto-load-project pfc toppath))))
-
- ;; Return the found root project.
- (when rootreturn (set rootreturn o))
-
- (let (tocheck found)
- ;; Now find the project file belonging to FILE!
- (setq tocheck (list o))
- (setq file (ede-dir-to-projectfile pfc (expand-file-name path)))
- (while (and tocheck (not found))
- (let ((newbits nil))
- (when (car tocheck)
- (if (string= file (oref (car tocheck) file))
- (setq found (car tocheck)))
- (setq newbits (oref (car tocheck) subproj)))
- (setq tocheck
- (append (cdr tocheck) newbits))))
- (if (not found)
- (message "No project for %s, but passes project-p test" file)
- ;; Now that the file has been reset inside the project object, do
- ;; the cache maintenance.
- (setq ede-project-cache-files
- (delete (oref found file) ede-project-cache-files)))
- found)))))
+ ;; Don't do anything if we are in the process of
+ ;; constructing an EDE object.
+ ;;
+ ;; Prevent recursion.
+ (unless ede-constructing
+
+ ;; Only load if something new is going on. Flush the dirhash.
+ (ede-project-directory-remove-hash dir)
+
+ ;; Do the load
+ ;;(message "EDE LOAD : %S" file)
+ (let* ((file dir)
+ (path (file-name-as-directory (expand-file-name dir)))
+ (detect (or detectin (ede-directory-project-cons path)))
+ (autoloader nil)
+ (toppath nil)
+ (o nil))
+
+ (when detect
+ (setq toppath (car detect))
+ (setq autoloader (cdr detect))
+
+ ;; See if it's been loaded before. Use exact matching since
+ ;; know that 'toppath' is the root of the project.
+ (setq o (ede-directory-get-toplevel-open-project toppath 'exact))
+
+ ;; If not open yet, load it.
+ (unless o
+ ;; NOTE: We set ede-constructing to the autoloader we are using.
+ ;; Some project types have one class, but many autoloaders
+ ;; and this is how we tell the instantiation which kind of
+ ;; project to make.
+ (let ((ede-constructing autoloader))
+
+ ;; This is the only place `ede-auto-load-project' should be called.
+
+ (setq o (ede-auto-load-project autoloader toppath))))
+
+ ;; Return the found root project.
+ (when rootreturn (set rootreturn o))
+
+ ;; The project has been found (in the global list) or loaded from
+ ;; disk (via autoloader.) We can now search for the project asked
+ ;; for from DIR in the sub-list.
+ (ede-find-subproject-for-directory o path)
+
+ ;; Return the project.
+ o))))