Thursday, June 23, 2011

Setting up Cedet for multiple copies of the same project in Emacs

When working on a project from a project repository, I find it useful to have multiple copies of a project checked out at once. I use Cedet and it is repetitious to define a project for each checked-out copy. My solution is to utilize an environment variable called PROJECT_WORKSPACES containing the space-separated paths of all checked-out copies. The following .emacs code sets up the Cedet project for each of project paths specified in the environment variable.

  (when (getenv "PROJECT_WORKSPACES")
    (setq project_paths (split-string (getenv "PROJECT_WORKSPACES")))

    (while project_paths
      (setq project_path (eval (car project_paths)))
      (when (and project_path (file-exists-p project_path))
        (ede-cpp-root-project project_path
                              :name project_path
                              :file (concat project_path "/p4config.txt")
                              :include-path '("/include"
                                              )
                              ))
      (setq project_paths (cdr project_paths))
      )
    )

More idiomatic version by Aankhen.

(when (getenv "PROJECT_WORKSPACES")
   (let ((paths (split-string (getenv "PROJECT_WORKSPACES"))))
     (dolist (path paths)
       (when (and path (file-exists-p path))
         (ede-cpp-root-project path
                               :name path
                               :file (concat path "/p4config.txt")
                               :include-path '("/include"))))))

2 comments:

Aankhen said...

Here’s some slightly more idiomatic code:

(when (getenv "PROJECT_WORKSPACES")
(let ((paths (split-string (getenv "PROJECT_WORKSPACES"))))
(dolist (path paths)
(when (and path (file-exists-p path))
(ede-cpp-root-project path
:name path
:file (concat path "/p4config.txt")
:include-path '("/include"))))))

It’s a pity that Blogger will probably eat the indentation.

tsengf said...

Thanks Aankhen for the improvement.