emacs/lisp/cedet/ede/cpp-root.el
David Engster 5d4da32d4e Update from CEDET trunk.
* grammars/c.by (template-type): Add :template-specifier and
:typevar to capture extra details about the template.
(opt-post-fcn-modifiers): Splice in the found symbol into the
return value correctly.
(QUESTION): New punctuation.
(expression): Add ternary conditional support.

* grammars/scheme.by (MODULE): New token.
(scheme): Handle expanding the MODULE tag.
(scheme-list): Remove closeparen required match.
(scheme-in-list): Remove extraneous matches for DEFINE.  Add
support for MODULE Simplify matching for code & make work.
(name-args, name-arg-list, name-arg-expand): Make it work.

* semantic.el (semantic-mode): Add/remove 3
completion-at-point-functions.
(semantic-completion-at-point-function): Removed.
(semantic-analyze-completion-at-point-function)
(semantic-analyze-notc-completion-at-point-function)
(semantic-analyze-nolongprefix-completion-at-point-function): New
completion at point functions.

* semantic/doc.el (semantic-doc-snarf-comment-for-tag): Fix case
when comment-end is empty string.

* semantic/debug.el
(semantic-debug-parser-debugger-source): New buffer local
variable.
(semantic-debug-interface): Add 'nil' initform to overlays.
(semantic-debug-mode): Remove read-only tags from buffers on exit.
(semantic-debug): Add autoload cookie.  Force the language
specific debugger to load.

* semantic/db.el (generic::semanticdb-full-filename): New generic
method to allow this method to be used on buffer names via an
associated database.

