From 35e454b83932dca5817b6f8b5d4f05b5dbb41dc3 Mon Sep 17 00:00:00 2001 From: Ravi R Kiran Date: Mon, 29 May 2017 18:56:15 -0700 Subject: Let rtags help company-c-headers 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 -- cgit v0.10.1