File: cpp-root.el.html
NOTE: ede/cpp-root.el has been commented so as to also make it
useful for learning how to make similar project types.
Not everyone can use automake, or an EDE project type. For pre-existing code, it is often helpful jut to be able to wrap the whole thing up in as simple a way as possible.
The cpp-root project type will allow you to create a single object with no save-file in your .emacs file that will be recognized, and provide a way to easily allow EDE to provide Semantic with the ability to find header files, and other various source files quickly.
The cpp-root class knows a few things about C++ projects, such as
the prevalence of "include" directories, and typical file-layout
stuff. If this isn't sufficient, you can subclass
ede-cpp-root-project(var)/ede-cpp-root-project(fun) and add your own tweaks in just a few lines.
See the end of this file for an example.
; EXAMPLE
Add this to your .emacs file, modifying appropriate bits as needed.
(ede-cpp-root-project "SOMENAME" :file "/dir/to/some/file")
Replace SOMENAME with whatever name you want, and the filename to an actual file at the root of your project. It might be a Makefile, a README file. Whatever. It doesn't matter. It's just a key to hang the rest of EDE off of.
The most likely reason to create this project, is to help make finding files within the project faster. In conjunction with Semantic completion, having a short include path is key. You can override the include path like this:
(ede-cpp-root-project "NAME" :file "FILENAME"
:include-path '( "/include" "../include" "/c/include" )
:system-include-path '( "/usr/include/c++/3.2.2/" )
:spp-table '( ("MOOSE" . "")
("CONST" . "const") )
:spp-files '( "include/config.h" )
)
In this case each item in the include path list is searched. If
the directory starts with "/", then that expands to the project
root directory. If a directory does not start with "/", then it
is relative to the default-directory of the current buffer when
the file name is expanded.
The include path only affects C/C++ header files. Use the slot
:header-match-regexp to change it.
The :system-include-path allows you to specify full directory
names to include directories where system header files can be
found. These will be applied to files in this project only.
The :spp-table provides a list of project specific #define style
macros that are unique to this project, passed in to the compiler
on the command line, or are in special headers.
The :spp-files option is like :spp-table, except you can provide a
file name for a header in your project where most of your CPP
macros reside. Doing this can be easier than listing everything in
the :spp-table option. The files listed in :spp-files should not
start with a /, and are relative to something in :include-path.
If you want to override the file-finding tool with your own function you can do this:
(ede-cpp-root-project "NAME" :file "FILENAME" :locate-fcn 'MYFCN)
Where FILENAME is a file in the root directory of the project. Where MYFCN is a symbol for a function. See:
M-x describe-function RET ede-cpp-root-project RET
for documentation about the locate-fcn extension.
; ADVANCED EXAMPLE
If the cpp-root project style is right for you, but you want a dynamic loader, instead of hard-coding values in your .emacs, you can do that too, but you will need to write some Lisp code.
To do that, you need to add an entry to the
ede-project-class-files list, and also provide two functions to
teach EDE how to load your project pattern
It would look like this:
(defun MY-FILE-FOR-DIR (&optional dir)
"Return a full file name to the project file stored in DIR."
<write your code here, or return nil>
)
(defun MY-LOAD (dir)
"Load a project of type `cpp-root' for the directory DIR.
Return nil if there isn't one."
(ede-cpp-root-project "NAME" :file (expand-file-name "FILE" dir)
:locate-fcn 'MYFCN)
)
(ede-add-project-autoload
(ede-project-autoload "cpp-root"
:name "CPP ROOT"
:file 'ede/cpp-root
:proj-file 'MY-FILE-FOR-DIR
:load-type 'MY-LOAD
:class-sym 'ede-cpp-root-project
:safe-p t))
; TODO
Need a way to reconfigure a project, and have it affect all open buffers. From Tobias Gerdin:
>>3) Is there any way to refresh an ede-cpp-root-project dynamically? I have
>>some file open part of the project, fiddle with the include paths and would
>>like the open buffer to notice this when I re-evaluate the
>>ede-cpp-root-project constructor.
>
> Another good idea. The easy way is to "revert-buffer" as needed. The
> ede "project local variables" does this already, so it should be easy
> to adapt something.
I actually tried reverting the buffer but Semantic did not seem to pick
up the differences (the "include summary" reported the same include paths).
Defined variables (1)
ede-cpp-root-project-list | List of projects created by option ‘ede-cpp-root-project’. |
Defined functions (10)
ede-cpp-root-header-file-p | (ARG &rest ARGS) |
ede-cpp-root-project | (&rest SLOTS) |
ede-cpp-root-project--eieio-childp | (OBJ) |
ede-cpp-root-project-child-p | (OBJ) |
ede-cpp-root-project-p | (OBJ) |
ede-cpp-root-target | (&rest SLOTS) |
ede-cpp-root-target--eieio-childp | (OBJ) |
ede-cpp-root-target-child-p | (OBJ) |
ede-cpp-root-target-p | (OBJ) |
ede-cpp-root-translate-file | (ARG &rest ARGS) |