]> code.delx.au - gnu-emacs/blobdiff - lisp/cedet/ede/base.el
Update copyright year to 2015
[gnu-emacs] / lisp / cedet / ede / base.el
index da36919b23a55e8e95786da2465a3de164c6d561..9f4fa45ff3ac8e972d37250a28198f42f955d82a 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ede/base.el --- Baseclasses for EDE.
 
-;; Copyright (C) 2010-201 Free Software Foundation, Inc.
+;; Copyright (C) 2010-2015 Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 
@@ -135,7 +135,9 @@ other desired outcome.")
    (dirinode :documentation "The inode id for :directory.")
    (file :type string
         :initarg :file
-        :documentation "File name where this project is stored.")
+        :documentation "The File uniquely tagging this project instance.
+For some project types, this will be the file that stores the project configuration.
+In other projects types, this file is merely a unique identifier to this type of project.")
    (rootproject ; :initarg - no initarg, don't save this slot!
     :initform nil
     :type (or null ede-project-placeholder-child)
@@ -163,7 +165,7 @@ and querying them will cause the actual project to get loaded.")
            :documentation "Sub projects controlled by this project.
 For Automake based projects, each directory is treated as a project.")
    (targets :initarg :targets
-           :type list
+           :type ede-target-list
            :custom (repeat (object :objectcreatefcn ede-new-target-custom))
            :label "Local Targets"
            :group (targets)
@@ -285,22 +287,15 @@ All specific project types must derive from this project."
 ;;
 (defmacro ede-with-projectfile (obj &rest forms)
   "For the project in which OBJ resides, execute FORMS."
-  (list 'save-window-excursion
-       (list 'let* (list
-                    (list 'pf
-                          (list 'if (list 'obj-of-class-p
-                                          obj 'ede-target)
-                                ;; @todo -I think I can change
-                                ;; this to not need ede-load-project-file
-                                ;; but I'm not sure how to test well.
-                                (list 'ede-load-project-file
-                                      (list 'oref obj 'path))
-                                obj))
-                    '(dbka (get-file-buffer (oref pf file))))
-             '(if (not dbka) (find-file (oref pf file))
-                (switch-to-buffer dbka))
-             (cons 'progn forms)
-             '(if (not dbka) (kill-buffer (current-buffer))))))
+  `(save-window-excursion
+     (let* ((pf (if (obj-of-class-p ,obj ede-target)
+                   (ede-target-parent ,obj)
+                 ,obj))
+           (dbka (get-file-buffer (oref pf file))))
+       (if (not dbka) (find-file (oref pf file))
+        (switch-to-buffer dbka))
+       ,@forms
+       (if (not dbka) (kill-buffer (current-buffer))))))
 (put 'ede-with-projectfile 'lisp-indent-function 1)
 
 ;;; The EDE persistent cache.
@@ -311,7 +306,8 @@ All specific project types must derive from this project."
 ;;
 (defcustom ede-project-placeholder-cache-file
   (locate-user-emacs-file "ede-projects.el" ".projects.ede")
-  "File containing the list of projects EDE has viewed."
+  "File containing the list of projects EDE has viewed.
+If set to nil, then the cache is not saved."
   :group 'ede
   :type 'file)
 
@@ -321,48 +317,49 @@ All specific project types must derive from this project."
 (defun ede-save-cache ()
   "Save a cache of EDE objects that Emacs has seen before."
   (interactive)
-  (let ((p ede-projects)
-       (c ede-project-cache-files)
-       (recentf-exclude '( (lambda (f) t) ))
-       )
-    (condition-case nil
-       (progn
-         (set-buffer (find-file-noselect ede-project-placeholder-cache-file t))
-         (erase-buffer)
-         (insert ";; EDE project cache file.
-;; This contains a list of projects you have visited.\n(")
-         (while p
-           (when (and (car p) (ede-project-p p))
-             (let ((f (oref (car p) file)))
-               (when (file-exists-p f)
-                 (insert "\n  \"" f "\""))))
-           (setq p (cdr p)))
-         (while c
-           (insert "\n \"" (car c) "\"")
-           (setq c (cdr c)))
-         (insert "\n)\n")
-         (condition-case nil
-             (save-buffer 0)
-           (error
-            (message "File %s could not be saved."
-                     ede-project-placeholder-cache-file)))
-         (kill-buffer (current-buffer))
+  (when ede-project-placeholder-cache-file
+    (let ((p ede-projects)
+         (c ede-project-cache-files)
+         (recentf-exclude '( (lambda (f) t) ))
          )
-      (error
-       (message "File %s could not be read."
-               ede-project-placeholder-cache-file))
-
-      )))
+      (condition-case nil
+         (progn
+           (set-buffer (find-file-noselect ede-project-placeholder-cache-file t))
+           (erase-buffer)
+           (insert ";; EDE project cache file.
+;; This contains a list of projects you have visited.\n(")
+           (while p
+             (when (and (car p) (ede-project-p p))
+               (let ((f (oref (car p) file)))
+                 (when (file-exists-p f)
+                   (insert "\n  \"" f "\""))))
+             (setq p (cdr p)))
+           (while c
+             (insert "\n \"" (car c) "\"")
+             (setq c (cdr c)))
+           (insert "\n)\n")
+           (condition-case nil
+               (save-buffer 0)
+             (error
+              (message "File %s could not be saved."
+                       ede-project-placeholder-cache-file)))
+           (kill-buffer (current-buffer))
+           )
+       (error
+        (message "File %s could not be read."
+                 ede-project-placeholder-cache-file))
+
+       ))))
 
 (defun ede-load-cache ()
   "Load the cache of EDE projects."
   (save-excursion
-    (let ((cachebuffer nil))
+    (let ((cachebuffer (get-buffer-create "*ede cache*")))
       (condition-case nil
-         (progn
-           (setq cachebuffer
-                 (find-file-noselect ede-project-placeholder-cache-file t))
-           (set-buffer cachebuffer)
+         (with-current-buffer cachebuffer
+           (erase-buffer)
+           (when (file-exists-p ede-project-placeholder-cache-file)
+             (insert-file-contents ede-project-placeholder-cache-file))
            (goto-char (point-min))
            (let ((c (read (current-buffer)))
                  (new nil)
@@ -413,7 +410,7 @@ Specifying PARENT is useful for sub-sub projects relative to the root project."
 (defmethod ede-subproject-p ((proj ede-project))
   "Return non-nil if PROJ is a sub project."
   ;; @TODO - Use this in more places, and also pay attention to
-  ;; metasubproject in ede-proj.el
+  ;; metasubproject in ede/proj.el
   (ede-parent-project proj))
 
 \f
@@ -608,7 +605,7 @@ Display the results as a debug list."
   "Return the ede project which is the root of the current project.
 Optional argument SUBPROJ indicates a subproject to start from
 instead of the current project."
-  (or ede-object-root-project
+  (or (when (not subproj) ede-object-root-project)
       (let* ((cp (or subproj (ede-current-project))))
        (or (and cp (ede-project-root cp))
            (progn
@@ -616,6 +613,28 @@ instead of the current project."
                (setq cp (ede-parent-project cp)))
              cp)))))
 
+\f
+;;; Utility functions
+;;
+
+(defun ede-normalize-file/directory (this project-file-name)
+  "Fills :directory or :file slots if they're missing in project THIS.
+The other slot will be used to calculate values.
+PROJECT-FILE-NAME is a name of project file (short name, like 'pom.xml', etc."
+  (when (and (or (not (slot-boundp this :file))
+                (not (oref this :file)))
+            (slot-boundp this :directory)
+            (oref this :directory))
+    (oset this :file (expand-file-name project-file-name (oref this :directory))))
+  (when (and (or (not (slot-boundp this :directory))
+                (not (oref this :directory)))
+            (slot-boundp this :file)
+            (oref this :file))
+    (oset this :directory (file-name-directory (oref this :file))))
+  )
+
+
+
 \f
 ;;; Hooks & Autoloads
 ;;