Open dabrahams opened 11 years ago
I could, if you explain CEDET to me...
I managed to get ac-clang-complete-(async) to play at least with the ede-cpp-root-project stuff from CEDET. While i still use CEDET/semantic for browsing in my code i disabled it's completion features because ac-clang-complete works much better (not only faster but also accurate :-)).
Here's my configuration snippet. Note that i'm not a real good elisp-hacker so if you have hints to improve then let me know...
(when (file-directory-p "~/lisp/emacs-clang-complete-async")
(add-to-list 'load-path "~/lisp/emacs-clang-complete-async")
(require 'auto-complete-clang-async)
(require 'ede)
(when (file-exists-p "~/.emacs.d/clang-complete")
(setq ac-clang-complete-executable "~/.emacs.d/clang-complete"))
(when (and (string= ac-clang-complete-executable "")
(file-exists-p "~/bin/clang-complete"))
(setq ac-clang-complete-executable "~/bin/clang-complete" "/"))
(when (file-directory-p "~/bin/llvm-3.3-svn/lib")
(setenv "LD_LIBRARY_PATH" (expand-file-name "~/bin/llvm-3.3-svn/lib" "/")))
(cond ((string-equal system-name "darkstar")
(setq ac-cc-mode-system-includes '("/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1"
"/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/x86_64-unknown-linux-gnu"
"/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/backward"
"/usr/local/include"
"/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include"
"/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include-fixed"
"/usr/include")))
((string-equal system-name "hostname-at-work")
(setq ac-cc-mode-system-includes '("/usr/include/c++/4.4"
"/usr/include/c++/4.4/x86_64-linux-gnu"
"/usr/include/c++/4.4/backward"
"/usr/local/include"
"/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include"
"/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include-fixed"
"/usr/include")))
(t nil))
(defmethod ede-include-path ((this ede-cpp-root-project))
"Get the system include path used by ede-project."
(oref this include-path))
(defvar ac-cc-mode-setup-cflags-hook nil
"This hooks are run after the ede and system-includes are set")
(defun ac-cc-mode-setup-from-ede-project ()
"Setup ac-clang-completion based on ede-cpp-root-project"
(ac-config-default)
(when (ede-current-project)
(let ((prj (ede-current-project))
(root (ede-project-root-directory (ede-current-project)))
(cxxflags))
;;---------------------------------------------------------------------------------------------------------------
;; first: parse the ede :spp-table.
;; second: parse the ede :include dirs
;; third: parse the ede :system-include dirs
;; finally: add the ac-cc-mode-system-includes
;;---------------------------------------------------------------------------------------------------------------
(setq cxxflags (append
(mapcar (lambda (def) (let ((sym (car def))
(val (cdr def)))
(cond ((and (stringp val)
(not (zerop (length val))))
(format "-D%s=\"%s\"" sym val))
((numberp val)
(format "-D%s=%s" sym (number-to-string val)))
(t
(concat "-D" sym)))))
(ede-preprocessor-map prj))
(mapcar (lambda (dir) (format "-I%s%s" root (substring dir 1 nil)))
(ede-include-path prj))
(mapcar (lambda (dir) (format "-I%s" dir))
(ede-system-include-path prj))
(mapcar (lambda (dir) (format "-I%s" dir)) ac-cc-mode-system-includes)))
(setq ac-clang-cflags cxxflags))
(setq ac-sources '(ac-source-clang-async))
(run-hooks 'ac-cc-mode-setup-hook)
(ac-clang-launch-completion-process)
(local-set-key (kbd "C-<tab>") 'ac-complete-clang-async)))
(add-hook 'c-mode-common-hook 'ac-cc-mode-setup-from-ede-project)
(add-hook 'auto-complete-mode-hook 'ac-common-setup)
)
Sample project.el:
(ede-cpp-root-project "your-proj"
:name "your-proj"
:file "~/projects/your-proj/Makefile"
:include-path '("/build"
"/first/include"
"/second/include")
:system-include-path '("/usr/include/boost")
:spp-table '(("DEBUG" . "")
("SYMBOL" . "")
("ZERO" . 0)
("ONE" . 1)
("PROJECT_NAME" . "your-proj")
("PROJECT_VERSION" . "1.0.0")))
(defun project-add-clang-cflags ()
(setq ac-clang-cflags (append '("-std=c++11" "-Wall" "-Wextra" "-pedantic" "-D_REENTRANT") ac-clang-cflags)))
(add-hook 'ac-cc-mode-setup-cflags-hook 'project-add-clang-cflags)
The ac-clang-cflags setup you have here is unique from what I have. Can you ac-complete the
Yeah, I realize this might be considered out-of-scope for your project, but when it works it works so well! So it would be awesome if there were some explanation in the README of how to use this effectively with CEDET.