Creating a custom ede project.
Simon Brown <[email protected]> Thu, 28 May 2015 17:02:09 +0100
| Newsgroups | gmane.emacs.cedet |
|---|---|
| Message-ID | <[email protected]> |
Hi all, I work concurrently on several copies of the same code base spread across a few machines, which makes setting up an ede-cpp-root-project for each one a bit tedious. I've been toying with creating an ede project type for this code base for some time and have recently been having another go. I'm just after code completion at the moment, nothing fancy. My elisp and eieio skills aren't that great though and I'm currently stuck with an eieio error that I don't know how to debug, something is unbound, but I don't know how to deduce what. I also don't know if I should be concerned about the project being unsafe. I've attached the backtrace and the elisp for the project. The elisp is badly butchered from the linux project type. The anchor project type is just a test code base, one include file in /include and one source file in /src. Any hints or suggestions? Simon ------------------------------------------------------------------------------ _______________________________________________ Cedet-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/cedet-devel
anchor.el
(text/x-emacs-lisp, 4.8 KB)
(defvar ede-anchor-project-list nil
"List of Anchor projects.")
(defun ede-anchor-file-existing (dir)
"Find a project in the lis of Anchor projects. DIR is the directory to search from"
(let ((projs ede-anchor-project-list)
(ans nil))
(while (and projs (not ans))
(let ((root (ede-project-root-directory (car projs))))
(when (string-match (concat "^" (regexp-quote root)) dir)
(setq ans (car projs))))
(setq projs (cdr projs)))
ans))
(defun ede-anchor-root (&optional dir)
"Get the root director within the project."
;;(debug)
(when (not dir) (setq dir default-directory))
(let ((case-fold-search t)
(proj (ede-anchor-file-existing dir)))
(if proj
(ede-up-directory (file-name-directory
(oref proj :file)))
;; No pre-existing project. Let's take a wild-guess if we have
;; an Linux project here.
(catch 'found
(dotimes (i 5)
(when (file-exists-p (expand-file-name "include/anchor.h" dir))
(throw 'found dir))
(when (not dir) (throw 'found nil))
(setq dir (ede-up-directory dir)))))))
(defclass ede-anchor-project (ede-project eieio-instance-tracker)
((tracking-symbol:initform 'ede-anchor-project-list)
(include-path :initarg :include-path
:type list
:default nil
:documentation "Include directories."))
"Project type for Imagination Anchor trees."
:method-invocation-order :depth-first)
(defun ede-anchor-include-path (rootdir)
"Returns a list with include directories."
(list (concat rootdir "include")
(concat rootdir "Some/other/dir")))
(defun ede-anchor-load (dir &optional rootproj)
"Return a Anchor Project object if there is a match, nil otherwise.
Arguement DIR is the directory it is created for. ROOTPROJ is something else"
;;(debug)
(or (ede-anchor-file-existing dir)
(let* ((rootdir (ede-anchor-root dir))
(inc-path (ede-anchor-include-path rootdir))
(proj (ede-anchor-project
"Anchor Project"
:name "Test Anchor Project"
:directory (file-name-as-directory dir)
:file (expand-file-name "include/anchor.h" dir))))
:include-path (list "/flurgle" "/wargle")
(ede-add-project-to-global-list proj))))
(ede-add-project-autoload
(ede-project-autoload "Anchor"
:name "Test Anchor Project"
:file 'ede/anchor
:proj-file "include/anchor.h"
;; :proj-root 'ede-anchor-root
:load-type 'ede-anchor-load
:class-sym 'ede-anchor-project
:new-p nil
:safe-p t)
'unique)
(defmethod initialize-instance ((this ede-anchor-project)
&rest fields)
"Do something"
;; (debug)
(call-next-method)
(unless (slot-boundp this 'targets)
(oset this :targets nil)))
(defmethod ede-project-root-directory ((this ede-anchor-project)
&optional file)
"Return something"
(ede-up-directory (file-name-directory (oref this file))))
(defmethod ede-project-root ((this ede-anchor-project))
"Returns something"
(ede-anchor-root))
(defclass ede-anchor-target-c-cpp (ede-target)
((shortname :initform "C/C++")
(extension :initform "\\([ch]\\(pp\\|xx\\|\\+\\+\\)?\\|cc\\|hh\\|CC?\\)"))
"EDE Anchor Project target for C and C++ code.
All directories need at least one target.")
(defclass ede-anchor-target-misc (ede-target)
((shortname :initform "Misc")
(extension :initform ""))
"EDE Anchor Project target for Misc files.
All directories need at least one target.")
(defun ede-anchor-find-matching-target (class dir targets)
"Find a target that is a CLASS and is in DIR in the list of TARGETS."
(let ((match nil))
(dolist (T targets)
(when (and (object-of-class-p T class)
(string= (oref T :path) dir))
(setq match T)
))
match))
(defmethod ede-find-target ((proj ede-anchor-project) buffer)
"Find an EDE target in PROJ for BUFFER.
If one doesn't exist, create a new one for this directory."
(let* ((ext (file-name-extension (buffer-file-name buffer)))
(cls (cond ((not ext)
'ede-anchor-target-misc)
((string-match "c\\|h" ext)
'ede-anchor-target-c-cpp)
(t 'ede-anchor-target-misc)))
(targets (oref proj targets))
(dir default-directory)
(ans (ede-anchor-find-matching-target cls dir targets)))
(when (not ans)
(setq ans (make-instance
cls
:name (file-name-nondirectory
(directory-file-name dir))
:path dir
:source nil))
(object-add-to-list proj :targets ans))
ans))
(defmethod ede-system-include-path ((this ede-anchor-target-c-cpp))
(list "badgerbadger" "Mushroom"))
(provide 'ede/anchor)
backtrace.txt
(text/plain, 5.8 KB) - not displayed