summaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorRavi R Kiran <aine.marina@gmail.com>2017-05-30 01:56:15 (GMT)
committerRavi R Kiran <aine.marina@gmail.com>2017-05-30 01:56:15 (GMT)
commit35e454b83932dca5817b6f8b5d4f05b5dbb41dc3 (patch)
tree2485fcbf5dc1b8d43d213b508f28d568982aa12e /lisp
parent9b38e1a4d65046e03746533fdd299050dec66026 (diff)
downloaddotemacs-35e454b83932dca5817b6f8b5d4f05b5dbb41dc3.zip
dotemacs-35e454b83932dca5817b6f8b5d4f05b5dbb41dc3.tar.gz
dotemacs-35e454b83932dca5817b6f8b5d4f05b5dbb41dc3.tar.bz2
Let rtags help company-c-headers
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ravi-init-cpp.el34
1 files changed, 34 insertions, 0 deletions
diff --git a/lisp/ravi-init-cpp.el b/lisp/ravi-init-cpp.el
index e30c38a..09a0d5b 100644
--- a/lisp/ravi-init-cpp.el
+++ b/lisp/ravi-init-cpp.el
@@ -457,6 +457,40 @@ this to 3 makes header-protection define KIG_MISC_NEWTYPE_H for a file named
(setq rtags-path (ravi/emacs-file "site-lisp/rtags/bin"))
(rtags-start-process-unless-running)
+ ;; Extra support for company-c-headers if we can get include paths
+ ;; from the compilation command line from rtags
+ ;; (require 'dash) (require 's)
+ (defun ravi/set-company-c-headers-paths-from-rtags ()
+ (interactive)
+ (let* ((compile-flags (rtags-compilation-flags))
+ (nostdinc (-contains? compile-flags "-nostdinc"))
+ (isystem-found)
+ (i-found)
+ (system-dirs)
+ (user-dirs))
+ (when compile-flags
+ (setq isystem-found nil
+ i-found nil
+ system-dirs (list)
+ user-dirs (list))
+ (dolist (flag compile-flags)
+ (cond
+ (isystem-found (add-to-list 'system-dirs flag t)
+ (setq isystem-found nil))
+ (i-found (add-to-list 'user-dirs flag t)
+ (setq i-found nil))
+ ((s-equals? "-isystem" flag) (setq isystem-found t))
+ ((s-equals? "-I" flag) (setq i-found t))
+ ((s-starts-with? "-I" flag) (add-to-list 'user-dirs (s-chop-prefix "-I" flag) t))
+ (t nil)))
+ (setq user-dirs (-concat (-difference user-dirs system-dirs) system-dirs))
+ ;(message "User dirs: %s" user-dirs)
+ (if nostdinc
+ (set (make-local-variable 'company-c-headers-path-system) user-dirs)
+ (when user-dirs
+ (make-local-variable 'company-c-headers-path-system)
+ (setq company-c-headers-path-system (-concat user-dirs company-c-headers-path-system)))))))
+ (add-hook 'c++-mode-hook 'ravi/set-company-c-headers-paths-from-rtags)
(use-package company-rtags
:config