* semantic/symref.el
(semantic-symref-cleanup-recent-buffers-fcn): When cleaning up
buffers, don't clean up buffers that are being used (i.e., in a
window) when the hook fires.
(semantic-symref-recently-opened-buffers): New tracking variable.
(semantic-symref-cleanup-recent-buffers-fcn): New hook fcn.
(semantic-symref-result-get-tags): Move logic into
`semantic-symref-hit-to-tag-via-buffer', and cleanup buffers via
the symref cleanup function in post-command-hook.
(semantic-symref-hit-to-tag-via-buffer): Logic that used to be
from above.
(semantic-symref-hit-to-tag-via-db): New.

* semantic/analyze.el:
(semantic-analyze-find-tag-sequence-default): If first entry in
sequence is the only one, apply tagclass filter.
(semantic-analyze-princ-sequence): Show slot even if empty.
(semantic-analyze-find-tag-sequence)
(semantic-analyze-find-tag-sequence-default): Add flags argument.
Add support for forcing the final entry of the sequence to be of
class variable.
(semantic-analyze-find-tag): Fix bug where input class filter was
ignored if there was a typecache match.
(semantic-analyze-current-context-default): For assignments, the
assignee now must be of class variable.

* semantic/analyze/complete.el
(semantic-analyze-possible-completions-default): Add
'no-longprefix' flag.  When used, the prefix and prefixtypes are
shortened to just the last symbol.

* semantic/bovine/c.el (semantic-c-do-lex-if): Catch errors from
'hideif', and push to the parser warning stack.
(semantic-lex-cpp-define): When a comment is at the end of a
macro, do not subtract an extra 1 from the found position.  Fixes
bug with: #define foo (a)/**/ adding an extra ')' to the stream.

* semantic/bovine/scm.el (semantic-lex-scheme-symbol): Allow
symbols to be one char long.

* semantic/bovine/grammar.el
(bovine-grammar-calculate-source-on-path): New.
(bovine-grammar-setupcode-builder): Use it.

* ede.el (ede/detect): New require.
(ede-version): Bump version
(ede-initialize-state-current-buffer): Use new
`ede-detect-directory-for-project' to detect projects first
instead of depending on currente dir only.
(ede-delete-project-from-global-list): New.
(ede-flush-deleted-projects): Use above.
(ede-check-project-query-fcn): New variable
(ede-check-project-directory): Use above when querying the user.
Added to support unit testing of this security measure.
(ede-initialize-state-current-buffer): Use
`ede-directory-project-cons' instead of the -detect- fcn to take
advantage of the cache.  Pass found project into
`ede-load-project-file'.
(ede-load-project-file): Add new input DETECTIN.
(ede-rescan-toplevel): Get the proj root a better way.
(ede-load-project-file): Return the loaded object.  When asking
for existing project, ask for an exact match.
(ede-initialize-state-current-buffer): Simplify some conditional
logic.
(ede-load-project-file): Simplify conditional logic.
(ede-global-list-sanity-check): New Testing fcn.
(ede-parent-project): Replace old code with call to faster
`ede-find-subproject-for-directory'.
(ede-load-project-file): Use
`ede-directory-get-toplevel-open-project' instead of above
deleted.  Rename "pfc" to "autoloader".  Use
`ede-directory-project-cons' to detect a project.  Delete no
project found case where we search up the tree.

* ede/auto.el (ede-project-autoload): Fix doc typo.  Add
`:root-only' slot.
(ede-auto-load-project): Doc update: warn to not use.
(ede-dir-to-projectfile): Deleted.
(ede-project-autoload-dirmatch): Add subdir-only slot.  Make
configdatastash unbound by default.
(ede-do-dirmatch): If subdir-only is true, then don't allow exact
matches.  Account for configdatastash as unbound.  Assume value of
nil means no tool installed.  Make sure loaded path matches from
beginning.  Stash the regexp, not the raw string.
(ede-project-class-files): Note that makefile and automake are not
root only.
(ede-auto-detect-in-dir): New (for use with `ede/detect.el').
(ede-project-dirmatch-p): Deleted.
(ede-project-root-directory): Remove body, return nil.
(ede-project-autoload): :proj-root-dirmatch can be null & doc fix.
(ede-auto-detect-in-dir): If there is no :proj-file, check for a
dirmatch.

* ede/generic.el (ede/config): Replace require of ede.
(ede-generic-new-autoloader): Generic projects are now safe by
default.  Note this is NOT a root only project.
(project-rescan, ede-project-root, ede-generic-target-java)
(ede-java-classpath, ede-find-subproject-for-directory): New.
(ede-enable-generic-projects): Add new autoloaders for git, bzr,
hg, sv, CVS.
(ede-generic-vc-project)
(ede-generic-vc-project::ede-generic-setup-configuration): New.
(ede-generic-config): Remove slots: c-include-path,
c-preprocessor-table, c-preprocessor-files, classpath,
build-command, debug-command, run command.  Inherit from
ede-extra-config-build, ede-extra-config-program.  Make
run-command :value match :custom so only strings are accepted.
Add some more :group slot specifiers.
(ede-generic-project): Add mixins `ede-project-with-config-c' and
`ede-project-with-config-java'. Inherit from
`ede-project-with-config-build',
`ede-project-with-config-program'.  Subclass
`ede-project-with-config'.  Remove duplication from new baseclass.
(ede-generic-target): Inherit from `ede-target-with-config-build',
`ede-target-with-config-program'. Subclass `ede-target-with-config'.
(ede-generic-target-c-cpp): Add mixin `ede-target-with-config-c'.
(ede-generic-target-java): Add mixin `ede-target-with-config-java'.
(ede-preprocessor-map, ede-system-include-path)
(edejava-classpath): Deleted, moved to config.el.
(project-compile-project, project-compile-target)
(project-debug-target, project-run-target): Deleted.
(ede-generic-get-configuration, ede-generic-setup-configuration)
(ede-commit-project, project-rescan)
(ede-generic-project::ede-customize)
(ede-generic-target::ede-customize)
(ede-generic-config::eieio-done-customizing)
(ede-generic-config::ede-commit): Deleted.  Subsumed by new
baseclass.
(ede-preprocessor-map, ede-system-include-path)
(project-debug-target, project-run-target): Call new
`ede-config-get-configuration' instead of old version.
(ede-generic-load): Do not add to global list here.

* ede/files.el (ede-find-project-root)
(ede-files-find-existing)
(ede-directory-get-toplevel-open-project-new): Deleted.
(ede-project-root-directory): Use `ede-project-root' first.
(ede-project-directory-remove-hash)
(ede--directory-project-from-hash)
(ede--directory-project-add-description-to-hash): Rename to make
internal symbols (via --).  Expand input dir first.
(ede-directory-project-p): Doc fix (note obsoleted.)
(ede-toplevel-project-or-nil): Alias to `ede-toplevel-project'.
(ede-toplevel-project): Doc Fix.  Delete commented out old code.
Simplify returning result from ede-detect-directory-for-project.
(ede-directory-get-open-project): Support when
inodes are disabled.  If disabled to str compare on root project.
(ede-directory-get-toplevel-open-project): Enabled nested
projects.  When doing directory name matching, save the 'short'
version of an answer (non-exact match) and eventually select the
shortest answer at the end.  Expand the filename of tested
projects.  Better support for when inodes are disabled.  Add
'exact' option so that it will return a project that is an exact
match.
(ede-find-subproject-for-directory): Small optimization to run
`file-truename' less often.
(ede-directory-project-p): Move content, then use
`ede-directory-project-cons'.  Use
`ede-detect-directory-for-project', replacing old detection loop.
(ede-directory-project-cons): New, from above.
(ede-toplevel-project): Toss old scanning code.  Use
`ede-detect-directory-for-project' instead.
(ede-directory-get-toplevel-open-project-new): New.

* ede/linux.el (ede-linux-project-root): Deleted.
(ede-project-autoload): Remove dirmatch entry - it is no longer
needed.

* lisp/cedet/ede/proj.el (project-rescan): Replace direct
manipulation of `ede-projects' with equivalent and better
functions.
(ede-proj-load): Replace call to test if dir has project to
explicity ask filesystem if Project.ede is there.

* ede/config.el:
* ede/detect.el: New files.

* ede/project-am.el (project-run-target): Add "./" to program to
run for systems where '.' isn't in PATH.
(project-am-load): Remove old code regarding `ede-constructing'.
Just read in the makefiles.

* ede/linux.el (ede-linux-load): Do not add to global list here.
Don't check for existing anymore.
(project-rescan): New.
(ede-linux-project-list, ede-linux-file-existing): Deleted.
(ede-linux-project-root): Delete body.  Need symbol for autoloads
for now.
(ede-linux-project): No longer instance tracker.
(ede-project-autoload): Don't provide :proj-root

* ede/emacs.el (ede-emacs-load): Do not add project to global list
here.  Don't look for existing first.
(ede-project-autoload): Remove dirmatch entry - it is no longer
needed.  Don't provide proj-root anymore.
(ede-emacs-project-list, ede-emacs-file-existing): Delete.
(ede-emacs-project-root): Remove body (need symbol for loaddefs
still).
(ede-emacs-project): Do not instance track anymore.

* ede/cpp-root.el (initialize-instance): Remove commented code.
Add note about why we are adding the project to the master list.
Make sure if we are replacing a prev version, remove from global
list.
(ede-cpp-root-file-existing)
(ede-cpp-root-project-file-for-dir)
(ede-cpp-root-count, ede-cpp-root-project-root, ede-cpp-root-load)
(ede-project-autoload cpp-root): Deleted.
(ede-project-root-directory): Return :directory instead of
calculating from :file.
(project-rescan): New.

* ede/base.el (ede-toplevel): Only use buffer cached value if
subproj not passed in.

* srecode/java.el (srecode-semantic-handle-:java): Fix case when
an EDE project didn't support java paths.

* lisp/cedet/ede/proj-elisp.el
(ede-proj-target-elisp::ede-proj-tweak-autoconf): Kill buffer
after saving modified elisp-comp script, as to avoid "file has
changed on disk; really edit the buffer" questions when script
gets rewritten.

* emacs-lisp/eieio-custom.el (eieio-customize-object): Set
eieio-cog (current group) to g, which is an improved form of input
group.

* srecode/doc-cpp.srt (mode): Set to c mode so this works with
both C and C++.
2014-11-10 01:04:30 +01:00

505 lines
19 KiB
EmacsLisp

;;; ede/cpp-root.el --- A simple way to wrap a C++ project with a single root
;; Copyright (C) 2007-2014 Free Software Foundation, Inc.
;; Author: Eric M. Ludlam <eric@siege-engine.com>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; 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' 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 a 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).
(require 'ede)
(defvar semantic-lex-spp-project-macro-symbol-obarray)
(declare-function semantic-lex-make-spp-table "semantic/lex-spp")
(declare-function semanticdb-file-table-object "semantic/db")
(declare-function semanticdb-needs-refresh-p "semantic/db")
(declare-function semanticdb-refresh-table "semantic/db")
;;; Code:
;;; PROJECT CACHE:
;;
;; cpp-root projects are created in a .emacs or other config file. We
;; need to cache them so if the user re-loads a lisp file with the
;; config in it, we can flush out the old one and replace it.
;;
(defvar ede-cpp-root-project-list nil
"List of projects created by option `ede-cpp-root-project'.")
;;; CLASSES
;;
;; EDE sets up projects with two kinds of objects.
;;
;; The PROJECT is a class that represents everything under a directory
;; hierarchy. A TARGET represents a subset of files within a project.
;; A project can have multiple targets, and multiple sub-projects.
;; Sub projects should map to sub-directories.
;;
;; The CPP-ROOT project maps any file in C or C++ mode to a target for
;; C files.
;;
;; When creating a custom project the project developer an opportunity
;; to run code to setup various tools whenever an associated buffer is
;; loaded. The CPP-ROOT project spends most of its time setting up C
;; level include paths, and PreProcessor macro tables.
(defclass ede-cpp-root-target (ede-target)
((project :initform nil
:initarg :project))
"EDE cpp-root project target.
All directories need at least one target.")
;;;###autoload
(defclass ede-cpp-root-project (ede-project eieio-instance-tracker)
((tracking-symbol :initform 'ede-cpp-root-project-list)
(include-path :initarg :include-path
:initform '( "/include" "../include/" )
:type list
:documentation
"The default locate function expands filenames within a project.
If a header file (.h, .hh, etc) name is expanded, and
the :locate-fcn slot is nil, then the include path is checked
first, and other directories are ignored. For very large
projects, this optimization can save a lot of time.
Directory names in the path can be relative to the current
buffer's `default-directory' (not starting with a /). Directories
that are relative to the project's root should start with a /, such
as \"/include\", meaning the directory `include' off the project root
directory.")
(system-include-path :initarg :system-include-path
:initform nil
:type list
:documentation
"The system include path for files in this project.
C files initialized in an ede-cpp-root-project have their semantic
system include path set to this value. If this is nil, then the
semantic path is not modified.")
(spp-table :initarg :spp-table
:initform nil
:type list
:documentation
"C Preprocessor macros for your files.
Preprocessor symbols will be used while parsing your files.
These macros might be passed in through the command line compiler, or
are critical symbols derived from header files. Providing header files
macro values through this slot improves accuracy and performance.
Use `:spp-files' to use these files directly.")
(spp-files :initarg :spp-files
:initform nil
:type list
:documentation
"C header file with Preprocessor macros for your files.
The PreProcessor symbols appearing in these files will be used while
parsing files in this project.
See `semantic-lex-c-preprocessor-symbol-map' for more on how this works.")
(header-match-regexp :initarg :header-match-regexp
:initform
"\\.\\(h\\(h\\|xx\\|pp\\|\\+\\+\\)?\\|H\\)$\\|\\<\\w+$"
:type string
:documentation
"Regexp used to identify C/C++ header files.")
(locate-fcn :initarg :locate-fcn
:initform nil
:type (or null function)
:documentation
"The locate function can be used in place of
`ede-expand-filename' so you can quickly customize your custom target
to use specialized local routines instead of the EDE routines.
The function symbol must take two arguments:
NAME - The name of the file to find.
DIR - The directory root for this cpp-root project.
It should return the fully qualified file name passed in from NAME. If that file does not
exist, it should return nil."
)
(compile-command :initarg :compile-command
:initform nil
:type (or null string function)
:documentation
"Compilation command that will be used for this project.
It could be string or function that will accept proj argument and should return string.
The string will be passed to 'compile' function that will be issued in root
directory of project."
)
)
"EDE cpp-root project class.
Each directory needs a project file to control it.")
;;; INIT
;;
;; Most projects use `initialize-instance' to do special setup
;; on the object when it is created. In this case, EDE-CPP-ROOT can
;; find previous copies of this project, and make sure that one of the
;; objects is deleted.
(defmethod initialize-instance ((this ede-cpp-root-project)
&rest fields)
"Make sure the :file is fully expanded."
;; Add ourselves to the master list
(call-next-method)
(let ((f (expand-file-name (oref this :file))))
;; Remove any previous entries from the main list.
(let ((old (eieio-instance-tracker-find (file-name-directory f)
:directory 'ede-cpp-root-project-list)))
;; This is safe, because :directory isn't filled in till later.
(when (and old (not (eq old this)))
(ede-delete-project-from-global-list old)
(delete-instance old)))
;; Basic initialization.
(when (or (not (file-exists-p f))
(file-directory-p f))
(delete-instance this)
(error ":file for ede-cpp-root-project must be a file"))
(oset this :file f)
(oset this :directory (file-name-directory f))
(ede-project-directory-remove-hash (file-name-directory f))
;; NOTE: We must add to global list here because these classes are not
;; created via the typial loader, but instead via calls from a .emacs
;; file.
(ede-add-project-to-global-list this)
(unless (slot-boundp this 'targets)
(oset this :targets nil))
))
;;; SUBPROJ Management.
;;
;; This is a way to allow a subdirectory to point back to the root
;; project, simplifying authoring new single-point projects.
(defmethod ede-find-subproject-for-directory ((proj ede-cpp-root-project)
dir)
"Return PROJ, for handling all subdirs below DIR."
proj)
;;; TARGET MANAGEMENT
;;
;; Creating new targets on a per directory basis is a good way to keep
;; files organized. See ede-emacs for an example with multiple file
;; types.
(defmethod ede-find-target ((proj ede-cpp-root-project) buffer)
"Find an EDE target in PROJ for BUFFER.
If one doesn't exist, create a new one for this directory."
(let* ((targets (oref proj targets))
(dir default-directory)
(ans (object-assoc dir :path targets))
)
(when (not ans)
(setq ans (ede-cpp-root-target dir
:name (file-name-nondirectory
(directory-file-name dir))
:path dir
:source nil
:project proj))
(object-add-to-list proj :targets ans)
)
ans))
;;; FILE NAMES
;;
;; One of the more important jobs of EDE is to find files in a
;; directory structure. cpp-root has tricks it knows about how most C
;; projects are set up with include paths.
;;
;; This tools also uses the ede-locate setup for augmented file name
;; lookup using external tools.
(defmethod ede-expand-filename-impl ((proj ede-cpp-root-project) name)
"Within this project PROJ, find the file NAME.
This knows details about or source tree."
;; The slow part of the original is looping over subprojects.
;; This version has no subprojects, so this will handle some
;; basic cases.
(let ((ans (call-next-method)))
(unless ans
(let* ((lf (oref proj locate-fcn))
(dir (file-name-directory (oref proj file))))
(if lf
(setq ans (funcall lf name dir))
(if (ede-cpp-root-header-file-p proj name)
;; Else, use our little hack.
(let ((ip (oref proj include-path))
(tmp nil))
(while ip
;; Translate
(setq tmp (ede-cpp-root-translate-file proj (car ip)))
;; Test this name.
(setq tmp (expand-file-name name tmp))
(if (file-exists-p tmp)
(setq ans tmp))
(setq ip (cdr ip)) ))
;; Else, do the usual.
(setq ans (call-next-method)))
)))
;; TODO - does this call-next-method happen twice. Is that bad?? Why is it here?
(or ans (call-next-method))))
(defmethod ede-project-root ((this ede-cpp-root-project))
"Return my root."
this)
(defmethod ede-project-root-directory ((this ede-cpp-root-project))
"Return my root."
(oref this directory))
;;; C/CPP SPECIFIC CODE
;;
;; The following code is specific to setting up header files,
;; include lists, and Preprocessor symbol tables.
(defmethod ede-cpp-root-header-file-p ((proj ede-cpp-root-project) name)
"Non nil if in PROJ the filename NAME is a header."
(save-match-data
(string-match (oref proj header-match-regexp) name)))
(defmethod ede-cpp-root-translate-file ((proj ede-cpp-root-project) filename)
"For PROJ, translate a user specified FILENAME.
This is for project include paths and spp source files."
;; Step one: Root of this project.
(let ((dir (file-name-directory (oref proj file))))
;; Step two: Analyze first char, and rehost
(if (and (not (string= filename "")) (= (aref filename 0) ?/))
;; Check relative to root of project
(setq filename (expand-file-name (substring filename 1)
dir))
;; Relative to current directory.
(setq filename (expand-file-name filename)))
filename))
(defmethod ede-system-include-path ((this ede-cpp-root-project))
"Get the system include path used by project THIS."
(oref this system-include-path))
(defmethod ede-preprocessor-map ((this ede-cpp-root-project))
"Get the pre-processor map for project THIS."
(require 'semantic/db)
(let ((spp (oref this spp-table))
(root (ede-project-root this))
)
(mapc
(lambda (F)
(let* ((expfile (ede-expand-filename root F))
(table (when expfile
;; Disable EDE init on preprocessor file load
;; otherwise we recurse, cause errs, etc.
(let ((ede-constructing t))
(semanticdb-file-table-object expfile))))
)
(cond
((not (file-exists-p expfile))
(message "Cannot find file %s in project." F))
((string= expfile (buffer-file-name))
;; Don't include this file in it's own spp table.
)
((not table)
(message "No db table available for %s." expfile))
(t
(when (semanticdb-needs-refresh-p table)
(semanticdb-refresh-table table))
(setq spp (append spp (oref table lexical-table)))))))
(oref this spp-files))
spp))
(defmethod ede-system-include-path ((this ede-cpp-root-target))
"Get the system include path used by target THIS."
(ede-system-include-path (ede-target-parent this)))
(defmethod ede-preprocessor-map ((this ede-cpp-root-target))
"Get the pre-processor map for project THIS."
(ede-preprocessor-map (ede-target-parent this)))
(defmethod project-compile-project ((proj ede-cpp-root-project) &optional command)
"Compile the entire current project PROJ.
Argument COMMAND is the command to use when compiling."
;; we need to be in the proj root dir for this to work
(let* ((cmd (oref proj :compile-command))
(ov (oref proj :local-variables))
(lcmd (when ov (cdr (assoc 'compile-command ov))))
(cmd-str (cond
((stringp cmd) cmd)
((functionp cmd) (funcall cmd proj))
((stringp lcmd) lcmd)
((functionp lcmd) (funcall lcmd proj)))))
(when cmd-str
(let ((default-directory (ede-project-root-directory proj)))
(compile cmd-str)))))
(defmethod project-compile-target ((obj ede-cpp-root-target) &optional command)
"Compile the current target OBJ.
Argument COMMAND is the command to use for compiling the target."
(when (oref obj :project)
(project-compile-project (oref obj :project) command)))
(defmethod project-rescan ((this ede-cpp-root-project))
"Don't rescan this project from the sources."
(message "cpp-root has nothing to rescan."))
;;; Quick Hack
(defun ede-create-lots-of-projects-under-dir (dir projfile &rest attributes)
"Create a bunch of projects under directory DIR.
PROJFILE is a file name sans directory that indicates a subdirectory
is a project directory.
Generic ATTRIBUTES, such as :include-path can be added.
Note: This needs some work."
(let ((files (directory-files dir t)))
(dolist (F files)
(if (file-exists-p (expand-file-name projfile F))
`(ede-cpp-root-project (file-name-nondirectory F)
:name (file-name-nondirectory F)
:file (expand-file-name projfile F)
attributes)))))
(provide 'ede/cpp-root)
;; Local variables:
;; generated-autoload-file: "loaddefs.el"
;; generated-autoload-load-name: "ede/cpp-root"
;; End:
;;; ede/cpp-root.el ends here